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>
This commit is contained in:
parent
4aaea85044
commit
f5dfe248ce
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue