summaryrefslogtreecommitdiff
path: root/src/arch
diff options
context:
space:
mode:
authorSubrata Banik <subratabanik@google.com>2024-03-16 17:57:28 +0530
committerSubrata Banik <subratabanik@google.com>2024-03-17 11:54:58 +0000
commita4c91e15f879eb2b6cf0984f97c6efdc6c8fdca8 (patch)
treec5599d73ba4b292144799dd73ebf59ed872e2bab /src/arch
parentbbf884ddbd76b38fdc9b5ec4163cfc0dadd872ce (diff)
arch/x86: Add API to check if cache sets are power-of-two
Introduce a function to determine whether the number of cache sets is a power of two. This aligns with common cache design practices that favor power-of-two counts for efficient indexing and addressing. BUG=b:306677879 BRANCH=firmware-rex-15709.B TEST=Verified functionality on google/ovis and google/rex (including a non-power-of-two Ovis configuration). Change-Id: I819e0d1aeb4c1dbe1cdf3115b2e172588a6e8da5 Signed-off-by: Subrata Banik <subratabanik@google.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/81268 Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'src/arch')
-rw-r--r--src/arch/x86/cpu_common.c16
-rw-r--r--src/arch/x86/include/arch/cpu.h9
2 files changed, 25 insertions, 0 deletions
diff --git a/src/arch/x86/cpu_common.c b/src/arch/x86/cpu_common.c
index c4d30a2c06..ee0721412b 100644
--- a/src/arch/x86/cpu_common.c
+++ b/src/arch/x86/cpu_common.c
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0-only */
+#include <commonlib/helpers.h>
#include <cpu/cpu.h>
#include <types.h>
@@ -234,3 +235,18 @@ bool fill_cpu_cache_info(uint8_t level, struct cpu_cache_info *info)
return true;
}
+
+bool is_cache_sets_power_of_two(void)
+{
+ struct cpu_cache_info info;
+
+ if (!fill_cpu_cache_info(CACHE_L3, &info))
+ return false;
+
+ size_t cache_sets = cpu_get_cache_sets(&info);
+
+ if (IS_POWER_OF_2(cache_sets))
+ return true;
+
+ return false;
+}
diff --git a/src/arch/x86/include/arch/cpu.h b/src/arch/x86/include/arch/cpu.h
index 0c4decfc1b..fa0d5f4678 100644
--- a/src/arch/x86/include/arch/cpu.h
+++ b/src/arch/x86/include/arch/cpu.h
@@ -329,6 +329,15 @@ uint8_t cpu_get_c_substate_support(const int state);
*/
bool fill_cpu_cache_info(uint8_t level, struct cpu_cache_info *info);
+/*
+ * Determines whether the number of cache sets is a power of two.
+ *
+ * Cache designs often favor power-of-two set counts for efficient indexing
+ * and addressing. This function checks if the provided cache configuration
+ * adheres to this practice.
+ */
+bool is_cache_sets_power_of_two(void);
+
#if CONFIG(RESERVED_PHYSICAL_ADDRESS_BITS_SUPPORT)
unsigned int get_reserved_phys_addr_bits(void);
#else