目录

​​1.mmc驱动结构体定义​​

​​2.mmc总线结构体定义​​

​​3.代码流程​​


1.mmc驱动结构体定义

static struct mmc_driver mmc_driver = {
.drv = {
.name = "mmcblk",
.pm = &mmc_blk_pm_ops,
},
.probe = mmc_blk_probe,
.remove = mmc_blk_remove,
.shutdown = mmc_blk_shutdown,
};

见下mmc_blk_probe的执行流程。

2.mmc总线结构体定义

static struct bus_type mmc_bus_type = {
.name = "mmc",
.dev_groups = mmc_dev_groups,
.match = mmc_bus_match,
.uevent = mmc_bus_uevent,
.probe = mmc_bus_probe,
.remove = mmc_bus_remove,
.shutdown = mmc_bus_shutdown,
.pm = &mmc_bus_pm_ops,
};

在mmc总线上进行驱动和设备的匹配,匹配成功调用mmc_bus_probe。

3.代码流程

module_init(mmc_blk_init)
mmc_blk_init //drivers\mmc\core\block.c
mmc_register_driver(&mmc_driver) //mmc驱动名称为mmcblk
drv->drv.bus = &mmc_bus_type //绑定到mmc总线
driver_register(&drv->drv) //驱动注册

//上面的驱动mmcblk与设备在总线mmc上匹配,将执行下面的函数

mmc_blk_probe
mmc_blk_alloc
mmc_blk_alloc_req
mmc_init_queue //drivers\mmc\core\queue.c
mq->queue = blk_mq_init_queue(&mq->tag_set);
blk_mq_init_queue
blk_mq_init_queue_data
blk_mq_init_allocated_queue
blk_mq_realloc_hw_ctxs
blk_mq_alloc_and_init_hctx
->blk_mq_alloc_hctx
->blk_mq_run_work_fn
->__blk_mq_run_hw_queue
->blk_mq_sched_dispatch_requests
->blk_mq_run_hw_queue

mmc_blk_alloc_parts
mmc_blk_alloc_req/mmc_blk_alloc_rpmb_part
mmc_init_queue //drivers\mmc\core\queue.c
mq->queue = blk_mq_init_queue(&mq->tag_set);
blk_mq_init_queue
blk_mq_init_queue_data
blk_mq_init_allocated_queue
blk_mq_realloc_hw_ctxs
blk_mq_alloc_and_init_hctx
->blk_mq_alloc_hctx
->blk_mq_run_work_fn
->__blk_mq_run_hw_queue
->blk_mq_sched_dispatch_requests
->blk_mq_run_hw_queue
INIT_DELAYED_WORK(&hctx->run_work, blk_mq_run_work_fn);

INIT_DELAYED_WORK(&hctx->run_work, blk_mq_run_work_fn);