LDD 3 PCI Ant 1 5 PCI bus
LDD 3 PCI Ant 實驗室 1
5 PCI裝置編號 匯流排(bus number) 8 bits 2^8 至多可連接 256 個匯流排(0 to ff), 裝置(device number) 5 bits 2^5 至多可接 32 種 裝置(0 to 1 f) 以及 功能(function number) 3 bits 2^3 至多每種裝置 可有 8 項功能(0 to 7).
6 PCI Lspci cat /proc/bus/pci/devices tree /sys/bus/pci/devices/
7 PCI 內容 tree /sys/bus/pci/devices/XXXX
10 註冊PCI驅動(1) const char *name; 驅動的名子 (必需) const struct pci_device_id *id_table; 指向 struct pci_device_id 表的指標
11 註冊PCI驅動(2) int (*probe) (struct pci_dev *dev, const struct pci_device_id *id); 此指標指向PCI驅動中的探測函式 void (*remove) (struct pci_dev *dev) 此指標指向PCI驅動中的移除函式
12 註冊PCI驅動(3) int (*suspend) (struct pci_dev *dev, u 32 state); 此指標指向暫停函式 int (*resume) (struct pci_dev *dev); 此指標指向恢復函式
13 註冊PCI驅動(4) 要創造PCI的結構只需要初始以下四個欄位 static struct pci_driver = {. name = "pci_skel", . id_table = ids, . probe = probe, . remove = remove, };
14 註冊PCI驅動(5) static int __init pci_skel_init(void) { return pci_register_driver(&pci_driver); }
15 註冊PCI驅動(6) static void __exit pci_skel_exit(void) { pci_unregister_driver(&pci_driver); }
17 舊式的PCI探測法(2) struct pci_dev *pci_get_device(unsigned int vendor, unsigned int device, struct pci_dev *from); struct pci_dev *dev; dev = pci_get_device(PCI_VENDOR_FOO, PCI_DEVICE_FOO, NULL); if (dev) { /* Use the PCI device */. . . pci_dev_put(dev); }
18 舊式的PCI探測法(3) struct pci_dev *pci_get_subsys(unsigned int vendor, unsigned int device, unsigned int ss_vendor, unsigned int ss_device, struct pci_dev *from);
19 舊式的PCI探測法(4) struct pci_dev *pci_get_slot(struct pci_bus *bus, unsigned int devfn);
20 啟用 PCI int pci_enable_device(struct pci_dev *dev);
21 存取配置空間(1) int pci_read_config_byte(struct pci_dev *dev, int where, u 8 *val); int pci_read_config_word(struct pci_dev *dev, int where, u 16 *val); int pci_read_config_dword(struct pci_dev *dev, int where, u 32 *val);
22 存取配置空間(2) int pci_write_config_byte(struct pci_dev *dev, int where, u 8 val); int pci_write_config_word(struct pci_dev *dev, int where, u 16 val); int pci_write_config_dword(struct pci_dev *dev, int where, u 32 val);
23 存取配置空間(3) int pci_bus_read_config_byte (struct pci_bus *bus, unsigned int devfn, int where, u 8 *val); int pci_bus_read_config_word (struct pci_bus *bus, unsigned int devfn, int where, u 16 *val); int pci_bus_read_config_dword (struct pci_bus *bus, unsigned int devfn, int where, u 32 *val);
24 存取配置空間(4) int pci_bus_write_config_byte (struct pci_bus *bus, unsigned int devfn, int where, u 8 val); int pci_bus_write_config_word (struct pci_bus *bus, unsigned int devfn, int where, u 16 val); int pci_bus_write_config_dword (struct pci_bus *bus, unsigned int devfn, int where, u 32 val);
25 PCI 記憶體 unsigned long pci_resource_start(struct pci_dev *dev, int bar); unsigned long pci_resource_end(struct pci_dev *dev, int bar); unsigned long pci_resource_flags(struct pci_dev *dev, int bar);
26 PCI 中斷 result = pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &myirq); if (result) { /* deal with error */ }
27 DEMO Lspci cat /proc/bus/pci/devices tree /sys/bus/pci/devices/XXXX
- Slides: 27