2025-02-12 21:59:19 +00:00
|
|
|
#include "gpu.h"
|
2026-01-06 09:48:38 +08:00
|
|
|
#include "common/io.h"
|
2025-02-12 21:59:19 +00:00
|
|
|
|
|
|
|
|
#include <private/drivers/poke.h>
|
|
|
|
|
|
|
|
|
|
const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* gpus)
|
|
|
|
|
{
|
2025-06-19 18:11:54 +08:00
|
|
|
FF_AUTO_CLOSE_FD int pokefd = open(POKE_DEVICE_FULLNAME, O_RDWR | O_CLOEXEC);
|
2025-02-12 21:59:19 +00:00
|
|
|
if (pokefd < 0) return "open(POKE_DEVICE_FULLNAME) failed";
|
|
|
|
|
|
|
|
|
|
pci_info dev;
|
|
|
|
|
pci_info_args cmd = {
|
|
|
|
|
.signature = POKE_SIGNATURE,
|
|
|
|
|
.info = &dev,
|
|
|
|
|
};
|
|
|
|
|
|
2025-02-18 19:49:19 +08:00
|
|
|
for (cmd.index = 0; ioctl(pokefd, POKE_GET_NTH_PCI_INFO, &cmd, sizeof(cmd)) == B_OK && cmd.status == B_OK; ++cmd.index)
|
2025-02-12 21:59:19 +00:00
|
|
|
{
|
|
|
|
|
if (dev.class_base != 0x03 /*PCI_BASE_CLASS_DISPLAY*/)
|
|
|
|
|
continue;
|
|
|
|
|
|
2025-10-30 14:46:30 +08:00
|
|
|
if (dev.function > 0 && dev.class_sub == 0x80 /*PCI_CLASS_DISPLAY_OTHER*/)
|
|
|
|
|
continue; // Likely an auxiliary display controller (#2034)
|
|
|
|
|
|
2025-02-12 21:59:19 +00:00
|
|
|
FFGPUResult* gpu = (FFGPUResult*)ffListAdd(gpus);
|
|
|
|
|
ffStrbufInitStatic(&gpu->vendor, ffGPUGetVendorString(dev.vendor_id));
|
|
|
|
|
ffStrbufInit(&gpu->name);
|
|
|
|
|
ffStrbufInit(&gpu->driver);
|
2025-03-24 15:19:34 +08:00
|
|
|
ffStrbufInitStatic(&gpu->platformApi, POKE_DEVICE_FULLNAME);
|
|
|
|
|
ffStrbufInit(&gpu->memoryType);
|
2025-02-12 21:59:19 +00:00
|
|
|
gpu->temperature = FF_GPU_TEMP_UNSET;
|
|
|
|
|
gpu->coreCount = FF_GPU_CORE_COUNT_UNSET;
|
2025-02-16 21:50:19 +08:00
|
|
|
gpu->coreUsage = FF_GPU_CORE_USAGE_UNSET;
|
2025-02-12 21:59:19 +00:00
|
|
|
gpu->type = FF_GPU_TYPE_UNKNOWN;
|
|
|
|
|
gpu->dedicated.total = gpu->dedicated.used = gpu->shared.total = gpu->shared.used = FF_GPU_VMEM_SIZE_UNSET;
|
2025-10-30 10:26:35 +08:00
|
|
|
gpu->deviceId = ffGPUPciAddr2Id(0, dev.bus, dev.device, dev.function);
|
2025-02-12 21:59:19 +00:00
|
|
|
gpu->frequency = FF_GPU_FREQUENCY_UNSET;
|
|
|
|
|
|
|
|
|
|
if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_AMD)
|
|
|
|
|
ffGPUQueryAmdGpuName(dev.device_id, dev.revision, gpu);
|
|
|
|
|
|
|
|
|
|
if (gpu->name.length == 0)
|
|
|
|
|
ffGPUFillVendorAndName(dev.class_sub, dev.vendor_id, dev.device_id, gpu);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|