blob: 79dd3681c3328e4c9f5f16234df47fa77545594f [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>
Aaron Durbin6d720f32015-12-08 17:00:23 -060021#include <program_loading.h>
Aaron Durbine6af4be2015-09-24 12:26:31 -050022#include <timestamp.h>
23
Aaron Durbin909c5122015-09-29 17:41:30 -050024FSP_INFO_HEADER *fih_car CAR_GLOBAL;
25
26/* Save FSP_INFO_HEADER for TempRamExit() call in assembly. */
27static inline void set_fih_car(FSP_INFO_HEADER *fih)
28{
29 /* This variable is written in the raw form because it's only
30 * ever accessed in code that that has the cache-as-ram enabled. The
31 * assembly routine which tears down cache-as-ram utilizes this
32 * variable for determining where to find FSP. */
33 fih_car = fih;
34}
35
Aaron Durbine6af4be2015-09-24 12:26:31 -050036asmlinkage void *cache_as_ram_main(struct cache_as_ram_params *car_params)
37{
Arthur Heymans61b22cb2019-01-08 23:25:04 +010038 int i;
39 const int num_guards = 4;
40 const u32 stack_guard = 0xdeadbeef;
41 u32 *stack_base;
Arthur Heymansec3c8b52019-01-12 11:44:08 +010042 void *ram_stack;
Arthur Heymans61b22cb2019-01-08 23:25:04 +010043 u32 size;
44
45 /* Size of unallocated CAR. */
46 size = _car_region_end - _car_relocatable_data_end;
47 size = ALIGN_DOWN(size, 16);
48
49 stack_base = (u32 *) (_car_region_end - size);
50
51 for (i = 0; i < num_guards; i++)
52 stack_base[i] = stack_guard;
53
Aaron Durbine6af4be2015-09-24 12:26:31 -050054 /* Initialize timestamp book keeping only once. */
55 timestamp_init(car_params->tsc);
56
57 /* Call into pre-console init code then initialize console. */
58 car_soc_pre_console_init();
59 car_mainboard_pre_console_init();
60 console_init();
61
62 printk(BIOS_DEBUG, "FSP TempRamInit successful\n");
63
64 printk(BIOS_SPEW, "bist: 0x%08x\n", car_params->bist);
65 printk(BIOS_SPEW, "tsc: 0x%016llx\n", car_params->tsc);
66
67 if (car_params->bootloader_car_start != CONFIG_DCACHE_RAM_BASE ||
68 car_params->bootloader_car_end !=
69 (CONFIG_DCACHE_RAM_BASE + CONFIG_DCACHE_RAM_SIZE)) {
70 printk(BIOS_INFO, "CAR mismatch: %08x--%08x vs %08lx--%08lx\n",
71 CONFIG_DCACHE_RAM_BASE,
72 CONFIG_DCACHE_RAM_BASE + CONFIG_DCACHE_RAM_SIZE,
73 (long)car_params->bootloader_car_start,
74 (long)car_params->bootloader_car_end);
75 }
76
77 car_soc_post_console_init();
78 car_mainboard_post_console_init();
79
Aaron Durbin909c5122015-09-29 17:41:30 -050080 set_fih_car(car_params->fih);
81
Arthur Heymansec3c8b52019-01-12 11:44:08 +010082 /* Return new stack value in RAM back to assembly stub. */
83 ram_stack = cache_as_ram_stage_main(car_params->fih);
84
Arthur Heymans61b22cb2019-01-08 23:25:04 +010085 /* Check the stack. */
86 for (i = 0; i < num_guards; i++) {
87 if (stack_base[i] == stack_guard)
88 continue;
89 printk(BIOS_DEBUG, "Smashed stack detected in romstage!\n");
90 }
91
Arthur Heymansec3c8b52019-01-12 11:44:08 +010092 return ram_stack;
Aaron Durbine6af4be2015-09-24 12:26:31 -050093}
94
Aaron Durbin909c5122015-09-29 17:41:30 -050095/* Entry point taken when romstage is called after a separate verstage. */
Teo Boon Tiongd8e34b22016-12-28 18:56:26 +080096asmlinkage void *romstage_c_entry(void)
Aaron Durbin909c5122015-09-29 17:41:30 -050097{
98 /* Need to locate the current FSP_INFO_HEADER. The cache-as-ram
99 * is still enabled. We can directly access work buffer here. */
100 FSP_INFO_HEADER *fih;
Aaron Durbin7e7a4df2015-12-08 14:34:35 -0600101 struct prog fsp = PROG_INIT(PROG_REFCODE, "fsp.bin");
Aaron Durbin909c5122015-09-29 17:41:30 -0500102
103 console_init();
104
Aaron Durbin6d720f32015-12-08 17:00:23 -0600105 if (prog_locate(&fsp)) {
Aaron Durbin909c5122015-09-29 17:41:30 -0500106 fih = NULL;
Aaron Durbin6d720f32015-12-08 17:00:23 -0600107 printk(BIOS_ERR, "Unable to locate %s\n", prog_name(&fsp));
Aaron Durbin909c5122015-09-29 17:41:30 -0500108 } else
Aaron Durbin6d720f32015-12-08 17:00:23 -0600109 /* This leaks a mapping which this code assumes is benign as
110 * the flash is memory mapped CPU's address space. */
111 fih = find_fsp((uintptr_t)rdev_mmap_full(prog_rdev(&fsp)));
Aaron Durbin909c5122015-09-29 17:41:30 -0500112
113 set_fih_car(fih);
114
Elyes HAOUAS77537312016-07-30 15:37:26 +0200115 /* Return new stack value in RAM back to assembly stub. */
Aaron Durbin909c5122015-09-29 17:41:30 -0500116 return cache_as_ram_stage_main(fih);
117}
118
Aaron Durbine6af4be2015-09-24 12:26:31 -0500119asmlinkage void after_cache_as_ram(void *chipset_context)
120{
121 timestamp_add_now(TS_FSP_TEMP_RAM_EXIT_END);
122 printk(BIOS_DEBUG, "FspTempRamExit returned successfully\n");
Nico Huberd67edca2018-11-13 19:28:07 +0100123 display_mtrrs();
Aaron Durbine6af4be2015-09-24 12:26:31 -0500124
125 after_cache_as_ram_stage();
126}
127
Aaron Durbin64031672018-04-21 14:45:32 -0600128void __weak car_mainboard_pre_console_init(void)
Aaron Durbine6af4be2015-09-24 12:26:31 -0500129{
130}
131
Aaron Durbin64031672018-04-21 14:45:32 -0600132void __weak car_soc_pre_console_init(void)
Aaron Durbine6af4be2015-09-24 12:26:31 -0500133{
134}
135
Aaron Durbin64031672018-04-21 14:45:32 -0600136void __weak car_mainboard_post_console_init(void)
Aaron Durbine6af4be2015-09-24 12:26:31 -0500137{
138}
139
Aaron Durbin64031672018-04-21 14:45:32 -0600140void __weak car_soc_post_console_init(void)
Aaron Durbine6af4be2015-09-24 12:26:31 -0500141{
142}