blob: 9aa31b85c1ab5c7100ce938984137d4585427abb [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.
Duncan Lauriec88c54c2014-04-30 16:36:13 -070014 */
15
16#include <stddef.h>
17#include <stdint.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070018#include <arch/cbfs.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070019#include <arch/early_variables.h>
Kyösti Mälkkic641f7e2018-12-28 16:54:54 +020020#include <bootblock_common.h>
Julius Wernerb04cc6b2017-03-17 14:14:14 -070021#include <bootmode.h>
Arthur Heymans90cca542018-11-29 13:36:54 +010022#include <cbmem.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070023#include <console/console.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070024#include <cpu/x86/mtrr.h>
25#include <elog.h>
Kyösti Mälkki65e8f642016-06-27 11:27:56 +030026#include <program_loading.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070027#include <romstage_handoff.h>
Aaron Durbinbd74a4b2015-03-06 23:17:33 -060028#include <stage_cache.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070029#include <timestamp.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070030#include <soc/me.h>
31#include <soc/pei_data.h>
32#include <soc/pm.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070033#include <soc/romstage.h>
34#include <soc/spi.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070035
Arthur Heymans90cca542018-11-29 13:36:54 +010036#define ROMSTAGE_RAM_STACK_SIZE 0x5000
37
38/* platform_enter_postcar() determines the stack to use after
39 * cache-as-ram is torn down as well as the MTRR settings to use,
40 * and continues execution in postcar stage. */
41static void platform_enter_postcar(void)
42{
43 struct postcar_frame pcf;
44 uintptr_t top_of_ram;
45
46 if (postcar_frame_init(&pcf, ROMSTAGE_RAM_STACK_SIZE))
47 die("Unable to initialize postcar frame.\n");
48 /* Cache the ROM as WP just below 4GiB. */
Nico Huber4c7eee22019-02-10 19:35:41 +010049 postcar_frame_add_romcache(&pcf, MTRR_TYPE_WRPROT);
Arthur Heymans90cca542018-11-29 13:36:54 +010050
51 /* Cache RAM as WB from 0 -> CACHE_TMP_RAMTOP. */
52 postcar_frame_add_mtrr(&pcf, 0, CACHE_TMP_RAMTOP, MTRR_TYPE_WRBACK);
53
54 /* Cache at least 8 MiB below the top of ram, and at most 8 MiB
55 * above top of the ram. This satisfies MTRR alignment requirement
56 * with different TSEG size configurations.
57 */
58 top_of_ram = ALIGN_DOWN((uintptr_t)cbmem_top(), 8*MiB);
59 postcar_frame_add_mtrr(&pcf, top_of_ram - 8*MiB, 16*MiB,
60 MTRR_TYPE_WRBACK);
61
62 run_postcar_phase(&pcf);
63}
64
Duncan Lauriec88c54c2014-04-30 16:36:13 -070065/* Entry from cache-as-ram.inc. */
Kyösti Mälkkic641f7e2018-12-28 16:54:54 +020066static void romstage_main(uint64_t tsc, uint32_t bist)
Duncan Lauriec88c54c2014-04-30 16:36:13 -070067{
68 struct romstage_params rp = {
69 .bist = bist,
70 .pei_data = NULL,
71 };
72
73 post_code(0x30);
74
75 /* Save initial timestamp from bootblock. */
Kyösti Mälkkic641f7e2018-12-28 16:54:54 +020076 timestamp_init(tsc);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070077
78 /* Save romstage begin */
Kyösti Mälkki41759272014-12-31 21:11:51 +020079 timestamp_add_now(TS_START_ROMSTAGE);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070080
81 /* System Agent Early Initialization */
82 systemagent_early_init();
83
84 /* PCH Early Initialization */
85 pch_early_init();
86
Wenkai Du1006b102014-11-05 21:10:57 -080087 /* Call into mainboard pre console init. Needed to enable serial port
88 on IT8772 */
89 mainboard_pre_console_init();
90
Duncan Lauriec88c54c2014-04-30 16:36:13 -070091 /* Start console drivers */
92 console_init();
93
Duncan Laurie61680272014-05-05 12:42:35 -050094 /* Get power state */
95 rp.power_state = fill_power_state();
96
Duncan Lauriec88c54c2014-04-30 16:36:13 -070097 /* Print useful platform information */
98 report_platform_info();
99
100 /* Set CPU frequency to maximum */
101 set_max_freq();
102
103 /* Call into mainboard. */
104 mainboard_romstage_entry(&rp);
105
Arthur Heymans90cca542018-11-29 13:36:54 +0100106 platform_enter_postcar();
Kyösti Mälkkic641f7e2018-12-28 16:54:54 +0200107}
Arthur Heymans90cca542018-11-29 13:36:54 +0100108
Kyösti Mälkkic641f7e2018-12-28 16:54:54 +0200109/* This wrapper enables easy transition towards C_ENVIRONMENT_BOOTBLOCK,
110 * keeping changes in cache_as_ram.S easy to manage.
111 */
112asmlinkage void bootblock_c_entry_bist(uint64_t base_timestamp, uint32_t bist)
113{
114 romstage_main(base_timestamp, bist);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700115}
116
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700117/* Entry from the mainboard. */
118void romstage_common(struct romstage_params *params)
119{
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700120 post_code(0x32);
121
Kyösti Mälkki41759272014-12-31 21:11:51 +0200122 timestamp_add_now(TS_BEFORE_INITRAM);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700123
Duncan Laurie61680272014-05-05 12:42:35 -0500124 params->pei_data->boot_mode = params->power_state->prev_sleep_state;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700125
Martin Rothe6ff1592017-06-24 21:34:29 -0600126#if IS_ENABLED(CONFIG_ELOG_BOOT_COUNT)
Aaron Durbin9e6d1432016-07-13 23:21:41 -0500127 if (params->power_state->prev_sleep_state != ACPI_S3)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700128 boot_count_increment();
129#endif
130
131 /* Print ME state before MRC */
132 intel_me_status();
133
Duncan Lauriea7d8ea82014-08-26 13:49:24 -0700134 /* Save ME HSIO version */
135 intel_me_hsio_version(&params->power_state->hsio_version,
136 &params->power_state->hsio_checksum);
137
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700138 /* Initialize RAM */
139 raminit(params->pei_data);
Kyösti Mälkki41759272014-12-31 21:11:51 +0200140
141 timestamp_add_now(TS_AFTER_INITRAM);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700142
Aaron Durbin77e13992016-11-29 17:43:04 -0600143 romstage_handoff_init(params->power_state->prev_sleep_state == ACPI_S3);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700144}
145
Aaron Durbin64031672018-04-21 14:45:32 -0600146void __weak mainboard_pre_console_init(void) {}