blob: 37e39428e25720d4ec85d599ebbdb59c2ac0120f [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
14#include <arch/cpu.h>
15#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>
20
Kyösti Mälkkidfb2de82016-11-19 16:39:21 +020021#define DCACHE_RAM_ROMSTAGE_STACK_SIZE 0x2000
Kyösti Mälkkie325b222016-06-17 11:04:37 +030022
Lee Leahy9d62e7e2017-03-15 17:40:50 -070023asmlinkage void *romstage_main(unsigned long bist)
Kyösti Mälkkie325b222016-06-17 11:04:37 +030024{
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030025 int i;
26 void *romstage_stack_after_car;
27 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. */
33 size = _car_region_end - _car_relocatable_data_end;
34 size = ALIGN_DOWN(size, 16);
35
36 size = MIN(size, DCACHE_RAM_ROMSTAGE_STACK_SIZE);
37 if (size < DCACHE_RAM_ROMSTAGE_STACK_SIZE)
38 printk(BIOS_DEBUG, "Romstage stack size limited to 0x%x!\n",
39 size);
40
41 stack_base = (u32 *) (_car_region_end - size);
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030042
43 for (i = 0; i < num_guards; i++)
44 stack_base[i] = stack_guard;
45
Kyösti Mälkkie325b222016-06-17 11:04:37 +030046 mainboard_romstage_entry(bist);
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030047
48 /* Check the stack. */
49 for (i = 0; i < num_guards; i++) {
50 if (stack_base[i] == stack_guard)
51 continue;
52 printk(BIOS_DEBUG, "Smashed stack detected in romstage!\n");
53 }
54
55 /* Get the stack to use after cache-as-ram is torn down. */
Kyösti Mälkki823020d2016-07-22 22:53:19 +030056 romstage_stack_after_car = setup_stack_and_mtrrs();
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030057
58 return romstage_stack_after_car;
59}
60
Lee Leahy9d62e7e2017-03-15 17:40:50 -070061asmlinkage void romstage_after_car(void)
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030062{
63 /* Load the ramstage. */
64 run_ramstage();
Kyösti Mälkkie325b222016-06-17 11:04:37 +030065}