diff --git a/src/detection/gpu/gpu.c b/src/detection/gpu/gpu.c index bf6cde9b6..7400652ad 100644 --- a/src/detection/gpu/gpu.c +++ b/src/detection/gpu/gpu.c @@ -324,7 +324,7 @@ const char* ffDetectGPU(const FFGPUOptions* options, FFlist* result) { return "GPU detection failed"; } -bool ffGPUFillVendorByDeviceName(FFGPUResult* gpu) { +bool ffGPUDetectTypeByVendorAndName(FFGPUResult* gpu) { if (gpu->type != FF_GPU_TYPE_UNKNOWN) { return true; } diff --git a/src/detection/gpu/gpu.h b/src/detection/gpu/gpu.h index 84e1467a1..32b6ff636 100644 --- a/src/detection/gpu/gpu.h +++ b/src/detection/gpu/gpu.h @@ -107,4 +107,4 @@ static inline uint64_t ffGPUGeneral2Id(uint64_t originalId) { return (1ULL << 63) | originalId; } -bool ffGPUFillVendorByDeviceName(FFGPUResult* gpu); +bool ffGPUDetectTypeByVendorAndName(FFGPUResult* gpu); diff --git a/src/detection/gpu/gpu_bsd.c b/src/detection/gpu/gpu_bsd.c index 607cfff3f..f5f8d5800 100644 --- a/src/detection/gpu/gpu_bsd.c +++ b/src/detection/gpu/gpu_bsd.c @@ -77,7 +77,7 @@ static const char* detectByPci(const FFGPUOptions* options, FFlist* gpus) { } } - ffGPUFillVendorByDeviceName(gpu); + ffGPUDetectTypeByVendorAndName(gpu); } return NULL; diff --git a/src/detection/gpu/gpu_bsddrm.c b/src/detection/gpu/gpu_bsddrm.c index 7f3a16a00..16283cbe4 100644 --- a/src/detection/gpu/gpu_bsddrm.c +++ b/src/detection/gpu/gpu_bsddrm.c @@ -72,7 +72,6 @@ static const char* drmGetPciinfo(int drmfd, const char* drmId, struct drm_pciinf }; if (ioctl(pcifd, PCIOCGETCONF, &pcio) < 0) { - perror("ioctl"); return "ioctl(pcifd, PCIOCGETCONF, &pc) failed"; } @@ -188,7 +187,7 @@ const char* ffGPUDetectByDrmBSD(const FFGPUOptions* options, FFlist* gpus) { } } - ffGPUFillVendorByDeviceName(gpu); + ffGPUDetectTypeByVendorAndName(gpu); } return NULL; @@ -201,4 +200,4 @@ const char* ffGPUDetectByDrmBSD(const FFGPUOptions* options, FFlist* gpus) { return "Fastfetch was built without libdrm support"; } -#endif // __FreeBSD__ || __OpenBSD__ +#endif // FF_HAVE_DRM diff --git a/src/detection/gpu/gpu_drm.c b/src/detection/gpu/gpu_drm.c index efeb15bfb..b22d0a7a9 100644 --- a/src/detection/gpu/gpu_drm.c +++ b/src/detection/gpu/gpu_drm.c @@ -50,7 +50,7 @@ const char* ffDrmDetectRadeon(const FFGPUOptions* options, FFGPUResult* gpu, con } if (ioctl(fd, DRM_IOCTL_RADEON_INFO, &(struct drm_radeon_info) { - .request = RADEON_INFO_MAX_SCLK, // MHz + .request = RADEON_INFO_MAX_SCLK, // KHz .value = (uintptr_t) &value, }) >= 0) { gpu->frequency = (uint32_t) (value / 1000u); @@ -59,7 +59,7 @@ const char* ffDrmDetectRadeon(const FFGPUOptions* options, FFGPUResult* gpu, con if (options->driverSpecific) { struct drm_radeon_gem_info gemInfo; if (ioctl(fd, DRM_IOCTL_RADEON_GEM_INFO, &gemInfo) >= 0) { - // vram_usage can be bigger than vram_usage, so we use vram_size here + // vram_usage can be bigger than vram_size, so we use vram_size here gpu->dedicated.total = gemInfo.vram_size; gpu->shared.total = gemInfo.gart_size; @@ -146,6 +146,7 @@ const char* ffDrmDetectAmdgpu(const FFGPUOptions* options, FFGPUResult* gpu, con ffStrbufAppendF(&gpu->memoryType, "Unknown (%u)", devInfo.vram_type); break; } + #undef FF_VRAM_CASE } struct drm_amdgpu_memory_info memInfo; @@ -228,12 +229,12 @@ static inline int popcountBytes(uint8_t* bytes, uint32_t length) { length -= 4; } if (length >= 2) { - count += __builtin_popcountl(*(uint16_t*) bytes); + count += __builtin_popcount(*(uint16_t*) bytes); bytes += 2; length -= 2; } if (length) { - count += __builtin_popcountl(*(uint8_t*) bytes); + count += __builtin_popcount(*(uint8_t*) bytes); } return count; } diff --git a/src/detection/gpu/gpu_linux.c b/src/detection/gpu/gpu_linux.c index 2f96d8ea7..91f6b566d 100644 --- a/src/detection/gpu/gpu_linux.c +++ b/src/detection/gpu/gpu_linux.c @@ -7,7 +7,7 @@ #include #include -static bool pciDetectDriver(FFstrbuf* result, FFstrbuf* pciDir, FFstrbuf* buffer, FF_A_UNUSED const char* drmKey) { +static bool detectDriverFromSysfs(FFstrbuf* result, FFstrbuf* pciDir, FFstrbuf* buffer, FF_A_UNUSED const char* drmKey) { uint32_t pciDirLength = pciDir->length; ffStrbufAppendS(pciDir, "/driver"); char pathBuf[PATH_MAX]; @@ -90,6 +90,7 @@ static void pciDetectAmdSpecific(const FFGPUOptions* options, FFGPUResult* gpu, ffStrbufAppendS(pciDir, "/hwmon/"); FF_AUTO_CLOSE_DIR DIR* dirp = opendir(pciDir->chars); if (!dirp) { + ffStrbufSubstrBefore(pciDir, pciDirLen); return; } @@ -101,6 +102,7 @@ static void pciDetectAmdSpecific(const FFGPUOptions* options, FFGPUResult* gpu, break; } if (!entry) { + ffStrbufSubstrBefore(pciDir, pciDirLen); return; } ffStrbufAppendS(pciDir, entry->d_name); @@ -407,7 +409,7 @@ static const char* detectPci(const FFGPUOptions* options, FFlist* gpus, FFstrbuf ffStrbufSetF(&gpu->platformApi, "DRM (%s)", drmKey); } - pciDetectDriver(&gpu->driver, deviceDir, buffer, drmKey); + detectDriverFromSysfs(&gpu->driver, deviceDir, buffer, drmKey); ffStrbufSubstrBefore(deviceDir, drmDirPathLength); if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_AMD) { @@ -457,7 +459,7 @@ static const char* detectPci(const FFGPUOptions* options, FFlist* gpus, FFstrbuf ffGPUFillVendorAndName(subclassId, (uint16_t) vendorId, (uint16_t) deviceId, gpu); } - ffGPUFillVendorByDeviceName(gpu); + ffGPUDetectTypeByVendorAndName(gpu); if (options->driverSpecific && gpu->pcieSpeed == FF_GPU_PCIE_SPEED_UNSET) { ffStrbufAppendS(deviceDir, "/max_link_speed"); @@ -535,12 +537,12 @@ static const char* detectOf(FFlist* gpus, FFstrbuf* buffer, FFstrbuf* drmDir, co gpu->temperature = FF_GPU_TEMP_UNSET; gpu->coreCount = FF_GPU_CORE_COUNT_UNSET; gpu->coreUsage = FF_GPU_CORE_USAGE_UNSET; - gpu->type = FF_GPU_TYPE_INTEGRATED; + gpu->type = FF_GPU_TYPE_INTEGRATED; // Open Firmware is only used on integrated GPUs gpu->dedicated.total = gpu->dedicated.used = gpu->shared.total = gpu->shared.used = FF_GPU_VMEM_SIZE_UNSET; gpu->frequency = FF_GPU_FREQUENCY_UNSET; gpu->pcieSpeed = FF_GPU_PCIE_SPEED_UNSET; - pciDetectDriver(&gpu->driver, drmDir, buffer, drmKey); + detectDriverFromSysfs(&gpu->driver, drmDir, buffer, drmKey); #ifdef __aarch64__ if (ffStrbufEqualS(&gpu->driver, "asahi")) { @@ -557,7 +559,7 @@ static const char* detectOf(FFlist* gpus, FFstrbuf* buffer, FFstrbuf* drmDir, co ffStrbufSetStatic(&gpu->vendor, "Broadcom"); // Raspberry Pi } else { ffStrbufSetS(&gpu->vendor, compatible); - gpu->vendor.chars[0] = (char) toupper(compatible[0]); + gpu->vendor.chars[0] = (char) toupper((uint8_t) compatible[0]); } } @@ -586,10 +588,11 @@ static const char* drmDetectGPUs(const FFGPUOptions* options, FFlist* gpus) { ffStrbufAppendS(&drmDir, entry->d_name); ffStrbufAppendS(&drmDir, "/device/modalias"); - if (!ffReadFileBuffer(drmDir.chars, &buffer)) { + ffReadFileBuffer(drmDir.chars, &buffer); + ffStrbufSubstrBefore(&drmDir, drmDir.length - (uint32_t) strlen("/modalias")); + if (!buffer.length) { continue; } - ffStrbufSubstrBefore(&drmDir, drmDir.length - (uint32_t) strlen("/modalias")); if (ffStrbufStartsWithS(&buffer, "pci:")) { detectPci(options, gpus, &buffer, &drmDir, entry->d_name); diff --git a/src/detection/gpu/gpu_windows.c b/src/detection/gpu/gpu_windows.c index 44b68ff31..589fee4e1 100644 --- a/src/detection/gpu/gpu_windows.c +++ b/src/detection/gpu/gpu_windows.c @@ -225,7 +225,7 @@ static void ffStrbufSetWS(FFstrbuf* strbuf, const char16_t* str) { static void closeDxgfd(void) { if (dxgfd >= 0) { close(dxgfd); - dxgfd = 0; + dxgfd = -2; FF_DEBUG("Closed /dev/dxg file descriptor"); } } @@ -294,7 +294,7 @@ ffGPUDetectWsl2 }); if (!NT_SUCCESS(status)) { FF_DEBUG("KMTQAITYPE_ADAPTERTYPE query failed for adapter #%u: %s", i, ffDebugNtStatus(status)); - continue; + goto close_adapter; } if (adapterType.SoftwareDevice) { FF_DEBUG("Skipping software adapter #%u", i); @@ -607,7 +607,7 @@ ffGPUDetectWsl2 } if (gpu->type == FF_GPU_TYPE_UNKNOWN) { - if (ffGPUFillVendorByDeviceName(gpu)) { + if (ffGPUDetectTypeByVendorAndName(gpu)) { // OK } #if _WIN32