// This file is part of noxos and licensed under the MIT open source license #ifndef NOXOS_PCI_H #define NOXOS_PCI_H #include "utils/stdtypes.h" #include "utils/string.h" typedef enum { PCI_CLASS_UNCLASSIFIED = 0x00, PCI_CLASS_MASS_STORAGE_CONTROLLER = 0x01, PCI_CLASS_NETWORK_CONTROLLER = 0x02, PCI_CLASS_DISPLAY_CONTROLLER = 0x03, PCI_CLASS_MULTIMEDIA_CONTROLLER = 0x04, PCI_CLASS_MEMORY_CONTROLLER = 0x05, PCI_CLASS_BRIDGE = 0x06, PCI_CLASS_SIMPLE_COMMUNICATION_CONTROLLER = 0x07, PCI_CLASS_BASE_SYSTEM_PERIPHERAL = 0x08, PCI_CLASS_INPUT_DEVICE_CONTROLLER = 0x09, PCI_CLASS_DOCKING_STATION = 0x0a, PCI_CLASS_PROCESSOR = 0x0b, PCI_CLASS_SERIAL_BUS_CONTROLLER = 0x0c, PCI_CLASS_WIRELESS_CONTROLLER = 0x0d, PCI_CLASS_INTELLIGENT_CONTROLLER = 0x0e, PCI_CLASS_SATELLITE_COMMUNICATION_CONTROLLER = 0x0f, PCI_CLASS_ENCRYPTION_CONTROLLER = 0x10, PCI_CLASS_SIGNAL_PROCESSING_CONTROLLER = 0x11, PCI_CLASS_PROCESSING_ACCELERATOR = 0x12, PCI_CLASS_NON_ESSENTIAL_INSTRUMENTATION = 0x13, PCI_CLASS_COPROCESSOR = 0x40 } pci_class_E; typedef enum { PCI_SUBCLASS_NON_VGA_COMPATIBLE_UNCLASSIFIED_DEVICE = 0x00, PCI_SUBCLASS_VGA_COMPATIBLE_UNCLASSIFIED_DEVICE = 0x01 } pci_unclassified_sublasses_E; typedef enum { PCI_SUBCLASS_SCSI_BUS_CONTROLLER = 0x00, PCI_SUBCLASS_IDE_CONTROLLER = 0x01, PCI_SUBCLASS_FLOPPY_DISK_CONTROLLER = 0x02, PCI_SUBCLASS_IPI_BUS_CONTROLLER = 0x03, PCI_SUBCLASS_RAID_CONTROLLER = 0x04, PCI_SUBCLASS_ATA_CONTROLLER = 0x05, PCI_SUBCLASS_SERIAL_ATA_CONTROLLER = 0x06, PCI_SUBCLASS_SERIAL_ATTACHED_SCSI_CONTROLLER = 0x07, PCI_SUBCLASS_NON_VOLATILE_MEMORY_CONTROLLER = 0x08, PCI_SUBCLASS_OTHER_MASS_STORAGE_CONTROLLER = 0x80 } pci_mass_storage_controller_subclasses_E; typedef enum { PCI_SUBCLASS_ETHERNET_CONTROLLER = 0x00, PCI_SUBCLASS_TOKEN_RING_CONTROLLER = 0x01, PCI_SUBCLASS_FDDI_CONTROLLER = 0x02, PCI_SUBCLASS_ATM_CONTROLLER = 0x03, PCI_SUBCLASS_ISDN_CONTROLLER = 0x04, PCI_SUBCLASS_WORLDFIP_CONTROLLER = 0x05, PCI_SUBCLASS_PICMG_2_14_MULTI_COMPUTING_CONTROLLER = 0x06, PCI_SUBCLASS_INFINIBAND_NETWORKCONTROLLER = 0x07, PCI_SUBCLASS_FABRIC_CONTROLLER = 0x08, PCI_SUBCLASS_OTHER_NETWORK_CONTROLLER = 0x80 } pci_network_controller_subclasses_E; typedef enum { PCI_SUBCLASS_VGA_COMPATIBLE_CONTROLLER = 0x00, PCI_SUBCLASS_XGA_COMPATIBLE_CONTROLLER = 0x01, PCI_SUBCLASS_3D_CONTROLLER_NOT_VGA_COMPATIBLE = 0x02, PCI_SUBCLASS_OTHER_DISPLAY_CONTROLLER = 0x80 } pci_display_controller_subclasses_E; typedef enum { PCI_SUBCLASS_MULTIMEDIA_VIDEO_CONTROLLER = 0x00, PCI_SUBCLASS_MULTIMEDIA_AUDIO_CONTROLLER = 0x01, PCI_SUBCLASS_COMPUTER_TELEPHONY_DEVICE = 0x02, PCI_SUBCLASS_AUDIO_DEVICE = 0x03, PCI_SUBCLASS_OTHER_MULTIMEDIA_CONTROLLER = 0x80 } pci_multimedia_controller_subclasses_E; typedef enum { PCI_SUBCLASS_RAM_CONTROLLER = 0x00, PCI_SUBCLASS_FLASH_CONTROLLER = 0x01, PCI_SUBCLASS_OTHER_MEMORY_CONTROLLER = 0x80 } pci_memory_controller_subclasses_E; typedef enum { PCI_SUBCLASS_HOST_BRIDGE = 0x00, PCI_SUBCLASS_ISA_BRIDGE = 0x01, PCI_SUBCLASS_EISA_BRIDGE = 0x02, PCI_SUBCLASS_MCA_BRIDGE = 0x03, PCI_SUBCLASS_PCI_TO_PCI_BRIDGE = 0x04, PCI_SUBCLASS_PCMCIA_BRIDGE = 0x05, PCI_SUBCLASS_NUBUS_BRIDGE = 0x06, PCI_SUBCLASS_CARDBUS_BRIDGE = 0x07, PCI_SUBCLASS_RACEWAY_BRIDGE = 0x08, PCI_SUBCLASS_PCI_TO_PCI_BRIDGE_2 = 0x09, PCI_SUBCLASS_INFINIBAND_TO_PCI_HOST_BRIDGE = 0x0a, PCI_SUBCLASS_OTHER_BRIDGE = 0x80 } pci_bridge_subclasses_E; typedef enum { PCI_SUBCLASS_SERIAL_SIMPLE_COMMUNICATION_CONTROLLER = 0x00, PCI_SUBCLASS_PARALLEL_SIMPLE_COMMUNICATION_CONTROLLER = 0x01, PCI_SUBCLASS_MULTIPORT_SERIAL_CONTROLLER = 0x02, PCI_SUBCLASS_MODEM = 0x03, PCI_SUBCLASS_IEEE_488_1_2_GPIB_CONTROLLER = 0x04, PCI_SUBCLASS_SMART_CARD_CONTROLLER = 0x05, PCI_SUBCLASS_OTHER_SIMPLE_COMMUNICATION_CONTROLLER = 0x80 } pci_simple_communication_controller_subclasses_E; typedef enum { PCI_SUBCLASS_PIC = 0x00, PCI_SUBCLASS_DMA_CONTROLLER = 0x01, PCI_SUBCLASS_TIMER = 0x02, PCI_SUBCLASS_RTC_CONTROLLER = 0x03, PCI_SUBCLASS_PCI_HOT_PLUG_CONTROLLER = 0x04, PCI_SUBCLASS_SD_HOST_CONTROLLER = 0x05, PCI_SUBCLASS_IOMMU = 0x06, PCI_SUBCLASS_OTHER_BASE_SYSTEM_PERIPHERAL = 0x80 } pci_base_system_peripheral_subclasses_E; typedef enum { PCI_SUBCLASS_KEYBOARD_CONTROLLER = 0x00, PCI_SUBCLASS_DIGITIZER_PEN = 0x01, PCI_SUBCLASS_MOUSE_CONTROLLER = 0x02, PCI_SUBCLASS_SCANNER_CONTROLLER = 0x03, PCI_SUBCLASS_GAMEPORT_CONTROLLER = 0x04, PCI_SUBCLASS_OTHER_INPUT_DEVICE_CONTROLLER = 0x80 } pci_input_device_controller_subclasses_E; typedef enum { PCI_SUBCLASS_GENERIC_DOCKING_STATION = 0x00, PCI_SUBCLASS_OTHER_DOCKING_STATION = 0x80 } pci_docking_station_subclasses_E; typedef enum { PCI_SUBCLASS_386_PROCESSOR = 0x00, PCI_SUBCLASS_486_PROCESSOR = 0x01, PCI_SUBCLASS_PENTIUM_PROCESSOR = 0x02, PCI_SUBCLASS_PENTIUM_PRO_PROCESSOR = 0x03, PCI_SUBCLASS_ALPHA_PROCESSOR = 0x10, PCI_SUBCLASS_POWERPC_PROCESSOR = 0x20, PCI_SUBCLASS_MIPS_PROCESSOR = 0x30, PCI_SUBCLASS_COPROCESSOR = 0x40, PCI_SUBCLASS_OTHER_PROCESSOR = 0x80 } pci_processor_subclasses_E; typedef enum { PCI_SUBCLASS_FIREWIRE_CONTROLLER = 0x00, PCI_SUBCLASS_ACCESS_BUS_CONTROLLER = 0x01, PCI_SUBCLASS_SSA = 0x02, PCI_SUBCLASS_USB_CONTROLLER = 0x03, PCI_SUBCLASS_FIBRE_CHANNEL = 0x04, PCI_SUBCLASS_SMBUS_CONTROLLER = 0x05, PCI_SUBCLASS_INFINIBAND_SERIAL_BUS_CONTROLLER = 0x06, PCI_SUBCLASS_IPMI_INTERFACE = 0x07, PCI_SUBCLASS_SERCOS_INTERFACE = 0x08, PCI_SUBCLASS_CANBUS_CONTROLLER = 0x09, PCI_SUBCLASS_OTHER_SERIAL_BUS_CONTROLLER = 0x80 } pci_serial_bus_controller_subclasses_E; typedef enum { PCI_SUBCLASS_IRDA_COMPATIBLE_CONTROLLER = 0x00, PCI_SUBCLASS_CONSUMER_IR_CONTROLLER = 0x01, PCI_SUBCLASS_RF_CONTROLLER = 0x10, PCI_SUBCLASS_BLUETOOTH_CONTROLLER = 0x11, PCI_SUBCLASS_BROADBAND_CONTROLLER = 0x12, PCI_SUBCLASS_ETHERNET_CONTROLLER_802_1A = 0x20, PCI_SUBCLASS_ETHERNET_CONTROLLER_802_1B = 0x21, PCI_SUBCLASS_OTHER_WIRELESS_CONTROLLER = 0x80 } pci_wireless_controller_subclasses_E; typedef enum { PCI_SUBCLASS_I20_INTELLIGENT_CONTROLLER = 0x00 } pci_intelligent_controller_subclasses_E; typedef enum { PCI_SUBCLASS_SATELLITE_TV_CONTROLLER = 0x01, PCI_SUBCLASS_SATELLITE_AUDIO_CONTROLLER = 0x02, PCI_SUBCLASS_SATELLITE_VOICE_CONTROLLER = 0x03, PCI_SUBCLASS_SATELLITE_DATA_CONTROLLER = 0x04 } pci_satellite_communication_controller_subclasses_E; typedef enum { PCI_SUBCLASS_NETWORK_AND_COMPUTING_ENCRYPTION_DECRYPTION = 0x00, PCI_SUBCLASS_ENTERTAINMENT_ENCRYPTION_DECRYPTION = 0x10, PCI_SUBCLASS_OTHER_ENCRYPTION_CONTROLLER = 0x80 } pci_encryption_controller_subclasses_E; typedef enum { PCI_SUBCLASS_DPIO_MODULES = 0x00, PCI_SUBCLASS_PERFORMANCE_COUNTERS = 0x01, PCI_SUBCLASS_COMMUNICATION_SYNCHRONIZER = 0x10, PCI_SUBCLASS_SIGNAL_PROCESSING_MANAGEMENT = 0x20, PCI_SUBCLASS_OTHER_SIGNAL_PROCESSING_CONTROLLER = 0x80 } pci_signal_processing_controller_subclasses_E; typedef struct { uint16_t vendor_id; uint16_t device_id; uint16_t command_reg; uint16_t status_reg; uint8_t revision_id; uint8_t progif; // Programming Interface Byte uint8_t subclass; uint8_t main_class; uint8_t cache_line_size; uint8_t latency_timer; uint8_t header_type; uint8_t bist; // Built-in Self-Test } __attribute__((packed)) pci_device_header_T; typedef struct { pci_device_header_T header; uint32_t bar0; uint32_t bar1; uint32_t bar2; uint32_t bar3; uint32_t bar4; uint32_t bar5; uint32_t cardbus_cis_pointer; uint16_t subsystem_vendor_id; uint16_t subsystem_id; uint32_t expansion_rom_base_address; uint8_t capabilities; uint8_t reserved[7]; uint8_t interrupt_line; uint8_t interrupt_pin; uint8_t min_grant; uint8_t max_latency; } __attribute__((packed)) pci_header_0_T; typedef struct pci_device_T pci_device_T; struct pci_device_T { pci_device_header_T* header; void* specific; pci_device_T* prev; pci_device_T* next; }; typedef struct { pci_device_T* devices; } pci_manager_T; void pci_init (); void pci_manager_add_device (pci_device_header_T* header); void pci_manager_remove_device (pci_device_T* device); pci_device_T* pci_manager_find_device (pci_class_E class, uint8_t subclass, uint8_t progif); void pci_manager_dump_devices (); string_t pci_get_subclass_string (pci_class_E class, uint8_t subclass); string_t pci_get_vendor_string (uint16_t vendor_id); #endif // NOXOS_PCI_H