SlideShare a Scribd company logo
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

What's hot

Linux Initialization Process (1)
Linux Initialization Process (1)Linux Initialization Process (1)
Linux Initialization Process (1)
shimosawa
 
Linux device drivers
Linux device drivers Linux device drivers
Linux I2C
Linux I2CLinux I2C
Linux I2C
KaidenYu
 
Linux Kernel Booting Process (2) - For NLKB
Linux Kernel Booting Process (2) - For NLKBLinux Kernel Booting Process (2) - For NLKB
Linux Kernel Booting Process (2) - For NLKB
shimosawa
 
Hands-on ethernet driver
Hands-on ethernet driverHands-on ethernet driver
Hands-on ethernet driver
SUSE Labs Taipei
 
I2c drivers
I2c driversI2c drivers
I2c drivers
pradeep_tewani
 
Introduction Linux Device Drivers
Introduction Linux Device DriversIntroduction Linux Device Drivers
Introduction Linux Device Drivers
NEEVEE Technologies
 
U-Boot - An universal bootloader
U-Boot - An universal bootloader U-Boot - An universal bootloader
U-Boot - An universal bootloader
Emertxe Information Technologies Pvt Ltd
 
The TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux KernelThe TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux Kernel
Divye Kapoor
 
Linux Network Stack
Linux Network StackLinux Network Stack
Linux Network Stack
Adrien Mahieux
 
Linux Kernel Module - For NLKB
Linux Kernel Module - For NLKBLinux Kernel Module - For NLKB
Linux Kernel Module - For NLKB
shimosawa
 
Platform Drivers
Platform DriversPlatform Drivers
Uboot startup sequence
Uboot startup sequenceUboot startup sequence
Uboot startup sequenceHoucheng Lin
 
Linux dma engine
Linux dma engineLinux dma engine
Linux dma engine
pradeep_tewani
 
Hardware Probing in the Linux Kernel
Hardware Probing in the Linux KernelHardware Probing in the Linux Kernel
Hardware Probing in the Linux Kernel
Kernel TLV
 
BeagleBone Black Bootloaders
BeagleBone Black BootloadersBeagleBone Black Bootloaders
BeagleBone Black Bootloaders
SysPlay eLearning Academy for You
 
Embedded linux network device driver development
Embedded linux network device driver developmentEmbedded linux network device driver development
Embedded linux network device driver development
Amr Ali (ISTQB CTAL Full, CSM, ITIL Foundation)
 
linux device driver
linux device driverlinux device driver
linux device driver
Rahul Batra
 
Bootloaders
BootloadersBootloaders
Bootloaders
Anil Kumar Pugalia
 
Introduction to open_sbi
Introduction to open_sbiIntroduction to open_sbi
Introduction to open_sbi
Nylon
 

What's hot (20)

Linux Initialization Process (1)
Linux Initialization Process (1)Linux Initialization Process (1)
Linux Initialization Process (1)
 
Linux device drivers
Linux device drivers Linux device drivers
Linux device drivers
 
Linux I2C
Linux I2CLinux I2C
Linux I2C
 
Linux Kernel Booting Process (2) - For NLKB
Linux Kernel Booting Process (2) - For NLKBLinux Kernel Booting Process (2) - For NLKB
Linux Kernel Booting Process (2) - For NLKB
 
Hands-on ethernet driver
Hands-on ethernet driverHands-on ethernet driver
Hands-on ethernet driver
 
I2c drivers
I2c driversI2c drivers
I2c drivers
 
Introduction Linux Device Drivers
Introduction Linux Device DriversIntroduction Linux Device Drivers
Introduction Linux Device Drivers
 
U-Boot - An universal bootloader
U-Boot - An universal bootloader U-Boot - An universal bootloader
U-Boot - An universal bootloader
 
The TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux KernelThe TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux Kernel
 
Linux Network Stack
Linux Network StackLinux Network Stack
Linux Network Stack
 
Linux Kernel Module - For NLKB
Linux Kernel Module - For NLKBLinux Kernel Module - For NLKB
Linux Kernel Module - For NLKB
 
Platform Drivers
Platform DriversPlatform Drivers
Platform Drivers
 
Uboot startup sequence
Uboot startup sequenceUboot startup sequence
Uboot startup sequence
 
Linux dma engine
Linux dma engineLinux dma engine
Linux dma engine
 
Hardware Probing in the Linux Kernel
Hardware Probing in the Linux KernelHardware Probing in the Linux Kernel
Hardware Probing in the Linux Kernel
 
