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> |
Kyösti Mälkki | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame] | 19 | #include <program_loading.h> |
Arthur Heymans | 4513020 | 2019-01-04 14:23:54 +0100 | [diff] [blame] | 20 | #include <timestamp.h> |
Kyösti Mälkki | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame] | 21 | |
Kyösti Mälkki | dfb2de8 | 2016-11-19 16:39:21 +0200 | [diff] [blame] | 22 | #define DCACHE_RAM_ROMSTAGE_STACK_SIZE 0x2000 |
Kyösti Mälkki | e325b22 | 2016-06-17 11:04:37 +0300 | [diff] [blame] | 23 | |
Kyösti Mälkki | c641f7e | 2018-12-28 16:54:54 +0200 | [diff] [blame] | 24 | static void romstage_main(unsigned long bist) |
Kyösti Mälkki | e325b22 | 2016-06-17 11:04:37 +0300 | [diff] [blame] | 25 | { |
Kyösti Mälkki | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame] | 26 | int i; |
Kyösti Mälkki | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame] | 27 | const int num_guards = 4; |
| 28 | const u32 stack_guard = 0xdeadbeef; |
Kyösti Mälkki | 65e5466 | 2017-09-01 07:10:56 +0300 | [diff] [blame] | 29 | u32 *stack_base; |
| 30 | u32 size; |
| 31 | |
| 32 | /* Size of unallocated CAR. */ |
Kyösti Mälkki | d7892bc | 2018-12-28 19:18:46 +0200 | [diff] [blame] | 33 | size = ALIGN_DOWN(_car_stack_size, 16); |
Kyösti Mälkki | 65e5466 | 2017-09-01 07:10:56 +0300 | [diff] [blame] | 34 | |
| 35 | size = MIN(size, DCACHE_RAM_ROMSTAGE_STACK_SIZE); |
| 36 | if (size < DCACHE_RAM_ROMSTAGE_STACK_SIZE) |
| 37 | printk(BIOS_DEBUG, "Romstage stack size limited to 0x%x!\n", |
| 38 | size); |
| 39 | |
Kyösti Mälkki | d7892bc | 2018-12-28 19:18:46 +0200 | [diff] [blame] | 40 | stack_base = (u32 *) (_car_stack_end - size); |
Kyösti Mälkki | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame] | 41 | |
| 42 | for (i = 0; i < num_guards; i++) |
| 43 | stack_base[i] = stack_guard; |
| 44 | |
Kyösti Mälkki | e325b22 | 2016-06-17 11:04:37 +0300 | [diff] [blame] | 45 | mainboard_romstage_entry(bist); |
Kyösti Mälkki | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame] | 46 | |
| 47 | /* Check the stack. */ |
| 48 | for (i = 0; i < num_guards; i++) { |
| 49 | if (stack_base[i] == stack_guard) |
| 50 | continue; |
| 51 | printk(BIOS_DEBUG, "Smashed stack detected in romstage!\n"); |
| 52 | } |
| 53 | |
Kyösti Mälkki | 6a8ce0d | 2018-05-17 17:22:51 +0300 | [diff] [blame] | 54 | platform_enter_postcar(); |
Kyösti Mälkki | c641f7e | 2018-12-28 16:54:54 +0200 | [diff] [blame] | 55 | } |
Kyösti Mälkki | 6a8ce0d | 2018-05-17 17:22:51 +0300 | [diff] [blame] | 56 | |
Arthur Heymans | d3d82e0 | 2018-06-05 11:19:22 +0200 | [diff] [blame] | 57 | #if !IS_ENABLED(CONFIG_C_ENVIRONMENT_BOOTBLOCK) |
Kyösti Mälkki | c641f7e | 2018-12-28 16:54:54 +0200 | [diff] [blame] | 58 | /* This wrapper enables easy transition towards C_ENVIRONMENT_BOOTBLOCK, |
| 59 | * keeping changes in cache_as_ram.S easy to manage. |
| 60 | */ |
| 61 | asmlinkage void bootblock_c_entry_bist(uint64_t base_timestamp, uint32_t bist) |
| 62 | { |
Arthur Heymans | 4513020 | 2019-01-04 14:23:54 +0100 | [diff] [blame] | 63 | timestamp_init(base_timestamp); |
| 64 | timestamp_add_now(TS_START_ROMSTAGE); |
Kyösti Mälkki | c641f7e | 2018-12-28 16:54:54 +0200 | [diff] [blame] | 65 | romstage_main(bist); |
Kyösti Mälkki | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame] | 66 | } |
Arthur Heymans | d3d82e0 | 2018-06-05 11:19:22 +0200 | [diff] [blame] | 67 | #endif |
| 68 | |
| 69 | |
| 70 | /* We don't carry BIST from bootblock in a good location to read from. |
| 71 | * Any error should have been reported in bootblock already. |
| 72 | */ |
| 73 | #define NO_BIST 0 |
| 74 | |
| 75 | asmlinkage void car_stage_entry(void) |
| 76 | { |
| 77 | /* Assumes the hardware was set up during the bootblock */ |
| 78 | console_init(); |
| 79 | |
| 80 | romstage_main(NO_BIST); |
| 81 | } |