blob: 7fe93bdfc5f8258dbc8d49fe545f7a335c19fed7 [file] [log] [blame]
Duncan Lauriec88c54c2014-04-30 16:36:13 -07001/*
2 * This file is part of the coreboot project.
3 *
Duncan Lauriec88c54c2014-04-30 16:36:13 -07004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Duncan Lauriec88c54c2014-04-30 16:36:13 -070013 */
14
Aaron Durbin31be2c92016-12-03 22:08:20 -060015#include <assert.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070016#include <cbfs.h>
17#include <cbmem.h>
Patrick Rudolph45022ae2018-10-01 19:17:11 +020018#include <cf9_reset.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070019#include <console/console.h>
20#include <device/pci_def.h>
Matt DeVillier9aaf59a2018-05-27 21:51:49 -050021#include <memory_info.h>
Aaron Durbindecd0622017-12-15 12:26:40 -070022#include <mrc_cache.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070023#include <string.h>
Julius Wernercd49cce2019-03-05 16:53:33 -080024#if CONFIG(EC_GOOGLE_CHROMEEC)
Duncan Lauriec88c54c2014-04-30 16:36:13 -070025#include <ec/google/chromeec/ec.h>
26#include <ec/google/chromeec/ec_commands.h>
27#endif
28#include <vendorcode/google/chromeos/chromeos.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070029#include <soc/iomap.h>
30#include <soc/pei_data.h>
31#include <soc/pei_wrapper.h>
32#include <soc/pm.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070033#include <soc/romstage.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070034#include <soc/systemagent.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070035
36/*
37 * Find PEI executable in coreboot filesystem and execute it.
38 */
39void raminit(struct pei_data *pei_data)
40{
Aaron Durbin31be2c92016-12-03 22:08:20 -060041 struct region_device rdev;
Lee Leahy26b7cd02017-03-16 18:47:55 -070042 struct memory_info *mem_info;
Duncan Lauriec88c54c2014-04-30 16:36:13 -070043 pei_wrapper_entry_t entry;
44 int ret;
Arthur Heymans4d56a062018-12-22 16:11:52 +010045 struct cbfsf f;
46 uint32_t type = CBFS_TYPE_MRC;
Duncan Lauriec88c54c2014-04-30 16:36:13 -070047
48 broadwell_fill_pei_data(pei_data);
49
Furquan Shaikh0325dc62016-07-25 13:02:36 -070050 if (vboot_recovery_mode_enabled()) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -070051 /* Recovery mode does not use MRC cache */
52 printk(BIOS_DEBUG, "Recovery mode: not using MRC cache.\n");
Aaron Durbin31be2c92016-12-03 22:08:20 -060053 } else if (!mrc_cache_get_current(MRC_TRAINING_DATA, 0, &rdev)) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -070054 /* MRC cache found */
Aaron Durbin31be2c92016-12-03 22:08:20 -060055 pei_data->saved_data_size = region_device_sz(&rdev);
56 pei_data->saved_data = rdev_mmap_full(&rdev);
57 /* Assume boot device is memory mapped. */
Julius Wernercd49cce2019-03-05 16:53:33 -080058 assert(CONFIG(BOOT_DEVICE_MEMORY_MAPPED));
Aaron Durbin9e6d1432016-07-13 23:21:41 -050059 } else if (pei_data->boot_mode == ACPI_S3) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -070060 /* Waking from S3 and no cache. */
61 printk(BIOS_DEBUG, "No MRC cache found in S3 resume path.\n");
62 post_code(POST_RESUME_FAILURE);
Patrick Rudolph45022ae2018-10-01 19:17:11 +020063 system_reset();
Duncan Lauriec88c54c2014-04-30 16:36:13 -070064 } else {
65 printk(BIOS_DEBUG, "No MRC cache found.\n");
Duncan Lauriec88c54c2014-04-30 16:36:13 -070066 }
67
Duncan Laurie61680272014-05-05 12:42:35 -050068 /*
69 * Do not use saved pei data. Can be set by mainboard romstage
70 * to force a full train of memory on every boot.
71 */
72 if (pei_data->disable_saved_data) {
73 printk(BIOS_DEBUG, "Disabling PEI saved data by request\n");
74 pei_data->saved_data = NULL;
75 pei_data->saved_data_size = 0;
76 }
77
Duncan Lauriec88c54c2014-04-30 16:36:13 -070078 /* Determine if mrc.bin is in the cbfs. */
Arthur Heymans4d56a062018-12-22 16:11:52 +010079 if (cbfs_locate_file_in_region(&f, "COREBOOT", "mrc.bin", &type) < 0)
80 die("mrc.bin not found!");
81 /* We don't care about leaking the mapping */
82 entry = (pei_wrapper_entry_t)rdev_mmap_full(&f.data);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070083 if (entry == NULL) {
84 printk(BIOS_DEBUG, "Couldn't find mrc.bin\n");
85 return;
86 }
87
88 printk(BIOS_DEBUG, "Starting Memory Reference Code\n");
89
90 ret = entry(pei_data);
91 if (ret < 0)
92 die("pei_data version mismatch\n");
93
94 /* Print the MRC version after executing the UEFI PEI stage. */
95 u32 version = MCHBAR32(MCHBAR_PEI_VERSION);
96 printk(BIOS_DEBUG, "MRC Version %d.%d.%d Build %d\n",
Lee Leahy26b7cd02017-03-16 18:47:55 -070097 version >> 24, (version >> 16) & 0xff,
Duncan Lauriec88c54c2014-04-30 16:36:13 -070098 (version >> 8) & 0xff, version & 0xff);
99
100 report_memory_config();
101
Aaron Durbin9e6d1432016-07-13 23:21:41 -0500102 if (pei_data->boot_mode != ACPI_S3) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700103 cbmem_initialize_empty();
Aaron Durbin42e68562015-06-09 13:55:51 -0500104 } else if (cbmem_initialize()) {
Julius Wernercd49cce2019-03-05 16:53:33 -0800105#if CONFIG(HAVE_ACPI_RESUME)
Aaron Durbin42e68562015-06-09 13:55:51 -0500106 printk(BIOS_DEBUG, "Failed to recover CBMEM in S3 resume.\n");
107 /* Failed S3 resume, reset to come up cleanly */
Patrick Rudolph45022ae2018-10-01 19:17:11 +0200108 system_reset();
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700109#endif
110 }
111
112 printk(BIOS_DEBUG, "MRC data at %p %d bytes\n", pei_data->data_to_save,
113 pei_data->data_to_save_size);
114
115 if (pei_data->data_to_save != NULL && pei_data->data_to_save_size > 0)
Aaron Durbin31be2c92016-12-03 22:08:20 -0600116 mrc_cache_stash_data(MRC_TRAINING_DATA, 0,
117 pei_data->data_to_save,
118 pei_data->data_to_save_size);
Kane Chenebbb0d42014-07-28 10:54:40 -0700119
120 printk(BIOS_DEBUG, "create cbmem for dimm information\n");
121 mem_info = cbmem_add(CBMEM_ID_MEMINFO, sizeof(struct memory_info));
John Zhao317cbd62019-05-31 10:44:46 -0700122
123 if (!mem_info) {
124 printk(BIOS_ERR, "Error! Failed to add mem_info to cbmem\n");
125 return;
126 }
127
Matt DeVillier9aaf59a2018-05-27 21:51:49 -0500128 memset(mem_info, 0, sizeof(*mem_info));
129 /* Translate pei_memory_info struct data into memory_info struct */
130 mem_info->dimm_cnt = pei_data->meminfo.dimm_cnt;
131 for (int i = 0; i < MIN(DIMM_INFO_TOTAL, PEI_DIMM_INFO_TOTAL); i++) {
132 struct dimm_info *dimm = &mem_info->dimm[i];
133 const struct pei_dimm_info *pei_dimm =
134 &pei_data->meminfo.dimm[i];
135 dimm->dimm_size = pei_dimm->dimm_size;
136 dimm->ddr_type = pei_dimm->ddr_type;
137 dimm->ddr_frequency = pei_dimm->ddr_frequency;
138 dimm->rank_per_dimm = pei_dimm->rank_per_dimm;
139 dimm->channel_num = pei_dimm->channel_num;
140 dimm->dimm_num = pei_dimm->dimm_num;
141 dimm->bank_locator = pei_dimm->bank_locator;
142 memcpy(&dimm->serial, &pei_dimm->serial,
143 MIN(sizeof(dimm->serial), sizeof(pei_dimm->serial)));
144 memcpy(&dimm->module_part_number,
145 &pei_dimm->module_part_number,
146 MIN(sizeof(dimm->module_part_number),
147 sizeof(pei_dimm->module_part_number)));
148 dimm->module_part_number[DIMM_INFO_PART_NUMBER_SIZE - 1] = '\0';
149 dimm->mod_id = pei_dimm->mod_id;
150 dimm->mod_type = pei_dimm->mod_type;
151 dimm->bus_width = pei_dimm->bus_width;
152 }
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700153}