Angel Pons | f94ac9a | 2020-04-05 15:46:48 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 2 | |
Aaron Durbin | 31be2c9 | 2016-12-03 22:08:20 -0600 | [diff] [blame] | 3 | #include <assert.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 4 | #include <cbfs.h> |
| 5 | #include <cbmem.h> |
Patrick Rudolph | 45022ae | 2018-10-01 19:17:11 +0200 | [diff] [blame] | 6 | #include <cf9_reset.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 7 | #include <console/console.h> |
| 8 | #include <device/pci_def.h> |
Matt DeVillier | 9aaf59a | 2018-05-27 21:51:49 -0500 | [diff] [blame] | 9 | #include <memory_info.h> |
Aaron Durbin | decd062 | 2017-12-15 12:26:40 -0700 | [diff] [blame] | 10 | #include <mrc_cache.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 11 | #include <string.h> |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 12 | #if CONFIG(EC_GOOGLE_CHROMEEC) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 13 | #include <ec/google/chromeec/ec.h> |
| 14 | #include <ec/google/chromeec/ec_commands.h> |
| 15 | #endif |
| 16 | #include <vendorcode/google/chromeos/chromeos.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 17 | #include <soc/iomap.h> |
| 18 | #include <soc/pei_data.h> |
| 19 | #include <soc/pei_wrapper.h> |
| 20 | #include <soc/pm.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 21 | #include <soc/romstage.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 22 | #include <soc/systemagent.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 23 | |
| 24 | /* |
| 25 | * Find PEI executable in coreboot filesystem and execute it. |
| 26 | */ |
| 27 | void raminit(struct pei_data *pei_data) |
| 28 | { |
Shelley Chen | ad9cd68 | 2020-07-23 16:10:52 -0700 | [diff] [blame] | 29 | size_t mrc_size; |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 30 | struct memory_info *mem_info; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 31 | pei_wrapper_entry_t entry; |
| 32 | int ret; |
Arthur Heymans | 4d56a06 | 2018-12-22 16:11:52 +0100 | [diff] [blame] | 33 | struct cbfsf f; |
| 34 | uint32_t type = CBFS_TYPE_MRC; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 35 | |
| 36 | broadwell_fill_pei_data(pei_data); |
| 37 | |
Julius Werner | 29fbfcc | 2020-03-02 15:54:43 -0800 | [diff] [blame] | 38 | if (CONFIG(BROADWELL_VBOOT_IN_BOOTBLOCK) && |
| 39 | vboot_recovery_mode_enabled()) { |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 40 | /* Recovery mode does not use MRC cache */ |
| 41 | printk(BIOS_DEBUG, "Recovery mode: not using MRC cache.\n"); |
Shelley Chen | ad9cd68 | 2020-07-23 16:10:52 -0700 | [diff] [blame] | 42 | } else { |
Aaron Durbin | 31be2c9 | 2016-12-03 22:08:20 -0600 | [diff] [blame] | 43 | /* Assume boot device is memory mapped. */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 44 | assert(CONFIG(BOOT_DEVICE_MEMORY_MAPPED)); |
Shelley Chen | ad9cd68 | 2020-07-23 16:10:52 -0700 | [diff] [blame] | 45 | |
| 46 | pei_data->saved_data = |
| 47 | mrc_cache_current_mmap_leak(MRC_TRAINING_DATA, 0, |
| 48 | &mrc_size); |
| 49 | if (pei_data->saved_data) { |
| 50 | /* MRC cache found */ |
| 51 | pei_data->saved_data_size = mrc_size; |
| 52 | } else if (pei_data->boot_mode == ACPI_S3) { |
| 53 | /* Waking from S3 and no cache. */ |
| 54 | printk(BIOS_DEBUG, |
| 55 | "No MRC cache found in S3 resume path.\n"); |
| 56 | post_code(POST_RESUME_FAILURE); |
| 57 | system_reset(); |
| 58 | } else { |
| 59 | printk(BIOS_DEBUG, "No MRC cache found.\n"); |
| 60 | } |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 63 | /* |
| 64 | * Do not use saved pei data. Can be set by mainboard romstage |
| 65 | * to force a full train of memory on every boot. |
| 66 | */ |
| 67 | if (pei_data->disable_saved_data) { |
| 68 | printk(BIOS_DEBUG, "Disabling PEI saved data by request\n"); |
| 69 | pei_data->saved_data = NULL; |
| 70 | pei_data->saved_data_size = 0; |
| 71 | } |
| 72 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 73 | /* Determine if mrc.bin is in the cbfs. */ |
Arthur Heymans | 4d56a06 | 2018-12-22 16:11:52 +0100 | [diff] [blame] | 74 | if (cbfs_locate_file_in_region(&f, "COREBOOT", "mrc.bin", &type) < 0) |
| 75 | die("mrc.bin not found!"); |
| 76 | /* We don't care about leaking the mapping */ |
| 77 | entry = (pei_wrapper_entry_t)rdev_mmap_full(&f.data); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 78 | if (entry == NULL) { |
| 79 | printk(BIOS_DEBUG, "Couldn't find mrc.bin\n"); |
| 80 | return; |
| 81 | } |
| 82 | |
| 83 | printk(BIOS_DEBUG, "Starting Memory Reference Code\n"); |
| 84 | |
| 85 | ret = entry(pei_data); |
| 86 | if (ret < 0) |
| 87 | die("pei_data version mismatch\n"); |
| 88 | |
| 89 | /* Print the MRC version after executing the UEFI PEI stage. */ |
| 90 | u32 version = MCHBAR32(MCHBAR_PEI_VERSION); |
| 91 | printk(BIOS_DEBUG, "MRC Version %d.%d.%d Build %d\n", |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 92 | version >> 24, (version >> 16) & 0xff, |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 93 | (version >> 8) & 0xff, version & 0xff); |
| 94 | |
| 95 | report_memory_config(); |
| 96 | |
Aaron Durbin | 9e6d143 | 2016-07-13 23:21:41 -0500 | [diff] [blame] | 97 | if (pei_data->boot_mode != ACPI_S3) { |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 98 | cbmem_initialize_empty(); |
Aaron Durbin | 42e6856 | 2015-06-09 13:55:51 -0500 | [diff] [blame] | 99 | } else if (cbmem_initialize()) { |
Aaron Durbin | 42e6856 | 2015-06-09 13:55:51 -0500 | [diff] [blame] | 100 | printk(BIOS_DEBUG, "Failed to recover CBMEM in S3 resume.\n"); |
| 101 | /* Failed S3 resume, reset to come up cleanly */ |
Patrick Rudolph | 45022ae | 2018-10-01 19:17:11 +0200 | [diff] [blame] | 102 | system_reset(); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | printk(BIOS_DEBUG, "MRC data at %p %d bytes\n", pei_data->data_to_save, |
| 106 | pei_data->data_to_save_size); |
| 107 | |
| 108 | if (pei_data->data_to_save != NULL && pei_data->data_to_save_size > 0) |
Aaron Durbin | 31be2c9 | 2016-12-03 22:08:20 -0600 | [diff] [blame] | 109 | mrc_cache_stash_data(MRC_TRAINING_DATA, 0, |
| 110 | pei_data->data_to_save, |
| 111 | pei_data->data_to_save_size); |
Kane Chen | ebbb0d4 | 2014-07-28 10:54:40 -0700 | [diff] [blame] | 112 | |
| 113 | printk(BIOS_DEBUG, "create cbmem for dimm information\n"); |
| 114 | mem_info = cbmem_add(CBMEM_ID_MEMINFO, sizeof(struct memory_info)); |
John Zhao | 317cbd6 | 2019-05-31 10:44:46 -0700 | [diff] [blame] | 115 | |
| 116 | if (!mem_info) { |
| 117 | printk(BIOS_ERR, "Error! Failed to add mem_info to cbmem\n"); |
| 118 | return; |
| 119 | } |
| 120 | |
Matt DeVillier | 9aaf59a | 2018-05-27 21:51:49 -0500 | [diff] [blame] | 121 | memset(mem_info, 0, sizeof(*mem_info)); |
| 122 | /* Translate pei_memory_info struct data into memory_info struct */ |
| 123 | mem_info->dimm_cnt = pei_data->meminfo.dimm_cnt; |
| 124 | for (int i = 0; i < MIN(DIMM_INFO_TOTAL, PEI_DIMM_INFO_TOTAL); i++) { |
| 125 | struct dimm_info *dimm = &mem_info->dimm[i]; |
| 126 | const struct pei_dimm_info *pei_dimm = |
| 127 | &pei_data->meminfo.dimm[i]; |
| 128 | dimm->dimm_size = pei_dimm->dimm_size; |
| 129 | dimm->ddr_type = pei_dimm->ddr_type; |
| 130 | dimm->ddr_frequency = pei_dimm->ddr_frequency; |
| 131 | dimm->rank_per_dimm = pei_dimm->rank_per_dimm; |
| 132 | dimm->channel_num = pei_dimm->channel_num; |
| 133 | dimm->dimm_num = pei_dimm->dimm_num; |
| 134 | dimm->bank_locator = pei_dimm->bank_locator; |
| 135 | memcpy(&dimm->serial, &pei_dimm->serial, |
| 136 | MIN(sizeof(dimm->serial), sizeof(pei_dimm->serial))); |
| 137 | memcpy(&dimm->module_part_number, |
| 138 | &pei_dimm->module_part_number, |
| 139 | MIN(sizeof(dimm->module_part_number), |
| 140 | sizeof(pei_dimm->module_part_number))); |
| 141 | dimm->module_part_number[DIMM_INFO_PART_NUMBER_SIZE - 1] = '\0'; |
| 142 | dimm->mod_id = pei_dimm->mod_id; |
| 143 | dimm->mod_type = pei_dimm->mod_type; |
| 144 | dimm->bus_width = pei_dimm->bus_width; |
| 145 | } |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 146 | } |