平台总线初始化流程
start_kernel
rest_init
kernel_thread(kernel_init, NULL, CLONE_FS | CLONE_SIGHAND);//调用kernel_thread函数启动内核进程kernel_init
do_basic_setup
driver_init
platform_bus_initint __init platform_bus_init(void) { int error; early_platform_cleanup(); //清除platform设备链表 //该函数把设备名为platform 的设备platform_bus注册到系统中,其他的platform的设备都会以它为parent。它在sysfs中目录下.即 /sys/devices/platform。 //platform_bus总线也是设备,所以也要进行设备的注册 error = device_register(&platform_bus);//将平台bus作为一个设备注册,出现在sys文件系统的device目录 if (error) return error; //默认platform_bus_type中没有定义probe函数。 error = bus_register(&platform_bus_type);//注册平台类型的bus,将出现sys文件系统在bus目录下,创建一个platform的目录,以及相关属性文件 if (error) device_unregister(&platform_bus); return error; }
struct device platform_bus = { .init_name = "platform", };
struct bus_type platform_bus_type = { .name = "platform", .dev_attrs = platform_dev_attrs, .match = platform_match, .uevent = platform_uevent, .pm = &platform_dev_pm_ops, };
系统启动时初始化时创建了platform_bus总线设备和platform_bus_type总线,platform总线是在内核初始化的时候就注册进了内核。
include/linux/platform_device.h
struct platform_device { const char * name; // 平台总线下设备的名字 int id; struct device dev; // 所有设备通用的属性部分 u32 num_resources; // 设备使用到的resource的个数 struct resource * resource; // 设备使用到的资源数组的首地址 const struct platform_device_id *id_entry; // 设备ID表 /* arch specific additions */ struct pdev_archdata archdata; // 自留地,用来