90 lines
2.2 KiB
C
90 lines
2.2 KiB
C
#ifndef PCI_PCI_H_
|
|
#define PCI_PCI_H_
|
|
|
|
#include <stdint.h>
|
|
#include <stddef.h>
|
|
|
|
#define PCI_MAKE_ID(bus, dev, fn) (((bus)<<16) | ((dev)<<11) | ((fn)<<8))
|
|
|
|
#define PCI_CONFIG_ADDR 0xCF8
|
|
#define PCI_CONFIG_DATA 0xCFC
|
|
|
|
#define PCI_MULTIFN 0x80
|
|
#define PCI_GENERIC 0x00
|
|
#define PCI_PCI_BRIDGE 0x01
|
|
#define PCI_CARDBUS_BRIDGE 0x02
|
|
|
|
#define PCI_VENDORID 0x00
|
|
#define PCI_DEVICEID 0x02
|
|
#define PCI_CMD 0x04
|
|
#define PCI_STATUS 0x06
|
|
#define PCI_REVID 0x08
|
|
#define PCI_PROGINTF 0x09
|
|
#define PCI_SUBCLASS 0x0A
|
|
#define PCI_CLASSCODE 0x0B
|
|
#define PCI_CACHELINESZ 0x0C
|
|
#define PCI_LATENCY 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_CARBUS_CIS 0x28
|
|
#define PCI_SUBSYS_VENDORID 0x2C
|
|
#define PCI_SUBSYS_DEVICEID 0x2E
|
|
#define PCI_EXPROM 0x30
|
|
#define PCI_CAP 0x34
|
|
#define PCI_INTRLINE 0x3C
|
|
#define PCI_INTRPIN 0x3D
|
|
#define PCI_MIN_GRANT 0x3E
|
|
#define PCI_MAX_LATENCY 0x3F
|
|
|
|
#define PCI_BAR_IO 0x01
|
|
#define PCI_BAR_MEM32 0x02
|
|
#define PCI_BAR_MEM64 0x04
|
|
#define PCI_BAR_PREFETCH 0x08
|
|
|
|
typedef struct {
|
|
union { void *addr; uint16_t port; } u;
|
|
uint64_t size;
|
|
uint32_t flags;
|
|
} PciBar;
|
|
|
|
typedef struct {
|
|
uint16_t vendorid;
|
|
uint16_t deviceid;
|
|
uint8_t classcode;
|
|
uint8_t subclass;
|
|
uint8_t progintf;
|
|
|
|
uint32_t bus, dev, fn;
|
|
} PciDevInfo;
|
|
|
|
typedef struct {
|
|
uint16_t k1;
|
|
uint16_t k2;
|
|
void (*initfn)(PciDevInfo *info);
|
|
} PciMatch;
|
|
|
|
#define PCI_DEV_MAGIC 0xAB0BA
|
|
|
|
typedef struct {
|
|
PciDevInfo devinfo;
|
|
} PciDev;
|
|
|
|
uint8_t pci_read8(uint32_t id, uint32_t reg);
|
|
uint16_t pci_read16(uint32_t id, uint32_t reg);
|
|
uint32_t pci_read32(uint32_t id, uint32_t reg);
|
|
void pci_write8(uint32_t id, uint32_t reg, uint8_t v);
|
|
void pci_write16(uint32_t id, uint32_t reg, uint16_t v);
|
|
void pci_write32(uint32_t id, uint32_t reg, uint32_t v);
|
|
void pci_getbar(PciBar *bar, uint32_t id, uint32_t idx);
|
|
|
|
void pci_init(void);
|
|
|
|
#endif // PCI_PCI_H_
|