diff --git a/CMakeLists.txt b/CMakeLists.txt index 92544f9a4..634ec3bf1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -83,7 +83,6 @@ cmake_dependent_option(ENABLE_XRANDR "Enable xrandr" ON "LINUX OR FreeBSD OR Ope cmake_dependent_option(ENABLE_DRM "Enable libdrm" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS OR GNU" OFF) cmake_dependent_option(ENABLE_VA "Enable libva" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS OR GNU" OFF) cmake_dependent_option(ENABLE_VDPAU "Enable vdpau" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS OR GNU" OFF) -cmake_dependent_option(ENABLE_DRM_AMDGPU "Enable libdrm_amdgpu" ON "LINUX OR FreeBSD OR OpenBSD OR GNU" OFF) cmake_dependent_option(ENABLE_GIO "Enable gio-2.0" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR ANDROID OR SunOS OR GNU" OFF) cmake_dependent_option(ENABLE_DCONF "Enable dconf" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR ANDROID OR SunOS OR GNU" OFF) cmake_dependent_option(ENABLE_EET "Enable eet" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR ANDROID OR SunOS OR GNU" OFF) @@ -1714,10 +1713,6 @@ ff_lib_enable(VDPAU "vdpau" "vdpau" ) -ff_lib_enable(DRM_AMDGPU - "libdrm_amdgpu" - "Libdrm_Amdgpu" -) ff_lib_enable(GIO "gio-2.0" "GIO" diff --git a/src/detection/gpu/asahi_drm.h b/src/detection/gpu/asahi_drm.h index 69b537b75..953caefe5 100644 --- a/src/detection/gpu/asahi_drm.h +++ b/src/detection/gpu/asahi_drm.h @@ -7,7 +7,11 @@ #ifndef _ASAHI_DRM_H_ #define _ASAHI_DRM_H_ -#include +#if __has_include() + #include +#else + #include +#endif #if defined(__cplusplus) extern "C" { diff --git a/src/detection/gpu/gpu.h b/src/detection/gpu/gpu.h index 43caee312..ff2c24d6d 100644 --- a/src/detection/gpu/gpu.h +++ b/src/detection/gpu/gpu.h @@ -67,7 +67,7 @@ typedef struct FFGpuDriverPciBusId { void ffGPUFillVendorAndName(uint8_t subclass, uint16_t vendor, uint16_t device, FFGPUResult* gpu); void ffGPUQueryAmdGpuName(uint16_t deviceId, uint8_t revisionId, FFGPUResult* gpu); - #if FF_HAVE_DRM + #if FF_HAVE_DRM || __has_include() const char* ffDrmDetectRadeon(const FFGPUOptions* options, FFGPUResult* gpu, const char* renderPath); const char* ffDrmDetectAmdgpu(const FFGPUOptions* options, FFGPUResult* gpu, const char* renderPath); const char* ffDrmDetectI915(FFGPUResult* gpu, int fd); @@ -77,7 +77,7 @@ const char* ffDrmDetectNouveau(FFGPUResult* gpu, int fd); #if __FreeBSD__ || __OpenBSD__ // DRM is not available on NetBSD const char* ffGPUDetectByDrmBSD(const FFGPUOptions* options, FFlist* gpus); #endif - #endif // FF_HAVE_DRM + #endif // FF_HAVE_DRM || __has_include() const char* ffGPUDetectDriverSpecific(const FFGPUOptions* options, FFGPUResult* gpu, FFGpuDriverPciBusId pciBusId); #endif // defined(XXX) diff --git a/src/detection/gpu/gpu_drm.c b/src/detection/gpu/gpu_drm.c index 96f800236..8b7b9a9aa 100644 --- a/src/detection/gpu/gpu_drm.c +++ b/src/detection/gpu/gpu_drm.c @@ -1,19 +1,25 @@ #include "gpu.h" -#if FF_HAVE_DRM - #include +#if FF_HAVE_DRM || __has_include() #include #include #include "common/io.h" - #include "common/library.h" #include "common/mallocHelper.h" - #include "common/strutil.h" + #if FF_HAVE_DRM + #include + #include + #include + #include + #else + #include + #include + #include + #include + #endif #include "intel_drm.h" #include "asahi_drm.h" - #include - #include const char* ffDrmDetectRadeon(const FFGPUOptions* options, FFGPUResult* gpu, const char* renderPath) { FF_AUTO_CLOSE_FD int fd = open(renderPath, O_RDONLY | O_CLOEXEC); @@ -76,52 +82,42 @@ const char* ffDrmDetectRadeon(const FFGPUOptions* options, FFGPUResult* gpu, con return NULL; } - #ifdef FF_HAVE_DRM_AMDGPU - #include - #include - const char* ffDrmDetectAmdgpu(const FFGPUOptions* options, FFGPUResult* gpu, const char* renderPath) { - #if FF_HAVE_DRM_AMDGPU - FF_LIBRARY_LOAD_MESSAGE(libdrm, "libdrm_amdgpu" FF_LIBRARY_EXTENSION, 1) - FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libdrm, amdgpu_device_initialize) - FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libdrm, amdgpu_get_marketing_name) - FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libdrm, amdgpu_query_gpu_info) - FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libdrm, amdgpu_query_sensor_info) - FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libdrm, amdgpu_query_heap_info) - FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libdrm, amdgpu_device_deinitialize) - FF_AUTO_CLOSE_FD int fd = open(renderPath, O_RDONLY | O_CLOEXEC); if (fd < 0) { return "Failed to open DRM render device"; } - amdgpu_device_handle handle; - uint32_t majorVersion, minorVersion; - if (ffamdgpu_device_initialize(fd, &majorVersion, &minorVersion, &handle) < 0) { - return "Failed to initialize AMDGPU device"; - } - uint32_t value; if (options->temp) { - if (ffamdgpu_query_sensor_info(handle, AMDGPU_INFO_SENSOR_GPU_TEMP, sizeof(value), &value) >= 0) { + if (ioctl(fd, DRM_IOCTL_AMDGPU_INFO, + &(struct drm_amdgpu_info) { + .return_pointer = (uintptr_t) &value, + .return_size = sizeof(value), + .query = AMDGPU_INFO_SENSOR, + .query_hw_ip.type = AMDGPU_INFO_SENSOR_GPU_TEMP, + }) >= 0 && value != 0) { gpu->temperature = value / 1000.; } } - ffStrbufSetS(&gpu->name, ffamdgpu_get_marketing_name(handle)); - - struct amdgpu_gpu_info gpuInfo; - if (ffamdgpu_query_gpu_info(handle, &gpuInfo) >= 0) { - gpu->coreCount = (int32_t) gpuInfo.cu_active_number; - gpu->frequency = (uint32_t) (gpuInfo.max_engine_clk / 1000u); + struct drm_amdgpu_info_device devInfo; + if (ioctl(fd, DRM_IOCTL_AMDGPU_INFO, + &(struct drm_amdgpu_info) { + .return_pointer = (uintptr_t) &devInfo, + .return_size = sizeof(devInfo), + .query = AMDGPU_INFO_DEV_INFO, + }) >= 0) { + gpu->coreCount = (int32_t) devInfo.cu_active_number; + gpu->frequency = (uint32_t) (devInfo.max_engine_clock / 1000u); gpu->index = FF_GPU_INDEX_UNSET; - gpu->type = gpuInfo.ids_flags & AMDGPU_IDS_FLAGS_FUSION ? FF_GPU_TYPE_INTEGRATED : FF_GPU_TYPE_DISCRETE; - #define FF_VRAM_CASE(name, value) \ - case value /* AMDGPU_VRAM_TYPE_ ## name */: \ + gpu->type = devInfo.ids_flags & AMDGPU_IDS_FLAGS_FUSION ? FF_GPU_TYPE_INTEGRATED : FF_GPU_TYPE_DISCRETE; + #define FF_VRAM_CASE(name, value) \ + case value /* AMDGPU_VRAM_TYPE_ ## name */: \ ffStrbufSetStatic(&gpu->memoryType, #name); \ break - switch (gpuInfo.vram_type) { + switch (devInfo.vram_type) { FF_VRAM_CASE(UNKNOWN, 0); FF_VRAM_CASE(GDDR1, 1); FF_VRAM_CASE(DDR2, 2); @@ -135,35 +131,39 @@ const char* ffDrmDetectAmdgpu(const FFGPUOptions* options, FFGPUResult* gpu, con FF_VRAM_CASE(DDR5, 10); FF_VRAM_CASE(LPDDR4, 11); FF_VRAM_CASE(LPDDR5, 12); + FF_VRAM_CASE(HBM3E, 13); + FF_VRAM_CASE(HBM4, 14); default: - ffStrbufAppendF(&gpu->memoryType, "Unknown (%u)", gpuInfo.vram_type); + ffStrbufAppendF(&gpu->memoryType, "Unknown (%u)", devInfo.vram_type); break; } - - struct amdgpu_heap_info heapInfo; - if (ffamdgpu_query_heap_info(handle, AMDGPU_GEM_DOMAIN_VRAM, 0, &heapInfo) >= 0) { - gpu->dedicated.total = heapInfo.heap_size; - gpu->dedicated.used = heapInfo.heap_usage; - } - if (ffamdgpu_query_heap_info(handle, AMDGPU_GEM_DOMAIN_GTT, 0, &heapInfo) >= 0) { - gpu->shared.total = heapInfo.heap_size; - gpu->shared.used = heapInfo.heap_usage; - } } - if (ffamdgpu_query_sensor_info(handle, AMDGPU_INFO_SENSOR_GPU_LOAD, sizeof(value), &value) >= 0) { + struct drm_amdgpu_memory_info memInfo; + if (ioctl(fd, DRM_IOCTL_AMDGPU_INFO, + &(struct drm_amdgpu_info) { + .return_pointer = (uintptr_t) &memInfo, + .return_size = sizeof(memInfo), + .query = AMDGPU_INFO_MEMORY, + }) >= 0) { + gpu->dedicated.total = memInfo.vram.total_heap_size; + gpu->dedicated.used = memInfo.vram.heap_usage; + gpu->shared.total = memInfo.gtt.total_heap_size; + gpu->shared.used = memInfo.gtt.heap_usage; + } + + if (ioctl(fd, DRM_IOCTL_AMDGPU_INFO, + &(struct drm_amdgpu_info) { + .return_pointer = (uintptr_t) &value, + .return_size = sizeof(value), + .query = AMDGPU_INFO_SENSOR, + .query_hw_ip.type = AMDGPU_INFO_SENSOR_GPU_LOAD, + }) >= 0) { gpu->coreUsage = value; } - ffamdgpu_device_deinitialize(handle); - return NULL; - #else - FF_UNUSED(options, gpu, renderPath); - return "Fastfetch is compiled without libdrm support"; - #endif } - #endif const char* ffDrmDetectI915(FFGPUResult* gpu, int fd) { { diff --git a/src/detection/gpu/gpu_linux.c b/src/detection/gpu/gpu_linux.c index d10252137..c679bb09c 100644 --- a/src/detection/gpu/gpu_linux.c +++ b/src/detection/gpu/gpu_linux.c @@ -1,40 +1,12 @@ #include "detection/gpu/gpu.h" -#include "detection/vulkan/vulkan.h" -#include "detection/cpu/cpu.h" -#include "detection/gpu/gpu_driver_specific.h" #include "common/io.h" -#include "common/library.h" #include "common/FFstrbuf.h" #include "common/strutil.h" -#include "common/mallocHelper.h" #include "modules/gpu/option.h" #include #include -#ifdef FF_HAVE_DRM_AMDGPU - #include - #include - #include -#endif - -#ifdef FF_HAVE_DRM - #include "intel_drm.h" - #include - #include -#endif - -#if defined(FF_HAVE_DRM) && defined(__aarch64__) - // https://github.com/alyssarosenzweig/linux/blob/agx-uapi-v7/include/uapi/drm/asahi_drm.h - // Found in kernel-headers-6.14.4-400.asahi.fc42.aarch64 - #if __has_include() - #include - #else - #include "asahi_drm.h" - #endif - #define FF_HAVE_DRM_ASAHI 1 -#endif - static bool pciDetectDriver(FFstrbuf* result, FFstrbuf* pciDir, FFstrbuf* buffer, FF_A_UNUSED const char* drmKey) { uint32_t pciDirLength = pciDir->length; ffStrbufAppendS(pciDir, "/driver"); @@ -246,7 +218,6 @@ static void pciDetectIntelSpecific(const FFGPUOptions* options, FFGPUResult* gpu } static const char* drmDetectIntelSpecific(FFGPUResult* gpu, const char* drmKey, FFstrbuf* buffer) { -#if FF_HAVE_DRM ffStrbufSetS(buffer, "/dev/dri/"); ffStrbufAppendS(buffer, drmKey); FF_AUTO_CLOSE_FD int fd = open(buffer->chars, O_RDONLY | O_CLOEXEC); @@ -260,10 +231,6 @@ static const char* drmDetectIntelSpecific(FFGPUResult* gpu, const char* drmKey, return ffDrmDetectI915(gpu, fd); } return "Unknown Intel GPU driver"; -#else - FF_UNUSED(gpu, drmKey, buffer); - return "Fastfetch is not compiled with drm support"; -#endif } static const char* pciDetectTempGeneral(const FFGPUOptions* options, FFGPUResult* gpu, FFstrbuf* pciDir, FFstrbuf* buffer) { @@ -294,7 +261,6 @@ static const char* pciDetectTempGeneral(const FFGPUOptions* options, FFGPUResult } static const char* drmDetectNouveauSpecific(FFGPUResult* gpu, const char* drmKey, FFstrbuf* buffer) { -#if FF_HAVE_DRM ffStrbufSetS(buffer, "/dev/dri/"); ffStrbufAppendS(buffer, drmKey); FF_AUTO_CLOSE_FD int fd = open(buffer->chars, O_RDONLY | O_CLOEXEC); @@ -303,10 +269,6 @@ static const char* drmDetectNouveauSpecific(FFGPUResult* gpu, const char* drmKey } return ffDrmDetectNouveau(gpu, fd); -#else - FF_UNUSED(gpu, drmKey, buffer); - return "Fastfetch is not compiled with drm support"; -#endif } static const char* pciDetectZxSpecific(const FFGPUOptions* options, FFGPUResult* gpu, FFstrbuf* pciDir, FFstrbuf* buffer) { @@ -484,6 +446,7 @@ static const char* detectPci(const FFGPUOptions* options, FFlist* gpus, FFstrbuf } #if __aarch64__ +#include "detection/cpu/cpu.h" FF_A_UNUSED static const char* drmDetectAsahiSpecific(FFGPUResult* gpu, const char* name, FF_A_UNUSED FFstrbuf* buffer, FF_A_UNUSED const char* drmKey) { if (sscanf(name, "agx-t%lu", &gpu->deviceId) == 1) { @@ -491,14 +454,12 @@ FF_A_UNUSED static const char* drmDetectAsahiSpecific(FFGPUResult* gpu, const ch } ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_APPLE); - #if FF_HAVE_DRM_ASAHI ffStrbufSetS(buffer, "/dev/dri/"); ffStrbufAppendS(buffer, drmKey); FF_AUTO_CLOSE_FD int fd = open(buffer->chars, O_RDONLY | O_CLOEXEC); if (fd >= 0) { return ffDrmDetectAsahi(gpu, fd); } - #endif return NULL; } diff --git a/src/detection/gpu/intel_drm.h b/src/detection/gpu/intel_drm.h index 3e2574822..a74fd3a0d 100644 --- a/src/detection/gpu/intel_drm.h +++ b/src/detection/gpu/intel_drm.h @@ -1,7 +1,11 @@ #pragma once /* SPDX-License-Identifier: MIT */ -#include +#if __has_include() + #include +#else + #include +#endif // xe_drm.h