SlideShare a Scribd company logo
1 of 20
LINUX PCI EXPRESS DRIVER
Background
 PCI Express (Peripheral Component Interconnect
Express), officially abbreviated as PCIe, is a high-
speed serial computer expansion bus standard
designed to replace the older PCI, PCI-X, and
AGP bus standards.
 At the software level, PCI Express preserves
backward compatibility with PCI; legacy PCI
system software can detect and configure newer
PCI Express devices without explicit support for
the PCI Express standard, though new PCI
Express features are inaccessible.
Topology
Note: figure from https://en.wikipedia.org/wiki/PCI_Express
Terminology
 Lane
 A lane is composed of two differential signaling pairs, with one pair for receiving data and the other for
transmitting. 1, 2, …, 32 lanes will denote x1, x2, …, x32.
 Root Complex
 the device that connects the CPU and memory subsystem to the PCI Express fabric. It may support one or
more PCI Express ports.
 Endpoint
 devices other than root complex and switches that are requesters or completers of PCI Express transactions.
 Configuration Space
 PCI devices have a set of registers referred to as configuration space and PCI Express introduces extended
configuration space for devices.
 BAR
 Base Address Registers (commonly called BARs) to inform the device of its address mapping by writing
configuration commands to the PCI controller.
 INTx
 An in-band messages which emulate the four physical interrupt signals (INTA-INTD) routed between PCI
devices and the system interrupt controller
 MSI/MIS-X
 An alternative in-band method of signaling an interrupt, using special in-band messages to replace traditional
out-of-band assertion of dedicated interrupt lines.
Configuration Space Layout
Note: figure from
http://www.flashmemorysummit.com/English/Collaterals/Proceedings/2013/20130812_PreConfD_Onufryk.pdf
Configuration Space Header
Status
BIST
Header
Type
Latency
Timer
Cache
Line Size
Class Code
Rev
ID
Device ID Vendor ID
Command
Base Address 0 (BAR0)
Base Address 1 (BAR1)
Base Address 2 (BAR2)
Base Address 3 (BAR3)
Base Address 4 (BAR4)
Base Address 5 (BAR5)
CardBus CIS Pointer
Subsystem
Device ID
Subsystem
Vendor ID
Expansion ROM Base Address
Reserved
Capability
Pointer
Reserved
Max Lat Min Gnt
Interrupt
Pin
Interrupt
Line
00h
04h
08h
0Ch
10h
14h
18h
1Ch
20h
24h
28h
2Ch
30h
38h
34h
3Ch
07152331
Status
BIST
Header
Type
Latency
Timer
Cache
Line Size
Class Code
Rev
ID
Device ID Vendor ID
Command
Base Address 0 (BAR0)
Base Address 1 (BAR1)
Secondary
Lat timer
Secondary
Status
(Non-Prefetchable)
Memory Limit
Prefetchable
Memory Limit
Pretetchable Memory Base
Upper 32 Bits
Prefetchable Memory Limit
Upper 32 Bits
IO Limit
Upper 16 Bits
Reserved
Capability
Pointer
Expansion ROM Base Address
Max Lat Min Gnt
Interrupt
Pin
Interrupt
Line
00h
04h
08h
0Ch
10h
14h
18h
1Ch
20h
24h
28h
2Ch
30h
38h
34h
3Ch
07152331
Type 0 Header Type 1 Header
Subordinate
Bus #
Secondary
Bus #
Primary
Bus #
IO
Limit
IO
Base
(Non-Prefetchable)
Memory Base
Prefetchable
Memory Base
IO Base
Upper 16 Bits
Capabilities List
Example: http://www.alterawiki.com/wiki/PCI_Configuration_Space
Device Layers and their
Associated Packets
Note: figure from http://resources.infosecinstitute.com/system-address-map-initialization-x86x64-architecture-part-2-
pci-express-based-systems/
Layer Packets Relationship
Note: figure from http://www.verien.com/pcie_primer.htm
Function of Each PCIE Layer
 Transaction Layer
 Mechanisms for differentiating the ordering and processing
