Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; version 2 of the License. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #include <console/console.h> |
| 16 | #include <console/usb.h> |
| 17 | #include <bootmode.h> |
Elyes HAOUAS | c056729 | 2019-04-28 17:57:47 +0200 | [diff] [blame] | 18 | #include <cf9_reset.h> |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 19 | #include <string.h> |
Nico Huber | 47bf498 | 2019-11-17 02:58:00 +0100 | [diff] [blame] | 20 | #include <device/device.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 21 | #include <device/pci_ops.h> |
Patrick Rudolph | 5709e03 | 2019-03-25 10:12:14 +0100 | [diff] [blame] | 22 | #include <arch/cpu.h> |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 23 | #include <cbmem.h> |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 24 | #include <cbfs.h> |
| 25 | #include <ip_checksum.h> |
| 26 | #include <pc80/mc146818rtc.h> |
| 27 | #include <device/pci_def.h> |
Kyösti Mälkki | b697c90 | 2019-01-30 08:19:49 +0200 | [diff] [blame] | 28 | #include <lib.h> |
Arthur Heymans | 7539b8c | 2017-12-24 10:42:57 +0100 | [diff] [blame] | 29 | #include <mrc_cache.h> |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 30 | #include <timestamp.h> |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 31 | #include "raminit.h" |
| 32 | #include "pei_data.h" |
| 33 | #include "sandybridge.h" |
Patrick Rudolph | 5709e03 | 2019-03-25 10:12:14 +0100 | [diff] [blame] | 34 | #include "chip.h" |
Philipp Deppenwiese | fea2429 | 2017-10-17 17:02:29 +0200 | [diff] [blame] | 35 | #include <security/vboot/vboot_common.h> |
Patrick Georgi | 27fbbcf | 2019-04-23 12:33:23 +0200 | [diff] [blame] | 36 | #include <southbridge/intel/bd82x6x/pch.h> |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 37 | |
| 38 | /* Management Engine is in the southbridge */ |
Elyes HAOUAS | 21b71ce6 | 2018-06-16 18:43:52 +0200 | [diff] [blame] | 39 | #include <southbridge/intel/bd82x6x/me.h> |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 40 | |
| 41 | /* |
| 42 | * MRC scrambler seed offsets should be reserved in |
| 43 | * mainboard cmos.layout and not covered by checksum. |
| 44 | */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 45 | #if CONFIG(USE_OPTION_TABLE) |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 46 | #include "option_table.h" |
| 47 | #define CMOS_OFFSET_MRC_SEED (CMOS_VSTART_mrc_scrambler_seed >> 3) |
| 48 | #define CMOS_OFFSET_MRC_SEED_S3 (CMOS_VSTART_mrc_scrambler_seed_s3 >> 3) |
| 49 | #define CMOS_OFFSET_MRC_SEED_CHK (CMOS_VSTART_mrc_scrambler_seed_chk >> 3) |
| 50 | #else |
| 51 | #define CMOS_OFFSET_MRC_SEED 152 |
| 52 | #define CMOS_OFFSET_MRC_SEED_S3 156 |
| 53 | #define CMOS_OFFSET_MRC_SEED_CHK 160 |
| 54 | #endif |
| 55 | |
Arthur Heymans | 7539b8c | 2017-12-24 10:42:57 +0100 | [diff] [blame] | 56 | #define MRC_CACHE_VERSION 0 |
| 57 | |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 58 | void save_mrc_data(struct pei_data *pei_data) |
| 59 | { |
| 60 | u16 c1, c2, checksum; |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 61 | |
| 62 | /* Save the MRC S3 restore data to cbmem */ |
Arthur Heymans | 7539b8c | 2017-12-24 10:42:57 +0100 | [diff] [blame] | 63 | mrc_cache_stash_data(MRC_TRAINING_DATA, MRC_CACHE_VERSION, |
| 64 | pei_data->mrc_output, |
| 65 | pei_data->mrc_output_len); |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 66 | |
| 67 | /* Save the MRC seed values to CMOS */ |
Kyösti Mälkki | 2879107 | 2020-01-04 12:58:53 +0200 | [diff] [blame] | 68 | cmos_write32(pei_data->scrambler_seed, CMOS_OFFSET_MRC_SEED); |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 69 | printk(BIOS_DEBUG, "Save scrambler seed 0x%08x to CMOS 0x%02x\n", |
| 70 | pei_data->scrambler_seed, CMOS_OFFSET_MRC_SEED); |
| 71 | |
Kyösti Mälkki | 2879107 | 2020-01-04 12:58:53 +0200 | [diff] [blame] | 72 | cmos_write32(pei_data->scrambler_seed_s3, CMOS_OFFSET_MRC_SEED_S3); |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 73 | printk(BIOS_DEBUG, "Save s3 scrambler seed 0x%08x to CMOS 0x%02x\n", |
| 74 | pei_data->scrambler_seed_s3, CMOS_OFFSET_MRC_SEED_S3); |
| 75 | |
| 76 | /* Save a simple checksum of the seed values */ |
| 77 | c1 = compute_ip_checksum((u8*)&pei_data->scrambler_seed, |
| 78 | sizeof(u32)); |
| 79 | c2 = compute_ip_checksum((u8*)&pei_data->scrambler_seed_s3, |
| 80 | sizeof(u32)); |
| 81 | checksum = add_ip_checksums(sizeof(u32), c1, c2); |
| 82 | |
| 83 | cmos_write(checksum & 0xff, CMOS_OFFSET_MRC_SEED_CHK); |
| 84 | cmos_write((checksum >> 8) & 0xff, CMOS_OFFSET_MRC_SEED_CHK+1); |
| 85 | } |
| 86 | |
| 87 | static void prepare_mrc_cache(struct pei_data *pei_data) |
| 88 | { |
Arthur Heymans | 7539b8c | 2017-12-24 10:42:57 +0100 | [diff] [blame] | 89 | struct region_device rdev; |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 90 | u16 c1, c2, checksum, seed_checksum; |
| 91 | |
| 92 | // preset just in case there is an error |
| 93 | pei_data->mrc_input = NULL; |
| 94 | pei_data->mrc_input_len = 0; |
| 95 | |
| 96 | /* Read scrambler seeds from CMOS */ |
| 97 | pei_data->scrambler_seed = cmos_read32(CMOS_OFFSET_MRC_SEED); |
| 98 | printk(BIOS_DEBUG, "Read scrambler seed 0x%08x from CMOS 0x%02x\n", |
| 99 | pei_data->scrambler_seed, CMOS_OFFSET_MRC_SEED); |
| 100 | |
| 101 | pei_data->scrambler_seed_s3 = cmos_read32(CMOS_OFFSET_MRC_SEED_S3); |
| 102 | printk(BIOS_DEBUG, "Read S3 scrambler seed 0x%08x from CMOS 0x%02x\n", |
| 103 | pei_data->scrambler_seed_s3, CMOS_OFFSET_MRC_SEED_S3); |
| 104 | |
| 105 | /* Compute seed checksum and compare */ |
| 106 | c1 = compute_ip_checksum((u8*)&pei_data->scrambler_seed, |
| 107 | sizeof(u32)); |
| 108 | c2 = compute_ip_checksum((u8*)&pei_data->scrambler_seed_s3, |
| 109 | sizeof(u32)); |
| 110 | checksum = add_ip_checksums(sizeof(u32), c1, c2); |
| 111 | |
| 112 | seed_checksum = cmos_read(CMOS_OFFSET_MRC_SEED_CHK); |
| 113 | seed_checksum |= cmos_read(CMOS_OFFSET_MRC_SEED_CHK+1) << 8; |
| 114 | |
| 115 | if (checksum != seed_checksum) { |
| 116 | printk(BIOS_ERR, "%s: invalid seed checksum\n", __func__); |
| 117 | pei_data->scrambler_seed = 0; |
| 118 | pei_data->scrambler_seed_s3 = 0; |
| 119 | return; |
| 120 | } |
| 121 | |
Arthur Heymans | 7539b8c | 2017-12-24 10:42:57 +0100 | [diff] [blame] | 122 | if (mrc_cache_get_current(MRC_TRAINING_DATA, MRC_CACHE_VERSION, |
| 123 | &rdev)) { |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 124 | /* error message printed in find_current_mrc_cache */ |
| 125 | return; |
| 126 | } |
| 127 | |
Arthur Heymans | 7539b8c | 2017-12-24 10:42:57 +0100 | [diff] [blame] | 128 | pei_data->mrc_input = rdev_mmap_full(&rdev); |
| 129 | pei_data->mrc_input_len = region_device_sz(&rdev); |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 130 | |
Arthur Heymans | 7539b8c | 2017-12-24 10:42:57 +0100 | [diff] [blame] | 131 | printk(BIOS_DEBUG, "%s: at %p, size %x\n", |
| 132 | __func__, pei_data->mrc_input, pei_data->mrc_input_len); |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Elyes HAOUAS | 448d9fb | 2018-05-22 12:51:27 +0200 | [diff] [blame] | 135 | static const char *ecc_decoder[] = { |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 136 | "inactive", |
| 137 | "active on IO", |
| 138 | "disabled on IO", |
| 139 | "active" |
| 140 | }; |
| 141 | |
| 142 | /* |
| 143 | * Dump in the log memory controller configuration as read from the memory |
| 144 | * controller registers. |
| 145 | */ |
| 146 | static void report_memory_config(void) |
| 147 | { |
| 148 | u32 addr_decoder_common, addr_decode_ch[2]; |
| 149 | int i; |
| 150 | |
Felix Held | dee167e | 2019-12-30 17:30:16 +0100 | [diff] [blame] | 151 | addr_decoder_common = MCHBAR32(MAD_CHNL); |
| 152 | addr_decode_ch[0] = MCHBAR32(MAD_DIMM_CH0); |
| 153 | addr_decode_ch[1] = MCHBAR32(MAD_DIMM_CH1); |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 154 | |
| 155 | printk(BIOS_DEBUG, "memcfg DDR3 clock %d MHz\n", |
Angel Pons | 3473f76 | 2019-12-31 14:26:23 +0100 | [diff] [blame] | 156 | (MCHBAR32(MC_BIOS_DATA) * 13333 * 2 + 50)/100); |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 157 | printk(BIOS_DEBUG, "memcfg channel assignment: A: %d, B % d, C % d\n", |
| 158 | addr_decoder_common & 3, |
| 159 | (addr_decoder_common >> 2) & 3, |
| 160 | (addr_decoder_common >> 4) & 3); |
| 161 | |
| 162 | for (i = 0; i < ARRAY_SIZE(addr_decode_ch); i++) { |
| 163 | u32 ch_conf = addr_decode_ch[i]; |
| 164 | printk(BIOS_DEBUG, "memcfg channel[%d] config (%8.8x):\n", |
| 165 | i, ch_conf); |
| 166 | printk(BIOS_DEBUG, " ECC %s\n", |
| 167 | ecc_decoder[(ch_conf >> 24) & 3]); |
| 168 | printk(BIOS_DEBUG, " enhanced interleave mode %s\n", |
| 169 | ((ch_conf >> 22) & 1) ? "on" : "off"); |
| 170 | printk(BIOS_DEBUG, " rank interleave %s\n", |
| 171 | ((ch_conf >> 21) & 1) ? "on" : "off"); |
| 172 | printk(BIOS_DEBUG, " DIMMA %d MB width x%d %s rank%s\n", |
| 173 | ((ch_conf >> 0) & 0xff) * 256, |
| 174 | ((ch_conf >> 19) & 1) ? 16 : 8, |
| 175 | ((ch_conf >> 17) & 1) ? "dual" : "single", |
| 176 | ((ch_conf >> 16) & 1) ? "" : ", selected"); |
| 177 | printk(BIOS_DEBUG, " DIMMB %d MB width x%d %s rank%s\n", |
| 178 | ((ch_conf >> 8) & 0xff) * 256, |
| 179 | ((ch_conf >> 20) & 1) ? 16 : 8, |
| 180 | ((ch_conf >> 18) & 1) ? "dual" : "single", |
| 181 | ((ch_conf >> 16) & 1) ? ", selected" : ""); |
| 182 | } |
| 183 | } |
| 184 | |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 185 | /** |
| 186 | * Find PEI executable in coreboot filesystem and execute it. |
| 187 | * |
| 188 | * @param pei_data: configuration data for UEFI PEI reference code |
| 189 | */ |
| 190 | void sdram_initialize(struct pei_data *pei_data) |
| 191 | { |
| 192 | struct sys_info sysinfo; |
Stefan Reinauer | 6a00113 | 2017-07-13 02:20:27 +0200 | [diff] [blame] | 193 | int (*entry) (struct pei_data *pei_data) __attribute__((regparm(1))); |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 194 | |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 195 | /* Wait for ME to be ready */ |
| 196 | intel_early_me_init(); |
| 197 | intel_early_me_uma_size(); |
| 198 | |
| 199 | printk(BIOS_DEBUG, "Starting UEFI PEI System Agent\n"); |
| 200 | |
| 201 | memset(&sysinfo, 0, sizeof(sysinfo)); |
| 202 | |
| 203 | sysinfo.boot_path = pei_data->boot_mode; |
| 204 | |
| 205 | /* |
| 206 | * Do not pass MRC data in for recovery mode boot, |
| 207 | * Always pass it in for S3 resume. |
| 208 | */ |
Furquan Shaikh | 0325dc6 | 2016-07-25 13:02:36 -0700 | [diff] [blame] | 209 | if (!vboot_recovery_mode_enabled() || pei_data->boot_mode == 2) |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 210 | prepare_mrc_cache(pei_data); |
| 211 | |
| 212 | /* If MRC data is not found we cannot continue S3 resume. */ |
| 213 | if (pei_data->boot_mode == 2 && !pei_data->mrc_input) { |
Elyes HAOUAS | 3cd4327 | 2020-03-05 22:01:17 +0100 | [diff] [blame] | 214 | printk(BIOS_DEBUG, "Giving up in %s: No MRC data\n", __func__); |
Elyes HAOUAS | c056729 | 2019-04-28 17:57:47 +0200 | [diff] [blame] | 215 | system_reset(); |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | /* Pass console handler in pei_data */ |
| 219 | pei_data->tx_byte = do_putchar; |
| 220 | |
| 221 | /* Locate and call UEFI System Agent binary. */ |
| 222 | entry = cbfs_boot_map_with_leak("mrc.bin", CBFS_TYPE_MRC, NULL); |
| 223 | if (entry) { |
| 224 | int rv; |
| 225 | rv = entry (pei_data); |
| 226 | if (rv) { |
| 227 | switch (rv) { |
| 228 | case -1: |
| 229 | printk(BIOS_ERR, "PEI version mismatch.\n"); |
| 230 | break; |
| 231 | case -2: |
| 232 | printk(BIOS_ERR, "Invalid memory frequency.\n"); |
| 233 | break; |
| 234 | default: |
| 235 | printk(BIOS_ERR, "MRC returned %x.\n", rv); |
| 236 | } |
Keith Short | bb41aba | 2019-05-16 14:07:43 -0600 | [diff] [blame] | 237 | die_with_post_code(POST_INVALID_VENDOR_BINARY, |
| 238 | "Nonzero MRC return value.\n"); |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 239 | } |
| 240 | } else { |
| 241 | die("UEFI PEI System Agent not found.\n"); |
| 242 | } |
| 243 | |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 244 | /* mrc.bin reconfigures USB, so reinit it to have debug */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 245 | if (CONFIG(USBDEBUG_IN_PRE_RAM)) |
Kyösti Mälkki | 63649d2 | 2018-12-29 09:40:40 +0200 | [diff] [blame] | 246 | usbdebug_hw_init(true); |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 247 | |
| 248 | /* For reference print the System Agent version |
| 249 | * after executing the UEFI PEI stage. |
| 250 | */ |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 251 | u32 version = MCHBAR32(MRC_REVISION); |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 252 | printk(BIOS_DEBUG, "System Agent Version %d.%d.%d Build %d\n", |
Elyes HAOUAS | a342f39 | 2018-10-17 10:56:26 +0200 | [diff] [blame] | 253 | version >> 24, (version >> 16) & 0xff, |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 254 | (version >> 8) & 0xff, version & 0xff); |
| 255 | |
| 256 | /* Send ME init done for SandyBridge here. This is done |
| 257 | * inside the SystemAgent binary on IvyBridge. */ |
| 258 | if (BASE_REV_SNB == |
| 259 | (pci_read_config16(PCI_CPU_DEVICE, PCI_DEVICE_ID) & BASE_REV_MASK)) |
| 260 | intel_early_me_init_done(ME_INIT_STATUS_SUCCESS); |
| 261 | else |
| 262 | intel_early_me_status(); |
| 263 | |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 264 | report_memory_config(); |
| 265 | } |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 266 | |
Arthur Heymans | 01c83a2 | 2019-06-05 13:36:55 +0200 | [diff] [blame] | 267 | /* These are the location and structure of MRC_VAR data in CAR. |
| 268 | The CAR region looks like this: |
| 269 | +------------------+ -> DCACHE_RAM_BASE |
| 270 | | | |
| 271 | | | |
| 272 | | COREBOOT STACK | |
| 273 | | | |
| 274 | | | |
| 275 | +------------------+ -> DCACHE_RAM_BASE + DCACHE_RAM_SIZE |
| 276 | | | |
| 277 | | MRC HEAP | |
| 278 | | size = 0x5000 | |
| 279 | | | |
| 280 | +------------------+ |
| 281 | | | |
| 282 | | MRC VAR | |
| 283 | | size = 0x4000 | |
| 284 | | | |
| 285 | +------------------+ -> DACHE_RAM_BASE + DACHE_RAM_SIZE |
| 286 | + DCACHE_RAM_MRC_VAR_SIZE |
| 287 | |
| 288 | */ |
Kyösti Mälkki | b697c90 | 2019-01-30 08:19:49 +0200 | [diff] [blame] | 289 | #define DCACHE_RAM_MRC_VAR_BASE \ |
Arthur Heymans | 01c83a2 | 2019-06-05 13:36:55 +0200 | [diff] [blame] | 290 | (CONFIG_DCACHE_RAM_BASE + CONFIG_DCACHE_RAM_SIZE + \ |
| 291 | CONFIG_DCACHE_RAM_MRC_VAR_SIZE - 0x4000) |
Kyösti Mälkki | b697c90 | 2019-01-30 08:19:49 +0200 | [diff] [blame] | 292 | |
| 293 | struct mrc_var_data { |
| 294 | u32 acpi_timer_flag; |
| 295 | u32 pool_used; |
| 296 | u32 pool_base; |
| 297 | u32 tx_byte; |
| 298 | u32 reserved[4]; |
| 299 | } __packed; |
| 300 | |
Patrick Rudolph | 5709e03 | 2019-03-25 10:12:14 +0100 | [diff] [blame] | 301 | static void northbridge_fill_pei_data(struct pei_data *pei_data) |
| 302 | { |
| 303 | pei_data->mchbar = (uintptr_t)DEFAULT_MCHBAR; |
| 304 | pei_data->dmibar = (uintptr_t)DEFAULT_DMIBAR; |
| 305 | pei_data->epbar = DEFAULT_EPBAR; |
| 306 | pei_data->pciexbar = CONFIG_MMCONF_BASE_ADDRESS; |
| 307 | pei_data->hpet_address = CONFIG_HPET_ADDRESS; |
| 308 | pei_data->thermalbase = 0xfed08000; |
| 309 | pei_data->system_type = get_platform_type() == PLATFORM_MOBILE ? 0 : 1; |
| 310 | pei_data->tseg_size = CONFIG_SMM_TSEG_SIZE; |
| 311 | |
| 312 | if ((cpu_get_cpuid() & 0xffff0) == 0x306a0) { |
| 313 | const struct device *dev = pcidev_on_root(1, 0); |
| 314 | pei_data->pcie_init = dev && dev->enabled; |
| 315 | } else { |
| 316 | pei_data->pcie_init = 0; |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | static void southbridge_fill_pei_data(struct pei_data *pei_data) |
| 321 | { |
| 322 | const struct device *dev = pcidev_on_root(0x19, 0); |
| 323 | |
| 324 | pei_data->smbusbar = SMBUS_IO_BASE; |
| 325 | pei_data->wdbbar = 0x4000000; |
| 326 | pei_data->wdbsize = 0x1000; |
| 327 | pei_data->rcba = (uintptr_t)DEFAULT_RCBABASE; |
| 328 | pei_data->pmbase = DEFAULT_PMBASE; |
| 329 | pei_data->gpiobase = DEFAULT_GPIOBASE; |
| 330 | pei_data->gbe_enable = dev && dev->enabled; |
| 331 | } |
| 332 | |
| 333 | static void devicetree_fill_pei_data(struct pei_data *pei_data) |
| 334 | { |
| 335 | const struct northbridge_intel_sandybridge_config *cfg; |
| 336 | |
| 337 | const struct device *dev = pcidev_on_root(0, 0); |
| 338 | if (!dev || !dev->chip_info) |
| 339 | return; |
| 340 | |
| 341 | cfg = dev->chip_info; |
| 342 | |
| 343 | switch (cfg->max_mem_clock_mhz) { |
| 344 | /* MRC only supports fixed numbers of frequencies */ |
| 345 | default: |
| 346 | printk(BIOS_WARNING, "RAMINIT: Limiting DDR3 clock to 800 Mhz\n"); |
| 347 | /* fallthrough */ |
| 348 | case 400: |
| 349 | pei_data->max_ddr3_freq = 800; |
| 350 | break; |
| 351 | case 533: |
| 352 | pei_data->max_ddr3_freq = 1066; |
| 353 | break; |
| 354 | case 666: |
| 355 | pei_data->max_ddr3_freq = 1333; |
| 356 | break; |
| 357 | case 800: |
| 358 | pei_data->max_ddr3_freq = 1600; |
| 359 | break; |
| 360 | |
| 361 | } |
| 362 | |
| 363 | memcpy(pei_data->spd_addresses, cfg->spd_addresses, |
| 364 | sizeof(pei_data->spd_addresses)); |
| 365 | |
| 366 | memcpy(pei_data->ts_addresses, cfg->ts_addresses, |
| 367 | sizeof(pei_data->ts_addresses)); |
| 368 | |
| 369 | pei_data->ec_present = cfg->ec_present; |
| 370 | pei_data->ddr3lv_support = cfg->ddr3lv_support; |
| 371 | |
| 372 | pei_data->nmode = cfg->nmode; |
| 373 | pei_data->ddr_refresh_rate_config = cfg->ddr_refresh_rate_config; |
| 374 | |
| 375 | memcpy(pei_data->usb_port_config, cfg->usb_port_config, |
| 376 | sizeof(pei_data->usb_port_config)); |
| 377 | |
| 378 | pei_data->usb3.mode = cfg->usb3.mode; |
| 379 | pei_data->usb3.hs_port_switch_mask = cfg->usb3.hs_port_switch_mask; |
| 380 | pei_data->usb3.preboot_support = cfg->usb3.preboot_support; |
| 381 | pei_data->usb3.xhci_streams = cfg->usb3.xhci_streams; |
| 382 | } |
| 383 | |
Nico Huber | 47bf498 | 2019-11-17 02:58:00 +0100 | [diff] [blame] | 384 | static void disable_p2p(void) |
| 385 | { |
| 386 | /* Disable PCI-to-PCI bridge early to prevent probing by MRC. */ |
| 387 | const struct device *const p2p = pcidev_on_root(0x1e, 0); |
| 388 | if (p2p && p2p->enabled) |
| 389 | return; |
| 390 | |
| 391 | RCBA32(FD) |= PCH_DISABLE_P2P; |
| 392 | } |
| 393 | |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 394 | void perform_raminit(int s3resume) |
| 395 | { |
| 396 | int cbmem_was_initted; |
| 397 | struct pei_data pei_data; |
Kyösti Mälkki | b697c90 | 2019-01-30 08:19:49 +0200 | [diff] [blame] | 398 | struct mrc_var_data *mrc_var; |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 399 | |
| 400 | /* Prepare USB controller early in S3 resume */ |
| 401 | if (!mainboard_should_reset_usb(s3resume)) |
| 402 | enable_usb_bar(); |
| 403 | |
Patrick Rudolph | 5709e03 | 2019-03-25 10:12:14 +0100 | [diff] [blame] | 404 | memset(&pei_data, 0, sizeof(pei_data)); |
| 405 | pei_data.pei_version = PEI_VERSION, |
| 406 | |
| 407 | northbridge_fill_pei_data(&pei_data); |
| 408 | southbridge_fill_pei_data(&pei_data); |
| 409 | devicetree_fill_pei_data(&pei_data); |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 410 | mainboard_fill_pei_data(&pei_data); |
| 411 | |
| 412 | post_code(0x3a); |
Patrick Rudolph | 59b4255 | 2019-05-08 12:44:15 +0200 | [diff] [blame] | 413 | |
Patrick Rudolph | 5709e03 | 2019-03-25 10:12:14 +0100 | [diff] [blame] | 414 | /* Fill after mainboard_fill_pei_data as it might provide spd_data */ |
| 415 | pei_data.dimm_channel0_disabled = |
| 416 | (!pei_data.spd_addresses[0] && !pei_data.spd_data[0][0]) + |
| 417 | (!pei_data.spd_addresses[1] && !pei_data.spd_data[1][0]) * 2; |
| 418 | |
| 419 | pei_data.dimm_channel1_disabled = |
| 420 | (!pei_data.spd_addresses[2] && !pei_data.spd_data[2][0]) + |
| 421 | (!pei_data.spd_addresses[3] && !pei_data.spd_data[3][0]) * 2; |
| 422 | |
Patrick Rudolph | 59b4255 | 2019-05-08 12:44:15 +0200 | [diff] [blame] | 423 | /* Fix spd_data. MRC only uses spd_data[0] and ignores the other */ |
| 424 | for (size_t i = 1; i < ARRAY_SIZE(pei_data.spd_data); i++) { |
| 425 | if (pei_data.spd_data[i][0] && !pei_data.spd_data[0][0]) { |
| 426 | memcpy(pei_data.spd_data[0], pei_data.spd_data[i], |
| 427 | sizeof(pei_data.spd_data[0])); |
| 428 | } else if (pei_data.spd_data[i][0] && pei_data.spd_data[0][0]) { |
| 429 | if (memcmp(pei_data.spd_data[i], pei_data.spd_data[0], |
| 430 | sizeof(pei_data.spd_data[0])) != 0) |
| 431 | die("Onboard SPDs must match each other"); |
| 432 | } |
| 433 | } |
| 434 | |
Nico Huber | 47bf498 | 2019-11-17 02:58:00 +0100 | [diff] [blame] | 435 | disable_p2p(); |
| 436 | |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 437 | pei_data.boot_mode = s3resume ? 2 : 0; |
| 438 | timestamp_add_now(TS_BEFORE_INITRAM); |
| 439 | sdram_initialize(&pei_data); |
Kyösti Mälkki | b697c90 | 2019-01-30 08:19:49 +0200 | [diff] [blame] | 440 | |
| 441 | mrc_var = (void *)DCACHE_RAM_MRC_VAR_BASE; |
| 442 | /* Sanity check mrc_var location by verifying a known field. */ |
| 443 | if (mrc_var->tx_byte == (uintptr_t)pei_data.tx_byte) { |
| 444 | printk(BIOS_DEBUG, "MRC_VAR pool occupied [%08x,%08x]\n", |
| 445 | mrc_var->pool_base, |
| 446 | mrc_var->pool_base + mrc_var->pool_used); |
| 447 | } else { |
| 448 | printk(BIOS_ERR, "Could not parse MRC_VAR data\n"); |
| 449 | hexdump32(BIOS_ERR, mrc_var, sizeof(*mrc_var)/sizeof(u32)); |
| 450 | } |
| 451 | |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 452 | cbmem_was_initted = !cbmem_recovery(s3resume); |
| 453 | if (!s3resume) |
| 454 | save_mrc_data(&pei_data); |
| 455 | |
| 456 | if (s3resume && !cbmem_was_initted) { |
| 457 | /* Failed S3 resume, reset to come up cleanly */ |
Elyes HAOUAS | c056729 | 2019-04-28 17:57:47 +0200 | [diff] [blame] | 458 | system_reset(); |
Vladimir Serbinenko | ffbb3c0 | 2016-02-10 01:36:25 +0100 | [diff] [blame] | 459 | } |
| 460 | } |