blob: bddec6c66b6609326e7c0730411959ee93f35453 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Simon Glass0b36ecd2014-11-12 22:42:07 -07002/*
3 * Copyright (c) 2011 The Chromium OS Authors.
4 * (C) Copyright 2010,2011
5 * Graeme Russ, <graeme.russ@gmail.com>
6 *
7 * Portions from Coreboot mainboard/google/link/romstage.c
8 * Copyright (C) 2007-2010 coresystems GmbH
9 * Copyright (C) 2011 Google Inc.
Simon Glass0b36ecd2014-11-12 22:42:07 -070010 */
11
Simon Glass3a1d96f2023-07-15 21:39:11 -060012#define LOG_CATEGORY UCLASS_RAM
13
Simon Glass7130b952020-07-19 10:15:40 -060014#include <dm.h>
Simon Glass268eefd2014-11-12 22:42:28 -070015#include <errno.h>
16#include <fdtdec.h>
Simon Glass6980b6b2019-11-14 12:57:45 -070017#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060018#include <log.h>
Simon Glass268eefd2014-11-12 22:42:28 -070019#include <malloc.h>
Simon Glass428dfa42015-01-19 22:16:14 -070020#include <net.h>
21#include <rtc.h>
22#include <spi.h>
23#include <spi_flash.h>
Simon Glass43a50342016-01-17 16:11:58 -070024#include <syscon.h>
Bin Mengaf5b8d22018-07-19 03:07:33 -070025#include <sysreset.h>
Simon Glass43a50342016-01-17 16:11:58 -070026#include <asm/cpu.h>
Simon Glass268eefd2014-11-12 22:42:28 -070027#include <asm/processor.h>
28#include <asm/gpio.h>
29#include <asm/global_data.h>
Simon Glass55357302016-03-11 22:06:55 -070030#include <asm/intel_regs.h>
Bin Meng21666cf2015-10-11 21:37:36 -070031#include <asm/mrccache.h>
Simon Glasse623ff62016-03-16 07:44:38 -060032#include <asm/mrc_common.h>
Simon Glassa754b952015-01-01 16:18:10 -070033#include <asm/mtrr.h>
Simon Glass268eefd2014-11-12 22:42:28 -070034#include <asm/pci.h>
Simon Glassb67be7e2016-03-11 22:07:00 -070035#include <asm/report_platform.h>
Simon Glass268eefd2014-11-12 22:42:28 -070036#include <asm/arch/me.h>
37#include <asm/arch/pei_data.h>
38#include <asm/arch/pch.h>
39#include <asm/post.h>
40#include <asm/arch/sandybridge.h>
41
42DECLARE_GLOBAL_DATA_PTR;
43
Simon Glass428dfa42015-01-19 22:16:14 -070044#define CMOS_OFFSET_MRC_SEED 152
45#define CMOS_OFFSET_MRC_SEED_S3 156
46#define CMOS_OFFSET_MRC_SEED_CHK 160
47
Heinrich Schuchardt51a9aac2023-08-12 20:16:58 +020048phys_addr_t board_get_usable_ram_top(phys_size_t total_size)
Simon Glass268eefd2014-11-12 22:42:28 -070049{
Simon Glasse623ff62016-03-16 07:44:38 -060050 return mrc_common_board_get_usable_ram_top(total_size);
Simon Glass268eefd2014-11-12 22:42:28 -070051}
52
Simon Glass2f949c32017-03-31 08:40:32 -060053int dram_init_banksize(void)
Simon Glass268eefd2014-11-12 22:42:28 -070054{
Simon Glasse623ff62016-03-16 07:44:38 -060055 mrc_common_dram_init_banksize();
Simon Glass2f949c32017-03-31 08:40:32 -060056
57 return 0;
Simon Glass428dfa42015-01-19 22:16:14 -070058}
59
Simon Glass428dfa42015-01-19 22:16:14 -070060static int read_seed_from_cmos(struct pei_data *pei_data)
61{
62 u16 c1, c2, checksum, seed_checksum;
Bin Meng770fd332015-07-15 16:23:39 +080063 struct udevice *dev;
Simon Glassa45312e2015-10-18 15:55:32 -060064 int ret = 0;
Bin Meng770fd332015-07-15 16:23:39 +080065
Simon Glassa45312e2015-10-18 15:55:32 -060066 ret = uclass_get_device(UCLASS_RTC, 0, &dev);
67 if (ret) {
68 debug("Cannot find RTC: err=%d\n", ret);
Bin Meng770fd332015-07-15 16:23:39 +080069 return -ENODEV;
70 }
Simon Glass428dfa42015-01-19 22:16:14 -070071
72 /*
73 * Read scrambler seeds from CMOS RAM. We don't want to store them in
74 * SPI flash since they change on every boot and that would wear down
75 * the flash too much. So we store these in CMOS and the large MRC
76 * data in SPI flash.
77 */
Simon Glass664c0e12015-10-18 15:55:33 -060078 ret = rtc_read32(dev, CMOS_OFFSET_MRC_SEED, &pei_data->scrambler_seed);
79 if (!ret) {
80 ret = rtc_read32(dev, CMOS_OFFSET_MRC_SEED_S3,
81 &pei_data->scrambler_seed_s3);
82 }
83 if (ret) {
84 debug("Failed to read from RTC %s\n", dev->name);
85 return ret;
86 }
87
Simon Glass428dfa42015-01-19 22:16:14 -070088 debug("Read scrambler seed 0x%08x from CMOS 0x%02x\n",
89 pei_data->scrambler_seed, CMOS_OFFSET_MRC_SEED);
Simon Glass428dfa42015-01-19 22:16:14 -070090 debug("Read S3 scrambler seed 0x%08x from CMOS 0x%02x\n",
91 pei_data->scrambler_seed_s3, CMOS_OFFSET_MRC_SEED_S3);
92
93 /* Compute seed checksum and compare */
94 c1 = compute_ip_checksum((u8 *)&pei_data->scrambler_seed,
95 sizeof(u32));
96 c2 = compute_ip_checksum((u8 *)&pei_data->scrambler_seed_s3,
97 sizeof(u32));
98 checksum = add_ip_checksums(sizeof(u32), c1, c2);
99
Bin Meng770fd332015-07-15 16:23:39 +0800100 seed_checksum = rtc_read8(dev, CMOS_OFFSET_MRC_SEED_CHK);
101 seed_checksum |= rtc_read8(dev, CMOS_OFFSET_MRC_SEED_CHK + 1) << 8;
Simon Glass428dfa42015-01-19 22:16:14 -0700102
103 if (checksum != seed_checksum) {
104 debug("%s: invalid seed checksum\n", __func__);
105 pei_data->scrambler_seed = 0;
106 pei_data->scrambler_seed_s3 = 0;
107 return -EINVAL;
108 }
109
110 return 0;
111}
112
113static int prepare_mrc_cache(struct pei_data *pei_data)
114{
115 struct mrc_data_container *mrc_cache;
Bin Meng2845ead2015-10-11 21:37:41 -0700116 struct mrc_region entry;
Simon Glass428dfa42015-01-19 22:16:14 -0700117 int ret;
118
119 ret = read_seed_from_cmos(pei_data);
120 if (ret)
121 return ret;
Simon Glass91efff52019-12-06 21:42:07 -0700122 ret = mrccache_get_region(MRC_TYPE_NORMAL, NULL, &entry);
Simon Glass428dfa42015-01-19 22:16:14 -0700123 if (ret)
124 return ret;
125 mrc_cache = mrccache_find_current(&entry);
126 if (!mrc_cache)
127 return -ENOENT;
128
Bin Meng149f24f2015-10-18 15:55:37 -0600129 pei_data->mrc_input = mrc_cache->data;
130 pei_data->mrc_input_len = mrc_cache->data_size;
Simon Glass428dfa42015-01-19 22:16:14 -0700131 debug("%s: at %p, size %x checksum %04x\n", __func__,
132 pei_data->mrc_input, pei_data->mrc_input_len,
133 mrc_cache->checksum);
134
135 return 0;
136}
137
Simon Glass428dfa42015-01-19 22:16:14 -0700138static int write_seeds_to_cmos(struct pei_data *pei_data)
139{
140 u16 c1, c2, checksum;
Bin Meng770fd332015-07-15 16:23:39 +0800141 struct udevice *dev;
Simon Glassa45312e2015-10-18 15:55:32 -0600142 int ret = 0;
Bin Meng770fd332015-07-15 16:23:39 +0800143
Simon Glassa45312e2015-10-18 15:55:32 -0600144 ret = uclass_get_device(UCLASS_RTC, 0, &dev);
145 if (ret) {
146 debug("Cannot find RTC: err=%d\n", ret);
Bin Meng770fd332015-07-15 16:23:39 +0800147 return -ENODEV;
148 }
Simon Glass428dfa42015-01-19 22:16:14 -0700149
150 /* Save the MRC seed values to CMOS */
Bin Meng770fd332015-07-15 16:23:39 +0800151 rtc_write32(dev, CMOS_OFFSET_MRC_SEED, pei_data->scrambler_seed);
Simon Glass428dfa42015-01-19 22:16:14 -0700152 debug("Save scrambler seed 0x%08x to CMOS 0x%02x\n",
153 pei_data->scrambler_seed, CMOS_OFFSET_MRC_SEED);
154
Bin Meng770fd332015-07-15 16:23:39 +0800155 rtc_write32(dev, CMOS_OFFSET_MRC_SEED_S3, pei_data->scrambler_seed_s3);
Simon Glass428dfa42015-01-19 22:16:14 -0700156 debug("Save s3 scrambler seed 0x%08x to CMOS 0x%02x\n",
157 pei_data->scrambler_seed_s3, CMOS_OFFSET_MRC_SEED_S3);
158
159 /* Save a simple checksum of the seed values */
160 c1 = compute_ip_checksum((u8 *)&pei_data->scrambler_seed,
161 sizeof(u32));
162 c2 = compute_ip_checksum((u8 *)&pei_data->scrambler_seed_s3,
163 sizeof(u32));
164 checksum = add_ip_checksums(sizeof(u32), c1, c2);
165
Bin Meng770fd332015-07-15 16:23:39 +0800166 rtc_write8(dev, CMOS_OFFSET_MRC_SEED_CHK, checksum & 0xff);
167 rtc_write8(dev, CMOS_OFFSET_MRC_SEED_CHK + 1, (checksum >> 8) & 0xff);
Simon Glass428dfa42015-01-19 22:16:14 -0700168
169 return 0;
170}
171
Simon Glass428dfa42015-01-19 22:16:14 -0700172/* Use this hook to save our SDRAM parameters */
173int misc_init_r(void)
174{
175 int ret;
176
Bin Mengf34c0592015-10-11 21:37:40 -0700177 ret = mrccache_save();
Simon Glass428dfa42015-01-19 22:16:14 -0700178 if (ret)
179 printf("Unable to save MRC data: %d\n", ret);
180
181 return 0;
182}
183
Simon Glasse623ff62016-03-16 07:44:38 -0600184static void post_system_agent_init(struct udevice *dev, struct udevice *me_dev,
185 struct pei_data *pei_data)
Simon Glass268eefd2014-11-12 22:42:28 -0700186{
Simon Glass268eefd2014-11-12 22:42:28 -0700187 uint16_t done;
Simon Glass268eefd2014-11-12 22:42:28 -0700188
189 /*
190 * Send ME init done for SandyBridge here. This is done inside the
191 * SystemAgent binary on IvyBridge
192 */
Simon Glass1e186f52016-01-17 16:11:48 -0700193 dm_pci_read_config16(dev, PCI_DEVICE_ID, &done);
Simon Glass268eefd2014-11-12 22:42:28 -0700194 done &= BASE_REV_MASK;
195 if (BASE_REV_SNB == done)
Simon Glass37a91ff2016-01-17 16:11:50 -0700196 intel_early_me_init_done(dev, me_dev, ME_INIT_STATUS_SUCCESS);
Simon Glass268eefd2014-11-12 22:42:28 -0700197 else
Simon Glassb67be7e2016-03-11 22:07:00 -0700198 intel_me_status(me_dev);
Simon Glass268eefd2014-11-12 22:42:28 -0700199
Simon Glasse623ff62016-03-16 07:44:38 -0600200 /* If PCIe init is skipped, set the PEG clock gating */
201 if (!pei_data->pcie_init)
202 setbits_le32(MCHBAR_REG(0x7010), 1);
Simon Glass428dfa42015-01-19 22:16:14 -0700203}
204
Simon Glasse623ff62016-03-16 07:44:38 -0600205static int recovery_mode_enabled(void)
Simon Glass428dfa42015-01-19 22:16:14 -0700206{
Simon Glasse623ff62016-03-16 07:44:38 -0600207 return false;
Simon Glass268eefd2014-11-12 22:42:28 -0700208}
209
Simon Glasse623ff62016-03-16 07:44:38 -0600210static int copy_spd(struct udevice *dev, struct pei_data *peid)
Simon Glass268eefd2014-11-12 22:42:28 -0700211{
Simon Glasse623ff62016-03-16 07:44:38 -0600212 const void *data;
213 int ret;
Simon Glass268eefd2014-11-12 22:42:28 -0700214
Simon Glasse623ff62016-03-16 07:44:38 -0600215 ret = mrc_locate_spd(dev, sizeof(peid->spd_data[0]), &data);
Simon Glasse5367962017-01-16 07:03:38 -0700216 if (ret) {
Simon Glass3a1d96f2023-07-15 21:39:11 -0600217 log_debug("Could not locate SPD (err=%d)\n", ret);
Simon Glasse623ff62016-03-16 07:44:38 -0600218 return ret;
Simon Glasse5367962017-01-16 07:03:38 -0700219 }
Simon Glass268eefd2014-11-12 22:42:28 -0700220
Simon Glasse623ff62016-03-16 07:44:38 -0600221 memcpy(peid->spd_data[0], data, sizeof(peid->spd_data[0]));
Simon Glass268eefd2014-11-12 22:42:28 -0700222
223 return 0;
224}
225
226/**
227 * sdram_find() - Find available memory
228 *
229 * This is a bit complicated since on x86 there are system memory holes all
230 * over the place. We create a list of available memory blocks
Simon Glassa33044b2016-01-17 16:11:47 -0700231 *
232 * @dev: Northbridge device
Simon Glass268eefd2014-11-12 22:42:28 -0700233 */
Simon Glassa33044b2016-01-17 16:11:47 -0700234static int sdram_find(struct udevice *dev)
Simon Glass268eefd2014-11-12 22:42:28 -0700235{
236 struct memory_info *info = &gd->arch.meminfo;
237 uint32_t tseg_base, uma_size, tolud;
238 uint64_t tom, me_base, touud;
239 uint64_t uma_memory_base = 0;
Simon Glass268eefd2014-11-12 22:42:28 -0700240 unsigned long long tomk;
241 uint16_t ggc;
Simon Glassa33044b2016-01-17 16:11:47 -0700242 u32 val;
Simon Glass268eefd2014-11-12 22:42:28 -0700243
244 /* Total Memory 2GB example:
245 *
246 * 00000000 0000MB-1992MB 1992MB RAM (writeback)
247 * 7c800000 1992MB-2000MB 8MB TSEG (SMRR)
248 * 7d000000 2000MB-2002MB 2MB GFX GTT (uncached)
249 * 7d200000 2002MB-2034MB 32MB GFX UMA (uncached)
250 * 7f200000 2034MB TOLUD
251 * 7f800000 2040MB MEBASE
252 * 7f800000 2040MB-2048MB 8MB ME UMA (uncached)
253 * 80000000 2048MB TOM
254 * 100000000 4096MB-4102MB 6MB RAM (writeback)
255 *
256 * Total Memory 4GB example:
257 *
258 * 00000000 0000MB-2768MB 2768MB RAM (writeback)
259 * ad000000 2768MB-2776MB 8MB TSEG (SMRR)
260 * ad800000 2776MB-2778MB 2MB GFX GTT (uncached)
261 * ada00000 2778MB-2810MB 32MB GFX UMA (uncached)
262 * afa00000 2810MB TOLUD
263 * ff800000 4088MB MEBASE
264 * ff800000 4088MB-4096MB 8MB ME UMA (uncached)
265 * 100000000 4096MB TOM
266 * 100000000 4096MB-5374MB 1278MB RAM (writeback)
267 * 14fe00000 5368MB TOUUD
268 */
269
270 /* Top of Upper Usable DRAM, including remap */
Simon Glassa33044b2016-01-17 16:11:47 -0700271 dm_pci_read_config32(dev, TOUUD + 4, &val);
272 touud = (uint64_t)val << 32;
273 dm_pci_read_config32(dev, TOUUD, &val);
274 touud |= val;
Simon Glass268eefd2014-11-12 22:42:28 -0700275
276 /* Top of Lower Usable DRAM */
Simon Glassa33044b2016-01-17 16:11:47 -0700277 dm_pci_read_config32(dev, TOLUD, &tolud);
Simon Glass268eefd2014-11-12 22:42:28 -0700278
279 /* Top of Memory - does not account for any UMA */
Simon Glassa33044b2016-01-17 16:11:47 -0700280 dm_pci_read_config32(dev, 0xa4, &val);
281 tom = (uint64_t)val << 32;
282 dm_pci_read_config32(dev, 0xa0, &val);
283 tom |= val;
Simon Glass268eefd2014-11-12 22:42:28 -0700284
285 debug("TOUUD %llx TOLUD %08x TOM %llx\n", touud, tolud, tom);
286
287 /* ME UMA needs excluding if total memory <4GB */
Simon Glassa33044b2016-01-17 16:11:47 -0700288 dm_pci_read_config32(dev, 0x74, &val);
289 me_base = (uint64_t)val << 32;
290 dm_pci_read_config32(dev, 0x70, &val);
291 me_base |= val;
Simon Glass268eefd2014-11-12 22:42:28 -0700292
293 debug("MEBASE %llx\n", me_base);
294
295 /* TODO: Get rid of all this shifting by 10 bits */
296 tomk = tolud >> 10;
297 if (me_base == tolud) {
298 /* ME is from MEBASE-TOM */
299 uma_size = (tom - me_base) >> 10;
300 /* Increment TOLUD to account for ME as RAM */
301 tolud += uma_size << 10;
302 /* UMA starts at old TOLUD */
303 uma_memory_base = tomk * 1024ULL;
Simon Glass268eefd2014-11-12 22:42:28 -0700304 debug("ME UMA base %llx size %uM\n", me_base, uma_size >> 10);
305 }
306
307 /* Graphics memory comes next */
Simon Glassa33044b2016-01-17 16:11:47 -0700308 dm_pci_read_config16(dev, GGC, &ggc);
Simon Glass268eefd2014-11-12 22:42:28 -0700309 if (!(ggc & 2)) {
310 debug("IGD decoded, subtracting ");
311
312 /* Graphics memory */
313 uma_size = ((ggc >> 3) & 0x1f) * 32 * 1024ULL;
314 debug("%uM UMA", uma_size >> 10);
315 tomk -= uma_size;
316 uma_memory_base = tomk * 1024ULL;
Simon Glass268eefd2014-11-12 22:42:28 -0700317
318 /* GTT Graphics Stolen Memory Size (GGMS) */
319 uma_size = ((ggc >> 8) & 0x3) * 1024ULL;
320 tomk -= uma_size;
321 uma_memory_base = tomk * 1024ULL;
Simon Glass268eefd2014-11-12 22:42:28 -0700322 debug(" and %uM GTT\n", uma_size >> 10);
323 }
324
325 /* Calculate TSEG size from its base which must be below GTT */
Simon Glassa33044b2016-01-17 16:11:47 -0700326 dm_pci_read_config32(dev, 0xb8, &tseg_base);
Simon Glass268eefd2014-11-12 22:42:28 -0700327 uma_size = (uma_memory_base - tseg_base) >> 10;
328 tomk -= uma_size;
329 uma_memory_base = tomk * 1024ULL;
Simon Glass268eefd2014-11-12 22:42:28 -0700330 debug("TSEG base 0x%08x size %uM\n", tseg_base, uma_size >> 10);
331
332 debug("Available memory below 4GB: %lluM\n", tomk >> 10);
333
334 /* Report the memory regions */
Simon Glasse623ff62016-03-16 07:44:38 -0600335 mrc_add_memory_area(info, 1 << 20, 2 << 28);
336 mrc_add_memory_area(info, (2 << 28) + (2 << 20), 4 << 28);
337 mrc_add_memory_area(info, (4 << 28) + (2 << 20), tseg_base);
338 mrc_add_memory_area(info, 1ULL << 32, touud);
Simon Glassa754b952015-01-01 16:18:10 -0700339
340 /* Add MTRRs for memory */
341 mtrr_add_request(MTRR_TYPE_WRBACK, 0, 2ULL << 30);
342 mtrr_add_request(MTRR_TYPE_WRBACK, 2ULL << 30, 512 << 20);
343 mtrr_add_request(MTRR_TYPE_WRBACK, 0xaULL << 28, 256 << 20);
344 mtrr_add_request(MTRR_TYPE_UNCACHEABLE, tseg_base, 16 << 20);
345 mtrr_add_request(MTRR_TYPE_UNCACHEABLE, tseg_base + (16 << 20),
346 32 << 20);
347
Simon Glass268eefd2014-11-12 22:42:28 -0700348 /*
349 * If >= 4GB installed then memory from TOLUD to 4GB
350 * is remapped above TOM, TOUUD will account for both
351 */
352 if (touud > (1ULL << 32ULL)) {
353 debug("Available memory above 4GB: %lluM\n",
354 (touud >> 20) - 4096);
355 }
356
357 return 0;
358}
359
360static void rcba_config(void)
361{
362 /*
363 * GFX INTA -> PIRQA (MSI)
364 * D28IP_P3IP WLAN INTA -> PIRQB
365 * D29IP_E1P EHCI1 INTA -> PIRQD
366 * D26IP_E2P EHCI2 INTA -> PIRQF
367 * D31IP_SIP SATA INTA -> PIRQF (MSI)
368 * D31IP_SMIP SMBUS INTB -> PIRQH
369 * D31IP_TTIP THRT INTC -> PIRQA
370 * D27IP_ZIP HDA INTA -> PIRQA (MSI)
371 *
372 * TRACKPAD -> PIRQE (Edge Triggered)
373 * TOUCHSCREEN -> PIRQG (Edge Triggered)
374 */
375
376 /* Device interrupt pin register (board specific) */
377 writel((INTC << D31IP_TTIP) | (NOINT << D31IP_SIP2) |
378 (INTB << D31IP_SMIP) | (INTA << D31IP_SIP), RCB_REG(D31IP));
379 writel(NOINT << D30IP_PIP, RCB_REG(D30IP));
380 writel(INTA << D29IP_E1P, RCB_REG(D29IP));
381 writel(INTA << D28IP_P3IP, RCB_REG(D28IP));
382 writel(INTA << D27IP_ZIP, RCB_REG(D27IP));
383 writel(INTA << D26IP_E2P, RCB_REG(D26IP));
384 writel(NOINT << D25IP_LIP, RCB_REG(D25IP));
385 writel(NOINT << D22IP_MEI1IP, RCB_REG(D22IP));
386
387 /* Device interrupt route registers */
388 writel(DIR_ROUTE(PIRQB, PIRQH, PIRQA, PIRQC), RCB_REG(D31IR));
389 writel(DIR_ROUTE(PIRQD, PIRQE, PIRQF, PIRQG), RCB_REG(D29IR));
390 writel(DIR_ROUTE(PIRQB, PIRQC, PIRQD, PIRQE), RCB_REG(D28IR));
391 writel(DIR_ROUTE(PIRQA, PIRQH, PIRQA, PIRQB), RCB_REG(D27IR));
392 writel(DIR_ROUTE(PIRQF, PIRQE, PIRQG, PIRQH), RCB_REG(D26IR));
393 writel(DIR_ROUTE(PIRQA, PIRQB, PIRQC, PIRQD), RCB_REG(D25IR));
394 writel(DIR_ROUTE(PIRQA, PIRQB, PIRQC, PIRQD), RCB_REG(D22IR));
395
396 /* Enable IOAPIC (generic) */
397 writew(0x0100, RCB_REG(OIC));
398 /* PCH BWG says to read back the IOAPIC enable register */
399 (void)readw(RCB_REG(OIC));
400
401 /* Disable unused devices (board specific) */
402 setbits_le32(RCB_REG(FD), PCH_DISABLE_ALWAYS);
403}
Simon Glass0b36ecd2014-11-12 22:42:07 -0700404
405int dram_init(void)
406{
Simon Glasse623ff62016-03-16 07:44:38 -0600407 struct pei_data _pei_data __aligned(8) = {
Simon Glass268eefd2014-11-12 22:42:28 -0700408 .pei_version = PEI_VERSION,
Simon Glass55357302016-03-11 22:06:55 -0700409 .mchbar = MCH_BASE_ADDRESS,
Simon Glass268eefd2014-11-12 22:42:28 -0700410 .dmibar = DEFAULT_DMIBAR,
411 .epbar = DEFAULT_EPBAR,
Simon Glass461cebf2015-01-27 22:13:33 -0700412 .pciexbar = CONFIG_PCIE_ECAM_BASE,
Simon Glass268eefd2014-11-12 22:42:28 -0700413 .smbusbar = SMBUS_IO_BASE,
414 .wdbbar = 0x4000000,
415 .wdbsize = 0x1000,
416 .hpet_address = CONFIG_HPET_ADDRESS,
417 .rcba = DEFAULT_RCBABASE,
418 .pmbase = DEFAULT_PMBASE,
419 .gpiobase = DEFAULT_GPIOBASE,
420 .thermalbase = 0xfed08000,
421 .system_type = 0, /* 0 Mobile, 1 Desktop/Server */
422 .tseg_size = CONFIG_SMM_TSEG_SIZE,
423 .ts_addresses = { 0x00, 0x00, 0x00, 0x00 },
424 .ec_present = 1,
425 .ddr3lv_support = 1,
426 /*
427 * 0 = leave channel enabled
428 * 1 = disable dimm 0 on channel
429 * 2 = disable dimm 1 on channel
430 * 3 = disable dimm 0+1 on channel
431 */
432 .dimm_channel0_disabled = 2,
433 .dimm_channel1_disabled = 2,
434 .max_ddr3_freq = 1600,
435 .usb_port_config = {
436 /*
437 * Empty and onboard Ports 0-7, set to un-used pin
438 * OC3
439 */
440 { 0, 3, 0x0000 }, /* P0= Empty */
441 { 1, 0, 0x0040 }, /* P1= Left USB 1 (OC0) */
442 { 1, 1, 0x0040 }, /* P2= Left USB 2 (OC1) */
443 { 1, 3, 0x0040 }, /* P3= SDCARD (no OC) */
444 { 0, 3, 0x0000 }, /* P4= Empty */
445 { 1, 3, 0x0040 }, /* P5= WWAN (no OC) */
446 { 0, 3, 0x0000 }, /* P6= Empty */
447 { 0, 3, 0x0000 }, /* P7= Empty */
448 /*
449 * Empty and onboard Ports 8-13, set to un-used pin
450 * OC4
451 */
452 { 1, 4, 0x0040 }, /* P8= Camera (no OC) */
453 { 1, 4, 0x0040 }, /* P9= Bluetooth (no OC) */
454 { 0, 4, 0x0000 }, /* P10= Empty */
455 { 0, 4, 0x0000 }, /* P11= Empty */
456 { 0, 4, 0x0000 }, /* P12= Empty */
457 { 0, 4, 0x0000 }, /* P13= Empty */
458 },
459 };
Simon Glasse623ff62016-03-16 07:44:38 -0600460 struct pei_data *pei_data = &_pei_data;
Simon Glass37a91ff2016-01-17 16:11:50 -0700461 struct udevice *dev, *me_dev;
Simon Glass268eefd2014-11-12 22:42:28 -0700462 int ret;
463
Simon Glasse0f0cc52016-07-11 09:30:55 -0600464 /* We need the pinctrl set up early */
465 ret = syscon_get_by_driver_data(X86_SYSCON_PINCONF, &dev);
Simon Glasse5367962017-01-16 07:03:38 -0700466 if (ret) {
467 debug("%s: Could not get pinconf (ret=%d)\n", __func__, ret);
Simon Glasse0f0cc52016-07-11 09:30:55 -0600468 return ret;
Simon Glasse5367962017-01-16 07:03:38 -0700469 }
Simon Glasse0f0cc52016-07-11 09:30:55 -0600470
Simon Glassc7298e72016-02-11 13:23:26 -0700471 ret = uclass_first_device_err(UCLASS_NORTHBRIDGE, &dev);
Simon Glasse5367962017-01-16 07:03:38 -0700472 if (ret) {
473 debug("%s: Could not get northbridge (ret=%d)\n", __func__,
474 ret);
Simon Glass1e186f52016-01-17 16:11:48 -0700475 return ret;
Simon Glasse5367962017-01-16 07:03:38 -0700476 }
Simon Glass43a50342016-01-17 16:11:58 -0700477 ret = syscon_get_by_driver_data(X86_SYSCON_ME, &me_dev);
Simon Glasse5367962017-01-16 07:03:38 -0700478 if (ret) {
479 debug("%s: Could not get ME (ret=%d)\n", __func__, ret);
Simon Glass37a91ff2016-01-17 16:11:50 -0700480 return ret;
Simon Glasse5367962017-01-16 07:03:38 -0700481 }
Simon Glasse623ff62016-03-16 07:44:38 -0600482 ret = copy_spd(dev, pei_data);
Simon Glasse5367962017-01-16 07:03:38 -0700483 if (ret) {
484 debug("%s: Could not get SPD (ret=%d)\n", __func__, ret);
Simon Glass268eefd2014-11-12 22:42:28 -0700485 return ret;
Simon Glasse5367962017-01-16 07:03:38 -0700486 }
Simon Glasse623ff62016-03-16 07:44:38 -0600487 pei_data->boot_mode = gd->arch.pei_boot_mode;
488 debug("Boot mode %d\n", gd->arch.pei_boot_mode);
489 debug("mrc_input %p\n", pei_data->mrc_input);
Simon Glass268eefd2014-11-12 22:42:28 -0700490
Simon Glasse623ff62016-03-16 07:44:38 -0600491 /*
492 * Do not pass MRC data in for recovery mode boot,
493 * Always pass it in for S3 resume.
494 */
495 if (!recovery_mode_enabled() ||
496 pei_data->boot_mode == PEI_BOOT_RESUME) {
497 ret = prepare_mrc_cache(pei_data);
498 if (ret)
499 debug("prepare_mrc_cache failed: %d\n", ret);
500 }
Simon Glass268eefd2014-11-12 22:42:28 -0700501
Simon Glasse623ff62016-03-16 07:44:38 -0600502 /* If MRC data is not found we cannot continue S3 resume. */
503 if (pei_data->boot_mode == PEI_BOOT_RESUME && !pei_data->mrc_input) {
504 debug("Giving up in sdram_initialize: No MRC data\n");
Bin Mengaf5b8d22018-07-19 03:07:33 -0700505 sysreset_walk_halt(SYSRESET_COLD);
Simon Glasse623ff62016-03-16 07:44:38 -0600506 }
Simon Glass268eefd2014-11-12 22:42:28 -0700507
Simon Glasse623ff62016-03-16 07:44:38 -0600508 /* Pass console handler in pei_data */
509 pei_data->tx_byte = sdram_console_tx_byte;
Simon Glass268eefd2014-11-12 22:42:28 -0700510
Simon Glasse623ff62016-03-16 07:44:38 -0600511 /* Wait for ME to be ready */
512 ret = intel_early_me_init(me_dev);
Simon Glasse5367962017-01-16 07:03:38 -0700513 if (ret) {
514 debug("%s: Could not init ME (ret=%d)\n", __func__, ret);
Simon Glass268eefd2014-11-12 22:42:28 -0700515 return ret;
Simon Glasse5367962017-01-16 07:03:38 -0700516 }
Simon Glasse623ff62016-03-16 07:44:38 -0600517 ret = intel_early_me_uma_size(me_dev);
Simon Glasse5367962017-01-16 07:03:38 -0700518 if (ret < 0) {
519 debug("%s: Could not get UMA size (ret=%d)\n", __func__, ret);
Simon Glasse623ff62016-03-16 07:44:38 -0600520 return ret;
Simon Glasse5367962017-01-16 07:03:38 -0700521 }
Simon Glasse623ff62016-03-16 07:44:38 -0600522
523 ret = mrc_common_init(dev, pei_data, false);
Simon Glasse5367962017-01-16 07:03:38 -0700524 if (ret) {
525 debug("%s: mrc_common_init() failed (ret=%d)\n", __func__, ret);
Simon Glasse623ff62016-03-16 07:44:38 -0600526 return ret;
Simon Glasse5367962017-01-16 07:03:38 -0700527 }
Simon Glass268eefd2014-11-12 22:42:28 -0700528
Simon Glasse623ff62016-03-16 07:44:38 -0600529 ret = sdram_find(dev);
Simon Glasse5367962017-01-16 07:03:38 -0700530 if (ret) {
531 debug("%s: sdram_find() failed (ret=%d)\n", __func__, ret);
Simon Glasse623ff62016-03-16 07:44:38 -0600532 return ret;
Simon Glasse5367962017-01-16 07:03:38 -0700533 }
Simon Glass268eefd2014-11-12 22:42:28 -0700534 gd->ram_size = gd->arch.meminfo.total_32bit_memory;
Simon Glass0b36ecd2014-11-12 22:42:07 -0700535
Simon Glasse623ff62016-03-16 07:44:38 -0600536 debug("MRC output data length %#x at %p\n", pei_data->mrc_output_len,
537 pei_data->mrc_output);
538
539 post_system_agent_init(dev, me_dev, pei_data);
540 report_memory_config();
541
542 /* S3 resume: don't save scrambler seed or MRC data */
543 if (pei_data->boot_mode != PEI_BOOT_RESUME) {
Simon Glass91efff52019-12-06 21:42:07 -0700544 struct mrc_output *mrc = &gd->arch.mrc[MRC_TYPE_NORMAL];
545
Simon Glasse623ff62016-03-16 07:44:38 -0600546 /*
547 * This will be copied to SDRAM in reserve_arch(), then written
548 * to SPI flash in mrccache_save()
549 */
Simon Glass91efff52019-12-06 21:42:07 -0700550 mrc->buf = (char *)pei_data->mrc_output;
551 mrc->len = pei_data->mrc_output_len;
Simon Glasse623ff62016-03-16 07:44:38 -0600552 ret = write_seeds_to_cmos(pei_data);
553 if (ret)
554 debug("Failed to write seeds to CMOS: %d\n", ret);
555 }
556
557 writew(0xCAFE, MCHBAR_REG(SSKPD));
558 if (ret)
559 return ret;
560
561 rcba_config();
562
Simon Glass0b36ecd2014-11-12 22:42:07 -0700563 return 0;
564}