SlideShare a Scribd company logo
1 of 16
© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Peripheral Component Interconnect (PCI) Drivers
2© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
What to Expect?
PCI Subsystem
Coding Details of a PCI Device Driver
Browsing Sample Code
3© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
PCI Prologue
Developed by Intel as a replacement for ISA
More of a processor (specific) bus for x86 architectures
Replacing Features
Plug n Play
Platform independent
Fast
Hardware Addressing
Through South Bridge (PCI Controller)
Buses (upto 256) → Devices (upto 32) → Functions (upto 8)
4© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Kernel Aspect
Organized as
PCI Core (driver of the PCI Controller)
PCI Drivers (device drivers)
Kernel Windows for PCI
/proc/bus/pci/devices (Try cat)
/sys/bus/pci/devices (Try tree)
Command: lspci
5© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Dynamic Device Configuration
What Configuration?
Device Base Address(es)
Register Space(s)
Memory(s)
Interrupt Vectors
...
Done during Bootup by
BIOS, Or
PCI Core (Bootloader or Kernel)
Configured by the time, driver comes up
But, where is this configuration stored?
6© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
PCI Device Configuration Space
Vendor
ID
BIST
Header
Type
Lat
Timer
Cache
Line
Class Code
Rev
ID
Status
Register
Command
Register
Device
ID
0x0 0xF
Base Address 0
CardBus CIS pointerBase Address 5Base Address 4
Base Address 3Base Address 2Base Address 1
Subsystem
Vendor ID
Subsystem
Device ID
Expansion ROM
Base Address
IRQ
Line
IRQ
Pin
Min
Gnt
Max
Lat
0x00
0x30
0x20
0x10
Reserved
7© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
PCI Device Config Space Access
Header: <linux/pci.h>
APIs
int pci_read_config_byte(struct pci_dev *dev, int where, u8 *val);
int pci_read_config_word(struct pci_dev *dev, int where, u16 *val);
int pci_read_config_dword(struct pci_dev *dev, int where, u32 *val);
int pci_write_config_byte(struct pci_dev *dev, int where, u8 *val);
int pci_write_config_word(struct pci_dev *dev, int where, u16 *val);
int pci_write_config_dword(struct pci_dev *dev, int where, u32 *val);
NB struct pci_dev *dev would be available as parameter to
probe()
8© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Standard PCI Device Access API
Upto 6 Memory or I/O regions
Header: <linux/pci.h>
APIs
unsigned long pci_resource_start(dev, bar);
unsigned long pci_resource_len(dev, bar);
unsigned long pci_resource_flags(dev, bar);
Flags
IORESOURCE_IO
IORESOURCE_MEM
IORESOURCE_PREFETCH
9© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
PCI Driver Registration
int pci_register_driver(struct pci_driver *drv);
int pci_unregister_driver(struct pci_driver *drv);
struct pci_driver
const char *name
const struct pci_dev_id *id_table;
PCI_DEVICE(vendor, device);
PCI_DEVICE_CLASS(dev_class, dev_class_mask);
int (*probe)(pci_dev, id_table);
void (*remove)(pci_dev);
Header: <linux/pci.h>
10© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Typical 'probe' Function
int probe(struct pci_dev *dev, struct pci_dev_id *id)
{
/* Enable the PCI Device */
pci_enable_device(dev);
...
/* Acquire PCI Device's regions */
pci_request_regions(dev, “label”);
...
/* Possibly map I/Os */
...
pci_set_drvdata(dev, <pvt_data_ptr>); // Optional
...
/* Register the vertical */
...
return 0; /* Claimed. Negative for not Claimed */
}
11© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Typical 'remove' Function
void remove(struct pci_dev *dev)
{
/* Unregister the vertical */
...
pci_set_drvdata(dev, NULL); // Optional
...
/* Possibly unmap I/Os */
...
/* Release PCI Device's regions */
pci_release_regions(dev);
...
/* Disable the PCI Device */
pci_disable_device(dev);
}
12© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Old-style PCI Probing & Getting
struct pci_dev *pci_find_*(vendor, device, from);
struct pci_dev *pci_get_device(v, d, from);
struct pci_dev *pci_get_subsys(v, d, ssv, ssd, f);
struct pci_dev *pci_get_slot(bus, devfn);
pci_dev_put(pci_dev);
© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
DMA Mapping
APIs
dma_addr_t pci_map_single(struct pci_dev *, void *, size_t, int dir);
void pci_unmap_single(struct pci_dev *, dma_addr_t, size_t, int dir);
Directions
PCI_DMA_BIDIRECTIONAL
PCI_DMA_TODEVICE
PCI_DMA_FROMDEVICE
Header: <linux/pci.h>
To Device
PM VM
PA VA
From Device
© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
DMA Allocation
PM VM
APIs
void *pci_alloc_consistent(struct pci_dev *, size_t, dma_addr_t *);
void pci_free_consistent(struct pci_dev *, size_t, void *,
dma_addr_t);
int pci_set_dma_mask(struct pci_dev *, u64 mask);
Header: <linux/pci.h>
PA VA
15© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
What all have we learnt?
PCI Subsystem
Coding Details of a PCI Device Driver
Browsing Sample Code
DMA with PCI
16© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Any Queries?

