blob: bf072fa955ff4ff496fad0bce8a85c9d3d885fa5 [file] [log] [blame]
Angel Pons4b429832020-04-02 23:48:50 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Aaron Durbin76c37002012-10-30 09:03:43 -05002
Felix Held972d9f22022-02-23 16:32:20 +01003#include <arch/hpet.h>
Aaron Durbin76c37002012-10-30 09:03:43 -05004#include <console/console.h>
Iru Cai33642032019-06-11 14:24:43 +08005#include <console/usb.h>
Aaron Durbin76c37002012-10-30 09:03:43 -05006#include <string.h>
Aaron Durbin76c37002012-10-30 09:03:43 -05007#include <cbmem.h>
Aaron Durbin76c37002012-10-30 09:03:43 -05008#include <cbfs.h>
Elyes HAOUAS82d46422019-04-28 18:01:48 +02009#include <cf9_reset.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050010#include <ip_checksum.h>
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -050011#include <memory_info.h>
Arthur Heymansf300f362018-01-27 13:39:12 +010012#include <mrc_cache.h>
Angel Ponsd99b6932021-03-12 17:37:42 +010013#include <device/device.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050014#include <device/pci_def.h>
Patrick Rudolph42609d82020-07-27 16:23:36 +020015#include <device/pci_ops.h>
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -050016#include <device/dram/ddr3.h>
Angel Ponsd99b6932021-03-12 17:37:42 +010017#include <northbridge/intel/haswell/chip.h>
Angel Pons863efe42021-06-15 12:59:57 +020018#include <northbridge/intel/haswell/haswell.h>
19#include <northbridge/intel/haswell/raminit.h>
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -050020#include <smbios.h>
21#include <spd.h>
Philipp Deppenwiesefea24292017-10-17 17:02:29 +020022#include <security/vboot/vboot_common.h>
Arthur Heymansf300f362018-01-27 13:39:12 +010023#include <commonlib/region.h>
Angel Ponsd99b6932021-03-12 17:37:42 +010024#include <southbridge/intel/lynxpoint/me.h>
25#include <southbridge/intel/lynxpoint/pch.h>
26#include <timestamp.h>
Elyes HAOUAS030d3382021-02-12 08:17:35 +010027#include <types.h>
28
Aaron Durbin76c37002012-10-30 09:03:43 -050029#include "pei_data.h"
Aaron Durbin76c37002012-10-30 09:03:43 -050030
Arthur Heymansf300f362018-01-27 13:39:12 +010031#define MRC_CACHE_VERSION 1
32
Angel Ponsd99b6932021-03-12 17:37:42 +010033static void save_mrc_data(struct pei_data *pei_data)
Aaron Durbin76c37002012-10-30 09:03:43 -050034{
Aaron Durbin76c37002012-10-30 09:03:43 -050035 /* Save the MRC S3 restore data to cbmem */
Angel Pons1db5bc72020-01-15 00:49:03 +010036 mrc_cache_stash_data(MRC_TRAINING_DATA, MRC_CACHE_VERSION, pei_data->mrc_output,
37 pei_data->mrc_output_len);
Aaron Durbin76c37002012-10-30 09:03:43 -050038}
39
40static void prepare_mrc_cache(struct pei_data *pei_data)
41{
Shelley Chenad9cd682020-07-23 16:10:52 -070042 size_t mrc_size;
Aaron Durbin76c37002012-10-30 09:03:43 -050043
Angel Pons1db5bc72020-01-15 00:49:03 +010044 /* Preset just in case there is an error */
Aaron Durbin76c37002012-10-30 09:03:43 -050045 pei_data->mrc_input = NULL;
46 pei_data->mrc_input_len = 0;
47
Shelley Chenad9cd682020-07-23 16:10:52 -070048 pei_data->mrc_input =
49 mrc_cache_current_mmap_leak(MRC_TRAINING_DATA,
50 MRC_CACHE_VERSION,
51 &mrc_size);
52 if (!pei_data->mrc_input)
Angel Pons1db5bc72020-01-15 00:49:03 +010053 /* Error message printed in find_current_mrc_cache */
Aaron Durbin76c37002012-10-30 09:03:43 -050054 return;
Aaron Durbin76c37002012-10-30 09:03:43 -050055
Shelley Chenad9cd682020-07-23 16:10:52 -070056 pei_data->mrc_input_len = mrc_size;
Aaron Durbin76c37002012-10-30 09:03:43 -050057
Shelley Chenad9cd682020-07-23 16:10:52 -070058 printk(BIOS_DEBUG, "%s: at %p, size %zx\n", __func__,
59 pei_data->mrc_input, mrc_size);
Aaron Durbin76c37002012-10-30 09:03:43 -050060}
61
Angel Pons0117e4e2020-10-13 23:34:27 +020062static const char *const ecc_decoder[] = {
Aaron Durbin76c37002012-10-30 09:03:43 -050063 "inactive",
64 "active on IO",
65 "disabled on IO",
Angel Pons1db5bc72020-01-15 00:49:03 +010066 "active",
Aaron Durbin76c37002012-10-30 09:03:43 -050067};
68
Angel Pons1db5bc72020-01-15 00:49:03 +010069/* Print out the memory controller configuration, as per the values in its registers. */
Aaron Durbin76c37002012-10-30 09:03:43 -050070static void report_memory_config(void)
71{
Aaron Durbin76c37002012-10-30 09:03:43 -050072 int i;
73
Angel Pons2e397ae2021-03-26 12:35:57 +010074 const u32 addr_decoder_common = mchbar_read32(MAD_CHNL);
Aaron Durbin76c37002012-10-30 09:03:43 -050075
76 printk(BIOS_DEBUG, "memcfg DDR3 clock %d MHz\n",
Angel Pons2e397ae2021-03-26 12:35:57 +010077 (mchbar_read32(MC_BIOS_DATA) * 13333 * 2 + 50) / 100);
Angel Pons1db5bc72020-01-15 00:49:03 +010078
Aaron Durbin76c37002012-10-30 09:03:43 -050079 printk(BIOS_DEBUG, "memcfg channel assignment: A: %d, B % d, C % d\n",
Angel Pons1db5bc72020-01-15 00:49:03 +010080 (addr_decoder_common >> 0) & 3,
Aaron Durbin76c37002012-10-30 09:03:43 -050081 (addr_decoder_common >> 2) & 3,
82 (addr_decoder_common >> 4) & 3);
83
Angel Pons82654b32020-10-13 21:45:45 +020084 for (i = 0; i < NUM_CHANNELS; i++) {
Angel Pons2e397ae2021-03-26 12:35:57 +010085 const u32 ch_conf = mchbar_read32(MAD_DIMM(i));
Angel Pons1db5bc72020-01-15 00:49:03 +010086
87 printk(BIOS_DEBUG, "memcfg channel[%d] config (%8.8x):\n", i, ch_conf);
88 printk(BIOS_DEBUG, " ECC %s\n", ecc_decoder[(ch_conf >> 24) & 3]);
Aaron Durbin76c37002012-10-30 09:03:43 -050089 printk(BIOS_DEBUG, " enhanced interleave mode %s\n",
90 ((ch_conf >> 22) & 1) ? "on" : "off");
Angel Pons1db5bc72020-01-15 00:49:03 +010091
Aaron Durbin76c37002012-10-30 09:03:43 -050092 printk(BIOS_DEBUG, " rank interleave %s\n",
93 ((ch_conf >> 21) & 1) ? "on" : "off");
Angel Pons1db5bc72020-01-15 00:49:03 +010094
Duncan Laurie8d774022013-10-22 16:32:49 -070095 printk(BIOS_DEBUG, " DIMMA %d MB width %s %s rank%s\n",
Aaron Durbin76c37002012-10-30 09:03:43 -050096 ((ch_conf >> 0) & 0xff) * 256,
Duncan Laurie8d774022013-10-22 16:32:49 -070097 ((ch_conf >> 19) & 1) ? "x16" : "x8 or x32",
Aaron Durbin76c37002012-10-30 09:03:43 -050098 ((ch_conf >> 17) & 1) ? "dual" : "single",
99 ((ch_conf >> 16) & 1) ? "" : ", selected");
Angel Pons1db5bc72020-01-15 00:49:03 +0100100
Duncan Laurie8d774022013-10-22 16:32:49 -0700101 printk(BIOS_DEBUG, " DIMMB %d MB width %s %s rank%s\n",
Aaron Durbin76c37002012-10-30 09:03:43 -0500102 ((ch_conf >> 8) & 0xff) * 256,
Ryan Salsamendidab81a42017-06-30 17:36:41 -0700103 ((ch_conf >> 20) & 1) ? "x16" : "x8 or x32",
Aaron Durbin76c37002012-10-30 09:03:43 -0500104 ((ch_conf >> 18) & 1) ? "dual" : "single",
105 ((ch_conf >> 16) & 1) ? ", selected" : "");
106 }
107}
108
109/**
110 * Find PEI executable in coreboot filesystem and execute it.
111 *
112 * @param pei_data: configuration data for UEFI PEI reference code
113 */
Angel Ponsd99b6932021-03-12 17:37:42 +0100114static void sdram_initialize(struct pei_data *pei_data)
Aaron Durbin76c37002012-10-30 09:03:43 -0500115{
Angel Pons1ca6b532020-10-13 23:43:00 +0200116 int (*entry)(struct pei_data *pei_data) __attribute__((regparm(1)));
117
Aaron Durbin76c37002012-10-30 09:03:43 -0500118 printk(BIOS_DEBUG, "Starting UEFI PEI System Agent\n");
119
Shelley Chen6615c6e2020-10-27 15:58:31 -0700120 /*
121 * Always pass in mrc_cache data. The driver will determine
122 * whether to use the data or not.
123 */
124 prepare_mrc_cache(pei_data);
Aaron Durbin76c37002012-10-30 09:03:43 -0500125
Angel Pons1db5bc72020-01-15 00:49:03 +0100126 /* If MRC data is not found, we cannot continue S3 resume */
Aaron Durbin76c37002012-10-30 09:03:43 -0500127 if (pei_data->boot_mode == 2 && !pei_data->mrc_input) {
lilacious40cb3fe2023-06-21 23:24:14 +0200128 post_code(POSTCODE_RESUME_FAILURE);
Elyes HAOUAS3cd43272020-03-05 22:01:17 +0100129 printk(BIOS_DEBUG, "Giving up in %s: No MRC data\n", __func__);
Elyes HAOUAS82d46422019-04-28 18:01:48 +0200130 system_reset();
Aaron Durbin76c37002012-10-30 09:03:43 -0500131 }
132
133 /* Pass console handler in pei_data */
Kyösti Mälkki657e0be2014-02-04 19:03:57 +0200134 pei_data->tx_byte = do_putchar;
Aaron Durbin76c37002012-10-30 09:03:43 -0500135
Arthur Heymans8da2fa02018-06-06 10:35:45 +0200136 /*
Angel Pons1db5bc72020-01-15 00:49:03 +0100137 * Locate and call UEFI System Agent binary. The binary needs to be at a fixed offset
Julius Werner9d0cc2a2020-01-22 18:00:18 -0800138 * in the flash and can therefore only reside in the COREBOOT fmap region. We don't care
139 * about leaking the mapping.
Arthur Heymans8da2fa02018-06-06 10:35:45 +0200140 */
Julius Werner9d0cc2a2020-01-22 18:00:18 -0800141 entry = cbfs_ro_map("mrc.bin", NULL);
Aaron Durbin76c37002012-10-30 09:03:43 -0500142 if (entry) {
Angel Pons1ca6b532020-10-13 23:43:00 +0200143 int rv = entry(pei_data);
Iru Cai33642032019-06-11 14:24:43 +0800144
Angel Pons1db5bc72020-01-15 00:49:03 +0100145 /* The mrc.bin reconfigures USB, so usbdebug needs to be reinitialized */
Iru Cai33642032019-06-11 14:24:43 +0800146 if (CONFIG(USBDEBUG_IN_PRE_RAM))
147 usbdebug_hw_init(true);
148
Aaron Durbin76c37002012-10-30 09:03:43 -0500149 if (rv) {
150 switch (rv) {
151 case -1:
152 printk(BIOS_ERR, "PEI version mismatch.\n");
153 break;
154 case -2:
155 printk(BIOS_ERR, "Invalid memory frequency.\n");
156 break;
157 default:
158 printk(BIOS_ERR, "MRC returned %x.\n", rv);
159 }
lilacious40cb3fe2023-06-21 23:24:14 +0200160 die_with_post_code(POSTCODE_INVALID_VENDOR_BINARY,
Keith Shortbb41aba2019-05-16 14:07:43 -0600161 "Nonzero MRC return value.\n");
Aaron Durbin76c37002012-10-30 09:03:43 -0500162 }
163 } else {
164 die("UEFI PEI System Agent not found.\n");
165 }
166
Angel Pons7f454e42020-10-13 23:49:03 +0200167 /* Print the MRC version after executing the UEFI PEI stage */
Angel Pons2e397ae2021-03-26 12:35:57 +0100168 u32 version = mchbar_read32(MRC_REVISION);
Angel Ponsc1328a62021-06-14 12:43:11 +0200169 printk(BIOS_DEBUG, "MRC Version %u.%u.%u Build %u\n",
Angel Pons7f454e42020-10-13 23:49:03 +0200170 (version >> 24) & 0xff, (version >> 16) & 0xff,
171 (version >> 8) & 0xff, (version >> 0) & 0xff);
Aaron Durbin76c37002012-10-30 09:03:43 -0500172
Angel Pons6462cbb2021-03-30 11:01:25 +0200173 /*
174 * MRC may return zero even when raminit did not complete successfully.
175 * Ensure the mc_init_done_ack bit is set before continuing. Otherwise,
176 * attempting to access memory will lock up the system.
177 */
Angel Ponsa8753e92021-04-17 14:34:37 +0200178 if (!(mchbar_read32(MC_INIT_STATE_G) & (1 << 5))) {
Angel Pons6462cbb2021-03-30 11:01:25 +0200179 printk(BIOS_EMERG, "Memory controller did not acknowledge raminit.\n");
180 die("MRC raminit failed\n");
181 }
182
Aaron Durbin76c37002012-10-30 09:03:43 -0500183 report_memory_config();
Aaron Durbin76c37002012-10-30 09:03:43 -0500184}
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -0500185
Angel Pons6724ba42021-01-31 15:06:59 +0100186static uint8_t nb_get_ecc_type(const uint32_t capid0_a)
Patrick Rudolph42609d82020-07-27 16:23:36 +0200187{
Angel Pons6724ba42021-01-31 15:06:59 +0100188 return capid0_a & CAPID_ECCDIS ? MEMORY_ARRAY_ECC_NONE : MEMORY_ARRAY_ECC_SINGLE_BIT;
Patrick Rudolph42609d82020-07-27 16:23:36 +0200189}
190
191static uint16_t nb_slots_per_channel(const uint32_t capid0_a)
192{
193 return !(capid0_a & CAPID_DDPCD) + 1;
194}
195
196static uint16_t nb_number_of_channels(const uint32_t capid0_a)
197{
198 return !(capid0_a & CAPID_PDCD) + 1;
199}
200
201static uint32_t nb_max_chan_capacity_mib(const uint32_t capid0_a)
202{
203 uint32_t ddrsz;
204
205 /* Values from documentation, which assume two DIMMs per channel */
206 switch (CAPID_DDRSZ(capid0_a)) {
207 case 1:
208 ddrsz = 8192;
209 break;
210 case 2:
211 ddrsz = 2048;
212 break;
213 case 3:
214 ddrsz = 512;
215 break;
216 default:
217 ddrsz = 16384;
218 break;
219 }
220
221 /* Account for the maximum number of DIMMs per channel */
222 return (ddrsz / 2) * nb_slots_per_channel(capid0_a);
223}
224
Angel Ponsd99b6932021-03-12 17:37:42 +0100225static void setup_sdram_meminfo(struct pei_data *pei_data)
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -0500226{
Angel Pons1db5bc72020-01-15 00:49:03 +0100227 struct memory_info *mem_info;
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -0500228 struct dimm_info *dimm;
Angel Pons82654b32020-10-13 21:45:45 +0200229 int ch, d_num;
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -0500230 int dimm_cnt = 0;
231
232 mem_info = cbmem_add(CBMEM_ID_MEMINFO, sizeof(struct memory_info));
Nico Huberacac02d2017-06-20 14:49:04 +0200233 if (!mem_info)
234 die("Failed to add memory info to CBMEM.\n");
Angel Pons1db5bc72020-01-15 00:49:03 +0100235
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -0500236 memset(mem_info, 0, sizeof(struct memory_info));
237
Angel Pons8b94d3e2022-01-31 16:47:54 +0100238 const u32 ddr_freq_mhz = (mchbar_read32(MC_BIOS_DATA) * 13333 * 2 + 50) / 100;
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -0500239
Angel Pons82654b32020-10-13 21:45:45 +0200240 for (ch = 0; ch < NUM_CHANNELS; ch++) {
Angel Pons2e397ae2021-03-26 12:35:57 +0100241 const u32 ch_conf = mchbar_read32(MAD_DIMM(ch));
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -0500242 /* DIMMs A/B */
Angel Pons82654b32020-10-13 21:45:45 +0200243 for (d_num = 0; d_num < NUM_SLOTS; d_num++) {
244 const u32 dimm_size = ((ch_conf >> (d_num * 8)) & 0xff) * 256;
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -0500245 if (dimm_size) {
Angel Ponsafc6c0a2021-03-12 15:49:55 +0100246 const int index = ch * NUM_SLOTS + d_num;
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -0500247 dimm = &mem_info->dimm[dimm_cnt];
248 dimm->dimm_size = dimm_size;
249 dimm->ddr_type = MEMORY_TYPE_DDR3;
Angel Pons8b94d3e2022-01-31 16:47:54 +0100250 dimm->ddr_frequency = ddr_freq_mhz * 2; /* In MT/s */
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -0500251 dimm->rank_per_dimm = 1 + ((ch_conf >> (17 + d_num)) & 1);
252 dimm->channel_num = ch;
253 dimm->dimm_num = d_num;
254 dimm->bank_locator = ch * 2;
255 memcpy(dimm->serial,
Angel Ponsafc6c0a2021-03-12 15:49:55 +0100256 &pei_data->spd_data[index][SPD_DIMM_SERIAL_NUM],
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -0500257 SPD_DIMM_SERIAL_LEN);
258 memcpy(dimm->module_part_number,
Angel Ponsafc6c0a2021-03-12 15:49:55 +0100259 &pei_data->spd_data[index][SPD_DIMM_PART_NUM],
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -0500260 SPD_DIMM_PART_LEN);
261 dimm->mod_id =
Angel Ponsafc6c0a2021-03-12 15:49:55 +0100262 (pei_data->spd_data[index][SPD_DIMM_MOD_ID2] << 8) |
263 (pei_data->spd_data[index][SPD_DIMM_MOD_ID1] & 0xff);
Elyes Haouasf82e68c2022-12-28 12:33:58 +0100264 dimm->mod_type = SPD_DDR3_DIMM_TYPE_SO_DIMM;
Elyes HAOUAS7d964ae2020-07-19 09:19:59 +0200265 dimm->bus_width = MEMORY_BUS_WIDTH_64;
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -0500266 dimm_cnt++;
267 }
268 }
269 }
270 mem_info->dimm_cnt = dimm_cnt;
Patrick Rudolph42609d82020-07-27 16:23:36 +0200271
272 const uint32_t capid0_a = pci_read_config32(HOST_BRIDGE, CAPID0_A);
273
274 const uint16_t channels = nb_number_of_channels(capid0_a);
275
Angel Pons6724ba42021-01-31 15:06:59 +0100276 mem_info->ecc_type = nb_get_ecc_type(capid0_a);
Patrick Rudolph42609d82020-07-27 16:23:36 +0200277 mem_info->max_capacity_mib = channels * nb_max_chan_capacity_mib(capid0_a);
278 mem_info->number_of_devices = channels * nb_slots_per_channel(capid0_a);
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -0500279}
Angel Ponsd99b6932021-03-12 17:37:42 +0100280
281/* Copy SPD data for on-board memory */
282static void copy_spd(struct pei_data *pei_data, struct spd_info *spdi)
283{
284 if (!CONFIG(HAVE_SPD_IN_CBFS))
285 return;
286
287 printk(BIOS_DEBUG, "SPD index %d\n", spdi->spd_index);
288
289 size_t spd_file_len;
290 uint8_t *spd_file = cbfs_map("spd.bin", &spd_file_len);
291
292 if (!spd_file)
293 die("SPD data not found.");
294
295 if (spd_file_len < ((spdi->spd_index + 1) * SPD_LEN)) {
296 printk(BIOS_ERR, "SPD index override to 0 - old hardware?\n");
297 spdi->spd_index = 0;
298 }
299
300 if (spd_file_len < SPD_LEN)
301 die("Missing SPD data.");
302
303 /* MRC only uses index 0, but coreboot uses the other indices */
304 memcpy(pei_data->spd_data[0], spd_file + (spdi->spd_index * SPD_LEN), SPD_LEN);
305
306 for (size_t i = 1; i < ARRAY_SIZE(spdi->addresses); i++) {
307 if (spdi->addresses[i] == SPD_MEMORY_DOWN)
308 memcpy(pei_data->spd_data[i], pei_data->spd_data[0], SPD_LEN);
309 }
310}
311
312/*
313 * 0 = leave channel enabled
314 * 1 = disable dimm 0 on channel
315 * 2 = disable dimm 1 on channel
316 * 3 = disable dimm 0+1 on channel
317 */
318static int make_channel_disabled_mask(const struct pei_data *pd, int ch)
319{
320 return (!pd->spd_addresses[ch + ch] << 0) | (!pd->spd_addresses[ch + ch + 1] << 1);
321}
322
Angel Ponsd0f971f2021-03-12 14:20:05 +0100323static enum pei_usb2_port_location map_to_pei_usb2_location(const enum usb2_port_location loc)
324{
325 static const enum pei_usb2_port_location map[] = {
326 [USB_PORT_SKIP] = PEI_USB_PORT_SKIP,
327 [USB_PORT_BACK_PANEL] = PEI_USB_PORT_BACK_PANEL,
328 [USB_PORT_FRONT_PANEL] = PEI_USB_PORT_FRONT_PANEL,
329 [USB_PORT_DOCK] = PEI_USB_PORT_DOCK,
330 [USB_PORT_MINI_PCIE] = PEI_USB_PORT_MINI_PCIE,
331 [USB_PORT_FLEX] = PEI_USB_PORT_FLEX,
332 [USB_PORT_INTERNAL] = PEI_USB_PORT_INTERNAL,
333 };
334 return loc >= ARRAY_SIZE(map) ? PEI_USB_PORT_SKIP : map[loc];
335}
336
337static uint8_t map_to_pei_oc_pin(const uint8_t oc_pin)
338{
339 return oc_pin >= USB_OC_PIN_SKIP ? PEI_USB_OC_PIN_SKIP : oc_pin;
340}
341
Angel Ponsd99b6932021-03-12 17:37:42 +0100342void perform_raminit(const int s3resume)
343{
344 const struct device *gbe = pcidev_on_root(0x19, 0);
345
346 const struct northbridge_intel_haswell_config *cfg = config_of_soc();
347
348 struct pei_data pei_data = {
349 .pei_version = PEI_VERSION,
350 .mchbar = CONFIG_FIXED_MCHBAR_MMIO_BASE,
351 .dmibar = CONFIG_FIXED_DMIBAR_MMIO_BASE,
352 .epbar = CONFIG_FIXED_EPBAR_MMIO_BASE,
Shelley Chen4e9bb332021-10-20 15:43:45 -0700353 .pciexbar = CONFIG_ECAM_MMCONF_BASE_ADDRESS,
Angel Ponsd99b6932021-03-12 17:37:42 +0100354 .smbusbar = CONFIG_FIXED_SMBUS_IO_BASE,
Felix Held972d9f22022-02-23 16:32:20 +0100355 .hpet_address = HPET_BASE_ADDRESS,
Angel Ponsd99b6932021-03-12 17:37:42 +0100356 .rcba = CONFIG_FIXED_RCBA_MMIO_BASE,
357 .pmbase = DEFAULT_PMBASE,
358 .gpiobase = DEFAULT_GPIOBASE,
359 .temp_mmio_base = 0xfed08000,
360 .system_type = get_pch_platform_type(),
361 .tseg_size = CONFIG_SMM_TSEG_SIZE,
362 .ec_present = cfg->ec_present,
363 .gbe_enable = gbe && gbe->enabled,
364 .ddr_refresh_2x = CONFIG(ENABLE_DDR_2X_REFRESH),
365 .dq_pins_interleaved = cfg->dq_pins_interleaved,
366 .max_ddr3_freq = 1600,
367 .usb_xhci_on_resume = cfg->usb_xhci_on_resume,
368 };
369
Angel Ponsd0f971f2021-03-12 14:20:05 +0100370 for (size_t i = 0; i < ARRAY_SIZE(mainboard_usb2_ports); i++) {
371 /* If a port is not enabled, skip it */
372 if (!mainboard_usb2_ports[i].enable) {
373 pei_data.usb2_ports[i].over_current_pin = PEI_USB_OC_PIN_SKIP;
374 pei_data.usb2_ports[i].location = PEI_USB_PORT_SKIP;
375 continue;
376 }
377 const enum usb2_port_location loc = mainboard_usb2_ports[i].location;
378 const uint8_t oc_pin = mainboard_usb2_ports[i].oc_pin;
379 pei_data.usb2_ports[i].length = mainboard_usb2_ports[i].length;
380 pei_data.usb2_ports[i].enable = mainboard_usb2_ports[i].enable;
381 pei_data.usb2_ports[i].over_current_pin = map_to_pei_oc_pin(oc_pin);
382 pei_data.usb2_ports[i].location = map_to_pei_usb2_location(loc);
383 }
384
385 for (size_t i = 0; i < ARRAY_SIZE(mainboard_usb3_ports); i++) {
386 const uint8_t oc_pin = mainboard_usb3_ports[i].oc_pin;
387 pei_data.usb3_ports[i].enable = mainboard_usb3_ports[i].enable;
388 pei_data.usb3_ports[i].over_current_pin = map_to_pei_oc_pin(oc_pin);
389 }
Angel Ponsd99b6932021-03-12 17:37:42 +0100390
391 /* MRC has hardcoded assumptions of 2 meaning S3 wake. Normalize it here. */
392 pei_data.boot_mode = s3resume ? 2 : 0;
393
394 /* Obtain the SPD addresses from mainboard code */
395 struct spd_info spdi = {0};
396 mb_get_spd_map(&spdi);
397
Angel Ponsc4ee7142021-03-12 20:48:53 +0100398 /* MRC expects left-aligned SMBus addresses, and 0xff for memory-down */
399 for (size_t i = 0; i < ARRAY_SIZE(spdi.addresses); i++) {
400 const uint8_t addr = spdi.addresses[i];
401 pei_data.spd_addresses[i] = addr == SPD_MEMORY_DOWN ? 0xff : addr << 1;
402 }
Angel Ponsd99b6932021-03-12 17:37:42 +0100403
404 /* Calculate unimplemented DIMM slots for each channel */
405 pei_data.dimm_channel0_disabled = make_channel_disabled_mask(&pei_data, 0);
406 pei_data.dimm_channel1_disabled = make_channel_disabled_mask(&pei_data, 1);
407
Jakub Czapigaad6157e2022-02-15 11:50:31 +0100408 timestamp_add_now(TS_INITRAM_START);
Angel Ponsd99b6932021-03-12 17:37:42 +0100409
410 copy_spd(&pei_data, &spdi);
411
412 sdram_initialize(&pei_data);
413
Jakub Czapigaad6157e2022-02-15 11:50:31 +0100414 timestamp_add_now(TS_INITRAM_END);
Angel Ponsd99b6932021-03-12 17:37:42 +0100415
416 post_code(0x3b);
417
418 intel_early_me_status();
419
420 int cbmem_was_initted = !cbmem_recovery(s3resume);
421 if (s3resume && !cbmem_was_initted) {
422 /* Failed S3 resume, reset to come up cleanly */
423 printk(BIOS_CRIT, "Failed to recover CBMEM in S3 resume.\n");
424 system_reset();
425 }
426
427 /* Save data returned from MRC on non-S3 resumes. */
428 if (!s3resume)
429 save_mrc_data(&pei_data);
430
431 setup_sdram_meminfo(&pei_data);
432}