xref: /openbmc/u-boot/arch/x86/cpu/ivybridge/sdram.c (revision 42913a1c7ad6efae598364f5ea1ae083279b571f)
18ef07571SSimon Glass /*
28ef07571SSimon Glass  * Copyright (c) 2011 The Chromium OS Authors.
38ef07571SSimon Glass  * (C) Copyright 2010,2011
48ef07571SSimon Glass  * Graeme Russ, <graeme.russ@gmail.com>
58ef07571SSimon Glass  *
68ef07571SSimon Glass  * Portions from Coreboot mainboard/google/link/romstage.c
78ef07571SSimon Glass  * Copyright (C) 2007-2010 coresystems GmbH
88ef07571SSimon Glass  * Copyright (C) 2011 Google Inc.
98ef07571SSimon Glass  *
108ef07571SSimon Glass  * SPDX-License-Identifier:	GPL-2.0
118ef07571SSimon Glass  */
128ef07571SSimon Glass 
138ef07571SSimon Glass #include <common.h>
1465dd74a6SSimon Glass #include <errno.h>
1565dd74a6SSimon Glass #include <fdtdec.h>
1665dd74a6SSimon Glass #include <malloc.h>
17191c008aSSimon Glass #include <net.h>
18191c008aSSimon Glass #include <rtc.h>
19191c008aSSimon Glass #include <spi.h>
20191c008aSSimon Glass #include <spi_flash.h>
2165dd74a6SSimon Glass #include <asm/processor.h>
2265dd74a6SSimon Glass #include <asm/gpio.h>
2365dd74a6SSimon Glass #include <asm/global_data.h>
24f6220f1aSBin Meng #include <asm/mrccache.h>
25aaafcd6cSSimon Glass #include <asm/mtrr.h>
2665dd74a6SSimon Glass #include <asm/pci.h>
2765dd74a6SSimon Glass #include <asm/arch/me.h>
2865dd74a6SSimon Glass #include <asm/arch/pei_data.h>
2965dd74a6SSimon Glass #include <asm/arch/pch.h>
3065dd74a6SSimon Glass #include <asm/post.h>
3165dd74a6SSimon Glass #include <asm/arch/sandybridge.h>
3265dd74a6SSimon Glass 
3365dd74a6SSimon Glass DECLARE_GLOBAL_DATA_PTR;
3465dd74a6SSimon Glass 
35191c008aSSimon Glass #define CMOS_OFFSET_MRC_SEED		152
36191c008aSSimon Glass #define CMOS_OFFSET_MRC_SEED_S3		156
37191c008aSSimon Glass #define CMOS_OFFSET_MRC_SEED_CHK	160
38191c008aSSimon Glass 
3965dd74a6SSimon Glass /*
4065dd74a6SSimon Glass  * This function looks for the highest region of memory lower than 4GB which
4165dd74a6SSimon Glass  * has enough space for U-Boot where U-Boot is aligned on a page boundary.
4265dd74a6SSimon Glass  * It overrides the default implementation found elsewhere which simply
4365dd74a6SSimon Glass  * picks the end of ram, wherever that may be. The location of the stack,
4465dd74a6SSimon Glass  * the relocation address, and how far U-Boot is moved by relocation are
4565dd74a6SSimon Glass  * set in the global data structure.
4665dd74a6SSimon Glass  */
4765dd74a6SSimon Glass ulong board_get_usable_ram_top(ulong total_size)
4865dd74a6SSimon Glass {
4965dd74a6SSimon Glass 	struct memory_info *info = &gd->arch.meminfo;
5065dd74a6SSimon Glass 	uintptr_t dest_addr = 0;
5165dd74a6SSimon Glass 	struct memory_area *largest = NULL;
5265dd74a6SSimon Glass 	int i;
5365dd74a6SSimon Glass 
5465dd74a6SSimon Glass 	/* Find largest area of memory below 4GB */
5565dd74a6SSimon Glass 
5665dd74a6SSimon Glass 	for (i = 0; i < info->num_areas; i++) {
5765dd74a6SSimon Glass 		struct memory_area *area = &info->area[i];
5865dd74a6SSimon Glass 
5965dd74a6SSimon Glass 		if (area->start >= 1ULL << 32)
6065dd74a6SSimon Glass 			continue;
6165dd74a6SSimon Glass 		if (!largest || area->size > largest->size)
6265dd74a6SSimon Glass 			largest = area;
6365dd74a6SSimon Glass 	}
6465dd74a6SSimon Glass 
6565dd74a6SSimon Glass 	/* If no suitable area was found, return an error. */
6665dd74a6SSimon Glass 	assert(largest);
6765dd74a6SSimon Glass 	if (!largest || largest->size < (2 << 20))
6865dd74a6SSimon Glass 		panic("No available memory found for relocation");
6965dd74a6SSimon Glass 
7065dd74a6SSimon Glass 	dest_addr = largest->start + largest->size;
7165dd74a6SSimon Glass 
7265dd74a6SSimon Glass 	return (ulong)dest_addr;
7365dd74a6SSimon Glass }
7465dd74a6SSimon Glass 
7565dd74a6SSimon Glass void dram_init_banksize(void)
7665dd74a6SSimon Glass {
7765dd74a6SSimon Glass 	struct memory_info *info = &gd->arch.meminfo;
7865dd74a6SSimon Glass 	int num_banks;
7965dd74a6SSimon Glass 	int i;
8065dd74a6SSimon Glass 
8165dd74a6SSimon Glass 	for (i = 0, num_banks = 0; i < info->num_areas; i++) {
8265dd74a6SSimon Glass 		struct memory_area *area = &info->area[i];
8365dd74a6SSimon Glass 
8465dd74a6SSimon Glass 		if (area->start >= 1ULL << 32)
8565dd74a6SSimon Glass 			continue;
8665dd74a6SSimon Glass 		gd->bd->bi_dram[num_banks].start = area->start;
8765dd74a6SSimon Glass 		gd->bd->bi_dram[num_banks].size = area->size;
8865dd74a6SSimon Glass 		num_banks++;
8965dd74a6SSimon Glass 	}
9065dd74a6SSimon Glass }
9165dd74a6SSimon Glass 
92191c008aSSimon Glass static int read_seed_from_cmos(struct pei_data *pei_data)
93191c008aSSimon Glass {
94191c008aSSimon Glass 	u16 c1, c2, checksum, seed_checksum;
9593f8a311SBin Meng 	struct udevice *dev;
9693f8a311SBin Meng 	int rcode = 0;
9793f8a311SBin Meng 
9893f8a311SBin Meng 	rcode = uclass_get_device(UCLASS_RTC, 0, &dev);
9993f8a311SBin Meng 	if (rcode) {
10093f8a311SBin Meng 		debug("Cannot find RTC: err=%d\n", rcode);
10193f8a311SBin Meng 		return -ENODEV;
10293f8a311SBin Meng 	}
103191c008aSSimon Glass 
104191c008aSSimon Glass 	/*
105191c008aSSimon Glass 	 * Read scrambler seeds from CMOS RAM. We don't want to store them in
106191c008aSSimon Glass 	 * SPI flash since they change on every boot and that would wear down
107191c008aSSimon Glass 	 * the flash too much. So we store these in CMOS and the large MRC
108191c008aSSimon Glass 	 * data in SPI flash.
109191c008aSSimon Glass 	 */
11093f8a311SBin Meng 	rtc_read32(dev, CMOS_OFFSET_MRC_SEED, &pei_data->scrambler_seed);
111191c008aSSimon Glass 	debug("Read scrambler seed    0x%08x from CMOS 0x%02x\n",
112191c008aSSimon Glass 	      pei_data->scrambler_seed, CMOS_OFFSET_MRC_SEED);
113191c008aSSimon Glass 
11493f8a311SBin Meng 	rtc_read32(dev, CMOS_OFFSET_MRC_SEED_S3, &pei_data->scrambler_seed_s3);
115191c008aSSimon Glass 	debug("Read S3 scrambler seed 0x%08x from CMOS 0x%02x\n",
116191c008aSSimon Glass 	      pei_data->scrambler_seed_s3, CMOS_OFFSET_MRC_SEED_S3);
117191c008aSSimon Glass 
118191c008aSSimon Glass 	/* Compute seed checksum and compare */
119191c008aSSimon Glass 	c1 = compute_ip_checksum((u8 *)&pei_data->scrambler_seed,
120191c008aSSimon Glass 				 sizeof(u32));
121191c008aSSimon Glass 	c2 = compute_ip_checksum((u8 *)&pei_data->scrambler_seed_s3,
122191c008aSSimon Glass 				 sizeof(u32));
123191c008aSSimon Glass 	checksum = add_ip_checksums(sizeof(u32), c1, c2);
124191c008aSSimon Glass 
12593f8a311SBin Meng 	seed_checksum = rtc_read8(dev, CMOS_OFFSET_MRC_SEED_CHK);
12693f8a311SBin Meng 	seed_checksum |= rtc_read8(dev, CMOS_OFFSET_MRC_SEED_CHK + 1) << 8;
127191c008aSSimon Glass 
128191c008aSSimon Glass 	if (checksum != seed_checksum) {
129191c008aSSimon Glass 		debug("%s: invalid seed checksum\n", __func__);
130191c008aSSimon Glass 		pei_data->scrambler_seed = 0;
131191c008aSSimon Glass 		pei_data->scrambler_seed_s3 = 0;
132191c008aSSimon Glass 		return -EINVAL;
133191c008aSSimon Glass 	}
134191c008aSSimon Glass 
135191c008aSSimon Glass 	return 0;
136191c008aSSimon Glass }
137191c008aSSimon Glass 
138191c008aSSimon Glass static int prepare_mrc_cache(struct pei_data *pei_data)
139191c008aSSimon Glass {
140191c008aSSimon Glass 	struct mrc_data_container *mrc_cache;
141191c008aSSimon Glass 	struct fmap_entry entry;
142191c008aSSimon Glass 	int ret;
143191c008aSSimon Glass 
144191c008aSSimon Glass 	ret = read_seed_from_cmos(pei_data);
145191c008aSSimon Glass 	if (ret)
146191c008aSSimon Glass 		return ret;
147*42913a1cSBin Meng 	ret = mrccache_get_region(NULL, &entry);
148191c008aSSimon Glass 	if (ret)
149191c008aSSimon Glass 		return ret;
150191c008aSSimon Glass 	mrc_cache = mrccache_find_current(&entry);
151191c008aSSimon Glass 	if (!mrc_cache)
152191c008aSSimon Glass 		return -ENOENT;
153191c008aSSimon Glass 
154191c008aSSimon Glass 	/*
155191c008aSSimon Glass 	 * TODO(sjg@chromium.org): Skip this for now as it causes boot
156191c008aSSimon Glass 	 * problems
157191c008aSSimon Glass 	 */
158191c008aSSimon Glass 	if (0) {
159191c008aSSimon Glass 		pei_data->mrc_input = mrc_cache->data;
160191c008aSSimon Glass 		pei_data->mrc_input_len = mrc_cache->data_size;
161191c008aSSimon Glass 	}
162191c008aSSimon Glass 	debug("%s: at %p, size %x checksum %04x\n", __func__,
163191c008aSSimon Glass 	      pei_data->mrc_input, pei_data->mrc_input_len,
164191c008aSSimon Glass 	      mrc_cache->checksum);
165191c008aSSimon Glass 
166191c008aSSimon Glass 	return 0;
167191c008aSSimon Glass }
168191c008aSSimon Glass 
169191c008aSSimon Glass static int write_seeds_to_cmos(struct pei_data *pei_data)
170191c008aSSimon Glass {
171191c008aSSimon Glass 	u16 c1, c2, checksum;
17293f8a311SBin Meng 	struct udevice *dev;
17393f8a311SBin Meng 	int rcode = 0;
17493f8a311SBin Meng 
17593f8a311SBin Meng 	rcode = uclass_get_device(UCLASS_RTC, 0, &dev);
17693f8a311SBin Meng 	if (rcode) {
17793f8a311SBin Meng 		debug("Cannot find RTC: err=%d\n", rcode);
17893f8a311SBin Meng 		return -ENODEV;
17993f8a311SBin Meng 	}
180191c008aSSimon Glass 
181191c008aSSimon Glass 	/* Save the MRC seed values to CMOS */
18293f8a311SBin Meng 	rtc_write32(dev, CMOS_OFFSET_MRC_SEED, pei_data->scrambler_seed);
183191c008aSSimon Glass 	debug("Save scrambler seed    0x%08x to CMOS 0x%02x\n",
184191c008aSSimon Glass 	      pei_data->scrambler_seed, CMOS_OFFSET_MRC_SEED);
185191c008aSSimon Glass 
18693f8a311SBin Meng 	rtc_write32(dev, CMOS_OFFSET_MRC_SEED_S3, pei_data->scrambler_seed_s3);
187191c008aSSimon Glass 	debug("Save s3 scrambler seed 0x%08x to CMOS 0x%02x\n",
188191c008aSSimon Glass 	      pei_data->scrambler_seed_s3, CMOS_OFFSET_MRC_SEED_S3);
189191c008aSSimon Glass 
190191c008aSSimon Glass 	/* Save a simple checksum of the seed values */
191191c008aSSimon Glass 	c1 = compute_ip_checksum((u8 *)&pei_data->scrambler_seed,
192191c008aSSimon Glass 				 sizeof(u32));
193191c008aSSimon Glass 	c2 = compute_ip_checksum((u8 *)&pei_data->scrambler_seed_s3,
194191c008aSSimon Glass 				 sizeof(u32));
195191c008aSSimon Glass 	checksum = add_ip_checksums(sizeof(u32), c1, c2);
196191c008aSSimon Glass 
19793f8a311SBin Meng 	rtc_write8(dev, CMOS_OFFSET_MRC_SEED_CHK, checksum & 0xff);
19893f8a311SBin Meng 	rtc_write8(dev, CMOS_OFFSET_MRC_SEED_CHK + 1, (checksum >> 8) & 0xff);
199191c008aSSimon Glass 
200191c008aSSimon Glass 	return 0;
201191c008aSSimon Glass }
202191c008aSSimon Glass 
203191c008aSSimon Glass /* Use this hook to save our SDRAM parameters */
204191c008aSSimon Glass int misc_init_r(void)
205191c008aSSimon Glass {
206191c008aSSimon Glass 	int ret;
207191c008aSSimon Glass 
208*42913a1cSBin Meng 	ret = mrccache_save();
209191c008aSSimon Glass 	if (ret)
210191c008aSSimon Glass 		printf("Unable to save MRC data: %d\n", ret);
211191c008aSSimon Glass 
212191c008aSSimon Glass 	return 0;
213191c008aSSimon Glass }
214191c008aSSimon Glass 
21565dd74a6SSimon Glass static const char *const ecc_decoder[] = {
21665dd74a6SSimon Glass 	"inactive",
21765dd74a6SSimon Glass 	"active on IO",
21865dd74a6SSimon Glass 	"disabled on IO",
21965dd74a6SSimon Glass 	"active"
22065dd74a6SSimon Glass };
22165dd74a6SSimon Glass 
22265dd74a6SSimon Glass /*
22365dd74a6SSimon Glass  * Dump in the log memory controller configuration as read from the memory
22465dd74a6SSimon Glass  * controller registers.
22565dd74a6SSimon Glass  */
22665dd74a6SSimon Glass static void report_memory_config(void)
22765dd74a6SSimon Glass {
22865dd74a6SSimon Glass 	u32 addr_decoder_common, addr_decode_ch[2];
22965dd74a6SSimon Glass 	int i;
23065dd74a6SSimon Glass 
23165dd74a6SSimon Glass 	addr_decoder_common = readl(MCHBAR_REG(0x5000));
23265dd74a6SSimon Glass 	addr_decode_ch[0] = readl(MCHBAR_REG(0x5004));
23365dd74a6SSimon Glass 	addr_decode_ch[1] = readl(MCHBAR_REG(0x5008));
23465dd74a6SSimon Glass 
23565dd74a6SSimon Glass 	debug("memcfg DDR3 clock %d MHz\n",
23665dd74a6SSimon Glass 	      (readl(MCHBAR_REG(0x5e04)) * 13333 * 2 + 50) / 100);
23765dd74a6SSimon Glass 	debug("memcfg channel assignment: A: %d, B % d, C % d\n",
23865dd74a6SSimon Glass 	      addr_decoder_common & 3,
23965dd74a6SSimon Glass 	      (addr_decoder_common >> 2) & 3,
24065dd74a6SSimon Glass 	      (addr_decoder_common >> 4) & 3);
24165dd74a6SSimon Glass 
24265dd74a6SSimon Glass 	for (i = 0; i < ARRAY_SIZE(addr_decode_ch); i++) {
24365dd74a6SSimon Glass 		u32 ch_conf = addr_decode_ch[i];
24465dd74a6SSimon Glass 		debug("memcfg channel[%d] config (%8.8x):\n", i, ch_conf);
24565dd74a6SSimon Glass 		debug("   ECC %s\n", ecc_decoder[(ch_conf >> 24) & 3]);
24665dd74a6SSimon Glass 		debug("   enhanced interleave mode %s\n",
24765dd74a6SSimon Glass 		      ((ch_conf >> 22) & 1) ? "on" : "off");
24865dd74a6SSimon Glass 		debug("   rank interleave %s\n",
24965dd74a6SSimon Glass 		      ((ch_conf >> 21) & 1) ? "on" : "off");
25065dd74a6SSimon Glass 		debug("   DIMMA %d MB width x%d %s rank%s\n",
25165dd74a6SSimon Glass 		      ((ch_conf >> 0) & 0xff) * 256,
25265dd74a6SSimon Glass 		      ((ch_conf >> 19) & 1) ? 16 : 8,
25365dd74a6SSimon Glass 		      ((ch_conf >> 17) & 1) ? "dual" : "single",
25465dd74a6SSimon Glass 		      ((ch_conf >> 16) & 1) ? "" : ", selected");
25565dd74a6SSimon Glass 		debug("   DIMMB %d MB width x%d %s rank%s\n",
25665dd74a6SSimon Glass 		      ((ch_conf >> 8) & 0xff) * 256,
25765dd74a6SSimon Glass 		      ((ch_conf >> 20) & 1) ? 16 : 8,
25865dd74a6SSimon Glass 		      ((ch_conf >> 18) & 1) ? "dual" : "single",
25965dd74a6SSimon Glass 		      ((ch_conf >> 16) & 1) ? ", selected" : "");
26065dd74a6SSimon Glass 	}
26165dd74a6SSimon Glass }
26265dd74a6SSimon Glass 
26365dd74a6SSimon Glass static void post_system_agent_init(struct pei_data *pei_data)
26465dd74a6SSimon Glass {
26565dd74a6SSimon Glass 	/* If PCIe init is skipped, set the PEG clock gating */
26665dd74a6SSimon Glass 	if (!pei_data->pcie_init)
26765dd74a6SSimon Glass 		setbits_le32(MCHBAR_REG(0x7010), 1);
26865dd74a6SSimon Glass }
26965dd74a6SSimon Glass 
27065dd74a6SSimon Glass static asmlinkage void console_tx_byte(unsigned char byte)
27165dd74a6SSimon Glass {
27265dd74a6SSimon Glass #ifdef DEBUG
27365dd74a6SSimon Glass 	putc(byte);
27465dd74a6SSimon Glass #endif
27565dd74a6SSimon Glass }
27665dd74a6SSimon Glass 
277191c008aSSimon Glass static int recovery_mode_enabled(void)
278191c008aSSimon Glass {
279191c008aSSimon Glass 	return false;
280191c008aSSimon Glass }
281191c008aSSimon Glass 
28265dd74a6SSimon Glass /**
28365dd74a6SSimon Glass  * Find the PEI executable in the ROM and execute it.
28465dd74a6SSimon Glass  *
28565dd74a6SSimon Glass  * @param pei_data: configuration data for UEFI PEI reference code
28665dd74a6SSimon Glass  */
28765dd74a6SSimon Glass int sdram_initialise(struct pei_data *pei_data)
28865dd74a6SSimon Glass {
28965dd74a6SSimon Glass 	unsigned version;
29065dd74a6SSimon Glass 	const char *data;
29165dd74a6SSimon Glass 	uint16_t done;
29265dd74a6SSimon Glass 	int ret;
29365dd74a6SSimon Glass 
29465dd74a6SSimon Glass 	report_platform_info();
29565dd74a6SSimon Glass 
29665dd74a6SSimon Glass 	/* Wait for ME to be ready */
29765dd74a6SSimon Glass 	ret = intel_early_me_init();
29865dd74a6SSimon Glass 	if (ret)
29965dd74a6SSimon Glass 		return ret;
30065dd74a6SSimon Glass 	ret = intel_early_me_uma_size();
30165dd74a6SSimon Glass 	if (ret < 0)
30265dd74a6SSimon Glass 		return ret;
30365dd74a6SSimon Glass 
30465dd74a6SSimon Glass 	debug("Starting UEFI PEI System Agent\n");
30565dd74a6SSimon Glass 
306191c008aSSimon Glass 	/*
307191c008aSSimon Glass 	 * Do not pass MRC data in for recovery mode boot,
308191c008aSSimon Glass 	 * Always pass it in for S3 resume.
309191c008aSSimon Glass 	 */
310191c008aSSimon Glass 	if (!recovery_mode_enabled() ||
311191c008aSSimon Glass 	    pei_data->boot_mode == PEI_BOOT_RESUME) {
312191c008aSSimon Glass 		ret = prepare_mrc_cache(pei_data);
313191c008aSSimon Glass 		if (ret)
314191c008aSSimon Glass 			debug("prepare_mrc_cache failed: %d\n", ret);
315191c008aSSimon Glass 	}
316191c008aSSimon Glass 
31765dd74a6SSimon Glass 	/* If MRC data is not found we cannot continue S3 resume. */
31865dd74a6SSimon Glass 	if (pei_data->boot_mode == PEI_BOOT_RESUME && !pei_data->mrc_input) {
31965dd74a6SSimon Glass 		debug("Giving up in sdram_initialize: No MRC data\n");
3205021c81fSSimon Glass 		reset_cpu(0);
32165dd74a6SSimon Glass 	}
32265dd74a6SSimon Glass 
32365dd74a6SSimon Glass 	/* Pass console handler in pei_data */
32465dd74a6SSimon Glass 	pei_data->tx_byte = console_tx_byte;
32565dd74a6SSimon Glass 
32665dd74a6SSimon Glass 	debug("PEI data at %p, size %x:\n", pei_data, sizeof(*pei_data));
32765dd74a6SSimon Glass 
3288c5224c9SBin Meng 	data = (char *)CONFIG_X86_MRC_ADDR;
32965dd74a6SSimon Glass 	if (data) {
33065dd74a6SSimon Glass 		int rv;
33165dd74a6SSimon Glass 		int (*func)(struct pei_data *);
33265dd74a6SSimon Glass 
33365dd74a6SSimon Glass 		debug("Calling MRC at %p\n", data);
33465dd74a6SSimon Glass 		post_code(POST_PRE_MRC);
33565dd74a6SSimon Glass 		func = (int (*)(struct pei_data *))data;
33665dd74a6SSimon Glass 		rv = func(pei_data);
33765dd74a6SSimon Glass 		post_code(POST_MRC);
33865dd74a6SSimon Glass 		if (rv) {
33965dd74a6SSimon Glass 			switch (rv) {
34065dd74a6SSimon Glass 			case -1:
34165dd74a6SSimon Glass 				printf("PEI version mismatch.\n");
34265dd74a6SSimon Glass 				break;
34365dd74a6SSimon Glass 			case -2:
34465dd74a6SSimon Glass 				printf("Invalid memory frequency.\n");
34565dd74a6SSimon Glass 				break;
34665dd74a6SSimon Glass 			default:
34765dd74a6SSimon Glass 				printf("MRC returned %x.\n", rv);
34865dd74a6SSimon Glass 			}
34965dd74a6SSimon Glass 			printf("Nonzero MRC return value.\n");
35065dd74a6SSimon Glass 			return -EFAULT;
35165dd74a6SSimon Glass 		}
35265dd74a6SSimon Glass 	} else {
35365dd74a6SSimon Glass 		printf("UEFI PEI System Agent not found.\n");
35465dd74a6SSimon Glass 		return -ENOSYS;
35565dd74a6SSimon Glass 	}
35665dd74a6SSimon Glass 
35765dd74a6SSimon Glass #if CONFIG_USBDEBUG
35865dd74a6SSimon Glass 	/* mrc.bin reconfigures USB, so reinit it to have debug */
35965dd74a6SSimon Glass 	early_usbdebug_init();
36065dd74a6SSimon Glass #endif
36165dd74a6SSimon Glass 
36265dd74a6SSimon Glass 	version = readl(MCHBAR_REG(0x5034));
36365dd74a6SSimon Glass 	debug("System Agent Version %d.%d.%d Build %d\n",
36465dd74a6SSimon Glass 	      version >> 24 , (version >> 16) & 0xff,
36565dd74a6SSimon Glass 	      (version >> 8) & 0xff, version & 0xff);
366191c008aSSimon Glass 	debug("MCR output data length %#x at %p\n", pei_data->mrc_output_len,
367191c008aSSimon Glass 	      pei_data->mrc_output);
36865dd74a6SSimon Glass 
36965dd74a6SSimon Glass 	/*
37065dd74a6SSimon Glass 	 * Send ME init done for SandyBridge here.  This is done inside the
37165dd74a6SSimon Glass 	 * SystemAgent binary on IvyBridge
37265dd74a6SSimon Glass 	 */
37331f57c28SSimon Glass 	done = x86_pci_read_config32(PCH_DEV, PCI_DEVICE_ID);
37465dd74a6SSimon Glass 	done &= BASE_REV_MASK;
37565dd74a6SSimon Glass 	if (BASE_REV_SNB == done)
37665dd74a6SSimon Glass 		intel_early_me_init_done(ME_INIT_STATUS_SUCCESS);
37765dd74a6SSimon Glass 	else
37865dd74a6SSimon Glass 		intel_early_me_status();
37965dd74a6SSimon Glass 
38065dd74a6SSimon Glass 	post_system_agent_init(pei_data);
38165dd74a6SSimon Glass 	report_memory_config();
38265dd74a6SSimon Glass 
383191c008aSSimon Glass 	/* S3 resume: don't save scrambler seed or MRC data */
384191c008aSSimon Glass 	if (pei_data->boot_mode != PEI_BOOT_RESUME) {
385191c008aSSimon Glass 		/*
386191c008aSSimon Glass 		 * This will be copied to SDRAM in reserve_arch(), then written
387*42913a1cSBin Meng 		 * to SPI flash in mrccache_save()
388191c008aSSimon Glass 		 */
389191c008aSSimon Glass 		gd->arch.mrc_output = (char *)pei_data->mrc_output;
390191c008aSSimon Glass 		gd->arch.mrc_output_len = pei_data->mrc_output_len;
391191c008aSSimon Glass 		ret = write_seeds_to_cmos(pei_data);
392191c008aSSimon Glass 		if (ret)
393191c008aSSimon Glass 			debug("Failed to write seeds to CMOS: %d\n", ret);
394191c008aSSimon Glass 	}
395191c008aSSimon Glass 
396191c008aSSimon Glass 	return 0;
397191c008aSSimon Glass }
398191c008aSSimon Glass 
399191c008aSSimon Glass int reserve_arch(void)
400191c008aSSimon Glass {
401*42913a1cSBin Meng 	return mrccache_reserve();
40265dd74a6SSimon Glass }
40365dd74a6SSimon Glass 
40465dd74a6SSimon Glass static int copy_spd(struct pei_data *peid)
40565dd74a6SSimon Glass {
40665dd74a6SSimon Glass 	const int gpio_vector[] = {41, 42, 43, 10, -1};
40765dd74a6SSimon Glass 	int spd_index;
40865dd74a6SSimon Glass 	const void *blob = gd->fdt_blob;
40965dd74a6SSimon Glass 	int node, spd_node;
41065dd74a6SSimon Glass 	int ret, i;
41165dd74a6SSimon Glass 
41265dd74a6SSimon Glass 	for (i = 0; ; i++) {
41365dd74a6SSimon Glass 		if (gpio_vector[i] == -1)
41465dd74a6SSimon Glass 			break;
41565dd74a6SSimon Glass 		ret = gpio_requestf(gpio_vector[i], "spd_id%d", i);
41665dd74a6SSimon Glass 		if (ret) {
41765dd74a6SSimon Glass 			debug("%s: Could not request gpio %d\n", __func__,
41865dd74a6SSimon Glass 			      gpio_vector[i]);
41965dd74a6SSimon Glass 			return ret;
42065dd74a6SSimon Glass 		}
42165dd74a6SSimon Glass 	}
42265dd74a6SSimon Glass 	spd_index = gpio_get_values_as_int(gpio_vector);
42365dd74a6SSimon Glass 	debug("spd index %d\n", spd_index);
42465dd74a6SSimon Glass 	node = fdtdec_next_compatible(blob, 0, COMPAT_MEMORY_SPD);
42565dd74a6SSimon Glass 	if (node < 0) {
42665dd74a6SSimon Glass 		printf("SPD data not found.\n");
42765dd74a6SSimon Glass 		return -ENOENT;
42865dd74a6SSimon Glass 	}
42965dd74a6SSimon Glass 
43065dd74a6SSimon Glass 	for (spd_node = fdt_first_subnode(blob, node);
43165dd74a6SSimon Glass 	     spd_node > 0;
43265dd74a6SSimon Glass 	     spd_node = fdt_next_subnode(blob, spd_node)) {
43365dd74a6SSimon Glass 		const char *data;
43465dd74a6SSimon Glass 		int len;
43565dd74a6SSimon Glass 
43665dd74a6SSimon Glass 		if (fdtdec_get_int(blob, spd_node, "reg", -1) != spd_index)
43765dd74a6SSimon Glass 			continue;
43865dd74a6SSimon Glass 		data = fdt_getprop(blob, spd_node, "data", &len);
43965dd74a6SSimon Glass 		if (len < sizeof(peid->spd_data[0])) {
44065dd74a6SSimon Glass 			printf("Missing SPD data\n");
44165dd74a6SSimon Glass 			return -EINVAL;
44265dd74a6SSimon Glass 		}
44365dd74a6SSimon Glass 
44465dd74a6SSimon Glass 		debug("Using SDRAM SPD data for '%s'\n",
44565dd74a6SSimon Glass 		      fdt_get_name(blob, spd_node, NULL));
44665dd74a6SSimon Glass 		memcpy(peid->spd_data[0], data, sizeof(peid->spd_data[0]));
44765dd74a6SSimon Glass 		break;
44865dd74a6SSimon Glass 	}
44965dd74a6SSimon Glass 
45065dd74a6SSimon Glass 	if (spd_node < 0) {
45165dd74a6SSimon Glass 		printf("No SPD data found for index %d\n", spd_index);
45265dd74a6SSimon Glass 		return -ENOENT;
45365dd74a6SSimon Glass 	}
45465dd74a6SSimon Glass 
45565dd74a6SSimon Glass 	return 0;
45665dd74a6SSimon Glass }
45765dd74a6SSimon Glass 
45865dd74a6SSimon Glass /**
45965dd74a6SSimon Glass  * add_memory_area() - Add a new usable memory area to our list
46065dd74a6SSimon Glass  *
46165dd74a6SSimon Glass  * Note: @start and @end must not span the first 4GB boundary
46265dd74a6SSimon Glass  *
46365dd74a6SSimon Glass  * @info:	Place to store memory info
46465dd74a6SSimon Glass  * @start:	Start of this memory area
46565dd74a6SSimon Glass  * @end:	End of this memory area + 1
46665dd74a6SSimon Glass  */
46765dd74a6SSimon Glass static int add_memory_area(struct memory_info *info,
46865dd74a6SSimon Glass 			   uint64_t start, uint64_t end)
46965dd74a6SSimon Glass {
47065dd74a6SSimon Glass 	struct memory_area *ptr;
47165dd74a6SSimon Glass 
47265dd74a6SSimon Glass 	if (info->num_areas == CONFIG_NR_DRAM_BANKS)
47365dd74a6SSimon Glass 		return -ENOSPC;
47465dd74a6SSimon Glass 
47565dd74a6SSimon Glass 	ptr = &info->area[info->num_areas];
47665dd74a6SSimon Glass 	ptr->start = start;
47765dd74a6SSimon Glass 	ptr->size = end - start;
47865dd74a6SSimon Glass 	info->total_memory += ptr->size;
47965dd74a6SSimon Glass 	if (ptr->start < (1ULL << 32))
48065dd74a6SSimon Glass 		info->total_32bit_memory += ptr->size;
48165dd74a6SSimon Glass 	debug("%d: memory %llx size %llx, total now %llx / %llx\n",
48265dd74a6SSimon Glass 	      info->num_areas, ptr->start, ptr->size,
48365dd74a6SSimon Glass 	      info->total_32bit_memory, info->total_memory);
48465dd74a6SSimon Glass 	info->num_areas++;
48565dd74a6SSimon Glass 
48665dd74a6SSimon Glass 	return 0;
48765dd74a6SSimon Glass }
48865dd74a6SSimon Glass 
48965dd74a6SSimon Glass /**
49065dd74a6SSimon Glass  * sdram_find() - Find available memory
49165dd74a6SSimon Glass  *
49265dd74a6SSimon Glass  * This is a bit complicated since on x86 there are system memory holes all
49365dd74a6SSimon Glass  * over the place. We create a list of available memory blocks
49465dd74a6SSimon Glass  */
49565dd74a6SSimon Glass static int sdram_find(pci_dev_t dev)
49665dd74a6SSimon Glass {
49765dd74a6SSimon Glass 	struct memory_info *info = &gd->arch.meminfo;
49865dd74a6SSimon Glass 	uint32_t tseg_base, uma_size, tolud;
49965dd74a6SSimon Glass 	uint64_t tom, me_base, touud;
50065dd74a6SSimon Glass 	uint64_t uma_memory_base = 0;
50165dd74a6SSimon Glass 	uint64_t uma_memory_size;
50265dd74a6SSimon Glass 	unsigned long long tomk;
50365dd74a6SSimon Glass 	uint16_t ggc;
50465dd74a6SSimon Glass 
50565dd74a6SSimon Glass 	/* Total Memory 2GB example:
50665dd74a6SSimon Glass 	 *
50765dd74a6SSimon Glass 	 *  00000000  0000MB-1992MB  1992MB  RAM     (writeback)
50865dd74a6SSimon Glass 	 *  7c800000  1992MB-2000MB     8MB  TSEG    (SMRR)
50965dd74a6SSimon Glass 	 *  7d000000  2000MB-2002MB     2MB  GFX GTT (uncached)
51065dd74a6SSimon Glass 	 *  7d200000  2002MB-2034MB    32MB  GFX UMA (uncached)
51165dd74a6SSimon Glass 	 *  7f200000   2034MB TOLUD
51265dd74a6SSimon Glass 	 *  7f800000   2040MB MEBASE
51365dd74a6SSimon Glass 	 *  7f800000  2040MB-2048MB     8MB  ME UMA  (uncached)
51465dd74a6SSimon Glass 	 *  80000000   2048MB TOM
51565dd74a6SSimon Glass 	 * 100000000  4096MB-4102MB     6MB  RAM     (writeback)
51665dd74a6SSimon Glass 	 *
51765dd74a6SSimon Glass 	 * Total Memory 4GB example:
51865dd74a6SSimon Glass 	 *
51965dd74a6SSimon Glass 	 *  00000000  0000MB-2768MB  2768MB  RAM     (writeback)
52065dd74a6SSimon Glass 	 *  ad000000  2768MB-2776MB     8MB  TSEG    (SMRR)
52165dd74a6SSimon Glass 	 *  ad800000  2776MB-2778MB     2MB  GFX GTT (uncached)
52265dd74a6SSimon Glass 	 *  ada00000  2778MB-2810MB    32MB  GFX UMA (uncached)
52365dd74a6SSimon Glass 	 *  afa00000   2810MB TOLUD
52465dd74a6SSimon Glass 	 *  ff800000   4088MB MEBASE
52565dd74a6SSimon Glass 	 *  ff800000  4088MB-4096MB     8MB  ME UMA  (uncached)
52665dd74a6SSimon Glass 	 * 100000000   4096MB TOM
52765dd74a6SSimon Glass 	 * 100000000  4096MB-5374MB  1278MB  RAM     (writeback)
52865dd74a6SSimon Glass 	 * 14fe00000   5368MB TOUUD
52965dd74a6SSimon Glass 	 */
53065dd74a6SSimon Glass 
53165dd74a6SSimon Glass 	/* Top of Upper Usable DRAM, including remap */
53231f57c28SSimon Glass 	touud = x86_pci_read_config32(dev, TOUUD+4);
53365dd74a6SSimon Glass 	touud <<= 32;
53431f57c28SSimon Glass 	touud |= x86_pci_read_config32(dev, TOUUD);
53565dd74a6SSimon Glass 
53665dd74a6SSimon Glass 	/* Top of Lower Usable DRAM */
53731f57c28SSimon Glass 	tolud = x86_pci_read_config32(dev, TOLUD);
53865dd74a6SSimon Glass 
53965dd74a6SSimon Glass 	/* Top of Memory - does not account for any UMA */
54031f57c28SSimon Glass 	tom = x86_pci_read_config32(dev, 0xa4);
54165dd74a6SSimon Glass 	tom <<= 32;
54231f57c28SSimon Glass 	tom |= x86_pci_read_config32(dev, 0xa0);
54365dd74a6SSimon Glass 
54465dd74a6SSimon Glass 	debug("TOUUD %llx TOLUD %08x TOM %llx\n", touud, tolud, tom);
54565dd74a6SSimon Glass 
54665dd74a6SSimon Glass 	/* ME UMA needs excluding if total memory <4GB */
54731f57c28SSimon Glass 	me_base = x86_pci_read_config32(dev, 0x74);
54865dd74a6SSimon Glass 	me_base <<= 32;
54931f57c28SSimon Glass 	me_base |= x86_pci_read_config32(dev, 0x70);
55065dd74a6SSimon Glass 
55165dd74a6SSimon Glass 	debug("MEBASE %llx\n", me_base);
55265dd74a6SSimon Glass 
55365dd74a6SSimon Glass 	/* TODO: Get rid of all this shifting by 10 bits */
55465dd74a6SSimon Glass 	tomk = tolud >> 10;
55565dd74a6SSimon Glass 	if (me_base == tolud) {
55665dd74a6SSimon Glass 		/* ME is from MEBASE-TOM */
55765dd74a6SSimon Glass 		uma_size = (tom - me_base) >> 10;
55865dd74a6SSimon Glass 		/* Increment TOLUD to account for ME as RAM */
55965dd74a6SSimon Glass 		tolud += uma_size << 10;
56065dd74a6SSimon Glass 		/* UMA starts at old TOLUD */
56165dd74a6SSimon Glass 		uma_memory_base = tomk * 1024ULL;
56265dd74a6SSimon Glass 		uma_memory_size = uma_size * 1024ULL;
56365dd74a6SSimon Glass 		debug("ME UMA base %llx size %uM\n", me_base, uma_size >> 10);
56465dd74a6SSimon Glass 	}
56565dd74a6SSimon Glass 
56665dd74a6SSimon Glass 	/* Graphics memory comes next */
56731f57c28SSimon Glass 	ggc = x86_pci_read_config16(dev, GGC);
56865dd74a6SSimon Glass 	if (!(ggc & 2)) {
56965dd74a6SSimon Glass 		debug("IGD decoded, subtracting ");
57065dd74a6SSimon Glass 
57165dd74a6SSimon Glass 		/* Graphics memory */
57265dd74a6SSimon Glass 		uma_size = ((ggc >> 3) & 0x1f) * 32 * 1024ULL;
57365dd74a6SSimon Glass 		debug("%uM UMA", uma_size >> 10);
57465dd74a6SSimon Glass 		tomk -= uma_size;
57565dd74a6SSimon Glass 		uma_memory_base = tomk * 1024ULL;
57665dd74a6SSimon Glass 		uma_memory_size += uma_size * 1024ULL;
57765dd74a6SSimon Glass 
57865dd74a6SSimon Glass 		/* GTT Graphics Stolen Memory Size (GGMS) */
57965dd74a6SSimon Glass 		uma_size = ((ggc >> 8) & 0x3) * 1024ULL;
58065dd74a6SSimon Glass 		tomk -= uma_size;
58165dd74a6SSimon Glass 		uma_memory_base = tomk * 1024ULL;
58265dd74a6SSimon Glass 		uma_memory_size += uma_size * 1024ULL;
58365dd74a6SSimon Glass 		debug(" and %uM GTT\n", uma_size >> 10);
58465dd74a6SSimon Glass 	}
58565dd74a6SSimon Glass 
58665dd74a6SSimon Glass 	/* Calculate TSEG size from its base which must be below GTT */
58731f57c28SSimon Glass 	tseg_base = x86_pci_read_config32(dev, 0xb8);
58865dd74a6SSimon Glass 	uma_size = (uma_memory_base - tseg_base) >> 10;
58965dd74a6SSimon Glass 	tomk -= uma_size;
59065dd74a6SSimon Glass 	uma_memory_base = tomk * 1024ULL;
59165dd74a6SSimon Glass 	uma_memory_size += uma_size * 1024ULL;
59265dd74a6SSimon Glass 	debug("TSEG base 0x%08x size %uM\n", tseg_base, uma_size >> 10);
59365dd74a6SSimon Glass 
59465dd74a6SSimon Glass 	debug("Available memory below 4GB: %lluM\n", tomk >> 10);
59565dd74a6SSimon Glass 
59665dd74a6SSimon Glass 	/* Report the memory regions */
59765dd74a6SSimon Glass 	add_memory_area(info, 1 << 20, 2 << 28);
59865dd74a6SSimon Glass 	add_memory_area(info, (2 << 28) + (2 << 20), 4 << 28);
59965dd74a6SSimon Glass 	add_memory_area(info, (4 << 28) + (2 << 20), tseg_base);
60065dd74a6SSimon Glass 	add_memory_area(info, 1ULL << 32, touud);
601aaafcd6cSSimon Glass 
602aaafcd6cSSimon Glass 	/* Add MTRRs for memory */
603aaafcd6cSSimon Glass 	mtrr_add_request(MTRR_TYPE_WRBACK, 0, 2ULL << 30);
604aaafcd6cSSimon Glass 	mtrr_add_request(MTRR_TYPE_WRBACK, 2ULL << 30, 512 << 20);
605aaafcd6cSSimon Glass 	mtrr_add_request(MTRR_TYPE_WRBACK, 0xaULL << 28, 256 << 20);
606aaafcd6cSSimon Glass 	mtrr_add_request(MTRR_TYPE_UNCACHEABLE, tseg_base, 16 << 20);
607aaafcd6cSSimon Glass 	mtrr_add_request(MTRR_TYPE_UNCACHEABLE, tseg_base + (16 << 20),
608aaafcd6cSSimon Glass 			 32 << 20);
609aaafcd6cSSimon Glass 
61065dd74a6SSimon Glass 	/*
61165dd74a6SSimon Glass 	 * If >= 4GB installed then memory from TOLUD to 4GB
61265dd74a6SSimon Glass 	 * is remapped above TOM, TOUUD will account for both
61365dd74a6SSimon Glass 	 */
61465dd74a6SSimon Glass 	if (touud > (1ULL << 32ULL)) {
61565dd74a6SSimon Glass 		debug("Available memory above 4GB: %lluM\n",
61665dd74a6SSimon Glass 		      (touud >> 20) - 4096);
61765dd74a6SSimon Glass 	}
61865dd74a6SSimon Glass 
61965dd74a6SSimon Glass 	return 0;
62065dd74a6SSimon Glass }
62165dd74a6SSimon Glass 
62265dd74a6SSimon Glass static void rcba_config(void)
62365dd74a6SSimon Glass {
62465dd74a6SSimon Glass 	/*
62565dd74a6SSimon Glass 	 *             GFX    INTA -> PIRQA (MSI)
62665dd74a6SSimon Glass 	 * D28IP_P3IP  WLAN   INTA -> PIRQB
62765dd74a6SSimon Glass 	 * D29IP_E1P   EHCI1  INTA -> PIRQD
62865dd74a6SSimon Glass 	 * D26IP_E2P   EHCI2  INTA -> PIRQF
62965dd74a6SSimon Glass 	 * D31IP_SIP   SATA   INTA -> PIRQF (MSI)
63065dd74a6SSimon Glass 	 * D31IP_SMIP  SMBUS  INTB -> PIRQH
63165dd74a6SSimon Glass 	 * D31IP_TTIP  THRT   INTC -> PIRQA
63265dd74a6SSimon Glass 	 * D27IP_ZIP   HDA    INTA -> PIRQA (MSI)
63365dd74a6SSimon Glass 	 *
63465dd74a6SSimon Glass 	 * TRACKPAD                -> PIRQE (Edge Triggered)
63565dd74a6SSimon Glass 	 * TOUCHSCREEN             -> PIRQG (Edge Triggered)
63665dd74a6SSimon Glass 	 */
63765dd74a6SSimon Glass 
63865dd74a6SSimon Glass 	/* Device interrupt pin register (board specific) */
63965dd74a6SSimon Glass 	writel((INTC << D31IP_TTIP) | (NOINT << D31IP_SIP2) |
64065dd74a6SSimon Glass 	       (INTB << D31IP_SMIP) | (INTA << D31IP_SIP), RCB_REG(D31IP));
64165dd74a6SSimon Glass 	writel(NOINT << D30IP_PIP, RCB_REG(D30IP));
64265dd74a6SSimon Glass 	writel(INTA << D29IP_E1P, RCB_REG(D29IP));
64365dd74a6SSimon Glass 	writel(INTA << D28IP_P3IP, RCB_REG(D28IP));
64465dd74a6SSimon Glass 	writel(INTA << D27IP_ZIP, RCB_REG(D27IP));
64565dd74a6SSimon Glass 	writel(INTA << D26IP_E2P, RCB_REG(D26IP));
64665dd74a6SSimon Glass 	writel(NOINT << D25IP_LIP, RCB_REG(D25IP));
64765dd74a6SSimon Glass 	writel(NOINT << D22IP_MEI1IP, RCB_REG(D22IP));
64865dd74a6SSimon Glass 
64965dd74a6SSimon Glass 	/* Device interrupt route registers */
65065dd74a6SSimon Glass 	writel(DIR_ROUTE(PIRQB, PIRQH, PIRQA, PIRQC), RCB_REG(D31IR));
65165dd74a6SSimon Glass 	writel(DIR_ROUTE(PIRQD, PIRQE, PIRQF, PIRQG), RCB_REG(D29IR));
65265dd74a6SSimon Glass 	writel(DIR_ROUTE(PIRQB, PIRQC, PIRQD, PIRQE), RCB_REG(D28IR));
65365dd74a6SSimon Glass 	writel(DIR_ROUTE(PIRQA, PIRQH, PIRQA, PIRQB), RCB_REG(D27IR));
65465dd74a6SSimon Glass 	writel(DIR_ROUTE(PIRQF, PIRQE, PIRQG, PIRQH), RCB_REG(D26IR));
65565dd74a6SSimon Glass 	writel(DIR_ROUTE(PIRQA, PIRQB, PIRQC, PIRQD), RCB_REG(D25IR));
65665dd74a6SSimon Glass 	writel(DIR_ROUTE(PIRQA, PIRQB, PIRQC, PIRQD), RCB_REG(D22IR));
65765dd74a6SSimon Glass 
65865dd74a6SSimon Glass 	/* Enable IOAPIC (generic) */
65965dd74a6SSimon Glass 	writew(0x0100, RCB_REG(OIC));
66065dd74a6SSimon Glass 	/* PCH BWG says to read back the IOAPIC enable register */
66165dd74a6SSimon Glass 	(void)readw(RCB_REG(OIC));
66265dd74a6SSimon Glass 
66365dd74a6SSimon Glass 	/* Disable unused devices (board specific) */
66465dd74a6SSimon Glass 	setbits_le32(RCB_REG(FD), PCH_DISABLE_ALWAYS);
66565dd74a6SSimon Glass }
6668ef07571SSimon Glass 
6678ef07571SSimon Glass int dram_init(void)
6688ef07571SSimon Glass {
66965dd74a6SSimon Glass 	struct pei_data pei_data __aligned(8) = {
67065dd74a6SSimon Glass 		.pei_version = PEI_VERSION,
67165dd74a6SSimon Glass 		.mchbar = DEFAULT_MCHBAR,
67265dd74a6SSimon Glass 		.dmibar = DEFAULT_DMIBAR,
67365dd74a6SSimon Glass 		.epbar = DEFAULT_EPBAR,
6742d934e57SSimon Glass 		.pciexbar = CONFIG_PCIE_ECAM_BASE,
67565dd74a6SSimon Glass 		.smbusbar = SMBUS_IO_BASE,
67665dd74a6SSimon Glass 		.wdbbar = 0x4000000,
67765dd74a6SSimon Glass 		.wdbsize = 0x1000,
67865dd74a6SSimon Glass 		.hpet_address = CONFIG_HPET_ADDRESS,
67965dd74a6SSimon Glass 		.rcba = DEFAULT_RCBABASE,
68065dd74a6SSimon Glass 		.pmbase = DEFAULT_PMBASE,
68165dd74a6SSimon Glass 		.gpiobase = DEFAULT_GPIOBASE,
68265dd74a6SSimon Glass 		.thermalbase = 0xfed08000,
68365dd74a6SSimon Glass 		.system_type = 0, /* 0 Mobile, 1 Desktop/Server */
68465dd74a6SSimon Glass 		.tseg_size = CONFIG_SMM_TSEG_SIZE,
68565dd74a6SSimon Glass 		.ts_addresses = { 0x00, 0x00, 0x00, 0x00 },
68665dd74a6SSimon Glass 		.ec_present = 1,
68765dd74a6SSimon Glass 		.ddr3lv_support = 1,
68865dd74a6SSimon Glass 		/*
68965dd74a6SSimon Glass 		 * 0 = leave channel enabled
69065dd74a6SSimon Glass 		 * 1 = disable dimm 0 on channel
69165dd74a6SSimon Glass 		 * 2 = disable dimm 1 on channel
69265dd74a6SSimon Glass 		 * 3 = disable dimm 0+1 on channel
69365dd74a6SSimon Glass 		 */
69465dd74a6SSimon Glass 		.dimm_channel0_disabled = 2,
69565dd74a6SSimon Glass 		.dimm_channel1_disabled = 2,
69665dd74a6SSimon Glass 		.max_ddr3_freq = 1600,
69765dd74a6SSimon Glass 		.usb_port_config = {
69865dd74a6SSimon Glass 			/*
69965dd74a6SSimon Glass 			 * Empty and onboard Ports 0-7, set to un-used pin
70065dd74a6SSimon Glass 			 * OC3
70165dd74a6SSimon Glass 			 */
70265dd74a6SSimon Glass 			{ 0, 3, 0x0000 }, /* P0= Empty */
70365dd74a6SSimon Glass 			{ 1, 0, 0x0040 }, /* P1= Left USB 1  (OC0) */
70465dd74a6SSimon Glass 			{ 1, 1, 0x0040 }, /* P2= Left USB 2  (OC1) */
70565dd74a6SSimon Glass 			{ 1, 3, 0x0040 }, /* P3= SDCARD      (no OC) */
70665dd74a6SSimon Glass 			{ 0, 3, 0x0000 }, /* P4= Empty */
70765dd74a6SSimon Glass 			{ 1, 3, 0x0040 }, /* P5= WWAN        (no OC) */
70865dd74a6SSimon Glass 			{ 0, 3, 0x0000 }, /* P6= Empty */
70965dd74a6SSimon Glass 			{ 0, 3, 0x0000 }, /* P7= Empty */
71065dd74a6SSimon Glass 			/*
71165dd74a6SSimon Glass 			 * Empty and onboard Ports 8-13, set to un-used pin
71265dd74a6SSimon Glass 			 * OC4
71365dd74a6SSimon Glass 			 */
71465dd74a6SSimon Glass 			{ 1, 4, 0x0040 }, /* P8= Camera      (no OC) */
71565dd74a6SSimon Glass 			{ 1, 4, 0x0040 }, /* P9= Bluetooth   (no OC) */
71665dd74a6SSimon Glass 			{ 0, 4, 0x0000 }, /* P10= Empty */
71765dd74a6SSimon Glass 			{ 0, 4, 0x0000 }, /* P11= Empty */
71865dd74a6SSimon Glass 			{ 0, 4, 0x0000 }, /* P12= Empty */
71965dd74a6SSimon Glass 			{ 0, 4, 0x0000 }, /* P13= Empty */
72065dd74a6SSimon Glass 		},
72165dd74a6SSimon Glass 	};
72265dd74a6SSimon Glass 	pci_dev_t dev = PCI_BDF(0, 0, 0);
72365dd74a6SSimon Glass 	int ret;
72465dd74a6SSimon Glass 
72565dd74a6SSimon Glass 	debug("Boot mode %d\n", gd->arch.pei_boot_mode);
72665dd74a6SSimon Glass 	debug("mcr_input %p\n", pei_data.mrc_input);
72765dd74a6SSimon Glass 	pei_data.boot_mode = gd->arch.pei_boot_mode;
72865dd74a6SSimon Glass 	ret = copy_spd(&pei_data);
72965dd74a6SSimon Glass 	if (!ret)
73065dd74a6SSimon Glass 		ret = sdram_initialise(&pei_data);
73165dd74a6SSimon Glass 	if (ret)
73265dd74a6SSimon Glass 		return ret;
73365dd74a6SSimon Glass 
73465dd74a6SSimon Glass 	rcba_config();
73565dd74a6SSimon Glass 	quick_ram_check();
73665dd74a6SSimon Glass 
73765dd74a6SSimon Glass 	writew(0xCAFE, MCHBAR_REG(SSKPD));
73865dd74a6SSimon Glass 
73965dd74a6SSimon Glass 	post_code(POST_DRAM);
74065dd74a6SSimon Glass 
74165dd74a6SSimon Glass 	ret = sdram_find(dev);
74265dd74a6SSimon Glass 	if (ret)
74365dd74a6SSimon Glass 		return ret;
74465dd74a6SSimon Glass 
74565dd74a6SSimon Glass 	gd->ram_size = gd->arch.meminfo.total_32bit_memory;
7468ef07571SSimon Glass 
7478ef07571SSimon Glass 	return 0;
7488ef07571SSimon Glass }
749