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