Documentation/translations/zh_CN/PCI/pci.rst
Source file repositories/reference/linux-study-clean/Documentation/translations/zh_CN/PCI/pci.rst
File Facts
- System
- Linux kernel
- Corpus path
Documentation/translations/zh_CN/PCI/pci.rst- Extension
.rst- Size
- 22457 bytes
- Lines
- 515
- Domain
- Support Tooling And Documentation
- Bucket
- Documentation
- Inferred role
- Support Tooling And Documentation: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
描述驱动程序的结构体的指针( ``struct pci_driver`` ):
该API在以下内核代码中:
include/linux/pci.h
pci_driver
ID表是一个由 ``struct pci_device_id`` 结构体成员组成的数组,以一个全零的成员
结束。一般来说,带有静态常数的定义是首选。
该API在以下内核代码中:
include/linux/mod_devicetable.h
pci_device_id
大多数驱动程序只需要 ``PCI_DEVICE()`` 或 ``PCI_DEVICE_CLASS()`` 来设置一个
pci_device_id表。
新的 ``PCI ID`` 可以在运行时被添加到设备驱动的 ``pci_ids`` 表中,如下所示::
echo "vendor device subvendor subdevice class class_mask driver_data" > \
/sys/bus/pci/drivers/{driver}/new_id
所有字段都以十六进制值传递(没有前置0x)。供应商和设备字段是强制性的,其他字段是可
选的。用户只需要传递必要的可选字段:
- subvendor和subdevice字段默认为PCI_ANY_ID (FFFFFFF)。
- class和classmask字段默认为0
- driver_data默认为0UL。
- override_only字段默认为0。
请注意, ``driver_data`` 必须与驱动程序中定义的任何一个 ``pci_device_id`` 条
目所使用的值相匹配。如果所有的 ``pci_device_id`` 成员都有一个非零的driver_data
值,这使得driver_data字段是强制性的。
一旦添加,驱动程序探测程序将被调用,以探测其(新更新的) ``pci_ids`` 列表中列出的
任何无人认领的PCI设备。
当驱动退出时,它只是调用 ``pci_unregister_driver()`` ,PCI层会自动调用驱动处理
的所有设备的移除钩子。
驱动程序功能/数据的“属性”
-------------------------
请在适当的地方标记初始化和清理函数(相应的宏在<linux/init.h>中定义):
====== ==============================================
__init 初始化代码。在驱动程序初始化后被抛弃。
__exit 退出代码。对于非模块化的驱动程序来说是忽略的。
====== ==============================================
关于何时/何地使用上述属性的提示:
- module_init()/module_exit()函数(以及所有仅由这些函数调用的初始化函数)应该被标记
- 为__init/__exit。
- 不要标记pci_driver结构体。
- 如果你不确定应该使用哪种标记,请不要标记一个函数。不标记函数比标记错误的函数更好。
如何手动搜索PCI设备
===================
PCI驱动最好有一个非常好的理由不使用 ``pci_register_driver()`` 接口来搜索PCI设备。
PCI设备被多个驱动程序控制的主要原因是一个PCI设备实现了几个不同的HW服务。例如,组合的
串行/并行端口/软盘控制器。
Annotation
- Atlas domain: Support Tooling And Documentation / Documentation.
- Implementation status: pattern implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.