blob: 44a89377d47f47c8845568f5819e2fe0c85a9526 [file] [log] [blame]
Angel Ponsf94ac9a2020-04-05 15:46:48 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Duncan Lauriec88c54c2014-04-30 16:36:13 -07002
Aaron Durbin31be2c92016-12-03 22:08:20 -06003#include <assert.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -07004#include <cbfs.h>
5#include <cbmem.h>
Patrick Rudolph45022ae2018-10-01 19:17:11 +02006#include <cf9_reset.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -07007#include <console/console.h>
8#include <device/pci_def.h>
Matt DeVillier9aaf59a2018-05-27 21:51:49 -05009#include <memory_info.h>
Aaron Durbindecd0622017-12-15 12:26:40 -070010#include <mrc_cache.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070011#include <string.h>
Julius Wernercd49cce2019-03-05 16:53:33 -080012#if CONFIG(EC_GOOGLE_CHROMEEC)
Duncan Lauriec88c54c2014-04-30 16:36:13 -070013#include <ec/google/chromeec/ec.h>
14#include <ec/google/chromeec/ec_commands.h>
15#endif
16#include <vendorcode/google/chromeos/chromeos.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070017#include <soc/iomap.h>
18#include <soc/pei_data.h>
19#include <soc/pei_wrapper.h>
20#include <soc/pm.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070021#include <soc/romstage.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070022#include <soc/systemagent.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070023
Angel Pons29a52c82020-10-13 23:32:55 +020024static const char *const ecc_decoder[] = {
25 "inactive",
26 "active on IO",
27 "disabled on IO",
28 "active",
29};
30
Duncan Lauriec88c54c2014-04-30 16:36:13 -070031/*
Angel Pons239c9662020-10-13 21:34:53 +020032 * Dump in the log memory controller configuration as read from the memory
33 * controller registers.
34 */
35static void report_memory_config(void)
36{
Angel Pons239c9662020-10-13 21:34:53 +020037 int i;
38
Angel Pons430f1c52020-10-13 23:01:48 +020039 const u32 addr_decoder_common = MCHBAR32(MAD_CHNL);
Angel Pons239c9662020-10-13 21:34:53 +020040
41 printk(BIOS_DEBUG, "memcfg DDR3 clock %d MHz\n",
Angel Pons430f1c52020-10-13 23:01:48 +020042 (MCHBAR32(MC_BIOS_DATA) * 13333 * 2 + 50) / 100);
43
Angel Pons239c9662020-10-13 21:34:53 +020044 printk(BIOS_DEBUG, "memcfg channel assignment: A: %d, B % d, C % d\n",
Angel Pons430f1c52020-10-13 23:01:48 +020045 (addr_decoder_common >> 0) & 3,
Angel Pons239c9662020-10-13 21:34:53 +020046 (addr_decoder_common >> 2) & 3,
47 (addr_decoder_common >> 4) & 3);
48
Angel Pons162a7372020-10-13 23:37:07 +020049 for (i = 0; i < NUM_CHANNELS; i++) {
50 const u32 ch_conf = MCHBAR32(MAD_DIMM(i));
Angel Pons430f1c52020-10-13 23:01:48 +020051
52 printk(BIOS_DEBUG, "memcfg channel[%d] config (%8.8x):\n", i, ch_conf);
Angel Pons29a52c82020-10-13 23:32:55 +020053 printk(BIOS_DEBUG, " ECC %s\n", ecc_decoder[(ch_conf >> 24) & 3]);
Angel Pons239c9662020-10-13 21:34:53 +020054 printk(BIOS_DEBUG, " enhanced interleave mode %s\n",
55 ((ch_conf >> 22) & 1) ? "on" : "off");
Angel Pons430f1c52020-10-13 23:01:48 +020056
Angel Pons239c9662020-10-13 21:34:53 +020057 printk(BIOS_DEBUG, " rank interleave %s\n",
58 ((ch_conf >> 21) & 1) ? "on" : "off");
Angel Pons430f1c52020-10-13 23:01:48 +020059
Angel Pons239c9662020-10-13 21:34:53 +020060 printk(BIOS_DEBUG, " DIMMA %d MB width %s %s rank%s\n",
61 ((ch_conf >> 0) & 0xff) * 256,
62 ((ch_conf >> 19) & 1) ? "x16" : "x8 or x32",
63 ((ch_conf >> 17) & 1) ? "dual" : "single",
64 ((ch_conf >> 16) & 1) ? "" : ", selected");
Angel Pons430f1c52020-10-13 23:01:48 +020065
Angel Pons239c9662020-10-13 21:34:53 +020066 printk(BIOS_DEBUG, " DIMMB %d MB width %s %s rank%s\n",
67 ((ch_conf >> 8) & 0xff) * 256,
Angel Pons973c9d42020-10-13 23:28:23 +020068 ((ch_conf >> 20) & 1) ? "x16" : "x8 or x32",
Angel Pons239c9662020-10-13 21:34:53 +020069 ((ch_conf >> 18) & 1) ? "dual" : "single",
70 ((ch_conf >> 16) & 1) ? ", selected" : "");
71 }
72}
73
74/*
Duncan Lauriec88c54c2014-04-30 16:36:13 -070075 * Find PEI executable in coreboot filesystem and execute it.
76 */
77void raminit(struct pei_data *pei_data)
78{
Shelley Chenad9cd682020-07-23 16:10:52 -070079 size_t mrc_size;
Lee Leahy26b7cd02017-03-16 18:47:55 -070080 struct memory_info *mem_info;
Duncan Lauriec88c54c2014-04-30 16:36:13 -070081 pei_wrapper_entry_t entry;
82 int ret;
83
84 broadwell_fill_pei_data(pei_data);
85
Shelley Chen6615c6e2020-10-27 15:58:31 -070086 /* Assume boot device is memory mapped. */
87 assert(CONFIG(BOOT_DEVICE_MEMORY_MAPPED));
Shelley Chenad9cd682020-07-23 16:10:52 -070088
Shelley Chen6615c6e2020-10-27 15:58:31 -070089 pei_data->saved_data =
90 mrc_cache_current_mmap_leak(MRC_TRAINING_DATA, 0,
91 &mrc_size);
92 if (pei_data->saved_data) {
93 /* MRC cache found */
94 pei_data->saved_data_size = mrc_size;
95 } else if (pei_data->boot_mode == ACPI_S3) {
96 /* Waking from S3 and no cache. */
97 printk(BIOS_DEBUG,
98 "No MRC cache found in S3 resume path.\n");
99 post_code(POST_RESUME_FAILURE);
100 system_reset();
101 } else {
102 printk(BIOS_DEBUG, "No MRC cache found.\n");
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700103 }
104
Duncan Laurie61680272014-05-05 12:42:35 -0500105 /*
106 * Do not use saved pei data. Can be set by mainboard romstage
107 * to force a full train of memory on every boot.
108 */
109 if (pei_data->disable_saved_data) {
110 printk(BIOS_DEBUG, "Disabling PEI saved data by request\n");
111 pei_data->saved_data = NULL;
112 pei_data->saved_data_size = 0;
113 }
114
Arthur Heymans4d56a062018-12-22 16:11:52 +0100115 /* We don't care about leaking the mapping */
Julius Werner9d0cc2a2020-01-22 18:00:18 -0800116 entry = cbfs_ro_map("mrc.bin", NULL);
117 if (entry == NULL)
118 die("mrc.bin not found!");
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700119
120 printk(BIOS_DEBUG, "Starting Memory Reference Code\n");
121
122 ret = entry(pei_data);
123 if (ret < 0)
124 die("pei_data version mismatch\n");
125
126 /* Print the MRC version after executing the UEFI PEI stage. */
Angel Pons430f1c52020-10-13 23:01:48 +0200127 u32 version = MCHBAR32(MRC_REVISION);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700128 printk(BIOS_DEBUG, "MRC Version %d.%d.%d Build %d\n",
Angel Pons430f1c52020-10-13 23:01:48 +0200129 (version >> 24) & 0xff, (version >> 16) & 0xff,
130 (version >> 8) & 0xff, (version >> 0) & 0xff);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700131
132 report_memory_config();
133
Aaron Durbin9e6d1432016-07-13 23:21:41 -0500134 if (pei_data->boot_mode != ACPI_S3) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700135 cbmem_initialize_empty();
Aaron Durbin42e68562015-06-09 13:55:51 -0500136 } else if (cbmem_initialize()) {
Aaron Durbin42e68562015-06-09 13:55:51 -0500137 printk(BIOS_DEBUG, "Failed to recover CBMEM in S3 resume.\n");
138 /* Failed S3 resume, reset to come up cleanly */
Patrick Rudolph45022ae2018-10-01 19:17:11 +0200139 system_reset();
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700140 }
141
142 printk(BIOS_DEBUG, "MRC data at %p %d bytes\n", pei_data->data_to_save,
143 pei_data->data_to_save_size);
144
145 if (pei_data->data_to_save != NULL && pei_data->data_to_save_size > 0)
Aaron Durbin31be2c92016-12-03 22:08:20 -0600146 mrc_cache_stash_data(MRC_TRAINING_DATA, 0,
147 pei_data->data_to_save,
148 pei_data->data_to_save_size);
Kane Chenebbb0d42014-07-28 10:54:40 -0700149
150 printk(BIOS_DEBUG, "create cbmem for dimm information\n");
151 mem_info = cbmem_add(CBMEM_ID_MEMINFO, sizeof(struct memory_info));
John Zhao317cbd62019-05-31 10:44:46 -0700152
153 if (!mem_info) {
154 printk(BIOS_ERR, "Error! Failed to add mem_info to cbmem\n");
155 return;
156 }
157
Matt DeVillier9aaf59a2018-05-27 21:51:49 -0500158 memset(mem_info, 0, sizeof(*mem_info));
159 /* Translate pei_memory_info struct data into memory_info struct */
160 mem_info->dimm_cnt = pei_data->meminfo.dimm_cnt;
161 for (int i = 0; i < MIN(DIMM_INFO_TOTAL, PEI_DIMM_INFO_TOTAL); i++) {
162 struct dimm_info *dimm = &mem_info->dimm[i];
163 const struct pei_dimm_info *pei_dimm =
164 &pei_data->meminfo.dimm[i];
165 dimm->dimm_size = pei_dimm->dimm_size;
166 dimm->ddr_type = pei_dimm->ddr_type;
167 dimm->ddr_frequency = pei_dimm->ddr_frequency;
168 dimm->rank_per_dimm = pei_dimm->rank_per_dimm;
169 dimm->channel_num = pei_dimm->channel_num;
170 dimm->dimm_num = pei_dimm->dimm_num;
171 dimm->bank_locator = pei_dimm->bank_locator;
172 memcpy(&dimm->serial, &pei_dimm->serial,
173 MIN(sizeof(dimm->serial), sizeof(pei_dimm->serial)));
174 memcpy(&dimm->module_part_number,
175 &pei_dimm->module_part_number,
176 MIN(sizeof(dimm->module_part_number),
177 sizeof(pei_dimm->module_part_number)));
178 dimm->module_part_number[DIMM_INFO_PART_NUMBER_SIZE - 1] = '\0';
179 dimm->mod_id = pei_dimm->mod_id;
180 dimm->mod_type = pei_dimm->mod_type;
181 dimm->bus_width = pei_dimm->bus_width;
182 }
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700183}