|
ginnOS
The reference: libc, the libraries and the kernel
|
#include "pci.h"#include "kernel/sync/spinlock.h"#include "arch/arch.h"#include "arch/x86/cpu/io.h"#include "common/memory.h"#include "kernel/klog/klog.h"Macros | |
| #define | CONFIG_ADDRESS 0xCF8 |
| PCI enumeration with configuration mechanism #1: write the address of a register (bus, device, function, offset) to port 0xCF8, then read or write its 32-bit value at port 0xCFC. | |
| #define | CONFIG_DATA 0xCFC |
| #define | PCI_VENDOR_ID 0x00 |
| #define | PCI_DEVICE_ID 0x02 |
| #define | PCI_STATUS 0x06 |
| #define | PCI_REVISION 0x08 |
| #define | PCI_PROG_IF 0x09 |
| #define | PCI_SUBCLASS 0x0A |
| #define | PCI_CLASS 0x0B |
| #define | PCI_HEADER_TYPE 0x0E |
| #define | PCI_BAR0 0x10 |
| #define | PCI_CAPABILITIES 0x34 |
| #define | PCI_IRQ_LINE 0x3C |
| #define | PCI_IRQ_PIN 0x3D |
| #define | STATUS_CAPABILITIES 0x0010 |
| #define | CAP_MSI 0x05 |
| #define | CAP_MSIX 0x11 |
Functions | |
| 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. | |
| 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. | |
| const char * | pci_class_name (const pci_device_t *dev) |
| a short name for a class, for /proc/pci (for example "SATA controller"). | |
| #define CONFIG_ADDRESS 0xCF8 |
PCI enumeration with configuration mechanism #1: write the address of a register (bus, device, function, offset) to port 0xCF8, then read or write its 32-bit value at port 0xCFC.
locking: pci_init runs once at boot before other users; later accesses are each one out/in pair with interrupts off.
| #define CONFIG_DATA 0xCFC |
| #define PCI_VENDOR_ID 0x00 |
| #define PCI_DEVICE_ID 0x02 |
| #define PCI_STATUS 0x06 |
| #define PCI_REVISION 0x08 |
| #define PCI_PROG_IF 0x09 |
| #define PCI_SUBCLASS 0x0A |
| #define PCI_CLASS 0x0B |
| #define PCI_HEADER_TYPE 0x0E |
| #define PCI_BAR0 0x10 |
| #define PCI_CAPABILITIES 0x34 |
| #define PCI_IRQ_LINE 0x3C |
| #define PCI_IRQ_PIN 0x3D |
| #define STATUS_CAPABILITIES 0x0010 |
| #define CAP_MSI 0x05 |
| #define CAP_MSIX 0x11 |
| 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.
| 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. |
| const char * pci_class_name | ( | const pci_device_t * | dev | ) |
a short name for a class, for /proc/pci (for example "SATA controller").