blob: 34b2518c385a7b7090334c6c1858cbf7078f2682 [file] [log] [blame]
Aaron Durbine6af4be2015-09-24 12:26:31 -05001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2015 Google Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Aaron Durbine6af4be2015-09-24 12:26:31 -050014 */
15
Aaron Durbin909c5122015-09-29 17:41:30 -050016#include <arch/early_variables.h>
Aaron Durbine6af4be2015-09-24 12:26:31 -050017#include <console/console.h>
Nico Huberd67edca2018-11-13 19:28:07 +010018#include <cpu/x86/mtrr.h>
Aaron Durbine6af4be2015-09-24 12:26:31 -050019#include <fsp/car.h>
Aaron Durbin909c5122015-09-29 17:41:30 -050020#include <fsp/util.h>
Arthur Heymansbe291e82019-01-06 07:35:11 +010021#include <fsp/memmap.h>
Aaron Durbin6d720f32015-12-08 17:00:23 -060022#include <program_loading.h>
Aaron Durbine6af4be2015-09-24 12:26:31 -050023#include <timestamp.h>
24
Arthur Heymansbe291e82019-01-06 07:35:11 +010025#define ROMSTAGE_RAM_STACK_SIZE 0x5000
Aaron Durbin909c5122015-09-29 17:41:30 -050026
Arthur Heymansbe291e82019-01-06 07:35:11 +010027/* platform_enter_postcar() determines the stack to use after
28 * cache-as-ram is torn down as well as the MTRR settings to use,
29 * and continues execution in postcar stage. */
30static void platform_enter_postcar(void)
Aaron Durbin909c5122015-09-29 17:41:30 -050031{
Arthur Heymansbe291e82019-01-06 07:35:11 +010032 struct postcar_frame pcf;
33 size_t alignment;
34 uint32_t aligned_ram;
35
36 if (postcar_frame_init(&pcf, ROMSTAGE_RAM_STACK_SIZE))
37 die("Unable to initialize postcar frame.\n");
38 /* Cache the ROM as WP just below 4GiB. */
39 postcar_frame_add_mtrr(&pcf, CACHE_ROM_BASE, CACHE_ROM_SIZE,
40 MTRR_TYPE_WRPROT);
41
42 /* Cache RAM as WB from 0 -> CACHE_TMP_RAMTOP. */
43 postcar_frame_add_mtrr(&pcf, 0, CACHE_TMP_RAMTOP, MTRR_TYPE_WRBACK);
44
45 /*
46 * +-------------------------+ Top of RAM (aligned)
47 * | System Management Mode |
48 * | code and data | Length: CONFIG_TSEG_SIZE
49 * | (TSEG) |
50 * +-------------------------+ SMM base (aligned)
51 * | |
52 * | Chipset Reserved Memory | Length: Multiple of CONFIG_TSEG_SIZE
53 * | |
54 * +-------------------------+ top_of_ram (aligned)
55 * | |
56 * | CBMEM Root |
57 * | |
58 * +-------------------------+
59 * | |
60 * | FSP Reserved Memory |
61 * | |
62 * +-------------------------+
63 * | |
64 * | Various CBMEM Entries |
65 * | |
66 * +-------------------------+ top_of_stack (8 byte aligned)
67 * | |
68 * | stack (CBMEM Entry) |
69 * | |
70 * +-------------------------+
71 */
72
73 alignment = mmap_region_granularity();
74 aligned_ram = ALIGN_DOWN(romstage_ram_stack_bottom(), alignment);
75 postcar_frame_add_mtrr(&pcf, aligned_ram, alignment, MTRR_TYPE_WRBACK);
76
77 if (CONFIG(HAVE_SMI_HANDLER)) {
78 void *smm_base;
79 size_t smm_size;
80
81 /*
82 * Cache the TSEG region at the top of ram. This region is not
83 * restricted to SMM mode until SMM has been relocated. By
84 * setting the region to cacheable it provides faster access
85 * when relocating the SMM handler as well as using the TSEG
86 * region for other purposes.
87 */
88 smm_region(&smm_base, &smm_size);
89 postcar_frame_add_mtrr(&pcf, (uintptr_t)smm_base, alignment,
90 MTRR_TYPE_WRBACK);
91 }
92
93 run_postcar_phase(&pcf);
Aaron Durbin909c5122015-09-29 17:41:30 -050094}
95
Arthur Heymansbe291e82019-01-06 07:35:11 +010096/* This is the romstage C entry for platforms without
97 CONFIG_C_ENVIRONMENT_BOOTBLOCK */
98asmlinkage void cache_as_ram_main(struct cache_as_ram_params *car_params)
Aaron Durbine6af4be2015-09-24 12:26:31 -050099{
Arthur Heymans61b22cb2019-01-08 23:25:04 +0100100 int i;
101 const int num_guards = 4;
102 const u32 stack_guard = 0xdeadbeef;
103 u32 *stack_base;
104 u32 size;
105
106 /* Size of unallocated CAR. */
107 size = _car_region_end - _car_relocatable_data_end;
108 size = ALIGN_DOWN(size, 16);
109
Arthur Heymansbe291e82019-01-06 07:35:11 +0100110 stack_base = (u32 *)(_car_region_end - size);
Arthur Heymans61b22cb2019-01-08 23:25:04 +0100111
112 for (i = 0; i < num_guards; i++)
113 stack_base[i] = stack_guard;
114
Aaron Durbine6af4be2015-09-24 12:26:31 -0500115 /* Initialize timestamp book keeping only once. */
116 timestamp_init(car_params->tsc);
117
118 /* Call into pre-console init code then initialize console. */
119 car_soc_pre_console_init();
120 car_mainboard_pre_console_init();
121 console_init();
122
123 printk(BIOS_DEBUG, "FSP TempRamInit successful\n");
124
125 printk(BIOS_SPEW, "bist: 0x%08x\n", car_params->bist);
126 printk(BIOS_SPEW, "tsc: 0x%016llx\n", car_params->tsc);
127
Arthur Heymanse124fa52019-01-12 11:48:37 +0100128 display_mtrrs();
129
Arthur Heymansbe291e82019-01-06 07:35:11 +0100130 if (car_params->bootloader_car_start != CONFIG_DCACHE_RAM_BASE
131 || car_params->bootloader_car_end != (CONFIG_DCACHE_RAM_BASE
132 + CONFIG_DCACHE_RAM_SIZE)) {
Aaron Durbine6af4be2015-09-24 12:26:31 -0500133 printk(BIOS_INFO, "CAR mismatch: %08x--%08x vs %08lx--%08lx\n",
Arthur Heymansbe291e82019-01-06 07:35:11 +0100134 CONFIG_DCACHE_RAM_BASE,
135 CONFIG_DCACHE_RAM_BASE + CONFIG_DCACHE_RAM_SIZE,
136 (long)car_params->bootloader_car_start,
137 (long)car_params->bootloader_car_end);
Aaron Durbine6af4be2015-09-24 12:26:31 -0500138 }
139
140 car_soc_post_console_init();
141 car_mainboard_post_console_init();
142
Arthur Heymansbe291e82019-01-06 07:35:11 +0100143 cache_as_ram_stage_main(car_params->fih);
Arthur Heymansec3c8b52019-01-12 11:44:08 +0100144
Arthur Heymans61b22cb2019-01-08 23:25:04 +0100145 /* Check the stack. */
146 for (i = 0; i < num_guards; i++) {
147 if (stack_base[i] == stack_guard)
148 continue;
149 printk(BIOS_DEBUG, "Smashed stack detected in romstage!\n");
150 }
151
Arthur Heymansbe291e82019-01-06 07:35:11 +0100152 /* we don't return here */
153 platform_enter_postcar();
Aaron Durbine6af4be2015-09-24 12:26:31 -0500154}
155
Arthur Heymansbe291e82019-01-06 07:35:11 +0100156/* This is the romstage C entry for platforms with
157 CONFIG_C_ENVIRONMENT_BOOTBLOCK */
158asmlinkage void romstage_c_entry(void)
Aaron Durbin909c5122015-09-29 17:41:30 -0500159{
160 /* Need to locate the current FSP_INFO_HEADER. The cache-as-ram
161 * is still enabled. We can directly access work buffer here. */
162 FSP_INFO_HEADER *fih;
Aaron Durbin7e7a4df2015-12-08 14:34:35 -0600163 struct prog fsp = PROG_INIT(PROG_REFCODE, "fsp.bin");
Aaron Durbin909c5122015-09-29 17:41:30 -0500164
165 console_init();
166
Aaron Durbin6d720f32015-12-08 17:00:23 -0600167 if (prog_locate(&fsp)) {
Aaron Durbin909c5122015-09-29 17:41:30 -0500168 fih = NULL;
Aaron Durbin6d720f32015-12-08 17:00:23 -0600169 printk(BIOS_ERR, "Unable to locate %s\n", prog_name(&fsp));
Arthur Heymansbe291e82019-01-06 07:35:11 +0100170 } else {
Aaron Durbin6d720f32015-12-08 17:00:23 -0600171 /* This leaks a mapping which this code assumes is benign as
172 * the flash is memory mapped CPU's address space. */
173 fih = find_fsp((uintptr_t)rdev_mmap_full(prog_rdev(&fsp)));
Arthur Heymansbe291e82019-01-06 07:35:11 +0100174 }
Aaron Durbin909c5122015-09-29 17:41:30 -0500175
Arthur Heymansbe291e82019-01-06 07:35:11 +0100176 cache_as_ram_stage_main(fih);
Aaron Durbin909c5122015-09-29 17:41:30 -0500177
Arthur Heymansbe291e82019-01-06 07:35:11 +0100178 /* we don't return here */
179 platform_enter_postcar();
Aaron Durbine6af4be2015-09-24 12:26:31 -0500180}
181
Aaron Durbin64031672018-04-21 14:45:32 -0600182void __weak car_mainboard_pre_console_init(void)
Aaron Durbine6af4be2015-09-24 12:26:31 -0500183{
184}
185
Aaron Durbin64031672018-04-21 14:45:32 -0600186void __weak car_soc_pre_console_init(void)
Aaron Durbine6af4be2015-09-24 12:26:31 -0500187{
188}
189
Aaron Durbin64031672018-04-21 14:45:32 -0600190void __weak car_mainboard_post_console_init(void)
Aaron Durbine6af4be2015-09-24 12:26:31 -0500191{
192}
193
Aaron Durbin64031672018-04-21 14:45:32 -0600194void __weak car_soc_post_console_init(void)
Aaron Durbine6af4be2015-09-24 12:26:31 -0500195{
196}