Ch 15 Overview of Peripheral Buses Outline The
Ch 15 - Overview of Peripheral Buses
Outline • The PCI interface • A Look back:ISA • Other PC Buses – PC/104 and PC/104+ – SBus – Nu. Bus – External Buses • Backward Compatibility
PCI 定址法 • 查看系統上有哪些PCI裝置時: – lspci ( 在pciutils套件裡 ) 00: 00. 0 Host bridge 00: 01. 0 PCI bridge 00: 05. 0 Ethernet controller 00: 07. 0 ISA bridge 00: 07. 1 IDE interface 00: 07. 2 USB Controller 00: 07. 4 ISA bridge 00: 07. 5 Multimedia audio controller 00: 07. 6 Communication controller 00: 0 a. 0 Card. Bus bridge 01: 00. 0 VGA compatible controller – “BB: DD: F”就是識別碼的三個欄位 – cat /proc/bus/pci/devices | cut –f 1, 3 |sort
組態暫存器與初始化 • • • #include <linux/config. h> CONFIG_PCI #include <linux/pci. h> int pci_present(void); struct pci_dev *pci_find_device (unsigned int vendor, unsigned int device, const struct pci_dev *from); • struct pci_dev *pci_find_class (unsigned int class, const struct pci_dev *from); • int pci_enable_device(struct pci_dev *dev); • struct pci_dev *pci_find_slot (unsigned int bus, unsigned int devfn);
組態暫存器與初始化 #ifndef CONFIG_PCI # error "This driver needs PCI support to be available" #endif int jail_find_all_devices(void) { struct pci_dev *dev = NULL; int found; if (!pci_present()) return -ENODEV; for (found=0; found < JAIL_MAX_DEV; ) { dev = pci_find_device(JAIL_VENDOR, JAIL_ID, dev); if (!dev) /* no more devices are there */ break; /* do device-specific actions and count the device */ found += jail_init_one(dev); } return (index == 0) ? -ENODEV : 0; }
存取組態空間 • 順利偵測出裝置之後,驅動程式還需要能夠讀寫 裝置的三種位址空間:記憶體、I/O埠、組態空間。 • Linux核心對驅動程式提供了8, 16, 32 -bits三種資料 傳輸模式來存取組態空間。<linux/pci. h> 讀取: int pci_read_config_byte(struct pci_dev *dev, int where, u 8 *ptr); int pci_read_config_word(struct pci_dev *dev, int where, u 16 *ptr); int pci_read_config_dword(struct pci_dev *dev, int where, u 32 *ptr); 寫入: 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);
Linux 2. 4的PCI I/O資源 • Linux 2. 4,PCI裝置的I/O區域已經被整合進”通用 資源管理”,因此若想知道裝置的記憶空間或I/O 空間是映射到何處,可以利用下列函式來取得區 域的對應關係: 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); IORESOURCE_IO IORESOURCE_MEM IORESOURCE_PREFETCH IORESOURCE_READONLY • 只要利用這些函式,驅動程式其實可以完全不理 會實際的PCI暫存器,因為系統已經幫你解讀…
PCI 中斷 • PCI的中斷很容易處理,在啟動Linux時,電腦的 韌體就已經分配好各裝置的IRQ號碼,所以驅動程 式只要照用即可。 • Configuration register 60:PCI_INTERRUPT_LINE • Configuration register 61︰PCI_INTERRUPT_PINE • 第九章介紹的中斷號碼探測技術也可以用在PCI裝 置上,只不過可以直接從PCI_INTERRUPT_LINE 讀取中斷號碼,然後存在適當的變數裡即可,如 下: result = pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &myirq); if (result) { /* deal with error */ }
其他PC匯流排 • • ISA PC/104與PC/104+ MCA (Micro Channel Architecture) EISA (Extended ISA) VLB (VESA Local Bus) SBus Nu. Bus 外接式匯流排(USB)
USB • OHCI:採用Memory存取方式 (CPU使用I/O指令 來存取USB Controller) • UHCI:採用I/O-mapped存取方式 (CPU使用記憶 體指令來存取USB Controller) • EHCI:USB 2. 0 • cat /proc/pci
- Slides: 25