PCI DEVICE DRIVER 
1
什麼是PCI (Peripheral Component Interconnect) 
它是一種電腦的硬體bus 
可以讓多個週邊在上面運行,主要是給電 
腦擴充週邊用的 
它有分host端和client端,一個host可以接多 
個client (最多可達32個) 
可以經由PCI bridge串接更多的PCI client 
它的速度有33M 和66M兩種 
I/O為32bits,而記憶體可32或64b its 
2
3 
PCI System
4 
PCI Pin
5 
PCI 設定表
6 
Base address設定方式
7 
PCI啓動流程 
PCI Host 控制器 
初始化,並將 
可分配的資源 
設定好 
PCI Host開始掃 
描看看Bus上有 
多少個PCI Client 
元件 
針對每一個PCI 
Client元件給予分 
配可用資源 
尋找PCI Client是否有登 
記PCI probe callback, 
若有就給予呼叫(依據 
vendor & device ID)
8 
PCI Host Driver 
宣告一個struct 
hw_pci的資料 
結構 
呼叫 
pci_common_i 
nit() 
系統呼叫註冊的 
preinit callback 
function初始該PCI 
Host元件 
系統呼叫setup 
callback function 
設定PCI Host可 
分配的資源 
系統呼叫scan 
callback function 
並準備好struct 
pci_ops並開始掃 
描PCI client元件 
啓動PCI 
client元 
件
struct hw_pci 範例mach-ixp4xx/ixdp425-pci.c 
struct hw_pci ixdp425_pci __initdata = { 
.nr_controllers = 1, 
.preinit = ixdp425_pci_preinit, 
.swizzle = pci_std_swizzle, 
.setup = ixp4xx_setup, 
.scan = ixp4xx_scan_bus, 
.map_irq = ixdp425_map_irq, 
}; 
9 
int __init ixdp425_pci_init(void) 
{ 
if (machine_is_ixdp425() || machine_is_ixcdp1100() || 
machine_is_ixdp465() || machine_is_kixrp435()) 
pci_common_init(&ixdp425_pci); 
return 0; 
} 
subsys_initcall(ixdp425_pci_init);
保留系統所有PCI的資源 
在setup callback function中作保留的動作 
1) arch/arm/mach-ixp4xx/common-pci.c 
int ixp4xx_setup(int nr, struct pci_sys_data *sys) { 
struct resource *res; 
res[0].name = "PCI I/O Space"; 
res[0].start = 0x00000000; 
res[0].end = 0x0000ffff; 
res[0].flags = IORESOURCE_IO; 
res[1].name = "PCI Memory Space"; 
res[1].start = PCIBIOS_MIN_MEM; 
res[1].end = 0x4bffffff; 
res[1].flags = IORESOURCE_MEM; 
request_resource(&ioport_resource, &res[0]); 
request_resource(&iomem_resource, &res[1]); 
sys->resource[0] = &res[0]; 
sys->resource[1] = &res[1]; 
sys->resource[2] = NULL; 
return 1; 
} 
10
struct pci_ops 範例 
static struct pci_ops ftpci_ops = { 
.read = ftpci_read_config, 
.write = ftpci_write_config, 
}; 
其操作是給PCI Client Driver在讀PCI table時 
所使用的基本API (HAL) 
系統呼叫scan_bus call back function 中會呼 
叫pci_scan_bus(sys->busnr, &ixp4xx_ops, sys); 
時給予註冊(arch/arm/mach-ixp4xx/common-pci. 
c) 11
12 
PCI Host分配資源流程 
PCI Host 
Scan Device 
Read device 
configuration 
table to get 
requests 
Assign 
resources to 
device on 
configuration 
table 
比對Vendor ID & 
Device ID 確認是 
否有任何PCI 
Device Driver 登 
錄 
呼叫己登 
錄的probe 
callback 
function
static struct pci_driver rtl8139_pci_driver = { 
.name = DRV_NAME, 
.id_table = rtl8139_pci_tbl, 
.probe = rtl8139_init_one, 
.remove = __devexit_p(rtl8139_remove_one), 
#ifdef CONFIG_PM 
.suspend = rtl8139_suspend, 
.resume = rtl8139_resume, 
#endif /* CONFIG_PM */ 
}; 
static int __init rtl8139_init_module (void) 
{ 
/* when we're a module, we always print a version message, 
* even if no 8139 board is found. 
*/ 
#ifdef MODULE 
pr_info(RTL8139_DRIVER_NAME "n"); 
#endif 
return pci_register_driver(&rtl8139_pci_driver); 
} 
13 
PCI Client Driver
struct pci_device_id範例 
static struct pci_device_id rtl8139_pci_tbl[] = { 
{0x10ec, 0x8139, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RTL8139 }, 
{0x10ec, 0x8138, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RTL8139 }, 
{0x1113, 0x1211, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RTL8139 }, 
{0x1500, 0x1360, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RTL8139 }, 
{0x4033, 0x1360, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RTL8139 }, 
{0x1186, 0x1300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RTL8139 }, 
{0x1186, 0x1340, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RTL8139 }, 
{0} 
}; 
14
PCI Client如何取得被分配的資源 
pci_enable_device (pdev); 
pio_start = pci_resource_start (pdev, 0); 
pio_end = pci_resource_end (pdev, 0); 
pio_flags = pci_resource_flags (pdev, 0); 
pio_len = pci_resource_len (pdev, 0); 
mmio_start = pci_resource_start (pdev, 1); 
mmio_end = pci_resource_end (pdev, 1); 
mmio_flags = pci_resource_flags (pdev, 1); 
mmio_len = pci_resource_len (pdev, 1); 
15
PCI Bus有分I/O及memory access,而ARM只 
有memory access,所以在assign I/O 
resource 時要小心 
有的PCI controller需要改寫outb/inb & 
readb/writeb HAL API (arch/io.h) 
16 
注意事項 
CPU 
PCI Host 
Controller 
PCI Client 
Device 
Local 
Bus 
PCI 
Bus
17 
PCI Host Controller I 
CPU 
PCI Host 
Controller 
PCI 
Device 
I/O Access 
Memory Access 
Local 
Bus 
Local 
Bus 
PCI 
Bus 
PCI 
Bus
18 
PCI Host Controller II 
CPU 
PCI Host 
Controller 
PCI 
Device 
I/O Access 
Memory Access 
I/O 
CMD 
Mem 
CMD 
PCI 
Bus 
PCI 
Bus
PCI Host Controller II porting 
在mach-xxx/include/mach目錄之下建主一個 
檔案io.h 
若需redirect PCI access則不要宣告以下 
1) #define _ _mem_pci(a) (a) 
2) #define _ _io(v) _ _typesafe_io(v) 
Examples 
1) mach-ixp4xx/include/mach/io.h 
19

