2023-02-14 17:50:53 +08:00
|
|
|
#include "detection/gpu/gpu.h"
|
|
|
|
|
#include "detection/vulkan/vulkan.h"
|
2022-09-25 15:23:00 +08:00
|
|
|
#include "detection/temps/temps_linux.h"
|
2024-04-18 16:41:19 +08:00
|
|
|
#include "detection/cpu/cpu.h"
|
2024-06-22 22:03:28 +08:00
|
|
|
#include "detection/gpu/gpu_driver_specific.h"
|
2024-01-31 10:20:49 +08:00
|
|
|
#include "common/io/io.h"
|
2024-02-12 00:43:06 +08:00
|
|
|
#include "common/properties.h"
|
2023-02-01 15:56:25 +01:00
|
|
|
#include "util/stringUtils.h"
|
2022-09-05 17:42:42 +02:00
|
|
|
|
2024-01-31 10:20:49 +08:00
|
|
|
#include <inttypes.h>
|
2022-09-05 17:42:42 +02:00
|
|
|
|
2024-07-30 11:06:27 +08:00
|
|
|
#if __aarch64__
|
2024-07-30 16:43:56 +08:00
|
|
|
#if __has_include(<drm/asahi_drm.h>) && FF_HAVE_DRM
|
|
|
|
|
#include <drm/asahi_drm.h>
|
2024-07-30 11:06:27 +08:00
|
|
|
#include <drm.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <sys/ioctl.h>
|
2024-05-20 15:32:13 +08:00
|
|
|
#define FF_HAVE_ASAHI_DRM_H 1
|
2024-07-30 11:06:27 +08:00
|
|
|
#else
|
|
|
|
|
#warning "<asahi_drm.h> not available"
|
2024-05-20 15:32:13 +08:00
|
|
|
#endif
|
|
|
|
|
#endif
|
2024-05-19 20:01:32 +08:00
|
|
|
|
2024-07-30 11:06:27 +08:00
|
|
|
#define FF_STR_INDIR(x) #x
|
|
|
|
|
#define FF_STR(x) FF_STR_INDIR(x)
|
|
|
|
|
|
2024-05-20 21:07:28 +08:00
|
|
|
static bool pciDetectDriver(FFGPUResult* gpu, FFstrbuf* pciDir, FFstrbuf* buffer, FF_MAYBE_UNUSED const char* drmKey)
|
2024-05-19 20:01:32 +08:00
|
|
|
{
|
2024-07-11 09:51:56 +08:00
|
|
|
uint32_t pciDirLength = pciDir->length;
|
2024-01-31 10:20:49 +08:00
|
|
|
ffStrbufAppendS(pciDir, "/driver");
|
|
|
|
|
char pathBuf[PATH_MAX];
|
|
|
|
|
ssize_t resultLength = readlink(pciDir->chars, pathBuf, sizeof(pathBuf));
|
2024-07-11 09:51:56 +08:00
|
|
|
if(resultLength <= 0) return false;
|
|
|
|
|
|
|
|
|
|
const char* slash = memrchr(pathBuf, '/', (size_t) resultLength);
|
|
|
|
|
if (slash)
|
2023-01-12 12:54:04 +01:00
|
|
|
{
|
2024-07-11 09:51:56 +08:00
|
|
|
slash++;
|
|
|
|
|
ffStrbufSetNS(&gpu->driver, (uint32_t) (resultLength - (slash - pathBuf)), slash);
|
|
|
|
|
}
|
2023-06-24 19:38:12 +08:00
|
|
|
|
2024-07-11 09:51:56 +08:00
|
|
|
if (instance.config.general.detectVersion)
|
|
|
|
|
{
|
2024-01-31 10:20:49 +08:00
|
|
|
ffStrbufAppendS(pciDir, "/module/version");
|
|
|
|
|
if (ffReadFileBuffer(pciDir->chars, buffer))
|
|
|
|
|
{
|
|
|
|
|
ffStrbufTrimRightSpace(buffer);
|
|
|
|
|
ffStrbufAppendC(&gpu->driver, ' ');
|
|
|
|
|
ffStrbufAppend(&gpu->driver, buffer);
|
2024-07-11 09:51:56 +08:00
|
|
|
}
|
|
|
|
|
else if (ffStrbufEqualS(&gpu->driver, "zx"))
|
|
|
|
|
{
|
|
|
|
|
ffStrbufSubstrBefore(pciDir, pciDirLength);
|
|
|
|
|
ffStrbufAppendS(pciDir, "/zx_info/driver_version");
|
|
|
|
|
if (ffReadFileBuffer(pciDir->chars, buffer))
|
|
|
|
|
{
|
|
|
|
|
ffStrbufTrimRightSpace(buffer);
|
|
|
|
|
ffStrbufAppendC(&gpu->driver, ' ');
|
|
|
|
|
ffStrbufAppend(&gpu->driver, buffer);
|
|
|
|
|
}
|
2024-01-31 10:20:49 +08:00
|
|
|
}
|
2023-06-24 19:38:12 +08:00
|
|
|
}
|
2024-05-19 19:34:48 +08:00
|
|
|
|
2024-07-11 09:51:56 +08:00
|
|
|
return true;
|
2023-01-12 11:41:07 +01:00
|
|
|
}
|
|
|
|
|
|
2024-04-29 20:05:40 +08:00
|
|
|
static void pciDetectAmdSpecific(const FFGPUOptions* options, FFGPUResult* gpu, FFstrbuf* pciDir, FFstrbuf* buffer)
|
2024-04-17 14:21:30 +08:00
|
|
|
{
|
|
|
|
|
// https://www.kernel.org/doc/html/v5.10/gpu/amdgpu.html#mem-info-vis-vram-total
|
2024-04-29 20:05:40 +08:00
|
|
|
const uint32_t pciDirLen = pciDir->length;
|
|
|
|
|
|
|
|
|
|
ffStrbufAppendS(pciDir, "/hwmon/");
|
|
|
|
|
FF_AUTO_CLOSE_DIR DIR* dirp = opendir(pciDir->chars);
|
2024-05-03 08:28:20 +08:00
|
|
|
if (!dirp) return;
|
|
|
|
|
|
2024-04-29 20:28:50 +08:00
|
|
|
struct dirent* entry;
|
|
|
|
|
while ((entry = readdir(dirp)) != NULL)
|
|
|
|
|
{
|
|
|
|
|
if (entry->d_name[0] == '.') continue;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2024-04-29 20:05:40 +08:00
|
|
|
if (!entry) return;
|
|
|
|
|
ffStrbufAppendS(pciDir, entry->d_name);
|
|
|
|
|
ffStrbufAppendC(pciDir, '/');
|
|
|
|
|
|
|
|
|
|
const uint32_t hwmonLen = pciDir->length;
|
|
|
|
|
ffStrbufAppendS(pciDir, "in1_input"); // Northbridge voltage in millivolts (APUs only)
|
2024-07-08 09:11:53 +08:00
|
|
|
if (ffPathExists(pciDir->chars, FF_PATHTYPE_ANY))
|
2024-04-29 20:05:40 +08:00
|
|
|
gpu->type = FF_GPU_TYPE_INTEGRATED;
|
|
|
|
|
else
|
|
|
|
|
gpu->type = FF_GPU_TYPE_DISCRETE;
|
|
|
|
|
|
|
|
|
|
uint64_t value = 0;
|
|
|
|
|
if (options->temp)
|
|
|
|
|
{
|
|
|
|
|
ffStrbufSubstrBefore(pciDir, hwmonLen);
|
|
|
|
|
ffStrbufAppendS(pciDir, "temp1_input"); // The on die GPU temperature in millidegrees Celsius
|
|
|
|
|
if (ffReadFileBuffer(pciDir->chars, buffer) && (value = ffStrbufToUInt(buffer, 0)))
|
2024-04-29 20:43:19 +08:00
|
|
|
gpu->temperature = (double) value / 1000;
|
2024-04-29 20:05:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (options->driverSpecific)
|
2024-04-17 14:21:30 +08:00
|
|
|
{
|
2024-04-29 20:05:40 +08:00
|
|
|
ffStrbufSubstrBefore(pciDir, pciDirLen);
|
|
|
|
|
ffStrbufAppendS(pciDir, "/mem_info_vis_vram_total");
|
|
|
|
|
if (ffReadFileBuffer(pciDir->chars, buffer) && (value = ffStrbufToUInt(buffer, 0)))
|
2024-04-17 14:21:30 +08:00
|
|
|
{
|
2024-04-29 20:05:40 +08:00
|
|
|
ffStrbufSubstrBefore(pciDir, pciDir->length - (uint32_t) strlen("/mem_info_vis_vram_total"));
|
2024-04-29 14:17:13 +08:00
|
|
|
ffStrbufAppendS(pciDir, "/mem_info_vis_vram_used");
|
2024-04-29 20:05:40 +08:00
|
|
|
if (ffReadFileBuffer(pciDir->chars, buffer) && (value = ffStrbufToUInt(buffer, 0)))
|
|
|
|
|
{
|
|
|
|
|
if (gpu->type == FF_GPU_TYPE_DISCRETE)
|
|
|
|
|
gpu->dedicated.used = value;
|
|
|
|
|
else
|
|
|
|
|
gpu->shared.used = value;
|
|
|
|
|
}
|
2024-04-17 14:21:30 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-29 20:05:40 +08:00
|
|
|
static void pciDetectIntelSpecific(FFGPUResult* gpu, FFstrbuf* pciDir, FFstrbuf* buffer)
|
2024-04-18 16:41:19 +08:00
|
|
|
{
|
|
|
|
|
// Works for Intel GPUs
|
|
|
|
|
// https://patchwork.kernel.org/project/intel-gfx/patch/1422039866-11572-3-git-send-email-ville.syrjala@linux.intel.com/
|
2024-04-29 20:05:40 +08:00
|
|
|
|
|
|
|
|
if (ffStrbufStartsWithS(&gpu->name, "Intel "))
|
|
|
|
|
ffStrbufSubstrAfter(&gpu->name, (uint32_t) strlen("Intel "));
|
|
|
|
|
gpu->type = ffStrbufStartsWithIgnCaseS(&gpu->name, "Arc ") ? FF_GPU_TYPE_DISCRETE : FF_GPU_TYPE_INTEGRATED;
|
2024-05-19 18:40:32 +08:00
|
|
|
|
2024-07-12 19:24:55 +08:00
|
|
|
if (ffStrbufEqualS(&gpu->driver, "xe"))
|
2024-05-19 18:40:32 +08:00
|
|
|
{
|
2024-07-12 19:24:55 +08:00
|
|
|
ffStrbufAppendS(pciDir, "/tile0/gt0/freq0/max_freq");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ffStrbufAppendS(pciDir, "/drm/");
|
|
|
|
|
FF_AUTO_CLOSE_DIR DIR* dirp = opendir(pciDir->chars);
|
|
|
|
|
if (!dirp) return;
|
|
|
|
|
struct dirent* entry;
|
|
|
|
|
while ((entry = readdir(dirp)) != NULL)
|
|
|
|
|
{
|
|
|
|
|
if (ffStrStartsWith(entry->d_name, "card")) break;
|
|
|
|
|
}
|
|
|
|
|
if (!entry) return;
|
|
|
|
|
ffStrbufAppendS(pciDir, entry->d_name);
|
|
|
|
|
ffStrbufAppendS(pciDir, "/gt_max_freq_mhz");
|
2024-05-19 18:40:32 +08:00
|
|
|
}
|
|
|
|
|
if (ffReadFileBuffer(pciDir->chars, buffer))
|
2024-07-17 14:52:35 +08:00
|
|
|
gpu->frequency = (uint32_t) ffStrbufToUInt(buffer, 0);
|
2024-04-18 16:41:19 +08:00
|
|
|
}
|
|
|
|
|
|
2024-01-31 10:20:49 +08:00
|
|
|
static bool loadPciIds(FFstrbuf* pciids)
|
2022-09-05 17:42:42 +02:00
|
|
|
{
|
2024-02-27 15:20:02 +08:00
|
|
|
#ifdef FF_CUSTOM_PCI_IDS_PATH
|
2024-05-04 10:01:29 +08:00
|
|
|
|
2024-02-27 15:20:02 +08:00
|
|
|
ffReadFileBuffer(FF_STR(FF_CUSTOM_PCI_IDS_PATH), pciids);
|
|
|
|
|
if (pciids->length > 0) return true;
|
2024-05-04 10:01:29 +08:00
|
|
|
|
|
|
|
|
#else
|
2024-02-27 15:20:02 +08:00
|
|
|
|
2024-02-26 13:30:09 +08:00
|
|
|
ffReadFileBuffer(FASTFETCH_TARGET_DIR_USR "/share/hwdata/pci.ids", pciids);
|
2024-01-31 10:20:49 +08:00
|
|
|
if (pciids->length > 0) return true;
|
2022-09-05 17:42:42 +02:00
|
|
|
|
2024-02-26 13:30:09 +08:00
|
|
|
ffReadFileBuffer(FASTFETCH_TARGET_DIR_USR "/share/misc/pci.ids", pciids); // debian?
|
2024-01-31 10:20:49 +08:00
|
|
|
if (pciids->length > 0) return true;
|
2022-09-05 17:42:42 +02:00
|
|
|
|
2024-02-26 13:30:09 +08:00
|
|
|
ffReadFileBuffer(FASTFETCH_TARGET_DIR_USR "/local/share/hwdata/pci.ids", pciids);
|
2024-01-31 10:20:49 +08:00
|
|
|
if (pciids->length > 0) return true;
|
2022-09-05 17:42:42 +02:00
|
|
|
|
2024-05-04 10:01:29 +08:00
|
|
|
#endif
|
|
|
|
|
|
2024-01-31 10:20:49 +08:00
|
|
|
return false;
|
|
|
|
|
}
|
2023-12-29 15:12:41 +08:00
|
|
|
|
2024-05-19 20:01:32 +08:00
|
|
|
static const char* detectPci(const FFGPUOptions* options, FFlist* gpus, FFstrbuf* buffer, FFstrbuf* deviceDir, const char* drmKey)
|
2024-01-31 10:20:49 +08:00
|
|
|
{
|
2024-05-19 19:34:48 +08:00
|
|
|
const uint32_t drmDirPathLength = deviceDir->length;
|
2024-04-18 16:41:19 +08:00
|
|
|
uint32_t vendorId, deviceId, subVendorId, subDeviceId;
|
|
|
|
|
uint8_t classId, subclassId;
|
|
|
|
|
if (sscanf(buffer->chars + strlen("pci:"), "v%8" SCNx32 "d%8" SCNx32 "sv%8" SCNx32 "sd%8" SCNx32 "bc%2" SCNx8 "sc%2" SCNx8, &vendorId, &deviceId, &subVendorId, &subDeviceId, &classId, &subclassId) != 6)
|
|
|
|
|
return "Invalid modalias string";
|
|
|
|
|
|
|
|
|
|
if (classId != 0x03 /*PCI_BASE_CLASS_DISPLAY*/)
|
2024-04-18 21:00:47 +08:00
|
|
|
return "Not a GPU device";
|
2024-04-18 16:41:19 +08:00
|
|
|
|
|
|
|
|
char pciPath[PATH_MAX];
|
2024-05-19 19:34:48 +08:00
|
|
|
const char* pPciPath = NULL;
|
2024-05-19 20:01:32 +08:00
|
|
|
if (drmKey)
|
2024-05-19 19:34:48 +08:00
|
|
|
{
|
|
|
|
|
ssize_t pathLength = readlink(deviceDir->chars, pciPath, sizeof(pciPath) - 1);
|
|
|
|
|
if (pathLength <= 0)
|
|
|
|
|
return "Unable to get PCI device path";
|
|
|
|
|
pciPath[pathLength] = '\0';
|
|
|
|
|
pPciPath = strrchr(pciPath, '/');
|
|
|
|
|
if (__builtin_expect(pPciPath != NULL, true))
|
|
|
|
|
pPciPath++;
|
|
|
|
|
else
|
|
|
|
|
pPciPath = pciPath;
|
|
|
|
|
}
|
2024-04-18 16:41:19 +08:00
|
|
|
else
|
2024-05-19 19:34:48 +08:00
|
|
|
{
|
|
|
|
|
pPciPath = memrchr(deviceDir->chars, '/', deviceDir->length) + 1;
|
|
|
|
|
}
|
2024-04-18 16:41:19 +08:00
|
|
|
|
|
|
|
|
uint32_t pciDomain, pciBus, pciDevice, pciFunc;
|
|
|
|
|
if (sscanf(pPciPath, "%" SCNx32 ":%" SCNx32 ":%" SCNx32 ".%" SCNx32, &pciDomain, &pciBus, &pciDevice, &pciFunc) != 4)
|
|
|
|
|
return "Invalid PCI device path";
|
|
|
|
|
|
2024-07-09 14:00:04 +08:00
|
|
|
ffStrbufAppendS(deviceDir, "/enable");
|
|
|
|
|
if (ffReadFileBuffer(deviceDir->chars, buffer))
|
|
|
|
|
{
|
|
|
|
|
if (!ffStrbufStartsWithC(buffer, '1'))
|
|
|
|
|
return "GPU disabled";
|
|
|
|
|
}
|
2024-07-11 08:59:07 +08:00
|
|
|
ffStrbufSubstrBefore(deviceDir, drmDirPathLength);
|
2024-07-09 14:00:04 +08:00
|
|
|
|
2024-04-18 16:41:19 +08:00
|
|
|
FFGPUResult* gpu = (FFGPUResult*)ffListAdd(gpus);
|
|
|
|
|
ffStrbufInitStatic(&gpu->vendor, ffGetGPUVendorString((uint16_t) vendorId));
|
|
|
|
|
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) pciDomain << 6) | ((uint64_t) pciBus << 4) | (deviceId << 2) | pciFunc;
|
|
|
|
|
gpu->frequency = FF_GPU_FREQUENCY_UNSET;
|
|
|
|
|
|
2024-05-19 20:01:32 +08:00
|
|
|
if (drmKey) ffStrbufSetF(&gpu->platformApi, "DRM (%s)", drmKey);
|
|
|
|
|
|
2024-04-18 16:41:19 +08:00
|
|
|
if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_AMD)
|
|
|
|
|
{
|
2024-05-19 19:34:48 +08:00
|
|
|
ffStrbufAppendS(deviceDir, "/revision");
|
|
|
|
|
if (ffReadFileBuffer(deviceDir->chars, buffer))
|
2024-04-18 16:41:19 +08:00
|
|
|
{
|
|
|
|
|
char* pend;
|
|
|
|
|
uint64_t revision = strtoul(buffer->chars, &pend, 16);
|
|
|
|
|
if (pend != buffer->chars)
|
|
|
|
|
{
|
|
|
|
|
char query[32];
|
|
|
|
|
snprintf(query, sizeof(query), "%X,\t%X,", (unsigned) deviceId, (unsigned) revision);
|
2024-05-04 10:01:29 +08:00
|
|
|
#ifdef FF_CUSTOM_AMDGPU_IDS_PATH
|
|
|
|
|
ffParsePropFile(FF_STR(FF_CUSTOM_AMDGPU_IDS_PATH), query, &gpu->name);
|
|
|
|
|
#else
|
2024-04-18 16:41:19 +08:00
|
|
|
ffParsePropFileData("libdrm/amdgpu.ids", query, &gpu->name);
|
2024-05-04 10:01:29 +08:00
|
|
|
#endif
|
2024-04-18 16:41:19 +08:00
|
|
|
}
|
|
|
|
|
}
|
2024-05-19 19:34:48 +08:00
|
|
|
ffStrbufSubstrBefore(deviceDir, drmDirPathLength);
|
2024-04-18 16:41:19 +08:00
|
|
|
}
|
2022-09-05 17:42:42 +02:00
|
|
|
|
2024-04-18 16:41:19 +08:00
|
|
|
if (gpu->name.length == 0)
|
|
|
|
|
{
|
|
|
|
|
static FFstrbuf pciids;
|
|
|
|
|
if (pciids.chars == NULL)
|
|
|
|
|
{
|
|
|
|
|
ffStrbufInit(&pciids);
|
|
|
|
|
loadPciIds(&pciids);
|
|
|
|
|
}
|
2024-05-04 10:01:29 +08:00
|
|
|
ffGPUParsePciIds(&pciids, subclassId, (uint16_t) vendorId, (uint16_t) deviceId, gpu);
|
2024-04-18 16:41:19 +08:00
|
|
|
}
|
2022-09-05 17:42:42 +02:00
|
|
|
|
2024-05-19 20:01:32 +08:00
|
|
|
pciDetectDriver(gpu, deviceDir, buffer, drmKey);
|
2024-05-19 19:34:48 +08:00
|
|
|
ffStrbufSubstrBefore(deviceDir, drmDirPathLength);
|
2023-06-22 04:06:08 +00:00
|
|
|
|
2024-04-29 20:05:40 +08:00
|
|
|
if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_AMD)
|
2023-10-27 21:05:03 +08:00
|
|
|
{
|
2024-05-19 19:34:48 +08:00
|
|
|
pciDetectAmdSpecific(options, gpu, deviceDir, buffer);
|
|
|
|
|
ffStrbufSubstrBefore(deviceDir, drmDirPathLength);
|
2024-04-18 16:41:19 +08:00
|
|
|
}
|
2024-04-29 20:05:40 +08:00
|
|
|
else if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_INTEL)
|
|
|
|
|
{
|
2024-05-19 19:34:48 +08:00
|
|
|
pciDetectIntelSpecific(gpu, deviceDir, buffer);
|
|
|
|
|
ffStrbufSubstrBefore(deviceDir, drmDirPathLength);
|
2024-04-29 20:05:40 +08:00
|
|
|
}
|
|
|
|
|
else if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA)
|
|
|
|
|
{
|
|
|
|
|
if (options->temp || options->driverSpecific)
|
|
|
|
|
{
|
|
|
|
|
ffDetectNvidiaGpuInfo(&(FFGpuDriverCondition) {
|
|
|
|
|
.type = FF_GPU_DRIVER_CONDITION_TYPE_BUS_ID,
|
|
|
|
|
.pciBusId = {
|
|
|
|
|
.domain = pciDomain,
|
|
|
|
|
.bus = pciBus,
|
|
|
|
|
.device = pciDevice,
|
|
|
|
|
.func = pciFunc,
|
|
|
|
|
},
|
|
|
|
|
}, (FFGpuDriverResult) {
|
|
|
|
|
.temp = options->temp ? &gpu->temperature : NULL,
|
|
|
|
|
.memory = options->driverSpecific ? &gpu->dedicated : NULL,
|
|
|
|
|
.coreCount = options->driverSpecific ? (uint32_t*) &gpu->coreCount : NULL,
|
|
|
|
|
.type = &gpu->type,
|
2024-06-28 22:17:37 +08:00
|
|
|
.frequency = options->driverSpecific ? &gpu->frequency : NULL,
|
2024-04-29 20:05:40 +08:00
|
|
|
}, "libnvidia-ml.so");
|
|
|
|
|
}
|
2023-03-13 17:45:36 +08:00
|
|
|
|
2024-04-29 20:05:40 +08:00
|
|
|
if (gpu->type == FF_GPU_TYPE_UNKNOWN)
|
|
|
|
|
{
|
|
|
|
|
if (ffStrbufStartsWithIgnCaseS(&gpu->name, "GeForce") ||
|
|
|
|
|
ffStrbufStartsWithIgnCaseS(&gpu->name, "Quadro") ||
|
|
|
|
|
ffStrbufStartsWithIgnCaseS(&gpu->name, "Tesla"))
|
|
|
|
|
gpu->type = FF_GPU_TYPE_DISCRETE;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-09-05 17:42:42 +02:00
|
|
|
|
2024-04-18 16:41:19 +08:00
|
|
|
return NULL;
|
|
|
|
|
}
|
2024-01-31 10:20:49 +08:00
|
|
|
|
2024-05-19 20:01:32 +08:00
|
|
|
FF_MAYBE_UNUSED static const char* detectAsahi(FFlist* gpus, FFstrbuf* buffer, FFstrbuf* drmDir, const char* drmKey)
|
2024-04-18 16:41:19 +08:00
|
|
|
{
|
|
|
|
|
uint32_t index = ffStrbufFirstIndexS(buffer, "apple,agx-t");
|
|
|
|
|
if (index == buffer->length) return "display-subsystem?";
|
2024-05-03 10:07:16 +08:00
|
|
|
index += (uint32_t) strlen("apple,agx-t");
|
2024-04-18 16:41:19 +08:00
|
|
|
|
|
|
|
|
FFGPUResult* gpu = (FFGPUResult*)ffListAdd(gpus);
|
|
|
|
|
gpu->deviceId = strtoul(buffer->chars + index, NULL, 10);
|
2024-04-18 21:00:47 +08:00
|
|
|
ffStrbufInitStatic(&gpu->name, ffCPUAppleCodeToName((uint32_t) gpu->deviceId));
|
2024-04-18 16:41:19 +08:00
|
|
|
ffStrbufInitStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_APPLE);
|
|
|
|
|
ffStrbufInit(&gpu->driver);
|
2024-05-20 15:32:13 +08:00
|
|
|
ffStrbufInitF(&gpu->platformApi, "DRM (%s)", drmKey);
|
2024-04-18 16:41:19 +08:00
|
|
|
gpu->temperature = FF_GPU_TEMP_UNSET;
|
|
|
|
|
gpu->coreCount = FF_GPU_CORE_COUNT_UNSET;
|
|
|
|
|
gpu->type = FF_GPU_TYPE_INTEGRATED;
|
|
|
|
|
gpu->dedicated.total = gpu->dedicated.used = gpu->shared.total = gpu->shared.used = FF_GPU_VMEM_SIZE_UNSET;
|
|
|
|
|
gpu->frequency = FF_GPU_FREQUENCY_UNSET;
|
|
|
|
|
|
2024-05-19 20:01:32 +08:00
|
|
|
pciDetectDriver(gpu, drmDir, buffer, drmKey);
|
2024-01-31 10:20:49 +08:00
|
|
|
|
2024-05-20 15:32:13 +08:00
|
|
|
#if FF_HAVE_ASAHI_DRM_H
|
|
|
|
|
ffStrbufSetS(buffer, "/dev/dri/");
|
|
|
|
|
ffStrbufAppendS(buffer, drmKey);
|
|
|
|
|
FF_AUTO_CLOSE_FD int fd = open(buffer->chars, O_RDONLY);
|
|
|
|
|
if (fd >= 0)
|
|
|
|
|
{
|
|
|
|
|
struct drm_asahi_params_global paramsGlobal = {};
|
|
|
|
|
if (ioctl(fd, DRM_IOCTL_ASAHI_GET_PARAMS, &(struct drm_asahi_get_params){
|
|
|
|
|
.param_group = DRM_ASAHI_GET_PARAMS,
|
|
|
|
|
.pointer = (uint64_t) ¶msGlobal,
|
|
|
|
|
.size = sizeof(paramsGlobal),
|
|
|
|
|
}) >= 0)
|
|
|
|
|
{
|
|
|
|
|
gpu->coreCount = (int) paramsGlobal.num_cores_total_active;
|
2024-07-17 14:52:35 +08:00
|
|
|
gpu->frequency = paramsGlobal.max_frequency_khz / 1000;
|
2024-05-20 15:32:13 +08:00
|
|
|
gpu->deviceId = paramsGlobal.chip_id;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-04-18 16:41:19 +08:00
|
|
|
return NULL;
|
|
|
|
|
}
|
2024-01-31 10:20:49 +08:00
|
|
|
|
2024-04-18 16:41:19 +08:00
|
|
|
static const char* drmDetectGPUs(const FFGPUOptions* options, FFlist* gpus)
|
|
|
|
|
{
|
|
|
|
|
FF_STRBUF_AUTO_DESTROY drmDir = ffStrbufCreateA(64);
|
|
|
|
|
ffStrbufAppendS(&drmDir, "/sys/class/drm/");
|
|
|
|
|
const uint32_t drmDirLength = drmDir.length;
|
2024-01-31 10:20:49 +08:00
|
|
|
|
2024-04-18 16:41:19 +08:00
|
|
|
FF_AUTO_CLOSE_DIR DIR* dir = opendir(drmDir.chars);
|
|
|
|
|
if(dir == NULL)
|
2024-04-18 21:00:47 +08:00
|
|
|
return "Failed to open `/sys/class/drm/`";
|
2024-02-12 00:43:06 +08:00
|
|
|
|
2024-04-18 16:41:19 +08:00
|
|
|
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
|
2022-09-05 17:42:42 +02:00
|
|
|
|
2024-04-18 16:41:19 +08:00
|
|
|
struct dirent* entry;
|
|
|
|
|
while ((entry = readdir(dir)) != NULL)
|
|
|
|
|
{
|
|
|
|
|
if (!ffStrStartsWith(entry->d_name, "card") ||
|
|
|
|
|
strchr(entry->d_name + 4, '-') != NULL)
|
|
|
|
|
continue;
|
2024-04-17 14:21:30 +08:00
|
|
|
|
2024-04-18 16:41:19 +08:00
|
|
|
ffStrbufAppendS(&drmDir, entry->d_name);
|
2023-03-13 17:45:36 +08:00
|
|
|
|
2024-04-18 16:41:19 +08:00
|
|
|
ffStrbufAppendS(&drmDir, "/device/modalias");
|
|
|
|
|
if (!ffReadFileBuffer(drmDir.chars, &buffer))
|
|
|
|
|
continue;
|
|
|
|
|
ffStrbufSubstrBefore(&drmDir, drmDir.length - (uint32_t) strlen("/modalias"));
|
2022-09-05 17:42:42 +02:00
|
|
|
|
2024-04-18 16:41:19 +08:00
|
|
|
if (ffStrbufStartsWithS(&buffer, "pci:"))
|
2024-05-19 19:34:48 +08:00
|
|
|
detectPci(options, gpus, &buffer, &drmDir, entry->d_name);
|
2024-04-18 16:41:19 +08:00
|
|
|
#ifdef __aarch64__
|
|
|
|
|
else if (ffStrbufStartsWithS(&buffer, "of:"))
|
2024-05-19 20:01:32 +08:00
|
|
|
detectAsahi(gpus, &buffer, &drmDir, entry->d_name);
|
2024-01-31 10:20:49 +08:00
|
|
|
#endif
|
2024-04-18 16:41:19 +08:00
|
|
|
|
|
|
|
|
ffStrbufSubstrBefore(&drmDir, drmDirLength);
|
2022-09-05 17:42:42 +02:00
|
|
|
}
|
|
|
|
|
|
2022-09-16 18:11:39 +08:00
|
|
|
return NULL;
|
2022-09-05 17:42:42 +02:00
|
|
|
}
|
|
|
|
|
|
2024-04-18 21:00:47 +08:00
|
|
|
|
|
|
|
|
static const char* pciDetectGPUs(const FFGPUOptions* options, FFlist* gpus)
|
|
|
|
|
{
|
|
|
|
|
//https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-bus-pci
|
|
|
|
|
const char* pciDirPath = "/sys/bus/pci/devices/";
|
|
|
|
|
|
|
|
|
|
FF_AUTO_CLOSE_DIR DIR* dirp = opendir(pciDirPath);
|
|
|
|
|
if(dirp == NULL)
|
|
|
|
|
return "Failed to open `/sys/bus/pci/devices/`";
|
|
|
|
|
|
|
|
|
|
FF_STRBUF_AUTO_DESTROY pciDir = ffStrbufCreateA(64);
|
|
|
|
|
ffStrbufAppendS(&pciDir, pciDirPath);
|
|
|
|
|
|
|
|
|
|
const uint32_t pciBaseDirLength = pciDir.length;
|
|
|
|
|
|
|
|
|
|
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
|
|
|
|
|
|
|
|
|
|
struct dirent* entry;
|
|
|
|
|
while((entry = readdir(dirp)) != NULL)
|
|
|
|
|
{
|
|
|
|
|
if(entry->d_name[0] == '.')
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
ffStrbufSubstrBefore(&pciDir, pciBaseDirLength);
|
|
|
|
|
ffStrbufAppendS(&pciDir, entry->d_name);
|
|
|
|
|
const uint32_t pciDevDirLength = pciDir.length;
|
|
|
|
|
|
|
|
|
|
ffStrbufAppendS(&pciDir, "/modalias");
|
|
|
|
|
if (!ffReadFileBuffer(pciDir.chars, &buffer))
|
|
|
|
|
continue;
|
|
|
|
|
ffStrbufSubstrBefore(&pciDir, pciDevDirLength);
|
|
|
|
|
assert(ffStrbufStartsWithS(&buffer, "pci:"));
|
|
|
|
|
|
2024-05-19 19:34:48 +08:00
|
|
|
detectPci(options, gpus, &buffer, &pciDir, NULL);
|
2024-04-18 21:00:47 +08:00
|
|
|
ffStrbufSubstrBefore(&pciDir, pciBaseDirLength);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus)
|
2022-09-05 17:42:42 +02:00
|
|
|
{
|
2024-05-20 16:45:23 +08:00
|
|
|
if (options->detectionMethod == FF_GPU_DETECTION_METHOD_AUTO)
|
|
|
|
|
{
|
|
|
|
|
#ifdef FF_HAVE_DIRECTX_HEADERS
|
|
|
|
|
const char* ffGPUDetectByDirectX(const FFGPUOptions* options, FFlist* gpus);
|
|
|
|
|
if (ffGPUDetectByDirectX(options, gpus) == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
#endif
|
2024-04-18 21:00:47 +08:00
|
|
|
|
2024-05-20 16:45:23 +08:00
|
|
|
if (drmDetectGPUs(options, gpus) == NULL && gpus->length > 0)
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2024-04-18 21:00:47 +08:00
|
|
|
return pciDetectGPUs(options, gpus);
|
2022-09-05 17:42:42 +02:00
|
|
|
}
|