The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
pci.c File Reference
#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").

Macro Definition Documentation

◆ CONFIG_ADDRESS

#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.

◆ CONFIG_DATA

#define CONFIG_DATA   0xCFC

◆ PCI_VENDOR_ID

#define PCI_VENDOR_ID   0x00

◆ PCI_DEVICE_ID

#define PCI_DEVICE_ID   0x02

◆ PCI_STATUS

#define PCI_STATUS   0x06

◆ PCI_REVISION

#define PCI_REVISION   0x08

◆ PCI_PROG_IF

#define PCI_PROG_IF   0x09

◆ PCI_SUBCLASS

#define PCI_SUBCLASS   0x0A

◆ PCI_CLASS

#define PCI_CLASS   0x0B

◆ PCI_HEADER_TYPE

#define PCI_HEADER_TYPE   0x0E

◆ PCI_BAR0

#define PCI_BAR0   0x10

◆ PCI_CAPABILITIES

#define PCI_CAPABILITIES   0x34

◆ PCI_IRQ_LINE

#define PCI_IRQ_LINE   0x3C

◆ PCI_IRQ_PIN

#define PCI_IRQ_PIN   0x3D

◆ STATUS_CAPABILITIES

#define STATUS_CAPABILITIES   0x0010

◆ CAP_MSI

#define CAP_MSI   0x05

◆ CAP_MSIX

#define CAP_MSIX   0x11

Function Documentation

◆ 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_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_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").