blob: 7df512dce0ed093bdd68f7f1e2d43a4e3b6580a3 [file] [log] [blame]
Angel Ponsf23ae0b2020-04-02 23:48:12 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +03002
Jeremy Compostellafa838872022-11-30 19:26:01 -07003#include <adainit.h>
Kyösti Mälkkia963acd2019-08-16 20:34:25 +03004#include <arch/romstage.h>
Kyösti Mälkki65e54662017-09-01 07:10:56 +03005#include <arch/symbols.h>
Elyes HAOUASd26844c2019-06-21 07:31:40 +02006#include <commonlib/helpers.h>
Elyes Haouas7df5c682022-10-02 12:36:58 +02007#include <console/console.h>
8#include <cpu/x86/smm.h>
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +03009#include <program_loading.h>
Arthur Heymansbab9e2e2021-05-29 07:30:33 +020010#include <romstage_common.h>
Tim Wawrzynczakf2cae502019-10-25 15:13:04 -060011#include <security/vboot/vboot_common.h>
Elyes Haouas7df5c682022-10-02 12:36:58 +020012#include <types.h>
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030013
Arthur Heymans4c095fc2019-08-18 08:40:56 +020014/* If we do not have a constrained _car_stack region size, use the
15 following as a guideline for acceptable stack usage. */
Kyösti Mälkkidfb2de82016-11-19 16:39:21 +020016#define DCACHE_RAM_ROMSTAGE_STACK_SIZE 0x2000
Kyösti Mälkkie325b222016-06-17 11:04:37 +030017
Arthur Heymansbab9e2e2021-05-29 07:30:33 +020018void __noreturn romstage_main(void)
Kyösti Mälkkie325b222016-06-17 11:04:37 +030019{
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030020 int i;
Arthur Heymans4c095fc2019-08-18 08:40:56 +020021 const int num_guards = 64;
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030022 const u32 stack_guard = 0xdeadbeef;
Kyösti Mälkki65e54662017-09-01 07:10:56 +030023 u32 *stack_base;
24 u32 size;
Arthur Heymans4c095fc2019-08-18 08:40:56 +020025 const size_t stack_size = MAX(CONFIG_DCACHE_BSP_STACK_SIZE,
26 DCACHE_RAM_ROMSTAGE_STACK_SIZE);
Kyösti Mälkki65e54662017-09-01 07:10:56 +030027
28 /* Size of unallocated CAR. */
Kyösti Mälkkid7892bc2018-12-28 19:18:46 +020029 size = ALIGN_DOWN(_car_stack_size, 16);
Kyösti Mälkki65e54662017-09-01 07:10:56 +030030
Arthur Heymans4c095fc2019-08-18 08:40:56 +020031 size = MIN(size, stack_size);
32 if (size < stack_size)
Kyösti Mälkki65e54662017-09-01 07:10:56 +030033 printk(BIOS_DEBUG, "Romstage stack size limited to 0x%x!\n",
34 size);
35
Elyes Haouas4d685d42022-11-18 15:04:34 +010036 stack_base = (u32 *)(_ecar_stack - size);
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030037
38 for (i = 0; i < num_guards; i++)
39 stack_base[i] = stack_guard;
40
Tim Wawrzynczakf2cae502019-10-25 15:13:04 -060041 if (CONFIG(VBOOT_EARLY_EC_SYNC))
42 vboot_sync_ec();
43
Jeremy Compostellafa838872022-11-30 19:26:01 -070044 /*
45 * We can generally jump between C and Ada code back and forth
46 * without trouble. But since we don't have an Ada main() we
47 * have to do some Ada package initializations that GNAT would
48 * do there. This has to be done before calling any Ada code.
49 *
50 * The package initializations should not have any dependen-
51 * cies on C code. So we can call them here early, and don't
52 * have to worry at which point we can start to use Ada.
53 */
54 romstage_adainit();
55
Kyösti Mälkki157b1892019-08-16 14:02:25 +030056 mainboard_romstage_entry();
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030057
58 /* Check the stack. */
59 for (i = 0; i < num_guards; i++) {
60 if (stack_base[i] == stack_guard)
61 continue;
62 printk(BIOS_DEBUG, "Smashed stack detected in romstage!\n");
63 }
64
Kyösti Mälkki7cdb0472019-08-08 11:16:06 +030065 if (CONFIG(SMM_TSEG))
66 smm_list_regions();
67
Arthur Heymans876a1b42022-02-15 11:06:10 +010068 prepare_and_run_postcar();
Kyösti Mälkki5bc641a2019-08-09 09:37:49 +030069 /* We do not return here. */
Arthur Heymansd3d82e02018-06-05 11:19:22 +020070}