Skip to content

Commit 8ebc980

Browse files
committed
GPU (SunOS): simplify
1 parent dbeb338 commit 8ebc980

File tree

1 file changed

+33
-36
lines changed

1 file changed

+33
-36
lines changed

src/detection/gpu/gpu_sunos.c

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,42 @@
33

44
#include <libdevinfo.h>
55

6-
static int walkDevTree(di_node_t node, FFlist* gpus)
6+
static int walkDevTree(di_node_t node, FF_MAYBE_UNUSED di_minor_t minor, FFlist* gpus)
77
{
8-
if (ffStrEquals(di_node_name(node), "display"))
8+
int* vendorId;
9+
int* deviceId;
10+
if (di_prop_lookup_ints(DDI_DEV_T_ANY, node, "vendor-id", &vendorId) > 0
11+
&& di_prop_lookup_ints(DDI_DEV_T_ANY, node, "device-id", &deviceId) > 0)
912
{
10-
int* vendorId;
11-
int* deviceId;
12-
if (di_prop_lookup_ints(DDI_DEV_T_ANY, node, "vendor-id", &vendorId) > 0
13-
&& di_prop_lookup_ints(DDI_DEV_T_ANY, node, "device-id", &deviceId) > 0)
14-
{
15-
FFGPUResult* gpu = (FFGPUResult*)ffListAdd(gpus);
16-
ffStrbufInitS(&gpu->vendor, ffGPUGetVendorString((uint16_t) *vendorId));
17-
ffStrbufInit(&gpu->name);
18-
ffStrbufInitS(&gpu->driver, di_driver_name(node));
19-
ffStrbufInitStatic(&gpu->platformApi, "libdevinfo");
20-
ffStrbufInit(&gpu->memoryType);
21-
gpu->index = FF_GPU_INDEX_UNSET;
22-
gpu->temperature = FF_GPU_TEMP_UNSET;
23-
gpu->coreCount = FF_GPU_CORE_COUNT_UNSET;
24-
gpu->coreUsage = FF_GPU_CORE_USAGE_UNSET;
25-
gpu->type = FF_GPU_TYPE_UNKNOWN;
26-
gpu->dedicated.total = gpu->dedicated.used = gpu->shared.total = gpu->shared.used = FF_GPU_VMEM_SIZE_UNSET;
27-
gpu->deviceId = strtoul(di_bus_addr(node), NULL, 16);
28-
gpu->frequency = FF_GPU_FREQUENCY_UNSET;
13+
FFGPUResult* gpu = (FFGPUResult*)ffListAdd(gpus);
14+
ffStrbufInitS(&gpu->vendor, ffGPUGetVendorString((uint16_t) *vendorId));
15+
ffStrbufInit(&gpu->name);
16+
ffStrbufInitS(&gpu->driver, di_driver_name(node));
17+
ffStrbufInitStatic(&gpu->platformApi, "libdevinfo");
18+
ffStrbufInit(&gpu->memoryType);
19+
gpu->index = FF_GPU_INDEX_UNSET;
20+
gpu->temperature = FF_GPU_TEMP_UNSET;
21+
gpu->coreCount = FF_GPU_CORE_COUNT_UNSET;
22+
gpu->coreUsage = FF_GPU_CORE_USAGE_UNSET;
23+
gpu->type = FF_GPU_TYPE_UNKNOWN;
24+
gpu->dedicated.total = gpu->dedicated.used = gpu->shared.total = gpu->shared.used = FF_GPU_VMEM_SIZE_UNSET;
25+
gpu->deviceId = strtoul(di_bus_addr(node), NULL, 16);
26+
gpu->frequency = FF_GPU_FREQUENCY_UNSET;
2927

30-
if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_AMD)
31-
{
32-
int* revId;
33-
if (di_prop_lookup_ints(DDI_DEV_T_ANY, node, "revision-id", &revId) > 0)
34-
ffGPUQueryAmdGpuName((uint16_t) *deviceId, (uint8_t) *revId, gpu);
35-
}
28+
if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_AMD)
29+
{
30+
int* revId;
31+
if (di_prop_lookup_ints(DDI_DEV_T_ANY, node, "revision-id", &revId) > 0)
32+
ffGPUQueryAmdGpuName((uint16_t) *deviceId, (uint8_t) *revId, gpu);
33+
}
3634

37-
if (gpu->name.length == 0)
38-
{
39-
uint8_t subclass = 0; // assume VGA
40-
int* classCode;
41-
if (di_prop_lookup_ints(DDI_DEV_T_ANY, node, "class-code", &classCode) > 0)
42-
subclass = (uint8_t) (*classCode & 0xFFFF);
43-
ffGPUFillVendorAndName(subclass, (uint16_t) *vendorId, (uint16_t) *deviceId, gpu);
44-
}
35+
if (gpu->name.length == 0)
36+
{
37+
uint8_t subclass = 0; // assume VGA
38+
int* classCode;
39+
if (di_prop_lookup_ints(DDI_DEV_T_ANY, node, "class-code", &classCode) > 0)
40+
subclass = (uint8_t) (*classCode & 0xFFFF);
41+
ffGPUFillVendorAndName(subclass, (uint16_t) *vendorId, (uint16_t) *deviceId, gpu);
4542
}
4643
}
4744

@@ -53,7 +50,7 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
5350
di_node_t rootNode = di_init("/", DINFOCPYALL);
5451
if (rootNode == DI_NODE_NIL)
5552
return "di_init() failed";
56-
di_walk_node(rootNode, DI_WALK_CLDFIRST, gpus, (void*) walkDevTree);
53+
di_walk_minor(rootNode, DDI_NT_DISPLAY, DI_WALK_CLDFIRST, gpus, (void*) walkDevTree);
5754
di_fini(rootNode);
5855

5956
return NULL;

0 commit comments

Comments
 (0)