diff options
Diffstat (limited to 'src/cpu/x86/mtrr/earlymtrr.c')
-rw-r--r-- | src/cpu/x86/mtrr/earlymtrr.c | 24 |
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 |