From 44807acaefc71cd4985779e742e6791cb9daf65d Mon Sep 17 00:00:00 2001 From: Arthur Heymans Date: Tue, 13 Sep 2022 12:43:37 +0200 Subject: [PATCH] soc/amd/common: Add common function to get cpu count This is the same for all supported AMD hardware. Change-Id: Ic6b954308dbb4c5a2050f1eb8f15acb41d0b81bd Signed-off-by: Arthur Heymans Reviewed-on: https://review.coreboot.org/c/coreboot/+/67617 Reviewed-by: Matt DeVillier Tested-by: build bot (Jenkins) Reviewed-by: Felix Held --- src/cpu/amd/agesa/family14/model_14_init.c | 3 ++- src/cpu/amd/agesa/family15tn/model_15_init.c | 3 ++- src/cpu/amd/agesa/family16kb/model_16_init.c | 3 ++- src/cpu/amd/pi/00730F01/model_16_init.c | 3 ++- src/northbridge/amd/pi/00730F01/northbridge.c | 8 +------- src/soc/amd/common/block/cpu/Makefile.inc | 2 ++ src/soc/amd/common/block/cpu/cpu.c | 9 +++++++++ src/soc/amd/common/block/cpu/noncar/cpu.c | 5 ----- src/soc/amd/stoneyridge/cpu.c | 6 +----- 9 files changed, 21 insertions(+), 21 deletions(-) create mode 100644 src/soc/amd/common/block/cpu/cpu.c diff --git a/src/cpu/amd/agesa/family14/model_14_init.c b/src/cpu/amd/agesa/family14/model_14_init.c index 21ef584f17..1d2c294961 100644 --- a/src/cpu/amd/agesa/family14/model_14_init.c +++ b/src/cpu/amd/agesa/family14/model_14_init.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-only */ #include +#include #include #include #include @@ -57,7 +58,7 @@ static void model_14_init(struct device *dev) mca_clear_status(); #if CONFIG(LOGICAL_CPUS) - siblings = cpuid_ecx(0x80000008) & 0xff; + siblings = get_cpu_count() - 1; // minus BSP if (siblings > 0) { msr = rdmsr_amd(CPU_ID_FEATURES_MSR); diff --git a/src/cpu/amd/agesa/family15tn/model_15_init.c b/src/cpu/amd/agesa/family15tn/model_15_init.c index de4423025b..c256ffcabf 100644 --- a/src/cpu/amd/agesa/family15tn/model_15_init.c +++ b/src/cpu/amd/agesa/family15tn/model_15_init.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-only */ #include +#include #include #include #include @@ -59,7 +60,7 @@ static void model_15_init(struct device *dev) mca_clear_status(); #if CONFIG(LOGICAL_CPUS) - siblings = cpuid_ecx(0x80000008) & 0xff; + siblings = get_cpu_count() - 1; // minus BSP if (siblings > 0) { msr = rdmsr_amd(CPU_ID_FEATURES_MSR); diff --git a/src/cpu/amd/agesa/family16kb/model_16_init.c b/src/cpu/amd/agesa/family16kb/model_16_init.c index 3698a8f898..0f1113638c 100644 --- a/src/cpu/amd/agesa/family16kb/model_16_init.c +++ b/src/cpu/amd/agesa/family16kb/model_16_init.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-only */ #include +#include #include #include #include @@ -57,7 +58,7 @@ static void model_16_init(struct device *dev) mca_clear_status(); #if CONFIG(LOGICAL_CPUS) - siblings = cpuid_ecx(0x80000008) & 0xff; + siblings = get_cpu_count() - 1; // minus BSP if (siblings > 0) { msr = rdmsr_amd(CPU_ID_FEATURES_MSR); diff --git a/src/cpu/amd/pi/00730F01/model_16_init.c b/src/cpu/amd/pi/00730F01/model_16_init.c index a33b5f35b5..5b43a07264 100644 --- a/src/cpu/amd/pi/00730F01/model_16_init.c +++ b/src/cpu/amd/pi/00730F01/model_16_init.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ +#include #include #include #include @@ -25,7 +26,7 @@ static void model_16_init(struct device *dev) mca_clear_status(); if (CONFIG(LOGICAL_CPUS)) { - siblings = cpuid_ecx(0x80000008) & 0xff; + siblings = get_cpu_count() - 1; // minus BSP if (siblings > 0) { msr = rdmsr_amd(CPU_ID_FEATURES_MSR); diff --git a/src/northbridge/amd/pi/00730F01/northbridge.c b/src/northbridge/amd/pi/00730F01/northbridge.c index b1df81a68a..0245a74ea9 100644 --- a/src/northbridge/amd/pi/00730F01/northbridge.c +++ b/src/northbridge/amd/pi/00730F01/northbridge.c @@ -23,6 +23,7 @@ #include #include #include +#include #define MAX_NODE_NUMS MAX_NODES #define PCIE_CAP_AER BIT(5) @@ -873,13 +874,6 @@ static void pre_mp_init(void) x86_mtrr_check(); } -static int get_cpu_count(void) -{ - uint8_t siblings = cpuid_ecx(0x80000008) & 0xff; - - return siblings + 1; -} - static const struct mp_ops mp_ops = { .pre_mp_init = pre_mp_init, .get_cpu_count = get_cpu_count, diff --git a/src/soc/amd/common/block/cpu/Makefile.inc b/src/soc/amd/common/block/cpu/Makefile.inc index 34685689de..7541a9bd5b 100644 --- a/src/soc/amd/common/block/cpu/Makefile.inc +++ b/src/soc/amd/common/block/cpu/Makefile.inc @@ -1,5 +1,7 @@ subdirs-y += ./* ramstage-$(CONFIG_SOC_AMD_COMMON_BLOCK_UCODE) += update_microcode.c +romstage-y += cpu.c +ramstage-y += cpu.c ifeq ($(CONFIG_SOC_AMD_COMMON_BLOCK_UCODE),y) define add-ucode-as-cbfs diff --git a/src/soc/amd/common/block/cpu/cpu.c b/src/soc/amd/common/block/cpu/cpu.c new file mode 100644 index 0000000000..bece89bc72 --- /dev/null +++ b/src/soc/amd/common/block/cpu/cpu.c @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include +#include + +int get_cpu_count(void) +{ + return 1 + (cpuid_ecx(0x80000008) & 0xff); +} diff --git a/src/soc/amd/common/block/cpu/noncar/cpu.c b/src/soc/amd/common/block/cpu/noncar/cpu.c index 56d4eb0384..8fd371564e 100644 --- a/src/soc/amd/common/block/cpu/noncar/cpu.c +++ b/src/soc/amd/common/block/cpu/noncar/cpu.c @@ -8,11 +8,6 @@ #include #include -int get_cpu_count(void) -{ - return 1 + (cpuid_ecx(0x80000008) & 0xff); -} - unsigned int smbios_processor_family(struct cpuid_result res) { return 0x6b; /* Zen */ diff --git a/src/soc/amd/stoneyridge/cpu.c b/src/soc/amd/stoneyridge/cpu.c index 7f71703f1c..e8519f8eae 100644 --- a/src/soc/amd/stoneyridge/cpu.c +++ b/src/soc/amd/stoneyridge/cpu.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ +#include #include #include #include @@ -42,11 +43,6 @@ static void pre_mp_init(void) x86_mtrr_check(); } -static int get_cpu_count(void) -{ - return 1 + (cpuid_ecx(0x80000008) & 0xff); -} - static const struct mp_ops mp_ops = { .pre_mp_init = pre_mp_init, .get_cpu_count = get_cpu_count,