小结:
1、struct sys_device结构体是struct sysdev_class结构体的容器
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
函数列表:
int __devinit register_cpu(struct cpu *cpu, int num)
CPU注册
struct sys_device *get_cpu_sysdev(unsigned cpu)
//根据指定的cpu索引,返回该CPU中的系统设备(多核)
int __init cpu_dev_init(void)
注册系统设备类cpu_sysdev_class
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//声明一个系统设备类
struct sysdev_class cpu_sysdev_class = {
set_kset_name("cpu"), //设置kset名
};
static struct sys_device *cpu_sys_devices[NR_CPUS];
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//CPU注册
int __devinit register_cpu(struct cpu *cpu, int num)
{
int error;
cpu->node_id = cpu_to_node(num);
cpu->sysdev.id = num;
cpu->sysdev.cls = &cpu_sysdev_class;
//系统设备注册,实现在sys.c中
error = sysdev_register(&cpu->sysdev);
//空函数
if (!error && cpu->hotpluggable) register_cpu_control(cpu);
if (!error) cpu_sys_devices[num] = &cpu->sysdev;
if (!error) register_cpu_under_node(num, cpu_to_node(num));
return error;
}
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//根据指定的cpu索引,返回该CPU中的系统设备(多核)
struct sys_device *get_cpu_sysdev(unsigned cpu)
{
if (cpu < NR_CPUS) return cpu_sys_devices[cpu];
else return NULL;
}
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//cpu设备的初始化,实际就是注册系统设备类
int __init cpu_dev_init(void)
{
int err;
err = sysdev_class_register(&cpu_sysdev_class);
return err;
}