Kyösti Mälkki | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; version 2 of the License. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | |
Kyösti Mälkki | c641f7e | 2018-12-28 16:54:54 +0200 | [diff] [blame] | 14 | #include <bootblock_common.h> |
Kyösti Mälkki | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame] | 15 | #include <console/console.h> |
Kyösti Mälkki | e325b22 | 2016-06-17 11:04:37 +0300 | [diff] [blame] | 16 | #include <cpu/intel/romstage.h> |
Kyösti Mälkki | 823020d | 2016-07-22 22:53:19 +0300 | [diff] [blame] | 17 | #include <cpu/x86/mtrr.h> |
Kyösti Mälkki | 7cdb047 | 2019-08-08 11:16:06 +0300 | [diff] [blame] | 18 | #include <cpu/x86/smm.h> |
Kyösti Mälkki | 65e5466 | 2017-09-01 07:10:56 +0300 | [diff] [blame] | 19 | #include <arch/symbols.h> |
Elyes HAOUAS | d26844c | 2019-06-21 07:31:40 +0200 | [diff] [blame] | 20 | #include <commonlib/helpers.h> |
Kyösti Mälkki | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame] | 21 | #include <program_loading.h> |
Arthur Heymans | 4513020 | 2019-01-04 14:23:54 +0100 | [diff] [blame] | 22 | #include <timestamp.h> |
Kyösti Mälkki | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame] | 23 | |
Arthur Heymans | 4c095fc | 2019-08-18 08:40:56 +0200 | [diff] [blame] | 24 | /* If we do not have a constrained _car_stack region size, use the |
| 25 | following as a guideline for acceptable stack usage. */ |
Kyösti Mälkki | dfb2de8 | 2016-11-19 16:39:21 +0200 | [diff] [blame] | 26 | #define DCACHE_RAM_ROMSTAGE_STACK_SIZE 0x2000 |
Kyösti Mälkki | e325b22 | 2016-06-17 11:04:37 +0300 | [diff] [blame] | 27 | |
Kyösti Mälkki | 5bc641a | 2019-08-09 09:37:49 +0300 | [diff] [blame] | 28 | static struct postcar_frame early_mtrrs; |
| 29 | |
| 30 | /* prepare_and_run_postcar() determines the stack to use after |
| 31 | * cache-as-ram is torn down as well as the MTRR settings to use. */ |
| 32 | static void prepare_and_run_postcar(struct postcar_frame *pcf) |
| 33 | { |
| 34 | if (postcar_frame_init(pcf, 0)) |
| 35 | die("Unable to initialize postcar frame.\n"); |
| 36 | |
| 37 | fill_postcar_frame(pcf); |
| 38 | |
Kyösti Mälkki | 544878b | 2019-08-09 11:41:15 +0300 | [diff] [blame] | 39 | postcar_frame_common_mtrrs(pcf); |
| 40 | |
Kyösti Mälkki | 5bc641a | 2019-08-09 09:37:49 +0300 | [diff] [blame] | 41 | run_postcar_phase(pcf); |
| 42 | /* We do not return here. */ |
| 43 | } |
| 44 | |
Kyösti Mälkki | c641f7e | 2018-12-28 16:54:54 +0200 | [diff] [blame] | 45 | static void romstage_main(unsigned long bist) |
Kyösti Mälkki | e325b22 | 2016-06-17 11:04:37 +0300 | [diff] [blame] | 46 | { |
Kyösti Mälkki | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame] | 47 | int i; |
Arthur Heymans | 4c095fc | 2019-08-18 08:40:56 +0200 | [diff] [blame] | 48 | const int num_guards = 64; |
Kyösti Mälkki | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame] | 49 | const u32 stack_guard = 0xdeadbeef; |
Kyösti Mälkki | 65e5466 | 2017-09-01 07:10:56 +0300 | [diff] [blame] | 50 | u32 *stack_base; |
| 51 | u32 size; |
Arthur Heymans | 4c095fc | 2019-08-18 08:40:56 +0200 | [diff] [blame] | 52 | const size_t stack_size = MAX(CONFIG_DCACHE_BSP_STACK_SIZE, |
| 53 | DCACHE_RAM_ROMSTAGE_STACK_SIZE); |
Kyösti Mälkki | 65e5466 | 2017-09-01 07:10:56 +0300 | [diff] [blame] | 54 | |
| 55 | /* Size of unallocated CAR. */ |
Kyösti Mälkki | d7892bc | 2018-12-28 19:18:46 +0200 | [diff] [blame] | 56 | size = ALIGN_DOWN(_car_stack_size, 16); |
Kyösti Mälkki | 65e5466 | 2017-09-01 07:10:56 +0300 | [diff] [blame] | 57 | |
Arthur Heymans | 4c095fc | 2019-08-18 08:40:56 +0200 | [diff] [blame] | 58 | size = MIN(size, stack_size); |
| 59 | if (size < stack_size) |
Kyösti Mälkki | 65e5466 | 2017-09-01 07:10:56 +0300 | [diff] [blame] | 60 | printk(BIOS_DEBUG, "Romstage stack size limited to 0x%x!\n", |
| 61 | size); |
| 62 | |
Kyösti Mälkki | d7892bc | 2018-12-28 19:18:46 +0200 | [diff] [blame] | 63 | stack_base = (u32 *) (_car_stack_end - size); |
Kyösti Mälkki | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame] | 64 | |
| 65 | for (i = 0; i < num_guards; i++) |
| 66 | stack_base[i] = stack_guard; |
| 67 | |
Kyösti Mälkki | 157b189 | 2019-08-16 14:02:25 +0300 | [diff] [blame] | 68 | mainboard_romstage_entry(); |
Kyösti Mälkki | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame] | 69 | |
| 70 | /* Check the stack. */ |
| 71 | for (i = 0; i < num_guards; i++) { |
| 72 | if (stack_base[i] == stack_guard) |
| 73 | continue; |
| 74 | printk(BIOS_DEBUG, "Smashed stack detected in romstage!\n"); |
| 75 | } |
| 76 | |
Kyösti Mälkki | 7cdb047 | 2019-08-08 11:16:06 +0300 | [diff] [blame] | 77 | if (CONFIG(SMM_TSEG)) |
| 78 | smm_list_regions(); |
| 79 | |
Kyösti Mälkki | 5bc641a | 2019-08-09 09:37:49 +0300 | [diff] [blame] | 80 | prepare_and_run_postcar(&early_mtrrs); |
| 81 | /* We do not return here. */ |
Kyösti Mälkki | c641f7e | 2018-12-28 16:54:54 +0200 | [diff] [blame] | 82 | } |
Kyösti Mälkki | 6a8ce0d | 2018-05-17 17:22:51 +0300 | [diff] [blame] | 83 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 84 | #if !CONFIG(C_ENVIRONMENT_BOOTBLOCK) |
Kyösti Mälkki | c641f7e | 2018-12-28 16:54:54 +0200 | [diff] [blame] | 85 | /* This wrapper enables easy transition towards C_ENVIRONMENT_BOOTBLOCK, |
| 86 | * keeping changes in cache_as_ram.S easy to manage. |
| 87 | */ |
| 88 | asmlinkage void bootblock_c_entry_bist(uint64_t base_timestamp, uint32_t bist) |
| 89 | { |
Arthur Heymans | 4513020 | 2019-01-04 14:23:54 +0100 | [diff] [blame] | 90 | timestamp_init(base_timestamp); |
| 91 | timestamp_add_now(TS_START_ROMSTAGE); |
Kyösti Mälkki | c641f7e | 2018-12-28 16:54:54 +0200 | [diff] [blame] | 92 | romstage_main(bist); |
Kyösti Mälkki | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame] | 93 | } |
Arthur Heymans | d3d82e0 | 2018-06-05 11:19:22 +0200 | [diff] [blame] | 94 | #endif |
| 95 | |
| 96 | |
| 97 | /* We don't carry BIST from bootblock in a good location to read from. |
| 98 | * Any error should have been reported in bootblock already. |
| 99 | */ |
| 100 | #define NO_BIST 0 |
| 101 | |
| 102 | asmlinkage void car_stage_entry(void) |
| 103 | { |
| 104 | /* Assumes the hardware was set up during the bootblock */ |
| 105 | console_init(); |
| 106 | |
| 107 | romstage_main(NO_BIST); |
| 108 | } |