From a03687553be31d3d7b6dd6ba7818853f8cd073e4 Mon Sep 17 00:00:00 2001 From: Alexander von Gluck IV Date: Fri, 20 Aug 2021 08:01:00 -0500 Subject: [PATCH] platform/efi: platform_cpu_info * This models the CpuInfo into a cross-architecture platform_cpu_info * Originally I was looking at merging this with "arch_cpu_info" however that is "overall cpu" while CpuInfo is "indivial core information" packed into an array. * Since every dtb platform will report individual cores in fdt, having a common cpu core info struct with at minimum the core id makes sense. * This could likely be refined further to some kind of core info packed inside of arch_cpu_info, but this will fix arm,arm64,etc for now until someone wants to dive into that. Change-Id: Ia18a352403cd0da7130c1e637fc205d4311478ef Reviewed-on: https://review.haiku-os.org/c/haiku/+/4363 Reviewed-by: Fredrik Holmqvist Tested-by: Commit checker robot --- .../kernel/boot/platform/efi/arch_smp.h | 9 +++++---- .../boot/platform/efi/arch/arm/arch_smp.cpp | 18 ++++++++++++++++++ .../platform/efi/arch/riscv64/arch_smp.cpp | 4 ++-- src/system/boot/platform/efi/dtb.cpp | 5 +++-- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/headers/private/kernel/boot/platform/efi/arch_smp.h b/headers/private/kernel/boot/platform/efi/arch_smp.h index 4a87605391..c7fb22d27a 100644 --- a/headers/private/kernel/boot/platform/efi/arch_smp.h +++ b/headers/private/kernel/boot/platform/efi/arch_smp.h @@ -5,17 +5,18 @@ #ifndef KERNEL_BOOT_PLATFORM_EFI_ARCH_SMP_H #define KERNEL_BOOT_PLATFORM_EFI_ARCH_SMP_H + #include -#ifdef __riscv +#if defined(__riscv) || defined(__ARM__) || defined(__ARM64__) +// These platforms take inventory of cpu cores from fdt -struct CpuInfo { +struct platform_cpu_info { uint32 id; }; -void arch_smp_register_cpu(CpuInfo** cpu); - +void arch_smp_register_cpu(platform_cpu_info** cpu); #endif diff --git a/src/system/boot/platform/efi/arch/arm/arch_smp.cpp b/src/system/boot/platform/efi/arch/arm/arch_smp.cpp index 84e25b57ac..0a989f4c52 100644 --- a/src/system/boot/platform/efi/arch/arm/arch_smp.cpp +++ b/src/system/boot/platform/efi/arch/arm/arch_smp.cpp @@ -25,6 +25,24 @@ #endif +static platform_cpu_info sCpus[SMP_MAX_CPUS]; +uint32 sCpuCount = 0; + + +void +arch_smp_register_cpu(platform_cpu_info** cpu) +{ + dprintf("arch_smp_register_cpu()\n"); + uint32 newCount = sCpuCount + 1; + if (newCount > SMP_MAX_CPUS) { + *cpu = NULL; + return; + } + *cpu = &sCpus[sCpuCount]; + sCpuCount = newCount; +} + + int arch_smp_get_current_cpu(void) { diff --git a/src/system/boot/platform/efi/arch/riscv64/arch_smp.cpp b/src/system/boot/platform/efi/arch/riscv64/arch_smp.cpp index e9839d6dae..6162e98fba 100644 --- a/src/system/boot/platform/efi/arch/riscv64/arch_smp.cpp +++ b/src/system/boot/platform/efi/arch/riscv64/arch_smp.cpp @@ -38,7 +38,7 @@ struct CpuEntryInfo { }; -static CpuInfo sCpus[SMP_MAX_CPUS]; +static platform_cpu_info sCpus[SMP_MAX_CPUS]; uint32 sCpuCount = 0; @@ -52,7 +52,7 @@ CpuEntry(int hartId, CpuEntryInfo* info) void -arch_smp_register_cpu(CpuInfo** cpu) +arch_smp_register_cpu(platform_cpu_info** cpu) { dprintf("arch_smp_register_cpu()\n"); uint32 newCount = sCpuCount + 1; diff --git a/src/system/boot/platform/efi/dtb.cpp b/src/system/boot/platform/efi/dtb.cpp index 3b54c980d7..d97205b047 100644 --- a/src/system/boot/platform/efi/dtb.cpp +++ b/src/system/boot/platform/efi/dtb.cpp @@ -356,11 +356,12 @@ HandleFdt(const void* fdt, int node, uint32 addressCells, uint32 sizeCells, if (deviceType != NULL) { if (strcmp(deviceType, "cpu") == 0) { - CpuInfo* info; + platform_cpu_info* info; arch_smp_register_cpu(&info); if (info == NULL) return; - info->id = fdt32_to_cpu(*(uint32*)fdt_getprop(fdt, node, "reg", NULL)); + info->id = fdt32_to_cpu(*(uint32*)fdt_getprop(fdt, node, + "reg", NULL)); dprintf("cpu\n"); dprintf(" id: %" B_PRIu32 "\n", info->id); }