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> 2198655f3aSSimon Glass #include <syscon.h> 2298655f3aSSimon Glass #include <asm/cpu.h> 2365dd74a6SSimon Glass #include <asm/processor.h> 2465dd74a6SSimon Glass #include <asm/gpio.h> 2565dd74a6SSimon Glass #include <asm/global_data.h> 26f6220f1aSBin Meng #include <asm/mrccache.h> 27aaafcd6cSSimon Glass #include <asm/mtrr.h> 2865dd74a6SSimon Glass #include <asm/pci.h> 2965dd74a6SSimon Glass #include <asm/arch/me.h> 3065dd74a6SSimon Glass #include <asm/arch/pei_data.h> 3165dd74a6SSimon Glass #include <asm/arch/pch.h> 3265dd74a6SSimon Glass #include <asm/post.h> 3365dd74a6SSimon Glass #include <asm/arch/sandybridge.h> 3465dd74a6SSimon Glass 3565dd74a6SSimon Glass DECLARE_GLOBAL_DATA_PTR; 3665dd74a6SSimon Glass 37191c008aSSimon Glass #define CMOS_OFFSET_MRC_SEED 152 38191c008aSSimon Glass #define CMOS_OFFSET_MRC_SEED_S3 156 39191c008aSSimon Glass #define CMOS_OFFSET_MRC_SEED_CHK 160 40191c008aSSimon Glass 4165dd74a6SSimon Glass /* 4265dd74a6SSimon Glass * This function looks for the highest region of memory lower than 4GB which 4365dd74a6SSimon Glass * has enough space for U-Boot where U-Boot is aligned on a page boundary. 4465dd74a6SSimon Glass * It overrides the default implementation found elsewhere which simply 4565dd74a6SSimon Glass * picks the end of ram, wherever that may be. The location of the stack, 4665dd74a6SSimon Glass * the relocation address, and how far U-Boot is moved by relocation are 4765dd74a6SSimon Glass * set in the global data structure. 4865dd74a6SSimon Glass */ 4965dd74a6SSimon Glass ulong board_get_usable_ram_top(ulong total_size) 5065dd74a6SSimon Glass { 5165dd74a6SSimon Glass struct memory_info *info = &gd->arch.meminfo; 5265dd74a6SSimon Glass uintptr_t dest_addr = 0; 5365dd74a6SSimon Glass struct memory_area *largest = NULL; 5465dd74a6SSimon Glass int i; 5565dd74a6SSimon Glass 5665dd74a6SSimon Glass /* Find largest area of memory below 4GB */ 5765dd74a6SSimon Glass 5865dd74a6SSimon Glass for (i = 0; i < info->num_areas; i++) { 5965dd74a6SSimon Glass struct memory_area *area = &info->area[i]; 6065dd74a6SSimon Glass 6165dd74a6SSimon Glass if (area->start >= 1ULL << 32) 6265dd74a6SSimon Glass continue; 6365dd74a6SSimon Glass if (!largest || area->size > largest->size) 6465dd74a6SSimon Glass largest = area; 6565dd74a6SSimon Glass } 6665dd74a6SSimon Glass 6765dd74a6SSimon Glass /* If no suitable area was found, return an error. */ 6865dd74a6SSimon Glass assert(largest); 6965dd74a6SSimon Glass if (!largest || largest->size < (2 << 20)) 7065dd74a6SSimon Glass panic("No available memory found for relocation"); 7165dd74a6SSimon Glass 7265dd74a6SSimon Glass dest_addr = largest->start + largest->size; 7365dd74a6SSimon Glass 7465dd74a6SSimon Glass return (ulong)dest_addr; 7565dd74a6SSimon Glass } 7665dd74a6SSimon Glass 7765dd74a6SSimon Glass void dram_init_banksize(void) 7865dd74a6SSimon Glass { 7965dd74a6SSimon Glass struct memory_info *info = &gd->arch.meminfo; 8065dd74a6SSimon Glass int num_banks; 8165dd74a6SSimon Glass int i; 8265dd74a6SSimon Glass 8365dd74a6SSimon Glass for (i = 0, num_banks = 0; i < info->num_areas; i++) { 8465dd74a6SSimon Glass struct memory_area *area = &info->area[i]; 8565dd74a6SSimon Glass 8665dd74a6SSimon Glass if (area->start >= 1ULL << 32) 8765dd74a6SSimon Glass continue; 8865dd74a6SSimon Glass gd->bd->bi_dram[num_banks].start = area->start; 8965dd74a6SSimon Glass gd->bd->bi_dram[num_banks].size = area->size; 9065dd74a6SSimon Glass num_banks++; 9165dd74a6SSimon Glass } 9265dd74a6SSimon Glass } 9365dd74a6SSimon Glass 94191c008aSSimon Glass static int read_seed_from_cmos(struct pei_data *pei_data) 95191c008aSSimon Glass { 96191c008aSSimon Glass u16 c1, c2, checksum, seed_checksum; 9793f8a311SBin Meng struct udevice *dev; 9853327d3eSSimon Glass int ret = 0; 9993f8a311SBin Meng 10053327d3eSSimon Glass ret = uclass_get_device(UCLASS_RTC, 0, &dev); 10153327d3eSSimon Glass if (ret) { 10253327d3eSSimon Glass debug("Cannot find RTC: err=%d\n", ret); 10393f8a311SBin Meng return -ENODEV; 10493f8a311SBin Meng } 105191c008aSSimon Glass 106191c008aSSimon Glass /* 107191c008aSSimon Glass * Read scrambler seeds from CMOS RAM. We don't want to store them in 108191c008aSSimon Glass * SPI flash since they change on every boot and that would wear down 109191c008aSSimon Glass * the flash too much. So we store these in CMOS and the large MRC 110191c008aSSimon Glass * data in SPI flash. 111191c008aSSimon Glass */ 1129fbc5ccdSSimon Glass ret = rtc_read32(dev, CMOS_OFFSET_MRC_SEED, &pei_data->scrambler_seed); 1139fbc5ccdSSimon Glass if (!ret) { 1149fbc5ccdSSimon Glass ret = rtc_read32(dev, CMOS_OFFSET_MRC_SEED_S3, 1159fbc5ccdSSimon Glass &pei_data->scrambler_seed_s3); 1169fbc5ccdSSimon Glass } 1179fbc5ccdSSimon Glass if (ret) { 1189fbc5ccdSSimon Glass debug("Failed to read from RTC %s\n", dev->name); 1199fbc5ccdSSimon Glass return ret; 1209fbc5ccdSSimon Glass } 1219fbc5ccdSSimon Glass 122191c008aSSimon Glass debug("Read scrambler seed 0x%08x from CMOS 0x%02x\n", 123191c008aSSimon Glass pei_data->scrambler_seed, CMOS_OFFSET_MRC_SEED); 124191c008aSSimon Glass debug("Read S3 scrambler seed 0x%08x from CMOS 0x%02x\n", 125191c008aSSimon Glass pei_data->scrambler_seed_s3, CMOS_OFFSET_MRC_SEED_S3); 126191c008aSSimon Glass 127191c008aSSimon Glass /* Compute seed checksum and compare */ 128191c008aSSimon Glass c1 = compute_ip_checksum((u8 *)&pei_data->scrambler_seed, 129191c008aSSimon Glass sizeof(u32)); 130191c008aSSimon Glass c2 = compute_ip_checksum((u8 *)&pei_data->scrambler_seed_s3, 131191c008aSSimon Glass sizeof(u32)); 132191c008aSSimon Glass checksum = add_ip_checksums(sizeof(u32), c1, c2); 133191c008aSSimon Glass 13493f8a311SBin Meng seed_checksum = rtc_read8(dev, CMOS_OFFSET_MRC_SEED_CHK); 13593f8a311SBin Meng seed_checksum |= rtc_read8(dev, CMOS_OFFSET_MRC_SEED_CHK + 1) << 8; 136191c008aSSimon Glass 137191c008aSSimon Glass if (checksum != seed_checksum) { 138191c008aSSimon Glass debug("%s: invalid seed checksum\n", __func__); 139191c008aSSimon Glass pei_data->scrambler_seed = 0; 140191c008aSSimon Glass pei_data->scrambler_seed_s3 = 0; 141191c008aSSimon Glass return -EINVAL; 142191c008aSSimon Glass } 143191c008aSSimon Glass 144191c008aSSimon Glass return 0; 145191c008aSSimon Glass } 146191c008aSSimon Glass 147191c008aSSimon Glass static int prepare_mrc_cache(struct pei_data *pei_data) 148191c008aSSimon Glass { 149191c008aSSimon Glass struct mrc_data_container *mrc_cache; 1504b9f6a66SBin Meng struct mrc_region entry; 151191c008aSSimon Glass int ret; 152191c008aSSimon Glass 153191c008aSSimon Glass ret = read_seed_from_cmos(pei_data); 154191c008aSSimon Glass if (ret) 155191c008aSSimon Glass return ret; 15642913a1cSBin Meng ret = mrccache_get_region(NULL, &entry); 157191c008aSSimon Glass if (ret) 158191c008aSSimon Glass return ret; 159191c008aSSimon Glass mrc_cache = mrccache_find_current(&entry); 160191c008aSSimon Glass if (!mrc_cache) 161191c008aSSimon Glass return -ENOENT; 162191c008aSSimon Glass 163191c008aSSimon Glass pei_data->mrc_input = mrc_cache->data; 164191c008aSSimon Glass pei_data->mrc_input_len = mrc_cache->data_size; 165191c008aSSimon Glass debug("%s: at %p, size %x checksum %04x\n", __func__, 166191c008aSSimon Glass pei_data->mrc_input, pei_data->mrc_input_len, 167191c008aSSimon Glass mrc_cache->checksum); 168191c008aSSimon Glass 169191c008aSSimon Glass return 0; 170191c008aSSimon Glass } 171191c008aSSimon Glass 172191c008aSSimon Glass static int write_seeds_to_cmos(struct pei_data *pei_data) 173191c008aSSimon Glass { 174191c008aSSimon Glass u16 c1, c2, checksum; 17593f8a311SBin Meng struct udevice *dev; 17653327d3eSSimon Glass int ret = 0; 17793f8a311SBin Meng 17853327d3eSSimon Glass ret = uclass_get_device(UCLASS_RTC, 0, &dev); 17953327d3eSSimon Glass if (ret) { 18053327d3eSSimon Glass debug("Cannot find RTC: err=%d\n", ret); 18193f8a311SBin Meng return -ENODEV; 18293f8a311SBin Meng } 183191c008aSSimon Glass 184191c008aSSimon Glass /* Save the MRC seed values to CMOS */ 18593f8a311SBin Meng rtc_write32(dev, CMOS_OFFSET_MRC_SEED, pei_data->scrambler_seed); 186191c008aSSimon Glass debug("Save scrambler seed 0x%08x to CMOS 0x%02x\n", 187191c008aSSimon Glass pei_data->scrambler_seed, CMOS_OFFSET_MRC_SEED); 188191c008aSSimon Glass 18993f8a311SBin Meng rtc_write32(dev, CMOS_OFFSET_MRC_SEED_S3, pei_data->scrambler_seed_s3); 190191c008aSSimon Glass debug("Save s3 scrambler seed 0x%08x to CMOS 0x%02x\n", 191191c008aSSimon Glass pei_data->scrambler_seed_s3, CMOS_OFFSET_MRC_SEED_S3); 192191c008aSSimon Glass 193191c008aSSimon Glass /* Save a simple checksum of the seed values */ 194191c008aSSimon Glass c1 = compute_ip_checksum((u8 *)&pei_data->scrambler_seed, 195191c008aSSimon Glass sizeof(u32)); 196191c008aSSimon Glass c2 = compute_ip_checksum((u8 *)&pei_data->scrambler_seed_s3, 197191c008aSSimon Glass sizeof(u32)); 198191c008aSSimon Glass checksum = add_ip_checksums(sizeof(u32), c1, c2); 199191c008aSSimon Glass 20093f8a311SBin Meng rtc_write8(dev, CMOS_OFFSET_MRC_SEED_CHK, checksum & 0xff); 20193f8a311SBin Meng rtc_write8(dev, CMOS_OFFSET_MRC_SEED_CHK + 1, (checksum >> 8) & 0xff); 202191c008aSSimon Glass 203191c008aSSimon Glass return 0; 204191c008aSSimon Glass } 205191c008aSSimon Glass 206191c008aSSimon Glass /* Use this hook to save our SDRAM parameters */ 207191c008aSSimon Glass int misc_init_r(void) 208191c008aSSimon Glass { 209191c008aSSimon Glass int ret; 210191c008aSSimon Glass 21142913a1cSBin Meng ret = mrccache_save(); 212191c008aSSimon Glass if (ret) 213191c008aSSimon Glass printf("Unable to save MRC data: %d\n", ret); 214191c008aSSimon Glass 215191c008aSSimon Glass return 0; 216191c008aSSimon Glass } 217191c008aSSimon Glass 21865dd74a6SSimon Glass static const char *const ecc_decoder[] = { 21965dd74a6SSimon Glass "inactive", 22065dd74a6SSimon Glass "active on IO", 22165dd74a6SSimon Glass "disabled on IO", 22265dd74a6SSimon Glass "active" 22365dd74a6SSimon Glass }; 22465dd74a6SSimon Glass 22565dd74a6SSimon Glass /* 22665dd74a6SSimon Glass * Dump in the log memory controller configuration as read from the memory 22765dd74a6SSimon Glass * controller registers. 22865dd74a6SSimon Glass */ 22965dd74a6SSimon Glass static void report_memory_config(void) 23065dd74a6SSimon Glass { 23165dd74a6SSimon Glass u32 addr_decoder_common, addr_decode_ch[2]; 23265dd74a6SSimon Glass int i; 23365dd74a6SSimon Glass 23465dd74a6SSimon Glass addr_decoder_common = readl(MCHBAR_REG(0x5000)); 23565dd74a6SSimon Glass addr_decode_ch[0] = readl(MCHBAR_REG(0x5004)); 23665dd74a6SSimon Glass addr_decode_ch[1] = readl(MCHBAR_REG(0x5008)); 23765dd74a6SSimon Glass 23865dd74a6SSimon Glass debug("memcfg DDR3 clock %d MHz\n", 23965dd74a6SSimon Glass (readl(MCHBAR_REG(0x5e04)) * 13333 * 2 + 50) / 100); 24065dd74a6SSimon Glass debug("memcfg channel assignment: A: %d, B % d, C % d\n", 24165dd74a6SSimon Glass addr_decoder_common & 3, 24265dd74a6SSimon Glass (addr_decoder_common >> 2) & 3, 24365dd74a6SSimon Glass (addr_decoder_common >> 4) & 3); 24465dd74a6SSimon Glass 24565dd74a6SSimon Glass for (i = 0; i < ARRAY_SIZE(addr_decode_ch); i++) { 24665dd74a6SSimon Glass u32 ch_conf = addr_decode_ch[i]; 24765dd74a6SSimon Glass debug("memcfg channel[%d] config (%8.8x):\n", i, ch_conf); 24865dd74a6SSimon Glass debug(" ECC %s\n", ecc_decoder[(ch_conf >> 24) & 3]); 24965dd74a6SSimon Glass debug(" enhanced interleave mode %s\n", 25065dd74a6SSimon Glass ((ch_conf >> 22) & 1) ? "on" : "off"); 25165dd74a6SSimon Glass debug(" rank interleave %s\n", 25265dd74a6SSimon Glass ((ch_conf >> 21) & 1) ? "on" : "off"); 25365dd74a6SSimon Glass debug(" DIMMA %d MB width x%d %s rank%s\n", 25465dd74a6SSimon Glass ((ch_conf >> 0) & 0xff) * 256, 25565dd74a6SSimon Glass ((ch_conf >> 19) & 1) ? 16 : 8, 25665dd74a6SSimon Glass ((ch_conf >> 17) & 1) ? "dual" : "single", 25765dd74a6SSimon Glass ((ch_conf >> 16) & 1) ? "" : ", selected"); 25865dd74a6SSimon Glass debug(" DIMMB %d MB width x%d %s rank%s\n", 25965dd74a6SSimon Glass ((ch_conf >> 8) & 0xff) * 256, 26065dd74a6SSimon Glass ((ch_conf >> 20) & 1) ? 16 : 8, 26165dd74a6SSimon Glass ((ch_conf >> 18) & 1) ? "dual" : "single", 26265dd74a6SSimon Glass ((ch_conf >> 16) & 1) ? ", selected" : ""); 26365dd74a6SSimon Glass } 26465dd74a6SSimon Glass } 26565dd74a6SSimon Glass 26665dd74a6SSimon Glass static void post_system_agent_init(struct pei_data *pei_data) 26765dd74a6SSimon Glass { 26865dd74a6SSimon Glass /* If PCIe init is skipped, set the PEG clock gating */ 26965dd74a6SSimon Glass if (!pei_data->pcie_init) 27065dd74a6SSimon Glass setbits_le32(MCHBAR_REG(0x7010), 1); 27165dd74a6SSimon Glass } 27265dd74a6SSimon Glass 27365dd74a6SSimon Glass static asmlinkage void console_tx_byte(unsigned char byte) 27465dd74a6SSimon Glass { 27565dd74a6SSimon Glass #ifdef DEBUG 27665dd74a6SSimon Glass putc(byte); 27765dd74a6SSimon Glass #endif 27865dd74a6SSimon Glass } 27965dd74a6SSimon Glass 280191c008aSSimon Glass static int recovery_mode_enabled(void) 281191c008aSSimon Glass { 282191c008aSSimon Glass return false; 283191c008aSSimon Glass } 284191c008aSSimon Glass 28565dd74a6SSimon Glass /** 28665dd74a6SSimon Glass * Find the PEI executable in the ROM and execute it. 28765dd74a6SSimon Glass * 2881641bb8cSSimon Glass * @dev: Northbridge device 2891641bb8cSSimon Glass * @pei_data: configuration data for UEFI PEI reference code 29065dd74a6SSimon Glass */ 291c02a4242SSimon Glass int sdram_initialise(struct udevice *dev, struct udevice *me_dev, 292c02a4242SSimon Glass struct pei_data *pei_data) 29365dd74a6SSimon Glass { 29465dd74a6SSimon Glass unsigned version; 29565dd74a6SSimon Glass const char *data; 29665dd74a6SSimon Glass uint16_t done; 29765dd74a6SSimon Glass int ret; 29865dd74a6SSimon Glass 299fad12961SSimon Glass report_platform_info(dev); 30065dd74a6SSimon Glass 30165dd74a6SSimon Glass /* Wait for ME to be ready */ 302c02a4242SSimon Glass ret = intel_early_me_init(me_dev); 30365dd74a6SSimon Glass if (ret) 30465dd74a6SSimon Glass return ret; 305c02a4242SSimon Glass ret = intel_early_me_uma_size(me_dev); 30665dd74a6SSimon Glass if (ret < 0) 30765dd74a6SSimon Glass return ret; 30865dd74a6SSimon Glass 30965dd74a6SSimon Glass debug("Starting UEFI PEI System Agent\n"); 31065dd74a6SSimon Glass 311191c008aSSimon Glass /* 312191c008aSSimon Glass * Do not pass MRC data in for recovery mode boot, 313191c008aSSimon Glass * Always pass it in for S3 resume. 314191c008aSSimon Glass */ 315191c008aSSimon Glass if (!recovery_mode_enabled() || 316191c008aSSimon Glass pei_data->boot_mode == PEI_BOOT_RESUME) { 317191c008aSSimon Glass ret = prepare_mrc_cache(pei_data); 318191c008aSSimon Glass if (ret) 319191c008aSSimon Glass debug("prepare_mrc_cache failed: %d\n", ret); 320191c008aSSimon Glass } 321191c008aSSimon Glass 32265dd74a6SSimon Glass /* If MRC data is not found we cannot continue S3 resume. */ 32365dd74a6SSimon Glass if (pei_data->boot_mode == PEI_BOOT_RESUME && !pei_data->mrc_input) { 32465dd74a6SSimon Glass debug("Giving up in sdram_initialize: No MRC data\n"); 3255021c81fSSimon Glass reset_cpu(0); 32665dd74a6SSimon Glass } 32765dd74a6SSimon Glass 32865dd74a6SSimon Glass /* Pass console handler in pei_data */ 32965dd74a6SSimon Glass pei_data->tx_byte = console_tx_byte; 33065dd74a6SSimon Glass 33165dd74a6SSimon Glass debug("PEI data at %p, size %x:\n", pei_data, sizeof(*pei_data)); 33265dd74a6SSimon Glass 3338c5224c9SBin Meng data = (char *)CONFIG_X86_MRC_ADDR; 33465dd74a6SSimon Glass if (data) { 33565dd74a6SSimon Glass int rv; 33665dd74a6SSimon Glass int (*func)(struct pei_data *); 337fd8f4729SSimon Glass ulong start; 33865dd74a6SSimon Glass 33965dd74a6SSimon Glass debug("Calling MRC at %p\n", data); 34065dd74a6SSimon Glass post_code(POST_PRE_MRC); 341fd8f4729SSimon Glass start = get_timer(0); 34265dd74a6SSimon Glass func = (int (*)(struct pei_data *))data; 34365dd74a6SSimon Glass rv = func(pei_data); 34465dd74a6SSimon Glass post_code(POST_MRC); 34565dd74a6SSimon Glass if (rv) { 34665dd74a6SSimon Glass switch (rv) { 34765dd74a6SSimon Glass case -1: 34865dd74a6SSimon Glass printf("PEI version mismatch.\n"); 34965dd74a6SSimon Glass break; 35065dd74a6SSimon Glass case -2: 35165dd74a6SSimon Glass printf("Invalid memory frequency.\n"); 35265dd74a6SSimon Glass break; 35365dd74a6SSimon Glass default: 35465dd74a6SSimon Glass printf("MRC returned %x.\n", rv); 35565dd74a6SSimon Glass } 35665dd74a6SSimon Glass printf("Nonzero MRC return value.\n"); 35765dd74a6SSimon Glass return -EFAULT; 35865dd74a6SSimon Glass } 359fd8f4729SSimon Glass debug("MRC execution time %lu ms\n", get_timer(start)); 36065dd74a6SSimon Glass } else { 36165dd74a6SSimon Glass printf("UEFI PEI System Agent not found.\n"); 36265dd74a6SSimon Glass return -ENOSYS; 36365dd74a6SSimon Glass } 36465dd74a6SSimon Glass 36565dd74a6SSimon Glass #if CONFIG_USBDEBUG 36665dd74a6SSimon Glass /* mrc.bin reconfigures USB, so reinit it to have debug */ 36765dd74a6SSimon Glass early_usbdebug_init(); 36865dd74a6SSimon Glass #endif 36965dd74a6SSimon Glass 37065dd74a6SSimon Glass version = readl(MCHBAR_REG(0x5034)); 37165dd74a6SSimon Glass debug("System Agent Version %d.%d.%d Build %d\n", 37265dd74a6SSimon Glass version >> 24 , (version >> 16) & 0xff, 37365dd74a6SSimon Glass (version >> 8) & 0xff, version & 0xff); 374c6c80d8bSBin Meng debug("MRC output data length %#x at %p\n", pei_data->mrc_output_len, 375191c008aSSimon Glass pei_data->mrc_output); 37665dd74a6SSimon Glass 37765dd74a6SSimon Glass /* 37865dd74a6SSimon Glass * Send ME init done for SandyBridge here. This is done inside the 37965dd74a6SSimon Glass * SystemAgent binary on IvyBridge 38065dd74a6SSimon Glass */ 3811641bb8cSSimon Glass dm_pci_read_config16(dev, PCI_DEVICE_ID, &done); 38265dd74a6SSimon Glass done &= BASE_REV_MASK; 38365dd74a6SSimon Glass if (BASE_REV_SNB == done) 384c02a4242SSimon Glass intel_early_me_init_done(dev, me_dev, ME_INIT_STATUS_SUCCESS); 38565dd74a6SSimon Glass else 386c02a4242SSimon Glass intel_early_me_status(me_dev); 38765dd74a6SSimon Glass 38865dd74a6SSimon Glass post_system_agent_init(pei_data); 38965dd74a6SSimon Glass report_memory_config(); 39065dd74a6SSimon Glass 391191c008aSSimon Glass /* S3 resume: don't save scrambler seed or MRC data */ 392191c008aSSimon Glass if (pei_data->boot_mode != PEI_BOOT_RESUME) { 393191c008aSSimon Glass /* 394191c008aSSimon Glass * This will be copied to SDRAM in reserve_arch(), then written 39542913a1cSBin Meng * to SPI flash in mrccache_save() 396191c008aSSimon Glass */ 397191c008aSSimon Glass gd->arch.mrc_output = (char *)pei_data->mrc_output; 398191c008aSSimon Glass gd->arch.mrc_output_len = pei_data->mrc_output_len; 399191c008aSSimon Glass ret = write_seeds_to_cmos(pei_data); 400191c008aSSimon Glass if (ret) 401191c008aSSimon Glass debug("Failed to write seeds to CMOS: %d\n", ret); 402191c008aSSimon Glass } 403191c008aSSimon Glass 404191c008aSSimon Glass return 0; 405191c008aSSimon Glass } 406191c008aSSimon Glass 407191c008aSSimon Glass int reserve_arch(void) 408191c008aSSimon Glass { 40942913a1cSBin Meng return mrccache_reserve(); 41065dd74a6SSimon Glass } 41165dd74a6SSimon Glass 41265dd74a6SSimon Glass static int copy_spd(struct pei_data *peid) 41365dd74a6SSimon Glass { 41465dd74a6SSimon Glass const int gpio_vector[] = {41, 42, 43, 10, -1}; 41565dd74a6SSimon Glass int spd_index; 41665dd74a6SSimon Glass const void *blob = gd->fdt_blob; 41765dd74a6SSimon Glass int node, spd_node; 41865dd74a6SSimon Glass int ret, i; 41965dd74a6SSimon Glass 42065dd74a6SSimon Glass for (i = 0; ; i++) { 42165dd74a6SSimon Glass if (gpio_vector[i] == -1) 42265dd74a6SSimon Glass break; 42365dd74a6SSimon Glass ret = gpio_requestf(gpio_vector[i], "spd_id%d", i); 42465dd74a6SSimon Glass if (ret) { 42565dd74a6SSimon Glass debug("%s: Could not request gpio %d\n", __func__, 42665dd74a6SSimon Glass gpio_vector[i]); 42765dd74a6SSimon Glass return ret; 42865dd74a6SSimon Glass } 42965dd74a6SSimon Glass } 43065dd74a6SSimon Glass spd_index = gpio_get_values_as_int(gpio_vector); 43165dd74a6SSimon Glass debug("spd index %d\n", spd_index); 43265dd74a6SSimon Glass node = fdtdec_next_compatible(blob, 0, COMPAT_MEMORY_SPD); 43365dd74a6SSimon Glass if (node < 0) { 43465dd74a6SSimon Glass printf("SPD data not found.\n"); 43565dd74a6SSimon Glass return -ENOENT; 43665dd74a6SSimon Glass } 43765dd74a6SSimon Glass 43865dd74a6SSimon Glass for (spd_node = fdt_first_subnode(blob, node); 43965dd74a6SSimon Glass spd_node > 0; 44065dd74a6SSimon Glass spd_node = fdt_next_subnode(blob, spd_node)) { 44165dd74a6SSimon Glass const char *data; 44265dd74a6SSimon Glass int len; 44365dd74a6SSimon Glass 44465dd74a6SSimon Glass if (fdtdec_get_int(blob, spd_node, "reg", -1) != spd_index) 44565dd74a6SSimon Glass continue; 44665dd74a6SSimon Glass data = fdt_getprop(blob, spd_node, "data", &len); 44765dd74a6SSimon Glass if (len < sizeof(peid->spd_data[0])) { 44865dd74a6SSimon Glass printf("Missing SPD data\n"); 44965dd74a6SSimon Glass return -EINVAL; 45065dd74a6SSimon Glass } 45165dd74a6SSimon Glass 45265dd74a6SSimon Glass debug("Using SDRAM SPD data for '%s'\n", 45365dd74a6SSimon Glass fdt_get_name(blob, spd_node, NULL)); 45465dd74a6SSimon Glass memcpy(peid->spd_data[0], data, sizeof(peid->spd_data[0])); 45565dd74a6SSimon Glass break; 45665dd74a6SSimon Glass } 45765dd74a6SSimon Glass 45865dd74a6SSimon Glass if (spd_node < 0) { 45965dd74a6SSimon Glass printf("No SPD data found for index %d\n", spd_index); 46065dd74a6SSimon Glass return -ENOENT; 46165dd74a6SSimon Glass } 46265dd74a6SSimon Glass 46365dd74a6SSimon Glass return 0; 46465dd74a6SSimon Glass } 46565dd74a6SSimon Glass 46665dd74a6SSimon Glass /** 46765dd74a6SSimon Glass * add_memory_area() - Add a new usable memory area to our list 46865dd74a6SSimon Glass * 46965dd74a6SSimon Glass * Note: @start and @end must not span the first 4GB boundary 47065dd74a6SSimon Glass * 47165dd74a6SSimon Glass * @info: Place to store memory info 47265dd74a6SSimon Glass * @start: Start of this memory area 47365dd74a6SSimon Glass * @end: End of this memory area + 1 47465dd74a6SSimon Glass */ 47565dd74a6SSimon Glass static int add_memory_area(struct memory_info *info, 47665dd74a6SSimon Glass uint64_t start, uint64_t end) 47765dd74a6SSimon Glass { 47865dd74a6SSimon Glass struct memory_area *ptr; 47965dd74a6SSimon Glass 48065dd74a6SSimon Glass if (info->num_areas == CONFIG_NR_DRAM_BANKS) 48165dd74a6SSimon Glass return -ENOSPC; 48265dd74a6SSimon Glass 48365dd74a6SSimon Glass ptr = &info->area[info->num_areas]; 48465dd74a6SSimon Glass ptr->start = start; 48565dd74a6SSimon Glass ptr->size = end - start; 48665dd74a6SSimon Glass info->total_memory += ptr->size; 48765dd74a6SSimon Glass if (ptr->start < (1ULL << 32)) 48865dd74a6SSimon Glass info->total_32bit_memory += ptr->size; 48965dd74a6SSimon Glass debug("%d: memory %llx size %llx, total now %llx / %llx\n", 49065dd74a6SSimon Glass info->num_areas, ptr->start, ptr->size, 49165dd74a6SSimon Glass info->total_32bit_memory, info->total_memory); 49265dd74a6SSimon Glass info->num_areas++; 49365dd74a6SSimon Glass 49465dd74a6SSimon Glass return 0; 49565dd74a6SSimon Glass } 49665dd74a6SSimon Glass 49765dd74a6SSimon Glass /** 49865dd74a6SSimon Glass * sdram_find() - Find available memory 49965dd74a6SSimon Glass * 50065dd74a6SSimon Glass * This is a bit complicated since on x86 there are system memory holes all 50165dd74a6SSimon Glass * over the place. We create a list of available memory blocks 5022588e711SSimon Glass * 5032588e711SSimon Glass * @dev: Northbridge device 50465dd74a6SSimon Glass */ 5052588e711SSimon Glass static int sdram_find(struct udevice *dev) 50665dd74a6SSimon Glass { 50765dd74a6SSimon Glass struct memory_info *info = &gd->arch.meminfo; 50865dd74a6SSimon Glass uint32_t tseg_base, uma_size, tolud; 50965dd74a6SSimon Glass uint64_t tom, me_base, touud; 51065dd74a6SSimon Glass uint64_t uma_memory_base = 0; 51165dd74a6SSimon Glass uint64_t uma_memory_size; 51265dd74a6SSimon Glass unsigned long long tomk; 51365dd74a6SSimon Glass uint16_t ggc; 5142588e711SSimon Glass u32 val; 51565dd74a6SSimon Glass 51665dd74a6SSimon Glass /* Total Memory 2GB example: 51765dd74a6SSimon Glass * 51865dd74a6SSimon Glass * 00000000 0000MB-1992MB 1992MB RAM (writeback) 51965dd74a6SSimon Glass * 7c800000 1992MB-2000MB 8MB TSEG (SMRR) 52065dd74a6SSimon Glass * 7d000000 2000MB-2002MB 2MB GFX GTT (uncached) 52165dd74a6SSimon Glass * 7d200000 2002MB-2034MB 32MB GFX UMA (uncached) 52265dd74a6SSimon Glass * 7f200000 2034MB TOLUD 52365dd74a6SSimon Glass * 7f800000 2040MB MEBASE 52465dd74a6SSimon Glass * 7f800000 2040MB-2048MB 8MB ME UMA (uncached) 52565dd74a6SSimon Glass * 80000000 2048MB TOM 52665dd74a6SSimon Glass * 100000000 4096MB-4102MB 6MB RAM (writeback) 52765dd74a6SSimon Glass * 52865dd74a6SSimon Glass * Total Memory 4GB example: 52965dd74a6SSimon Glass * 53065dd74a6SSimon Glass * 00000000 0000MB-2768MB 2768MB RAM (writeback) 53165dd74a6SSimon Glass * ad000000 2768MB-2776MB 8MB TSEG (SMRR) 53265dd74a6SSimon Glass * ad800000 2776MB-2778MB 2MB GFX GTT (uncached) 53365dd74a6SSimon Glass * ada00000 2778MB-2810MB 32MB GFX UMA (uncached) 53465dd74a6SSimon Glass * afa00000 2810MB TOLUD 53565dd74a6SSimon Glass * ff800000 4088MB MEBASE 53665dd74a6SSimon Glass * ff800000 4088MB-4096MB 8MB ME UMA (uncached) 53765dd74a6SSimon Glass * 100000000 4096MB TOM 53865dd74a6SSimon Glass * 100000000 4096MB-5374MB 1278MB RAM (writeback) 53965dd74a6SSimon Glass * 14fe00000 5368MB TOUUD 54065dd74a6SSimon Glass */ 54165dd74a6SSimon Glass 54265dd74a6SSimon Glass /* Top of Upper Usable DRAM, including remap */ 5432588e711SSimon Glass dm_pci_read_config32(dev, TOUUD + 4, &val); 5442588e711SSimon Glass touud = (uint64_t)val << 32; 5452588e711SSimon Glass dm_pci_read_config32(dev, TOUUD, &val); 5462588e711SSimon Glass touud |= val; 54765dd74a6SSimon Glass 54865dd74a6SSimon Glass /* Top of Lower Usable DRAM */ 5492588e711SSimon Glass dm_pci_read_config32(dev, TOLUD, &tolud); 55065dd74a6SSimon Glass 55165dd74a6SSimon Glass /* Top of Memory - does not account for any UMA */ 5522588e711SSimon Glass dm_pci_read_config32(dev, 0xa4, &val); 5532588e711SSimon Glass tom = (uint64_t)val << 32; 5542588e711SSimon Glass dm_pci_read_config32(dev, 0xa0, &val); 5552588e711SSimon Glass tom |= val; 55665dd74a6SSimon Glass 55765dd74a6SSimon Glass debug("TOUUD %llx TOLUD %08x TOM %llx\n", touud, tolud, tom); 55865dd74a6SSimon Glass 55965dd74a6SSimon Glass /* ME UMA needs excluding if total memory <4GB */ 5602588e711SSimon Glass dm_pci_read_config32(dev, 0x74, &val); 5612588e711SSimon Glass me_base = (uint64_t)val << 32; 5622588e711SSimon Glass dm_pci_read_config32(dev, 0x70, &val); 5632588e711SSimon Glass me_base |= val; 56465dd74a6SSimon Glass 56565dd74a6SSimon Glass debug("MEBASE %llx\n", me_base); 56665dd74a6SSimon Glass 56765dd74a6SSimon Glass /* TODO: Get rid of all this shifting by 10 bits */ 56865dd74a6SSimon Glass tomk = tolud >> 10; 56965dd74a6SSimon Glass if (me_base == tolud) { 57065dd74a6SSimon Glass /* ME is from MEBASE-TOM */ 57165dd74a6SSimon Glass uma_size = (tom - me_base) >> 10; 57265dd74a6SSimon Glass /* Increment TOLUD to account for ME as RAM */ 57365dd74a6SSimon Glass tolud += uma_size << 10; 57465dd74a6SSimon Glass /* UMA starts at old TOLUD */ 57565dd74a6SSimon Glass uma_memory_base = tomk * 1024ULL; 57665dd74a6SSimon Glass uma_memory_size = uma_size * 1024ULL; 57765dd74a6SSimon Glass debug("ME UMA base %llx size %uM\n", me_base, uma_size >> 10); 57865dd74a6SSimon Glass } 57965dd74a6SSimon Glass 58065dd74a6SSimon Glass /* Graphics memory comes next */ 5812588e711SSimon Glass dm_pci_read_config16(dev, GGC, &ggc); 58265dd74a6SSimon Glass if (!(ggc & 2)) { 58365dd74a6SSimon Glass debug("IGD decoded, subtracting "); 58465dd74a6SSimon Glass 58565dd74a6SSimon Glass /* Graphics memory */ 58665dd74a6SSimon Glass uma_size = ((ggc >> 3) & 0x1f) * 32 * 1024ULL; 58765dd74a6SSimon Glass debug("%uM UMA", uma_size >> 10); 58865dd74a6SSimon Glass tomk -= uma_size; 58965dd74a6SSimon Glass uma_memory_base = tomk * 1024ULL; 59065dd74a6SSimon Glass uma_memory_size += uma_size * 1024ULL; 59165dd74a6SSimon Glass 59265dd74a6SSimon Glass /* GTT Graphics Stolen Memory Size (GGMS) */ 59365dd74a6SSimon Glass uma_size = ((ggc >> 8) & 0x3) * 1024ULL; 59465dd74a6SSimon Glass tomk -= uma_size; 59565dd74a6SSimon Glass uma_memory_base = tomk * 1024ULL; 59665dd74a6SSimon Glass uma_memory_size += uma_size * 1024ULL; 59765dd74a6SSimon Glass debug(" and %uM GTT\n", uma_size >> 10); 59865dd74a6SSimon Glass } 59965dd74a6SSimon Glass 60065dd74a6SSimon Glass /* Calculate TSEG size from its base which must be below GTT */ 6012588e711SSimon Glass dm_pci_read_config32(dev, 0xb8, &tseg_base); 60265dd74a6SSimon Glass uma_size = (uma_memory_base - tseg_base) >> 10; 60365dd74a6SSimon Glass tomk -= uma_size; 60465dd74a6SSimon Glass uma_memory_base = tomk * 1024ULL; 60565dd74a6SSimon Glass uma_memory_size += uma_size * 1024ULL; 60665dd74a6SSimon Glass debug("TSEG base 0x%08x size %uM\n", tseg_base, uma_size >> 10); 60765dd74a6SSimon Glass 60865dd74a6SSimon Glass debug("Available memory below 4GB: %lluM\n", tomk >> 10); 60965dd74a6SSimon Glass 61065dd74a6SSimon Glass /* Report the memory regions */ 61165dd74a6SSimon Glass add_memory_area(info, 1 << 20, 2 << 28); 61265dd74a6SSimon Glass add_memory_area(info, (2 << 28) + (2 << 20), 4 << 28); 61365dd74a6SSimon Glass add_memory_area(info, (4 << 28) + (2 << 20), tseg_base); 61465dd74a6SSimon Glass add_memory_area(info, 1ULL << 32, touud); 615aaafcd6cSSimon Glass 616aaafcd6cSSimon Glass /* Add MTRRs for memory */ 617aaafcd6cSSimon Glass mtrr_add_request(MTRR_TYPE_WRBACK, 0, 2ULL << 30); 618aaafcd6cSSimon Glass mtrr_add_request(MTRR_TYPE_WRBACK, 2ULL << 30, 512 << 20); 619aaafcd6cSSimon Glass mtrr_add_request(MTRR_TYPE_WRBACK, 0xaULL << 28, 256 << 20); 620aaafcd6cSSimon Glass mtrr_add_request(MTRR_TYPE_UNCACHEABLE, tseg_base, 16 << 20); 621aaafcd6cSSimon Glass mtrr_add_request(MTRR_TYPE_UNCACHEABLE, tseg_base + (16 << 20), 622aaafcd6cSSimon Glass 32 << 20); 623aaafcd6cSSimon Glass 62465dd74a6SSimon Glass /* 62565dd74a6SSimon Glass * If >= 4GB installed then memory from TOLUD to 4GB 62665dd74a6SSimon Glass * is remapped above TOM, TOUUD will account for both 62765dd74a6SSimon Glass */ 62865dd74a6SSimon Glass if (touud > (1ULL << 32ULL)) { 62965dd74a6SSimon Glass debug("Available memory above 4GB: %lluM\n", 63065dd74a6SSimon Glass (touud >> 20) - 4096); 63165dd74a6SSimon Glass } 63265dd74a6SSimon Glass 63365dd74a6SSimon Glass return 0; 63465dd74a6SSimon Glass } 63565dd74a6SSimon Glass 63665dd74a6SSimon Glass static void rcba_config(void) 63765dd74a6SSimon Glass { 63865dd74a6SSimon Glass /* 63965dd74a6SSimon Glass * GFX INTA -> PIRQA (MSI) 64065dd74a6SSimon Glass * D28IP_P3IP WLAN INTA -> PIRQB 64165dd74a6SSimon Glass * D29IP_E1P EHCI1 INTA -> PIRQD 64265dd74a6SSimon Glass * D26IP_E2P EHCI2 INTA -> PIRQF 64365dd74a6SSimon Glass * D31IP_SIP SATA INTA -> PIRQF (MSI) 64465dd74a6SSimon Glass * D31IP_SMIP SMBUS INTB -> PIRQH 64565dd74a6SSimon Glass * D31IP_TTIP THRT INTC -> PIRQA 64665dd74a6SSimon Glass * D27IP_ZIP HDA INTA -> PIRQA (MSI) 64765dd74a6SSimon Glass * 64865dd74a6SSimon Glass * TRACKPAD -> PIRQE (Edge Triggered) 64965dd74a6SSimon Glass * TOUCHSCREEN -> PIRQG (Edge Triggered) 65065dd74a6SSimon Glass */ 65165dd74a6SSimon Glass 65265dd74a6SSimon Glass /* Device interrupt pin register (board specific) */ 65365dd74a6SSimon Glass writel((INTC << D31IP_TTIP) | (NOINT << D31IP_SIP2) | 65465dd74a6SSimon Glass (INTB << D31IP_SMIP) | (INTA << D31IP_SIP), RCB_REG(D31IP)); 65565dd74a6SSimon Glass writel(NOINT << D30IP_PIP, RCB_REG(D30IP)); 65665dd74a6SSimon Glass writel(INTA << D29IP_E1P, RCB_REG(D29IP)); 65765dd74a6SSimon Glass writel(INTA << D28IP_P3IP, RCB_REG(D28IP)); 65865dd74a6SSimon Glass writel(INTA << D27IP_ZIP, RCB_REG(D27IP)); 65965dd74a6SSimon Glass writel(INTA << D26IP_E2P, RCB_REG(D26IP)); 66065dd74a6SSimon Glass writel(NOINT << D25IP_LIP, RCB_REG(D25IP)); 66165dd74a6SSimon Glass writel(NOINT << D22IP_MEI1IP, RCB_REG(D22IP)); 66265dd74a6SSimon Glass 66365dd74a6SSimon Glass /* Device interrupt route registers */ 66465dd74a6SSimon Glass writel(DIR_ROUTE(PIRQB, PIRQH, PIRQA, PIRQC), RCB_REG(D31IR)); 66565dd74a6SSimon Glass writel(DIR_ROUTE(PIRQD, PIRQE, PIRQF, PIRQG), RCB_REG(D29IR)); 66665dd74a6SSimon Glass writel(DIR_ROUTE(PIRQB, PIRQC, PIRQD, PIRQE), RCB_REG(D28IR)); 66765dd74a6SSimon Glass writel(DIR_ROUTE(PIRQA, PIRQH, PIRQA, PIRQB), RCB_REG(D27IR)); 66865dd74a6SSimon Glass writel(DIR_ROUTE(PIRQF, PIRQE, PIRQG, PIRQH), RCB_REG(D26IR)); 66965dd74a6SSimon Glass writel(DIR_ROUTE(PIRQA, PIRQB, PIRQC, PIRQD), RCB_REG(D25IR)); 67065dd74a6SSimon Glass writel(DIR_ROUTE(PIRQA, PIRQB, PIRQC, PIRQD), RCB_REG(D22IR)); 67165dd74a6SSimon Glass 67265dd74a6SSimon Glass /* Enable IOAPIC (generic) */ 67365dd74a6SSimon Glass writew(0x0100, RCB_REG(OIC)); 67465dd74a6SSimon Glass /* PCH BWG says to read back the IOAPIC enable register */ 67565dd74a6SSimon Glass (void)readw(RCB_REG(OIC)); 67665dd74a6SSimon Glass 67765dd74a6SSimon Glass /* Disable unused devices (board specific) */ 67865dd74a6SSimon Glass setbits_le32(RCB_REG(FD), PCH_DISABLE_ALWAYS); 67965dd74a6SSimon Glass } 6808ef07571SSimon Glass 6818ef07571SSimon Glass int dram_init(void) 6828ef07571SSimon Glass { 68365dd74a6SSimon Glass struct pei_data pei_data __aligned(8) = { 68465dd74a6SSimon Glass .pei_version = PEI_VERSION, 68565dd74a6SSimon Glass .mchbar = DEFAULT_MCHBAR, 68665dd74a6SSimon Glass .dmibar = DEFAULT_DMIBAR, 68765dd74a6SSimon Glass .epbar = DEFAULT_EPBAR, 6882d934e57SSimon Glass .pciexbar = CONFIG_PCIE_ECAM_BASE, 68965dd74a6SSimon Glass .smbusbar = SMBUS_IO_BASE, 69065dd74a6SSimon Glass .wdbbar = 0x4000000, 69165dd74a6SSimon Glass .wdbsize = 0x1000, 69265dd74a6SSimon Glass .hpet_address = CONFIG_HPET_ADDRESS, 69365dd74a6SSimon Glass .rcba = DEFAULT_RCBABASE, 69465dd74a6SSimon Glass .pmbase = DEFAULT_PMBASE, 69565dd74a6SSimon Glass .gpiobase = DEFAULT_GPIOBASE, 69665dd74a6SSimon Glass .thermalbase = 0xfed08000, 69765dd74a6SSimon Glass .system_type = 0, /* 0 Mobile, 1 Desktop/Server */ 69865dd74a6SSimon Glass .tseg_size = CONFIG_SMM_TSEG_SIZE, 69965dd74a6SSimon Glass .ts_addresses = { 0x00, 0x00, 0x00, 0x00 }, 70065dd74a6SSimon Glass .ec_present = 1, 70165dd74a6SSimon Glass .ddr3lv_support = 1, 70265dd74a6SSimon Glass /* 70365dd74a6SSimon Glass * 0 = leave channel enabled 70465dd74a6SSimon Glass * 1 = disable dimm 0 on channel 70565dd74a6SSimon Glass * 2 = disable dimm 1 on channel 70665dd74a6SSimon Glass * 3 = disable dimm 0+1 on channel 70765dd74a6SSimon Glass */ 70865dd74a6SSimon Glass .dimm_channel0_disabled = 2, 70965dd74a6SSimon Glass .dimm_channel1_disabled = 2, 71065dd74a6SSimon Glass .max_ddr3_freq = 1600, 71165dd74a6SSimon Glass .usb_port_config = { 71265dd74a6SSimon Glass /* 71365dd74a6SSimon Glass * Empty and onboard Ports 0-7, set to un-used pin 71465dd74a6SSimon Glass * OC3 71565dd74a6SSimon Glass */ 71665dd74a6SSimon Glass { 0, 3, 0x0000 }, /* P0= Empty */ 71765dd74a6SSimon Glass { 1, 0, 0x0040 }, /* P1= Left USB 1 (OC0) */ 71865dd74a6SSimon Glass { 1, 1, 0x0040 }, /* P2= Left USB 2 (OC1) */ 71965dd74a6SSimon Glass { 1, 3, 0x0040 }, /* P3= SDCARD (no OC) */ 72065dd74a6SSimon Glass { 0, 3, 0x0000 }, /* P4= Empty */ 72165dd74a6SSimon Glass { 1, 3, 0x0040 }, /* P5= WWAN (no OC) */ 72265dd74a6SSimon Glass { 0, 3, 0x0000 }, /* P6= Empty */ 72365dd74a6SSimon Glass { 0, 3, 0x0000 }, /* P7= Empty */ 72465dd74a6SSimon Glass /* 72565dd74a6SSimon Glass * Empty and onboard Ports 8-13, set to un-used pin 72665dd74a6SSimon Glass * OC4 72765dd74a6SSimon Glass */ 72865dd74a6SSimon Glass { 1, 4, 0x0040 }, /* P8= Camera (no OC) */ 72965dd74a6SSimon Glass { 1, 4, 0x0040 }, /* P9= Bluetooth (no OC) */ 73065dd74a6SSimon Glass { 0, 4, 0x0000 }, /* P10= Empty */ 73165dd74a6SSimon Glass { 0, 4, 0x0000 }, /* P11= Empty */ 73265dd74a6SSimon Glass { 0, 4, 0x0000 }, /* P12= Empty */ 73365dd74a6SSimon Glass { 0, 4, 0x0000 }, /* P13= Empty */ 73465dd74a6SSimon Glass }, 73565dd74a6SSimon Glass }; 736c02a4242SSimon Glass struct udevice *dev, *me_dev; 73765dd74a6SSimon Glass int ret; 73865dd74a6SSimon Glass 739*3f603cbbSSimon Glass ret = uclass_first_device_err(UCLASS_NORTHBRIDGE, &dev); 7401641bb8cSSimon Glass if (ret) 7411641bb8cSSimon Glass return ret; 74298655f3aSSimon Glass ret = syscon_get_by_driver_data(X86_SYSCON_ME, &me_dev); 743c02a4242SSimon Glass if (ret) 744c02a4242SSimon Glass return ret; 74565dd74a6SSimon Glass debug("Boot mode %d\n", gd->arch.pei_boot_mode); 746c6c80d8bSBin Meng debug("mrc_input %p\n", pei_data.mrc_input); 74765dd74a6SSimon Glass pei_data.boot_mode = gd->arch.pei_boot_mode; 74865dd74a6SSimon Glass ret = copy_spd(&pei_data); 74965dd74a6SSimon Glass if (!ret) 750c02a4242SSimon Glass ret = sdram_initialise(dev, me_dev, &pei_data); 75165dd74a6SSimon Glass if (ret) 75265dd74a6SSimon Glass return ret; 75365dd74a6SSimon Glass 75465dd74a6SSimon Glass rcba_config(); 75565dd74a6SSimon Glass quick_ram_check(); 75665dd74a6SSimon Glass 75765dd74a6SSimon Glass writew(0xCAFE, MCHBAR_REG(SSKPD)); 75865dd74a6SSimon Glass 75965dd74a6SSimon Glass post_code(POST_DRAM); 76065dd74a6SSimon Glass 76165dd74a6SSimon Glass ret = sdram_find(dev); 76265dd74a6SSimon Glass if (ret) 76365dd74a6SSimon Glass return ret; 76465dd74a6SSimon Glass 76565dd74a6SSimon Glass gd->ram_size = gd->arch.meminfo.total_32bit_memory; 7668ef07571SSimon Glass 7678ef07571SSimon Glass return 0; 7688ef07571SSimon Glass } 769