61 lines
2.1 KiB
C
61 lines
2.1 KiB
C
#ifndef __PCI_H
|
|
#define __PCI_H
|
|
|
|
#define PCI_COMMAND_STATUS_REG 0x04
|
|
|
|
#define PCI_COMMAND_IO_ENABLE 0x00000001
|
|
#define PCI_COMMAND_MEM_ENABLE 0x00000002
|
|
#define PCI_COMMAND_MASTER_ENABLE 0x00000004
|
|
#define PCI_COMMAND_CAPABALITES_LIST 0x00000010
|
|
|
|
#define PCI_CAP_REG 0x34
|
|
// The bottom two bits are reserved and have to be masked off
|
|
#define PCI_CAP_MASK 0xfc
|
|
|
|
#define PCI_CAP_TYPE 0
|
|
#define PCI_CAP_NEXT 1
|
|
#define PCI_CAP_CFG_TYPE 3
|
|
#define PCI_CAP_BAR 4
|
|
#define PCI_CAP_OFF 8 // 05 byte is padding
|
|
#define PCI_CAP_POINTER(reg) (reg & ((1 << 8) - 1) << 0)
|
|
|
|
// The vendor ID is the last 16 bits of the ID register
|
|
#define PCI_VENDOR_ID(value) (value & ((1 << 16) - 1) << 0)
|
|
|
|
// The device ID if the high 16 bits of the ID register
|
|
#define PCI_DEVICE_ID(value) ((value & ((1 << 16) - 1) << 16) >> 16)
|
|
/*
|
|
* PCI config space BAR offset
|
|
*/
|
|
#define PCI_CFG_BAR_OFF 0x10
|
|
#define PCI_CFG_BAR_END 0x28
|
|
|
|
struct pci_device {
|
|
unsigned short vendor;
|
|
unsigned short device;
|
|
unsigned char header_type;
|
|
unsigned char classtype;
|
|
unsigned char subclasstype;
|
|
unsigned short bus;
|
|
unsigned short slot;
|
|
unsigned short func;
|
|
unsigned int base[6];
|
|
unsigned int size[6];
|
|
unsigned char type[6];
|
|
unsigned char irq;
|
|
|
|
unsigned char cap[6]; // Maps cap type to offset within the pci config space.
|
|
unsigned char cap_bar[6]; // Maps cap type to their BAR number
|
|
unsigned long cap_off[6]; // Map cap type to offset within bar
|
|
};
|
|
|
|
extern void init_pci(void);
|
|
extern int pci_find_device(unsigned char classt, unsigned char subclasst, struct pci_device **device, int offset);
|
|
extern int pci_find_device_by_vendor(unsigned short vendort, unsigned short devicet, struct pci_device **device, int offset);
|
|
extern int pci_find_device_by_vendor_virtio(unsigned short subsystemt, struct pci_device **device, int offset);
|
|
extern void pci_set_master(struct pci_device *dev, int enable);
|
|
extern void pci_set_mem_enable(struct pci_device *dev, int enable);
|
|
extern void pci_set_io_enable(struct pci_device *dev, int enable);
|
|
extern int pci_fill_capabilities(struct pci_device *dev);
|
|
extern int pci_dev_info(unsigned char *buffer, int len, int last_pci_dev);
|
|
#endif |