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