From f5dfe248ce30ff91a02430b925f3e4bd5dda955a Mon Sep 17 00:00:00 2001 From: Angel Pons Date: Wed, 3 Nov 2021 15:50:06 +0100 Subject: soc/intel/denverton_ns: Use `popcnt()` helper Use the `popcnt()` helper instead of manually counting the number of set bits in the first `CONFIG_MAX_CPUS` bits with a loop. Also, use unsigned types to store the number of active/total cores. Change-Id: Iae6b16991fcf07c9ad67d2b737e490212b8deedd Signed-off-by: Angel Pons Reviewed-on: https://review.coreboot.org/c/coreboot/+/58912 Tested-by: build bot (Jenkins) Reviewed-by: Felix Held --- src/soc/intel/denverton_ns/cpu.c | 27 +++++++++------------------ src/soc/intel/denverton_ns/include/soc/cpu.h | 1 - 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/src/soc/intel/denverton_ns/cpu.c b/src/soc/intel/denverton_ns/cpu.c index ef1140b76a..fb4923f7e1 100644 --- a/src/soc/intel/denverton_ns/cpu.c +++ b/src/soc/intel/denverton_ns/cpu.c @@ -15,7 +15,7 @@ #include #include #include - +#include #include #include #include @@ -182,28 +182,19 @@ static unsigned int detect_num_cpus_via_cpuid(void) } } -static int detect_num_cpus_via_mch(void) +/* Assumes that FSP has already programmed the cores disabled register */ +static unsigned int detect_num_cpus_via_mch(void) { - /* Assumes that FSP has already programmed the cores disabled register - */ - u32 core_exists_mask, active_cores_mask; - u32 core_disable_mask; - register int active_cores = 0, total_cores = 0; - register int counter = 0; - /* Get Masks for Total Existing SOC Cores and Core Disable Mask */ - core_exists_mask = MMIO32(DEFAULT_MCHBAR + MCH_BAR_CORE_EXISTS_MASK); - core_disable_mask = MMIO32(DEFAULT_MCHBAR + MCH_BAR_CORE_DISABLE_MASK); - active_cores_mask = (~core_disable_mask) & core_exists_mask; + const u32 core_exists_mask = MMIO32(DEFAULT_MCHBAR + MCH_BAR_CORE_EXISTS_MASK); + const u32 core_disable_mask = MMIO32(DEFAULT_MCHBAR + MCH_BAR_CORE_DISABLE_MASK); + const u32 active_cores_mask = ~core_disable_mask & core_exists_mask; /* Calculate Number of Active Cores */ - for (; counter < CONFIG_MAX_CPUS; - counter++, active_cores_mask >>= 1, core_exists_mask >>= 1) { - active_cores += (active_cores_mask & CORE_BIT_MSK); - total_cores += (core_exists_mask & CORE_BIT_MSK); - } + const unsigned int active_cores = popcnt(active_cores_mask); + const unsigned int total_cores = popcnt(core_exists_mask); - printk(BIOS_DEBUG, "Number of Active Cores: %d of %d total.\n", + printk(BIOS_DEBUG, "Number of Active Cores: %u of %u total.\n", active_cores, total_cores); return active_cores; diff --git a/src/soc/intel/denverton_ns/include/soc/cpu.h b/src/soc/intel/denverton_ns/include/soc/cpu.h index a714764767..a8af626500 100644 --- a/src/soc/intel/denverton_ns/include/soc/cpu.h +++ b/src/soc/intel/denverton_ns/include/soc/cpu.h @@ -11,7 +11,6 @@ int get_cpu_count(void); #ifndef __ACPI__ #define MSR_CORE_THREAD_COUNT 0x35 -#define CORE_BIT_MSK 0x1 #define MCH_BAR_CORE_EXISTS_MASK 0x7164 #define MCH_BAR_CORE_DISABLE_MASK 0x7168 -- cgit v1.2.3