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> |
| 21 | #include <arch/hlt.h> |
| 22 | #include <arch/io.h> |
| 23 | #include <cbfs.h> |
| 24 | #include <cbmem.h> |
| 25 | #include <console/console.h> |
| 26 | #include <device/pci_def.h> |
| 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; |
| 49 | pei_wrapper_entry_t entry; |
| 50 | int ret; |
| 51 | |
| 52 | broadwell_fill_pei_data(pei_data); |
| 53 | |
| 54 | if (recovery_mode_enabled()) { |
| 55 | /* Recovery mode does not use MRC cache */ |
| 56 | printk(BIOS_DEBUG, "Recovery mode: not using MRC cache.\n"); |
| 57 | } else if (!mrc_cache_get_current(&cache)) { |
| 58 | /* MRC cache found */ |
| 59 | pei_data->saved_data_size = cache->size; |
| 60 | pei_data->saved_data = &cache->data[0]; |
| 61 | } else if (pei_data->boot_mode == SLEEP_STATE_S3) { |
| 62 | /* Waking from S3 and no cache. */ |
| 63 | printk(BIOS_DEBUG, "No MRC cache found in S3 resume path.\n"); |
| 64 | post_code(POST_RESUME_FAILURE); |
| 65 | reset_system(); |
| 66 | } else { |
| 67 | printk(BIOS_DEBUG, "No MRC cache found.\n"); |
| 68 | #if CONFIG_EC_GOOGLE_CHROMEEC |
| 69 | if (pei_data->boot_mode == SLEEP_STATE_S0) { |
| 70 | /* Ensure EC is running RO firmware. */ |
| 71 | google_chromeec_check_ec_image(EC_IMAGE_RO); |
| 72 | } |
| 73 | #endif |
| 74 | } |
| 75 | |
| 76 | /* Determine if mrc.bin is in the cbfs. */ |
| 77 | entry = (pei_wrapper_entry_t)cbfs_get_file_content( |
| 78 | CBFS_DEFAULT_MEDIA, "mrc.bin", 0xab); |
| 79 | if (entry == NULL) { |
| 80 | printk(BIOS_DEBUG, "Couldn't find mrc.bin\n"); |
| 81 | return; |
| 82 | } |
| 83 | |
| 84 | printk(BIOS_DEBUG, "Starting Memory Reference Code\n"); |
| 85 | |
| 86 | ret = entry(pei_data); |
| 87 | if (ret < 0) |
| 88 | die("pei_data version mismatch\n"); |
| 89 | |
| 90 | /* Print the MRC version after executing the UEFI PEI stage. */ |
| 91 | u32 version = MCHBAR32(MCHBAR_PEI_VERSION); |
| 92 | printk(BIOS_DEBUG, "MRC Version %d.%d.%d Build %d\n", |
| 93 | version >> 24 , (version >> 16) & 0xff, |
| 94 | (version >> 8) & 0xff, version & 0xff); |
| 95 | |
| 96 | report_memory_config(); |
| 97 | |
| 98 | if (pei_data->boot_mode != SLEEP_STATE_S3) { |
| 99 | cbmem_initialize_empty(); |
| 100 | } else if (cbmem_initialize()) { |
| 101 | #if CONFIG_HAVE_ACPI_RESUME |
| 102 | printk(BIOS_DEBUG, "Failed to recover CBMEM in S3 resume.\n"); |
| 103 | /* Failed S3 resume, reset to come up cleanly */ |
| 104 | reset_system(); |
| 105 | #endif |
| 106 | } |
| 107 | |
| 108 | printk(BIOS_DEBUG, "MRC data at %p %d bytes\n", pei_data->data_to_save, |
| 109 | pei_data->data_to_save_size); |
| 110 | |
| 111 | if (pei_data->data_to_save != NULL && pei_data->data_to_save_size > 0) |
| 112 | mrc_cache_stash_data(pei_data->data_to_save, |
| 113 | pei_data->data_to_save_size); |
| 114 | } |