|
| 1 | +#include "gpu.h" |
| 2 | +#include "common/io/io.h" |
| 3 | + |
| 4 | +#include <private/drivers/poke.h> |
| 5 | + |
| 6 | +const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* gpus) |
| 7 | +{ |
| 8 | + FF_AUTO_CLOSE_FD int pokefd = open(POKE_DEVICE_FULLNAME, O_RDWR); |
| 9 | + if (pokefd < 0) return "open(POKE_DEVICE_FULLNAME) failed"; |
| 10 | + |
| 11 | + pci_info dev; |
| 12 | + pci_info_args cmd = { |
| 13 | + .signature = POKE_SIGNATURE, |
| 14 | + .info = &dev, |
| 15 | + }; |
| 16 | + |
| 17 | + for (cmd.index = 0; ioctl(pokefd, POKE_GET_NTH_PCI_INFO, &cmd) == B_OK && cmd.status == B_OK; ++cmd.index) |
| 18 | + { |
| 19 | + if (dev.class_base != 0x03 /*PCI_BASE_CLASS_DISPLAY*/) |
| 20 | + continue; |
| 21 | + |
| 22 | + FFGPUResult* gpu = (FFGPUResult*)ffListAdd(gpus); |
| 23 | + ffStrbufInitStatic(&gpu->vendor, ffGPUGetVendorString(dev.vendor_id)); |
| 24 | + ffStrbufInit(&gpu->name); |
| 25 | + ffStrbufInit(&gpu->driver); |
| 26 | + ffStrbufInit(&gpu->platformApi); |
| 27 | + gpu->temperature = FF_GPU_TEMP_UNSET; |
| 28 | + gpu->coreCount = FF_GPU_CORE_COUNT_UNSET; |
| 29 | + gpu->type = FF_GPU_TYPE_UNKNOWN; |
| 30 | + gpu->dedicated.total = gpu->dedicated.used = gpu->shared.total = gpu->shared.used = FF_GPU_VMEM_SIZE_UNSET; |
| 31 | + gpu->deviceId = ((uint64_t) dev.bus << 4) | ((uint64_t) dev.device << 2) | (uint64_t) dev.function; |
| 32 | + gpu->frequency = FF_GPU_FREQUENCY_UNSET; |
| 33 | + |
| 34 | + if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_AMD) |
| 35 | + ffGPUQueryAmdGpuName(dev.device_id, dev.revision, gpu); |
| 36 | + |
| 37 | + if (gpu->name.length == 0) |
| 38 | + ffGPUFillVendorAndName(dev.class_sub, dev.vendor_id, dev.device_id, gpu); |
| 39 | + } |
| 40 | + |
| 41 | + return NULL; |
| 42 | +} |
| 43 | + |
0 commit comments