blob: e24225e71eb96d39df2d0de7abff9933fa579be9 [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älkki7cdb0472019-08-08 11:16:06 +030018#include <cpu/x86/smm.h>
Kyösti Mälkki65e54662017-09-01 07:10:56 +030019#include <arch/symbols.h>
Elyes HAOUASd26844c2019-06-21 07:31:40 +020020#include <commonlib/helpers.h>
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030021#include <program_loading.h>
Arthur Heymans45130202019-01-04 14:23:54 +010022#include <timestamp.h>
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030023
Arthur Heymans4c095fc2019-08-18 08:40:56 +020024/* If we do not have a constrained _car_stack region size, use the
25 following as a guideline for acceptable stack usage. */
Kyösti Mälkkidfb2de82016-11-19 16:39:21 +020026#define DCACHE_RAM_ROMSTAGE_STACK_SIZE 0x2000
Kyösti Mälkkie325b222016-06-17 11:04:37 +030027
Kyösti Mälkki5bc641a2019-08-09 09:37:49 +030028static struct postcar_frame early_mtrrs;
29
30/* prepare_and_run_postcar() determines the stack to use after
31 * cache-as-ram is torn down as well as the MTRR settings to use. */
32static void prepare_and_run_postcar(struct postcar_frame *pcf)
33{
34 if (postcar_frame_init(pcf, 0))
35 die("Unable to initialize postcar frame.\n");
36
37 fill_postcar_frame(pcf);
38
Kyösti Mälkki544878b2019-08-09 11:41:15 +030039 postcar_frame_common_mtrrs(pcf);
40
Kyösti Mälkki5bc641a2019-08-09 09:37:49 +030041 run_postcar_phase(pcf);
42 /* We do not return here. */
43}
44
Kyösti Mälkkic641f7e2018-12-28 16:54:54 +020045static void romstage_main(unsigned long bist)
Kyösti Mälkkie325b222016-06-17 11:04:37 +030046{
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030047 int i;
Arthur Heymans4c095fc2019-08-18 08:40:56 +020048 const int num_guards = 64;
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030049 const u32 stack_guard = 0xdeadbeef;
Kyösti Mälkki65e54662017-09-01 07:10:56 +030050 u32 *stack_base;
51 u32 size;
Arthur Heymans4c095fc2019-08-18 08:40:56 +020052 const size_t stack_size = MAX(CONFIG_DCACHE_BSP_STACK_SIZE,
53 DCACHE_RAM_ROMSTAGE_STACK_SIZE);
Kyösti Mälkki65e54662017-09-01 07:10:56 +030054
55 /* Size of unallocated CAR. */
Kyösti Mälkkid7892bc2018-12-28 19:18:46 +020056 size = ALIGN_DOWN(_car_stack_size, 16);
Kyösti Mälkki65e54662017-09-01 07:10:56 +030057
Arthur Heymans4c095fc2019-08-18 08:40:56 +020058 size = MIN(size, stack_size);
59 if (size < stack_size)
Kyösti Mälkki65e54662017-09-01 07:10:56 +030060 printk(BIOS_DEBUG, "Romstage stack size limited to 0x%x!\n",
61 size);
62
Kyösti Mälkkid7892bc2018-12-28 19:18:46 +020063 stack_base = (u32 *) (_car_stack_end - size);
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030064
65 for (i = 0; i < num_guards; i++)
66 stack_base[i] = stack_guard;
67
Kyösti Mälkki157b1892019-08-16 14:02:25 +030068 mainboard_romstage_entry();
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030069
70 /* Check the stack. */
71 for (i = 0; i < num_guards; i++) {
72 if (stack_base[i] == stack_guard)
73 continue;
74 printk(BIOS_DEBUG, "Smashed stack detected in romstage!\n");
75 }
76
Kyösti Mälkki7cdb0472019-08-08 11:16:06 +030077 if (CONFIG(SMM_TSEG))
78 smm_list_regions();
79
Kyösti Mälkki5bc641a2019-08-09 09:37:49 +030080 prepare_and_run_postcar(&early_mtrrs);
81 /* We do not return here. */
Kyösti Mälkkic641f7e2018-12-28 16:54:54 +020082}
Kyösti Mälkki6a8ce0d2018-05-17 17:22:51 +030083
Julius Wernercd49cce2019-03-05 16:53:33 -080084#if !CONFIG(C_ENVIRONMENT_BOOTBLOCK)
Kyösti Mälkkic641f7e2018-12-28 16:54:54 +020085/* This wrapper enables easy transition towards C_ENVIRONMENT_BOOTBLOCK,
86 * keeping changes in cache_as_ram.S easy to manage.
87 */
88asmlinkage void bootblock_c_entry_bist(uint64_t base_timestamp, uint32_t bist)
89{
Arthur Heymans45130202019-01-04 14:23:54 +010090 timestamp_init(base_timestamp);
91 timestamp_add_now(TS_START_ROMSTAGE);
Kyösti Mälkkic641f7e2018-12-28 16:54:54 +020092 romstage_main(bist);
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030093}
Arthur Heymansd3d82e02018-06-05 11:19:22 +020094#endif
95
96
97/* We don't carry BIST from bootblock in a good location to read from.
98 * Any error should have been reported in bootblock already.
99 */
100#define NO_BIST 0
101
102asmlinkage void car_stage_entry(void)
103{
104 /* Assumes the hardware was set up during the bootblock */
105 console_init();
106
107 romstage_main(NO_BIST);
108}