blob: 99bc48021e6900fdb439fc2b1e8e04de99dfa93e [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Simon Glass8ef07572014-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 Glass8ef07572014-11-12 22:42:07 -070010 */
11
12#include <common.h>
Simon Glass65dd74a2014-11-12 22:42:28 -070013#include <errno.h>
14#include <fdtdec.h>
Simon Glass67c4e9f2019-11-14 12:57:45 -070015#include <init.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060016#include <log.h>
Simon Glass65dd74a2014-11-12 22:42:28 -070017#include <malloc.h>
Simon Glass191c0082015-01-19 22:16:14 -070018#include <net.h>
19#include <rtc.h>
20#include <spi.h>
21#include <spi_flash.h>
Simon Glass98655f32016-01-17 16:11:58 -070022#include <syscon.h>
Bin Mengb37b7b22018-07-19 03:07:33 -070023#include <sysreset.h>
Simon Glass98655f32016-01-17 16:11:58 -070024#include <asm/cpu.h>
Simon Glass65dd74a2014-11-12 22:42:28 -070025#include <asm/processor.h>
26#include <asm/gpio.h>
27#include <asm/global_data.h>
Simon Glass06d336c2016-03-11 22:06:55 -070028#include <asm/intel_regs.h>
Bin Mengf6220f12015-10-11 21:37:36 -070029#include <asm/mrccache.h>
Simon Glass147ba412016-03-16 07:44:38 -060030#include <asm/mrc_common.h>
Simon Glassaaafcd62015-01-01 16:18:10 -070031#include <asm/mtrr.h>
Simon Glass65dd74a2014-11-12 22:42:28 -070032#include <asm/pci.h>
Simon Glass8b900a42016-03-11 22:07:00 -070033#include <asm/report_platform.h>
Simon Glass65dd74a2014-11-12 22:42:28 -070034#include <asm/arch/me.h>
35#include <asm/arch/pei_data.h>
36#include <asm/arch/pch.h>
37#include <asm/post.h>
38#include <asm/arch/sandybridge.h>
39
40DECLARE_GLOBAL_DATA_PTR;
41
Simon Glass191c0082015-01-19 22:16:14 -070042#define CMOS_OFFSET_MRC_SEED 152
43#define CMOS_OFFSET_MRC_SEED_S3 156
44#define CMOS_OFFSET_MRC_SEED_CHK 160
45
Simon Glass65dd74a2014-11-12 22:42:28 -070046ulong board_get_usable_ram_top(ulong total_size)
47{
Simon Glass147ba412016-03-16 07:44:38 -060048 return mrc_common_board_get_usable_ram_top(total_size);
Simon Glass65dd74a2014-11-12 22:42:28 -070049}
50
Simon Glass76b00ac2017-03-31 08:40:32 -060051int dram_init_banksize(void)
Simon Glass65dd74a2014-11-12 22:42:28 -070052{
Simon Glass147ba412016-03-16 07:44:38 -060053 mrc_common_dram_init_banksize();
Simon Glass76b00ac2017-03-31 08:40:32 -060054
55 return 0;
Simon Glass65dd74a2014-11-12 22:42:28 -070056}
57
Simon Glass191c0082015-01-19 22:16:14 -070058static int read_seed_from_cmos(struct pei_data *pei_data)
59{
60 u16 c1, c2, checksum, seed_checksum;
Bin Meng93f8a312015-07-15 16:23:39 +080061 struct udevice *dev;
Simon Glass53327d32015-10-18 15:55:32 -060062 int ret = 0;
Bin Meng93f8a312015-07-15 16:23:39 +080063
Simon Glass53327d32015-10-18 15:55:32 -060064 ret = uclass_get_device(UCLASS_RTC, 0, &dev);
65 if (ret) {
66 debug("Cannot find RTC: err=%d\n", ret);
Bin Meng93f8a312015-07-15 16:23:39 +080067 return -ENODEV;
68 }
Simon Glass191c0082015-01-19 22:16:14 -070069
70 /*
71 * Read scrambler seeds from CMOS RAM. We don't want to store them in
72 * SPI flash since they change on every boot and that would wear down
73 * the flash too much. So we store these in CMOS and the large MRC
74 * data in SPI flash.
75 */
Simon Glass9fbc5cc2015-10-18 15:55:33 -060076 ret = rtc_read32(dev, CMOS_OFFSET_MRC_SEED, &pei_data->scrambler_seed);
77 if (!ret) {
78 ret = rtc_read32(dev, CMOS_OFFSET_MRC_SEED_S3,
79 &pei_data->scrambler_seed_s3);
80 }
81 if (ret) {
82 debug("Failed to read from RTC %s\n", dev->name);
83 return ret;
84 }
85
Simon Glass191c0082015-01-19 22:16:14 -070086 debug("Read scrambler seed 0x%08x from CMOS 0x%02x\n",
87 pei_data->scrambler_seed, CMOS_OFFSET_MRC_SEED);
Simon Glass191c0082015-01-19 22:16:14 -070088 debug("Read S3 scrambler seed 0x%08x from CMOS 0x%02x\n",
89 pei_data->scrambler_seed_s3, CMOS_OFFSET_MRC_SEED_S3);
90
91 /* Compute seed checksum and compare */
92 c1 = compute_ip_checksum((u8 *)&pei_data->scrambler_seed,
93 sizeof(u32));
94 c2 = compute_ip_checksum((u8 *)&pei_data->scrambler_seed_s3,
95 sizeof(u32));
96 checksum = add_ip_checksums(sizeof(u32), c1, c2);
97
Bin Meng93f8a312015-07-15 16:23:39 +080098 seed_checksum = rtc_read8(dev, CMOS_OFFSET_MRC_SEED_CHK);
99 seed_checksum |= rtc_read8(dev, CMOS_OFFSET_MRC_SEED_CHK + 1) << 8;
Simon Glass191c0082015-01-19 22:16:14 -0700100
101 if (checksum != seed_checksum) {
102 debug("%s: invalid seed checksum\n", __func__);
103 pei_data->scrambler_seed = 0;
104 pei_data->scrambler_seed_s3 = 0;
105 return -EINVAL;
106 }
107
108 return 0;
109}
110
111static int prepare_mrc_cache(struct pei_data *pei_data)
112{
113 struct mrc_data_container *mrc_cache;
Bin Meng4b9f6a62015-10-11 21:37:41 -0700114 struct mrc_region entry;
Simon Glass191c0082015-01-19 22:16:14 -0700115 int ret;
116
117 ret = read_seed_from_cmos(pei_data);
118 if (ret)
119 return ret;
Simon Glass515e8172019-12-06 21:42:07 -0700120 ret = mrccache_get_region(MRC_TYPE_NORMAL, NULL, &entry);
Simon Glass191c0082015-01-19 22:16:14 -0700121 if (ret)
122 return ret;
123 mrc_cache = mrccache_find_current(&entry);
124 if (!mrc_cache)
125 return -ENOENT;
126
Bin Meng3e45de62015-10-18 15:55:37 -0600127 pei_data->mrc_input = mrc_cache->data;
128 pei_data->mrc_input_len = mrc_cache->data_size;
Simon Glass191c0082015-01-19 22:16:14 -0700129 debug("%s: at %p, size %x checksum %04x\n", __func__,
130 pei_data->mrc_input, pei_data->mrc_input_len,
131 mrc_cache->checksum);
132
133 return 0;
134}
135
Simon Glass191c0082015-01-19 22:16:14 -0700136static int write_seeds_to_cmos(struct pei_data *pei_data)
137{
138 u16 c1, c2, checksum;
Bin Meng93f8a312015-07-15 16:23:39 +0800139 struct udevice *dev;
Simon Glass53327d32015-10-18 15:55:32 -0600140 int ret = 0;
Bin Meng93f8a312015-07-15 16:23:39 +0800141
Simon Glass53327d32015-10-18 15:55:32 -0600142 ret = uclass_get_device(UCLASS_RTC, 0, &dev);
143 if (ret) {
144 debug("Cannot find RTC: err=%d\n", ret);
Bin Meng93f8a312015-07-15 16:23:39 +0800145 return -ENODEV;
146 }
Simon Glass191c0082015-01-19 22:16:14 -0700147
148 /* Save the MRC seed values to CMOS */
Bin Meng93f8a312015-07-15 16:23:39 +0800149 rtc_write32(dev, CMOS_OFFSET_MRC_SEED, pei_data->scrambler_seed);
Simon Glass191c0082015-01-19 22:16:14 -0700150 debug("Save scrambler seed 0x%08x to CMOS 0x%02x\n",
151 pei_data->scrambler_seed, CMOS_OFFSET_MRC_SEED);
152
Bin Meng93f8a312015-07-15 16:23:39 +0800153 rtc_write32(dev, CMOS_OFFSET_MRC_SEED_S3, pei_data->scrambler_seed_s3);
Simon Glass191c0082015-01-19 22:16:14 -0700154 debug("Save s3 scrambler seed 0x%08x to CMOS 0x%02x\n",
155 pei_data->scrambler_seed_s3, CMOS_OFFSET_MRC_SEED_S3);
156
157 /* Save a simple checksum of the seed values */
158 c1 = compute_ip_checksum((u8 *)&pei_data->scrambler_seed,
159 sizeof(u32));
160 c2 = compute_ip_checksum((u8 *)&pei_data->scrambler_seed_s3,
161 sizeof(u32));
162 checksum = add_ip_checksums(sizeof(u32), c1, c2);
163
Bin Meng93f8a312015-07-15 16:23:39 +0800164 rtc_write8(dev, CMOS_OFFSET_MRC_SEED_CHK, checksum & 0xff);
165 rtc_write8(dev, CMOS_OFFSET_MRC_SEED_CHK + 1, (checksum >> 8) & 0xff);
Simon Glass191c0082015-01-19 22:16:14 -0700166
167 return 0;
168}
169
Simon Glass191c0082015-01-19 22:16:14 -0700170/* Use this hook to save our SDRAM parameters */
171int misc_init_r(void)
172{
173 int ret;
174
Bin Meng42913a12015-10-11 21:37:40 -0700175 ret = mrccache_save();
Simon Glass191c0082015-01-19 22:16:14 -0700176 if (ret)
177 printf("Unable to save MRC data: %d\n", ret);
178
179 return 0;
180}
181
Simon Glass147ba412016-03-16 07:44:38 -0600182static void post_system_agent_init(struct udevice *dev, struct udevice *me_dev,
183 struct pei_data *pei_data)
Simon Glass65dd74a2014-11-12 22:42:28 -0700184{
Simon Glass65dd74a2014-11-12 22:42:28 -0700185 uint16_t done;
Simon Glass65dd74a2014-11-12 22:42:28 -0700186
187 /*
188 * Send ME init done for SandyBridge here. This is done inside the
189 * SystemAgent binary on IvyBridge
190 */
Simon Glass1641bb82016-01-17 16:11:48 -0700191 dm_pci_read_config16(dev, PCI_DEVICE_ID, &done);
Simon Glass65dd74a2014-11-12 22:42:28 -0700192 done &= BASE_REV_MASK;
193 if (BASE_REV_SNB == done)
Simon Glassc02a4242016-01-17 16:11:50 -0700194 intel_early_me_init_done(dev, me_dev, ME_INIT_STATUS_SUCCESS);
Simon Glass65dd74a2014-11-12 22:42:28 -0700195 else
Simon Glass8b900a42016-03-11 22:07:00 -0700196 intel_me_status(me_dev);
Simon Glass65dd74a2014-11-12 22:42:28 -0700197
Simon Glass147ba412016-03-16 07:44:38 -0600198 /* If PCIe init is skipped, set the PEG clock gating */
199 if (!pei_data->pcie_init)
200 setbits_le32(MCHBAR_REG(0x7010), 1);
201}
Simon Glass65dd74a2014-11-12 22:42:28 -0700202
Simon Glass147ba412016-03-16 07:44:38 -0600203static int recovery_mode_enabled(void)
204{
205 return false;
Simon Glass191c0082015-01-19 22:16:14 -0700206}
207
Simon Glass147ba412016-03-16 07:44:38 -0600208static int copy_spd(struct udevice *dev, struct pei_data *peid)
Simon Glass65dd74a2014-11-12 22:42:28 -0700209{
Simon Glass147ba412016-03-16 07:44:38 -0600210 const void *data;
211 int ret;
Simon Glass65dd74a2014-11-12 22:42:28 -0700212
Simon Glass147ba412016-03-16 07:44:38 -0600213 ret = mrc_locate_spd(dev, sizeof(peid->spd_data[0]), &data);
Simon Glass8d8f3ac2017-01-16 07:03:38 -0700214 if (ret) {
215 debug("%s: Could not locate SPD (ret=%d)\n", __func__, ret);
Simon Glass147ba412016-03-16 07:44:38 -0600216 return ret;
Simon Glass8d8f3ac2017-01-16 07:03:38 -0700217 }
Simon Glass65dd74a2014-11-12 22:42:28 -0700218
Simon Glass147ba412016-03-16 07:44:38 -0600219 memcpy(peid->spd_data[0], data, sizeof(peid->spd_data[0]));
Simon Glass65dd74a2014-11-12 22:42:28 -0700220
221 return 0;
222}
223
224/**
225 * sdram_find() - Find available memory
226 *
227 * This is a bit complicated since on x86 there are system memory holes all
228 * over the place. We create a list of available memory blocks
Simon Glass2588e712016-01-17 16:11:47 -0700229 *
230 * @dev: Northbridge device
Simon Glass65dd74a2014-11-12 22:42:28 -0700231 */
Simon Glass2588e712016-01-17 16:11:47 -0700232static int sdram_find(struct udevice *dev)
Simon Glass65dd74a2014-11-12 22:42:28 -0700233{
234 struct memory_info *info = &gd->arch.meminfo;
235 uint32_t tseg_base, uma_size, tolud;
236 uint64_t tom, me_base, touud;
237 uint64_t uma_memory_base = 0;
Simon Glass65dd74a2014-11-12 22:42:28 -0700238 unsigned long long tomk;
239 uint16_t ggc;
Simon Glass2588e712016-01-17 16:11:47 -0700240 u32 val;
Simon Glass65dd74a2014-11-12 22:42:28 -0700241
242 /* Total Memory 2GB example:
243 *
244 * 00000000 0000MB-1992MB 1992MB RAM (writeback)
245 * 7c800000 1992MB-2000MB 8MB TSEG (SMRR)
246 * 7d000000 2000MB-2002MB 2MB GFX GTT (uncached)
247 * 7d200000 2002MB-2034MB 32MB GFX UMA (uncached)
248 * 7f200000 2034MB TOLUD
249 * 7f800000 2040MB MEBASE
250 * 7f800000 2040MB-2048MB 8MB ME UMA (uncached)
251 * 80000000 2048MB TOM
252 * 100000000 4096MB-4102MB 6MB RAM (writeback)
253 *
254 * Total Memory 4GB example:
255 *
256 * 00000000 0000MB-2768MB 2768MB RAM (writeback)
257 * ad000000 2768MB-2776MB 8MB TSEG (SMRR)
258 * ad800000 2776MB-2778MB 2MB GFX GTT (uncached)
259 * ada00000 2778MB-2810MB 32MB GFX UMA (uncached)
260 * afa00000 2810MB TOLUD
261 * ff800000 4088MB MEBASE
262 * ff800000 4088MB-4096MB 8MB ME UMA (uncached)
263 * 100000000 4096MB TOM
264 * 100000000 4096MB-5374MB 1278MB RAM (writeback)
265 * 14fe00000 5368MB TOUUD
266 */
267
268 /* Top of Upper Usable DRAM, including remap */
Simon Glass2588e712016-01-17 16:11:47 -0700269 dm_pci_read_config32(dev, TOUUD + 4, &val);
270 touud = (uint64_t)val << 32;
271 dm_pci_read_config32(dev, TOUUD, &val);
272 touud |= val;
Simon Glass65dd74a2014-11-12 22:42:28 -0700273
274 /* Top of Lower Usable DRAM */
Simon Glass2588e712016-01-17 16:11:47 -0700275 dm_pci_read_config32(dev, TOLUD, &tolud);
Simon Glass65dd74a2014-11-12 22:42:28 -0700276
277 /* Top of Memory - does not account for any UMA */
Simon Glass2588e712016-01-17 16:11:47 -0700278 dm_pci_read_config32(dev, 0xa4, &val);
279 tom = (uint64_t)val << 32;
280 dm_pci_read_config32(dev, 0xa0, &val);
281 tom |= val;
Simon Glass65dd74a2014-11-12 22:42:28 -0700282
283 debug("TOUUD %llx TOLUD %08x TOM %llx\n", touud, tolud, tom);
284
285 /* ME UMA needs excluding if total memory <4GB */
Simon Glass2588e712016-01-17 16:11:47 -0700286 dm_pci_read_config32(dev, 0x74, &val);
287 me_base = (uint64_t)val << 32;
288 dm_pci_read_config32(dev, 0x70, &val);
289 me_base |= val;
Simon Glass65dd74a2014-11-12 22:42:28 -0700290
291 debug("MEBASE %llx\n", me_base);
292
293 /* TODO: Get rid of all this shifting by 10 bits */
294 tomk = tolud >> 10;
295 if (me_base == tolud) {
296 /* ME is from MEBASE-TOM */
297 uma_size = (tom - me_base) >> 10;
298 /* Increment TOLUD to account for ME as RAM */
299 tolud += uma_size << 10;
300 /* UMA starts at old TOLUD */
301 uma_memory_base = tomk * 1024ULL;
Simon Glass65dd74a2014-11-12 22:42:28 -0700302 debug("ME UMA base %llx size %uM\n", me_base, uma_size >> 10);
303 }
304
305 /* Graphics memory comes next */
Simon Glass2588e712016-01-17 16:11:47 -0700306 dm_pci_read_config16(dev, GGC, &ggc);
Simon Glass65dd74a2014-11-12 22:42:28 -0700307 if (!(ggc & 2)) {
308 debug("IGD decoded, subtracting ");
309
310 /* Graphics memory */
311 uma_size = ((ggc >> 3) & 0x1f) * 32 * 1024ULL;
312 debug("%uM UMA", uma_size >> 10);
313 tomk -= uma_size;
314 uma_memory_base = tomk * 1024ULL;
Simon Glass65dd74a2014-11-12 22:42:28 -0700315
316 /* GTT Graphics Stolen Memory Size (GGMS) */
317 uma_size = ((ggc >> 8) & 0x3) * 1024ULL;
318 tomk -= uma_size;
319 uma_memory_base = tomk * 1024ULL;
Simon Glass65dd74a2014-11-12 22:42:28 -0700320 debug(" and %uM GTT\n", uma_size >> 10);
321 }
322
323 /* Calculate TSEG size from its base which must be below GTT */
Simon Glass2588e712016-01-17 16:11:47 -0700324 dm_pci_read_config32(dev, 0xb8, &tseg_base);
Simon Glass65dd74a2014-11-12 22:42:28 -0700325 uma_size = (uma_memory_base - tseg_base) >> 10;
326 tomk -= uma_size;
327 uma_memory_base = tomk * 1024ULL;
Simon Glass65dd74a2014-11-12 22:42:28 -0700328 debug("TSEG base 0x%08x size %uM\n", tseg_base, uma_size >> 10);
329
330 debug("Available memory below 4GB: %lluM\n", tomk >> 10);
331
332 /* Report the memory regions */
Simon Glass147ba412016-03-16 07:44:38 -0600333 mrc_add_memory_area(info, 1 << 20, 2 << 28);
334 mrc_add_memory_area(info, (2 << 28) + (2 << 20), 4 << 28);
335 mrc_add_memory_area(info, (4 << 28) + (2 << 20), tseg_base);
336 mrc_add_memory_area(info, 1ULL << 32, touud);
Simon Glassaaafcd62015-01-01 16:18:10 -0700337
338 /* Add MTRRs for memory */
339 mtrr_add_request(MTRR_TYPE_WRBACK, 0, 2ULL << 30);
340 mtrr_add_request(MTRR_TYPE_WRBACK, 2ULL << 30, 512 << 20);
341 mtrr_add_request(MTRR_TYPE_WRBACK, 0xaULL << 28, 256 << 20);
342 mtrr_add_request(MTRR_TYPE_UNCACHEABLE, tseg_base, 16 << 20);
343 mtrr_add_request(MTRR_TYPE_UNCACHEABLE, tseg_base + (16 << 20),
344 32 << 20);
345
Simon Glass65dd74a2014-11-12 22:42:28 -0700346 /*
347 * If >= 4GB installed then memory from TOLUD to 4GB
348 * is remapped above TOM, TOUUD will account for both
349 */
350 if (touud > (1ULL << 32ULL)) {
351 debug("Available memory above 4GB: %lluM\n",
352 (touud >> 20) - 4096);
353 }
354
355 return 0;
356}
357
358static void rcba_config(void)
359{
360 /*
361 * GFX INTA -> PIRQA (MSI)
362 * D28IP_P3IP WLAN INTA -> PIRQB
363 * D29IP_E1P EHCI1 INTA -> PIRQD
364 * D26IP_E2P EHCI2 INTA -> PIRQF
365 * D31IP_SIP SATA INTA -> PIRQF (MSI)
366 * D31IP_SMIP SMBUS INTB -> PIRQH
367 * D31IP_TTIP THRT INTC -> PIRQA
368 * D27IP_ZIP HDA INTA -> PIRQA (MSI)
369 *
370 * TRACKPAD -> PIRQE (Edge Triggered)
371 * TOUCHSCREEN -> PIRQG (Edge Triggered)
372 */
373
374 /* Device interrupt pin register (board specific) */
375 writel((INTC << D31IP_TTIP) | (NOINT << D31IP_SIP2) |
376 (INTB << D31IP_SMIP) | (INTA << D31IP_SIP), RCB_REG(D31IP));
377 writel(NOINT << D30IP_PIP, RCB_REG(D30IP));
378 writel(INTA << D29IP_E1P, RCB_REG(D29IP));
379 writel(INTA << D28IP_P3IP, RCB_REG(D28IP));
380 writel(INTA << D27IP_ZIP, RCB_REG(D27IP));
381 writel(INTA << D26IP_E2P, RCB_REG(D26IP));
382 writel(NOINT << D25IP_LIP, RCB_REG(D25IP));
383 writel(NOINT << D22IP_MEI1IP, RCB_REG(D22IP));
384
385 /* Device interrupt route registers */
386 writel(DIR_ROUTE(PIRQB, PIRQH, PIRQA, PIRQC), RCB_REG(D31IR));
387 writel(DIR_ROUTE(PIRQD, PIRQE, PIRQF, PIRQG), RCB_REG(D29IR));
388 writel(DIR_ROUTE(PIRQB, PIRQC, PIRQD, PIRQE), RCB_REG(D28IR));
389 writel(DIR_ROUTE(PIRQA, PIRQH, PIRQA, PIRQB), RCB_REG(D27IR));
390 writel(DIR_ROUTE(PIRQF, PIRQE, PIRQG, PIRQH), RCB_REG(D26IR));
391 writel(DIR_ROUTE(PIRQA, PIRQB, PIRQC, PIRQD), RCB_REG(D25IR));
392 writel(DIR_ROUTE(PIRQA, PIRQB, PIRQC, PIRQD), RCB_REG(D22IR));
393
394 /* Enable IOAPIC (generic) */
395 writew(0x0100, RCB_REG(OIC));
396 /* PCH BWG says to read back the IOAPIC enable register */
397 (void)readw(RCB_REG(OIC));
398
399 /* Disable unused devices (board specific) */
400 setbits_le32(RCB_REG(FD), PCH_DISABLE_ALWAYS);
401}
Simon Glass8ef07572014-11-12 22:42:07 -0700402
403int dram_init(void)
404{
Simon Glass147ba412016-03-16 07:44:38 -0600405 struct pei_data _pei_data __aligned(8) = {
Simon Glass65dd74a2014-11-12 22:42:28 -0700406 .pei_version = PEI_VERSION,
Simon Glass06d336c2016-03-11 22:06:55 -0700407 .mchbar = MCH_BASE_ADDRESS,
Simon Glass65dd74a2014-11-12 22:42:28 -0700408 .dmibar = DEFAULT_DMIBAR,
409 .epbar = DEFAULT_EPBAR,
Simon Glass2d934e52015-01-27 22:13:33 -0700410 .pciexbar = CONFIG_PCIE_ECAM_BASE,
Simon Glass65dd74a2014-11-12 22:42:28 -0700411 .smbusbar = SMBUS_IO_BASE,
412 .wdbbar = 0x4000000,
413 .wdbsize = 0x1000,
414 .hpet_address = CONFIG_HPET_ADDRESS,
415 .rcba = DEFAULT_RCBABASE,
416 .pmbase = DEFAULT_PMBASE,
417 .gpiobase = DEFAULT_GPIOBASE,
418 .thermalbase = 0xfed08000,
419 .system_type = 0, /* 0 Mobile, 1 Desktop/Server */
420 .tseg_size = CONFIG_SMM_TSEG_SIZE,
421 .ts_addresses = { 0x00, 0x00, 0x00, 0x00 },
422 .ec_present = 1,
423 .ddr3lv_support = 1,
424 /*
425 * 0 = leave channel enabled
426 * 1 = disable dimm 0 on channel
427 * 2 = disable dimm 1 on channel
428 * 3 = disable dimm 0+1 on channel
429 */
430 .dimm_channel0_disabled = 2,
431 .dimm_channel1_disabled = 2,
432 .max_ddr3_freq = 1600,
433 .usb_port_config = {
434 /*
435 * Empty and onboard Ports 0-7, set to un-used pin
436 * OC3
437 */
438 { 0, 3, 0x0000 }, /* P0= Empty */
439 { 1, 0, 0x0040 }, /* P1= Left USB 1 (OC0) */
440 { 1, 1, 0x0040 }, /* P2= Left USB 2 (OC1) */
441 { 1, 3, 0x0040 }, /* P3= SDCARD (no OC) */
442 { 0, 3, 0x0000 }, /* P4= Empty */
443 { 1, 3, 0x0040 }, /* P5= WWAN (no OC) */
444 { 0, 3, 0x0000 }, /* P6= Empty */
445 { 0, 3, 0x0000 }, /* P7= Empty */
446 /*
447 * Empty and onboard Ports 8-13, set to un-used pin
448 * OC4
449 */
450 { 1, 4, 0x0040 }, /* P8= Camera (no OC) */
451 { 1, 4, 0x0040 }, /* P9= Bluetooth (no OC) */
452 { 0, 4, 0x0000 }, /* P10= Empty */
453 { 0, 4, 0x0000 }, /* P11= Empty */
454 { 0, 4, 0x0000 }, /* P12= Empty */
455 { 0, 4, 0x0000 }, /* P13= Empty */
456 },
457 };
Simon Glass147ba412016-03-16 07:44:38 -0600458 struct pei_data *pei_data = &_pei_data;
Simon Glassc02a4242016-01-17 16:11:50 -0700459 struct udevice *dev, *me_dev;
Simon Glass65dd74a2014-11-12 22:42:28 -0700460 int ret;
461
Simon Glass9532fe32016-07-11 09:30:55 -0600462 /* We need the pinctrl set up early */
463 ret = syscon_get_by_driver_data(X86_SYSCON_PINCONF, &dev);
Simon Glass8d8f3ac2017-01-16 07:03:38 -0700464 if (ret) {
465 debug("%s: Could not get pinconf (ret=%d)\n", __func__, ret);
Simon Glass9532fe32016-07-11 09:30:55 -0600466 return ret;
Simon Glass8d8f3ac2017-01-16 07:03:38 -0700467 }
Simon Glass9532fe32016-07-11 09:30:55 -0600468
Simon Glass3f603cb2016-02-11 13:23:26 -0700469 ret = uclass_first_device_err(UCLASS_NORTHBRIDGE, &dev);
Simon Glass8d8f3ac2017-01-16 07:03:38 -0700470 if (ret) {
471 debug("%s: Could not get northbridge (ret=%d)\n", __func__,
472 ret);
Simon Glass1641bb82016-01-17 16:11:48 -0700473 return ret;
Simon Glass8d8f3ac2017-01-16 07:03:38 -0700474 }
Simon Glass98655f32016-01-17 16:11:58 -0700475 ret = syscon_get_by_driver_data(X86_SYSCON_ME, &me_dev);
Simon Glass8d8f3ac2017-01-16 07:03:38 -0700476 if (ret) {
477 debug("%s: Could not get ME (ret=%d)\n", __func__, ret);
Simon Glassc02a4242016-01-17 16:11:50 -0700478 return ret;
Simon Glass8d8f3ac2017-01-16 07:03:38 -0700479 }
Simon Glass147ba412016-03-16 07:44:38 -0600480 ret = copy_spd(dev, pei_data);
Simon Glass8d8f3ac2017-01-16 07:03:38 -0700481 if (ret) {
482 debug("%s: Could not get SPD (ret=%d)\n", __func__, ret);
Simon Glass65dd74a2014-11-12 22:42:28 -0700483 return ret;
Simon Glass8d8f3ac2017-01-16 07:03:38 -0700484 }
Simon Glass147ba412016-03-16 07:44:38 -0600485 pei_data->boot_mode = gd->arch.pei_boot_mode;
486 debug("Boot mode %d\n", gd->arch.pei_boot_mode);
487 debug("mrc_input %p\n", pei_data->mrc_input);
Simon Glass65dd74a2014-11-12 22:42:28 -0700488
Simon Glass147ba412016-03-16 07:44:38 -0600489 /*
490 * Do not pass MRC data in for recovery mode boot,
491 * Always pass it in for S3 resume.
492 */
493 if (!recovery_mode_enabled() ||
494 pei_data->boot_mode == PEI_BOOT_RESUME) {
495 ret = prepare_mrc_cache(pei_data);
496 if (ret)
497 debug("prepare_mrc_cache failed: %d\n", ret);
498 }
Simon Glass65dd74a2014-11-12 22:42:28 -0700499
Simon Glass147ba412016-03-16 07:44:38 -0600500 /* If MRC data is not found we cannot continue S3 resume. */
501 if (pei_data->boot_mode == PEI_BOOT_RESUME && !pei_data->mrc_input) {
502 debug("Giving up in sdram_initialize: No MRC data\n");
Bin Mengb37b7b22018-07-19 03:07:33 -0700503 sysreset_walk_halt(SYSRESET_COLD);
Simon Glass147ba412016-03-16 07:44:38 -0600504 }
Simon Glass65dd74a2014-11-12 22:42:28 -0700505
Simon Glass147ba412016-03-16 07:44:38 -0600506 /* Pass console handler in pei_data */
507 pei_data->tx_byte = sdram_console_tx_byte;
508
509 /* Wait for ME to be ready */
510 ret = intel_early_me_init(me_dev);
Simon Glass8d8f3ac2017-01-16 07:03:38 -0700511 if (ret) {
512 debug("%s: Could not init ME (ret=%d)\n", __func__, ret);
Simon Glass147ba412016-03-16 07:44:38 -0600513 return ret;
Simon Glass8d8f3ac2017-01-16 07:03:38 -0700514 }
Simon Glass147ba412016-03-16 07:44:38 -0600515 ret = intel_early_me_uma_size(me_dev);
Simon Glass8d8f3ac2017-01-16 07:03:38 -0700516 if (ret < 0) {
517 debug("%s: Could not get UMA size (ret=%d)\n", __func__, ret);
Simon Glass147ba412016-03-16 07:44:38 -0600518 return ret;
Simon Glass8d8f3ac2017-01-16 07:03:38 -0700519 }
Simon Glass147ba412016-03-16 07:44:38 -0600520
521 ret = mrc_common_init(dev, pei_data, false);
Simon Glass8d8f3ac2017-01-16 07:03:38 -0700522 if (ret) {
523 debug("%s: mrc_common_init() failed (ret=%d)\n", __func__, ret);
Simon Glass147ba412016-03-16 07:44:38 -0600524 return ret;
Simon Glass8d8f3ac2017-01-16 07:03:38 -0700525 }
Simon Glass65dd74a2014-11-12 22:42:28 -0700526
527 ret = sdram_find(dev);
Simon Glass8d8f3ac2017-01-16 07:03:38 -0700528 if (ret) {
529 debug("%s: sdram_find() failed (ret=%d)\n", __func__, ret);
Simon Glass65dd74a2014-11-12 22:42:28 -0700530 return ret;
Simon Glass8d8f3ac2017-01-16 07:03:38 -0700531 }
Simon Glass65dd74a2014-11-12 22:42:28 -0700532 gd->ram_size = gd->arch.meminfo.total_32bit_memory;
Simon Glass8ef07572014-11-12 22:42:07 -0700533
Simon Glass147ba412016-03-16 07:44:38 -0600534 debug("MRC output data length %#x at %p\n", pei_data->mrc_output_len,
535 pei_data->mrc_output);
536
537 post_system_agent_init(dev, me_dev, pei_data);
538 report_memory_config();
539
540 /* S3 resume: don't save scrambler seed or MRC data */
541 if (pei_data->boot_mode != PEI_BOOT_RESUME) {
Simon Glass515e8172019-12-06 21:42:07 -0700542 struct mrc_output *mrc = &gd->arch.mrc[MRC_TYPE_NORMAL];
543
Simon Glass147ba412016-03-16 07:44:38 -0600544 /*
545 * This will be copied to SDRAM in reserve_arch(), then written
546 * to SPI flash in mrccache_save()
547 */
Simon Glass515e8172019-12-06 21:42:07 -0700548 mrc->buf = (char *)pei_data->mrc_output;
549 mrc->len = pei_data->mrc_output_len;
Simon Glass147ba412016-03-16 07:44:38 -0600550 ret = write_seeds_to_cmos(pei_data);
551 if (ret)
552 debug("Failed to write seeds to CMOS: %d\n", ret);
553 }
554
555 writew(0xCAFE, MCHBAR_REG(SSKPD));
556 if (ret)
557 return ret;
558
559 rcba_config();
560
Simon Glass8ef07572014-11-12 22:42:07 -0700561 return 0;
562}