BeagleBone Black Bootloaders
BeagleBone Black BootloadersBeagleBone Black Bootloaders
BeagleBone Black Bootloaders
 
Embedded linux network device driver development
Embedded linux network device driver developmentEmbedded linux network device driver development
Embedded linux network device driver development
 
linux device driver
linux device driverlinux device driver
linux device driver
 
Bootloaders
BootloadersBootloaders
Bootloaders
 
Introduction to open_sbi
Introduction to open_sbiIntroduction to open_sbi
Introduction to open_sbi
 

Similar to Linux PCI device driver

Project ACRN expose and pass through platform hidden PCIe devices to SOS
Project ACRN expose and pass through platform hidden PCIe devices to SOSProject ACRN expose and pass through platform hidden PCIe devices to SOS
Project ACRN expose and pass through platform hidden PCIe devices to SOS
Project ACRN
 
Slideshare - PCIe
Slideshare - PCIeSlideshare - PCIe
Slideshare - PCIe
Jin Wu
 
CIP for PCI 4.0 Solution Guide for ArcSight Logger
CIP for PCI 4.0 Solution Guide for ArcSight LoggerCIP for PCI 4.0 Solution Guide for ArcSight Logger
CIP for PCI 4.0 Solution Guide for ArcSight Logger
protect724rkeer
 
Pcie drivers basics
Pcie drivers basicsPcie drivers basics
Pcie drivers basics
Venkatesh Malla
 
Io Architecture
Io ArchitectureIo Architecture
Io ArchitectureAero Plane
 
Linux : PSCI
Linux : PSCILinux : PSCI
Linux : PSCI
Mr. Vengineer
 
Information Gathering 2
Information Gathering 2Information Gathering 2
Information Gathering 2Aero Plane
 
iSCSI introduction and usage
iSCSI introduction and usageiSCSI introduction and usage
iSCSI introduction and usage
Lingshan Zhu
 
DEF CON 24 - Patrick Wardle - 99 problems little snitch
DEF CON 24 - Patrick Wardle - 99 problems little snitchDEF CON 24 - Patrick Wardle - 99 problems little snitch
DEF CON 24 - Patrick Wardle - 99 problems little snitch
Felipe Prado
 
Technical Report Vawtrak v2
Technical Report Vawtrak v2Technical Report Vawtrak v2
Technical Report Vawtrak v2
Blueliv
 
ebpf and IO Visor: The What, how, and what next!
ebpf and IO Visor: The What, how, and what next!ebpf and IO Visor: The What, how, and what next!
ebpf and IO Visor: The What, how, and what next!
Affan Syed
 
LCA13: Power State Coordination Interface
LCA13: Power State Coordination InterfaceLCA13: Power State Coordination Interface
LCA13: Power State Coordination Interface
Linaro
 
Pycon - Python for ethical hackers
Pycon - Python for ethical hackers Pycon - Python for ethical hackers
Pycon - Python for ethical hackers
Mohammad Reza Kamalifard
 
PCI_Express_Basics_Background.pdf
PCI_Express_Basics_Background.pdfPCI_Express_Basics_Background.pdf
PCI_Express_Basics_Background.pdf
zahixdd
 
Implementation of PCI Target Controller Interfacing with Asynchronous SRAM
Implementation of PCI Target Controller Interfacing with Asynchronous SRAMImplementation of PCI Target Controller Interfacing with Asynchronous SRAM
Implementation of PCI Target Controller Interfacing with Asynchronous SRAM
IOSR Journals
 
FreeLix: Semplicità & Controllo
FreeLix: Semplicità & ControlloFreeLix: Semplicità & Controllo
FreeLix: Semplicità & Controllo
Valerio Balbi
 
Attack your Trusted Core
Attack your Trusted CoreAttack your Trusted Core
Attack your Trusted Core
Di Shen
 
ACPI Debugging from Linux Kernel
ACPI Debugging from Linux KernelACPI Debugging from Linux Kernel
ACPI Debugging from Linux Kernel
SUSE Labs Taipei
 

Similar to Linux PCI device driver (20)

Project ACRN expose and pass through platform hidden PCIe devices to SOS
Project ACRN expose and pass through platform hidden PCIe devices to SOSProject ACRN expose and pass through platform hidden PCIe devices to SOS
Project ACRN expose and pass through platform hidden PCIe devices to SOS
 
