blob: 688f3579db64e5fdec5759b456268393ccc029f2 [file] [log] [blame]
Aaron Durbin3d0071b2013-01-18 14:32:50 -06001/*
2 * This file is part of the coreboot project.
3 *
Patrick Georgi5b2a2d02018-09-26 20:46:04 +02004 * Copyright (C) 2012 Google LLC
Aaron Durbin3d0071b2013-01-18 14:32:50 -06005 *
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 Durbin3d0071b2013-01-18 14:32:50 -060018#include <console/console.h>
Aaron Durbina2671612013-02-06 21:41:01 -060019#include <arch/cpu.h>
Patrick Rudolph45022ae2018-10-01 19:17:11 +020020#include <cf9_reset.h>
Aaron Durbina2671612013-02-06 21:41:01 -060021#include <cpu/x86/bist.h>
22#include <cpu/x86/msr.h>
Aaron Durbin38d94232013-02-07 00:03:33 -060023#include <cpu/x86/mtrr.h>
Patrick Georgibd79c5e2014-11-28 22:35:36 +010024#include <halt.h>
Aaron Durbina2671612013-02-06 21:41:01 -060025#include <lib.h>
26#include <timestamp.h>
Kyösti Mälkkia969ed32016-06-15 06:08:15 +030027#include <arch/acpi.h>
Aaron Durbina2671612013-02-06 21:41:01 -060028#include <arch/io.h>
Aaron Durbina2671612013-02-06 21:41:01 -060029#include <device/pci_def.h>
30#include <cpu/x86/lapic.h>
Kyösti Mälkki465eff62016-06-15 06:07:55 +030031#include <cbmem.h>
Kyösti Mälkki65e8f642016-06-27 11:27:56 +030032#include <program_loading.h>
Aaron Durbinbf396ff2013-02-11 21:50:35 -060033#include <romstage_handoff.h>
Aaron Durbina2671612013-02-06 21:41:01 -060034#include <vendorcode/google/chromeos/chromeos.h>
Martin Rothffdee282017-06-24 13:43:40 -060035#if IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC)
Duncan Laurie7cced0d2013-06-04 10:03:34 -070036#include <ec/google/chromeec/ec.h>
37#endif
Elyes HAOUAS65bb5432018-07-03 14:59:50 +020038#include <northbridge/intel/haswell/haswell.h>
39#include <northbridge/intel/haswell/raminit.h>
40#include <southbridge/intel/lynxpoint/pch.h>
41#include <southbridge/intel/lynxpoint/me.h>
Arthur Heymansfaa5f982018-06-04 19:34:59 +020042#include <cpu/intel/romstage.h>
Elyes HAOUAS65bb5432018-07-03 14:59:50 +020043#include "haswell.h"
Aaron Durbina2671612013-02-06 21:41:01 -060044
Arthur Heymans88af0f32018-06-03 12:37:54 +020045#define ROMSTAGE_RAM_STACK_SIZE 0x5000
Aaron Durbin3d0071b2013-01-18 14:32:50 -060046
Arthur Heymans88af0f32018-06-03 12:37:54 +020047/* platform_enter_postcar() determines the stack to use after
48 * cache-as-ram is torn down as well as the MTRR settings to use,
49 * and continues execution in postcar stage. */
Arthur Heymansfaa5f982018-06-04 19:34:59 +020050void platform_enter_postcar(void)
Aaron Durbin38d94232013-02-07 00:03:33 -060051{
Arthur Heymans88af0f32018-06-03 12:37:54 +020052 struct postcar_frame pcf;
53 uintptr_t top_of_ram;
Aaron Durbin38d94232013-02-07 00:03:33 -060054
Arthur Heymans88af0f32018-06-03 12:37:54 +020055 if (postcar_frame_init(&pcf, ROMSTAGE_RAM_STACK_SIZE))
56 die("Unable to initialize postcar frame.\n");
Aaron Durbin38d94232013-02-07 00:03:33 -060057 /* Cache the ROM as WP just below 4GiB. */
Arthur Heymans88af0f32018-06-03 12:37:54 +020058 postcar_frame_add_mtrr(&pcf, CACHE_ROM_BASE, CACHE_ROM_SIZE,
59 MTRR_TYPE_WRPROT);
Aaron Durbin38d94232013-02-07 00:03:33 -060060
Kyösti Mälkki65cc5262016-06-19 20:38:41 +030061 /* Cache RAM as WB from 0 -> CACHE_TMP_RAMTOP. */
Arthur Heymans88af0f32018-06-03 12:37:54 +020062 postcar_frame_add_mtrr(&pcf, 0, CACHE_TMP_RAMTOP, MTRR_TYPE_WRBACK);
Aaron Durbin38d94232013-02-07 00:03:33 -060063
Arthur Heymans88af0f32018-06-03 12:37:54 +020064 /* Cache at least 8 MiB below the top of ram, and at most 8 MiB
65 * above top of the ram. This satisfies MTRR alignment requirement
66 * with different TSEG size configurations.
67 */
68 top_of_ram = ALIGN_DOWN((uintptr_t)cbmem_top(), 8*MiB);
69 postcar_frame_add_mtrr(&pcf, top_of_ram - 8*MiB, 16*MiB,
70 MTRR_TYPE_WRBACK);
Aaron Durbin67481ddc2013-02-15 15:08:37 -060071
Arthur Heymans88af0f32018-06-03 12:37:54 +020072 run_postcar_phase(&pcf);
Aaron Durbin38d94232013-02-07 00:03:33 -060073}
74
Aaron Durbina2671612013-02-06 21:41:01 -060075void romstage_common(const struct romstage_params *params)
76{
Aaron Durbinbf396ff2013-02-11 21:50:35 -060077 int boot_mode;
Aaron Durbina2671612013-02-06 21:41:01 -060078 int wake_from_s3;
Aaron Durbina2671612013-02-06 21:41:01 -060079
Kyösti Mälkki3d45c402013-09-07 20:26:36 +030080 timestamp_init(get_initial_timestamp());
81 timestamp_add_now(TS_START_ROMSTAGE);
Aaron Durbina2671612013-02-06 21:41:01 -060082
83 if (params->bist == 0)
84 enable_lapic();
85
86 wake_from_s3 = early_pch_init(params->gpio_map, params->rcba_config);
87
88 /* Halt if there was a built in self test failure */
89 report_bist_failure(params->bist);
90
91 /* Perform some early chipset initialization required
92 * before RAM initialization can work
93 */
94 haswell_early_initialization(HASWELL_MOBILE);
95 printk(BIOS_DEBUG, "Back from haswell_early_initialization()\n");
96
97 if (wake_from_s3) {
Martin Rothffdee282017-06-24 13:43:40 -060098#if IS_ENABLED(CONFIG_HAVE_ACPI_RESUME)
Aaron Durbina2671612013-02-06 21:41:01 -060099 printk(BIOS_DEBUG, "Resume from S3 detected.\n");
Aaron Durbina2671612013-02-06 21:41:01 -0600100#else
101 printk(BIOS_DEBUG, "Resume from S3 detected, but disabled.\n");
Aaron Durbinbf396ff2013-02-11 21:50:35 -0600102 wake_from_s3 = 0;
Aaron Durbina2671612013-02-06 21:41:01 -0600103#endif
104 }
105
Aaron Durbinbf396ff2013-02-11 21:50:35 -0600106 /* There are hard coded assumptions of 2 meaning s3 wake. Normalize
107 * the users of the 2 literal here based off wake_from_s3. */
108 boot_mode = wake_from_s3 ? 2 : 0;
109
Aaron Durbina2671612013-02-06 21:41:01 -0600110 /* Prepare USB controller early in S3 resume */
Aaron Durbinbf396ff2013-02-11 21:50:35 -0600111 if (wake_from_s3)
Aaron Durbina2671612013-02-06 21:41:01 -0600112 enable_usb_bar();
113
114 post_code(0x3a);
115 params->pei_data->boot_mode = boot_mode;
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300116
117 timestamp_add_now(TS_BEFORE_INITRAM);
Aaron Durbina2671612013-02-06 21:41:01 -0600118
119 report_platform_info();
120
Aaron Durbinc7633f42013-06-13 17:29:36 -0700121 if (params->copy_spd != NULL)
122 params->copy_spd(params->pei_data);
123
Aaron Durbina2671612013-02-06 21:41:01 -0600124 sdram_initialize(params->pei_data);
125
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300126 timestamp_add_now(TS_AFTER_INITRAM);
127
Aaron Durbina2671612013-02-06 21:41:01 -0600128 post_code(0x3b);
129
130 intel_early_me_status();
131
132 quick_ram_check();
133 post_code(0x3e);
134
Aaron Durbinc0cbd6e2013-03-13 13:51:20 -0500135 if (!wake_from_s3) {
136 cbmem_initialize_empty();
137 /* Save data returned from MRC on non-S3 resumes. */
Aaron Durbin2ad1dba2013-02-07 00:51:18 -0600138 save_mrc_data(params->pei_data);
Aaron Durbin42e68562015-06-09 13:55:51 -0500139 } else if (cbmem_initialize()) {
Martin Rothffdee282017-06-24 13:43:40 -0600140 #if IS_ENABLED(CONFIG_HAVE_ACPI_RESUME)
Aaron Durbin42e68562015-06-09 13:55:51 -0500141 /* Failed S3 resume, reset to come up cleanly */
Patrick Rudolph45022ae2018-10-01 19:17:11 +0200142 system_reset();
Aaron Durbin42e68562015-06-09 13:55:51 -0500143 #endif
Aaron Durbina2671612013-02-06 21:41:01 -0600144 }
Aaron Durbinbf396ff2013-02-11 21:50:35 -0600145
Tristan Corrick334be322018-12-17 22:10:21 +1300146 haswell_unhide_peg();
147
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -0500148 setup_sdram_meminfo(params->pei_data);
149
Aaron Durbin77e13992016-11-29 17:43:04 -0600150 romstage_handoff_init(wake_from_s3);
Aaron Durbinbf396ff2013-02-11 21:50:35 -0600151
Aaron Durbina2671612013-02-06 21:41:01 -0600152 post_code(0x3f);
Aaron Durbina2671612013-02-06 21:41:01 -0600153}