blob: fc8b7c6984a348c159fc9c86a9890b652ca9f5b9 [file] [log] [blame]
Duncan Lauriec88c54c2014-04-30 16:36:13 -07001/*
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 Lauriec88c54c2014-04-30 16:36:13 -070014 */
15
16#include <arch/cbfs.h>
Aaron Durbin31be2c92016-12-03 22:08:20 -060017#include <assert.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070018#include <cbfs.h>
19#include <cbmem.h>
Patrick Rudolph45022ae2018-10-01 19:17:11 +020020#include <cf9_reset.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070021#include <console/console.h>
22#include <device/pci_def.h>
Matt DeVillier9aaf59a2018-05-27 21:51:49 -050023#include <memory_info.h>
Aaron Durbindecd0622017-12-15 12:26:40 -070024#include <mrc_cache.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070025#include <string.h>
Julius Wernercd49cce2019-03-05 16:53:33 -080026#if CONFIG(EC_GOOGLE_CHROMEEC)
Duncan Lauriec88c54c2014-04-30 16:36:13 -070027#include <ec/google/chromeec/ec.h>
28#include <ec/google/chromeec/ec_commands.h>
29#endif
30#include <vendorcode/google/chromeos/chromeos.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070031#include <soc/iomap.h>
32#include <soc/pei_data.h>
33#include <soc/pei_wrapper.h>
34#include <soc/pm.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070035#include <soc/romstage.h>
36#include <soc/smm.h>
37#include <soc/systemagent.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070038
39/*
40 * Find PEI executable in coreboot filesystem and execute it.
41 */
42void raminit(struct pei_data *pei_data)
43{
Aaron Durbin31be2c92016-12-03 22:08:20 -060044 struct region_device rdev;
Lee Leahy26b7cd02017-03-16 18:47:55 -070045 struct memory_info *mem_info;
Duncan Lauriec88c54c2014-04-30 16:36:13 -070046 pei_wrapper_entry_t entry;
47 int ret;
Arthur Heymans4d56a062018-12-22 16:11:52 +010048 struct cbfsf f;
49 uint32_t type = CBFS_TYPE_MRC;
Duncan Lauriec88c54c2014-04-30 16:36:13 -070050
51 broadwell_fill_pei_data(pei_data);
52
Furquan Shaikh0325dc62016-07-25 13:02:36 -070053 if (vboot_recovery_mode_enabled()) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -070054 /* Recovery mode does not use MRC cache */
55 printk(BIOS_DEBUG, "Recovery mode: not using MRC cache.\n");
Aaron Durbin31be2c92016-12-03 22:08:20 -060056 } else if (!mrc_cache_get_current(MRC_TRAINING_DATA, 0, &rdev)) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -070057 /* MRC cache found */
Aaron Durbin31be2c92016-12-03 22:08:20 -060058 pei_data->saved_data_size = region_device_sz(&rdev);
59 pei_data->saved_data = rdev_mmap_full(&rdev);
60 /* Assume boot device is memory mapped. */
Julius Wernercd49cce2019-03-05 16:53:33 -080061 assert(CONFIG(BOOT_DEVICE_MEMORY_MAPPED));
Aaron Durbin9e6d1432016-07-13 23:21:41 -050062 } else if (pei_data->boot_mode == ACPI_S3) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -070063 /* Waking from S3 and no cache. */
64 printk(BIOS_DEBUG, "No MRC cache found in S3 resume path.\n");
65 post_code(POST_RESUME_FAILURE);
Patrick Rudolph45022ae2018-10-01 19:17:11 +020066 system_reset();
Duncan Lauriec88c54c2014-04-30 16:36:13 -070067 } else {
68 printk(BIOS_DEBUG, "No MRC cache found.\n");
Duncan Lauriec88c54c2014-04-30 16:36:13 -070069 }
70
Duncan Laurie61680272014-05-05 12:42:35 -050071 /*
72 * Do not use saved pei data. Can be set by mainboard romstage
73 * to force a full train of memory on every boot.
74 */
75 if (pei_data->disable_saved_data) {
76 printk(BIOS_DEBUG, "Disabling PEI saved data by request\n");
77 pei_data->saved_data = NULL;
78 pei_data->saved_data_size = 0;
79 }
80
Duncan Lauriec88c54c2014-04-30 16:36:13 -070081 /* Determine if mrc.bin is in the cbfs. */
Arthur Heymans4d56a062018-12-22 16:11:52 +010082 if (cbfs_locate_file_in_region(&f, "COREBOOT", "mrc.bin", &type) < 0)
83 die("mrc.bin not found!");
84 /* We don't care about leaking the mapping */
85 entry = (pei_wrapper_entry_t)rdev_mmap_full(&f.data);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070086 if (entry == NULL) {
87 printk(BIOS_DEBUG, "Couldn't find mrc.bin\n");
88 return;
89 }
90
91 printk(BIOS_DEBUG, "Starting Memory Reference Code\n");
92
93 ret = entry(pei_data);
94 if (ret < 0)
95 die("pei_data version mismatch\n");
96
97 /* Print the MRC version after executing the UEFI PEI stage. */
98 u32 version = MCHBAR32(MCHBAR_PEI_VERSION);
99 printk(BIOS_DEBUG, "MRC Version %d.%d.%d Build %d\n",
Lee Leahy26b7cd02017-03-16 18:47:55 -0700100 version >> 24, (version >> 16) & 0xff,
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700101 (version >> 8) & 0xff, version & 0xff);
102
103 report_memory_config();
104
Aaron Durbin9e6d1432016-07-13 23:21:41 -0500105 if (pei_data->boot_mode != ACPI_S3) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700106 cbmem_initialize_empty();
Aaron Durbin42e68562015-06-09 13:55:51 -0500107 } else if (cbmem_initialize()) {
Julius Wernercd49cce2019-03-05 16:53:33 -0800108#if CONFIG(HAVE_ACPI_RESUME)
Aaron Durbin42e68562015-06-09 13:55:51 -0500109 printk(BIOS_DEBUG, "Failed to recover CBMEM in S3 resume.\n");
110 /* Failed S3 resume, reset to come up cleanly */
Patrick Rudolph45022ae2018-10-01 19:17:11 +0200111 system_reset();
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700112#endif
113 }
114
115 printk(BIOS_DEBUG, "MRC data at %p %d bytes\n", pei_data->data_to_save,
116 pei_data->data_to_save_size);
117
118 if (pei_data->data_to_save != NULL && pei_data->data_to_save_size > 0)
Aaron Durbin31be2c92016-12-03 22:08:20 -0600119 mrc_cache_stash_data(MRC_TRAINING_DATA, 0,
120 pei_data->data_to_save,
121 pei_data->data_to_save_size);
Kane Chenebbb0d42014-07-28 10:54:40 -0700122
123 printk(BIOS_DEBUG, "create cbmem for dimm information\n");
124 mem_info = cbmem_add(CBMEM_ID_MEMINFO, sizeof(struct memory_info));
Matt DeVillier9aaf59a2018-05-27 21:51:49 -0500125 memset(mem_info, 0, sizeof(*mem_info));
126 /* Translate pei_memory_info struct data into memory_info struct */
127 mem_info->dimm_cnt = pei_data->meminfo.dimm_cnt;
128 for (int i = 0; i < MIN(DIMM_INFO_TOTAL, PEI_DIMM_INFO_TOTAL); i++) {
129 struct dimm_info *dimm = &mem_info->dimm[i];
130 const struct pei_dimm_info *pei_dimm =
131 &pei_data->meminfo.dimm[i];
132 dimm->dimm_size = pei_dimm->dimm_size;
133 dimm->ddr_type = pei_dimm->ddr_type;
134 dimm->ddr_frequency = pei_dimm->ddr_frequency;
135 dimm->rank_per_dimm = pei_dimm->rank_per_dimm;
136 dimm->channel_num = pei_dimm->channel_num;
137 dimm->dimm_num = pei_dimm->dimm_num;
138 dimm->bank_locator = pei_dimm->bank_locator;
139 memcpy(&dimm->serial, &pei_dimm->serial,
140 MIN(sizeof(dimm->serial), sizeof(pei_dimm->serial)));
141 memcpy(&dimm->module_part_number,
142 &pei_dimm->module_part_number,
143 MIN(sizeof(dimm->module_part_number),
144 sizeof(pei_dimm->module_part_number)));
145 dimm->module_part_number[DIMM_INFO_PART_NUMBER_SIZE - 1] = '\0';
146 dimm->mod_id = pei_dimm->mod_id;
147 dimm->mod_type = pei_dimm->mod_type;
148 dimm->bus_width = pei_dimm->bus_width;
149 }
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700150}