summaryrefslogtreecommitdiff
path: root/src/cpu/x86/mtrr
diff options
context:
space:
mode:
authorFurquan Shaikh <furquan@google.com>2016-03-16 16:12:06 -0700
committerMartin Roth <martinroth@google.com>2016-03-18 19:14:52 +0100
commit331ac1b07896140a14dbb079b3cb907762cec218 (patch)
tree8352f21b1d295a9e4a9b0bc801735e584ca324ee /src/cpu/x86/mtrr
parent39e55209dce7d971c2e5b53706c5124e1ec01bb3 (diff)
downloadcoreboot-331ac1b07896140a14dbb079b3cb907762cec218.tar.xz
mtrr: Define a function for obtaining free var mtrr
Instead of hard-coding var mtrr numbers in code, use this function to identify the first available variable mtrr. If no such mtrr is available, the function will return -1. Change-Id: I2a1e02cdb45c0ab7e30609641977471eaa2431fd Signed-off-by: Furquan Shaikh <furquan@google.com> Reviewed-on: https://review.coreboot.org/14115 Tested-by: build bot (Jenkins) Reviewed-by: Andrey Petrov <andrey.petrov@intel.com>
Diffstat (limited to 'src/cpu/x86/mtrr')
-rw-r--r--src/cpu/x86/mtrr/earlymtrr.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/cpu/x86/mtrr/earlymtrr.c b/src/cpu/x86/mtrr/earlymtrr.c
index a84ecf8f72..eae6ba67b2 100644
--- a/src/cpu/x86/mtrr/earlymtrr.c
+++ b/src/cpu/x86/mtrr/earlymtrr.c
@@ -2,6 +2,30 @@
#include <cpu/x86/mtrr.h>
#include <cpu/x86/msr.h>
+/* Get first available variable MTRR.
+ * Returns var# if available, else returns -1.
+ */
+int get_free_var_mtrr(void)
+{
+ msr_t msr, maskm;
+ int vcnt;
+ int i;
+
+ /* Read MTRRCap and get vcnt - variable memory type ranges. */
+ msr = rdmsr(MTRR_CAP_MSR);
+ vcnt = msr.lo & 0xff;
+
+ /* Identify the first var mtrr which is not valid. */
+ for (i = 0; i < vcnt; i++) {
+ maskm = rdmsr(MTRR_PHYS_MASK(i));
+ if ((maskm.lo & MTRR_PHYS_MASK_VALID) == 0)
+ return i;
+ }
+
+ /* No free var mtrr. */
+ return -1;
+}
+
#ifdef __ROMCC__
static
#endif