From f5826164936359560ef5b88b97fc953065eb7794 Mon Sep 17 00:00:00 2001 From: Aleksa Vuckovic Date: Fri, 10 Mar 2023 23:17:33 +0100 Subject: pci_info: get_ vendor/class/subclass/progif _str --- kernel/src/devices/pci.c | 52 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 14 deletions(-) (limited to 'kernel/src/devices/pci.c') diff --git a/kernel/src/devices/pci.c b/kernel/src/devices/pci.c index 978e9e9..9862dee 100644 --- a/kernel/src/devices/pci.c +++ b/kernel/src/devices/pci.c @@ -7,17 +7,46 @@ #include #include #include +#include -const char *vendor_name(uint64_t vendor_id) +inline void pci_print_dev(pci_dev *pci_func) { - switch (vendor_id) { - case 0x8086: - return "Intel"; - case 0x1022: - return "AMD"; - default: - return "Unknown"; + const char *vendor_str = get_vendor(pci_func->vendor_id); + const char *class_str = get_class(pci_func->class_); + const char *subclass_str = + get_subclass(pci_func->class_, pci_func->subclass); + const char *progif_str = get_progif( + pci_func->class_, pci_func->subclass, pci_func->progif); + + if (vendor_str != NULL) { + printf("%s", vendor_str); + } else { + printf("%x", pci_func->vendor_id); } + printf(" / "); + + if (class_str != NULL) { + printf("%s", class_str); + } else { + printf("%x", pci_func->class_); + } + printf(" / "); + + if (subclass_str != NULL) { + printf("%s", subclass_str); + } else { + printf("%x", pci_func->subclass); + } + printf(" / "); + + if (progif_str != NULL) { + printf("%s", progif_str); + printf(" / "); + } + + printf("%x", pci_func->device_id); + + printf("\n"); } void enumerate_function(uint64_t dev_addr, uint64_t function) @@ -33,12 +62,7 @@ void enumerate_function(uint64_t dev_addr, uint64_t function) if (pci_func->device_id == 0xFFFF) goto error; - const char *vendor_str = vendor_name(pci_func->vendor_id); - size_t class_str = - pci_func->class_ < sizeof(class_string) ? pci_func->class_ : 0; - - printf("%s, 0x%x, %s, 0x%x\n", vendor_str, pci_func->device_id, - class_string[class_str], pci_func->subclass); + pci_print_dev(pci_func); error: kfree(pci_func); -- cgit v1.2.3