Files
my-os-project2/kernel/pci/pci.h
2025-11-23 21:37:12 +01:00

72 lines
1.8 KiB
C

#ifndef PCI_PCI_H_
#define PCI_PCI_H_
#include <stdint.h>
#include <stddef.h>
typedef union {
uint32_t bits;
struct {
uint32_t alwayszero: 2;
uint32_t fieldnum: 6;
uint32_t fnnum: 3;
uint32_t devnum: 5;
uint32_t busnum: 8;
uint32_t resv: 7;
uint32_t enable: 1;
};
} PciDev;
#define PCI_CFG_ADDR 0xCF8
#define PCI_CFG_DATA 0xCFC
#define PCI_VENDORID 0x00
#define PCI_DEVICEID 0x02
#define PCI_CMD 0x04
#define PCI_STATUS 0x06
#define PCI_REVID 0x08
#define PCI_PROGIF 0x09
#define PCI_SUBCLASS 0x0A
#define PCI_CLASS 0x0B
#define PCI_CACHELINESZ 0x0C
#define PCI_LTNCY_TIMER 0x0D
#define PCI_HDRTYPE 0x0E
#define PCI_BIST 0x0F
#define PCI_BAR0 0x10
#define PCI_BAR1 0x14
#define PCI_BAR2 0x18
#define PCI_BAR3 0x1C
#define PCI_BAR4 0x20
#define PCI_BAR5 0x24
#define PCI_INTRLINE 0x3C
#define PCI_SCNDRY_BUS 0x09
#define PCI_HDR_DEV 0
#define PCI_HDR_BRIDGE 1
#define PCI_HDR_CARDBUS 2
#define PCI_DEV_PER_BUS 32
#define PCI_FN_PER_DEV 32
uint32_t pci_read(PciDev dev, uint32_t field);
void pci_write(PciDev dev, uint32_t field, uint32_t v);
uint32_t pci_devtype(PciDev dev);
uint32_t pci_scndrybus(PciDev dev);
uint32_t pci_isend(PciDev dev);
PciDev pci_scanfn(uint16_t vendorid, uint16_t deviceid, uint32_t bus,
uint32_t device, uint32_t fn, int devtype);
PciDev pci_scanbus(uint16_t vendorid, uint16_t deviceid,
uint32_t bus, int devtype);
PciDev pci_scandev(uint16_t vendorid, uint16_t deviceid,
uint32_t bus, uint32_t device, int devtype);
PciDev pci_getdev(uint16_t vendorid, uint16_t deviceid, int devtype);
void pci_init(void);
#define PCI_INIT_ARRAY_MAX 0x100
typedef void (*PciInitFn)(void);
extern PciInitFn PCI_INIT_ARRAY[PCI_INIT_ARRAY_MAX];
#endif // PCI_PCI_H_