blob: e950b1ec6fcccbb4af14b42e6060d5f2b28748af [file] [log] [blame]
Duncan Lauriec88c54c2014-04-30 16:36:13 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2014 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.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
Patrick Georgib890a122015-03-26 15:17:45 +010017 * Foundation, Inc.
Duncan Lauriec88c54c2014-04-30 16:36:13 -070018 */
19
20#include <stddef.h>
21#include <stdint.h>
22#include <arch/cpu.h>
23#include <arch/io.h>
24#include <arch/cbfs.h>
25#include <arch/stages.h>
26#include <arch/early_variables.h>
27#include <console/console.h>
Aaron Durbinbd74a4b2015-03-06 23:17:33 -060028#include <cbfs.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070029#include <cbmem.h>
30#include <cpu/x86/mtrr.h>
31#include <elog.h>
Vladimir Serbinenko0e90dae2015-05-18 10:29:06 +020032#include <tpm.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070033#include <romstage_handoff.h>
Aaron Durbinbd74a4b2015-03-06 23:17:33 -060034#include <stage_cache.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070035#include <timestamp.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070036#include <soc/me.h>
37#include <soc/pei_data.h>
38#include <soc/pm.h>
39#include <soc/reset.h>
40#include <soc/romstage.h>
41#include <soc/spi.h>
Patrick Georgi3e18aca2015-04-29 18:59:04 +020042#include <vendorcode/google/chromeos/chromeos.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070043
Duncan Lauriec88c54c2014-04-30 16:36:13 -070044/* Entry from cache-as-ram.inc. */
45void * asmlinkage romstage_main(unsigned long bist,
46 uint32_t tsc_low, uint32_t tsc_hi)
47{
48 struct romstage_params rp = {
49 .bist = bist,
50 .pei_data = NULL,
51 };
52
53 post_code(0x30);
54
55 /* Save initial timestamp from bootblock. */
Kyösti Mälkki41759272014-12-31 21:11:51 +020056 timestamp_init((((uint64_t)tsc_hi) << 32) | (uint64_t)tsc_low);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070057
58 /* Save romstage begin */
Kyösti Mälkki41759272014-12-31 21:11:51 +020059 timestamp_add_now(TS_START_ROMSTAGE);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070060
61 /* System Agent Early Initialization */
62 systemagent_early_init();
63
64 /* PCH Early Initialization */
65 pch_early_init();
66
Wenkai Du1006b102014-11-05 21:10:57 -080067 /* Call into mainboard pre console init. Needed to enable serial port
68 on IT8772 */
69 mainboard_pre_console_init();
70
Duncan Lauriec88c54c2014-04-30 16:36:13 -070071 /* Start console drivers */
72 console_init();
73
Duncan Laurie61680272014-05-05 12:42:35 -050074 /* Get power state */
75 rp.power_state = fill_power_state();
76
Duncan Lauriec88c54c2014-04-30 16:36:13 -070077 /* Print useful platform information */
78 report_platform_info();
79
80 /* Set CPU frequency to maximum */
81 set_max_freq();
82
83 /* Call into mainboard. */
84 mainboard_romstage_entry(&rp);
85
Ryan Linb2deb222015-01-18 21:32:44 +080086#if CONFIG_CHROMEOS
87 save_chromeos_gpios();
88#endif
89
Duncan Lauriec88c54c2014-04-30 16:36:13 -070090 return setup_stack_and_mttrs();
91}
92
Duncan Lauriec88c54c2014-04-30 16:36:13 -070093/* Entry from the mainboard. */
94void romstage_common(struct romstage_params *params)
95{
Duncan Lauriec88c54c2014-04-30 16:36:13 -070096 struct romstage_handoff *handoff;
97
98 post_code(0x32);
99
Kyösti Mälkki41759272014-12-31 21:11:51 +0200100 timestamp_add_now(TS_BEFORE_INITRAM);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700101
Duncan Laurie61680272014-05-05 12:42:35 -0500102 params->pei_data->boot_mode = params->power_state->prev_sleep_state;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700103
104#if CONFIG_ELOG_BOOT_COUNT
Duncan Laurie61680272014-05-05 12:42:35 -0500105 if (params->power_state->prev_sleep_state != SLEEP_STATE_S3)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700106 boot_count_increment();
107#endif
108
109 /* Print ME state before MRC */
110 intel_me_status();
111
Duncan Lauriea7d8ea82014-08-26 13:49:24 -0700112 /* Save ME HSIO version */
113 intel_me_hsio_version(&params->power_state->hsio_version,
114 &params->power_state->hsio_checksum);
115
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700116 /* Initialize RAM */
117 raminit(params->pei_data);
Kyösti Mälkki41759272014-12-31 21:11:51 +0200118
119 timestamp_add_now(TS_AFTER_INITRAM);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700120
121 handoff = romstage_handoff_find_or_add();
122 if (handoff != NULL)
Duncan Laurie61680272014-05-05 12:42:35 -0500123 handoff->s3_resume = (params->power_state->prev_sleep_state ==
124 SLEEP_STATE_S3);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700125 else
126 printk(BIOS_DEBUG, "Romstage handoff structure not added!\n");
127
Vladimir Serbinenko0e90dae2015-05-18 10:29:06 +0200128#if CONFIG_LPC_TPM
129 init_tpm(prev_sleep_state == SLEEP_STATE_S3);
130#endif
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700131}
132
133void asmlinkage romstage_after_car(void)
134{
135 timestamp_add_now(TS_END_ROMSTAGE);
136
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700137 /* Load the ramstage. */
138 copy_and_run();
139 while (1);
140}
141
Aaron Durbinbd74a4b2015-03-06 23:17:33 -0600142void ramstage_cache_invalid(void)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700143{
144#if CONFIG_RESET_ON_INVALID_RAMSTAGE_CACHE
145 /* Perform cold reset on invalid ramstage cache. */
146 reset_system();
147#endif
148}
149
150#if CONFIG_CHROMEOS
151int vboot_get_sw_write_protect(void)
152{
153 u8 status;
154 /* Return unprotected status if status read fails. */
155 return (early_spi_read_wpsr(&status) ? 0 : !!(status & 0x80));
156}
Wenkai Du1006b102014-11-05 21:10:57 -0800157
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700158#endif
Wenkai Du1006b102014-11-05 21:10:57 -0800159void __attribute__((weak)) mainboard_pre_console_init(void) {}