Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

系统启动时在bus系统中注册platform总线 #11

Open
TongxinV opened this issue Feb 3, 2017 · 0 comments
Open

系统启动时在bus系统中注册platform总线 #11

TongxinV opened this issue Feb 3, 2017 · 0 comments

Comments

@TongxinV
Copy link
Owner

TongxinV commented Feb 3, 2017

系统启动时在bus系统中注册platform总线

platform总线的注册是由platform_bus_init函数完成的,主要的内容是注册bus_type结构体类型的变量

Linux设备模型--设备驱动模型和sysfs文件系统解读http://www.cnblogs.com/Ph-one/p/5052191.html

该函数在内核启动阶段被调用,简单看下调用过程:

start_kernel()->rest_init()->kernel_init()->do_basic_setup()->driver_init()->platform_bus_init()

注:kernel_init()是在rest_init函数中创建内核线程来执行的
    源代码:kernel_thread(kernel_init, NULL, CLONE_FS | CLONE_SIGHAND);

platform_bus_init

blog012

bus_register

blog013

函数中,首先调用kobject_set_name设置了bus对象的subsys.kobject->name 为 platform,也就是说会建立一个名为platform的目录

在这里还用到了bus_kset这个变量,这个变量就是在buses_init函数中建立bus目录所对应的kset对象

接着,priv->subsys.kobj.kset = bus_kset,设置subsys的kobj在bus_kset对象包含的集合中,也就是说bus目录下将包含subsys对象所对应的目录,即platform

紧接着调用了kset_register,参数为&priv->subsys。该函数在......在该函数的调用过程中,将调用kobj_kset_join函数,该函数将kojbect添加到kobject->kset结构(也就是他的上一级目录bus)中的链表当中

kset_register函数执行完成后,将在/sys/bus/下建立目录platform。此刻,我们先来看下kset和kobject之间的关系

p.2

然后,调用了bus_create_file函数在/sys/bus/platform/下建立文件uevent

接着调用了2次kset_create_and_add,分别在/sys/bus/platform/下建立了文件夹devicesdrivers

这里和我们之前讲/sys下创建bus目录时用到的kset_create_and_add时的最主要一个区别就是:

此时的parent参数不为NULL,而是&priv->subsys.kobj

也就是说,将要创建的kset的kobject->parent = &priv->subsys.kobj,也即新建的kset被包含在platform文件夹对应的kset中

p.3

随后,调用了add_probe_files创建了属性文件drivers_autoprobedrivers_probe

好了,整个bus_register调用完成了,我们来看下sysfs中实际的情况

[root@yj423 platform]#pwd
/sys/bus/platform
[root@yj423 platform]#ls
devices            drivers            drivers_autoprobe  drivers_probe      uevent

最后,我们对整个bus_register的过程进行一个小结:

p.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant