|
ginnOS
The reference: libc, the libraries and the kernel
|
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"). | |
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.
| #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 |
| uint32_t pci_init | ( | void | ) |
enumerate the PCI bus.
call once, before the drivers that use PCI.
| 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.
| prog_if | the programming interface, or -1 for any. |
| nth | 0 for the first match. |
| 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").