requirements ofTransaction Layer Packets (TLPs)
 Credit-based flow control
 TLP construction and processing
 Association of transaction-level mechanisms with device resources
including Flow Control andVirtual Channel management.
 Data Link Layer
 Data Exchange
 Error Detection and Retry
 Initialization and power management
 Physical Layer
 Logical Sub-block – symbol encoding, framing, data scrambling, Link
initialization and training, Lane to lane de-skew
 Electrical Sub-block – defines the physical layer of PCI Express that
consists of a reference clock source,Transmitter, channel, and Receiver.
Packet Routing
 Address Routing - Memory and IO requests
 Address routing is used to transfer data to or from
memory, memory mapped IO, or IO locations.
 ID Routing - Completions and Configuration
 ID routing is based on the logical position (Bus
Number, Device Number, Function Number) of a
device function within the PCI bus topology.
 Implicit Routing - Message requests
 Implicit routing is based on the intrinsic knowledge
PCI Express devices are required to have concerning
upstream and downstream traffic and the existence of
a single PCI Express Root Complex at the top of the
PCI Express topology.
pciutils – lspci command
 Command “lspci”
 is a utility for displaying information about PCI
buses in the system and devices connected to
them
 Command “lspci” popular options
 -t Show bus tree
 -v Be verbose (-vv for very verbose)
 -k Show kernel drivers handling each device
 -x Show hex-dump of the standard part of the config space