More Related Content

PDF
Arm device tree and linux device drivers
PDF
I2C Subsystem In Linux-2.6.24
PDF
Spi drivers
PPTX
Linux MMAP & Ioremap introduction
PDF
I2c drivers
PPTX
Linux Initialization Process (2)
PPTX
Linux Kernel Booting Process (1) - For NLKB
PPTX
用Raspberry Pi 學Linux I2C Driver
Arm device tree and linux device drivers
I2C Subsystem In Linux-2.6.24
Spi drivers
Linux MMAP & Ioremap introduction
I2c drivers
Linux Initialization Process (2)
Linux Kernel Booting Process (1) - For NLKB
用Raspberry Pi 學Linux I2C Driver

What's hot (20)

PDF
Character Drivers
PPTX
Linux Initialization Process (1)
PDF
spinlock.pdf
PDF
malloc & vmalloc in Linux
PDF
BusyBox for Embedded Linux
PPT
linux device driver
PPT
U boot porting guide for SoC
PPT
Pcie drivers basics
PPTX
Slab Allocator in Linux Kernel
PDF
VLANs in the Linux Kernel
PPTX
Linux Serial Driver
PDF
Linux Kernel - Virtual File System
PDF
Decompressed vmlinux: linux kernel initialization from page table configurati...
PDF
Booting Android: bootloaders, fastboot and boot images
PPTX
Linux Kernel MMC Storage driver Overview
PPTX
Bootloaders (U-Boot)
PDF
Ixgbe internals
PDF
Board support package_on_linux
PDF
Qemu device prototyping
Character Drivers
Linux Initialization Process (1)
spinlock.pdf
malloc & vmalloc in Linux
BusyBox for Embedded Linux
linux device driver
U boot porting guide for SoC
Pcie drivers basics
Slab Allocator in Linux Kernel
VLANs in the Linux Kernel
Linux Serial Driver
Linux Kernel - Virtual File System
Decompressed vmlinux: linux kernel initialization from page table configurati...
Booting Android: bootloaders, fastboot and boot images
Linux Kernel MMC Storage driver Overview
Bootloaders (U-Boot)
Ixgbe internals
Board support package_on_linux
Qemu device prototyping
Ad

