Linux那些事兒之我是EHCI(3) pci match 和 probe

來源:互聯網
上載者:User

pci_bus_type 定義如下, 

struct bus_type pci_bus_type = ...{
    .name        = "pci",
    .match        = pci_bus_match,
    .uevent        = pci_uevent,
    .probe        = pci_device_probe,
    .remove        = pci_device_remove,
    .suspend    = pci_device_suspend,
    .suspend_late    = pci_device_suspend_late,
    .resume_early    = pci_device_resume_early,
    .resume        = pci_device_resume,
    .shutdown    = pci_device_shutdown,
    .dev_attrs    = pci_dev_attrs,
};static int pci_bus_match(struct device *dev, struct device_driver *drv)
...{
    struct pci_dev *pci_dev = to_pci_dev(dev);
    struct pci_driver *pci_drv = to_pci_driver(drv);
    const struct pci_device_id *found_id;

    found_id = pci_match_device(pci_drv, pci_dev);
    if (found_id)
        return 1;

    return 0;
}

總的來說,判斷一個裝置和驅動是否匹配,是看裝置的描述符是否和驅動所支援的一樣。pci_match_device()分別在driver->dynid,driver->id_table這兩個列表(由一系列的pci_device_id構成)裡面尋找。找到則返回這個裝置的pci_device_id。(不妨比較一下pci_bus_type->match 和 usb_bus_type->match)

struct pci_device_id ...{
    __u32 vendor, device;        /**//* Vendor and device ID or PCI_ANY_ID*/
    __u32 subvendor, subdevice;    /**//* Subsystem ID's or PCI_ANY_ID */
    __u32 class, class_mask;    /**//* (class,subclass,prog-if) triplet */
    kernel_ulong_t driver_data;    /**//* Data private to the driver */
};

注意,pci_device_id->driver_data指向了每個pci裝置驅動所特有的資料結構,比如ehci來說:.driver_data = (unsigned long) &ehci_pci_hc_driver。

另外就是,

static int pci_device_probe(struct device * dev)
...{
    int error = 0;
    struct pci_driver *drv;
    struct pci_dev *pci_dev;

    drv = to_pci_driver(dev->driver);
    pci_dev = to_pci_dev(dev);
    pci_dev_get(pci_dev);
    error = __pci_device_probe(drv, pci_dev);
    if (error)
        pci_dev_put(pci_dev);

    return error;
}

pci_device_probe() ---> __pci_device_probe() ---> pci_call_probe() ---> ( pci_driver->probe() )

而ehci_pci_driver->probe = usb_hcd_pci_probe()。像pci_device_probe的外包函數,就是一種物件導向的設計。不管怎樣,經曆了千辛萬苦,咱終於繞到usb了。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.