From 5c0ad030cc49f49b26e90598e4a3785d12ebe970 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Sat, 19 Jul 2025 16:27:38 +0800 Subject: [PATCH] GPU (Linux): support advanced detection for nouveau driver --- src/detection/gpu/gpu.h | 1 + src/detection/gpu/gpu_bsd.c | 2 ++ src/detection/gpu/gpu_drm.c | 24 ++++++++++++++++++++++++ src/detection/gpu/gpu_linux.c | 20 ++++++++++++++++++++ 4 files changed, 47 insertions(+) diff --git a/src/detection/gpu/gpu.h b/src/detection/gpu/gpu.h index 1ebee2de6..e4db0f858 100644 --- a/src/detection/gpu/gpu.h +++ b/src/detection/gpu/gpu.h @@ -67,6 +67,7 @@ const char* ffDrmDetectAmdgpu(const FFGPUOptions* options, FFGPUResult* gpu, con const char* ffDrmDetectI915(FFGPUResult* gpu, int fd); const char* ffDrmDetectXe(FFGPUResult* gpu, int fd); const char* ffDrmDetectAsahi(FFGPUResult* gpu, int fd); +const char* ffDrmDetectNouveau(FFGPUResult* gpu, int fd); #endif // FF_HAVE_DRM const char* ffGPUDetectDriverSpecific(const FFGPUOptions* options, FFGPUResult* gpu, FFGpuDriverPciBusId pciBusId); diff --git a/src/detection/gpu/gpu_bsd.c b/src/detection/gpu/gpu_bsd.c index 3d4605546..b4c263699 100644 --- a/src/detection/gpu/gpu_bsd.c +++ b/src/detection/gpu/gpu_bsd.c @@ -118,6 +118,8 @@ static const char* detectByDrm(const FFGPUOptions* options, FFlist* gpus) ffDrmDetectXe(gpu, fd); else if (ffStrStartsWith(driverName, "asahi")) ffDrmDetectAsahi(gpu, fd); + else if (ffStrStartsWith(driverName, "nouveau")) + ffDrmDetectNouveau(gpu, fd); else if (dev->bustype == DRM_BUS_PCI) { ffGPUDetectDriverSpecific(options, gpu, (FFGpuDriverPciBusId) { diff --git a/src/detection/gpu/gpu_drm.c b/src/detection/gpu/gpu_drm.c index 5ddea2799..a1c9cd0c3 100644 --- a/src/detection/gpu/gpu_drm.c +++ b/src/detection/gpu/gpu_drm.c @@ -13,6 +13,7 @@ #include "intel_drm.h" #include "asahi_drm.h" #include +#include const char* ffDrmDetectRadeon(const FFGPUOptions* options, FFGPUResult* gpu, const char* renderPath) { @@ -343,6 +344,29 @@ const char* ffDrmDetectAsahi(FFGPUResult* gpu, int fd) return "Failed to query Asahi GPU information"; } +#ifndef DRM_IOCTL_NOUVEAU_GETPARAM +#define DRM_IOCTL_NOUVEAU_GETPARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_GETPARAM, struct drm_nouveau_getparam) +#endif + +const char* ffDrmDetectNouveau(FFGPUResult* gpu, int fd) +{ + struct drm_nouveau_getparam getparam = { }; + + getparam.param = NOUVEAU_GETPARAM_FB_SIZE; + if (ioctl(fd, DRM_IOCTL_NOUVEAU_GETPARAM, &getparam) == 0) + gpu->dedicated.total = getparam.value; + + getparam.param = NOUVEAU_GETPARAM_AGP_SIZE; + if (ioctl(fd, DRM_IOCTL_NOUVEAU_GETPARAM, &getparam) == 0) + gpu->shared.total = getparam.value; + + getparam.param = NOUVEAU_GETPARAM_GRAPH_UNITS; + if (ioctl(fd, DRM_IOCTL_NOUVEAU_GETPARAM, &getparam) == 0 && getparam.value < INT32_MAX) + gpu->coreCount = (int32_t) getparam.value; + + return NULL; +} + #endif // FF_HAVE_DRM #include "gpu_driver_specific.h" diff --git a/src/detection/gpu/gpu_linux.c b/src/detection/gpu/gpu_linux.c index c37502e47..39fca1478 100644 --- a/src/detection/gpu/gpu_linux.c +++ b/src/detection/gpu/gpu_linux.c @@ -263,6 +263,21 @@ static const char* drmDetectIntelSpecific(FFGPUResult* gpu, const char* drmKey, #endif } +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); + if (fd < 0) return "Failed to open drm device"; + + return ffDrmDetectNouveau(gpu, fd); + #else + FF_UNUSED(gpu, drmKey, buffer); + return "Fastfetch is not compiled with drm support"; + #endif +} + static const char* detectPci(const FFGPUOptions* options, FFlist* gpus, FFstrbuf* buffer, FFstrbuf* deviceDir, const char* drmKey) { const uint32_t drmDirPathLength = deviceDir->length; @@ -369,6 +384,11 @@ static const char* detectPci(const FFGPUOptions* options, FFlist* gpus, FFstrbuf if (options->driverSpecific && drmKey) drmDetectIntelSpecific(gpu, drmKey, buffer); } + else if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA && ffStrbufEqualS(&gpu->driver, "nouveau")) + { + if (options->driverSpecific && drmKey) + drmDetectNouveauSpecific(gpu, drmKey, buffer); + } else { ffGPUDetectDriverSpecific(options, gpu, (FFGpuDriverPciBusId) {