目录
三、int __init platform_bus_init(void) 函数分析
这里只是做一个流程的分析,太复杂了,没怎么看懂 ......T_T
看这里一定要跟踪内核源码来看,不然更加不知道讲的什么鬼....
以下的代码都是基于某个项目 Android源码下的代码进行摘取的,某些结构体与原生的内核源码可能不一致,但只是名字有略微的变化,内容还是一样的。
一、重要结构体
打开源码,看到一堆结构体,真是头大。。。。
想了想还是按照自己的思路来理解吧,假设让你来设计这个平台总线的模型,你会怎么设计?
1.1 总线是怎么定义的?
平台总线是一种模型,既然是模型,肯定得对它进行抽象。那么必定有一个结构体用来表述它(C++ JAVA中用类来抽象一个对象,C语言中就是通过结构体来抽象的)。另外,平台总线是总线的一种,它肯定会继承总线的特性,所以我们得先看看总线是怎么定义的。
linux 中总线是用结构体 bus_type 描述的,一般定义在kernel-3.18\drivers\base\device.h
/**
* struct subsys_private - structure to hold the private to the driver core portions of the bus_type/class structure.
*
* @subsys - the struct kset that defines this subsystem
* @devices_kset - the subsystem's 'devices' directory
* @interfaces - list of subsystem interfaces associated
* @mutex - protect the devices, and interfaces lists.
*
* @drivers_kset - the list of drivers associated
* @klist_devices - the klist to iterate over the @devices_kset
* @klist_drivers - the klist to iterate over the @drivers_kset
* @bus_notifier - the bus notifier list for anything that cares about things
* on this bus.
* @bus - pointer back to the struct bus_type that this structure is associated
* with.
*
* @glue_dirs - "glue" directory to put in-between the parent device to
* avoid namespace conflicts
* @class - pointer back to the struct class that this structure is associated
* with.
*
* This structure is the one that is the actual kobject allowing struct
* bus_type/class to be statically allocated safely. Nothing outside of the
* driver core should ever touch these fields.
*/
struct subsys_private {
struct kset subsys;
struct kset *devices_kset; //sys/bus/platform/devices 目录
struct list_head interfaces;
struct mutex mutex;
struct kset *drivers_kset; //sys/bus/platform/drivers 目录
struct klist klist_devices; //device 链表
struct klist klist_drivers; //driver 链表
struct blocking_notifier_head bus_notifier;
unsigned int drivers_autoprobe:1;
struct bus_type *bus; //总线类型
struct kset glue_dirs;
struct class *class;
};
/**
* struct bus_type - The bus type of the device
*
* @name: The name of the bus.
* @dev_name: Used for subsystems to enumerate devices like ("foo%u", dev->id).
* @dev_root: Default device to us