blob: 41a02f33b95c4bd44b1ed58e8d7c0390d7642941 [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
Arthur Heymans8a1b94c2019-05-25 09:47:01 +020016#include <arch/symbols.h>
Aaron Durbine6af4be2015-09-24 12:26:31 -050017#include <console/console.h>
Arthur Heymans56e2d7d2019-05-23 15:07:49 +020018#include <cpu/intel/romstage.h>
Nico Huberd67edca2018-11-13 19:28:07 +010019#include <cpu/x86/mtrr.h>
Aaron Durbine6af4be2015-09-24 12:26:31 -050020#include <fsp/car.h>
Aaron Durbin909c5122015-09-29 17:41:30 -050021#include <fsp/util.h>
Arthur Heymansbe291e82019-01-06 07:35:11 +010022#include <fsp/memmap.h>
Aaron Durbin6d720f32015-12-08 17:00:23 -060023#include <program_loading.h>
Aaron Durbine6af4be2015-09-24 12:26:31 -050024#include <timestamp.h>
25
Arthur Heymansbe291e82019-01-06 07:35:11 +010026#define ROMSTAGE_RAM_STACK_SIZE 0x5000
Aaron Durbin909c5122015-09-29 17:41:30 -050027
Arthur Heymansbe291e82019-01-06 07:35:11 +010028/* platform_enter_postcar() determines the stack to use after
29 * cache-as-ram is torn down as well as the MTRR settings to use,
30 * and continues execution in postcar stage. */
Arthur Heymans56e2d7d2019-05-23 15:07:49 +020031void platform_enter_postcar(void)
Aaron Durbin909c5122015-09-29 17:41:30 -050032{
Arthur Heymansbe291e82019-01-06 07:35:11 +010033 struct postcar_frame pcf;
34 size_t alignment;
35 uint32_t aligned_ram;
36
37 if (postcar_frame_init(&pcf, ROMSTAGE_RAM_STACK_SIZE))
38 die("Unable to initialize postcar frame.\n");
39 /* Cache the ROM as WP just below 4GiB. */
40 postcar_frame_add_mtrr(&pcf, CACHE_ROM_BASE, CACHE_ROM_SIZE,
41 MTRR_TYPE_WRPROT);
42
43 /* Cache RAM as WB from 0 -> CACHE_TMP_RAMTOP. */
44 postcar_frame_add_mtrr(&pcf, 0, CACHE_TMP_RAMTOP, MTRR_TYPE_WRBACK);
45
46 /*
47 * +-------------------------+ Top of RAM (aligned)
48 * | System Management Mode |
49 * | code and data | Length: CONFIG_TSEG_SIZE
50 * | (TSEG) |
51 * +-------------------------+ SMM base (aligned)
52 * | |
53 * | Chipset Reserved Memory | Length: Multiple of CONFIG_TSEG_SIZE
54 * | |
55 * +-------------------------+ top_of_ram (aligned)
56 * | |
57 * | CBMEM Root |
58 * | |
59 * +-------------------------+
60 * | |
61 * | FSP Reserved Memory |
62 * | |
63 * +-------------------------+
64 * | |
65 * | Various CBMEM Entries |
66 * | |
67 * +-------------------------+ top_of_stack (8 byte aligned)
68 * | |
69 * | stack (CBMEM Entry) |
70 * | |
71 * +-------------------------+
72 */
73
74 alignment = mmap_region_granularity();
75 aligned_ram = ALIGN_DOWN(romstage_ram_stack_bottom(), alignment);
76 postcar_frame_add_mtrr(&pcf, aligned_ram, alignment, MTRR_TYPE_WRBACK);
77
78 if (CONFIG(HAVE_SMI_HANDLER)) {
79 void *smm_base;
80 size_t smm_size;
81
82 /*
83 * Cache the TSEG region at the top of ram. This region is not
84 * restricted to SMM mode until SMM has been relocated. By
85 * setting the region to cacheable it provides faster access
86 * when relocating the SMM handler as well as using the TSEG
87 * region for other purposes.
88 */
89 smm_region(&smm_base, &smm_size);
90 postcar_frame_add_mtrr(&pcf, (uintptr_t)smm_base, alignment,
91 MTRR_TYPE_WRBACK);
92 }
93
94 run_postcar_phase(&pcf);
Aaron Durbin909c5122015-09-29 17:41:30 -050095}
96
Arthur Heymansbe291e82019-01-06 07:35:11 +010097/* This is the romstage C entry for platforms without
98 CONFIG_C_ENVIRONMENT_BOOTBLOCK */
99asmlinkage void cache_as_ram_main(struct cache_as_ram_params *car_params)
Aaron Durbine6af4be2015-09-24 12:26:31 -0500100{
Arthur Heymans61b22cb2019-01-08 23:25:04 +0100101 int i;
102 const int num_guards = 4;
103 const u32 stack_guard = 0xdeadbeef;
104 u32 *stack_base;
105 u32 size;
106
107 /* Size of unallocated CAR. */
108 size = _car_region_end - _car_relocatable_data_end;
109 size = ALIGN_DOWN(size, 16);
110
Arthur Heymansbe291e82019-01-06 07:35:11 +0100111 stack_base = (u32 *)(_car_region_end - size);
Arthur Heymans61b22cb2019-01-08 23:25:04 +0100112
113 for (i = 0; i < num_guards; i++)
114 stack_base[i] = stack_guard;
115
Aaron Durbine6af4be2015-09-24 12:26:31 -0500116 /* Initialize timestamp book keeping only once. */
117 timestamp_init(car_params->tsc);
118
119 /* Call into pre-console init code then initialize console. */
120 car_soc_pre_console_init();
121 car_mainboard_pre_console_init();
122 console_init();
123
124 printk(BIOS_DEBUG, "FSP TempRamInit successful\n");
125
126 printk(BIOS_SPEW, "bist: 0x%08x\n", car_params->bist);
127 printk(BIOS_SPEW, "tsc: 0x%016llx\n", car_params->tsc);
128
Arthur Heymanse124fa52019-01-12 11:48:37 +0100129 display_mtrrs();
130
Arthur Heymansbe291e82019-01-06 07:35:11 +0100131 if (car_params->bootloader_car_start != CONFIG_DCACHE_RAM_BASE
132 || car_params->bootloader_car_end != (CONFIG_DCACHE_RAM_BASE
133 + CONFIG_DCACHE_RAM_SIZE)) {
Aaron Durbine6af4be2015-09-24 12:26:31 -0500134 printk(BIOS_INFO, "CAR mismatch: %08x--%08x vs %08lx--%08lx\n",
Arthur Heymansbe291e82019-01-06 07:35:11 +0100135 CONFIG_DCACHE_RAM_BASE,
136 CONFIG_DCACHE_RAM_BASE + CONFIG_DCACHE_RAM_SIZE,
137 (long)car_params->bootloader_car_start,
138 (long)car_params->bootloader_car_end);
Aaron Durbine6af4be2015-09-24 12:26:31 -0500139 }
140
141 car_soc_post_console_init();
142 car_mainboard_post_console_init();
143
Arthur Heymansbe291e82019-01-06 07:35:11 +0100144 cache_as_ram_stage_main(car_params->fih);
Arthur Heymansec3c8b52019-01-12 11:44:08 +0100145
Arthur Heymans61b22cb2019-01-08 23:25:04 +0100146 /* Check the stack. */
147 for (i = 0; i < num_guards; i++) {
148 if (stack_base[i] == stack_guard)
149 continue;
150 printk(BIOS_DEBUG, "Smashed stack detected in romstage!\n");
151 }
152
Arthur Heymansbe291e82019-01-06 07:35:11 +0100153 /* we don't return here */
154 platform_enter_postcar();
Aaron Durbine6af4be2015-09-24 12:26:31 -0500155}
156
Arthur Heymans56e2d7d2019-05-23 15:07:49 +0200157/* This is the entry for platforms with CONFIG_C_ENVIRONMENT_BOOTBLOCK
158 called from cpu/intel/car/romstage.c */
159void mainboard_romstage_entry(unsigned long bist)
Aaron Durbin909c5122015-09-29 17:41:30 -0500160{
161 /* Need to locate the current FSP_INFO_HEADER. The cache-as-ram
162 * is still enabled. We can directly access work buffer here. */
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
Jacob Garberf7f90f72019-05-28 15:37:37 -0600165 if (prog_locate(&fsp))
166 die_with_post_code(POST_INVALID_CBFS, "Unable to locate fsp.bin");
167
168 /* This leaks a mapping which this code assumes is benign as
169 * the flash is memory mapped CPU's address space. */
170 FSP_INFO_HEADER *fih = find_fsp((uintptr_t)rdev_mmap_full(prog_rdev(&fsp)));
Aaron Durbin909c5122015-09-29 17:41:30 -0500171
Arthur Heymansbe291e82019-01-06 07:35:11 +0100172 cache_as_ram_stage_main(fih);
Aaron Durbine6af4be2015-09-24 12:26:31 -0500173}
174
Aaron Durbin64031672018-04-21 14:45:32 -0600175void __weak car_mainboard_pre_console_init(void)
Aaron Durbine6af4be2015-09-24 12:26:31 -0500176{
177}
178
Aaron Durbin64031672018-04-21 14:45:32 -0600179void __weak car_soc_pre_console_init(void)
Aaron Durbine6af4be2015-09-24 12:26:31 -0500180{
181}
182
Aaron Durbin64031672018-04-21 14:45:32 -0600183void __weak car_mainboard_post_console_init(void)
Aaron Durbine6af4be2015-09-24 12:26:31 -0500184{
185}
186
Aaron Durbin64031672018-04-21 14:45:32 -0600187void __weak car_soc_post_console_init(void)
Aaron Durbine6af4be2015-09-24 12:26:31 -0500188{
189}