PCI Drivers
PCI DriversPCI Drivers
PCI Drivers
 
Slideshare - PCIe
Slideshare - PCIeSlideshare - PCIe
Slideshare - PCIe
 
Status update-qemu-pcie
Status update-qemu-pcieStatus update-qemu-pcie
Status update-qemu-pcie
 
CIP for PCI 4.0 Solution Guide for ArcSight Logger
CIP for PCI 4.0 Solution Guide for ArcSight LoggerCIP for PCI 4.0 Solution Guide for ArcSight Logger
CIP for PCI 4.0 Solution Guide for ArcSight Logger
 
Pcie drivers basics
Pcie drivers basicsPcie drivers basics
Pcie drivers basics
 
Io Architecture
Io ArchitectureIo Architecture
Io Architecture
 
Linux : PSCI
Linux : PSCILinux : PSCI
Linux : PSCI
 
Information Gathering 2
Information Gathering 2Information Gathering 2
Information Gathering 2
 
iSCSI introduction and usage
iSCSI introduction and usageiSCSI introduction and usage
iSCSI introduction and usage
 
DEF CON 24 - Patrick Wardle - 99 problems little snitch
DEF CON 24 - Patrick Wardle - 99 problems little snitchDEF CON 24 - Patrick Wardle - 99 problems little snitch
DEF CON 24 - Patrick Wardle - 99 problems little snitch
 
Technical Report Vawtrak v2
Technical Report Vawtrak v2Technical Report Vawtrak v2
Technical Report Vawtrak v2
 
ebpf and IO Visor: The What, how, and what next!
ebpf and IO Visor: The What, how, and what next!ebpf and IO Visor: The What, how, and what next!
ebpf and IO Visor: The What, how, and what next!
 
LCA13: Power State Coordination Interface
LCA13: Power State Coordination InterfaceLCA13: Power State Coordination Interface
LCA13: Power State Coordination Interface
 
Pycon - Python for ethical hackers
Pycon - Python for ethical hackers Pycon - Python for ethical hackers
Pycon - Python for ethical hackers
 
PCI_Express_Basics_Background.pdf
PCI_Express_Basics_Background.pdfPCI_Express_Basics_Background.pdf
PCI_Express_Basics_Background.pdf
 
Implementation of PCI Target Controller Interfacing with Asynchronous SRAM
Implementation of PCI Target Controller Interfacing with Asynchronous SRAMImplementation of PCI Target Controller Interfacing with Asynchronous SRAM
Implementation of PCI Target Controller Interfacing with Asynchronous SRAM
 
FreeLix: Semplicità & Controllo
FreeLix: Semplicità & ControlloFreeLix: Semplicità & Controllo
FreeLix: Semplicità & Controllo
 
Attack your Trusted Core
Attack your Trusted CoreAttack your Trusted Core
Attack your Trusted Core
 
ACPI Debugging from Linux Kernel
ACPI Debugging from Linux KernelACPI Debugging from Linux Kernel
ACPI Debugging from Linux Kernel
 

More from 艾鍗科技

TinyML - 4 speech recognition
TinyML - 4 speech recognition TinyML - 4 speech recognition
TinyML - 4 speech recognition
艾鍗科技
 
Appendix 1 Goolge colab
Appendix 1 Goolge colabAppendix 1 Goolge colab
Appendix 1 Goolge colab
艾鍗科技
 
Project-IOT於餐館系統的應用
Project-IOT於餐館系統的應用Project-IOT於餐館系統的應用
Project-IOT於餐館系統的應用
艾鍗科技
 
02 IoT implementation
02 IoT implementation02 IoT implementation
02 IoT implementation
艾鍗科技
 
Tiny ML for spark Fun Edge
Tiny ML for spark Fun EdgeTiny ML for spark Fun Edge
Tiny ML for spark Fun Edge
艾鍗科技
 
Openvino ncs2
Openvino ncs2Openvino ncs2
Openvino ncs2
艾鍗科技
 
Step motor
Step motorStep motor
Step motor
艾鍗科技
 
2. 機器學習簡介
2. 機器學習簡介2. 機器學習簡介
2. 機器學習簡介
艾鍗科技
 
5.MLP(Multi-Layer Perceptron)
5.MLP(Multi-Layer Perceptron) 5.MLP(Multi-Layer Perceptron)
5.MLP(Multi-Layer Perceptron)
艾鍗科技
 
3. data features
3. data features3. data features
3. data features
艾鍗科技
 