More Related Content

What's hot

Arm device tree and linux device drivers
Arm device tree and linux device driversArm device tree and linux device drivers
Arm device tree and linux device driversHoucheng Lin
 
U Boot or Universal Bootloader
U Boot or Universal BootloaderU Boot or Universal Bootloader
U Boot or Universal BootloaderSatpal Parmar
 
用Raspberry Pi 學Linux I2C Driver
用Raspberry Pi 學Linux I2C Driver用Raspberry Pi 學Linux I2C Driver
用Raspberry Pi 學Linux I2C Driver艾鍗科技
 
Kernel Recipes 2015: Representing device-tree peripherals in ACPI
Kernel Recipes 2015: Representing device-tree peripherals in ACPIKernel Recipes 2015: Representing device-tree peripherals in ACPI
Kernel Recipes 2015: Representing device-tree peripherals in ACPIAnne Nicolas
 
U-Boot presentation 2013
U-Boot presentation  2013U-Boot presentation  2013
U-Boot presentation 2013Wave Digitech
 
Linux Initialization Process (2)
Linux Initialization Process (2)Linux Initialization Process (2)
Linux Initialization Process (2)shimosawa
 
Linux Ethernet device driver
Linux Ethernet device driverLinux Ethernet device driver
Linux Ethernet device driver艾鍗科技
 
Device Tree for Dummies (ELC 2014)
Device Tree for Dummies (ELC 2014)Device Tree for Dummies (ELC 2014)
Device Tree for Dummies (ELC 2014)Thomas Petazzoni
 
Linux Kernel MMC Storage driver Overview
Linux Kernel MMC Storage driver OverviewLinux Kernel MMC Storage driver Overview
Linux Kernel MMC Storage driver OverviewRajKumar Rampelli
 
Linux PCI device driver
Linux PCI device driverLinux PCI device driver
Linux PCI device driver艾鍗科技
 

What's hot (20)

Linux Internals - Part II
Linux Internals - Part IILinux Internals - Part II
Linux Internals - Part II
 
Arm device tree and linux device drivers
Arm device tree and linux device driversArm device tree and linux device drivers
Arm device tree and linux device drivers
 
SPI Drivers
SPI DriversSPI Drivers
SPI Drivers
 
I2c drivers
I2c driversI2c drivers
I2c drivers
 
Linux-Internals-and-Networking
Linux-Internals-and-NetworkingLinux-Internals-and-Networking
Linux-Internals-and-Networking
 
U Boot or Universal Bootloader
U Boot or Universal BootloaderU Boot or Universal Bootloader
U Boot or Universal Bootloader
 
Network Drivers
Network DriversNetwork Drivers
Network Drivers
 
用Raspberry Pi 學Linux I2C Driver
用Raspberry Pi 學Linux I2C Driver用Raspberry Pi 學Linux I2C Driver
用Raspberry Pi 學Linux I2C Driver
 
Kernel Recipes 2015: Representing device-tree peripherals in ACPI
Kernel Recipes 2015: Representing device-tree peripherals in ACPIKernel Recipes 2015: Representing device-tree peripherals in ACPI
Kernel Recipes 2015: Representing device-tree peripherals in ACPI
 
U-Boot presentation 2013
U-Boot presentation  2013U-Boot presentation  2013
U-Boot presentation 2013
 
Linux Initialization Process (2)
Linux Initialization Process (2)Linux Initialization Process (2)
Linux Initialization Process (2)
 
