ohmu
·
2026-10-15
1#include "gpu.h"
2#include "common/debug.h"
3#include "common/io.h"
4
5#include <errno.h>
6#include <string.h>
7
8#include <private/drivers/poke.h>
9
10const char* ffDetectGPUImpl([[maybe_unused]] const FFGPUOptions* options, FFlist* gpus) {
11 FF_AUTO_CLOSE_FD int pokefd = open(POKE_DEVICE_FULLNAME, O_RDWR | O_CLOEXEC);
12 if (pokefd < 0) {
13 FF_DEBUG("open(%s) failed: %s", POKE_DEVICE_FULLNAME, strerror(errno));
14 return "open(POKE_DEVICE_FULLNAME) failed";
15 }
16
17 pci_info dev;
18 pci_info_args cmd = {
19 .signature = POKE_SIGNATURE,
20 .info = &dev,
21 };
22
23 for (cmd.index = 0; ioctl(pokefd, POKE_GET_NTH_PCI_INFO, &cmd, sizeof(cmd)) == B_OK && cmd.status == B_OK; ++cmd.index) {
24 if (dev.class_base != 0x03 /*PCI_BASE_CLASS_DISPLAY*/) {
25 continue;
26 }
27
28 if (dev.function > 0 && dev.class_sub == 0x80 /*PCI_CLASS_DISPLAY_OTHER*/) {
29 continue; // Likely an auxiliary display controller (#2034)
30 }
31
32 FFGPUResult* gpu = FF_LIST_ADD(FFGPUResult, *gpus);
33 ffStrbufInitStatic(&gpu->vendor, ffGPUGetVendorString(dev.vendor_id));
34 ffStrbufInit(&gpu->name);
35 ffStrbufInit(&gpu->driver);
36 ffStrbufInitStatic(&gpu->platformApi, POKE_DEVICE_FULLNAME);
37 ffStrbufInit(&gpu->memoryType);
38 gpu->temperature = FF_GPU_TEMP_UNSET;
39 gpu->coreCount = FF_GPU_CORE_COUNT_UNSET;
40 gpu->coreUsage = FF_GPU_CORE_USAGE_UNSET;
41 gpu->type = FF_GPU_TYPE_UNKNOWN;
42 gpu->dedicated.total = gpu->dedicated.used = gpu->shared.total = gpu->shared.used = FF_GPU_VMEM_SIZE_UNSET;
43 gpu->deviceId = ffGPUPciAddr2Id(0, dev.bus, dev.device, dev.function);
44 gpu->frequency = FF_GPU_FREQUENCY_UNSET;
45 gpu->pcieSpeed = FF_GPU_PCIE_SPEED_UNSET;
46
47 if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_AMD) {
48 ffGPUQueryAmdGpuName(dev.device_id, dev.revision, gpu);
49 }
50
51 if (gpu->name.length == 0) {
52 ffGPUFillVendorAndName(dev.class_sub, dev.vendor_id, dev.device_id, gpu);
53 }
54 }
55
56 return nullptr;
57}