心率血氧檢測與運動促進
心率血氧檢測與運動促進心率血氧檢測與運動促進
心率血氧檢測與運動促進
艾鍗科技
 
利用音樂&情境燈幫助放鬆
利用音樂&情境燈幫助放鬆利用音樂&情境燈幫助放鬆
利用音樂&情境燈幫助放鬆
艾鍗科技
 
IoT感測器驅動程式 在樹莓派上實作
IoT感測器驅動程式在樹莓派上實作IoT感測器驅動程式在樹莓派上實作
IoT感測器驅動程式 在樹莓派上實作
艾鍗科技
 
無線聲控遙控車
無線聲控遙控車無線聲控遙控車
無線聲控遙控車
艾鍗科技
 
最佳光源的研究和實作
最佳光源的研究和實作最佳光源的研究和實作
最佳光源的研究和實作
艾鍗科技
 
無線監控網路攝影機與控制自走車
無線監控網路攝影機與控制自走車無線監控網路攝影機與控制自走車
無線監控網路攝影機與控制自走車
艾鍗科技
 
Reinforcement Learning
Reinforcement LearningReinforcement Learning
Reinforcement Learning
艾鍗科技
 
Linux Device Tree
Linux Device TreeLinux Device Tree
Linux Device Tree
艾鍗科技
 
人臉辨識考勤系統
人臉辨識考勤系統人臉辨識考勤系統
人臉辨識考勤系統
艾鍗科技
 
智慧家庭Smart Home
智慧家庭Smart Home智慧家庭Smart Home
智慧家庭Smart Home
艾鍗科技
 

More from 艾鍗科技 (20)

TinyML - 4 speech recognition
TinyML - 4 speech recognition TinyML - 4 speech recognition
TinyML - 4 speech recognition
 
Appendix 1 Goolge colab
Appendix 1 Goolge colabAppendix 1 Goolge colab
Appendix 1 Goolge colab
 
Project-IOT於餐館系統的應用
Project-IOT於餐館系統的應用Project-IOT於餐館系統的應用
Project-IOT於餐館系統的應用
 
02 IoT implementation
02 IoT implementation02 IoT implementation
02 IoT implementation
 
Tiny ML for spark Fun Edge
Tiny ML for spark Fun EdgeTiny ML for spark Fun Edge
Tiny ML for spark Fun Edge
 
Openvino ncs2
Openvino ncs2Openvino ncs2
Openvino ncs2
 
Step motor
Step motorStep motor
Step motor
 
2. 機器學習簡介
2. 機器學習簡介2. 機器學習簡介
2. 機器學習簡介
 
5.MLP(Multi-Layer Perceptron)
5.MLP(Multi-Layer Perceptron) 5.MLP(Multi-Layer Perceptron)
5.MLP(Multi-Layer Perceptron)
 
3. data features
3. data features3. data features
3. data features
 
心率血氧檢測與運動促進
心率血氧檢測與運動促進心率血氧檢測與運動促進
心率血氧檢測與運動促進
 
利用音樂&情境燈幫助放鬆
利用音樂&情境燈幫助放鬆利用音樂&情境燈幫助放鬆
利用音樂&情境燈幫助放鬆
 
IoT感測器驅動程式 在樹莓派上實作
IoT感測器驅動程式在樹莓派上實作IoT感測器驅動程式在樹莓派上實作
IoT感測器驅動程式 在樹莓派上實作
 
無線聲控遙控車
無線聲控遙控車無線聲控遙控車
無線聲控遙控車
 
最佳光源的研究和實作
最佳光源的研究和實作最佳光源的研究和實作
最佳光源的研究和實作
 
無線監控網路攝影機與控制自走車
無線監控網路攝影機與控制自走車無線監控網路攝影機與控制自走車
無線監控網路攝影機與控制自走車
 
Reinforcement Learning
Reinforcement LearningReinforcement Learning
Reinforcement Learning
 
Linux Device Tree
Linux Device TreeLinux Device Tree
Linux Device Tree
 
人臉辨識考勤系統
人臉辨識考勤系統人臉辨識考勤系統
人臉辨識考勤系統
 
智慧家庭Smart Home
智慧家庭Smart Home智慧家庭Smart Home
智慧家庭Smart Home
 

Recently uploaded

Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
KrzysztofKkol1
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024
Sharepoint Designs
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
ayushiqss
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2
 
Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
varshanayak241
 

Recently uploaded (20)

Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
 

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

  1. Ps : 需查明以上資訊是否為正確