gpt4 book ai didi

c - Linux PCI 驱动程序设置和拆卸

转载 作者:太空狗 更新时间:2023-10-29 16:56:37 24 4
gpt4 key购买 nike

查看内核文档后:https://www.kernel.org/doc/Documentation/PCI/pci.txt我不知道设置和拆除 PCI 驱动程序的函数调用顺序。

我有两个问题:

  1. 对于设置,pci_enable_device() 是否总是在前面pci_request_regions()?文档似乎指向了这一点事实上,但确实声明:

    OS BUG: we don't check resource allocations before enabling those resources. The sequence would make more sense if we called pci_request_resources() before calling pci_enable_device(). Currently, the device drivers can't detect the bug when when two devices have been allocated the same range. This is not a common problem and unlikely to get fixed soon. This has been discussed before but not changed as of 2.6.19: http://lkml.org/lkml/2006/3/2/194

    然而,在快速浏览了几个源代码之后驱动程序,共识是 pci_enable_device() 总是来第一的。这些电话中的哪一个应该先到,为什么?

  2. 为了拆掉驱动,我更糊涂了。假设 pci_enable_device() 先出现,我希望您在调用 pci_disable_device() 之前先调用 pci_release_regions()(即遵循一些对称性).然而,内核文档说 pci_release_regions() 应该放在最后。让事情变得更复杂的是,我查看了许多驱动程序,几乎所有驱动程序都在 pci_disable_device() 之前有 pci_release_regions(),正如我所期望的那样。然而,我偶然发现了这个驱动程序:https://elixir.bootlin.com/linux/v4.12/source/drivers/infiniband/hw/hfi1/pcie.c (代码转载如下)。

    void hfi1_pcie_cleanup(struct pci_dev *pdev)
    {
    pci_disable_device(pdev);
    /*
    * Release regions should be called after the disable. OK to
    * call if request regions has not been called or failed.
    */
    pci_release_regions(pdev);
    }

    拆卸驱动程序时应该首先使用哪个功能?似乎内核中的驱动程序本身不能同意。

最佳答案

最后声明如下:

o wake up the device if it was in suspended state,

o allocate I/O and memory regions of the device (if BIOS did not),

o allocate an IRQ (if BIOS did not).

因此,如果没有资源,要求内核保留资源是没有意义的。在大多数情况下,当我们不需要分配资源时,因为它已由 bios 完成,在这些情况下,我们可以先保留其中一个功能,但只有在您完全确定时才这样做。

关于c - Linux PCI 驱动程序设置和拆卸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51163832/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com