Similar to Linux PCI device driver (20)

PDF
Project ACRN expose and pass through platform hidden PCIe devices to SOS
PDF
PCI Drivers
PPTX
Slideshare - PCIe
PDF
Status update-qemu-pcie
PDF
CIP for PCI 4.0 Solution Guide for ArcSight Logger
ODP
Io Architecture
PDF
Linux : PSCI
ODP
Information Gathering 2
PDF
iSCSI introduction and usage
PDF
DEF CON 24 - Patrick Wardle - 99 problems little snitch
PDF
Technical Report Vawtrak v2
PDF
ebpf and IO Visor: The What, how, and what next!
PDF
LCA13: Power State Coordination Interface
PDF
Pycon - Python for ethical hackers
PDF
PCI_Express_Basics_Background.pdf
PDF
Implementation of PCI Target Controller Interfacing with Asynchronous SRAM
ODP
FreeLix: Semplicità & Controllo
PDF
PCI Alias Is Not Defined_ OpenStack Nova Troubleshooting.pdf
PDF
Attack your Trusted Core
PDF
ACPI Debugging from Linux Kernel
Project ACRN expose and pass through platform hidden PCIe devices to SOS
PCI Drivers
Slideshare - PCIe
Status update-qemu-pcie
CIP for PCI 4.0 Solution Guide for ArcSight Logger
Io Architecture
Linux : PSCI
Information Gathering 2
iSCSI introduction and usage
DEF CON 24 - Patrick Wardle - 99 problems little snitch
Technical Report Vawtrak v2
ebpf and IO Visor: The What, how, and what next!
LCA13: Power State Coordination Interface
Pycon - Python for ethical hackers
PCI_Express_Basics_Background.pdf
Implementation of PCI Target Controller Interfacing with Asynchronous SRAM
FreeLix: Semplicità & Controllo
PCI Alias Is Not Defined_ OpenStack Nova Troubleshooting.pdf
Attack your Trusted Core
ACPI Debugging from Linux Kernel
Ad

More from 艾鍗科技 (20)

PPTX
AI 技術浪潮, 什麼是機器學習? 什麼是深度學習, 什麼是生成式AI, AI 能力認證
PDF
TinyML - 4 speech recognition
PPTX
Appendix 1 Goolge colab
PPTX
Project-IOT於餐館系統的應用
PPTX
02 IoT implementation
PPTX
Tiny ML for spark Fun Edge
PDF
Openvino ncs2
PDF
Step motor
PDF
2. 機器學習簡介
PDF
5.MLP(Multi-Layer Perceptron)
PDF
3. data features
PPTX
心率血氧檢測與運動促進
PPTX
利用音樂&情境燈幫助放鬆
PPTX
IoT感測器驅動程式 在樹莓派上實作
PPTX
無線聲控遙控車
PPT
最佳光源的研究和實作
PPTX
無線監控網路攝影機與控制自走車
PPTX
Reinforcement Learning
PPTX
Linux Device Tree
PPTX
人臉辨識考勤系統
AI 技術浪潮, 什麼是機器學習? 什麼是深度學習, 什麼是生成式AI, AI 能力認證
TinyML - 4 speech recognition
Appendix 1 Goolge colab
Project-IOT於餐館系統的應用
02 IoT implementation
Tiny ML for spark Fun Edge
Openvino ncs2
Step motor
2. 機器學習簡介
5.MLP(Multi-Layer Perceptron)
3. data features
心率血氧檢測與運動促進
利用音樂&情境燈幫助放鬆
IoT感測器驅動程式 在樹莓派上實作
無線聲控遙控車
最佳光源的研究和實作
無線監控網路攝影機與控制自走車
Reinforcement Learning
Linux Device Tree
人臉辨識考勤系統

Recently uploaded (20)

