blob: 9db34befff73fca3cf3b79c92dd18966fa7b5549 [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 Werner4ee4bd52014-10-20 13:46:39 -070012#include <soc/iomap.h>
13#include <soc/pei_data.h>
14#include <soc/pei_wrapper.h>
15#include <soc/pm.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070016#include <soc/romstage.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070017#include <soc/systemagent.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070018
Angel Ponsd0d528a2021-01-20 23:09:16 +010019void save_mrc_data(struct pei_data *pei_data)
20{
21 printk(BIOS_DEBUG, "MRC data at %p %d bytes\n", pei_data->data_to_save,
22 pei_data->data_to_save_size);
23
24 if (pei_data->data_to_save != NULL && pei_data->data_to_save_size > 0)
25 mrc_cache_stash_data(MRC_TRAINING_DATA, 0,
26 pei_data->data_to_save,
27 pei_data->data_to_save_size);
28}
29
Angel Pons29a52c82020-10-13 23:32:55 +020030static const char *const ecc_decoder[] = {
31 "inactive",
32 "active on IO",
33 "disabled on IO",
34 "active",
35};
36
Duncan Lauriec88c54c2014-04-30 16:36:13 -070037/*
Angel Pons239c9662020-10-13 21:34:53 +020038 * Dump in the log memory controller configuration as read from the memory
39 * controller registers.
40 */
41static void report_memory_config(void)
42{
Angel Pons239c9662020-10-13 21:34:53 +020043 int i;
44
Angel Ponsa8753e92021-04-17 14:34:37 +020045 const u32 addr_decoder_common = mchbar_read32(MAD_CHNL);
Angel Pons239c9662020-10-13 21:34:53 +020046
47 printk(BIOS_DEBUG, "memcfg DDR3 clock %d MHz\n",
Angel Ponsa8753e92021-04-17 14:34:37 +020048 (mchbar_read32(MC_BIOS_DATA) * 13333 * 2 + 50) / 100);
Angel Pons430f1c52020-10-13 23:01:48 +020049
Angel Pons239c9662020-10-13 21:34:53 +020050 printk(BIOS_DEBUG, "memcfg channel assignment: A: %d, B % d, C % d\n",
Angel Pons430f1c52020-10-13 23:01:48 +020051 (addr_decoder_common >> 0) & 3,
Angel Pons239c9662020-10-13 21:34:53 +020052 (addr_decoder_common >> 2) & 3,
53 (addr_decoder_common >> 4) & 3);
54
Angel Pons162a7372020-10-13 23:37:07 +020055 for (i = 0; i < NUM_CHANNELS; i++) {
Angel Ponsa8753e92021-04-17 14:34:37 +020056 const u32 ch_conf = mchbar_read32(MAD_DIMM(i));
Angel Pons430f1c52020-10-13 23:01:48 +020057
58 printk(BIOS_DEBUG, "memcfg channel[%d] config (%8.8x):\n", i, ch_conf);
Angel Pons29a52c82020-10-13 23:32:55 +020059 printk(BIOS_DEBUG, " ECC %s\n", ecc_decoder[(ch_conf >> 24) & 3]);
Angel Pons239c9662020-10-13 21:34:53 +020060 printk(BIOS_DEBUG, " enhanced interleave mode %s\n",
61 ((ch_conf >> 22) & 1) ? "on" : "off");
Angel Pons430f1c52020-10-13 23:01:48 +020062
Angel Pons239c9662020-10-13 21:34:53 +020063 printk(BIOS_DEBUG, " rank interleave %s\n",
64 ((ch_conf >> 21) & 1) ? "on" : "off");
Angel Pons430f1c52020-10-13 23:01:48 +020065
Angel Pons239c9662020-10-13 21:34:53 +020066 printk(BIOS_DEBUG, " DIMMA %d MB width %s %s rank%s\n",
67 ((ch_conf >> 0) & 0xff) * 256,
68 ((ch_conf >> 19) & 1) ? "x16" : "x8 or x32",
69 ((ch_conf >> 17) & 1) ? "dual" : "single",
70 ((ch_conf >> 16) & 1) ? "" : ", selected");
Angel Pons430f1c52020-10-13 23:01:48 +020071
Angel Pons239c9662020-10-13 21:34:53 +020072 printk(BIOS_DEBUG, " DIMMB %d MB width %s %s rank%s\n",
73 ((ch_conf >> 8) & 0xff) * 256,
Angel Pons973c9d42020-10-13 23:28:23 +020074 ((ch_conf >> 20) & 1) ? "x16" : "x8 or x32",
Angel Pons239c9662020-10-13 21:34:53 +020075 ((ch_conf >> 18) & 1) ? "dual" : "single",
76 ((ch_conf >> 16) & 1) ? ", selected" : "");
77 }
78}
79
80/*
Duncan Lauriec88c54c2014-04-30 16:36:13 -070081 * Find PEI executable in coreboot filesystem and execute it.
82 */
Angel Ponsd0d528a2021-01-20 23:09:16 +010083void sdram_initialize(struct pei_data *pei_data)
Duncan Lauriec88c54c2014-04-30 16:36:13 -070084{
Shelley Chenad9cd682020-07-23 16:10:52 -070085 size_t mrc_size;
Duncan Lauriec88c54c2014-04-30 16:36:13 -070086 pei_wrapper_entry_t entry;
87 int ret;
88
89 broadwell_fill_pei_data(pei_data);
90
Shelley Chen6615c6e2020-10-27 15:58:31 -070091 /* Assume boot device is memory mapped. */
92 assert(CONFIG(BOOT_DEVICE_MEMORY_MAPPED));
Shelley Chenad9cd682020-07-23 16:10:52 -070093
Shelley Chen6615c6e2020-10-27 15:58:31 -070094 pei_data->saved_data =
95 mrc_cache_current_mmap_leak(MRC_TRAINING_DATA, 0,
96 &mrc_size);
97 if (pei_data->saved_data) {
98 /* MRC cache found */
99 pei_data->saved_data_size = mrc_size;
100 } else if (pei_data->boot_mode == ACPI_S3) {
101 /* Waking from S3 and no cache. */
102 printk(BIOS_DEBUG,
103 "No MRC cache found in S3 resume path.\n");
104 post_code(POST_RESUME_FAILURE);
105 system_reset();
106 } else {
107 printk(BIOS_DEBUG, "No MRC cache found.\n");
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700108 }
109
Duncan Laurie61680272014-05-05 12:42:35 -0500110 /*
111 * Do not use saved pei data. Can be set by mainboard romstage
112 * to force a full train of memory on every boot.
113 */
114 if (pei_data->disable_saved_data) {
115 printk(BIOS_DEBUG, "Disabling PEI saved data by request\n");
116 pei_data->saved_data = NULL;
117 pei_data->saved_data_size = 0;
118 }
119
Arthur Heymans4d56a062018-12-22 16:11:52 +0100120 /* We don't care about leaking the mapping */
Julius Werner9d0cc2a2020-01-22 18:00:18 -0800121 entry = cbfs_ro_map("mrc.bin", NULL);
122 if (entry == NULL)
123 die("mrc.bin not found!");
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700124
125 printk(BIOS_DEBUG, "Starting Memory Reference Code\n");
126
127 ret = entry(pei_data);
128 if (ret < 0)
129 die("pei_data version mismatch\n");
130
131 /* Print the MRC version after executing the UEFI PEI stage. */
Angel Ponsa8753e92021-04-17 14:34:37 +0200132 u32 version = mchbar_read32(MRC_REVISION);
Angel Ponsc1328a62021-06-14 12:43:11 +0200133 printk(BIOS_DEBUG, "MRC Version %u.%u.%u Build %u\n",
Angel Pons430f1c52020-10-13 23:01:48 +0200134 (version >> 24) & 0xff, (version >> 16) & 0xff,
135 (version >> 8) & 0xff, (version >> 0) & 0xff);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700136
137 report_memory_config();
Angel Ponsd0d528a2021-01-20 23:09:16 +0100138}
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700139
Angel Ponsd0d528a2021-01-20 23:09:16 +0100140void setup_sdram_meminfo(struct pei_data *pei_data)
141{
142 struct memory_info *mem_info;
Kane Chenebbb0d42014-07-28 10:54:40 -0700143
144 printk(BIOS_DEBUG, "create cbmem for dimm information\n");
145 mem_info = cbmem_add(CBMEM_ID_MEMINFO, sizeof(struct memory_info));
John Zhao317cbd62019-05-31 10:44:46 -0700146
147 if (!mem_info) {
148 printk(BIOS_ERR, "Error! Failed to add mem_info to cbmem\n");
149 return;
150 }
151
Matt DeVillier9aaf59a2018-05-27 21:51:49 -0500152 memset(mem_info, 0, sizeof(*mem_info));
153 /* Translate pei_memory_info struct data into memory_info struct */
154 mem_info->dimm_cnt = pei_data->meminfo.dimm_cnt;
155 for (int i = 0; i < MIN(DIMM_INFO_TOTAL, PEI_DIMM_INFO_TOTAL); i++) {
156 struct dimm_info *dimm = &mem_info->dimm[i];
157 const struct pei_dimm_info *pei_dimm =
158 &pei_data->meminfo.dimm[i];
159 dimm->dimm_size = pei_dimm->dimm_size;
160 dimm->ddr_type = pei_dimm->ddr_type;
161 dimm->ddr_frequency = pei_dimm->ddr_frequency;
162 dimm->rank_per_dimm = pei_dimm->rank_per_dimm;
163 dimm->channel_num = pei_dimm->channel_num;
164 dimm->dimm_num = pei_dimm->dimm_num;
165 dimm->bank_locator = pei_dimm->bank_locator;
166 memcpy(&dimm->serial, &pei_dimm->serial,
167 MIN(sizeof(dimm->serial), sizeof(pei_dimm->serial)));
168 memcpy(&dimm->module_part_number,
169 &pei_dimm->module_part_number,
170 MIN(sizeof(dimm->module_part_number),
171 sizeof(pei_dimm->module_part_number)));
172 dimm->module_part_number[DIMM_INFO_PART_NUMBER_SIZE - 1] = '\0';
173 dimm->mod_id = pei_dimm->mod_id;
174 dimm->mod_type = pei_dimm->mod_type;
175 dimm->bus_width = pei_dimm->bus_width;
176 }
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700177}