diff options
author | Angel Pons <th3fanbus@gmail.com> | 2021-11-03 15:50:06 +0100 |
---|---|---|
committer | Felix Held <felix-coreboot@felixheld.de> | 2021-12-17 21:41:39 +0000 |
commit | f5dfe248ce30ff91a02430b925f3e4bd5dda955a (patch) | |
tree | b556cce475c206cfe1bc75e532e4dbb6cbcf5cd9 | |
parent | 4aaea8504406c8bce8f853e5b7064de2138f54f3 (diff) |
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 <th3fanbus@gmail.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/58912
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Felix Held <felix-coreboot@felixheld.de>
-rw-r--r-- | src/soc/intel/denverton_ns/cpu.c | 27 | ||||
-rw-r--r-- | 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 <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> @@ -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 |