Embedded Linux Kernel - Build your custom kernel
Embedded Linux Kernel - Build your custom kernelEmbedded Linux Kernel - Build your custom kernel
Embedded Linux Kernel - Build your custom kernel
 
Linux Ethernet device driver
Linux Ethernet device driverLinux Ethernet device driver
Linux Ethernet device driver
 
Device Tree for Dummies (ELC 2014)
Device Tree for Dummies (ELC 2014)Device Tree for Dummies (ELC 2014)
Device Tree for Dummies (ELC 2014)
 
Linux Kernel MMC Storage driver Overview
Linux Kernel MMC Storage driver OverviewLinux Kernel MMC Storage driver Overview
Linux Kernel MMC Storage driver Overview
 
Embedded linux network device driver development
Embedded linux network device driver developmentEmbedded linux network device driver development
Embedded linux network device driver development
 
USB Drivers
USB DriversUSB Drivers
USB Drivers
 
Block Drivers
Block DriversBlock Drivers
Block Drivers
 
Linux Internals - Part I
Linux Internals - Part ILinux Internals - Part I
Linux Internals - Part I
 
Linux PCI device driver
Linux PCI device driverLinux PCI device driver
Linux PCI device driver
 

Viewers also liked (16)

File System Modules
File System ModulesFile System Modules
File System Modules
 
Serial Drivers
Serial DriversSerial Drivers
Serial Drivers
 
Introduction to Linux Drivers
Introduction to Linux DriversIntroduction to Linux Drivers
Introduction to Linux Drivers
 
References
ReferencesReferences
References
 
Kernel Debugging & Profiling
Kernel Debugging & ProfilingKernel Debugging & Profiling
Kernel Debugging & Profiling
 
Embedded C
Embedded CEmbedded C
Embedded C
 
gcc and friends
gcc and friendsgcc and friends
gcc and friends
 
Character Drivers
Character DriversCharacter Drivers
Character Drivers
 
Platform Drivers
Platform DriversPlatform Drivers
Platform Drivers
 
Audio Drivers
Audio DriversAudio Drivers
Audio Drivers
 
Kernel Programming
Kernel ProgrammingKernel Programming
Kernel Programming
 
Low-level Accesses
Low-level AccessesLow-level Accesses
Low-level Accesses
 
Linux Porting
Linux PortingLinux Porting
Linux Porting
 
BeagleBoard-xM Bootloaders
BeagleBoard-xM BootloadersBeagleBoard-xM Bootloaders
BeagleBoard-xM Bootloaders
 
BeagleBone Black Bootloaders
BeagleBone Black BootloadersBeagleBone Black Bootloaders
BeagleBone Black Bootloaders
 
File Systems
File SystemsFile Systems
File Systems
 

Similar to PCI Drivers

Slideshare - PCIe
Slideshare - PCIeSlideshare - PCIe
Slideshare - PCIeJin Wu
 
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
 
PCI_Express_Basics_Background.pdf
PCI_Express_Basics_Background.pdfPCI_Express_Basics_Background.pdf
PCI_Express_Basics_Background.pdfzahixdd
 
Revisit DCA, PCIe TPH and DDIO
Revisit DCA, PCIe TPH and DDIORevisit DCA, PCIe TPH and DDIO
Revisit DCA, PCIe TPH and DDIOHisaki Ohara
 
101 1.1 hardware settings v2
101 1.1 hardware settings v2101 1.1 hardware settings v2
101 1.1 hardware settings v2Acácio Oliveira
 
Track c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -eveTrack c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -evechiportal
 
my Windows 7 info
my Windows 7 infomy Windows 7 info
my Windows 7 infoisky guard
 
DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...
DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...
DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...Felipe Prado
 
Developing a Windows CE OAL.ppt
Developing a Windows CE OAL.pptDeveloping a Windows CE OAL.ppt
Developing a Windows CE OAL.pptKundanSingh887495
 

Similar to PCI Drivers (20)

SPI Drivers
SPI DriversSPI Drivers
SPI Drivers
 
BeagleBone Black Bootloaders
BeagleBone Black BootloadersBeagleBone Black Bootloaders
BeagleBone Black Bootloaders
 
Slideshare - PCIe
Slideshare - PCIeSlideshare - PCIe
Slideshare - PCIe
 
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_Express_Basics_Background.pdf
PCI_Express_Basics_Background.pdfPCI_Express_Basics_Background.pdf
PCI_Express_Basics_Background.pdf
 
