blob: f6b62192f1b22fc1596d64bd2db826759066ad63 [file] [log] [blame]
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +03001/*
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älkkic641f7e2018-12-28 16:54:54 +020014#include <bootblock_common.h>
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030015#include <console/console.h>
Kyösti Mälkkie325b222016-06-17 11:04:37 +030016#include <cpu/intel/romstage.h>
Kyösti Mälkki823020d2016-07-22 22:53:19 +030017#include <cpu/x86/mtrr.h>
Kyösti Mälkki65e54662017-09-01 07:10:56 +030018#include <arch/symbols.h>
Elyes HAOUASd26844c2019-06-21 07:31:40 +020019#include <commonlib/helpers.h>
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030020#include <program_loading.h>
Arthur Heymans45130202019-01-04 14:23:54 +010021#include <timestamp.h>
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030022
Kyösti Mälkkidfb2de82016-11-19 16:39:21 +020023#define DCACHE_RAM_ROMSTAGE_STACK_SIZE 0x2000
Kyösti Mälkkie325b222016-06-17 11:04:37 +030024
Kyösti Mälkki5bc641a2019-08-09 09:37:49 +030025static 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. */
29static 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älkkic641f7e2018-12-28 16:54:54 +020040static void romstage_main(unsigned long bist)
Kyösti Mälkkie325b222016-06-17 11:04:37 +030041{
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030042 int i;
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030043 const int num_guards = 4;
44 const u32 stack_guard = 0xdeadbeef;
Kyösti Mälkki65e54662017-09-01 07:10:56 +030045 u32 *stack_base;
46 u32 size;
47
48 /* Size of unallocated CAR. */
Kyösti Mälkkid7892bc2018-12-28 19:18:46 +020049 size = ALIGN_DOWN(_car_stack_size, 16);
Kyösti Mälkki65e54662017-09-01 07:10:56 +030050
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älkkid7892bc2018-12-28 19:18:46 +020056 stack_base = (u32 *) (_car_stack_end - size);
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030057
58 for (i = 0; i < num_guards; i++)
59 stack_base[i] = stack_guard;
60
Kyösti Mälkkie325b222016-06-17 11:04:37 +030061 mainboard_romstage_entry(bist);
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030062
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älkki5bc641a2019-08-09 09:37:49 +030070 prepare_and_run_postcar(&early_mtrrs);
71 /* We do not return here. */
Kyösti Mälkkic641f7e2018-12-28 16:54:54 +020072}
Kyösti Mälkki6a8ce0d2018-05-17 17:22:51 +030073
Julius Wernercd49cce2019-03-05 16:53:33 -080074#if !CONFIG(C_ENVIRONMENT_BOOTBLOCK)
Kyösti Mälkkic641f7e2018-12-28 16:54:54 +020075/* This wrapper enables easy transition towards C_ENVIRONMENT_BOOTBLOCK,
76 * keeping changes in cache_as_ram.S easy to manage.
77 */
78asmlinkage void bootblock_c_entry_bist(uint64_t base_timestamp, uint32_t bist)
79{
Arthur Heymans45130202019-01-04 14:23:54 +010080 timestamp_init(base_timestamp);
81 timestamp_add_now(TS_START_ROMSTAGE);
Kyösti Mälkkic641f7e2018-12-28 16:54:54 +020082 romstage_main(bist);
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030083}
Arthur Heymansd3d82e02018-06-05 11:19:22 +020084#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
92asmlinkage 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}