| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | #ifndef PCI_H |
|---|
| 20 | #define PCI_H |
|---|
| 21 | |
|---|
| 22 | #include <console.h> |
|---|
| 23 | #include <typedefs.h> |
|---|
| 24 | |
|---|
| 25 | struct PciBus |
|---|
| 26 | { |
|---|
| 27 | int index; |
|---|
| 28 | struct ListHead next; |
|---|
| 29 | struct ListHead deviceList; |
|---|
| 30 | }; |
|---|
| 31 | |
|---|
| 32 | struct PciDevice |
|---|
| 33 | { |
|---|
| 34 | struct PciBus* bus; |
|---|
| 35 | BYTE dev,func; |
|---|
| 36 | WORD vendorId,deviceId; |
|---|
| 37 | BYTE devClass,subClass,irq; |
|---|
| 38 | WORD subVendor, subDevice; |
|---|
| 39 | DWORD spaces[6]; |
|---|
| 40 | void* driverData; |
|---|
| 41 | |
|---|
| 42 | struct ListHead next; |
|---|
| 43 | }; |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | struct PciBios |
|---|
| 47 | { |
|---|
| 48 | DWORD magicNumber; |
|---|
| 49 | DWORD physEntry; |
|---|
| 50 | BYTE version; |
|---|
| 51 | BYTE length; |
|---|
| 52 | BYTE crc; |
|---|
| 53 | BYTE reserved[5]; |
|---|
| 54 | }PACKED; |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | #define PCI_VENDOR_ID 0x00 |
|---|
| 58 | #define PCI_DEVICE_ID 0x02 |
|---|
| 59 | #define PCI_COMMAND 0x04 |
|---|
| 60 | #define PCI_COMMAND_IO 0x01 |
|---|
| 61 | #define PCI_COMMAND_MEM 0x02 |
|---|
| 62 | #define PCI_COMMAND_MASTER 0x04 |
|---|
| 63 | #define PCI_SUBSYS_VENDOR_ID 0x2C |
|---|
| 64 | #define PCI_SUBSYS_ID 0x2E |
|---|
| 65 | |
|---|
| 66 | extern int (*PciRead)(int bus, int dev, int func, int reg, int bytes, DWORD* val); |
|---|
| 67 | extern int (*PciWrite)(int bus, int dev, int func, int reg, DWORD v, int bytes); |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | int PciDetectBios(); |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | #define PCI_VENDOR_INVALID(vendorId) (((vendorId) == 0xFFFF) || ((vendorId) == 0x0000)) |
|---|
| 74 | #define PCI_RES_BEGIN_MASK(addressReg) ((addressReg) & 0xFFFFFFF0) |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | #define PCI_ID_ANY (~0) |
|---|
| 81 | |
|---|
| 82 | struct PciDeviceId |
|---|
| 83 | { |
|---|
| 84 | DWORD vendorId, deviceId; |
|---|
| 85 | DWORD subVendor, subDevice; |
|---|
| 86 | DWORD class, classMask; |
|---|
| 87 | void* data; |
|---|
| 88 | }; |
|---|
| 89 | |
|---|
| 90 | struct PciDriver |
|---|
| 91 | { |
|---|
| 92 | char* name; |
|---|
| 93 | struct PciDeviceId* idTable; |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | int (*initOne)(struct PciDevice* device, struct PciDeviceId* devId); |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | struct ListHead next; |
|---|
| 100 | }; |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | int PciEnableDevice(struct PciDevice* device); |
|---|
| 104 | int PciRegisterDriver(struct PciDriver* pciDriver); |
|---|
| 105 | int PciResourceStart(struct PciDevice* device, int index); |
|---|
| 106 | int PciWriteConfigByte(struct PciDevice* device, int reg, BYTE value); |
|---|
| 107 | int PciReadConfigByte(struct PciDevice* device, int reg, BYTE* value); |
|---|
| 108 | |
|---|
| 109 | #endif |
|---|