101 1.1 hardware settings
101 1.1 hardware settings101 1.1 hardware settings
101 1.1 hardware settings
 
haifux-pcie.pdf
haifux-pcie.pdfhaifux-pcie.pdf
haifux-pcie.pdf
 
Linux Network Management
Linux Network ManagementLinux Network Management
Linux Network Management
 
Revisit DCA, PCIe TPH and DDIO
Revisit DCA, PCIe TPH and DDIORevisit DCA, PCIe TPH and DDIO
Revisit DCA, PCIe TPH and DDIO
 
Embedded I/O Management
Embedded I/O ManagementEmbedded I/O Management
Embedded I/O Management
 
Kernel Debugging & Profiling
Kernel Debugging & ProfilingKernel Debugging & Profiling
Kernel Debugging & Profiling
 
101 1.1 hardware settings v2
101 1.1 hardware settings v2101 1.1 hardware settings v2
101 1.1 hardware settings v2
 
Track c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -eveTrack c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -eve
 
Slimline Open Firmware
Slimline Open FirmwareSlimline Open Firmware
Slimline Open Firmware
 
my Windows 7 info
my Windows 7 infomy Windows 7 info
my Windows 7 info
 
1.1 hardware settings v2
1.1 hardware settings v21.1 hardware settings v2
1.1 hardware settings v2
 
DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...
DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...
DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...
 
Developing a Windows CE OAL.ppt
Developing a Windows CE OAL.pptDeveloping a Windows CE OAL.ppt
Developing a Windows CE OAL.ppt
 
Bootloaders
BootloadersBootloaders
Bootloaders
 
Resume
ResumeResume
Resume
 

More from Anil Kumar Pugalia (20)

File System Modules
File System ModulesFile System Modules
File System Modules
 
Processes
ProcessesProcesses
Processes
 
System Calls
System CallsSystem Calls
System Calls
 
Introduction to Linux
Introduction to LinuxIntroduction to Linux
Introduction to Linux
 
Embedded Software Design
Embedded Software DesignEmbedded Software Design
Embedded Software Design
 
Playing with R L C Circuits
Playing with R L C CircuitsPlaying with R L C Circuits
Playing with R L C Circuits
 
Mobile Hacking using Linux Drivers
Mobile Hacking using Linux DriversMobile Hacking using Linux Drivers
Mobile Hacking using Linux Drivers
 
Shell Scripting
Shell ScriptingShell Scripting
Shell Scripting
 
Functional Programming with LISP
Functional Programming with LISPFunctional Programming with LISP
Functional Programming with LISP
 
Power of vi
Power of viPower of vi
Power of vi
 
"make" system
"make" system"make" system
"make" system
 
Hardware Design for Software Hackers
Hardware Design for Software HackersHardware Design for Software Hackers
Hardware Design for Software Hackers
 
RPM Building
RPM BuildingRPM Building
RPM Building
 
Linux User Space Debugging & Profiling
Linux User Space Debugging & ProfilingLinux User Space Debugging & Profiling
Linux User Space Debugging & Profiling
 
System Calls
System CallsSystem Calls
System Calls
 
Timers
TimersTimers
Timers
 
Threads
ThreadsThreads
Threads
 
Synchronization
SynchronizationSynchronization
Synchronization
 
Processes
ProcessesProcesses
Processes
 
Signals
SignalsSignals
Signals
 

Recently uploaded

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 

