blob: ab9fd591be854cec993951ab4321bd31ebd1d514 [file] [log] [blame]
Aaron Durbin3d0071b2013-01-18 14:32:50 -06001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2012 ChromeOS Authors
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 Durbin3d0071b2013-01-18 14:32:50 -060014 */
15
16#include <stdint.h>
Aaron Durbin7492ec12013-02-08 22:18:04 -060017#include <string.h>
Aaron Durbinbd74a4b2015-03-06 23:17:33 -060018#include <cbfs.h>
Aaron Durbin3d0071b2013-01-18 14:32:50 -060019#include <console/console.h>
Aaron Durbina2671612013-02-06 21:41:01 -060020#include <arch/cpu.h>
Kyösti Mälkki140087f2016-12-06 14:00:05 +020021#include <cpu/cpu.h>
Aaron Durbina2671612013-02-06 21:41:01 -060022#include <cpu/x86/bist.h>
23#include <cpu/x86/msr.h>
Aaron Durbin38d94232013-02-07 00:03:33 -060024#include <cpu/x86/mtrr.h>
Patrick Georgibd79c5e2014-11-28 22:35:36 +010025#include <halt.h>
Aaron Durbina2671612013-02-06 21:41:01 -060026#include <lib.h>
27#include <timestamp.h>
Kyösti Mälkkia969ed32016-06-15 06:08:15 +030028#include <arch/acpi.h>
Aaron Durbina2671612013-02-06 21:41:01 -060029#include <arch/io.h>
Aaron Durbina2671612013-02-06 21:41:01 -060030#include <device/pci_def.h>
31#include <cpu/x86/lapic.h>
Kyösti Mälkki465eff62016-06-15 06:07:55 +030032#include <cbmem.h>
Kyösti Mälkki65e8f642016-06-27 11:27:56 +030033#include <program_loading.h>
Aaron Durbinbf396ff2013-02-11 21:50:35 -060034#include <romstage_handoff.h>
Aaron Durbinb86113f2013-02-19 08:59:16 -060035#include <reset.h>
Aaron Durbina2671612013-02-06 21:41:01 -060036#include <vendorcode/google/chromeos/chromeos.h>
Martin Rothffdee282017-06-24 13:43:40 -060037#if IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC)
Duncan Laurie7cced0d2013-06-04 10:03:34 -070038#include <ec/google/chromeec/ec.h>
39#endif
Aaron Durbina2671612013-02-06 21:41:01 -060040#include "haswell.h"
41#include "northbridge/intel/haswell/haswell.h"
42#include "northbridge/intel/haswell/raminit.h"
43#include "southbridge/intel/lynxpoint/pch.h"
44#include "southbridge/intel/lynxpoint/me.h"
Philipp Deppenwiesec07f8fb2018-02-27 19:40:52 +010045#include <security/tpm/tspi.h>
Aaron Durbina2671612013-02-06 21:41:01 -060046
Aaron Durbinb86113f2013-02-19 08:59:16 -060047static inline void reset_system(void)
48{
49 hard_reset();
Patrick Georgibd79c5e2014-11-28 22:35:36 +010050 halt();
Aaron Durbinb86113f2013-02-19 08:59:16 -060051}
52
Arthur Heymans88af0f32018-06-03 12:37:54 +020053#define ROMSTAGE_RAM_STACK_SIZE 0x5000
Aaron Durbin3d0071b2013-01-18 14:32:50 -060054
Arthur Heymans88af0f32018-06-03 12:37:54 +020055/* platform_enter_postcar() determines the stack to use after
56 * cache-as-ram is torn down as well as the MTRR settings to use,
57 * and continues execution in postcar stage. */
58static void platform_enter_postcar(void)
Aaron Durbin38d94232013-02-07 00:03:33 -060059{
Arthur Heymans88af0f32018-06-03 12:37:54 +020060 struct postcar_frame pcf;
61 uintptr_t top_of_ram;
Aaron Durbin38d94232013-02-07 00:03:33 -060062
Arthur Heymans88af0f32018-06-03 12:37:54 +020063 if (postcar_frame_init(&pcf, ROMSTAGE_RAM_STACK_SIZE))
64 die("Unable to initialize postcar frame.\n");
Aaron Durbin38d94232013-02-07 00:03:33 -060065 /* Cache the ROM as WP just below 4GiB. */
Arthur Heymans88af0f32018-06-03 12:37:54 +020066 postcar_frame_add_mtrr(&pcf, CACHE_ROM_BASE, CACHE_ROM_SIZE,
67 MTRR_TYPE_WRPROT);
Aaron Durbin38d94232013-02-07 00:03:33 -060068
Kyösti Mälkki65cc5262016-06-19 20:38:41 +030069 /* Cache RAM as WB from 0 -> CACHE_TMP_RAMTOP. */
Arthur Heymans88af0f32018-06-03 12:37:54 +020070 postcar_frame_add_mtrr(&pcf, 0, CACHE_TMP_RAMTOP, MTRR_TYPE_WRBACK);
Aaron Durbin38d94232013-02-07 00:03:33 -060071
Arthur Heymans88af0f32018-06-03 12:37:54 +020072 /* Cache at least 8 MiB below the top of ram, and at most 8 MiB
73 * above top of the ram. This satisfies MTRR alignment requirement
74 * with different TSEG size configurations.
75 */
76 top_of_ram = ALIGN_DOWN((uintptr_t)cbmem_top(), 8*MiB);
77 postcar_frame_add_mtrr(&pcf, top_of_ram - 8*MiB, 16*MiB,
78 MTRR_TYPE_WRBACK);
Aaron Durbin67481ddc2013-02-15 15:08:37 -060079
Arthur Heymans88af0f32018-06-03 12:37:54 +020080 run_postcar_phase(&pcf);
Aaron Durbin38d94232013-02-07 00:03:33 -060081}
82
Lee Leahy9d62e7e2017-03-15 17:40:50 -070083asmlinkage void *romstage_main(unsigned long bist)
Aaron Durbin3d0071b2013-01-18 14:32:50 -060084{
85 int i;
86 const int num_guards = 4;
87 const u32 stack_guard = 0xdeadbeef;
88 u32 *stack_base = (void *)(CONFIG_DCACHE_RAM_BASE +
Lee Leahy7b5f12b92017-03-15 17:16:59 -070089 CONFIG_DCACHE_RAM_SIZE -
90 CONFIG_DCACHE_RAM_ROMSTAGE_STACK_SIZE);
Aaron Durbin3d0071b2013-01-18 14:32:50 -060091
92 printk(BIOS_DEBUG, "Setting up stack guards.\n");
93 for (i = 0; i < num_guards; i++)
94 stack_base[i] = stack_guard;
95
Aaron Durbina2671612013-02-06 21:41:01 -060096 mainboard_romstage_entry(bist);
Aaron Durbin3d0071b2013-01-18 14:32:50 -060097
98 /* Check the stack. */
99 for (i = 0; i < num_guards; i++) {
100 if (stack_base[i] == stack_guard)
101 continue;
102 printk(BIOS_DEBUG, "Smashed stack detected in romstage!\n");
103 }
104
Arthur Heymans88af0f32018-06-03 12:37:54 +0200105 platform_enter_postcar();
Aaron Durbin38d94232013-02-07 00:03:33 -0600106
Arthur Heymans88af0f32018-06-03 12:37:54 +0200107 /* We do not return here */
108 return NULL;
Aaron Durbin3d0071b2013-01-18 14:32:50 -0600109}
Aaron Durbina2671612013-02-06 21:41:01 -0600110
111void romstage_common(const struct romstage_params *params)
112{
Aaron Durbinbf396ff2013-02-11 21:50:35 -0600113 int boot_mode;
Aaron Durbina2671612013-02-06 21:41:01 -0600114 int wake_from_s3;
Aaron Durbina2671612013-02-06 21:41:01 -0600115
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300116 timestamp_init(get_initial_timestamp());
117 timestamp_add_now(TS_START_ROMSTAGE);
Aaron Durbina2671612013-02-06 21:41:01 -0600118
119 if (params->bist == 0)
120 enable_lapic();
121
122 wake_from_s3 = early_pch_init(params->gpio_map, params->rcba_config);
123
124 /* Halt if there was a built in self test failure */
125 report_bist_failure(params->bist);
126
127 /* Perform some early chipset initialization required
128 * before RAM initialization can work
129 */
130 haswell_early_initialization(HASWELL_MOBILE);
131 printk(BIOS_DEBUG, "Back from haswell_early_initialization()\n");
132
133 if (wake_from_s3) {
Martin Rothffdee282017-06-24 13:43:40 -0600134#if IS_ENABLED(CONFIG_HAVE_ACPI_RESUME)
Aaron Durbina2671612013-02-06 21:41:01 -0600135 printk(BIOS_DEBUG, "Resume from S3 detected.\n");
Aaron Durbina2671612013-02-06 21:41:01 -0600136#else
137 printk(BIOS_DEBUG, "Resume from S3 detected, but disabled.\n");
Aaron Durbinbf396ff2013-02-11 21:50:35 -0600138 wake_from_s3 = 0;
Aaron Durbina2671612013-02-06 21:41:01 -0600139#endif
140 }
141
Aaron Durbinbf396ff2013-02-11 21:50:35 -0600142 /* There are hard coded assumptions of 2 meaning s3 wake. Normalize
143 * the users of the 2 literal here based off wake_from_s3. */
144 boot_mode = wake_from_s3 ? 2 : 0;
145
Aaron Durbina2671612013-02-06 21:41:01 -0600146 /* Prepare USB controller early in S3 resume */
Aaron Durbinbf396ff2013-02-11 21:50:35 -0600147 if (wake_from_s3)
Aaron Durbina2671612013-02-06 21:41:01 -0600148 enable_usb_bar();
149
150 post_code(0x3a);
151 params->pei_data->boot_mode = boot_mode;
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300152
153 timestamp_add_now(TS_BEFORE_INITRAM);
Aaron Durbina2671612013-02-06 21:41:01 -0600154
155 report_platform_info();
156
Aaron Durbinc7633f42013-06-13 17:29:36 -0700157 if (params->copy_spd != NULL)
158 params->copy_spd(params->pei_data);
159
Aaron Durbina2671612013-02-06 21:41:01 -0600160 sdram_initialize(params->pei_data);
161
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300162 timestamp_add_now(TS_AFTER_INITRAM);
163
Aaron Durbina2671612013-02-06 21:41:01 -0600164 post_code(0x3b);
165
166 intel_early_me_status();
167
168 quick_ram_check();
169 post_code(0x3e);
170
Aaron Durbinc0cbd6e2013-03-13 13:51:20 -0500171 if (!wake_from_s3) {
172 cbmem_initialize_empty();
173 /* Save data returned from MRC on non-S3 resumes. */
Aaron Durbin2ad1dba2013-02-07 00:51:18 -0600174 save_mrc_data(params->pei_data);
Aaron Durbin42e68562015-06-09 13:55:51 -0500175 } else if (cbmem_initialize()) {
Martin Rothffdee282017-06-24 13:43:40 -0600176 #if IS_ENABLED(CONFIG_HAVE_ACPI_RESUME)
Aaron Durbin42e68562015-06-09 13:55:51 -0500177 /* Failed S3 resume, reset to come up cleanly */
178 reset_system();
179 #endif
Aaron Durbina2671612013-02-06 21:41:01 -0600180 }
Aaron Durbinbf396ff2013-02-11 21:50:35 -0600181
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -0500182 setup_sdram_meminfo(params->pei_data);
183
Aaron Durbin77e13992016-11-29 17:43:04 -0600184 romstage_handoff_init(wake_from_s3);
Aaron Durbinbf396ff2013-02-11 21:50:35 -0600185
Aaron Durbina2671612013-02-06 21:41:01 -0600186 post_code(0x3f);
Philipp Deppenwiesec07f8fb2018-02-27 19:40:52 +0100187 if (IS_ENABLED(CONFIG_TPM1) || IS_ENABLED(CONFIG_TPM2))
188 tpm_setup(wake_from_s3);
Aaron Durbina2671612013-02-06 21:41:01 -0600189}