Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2014 Google Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #include <arch/cbfs.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 21 | #include <arch/io.h> |
| 22 | #include <cbfs.h> |
| 23 | #include <cbmem.h> |
| 24 | #include <console/console.h> |
| 25 | #include <device/pci_def.h> |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 26 | #include <lib.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 27 | #include <string.h> |
| 28 | #if CONFIG_EC_GOOGLE_CHROMEEC |
| 29 | #include <ec/google/chromeec/ec.h> |
| 30 | #include <ec/google/chromeec/ec_commands.h> |
| 31 | #endif |
| 32 | #include <vendorcode/google/chromeos/chromeos.h> |
| 33 | #include <soc/intel/common/mrc_cache.h> |
| 34 | #include <broadwell/iomap.h> |
| 35 | #include <broadwell/pei_data.h> |
| 36 | #include <broadwell/pei_wrapper.h> |
| 37 | #include <broadwell/pm.h> |
| 38 | #include <broadwell/reset.h> |
| 39 | #include <broadwell/romstage.h> |
| 40 | #include <broadwell/smm.h> |
| 41 | #include <broadwell/systemagent.h> |
| 42 | |
| 43 | /* |
| 44 | * Find PEI executable in coreboot filesystem and execute it. |
| 45 | */ |
| 46 | void raminit(struct pei_data *pei_data) |
| 47 | { |
| 48 | const struct mrc_saved_data *cache; |
Kane Chen | ebbb0d4 | 2014-07-28 10:54:40 -0700 | [diff] [blame^] | 49 | struct memory_info* mem_info; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 50 | pei_wrapper_entry_t entry; |
| 51 | int ret; |
| 52 | |
| 53 | broadwell_fill_pei_data(pei_data); |
| 54 | |
| 55 | if (recovery_mode_enabled()) { |
| 56 | /* Recovery mode does not use MRC cache */ |
| 57 | printk(BIOS_DEBUG, "Recovery mode: not using MRC cache.\n"); |
| 58 | } else if (!mrc_cache_get_current(&cache)) { |
| 59 | /* MRC cache found */ |
| 60 | pei_data->saved_data_size = cache->size; |
| 61 | pei_data->saved_data = &cache->data[0]; |
| 62 | } else if (pei_data->boot_mode == SLEEP_STATE_S3) { |
| 63 | /* Waking from S3 and no cache. */ |
| 64 | printk(BIOS_DEBUG, "No MRC cache found in S3 resume path.\n"); |
| 65 | post_code(POST_RESUME_FAILURE); |
| 66 | reset_system(); |
| 67 | } else { |
| 68 | printk(BIOS_DEBUG, "No MRC cache found.\n"); |
| 69 | #if CONFIG_EC_GOOGLE_CHROMEEC |
| 70 | if (pei_data->boot_mode == SLEEP_STATE_S0) { |
| 71 | /* Ensure EC is running RO firmware. */ |
| 72 | google_chromeec_check_ec_image(EC_IMAGE_RO); |
| 73 | } |
| 74 | #endif |
| 75 | } |
| 76 | |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 77 | /* |
| 78 | * Do not use saved pei data. Can be set by mainboard romstage |
| 79 | * to force a full train of memory on every boot. |
| 80 | */ |
| 81 | if (pei_data->disable_saved_data) { |
| 82 | printk(BIOS_DEBUG, "Disabling PEI saved data by request\n"); |
| 83 | pei_data->saved_data = NULL; |
| 84 | pei_data->saved_data_size = 0; |
| 85 | } |
| 86 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 87 | /* Determine if mrc.bin is in the cbfs. */ |
| 88 | entry = (pei_wrapper_entry_t)cbfs_get_file_content( |
Marc Jones | a6354a1 | 2014-12-26 22:11:14 -0700 | [diff] [blame] | 89 | CBFS_DEFAULT_MEDIA, "mrc.bin", 0xab, NULL); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 90 | if (entry == NULL) { |
| 91 | printk(BIOS_DEBUG, "Couldn't find mrc.bin\n"); |
| 92 | return; |
| 93 | } |
| 94 | |
| 95 | printk(BIOS_DEBUG, "Starting Memory Reference Code\n"); |
| 96 | |
| 97 | ret = entry(pei_data); |
| 98 | if (ret < 0) |
| 99 | die("pei_data version mismatch\n"); |
| 100 | |
| 101 | /* Print the MRC version after executing the UEFI PEI stage. */ |
| 102 | u32 version = MCHBAR32(MCHBAR_PEI_VERSION); |
| 103 | printk(BIOS_DEBUG, "MRC Version %d.%d.%d Build %d\n", |
| 104 | version >> 24 , (version >> 16) & 0xff, |
| 105 | (version >> 8) & 0xff, version & 0xff); |
| 106 | |
| 107 | report_memory_config(); |
| 108 | |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 109 | /* Basic memory sanity test */ |
| 110 | quick_ram_check(); |
| 111 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 112 | if (pei_data->boot_mode != SLEEP_STATE_S3) { |
| 113 | cbmem_initialize_empty(); |
| 114 | } else if (cbmem_initialize()) { |
| 115 | #if CONFIG_HAVE_ACPI_RESUME |
| 116 | printk(BIOS_DEBUG, "Failed to recover CBMEM in S3 resume.\n"); |
| 117 | /* Failed S3 resume, reset to come up cleanly */ |
| 118 | reset_system(); |
| 119 | #endif |
| 120 | } |
| 121 | |
| 122 | printk(BIOS_DEBUG, "MRC data at %p %d bytes\n", pei_data->data_to_save, |
| 123 | pei_data->data_to_save_size); |
| 124 | |
| 125 | if (pei_data->data_to_save != NULL && pei_data->data_to_save_size > 0) |
| 126 | mrc_cache_stash_data(pei_data->data_to_save, |
| 127 | pei_data->data_to_save_size); |
Kane Chen | ebbb0d4 | 2014-07-28 10:54:40 -0700 | [diff] [blame^] | 128 | |
| 129 | printk(BIOS_DEBUG, "create cbmem for dimm information\n"); |
| 130 | mem_info = cbmem_add(CBMEM_ID_MEMINFO, sizeof(struct memory_info)); |
| 131 | memcpy(mem_info, &pei_data->meminfo, sizeof(struct memory_info)); |
| 132 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 133 | } |