blob: a0dc7438060d955f5683714190a434abb3c11e20 [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älkkia963acd2019-08-16 20:34:25 +030014#include <arch/cpu.h>
15#include <arch/romstage.h>
Kyösti Mälkkic641f7e2018-12-28 16:54:54 +020016#include <bootblock_common.h>
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030017#include <console/console.h>
Kyösti Mälkkie325b222016-06-17 11:04:37 +030018#include <cpu/intel/romstage.h>
Kyösti Mälkki823020d2016-07-22 22:53:19 +030019#include <cpu/x86/mtrr.h>
Kyösti Mälkki7cdb0472019-08-08 11:16:06 +030020#include <cpu/x86/smm.h>
Kyösti Mälkki65e54662017-09-01 07:10:56 +030021#include <arch/symbols.h>
Elyes HAOUASd26844c2019-06-21 07:31:40 +020022#include <commonlib/helpers.h>
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030023#include <program_loading.h>
Arthur Heymans45130202019-01-04 14:23:54 +010024#include <timestamp.h>
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030025
Arthur Heymans4c095fc2019-08-18 08:40:56 +020026/* If we do not have a constrained _car_stack region size, use the
27 following as a guideline for acceptable stack usage. */
Kyösti Mälkkidfb2de82016-11-19 16:39:21 +020028#define DCACHE_RAM_ROMSTAGE_STACK_SIZE 0x2000
Kyösti Mälkkie325b222016-06-17 11:04:37 +030029
Kyösti Mälkki5bc641a2019-08-09 09:37:49 +030030static struct postcar_frame early_mtrrs;
31
32/* prepare_and_run_postcar() determines the stack to use after
33 * cache-as-ram is torn down as well as the MTRR settings to use. */
34static void prepare_and_run_postcar(struct postcar_frame *pcf)
35{
36 if (postcar_frame_init(pcf, 0))
37 die("Unable to initialize postcar frame.\n");
38
39 fill_postcar_frame(pcf);
40
Kyösti Mälkki544878b2019-08-09 11:41:15 +030041 postcar_frame_common_mtrrs(pcf);
42
Kyösti Mälkki5bc641a2019-08-09 09:37:49 +030043 run_postcar_phase(pcf);
44 /* We do not return here. */
45}
46
Kyösti Mälkkic641f7e2018-12-28 16:54:54 +020047static void romstage_main(unsigned long bist)
Kyösti Mälkkie325b222016-06-17 11:04:37 +030048{
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030049 int i;
Arthur Heymans4c095fc2019-08-18 08:40:56 +020050 const int num_guards = 64;
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030051 const u32 stack_guard = 0xdeadbeef;
Kyösti Mälkki65e54662017-09-01 07:10:56 +030052 u32 *stack_base;
53 u32 size;
Arthur Heymans4c095fc2019-08-18 08:40:56 +020054 const size_t stack_size = MAX(CONFIG_DCACHE_BSP_STACK_SIZE,
55 DCACHE_RAM_ROMSTAGE_STACK_SIZE);
Kyösti Mälkki65e54662017-09-01 07:10:56 +030056
57 /* Size of unallocated CAR. */
Kyösti Mälkkid7892bc2018-12-28 19:18:46 +020058 size = ALIGN_DOWN(_car_stack_size, 16);
Kyösti Mälkki65e54662017-09-01 07:10:56 +030059
Arthur Heymans4c095fc2019-08-18 08:40:56 +020060 size = MIN(size, stack_size);
61 if (size < stack_size)
Kyösti Mälkki65e54662017-09-01 07:10:56 +030062 printk(BIOS_DEBUG, "Romstage stack size limited to 0x%x!\n",
63 size);
64
Kyösti Mälkkid7892bc2018-12-28 19:18:46 +020065 stack_base = (u32 *) (_car_stack_end - size);
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030066
67 for (i = 0; i < num_guards; i++)
68 stack_base[i] = stack_guard;
69
Kyösti Mälkki157b1892019-08-16 14:02:25 +030070 mainboard_romstage_entry();
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030071
72 /* Check the stack. */
73 for (i = 0; i < num_guards; i++) {
74 if (stack_base[i] == stack_guard)
75 continue;
76 printk(BIOS_DEBUG, "Smashed stack detected in romstage!\n");
77 }
78
Kyösti Mälkki7cdb0472019-08-08 11:16:06 +030079 if (CONFIG(SMM_TSEG))
80 smm_list_regions();
81
Kyösti Mälkki5bc641a2019-08-09 09:37:49 +030082 prepare_and_run_postcar(&early_mtrrs);
83 /* We do not return here. */
Kyösti Mälkkic641f7e2018-12-28 16:54:54 +020084}
Kyösti Mälkki6a8ce0d2018-05-17 17:22:51 +030085
Julius Wernercd49cce2019-03-05 16:53:33 -080086#if !CONFIG(C_ENVIRONMENT_BOOTBLOCK)
Kyösti Mälkkic641f7e2018-12-28 16:54:54 +020087/* This wrapper enables easy transition towards C_ENVIRONMENT_BOOTBLOCK,
88 * keeping changes in cache_as_ram.S easy to manage.
89 */
90asmlinkage void bootblock_c_entry_bist(uint64_t base_timestamp, uint32_t bist)
91{
Arthur Heymans45130202019-01-04 14:23:54 +010092 timestamp_init(base_timestamp);
93 timestamp_add_now(TS_START_ROMSTAGE);
Kyösti Mälkkic641f7e2018-12-28 16:54:54 +020094 romstage_main(bist);
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030095}
Arthur Heymansd3d82e02018-06-05 11:19:22 +020096#endif
97
98
99/* We don't carry BIST from bootblock in a good location to read from.
100 * Any error should have been reported in bootblock already.
101 */
102#define NO_BIST 0
103
104asmlinkage void car_stage_entry(void)
105{
106 /* Assumes the hardware was set up during the bootblock */
107 console_init();
108
109 romstage_main(NO_BIST);
110}