PDF
IObit Driver Booster Pro Crack Latest Version Download
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
PPTX
StacksandQueuesCLASS 12 COMPUTER SCIENCE.pptx
PPTX
UNIT II: Software design, software .pptx
PPTX
WJQSJXNAZJVCVSAXJHBZKSJXKJKXJSBHJBJEHHJB
PDF
OpenEXR Virtual Town Hall - August 2025
PPTX
oracle_ebs_12.2_project_cutoveroutage.pptx
PPTX
Relevance Tuning with Genetic Algorithms
PDF
DOWNLOAD—IOBit Uninstaller Pro Crack Download Free
PDF
OpenTimelineIO Virtual Town Hall - August 2025
PPTX
Comprehensive Guide to Digital Image Processing Concepts and Applications
PDF
WhatsApp Chatbots The Key to Scalable Customer Support.pdf
PDF
Canva Desktop App With Crack Free Download 2025?
PDF
Ragic Data Security Overview: Certifications, Compliance, and Network Safegua...
PDF
Multiverse AI Review 2025_ The Ultimate All-in-One AI Platform.pdf
PPTX
Improving Audience Engagement ROI with ERP-Powered Insights
PPTX
Advanced Heap Dump Analysis Techniques Webinar Deck
PDF
OpenColorIO Virtual Town Hall - August 2025
PDF
Difference Between Website and Web Application.pdf
PDF
MaterialX Virtual Town Hall - August 2025
IObit Driver Booster Pro Crack Latest Version Download
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
StacksandQueuesCLASS 12 COMPUTER SCIENCE.pptx
UNIT II: Software design, software .pptx
WJQSJXNAZJVCVSAXJHBZKSJXKJKXJSBHJBJEHHJB
OpenEXR Virtual Town Hall - August 2025
oracle_ebs_12.2_project_cutoveroutage.pptx
Relevance Tuning with Genetic Algorithms
DOWNLOAD—IOBit Uninstaller Pro Crack Download Free
OpenTimelineIO Virtual Town Hall - August 2025
Comprehensive Guide to Digital Image Processing Concepts and Applications
WhatsApp Chatbots The Key to Scalable Customer Support.pdf
Canva Desktop App With Crack Free Download 2025?
Ragic Data Security Overview: Certifications, Compliance, and Network Safegua...
Multiverse AI Review 2025_ The Ultimate All-in-One AI Platform.pdf
Improving Audience Engagement ROI with ERP-Powered Insights
Advanced Heap Dump Analysis Techniques Webinar Deck
OpenColorIO Virtual Town Hall - August 2025
Difference Between Website and Web Application.pdf
MaterialX Virtual Town Hall - August 2025

