Skip to content

Commit 1d83743

Browse files
committed
GPU (Linux): detect more GPU driver versions
1 parent 48bb38c commit 1d83743

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

src/detection/gpu/gpu_linux.c

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,29 +32,42 @@
3232

3333
static bool pciDetectDriver(FFGPUResult* gpu, FFstrbuf* pciDir, FFstrbuf* buffer, FF_MAYBE_UNUSED const char* drmKey)
3434
{
35+
uint32_t pciDirLength = pciDir->length;
3536
ffStrbufAppendS(pciDir, "/driver");
3637
char pathBuf[PATH_MAX];
3738
ssize_t resultLength = readlink(pciDir->chars, pathBuf, sizeof(pathBuf));
38-
if(resultLength > 0)
39+
if(resultLength <= 0) return false;
40+
41+
const char* slash = memrchr(pathBuf, '/', (size_t) resultLength);
42+
if (slash)
3943
{
40-
const char* slash = memrchr(pathBuf, '/', (size_t) resultLength);
41-
if (slash)
42-
{
43-
slash++;
44-
ffStrbufSetNS(&gpu->driver, (uint32_t) (resultLength - (slash - pathBuf)), slash);
45-
}
44+
slash++;
45+
ffStrbufSetNS(&gpu->driver, (uint32_t) (resultLength - (slash - pathBuf)), slash);
46+
}
4647

48+
if (instance.config.general.detectVersion)
49+
{
4750
ffStrbufAppendS(pciDir, "/module/version");
4851
if (ffReadFileBuffer(pciDir->chars, buffer))
4952
{
5053
ffStrbufTrimRightSpace(buffer);
5154
ffStrbufAppendC(&gpu->driver, ' ');
5255
ffStrbufAppend(&gpu->driver, buffer);
53-
return true;
56+
}
57+
else if (ffStrbufEqualS(&gpu->driver, "zx"))
58+
{
59+
ffStrbufSubstrBefore(pciDir, pciDirLength);
60+
ffStrbufAppendS(pciDir, "/zx_info/driver_version");
61+
if (ffReadFileBuffer(pciDir->chars, buffer))
62+
{
63+
ffStrbufTrimRightSpace(buffer);
64+
ffStrbufAppendC(&gpu->driver, ' ');
65+
ffStrbufAppend(&gpu->driver, buffer);
66+
}
5467
}
5568
}
5669

57-
return false;
70+
return true;
5871
}
5972

6073
static void pciDetectAmdSpecific(const FFGPUOptions* options, FFGPUResult* gpu, FFstrbuf* pciDir, FFstrbuf* buffer)

0 commit comments

Comments
 (0)