0

in linux kernel 3.3, the drivers/mmc/host/dw-mmc.c file had this part.

static int __init dw_mci_init(void)
{
    return platform_driver_probe(&dw_mci_driver, dw_mci_probe);
}

static void __exit dw_mci_exit(void)
{
    platform_driver_unregister(&dw_mci_driver);
}

module_init(dw_mci_init);
module_exit(dw_mci_exit);

at some point during the kernel booting (actually in start_kernel(), in init_call loop), the dw_mci_init is called(because it's with __init tag) and the probe function probes the device and installs the driver. Some years ago I have modified this driver to implement our own SD card controller driver.

Now, when I look at linux kernel 5.4.21, above part of the same file has changed like this :

static int __init dw_mci_init(void)
{
    pr_info("Synopsys Designware Multimedia Card Interface Driver\n");
    return 0;
}

static void __exit dw_mci_exit(void)
{
}

module_init(dw_mci_init);
module_exit(dw_mci_exit);

The driver init function does nothing but a print. What happened? I guess somewhere in the kernel initialization, the kernel parses the "device tree" (flattend device tree, .dtb file) and the matching platform drivers are found and called to initialize the deivce and driver. Is this correct? and if so, where in the kernel source can I find the device tree (flattend device tree) parsing and device driver installation operation?

Chan Kim
  • 5,177
  • 12
  • 57
  • 112

1 Answers1

1

What happened?

The driver has been split into separate modules to handle devices from different bus types. The platform driver is in the "dw_mmc-pltfrm" module. (This also handles devices configured by device tree nodes.) There is also a PCI driver in the "dw_mmc-pci" module. The old "dw_mmc" module exports functions in common to the bus type-specific driver modules.

In "dw_mmc-pltfrm.c", the module init and exit functions are defined by the helper macro call:

module_platform_driver(dw_mci_pltfm_driver);
Ian Abbott
  • 15,083
  • 19
  • 33
  • thanks, I searched start_kernel() but couldn't find where it initializes the driver (location of init calls in ver 5.4) Can you elaborate a little more on how module_platform_driver() or builtin_platform_driver are used during initialization? – Chan Kim Nov 19 '20 at 12:18
  • ah, I found start_kernel-> arch_call_rest_init -> rest_init -> kernel_init(a kernel_thread) -> kernet_init_freeable -> basic_setup -> do_initcalls. Is this where drivers with builtin_platform_driver macro called? (maybe not it seems for drivers with device_initcall macro..placed in the init.. sections..) I don't know where the drivers with builtin_platform_driver macro are called. – Chan Kim Nov 19 '20 at 12:37
  • I did my homework : From https://www.programmersought.com/article/22512423913/ and https://stackoverflow.com/questions/18605653/module-init-vs-core-initcall-vs-early-initcall I found module_platform_driver is just module_init, which is just device_initcall that gets called during the later part of do_initcalls. Thanks! – Chan Kim Nov 19 '20 at 13:36