Angel Pons has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/58912 )
Change subject: soc/intel/denverton_ns: Refactor `detect_num_cpus_via_mch()` ......................................................................
soc/intel/denverton_ns: Refactor `detect_num_cpus_via_mch()`
Use the `popcnt()` helper and use unsigned types.
Change-Id: Iae6b16991fcf07c9ad67d2b737e490212b8deedd Signed-off-by: Angel Pons th3fanbus@gmail.com --- M src/soc/intel/denverton_ns/cpu.c M src/soc/intel/denverton_ns/include/soc/cpu.h 2 files changed, 9 insertions(+), 19 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/12/58912/1
diff --git a/src/soc/intel/denverton_ns/cpu.c b/src/soc/intel/denverton_ns/cpu.c index 44cb297..c1bb4a9 100644 --- a/src/soc/intel/denverton_ns/cpu.c +++ b/src/soc/intel/denverton_ns/cpu.c @@ -14,7 +14,7 @@ #include <device/device.h> #include <device/pci.h> #include <intelblocks/cpulib.h> - +#include <lib.h> #include <soc/msr.h> #include <soc/cpu.h> #include <soc/iomap.h> @@ -179,28 +179,19 @@ return (leaf_b.ebx & 0xffff); }
-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 a714764..a8af626 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 @@ #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