概述
linux的emmc驱动在driversmmccardblock.c,其mmc_dirver结构体如下:
根据以往平台总线驱动模型的经验来看的话,内核里应该有mmc_devices结构体,并且
其name也为"mmcblk",这样其probe函数将被调用,但是搜索整个内核文件并没有发现mmc_devices。
现在我们分析一下mmc_blk_probe什么时候被调用。
static int __init mmc_blk_init(void) //driversmmccardblock.c
{
res = mmc_register_driver(&mmc_driver); //注册mmc_driver
}
int mmc_register_driver(struct mmc_driver *drv) //driversmmccorebus.c
{
drv->drv.bus = &mmc_bus_type; //mmc设备是挂载在mmc总线上的
return driver_register(&drv->drv); //注册mmc驱动
}
int driver_register(struct device_driver *drv) //driversbasedriver.c
{
other = driver_find(drv->name, drv->bus); //在总线上查找是否已经注册过此驱动
if (other) {
put_driver(other);
printk(KERN_ERR "Error: Driver '%s' is already registered, "
"aborting...n", drv->name);
return -EBUSY;
}
ret = bus_add_driver(drv); //如果没有注册过,则注册此驱动
}
int bus_add_driver(struct device_driver *drv) //driversbasebus.c
{
error = driver_attach(drv);
error = driver_create_file(drv, &driver_attr_uevent);
}
//try to bind driver to devices
int driver_attach(struct device_driver *drv) //drivers/base/dd.c
{
return bus_for_each_dev(drv->bus, NULL, drv, __driver_attach);
//__driver_attach的里面device的查找还没搞清楚
}
static int __driver_attach(struct device *dev, void *data) //drivers/base/dd.c
{
if (!driver_match_device(drv, dev))
return 0;
driver_probe_device(drv, dev);
}
static inline int driver_match_device(struct device_driver *drv, //drivers/base/base.h
struct device *dev)
{
//这里调用了mmc总线的match函数
return drv->bus->match ? drv->bus->match(dev, drv) : 1;
}
static int mmc_bus_match(struct device *dev, struct device_driver *drv) //driversmmccorebus.c
{
//mmc总线的match直接返回了1
return 1;
}
int driver_probe_device(struct device_driver *drv, struct device *dev) //drivers/base/dd.c
{
really_probe(dev, drv);
}
static int really_probe(struct device *dev, struct device_driver *drv) //drivers/base/dd.c
{
dev->bus->probe(dev); //这里调用总线的probe函数
}
static int mmc_bus_probe(struct device *dev) //driversmmccorebus.c
{
return drv->probe(card); //最终mmc总线的probe函数调用mmc_driver的probe函数
}
最后
以上就是彪壮小兔子为你收集整理的linux mmc设备挂载流程解析的全部内容,希望文章能够帮你解决linux mmc设备挂载流程解析所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复