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. |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <arch/cbfs.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 17 | #include <arch/io.h> |
| 18 | #include <cbfs.h> |
| 19 | #include <cbmem.h> |
| 20 | #include <console/console.h> |
| 21 | #include <device/pci_def.h> |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 22 | #include <lib.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 23 | #include <string.h> |
| 24 | #if CONFIG_EC_GOOGLE_CHROMEEC |
| 25 | #include <ec/google/chromeec/ec.h> |
| 26 | #include <ec/google/chromeec/ec_commands.h> |
| 27 | #endif |
| 28 | #include <vendorcode/google/chromeos/chromeos.h> |
| 29 | #include <soc/intel/common/mrc_cache.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 30 | #include <soc/iomap.h> |
| 31 | #include <soc/pei_data.h> |
| 32 | #include <soc/pei_wrapper.h> |
| 33 | #include <soc/pm.h> |
| 34 | #include <soc/reset.h> |
| 35 | #include <soc/romstage.h> |
| 36 | #include <soc/smm.h> |
| 37 | #include <soc/systemagent.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 38 | |
| 39 | /* |
| 40 | * Find PEI executable in coreboot filesystem and execute it. |
| 41 | */ |
| 42 | void raminit(struct pei_data *pei_data) |
| 43 | { |
| 44 | const struct mrc_saved_data *cache; |
Kane Chen | ebbb0d4 | 2014-07-28 10:54:40 -0700 | [diff] [blame] | 45 | struct memory_info* mem_info; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 46 | pei_wrapper_entry_t entry; |
| 47 | int ret; |
| 48 | |
| 49 | broadwell_fill_pei_data(pei_data); |
| 50 | |
Furquan Shaikh | 0325dc6 | 2016-07-25 13:02:36 -0700 | [diff] [blame] | 51 | if (vboot_recovery_mode_enabled()) { |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 52 | /* Recovery mode does not use MRC cache */ |
| 53 | printk(BIOS_DEBUG, "Recovery mode: not using MRC cache.\n"); |
| 54 | } else if (!mrc_cache_get_current(&cache)) { |
| 55 | /* MRC cache found */ |
| 56 | pei_data->saved_data_size = cache->size; |
| 57 | pei_data->saved_data = &cache->data[0]; |
Aaron Durbin | 9e6d143 | 2016-07-13 23:21:41 -0500 | [diff] [blame] | 58 | } else if (pei_data->boot_mode == ACPI_S3) { |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 59 | /* Waking from S3 and no cache. */ |
| 60 | printk(BIOS_DEBUG, "No MRC cache found in S3 resume path.\n"); |
| 61 | post_code(POST_RESUME_FAILURE); |
| 62 | reset_system(); |
| 63 | } else { |
| 64 | printk(BIOS_DEBUG, "No MRC cache found.\n"); |
| 65 | #if CONFIG_EC_GOOGLE_CHROMEEC |
Aaron Durbin | 9e6d143 | 2016-07-13 23:21:41 -0500 | [diff] [blame] | 66 | if (pei_data->boot_mode == ACPI_S0) { |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 67 | /* Ensure EC is running RO firmware. */ |
| 68 | google_chromeec_check_ec_image(EC_IMAGE_RO); |
| 69 | } |
| 70 | #endif |
| 71 | } |
| 72 | |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 73 | /* |
| 74 | * Do not use saved pei data. Can be set by mainboard romstage |
| 75 | * to force a full train of memory on every boot. |
| 76 | */ |
| 77 | if (pei_data->disable_saved_data) { |
| 78 | printk(BIOS_DEBUG, "Disabling PEI saved data by request\n"); |
| 79 | pei_data->saved_data = NULL; |
| 80 | pei_data->saved_data_size = 0; |
| 81 | } |
| 82 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 83 | /* Determine if mrc.bin is in the cbfs. */ |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 84 | entry = cbfs_boot_map_with_leak("mrc.bin", CBFS_TYPE_MRC, NULL); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 85 | if (entry == NULL) { |
| 86 | printk(BIOS_DEBUG, "Couldn't find mrc.bin\n"); |
| 87 | return; |
| 88 | } |
| 89 | |
| 90 | printk(BIOS_DEBUG, "Starting Memory Reference Code\n"); |
| 91 | |
| 92 | ret = entry(pei_data); |
| 93 | if (ret < 0) |
| 94 | die("pei_data version mismatch\n"); |
| 95 | |
| 96 | /* Print the MRC version after executing the UEFI PEI stage. */ |
| 97 | u32 version = MCHBAR32(MCHBAR_PEI_VERSION); |
| 98 | printk(BIOS_DEBUG, "MRC Version %d.%d.%d Build %d\n", |
| 99 | version >> 24 , (version >> 16) & 0xff, |
| 100 | (version >> 8) & 0xff, version & 0xff); |
| 101 | |
| 102 | report_memory_config(); |
| 103 | |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 104 | /* Basic memory sanity test */ |
| 105 | quick_ram_check(); |
| 106 | |
Aaron Durbin | 9e6d143 | 2016-07-13 23:21:41 -0500 | [diff] [blame] | 107 | if (pei_data->boot_mode != ACPI_S3) { |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 108 | cbmem_initialize_empty(); |
Aaron Durbin | 42e6856 | 2015-06-09 13:55:51 -0500 | [diff] [blame] | 109 | } else if (cbmem_initialize()) { |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 110 | #if CONFIG_HAVE_ACPI_RESUME |
Aaron Durbin | 42e6856 | 2015-06-09 13:55:51 -0500 | [diff] [blame] | 111 | printk(BIOS_DEBUG, "Failed to recover CBMEM in S3 resume.\n"); |
| 112 | /* Failed S3 resume, reset to come up cleanly */ |
| 113 | reset_system(); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 114 | #endif |
| 115 | } |
| 116 | |
| 117 | printk(BIOS_DEBUG, "MRC data at %p %d bytes\n", pei_data->data_to_save, |
| 118 | pei_data->data_to_save_size); |
| 119 | |
| 120 | if (pei_data->data_to_save != NULL && pei_data->data_to_save_size > 0) |
| 121 | mrc_cache_stash_data(pei_data->data_to_save, |
| 122 | pei_data->data_to_save_size); |
Kane Chen | ebbb0d4 | 2014-07-28 10:54:40 -0700 | [diff] [blame] | 123 | |
| 124 | printk(BIOS_DEBUG, "create cbmem for dimm information\n"); |
| 125 | mem_info = cbmem_add(CBMEM_ID_MEMINFO, sizeof(struct memory_info)); |
| 126 | memcpy(mem_info, &pei_data->meminfo, sizeof(struct memory_info)); |
| 127 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 128 | } |