blob: 3227c02287f83f927ba0ed133ea61ac6dd041d98 [file] [log] [blame]
Angel Ponsf23ae0b2020-04-02 23:48:12 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Aaron Durbin3d0071b2013-01-18 14:32:50 -06002
Angel Pons45f448f2020-07-03 14:46:47 +02003#include <arch/romstage.h>
Aaron Durbin3d0071b2013-01-18 14:32:50 -06004#include <console/console.h>
Patrick Rudolph45022ae2018-10-01 19:17:11 +02005#include <cf9_reset.h>
Angel Pons39a60932020-07-04 01:07:24 +02006#include <device/device.h>
Angel Pons6c49f402020-08-28 02:02:00 +02007#include <device/mmio.h>
Aaron Durbina2671612013-02-06 21:41:01 -06008#include <timestamp.h>
Aaron Durbina2671612013-02-06 21:41:01 -06009#include <cpu/x86/lapic.h>
Kyösti Mälkki465eff62016-06-15 06:07:55 +030010#include <cbmem.h>
Elyes HAOUASd26844c2019-06-21 07:31:40 +020011#include <commonlib/helpers.h>
Aaron Durbinbf396ff2013-02-11 21:50:35 -060012#include <romstage_handoff.h>
Angel Pons6c49f402020-08-28 02:02:00 +020013#include <security/intel/txt/txt.h>
14#include <security/intel/txt/txt_register.h>
Angel Pons2e25ac62020-07-03 12:06:04 +020015#include <cpu/intel/haswell/haswell.h>
Angel Pons8aab7872020-07-04 01:24:59 +020016#include <northbridge/intel/haswell/chip.h>
Elyes HAOUAS65bb5432018-07-03 14:59:50 +020017#include <northbridge/intel/haswell/haswell.h>
18#include <northbridge/intel/haswell/raminit.h>
19#include <southbridge/intel/lynxpoint/pch.h>
20#include <southbridge/intel/lynxpoint/me.h>
Aaron Durbina2671612013-02-06 21:41:01 -060021
Angel Pons6eea1912020-07-03 14:14:30 +020022/* Copy SPD data for on-board memory */
23void __weak copy_spd(struct pei_data *peid)
24{
25}
26
Angel Pons73fa0352020-07-03 12:29:03 +020027void __weak mb_late_romstage_setup(void)
28{
29}
30
Angel Ponsd7bf3ad2020-07-03 20:31:39 +020031/*
32 * 0 = leave channel enabled
33 * 1 = disable dimm 0 on channel
34 * 2 = disable dimm 1 on channel
35 * 3 = disable dimm 0+1 on channel
36 */
37static int make_channel_disabled_mask(const struct pei_data *pd, int ch)
38{
39 return (!pd->spd_addresses[ch + ch] << 0) | (!pd->spd_addresses[ch + ch + 1] << 1);
40}
41
Angel Pons45f448f2020-07-03 14:46:47 +020042/* The romstage entry point for this platform is not mainboard-specific, hence the name */
43void mainboard_romstage_entry(void)
Aaron Durbina2671612013-02-06 21:41:01 -060044{
Angel Pons39a60932020-07-04 01:07:24 +020045 const struct device *gbe = pcidev_on_root(0x19, 0);
46
Angel Pons8aab7872020-07-04 01:24:59 +020047 const struct northbridge_intel_haswell_config *cfg = config_of_soc();
48
Aaron Durbina2671612013-02-06 21:41:01 -060049 int wake_from_s3;
Aaron Durbina2671612013-02-06 21:41:01 -060050
Angel Pons45f448f2020-07-03 14:46:47 +020051 struct pei_data pei_data = {
Angel Ponsae0eeb22020-07-04 01:38:03 +020052 .pei_version = PEI_VERSION,
53 .mchbar = (uintptr_t)DEFAULT_MCHBAR,
54 .dmibar = (uintptr_t)DEFAULT_DMIBAR,
55 .epbar = DEFAULT_EPBAR,
56 .pciexbar = CONFIG_MMCONF_BASE_ADDRESS,
Angel Ponsb21bffa2020-07-03 01:02:28 +020057 .smbusbar = CONFIG_FIXED_SMBUS_IO_BASE,
Angel Ponsae0eeb22020-07-04 01:38:03 +020058 .hpet_address = HPET_ADDR,
59 .rcba = (uintptr_t)DEFAULT_RCBA,
60 .pmbase = DEFAULT_PMBASE,
61 .gpiobase = DEFAULT_GPIOBASE,
62 .temp_mmio_base = 0xfed08000,
63 .system_type = get_pch_platform_type(),
64 .tseg_size = CONFIG_SMM_TSEG_SIZE,
65 .ec_present = cfg->ec_present,
66 .gbe_enable = gbe && gbe->enabled,
67 .ddr_refresh_2x = CONFIG(ENABLE_DDR_2X_REFRESH),
68 .dq_pins_interleaved = cfg->dq_pins_interleaved,
69 .max_ddr3_freq = 1600,
70 .usb_xhci_on_resume = cfg->usb_xhci_on_resume,
Angel Pons45f448f2020-07-03 14:46:47 +020071 };
72
73 mainboard_fill_pei_data(&pei_data);
74
Kyösti Mälkki157b1892019-08-16 14:02:25 +030075 enable_lapic();
Aaron Durbina2671612013-02-06 21:41:01 -060076
Angel Pons03f0e432020-07-03 13:51:15 +020077 wake_from_s3 = early_pch_init();
Aaron Durbina2671612013-02-06 21:41:01 -060078
Aaron Durbina2671612013-02-06 21:41:01 -060079 /* Perform some early chipset initialization required
80 * before RAM initialization can work
81 */
Angel Ponse8168292020-07-03 11:42:22 +020082 haswell_early_initialization();
Aaron Durbina2671612013-02-06 21:41:01 -060083 printk(BIOS_DEBUG, "Back from haswell_early_initialization()\n");
84
85 if (wake_from_s3) {
Julius Wernercd49cce2019-03-05 16:53:33 -080086#if CONFIG(HAVE_ACPI_RESUME)
Aaron Durbina2671612013-02-06 21:41:01 -060087 printk(BIOS_DEBUG, "Resume from S3 detected.\n");
Aaron Durbina2671612013-02-06 21:41:01 -060088#else
89 printk(BIOS_DEBUG, "Resume from S3 detected, but disabled.\n");
Aaron Durbinbf396ff2013-02-11 21:50:35 -060090 wake_from_s3 = 0;
Aaron Durbina2671612013-02-06 21:41:01 -060091#endif
92 }
93
94 /* Prepare USB controller early in S3 resume */
Aaron Durbinbf396ff2013-02-11 21:50:35 -060095 if (wake_from_s3)
Aaron Durbina2671612013-02-06 21:41:01 -060096 enable_usb_bar();
97
98 post_code(0x3a);
Angel Pons284a5472020-07-03 11:46:50 +020099
100 /* MRC has hardcoded assumptions of 2 meaning S3 wake. Normalize it here. */
Angel Pons45f448f2020-07-03 14:46:47 +0200101 pei_data.boot_mode = wake_from_s3 ? 2 : 0;
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300102
Angel Ponsd37b7d82020-07-03 23:52:34 +0200103 /* Obtain the SPD addresses from mainboard code */
104 mb_get_spd_map(pei_data.spd_addresses);
105
Angel Ponsd7bf3ad2020-07-03 20:31:39 +0200106 /* Calculate unimplemented DIMM slots for each channel */
107 pei_data.dimm_channel0_disabled = make_channel_disabled_mask(&pei_data, 0);
108 pei_data.dimm_channel1_disabled = make_channel_disabled_mask(&pei_data, 1);
109
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300110 timestamp_add_now(TS_BEFORE_INITRAM);
Aaron Durbina2671612013-02-06 21:41:01 -0600111
112 report_platform_info();
113
Angel Pons6c49f402020-08-28 02:02:00 +0200114 if (CONFIG(INTEL_TXT))
115 intel_txt_romstage_init();
116
Angel Pons45f448f2020-07-03 14:46:47 +0200117 copy_spd(&pei_data);
Aaron Durbinc7633f42013-06-13 17:29:36 -0700118
Angel Pons45f448f2020-07-03 14:46:47 +0200119 sdram_initialize(&pei_data);
Aaron Durbina2671612013-02-06 21:41:01 -0600120
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300121 timestamp_add_now(TS_AFTER_INITRAM);
122
Angel Pons6c49f402020-08-28 02:02:00 +0200123 if (CONFIG(INTEL_TXT)) {
124 printk(BIOS_DEBUG, "Check TXT_ERROR register after MRC\n");
125
126 intel_txt_log_acm_error(read32((void *)TXT_ERROR));
127
128 intel_txt_log_spad();
129
130 intel_txt_memory_has_secrets();
131
132 txt_dump_regions();
133 }
134
Aaron Durbina2671612013-02-06 21:41:01 -0600135 post_code(0x3b);
136
137 intel_early_me_status();
138
Aaron Durbinc0cbd6e2013-03-13 13:51:20 -0500139 if (!wake_from_s3) {
140 cbmem_initialize_empty();
141 /* Save data returned from MRC on non-S3 resumes. */
Angel Pons45f448f2020-07-03 14:46:47 +0200142 save_mrc_data(&pei_data);
Aaron Durbin42e68562015-06-09 13:55:51 -0500143 } else if (cbmem_initialize()) {
Julius Wernercd49cce2019-03-05 16:53:33 -0800144 #if CONFIG(HAVE_ACPI_RESUME)
Aaron Durbin42e68562015-06-09 13:55:51 -0500145 /* Failed S3 resume, reset to come up cleanly */
Patrick Rudolph45022ae2018-10-01 19:17:11 +0200146 system_reset();
Aaron Durbin42e68562015-06-09 13:55:51 -0500147 #endif
Aaron Durbina2671612013-02-06 21:41:01 -0600148 }
Aaron Durbinbf396ff2013-02-11 21:50:35 -0600149
Tristan Corrick334be322018-12-17 22:10:21 +1300150 haswell_unhide_peg();
151
Angel Pons45f448f2020-07-03 14:46:47 +0200152 setup_sdram_meminfo(&pei_data);
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -0500153
Aaron Durbin77e13992016-11-29 17:43:04 -0600154 romstage_handoff_init(wake_from_s3);
Aaron Durbinbf396ff2013-02-11 21:50:35 -0600155
Angel Pons73fa0352020-07-03 12:29:03 +0200156 mb_late_romstage_setup();
157
Aaron Durbina2671612013-02-06 21:41:01 -0600158 post_code(0x3f);
Aaron Durbina2671612013-02-06 21:41:01 -0600159}