The CONFIG value should only be used when it cannot be read from the
CPU. This is particularly important when using kvm since the CPU size
depends on the host CPU.

Update set_var_mtrr() to use the correct function for this, which now
supports 64-bit operation. Ensure that the lower bits of the mask are
zeroed as required.

Signed-off-by: Simon Glass <s...@chromium.org>
---

Changes in v2:
- Add new patch to tidy up address size in MTRR calculations

 arch/x86/cpu/mtrr.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/arch/x86/cpu/mtrr.c b/arch/x86/cpu/mtrr.c
index 07ea89162de..d05263c8eab 100644
--- a/arch/x86/cpu/mtrr.c
+++ b/arch/x86/cpu/mtrr.c
@@ -16,6 +16,7 @@
  * since the MTRR registers are sometimes in flux.
  */
 
+#include <cpu.h>
 #include <cpu_func.h>
 #include <log.h>
 #include <sort.h>
@@ -70,9 +71,10 @@ static void set_var_mtrr(uint reg, uint type, uint64_t 
start, uint64_t size)
 {
        u64 mask;
 
-       wrmsrl(MTRR_PHYS_BASE_MSR(reg), start | type);
        mask = ~(size - 1);
-       mask &= (1ULL << CONFIG_CPU_ADDR_BITS) - 1;
+       mask &= (1ull << cpu_phys_address_size()) - 1;
+
+       wrmsrl(MTRR_PHYS_BASE_MSR(reg), start | type);
        wrmsrl(MTRR_PHYS_MASK_MSR(reg), mask | MTRR_PHYS_MASK_VALID);
 }
 
@@ -205,7 +207,7 @@ int mtrr_add_request(int type, uint64_t start, uint64_t 
size)
        debug("%d: type=%d, %08llx  %08llx\n", gd->arch.mtrr_req_count - 1,
              req->type, req->start, req->size);
        mask = ~(req->size - 1);
-       mask &= (1ULL << CONFIG_CPU_ADDR_BITS) - 1;
+       mask &= (1ULL << cpu_phys_address_size()) - 1;
        mask |= MTRR_PHYS_MASK_VALID;
        debug("   %016llx %016llx\n", req->start | req->type, mask);
 
@@ -360,7 +362,7 @@ int mtrr_list(int reg_count, int cpu_select)
 
                base = info.mtrr[i].base;
                mask = info.mtrr[i].mask;
-               size = ~mask & ((1ULL << CONFIG_CPU_ADDR_BITS) - 1);
+               size = ~mask & ((1ULL << cpu_phys_address_size()) - 1);
                size |= (1 << 12) - 1;
                size += 1;
                valid = mask & MTRR_PHYS_MASK_VALID;
-- 
2.43.0

Reply via email to