Skip to content

Commit 5c0ad03

Browse files
committed
GPU (Linux): support advanced detection for nouveau driver
1 parent 02aafbd commit 5c0ad03

4 files changed

Lines changed: 47 additions & 0 deletions

File tree

src/detection/gpu/gpu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ const char* ffDrmDetectAmdgpu(const FFGPUOptions* options, FFGPUResult* gpu, con
6767
const char* ffDrmDetectI915(FFGPUResult* gpu, int fd);
6868
const char* ffDrmDetectXe(FFGPUResult* gpu, int fd);
6969
const char* ffDrmDetectAsahi(FFGPUResult* gpu, int fd);
70+
const char* ffDrmDetectNouveau(FFGPUResult* gpu, int fd);
7071
#endif // FF_HAVE_DRM
7172

7273
const char* ffGPUDetectDriverSpecific(const FFGPUOptions* options, FFGPUResult* gpu, FFGpuDriverPciBusId pciBusId);

src/detection/gpu/gpu_bsd.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ static const char* detectByDrm(const FFGPUOptions* options, FFlist* gpus)
118118
ffDrmDetectXe(gpu, fd);
119119
else if (ffStrStartsWith(driverName, "asahi"))
120120
ffDrmDetectAsahi(gpu, fd);
121+
else if (ffStrStartsWith(driverName, "nouveau"))
122+
ffDrmDetectNouveau(gpu, fd);
121123
else if (dev->bustype == DRM_BUS_PCI)
122124
{
123125
ffGPUDetectDriverSpecific(options, gpu, (FFGpuDriverPciBusId) {

src/detection/gpu/gpu_drm.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "intel_drm.h"
1414
#include "asahi_drm.h"
1515
#include <radeon_drm.h>
16+
#include <nouveau_drm.h>
1617

1718
const char* ffDrmDetectRadeon(const FFGPUOptions* options, FFGPUResult* gpu, const char* renderPath)
1819
{
@@ -343,6 +344,29 @@ const char* ffDrmDetectAsahi(FFGPUResult* gpu, int fd)
343344
return "Failed to query Asahi GPU information";
344345
}
345346

347+
#ifndef DRM_IOCTL_NOUVEAU_GETPARAM
348+
#define DRM_IOCTL_NOUVEAU_GETPARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_GETPARAM, struct drm_nouveau_getparam)
349+
#endif
350+
351+
const char* ffDrmDetectNouveau(FFGPUResult* gpu, int fd)
352+
{
353+
struct drm_nouveau_getparam getparam = { };
354+
355+
getparam.param = NOUVEAU_GETPARAM_FB_SIZE;
356+
if (ioctl(fd, DRM_IOCTL_NOUVEAU_GETPARAM, &getparam) == 0)
357+
gpu->dedicated.total = getparam.value;
358+
359+
getparam.param = NOUVEAU_GETPARAM_AGP_SIZE;
360+
if (ioctl(fd, DRM_IOCTL_NOUVEAU_GETPARAM, &getparam) == 0)
361+
gpu->shared.total = getparam.value;
362+
363+
getparam.param = NOUVEAU_GETPARAM_GRAPH_UNITS;
364+
if (ioctl(fd, DRM_IOCTL_NOUVEAU_GETPARAM, &getparam) == 0 && getparam.value < INT32_MAX)
365+
gpu->coreCount = (int32_t) getparam.value;
366+
367+
return NULL;
368+
}
369+
346370
#endif // FF_HAVE_DRM
347371

348372
#include "gpu_driver_specific.h"

src/detection/gpu/gpu_linux.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,21 @@ static const char* drmDetectIntelSpecific(FFGPUResult* gpu, const char* drmKey,
263263
#endif
264264
}
265265

266+
static const char* drmDetectNouveauSpecific(FFGPUResult* gpu, const char* drmKey, FFstrbuf* buffer)
267+
{
268+
#if FF_HAVE_DRM
269+
ffStrbufSetS(buffer, "/dev/dri/");
270+
ffStrbufAppendS(buffer, drmKey);
271+
FF_AUTO_CLOSE_FD int fd = open(buffer->chars, O_RDONLY | O_CLOEXEC);
272+
if (fd < 0) return "Failed to open drm device";
273+
274+
return ffDrmDetectNouveau(gpu, fd);
275+
#else
276+
FF_UNUSED(gpu, drmKey, buffer);
277+
return "Fastfetch is not compiled with drm support";
278+
#endif
279+
}
280+
266281
static const char* detectPci(const FFGPUOptions* options, FFlist* gpus, FFstrbuf* buffer, FFstrbuf* deviceDir, const char* drmKey)
267282
{
268283
const uint32_t drmDirPathLength = deviceDir->length;
@@ -369,6 +384,11 @@ static const char* detectPci(const FFGPUOptions* options, FFlist* gpus, FFstrbuf
369384
if (options->driverSpecific && drmKey)
370385
drmDetectIntelSpecific(gpu, drmKey, buffer);
371386
}
387+
else if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA && ffStrbufEqualS(&gpu->driver, "nouveau"))
388+
{
389+
if (options->driverSpecific && drmKey)
390+
drmDetectNouveauSpecific(gpu, drmKey, buffer);
391+
}
372392
else
373393
{
374394
ffGPUDetectDriverSpecific(options, gpu, (FFGpuDriverPciBusId) {

0 commit comments

Comments
 (0)