Skip to content

Commit 2738f20

Browse files
committed
GPU (Linux): detect driver specific info for zhaoxin
1 parent 09362b2 commit 2738f20

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

src/detection/gpu/gpu.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,18 @@ extern const char* FF_GPU_VENDOR_NAME_AMD;
1515
extern const char* FF_GPU_VENDOR_NAME_INTEL;
1616
extern const char* FF_GPU_VENDOR_NAME_NVIDIA;
1717
extern const char* FF_GPU_VENDOR_NAME_MTHREADS;
18+
extern const char* FF_GPU_VENDOR_NAME_QUALCOMM;
19+
extern const char* FF_GPU_VENDOR_NAME_MTK;
1820
extern const char* FF_GPU_VENDOR_NAME_VMWARE;
1921
extern const char* FF_GPU_VENDOR_NAME_PARALLEL;
2022
extern const char* FF_GPU_VENDOR_NAME_MICROSOFT;
2123
extern const char* FF_GPU_VENDOR_NAME_REDHAT;
2224
extern const char* FF_GPU_VENDOR_NAME_ORACLE;
25+
extern const char* FF_GPU_VENDOR_NAME_BROADCOM;
26+
extern const char* FF_GPU_VENDOR_NAME_LOONGSON;
27+
extern const char* FF_GPU_VENDOR_NAME_JINGJIA_MICRO;
28+
extern const char* FF_GPU_VENDOR_NAME_HUAWEI;
29+
extern const char* FF_GPU_VENDOR_NAME_ZHAOXIN;
2330

2431
typedef struct FFGPUMemory
2532
{

src/detection/gpu/gpu_linux.c

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
#include "detection/gpu/gpu_driver_specific.h"
55
#include "common/io/io.h"
66
#include "common/library.h"
7+
#include "modules/gpu/option.h"
8+
#include "util/FFstrbuf.h"
79
#include "util/stringUtils.h"
810
#include "util/mallocHelper.h"
911

1012
#include <inttypes.h>
13+
#include <stdint.h>
1114

1215
#ifdef FF_HAVE_DRM_AMDGPU
1316
#include <amdgpu.h>
@@ -263,7 +266,7 @@ static const char* drmDetectIntelSpecific(FFGPUResult* gpu, const char* drmKey,
263266
#endif
264267
}
265268

266-
static const char* pciDetectNouveauSpecific(const FFGPUOptions* options, FFGPUResult* gpu, FFstrbuf* pciDir, FFstrbuf* buffer)
269+
static const char* pciDetectTempGeneral(const FFGPUOptions* options, FFGPUResult* gpu, FFstrbuf* pciDir, FFstrbuf* buffer)
267270
{
268271
if (options->temp)
269272
{
@@ -306,6 +309,48 @@ static const char* drmDetectNouveauSpecific(FFGPUResult* gpu, const char* drmKey
306309
#endif
307310
}
308311

312+
static const char* pciDetectZxSpecific(const FFGPUOptions* options, FFGPUResult* gpu, FFstrbuf* pciDir, FFstrbuf* buffer)
313+
{
314+
gpu->type = FF_GPU_TYPE_INTEGRATED;
315+
316+
const uint32_t pciDirLen = pciDir->length;
317+
ffStrbufAppendS(pciDir, "/zx_info/eclk");
318+
if (ffReadFileBuffer(pciDir->chars, buffer))
319+
gpu->frequency = (uint32_t) ffStrbufToUInt(buffer, FF_GPU_FREQUENCY_UNSET);
320+
ffStrbufSubstrBefore(pciDir, pciDirLen);
321+
322+
if (options->driverSpecific)
323+
{
324+
ffStrbufAppendS(pciDir, "/zx_info/engine_3d_usage");
325+
if (ffReadFileBuffer(pciDir->chars, buffer))
326+
gpu->coreUsage = ffStrbufToDouble(buffer, FF_GPU_CORE_USAGE_UNSET);
327+
ffStrbufSubstrBefore(pciDir, pciDirLen);
328+
329+
ffStrbufAppendS(pciDir, "/zx_info/fb_size");
330+
if (ffReadFileBuffer(pciDir->chars, buffer))
331+
gpu->shared.total = ffStrbufToUInt(buffer, FF_GPU_VMEM_SIZE_UNSET);
332+
ffStrbufSubstrBefore(pciDir, pciDirLen);
333+
334+
if (gpu->shared.total != FF_GPU_VMEM_SIZE_UNSET)
335+
{
336+
gpu->shared.total *= 1024 * 1024;
337+
338+
ffStrbufAppendS(pciDir, "/zx_info/free_fb_mem");
339+
if (ffReadFileBuffer(pciDir->chars, buffer))
340+
gpu->shared.used = ffStrbufToUInt(buffer, FF_GPU_VMEM_SIZE_UNSET);
341+
ffStrbufSubstrBefore(pciDir, pciDirLen);
342+
343+
if (gpu->shared.used != FF_GPU_VMEM_SIZE_UNSET)
344+
{
345+
gpu->shared.used *= 1024 * 1024;
346+
gpu->shared.used = gpu->shared.total - gpu->shared.used;
347+
}
348+
}
349+
}
350+
351+
return NULL;
352+
}
353+
309354
static const char* detectPci(const FFGPUOptions* options, FFlist* gpus, FFstrbuf* buffer, FFstrbuf* deviceDir, const char* drmKey)
310355
{
311356
const uint32_t drmDirPathLength = deviceDir->length;
@@ -417,10 +462,15 @@ static const char* detectPci(const FFGPUOptions* options, FFlist* gpus, FFstrbuf
417462
}
418463
else if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA && ffStrbufEqualS(&gpu->driver, "nouveau"))
419464
{
420-
pciDetectNouveauSpecific(options, gpu, deviceDir, buffer);
465+
pciDetectTempGeneral(options, gpu, deviceDir, buffer);
421466
if (options->driverSpecific && drmKey)
422467
drmDetectNouveauSpecific(gpu, drmKey, buffer);
423468
}
469+
else if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_ZHAOXIN && ffStrbufStartsWithS(&gpu->driver, "zx"))
470+
{
471+
pciDetectTempGeneral(options, gpu, deviceDir, buffer);
472+
pciDetectZxSpecific(options, gpu, deviceDir, buffer);
473+
}
424474
else
425475
{
426476
ffGPUDetectDriverSpecific(options, gpu, (FFGpuDriverPciBusId) {

0 commit comments

Comments
 (0)