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 | |
| 14 | #include <arch/cpu.h> |
| 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> |
| 20 | |
Kyösti Mälkki | dfb2de8 | 2016-11-19 16:39:21 +0200 | [diff] [blame] | 21 | #define DCACHE_RAM_ROMSTAGE_STACK_SIZE 0x2000 |
Kyösti Mälkki | e325b22 | 2016-06-17 11:04:37 +0300 | [diff] [blame] | 22 | |
Lee Leahy | 9d62e7e | 2017-03-15 17:40:50 -0700 | [diff] [blame] | 23 | asmlinkage void *romstage_main(unsigned long bist) |
Kyösti Mälkki | e325b22 | 2016-06-17 11:04:37 +0300 | [diff] [blame] | 24 | { |
Kyösti Mälkki | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame] | 25 | int i; |
| 26 | void *romstage_stack_after_car; |
| 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. */ |
| 33 | size = _car_region_end - _car_relocatable_data_end; |
| 34 | size = ALIGN_DOWN(size, 16); |
| 35 | |
| 36 | size = MIN(size, DCACHE_RAM_ROMSTAGE_STACK_SIZE); |
| 37 | if (size < DCACHE_RAM_ROMSTAGE_STACK_SIZE) |
| 38 | printk(BIOS_DEBUG, "Romstage stack size limited to 0x%x!\n", |
| 39 | size); |
| 40 | |
| 41 | stack_base = (u32 *) (_car_region_end - size); |
Kyösti Mälkki | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame] | 42 | |
| 43 | for (i = 0; i < num_guards; i++) |
| 44 | stack_base[i] = stack_guard; |
| 45 | |
Kyösti Mälkki | e325b22 | 2016-06-17 11:04:37 +0300 | [diff] [blame] | 46 | mainboard_romstage_entry(bist); |
Kyösti Mälkki | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame] | 47 | |
| 48 | /* Check the stack. */ |
| 49 | for (i = 0; i < num_guards; i++) { |
| 50 | if (stack_base[i] == stack_guard) |
| 51 | continue; |
| 52 | printk(BIOS_DEBUG, "Smashed stack detected in romstage!\n"); |
| 53 | } |
| 54 | |
| 55 | /* Get the stack to use after cache-as-ram is torn down. */ |
Kyösti Mälkki | 823020d | 2016-07-22 22:53:19 +0300 | [diff] [blame] | 56 | romstage_stack_after_car = setup_stack_and_mtrrs(); |
Kyösti Mälkki | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame] | 57 | |
| 58 | return romstage_stack_after_car; |
| 59 | } |
| 60 | |
Lee Leahy | 9d62e7e | 2017-03-15 17:40:50 -0700 | [diff] [blame] | 61 | asmlinkage void romstage_after_car(void) |
Kyösti Mälkki | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame] | 62 | { |
| 63 | /* Load the ramstage. */ |
| 64 | run_ramstage(); |
Kyösti Mälkki | e325b22 | 2016-06-17 11:04:37 +0300 | [diff] [blame] | 65 | } |
Kyösti Mälkki | 823020d | 2016-07-22 22:53:19 +0300 | [diff] [blame] | 66 | |
| 67 | #if IS_ENABLED(CONFIG_LATE_CBMEM_INIT) |
| 68 | /* setup_stack_and_mtrrs() determines the stack to use after |
| 69 | * cache-as-ram is torn down as well as the MTRR settings to use. */ |
| 70 | void *setup_stack_and_mtrrs(void) |
| 71 | { |
| 72 | struct postcar_frame pcf; |
| 73 | |
| 74 | postcar_frame_init_lowmem(&pcf); |
| 75 | |
| 76 | /* Cache the ROM as WP just below 4GiB. */ |
Nico Huber | 654cc2f | 2018-05-27 13:52:28 +0200 | [diff] [blame] | 77 | postcar_frame_add_mtrr(&pcf, CACHE_ROM_BASE, CACHE_ROM_SIZE, |
Kyösti Mälkki | 823020d | 2016-07-22 22:53:19 +0300 | [diff] [blame] | 78 | MTRR_TYPE_WRPROT); |
| 79 | |
| 80 | /* Cache RAM as WB from 0 -> CACHE_TMP_RAMTOP. */ |
| 81 | postcar_frame_add_mtrr(&pcf, 0, CACHE_TMP_RAMTOP, MTRR_TYPE_WRBACK); |
| 82 | |
| 83 | /* Save the number of MTRRs to setup. Return the stack location |
| 84 | * pointing to the number of MTRRs. |
| 85 | */ |
| 86 | return postcar_commit_mtrrs(&pcf); |
| 87 | } |
| 88 | #endif /* CONFIG_LATE_CBMEM_INIT */ |