miniOS
x86_64 hobby kernel with SMP, VFS, and POSIX process model
Loading...
Searching...
No Matches
pci.c File Reference

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>
Include dependency graph for pci.c:

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

Detailed Description

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.

Function Documentation

◆ hex16()

void hex16 ( char * out,
uint16_t val )
static

hex16() - Write a 4-character hex representation of val into out[0..3]. Does NOT null-terminate.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hex32()

void hex32 ( char * out,
uint32_t val )
static

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hex8()

void hex8 ( char * out,
uint8_t val )
static

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hex_nibble()

char hex_nibble ( uint8_t n)
static

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

Here is the caller graph for this function:

◆ pci_config_read32()

uint32_t pci_config_read32 ( uint8_t bus,
uint8_t dev,
uint8_t fn,
uint8_t off )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pci_config_write32()

void pci_config_write32 ( uint8_t bus,
uint8_t dev,
uint8_t fn,
uint8_t off,
uint32_t val )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pci_init()

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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pci_populate_sysfs()

void pci_populate_sysfs ( void )
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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pci_write_attr16()

void pci_write_attr16 ( sysfs_node_t * dir,
const char * name,
uint16_t val )
static

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pci_write_attr32()

void pci_write_attr32 ( sysfs_node_t * dir,
const char * name,
uint32_t val )
static

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pci_write_class()

void pci_write_class ( sysfs_node_t * dir,
uint8_t class_code,
uint8_t subclass )
static

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pci_write_dec()

void pci_write_dec ( sysfs_node_t * dir,
const char * name,
uint8_t val )
static

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

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ pci_device_count

int pci_device_count = 0

Number of valid entries in pci_devices[]; set by pci_init().

◆ pci_devices

Global array of discovered PCI devices; populated by pci_init().