Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 1 | /* |
| 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 Georgi | b890a12 | 2015-03-26 15:17:45 +0100 | [diff] [blame] | 17 | * Foundation, Inc. |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 18 | */ |
| 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 Durbin | bd74a4b | 2015-03-06 23:17:33 -0600 | [diff] [blame] | 28 | #include <cbfs.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 29 | #include <cbmem.h> |
| 30 | #include <cpu/x86/mtrr.h> |
| 31 | #include <elog.h> |
Vladimir Serbinenko | 0e90dae | 2015-05-18 10:29:06 +0200 | [diff] [blame^] | 32 | #include <tpm.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 33 | #include <romstage_handoff.h> |
Aaron Durbin | bd74a4b | 2015-03-06 23:17:33 -0600 | [diff] [blame] | 34 | #include <stage_cache.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 35 | #include <timestamp.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 36 | #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 Georgi | 3e18aca | 2015-04-29 18:59:04 +0200 | [diff] [blame] | 42 | #include <vendorcode/google/chromeos/chromeos.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 43 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 44 | /* Entry from cache-as-ram.inc. */ |
| 45 | void * 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älkki | 4175927 | 2014-12-31 21:11:51 +0200 | [diff] [blame] | 56 | timestamp_init((((uint64_t)tsc_hi) << 32) | (uint64_t)tsc_low); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 57 | |
| 58 | /* Save romstage begin */ |
Kyösti Mälkki | 4175927 | 2014-12-31 21:11:51 +0200 | [diff] [blame] | 59 | timestamp_add_now(TS_START_ROMSTAGE); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 60 | |
| 61 | /* System Agent Early Initialization */ |
| 62 | systemagent_early_init(); |
| 63 | |
| 64 | /* PCH Early Initialization */ |
| 65 | pch_early_init(); |
| 66 | |
Wenkai Du | 1006b10 | 2014-11-05 21:10:57 -0800 | [diff] [blame] | 67 | /* Call into mainboard pre console init. Needed to enable serial port |
| 68 | on IT8772 */ |
| 69 | mainboard_pre_console_init(); |
| 70 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 71 | /* Start console drivers */ |
| 72 | console_init(); |
| 73 | |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 74 | /* Get power state */ |
| 75 | rp.power_state = fill_power_state(); |
| 76 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 77 | /* 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 Lin | b2deb22 | 2015-01-18 21:32:44 +0800 | [diff] [blame] | 86 | #if CONFIG_CHROMEOS |
| 87 | save_chromeos_gpios(); |
| 88 | #endif |
| 89 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 90 | return setup_stack_and_mttrs(); |
| 91 | } |
| 92 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 93 | /* Entry from the mainboard. */ |
| 94 | void romstage_common(struct romstage_params *params) |
| 95 | { |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 96 | struct romstage_handoff *handoff; |
| 97 | |
| 98 | post_code(0x32); |
| 99 | |
Kyösti Mälkki | 4175927 | 2014-12-31 21:11:51 +0200 | [diff] [blame] | 100 | timestamp_add_now(TS_BEFORE_INITRAM); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 101 | |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 102 | params->pei_data->boot_mode = params->power_state->prev_sleep_state; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 103 | |
| 104 | #if CONFIG_ELOG_BOOT_COUNT |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 105 | if (params->power_state->prev_sleep_state != SLEEP_STATE_S3) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 106 | boot_count_increment(); |
| 107 | #endif |
| 108 | |
| 109 | /* Print ME state before MRC */ |
| 110 | intel_me_status(); |
| 111 | |
Duncan Laurie | a7d8ea8 | 2014-08-26 13:49:24 -0700 | [diff] [blame] | 112 | /* Save ME HSIO version */ |
| 113 | intel_me_hsio_version(¶ms->power_state->hsio_version, |
| 114 | ¶ms->power_state->hsio_checksum); |
| 115 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 116 | /* Initialize RAM */ |
| 117 | raminit(params->pei_data); |
Kyösti Mälkki | 4175927 | 2014-12-31 21:11:51 +0200 | [diff] [blame] | 118 | |
| 119 | timestamp_add_now(TS_AFTER_INITRAM); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 120 | |
| 121 | handoff = romstage_handoff_find_or_add(); |
| 122 | if (handoff != NULL) |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 123 | handoff->s3_resume = (params->power_state->prev_sleep_state == |
| 124 | SLEEP_STATE_S3); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 125 | else |
| 126 | printk(BIOS_DEBUG, "Romstage handoff structure not added!\n"); |
| 127 | |
Vladimir Serbinenko | 0e90dae | 2015-05-18 10:29:06 +0200 | [diff] [blame^] | 128 | #if CONFIG_LPC_TPM |
| 129 | init_tpm(prev_sleep_state == SLEEP_STATE_S3); |
| 130 | #endif |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | void asmlinkage romstage_after_car(void) |
| 134 | { |
| 135 | timestamp_add_now(TS_END_ROMSTAGE); |
| 136 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 137 | /* Load the ramstage. */ |
| 138 | copy_and_run(); |
| 139 | while (1); |
| 140 | } |
| 141 | |
Aaron Durbin | bd74a4b | 2015-03-06 23:17:33 -0600 | [diff] [blame] | 142 | void ramstage_cache_invalid(void) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 143 | { |
| 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 |
| 151 | int 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 Du | 1006b10 | 2014-11-05 21:10:57 -0800 | [diff] [blame] | 157 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 158 | #endif |
Wenkai Du | 1006b10 | 2014-11-05 21:10:57 -0800 | [diff] [blame] | 159 | void __attribute__((weak)) mainboard_pre_console_init(void) {} |