Skip to content

Commit

Permalink
mtrr: Define a function for obtaining free var mtrr
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
furquan-goog authored and Martin Roth committed Mar 18, 2016
1 parent 39e5520 commit 331ac1b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/cpu/x86/mtrr/earlymtrr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/include/cpu/x86/mtrr.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ void x86_mtrr_check(void);

#if !defined(__ASSEMBLER__) && defined(__PRE_RAM__) && !defined(__ROMCC__)
void set_var_mtrr(unsigned reg, unsigned base, unsigned size, unsigned type);
int get_free_var_mtrr(void);
#endif

/* Align up to next power of 2, suitable for ROMCC and assembler too.
Expand Down

0 comments on commit 331ac1b

Please sign in to comment.