Skip to content

Commit

Permalink
GPU (Haiku): use system API to fetch PCI devices
Browse files Browse the repository at this point in the history
  • Loading branch information
CarterLi committed Feb 13, 2025
1 parent b8e25bd commit 464e00d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ cmake_dependent_option(ENABLE_DIRECTX_HEADERS "Enable DirectX headers for WSL" O
cmake_dependent_option(ENABLE_ELF "Enable libelf" ON "LINUX OR ANDROID OR DragonFly OR Haiku" OFF)
cmake_dependent_option(ENABLE_THREADS "Enable multithreading" ON "Threads_FOUND" OFF)
cmake_dependent_option(ENABLE_LIBZFS "Enable libzfs" ON "LINUX OR FreeBSD OR SunOS" OFF)
cmake_dependent_option(ENABLE_PCIACCESS "Enable libpciaccess" ON "NetBSD OR OpenBSD OR SunOS OR Haiku" OFF)
cmake_dependent_option(ENABLE_PCIACCESS "Enable libpciaccess" ON "NetBSD OR OpenBSD OR SunOS" OFF)

option(ENABLE_SYSTEM_YYJSON "Use system provided (instead of fastfetch embedded) yyjson library" OFF)
option(ENABLE_ASAN "Build fastfetch with ASAN (address sanitizer)" OFF)
Expand Down Expand Up @@ -1143,7 +1143,7 @@ elseif(Haiku)
src/detection/diskio/diskio_nosupport.c
src/detection/displayserver/displayserver_haiku.cpp
src/detection/font/font_haiku.cpp
src/detection/gpu/gpu_general.c
src/detection/gpu/gpu_haiku.c
src/detection/gpu/gpu_pci.c
src/detection/gtk_qt/gtk.c
src/detection/host/host_nosupport.c
Expand Down
43 changes: 43 additions & 0 deletions src/detection/gpu/gpu_haiku.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "gpu.h"
#include "common/io/io.h"

#include <private/drivers/poke.h>

const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* gpus)
{
FF_AUTO_CLOSE_FD int pokefd = open(POKE_DEVICE_FULLNAME, O_RDWR);
if (pokefd < 0) return "open(POKE_DEVICE_FULLNAME) failed";

pci_info dev;
pci_info_args cmd = {
.signature = POKE_SIGNATURE,
.info = &dev,
};

for (cmd.index = 0; ioctl(pokefd, POKE_GET_NTH_PCI_INFO, &cmd) == B_OK && cmd.status == B_OK; ++cmd.index)
{
if (dev.class_base != 0x03 /*PCI_BASE_CLASS_DISPLAY*/)
continue;

FFGPUResult* gpu = (FFGPUResult*)ffListAdd(gpus);
ffStrbufInitStatic(&gpu->vendor, ffGPUGetVendorString(dev.vendor_id));
ffStrbufInit(&gpu->name);
ffStrbufInit(&gpu->driver);
ffStrbufInit(&gpu->platformApi);
gpu->temperature = FF_GPU_TEMP_UNSET;
gpu->coreCount = FF_GPU_CORE_COUNT_UNSET;
gpu->type = FF_GPU_TYPE_UNKNOWN;
gpu->dedicated.total = gpu->dedicated.used = gpu->shared.total = gpu->shared.used = FF_GPU_VMEM_SIZE_UNSET;
gpu->deviceId = ((uint64_t) dev.bus << 4) | ((uint64_t) dev.device << 2) | (uint64_t) dev.function;
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;
}

0 comments on commit 464e00d

Please sign in to comment.