Skip to content

Commit 464e00d

Browse files
committed
GPU (Haiku): use system API to fetch PCI devices
1 parent b8e25bd commit 464e00d

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ cmake_dependent_option(ENABLE_DIRECTX_HEADERS "Enable DirectX headers for WSL" O
8383
cmake_dependent_option(ENABLE_ELF "Enable libelf" ON "LINUX OR ANDROID OR DragonFly OR Haiku" OFF)
8484
cmake_dependent_option(ENABLE_THREADS "Enable multithreading" ON "Threads_FOUND" OFF)
8585
cmake_dependent_option(ENABLE_LIBZFS "Enable libzfs" ON "LINUX OR FreeBSD OR SunOS" OFF)
86-
cmake_dependent_option(ENABLE_PCIACCESS "Enable libpciaccess" ON "NetBSD OR OpenBSD OR SunOS OR Haiku" OFF)
86+
cmake_dependent_option(ENABLE_PCIACCESS "Enable libpciaccess" ON "NetBSD OR OpenBSD OR SunOS" OFF)
8787

8888
option(ENABLE_SYSTEM_YYJSON "Use system provided (instead of fastfetch embedded) yyjson library" OFF)
8989
option(ENABLE_ASAN "Build fastfetch with ASAN (address sanitizer)" OFF)
@@ -1143,7 +1143,7 @@ elseif(Haiku)
11431143
src/detection/diskio/diskio_nosupport.c
11441144
src/detection/displayserver/displayserver_haiku.cpp
11451145
src/detection/font/font_haiku.cpp
1146-
src/detection/gpu/gpu_general.c
1146+
src/detection/gpu/gpu_haiku.c
11471147
src/detection/gpu/gpu_pci.c
11481148
src/detection/gtk_qt/gtk.c
11491149
src/detection/host/host_nosupport.c

src/detection/gpu/gpu_haiku.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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

Comments
 (0)