diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a182310a..7c1234692 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,7 +60,6 @@ add_executable(fastfetch target_link_libraries(fastfetch ${CMAKE_DL_LIBS} - pci ) add_executable(flashfetch @@ -74,5 +73,4 @@ target_compile_definitions(flashfetch PUBLIC target_link_libraries(flashfetch ${CMAKE_DL_LIBS} - pci ) \ No newline at end of file diff --git a/src/modules/gpu.c b/src/modules/gpu.c index d285b0d05..da0d667a1 100644 --- a/src/modules/gpu.c +++ b/src/modules/gpu.c @@ -1,9 +1,9 @@ #include "fastfetch.h" - #include +#include -static void handleGPU(FFinstance* instance, struct pci_access* pacc, struct pci_dev* dev, uint16_t counter) +static void handleGPU(FFinstance* instance, struct pci_access* pacc, struct pci_dev* dev, uint16_t counter, char*(*ffpci_lookup_name)(struct pci_access*, char*, int, int, ...)) { char key[8]; sprintf(key, "GPU%hu", counter); @@ -14,10 +14,10 @@ static void handleGPU(FFinstance* instance, struct pci_access* pacc, struct pci_ char gpu[1024]; char vendor[512]; - pci_lookup_name(pacc, vendor, sizeof(vendor), PCI_LOOKUP_VENDOR, dev->vendor_id, dev->device_id); + ffpci_lookup_name(pacc, vendor, sizeof(vendor), PCI_LOOKUP_VENDOR, dev->vendor_id, dev->device_id); char name[512]; - pci_lookup_name(pacc, name, sizeof(name), PCI_LOOKUP_DEVICE, dev->vendor_id, dev->device_id); + ffpci_lookup_name(pacc, name, sizeof(name), PCI_LOOKUP_DEVICE, dev->vendor_id, dev->device_id); if(strcasecmp(vendor, "Advanced Micro Devices, Inc. [AMD/ATI]") == 0) { @@ -36,26 +36,75 @@ static void handleGPU(FFinstance* instance, struct pci_access* pacc, struct pci_ void ffPrintGPU(FFinstance* instance) { + void* pci = dlopen("libpci.so", RTLD_LAZY); + if(pci == NULL) + { + ffPrintError(instance, "GPU", "dlopen(\"libpci.so\", RTLD_LAZY) == NULL"); + return; + } + + struct pci_access*(*ffpci_alloc)() = dlsym(pci, "pci_alloc"); + if(ffpci_alloc == NULL) + { + ffPrintError(instance, "GPU", "dlsym(pci, \"pci_alloc\") == NULL"); + return; + } + + void(*ffpci_init)(struct pci_access*) = dlsym(pci, "pci_init"); + if(ffpci_init == NULL) + { + ffPrintError(instance, "GPU", "dlsym(pci, \"pci_init\") == NULL"); + return; + } + + void(*ffpci_scan_bus)(struct pci_access*) = dlsym(pci, "pci_scan_bus"); + if(ffpci_scan_bus == NULL) + { + ffPrintError(instance, "GPU", "dlsym(pci, \"pci_init\") == NULL"); + return; + } + + int(*ffpci_fill_info)(struct pci_dev*, int) = dlsym(pci, "pci_fill_info"); + if(ffpci_fill_info == NULL) + { + ffPrintError(instance, "GPU", "dlsym(pci, \"pci_fill_info\") == NULL"); + return; + } + + char*(*ffpci_lookup_name)(struct pci_access*, char*, int, int, ...) = dlsym(pci, "pci_lookup_name"); + if(ffpci_lookup_name == NULL) + { + ffPrintError(instance, "GPU", "dlsym(pci, \"pci_lookup_name\") == NULL"); + return; + } + + void(*ffpci_cleanup)(struct pci_access*) = dlsym(pci, "pci_cleanup"); + if(ffpci_cleanup == NULL) + { + ffPrintError(instance, "GPU", "dlsym(pci, \"pci_cleanup\") == NULL"); + return; + } + uint16_t counter = 0; struct pci_access *pacc; struct pci_dev *dev; - pacc = pci_alloc(); - pci_init(pacc); - pci_scan_bus(pacc); + pacc = ffpci_alloc(); + ffpci_init(pacc); + ffpci_scan_bus(pacc); for (dev=pacc->devices; dev; dev=dev->next) { - pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_CLASS); + ffpci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_CLASS); char class[1024]; - pci_lookup_name(pacc, class, sizeof(class), PCI_LOOKUP_CLASS, dev->device_class); + ffpci_lookup_name(pacc, class, sizeof(class), PCI_LOOKUP_CLASS, dev->device_class); if( strcasecmp("VGA compatible controller", class) == 0 || strcasecmp("3D controller", class) == 0 || strcasecmp("Display controller", class) == 0 ) { - handleGPU(instance, pacc, dev, counter++); + handleGPU(instance, pacc, dev, counter++, ffpci_lookup_name); } } - pci_cleanup(pacc); + ffpci_cleanup(pacc); } \ No newline at end of file