Aaron Durbin | 9a7d7bc | 2013-09-07 00:41:48 -0500 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2013 Google Inc. |
| 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. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #include <stddef.h> |
| 21 | #include <arch/cpu.h> |
| 22 | #include <arch/io.h> |
| 23 | #include <arch/cbfs.h> |
| 24 | #include <arch/stages.h> |
Aaron Durbin | 00bf3db | 2014-01-09 10:33:23 -0600 | [diff] [blame] | 25 | #include <arch/early_variables.h> |
Aaron Durbin | 9a7d7bc | 2013-09-07 00:41:48 -0500 | [diff] [blame] | 26 | #include <console/console.h> |
| 27 | #include <cbmem.h> |
| 28 | #include <cpu/x86/mtrr.h> |
Aaron Durbin | 3e0eea1 | 2013-10-28 11:20:35 -0500 | [diff] [blame] | 29 | #if CONFIG_EC_GOOGLE_CHROMEEC |
| 30 | #include <ec/google/chromeec/ec.h> |
| 31 | #endif |
Aaron Durbin | a8e9b63 | 2013-10-30 15:46:07 -0500 | [diff] [blame] | 32 | #include <elog.h> |
Aaron Durbin | dc249f6 | 2013-10-10 21:03:50 -0500 | [diff] [blame] | 33 | #include <ramstage_cache.h> |
Aaron Durbin | 9a7d7bc | 2013-09-07 00:41:48 -0500 | [diff] [blame] | 34 | #include <romstage_handoff.h> |
Aaron Durbin | 794bddf | 2013-09-27 11:38:36 -0500 | [diff] [blame] | 35 | #include <timestamp.h> |
Aaron Durbin | ebf7ec5 | 2013-11-14 13:47:08 -0600 | [diff] [blame] | 36 | #include <vendorcode/google/chromeos/chromeos.h> |
Aaron Durbin | 9a7d7bc | 2013-09-07 00:41:48 -0500 | [diff] [blame] | 37 | #include <baytrail/gpio.h> |
| 38 | #include <baytrail/iomap.h> |
Aaron Durbin | 9a7d7bc | 2013-09-07 00:41:48 -0500 | [diff] [blame] | 39 | #include <baytrail/lpc.h> |
| 40 | #include <baytrail/pci_devs.h> |
Aaron Durbin | 6e32893 | 2013-11-06 12:04:50 -0600 | [diff] [blame] | 41 | #include <baytrail/pmc.h> |
Aaron Durbin | dc249f6 | 2013-10-10 21:03:50 -0500 | [diff] [blame] | 42 | #include <baytrail/reset.h> |
Aaron Durbin | 9a7d7bc | 2013-09-07 00:41:48 -0500 | [diff] [blame] | 43 | #include <baytrail/romstage.h> |
Aaron Durbin | 7837be6 | 2013-10-21 22:32:00 -0500 | [diff] [blame] | 44 | #include <baytrail/smm.h> |
Aaron Durbin | 6f9947a | 2013-11-18 11:16:20 -0600 | [diff] [blame] | 45 | #include <baytrail/spi.h> |
Aaron Durbin | 9a7d7bc | 2013-09-07 00:41:48 -0500 | [diff] [blame] | 46 | |
| 47 | /* The cache-as-ram assembly file calls romstage_main() after setting up |
| 48 | * cache-as-ram. romstage_main() will then call the mainboards's |
| 49 | * mainboard_romstage_entry() function. That function then calls |
| 50 | * romstage_common() below. The reason for the back and forth is to provide |
| 51 | * common entry point from cache-as-ram while still allowing for code sharing. |
| 52 | * Because we can't use global variables the stack is used for allocations -- |
| 53 | * thus the need to call back and forth. */ |
| 54 | |
| 55 | static void *setup_stack_and_mttrs(void); |
| 56 | |
| 57 | static void program_base_addresses(void) |
| 58 | { |
| 59 | uint32_t reg; |
| 60 | const uint32_t lpc_dev = PCI_DEV(0, LPC_DEV, LPC_FUNC); |
| 61 | |
| 62 | /* Memory Mapped IO registers. */ |
| 63 | reg = PMC_BASE_ADDRESS | 2; |
| 64 | pci_write_config32(lpc_dev, PBASE, reg); |
| 65 | reg = IO_BASE_ADDRESS | 2; |
| 66 | pci_write_config32(lpc_dev, IOBASE, reg); |
| 67 | reg = ILB_BASE_ADDRESS | 2; |
| 68 | pci_write_config32(lpc_dev, IBASE, reg); |
| 69 | reg = SPI_BASE_ADDRESS | 2; |
| 70 | pci_write_config32(lpc_dev, SBASE, reg); |
| 71 | reg = MPHY_BASE_ADDRESS | 2; |
| 72 | pci_write_config32(lpc_dev, MPBASE, reg); |
Aaron Durbin | a64ef62 | 2013-10-03 12:56:37 -0500 | [diff] [blame] | 73 | reg = PUNIT_BASE_ADDRESS | 2; |
| 74 | pci_write_config32(lpc_dev, PUBASE, reg); |
Aaron Durbin | 9a7d7bc | 2013-09-07 00:41:48 -0500 | [diff] [blame] | 75 | reg = RCBA_BASE_ADDRESS | 1; |
| 76 | pci_write_config32(lpc_dev, RCBA, reg); |
| 77 | |
| 78 | /* IO Port Registers. */ |
| 79 | reg = ACPI_BASE_ADDRESS | 2; |
| 80 | pci_write_config32(lpc_dev, ABASE, reg); |
| 81 | reg = GPIO_BASE_ADDRESS | 2; |
| 82 | pci_write_config32(lpc_dev, GBASE, reg); |
| 83 | } |
| 84 | |
Aaron Durbin | 6f9947a | 2013-11-18 11:16:20 -0600 | [diff] [blame] | 85 | static void spi_init(void) |
| 86 | { |
Aaron Durbin | 4177db5 | 2014-02-05 14:55:26 -0600 | [diff] [blame] | 87 | const unsigned long scs = SPI_BASE_ADDRESS + SCS; |
Aaron Durbin | 6f9947a | 2013-11-18 11:16:20 -0600 | [diff] [blame] | 88 | const unsigned long bcr = SPI_BASE_ADDRESS + BCR; |
Aaron Durbin | 4177db5 | 2014-02-05 14:55:26 -0600 | [diff] [blame] | 89 | uint32_t reg; |
| 90 | |
| 91 | /* Disable generating SMI when setting WPD bit. */ |
| 92 | write32(scs, read32(scs) & ~SMIWPEN); |
| 93 | /* |
| 94 | * Enable caching and prefetching in the SPI controller. Disable |
| 95 | * the SMM-only BIOS write and set WPD bit. |
| 96 | */ |
| 97 | reg = (read32(bcr) & ~SRC_MASK) | SRC_CACHE_PREFETCH | BCR_WPD; |
| 98 | reg &= ~EISS; |
| 99 | write32(bcr, reg); |
Aaron Durbin | 6f9947a | 2013-11-18 11:16:20 -0600 | [diff] [blame] | 100 | } |
| 101 | |
Aaron Durbin | 794bddf | 2013-09-27 11:38:36 -0500 | [diff] [blame] | 102 | /* Entry from cache-as-ram.inc. */ |
| 103 | void * asmlinkage romstage_main(unsigned long bist, |
| 104 | uint32_t tsc_low, uint32_t tsc_hi) |
| 105 | { |
| 106 | struct romstage_params rp = { |
| 107 | .bist = bist, |
| 108 | .mrc_params = NULL, |
| 109 | }; |
| 110 | |
| 111 | /* Save initial timestamp from bootblock. */ |
Kyösti Mälkki | 4175927 | 2014-12-31 21:11:51 +0200 | [diff] [blame^] | 112 | timestamp_init((((uint64_t)tsc_hi) << 32) | (uint64_t)tsc_low); |
| 113 | |
Aaron Durbin | 794bddf | 2013-09-27 11:38:36 -0500 | [diff] [blame] | 114 | /* Save romstage begin */ |
Kyösti Mälkki | 4175927 | 2014-12-31 21:11:51 +0200 | [diff] [blame^] | 115 | timestamp_add_now(TS_START_ROMSTAGE); |
Aaron Durbin | 794bddf | 2013-09-27 11:38:36 -0500 | [diff] [blame] | 116 | |
Aaron Durbin | 9a7d7bc | 2013-09-07 00:41:48 -0500 | [diff] [blame] | 117 | program_base_addresses(); |
| 118 | |
Aaron Durbin | fd039f7 | 2013-10-04 11:11:52 -0500 | [diff] [blame] | 119 | tco_disable(); |
| 120 | |
Aaron Durbin | 9a7d7bc | 2013-09-07 00:41:48 -0500 | [diff] [blame] | 121 | byt_config_com1_and_enable(); |
| 122 | |
| 123 | console_init(); |
| 124 | |
Aaron Durbin | 6f9947a | 2013-11-18 11:16:20 -0600 | [diff] [blame] | 125 | spi_init(); |
| 126 | |
Aaron Durbin | bb3ee83 | 2013-10-07 17:12:20 -0500 | [diff] [blame] | 127 | set_max_freq(); |
| 128 | |
Aaron Durbin | 189aa3e | 2013-10-04 11:17:45 -0500 | [diff] [blame] | 129 | punit_init(); |
| 130 | |
Aaron Durbin | ecf9086 | 2013-09-24 12:36:14 -0500 | [diff] [blame] | 131 | gfx_init(); |
| 132 | |
Aaron Durbin | 3e0eea1 | 2013-10-28 11:20:35 -0500 | [diff] [blame] | 133 | #if CONFIG_EC_GOOGLE_CHROMEEC |
| 134 | /* Ensure the EC is in the right mode for recovery */ |
| 135 | google_chromeec_early_init(); |
| 136 | #endif |
| 137 | |
Aaron Durbin | 5f8ad56 | 2013-10-08 16:54:18 -0500 | [diff] [blame] | 138 | /* Call into mainboard. */ |
| 139 | mainboard_romstage_entry(&rp); |
| 140 | |
| 141 | return setup_stack_and_mttrs(); |
| 142 | } |
| 143 | |
Aaron Durbin | 00bf3db | 2014-01-09 10:33:23 -0600 | [diff] [blame] | 144 | static struct chipset_power_state power_state CAR_GLOBAL; |
| 145 | |
| 146 | static void migrate_power_state(void) |
Aaron Durbin | 6e32893 | 2013-11-06 12:04:50 -0600 | [diff] [blame] | 147 | { |
Aaron Durbin | 00bf3db | 2014-01-09 10:33:23 -0600 | [diff] [blame] | 148 | struct chipset_power_state *ps_cbmem; |
| 149 | struct chipset_power_state *ps_car; |
| 150 | |
| 151 | ps_car = car_get_var_ptr(&power_state); |
| 152 | ps_cbmem = cbmem_add(CBMEM_ID_POWER_STATE, sizeof(*ps_cbmem)); |
| 153 | |
| 154 | if (ps_cbmem == NULL) { |
| 155 | printk(BIOS_DEBUG, "Not adding power state to cbmem!\n"); |
| 156 | return; |
| 157 | } |
| 158 | memcpy(ps_cbmem, ps_car, sizeof(*ps_cbmem)); |
| 159 | } |
| 160 | CAR_MIGRATE(migrate_power_state); |
| 161 | |
| 162 | static struct chipset_power_state *fill_power_state(void) |
| 163 | { |
| 164 | struct chipset_power_state *ps = car_get_var_ptr(&power_state); |
| 165 | |
| 166 | ps->pm1_sts = inw(ACPI_BASE_ADDRESS + PM1_STS); |
| 167 | ps->pm1_en = inw(ACPI_BASE_ADDRESS + PM1_EN); |
| 168 | ps->pm1_cnt = inl(ACPI_BASE_ADDRESS + PM1_CNT); |
| 169 | ps->gpe0_sts = inl(ACPI_BASE_ADDRESS + GPE0_STS); |
| 170 | ps->gpe0_en = inl(ACPI_BASE_ADDRESS + GPE0_EN); |
| 171 | ps->tco_sts = inl(ACPI_BASE_ADDRESS + TCO_STS); |
| 172 | ps->prsts = read32(PMC_BASE_ADDRESS + PRSTS); |
| 173 | ps->gen_pmcon1 = read32(PMC_BASE_ADDRESS + GEN_PMCON1); |
| 174 | ps->gen_pmcon2 = read32(PMC_BASE_ADDRESS + GEN_PMCON2); |
| 175 | |
| 176 | printk(BIOS_DEBUG, "pm1_sts: %04x pm1_en: %04x pm1_cnt: %08x\n", |
| 177 | ps->pm1_sts, ps->pm1_en, ps->pm1_cnt); |
| 178 | printk(BIOS_DEBUG, "gpe0_sts: %08x gpe0_en: %08x tco_sts: %08x\n", |
| 179 | ps->gpe0_sts, ps->gpe0_en, ps->tco_sts); |
| 180 | printk(BIOS_DEBUG, "prsts: %08x gen_pmcon1: %08x gen_pmcon2: %08x\n", |
| 181 | ps->prsts, ps->gen_pmcon1, ps->gen_pmcon2); |
| 182 | |
| 183 | return ps; |
| 184 | } |
| 185 | |
| 186 | /* Return 0, 3, or 5 to indicate the previous sleep state. */ |
| 187 | static int chipset_prev_sleep_state(struct chipset_power_state *ps) |
| 188 | { |
Aaron Durbin | 6e32893 | 2013-11-06 12:04:50 -0600 | [diff] [blame] | 189 | /* Default to S0. */ |
| 190 | int prev_sleep_state = 0; |
| 191 | |
Aaron Durbin | 00bf3db | 2014-01-09 10:33:23 -0600 | [diff] [blame] | 192 | if (ps->pm1_sts & WAK_STS) { |
| 193 | switch ((ps->pm1_cnt & SLP_TYP) >> SLP_TYP_SHIFT) { |
Aaron Durbin | 6e32893 | 2013-11-06 12:04:50 -0600 | [diff] [blame] | 194 | #if CONFIG_HAVE_ACPI_RESUME |
| 195 | case SLP_TYP_S3: |
| 196 | prev_sleep_state = 3; |
| 197 | break; |
| 198 | #endif |
| 199 | case SLP_TYP_S5: |
| 200 | prev_sleep_state = 5; |
Aaron Durbin | 00bf3db | 2014-01-09 10:33:23 -0600 | [diff] [blame] | 201 | break; |
Aaron Durbin | 6e32893 | 2013-11-06 12:04:50 -0600 | [diff] [blame] | 202 | } |
| 203 | /* Clear SLP_TYP. */ |
Aaron Durbin | 00bf3db | 2014-01-09 10:33:23 -0600 | [diff] [blame] | 204 | outl(ps->pm1_cnt & ~(SLP_TYP), ACPI_BASE_ADDRESS + PM1_CNT); |
Aaron Durbin | 6e32893 | 2013-11-06 12:04:50 -0600 | [diff] [blame] | 205 | } |
| 206 | |
Aaron Durbin | 00bf3db | 2014-01-09 10:33:23 -0600 | [diff] [blame] | 207 | if (ps->gen_pmcon1 & (PWR_FLR | SUS_PWR_FLR)) { |
Aaron Durbin | 6e32893 | 2013-11-06 12:04:50 -0600 | [diff] [blame] | 208 | prev_sleep_state = 5; |
| 209 | } |
| 210 | |
Aaron Durbin | 6e32893 | 2013-11-06 12:04:50 -0600 | [diff] [blame] | 211 | return prev_sleep_state; |
| 212 | } |
| 213 | |
Aaron Durbin | ebf7ec5 | 2013-11-14 13:47:08 -0600 | [diff] [blame] | 214 | static inline void chromeos_init(int prev_sleep_state) |
| 215 | { |
Aaron Durbin | 00bf3db | 2014-01-09 10:33:23 -0600 | [diff] [blame] | 216 | #if CONFIG_CHROMEOS |
Aaron Durbin | ebf7ec5 | 2013-11-14 13:47:08 -0600 | [diff] [blame] | 217 | /* Normalize the sleep state to what init_chromeos() wants for S3: 2. */ |
| 218 | init_chromeos(prev_sleep_state == 3 ? 2 : 0); |
Aaron Durbin | ebf7ec5 | 2013-11-14 13:47:08 -0600 | [diff] [blame] | 219 | #endif |
Aaron Durbin | 00bf3db | 2014-01-09 10:33:23 -0600 | [diff] [blame] | 220 | } |
Aaron Durbin | ebf7ec5 | 2013-11-14 13:47:08 -0600 | [diff] [blame] | 221 | |
Aaron Durbin | 5f8ad56 | 2013-10-08 16:54:18 -0500 | [diff] [blame] | 222 | /* Entry from the mainboard. */ |
| 223 | void romstage_common(struct romstage_params *params) |
| 224 | { |
| 225 | struct romstage_handoff *handoff; |
Aaron Durbin | 00bf3db | 2014-01-09 10:33:23 -0600 | [diff] [blame] | 226 | struct chipset_power_state *ps; |
Aaron Durbin | 6e32893 | 2013-11-06 12:04:50 -0600 | [diff] [blame] | 227 | int prev_sleep_state; |
Aaron Durbin | 5f8ad56 | 2013-10-08 16:54:18 -0500 | [diff] [blame] | 228 | |
Kyösti Mälkki | 4175927 | 2014-12-31 21:11:51 +0200 | [diff] [blame^] | 229 | timestamp_add_now(TS_BEFORE_INITRAM); |
Aaron Durbin | 794bddf | 2013-09-27 11:38:36 -0500 | [diff] [blame] | 230 | |
Aaron Durbin | 00bf3db | 2014-01-09 10:33:23 -0600 | [diff] [blame] | 231 | ps = fill_power_state(); |
| 232 | prev_sleep_state = chipset_prev_sleep_state(ps); |
Aaron Durbin | 6e32893 | 2013-11-06 12:04:50 -0600 | [diff] [blame] | 233 | |
| 234 | printk(BIOS_DEBUG, "prev_sleep_state = S%d\n", prev_sleep_state); |
| 235 | |
Aaron Durbin | 4177db5 | 2014-02-05 14:55:26 -0600 | [diff] [blame] | 236 | #if CONFIG_ELOG_BOOT_COUNT |
| 237 | if (prev_sleep_state != 3) |
| 238 | boot_count_increment(); |
| 239 | #endif |
| 240 | |
| 241 | |
Aaron Durbin | 9a7d7bc | 2013-09-07 00:41:48 -0500 | [diff] [blame] | 242 | /* Initialize RAM */ |
Aaron Durbin | 6e32893 | 2013-11-06 12:04:50 -0600 | [diff] [blame] | 243 | raminit(params->mrc_params, prev_sleep_state); |
Aaron Durbin | 9a7d7bc | 2013-09-07 00:41:48 -0500 | [diff] [blame] | 244 | |
Kyösti Mälkki | 4175927 | 2014-12-31 21:11:51 +0200 | [diff] [blame^] | 245 | timestamp_add_now(TS_AFTER_INITRAM); |
Aaron Durbin | 794bddf | 2013-09-27 11:38:36 -0500 | [diff] [blame] | 246 | |
Aaron Durbin | 9a7d7bc | 2013-09-07 00:41:48 -0500 | [diff] [blame] | 247 | handoff = romstage_handoff_find_or_add(); |
| 248 | if (handoff != NULL) |
Aaron Durbin | 6e32893 | 2013-11-06 12:04:50 -0600 | [diff] [blame] | 249 | handoff->s3_resume = (prev_sleep_state == 3); |
Aaron Durbin | 9a7d7bc | 2013-09-07 00:41:48 -0500 | [diff] [blame] | 250 | else |
| 251 | printk(BIOS_DEBUG, "Romstage handoff structure not added!\n"); |
| 252 | |
Aaron Durbin | ebf7ec5 | 2013-11-14 13:47:08 -0600 | [diff] [blame] | 253 | chromeos_init(prev_sleep_state); |
Aaron Durbin | 9a7d7bc | 2013-09-07 00:41:48 -0500 | [diff] [blame] | 254 | } |
| 255 | |
Aaron Durbin | 9a7d7bc | 2013-09-07 00:41:48 -0500 | [diff] [blame] | 256 | void asmlinkage romstage_after_car(void) |
| 257 | { |
Aaron Durbin | 794bddf | 2013-09-27 11:38:36 -0500 | [diff] [blame] | 258 | timestamp_add_now(TS_END_ROMSTAGE); |
| 259 | |
Aaron Durbin | 9a7d7bc | 2013-09-07 00:41:48 -0500 | [diff] [blame] | 260 | /* Load the ramstage. */ |
| 261 | copy_and_run(); |
| 262 | while (1); |
| 263 | } |
| 264 | |
| 265 | static inline uint32_t *stack_push(u32 *stack, u32 value) |
| 266 | { |
| 267 | stack = &stack[-1]; |
| 268 | *stack = value; |
| 269 | return stack; |
| 270 | } |
| 271 | |
| 272 | /* Romstage needs quite a bit of stack for decompressing images since the lzma |
| 273 | * lib keeps its state on the stack during romstage. */ |
| 274 | static unsigned long choose_top_of_stack(void) |
| 275 | { |
| 276 | unsigned long stack_top; |
| 277 | const unsigned long romstage_ram_stack_size = 0x5000; |
| 278 | |
| 279 | /* cbmem_add() does a find() before add(). */ |
| 280 | stack_top = (unsigned long)cbmem_add(CBMEM_ID_ROMSTAGE_RAM_STACK, |
| 281 | romstage_ram_stack_size); |
| 282 | stack_top += romstage_ram_stack_size; |
| 283 | return stack_top; |
| 284 | } |
| 285 | |
| 286 | /* setup_stack_and_mttrs() determines the stack to use after |
| 287 | * cache-as-ram is torn down as well as the MTRR settings to use. */ |
| 288 | static void *setup_stack_and_mttrs(void) |
| 289 | { |
| 290 | unsigned long top_of_stack; |
| 291 | int num_mtrrs; |
| 292 | uint32_t *slot; |
| 293 | uint32_t mtrr_mask_upper; |
| 294 | uint32_t top_of_ram; |
| 295 | |
| 296 | /* Top of stack needs to be aligned to a 4-byte boundary. */ |
| 297 | top_of_stack = choose_top_of_stack() & ~3; |
| 298 | slot = (void *)top_of_stack; |
| 299 | num_mtrrs = 0; |
| 300 | |
| 301 | /* The upper bits of the MTRR mask need to set according to the number |
| 302 | * of physical address bits. */ |
| 303 | mtrr_mask_upper = (1 << ((cpuid_eax(0x80000008) & 0xff) - 32)) - 1; |
| 304 | |
| 305 | /* The order for each MTRR is value then base with upper 32-bits of |
| 306 | * each value coming before the lower 32-bits. The reasoning for |
| 307 | * this ordering is to create a stack layout like the following: |
| 308 | * +0: Number of MTRRs |
| 309 | * +4: MTRR base 0 31:0 |
| 310 | * +8: MTRR base 0 63:32 |
| 311 | * +12: MTRR mask 0 31:0 |
| 312 | * +16: MTRR mask 0 63:32 |
| 313 | * +20: MTRR base 1 31:0 |
| 314 | * +24: MTRR base 1 63:32 |
| 315 | * +28: MTRR mask 1 31:0 |
| 316 | * +32: MTRR mask 1 63:32 |
| 317 | */ |
| 318 | |
| 319 | /* Cache the ROM as WP just below 4GiB. */ |
| 320 | slot = stack_push(slot, mtrr_mask_upper); /* upper mask */ |
| 321 | slot = stack_push(slot, ~(CONFIG_ROM_SIZE - 1) | MTRRphysMaskValid); |
| 322 | slot = stack_push(slot, 0); /* upper base */ |
| 323 | slot = stack_push(slot, ~(CONFIG_ROM_SIZE - 1) | MTRR_TYPE_WRPROT); |
| 324 | num_mtrrs++; |
| 325 | |
| 326 | /* Cache RAM as WB from 0 -> CONFIG_RAMTOP. */ |
| 327 | slot = stack_push(slot, mtrr_mask_upper); /* upper mask */ |
| 328 | slot = stack_push(slot, ~(CONFIG_RAMTOP - 1) | MTRRphysMaskValid); |
| 329 | slot = stack_push(slot, 0); /* upper base */ |
| 330 | slot = stack_push(slot, 0 | MTRR_TYPE_WRBACK); |
| 331 | num_mtrrs++; |
| 332 | |
| 333 | top_of_ram = (uint32_t)cbmem_top(); |
| 334 | /* Cache 8MiB below the top of ram. The top of ram under 4GiB is the |
| 335 | * start of the TSEG region. It is required to be 8MiB aligned. Set |
| 336 | * this area as cacheable so it can be used later for ramstage before |
| 337 | * setting up the entire RAM as cacheable. */ |
| 338 | slot = stack_push(slot, mtrr_mask_upper); /* upper mask */ |
| 339 | slot = stack_push(slot, ~((8 << 20) - 1) | MTRRphysMaskValid); |
| 340 | slot = stack_push(slot, 0); /* upper base */ |
| 341 | slot = stack_push(slot, (top_of_ram - (8 << 20)) | MTRR_TYPE_WRBACK); |
| 342 | num_mtrrs++; |
| 343 | |
| 344 | /* Cache 8MiB at the top of ram. Top of ram is where the TSEG |
| 345 | * region resides. However, it is not restricted to SMM mode until |
| 346 | * SMM has been relocated. By setting the region to cacheable it |
| 347 | * provides faster access when relocating the SMM handler as well |
| 348 | * as using the TSEG region for other purposes. */ |
| 349 | slot = stack_push(slot, mtrr_mask_upper); /* upper mask */ |
| 350 | slot = stack_push(slot, ~((8 << 20) - 1) | MTRRphysMaskValid); |
| 351 | slot = stack_push(slot, 0); /* upper base */ |
| 352 | slot = stack_push(slot, top_of_ram | MTRR_TYPE_WRBACK); |
| 353 | num_mtrrs++; |
| 354 | |
| 355 | /* Save the number of MTRRs to setup. Return the stack location |
| 356 | * pointing to the number of MTRRs. */ |
| 357 | slot = stack_push(slot, num_mtrrs); |
| 358 | |
| 359 | return slot; |
| 360 | } |
Aaron Durbin | dc249f6 | 2013-10-10 21:03:50 -0500 | [diff] [blame] | 361 | |
Aaron Durbin | dc249f6 | 2013-10-10 21:03:50 -0500 | [diff] [blame] | 362 | void ramstage_cache_invalid(struct ramstage_cache *cache) |
| 363 | { |
| 364 | #if CONFIG_RESET_ON_INVALID_RAMSTAGE_CACHE |
| 365 | /* Perform cold reset on invalid ramstage cache. */ |
| 366 | cold_reset(); |
| 367 | #endif |
| 368 | } |
Shawn Nematbakhsh | 565d409 | 2014-03-14 14:06:45 -0700 | [diff] [blame] | 369 | |
| 370 | #if CONFIG_CHROMEOS |
| 371 | int vboot_get_sw_write_protect(void) |
| 372 | { |
| 373 | u8 status; |
| 374 | /* Return unprotected status if status read fails. */ |
| 375 | return (early_spi_read_wpsr(&status) ? 0 : !!(status & 0x80)); |
| 376 | } |
| 377 | #endif |