blob: 3cbdf44c1d051842f01ea23595cb48b8108778cd [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 Durbin3d0071b2013-01-18 14:32:50 -060017#include <console/console.h>
Aaron Durbina2671612013-02-06 21:41:01 -060018#include <arch/cpu.h>
Patrick Rudolph45022ae2018-10-01 19:17:11 +020019#include <cf9_reset.h>
Aaron Durbina2671612013-02-06 21:41:01 -060020#include <cpu/x86/bist.h>
21#include <cpu/x86/msr.h>
Aaron Durbin38d94232013-02-07 00:03:33 -060022#include <cpu/x86/mtrr.h>
Aaron Durbina2671612013-02-06 21:41:01 -060023#include <timestamp.h>
Aaron Durbina2671612013-02-06 21:41:01 -060024#include <device/pci_def.h>
25#include <cpu/x86/lapic.h>
Kyösti Mälkki465eff62016-06-15 06:07:55 +030026#include <cbmem.h>
Elyes HAOUASd26844c2019-06-21 07:31:40 +020027#include <commonlib/helpers.h>
Kyösti Mälkki65e8f642016-06-27 11:27:56 +030028#include <program_loading.h>
Aaron Durbinbf396ff2013-02-11 21:50:35 -060029#include <romstage_handoff.h>
Aaron Durbina2671612013-02-06 21:41:01 -060030#include <vendorcode/google/chromeos/chromeos.h>
Julius Wernercd49cce2019-03-05 16:53:33 -080031#if CONFIG(EC_GOOGLE_CHROMEEC)
Duncan Laurie7cced0d2013-06-04 10:03:34 -070032#include <ec/google/chromeec/ec.h>
33#endif
Elyes HAOUAS65bb5432018-07-03 14:59:50 +020034#include <northbridge/intel/haswell/haswell.h>
35#include <northbridge/intel/haswell/raminit.h>
36#include <southbridge/intel/lynxpoint/pch.h>
37#include <southbridge/intel/lynxpoint/me.h>
Arthur Heymansfaa5f982018-06-04 19:34:59 +020038#include <cpu/intel/romstage.h>
Elyes HAOUAS65bb5432018-07-03 14:59:50 +020039#include "haswell.h"
Aaron Durbina2671612013-02-06 21:41:01 -060040
Arthur Heymans88af0f32018-06-03 12:37:54 +020041#define ROMSTAGE_RAM_STACK_SIZE 0x5000
Aaron Durbin3d0071b2013-01-18 14:32:50 -060042
Arthur Heymans88af0f32018-06-03 12:37:54 +020043/* platform_enter_postcar() determines the stack to use after
44 * cache-as-ram is torn down as well as the MTRR settings to use,
45 * and continues execution in postcar stage. */
Arthur Heymansfaa5f982018-06-04 19:34:59 +020046void platform_enter_postcar(void)
Aaron Durbin38d94232013-02-07 00:03:33 -060047{
Arthur Heymans88af0f32018-06-03 12:37:54 +020048 struct postcar_frame pcf;
49 uintptr_t top_of_ram;
Aaron Durbin38d94232013-02-07 00:03:33 -060050
Arthur Heymans88af0f32018-06-03 12:37:54 +020051 if (postcar_frame_init(&pcf, ROMSTAGE_RAM_STACK_SIZE))
52 die("Unable to initialize postcar frame.\n");
Aaron Durbin38d94232013-02-07 00:03:33 -060053 /* Cache the ROM as WP just below 4GiB. */
Nico Huber4c7eee22019-02-10 19:35:41 +010054 postcar_frame_add_romcache(&pcf, MTRR_TYPE_WRPROT);
Aaron Durbin38d94232013-02-07 00:03:33 -060055
Kyösti Mälkki65cc5262016-06-19 20:38:41 +030056 /* Cache RAM as WB from 0 -> CACHE_TMP_RAMTOP. */
Arthur Heymans88af0f32018-06-03 12:37:54 +020057 postcar_frame_add_mtrr(&pcf, 0, CACHE_TMP_RAMTOP, MTRR_TYPE_WRBACK);
Aaron Durbin38d94232013-02-07 00:03:33 -060058
Arthur Heymans88af0f32018-06-03 12:37:54 +020059 /* Cache at least 8 MiB below the top of ram, and at most 8 MiB
60 * above top of the ram. This satisfies MTRR alignment requirement
61 * with different TSEG size configurations.
62 */
63 top_of_ram = ALIGN_DOWN((uintptr_t)cbmem_top(), 8*MiB);
64 postcar_frame_add_mtrr(&pcf, top_of_ram - 8*MiB, 16*MiB,
65 MTRR_TYPE_WRBACK);
Aaron Durbin67481ddc2013-02-15 15:08:37 -060066
Arthur Heymans88af0f32018-06-03 12:37:54 +020067 run_postcar_phase(&pcf);
Aaron Durbin38d94232013-02-07 00:03:33 -060068}
69
Aaron Durbina2671612013-02-06 21:41:01 -060070void romstage_common(const struct romstage_params *params)
71{
Aaron Durbinbf396ff2013-02-11 21:50:35 -060072 int boot_mode;
Aaron Durbina2671612013-02-06 21:41:01 -060073 int wake_from_s3;
Aaron Durbina2671612013-02-06 21:41:01 -060074
Aaron Durbina2671612013-02-06 21:41:01 -060075 if (params->bist == 0)
76 enable_lapic();
77
78 wake_from_s3 = early_pch_init(params->gpio_map, params->rcba_config);
79
80 /* Halt if there was a built in self test failure */
81 report_bist_failure(params->bist);
82
83 /* Perform some early chipset initialization required
84 * before RAM initialization can work
85 */
86 haswell_early_initialization(HASWELL_MOBILE);
87 printk(BIOS_DEBUG, "Back from haswell_early_initialization()\n");
88
89 if (wake_from_s3) {
Julius Wernercd49cce2019-03-05 16:53:33 -080090#if CONFIG(HAVE_ACPI_RESUME)
Aaron Durbina2671612013-02-06 21:41:01 -060091 printk(BIOS_DEBUG, "Resume from S3 detected.\n");
Aaron Durbina2671612013-02-06 21:41:01 -060092#else
93 printk(BIOS_DEBUG, "Resume from S3 detected, but disabled.\n");
Aaron Durbinbf396ff2013-02-11 21:50:35 -060094 wake_from_s3 = 0;
Aaron Durbina2671612013-02-06 21:41:01 -060095#endif
96 }
97
Aaron Durbinbf396ff2013-02-11 21:50:35 -060098 /* There are hard coded assumptions of 2 meaning s3 wake. Normalize
99 * the users of the 2 literal here based off wake_from_s3. */
100 boot_mode = wake_from_s3 ? 2 : 0;
101
Aaron Durbina2671612013-02-06 21:41:01 -0600102 /* Prepare USB controller early in S3 resume */
Aaron Durbinbf396ff2013-02-11 21:50:35 -0600103 if (wake_from_s3)
Aaron Durbina2671612013-02-06 21:41:01 -0600104 enable_usb_bar();
105
106 post_code(0x3a);
107 params->pei_data->boot_mode = boot_mode;
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300108
109 timestamp_add_now(TS_BEFORE_INITRAM);
Aaron Durbina2671612013-02-06 21:41:01 -0600110
111 report_platform_info();
112
Aaron Durbinc7633f42013-06-13 17:29:36 -0700113 if (params->copy_spd != NULL)
114 params->copy_spd(params->pei_data);
115
Aaron Durbina2671612013-02-06 21:41:01 -0600116 sdram_initialize(params->pei_data);
117
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300118 timestamp_add_now(TS_AFTER_INITRAM);
119
Aaron Durbina2671612013-02-06 21:41:01 -0600120 post_code(0x3b);
121
122 intel_early_me_status();
123
Aaron Durbinc0cbd6e2013-03-13 13:51:20 -0500124 if (!wake_from_s3) {
125 cbmem_initialize_empty();
126 /* Save data returned from MRC on non-S3 resumes. */
Aaron Durbin2ad1dba2013-02-07 00:51:18 -0600127 save_mrc_data(params->pei_data);
Aaron Durbin42e68562015-06-09 13:55:51 -0500128 } else if (cbmem_initialize()) {
Julius Wernercd49cce2019-03-05 16:53:33 -0800129 #if CONFIG(HAVE_ACPI_RESUME)
Aaron Durbin42e68562015-06-09 13:55:51 -0500130 /* Failed S3 resume, reset to come up cleanly */
Patrick Rudolph45022ae2018-10-01 19:17:11 +0200131 system_reset();
Aaron Durbin42e68562015-06-09 13:55:51 -0500132 #endif
Aaron Durbina2671612013-02-06 21:41:01 -0600133 }
Aaron Durbinbf396ff2013-02-11 21:50:35 -0600134
Tristan Corrick334be322018-12-17 22:10:21 +1300135 haswell_unhide_peg();
136
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -0500137 setup_sdram_meminfo(params->pei_data);
138
Aaron Durbin77e13992016-11-29 17:43:04 -0600139 romstage_handoff_init(wake_from_s3);
Aaron Durbinbf396ff2013-02-11 21:50:35 -0600140
Aaron Durbina2671612013-02-06 21:41:01 -0600141 post_code(0x3f);
Aaron Durbina2671612013-02-06 21:41:01 -0600142}