cpu/x86/mtrr: Introduce mtrrlib with common MTRR helper functions

This change refactors MTRR handling by consolidating helper functions
from `earlymtrr.c` and `mtrr.c` into a new MTRR library (`mtrrlib`).
This approach improves code modularity and reusability, making these
utilities consistently available across different coreboot boot phases.

The following functions are now part of `mtrrlib`:

- `get_free_var_mtrr`: Retrieves the index of the first available
  variable MTRR.
- `set_var_mtrr`: Configures the variable MTRR, specified by an `index`,
  for a memory region defined by `base`, `size`, and `type`.
- `clear_var_mtrr`: Disables the variable MTRR at a given index.
- `acquire_and_configure_mtrr`: Acquires a free variable MTRR, configures
   it with the given `base`, `size`, and `type`.

BUG=b:409718202
TEST=Built and booted google/fatcat successfully.

Change-Id: Iba332b7088221fd930e973fad9410833bff184b9
Signed-off-by: Subrata Banik <subratabanik@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/87539
Reviewed-by: Jérémy Compostella <jeremy.compostella@intel.com>
Reviewed-by: Shuo Liu <shuo.liu@intel.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nick Vaccaro <nvaccaro@google.com>
This commit is contained in:
Subrata Banik 2025-05-05 16:58:02 +05:30
commit 5f941893ef
5 changed files with 96 additions and 64 deletions

View file

@ -124,9 +124,11 @@ static inline int get_var_mtrr_count(void)
return rdmsr(MTRR_CAP_MSR).lo & MTRR_CAP_VCNT;
}
void set_var_mtrr(unsigned int reg, unsigned int base, unsigned int size,
int acquire_and_configure_mtrr(unsigned int base, unsigned int size, unsigned int type);
void set_var_mtrr(unsigned int index, unsigned int base, unsigned int size,
unsigned int type);
int get_free_var_mtrr(void);
void clear_var_mtrr(int index);
void clear_all_var_mtrr(void);
asmlinkage void display_mtrrs(void);