blob: f65098f6fcf20776aa57db32148e6eb32d488ace [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>
Angel Pons90ae0892021-03-12 17:00:52 +01004#include <cbfs.h>
Aaron Durbin3d0071b2013-01-18 14:32:50 -06005#include <console/console.h>
Patrick Rudolph45022ae2018-10-01 19:17:11 +02006#include <cf9_reset.h>
Angel Pons39a60932020-07-04 01:07:24 +02007#include <device/device.h>
Angel Pons6c49f402020-08-28 02:02:00 +02008#include <device/mmio.h>
Angel Pons30931f52021-03-12 13:06:45 +01009#include <elog.h>
Aaron Durbina2671612013-02-06 21:41:01 -060010#include <timestamp.h>
Aaron Durbina2671612013-02-06 21:41:01 -060011#include <cpu/x86/lapic.h>
Kyösti Mälkki465eff62016-06-15 06:07:55 +030012#include <cbmem.h>
Elyes HAOUASd26844c2019-06-21 07:31:40 +020013#include <commonlib/helpers.h>
Aaron Durbinbf396ff2013-02-11 21:50:35 -060014#include <romstage_handoff.h>
Angel Pons6c49f402020-08-28 02:02:00 +020015#include <security/intel/txt/txt.h>
16#include <security/intel/txt/txt_register.h>
Angel Pons2e25ac62020-07-03 12:06:04 +020017#include <cpu/intel/haswell/haswell.h>
Angel Pons8aab7872020-07-04 01:24:59 +020018#include <northbridge/intel/haswell/chip.h>
Elyes HAOUAS65bb5432018-07-03 14:59:50 +020019#include <northbridge/intel/haswell/haswell.h>
20#include <northbridge/intel/haswell/raminit.h>
Angel Pons30931f52021-03-12 13:06:45 +010021#include <southbridge/intel/common/pmclib.h>
Elyes HAOUAS65bb5432018-07-03 14:59:50 +020022#include <southbridge/intel/lynxpoint/pch.h>
23#include <southbridge/intel/lynxpoint/me.h>
Angel Pons33b59c92021-02-11 13:42:20 +010024#include <string.h>
Angel Pons90ae0892021-03-12 17:00:52 +010025#include <types.h>
Aaron Durbina2671612013-02-06 21:41:01 -060026
Angel Pons6eea1912020-07-03 14:14:30 +020027/* Copy SPD data for on-board memory */
Angel Pons90ae0892021-03-12 17:00:52 +010028static void copy_spd(struct pei_data *pei_data, struct spd_info *spdi)
Angel Pons6eea1912020-07-03 14:14:30 +020029{
Angel Pons90ae0892021-03-12 17:00:52 +010030 if (!CONFIG(HAVE_SPD_IN_CBFS))
31 return;
32
33 printk(BIOS_DEBUG, "SPD index %d\n", spdi->spd_index);
34
35 size_t spd_file_len;
36 uint8_t *spd_file = cbfs_map("spd.bin", &spd_file_len);
37
38 if (!spd_file)
39 die("SPD data not found.");
40
41 if (spd_file_len < ((spdi->spd_index + 1) * SPD_LEN)) {
42 printk(BIOS_ERR, "SPD index override to 0 - old hardware?\n");
43 spdi->spd_index = 0;
44 }
45
46 if (spd_file_len < SPD_LEN)
47 die("Missing SPD data.");
48
49 /* MRC only uses index 0, but coreboot uses the other indices */
50 memcpy(pei_data->spd_data[0], spd_file + (spdi->spd_index * SPD_LEN), SPD_LEN);
51
52 for (size_t i = 1; i < ARRAY_SIZE(spdi->addresses); i++) {
53 if (spdi->addresses[i] == SPD_MEMORY_DOWN)
54 memcpy(pei_data->spd_data[i], pei_data->spd_data[0], SPD_LEN);
55 }
Angel Pons6eea1912020-07-03 14:14:30 +020056}
57
Angel Pons73fa0352020-07-03 12:29:03 +020058void __weak mb_late_romstage_setup(void)
59{
60}
61
Angel Ponsd7bf3ad2020-07-03 20:31:39 +020062/*
63 * 0 = leave channel enabled
64 * 1 = disable dimm 0 on channel
65 * 2 = disable dimm 1 on channel
66 * 3 = disable dimm 0+1 on channel
67 */
68static int make_channel_disabled_mask(const struct pei_data *pd, int ch)
69{
70 return (!pd->spd_addresses[ch + ch] << 0) | (!pd->spd_addresses[ch + ch + 1] << 1);
71}
72
Angel Pons45f448f2020-07-03 14:46:47 +020073/* The romstage entry point for this platform is not mainboard-specific, hence the name */
74void mainboard_romstage_entry(void)
Aaron Durbina2671612013-02-06 21:41:01 -060075{
Angel Pons39a60932020-07-04 01:07:24 +020076 const struct device *gbe = pcidev_on_root(0x19, 0);
77
Angel Pons8aab7872020-07-04 01:24:59 +020078 const struct northbridge_intel_haswell_config *cfg = config_of_soc();
79
Angel Pons45f448f2020-07-03 14:46:47 +020080 struct pei_data pei_data = {
Angel Ponsae0eeb22020-07-04 01:38:03 +020081 .pei_version = PEI_VERSION,
Angel Ponsf95b9b42021-01-20 01:10:48 +010082 .mchbar = CONFIG_FIXED_MCHBAR_MMIO_BASE,
83 .dmibar = CONFIG_FIXED_DMIBAR_MMIO_BASE,
84 .epbar = CONFIG_FIXED_EPBAR_MMIO_BASE,
Angel Ponsae0eeb22020-07-04 01:38:03 +020085 .pciexbar = CONFIG_MMCONF_BASE_ADDRESS,
Angel Ponsb21bffa2020-07-03 01:02:28 +020086 .smbusbar = CONFIG_FIXED_SMBUS_IO_BASE,
Angel Pons0b393792021-03-12 12:54:45 +010087 .hpet_address = CONFIG_HPET_ADDRESS,
Angel Pons6e732d32021-01-28 13:56:18 +010088 .rcba = CONFIG_FIXED_RCBA_MMIO_BASE,
Angel Ponsae0eeb22020-07-04 01:38:03 +020089 .pmbase = DEFAULT_PMBASE,
90 .gpiobase = DEFAULT_GPIOBASE,
91 .temp_mmio_base = 0xfed08000,
92 .system_type = get_pch_platform_type(),
93 .tseg_size = CONFIG_SMM_TSEG_SIZE,
94 .ec_present = cfg->ec_present,
95 .gbe_enable = gbe && gbe->enabled,
96 .ddr_refresh_2x = CONFIG(ENABLE_DDR_2X_REFRESH),
97 .dq_pins_interleaved = cfg->dq_pins_interleaved,
98 .max_ddr3_freq = 1600,
99 .usb_xhci_on_resume = cfg->usb_xhci_on_resume,
Angel Pons45f448f2020-07-03 14:46:47 +0200100 };
101
Angel Pons33b59c92021-02-11 13:42:20 +0100102 memcpy(pei_data.usb2_ports, mainboard_usb2_ports, sizeof(mainboard_usb2_ports));
103 memcpy(pei_data.usb3_ports, mainboard_usb3_ports, sizeof(mainboard_usb3_ports));
Angel Pons45f448f2020-07-03 14:46:47 +0200104
Kyösti Mälkki157b1892019-08-16 14:02:25 +0300105 enable_lapic();
Aaron Durbina2671612013-02-06 21:41:01 -0600106
Angel Pons30931f52021-03-12 13:06:45 +0100107 early_pch_init();
108
109 const int s3resume = southbridge_detect_s3_resume();
110
111 elog_boot_notify(s3resume);
Aaron Durbina2671612013-02-06 21:41:01 -0600112
Aaron Durbina2671612013-02-06 21:41:01 -0600113 /* Perform some early chipset initialization required
114 * before RAM initialization can work
115 */
Angel Ponse8168292020-07-03 11:42:22 +0200116 haswell_early_initialization();
Aaron Durbina2671612013-02-06 21:41:01 -0600117 printk(BIOS_DEBUG, "Back from haswell_early_initialization()\n");
118
Aaron Durbina2671612013-02-06 21:41:01 -0600119 /* Prepare USB controller early in S3 resume */
Kyösti Mälkkib6fc13b2021-02-17 17:33:09 +0200120 if (s3resume)
Aaron Durbina2671612013-02-06 21:41:01 -0600121 enable_usb_bar();
122
123 post_code(0x3a);
Angel Pons284a5472020-07-03 11:46:50 +0200124
125 /* MRC has hardcoded assumptions of 2 meaning S3 wake. Normalize it here. */
Kyösti Mälkkib6fc13b2021-02-17 17:33:09 +0200126 pei_data.boot_mode = s3resume ? 2 : 0;
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300127
Angel Ponsd37b7d82020-07-03 23:52:34 +0200128 /* Obtain the SPD addresses from mainboard code */
Angel Pons90ae0892021-03-12 17:00:52 +0100129 struct spd_info spdi = {0};
130 mb_get_spd_map(&spdi);
131
132 for (size_t i = 0; i < ARRAY_SIZE(spdi.addresses); i++)
133 pei_data.spd_addresses[i] = spdi.addresses[i];
Angel Ponsd37b7d82020-07-03 23:52:34 +0200134
Angel Ponsd7bf3ad2020-07-03 20:31:39 +0200135 /* Calculate unimplemented DIMM slots for each channel */
136 pei_data.dimm_channel0_disabled = make_channel_disabled_mask(&pei_data, 0);
137 pei_data.dimm_channel1_disabled = make_channel_disabled_mask(&pei_data, 1);
138
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300139 timestamp_add_now(TS_BEFORE_INITRAM);
Aaron Durbina2671612013-02-06 21:41:01 -0600140
141 report_platform_info();
142
Angel Pons6c49f402020-08-28 02:02:00 +0200143 if (CONFIG(INTEL_TXT))
144 intel_txt_romstage_init();
145
Angel Pons90ae0892021-03-12 17:00:52 +0100146 copy_spd(&pei_data, &spdi);
Aaron Durbinc7633f42013-06-13 17:29:36 -0700147
Angel Pons45f448f2020-07-03 14:46:47 +0200148 sdram_initialize(&pei_data);
Aaron Durbina2671612013-02-06 21:41:01 -0600149
Kyösti Mälkki3d45c402013-09-07 20:26:36 +0300150 timestamp_add_now(TS_AFTER_INITRAM);
151
Angel Pons6c49f402020-08-28 02:02:00 +0200152 if (CONFIG(INTEL_TXT)) {
153 printk(BIOS_DEBUG, "Check TXT_ERROR register after MRC\n");
154
155 intel_txt_log_acm_error(read32((void *)TXT_ERROR));
156
157 intel_txt_log_spad();
158
159 intel_txt_memory_has_secrets();
160
161 txt_dump_regions();
162 }
163
Aaron Durbina2671612013-02-06 21:41:01 -0600164 post_code(0x3b);
165
166 intel_early_me_status();
167
Kyösti Mälkkib6fc13b2021-02-17 17:33:09 +0200168 int cbmem_was_initted = !cbmem_recovery(s3resume);
169 if (s3resume && !cbmem_was_initted) {
Aaron Durbin42e68562015-06-09 13:55:51 -0500170 /* Failed S3 resume, reset to come up cleanly */
Kyösti Mälkkib6fc13b2021-02-17 17:33:09 +0200171 printk(BIOS_CRIT, "Failed to recover CBMEM in S3 resume.\n");
Patrick Rudolph45022ae2018-10-01 19:17:11 +0200172 system_reset();
Aaron Durbina2671612013-02-06 21:41:01 -0600173 }
Aaron Durbinbf396ff2013-02-11 21:50:35 -0600174
Kyösti Mälkkib6fc13b2021-02-17 17:33:09 +0200175 /* Save data returned from MRC on non-S3 resumes. */
176 if (!s3resume)
177 save_mrc_data(&pei_data);
178
179
Tristan Corrick334be322018-12-17 22:10:21 +1300180 haswell_unhide_peg();
181
Angel Pons45f448f2020-07-03 14:46:47 +0200182 setup_sdram_meminfo(&pei_data);
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -0500183
Kyösti Mälkkib6fc13b2021-02-17 17:33:09 +0200184 romstage_handoff_init(s3resume);
Aaron Durbinbf396ff2013-02-11 21:50:35 -0600185
Angel Pons73fa0352020-07-03 12:29:03 +0200186 mb_late_romstage_setup();
187
Aaron Durbina2671612013-02-06 21:41:01 -0600188 post_code(0x3f);
Aaron Durbina2671612013-02-06 21:41:01 -0600189}