blob: d97ab2a8acd30c4b8c92bf975c6304bc22feb67d [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>
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -050010#include <memory_info.h>
Arthur Heymansf300f362018-01-27 13:39:12 +010011#include <mrc_cache.h>
Angel Ponsd99b6932021-03-12 17:37:42 +010012#include <device/device.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050013#include <device/pci_def.h>
Patrick Rudolph42609d82020-07-27 16:23:36 +020014#include <device/pci_ops.h>
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -050015#include <device/dram/ddr3.h>
Angel Ponsd99b6932021-03-12 17:37:42 +010016#include <northbridge/intel/haswell/chip.h>
Angel Pons863efe42021-06-15 12:59:57 +020017#include <northbridge/intel/haswell/haswell.h>
18#include <northbridge/intel/haswell/raminit.h>
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -050019#include <smbios.h>
20#include <spd.h>
Philipp Deppenwiesefea24292017-10-17 17:02:29 +020021#include <security/vboot/vboot_common.h>
Arthur Heymansf300f362018-01-27 13:39:12 +010022#include <commonlib/region.h>
Angel Ponsd99b6932021-03-12 17:37:42 +010023#include <southbridge/intel/lynxpoint/me.h>
24#include <southbridge/intel/lynxpoint/pch.h>
25#include <timestamp.h>
Elyes HAOUAS030d3382021-02-12 08:17:35 +010026#include <types.h>
27
Aaron Durbin76c37002012-10-30 09:03:43 -050028#include "pei_data.h"
Aaron Durbin76c37002012-10-30 09:03:43 -050029
Arthur Heymansf300f362018-01-27 13:39:12 +010030#define MRC_CACHE_VERSION 1
31
Angel Ponsd99b6932021-03-12 17:37:42 +010032static void save_mrc_data(struct pei_data *pei_data)
Aaron Durbin76c37002012-10-30 09:03:43 -050033{
Aaron Durbin76c37002012-10-30 09:03:43 -050034 /* Save the MRC S3 restore data to cbmem */
Angel Pons1db5bc72020-01-15 00:49:03 +010035 mrc_cache_stash_data(MRC_TRAINING_DATA, MRC_CACHE_VERSION, pei_data->mrc_output,
36 pei_data->mrc_output_len);
Aaron Durbin76c37002012-10-30 09:03:43 -050037}
38
39static void prepare_mrc_cache(struct pei_data *pei_data)
40{
Shelley Chenad9cd682020-07-23 16:10:52 -070041 size_t mrc_size;
Aaron Durbin76c37002012-10-30 09:03:43 -050042
Angel Pons1db5bc72020-01-15 00:49:03 +010043 /* Preset just in case there is an error */
Aaron Durbin76c37002012-10-30 09:03:43 -050044 pei_data->mrc_input = NULL;
45 pei_data->mrc_input_len = 0;
46
Shelley Chenad9cd682020-07-23 16:10:52 -070047 pei_data->mrc_input =
48 mrc_cache_current_mmap_leak(MRC_TRAINING_DATA,
49 MRC_CACHE_VERSION,
50 &mrc_size);
51 if (!pei_data->mrc_input)
Angel Pons1db5bc72020-01-15 00:49:03 +010052 /* Error message printed in find_current_mrc_cache */
Aaron Durbin76c37002012-10-30 09:03:43 -050053 return;
Aaron Durbin76c37002012-10-30 09:03:43 -050054
Shelley Chenad9cd682020-07-23 16:10:52 -070055 pei_data->mrc_input_len = mrc_size;
Aaron Durbin76c37002012-10-30 09:03:43 -050056
Shelley Chenad9cd682020-07-23 16:10:52 -070057 printk(BIOS_DEBUG, "%s: at %p, size %zx\n", __func__,
58 pei_data->mrc_input, mrc_size);
Aaron Durbin76c37002012-10-30 09:03:43 -050059}
60
Angel Pons0117e4e2020-10-13 23:34:27 +020061static const char *const ecc_decoder[] = {
Aaron Durbin76c37002012-10-30 09:03:43 -050062 "inactive",
63 "active on IO",
64 "disabled on IO",
Angel Pons1db5bc72020-01-15 00:49:03 +010065 "active",
Aaron Durbin76c37002012-10-30 09:03:43 -050066};
67
Angel Pons1db5bc72020-01-15 00:49:03 +010068/* Print out the memory controller configuration, as per the values in its registers. */
Aaron Durbin76c37002012-10-30 09:03:43 -050069static void report_memory_config(void)
70{
Aaron Durbin76c37002012-10-30 09:03:43 -050071 int i;
72
Angel Pons2e397ae2021-03-26 12:35:57 +010073 const u32 addr_decoder_common = mchbar_read32(MAD_CHNL);
Aaron Durbin76c37002012-10-30 09:03:43 -050074
75 printk(BIOS_DEBUG, "memcfg DDR3 clock %d MHz\n",
Angel Pons6f75dd02021-04-24 10:53:19 +020076 DIV_ROUND_CLOSEST(mchbar_read32(MC_BIOS_DATA) * 13333 * 2, 100));
Angel Pons1db5bc72020-01-15 00:49:03 +010077
Aaron Durbin76c37002012-10-30 09:03:43 -050078 printk(BIOS_DEBUG, "memcfg channel assignment: A: %d, B % d, C % d\n",
Angel Pons1db5bc72020-01-15 00:49:03 +010079 (addr_decoder_common >> 0) & 3,
Aaron Durbin76c37002012-10-30 09:03:43 -050080 (addr_decoder_common >> 2) & 3,
81 (addr_decoder_common >> 4) & 3);
82
Angel Pons82654b32020-10-13 21:45:45 +020083 for (i = 0; i < NUM_CHANNELS; i++) {
Angel Pons2e397ae2021-03-26 12:35:57 +010084 const u32 ch_conf = mchbar_read32(MAD_DIMM(i));
Angel Pons1db5bc72020-01-15 00:49:03 +010085
86 printk(BIOS_DEBUG, "memcfg channel[%d] config (%8.8x):\n", i, ch_conf);
87 printk(BIOS_DEBUG, " ECC %s\n", ecc_decoder[(ch_conf >> 24) & 3]);
Aaron Durbin76c37002012-10-30 09:03:43 -050088 printk(BIOS_DEBUG, " enhanced interleave mode %s\n",
89 ((ch_conf >> 22) & 1) ? "on" : "off");
Angel Pons1db5bc72020-01-15 00:49:03 +010090
Aaron Durbin76c37002012-10-30 09:03:43 -050091 printk(BIOS_DEBUG, " rank interleave %s\n",
92 ((ch_conf >> 21) & 1) ? "on" : "off");
Angel Pons1db5bc72020-01-15 00:49:03 +010093
Duncan Laurie8d774022013-10-22 16:32:49 -070094 printk(BIOS_DEBUG, " DIMMA %d MB width %s %s rank%s\n",
Aaron Durbin76c37002012-10-30 09:03:43 -050095 ((ch_conf >> 0) & 0xff) * 256,
Duncan Laurie8d774022013-10-22 16:32:49 -070096 ((ch_conf >> 19) & 1) ? "x16" : "x8 or x32",
Aaron Durbin76c37002012-10-30 09:03:43 -050097 ((ch_conf >> 17) & 1) ? "dual" : "single",
98 ((ch_conf >> 16) & 1) ? "" : ", selected");
Angel Pons1db5bc72020-01-15 00:49:03 +010099
Duncan Laurie8d774022013-10-22 16:32:49 -0700100 printk(BIOS_DEBUG, " DIMMB %d MB width %s %s rank%s\n",
Aaron Durbin76c37002012-10-30 09:03:43 -0500101 ((ch_conf >> 8) & 0xff) * 256,
Ryan Salsamendidab81a42017-06-30 17:36:41 -0700102 ((ch_conf >> 20) & 1) ? "x16" : "x8 or x32",
Aaron Durbin76c37002012-10-30 09:03:43 -0500103 ((ch_conf >> 18) & 1) ? "dual" : "single",
104 ((ch_conf >> 16) & 1) ? ", selected" : "");
105 }
106}
107
108/**
109 * Find PEI executable in coreboot filesystem and execute it.
110 *
111 * @param pei_data: configuration data for UEFI PEI reference code
112 */
Angel Ponsd99b6932021-03-12 17:37:42 +0100113static void sdram_initialize(struct pei_data *pei_data)
Aaron Durbin76c37002012-10-30 09:03:43 -0500114{
Angel Pons1ca6b532020-10-13 23:43:00 +0200115 int (*entry)(struct pei_data *pei_data) __attribute__((regparm(1)));
116
Aaron Durbin76c37002012-10-30 09:03:43 -0500117 printk(BIOS_DEBUG, "Starting UEFI PEI System Agent\n");
118
Shelley Chen6615c6e2020-10-27 15:58:31 -0700119 /*
120 * Always pass in mrc_cache data. The driver will determine
121 * whether to use the data or not.
122 */
123 prepare_mrc_cache(pei_data);
Aaron Durbin76c37002012-10-30 09:03:43 -0500124
Angel Pons1db5bc72020-01-15 00:49:03 +0100125 /* If MRC data is not found, we cannot continue S3 resume */
Aaron Durbin76c37002012-10-30 09:03:43 -0500126 if (pei_data->boot_mode == 2 && !pei_data->mrc_input) {
lilacious40cb3fe2023-06-21 23:24:14 +0200127 post_code(POSTCODE_RESUME_FAILURE);
Elyes HAOUAS3cd43272020-03-05 22:01:17 +0100128 printk(BIOS_DEBUG, "Giving up in %s: No MRC data\n", __func__);
Elyes HAOUAS82d46422019-04-28 18:01:48 +0200129 system_reset();
Aaron Durbin76c37002012-10-30 09:03:43 -0500130 }
131
132 /* Pass console handler in pei_data */
Kyösti Mälkki657e0be2014-02-04 19:03:57 +0200133 pei_data->tx_byte = do_putchar;
Aaron Durbin76c37002012-10-30 09:03:43 -0500134
Arthur Heymans8da2fa02018-06-06 10:35:45 +0200135 /*
Angel Pons1db5bc72020-01-15 00:49:03 +0100136 * Locate and call UEFI System Agent binary. The binary needs to be at a fixed offset
Julius Werner9d0cc2a2020-01-22 18:00:18 -0800137 * in the flash and can therefore only reside in the COREBOOT fmap region. We don't care
138 * about leaking the mapping.
Arthur Heymans8da2fa02018-06-06 10:35:45 +0200139 */
Julius Werner9d0cc2a2020-01-22 18:00:18 -0800140 entry = cbfs_ro_map("mrc.bin", NULL);
Aaron Durbin76c37002012-10-30 09:03:43 -0500141 if (entry) {
Angel Pons1ca6b532020-10-13 23:43:00 +0200142 int rv = entry(pei_data);
Iru Cai33642032019-06-11 14:24:43 +0800143
Angel Pons1db5bc72020-01-15 00:49:03 +0100144 /* The mrc.bin reconfigures USB, so usbdebug needs to be reinitialized */
Iru Cai33642032019-06-11 14:24:43 +0800145 if (CONFIG(USBDEBUG_IN_PRE_RAM))
146 usbdebug_hw_init(true);
147
Aaron Durbin76c37002012-10-30 09:03:43 -0500148 if (rv) {
149 switch (rv) {
150 case -1:
151 printk(BIOS_ERR, "PEI version mismatch.\n");
152 break;
153 case -2:
154 printk(BIOS_ERR, "Invalid memory frequency.\n");
155 break;
156 default:
157 printk(BIOS_ERR, "MRC returned %x.\n", rv);
158 }
lilacious40cb3fe2023-06-21 23:24:14 +0200159 die_with_post_code(POSTCODE_INVALID_VENDOR_BINARY,
Keith Shortbb41aba2019-05-16 14:07:43 -0600160 "Nonzero MRC return value.\n");
Aaron Durbin76c37002012-10-30 09:03:43 -0500161 }
162 } else {
163 die("UEFI PEI System Agent not found.\n");
164 }
165
Angel Pons7f454e42020-10-13 23:49:03 +0200166 /* Print the MRC version after executing the UEFI PEI stage */
Angel Pons2e397ae2021-03-26 12:35:57 +0100167 u32 version = mchbar_read32(MRC_REVISION);
Angel Ponsc1328a62021-06-14 12:43:11 +0200168 printk(BIOS_DEBUG, "MRC Version %u.%u.%u Build %u\n",
Angel Pons7f454e42020-10-13 23:49:03 +0200169 (version >> 24) & 0xff, (version >> 16) & 0xff,
170 (version >> 8) & 0xff, (version >> 0) & 0xff);
Aaron Durbin76c37002012-10-30 09:03:43 -0500171
Angel Pons6462cbb2021-03-30 11:01:25 +0200172 /*
173 * MRC may return zero even when raminit did not complete successfully.
174 * Ensure the mc_init_done_ack bit is set before continuing. Otherwise,
175 * attempting to access memory will lock up the system.
176 */
Angel Ponsa8753e92021-04-17 14:34:37 +0200177 if (!(mchbar_read32(MC_INIT_STATE_G) & (1 << 5))) {
Angel Pons6462cbb2021-03-30 11:01:25 +0200178 printk(BIOS_EMERG, "Memory controller did not acknowledge raminit.\n");
179 die("MRC raminit failed\n");
180 }
181
Aaron Durbin76c37002012-10-30 09:03:43 -0500182 report_memory_config();
Aaron Durbin76c37002012-10-30 09:03:43 -0500183}
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -0500184
Angel Pons6724ba42021-01-31 15:06:59 +0100185static uint8_t nb_get_ecc_type(const uint32_t capid0_a)
Patrick Rudolph42609d82020-07-27 16:23:36 +0200186{
Angel Pons6724ba42021-01-31 15:06:59 +0100187 return capid0_a & CAPID_ECCDIS ? MEMORY_ARRAY_ECC_NONE : MEMORY_ARRAY_ECC_SINGLE_BIT;
Patrick Rudolph42609d82020-07-27 16:23:36 +0200188}
189
190static uint16_t nb_slots_per_channel(const uint32_t capid0_a)
191{
192 return !(capid0_a & CAPID_DDPCD) + 1;
193}
194
195static uint16_t nb_number_of_channels(const uint32_t capid0_a)
196{
197 return !(capid0_a & CAPID_PDCD) + 1;
198}
199
200static uint32_t nb_max_chan_capacity_mib(const uint32_t capid0_a)
201{
202 uint32_t ddrsz;
203
204 /* Values from documentation, which assume two DIMMs per channel */
205 switch (CAPID_DDRSZ(capid0_a)) {
206 case 1:
207 ddrsz = 8192;
208 break;
209 case 2:
210 ddrsz = 2048;
211 break;
212 case 3:
213 ddrsz = 512;
214 break;
215 default:
216 ddrsz = 16384;
217 break;
218 }
219
220 /* Account for the maximum number of DIMMs per channel */
221 return (ddrsz / 2) * nb_slots_per_channel(capid0_a);
222}
223
Angel Ponsd99b6932021-03-12 17:37:42 +0100224static void setup_sdram_meminfo(struct pei_data *pei_data)
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -0500225{
Angel Pons1db5bc72020-01-15 00:49:03 +0100226 struct memory_info *mem_info;
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -0500227 struct dimm_info *dimm;
Angel Pons82654b32020-10-13 21:45:45 +0200228 int ch, d_num;
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -0500229 int dimm_cnt = 0;
230
231 mem_info = cbmem_add(CBMEM_ID_MEMINFO, sizeof(struct memory_info));
Nico Huberacac02d2017-06-20 14:49:04 +0200232 if (!mem_info)
233 die("Failed to add memory info to CBMEM.\n");
Angel Pons1db5bc72020-01-15 00:49:03 +0100234
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -0500235 memset(mem_info, 0, sizeof(struct memory_info));
236
Angel Pons8b94d3e2022-01-31 16:47:54 +0100237 const u32 ddr_freq_mhz = (mchbar_read32(MC_BIOS_DATA) * 13333 * 2 + 50) / 100;
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -0500238
Angel Pons82654b32020-10-13 21:45:45 +0200239 for (ch = 0; ch < NUM_CHANNELS; ch++) {
Angel Pons2e397ae2021-03-26 12:35:57 +0100240 const u32 ch_conf = mchbar_read32(MAD_DIMM(ch));
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -0500241 /* DIMMs A/B */
Angel Pons82654b32020-10-13 21:45:45 +0200242 for (d_num = 0; d_num < NUM_SLOTS; d_num++) {
243 const u32 dimm_size = ((ch_conf >> (d_num * 8)) & 0xff) * 256;
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -0500244 if (dimm_size) {
Angel Ponsafc6c0a2021-03-12 15:49:55 +0100245 const int index = ch * NUM_SLOTS + d_num;
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -0500246 dimm = &mem_info->dimm[dimm_cnt];
247 dimm->dimm_size = dimm_size;
248 dimm->ddr_type = MEMORY_TYPE_DDR3;
Angel Pons8b94d3e2022-01-31 16:47:54 +0100249 dimm->ddr_frequency = ddr_freq_mhz * 2; /* In MT/s */
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -0500250 dimm->rank_per_dimm = 1 + ((ch_conf >> (17 + d_num)) & 1);
251 dimm->channel_num = ch;
252 dimm->dimm_num = d_num;
253 dimm->bank_locator = ch * 2;
254 memcpy(dimm->serial,
Elyes Haouas8bcd8212024-05-06 11:48:41 +0200255 &pei_data->spd_data[index][SPD_DDR3_SERIAL_NUM],
256 SPD_DDR3_SERIAL_LEN);
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -0500257 memcpy(dimm->module_part_number,
Elyes Haouas8bcd8212024-05-06 11:48:41 +0200258 &pei_data->spd_data[index][SPD_DDR3_PART_NUM],
259 SPD_DDR3_PART_LEN);
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -0500260 dimm->mod_id =
Elyes Haouas8bcd8212024-05-06 11:48:41 +0200261 (pei_data->spd_data[index][SPD_DDR3_MOD_ID2] << 8) |
262 (pei_data->spd_data[index][SPD_DDR3_MOD_ID1] & 0xff);
Elyes Haouasf82e68c2022-12-28 12:33:58 +0100263 dimm->mod_type = SPD_DDR3_DIMM_TYPE_SO_DIMM;
Elyes HAOUAS7d964ae2020-07-19 09:19:59 +0200264 dimm->bus_width = MEMORY_BUS_WIDTH_64;
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -0500265 dimm_cnt++;
266 }
267 }
268 }
269 mem_info->dimm_cnt = dimm_cnt;
Patrick Rudolph42609d82020-07-27 16:23:36 +0200270
271 const uint32_t capid0_a = pci_read_config32(HOST_BRIDGE, CAPID0_A);
272
273 const uint16_t channels = nb_number_of_channels(capid0_a);
274
Angel Pons6724ba42021-01-31 15:06:59 +0100275 mem_info->ecc_type = nb_get_ecc_type(capid0_a);
Patrick Rudolph42609d82020-07-27 16:23:36 +0200276 mem_info->max_capacity_mib = channels * nb_max_chan_capacity_mib(capid0_a);
277 mem_info->number_of_devices = channels * nb_slots_per_channel(capid0_a);
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -0500278}
Angel Ponsd99b6932021-03-12 17:37:42 +0100279
280/* Copy SPD data for on-board memory */
281static void copy_spd(struct pei_data *pei_data, struct spd_info *spdi)
282{
283 if (!CONFIG(HAVE_SPD_IN_CBFS))
284 return;
285
286 printk(BIOS_DEBUG, "SPD index %d\n", spdi->spd_index);
287
288 size_t spd_file_len;
289 uint8_t *spd_file = cbfs_map("spd.bin", &spd_file_len);
290
291 if (!spd_file)
292 die("SPD data not found.");
293
294 if (spd_file_len < ((spdi->spd_index + 1) * SPD_LEN)) {
295 printk(BIOS_ERR, "SPD index override to 0 - old hardware?\n");
296 spdi->spd_index = 0;
297 }
298
299 if (spd_file_len < SPD_LEN)
300 die("Missing SPD data.");
301
302 /* MRC only uses index 0, but coreboot uses the other indices */
303 memcpy(pei_data->spd_data[0], spd_file + (spdi->spd_index * SPD_LEN), SPD_LEN);
304
305 for (size_t i = 1; i < ARRAY_SIZE(spdi->addresses); i++) {
306 if (spdi->addresses[i] == SPD_MEMORY_DOWN)
307 memcpy(pei_data->spd_data[i], pei_data->spd_data[0], SPD_LEN);
308 }
309}
310
311/*
312 * 0 = leave channel enabled
313 * 1 = disable dimm 0 on channel
314 * 2 = disable dimm 1 on channel
315 * 3 = disable dimm 0+1 on channel
316 */
317static int make_channel_disabled_mask(const struct pei_data *pd, int ch)
318{
319 return (!pd->spd_addresses[ch + ch] << 0) | (!pd->spd_addresses[ch + ch + 1] << 1);
320}
321
Angel Ponsd0f971f2021-03-12 14:20:05 +0100322static enum pei_usb2_port_location map_to_pei_usb2_location(const enum usb2_port_location loc)
323{
324 static const enum pei_usb2_port_location map[] = {
325 [USB_PORT_SKIP] = PEI_USB_PORT_SKIP,
326 [USB_PORT_BACK_PANEL] = PEI_USB_PORT_BACK_PANEL,
327 [USB_PORT_FRONT_PANEL] = PEI_USB_PORT_FRONT_PANEL,
328 [USB_PORT_DOCK] = PEI_USB_PORT_DOCK,
329 [USB_PORT_MINI_PCIE] = PEI_USB_PORT_MINI_PCIE,
330 [USB_PORT_FLEX] = PEI_USB_PORT_FLEX,
331 [USB_PORT_INTERNAL] = PEI_USB_PORT_INTERNAL,
332 };
333 return loc >= ARRAY_SIZE(map) ? PEI_USB_PORT_SKIP : map[loc];
334}
335
336static uint8_t map_to_pei_oc_pin(const uint8_t oc_pin)
337{
338 return oc_pin >= USB_OC_PIN_SKIP ? PEI_USB_OC_PIN_SKIP : oc_pin;
339}
340
Angel Ponsd99b6932021-03-12 17:37:42 +0100341void perform_raminit(const int s3resume)
342{
343 const struct device *gbe = pcidev_on_root(0x19, 0);
344
345 const struct northbridge_intel_haswell_config *cfg = config_of_soc();
346
347 struct pei_data pei_data = {
348 .pei_version = PEI_VERSION,
349 .mchbar = CONFIG_FIXED_MCHBAR_MMIO_BASE,
350 .dmibar = CONFIG_FIXED_DMIBAR_MMIO_BASE,
351 .epbar = CONFIG_FIXED_EPBAR_MMIO_BASE,
Shelley Chen4e9bb332021-10-20 15:43:45 -0700352 .pciexbar = CONFIG_ECAM_MMCONF_BASE_ADDRESS,
Angel Ponsd99b6932021-03-12 17:37:42 +0100353 .smbusbar = CONFIG_FIXED_SMBUS_IO_BASE,
Felix Held972d9f22022-02-23 16:32:20 +0100354 .hpet_address = HPET_BASE_ADDRESS,
Angel Ponsd99b6932021-03-12 17:37:42 +0100355 .rcba = CONFIG_FIXED_RCBA_MMIO_BASE,
356 .pmbase = DEFAULT_PMBASE,
357 .gpiobase = DEFAULT_GPIOBASE,
358 .temp_mmio_base = 0xfed08000,
359 .system_type = get_pch_platform_type(),
360 .tseg_size = CONFIG_SMM_TSEG_SIZE,
361 .ec_present = cfg->ec_present,
362 .gbe_enable = gbe && gbe->enabled,
363 .ddr_refresh_2x = CONFIG(ENABLE_DDR_2X_REFRESH),
364 .dq_pins_interleaved = cfg->dq_pins_interleaved,
365 .max_ddr3_freq = 1600,
366 .usb_xhci_on_resume = cfg->usb_xhci_on_resume,
367 };
368
Angel Ponsd0f971f2021-03-12 14:20:05 +0100369 for (size_t i = 0; i < ARRAY_SIZE(mainboard_usb2_ports); i++) {
370 /* If a port is not enabled, skip it */
371 if (!mainboard_usb2_ports[i].enable) {
372 pei_data.usb2_ports[i].over_current_pin = PEI_USB_OC_PIN_SKIP;
373 pei_data.usb2_ports[i].location = PEI_USB_PORT_SKIP;
374 continue;
375 }
376 const enum usb2_port_location loc = mainboard_usb2_ports[i].location;
377 const uint8_t oc_pin = mainboard_usb2_ports[i].oc_pin;
378 pei_data.usb2_ports[i].length = mainboard_usb2_ports[i].length;
379 pei_data.usb2_ports[i].enable = mainboard_usb2_ports[i].enable;
380 pei_data.usb2_ports[i].over_current_pin = map_to_pei_oc_pin(oc_pin);
381 pei_data.usb2_ports[i].location = map_to_pei_usb2_location(loc);
382 }
383
384 for (size_t i = 0; i < ARRAY_SIZE(mainboard_usb3_ports); i++) {
385 const uint8_t oc_pin = mainboard_usb3_ports[i].oc_pin;
386 pei_data.usb3_ports[i].enable = mainboard_usb3_ports[i].enable;
387 pei_data.usb3_ports[i].over_current_pin = map_to_pei_oc_pin(oc_pin);
388 }
Angel Ponsd99b6932021-03-12 17:37:42 +0100389
390 /* MRC has hardcoded assumptions of 2 meaning S3 wake. Normalize it here. */
391 pei_data.boot_mode = s3resume ? 2 : 0;
392
393 /* Obtain the SPD addresses from mainboard code */
394 struct spd_info spdi = {0};
395 mb_get_spd_map(&spdi);
396
Angel Ponsc4ee7142021-03-12 20:48:53 +0100397 /* MRC expects left-aligned SMBus addresses, and 0xff for memory-down */
398 for (size_t i = 0; i < ARRAY_SIZE(spdi.addresses); i++) {
399 const uint8_t addr = spdi.addresses[i];
400 pei_data.spd_addresses[i] = addr == SPD_MEMORY_DOWN ? 0xff : addr << 1;
401 }
Angel Ponsd99b6932021-03-12 17:37:42 +0100402
403 /* Calculate unimplemented DIMM slots for each channel */
404 pei_data.dimm_channel0_disabled = make_channel_disabled_mask(&pei_data, 0);
405 pei_data.dimm_channel1_disabled = make_channel_disabled_mask(&pei_data, 1);
406
Jakub Czapigaad6157e2022-02-15 11:50:31 +0100407 timestamp_add_now(TS_INITRAM_START);
Angel Ponsd99b6932021-03-12 17:37:42 +0100408
409 copy_spd(&pei_data, &spdi);
410
411 sdram_initialize(&pei_data);
412
Jakub Czapigaad6157e2022-02-15 11:50:31 +0100413 timestamp_add_now(TS_INITRAM_END);
Angel Ponsd99b6932021-03-12 17:37:42 +0100414
415 post_code(0x3b);
416
417 intel_early_me_status();
418
419 int cbmem_was_initted = !cbmem_recovery(s3resume);
420 if (s3resume && !cbmem_was_initted) {
421 /* Failed S3 resume, reset to come up cleanly */
422 printk(BIOS_CRIT, "Failed to recover CBMEM in S3 resume.\n");
423 system_reset();
424 }
425
426 /* Save data returned from MRC on non-S3 resumes. */
427 if (!s3resume)
428 save_mrc_data(&pei_data);
429
430 setup_sdram_meminfo(&pei_data);
431}