The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
pci.h File Reference

PCI bus enumeration through the legacy configuration ports. More...

#include "common/stdint.h"

Go to the source code of this file.

Data Structures

struct  pci_bar_t
struct  pci_device_t

Macros

#define PCI_MAX_DEVICES   64
#define PCI_BAR_COUNT   6
#define PCI_CLASS_STORAGE   0x01
#define PCI_SUBCLASS_SATA   0x06
#define PCI_SUBCLASS_NVME   0x08
#define PCI_CLASS_MULTIMEDIA   0x04
#define PCI_SUBCLASS_AC97   0x01
#define PCI_SUBCLASS_HDA   0x03
#define PCI_CLASS_BRIDGE   0x06
#define PCI_CLASS_SERIAL   0x0C
#define PCI_SUBCLASS_USB   0x03
#define PCI_COMMAND   0x04
#define PCI_COMMAND_IO   0x0001
#define PCI_COMMAND_MEMORY   0x0002
#define PCI_COMMAND_BUS_MASTER   0x0004
#define PCI_COMMAND_INTX_OFF   0x0400

Functions

uint32_t pci_init (void)
 enumerate the PCI bus.
uint32_t pci_device_count (void)
 the number of functions pci_init found.
pci_device_t * pci_device_at (uint32_t index)
 a function by its index in the table.
pci_device_t * pci_find_class (uint8_t class_code, uint8_t subclass, int prog_if, uint32_t nth)
 the nth function of a class, subclass and programming interface.
uint32_t pci_read32 (const pci_device_t *dev, uint8_t offset)
 read or write the configuration space of a function (offsets are aligned to the width).
uint16_t pci_read16 (const pci_device_t *dev, uint8_t offset)
uint8_t pci_read8 (const pci_device_t *dev, uint8_t offset)
void pci_write32 (const pci_device_t *dev, uint8_t offset, uint32_t value)
void pci_write16 (const pci_device_t *dev, uint8_t offset, uint16_t value)
void pci_enable_bus_master (const pci_device_t *dev)
 turn on memory decoding and bus mastering (DMA) for a function.
const char * pci_class_name (const pci_device_t *dev)
 a short name for a class, for /proc/pci (for example "SATA controller").

Detailed Description

PCI bus enumeration through the legacy configuration ports.

pci_init reads the configuration space of every function on every bus (ports 0xCF8 and 0xCFC) and keeps a table of what it finds: the ids, the class, the BARs with their sizes, the interrupt line and pin, and where the MSI and MSI-X capabilities are. drivers find their device by class or by vendor and device id.

Macro Definition Documentation

◆ PCI_MAX_DEVICES

#define PCI_MAX_DEVICES   64

◆ PCI_BAR_COUNT

#define PCI_BAR_COUNT   6

◆ PCI_CLASS_STORAGE

#define PCI_CLASS_STORAGE   0x01

◆ PCI_SUBCLASS_SATA

#define PCI_SUBCLASS_SATA   0x06

◆ PCI_SUBCLASS_NVME

#define PCI_SUBCLASS_NVME   0x08

◆ PCI_CLASS_MULTIMEDIA

#define PCI_CLASS_MULTIMEDIA   0x04

◆ PCI_SUBCLASS_AC97

#define PCI_SUBCLASS_AC97   0x01

◆ PCI_SUBCLASS_HDA

#define PCI_SUBCLASS_HDA   0x03

◆ PCI_CLASS_BRIDGE

#define PCI_CLASS_BRIDGE   0x06

◆ PCI_CLASS_SERIAL

#define PCI_CLASS_SERIAL   0x0C

◆ PCI_SUBCLASS_USB

#define PCI_SUBCLASS_USB   0x03

◆ PCI_COMMAND

#define PCI_COMMAND   0x04

◆ PCI_COMMAND_IO

#define PCI_COMMAND_IO   0x0001

◆ PCI_COMMAND_MEMORY

#define PCI_COMMAND_MEMORY   0x0002

◆ PCI_COMMAND_BUS_MASTER

#define PCI_COMMAND_BUS_MASTER   0x0004

◆ PCI_COMMAND_INTX_OFF

#define PCI_COMMAND_INTX_OFF   0x0400

Function Documentation

◆ pci_init()

uint32_t pci_init ( void )

enumerate the PCI bus.

call once, before the drivers that use PCI.

Returns
the number of functions found.

◆ pci_device_count()

uint32_t pci_device_count ( void )

the number of functions pci_init found.

◆ pci_device_at()

pci_device_t * pci_device_at ( uint32_t index)

a function by its index in the table.

Returns
the function, or NULL if index is out of range.

◆ pci_find_class()

pci_device_t * pci_find_class ( uint8_t class_code,
uint8_t subclass,
int prog_if,
uint32_t nth )

the nth function of a class, subclass and programming interface.

Parameters
prog_ifthe programming interface, or -1 for any.
nth0 for the first match.
Returns
the function, or NULL if there is no such match.

◆ pci_read32()

uint32_t pci_read32 ( const pci_device_t * dev,
uint8_t offset )

read or write the configuration space of a function (offsets are aligned to the width).

◆ pci_read16()

uint16_t pci_read16 ( const pci_device_t * dev,
uint8_t offset )

◆ pci_read8()

uint8_t pci_read8 ( const pci_device_t * dev,
uint8_t offset )

◆ pci_write32()

void pci_write32 ( const pci_device_t * dev,
uint8_t offset,
uint32_t value )

◆ pci_write16()

void pci_write16 ( const pci_device_t * dev,
uint8_t offset,
uint16_t value )

◆ pci_enable_bus_master()

void pci_enable_bus_master ( const pci_device_t * dev)

turn on memory decoding and bus mastering (DMA) for a function.

◆ pci_class_name()

const char * pci_class_name ( const pci_device_t * dev)

a short name for a class, for /proc/pci (for example "SATA controller").