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 | 65e5466 | 2017-09-01 07:10:56 +0300 | [diff] [blame] | 18 | #include <arch/symbols.h> |
Elyes HAOUAS | d26844c | 2019-06-21 07:31:40 +0200 | [diff] [blame] | 19 | #include <commonlib/helpers.h> |
Kyösti Mälkki | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame] | 20 | #include <program_loading.h> |
Arthur Heymans | 4513020 | 2019-01-04 14:23:54 +0100 | [diff] [blame] | 21 | #include <timestamp.h> |
Kyösti Mälkki | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame] | 22 | |
Kyösti Mälkki | dfb2de8 | 2016-11-19 16:39:21 +0200 | [diff] [blame] | 23 | #define DCACHE_RAM_ROMSTAGE_STACK_SIZE 0x2000 |
Kyösti Mälkki | e325b22 | 2016-06-17 11:04:37 +0300 | [diff] [blame] | 24 | |
Kyösti Mälkki | 5bc641a | 2019-08-09 09:37:49 +0300 | [diff] [blame^] | 25 | static struct postcar_frame early_mtrrs; |
| 26 | |
| 27 | /* prepare_and_run_postcar() determines the stack to use after |
| 28 | * cache-as-ram is torn down as well as the MTRR settings to use. */ |
| 29 | static void prepare_and_run_postcar(struct postcar_frame *pcf) |
| 30 | { |
| 31 | if (postcar_frame_init(pcf, 0)) |
| 32 | die("Unable to initialize postcar frame.\n"); |
| 33 | |
| 34 | fill_postcar_frame(pcf); |
| 35 | |
| 36 | run_postcar_phase(pcf); |
| 37 | /* We do not return here. */ |
| 38 | } |
| 39 | |
Kyösti Mälkki | c641f7e | 2018-12-28 16:54:54 +0200 | [diff] [blame] | 40 | static void romstage_main(unsigned long bist) |
Kyösti Mälkki | e325b22 | 2016-06-17 11:04:37 +0300 | [diff] [blame] | 41 | { |
Kyösti Mälkki | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame] | 42 | int i; |
Kyösti Mälkki | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame] | 43 | const int num_guards = 4; |
| 44 | const u32 stack_guard = 0xdeadbeef; |
Kyösti Mälkki | 65e5466 | 2017-09-01 07:10:56 +0300 | [diff] [blame] | 45 | u32 *stack_base; |
| 46 | u32 size; |
| 47 | |
| 48 | /* Size of unallocated CAR. */ |
Kyösti Mälkki | d7892bc | 2018-12-28 19:18:46 +0200 | [diff] [blame] | 49 | size = ALIGN_DOWN(_car_stack_size, 16); |
Kyösti Mälkki | 65e5466 | 2017-09-01 07:10:56 +0300 | [diff] [blame] | 50 | |
| 51 | size = MIN(size, DCACHE_RAM_ROMSTAGE_STACK_SIZE); |
| 52 | if (size < DCACHE_RAM_ROMSTAGE_STACK_SIZE) |
| 53 | printk(BIOS_DEBUG, "Romstage stack size limited to 0x%x!\n", |
| 54 | size); |
| 55 | |
Kyösti Mälkki | d7892bc | 2018-12-28 19:18:46 +0200 | [diff] [blame] | 56 | stack_base = (u32 *) (_car_stack_end - size); |
Kyösti Mälkki | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame] | 57 | |
| 58 | for (i = 0; i < num_guards; i++) |
| 59 | stack_base[i] = stack_guard; |
| 60 | |
Kyösti Mälkki | e325b22 | 2016-06-17 11:04:37 +0300 | [diff] [blame] | 61 | mainboard_romstage_entry(bist); |
Kyösti Mälkki | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame] | 62 | |
| 63 | /* Check the stack. */ |
| 64 | for (i = 0; i < num_guards; i++) { |
| 65 | if (stack_base[i] == stack_guard) |
| 66 | continue; |
| 67 | printk(BIOS_DEBUG, "Smashed stack detected in romstage!\n"); |
| 68 | } |
| 69 | |
Kyösti Mälkki | 5bc641a | 2019-08-09 09:37:49 +0300 | [diff] [blame^] | 70 | prepare_and_run_postcar(&early_mtrrs); |
| 71 | /* We do not return here. */ |
Kyösti Mälkki | c641f7e | 2018-12-28 16:54:54 +0200 | [diff] [blame] | 72 | } |
Kyösti Mälkki | 6a8ce0d | 2018-05-17 17:22:51 +0300 | [diff] [blame] | 73 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 74 | #if !CONFIG(C_ENVIRONMENT_BOOTBLOCK) |
Kyösti Mälkki | c641f7e | 2018-12-28 16:54:54 +0200 | [diff] [blame] | 75 | /* This wrapper enables easy transition towards C_ENVIRONMENT_BOOTBLOCK, |
| 76 | * keeping changes in cache_as_ram.S easy to manage. |
| 77 | */ |
| 78 | asmlinkage void bootblock_c_entry_bist(uint64_t base_timestamp, uint32_t bist) |
| 79 | { |
Arthur Heymans | 4513020 | 2019-01-04 14:23:54 +0100 | [diff] [blame] | 80 | timestamp_init(base_timestamp); |
| 81 | timestamp_add_now(TS_START_ROMSTAGE); |
Kyösti Mälkki | c641f7e | 2018-12-28 16:54:54 +0200 | [diff] [blame] | 82 | romstage_main(bist); |
Kyösti Mälkki | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame] | 83 | } |
Arthur Heymans | d3d82e0 | 2018-06-05 11:19:22 +0200 | [diff] [blame] | 84 | #endif |
| 85 | |
| 86 | |
| 87 | /* We don't carry BIST from bootblock in a good location to read from. |
| 88 | * Any error should have been reported in bootblock already. |
| 89 | */ |
| 90 | #define NO_BIST 0 |
| 91 | |
| 92 | asmlinkage void car_stage_entry(void) |
| 93 | { |
| 94 | /* Assumes the hardware was set up during the bootblock */ |
| 95 | console_init(); |
| 96 | |
| 97 | romstage_main(NO_BIST); |
| 98 | } |