// // Created by rick on 02-02-21. // #ifndef NEW_KERNEL_PCI_H #define NEW_KERNEL_PCI_H #include #define PCI_CLASS_MASS_STORAGE 0x01 // class MASS STORAGE 1 #define PCI_SUB_CLASS_IDE 0x01 #define PCI_REGISTER_OK 0 #define PCI_REGISTER_ERR_FULL (-1) #define PCI_VALIDATE_OK 0 #define PCI_VALIDATE_FAIL 1 #define PCI_INIT_OK 0 #define PCI_INIT_FAIL 1 #define PCI_HEADER_TYPE_MULTI_FUNC 0x80 #define PCI_HEADER_TYPE_ENDPOINT 0x00 #define PCI_HEADER_TYPE_PCI_PCI_BRIDGE 0x01 #define PCI_HEADER_TYPE_PCI_CARDBUS_BRIDGE 0x02 #define PCI_CONFIG_VENDOR_ID 0x00 #define PCI_CONFIG_DEVICE_ID 0x02 #define PCI_CONFIG_COMMAND 0x04 #define PCI_CONFIG_STATUS 0x06 #define PCI_CONFIG_REVISION_ID 0x08 #define PCI_CONFIG_PROG_IF 0x09 #define PCI_CONFIG_SUBCLASS 0x0A #define PCI_CONFIG_CLASS_CODE 0x0B #define PCI_CONFIG_CACHE_LINE_SIZE 0x0C #define PCI_CONFIG_LATENCY_TIMER 0x0D #define PCI_CONFIG_HEADER_TYPE 0x0E #define PCI_CONFIG_BIST 0x0F #define PCI_CONFIG_BAR0 0x10 #define PCI_CONFIG_BAR1 0x14 #define PCI_CONFIG_BAR2 0x18 #define PCI_CONFIG_BAR3 0x1C #define PCI_CONFIG_BAR4 0x20 #define PCI_CONFIG_BAR5 0x24 #define PCI_CONFIG_CARDBUS_CIS_P 0x28 #define PCI_CONFIG_SUBSYSTEM_VENDOR_ID 0x2C #define PCI_CONFIG_SUBSYSTEM_ID 0x2E #define PCI_CONFIG_EXPANSION_ROM_ADDR 0x30 #define PCI_CONFIG_CAP_POINTER 0x34 #define PCI_CONFIG_INTERRUPT_LINE 0x3C #define PCI_CONFIG_INTERRUPT_PIN 0x3D #define PCI_CONFIG_MAX_GRANT 0x3E #define PCI_CONFIG_MAX_LATENCY 0x3F #define PCI_INTERRUPT_LINE_DISABLED 0xff typedef struct pci_driver pci_driver; typedef struct pci_device pci_device; typedef uint8_t (*pci_driver_validate)(const pci_device *); typedef uint8_t (*pci_driver_initialize)(pci_device *); typedef struct pci_driver { const char *name; const char *description; uint8_t order; uint8_t pci_class; uint8_t pci_subclass; struct { uint8_t pci_use_subclass: 1; }; pci_driver_validate validate; pci_driver_initialize initialize; } pci_driver; typedef struct { uint32_t address; uint32_t size; uint8_t present: 1; uint8_t is_io_space: 1; uint8_t type: 2; uint8_t prefetchable: 1; } bar_info; typedef struct pci_device { uint8_t bus; uint8_t slot; uint8_t func; union { struct { uint16_t vendorId; uint16_t deviceId; }; uint32_t config_line_0; }; union { struct { uint8_t revisionId; uint8_t programInterface; uint8_t subclass; uint8_t class; }; uint32_t config_line_2; }; union { struct { uint8_t cacheLineSize; uint8_t latencyTimer; uint8_t headerType; uint8_t bist; }; uint32_t config_line_3; }; bar_info bar0; bar_info bar1; bar_info bar2; bar_info bar3; bar_info bar4; bar_info bar5; const pci_driver *pci_driver; struct { uint8_t present: 1; } device_state; struct { uint8_t initialized: 1; } driver_state; } pci_device; void pci_print_info(); uint32_t pci_register_driver(const pci_driver *pci_driver); void pci_sort_drivers(); void pci_init_drivers(); void pci_scan(); uint32_t pci_config_read_double_word(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset); uint16_t pci_config_read_word(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset); uint8_t pci_config_read_byte(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset); void pci_config_write_double_word(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset, uint32_t value); void pci_config_write_word(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset, uint16_t value); void pci_config_write_byte(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset, uint8_t value); void pci_init_bar(pci_device *device, uint8_t bar_index); #endif //NEW_KERNEL_PCI_H