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 | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame] | 18 | #include <program_loading.h> |
| 19 | |
Kyösti Mälkki | dfb2de8 | 2016-11-19 16:39:21 +0200 | [diff] [blame] | 20 | #define DCACHE_RAM_ROMSTAGE_STACK_SIZE 0x2000 |
Kyösti Mälkki | e325b22 | 2016-06-17 11:04:37 +0300 | [diff] [blame] | 21 | |
| 22 | void * asmlinkage romstage_main(unsigned long bist) |
| 23 | { |
Kyösti Mälkki | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame] | 24 | int i; |
| 25 | void *romstage_stack_after_car; |
| 26 | const int num_guards = 4; |
| 27 | const u32 stack_guard = 0xdeadbeef; |
| 28 | u32 *stack_base = (void *)(CONFIG_DCACHE_RAM_BASE + |
| 29 | CONFIG_DCACHE_RAM_SIZE - |
| 30 | DCACHE_RAM_ROMSTAGE_STACK_SIZE); |
| 31 | |
| 32 | for (i = 0; i < num_guards; i++) |
| 33 | stack_base[i] = stack_guard; |
| 34 | |
Kyösti Mälkki | e325b22 | 2016-06-17 11:04:37 +0300 | [diff] [blame] | 35 | mainboard_romstage_entry(bist); |
Kyösti Mälkki | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame] | 36 | |
| 37 | /* Check the stack. */ |
| 38 | for (i = 0; i < num_guards; i++) { |
| 39 | if (stack_base[i] == stack_guard) |
| 40 | continue; |
| 41 | printk(BIOS_DEBUG, "Smashed stack detected in romstage!\n"); |
| 42 | } |
| 43 | |
| 44 | /* 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^] | 45 | romstage_stack_after_car = setup_stack_and_mtrrs(); |
Kyösti Mälkki | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame] | 46 | |
| 47 | return romstage_stack_after_car; |
| 48 | } |
| 49 | |
| 50 | void asmlinkage romstage_after_car(void) |
| 51 | { |
| 52 | /* Load the ramstage. */ |
| 53 | run_ramstage(); |
Kyösti Mälkki | e325b22 | 2016-06-17 11:04:37 +0300 | [diff] [blame] | 54 | } |
Kyösti Mälkki | 823020d | 2016-07-22 22:53:19 +0300 | [diff] [blame^] | 55 | |
| 56 | #if IS_ENABLED(CONFIG_LATE_CBMEM_INIT) |
| 57 | /* setup_stack_and_mtrrs() determines the stack to use after |
| 58 | * cache-as-ram is torn down as well as the MTRR settings to use. */ |
| 59 | void *setup_stack_and_mtrrs(void) |
| 60 | { |
| 61 | struct postcar_frame pcf; |
| 62 | |
| 63 | postcar_frame_init_lowmem(&pcf); |
| 64 | |
| 65 | /* Cache the ROM as WP just below 4GiB. */ |
| 66 | postcar_frame_add_mtrr(&pcf, -CACHE_ROM_SIZE, CACHE_ROM_SIZE, |
| 67 | MTRR_TYPE_WRPROT); |
| 68 | |
| 69 | /* Cache RAM as WB from 0 -> CACHE_TMP_RAMTOP. */ |
| 70 | postcar_frame_add_mtrr(&pcf, 0, CACHE_TMP_RAMTOP, MTRR_TYPE_WRBACK); |
| 71 | |
| 72 | /* Save the number of MTRRs to setup. Return the stack location |
| 73 | * pointing to the number of MTRRs. |
| 74 | */ |
| 75 | return postcar_commit_mtrrs(&pcf); |
| 76 | } |
| 77 | #endif /* CONFIG_LATE_CBMEM_INIT */ |