blob: 264ad4ab7facfa4b4fbfbf2533a0232246610d39 [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>
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030019#include <program_loading.h>
Arthur Heymans45130202019-01-04 14:23:54 +010020#include <timestamp.h>
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030021
Kyösti Mälkkidfb2de82016-11-19 16:39:21 +020022#define DCACHE_RAM_ROMSTAGE_STACK_SIZE 0x2000
Kyösti Mälkkie325b222016-06-17 11:04:37 +030023
Kyösti Mälkkic641f7e2018-12-28 16:54:54 +020024static void romstage_main(unsigned long bist)
Kyösti Mälkkie325b222016-06-17 11:04:37 +030025{
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030026 int i;
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030027 const int num_guards = 4;
28 const u32 stack_guard = 0xdeadbeef;
Kyösti Mälkki65e54662017-09-01 07:10:56 +030029 u32 *stack_base;
30 u32 size;
31
32 /* Size of unallocated CAR. */
Kyösti Mälkkid7892bc2018-12-28 19:18:46 +020033 size = ALIGN_DOWN(_car_stack_size, 16);
Kyösti Mälkki65e54662017-09-01 07:10:56 +030034
35 size = MIN(size, DCACHE_RAM_ROMSTAGE_STACK_SIZE);
36 if (size < DCACHE_RAM_ROMSTAGE_STACK_SIZE)
37 printk(BIOS_DEBUG, "Romstage stack size limited to 0x%x!\n",
38 size);
39
Kyösti Mälkkid7892bc2018-12-28 19:18:46 +020040 stack_base = (u32 *) (_car_stack_end - size);
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030041
42 for (i = 0; i < num_guards; i++)
43 stack_base[i] = stack_guard;
44
Kyösti Mälkkie325b222016-06-17 11:04:37 +030045 mainboard_romstage_entry(bist);
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030046
47 /* Check the stack. */
48 for (i = 0; i < num_guards; i++) {
49 if (stack_base[i] == stack_guard)
50 continue;
51 printk(BIOS_DEBUG, "Smashed stack detected in romstage!\n");
52 }
53
Kyösti Mälkki6a8ce0d2018-05-17 17:22:51 +030054 platform_enter_postcar();
Kyösti Mälkkic641f7e2018-12-28 16:54:54 +020055}
Kyösti Mälkki6a8ce0d2018-05-17 17:22:51 +030056
Arthur Heymansd3d82e02018-06-05 11:19:22 +020057#if !IS_ENABLED(CONFIG_C_ENVIRONMENT_BOOTBLOCK)
Kyösti Mälkkic641f7e2018-12-28 16:54:54 +020058/* This wrapper enables easy transition towards C_ENVIRONMENT_BOOTBLOCK,
59 * keeping changes in cache_as_ram.S easy to manage.
60 */
61asmlinkage void bootblock_c_entry_bist(uint64_t base_timestamp, uint32_t bist)
62{
Arthur Heymans45130202019-01-04 14:23:54 +010063 timestamp_init(base_timestamp);
64 timestamp_add_now(TS_START_ROMSTAGE);
Kyösti Mälkkic641f7e2018-12-28 16:54:54 +020065 romstage_main(bist);
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030066}
Arthur Heymansd3d82e02018-06-05 11:19:22 +020067#endif
68
69
70/* We don't carry BIST from bootblock in a good location to read from.
71 * Any error should have been reported in bootblock already.
72 */
73#define NO_BIST 0
74
75asmlinkage void car_stage_entry(void)
76{
77 /* Assumes the hardware was set up during the bootblock */
78 console_init();
79
80 romstage_main(NO_BIST);
81}