Commit 2a833213 authored by Patrick Mochel's avatar Patrick Mochel

driver model: add support for CPUs.

- Create struct cpu to generically describe cpus (it simply contains
  a struct sys_device in it).

- Define an array of size NR_CPUS in arch/i386/kernel/cpu/common.c 
  and register each on bootup. This gives us something like:

# tree -d /sys/root/sys/
/sys/root/sys/
|-- cpu0
|-- pic0
`-- rtc0

and:

# tree -d /sys/bus/system/devices/
/sys/bus/system/devices/
|-- cpu0 -> ../../../root/sys/cpu0

- Define arch-specific CPU driver that's also registered on boot.
  That gives us: 

# tree -d /sys/bus/system/drivers/
/sys/bus/system/drivers/
|-- cpu

- Create a CPU device class that's registered very early. That 
  gives us all the CPUs in the system in one place:

# tree -d /sys/class/cpu/
/sys/class/cpu/
|-- devices
|   `-- 0 -> ../../../root/sys/cpu0
`-- drivers

Other archs are encouraged to do the same.
parent 714279be
#include <linux/init.h>
#include <linux/string.h>
#include <linux/delay.h>
#include <linux/cpu.h>
#include <linux/smp.h>
#include <asm/semaphore.h>
#include <asm/processor.h>
......@@ -506,3 +507,37 @@ void __init cpu_init (void)
current->used_math = 0;
stts();
}
/*
* Bulk registration of the cpu devices with the system.
* Some of this stuff could possibly be moved into a shared
* location..
* Also, these devices should be integrated with other CPU data..
*/
static struct cpu cpu_devices[NR_CPUS];
static struct device_driver cpu_driver = {
.name = "cpu",
.bus = &system_bus_type,
.devclass = &cpu_devclass,
};
static int __init register_cpus(void)
{
int i;
driver_register(&cpu_driver);
for (i = 0; i < NR_CPUS; i++) {
struct sys_device * sysdev = &cpu_devices[i].sysdev;
sysdev->name = "cpu";
sysdev->id = i;
sysdev->dev.driver = &cpu_driver;
if (cpu_possible(i))
sys_device_register(sysdev);
}
return 0;
}
subsys_initcall(register_cpus);
# Makefile for the Linux device tree
obj-y := core.o sys.o interface.o power.o bus.o \
driver.o class.o intf.o platform.o
driver.o class.o intf.o platform.o \
cpu.o
obj-y += fs/
export-objs := core.o power.o sys.o bus.o driver.o \
class.o intf.o
class.o intf.o cpu.o
include $(TOPDIR)/Rules.make
/*
* cpu.c - basic cpu class support
*/
#include <linux/device.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/cpu.h>
static int cpu_add_device(struct device * dev)
{
return 0;
}
struct device_class cpu_devclass = {
.name = "cpu",
.add_device = cpu_add_device,
};
static int __init cpu_devclass_init(void)
{
return devclass_register(&cpu_devclass);
}
postcore_initcall(cpu_devclass_init);
EXPORT_SYMBOL(cpu_devclass);
/*
* cpu.h - generic cpu defition
*
* This is mainly for topological representation. We define the
* basic 'struct cpu' here, which can be embedded in per-arch
* definitions of processors.
*
* Basic handling of the devices is done in drivers/base/cpu.c
* and system devices are handled in drivers/base/sys.c.
*
* CPUs are exported via driverfs in the class/cpu/devices/
* directory.
*
* Per-cpu interfaces can be implemented using a struct device_interface.
* See the following for how to do this:
* - drivers/base/intf.c
* - Documentation/driver-model/interface.txt
*
*/
#include <linux/device.h>
extern struct device_class cpu_devclass;
struct cpu {
struct sys_device sysdev;
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment