|
miniOS
x86_64 hobby kernel with SMP, VFS, and POSIX process model
|
PCI bus enumeration and /sys/bus/pci/devices/ stub sysfs population. More...
#include <miniOS/drivers/pci.h>#include <miniOS/arch/x86_64/port.h>#include <miniOS/drivers/console.h>#include <miniOS/fs/sysfs.h>#include <miniOS/io.h>#include <string.h>
Functions | |
| uint32_t | pci_config_read32 (uint8_t bus, uint8_t dev, uint8_t fn, uint8_t off) |
| void | pci_config_write32 (uint8_t bus, uint8_t dev, uint8_t fn, uint8_t off, uint32_t val) |
| static char | hex_nibble (uint8_t n) |
| static void | hex8 (char *out, uint8_t val) |
| static void | hex16 (char *out, uint16_t val) |
| static void | hex32 (char *out, uint32_t val) |
| static void | pci_write_attr16 (sysfs_node_t *dir, const char *name, uint16_t val) |
| static void | pci_write_attr32 (sysfs_node_t *dir, const char *name, uint32_t val) |
| static void | pci_write_class (sysfs_node_t *dir, uint8_t class_code, uint8_t subclass) |
| static void | pci_write_dec (sysfs_node_t *dir, const char *name, uint8_t val) |
| static void | pci_populate_sysfs (void) |
| void | pci_init (void) |
Variables | |
| pci_device_t | pci_devices [PCI_MAX_DEVICES] |
| int | pci_device_count = 0 |
PCI bus enumeration and /sys/bus/pci/devices/ stub sysfs population.
Implements pci_init() which scans PCI bus 0, fills the global pci_devices[] array, and creates a static /sys directory tree populated at boot. Also provides the shared pci_config_read32()/pci_config_write32() helpers that replace the duplicates previously in ata.c.
|
static |
hex16() - Write a 4-character hex representation of val into out[0..3]. Does NOT null-terminate.


|
static |
hex32() - Write an 8-character hex representation of val into out[0..7]. Does NOT null-terminate.


|
static |
hex8() - Write a 2-character hex representation of val into out[0..1]. Does NOT null-terminate.


|
static |
hex_nibble() - Convert a 4-bit nibble to its ASCII hex character.





| void pci_init | ( | void | ) |
pci_init() - Enumerate PCI bus 0 and populate /sys/bus/pci/devices/.
Scans all 32 device slots on bus 0. For multi-function devices (header type bit 7 set), iterates functions 0-7; single-function devices use only fn 0. Each discovered function is stored in pci_devices[pci_device_count++]. Capped at PCI_MAX_DEVICES.


|
static |
pci_populate_sysfs() - Build /sys/bus/pci/devices/ using sysfs API.
Creates the directory tree rooted at g_sysfs_root and populates per-device attribute files. Safe to call before ext2 root is mounted since it only touches the in-kernel sysfs node tree.


|
static |
pci_write_attr16() - Create a sysfs file in dir and write "0xXXXX\n".


|
static |
pci_write_attr32() - Create a sysfs file in dir and write "0xNNNNNNNN\n".


|
static |
pci_write_class() - Create a sysfs file in dir and write "0xCCSS\n".


|
static |
pci_write_dec() - Create a sysfs file in dir and write a decimal uint8 + newline.


| int pci_device_count = 0 |
Number of valid entries in pci_devices[]; set by pci_init().
| pci_device_t pci_devices[PCI_MAX_DEVICES] |
Global array of discovered PCI devices; populated by pci_init().