pciutils – lspci example
lspci -vkx
02:00.0 Ethernet controller: Broadcom Corporation NetXtreme BCM5720 Gigabit
Ethernet PCIe
Subsystem: Broadcom Corporation Device 2003
Flags: bus master, fast devsel, latency 0, IRQ 16
Memory at f0050000 (64-bit, prefetchable) [size=64K]
Memory at f0040000 (64-bit, prefetchable) [size=64K]
Memory at f0030000 (64-bit, prefetchable) [size=64K]
Expansion ROM at f7c40000 [disabled] [size=256K]
Capabilities: [48] Power Management version 3
Capabilities: [50] Vital Product Data
Capabilities: [58] MSI: Enable- Count=1/8 Maskable- 64bit+
Capabilities: [a0] MSI-X: Enable- Count=17 Masked-
Capabilities: [ac] Express Endpoint, MSI 00
Capabilities: [100] Advanced Error Reporting
Capabilities: [13c] Device Serial Number 00-00-00-0a-f7-82-bf-82
Capabilities: [150] Power Budgeting <?>
Capabilities: [160] Virtual Channel
Kernel driver in use: tg3
00: e4 14 5f 16 06 00 10 00 00 00 00 02 10 00 80 00
10: 0c 00 05 f0 00 00 00 00 0c 00 04 f0 00 00 00 00
20: 0c 00 03 f0 00 00 00 00 00 00 00 00 e4 14 03 20
30: 00 00 c4 f7 48 00 00 00 00 00 00 00 0b 01 00 00
Controller Driver
 Find and assign resource
 Controller registers
 BARs for devices (device tree format -
http://devicetree.org/Device_Tree_Usage#PCI_Address_Translation)
 Operation implementation
 PCIe configuration access
 struct pci_ops (defined in include/linux/pci.h)
 INTx interrupts
 struct irq_domain_ops (defined in include/linux/irqdomain.h)
 struct irq_chip (defined in include/linux/irq.h)
 MSI/MSI-X interrupts
 struct irq_domain_ops
 struct irq_chip
 Example – PCIe host controller driver for Samsung EXYNOS SoCs
https://github.com/torvalds/linux/blob/master/drivers/pci/host/pc
i-exynos.c + pcie-designware.c
Enumeration Process –
Discovering the Topology
 After a system reset or power up, configuration
software has to scan the PCIe fabric to discover
the machine topology and learn how the fabric is
populated.
 Try to read device’sVendor ID register starting from
bus 0, device 0, function 0 to bus 255.
 A device is found, update device’s configuration
 Primary Bus Number Register
 Secondary Bus Number Register
 Subordinate Bus Number Register
 Enumeration software must perform a depth-first
search.
Single-Root System
Enumeration
Note: figure from https://codywu2010.wordpress.com/2015/11/29/how-modern-multi-processor-multi-root-complex-
system-assigns-pci-bus-number/
Device Driver -
Initialization Steps
Sequence Action Function
1 Enable the device pci_enable_device()
2 Enable DMA by setting the bus master bit in the
PCI_COMMAND register
pci_set_master()
3 Request MMIO/IOP resources pci_request_region()
4 Set the DMA mask size (for both coherent and streaming DMA) pci_set_dma_mask()
5 Allocate and initialize shared control data pci_ioremap_bar()
6 Access device configuration space pci_read_config_xxx()/
pci_write_config_xxx()
7 Register IRQ handler request_irq()
pci_enable_msi()
pci_enable_msix()
8 Initialize non-PCI (i.e. LAN/SCSI/etc parts of the chip)
9 Enable DMA/processing engines
 PCIe + non-PCIe
Note: How To Write Linux PCI Drivers - https://www.kernel.org/doc/Documentation/PCI/pci.txt
Device Driver – Access
Methods
 PCI/PCIe configuration access
 pci_read_config_xxx()/pci_write_config_xxx()
 Non-PCIe functionality (i.e. LAN…) registers
access
 readx()/writex()
 Example – BroadcomTigon3 ethernet driver
https://github.com/torvalds/linux/blob/maste
r/drivers/net/ethernet/broadcom/tg3.c
Common Port Service Drivers
Function Version Kconfig Port
Bus
Driver
Files
Native Hotplug (HP) 2.6.11 HOTPLUG_PCI
_PCIE
Yes drivers/pci/hotplug/pciehp*
Advanced Error
Reporting (AER)
2.6.19 PCIEAER Yes drivers/pci/pcie/aer/*
Active State Power
Management (ASPM)
/ASPM Policy
2.6.26
3.4
PCIEASPM
PCIEASPM_*
No drivers/pci/pcie/aspm.c
Power Management
Event (PME)
2.6.34 PCIE_PME Yes drivers/pci/pcie/pme/*
Note:
The PCI Express Port Bus Driver Guide HOWTO -
https://www.kernel.org/doc/Documentation/PCI/PCIEBUS-HOWTO.txt,
PCI Express Port Bus Driver Support for Linux - https://www.kernel.org/doc/ols/2005/ols2005v2-
pages-9-18.pdf
Reference Resource
• PCI Express Specifications
 https://www.pcisig.com/specifications/pciexpress/
• PCI/PCIe
 http://en.wikipedia.org/wiki/PCI_Express
 http://en.wikipedia.org/wiki/PCI_configuration_space
 http://en.wikipedia.org/wiki/Conventional_PCI
 PCIVendor(/Device) ID
 https://pcisig.com/membership/member-companies
 https://pci-ids.ucw.cz/
 http://www.pcidatabase.com/index.php
• pciutils - Linux User Space PCI configuration space access tool
 https://www.kernel.org/pub/software/utils/pciutils/
 BOOK - PCI ExpressTechnology 3.0
 https://www.mindshare.com/Books/Titles/PCI_Express_Technology_3.0

More Related Content

What's hot

Creating Your Own PCI Express System Using FPGAs: Embedded World 2010
Creating Your Own PCI Express System Using FPGAs: Embedded World 2010Creating Your Own PCI Express System Using FPGAs: Embedded World 2010
Creating Your Own PCI Express System Using FPGAs: Embedded World 2010Altera Corporation
 
PCI Express Verification using Reference Modeling
PCI Express Verification using Reference ModelingPCI Express Verification using Reference Modeling
PCI Express Verification using Reference ModelingDVClub
 
Difference between PCI PCI-X PCIe
Difference between PCI PCI-X PCIeDifference between PCI PCI-X PCIe
Difference between PCI PCI-X PCIeSUNODH GARLAPATI
 
44CON 2014 - Stupid PCIe Tricks, Joe Fitzpatrick
44CON 2014 - Stupid PCIe Tricks, Joe Fitzpatrick44CON 2014 - Stupid PCIe Tricks, Joe Fitzpatrick
44CON 2014 - Stupid PCIe Tricks, Joe Fitzpatrick44CON
 
pciexpress-200220095945.pdf
pciexpress-200220095945.pdfpciexpress-200220095945.pdf
pciexpress-200220095945.pdfzahixdd
 
APB protocol v1.0
APB protocol v1.0APB protocol v1.0
APB protocol v1.0Azad Mishra
 
SPI introduction(Serial Peripheral Interface)
SPI introduction(Serial Peripheral Interface)SPI introduction(Serial Peripheral Interface)
SPI introduction(Serial Peripheral Interface)SUNODH GARLAPATI
 
ASIC Design Flow | Physical Design | VLSI
ASIC Design Flow | Physical Design | VLSI ASIC Design Flow | Physical Design | VLSI
ASIC Design Flow | Physical Design | VLSI Jayant Suthar
 
Amba axi 29 3_2015
Amba axi 29 3_2015Amba axi 29 3_2015
Amba axi 29 3_2015kiemnhatminh
 

What's hot (20)

Creating Your Own PCI Express System Using FPGAs: Embedded World 2010
Creating Your Own PCI Express System Using FPGAs: Embedded World 2010Creating Your Own PCI Express System Using FPGAs: Embedded World 2010
Creating Your Own PCI Express System Using FPGAs: Embedded World 2010
 
PCIe DL_layer_3.0.1 (1)
PCIe DL_layer_3.0.1 (1)PCIe DL_layer_3.0.1 (1)
PCIe DL_layer_3.0.1 (1)
 
Pc ie tl_layer (3)
Pc ie tl_layer (3)Pc ie tl_layer (3)
Pc ie tl_layer (3)
 
Pci express technology 3.0
Pci express technology 3.0Pci express technology 3.0
Pci express technology 3.0
 
PCI Express Verification using Reference Modeling
PCI Express Verification using Reference ModelingPCI Express Verification using Reference Modeling
PCI Express Verification using Reference Modeling
 
axi protocol
axi protocolaxi protocol
axi protocol
 
AMBA Ahb 2.0
AMBA Ahb 2.0AMBA Ahb 2.0
AMBA Ahb 2.0
 
Difference between PCI PCI-X PCIe
Difference between PCI PCI-X PCIeDifference between PCI PCI-X PCIe
Difference between PCI PCI-X PCIe
 
44CON 2014 - Stupid PCIe Tricks, Joe Fitzpatrick
44CON 2014 - Stupid PCIe Tricks, Joe Fitzpatrick44CON 2014 - Stupid PCIe Tricks, Joe Fitzpatrick
44CON 2014 - Stupid PCIe Tricks, Joe Fitzpatrick
 
pciexpress-200220095945.pdf
pciexpress-200220095945.pdfpciexpress-200220095945.pdf
pciexpress-200220095945.pdf
 
Ambha axi
Ambha axiAmbha axi
Ambha axi
 
APB protocol v1.0
APB protocol v1.0APB protocol v1.0
APB protocol v1.0
 
AXI Protocol.pptx
AXI Protocol.pptxAXI Protocol.pptx
AXI Protocol.pptx
 
SPI introduction(Serial Peripheral Interface)
SPI introduction(Serial Peripheral Interface)SPI introduction(Serial Peripheral Interface)
SPI introduction(Serial Peripheral Interface)
 
ASIC Design Flow | Physical Design | VLSI
ASIC Design Flow | Physical Design | VLSI ASIC Design Flow | Physical Design | VLSI
ASIC Design Flow | Physical Design | VLSI
 
Amba axi 29 3_2015
Amba axi 29 3_2015Amba axi 29 3_2015
Amba axi 29 3_2015
 
CPU Verification
CPU VerificationCPU Verification
CPU Verification
 
Apb
ApbApb
Apb
 
Usb protocol
Usb protocol Usb protocol
Usb protocol
 
SPI Bus Protocol
SPI Bus ProtocolSPI Bus Protocol
SPI Bus Protocol
 

Similar to LINUX PCI EXPRESS DRIVER GUIDE

P C I L O C A L B U S
P C I  L O C A L  B U S P C I  L O C A L  B U S
P C I L O C A L B U S jainfu2
 
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 SOSProject ACRN
 
Intel® RDT Hands-on Lab
Intel® RDT Hands-on LabIntel® RDT Hands-on Lab
Intel® RDT Hands-on LabMichelle Holley
 
Motherboard components and their functions
Motherboard components and their functionsMotherboard components and their functions
Motherboard components and their functionsAbdullah-Al- Mahmud
 
Chapter 6: Expansion Buses
Chapter 6: Expansion BusesChapter 6: Expansion Buses
Chapter 6: Expansion Busesaskme
 
PCIe BUS: A State-of-the-Art-Review
PCIe BUS: A State-of-the-Art-ReviewPCIe BUS: A State-of-the-Art-Review
PCIe BUS: A State-of-the-Art-ReviewIOSRJVSP
 
PCI_Express_Basics_Background.pdf
PCI_Express_Basics_Background.pdfPCI_Express_Basics_Background.pdf
PCI_Express_Basics_Background.pdfzahixdd
 
MPC854XE: PowerQUICC III Processors
MPC854XE: PowerQUICC III ProcessorsMPC854XE: PowerQUICC III Processors
MPC854XE: PowerQUICC III ProcessorsPremier Farnell
 
Hardware Discovery Commands
Hardware Discovery CommandsHardware Discovery Commands
Hardware Discovery CommandsKevin OBrien
 
Computer hardware and networking by Pradeep Kudale
Computer hardware and networking by Pradeep KudaleComputer hardware and networking by Pradeep Kudale
Computer hardware and networking by Pradeep Kudaleshailu26
 
Raspberry Pi tutorial
Raspberry Pi tutorialRaspberry Pi tutorial
Raspberry Pi tutorial艾鍗科技
 
directCell - Cell/B.E. tightly coupled via PCI Express
directCell - Cell/B.E. tightly coupled via PCI ExpressdirectCell - Cell/B.E. tightly coupled via PCI Express
directCell - Cell/B.E. tightly coupled via PCI ExpressHeiko Joerg Schick
 
Lesson three hardware basics
Lesson three hardware basicsLesson three hardware basics
Lesson three hardware basicsMik Endale
 
Io Architecture
Io ArchitectureIo Architecture
Io ArchitectureAero Plane
 

Similar to LINUX PCI EXPRESS DRIVER GUIDE (20)

Mother board
Mother boardMother board
Mother board
 
P C I L O C A L B U S
P C I  L O C A L  B U S P C I  L O C A L  B U S
P C I L O C A L B U S
 
101 1.1 hardware settings
101 1.1 hardware settings101 1.1 hardware settings
101 1.1 hardware settings
 
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
 
Intel® RDT Hands-on Lab
Intel® RDT Hands-on LabIntel® RDT Hands-on Lab
Intel® RDT Hands-on Lab
 
Motherboard components and their functions
Motherboard components and their functionsMotherboard components and their functions
Motherboard components and their functions
 
Pc interface
Pc interfacePc interface
Pc interface
 
Chapter 6: Expansion Buses
Chapter 6: Expansion BusesChapter 6: Expansion Buses
Chapter 6: Expansion Buses
 
PCIe BUS: A State-of-the-Art-Review
PCIe BUS: A State-of-the-Art-ReviewPCIe BUS: A State-of-the-Art-Review
PCIe BUS: A State-of-the-Art-Review
 
PCI_Express_Basics_Background.pdf
PCI_Express_Basics_Background.pdfPCI_Express_Basics_Background.pdf
PCI_Express_Basics_Background.pdf
 
Bus
BusBus
Bus
 
Nsrit37
Nsrit37Nsrit37
Nsrit37
 
MPC854XE: PowerQUICC III Processors
MPC854XE: PowerQUICC III ProcessorsMPC854XE: PowerQUICC III Processors
MPC854XE: PowerQUICC III Processors
 
Hardware Discovery Commands
Hardware Discovery CommandsHardware Discovery Commands
Hardware Discovery Commands
 
Computer hardware and networking by Pradeep Kudale
Computer hardware and networking by Pradeep KudaleComputer hardware and networking by Pradeep Kudale
Computer hardware and networking by Pradeep Kudale
 
Raspberry Pi tutorial
Raspberry Pi tutorialRaspberry Pi tutorial
Raspberry Pi tutorial
 
directCell - Cell/B.E. tightly coupled via PCI Express
directCell - Cell/B.E. tightly coupled via PCI ExpressdirectCell - Cell/B.E. tightly coupled via PCI Express
directCell - Cell/B.E. tightly coupled via PCI Express
 
Lesson three hardware basics
Lesson three hardware basicsLesson three hardware basics
Lesson three hardware basics
 
Io Architecture
Io ArchitectureIo Architecture
Io Architecture
 
haifux-pcie.pdf
haifux-pcie.pdfhaifux-pcie.pdf
haifux-pcie.pdf
 

Recently uploaded

Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfkalichargn70th171
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 

Recently uploaded (20)

Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Odoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting ServiceOdoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting Service
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 

LINUX PCI EXPRESS DRIVER GUIDE

  • 2. Background  PCI Express (Peripheral Component Interconnect Express), officially abbreviated as PCIe, is a high- speed serial computer expansion bus standard designed to replace the older PCI, PCI-X, and AGP bus standards.  At the software level, PCI Express preserves backward compatibility with PCI; legacy PCI system software can detect and configure newer PCI Express devices without explicit support for the PCI Express standard, though new PCI Express features are inaccessible.
  • 3. Topology Note: figure from https://en.wikipedia.org/wiki/PCI_Express
  • 4. Terminology  Lane  A lane is composed of two differential signaling pairs, with one pair for receiving data and the other for transmitting. 1, 2, …, 32 lanes will denote x1, x2, …, x32.  Root Complex  the device that connects the CPU and memory subsystem to the PCI Express fabric. It may support one or more PCI Express ports.  Endpoint  devices other than root complex and switches that are requesters or completers of PCI Express transactions.  Configuration Space  PCI devices have a set of registers referred to as configuration space and PCI Express introduces extended configuration space for devices.  BAR  Base Address Registers (commonly called BARs) to inform the device of its address mapping by writing configuration commands to the PCI controller.  INTx  An in-band messages which emulate the four physical interrupt signals (INTA-INTD) routed between PCI devices and the system interrupt controller  MSI/MIS-X  An alternative in-band method of signaling an interrupt, using special in-band messages to replace traditional out-of-band assertion of dedicated interrupt lines.
  • 5. Configuration Space Layout Note: figure from http://www.flashmemorysummit.com/English/Collaterals/Proceedings/2013/20130812_PreConfD_Onufryk.pdf
  • 6. Configuration Space Header Status BIST Header Type Latency Timer Cache Line Size Class Code Rev ID Device ID Vendor ID Command Base Address 0 (BAR0) Base Address 1 (BAR1) Base Address 2 (BAR2) Base Address 3 (BAR3) Base Address 4 (BAR4) Base Address 5 (BAR5) CardBus CIS Pointer Subsystem Device ID Subsystem Vendor ID Expansion ROM Base Address Reserved Capability Pointer Reserved Max Lat Min Gnt Interrupt Pin Interrupt Line 00h 04h 08h 0Ch 10h 14h 18h 1Ch 20h 24h 28h 2Ch 30h 38h 34h 3Ch 07152331 Status BIST Header Type Latency Timer Cache Line Size Class Code Rev ID Device ID Vendor ID Command Base Address 0 (BAR0) Base Address 1 (BAR1) Secondary Lat timer Secondary Status (Non-Prefetchable) Memory Limit Prefetchable Memory Limit Pretetchable Memory Base Upper 32 Bits Prefetchable Memory Limit Upper 32 Bits IO Limit Upper 16 Bits Reserved Capability Pointer Expansion ROM Base Address Max Lat Min Gnt Interrupt Pin Interrupt Line 00h 04h 08h 0Ch 10h 14h 18h 1Ch 20h 24h 28h 2Ch 30h 38h 34h 3Ch 07152331 Type 0 Header Type 1 Header Subordinate Bus # Secondary Bus # Primary Bus # IO Limit IO Base (Non-Prefetchable) Memory Base Prefetchable Memory Base IO Base Upper 16 Bits
  • 8. Device Layers and their Associated Packets Note: figure from http://resources.infosecinstitute.com/system-address-map-initialization-x86x64-architecture-part-2- pci-express-based-systems/
  • 9. Layer Packets Relationship Note: figure from http://www.verien.com/pcie_primer.htm
  • 10. Function of Each PCIE Layer  Transaction Layer  Mechanisms for differentiating the ordering and processing requirements ofTransaction Layer Packets (TLPs)  Credit-based flow control  TLP construction and processing  Association of transaction-level mechanisms with device resources including Flow Control andVirtual Channel management.  Data Link Layer  Data Exchange  Error Detection and Retry  Initialization and power management  Physical Layer  Logical Sub-block – symbol encoding, framing, data scrambling, Link initialization and training, Lane to lane de-skew  Electrical Sub-block – defines the physical layer of PCI Express that consists of a reference clock source,Transmitter, channel, and Receiver.
  • 11. Packet Routing  Address Routing - Memory and IO requests  Address routing is used to transfer data to or from memory, memory mapped IO, or IO locations.  ID Routing - Completions and Configuration  ID routing is based on the logical position (Bus Number, Device Number, Function Number) of a device function within the PCI bus topology.  Implicit Routing - Message requests  Implicit routing is based on the intrinsic knowledge PCI Express devices are required to have concerning upstream and downstream traffic and the existence of a single PCI Express Root Complex at the top of the PCI Express topology.
  • 12. pciutils – lspci command  Command “lspci”  is a utility for displaying information about PCI buses in the system and devices connected to them  Command “lspci” popular options  -t Show bus tree  -v Be verbose (-vv for very verbose)  -k Show kernel drivers handling each device  -x Show hex-dump of the standard part of the config space
  • 13. pciutils – lspci example lspci -vkx 02:00.0 Ethernet controller: Broadcom Corporation NetXtreme BCM5720 Gigabit Ethernet PCIe Subsystem: Broadcom Corporation Device 2003 Flags: bus master, fast devsel, latency 0, IRQ 16 Memory at f0050000 (64-bit, prefetchable) [size=64K] Memory at f0040000 (64-bit, prefetchable) [size=64K] Memory at f0030000 (64-bit, prefetchable) [size=64K] Expansion ROM at f7c40000 [disabled] [size=256K] Capabilities: [48] Power Management version 3 Capabilities: [50] Vital Product Data Capabilities: [58] MSI: Enable- Count=1/8 Maskable- 64bit+ Capabilities: [a0] MSI-X: Enable- Count=17 Masked- Capabilities: [ac] Express Endpoint, MSI 00 Capabilities: [100] Advanced Error Reporting Capabilities: [13c] Device Serial Number 00-00-00-0a-f7-82-bf-82 Capabilities: [150] Power Budgeting <?> Capabilities: [160] Virtual Channel Kernel driver in use: tg3 00: e4 14 5f 16 06 00 10 00 00 00 00 02 10 00 80 00 10: 0c 00 05 f0 00 00 00 00 0c 00 04 f0 00 00 00 00 20: 0c 00 03 f0 00 00 00 00 00 00 00 00 e4 14 03 20 30: 00 00 c4 f7 48 00 00 00 00 00 00 00 0b 01 00 00
  • 14. Controller Driver  Find and assign resource  Controller registers  BARs for devices (device tree format - http://devicetree.org/Device_Tree_Usage#PCI_Address_Translation)  Operation implementation  PCIe configuration access  struct pci_ops (defined in include/linux/pci.h)  INTx interrupts  struct irq_domain_ops (defined in include/linux/irqdomain.h)  struct irq_chip (defined in include/linux/irq.h)  MSI/MSI-X interrupts  struct irq_domain_ops  struct irq_chip  Example – PCIe host controller driver for Samsung EXYNOS SoCs https://github.com/torvalds/linux/blob/master/drivers/pci/host/pc i-exynos.c + pcie-designware.c
  • 15. Enumeration Process – Discovering the Topology  After a system reset or power up, configuration software has to scan the PCIe fabric to discover the machine topology and learn how the fabric is populated.  Try to read device’sVendor ID register starting from bus 0, device 0, function 0 to bus 255.  A device is found, update device’s configuration  Primary Bus Number Register  Secondary Bus Number Register  Subordinate Bus Number Register  Enumeration software must perform a depth-first search.
  • 16. Single-Root System Enumeration Note: figure from https://codywu2010.wordpress.com/2015/11/29/how-modern-multi-processor-multi-root-complex- system-assigns-pci-bus-number/
  • 17. Device Driver - Initialization Steps Sequence Action Function 1 Enable the device pci_enable_device() 2 Enable DMA by setting the bus master bit in the PCI_COMMAND register pci_set_master() 3 Request MMIO/IOP resources pci_request_region() 4 Set the DMA mask size (for both coherent and streaming DMA) pci_set_dma_mask() 5 Allocate and initialize shared control data pci_ioremap_bar() 6 Access device configuration space pci_read_config_xxx()/ pci_write_config_xxx() 7 Register IRQ handler request_irq() pci_enable_msi() pci_enable_msix() 8 Initialize non-PCI (i.e. LAN/SCSI/etc parts of the chip) 9 Enable DMA/processing engines  PCIe + non-PCIe Note: How To Write Linux PCI Drivers - https://www.kernel.org/doc/Documentation/PCI/pci.txt
  • 18. Device Driver – Access Methods  PCI/PCIe configuration access  pci_read_config_xxx()/pci_write_config_xxx()  Non-PCIe functionality (i.e. LAN…) registers access  readx()/writex()  Example – BroadcomTigon3 ethernet driver https://github.com/torvalds/linux/blob/maste r/drivers/net/ethernet/broadcom/tg3.c
  • 19. Common Port Service Drivers Function Version Kconfig Port Bus Driver Files Native Hotplug (HP) 2.6.11 HOTPLUG_PCI _PCIE Yes drivers/pci/hotplug/pciehp* Advanced Error Reporting (AER) 2.6.19 PCIEAER Yes drivers/pci/pcie/aer/* Active State Power Management (ASPM) /ASPM Policy 2.6.26 3.4 PCIEASPM PCIEASPM_* No drivers/pci/pcie/aspm.c Power Management Event (PME) 2.6.34 PCIE_PME Yes drivers/pci/pcie/pme/* Note: The PCI Express Port Bus Driver Guide HOWTO - https://www.kernel.org/doc/Documentation/PCI/PCIEBUS-HOWTO.txt, PCI Express Port Bus Driver Support for Linux - https://www.kernel.org/doc/ols/2005/ols2005v2- pages-9-18.pdf
  • 20. Reference Resource • PCI Express Specifications  https://www.pcisig.com/specifications/pciexpress/ • PCI/PCIe  http://en.wikipedia.org/wiki/PCI_Express  http://en.wikipedia.org/wiki/PCI_configuration_space  http://en.wikipedia.org/wiki/Conventional_PCI  PCIVendor(/Device) ID  https://pcisig.com/membership/member-companies  https://pci-ids.ucw.cz/  http://www.pcidatabase.com/index.php • pciutils - Linux User Space PCI configuration space access tool  https://www.kernel.org/pub/software/utils/pciutils/  BOOK - PCI ExpressTechnology 3.0  https://www.mindshare.com/Books/Titles/PCI_Express_Technology_3.0

Editor's Notes

  1. https://en.wikipedia.org/wiki/PCI_Express
  2. http://www.verien.com/pcie_primer.htm
  3. http://www.testbench.in/introduction_to_pci_express.html