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