summaryrefslogtreecommitdiffstats
path: root/src/detection/cpu/cpu_haiku.c
diff options
context:
space:
mode:
authorsumuel <samuel@yakubos.org>2026-08-17 20:44:55 +0000
committersumuel <samuel@yakubos.org>2026-08-17 20:44:55 +0000
commit76424950e373d3b04ac3dd13019151bfba3e8423 (patch)
tree4c3cfdbda039e592b9186be3e28f8d7cfd439e8a /src/detection/cpu/cpu_haiku.c
Add the files
Diffstat (limited to 'src/detection/cpu/cpu_haiku.c')
-rw-r--r--src/detection/cpu/cpu_haiku.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/detection/cpu/cpu_haiku.c b/src/detection/cpu/cpu_haiku.c
new file mode 100644
index 0000000..9a8acb5
--- /dev/null
+++ b/src/detection/cpu/cpu_haiku.c
@@ -0,0 +1,68 @@
+#include "cpu.h"
+#include "common/mallocHelper.h"
+
+#include <OS.h>
+#include <private/shared/cpu_type.h>
+
+const char* ffDetectCPUImpl(FF_A_UNUSED const FFCPUOptions* options, FFCPUResult* cpu) {
+ system_info sysInfo;
+ if (get_system_info(&sysInfo) != B_OK) {
+ return "get_system_info() failed";
+ }
+
+ uint32 topoNodeCount = 0;
+ get_cpu_topology_info(NULL, &topoNodeCount);
+ if (topoNodeCount == 0) {
+ return "get_cpu_topology_info(NULL) failed";
+ }
+
+ FF_AUTO_FREE cpu_topology_node_info* topology = malloc(sizeof(*topology) * topoNodeCount);
+ if (get_cpu_topology_info(topology, &topoNodeCount) != B_OK) {
+ return "get_cpu_topology_info(topology) failed";
+ }
+
+ enum cpu_platform platform = B_CPU_UNKNOWN;
+ enum cpu_vendor cpuVendor = B_CPU_VENDOR_UNKNOWN;
+ uint32 cpuModel = 0, frequency = 0;
+ uint16_t packages = 0, cores = 0;
+
+ for (uint32 i = 0; i < topoNodeCount; i++) {
+ switch (topology[i].type) {
+ case B_TOPOLOGY_ROOT:
+ platform = topology[i].data.root.platform;
+ break;
+
+ case B_TOPOLOGY_PACKAGE:
+ cpuVendor = topology[i].data.package.vendor;
+ ++packages;
+ break;
+
+ case B_TOPOLOGY_CORE:
+ cpuModel = topology[i].data.core.model;
+ uint32_t freq = (uint32_t) (topology[i].data.core.default_frequency / 1000000);
+ frequency = freq > frequency ? freq : frequency;
+ ++cores;
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ const char* model = get_cpu_model_string(platform, cpuVendor, cpuModel);
+ if (model) {
+ ffStrbufSetS(&cpu->name, model);
+ } else {
+ ffStrbufSetF(&cpu->name, "(Unknown %" B_PRIx32 ")", cpuModel);
+ }
+ ffStrbufSetS(&cpu->vendor, get_cpu_vendor_string(cpuVendor));
+
+ ffCPUDetectByCpuid(cpu);
+ if (cpu->frequencyBase < frequency) {
+ cpu->frequencyBase = frequency;
+ }
+ cpu->packages = packages;
+ cpu->coresPhysical = cores;
+ cpu->coresOnline = cpu->coresLogical = (uint16_t) sysInfo.cpu_count;
+ return NULL;
+}