Linux PCI device driver

  • 2. 什麼是PCI (Peripheral Component Interconnect) 它是一種電腦的硬體bus 可以讓多個週邊在上面運行,主要是給電 腦擴充週邊用的 它有分host端和client端,一個host可以接多 個client (最多可達32個) 可以經由PCI bridge串接更多的PCI client 它的速度有33M 和66M兩種 I/O為32bits,而記憶體可32或64b its 2
  • 7. 7 PCI啓動流程 PCI Host 控制器 初始化,並將 可分配的資源 設定好 PCI Host開始掃 描看看Bus上有 多少個PCI Client 元件 針對每一個PCI Client元件給予分 配可用資源 尋找PCI Client是否有登 記PCI probe callback, 若有就給予呼叫(依據 vendor & device ID)
  • 8. 8 PCI Host Driver 宣告一個struct hw_pci的資料 結構 呼叫 pci_common_i nit() 系統呼叫註冊的 preinit callback function初始該PCI Host元件 系統呼叫setup callback function 設定PCI Host可 分配的資源 系統呼叫scan callback function 並準備好struct pci_ops並開始掃 描PCI client元件 啓動PCI client元 件
  • 9. struct hw_pci 範例mach-ixp4xx/ixdp425-pci.c struct hw_pci ixdp425_pci __initdata = { .nr_controllers = 1, .preinit = ixdp425_pci_preinit, .swizzle = pci_std_swizzle, .setup = ixp4xx_setup, .scan = ixp4xx_scan_bus, .map_irq = ixdp425_map_irq, }; 9 int __init ixdp425_pci_init(void) { if (machine_is_ixdp425() || machine_is_ixcdp1100() || machine_is_ixdp465() || machine_is_kixrp435()) pci_common_init(&ixdp425_pci); return 0; } subsys_initcall(ixdp425_pci_init);
  • 10. 保留系統所有PCI的資源 在setup callback function中作保留的動作 1) arch/arm/mach-ixp4xx/common-pci.c int ixp4xx_setup(int nr, struct pci_sys_data *sys) { struct resource *res; res[0].name = "PCI I/O Space"; res[0].start = 0x00000000; res[0].end = 0x0000ffff; res[0].flags = IORESOURCE_IO; res[1].name = "PCI Memory Space"; res[1].start = PCIBIOS_MIN_MEM; res[1].end = 0x4bffffff; res[1].flags = IORESOURCE_MEM; request_resource(&ioport_resource, &res[0]); request_resource(&iomem_resource, &res[1]); sys->resource[0] = &res[0]; sys->resource[1] = &res[1]; sys->resource[2] = NULL; return 1; } 10
  • 11. struct pci_ops 範例 static struct pci_ops ftpci_ops = { .read = ftpci_read_config, .write = ftpci_write_config, }; 其操作是給PCI Client Driver在讀PCI table時 所使用的基本API (HAL) 系統呼叫scan_bus call back function 中會呼 叫pci_scan_bus(sys->busnr, &ixp4xx_ops, sys); 時給予註冊(arch/arm/mach-ixp4xx/common-pci. c) 11
  • 12. 12 PCI Host分配資源流程 PCI Host Scan Device Read device configuration table to get requests Assign resources to device on configuration table 比對Vendor ID & Device ID 確認是 否有任何PCI Device Driver 登 錄 呼叫己登 錄的probe callback function
  • 13. static struct pci_driver rtl8139_pci_driver = { .name = DRV_NAME, .id_table = rtl8139_pci_tbl, .probe = rtl8139_init_one, .remove = __devexit_p(rtl8139_remove_one), #ifdef CONFIG_PM .suspend = rtl8139_suspend, .resume = rtl8139_resume, #endif /* CONFIG_PM */ }; static int __init rtl8139_init_module (void) { /* when we're a module, we always print a version message, * even if no 8139 board is found. */ #ifdef MODULE pr_info(RTL8139_DRIVER_NAME "n"); #endif return pci_register_driver(&rtl8139_pci_driver); } 13 PCI Client Driver
  • 14. struct pci_device_id範例 static struct pci_device_id rtl8139_pci_tbl[] = { {0x10ec, 0x8139, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RTL8139 }, {0x10ec, 0x8138, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RTL8139 }, {0x1113, 0x1211, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RTL8139 }, {0x1500, 0x1360, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RTL8139 }, {0x4033, 0x1360, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RTL8139 }, {0x1186, 0x1300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RTL8139 }, {0x1186, 0x1340, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RTL8139 }, {0} }; 14
  • 15. PCI Client如何取得被分配的資源 pci_enable_device (pdev); pio_start = pci_resource_start (pdev, 0); pio_end = pci_resource_end (pdev, 0); pio_flags = pci_resource_flags (pdev, 0); pio_len = pci_resource_len (pdev, 0); mmio_start = pci_resource_start (pdev, 1); mmio_end = pci_resource_end (pdev, 1); mmio_flags = pci_resource_flags (pdev, 1); mmio_len = pci_resource_len (pdev, 1); 15
  • 16. PCI Bus有分I/O及memory access,而ARM只 有memory access,所以在assign I/O resource 時要小心 有的PCI controller需要改寫outb/inb & readb/writeb HAL API (arch/io.h) 16 注意事項 CPU PCI Host Controller PCI Client Device Local Bus PCI Bus
  • 17. 17 PCI Host Controller I CPU PCI Host Controller PCI Device I/O Access Memory Access Local Bus Local Bus PCI Bus PCI Bus
  • 18. 18 PCI Host Controller II CPU PCI Host Controller PCI Device I/O Access Memory Access I/O CMD Mem CMD PCI Bus PCI Bus
  • 19. PCI Host Controller II porting 在mach-xxx/include/mach目錄之下建主一個 檔案io.h 若需redirect PCI access則不要宣告以下 1) #define _ _mem_pci(a) (a) 2) #define _ _io(v) _ _typesafe_io(v) Examples 1) mach-ixp4xx/include/mach/io.h 19

Editor's Notes

  • #7: Ps : 需查明以上資訊是否為正確