Recently uploaded (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 

PCI Drivers

  • 1. © 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Peripheral Component Interconnect (PCI) Drivers
  • 2. 2© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. What to Expect? PCI Subsystem Coding Details of a PCI Device Driver Browsing Sample Code
  • 3. 3© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. PCI Prologue Developed by Intel as a replacement for ISA More of a processor (specific) bus for x86 architectures Replacing Features Plug n Play Platform independent Fast Hardware Addressing Through South Bridge (PCI Controller) Buses (upto 256) → Devices (upto 32) → Functions (upto 8)
  • 4. 4© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Kernel Aspect Organized as PCI Core (driver of the PCI Controller) PCI Drivers (device drivers) Kernel Windows for PCI /proc/bus/pci/devices (Try cat) /sys/bus/pci/devices (Try tree) Command: lspci
  • 5. 5© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Dynamic Device Configuration What Configuration? Device Base Address(es) Register Space(s) Memory(s) Interrupt Vectors ... Done during Bootup by BIOS, Or PCI Core (Bootloader or Kernel) Configured by the time, driver comes up But, where is this configuration stored?
  • 6. 6© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. PCI Device Configuration Space Vendor ID BIST Header Type Lat Timer Cache Line Class Code Rev ID Status Register Command Register Device ID 0x0 0xF Base Address 0 CardBus CIS pointerBase Address 5Base Address 4 Base Address 3Base Address 2Base Address 1 Subsystem Vendor ID Subsystem Device ID Expansion ROM Base Address IRQ Line IRQ Pin Min Gnt Max Lat 0x00 0x30 0x20 0x10 Reserved
  • 7. 7© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. PCI Device Config Space Access Header: <linux/pci.h> APIs int pci_read_config_byte(struct pci_dev *dev, int where, u8 *val); int pci_read_config_word(struct pci_dev *dev, int where, u16 *val); int pci_read_config_dword(struct pci_dev *dev, int where, u32 *val); int pci_write_config_byte(struct pci_dev *dev, int where, u8 *val); int pci_write_config_word(struct pci_dev *dev, int where, u16 *val); int pci_write_config_dword(struct pci_dev *dev, int where, u32 *val); NB struct pci_dev *dev would be available as parameter to probe()
  • 8. 8© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Standard PCI Device Access API Upto 6 Memory or I/O regions Header: <linux/pci.h> APIs unsigned long pci_resource_start(dev, bar); unsigned long pci_resource_len(dev, bar); unsigned long pci_resource_flags(dev, bar); Flags IORESOURCE_IO IORESOURCE_MEM IORESOURCE_PREFETCH
  • 9. 9© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. PCI Driver Registration int pci_register_driver(struct pci_driver *drv); int pci_unregister_driver(struct pci_driver *drv); struct pci_driver const char *name const struct pci_dev_id *id_table; PCI_DEVICE(vendor, device); PCI_DEVICE_CLASS(dev_class, dev_class_mask); int (*probe)(pci_dev, id_table); void (*remove)(pci_dev); Header: <linux/pci.h>
  • 10. 10© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Typical 'probe' Function int probe(struct pci_dev *dev, struct pci_dev_id *id) { /* Enable the PCI Device */ pci_enable_device(dev); ... /* Acquire PCI Device's regions */ pci_request_regions(dev, “label”); ... /* Possibly map I/Os */ ... pci_set_drvdata(dev, <pvt_data_ptr>); // Optional ... /* Register the vertical */ ... return 0; /* Claimed. Negative for not Claimed */ }
  • 11. 11© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Typical 'remove' Function void remove(struct pci_dev *dev) { /* Unregister the vertical */ ... pci_set_drvdata(dev, NULL); // Optional ... /* Possibly unmap I/Os */ ... /* Release PCI Device's regions */ pci_release_regions(dev); ... /* Disable the PCI Device */ pci_disable_device(dev); }
  • 12. 12© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Old-style PCI Probing & Getting struct pci_dev *pci_find_*(vendor, device, from); struct pci_dev *pci_get_device(v, d, from); struct pci_dev *pci_get_subsys(v, d, ssv, ssd, f); struct pci_dev *pci_get_slot(bus, devfn); pci_dev_put(pci_dev);
  • 13. © 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. DMA Mapping APIs dma_addr_t pci_map_single(struct pci_dev *, void *, size_t, int dir); void pci_unmap_single(struct pci_dev *, dma_addr_t, size_t, int dir); Directions PCI_DMA_BIDIRECTIONAL PCI_DMA_TODEVICE PCI_DMA_FROMDEVICE Header: <linux/pci.h> To Device PM VM PA VA From Device
  • 14. © 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. DMA Allocation PM VM APIs void *pci_alloc_consistent(struct pci_dev *, size_t, dma_addr_t *); void pci_free_consistent(struct pci_dev *, size_t, void *, dma_addr_t); int pci_set_dma_mask(struct pci_dev *, u64 mask); Header: <linux/pci.h> PA VA
  • 15. 15© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. What all have we learnt? PCI Subsystem Coding Details of a PCI Device Driver Browsing Sample Code DMA with PCI
  • 16. 16© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Any Queries?