Tue, 12 Aug 2025 23:09:53 +0200
1 files changed,
42 insertions(+),
5 deletions(-)
jump to
M
kernel/pci.c
→
kernel/pci.c
@@ -20,12 +20,30 @@
#define DEVICE_ID_BIT_MASK (0xFFFF0000) #define DEVICE_ID_BIT_SHIFT (16) +#define CLASS_CODE_REGISTER (0x08) + +#define CLASS_CODE_BIT_MASK (0xFF000000) +#define CLASS_CODE_BIT_SHIFT (24) + +#define SUBCLASS_CODE_BIT_MASK (0x00FF0000) +#define SUBCLASS_CODE_BIT_SHIFT (16) + +#define HEADER_TYPE_REGISTER (0x0C) + +#define HEADER_TYPE_BIT_MASK (0x00FF0000) +#define HEADER_TYPE_BIT_SHIFT (16) + struct pci_device { uint8_t bus; uint8_t port; uint16_t vendor_id; uint16_t device_id; + + uint8_t class_code; + uint8_t subclass_code; + + uint8_t header_type; struct list_node node; };@@ -78,20 +96,39 @@
list_entry->vendor_id = vendor_id; list_entry->device_id = device_id; - printk("list before first %p last %p\n", pci_devices.first, pci_devices.last); + pci_read_register(&dev, 0, CLASS_CODE_REGISTER, ®_value); + + list_entry->class_code = + (reg_value & CLASS_CODE_BIT_MASK) >> CLASS_CODE_BIT_SHIFT; + list_entry->subclass_code = + (reg_value & SUBCLASS_CODE_BIT_MASK) >> SUBCLASS_CODE_BIT_SHIFT; + + pci_read_register(&dev, 0, HEADER_TYPE_REGISTER, ®_value); + + list_entry->header_type = + (reg_value & HEADER_TYPE_BIT_MASK) >> HEADER_TYPE_BIT_SHIFT; + list_append(&pci_devices, &(list_entry->node)); - printk("list after first %p last %p\n", pci_devices.first, pci_devices.last); num_devices++; } } printk("\nfound %i PCI devices:\n", num_devices); - printk("\n BUS : PORT VENDOR : DEVICE\n"); struct pci_device *entry; LIST_FOR_EACH_ENTRY(&pci_devices, struct pci_device, node, entry) { - printk("- %x:%x %x:%x\n", entry->bus, entry->port, - entry->vendor_id, entry->device_id); + printk( + "- bus: %x\n" + " port: %x\n" + " vendor id: %x\n" + " device id: %x\n" + " class: %x\n" + " subclass: %x\n" + " header type: %x\n", + entry->bus, entry->port, + entry->vendor_id, entry->device_id, + entry->class_code, entry->subclass_code, + entry->header_type); } return 0;