Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 1 | /* |
Stefan Reinauer | cdc5cc6 | 2007-04-24 18:40:02 +0000 | [diff] [blame] | 2 | * mtrr.c: setting MTRR to decent values for cache initialization on P6 |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 3 | * |
| 4 | * Derived from intel_set_mtrr in intel_subr.c and mtrr.c in linux kernel |
| 5 | * |
| 6 | * Copyright 2000 Silicon Integrated System Corporation |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 7 | * Copyright 2013 Google Inc. |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 19 | * |
Lee Leahy | c591707 | 2017-03-15 16:38:51 -0700 | [diff] [blame] | 20 | * Reference: Intel Architecture Software Developer's Manual, Volume 3: System |
| 21 | * Programming |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 22 | */ |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 23 | |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 24 | #include <stddef.h> |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 25 | #include <stdlib.h> |
| 26 | #include <string.h> |
Aaron Durbin | bebf669 | 2013-04-24 20:59:43 -0500 | [diff] [blame] | 27 | #include <bootstate.h> |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 28 | #include <console/console.h> |
| 29 | #include <device/device.h> |
Aaron Durbin | ca4f4b8 | 2014-02-08 15:41:52 -0600 | [diff] [blame] | 30 | #include <device/pci_ids.h> |
Aaron Durbin | ebf142a | 2013-03-29 16:23:23 -0500 | [diff] [blame] | 31 | #include <cpu/cpu.h> |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 32 | #include <cpu/x86/msr.h> |
| 33 | #include <cpu/x86/mtrr.h> |
| 34 | #include <cpu/x86/cache.h> |
Stefan Reinauer | 00093a8 | 2011-11-02 16:12:34 -0700 | [diff] [blame] | 35 | #include <cpu/x86/lapic.h> |
Sven Schnelle | adfbcb79 | 2012-01-10 12:01:43 +0100 | [diff] [blame] | 36 | #include <arch/cpu.h> |
Stefan Reinauer | 00093a8 | 2011-11-02 16:12:34 -0700 | [diff] [blame] | 37 | #include <arch/acpi.h> |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 38 | #include <memrange.h> |
Aaron Durbin | 57686f8 | 2013-03-20 15:50:59 -0500 | [diff] [blame] | 39 | #include <cpu/amd/mtrr.h> |
Marshall Dawson | c0dbeda | 2017-10-19 09:45:16 -0600 | [diff] [blame] | 40 | #if IS_ENABLED(CONFIG_X86_AMD_FIXED_MTRRS) |
Aaron Durbin | 57686f8 | 2013-03-20 15:50:59 -0500 | [diff] [blame] | 41 | #define MTRR_FIXED_WRBACK_BITS (MTRR_READ_MEM | MTRR_WRITE_MEM) |
| 42 | #else |
| 43 | #define MTRR_FIXED_WRBACK_BITS 0 |
| 44 | #endif |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 45 | |
Stefan Reinauer | c00dfbc | 2012-04-03 16:24:37 -0700 | [diff] [blame] | 46 | /* 2 MTRRS are reserved for the operating system */ |
| 47 | #define BIOS_MTRRS 6 |
| 48 | #define OS_MTRRS 2 |
| 49 | #define MTRRS (BIOS_MTRRS + OS_MTRRS) |
Gabe Black | 7756fe7 | 2014-02-25 01:40:34 -0800 | [diff] [blame] | 50 | /* |
Isaac Christensen | 81f90c5 | 2014-09-24 14:59:32 -0600 | [diff] [blame] | 51 | * Static storage size for variable MTRRs. It's sized sufficiently large to |
| 52 | * handle different types of CPUs. Empirically, 16 variable MTRRs has not |
Gabe Black | 7756fe7 | 2014-02-25 01:40:34 -0800 | [diff] [blame] | 53 | * yet been observed. |
| 54 | */ |
| 55 | #define NUM_MTRR_STATIC_STORAGE 16 |
Stefan Reinauer | c00dfbc | 2012-04-03 16:24:37 -0700 | [diff] [blame] | 56 | |
| 57 | static int total_mtrrs = MTRRS; |
| 58 | static int bios_mtrrs = BIOS_MTRRS; |
| 59 | |
| 60 | static void detect_var_mtrrs(void) |
| 61 | { |
| 62 | msr_t msr; |
| 63 | |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 64 | msr = rdmsr(MTRR_CAP_MSR); |
Stefan Reinauer | c00dfbc | 2012-04-03 16:24:37 -0700 | [diff] [blame] | 65 | |
| 66 | total_mtrrs = msr.lo & 0xff; |
Gabe Black | 7756fe7 | 2014-02-25 01:40:34 -0800 | [diff] [blame] | 67 | |
| 68 | if (total_mtrrs > NUM_MTRR_STATIC_STORAGE) { |
| 69 | printk(BIOS_WARNING, |
| 70 | "MTRRs detected (%d) > NUM_MTRR_STATIC_STORAGE (%d)\n", |
| 71 | total_mtrrs, NUM_MTRR_STATIC_STORAGE); |
| 72 | total_mtrrs = NUM_MTRR_STATIC_STORAGE; |
| 73 | } |
Stefan Reinauer | c00dfbc | 2012-04-03 16:24:37 -0700 | [diff] [blame] | 74 | bios_mtrrs = total_mtrrs - OS_MTRRS; |
| 75 | } |
| 76 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 77 | void enable_fixed_mtrr(void) |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 78 | { |
| 79 | msr_t msr; |
| 80 | |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 81 | msr = rdmsr(MTRR_DEF_TYPE_MSR); |
| 82 | msr.lo |= MTRR_DEF_TYPE_EN | MTRR_DEF_TYPE_FIX_EN; |
| 83 | wrmsr(MTRR_DEF_TYPE_MSR, msr); |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 84 | } |
| 85 | |
Marshall Dawson | c0dbeda | 2017-10-19 09:45:16 -0600 | [diff] [blame] | 86 | void fixed_mtrrs_expose_amd_rwdram(void) |
| 87 | { |
| 88 | msr_t syscfg; |
| 89 | |
| 90 | if (!IS_ENABLED(CONFIG_X86_AMD_FIXED_MTRRS)) |
| 91 | return; |
| 92 | |
| 93 | syscfg = rdmsr(SYSCFG_MSR); |
| 94 | syscfg.lo |= SYSCFG_MSR_MtrrFixDramModEn; |
| 95 | wrmsr(SYSCFG_MSR, syscfg); |
| 96 | } |
| 97 | |
| 98 | void fixed_mtrrs_hide_amd_rwdram(void) |
| 99 | { |
| 100 | msr_t syscfg; |
| 101 | |
| 102 | if (!IS_ENABLED(CONFIG_X86_AMD_FIXED_MTRRS)) |
| 103 | return; |
| 104 | |
| 105 | syscfg = rdmsr(SYSCFG_MSR); |
| 106 | syscfg.lo &= ~SYSCFG_MSR_MtrrFixDramModEn; |
| 107 | wrmsr(SYSCFG_MSR, syscfg); |
| 108 | } |
| 109 | |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 110 | static void enable_var_mtrr(unsigned char deftype) |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 111 | { |
| 112 | msr_t msr; |
| 113 | |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 114 | msr = rdmsr(MTRR_DEF_TYPE_MSR); |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 115 | msr.lo &= ~0xff; |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 116 | msr.lo |= MTRR_DEF_TYPE_EN | deftype; |
| 117 | wrmsr(MTRR_DEF_TYPE_MSR, msr); |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 118 | } |
| 119 | |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 120 | #define MTRR_VERBOSE_LEVEL BIOS_NEVER |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 121 | |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 122 | /* MTRRs are at a 4KiB granularity. Therefore all address calculations can |
| 123 | * be done with 32-bit numbers. This allows for the MTRR code to handle |
| 124 | * up to 2^44 bytes (16 TiB) of address space. */ |
| 125 | #define RANGE_SHIFT 12 |
| 126 | #define ADDR_SHIFT_TO_RANGE_SHIFT(x) \ |
| 127 | (((x) > RANGE_SHIFT) ? ((x) - RANGE_SHIFT) : RANGE_SHIFT) |
| 128 | #define PHYS_TO_RANGE_ADDR(x) ((x) >> RANGE_SHIFT) |
| 129 | #define RANGE_TO_PHYS_ADDR(x) (((resource_t)(x)) << RANGE_SHIFT) |
| 130 | #define NUM_FIXED_MTRRS (NUM_FIXED_RANGES / RANGES_PER_FIXED_MTRR) |
| 131 | |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 132 | /* Helpful constants. */ |
| 133 | #define RANGE_1MB PHYS_TO_RANGE_ADDR(1 << 20) |
| 134 | #define RANGE_4GB (1 << (ADDR_SHIFT_TO_RANGE_SHIFT(32))) |
| 135 | |
Aaron Durbin | e383442 | 2013-03-28 20:48:51 -0500 | [diff] [blame] | 136 | #define MTRR_ALGO_SHIFT (8) |
| 137 | #define MTRR_TAG_MASK ((1 << MTRR_ALGO_SHIFT) - 1) |
Aaron Durbin | e383442 | 2013-03-28 20:48:51 -0500 | [diff] [blame] | 138 | |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 139 | static inline uint32_t range_entry_base_mtrr_addr(struct range_entry *r) |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 140 | { |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 141 | return PHYS_TO_RANGE_ADDR(range_entry_base(r)); |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 142 | } |
| 143 | |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 144 | static inline uint32_t range_entry_end_mtrr_addr(struct range_entry *r) |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 145 | { |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 146 | return PHYS_TO_RANGE_ADDR(range_entry_end(r)); |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 147 | } |
| 148 | |
Aaron Durbin | e383442 | 2013-03-28 20:48:51 -0500 | [diff] [blame] | 149 | static inline int range_entry_mtrr_type(struct range_entry *r) |
| 150 | { |
| 151 | return range_entry_tag(r) & MTRR_TAG_MASK; |
| 152 | } |
| 153 | |
Aaron Durbin | ca4f4b8 | 2014-02-08 15:41:52 -0600 | [diff] [blame] | 154 | static int filter_vga_wrcomb(struct device *dev, struct resource *res) |
| 155 | { |
| 156 | /* Only handle PCI devices. */ |
| 157 | if (dev->path.type != DEVICE_PATH_PCI) |
| 158 | return 0; |
| 159 | |
| 160 | /* Only handle VGA class devices. */ |
| 161 | if (((dev->class >> 8) != PCI_CLASS_DISPLAY_VGA)) |
| 162 | return 0; |
| 163 | |
| 164 | /* Add resource as write-combining in the address space. */ |
| 165 | return 1; |
| 166 | } |
| 167 | |
Aaron Durbin | 2bebd7b | 2016-11-10 15:15:35 -0600 | [diff] [blame] | 168 | static void print_physical_address_space(const struct memranges *addr_space, |
| 169 | const char *identifier) |
| 170 | { |
| 171 | const struct range_entry *r; |
| 172 | |
| 173 | if (identifier) |
| 174 | printk(BIOS_DEBUG, "MTRR: %s Physical address space:\n", |
| 175 | identifier); |
| 176 | else |
| 177 | printk(BIOS_DEBUG, "MTRR: Physical address space:\n"); |
| 178 | |
| 179 | memranges_each_entry(r, addr_space) |
| 180 | printk(BIOS_DEBUG, |
| 181 | "0x%016llx - 0x%016llx size 0x%08llx type %ld\n", |
| 182 | range_entry_base(r), range_entry_end(r), |
| 183 | range_entry_size(r), range_entry_tag(r)); |
| 184 | } |
| 185 | |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 186 | static struct memranges *get_physical_address_space(void) |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 187 | { |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 188 | static struct memranges *addr_space; |
| 189 | static struct memranges addr_space_storage; |
Duncan Laurie | 7389fa9 | 2011-12-22 10:59:40 -0800 | [diff] [blame] | 190 | |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 191 | /* In order to handle some chipsets not being able to pre-determine |
Martin Roth | 4c3ab73 | 2013-07-08 16:23:54 -0600 | [diff] [blame] | 192 | * uncacheable ranges, such as graphics memory, at resource insertion |
| 193 | * time remove uncacheable regions from the cacheable ones. */ |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 194 | if (addr_space == NULL) { |
Aaron Durbin | 9b027fe | 2013-03-26 14:10:34 -0500 | [diff] [blame] | 195 | unsigned long mask; |
| 196 | unsigned long match; |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 197 | |
| 198 | addr_space = &addr_space_storage; |
| 199 | |
Aaron Durbin | 9b027fe | 2013-03-26 14:10:34 -0500 | [diff] [blame] | 200 | mask = IORESOURCE_CACHEABLE; |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 201 | /* Collect cacheable and uncacheable address ranges. The |
| 202 | * uncacheable regions take precedence over the cacheable |
| 203 | * regions. */ |
| 204 | memranges_init(addr_space, mask, mask, MTRR_TYPE_WRBACK); |
| 205 | memranges_add_resources(addr_space, mask, 0, |
Lee Leahy | a07d0dd | 2017-03-15 14:25:22 -0700 | [diff] [blame] | 206 | MTRR_TYPE_UNCACHEABLE); |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 207 | |
Aaron Durbin | 9b027fe | 2013-03-26 14:10:34 -0500 | [diff] [blame] | 208 | /* Handle any write combining resources. Only prefetchable |
Vladimir Serbinenko | 30fe612 | 2014-02-05 23:25:28 +0100 | [diff] [blame] | 209 | * resources are appropriate for this MTRR type. */ |
| 210 | match = IORESOURCE_PREFETCH; |
Aaron Durbin | 9b027fe | 2013-03-26 14:10:34 -0500 | [diff] [blame] | 211 | mask |= match; |
Lee Leahy | c591707 | 2017-03-15 16:38:51 -0700 | [diff] [blame] | 212 | memranges_add_resources_filter(addr_space, mask, match, |
| 213 | MTRR_TYPE_WRCOMB, filter_vga_wrcomb); |
Aaron Durbin | 9b027fe | 2013-03-26 14:10:34 -0500 | [diff] [blame] | 214 | |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 215 | /* The address space below 4GiB is special. It needs to be |
Martin Roth | 2f91403 | 2016-01-15 10:20:11 -0700 | [diff] [blame] | 216 | * covered entirely by range entries so that MTRR calculations |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 217 | * can be properly done for the full 32-bit address space. |
| 218 | * Therefore, ensure holes are filled up to 4GiB as |
| 219 | * uncacheable */ |
| 220 | memranges_fill_holes_up_to(addr_space, |
Lee Leahy | a07d0dd | 2017-03-15 14:25:22 -0700 | [diff] [blame] | 221 | RANGE_TO_PHYS_ADDR(RANGE_4GB), |
| 222 | MTRR_TYPE_UNCACHEABLE); |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 223 | |
Aaron Durbin | 2bebd7b | 2016-11-10 15:15:35 -0600 | [diff] [blame] | 224 | print_physical_address_space(addr_space, NULL); |
Carl-Daniel Hailfinger | 7dde1da | 2009-02-11 16:57:32 +0000 | [diff] [blame] | 225 | } |
Stefan Reinauer | 7f86ed1 | 2009-02-12 16:02:16 +0000 | [diff] [blame] | 226 | |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 227 | return addr_space; |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 228 | } |
| 229 | |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 230 | /* Fixed MTRR descriptor. This structure defines the step size and begin |
Martin Roth | 4c3ab73 | 2013-07-08 16:23:54 -0600 | [diff] [blame] | 231 | * and end (exclusive) address covered by a set of fixed MTRR MSRs. |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 232 | * It also describes the offset in byte intervals to store the calculated MTRR |
| 233 | * type in an array. */ |
| 234 | struct fixed_mtrr_desc { |
| 235 | uint32_t begin; |
| 236 | uint32_t end; |
| 237 | uint32_t step; |
| 238 | int range_index; |
| 239 | int msr_index_base; |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 240 | }; |
| 241 | |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 242 | /* Shared MTRR calculations. Can be reused by APs. */ |
| 243 | static uint8_t fixed_mtrr_types[NUM_FIXED_RANGES]; |
| 244 | |
| 245 | /* Fixed MTRR descriptors. */ |
| 246 | static const struct fixed_mtrr_desc fixed_mtrr_desc[] = { |
| 247 | { PHYS_TO_RANGE_ADDR(0x000000), PHYS_TO_RANGE_ADDR(0x080000), |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 248 | PHYS_TO_RANGE_ADDR(64 * 1024), 0, MTRR_FIX_64K_00000 }, |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 249 | { PHYS_TO_RANGE_ADDR(0x080000), PHYS_TO_RANGE_ADDR(0x0C0000), |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 250 | PHYS_TO_RANGE_ADDR(16 * 1024), 8, MTRR_FIX_16K_80000 }, |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 251 | { PHYS_TO_RANGE_ADDR(0x0C0000), PHYS_TO_RANGE_ADDR(0x100000), |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 252 | PHYS_TO_RANGE_ADDR(4 * 1024), 24, MTRR_FIX_4K_C0000 }, |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 253 | }; |
| 254 | |
| 255 | static void calc_fixed_mtrrs(void) |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 256 | { |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 257 | static int fixed_mtrr_types_initialized; |
| 258 | struct memranges *phys_addr_space; |
| 259 | struct range_entry *r; |
| 260 | const struct fixed_mtrr_desc *desc; |
| 261 | const struct fixed_mtrr_desc *last_desc; |
| 262 | uint32_t begin; |
| 263 | uint32_t end; |
| 264 | int type_index; |
| 265 | |
| 266 | if (fixed_mtrr_types_initialized) |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 267 | return; |
Kyösti Mälkki | 2d42b34 | 2012-07-12 00:18:22 +0300 | [diff] [blame] | 268 | |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 269 | phys_addr_space = get_physical_address_space(); |
Kyösti Mälkki | 2d42b34 | 2012-07-12 00:18:22 +0300 | [diff] [blame] | 270 | |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 271 | /* Set all fixed ranges to uncacheable first. */ |
| 272 | memset(&fixed_mtrr_types[0], MTRR_TYPE_UNCACHEABLE, NUM_FIXED_RANGES); |
Kyösti Mälkki | 2d42b34 | 2012-07-12 00:18:22 +0300 | [diff] [blame] | 273 | |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 274 | desc = &fixed_mtrr_desc[0]; |
| 275 | last_desc = &fixed_mtrr_desc[ARRAY_SIZE(fixed_mtrr_desc) - 1]; |
Kyösti Mälkki | 1ec5e74 | 2012-07-26 23:51:20 +0300 | [diff] [blame] | 276 | |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 277 | memranges_each_entry(r, phys_addr_space) { |
| 278 | begin = range_entry_base_mtrr_addr(r); |
| 279 | end = range_entry_end_mtrr_addr(r); |
Kyösti Mälkki | 2d42b34 | 2012-07-12 00:18:22 +0300 | [diff] [blame] | 280 | |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 281 | if (begin >= last_desc->end) |
| 282 | break; |
| 283 | |
| 284 | if (end > last_desc->end) |
| 285 | end = last_desc->end; |
| 286 | |
| 287 | /* Get to the correct fixed mtrr descriptor. */ |
| 288 | while (begin >= desc->end) |
| 289 | desc++; |
| 290 | |
| 291 | type_index = desc->range_index; |
| 292 | type_index += (begin - desc->begin) / desc->step; |
| 293 | |
| 294 | while (begin != end) { |
| 295 | unsigned char type; |
| 296 | |
| 297 | type = range_entry_tag(r); |
| 298 | printk(MTRR_VERBOSE_LEVEL, |
| 299 | "MTRR addr 0x%x-0x%x set to %d type @ %d\n", |
| 300 | begin, begin + desc->step, type, type_index); |
| 301 | if (type == MTRR_TYPE_WRBACK) |
| 302 | type |= MTRR_FIXED_WRBACK_BITS; |
| 303 | fixed_mtrr_types[type_index] = type; |
| 304 | type_index++; |
| 305 | begin += desc->step; |
| 306 | if (begin == desc->end) |
| 307 | desc++; |
Yinghai Lu | 6360187 | 2005-01-27 22:48:12 +0000 | [diff] [blame] | 308 | } |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 309 | } |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 310 | fixed_mtrr_types_initialized = 1; |
| 311 | } |
| 312 | |
| 313 | static void commit_fixed_mtrrs(void) |
| 314 | { |
| 315 | int i; |
| 316 | int j; |
| 317 | int msr_num; |
| 318 | int type_index; |
| 319 | /* 8 ranges per msr. */ |
| 320 | msr_t fixed_msrs[NUM_FIXED_MTRRS]; |
| 321 | unsigned long msr_index[NUM_FIXED_MTRRS]; |
| 322 | |
Marshall Dawson | c0dbeda | 2017-10-19 09:45:16 -0600 | [diff] [blame] | 323 | fixed_mtrrs_expose_amd_rwdram(); |
| 324 | |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 325 | memset(&fixed_msrs, 0, sizeof(fixed_msrs)); |
| 326 | |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 327 | msr_num = 0; |
| 328 | type_index = 0; |
| 329 | for (i = 0; i < ARRAY_SIZE(fixed_mtrr_desc); i++) { |
| 330 | const struct fixed_mtrr_desc *desc; |
| 331 | int num_ranges; |
| 332 | |
| 333 | desc = &fixed_mtrr_desc[i]; |
| 334 | num_ranges = (desc->end - desc->begin) / desc->step; |
| 335 | for (j = 0; j < num_ranges; j += RANGES_PER_FIXED_MTRR) { |
| 336 | msr_index[msr_num] = desc->msr_index_base + |
| 337 | (j / RANGES_PER_FIXED_MTRR); |
| 338 | fixed_msrs[msr_num].lo |= |
| 339 | fixed_mtrr_types[type_index++] << 0; |
| 340 | fixed_msrs[msr_num].lo |= |
| 341 | fixed_mtrr_types[type_index++] << 8; |
| 342 | fixed_msrs[msr_num].lo |= |
| 343 | fixed_mtrr_types[type_index++] << 16; |
| 344 | fixed_msrs[msr_num].lo |= |
| 345 | fixed_mtrr_types[type_index++] << 24; |
| 346 | fixed_msrs[msr_num].hi |= |
| 347 | fixed_mtrr_types[type_index++] << 0; |
| 348 | fixed_msrs[msr_num].hi |= |
| 349 | fixed_mtrr_types[type_index++] << 8; |
| 350 | fixed_msrs[msr_num].hi |= |
| 351 | fixed_mtrr_types[type_index++] << 16; |
| 352 | fixed_msrs[msr_num].hi |= |
| 353 | fixed_mtrr_types[type_index++] << 24; |
| 354 | msr_num++; |
| 355 | } |
| 356 | } |
| 357 | |
Gabe Black | 7756fe7 | 2014-02-25 01:40:34 -0800 | [diff] [blame] | 358 | for (i = 0; i < ARRAY_SIZE(fixed_msrs); i++) |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 359 | printk(BIOS_DEBUG, "MTRR: Fixed MSR 0x%lx 0x%08x%08x\n", |
| 360 | msr_index[i], fixed_msrs[i].hi, fixed_msrs[i].lo); |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 361 | |
Gabe Black | 7756fe7 | 2014-02-25 01:40:34 -0800 | [diff] [blame] | 362 | disable_cache(); |
| 363 | for (i = 0; i < ARRAY_SIZE(fixed_msrs); i++) |
| 364 | wrmsr(msr_index[i], fixed_msrs[i]); |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 365 | enable_cache(); |
Marshall Dawson | c0dbeda | 2017-10-19 09:45:16 -0600 | [diff] [blame] | 366 | fixed_mtrrs_hide_amd_rwdram(); |
| 367 | |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 368 | } |
| 369 | |
Aaron Durbin | 57686f8 | 2013-03-20 15:50:59 -0500 | [diff] [blame] | 370 | void x86_setup_fixed_mtrrs_no_enable(void) |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 371 | { |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 372 | calc_fixed_mtrrs(); |
| 373 | commit_fixed_mtrrs(); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 374 | } |
Stefan Reinauer | 7f86ed1 | 2009-02-12 16:02:16 +0000 | [diff] [blame] | 375 | |
Aaron Durbin | 57686f8 | 2013-03-20 15:50:59 -0500 | [diff] [blame] | 376 | void x86_setup_fixed_mtrrs(void) |
| 377 | { |
| 378 | x86_setup_fixed_mtrrs_no_enable(); |
| 379 | |
| 380 | printk(BIOS_SPEW, "call enable_fixed_mtrr()\n"); |
| 381 | enable_fixed_mtrr(); |
| 382 | } |
| 383 | |
Gabe Black | 7756fe7 | 2014-02-25 01:40:34 -0800 | [diff] [blame] | 384 | struct var_mtrr_regs { |
| 385 | msr_t base; |
| 386 | msr_t mask; |
| 387 | }; |
| 388 | |
| 389 | struct var_mtrr_solution { |
| 390 | int mtrr_default_type; |
| 391 | int num_used; |
| 392 | struct var_mtrr_regs regs[NUM_MTRR_STATIC_STORAGE]; |
| 393 | }; |
| 394 | |
| 395 | /* Global storage for variable MTRR solution. */ |
| 396 | static struct var_mtrr_solution mtrr_global_solution; |
| 397 | |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 398 | struct var_mtrr_state { |
| 399 | struct memranges *addr_space; |
| 400 | int above4gb; |
| 401 | int address_bits; |
Gabe Black | 7756fe7 | 2014-02-25 01:40:34 -0800 | [diff] [blame] | 402 | int prepare_msrs; |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 403 | int mtrr_index; |
| 404 | int def_mtrr_type; |
Gabe Black | 7756fe7 | 2014-02-25 01:40:34 -0800 | [diff] [blame] | 405 | struct var_mtrr_regs *regs; |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 406 | }; |
Aaron Durbin | 57686f8 | 2013-03-20 15:50:59 -0500 | [diff] [blame] | 407 | |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 408 | static void clear_var_mtrr(int index) |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 409 | { |
Aaron Durbin | 2bebd7b | 2016-11-10 15:15:35 -0600 | [diff] [blame] | 410 | msr_t msr = { .lo = 0, .hi = 0 }; |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 411 | |
Aaron Durbin | 2bebd7b | 2016-11-10 15:15:35 -0600 | [diff] [blame] | 412 | wrmsr(MTRR_PHYS_BASE(index), msr); |
| 413 | wrmsr(MTRR_PHYS_MASK(index), msr); |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 414 | } |
| 415 | |
Gabe Black | 7756fe7 | 2014-02-25 01:40:34 -0800 | [diff] [blame] | 416 | static void prep_var_mtrr(struct var_mtrr_state *var_state, |
Lee Leahy | a07d0dd | 2017-03-15 14:25:22 -0700 | [diff] [blame] | 417 | uint32_t base, uint32_t size, int mtrr_type) |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 418 | { |
Gabe Black | 7756fe7 | 2014-02-25 01:40:34 -0800 | [diff] [blame] | 419 | struct var_mtrr_regs *regs; |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 420 | resource_t rbase; |
| 421 | resource_t rsize; |
| 422 | resource_t mask; |
| 423 | |
| 424 | /* Some variable MTRRs are attempted to be saved for the OS use. |
| 425 | * However, it's more important to try to map the full address space |
| 426 | * properly. */ |
| 427 | if (var_state->mtrr_index >= bios_mtrrs) |
| 428 | printk(BIOS_WARNING, "Taking a reserved OS MTRR.\n"); |
| 429 | if (var_state->mtrr_index >= total_mtrrs) { |
Jonathan Neuschäfer | bb3a5ef | 2018-04-09 20:14:19 +0200 | [diff] [blame] | 430 | printk(BIOS_ERR, "ERROR: Not enough MTRRs available! MTRR index is %d with %d MTRRs in total.\n", |
Paul Menzel | 6a70dbc | 2015-10-15 12:41:53 +0200 | [diff] [blame] | 431 | var_state->mtrr_index, total_mtrrs); |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 432 | return; |
| 433 | } |
| 434 | |
| 435 | rbase = base; |
| 436 | rsize = size; |
| 437 | |
| 438 | rbase = RANGE_TO_PHYS_ADDR(rbase); |
| 439 | rsize = RANGE_TO_PHYS_ADDR(rsize); |
| 440 | rsize = -rsize; |
| 441 | |
| 442 | mask = (1ULL << var_state->address_bits) - 1; |
| 443 | rsize = rsize & mask; |
| 444 | |
| 445 | printk(BIOS_DEBUG, "MTRR: %d base 0x%016llx mask 0x%016llx type %d\n", |
| 446 | var_state->mtrr_index, rbase, rsize, mtrr_type); |
| 447 | |
Gabe Black | 7756fe7 | 2014-02-25 01:40:34 -0800 | [diff] [blame] | 448 | regs = &var_state->regs[var_state->mtrr_index]; |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 449 | |
Gabe Black | 7756fe7 | 2014-02-25 01:40:34 -0800 | [diff] [blame] | 450 | regs->base.lo = rbase; |
| 451 | regs->base.lo |= mtrr_type; |
| 452 | regs->base.hi = rbase >> 32; |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 453 | |
Gabe Black | 7756fe7 | 2014-02-25 01:40:34 -0800 | [diff] [blame] | 454 | regs->mask.lo = rsize; |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 455 | regs->mask.lo |= MTRR_PHYS_MASK_VALID; |
Gabe Black | 7756fe7 | 2014-02-25 01:40:34 -0800 | [diff] [blame] | 456 | regs->mask.hi = rsize >> 32; |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | static void calc_var_mtrr_range(struct var_mtrr_state *var_state, |
Lee Leahy | a07d0dd | 2017-03-15 14:25:22 -0700 | [diff] [blame] | 460 | uint32_t base, uint32_t size, int mtrr_type) |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 461 | { |
| 462 | while (size != 0) { |
| 463 | uint32_t addr_lsb; |
| 464 | uint32_t size_msb; |
| 465 | uint32_t mtrr_size; |
| 466 | |
| 467 | addr_lsb = fls(base); |
| 468 | size_msb = fms(size); |
| 469 | |
| 470 | /* All MTRR entries need to have their base aligned to the mask |
| 471 | * size. The maximum size is calculated by a function of the |
| 472 | * min base bit set and maximum size bit set. */ |
| 473 | if (addr_lsb > size_msb) |
| 474 | mtrr_size = 1 << size_msb; |
| 475 | else |
| 476 | mtrr_size = 1 << addr_lsb; |
| 477 | |
Gabe Black | 7756fe7 | 2014-02-25 01:40:34 -0800 | [diff] [blame] | 478 | if (var_state->prepare_msrs) |
| 479 | prep_var_mtrr(var_state, base, mtrr_size, mtrr_type); |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 480 | |
| 481 | size -= mtrr_size; |
| 482 | base += mtrr_size; |
| 483 | var_state->mtrr_index++; |
| 484 | } |
| 485 | } |
| 486 | |
Nico Huber | bd5fb66 | 2017-10-07 13:40:19 +0200 | [diff] [blame] | 487 | static uint32_t optimize_var_mtrr_hole(const uint32_t base, |
| 488 | const uint32_t hole, |
| 489 | const uint64_t limit, |
| 490 | const int carve_hole) |
| 491 | { |
| 492 | /* |
| 493 | * With default type UC, we can potentially optimize a WB |
| 494 | * range with unaligned upper end, by aligning it up and |
| 495 | * carving the added "hole" out again. |
| 496 | * |
| 497 | * To optimize the upper end of the hole, we will test |
| 498 | * how many MTRRs calc_var_mtrr_range() will spend for any |
| 499 | * alignment of the hole's upper end. |
| 500 | * |
| 501 | * We take four parameters, the lower end of the WB range |
| 502 | * `base`, upper end of the WB range as start of the `hole`, |
| 503 | * a `limit` how far we may align the upper end of the hole |
| 504 | * up and a flag `carve_hole` whether we should count MTRRs |
| 505 | * for carving the hole out. We return the optimal upper end |
| 506 | * for the hole (which may be the same as the end of the WB |
| 507 | * range in case we don't gain anything by aligning up). |
| 508 | */ |
| 509 | |
| 510 | const int dont_care = 0; |
| 511 | struct var_mtrr_state var_state = { 0, }; |
| 512 | |
| 513 | unsigned int align, best_count; |
| 514 | uint32_t best_end = hole; |
| 515 | |
| 516 | /* calculate MTRR count for the WB range alone (w/o a hole) */ |
| 517 | calc_var_mtrr_range(&var_state, base, hole - base, dont_care); |
| 518 | best_count = var_state.mtrr_index; |
| 519 | var_state.mtrr_index = 0; |
| 520 | |
| 521 | for (align = fls(hole) + 1; align <= fms(hole); ++align) { |
| 522 | const uint64_t hole_end = ALIGN_UP((uint64_t)hole, 1 << align); |
| 523 | if (hole_end > limit) |
| 524 | break; |
| 525 | |
| 526 | /* calculate MTRR count for this alignment */ |
| 527 | calc_var_mtrr_range( |
| 528 | &var_state, base, hole_end - base, dont_care); |
| 529 | if (carve_hole) |
| 530 | calc_var_mtrr_range( |
| 531 | &var_state, hole, hole_end - hole, dont_care); |
| 532 | |
| 533 | if (var_state.mtrr_index < best_count) { |
| 534 | best_count = var_state.mtrr_index; |
| 535 | best_end = hole_end; |
| 536 | } |
| 537 | var_state.mtrr_index = 0; |
| 538 | } |
| 539 | |
| 540 | return best_end; |
| 541 | } |
| 542 | |
Aaron Durbin | e383442 | 2013-03-28 20:48:51 -0500 | [diff] [blame] | 543 | static void calc_var_mtrrs_with_hole(struct var_mtrr_state *var_state, |
Lee Leahy | a07d0dd | 2017-03-15 14:25:22 -0700 | [diff] [blame] | 544 | struct range_entry *r) |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 545 | { |
Aaron Durbin | e383442 | 2013-03-28 20:48:51 -0500 | [diff] [blame] | 546 | uint32_t a1, a2, b1, b2; |
Nico Huber | bd5fb66 | 2017-10-07 13:40:19 +0200 | [diff] [blame] | 547 | int mtrr_type, carve_hole; |
Aaron Durbin | e383442 | 2013-03-28 20:48:51 -0500 | [diff] [blame] | 548 | |
| 549 | /* |
Martin Roth | 4c3ab73 | 2013-07-08 16:23:54 -0600 | [diff] [blame] | 550 | * Determine MTRRs based on the following algorithm for the given entry: |
Aaron Durbin | e383442 | 2013-03-28 20:48:51 -0500 | [diff] [blame] | 551 | * +------------------+ b2 = ALIGN_UP(end) |
| 552 | * | 0 or more bytes | <-- hole is carved out between b1 and b2 |
Nico Huber | bd5fb66 | 2017-10-07 13:40:19 +0200 | [diff] [blame] | 553 | * +------------------+ a2 = b1 = original end |
Aaron Durbin | e383442 | 2013-03-28 20:48:51 -0500 | [diff] [blame] | 554 | * | | |
| 555 | * +------------------+ a1 = begin |
| 556 | * |
Nico Huber | bd5fb66 | 2017-10-07 13:40:19 +0200 | [diff] [blame] | 557 | * Thus, there are up to 2 sub-ranges to configure variable MTRRs for. |
Aaron Durbin | e383442 | 2013-03-28 20:48:51 -0500 | [diff] [blame] | 558 | */ |
| 559 | mtrr_type = range_entry_mtrr_type(r); |
| 560 | |
| 561 | a1 = range_entry_base_mtrr_addr(r); |
| 562 | a2 = range_entry_end_mtrr_addr(r); |
| 563 | |
Aaron Durbin | a38677b | 2016-07-21 14:26:34 -0500 | [diff] [blame] | 564 | /* The end address is within the first 1MiB. The fixed MTRRs take |
Aaron Durbin | e383442 | 2013-03-28 20:48:51 -0500 | [diff] [blame] | 565 | * precedence over the variable ones. Therefore this range |
| 566 | * can be ignored. */ |
Aaron Durbin | a38677b | 2016-07-21 14:26:34 -0500 | [diff] [blame] | 567 | if (a2 <= RANGE_1MB) |
Aaron Durbin | e383442 | 2013-03-28 20:48:51 -0500 | [diff] [blame] | 568 | return; |
| 569 | |
| 570 | /* Again, the fixed MTRRs take precedence so the beginning |
Aaron Durbin | a38677b | 2016-07-21 14:26:34 -0500 | [diff] [blame] | 571 | * of the range can be set to 0 if it starts at or below 1MiB. */ |
| 572 | if (a1 <= RANGE_1MB) |
Aaron Durbin | e383442 | 2013-03-28 20:48:51 -0500 | [diff] [blame] | 573 | a1 = 0; |
| 574 | |
| 575 | /* If the range starts above 4GiB the processing is done. */ |
| 576 | if (!var_state->above4gb && a1 >= RANGE_4GB) |
| 577 | return; |
| 578 | |
| 579 | /* Clip the upper address to 4GiB if addresses above 4GiB |
| 580 | * are not being processed. */ |
| 581 | if (!var_state->above4gb && a2 > RANGE_4GB) |
| 582 | a2 = RANGE_4GB; |
| 583 | |
| 584 | b1 = a2; |
Nico Huber | 64f0bcb | 2017-10-07 16:37:04 +0200 | [diff] [blame] | 585 | b2 = a2; |
| 586 | carve_hole = 0; |
Aaron Durbin | 5392424 | 2013-03-29 11:48:27 -0500 | [diff] [blame] | 587 | |
Nico Huber | 64f0bcb | 2017-10-07 16:37:04 +0200 | [diff] [blame] | 588 | /* We only consider WB type ranges for hole-carving. */ |
| 589 | if (mtrr_type == MTRR_TYPE_WRBACK) { |
| 590 | struct range_entry *next; |
| 591 | uint64_t b2_limit; |
| 592 | /* |
| 593 | * Depending on the type of the next range, there are three |
| 594 | * different situations to handle: |
| 595 | * |
| 596 | * 1. WB range is last in address space: |
| 597 | * Aligning up, up to the next power of 2, may gain us |
| 598 | * something. |
| 599 | * |
| 600 | * 2. The next range is of type UC: |
| 601 | * We may align up, up to the _end_ of the next range. If |
| 602 | * there is a gap between the current and the next range, |
| 603 | * it would have been covered by the default type UC anyway. |
| 604 | * |
| 605 | * 3. The next range is not of type UC: |
| 606 | * We may align up, up to the _base_ of the next range. This |
| 607 | * may either be the end of the current range (if the next |
| 608 | * range follows immediately) or the end of the gap between |
| 609 | * the ranges. |
| 610 | */ |
| 611 | next = memranges_next_entry(var_state->addr_space, r); |
| 612 | if (next == NULL) { |
| 613 | b2_limit = ALIGN_UP((uint64_t)b1, 1 << fms(b1)); |
| 614 | /* If it's the last range above 4GiB, we won't carve |
| 615 | the hole out. If an OS wanted to move MMIO there, |
| 616 | it would have to override the MTRR setting using |
| 617 | PAT just like it would with WB as default type. */ |
| 618 | carve_hole = a1 < RANGE_4GB; |
| 619 | } else if (range_entry_mtrr_type(next) |
| 620 | == MTRR_TYPE_UNCACHEABLE) { |
| 621 | b2_limit = range_entry_end_mtrr_addr(next); |
| 622 | carve_hole = 1; |
| 623 | } else { |
| 624 | b2_limit = range_entry_base_mtrr_addr(next); |
| 625 | carve_hole = 1; |
| 626 | } |
| 627 | b2 = optimize_var_mtrr_hole(a1, b1, b2_limit, carve_hole); |
Aaron Durbin | 5392424 | 2013-03-29 11:48:27 -0500 | [diff] [blame] | 628 | } |
Aaron Durbin | e383442 | 2013-03-28 20:48:51 -0500 | [diff] [blame] | 629 | |
| 630 | calc_var_mtrr_range(var_state, a1, b2 - a1, mtrr_type); |
Nico Huber | bd5fb66 | 2017-10-07 13:40:19 +0200 | [diff] [blame] | 631 | if (carve_hole && b2 != b1) { |
| 632 | calc_var_mtrr_range(var_state, b1, b2 - b1, |
| 633 | MTRR_TYPE_UNCACHEABLE); |
| 634 | } |
Aaron Durbin | e383442 | 2013-03-28 20:48:51 -0500 | [diff] [blame] | 635 | } |
| 636 | |
Aaron Durbin | 5b9e3b6 | 2014-02-05 16:00:43 -0600 | [diff] [blame] | 637 | static void __calc_var_mtrrs(struct memranges *addr_space, |
Lee Leahy | a07d0dd | 2017-03-15 14:25:22 -0700 | [diff] [blame] | 638 | int above4gb, int address_bits, |
| 639 | int *num_def_wb_mtrrs, int *num_def_uc_mtrrs) |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 640 | { |
| 641 | int wb_deftype_count; |
| 642 | int uc_deftype_count; |
Aaron Durbin | e383442 | 2013-03-28 20:48:51 -0500 | [diff] [blame] | 643 | struct range_entry *r; |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 644 | struct var_mtrr_state var_state; |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 645 | |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 646 | /* The default MTRR cacheability type is determined by calculating |
Paul Menzel | 4fe9813 | 2014-01-25 15:55:28 +0100 | [diff] [blame] | 647 | * the number of MTRRs required for each MTRR type as if it was the |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 648 | * default. */ |
| 649 | var_state.addr_space = addr_space; |
Scott Duplichan | f3cce2f | 2010-11-13 19:07:59 +0000 | [diff] [blame] | 650 | var_state.above4gb = above4gb; |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 651 | var_state.address_bits = address_bits; |
Gabe Black | 7756fe7 | 2014-02-25 01:40:34 -0800 | [diff] [blame] | 652 | var_state.prepare_msrs = 0; |
Stefan Reinauer | 7f86ed1 | 2009-02-12 16:02:16 +0000 | [diff] [blame] | 653 | |
Aaron Durbin | e383442 | 2013-03-28 20:48:51 -0500 | [diff] [blame] | 654 | wb_deftype_count = 0; |
| 655 | uc_deftype_count = 0; |
Duncan Laurie | 7389fa9 | 2011-12-22 10:59:40 -0800 | [diff] [blame] | 656 | |
Aaron Durbin | e383442 | 2013-03-28 20:48:51 -0500 | [diff] [blame] | 657 | /* |
Nico Huber | 64f0bcb | 2017-10-07 16:37:04 +0200 | [diff] [blame] | 658 | * For each range do 2 calculations: |
| 659 | * 1. UC as default type with possible holes at top of range. |
| 660 | * 2. WB as default. |
Martin Roth | 4c3ab73 | 2013-07-08 16:23:54 -0600 | [diff] [blame] | 661 | * The lowest count is then used as default after totaling all |
Nico Huber | 64f0bcb | 2017-10-07 16:37:04 +0200 | [diff] [blame] | 662 | * MTRRs. UC takes precedence in the MTRR architecture. There- |
| 663 | * fore, only holes can be used when the type of the region is |
| 664 | * MTRR_TYPE_WRBACK with MTRR_TYPE_UNCACHEABLE as the default |
| 665 | * type. |
Aaron Durbin | e383442 | 2013-03-28 20:48:51 -0500 | [diff] [blame] | 666 | */ |
| 667 | memranges_each_entry(r, var_state.addr_space) { |
| 668 | int mtrr_type; |
| 669 | |
| 670 | mtrr_type = range_entry_mtrr_type(r); |
| 671 | |
| 672 | if (mtrr_type != MTRR_TYPE_UNCACHEABLE) { |
Aaron Durbin | e383442 | 2013-03-28 20:48:51 -0500 | [diff] [blame] | 673 | var_state.mtrr_index = 0; |
Nico Huber | 64f0bcb | 2017-10-07 16:37:04 +0200 | [diff] [blame] | 674 | var_state.def_mtrr_type = MTRR_TYPE_UNCACHEABLE; |
| 675 | calc_var_mtrrs_with_hole(&var_state, r); |
| 676 | uc_deftype_count += var_state.mtrr_index; |
Aaron Durbin | e383442 | 2013-03-28 20:48:51 -0500 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | if (mtrr_type != MTRR_TYPE_WRBACK) { |
| 680 | var_state.mtrr_index = 0; |
| 681 | var_state.def_mtrr_type = MTRR_TYPE_WRBACK; |
Nico Huber | 64f0bcb | 2017-10-07 16:37:04 +0200 | [diff] [blame] | 682 | calc_var_mtrrs_with_hole(&var_state, r); |
Aaron Durbin | e383442 | 2013-03-28 20:48:51 -0500 | [diff] [blame] | 683 | wb_deftype_count += var_state.mtrr_index; |
| 684 | } |
| 685 | } |
Aaron Durbin | 5b9e3b6 | 2014-02-05 16:00:43 -0600 | [diff] [blame] | 686 | *num_def_wb_mtrrs = wb_deftype_count; |
| 687 | *num_def_uc_mtrrs = uc_deftype_count; |
| 688 | } |
| 689 | |
| 690 | static int calc_var_mtrrs(struct memranges *addr_space, |
Lee Leahy | a07d0dd | 2017-03-15 14:25:22 -0700 | [diff] [blame] | 691 | int above4gb, int address_bits) |
Aaron Durbin | 5b9e3b6 | 2014-02-05 16:00:43 -0600 | [diff] [blame] | 692 | { |
| 693 | int wb_deftype_count = 0; |
| 694 | int uc_deftype_count = 0; |
| 695 | |
| 696 | __calc_var_mtrrs(addr_space, above4gb, address_bits, &wb_deftype_count, |
Lee Leahy | a07d0dd | 2017-03-15 14:25:22 -0700 | [diff] [blame] | 697 | &uc_deftype_count); |
Aaron Durbin | 5b9e3b6 | 2014-02-05 16:00:43 -0600 | [diff] [blame] | 698 | |
| 699 | if (wb_deftype_count > bios_mtrrs && uc_deftype_count > bios_mtrrs) { |
| 700 | printk(BIOS_DEBUG, "MTRR: Removing WRCOMB type. " |
| 701 | "WB/UC MTRR counts: %d/%d > %d.\n", |
| 702 | wb_deftype_count, uc_deftype_count, bios_mtrrs); |
| 703 | memranges_update_tag(addr_space, MTRR_TYPE_WRCOMB, |
Lee Leahy | a07d0dd | 2017-03-15 14:25:22 -0700 | [diff] [blame] | 704 | MTRR_TYPE_UNCACHEABLE); |
Aaron Durbin | 5b9e3b6 | 2014-02-05 16:00:43 -0600 | [diff] [blame] | 705 | __calc_var_mtrrs(addr_space, above4gb, address_bits, |
Lee Leahy | a07d0dd | 2017-03-15 14:25:22 -0700 | [diff] [blame] | 706 | &wb_deftype_count, &uc_deftype_count); |
Aaron Durbin | 5b9e3b6 | 2014-02-05 16:00:43 -0600 | [diff] [blame] | 707 | } |
Scott Duplichan | f3cce2f | 2010-11-13 19:07:59 +0000 | [diff] [blame] | 708 | |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 709 | printk(BIOS_DEBUG, "MTRR: default type WB/UC MTRR counts: %d/%d.\n", |
| 710 | wb_deftype_count, uc_deftype_count); |
Kyösti Mälkki | ffc1fb3 | 2012-07-11 14:40:19 +0300 | [diff] [blame] | 711 | |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 712 | if (wb_deftype_count < uc_deftype_count) { |
| 713 | printk(BIOS_DEBUG, "MTRR: WB selected as default type.\n"); |
| 714 | return MTRR_TYPE_WRBACK; |
| 715 | } |
| 716 | printk(BIOS_DEBUG, "MTRR: UC selected as default type.\n"); |
| 717 | return MTRR_TYPE_UNCACHEABLE; |
| 718 | } |
Kyösti Mälkki | ffc1fb3 | 2012-07-11 14:40:19 +0300 | [diff] [blame] | 719 | |
Gabe Black | 7756fe7 | 2014-02-25 01:40:34 -0800 | [diff] [blame] | 720 | static void prepare_var_mtrrs(struct memranges *addr_space, int def_type, |
| 721 | int above4gb, int address_bits, |
| 722 | struct var_mtrr_solution *sol) |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 723 | { |
Aaron Durbin | e383442 | 2013-03-28 20:48:51 -0500 | [diff] [blame] | 724 | struct range_entry *r; |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 725 | struct var_mtrr_state var_state; |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 726 | |
| 727 | var_state.addr_space = addr_space; |
| 728 | var_state.above4gb = above4gb; |
| 729 | var_state.address_bits = address_bits; |
Gabe Black | 7756fe7 | 2014-02-25 01:40:34 -0800 | [diff] [blame] | 730 | /* Prepare the MSRs. */ |
| 731 | var_state.prepare_msrs = 1; |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 732 | var_state.mtrr_index = 0; |
| 733 | var_state.def_mtrr_type = def_type; |
Gabe Black | 7756fe7 | 2014-02-25 01:40:34 -0800 | [diff] [blame] | 734 | var_state.regs = &sol->regs[0]; |
Aaron Durbin | e383442 | 2013-03-28 20:48:51 -0500 | [diff] [blame] | 735 | |
| 736 | memranges_each_entry(r, var_state.addr_space) { |
| 737 | if (range_entry_mtrr_type(r) == def_type) |
| 738 | continue; |
Nico Huber | 64f0bcb | 2017-10-07 16:37:04 +0200 | [diff] [blame] | 739 | calc_var_mtrrs_with_hole(&var_state, r); |
Aaron Durbin | e383442 | 2013-03-28 20:48:51 -0500 | [diff] [blame] | 740 | } |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 741 | |
Gabe Black | 7756fe7 | 2014-02-25 01:40:34 -0800 | [diff] [blame] | 742 | /* Update the solution. */ |
| 743 | sol->num_used = var_state.mtrr_index; |
| 744 | } |
| 745 | |
Aaron Durbin | d9762f7 | 2017-06-12 12:48:38 -0500 | [diff] [blame] | 746 | static int commit_var_mtrrs(const struct var_mtrr_solution *sol) |
Gabe Black | 7756fe7 | 2014-02-25 01:40:34 -0800 | [diff] [blame] | 747 | { |
| 748 | int i; |
| 749 | |
Aaron Durbin | d9762f7 | 2017-06-12 12:48:38 -0500 | [diff] [blame] | 750 | if (sol->num_used > total_mtrrs) { |
| 751 | printk(BIOS_WARNING, "Not enough MTRRs: %d vs %d\n", |
| 752 | sol->num_used, total_mtrrs); |
| 753 | return -1; |
| 754 | } |
| 755 | |
Isaac Christensen | 81f90c5 | 2014-09-24 14:59:32 -0600 | [diff] [blame] | 756 | /* Write out the variable MTRRs. */ |
Gabe Black | 7756fe7 | 2014-02-25 01:40:34 -0800 | [diff] [blame] | 757 | disable_cache(); |
| 758 | for (i = 0; i < sol->num_used; i++) { |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 759 | wrmsr(MTRR_PHYS_BASE(i), sol->regs[i].base); |
| 760 | wrmsr(MTRR_PHYS_MASK(i), sol->regs[i].mask); |
Gabe Black | 7756fe7 | 2014-02-25 01:40:34 -0800 | [diff] [blame] | 761 | } |
| 762 | /* Clear the ones that are unused. */ |
| 763 | for (; i < total_mtrrs; i++) |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 764 | clear_var_mtrr(i); |
Isaac Christensen | 81f90c5 | 2014-09-24 14:59:32 -0600 | [diff] [blame] | 765 | enable_var_mtrr(sol->mtrr_default_type); |
Gabe Black | 7756fe7 | 2014-02-25 01:40:34 -0800 | [diff] [blame] | 766 | enable_cache(); |
| 767 | |
Aaron Durbin | d9762f7 | 2017-06-12 12:48:38 -0500 | [diff] [blame] | 768 | return 0; |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | void x86_setup_var_mtrrs(unsigned int address_bits, unsigned int above4gb) |
| 772 | { |
Gabe Black | 7756fe7 | 2014-02-25 01:40:34 -0800 | [diff] [blame] | 773 | static struct var_mtrr_solution *sol = NULL; |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 774 | struct memranges *addr_space; |
| 775 | |
| 776 | addr_space = get_physical_address_space(); |
| 777 | |
Gabe Black | 7756fe7 | 2014-02-25 01:40:34 -0800 | [diff] [blame] | 778 | if (sol == NULL) { |
Gabe Black | 7756fe7 | 2014-02-25 01:40:34 -0800 | [diff] [blame] | 779 | sol = &mtrr_global_solution; |
| 780 | sol->mtrr_default_type = |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 781 | calc_var_mtrrs(addr_space, !!above4gb, address_bits); |
Gabe Black | 7756fe7 | 2014-02-25 01:40:34 -0800 | [diff] [blame] | 782 | prepare_var_mtrrs(addr_space, sol->mtrr_default_type, |
| 783 | !!above4gb, address_bits, sol); |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 784 | } |
Stefan Reinauer | 00093a8 | 2011-11-02 16:12:34 -0700 | [diff] [blame] | 785 | |
Gabe Black | 7756fe7 | 2014-02-25 01:40:34 -0800 | [diff] [blame] | 786 | commit_var_mtrrs(sol); |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 787 | } |
| 788 | |
Sven Schnelle | adfbcb79 | 2012-01-10 12:01:43 +0100 | [diff] [blame] | 789 | void x86_setup_mtrrs(void) |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 790 | { |
Sven Schnelle | adfbcb79 | 2012-01-10 12:01:43 +0100 | [diff] [blame] | 791 | int address_size; |
Aaron Durbin | e63be89 | 2016-03-07 16:05:36 -0600 | [diff] [blame] | 792 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 793 | x86_setup_fixed_mtrrs(); |
Sven Schnelle | adfbcb79 | 2012-01-10 12:01:43 +0100 | [diff] [blame] | 794 | address_size = cpu_phys_address_size(); |
Aaron Durbin | e63be89 | 2016-03-07 16:05:36 -0600 | [diff] [blame] | 795 | printk(BIOS_DEBUG, "CPU physical address size: %d bits\n", |
| 796 | address_size); |
| 797 | /* Always handle addresses above 4GiB. */ |
Sven Schnelle | adfbcb79 | 2012-01-10 12:01:43 +0100 | [diff] [blame] | 798 | x86_setup_var_mtrrs(address_size, 1); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 799 | } |
| 800 | |
Aaron Durbin | e63be89 | 2016-03-07 16:05:36 -0600 | [diff] [blame] | 801 | void x86_setup_mtrrs_with_detect(void) |
| 802 | { |
| 803 | detect_var_mtrrs(); |
| 804 | x86_setup_mtrrs(); |
| 805 | } |
| 806 | |
Kyösti Mälkki | 38a8fb0 | 2014-06-30 13:48:18 +0300 | [diff] [blame] | 807 | void x86_mtrr_check(void) |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 808 | { |
| 809 | /* Only Pentium Pro and later have MTRR */ |
| 810 | msr_t msr; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 811 | printk(BIOS_DEBUG, "\nMTRR check\n"); |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 812 | |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 813 | msr = rdmsr(MTRR_DEF_TYPE_MSR); |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 814 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 815 | printk(BIOS_DEBUG, "Fixed MTRRs : "); |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 816 | if (msr.lo & MTRR_DEF_TYPE_FIX_EN) |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 817 | printk(BIOS_DEBUG, "Enabled\n"); |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 818 | else |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 819 | printk(BIOS_DEBUG, "Disabled\n"); |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 820 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 821 | printk(BIOS_DEBUG, "Variable MTRRs: "); |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 822 | if (msr.lo & MTRR_DEF_TYPE_EN) |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 823 | printk(BIOS_DEBUG, "Enabled\n"); |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 824 | else |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 825 | printk(BIOS_DEBUG, "Disabled\n"); |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 826 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 827 | printk(BIOS_DEBUG, "\n"); |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 828 | |
| 829 | post_code(0x93); |
Eric Biederman | fcd5ace | 2004-10-14 19:29:29 +0000 | [diff] [blame] | 830 | } |
Aaron Durbin | 2bebd7b | 2016-11-10 15:15:35 -0600 | [diff] [blame] | 831 | |
| 832 | static bool put_back_original_solution; |
| 833 | |
| 834 | void mtrr_use_temp_range(uintptr_t begin, size_t size, int type) |
| 835 | { |
| 836 | const struct range_entry *r; |
| 837 | const struct memranges *orig; |
| 838 | struct var_mtrr_solution sol; |
| 839 | struct memranges addr_space; |
| 840 | const int above4gb = 1; /* Cover above 4GiB by default. */ |
| 841 | int address_bits; |
| 842 | |
| 843 | /* Make a copy of the original address space and tweak it with the |
| 844 | * provided range. */ |
| 845 | memranges_init_empty(&addr_space, NULL, 0); |
| 846 | orig = get_physical_address_space(); |
| 847 | memranges_each_entry(r, orig) { |
| 848 | unsigned long tag = range_entry_tag(r); |
| 849 | |
Aaron Durbin | 2bebd7b | 2016-11-10 15:15:35 -0600 | [diff] [blame] | 850 | /* Remove any write combining MTRRs from the temporary |
| 851 | * solution as it just fragments the address space. */ |
| 852 | if (tag == MTRR_TYPE_WRCOMB) |
| 853 | tag = MTRR_TYPE_UNCACHEABLE; |
| 854 | |
| 855 | memranges_insert(&addr_space, range_entry_base(r), |
| 856 | range_entry_size(r), tag); |
| 857 | } |
| 858 | |
| 859 | /* Place new range into the address space. */ |
| 860 | memranges_insert(&addr_space, begin, size, type); |
| 861 | |
| 862 | print_physical_address_space(&addr_space, "TEMPORARY"); |
| 863 | |
| 864 | /* Calculate a new solution with the updated address space. */ |
| 865 | address_bits = cpu_phys_address_size(); |
| 866 | memset(&sol, 0, sizeof(sol)); |
| 867 | sol.mtrr_default_type = |
| 868 | calc_var_mtrrs(&addr_space, above4gb, address_bits); |
| 869 | prepare_var_mtrrs(&addr_space, sol.mtrr_default_type, |
| 870 | above4gb, address_bits, &sol); |
Aaron Durbin | d9762f7 | 2017-06-12 12:48:38 -0500 | [diff] [blame] | 871 | |
| 872 | if (commit_var_mtrrs(&sol) < 0) |
| 873 | printk(BIOS_WARNING, "Unable to insert temporary MTRR range: 0x%016llx - 0x%016llx size 0x%08llx type %d\n", |
| 874 | (long long)begin, (long long)begin + size, |
| 875 | (long long)size, type); |
| 876 | else |
| 877 | put_back_original_solution = true; |
Aaron Durbin | 2bebd7b | 2016-11-10 15:15:35 -0600 | [diff] [blame] | 878 | |
| 879 | memranges_teardown(&addr_space); |
Aaron Durbin | 2bebd7b | 2016-11-10 15:15:35 -0600 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | static void remove_temp_solution(void *unused) |
| 883 | { |
| 884 | if (put_back_original_solution) |
| 885 | commit_var_mtrrs(&mtrr_global_solution); |
| 886 | } |
| 887 | |
| 888 | BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, remove_temp_solution, NULL); |
| 889 | BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, remove_temp_solution, NULL); |