Linux的下平台总线之二平台总线的注册

本文详细分析了Linux内核中平台总线的注册过程,从结构体定义到`platform_bus_init`函数的执行步骤。重点讨论了`bus_type`结构体,包括`match`、`probe`和`remove`等关键方法,并探讨了`device_register(&platform_bus)`的含义以及在Android系统启动过程中的作用。文章指出平台总线的注册涉及目录结构创建、驱动探测和设备列表的建立。
摘要由CSDN通过智能技术生成

目录

一、重要结构体

1.1 总线是怎么定义的?

1.2 平台总线是怎么定义的?

二、平台总线是什么时候注册的?

三、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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值