blob: dc3f139694ecd76ed95f5173143186f8ee8959c9 [file] [log] [blame]
Lee Leahy0946ec32015-04-20 15:24:54 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2015 Intel Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Lee Leahy0946ec32015-04-20 15:24:54 -070014 */
15
16#include <arch/cpu.h>
17#include <console/console.h>
18#include <cpu/x86/msr.h>
19#include <cpu/x86/mtrr.h>
20#include <soc/intel/common/util.h>
21#include <stddef.h>
22
Lee Leahy0946ec32015-04-20 15:24:54 -070023uint32_t soc_get_variable_mtrr_count(uint64_t *msr)
24{
25 union {
26 uint64_t u64;
27 msr_t s;
28 } mttrcap;
29
Alexandru Gagniuc86091f92015-09-30 20:23:09 -070030 mttrcap.s = rdmsr(MTRR_CAP_MSR);
Lee Leahy0946ec32015-04-20 15:24:54 -070031 if (msr != NULL)
32 *msr = mttrcap.u64;
Alexandru Gagniuc86091f92015-09-30 20:23:09 -070033 return mttrcap.u64 & MTRR_CAP_VCNT;
Lee Leahy0946ec32015-04-20 15:24:54 -070034}
35
36static const char *soc_display_mtrr_type(uint32_t type)
37{
38 switch (type) {
39 default: return "reserved";
40 case 0: return "UC";
41 case 1: return "WC";
42 case 4: return "WT";
43 case 5: return "WP";
44 case 6: return "WB";
45 case 7: return "UC-";
46 }
47}
48
49static void soc_display_mtrr_fixed_types(uint64_t msr,
50 uint32_t starting_address, uint32_t memory_size)
51{
52 uint32_t base_address;
53 uint32_t index;
54 uint32_t next_address;
55 uint32_t next_type;
56 uint32_t type;
57
Alexandru Gagniuc86091f92015-09-30 20:23:09 -070058 type = msr & MTRR_DEF_TYPE_MASK;
Lee Leahy0946ec32015-04-20 15:24:54 -070059 base_address = starting_address;
60 next_address = base_address;
61 for (index = 0; index < 64; index += 8) {
62 next_address = starting_address + (memory_size *
63 ((index >> 3) + 1));
Alexandru Gagniuc86091f92015-09-30 20:23:09 -070064 next_type = (msr >> index) & MTRR_DEF_TYPE_MASK;
Lee Leahy0946ec32015-04-20 15:24:54 -070065 if (next_type != type) {
66 printk(BIOS_DEBUG, " 0x%08x - 0x%08x: %s\n",
67 base_address, next_address - 1,
68 soc_display_mtrr_type(type));
69 base_address = next_address;
70 type = next_type;
71 }
72 }
73 if (base_address != next_address)
74 printk(BIOS_DEBUG, " 0x%08x - 0x%08x: %s\n",
75 base_address, next_address - 1,
76 soc_display_mtrr_type(type));
77}
78
79static void soc_display_4k_mtrr(uint32_t msr_reg, uint32_t starting_address,
80 const char *name)
81{
82 union {
83 uint64_t u64;
84 msr_t s;
85 } msr;
86
87 msr.s = rdmsr(msr_reg);
88 printk(BIOS_DEBUG, "0x%016llx: %s\n", msr.u64, name);
89 soc_display_mtrr_fixed_types(msr.u64, starting_address, 0x1000);
90}
91
92static void soc_display_16k_mtrr(uint32_t msr_reg, uint32_t starting_address,
93 const char *name)
94{
95 union {
96 uint64_t u64;
97 msr_t s;
98 } msr;
99
100 msr.s = rdmsr(msr_reg);
101 printk(BIOS_DEBUG, "0x%016llx: %s\n", msr.u64, name);
102 soc_display_mtrr_fixed_types(msr.u64, starting_address, 0x4000);
103}
104
105static void soc_display_64k_mtrr(void)
106{
107 union {
108 uint64_t u64;
109 msr_t s;
110 } msr;
111
Alexandru Gagniuc86091f92015-09-30 20:23:09 -0700112 msr.s = rdmsr(MTRR_FIX_64K_00000);
Lee Leahy0946ec32015-04-20 15:24:54 -0700113 printk(BIOS_DEBUG, "0x%016llx: IA32_MTRR_FIX64K_00000\n", msr.u64);
114 soc_display_mtrr_fixed_types(msr.u64, 0, 0x10000);
115}
116
117static uint32_t soc_display_mtrrcap(void)
118{
119 uint64_t msr;
120 uint32_t variable_mtrrs;
121
122 variable_mtrrs = soc_get_variable_mtrr_count(&msr);
123 printk(BIOS_DEBUG,
124 "0x%016llx: IA32_MTRRCAP: %s%s%s%d variable MTRRs\n",
125 msr,
Alexandru Gagniuc86091f92015-09-30 20:23:09 -0700126 (msr & MTRR_CAP_SMRR) ? "SMRR, " : "",
127 (msr & MTRR_CAP_WC) ? "WC, " : "",
128 (msr & MTRR_CAP_FIX) ? "FIX, " : "",
Lee Leahy0946ec32015-04-20 15:24:54 -0700129 variable_mtrrs);
130 return variable_mtrrs;
131}
132
133static void soc_display_mtrr_def_type(void)
134{
135 union {
136 uint64_t u64;
137 msr_t s;
138 } msr;
139
Alexandru Gagniuc86091f92015-09-30 20:23:09 -0700140 msr.s = rdmsr(MTRR_DEF_TYPE_MSR);
Lee Leahy0946ec32015-04-20 15:24:54 -0700141 printk(BIOS_DEBUG, "0x%016llx: IA32_MTRR_DEF_TYPE:%s%s %s\n",
142 msr.u64,
Alexandru Gagniuc86091f92015-09-30 20:23:09 -0700143 (msr.u64 & MTRR_DEF_TYPE_EN) ? " E," : "",
144 (msr.u64 & MTRR_DEF_TYPE_FIX_EN) ? " FE," : "",
145 soc_display_mtrr_type((uint32_t)(msr.u64 & MTRR_DEF_TYPE_MASK)));
Lee Leahy0946ec32015-04-20 15:24:54 -0700146}
147
148static void soc_display_variable_mtrr(uint32_t msr_reg, int index,
149 uint64_t address_mask)
150{
151 uint64_t base_address;
152 uint64_t length;
153 uint64_t mask;
154 union {
155 uint64_t u64;
156 msr_t s;
157 } msr_a;
158 union {
159 uint64_t u64;
160 msr_t s;
161 } msr_m;
162
163 msr_a.s = rdmsr(msr_reg);
164 msr_m.s = rdmsr(msr_reg + 1);
Alexandru Gagniuc86091f92015-09-30 20:23:09 -0700165 if (msr_m.u64 & MTRR_PHYS_MASK_VALID) {
Lee Leahy0946ec32015-04-20 15:24:54 -0700166 base_address = (msr_a.u64 & 0xfffffffffffff000ULL)
167 & address_mask;
168 printk(BIOS_DEBUG,
169 "0x%016llx: PHYBASE%d: Address = 0x%016llx, %s\n",
170 msr_a.u64, index, base_address,
Alexandru Gagniuc86091f92015-09-30 20:23:09 -0700171 soc_display_mtrr_type(msr_a.u64 & MTRR_DEF_TYPE_MASK));
Lee Leahy0946ec32015-04-20 15:24:54 -0700172 mask = (msr_m.u64 & 0xfffffffffffff000ULL) & address_mask;
173 length = (~mask & address_mask) + 1;
174 printk(BIOS_DEBUG,
175 "0x%016llx: PHYMASK%d: Length = 0x%016llx, Valid\n",
176 msr_m.u64, index, length);
177 } else {
178 printk(BIOS_DEBUG, "0x%016llx: PHYBASE%d\n", msr_a.u64, index);
179 printk(BIOS_DEBUG, "0x%016llx: PHYMASK%d: Disabled\n",
180 msr_m.u64, index);
181 }
182}
183
184asmlinkage void soc_display_mtrrs(void)
185{
186 if (IS_ENABLED(CONFIG_DISPLAY_MTRRS)) {
187 uint32_t address_bits;
188 uint64_t address_mask;
189 int i;
190 int variable_mtrrs;
191
192 /* Display the fixed MTRRs */
193 variable_mtrrs = soc_display_mtrrcap();
194 soc_display_mtrr_def_type();
195 soc_display_64k_mtrr();
Alexandru Gagniuc86091f92015-09-30 20:23:09 -0700196 soc_display_16k_mtrr(MTRR_FIX_16K_80000, 0x80000,
Lee Leahy0946ec32015-04-20 15:24:54 -0700197 "IA32_MTRR_FIX16K_80000");
Alexandru Gagniuc86091f92015-09-30 20:23:09 -0700198 soc_display_16k_mtrr(MTRR_FIX_16K_A0000, 0xa0000,
Lee Leahy0946ec32015-04-20 15:24:54 -0700199 "IA32_MTRR_FIX16K_A0000");
Alexandru Gagniuc86091f92015-09-30 20:23:09 -0700200 soc_display_4k_mtrr(MTRR_FIX_4K_C0000, 0xc0000,
Lee Leahy0946ec32015-04-20 15:24:54 -0700201 "IA32_MTRR_FIX4K_C0000");
Alexandru Gagniuc86091f92015-09-30 20:23:09 -0700202 soc_display_4k_mtrr(MTRR_FIX_4K_C8000, 0xc8000,
Lee Leahy0946ec32015-04-20 15:24:54 -0700203 "IA32_MTRR_FIX4K_C8000");
Alexandru Gagniuc86091f92015-09-30 20:23:09 -0700204 soc_display_4k_mtrr(MTRR_FIX_4K_D0000, 0xd0000,
Lee Leahy0946ec32015-04-20 15:24:54 -0700205 "IA32_MTRR_FIX4K_D0000");
Alexandru Gagniuc86091f92015-09-30 20:23:09 -0700206 soc_display_4k_mtrr(MTRR_FIX_4K_D8000, 0xd8000,
Lee Leahy0946ec32015-04-20 15:24:54 -0700207 "IA32_MTRR_FIX4K_D8000");
Alexandru Gagniuc86091f92015-09-30 20:23:09 -0700208 soc_display_4k_mtrr(MTRR_FIX_4K_E0000, 0xe0000,
Lee Leahy0946ec32015-04-20 15:24:54 -0700209 "IA32_MTRR_FIX4K_E0000");
Alexandru Gagniuc86091f92015-09-30 20:23:09 -0700210 soc_display_4k_mtrr(MTRR_FIX_4K_E8000, 0xe8000,
Lee Leahy0946ec32015-04-20 15:24:54 -0700211 "IA32_MTRR_FIX4K_E8000");
Alexandru Gagniuc86091f92015-09-30 20:23:09 -0700212 soc_display_4k_mtrr(MTRR_FIX_4K_F0000, 0xf0000,
Lee Leahy0946ec32015-04-20 15:24:54 -0700213 "IA32_MTRR_FIX4K_F0000");
Alexandru Gagniuc86091f92015-09-30 20:23:09 -0700214 soc_display_4k_mtrr(MTRR_FIX_4K_F8000, 0xf8000,
Lee Leahy0946ec32015-04-20 15:24:54 -0700215 "IA32_MTRR_FIX4K_F8000");
216 address_bits = cpu_phys_address_size();
217 address_mask = (1ULL << address_bits) - 1;
218
219 /* Display the variable MTRRs */
220 for (i = 0; i < variable_mtrrs; i++)
Alexandru Gagniuc86091f92015-09-30 20:23:09 -0700221 soc_display_variable_mtrr(MTRR_PHYS_BASE(i), i,
Lee Leahy0946ec32015-04-20 15:24:54 -0700222 address_mask);
223 }
224}