2015-04-21 00:24:54 +02:00
|
|
|
/*
|
|
|
|
* This file is part of the coreboot project.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <console/console.h>
|
2016-12-06 13:00:05 +01:00
|
|
|
#include <cpu/cpu.h>
|
2015-04-21 00:24:54 +02:00
|
|
|
#include <cpu/x86/mtrr.h>
|
2018-11-13 19:28:07 +01:00
|
|
|
#include <stdint.h>
|
2015-04-21 00:24:54 +02:00
|
|
|
|
2018-11-13 19:28:07 +01:00
|
|
|
static const char *display_mtrr_type(uint32_t type)
|
2015-04-21 00:24:54 +02:00
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
default: return "reserved";
|
|
|
|
case 0: return "UC";
|
|
|
|
case 1: return "WC";
|
|
|
|
case 4: return "WT";
|
|
|
|
case 5: return "WP";
|
|
|
|
case 6: return "WB";
|
|
|
|
case 7: return "UC-";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-13 19:28:07 +01:00
|
|
|
static void display_mtrr_fixed_types(uint64_t msr,
|
2015-04-21 00:24:54 +02:00
|
|
|
uint32_t starting_address, uint32_t memory_size)
|
|
|
|
{
|
|
|
|
uint32_t base_address;
|
|
|
|
uint32_t index;
|
|
|
|
uint32_t next_address;
|
|
|
|
uint32_t next_type;
|
|
|
|
uint32_t type;
|
|
|
|
|
2015-10-01 05:23:09 +02:00
|
|
|
type = msr & MTRR_DEF_TYPE_MASK;
|
2015-04-21 00:24:54 +02:00
|
|
|
base_address = starting_address;
|
|
|
|
next_address = base_address;
|
|
|
|
for (index = 0; index < 64; index += 8) {
|
|
|
|
next_address = starting_address + (memory_size *
|
|
|
|
((index >> 3) + 1));
|
2015-10-01 05:23:09 +02:00
|
|
|
next_type = (msr >> index) & MTRR_DEF_TYPE_MASK;
|
2015-04-21 00:24:54 +02:00
|
|
|
if (next_type != type) {
|
|
|
|
printk(BIOS_DEBUG, " 0x%08x - 0x%08x: %s\n",
|
|
|
|
base_address, next_address - 1,
|
2018-11-13 19:28:07 +01:00
|
|
|
display_mtrr_type(type));
|
2015-04-21 00:24:54 +02:00
|
|
|
base_address = next_address;
|
|
|
|
type = next_type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (base_address != next_address)
|
|
|
|
printk(BIOS_DEBUG, " 0x%08x - 0x%08x: %s\n",
|
|
|
|
base_address, next_address - 1,
|
2018-11-13 19:28:07 +01:00
|
|
|
display_mtrr_type(type));
|
2015-04-21 00:24:54 +02:00
|
|
|
}
|
|
|
|
|
2018-11-13 19:28:07 +01:00
|
|
|
static void display_4k_mtrr(uint32_t msr_reg, uint32_t starting_address,
|
2015-04-21 00:24:54 +02:00
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
union {
|
|
|
|
uint64_t u64;
|
|
|
|
msr_t s;
|
|
|
|
} msr;
|
|
|
|
|
2016-07-24 17:03:37 +02:00
|
|
|
msr.s = rdmsr(msr_reg);
|
2015-04-21 00:24:54 +02:00
|
|
|
printk(BIOS_DEBUG, "0x%016llx: %s\n", msr.u64, name);
|
2018-11-13 19:28:07 +01:00
|
|
|
display_mtrr_fixed_types(msr.u64, starting_address, 0x1000);
|
2015-04-21 00:24:54 +02:00
|
|
|
}
|
|
|
|
|
2018-11-13 19:28:07 +01:00
|
|
|
static void display_16k_mtrr(uint32_t msr_reg, uint32_t starting_address,
|
2015-04-21 00:24:54 +02:00
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
union {
|
|
|
|
uint64_t u64;
|
|
|
|
msr_t s;
|
|
|
|
} msr;
|
|
|
|
|
2016-07-24 17:03:37 +02:00
|
|
|
msr.s = rdmsr(msr_reg);
|
2015-04-21 00:24:54 +02:00
|
|
|
printk(BIOS_DEBUG, "0x%016llx: %s\n", msr.u64, name);
|
2018-11-13 19:28:07 +01:00
|
|
|
display_mtrr_fixed_types(msr.u64, starting_address, 0x4000);
|
2015-04-21 00:24:54 +02:00
|
|
|
}
|
|
|
|
|
2018-11-13 19:28:07 +01:00
|
|
|
static void display_64k_mtrr(void)
|
2015-04-21 00:24:54 +02:00
|
|
|
{
|
|
|
|
union {
|
|
|
|
uint64_t u64;
|
|
|
|
msr_t s;
|
|
|
|
} msr;
|
|
|
|
|
2016-07-24 17:03:37 +02:00
|
|
|
msr.s = rdmsr(MTRR_FIX_64K_00000);
|
2015-04-21 00:24:54 +02:00
|
|
|
printk(BIOS_DEBUG, "0x%016llx: IA32_MTRR_FIX64K_00000\n", msr.u64);
|
2018-11-13 19:28:07 +01:00
|
|
|
display_mtrr_fixed_types(msr.u64, 0, 0x10000);
|
2015-04-21 00:24:54 +02:00
|
|
|
}
|
|
|
|
|
2018-11-13 19:28:07 +01:00
|
|
|
static void display_mtrrcap(void)
|
2015-04-21 00:24:54 +02:00
|
|
|
{
|
2018-11-13 19:28:07 +01:00
|
|
|
msr_t msr;
|
2015-04-21 00:24:54 +02:00
|
|
|
|
2018-11-13 19:28:07 +01:00
|
|
|
msr = rdmsr(MTRR_CAP_MSR);
|
2015-04-21 00:24:54 +02:00
|
|
|
printk(BIOS_DEBUG,
|
2018-11-13 19:28:07 +01:00
|
|
|
"0x%08x%08x: IA32_MTRRCAP: %s%s%s%u variable MTRRs\n",
|
|
|
|
msr.hi, msr.lo,
|
|
|
|
(msr.lo & MTRR_CAP_SMRR) ? "SMRR, " : "",
|
|
|
|
(msr.lo & MTRR_CAP_WC) ? "WC, " : "",
|
|
|
|
(msr.lo & MTRR_CAP_FIX) ? "FIX, " : "",
|
|
|
|
msr.lo & MTRR_CAP_VCNT);
|
2015-04-21 00:24:54 +02:00
|
|
|
}
|
|
|
|
|
2018-11-13 19:28:07 +01:00
|
|
|
static void display_mtrr_def_type(void)
|
2015-04-21 00:24:54 +02:00
|
|
|
{
|
|
|
|
union {
|
|
|
|
uint64_t u64;
|
|
|
|
msr_t s;
|
|
|
|
} msr;
|
|
|
|
|
2016-07-24 17:03:37 +02:00
|
|
|
msr.s = rdmsr(MTRR_DEF_TYPE_MSR);
|
2015-04-21 00:24:54 +02:00
|
|
|
printk(BIOS_DEBUG, "0x%016llx: IA32_MTRR_DEF_TYPE:%s%s %s\n",
|
|
|
|
msr.u64,
|
2015-10-01 05:23:09 +02:00
|
|
|
(msr.u64 & MTRR_DEF_TYPE_EN) ? " E," : "",
|
|
|
|
(msr.u64 & MTRR_DEF_TYPE_FIX_EN) ? " FE," : "",
|
2018-11-13 19:28:07 +01:00
|
|
|
display_mtrr_type((uint32_t)(msr.u64 &
|
2016-01-29 23:35:13 +01:00
|
|
|
MTRR_DEF_TYPE_MASK)));
|
2015-04-21 00:24:54 +02:00
|
|
|
}
|
|
|
|
|
2018-11-13 19:28:07 +01:00
|
|
|
static void display_variable_mtrr(int index, uint64_t address_mask)
|
2015-04-21 00:24:54 +02:00
|
|
|
{
|
2018-11-13 19:28:07 +01:00
|
|
|
const uint32_t msr_reg = MTRR_PHYS_BASE(index);
|
2015-04-21 00:24:54 +02:00
|
|
|
uint64_t base_address;
|
|
|
|
uint64_t length;
|
|
|
|
uint64_t mask;
|
|
|
|
union {
|
|
|
|
uint64_t u64;
|
|
|
|
msr_t s;
|
|
|
|
} msr_a;
|
|
|
|
union {
|
|
|
|
uint64_t u64;
|
|
|
|
msr_t s;
|
|
|
|
} msr_m;
|
|
|
|
|
2016-07-24 17:03:37 +02:00
|
|
|
msr_a.s = rdmsr(msr_reg);
|
|
|
|
msr_m.s = rdmsr(msr_reg + 1);
|
2015-10-01 05:23:09 +02:00
|
|
|
if (msr_m.u64 & MTRR_PHYS_MASK_VALID) {
|
2015-04-21 00:24:54 +02:00
|
|
|
base_address = (msr_a.u64 & 0xfffffffffffff000ULL)
|
|
|
|
& address_mask;
|
|
|
|
printk(BIOS_DEBUG,
|
|
|
|
"0x%016llx: PHYBASE%d: Address = 0x%016llx, %s\n",
|
|
|
|
msr_a.u64, index, base_address,
|
2018-11-13 19:28:07 +01:00
|
|
|
display_mtrr_type(msr_a.u64 & MTRR_DEF_TYPE_MASK));
|
2015-04-21 00:24:54 +02:00
|
|
|
mask = (msr_m.u64 & 0xfffffffffffff000ULL) & address_mask;
|
|
|
|
length = (~mask & address_mask) + 1;
|
|
|
|
printk(BIOS_DEBUG,
|
|
|
|
"0x%016llx: PHYMASK%d: Length = 0x%016llx, Valid\n",
|
|
|
|
msr_m.u64, index, length);
|
|
|
|
} else {
|
|
|
|
printk(BIOS_DEBUG, "0x%016llx: PHYBASE%d\n", msr_a.u64, index);
|
|
|
|
printk(BIOS_DEBUG, "0x%016llx: PHYMASK%d: Disabled\n",
|
|
|
|
msr_m.u64, index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-13 19:28:07 +01:00
|
|
|
static void _display_mtrrs(void)
|
2015-04-21 00:24:54 +02:00
|
|
|
{
|
2018-11-13 19:28:07 +01:00
|
|
|
uint32_t address_bits;
|
|
|
|
uint64_t address_mask;
|
|
|
|
int i;
|
|
|
|
int variable_mtrrs;
|
|
|
|
|
|
|
|
/* Display the fixed MTRRs */
|
|
|
|
display_mtrrcap();
|
|
|
|
display_mtrr_def_type();
|
|
|
|
display_64k_mtrr();
|
|
|
|
display_16k_mtrr(MTRR_FIX_16K_80000, 0x80000, "IA32_MTRR_FIX16K_80000");
|
|
|
|
display_16k_mtrr(MTRR_FIX_16K_A0000, 0xa0000, "IA32_MTRR_FIX16K_A0000");
|
|
|
|
display_4k_mtrr(MTRR_FIX_4K_C0000, 0xc0000, "IA32_MTRR_FIX4K_C0000");
|
|
|
|
display_4k_mtrr(MTRR_FIX_4K_C8000, 0xc8000, "IA32_MTRR_FIX4K_C8000");
|
|
|
|
display_4k_mtrr(MTRR_FIX_4K_D0000, 0xd0000, "IA32_MTRR_FIX4K_D0000");
|
|
|
|
display_4k_mtrr(MTRR_FIX_4K_D8000, 0xd8000, "IA32_MTRR_FIX4K_D8000");
|
|
|
|
display_4k_mtrr(MTRR_FIX_4K_E0000, 0xe0000, "IA32_MTRR_FIX4K_E0000");
|
|
|
|
display_4k_mtrr(MTRR_FIX_4K_E8000, 0xe8000, "IA32_MTRR_FIX4K_E8000");
|
|
|
|
display_4k_mtrr(MTRR_FIX_4K_F0000, 0xf0000, "IA32_MTRR_FIX4K_F0000");
|
|
|
|
display_4k_mtrr(MTRR_FIX_4K_F8000, 0xf8000, "IA32_MTRR_FIX4K_F8000");
|
|
|
|
address_bits = cpu_phys_address_size();
|
|
|
|
address_mask = (1ULL << address_bits) - 1;
|
|
|
|
|
|
|
|
/* Display the variable MTRRs */
|
|
|
|
variable_mtrrs = get_var_mtrr_count();
|
|
|
|
for (i = 0; i < variable_mtrrs; i++)
|
|
|
|
display_variable_mtrr(i, address_mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
asmlinkage void display_mtrrs(void)
|
|
|
|
{
|
2019-03-06 01:53:33 +01:00
|
|
|
if (CONFIG(DISPLAY_MTRRS))
|
2018-11-13 19:28:07 +01:00
|
|
|
_display_mtrrs();
|
2015-04-21 00:24:54 +02:00
|
|
|
}
|