Device Driver's Probe Routine

本文详细解析了设备驱动中probe()函数的调用流程及参数来源,并以TCC UART设备驱动为例,阐述了从驱动注册到probe()函数被调用的具体过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

This post tries to answer two questions:

  • Who calls device driver’s probe() routine, and when?
  • Where is probe() parameter from?

  • Who calls device driver’s probe() routine, and when?

The story started from where the driver was registed.

TCC UART device driver (drivers/serial/tcc_serial.c), For example, its entry point defined like below:

        static int __init tcc_seril_modinit(void)
        {
            ...
            platform_driver_register(drv);
            ...
        }

        module_init(tcc_serial_moinit);

The function call stack thereafter is:
1. XXX_driver_register(drv)
2. driver_register(&drv->driver);
3. bus_add_driver(drv);
4. driver_attach(drv);
5. bus_for_each_dev(drv->bus, NULL, drv, __driver_attach);
6. __driver_attach(struct device *dev, void *data);
7. driver_probe_device(drv, dev);
8. really_probe(dev, drv)
{

ret = drv->probe(dev);

}

Now it’s clear that the driver’s register function eventually called
driver’s probe() routine.

And, the “__init” symbol denotes this happened on kernel start up.


  • Where is probe() parameter from?
    The XXX_driver_register() passes a single parameter, drv. In case of TCC serial driver, its type is struct platform_driver.However, the driver’s probe() routine get a parameter dev, which type is struct platform_device.

Go through above functions call stack, we have noticed that from step 1 to step 4, the parameter is struct platform_driver; from step 6 to step 8, there is at least one struct platform_device parameter.
The step 5, however, references member struct bus_type of the driver.
The bus found(match) the driver’s partnership, the device, and passes struct device to __driver_attach.

NOTE:
Registing device MUST be prior to the driver’s registration.

The camera module init routine, for example:
int __init camera_core_init(void)
{
    platform_device_register(&camera_core_device);
    platform_driver_register(&camera_core_driver);
    return 0;
}

In the case of TCC serial device driver, the dev parameter of probe() is exact the data passed to platform_device_register().
In arch/arm/mach-tcc8900/devices.c

platform_device_register(&tcc8900_uart0_device); 

static struct resource uart0_resources[] = {
/* PA -> VA */
    [0] = {
        .start  = 0xF0532000,
        .end    = 0xF05320FF,
        .flags  = IORESOURCE_MEM,
    },
    [1] = {
        .start  = INT_UART0,
        .end    = INT_UART0,
        .flags  = IORESOURCE_IRQ,
    },
};

static struct platform_device tcc8900_uart0_device = {
    .name           = "tcc8900-uart",
    .id             = 0,
    .resource       = uart0_resources,
    .num_resources  = ARRAY_SIZE(uart0_resources),
};  
appyorangedog@happyorangedog-Legion-Y9000P-IAX10:~/桌面$ dmesg | grep -i -E 'nvidia|pci|02:00.0' | tail -n 50 [19757.401402] nvidia-nvlink: Nvlink Core is being initialized, major device number 508 [19757.402388] nvidia 0000:02:00.0: vgaarb: changed VGA decodes: olddecodes=none,decodes=none:owns=none [19757.402416] NVRM: The NVIDIA GPU 0000:02:00.0 (PCI ID: 10de:2d59) NVRM: NVIDIA 470.256.02 driver release. NVRM: Please see 'Appendix A - Supported NVIDIA GPU Products' NVRM: specific graphics driver download page at www.nvidia.com. [19757.402472] nvidia: probe of 0000:02:00.0 failed with error -1 [19757.402492] NVRM: The NVIDIA probe routine failed for 1 device(s). [19757.402493] NVRM: None of the NVIDIA devices were initialized. [19757.403351] nvidia-nvlink: Unregistered the Nvlink Core, major device number 508 [19757.683000] nvidia-nvlink: Nvlink Core is being initialized, major device number 508 [19757.684018] nvidia 0000:02:00.0: vgaarb: changed VGA decodes: olddecodes=none,decodes=none:owns=none [19757.684044] NVRM: The NVIDIA GPU 0000:02:00.0 (PCI ID: 10de:2d59) NVRM: NVIDIA 470.256.02 driver release. NVRM: Please see 'Appendix A - Supported NVIDIA GPU Products' NVRM: specific graphics driver download page at www.nvidia.com. [19757.684094] nvidia: probe of 0000:02:00.0 failed with error -1 [19757.684112] NVRM: The NVIDIA probe routine failed for 1 device(s). [19757.684113] NVRM: None of the NVIDIA devices were initialized. [19757.684375] nvidia-nvlink: Unregistered the Nvlink Core, major device number 508 [19758.122468] nvidia-nvlink: Nvlink Core is being initialized, major device number 508 [19758.123418] nvidia 0000:02:00.0: vgaarb: changed VGA decodes: olddecodes=none,decodes=none:owns=none [19758.123445] NVRM: The NVIDIA GPU 0000:02:00.0 (PCI ID: 10de:2d59) NVRM: NVIDIA 470.256.02 driver release. NVRM: Please see 'Appendix A - Supported NVIDIA GPU Products' NVRM: specific graphics driver download page at www.nvidia.com. [19758.123501] nvidia: probe of 0000:02:00.0 failed with error -1 [19758.123521] NVRM: The NVIDIA probe routine failed for 1 device(s). [19758.123521] NVRM: None of the NVIDIA devices were initialized. [19758.123921] nvidia-nvlink: Unregistered the Nvlink Core, major device number 508 [19758.416138] nvidia-nvlink: Nvlink Core is being initialized, major device number 508 [19758.417011] nvidia 0000:02:00.0: vgaarb: changed VGA decodes: olddecodes=none,decodes=none:owns=none [19758.417035] NVRM: The NVIDIA GPU 0000:02:00.0 (PCI ID: 10de:2d59) NVRM: NVIDIA 470.256.02 driver release. NVRM: Please see 'Appendix A - Supported NVIDIA GPU Products' NVRM: specific graphics driver download page at www.nvidia.com. [19758.417085] nvidia: probe of 0000:02:00.0 failed with error -1 [19758.417102] NVRM: The NVIDIA probe routine failed for 1 device(s). [19758.417103] NVRM: None of the NVIDIA devices were initialized. [19758.418271] nvidia-nvlink: Unregistered the Nvlink Core, major device number 508 [19758.664889] nvidia-nvlink: Nvlink Core is being initialized, major device number 508 [19758.665906] nvidia 0000:02:00.0: vgaarb: changed VGA decodes: olddecodes=none,decodes=none:owns=none [19758.665935] NVRM: The NVIDIA GPU 0000:02:00.0 (PCI ID: 10de:2d59) NVRM: NVIDIA 470.256.02 driver release. NVRM: Please see 'Appendix A - Supported NVIDIA GPU Products' NVRM: specific graphics driver download page at www.nvidia.com. [19758.666002] nvidia: probe of 0000:02:00.0 failed with error -1 [19758.666025] NVRM: The NVIDIA probe routine failed for 1 device(s). [19758.666026] NVRM: None of the NVIDIA devices were initialized. [19758.666742] nvidia-nvlink: Unregistered the Nvlink Core, major device number 508
07-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值