2020-04-05 15:46:48 +02:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2014-05-01 01:36:13 +02:00
|
|
|
|
2016-12-04 05:08:20 +01:00
|
|
|
#include <assert.h>
|
2014-05-01 01:36:13 +02:00
|
|
|
#include <cbfs.h>
|
|
|
|
#include <cbmem.h>
|
2018-10-01 19:17:11 +02:00
|
|
|
#include <cf9_reset.h>
|
2014-05-01 01:36:13 +02:00
|
|
|
#include <console/console.h>
|
|
|
|
#include <device/pci_def.h>
|
2018-05-28 04:51:49 +02:00
|
|
|
#include <memory_info.h>
|
2017-12-15 20:26:40 +01:00
|
|
|
#include <mrc_cache.h>
|
2014-05-01 01:36:13 +02:00
|
|
|
#include <string.h>
|
2014-10-20 22:46:39 +02:00
|
|
|
#include <soc/iomap.h>
|
|
|
|
#include <soc/pei_data.h>
|
|
|
|
#include <soc/pei_wrapper.h>
|
|
|
|
#include <soc/pm.h>
|
|
|
|
#include <soc/romstage.h>
|
|
|
|
#include <soc/systemagent.h>
|
2014-05-01 01:36:13 +02:00
|
|
|
|
2021-01-20 23:09:16 +01:00
|
|
|
void save_mrc_data(struct pei_data *pei_data)
|
|
|
|
{
|
|
|
|
printk(BIOS_DEBUG, "MRC data at %p %d bytes\n", pei_data->data_to_save,
|
|
|
|
pei_data->data_to_save_size);
|
|
|
|
|
|
|
|
if (pei_data->data_to_save != NULL && pei_data->data_to_save_size > 0)
|
|
|
|
mrc_cache_stash_data(MRC_TRAINING_DATA, 0,
|
|
|
|
pei_data->data_to_save,
|
|
|
|
pei_data->data_to_save_size);
|
|
|
|
}
|
|
|
|
|
2020-10-13 23:32:55 +02:00
|
|
|
static const char *const ecc_decoder[] = {
|
|
|
|
"inactive",
|
|
|
|
"active on IO",
|
|
|
|
"disabled on IO",
|
|
|
|
"active",
|
|
|
|
};
|
|
|
|
|
2020-10-13 21:34:53 +02:00
|
|
|
/*
|
|
|
|
* Dump in the log memory controller configuration as read from the memory
|
|
|
|
* controller registers.
|
|
|
|
*/
|
|
|
|
static void report_memory_config(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2021-04-17 14:34:37 +02:00
|
|
|
const u32 addr_decoder_common = mchbar_read32(MAD_CHNL);
|
2020-10-13 21:34:53 +02:00
|
|
|
|
|
|
|
printk(BIOS_DEBUG, "memcfg DDR3 clock %d MHz\n",
|
2021-04-17 14:34:37 +02:00
|
|
|
(mchbar_read32(MC_BIOS_DATA) * 13333 * 2 + 50) / 100);
|
2020-10-13 23:01:48 +02:00
|
|
|
|
2020-10-13 21:34:53 +02:00
|
|
|
printk(BIOS_DEBUG, "memcfg channel assignment: A: %d, B % d, C % d\n",
|
2020-10-13 23:01:48 +02:00
|
|
|
(addr_decoder_common >> 0) & 3,
|
2020-10-13 21:34:53 +02:00
|
|
|
(addr_decoder_common >> 2) & 3,
|
|
|
|
(addr_decoder_common >> 4) & 3);
|
|
|
|
|
2020-10-13 23:37:07 +02:00
|
|
|
for (i = 0; i < NUM_CHANNELS; i++) {
|
2021-04-17 14:34:37 +02:00
|
|
|
const u32 ch_conf = mchbar_read32(MAD_DIMM(i));
|
2020-10-13 23:01:48 +02:00
|
|
|
|
|
|
|
printk(BIOS_DEBUG, "memcfg channel[%d] config (%8.8x):\n", i, ch_conf);
|
2020-10-13 23:32:55 +02:00
|
|
|
printk(BIOS_DEBUG, " ECC %s\n", ecc_decoder[(ch_conf >> 24) & 3]);
|
2020-10-13 21:34:53 +02:00
|
|
|
printk(BIOS_DEBUG, " enhanced interleave mode %s\n",
|
|
|
|
((ch_conf >> 22) & 1) ? "on" : "off");
|
2020-10-13 23:01:48 +02:00
|
|
|
|
2020-10-13 21:34:53 +02:00
|
|
|
printk(BIOS_DEBUG, " rank interleave %s\n",
|
|
|
|
((ch_conf >> 21) & 1) ? "on" : "off");
|
2020-10-13 23:01:48 +02:00
|
|
|
|
2020-10-13 21:34:53 +02:00
|
|
|
printk(BIOS_DEBUG, " DIMMA %d MB width %s %s rank%s\n",
|
|
|
|
((ch_conf >> 0) & 0xff) * 256,
|
|
|
|
((ch_conf >> 19) & 1) ? "x16" : "x8 or x32",
|
|
|
|
((ch_conf >> 17) & 1) ? "dual" : "single",
|
|
|
|
((ch_conf >> 16) & 1) ? "" : ", selected");
|
2020-10-13 23:01:48 +02:00
|
|
|
|
2020-10-13 21:34:53 +02:00
|
|
|
printk(BIOS_DEBUG, " DIMMB %d MB width %s %s rank%s\n",
|
|
|
|
((ch_conf >> 8) & 0xff) * 256,
|
2020-10-13 23:28:23 +02:00
|
|
|
((ch_conf >> 20) & 1) ? "x16" : "x8 or x32",
|
2020-10-13 21:34:53 +02:00
|
|
|
((ch_conf >> 18) & 1) ? "dual" : "single",
|
|
|
|
((ch_conf >> 16) & 1) ? ", selected" : "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-01 01:36:13 +02:00
|
|
|
/*
|
|
|
|
* Find PEI executable in coreboot filesystem and execute it.
|
|
|
|
*/
|
2021-01-20 23:09:16 +01:00
|
|
|
void sdram_initialize(struct pei_data *pei_data)
|
2014-05-01 01:36:13 +02:00
|
|
|
{
|
2020-07-24 01:10:52 +02:00
|
|
|
size_t mrc_size;
|
2014-05-01 01:36:13 +02:00
|
|
|
pei_wrapper_entry_t entry;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
broadwell_fill_pei_data(pei_data);
|
|
|
|
|
mrc_cache: Move code for triggering memory training into mrc_cache
Currently the decision of whether or not to use mrc_cache in recovery
mode is made within the individual platforms' drivers (ie: fsp2.0,
fsp1.1, etc.). As this is not platform specific, but uses common
vboot infrastructure, the code can be unified and moved into
mrc_cache. The conditions are as follows:
1. If HAS_RECOVERY_MRC_CACHE, use mrc_cache data (unless retrain
switch is true)
2. If !HAS_RECOVERY_MRC_CACHE && VBOOT_STARTS_IN_BOOTBLOCK, this
means that memory training will occur after verified boot,
meaning that mrc_cache will be filled with data from executing
RW code. So in this case, we never want to use the training
data in the mrc_cache for recovery mode.
3. If !HAS_RECOVERY_MRC_CACHE && VBOOT_STARTS_IN_ROMSTAGE, this
means that memory training happens before verfied boot, meaning
that the mrc_cache data is generated by RO code, so it is safe
to use for a recovery boot.
4. Any platform that does not use vboot should be unaffected.
Additionally, we have removed the
MRC_CLEAR_NORMAL_CACHE_ON_RECOVERY_RETRAIN config because the
mrc_cache driver takes care of invalidating the mrc_cache data for
normal mode. If the platform:
1. !HAS_RECOVERY_MRC_CACHE, always invalidate mrc_cache data
2. HAS_RECOVERY_MRC_CACHE, only invalidate if retrain switch is set
BUG=b:150502246
BRANCH=None
TEST=1. run dut-control power_state:rec_force_mrc twice on lazor
ensure that memory retraining happens both times
run dut-control power_state:rec twice on lazor
ensure that memory retraining happens only first time
2. remove HAS_RECOVERY_MRC_CACHE from lazor Kconfig
boot twice to ensure caching of memory training occurred
on each boot.
Change-Id: I3875a7b4a4ba3c1aa8a3c1507b3993036a7155fc
Signed-off-by: Shelley Chen <shchen@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/46855
Reviewed-by: Furquan Shaikh <furquan@google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
2020-10-27 23:58:31 +01:00
|
|
|
/* Assume boot device is memory mapped. */
|
|
|
|
assert(CONFIG(BOOT_DEVICE_MEMORY_MAPPED));
|
|
|
|
|
|
|
|
pei_data->saved_data =
|
|
|
|
mrc_cache_current_mmap_leak(MRC_TRAINING_DATA, 0,
|
|
|
|
&mrc_size);
|
|
|
|
if (pei_data->saved_data) {
|
|
|
|
/* MRC cache found */
|
|
|
|
pei_data->saved_data_size = mrc_size;
|
|
|
|
} else if (pei_data->boot_mode == ACPI_S3) {
|
|
|
|
/* Waking from S3 and no cache. */
|
|
|
|
printk(BIOS_DEBUG,
|
|
|
|
"No MRC cache found in S3 resume path.\n");
|
|
|
|
post_code(POST_RESUME_FAILURE);
|
|
|
|
system_reset();
|
2020-07-24 01:10:52 +02:00
|
|
|
} else {
|
mrc_cache: Move code for triggering memory training into mrc_cache
Currently the decision of whether or not to use mrc_cache in recovery
mode is made within the individual platforms' drivers (ie: fsp2.0,
fsp1.1, etc.). As this is not platform specific, but uses common
vboot infrastructure, the code can be unified and moved into
mrc_cache. The conditions are as follows:
1. If HAS_RECOVERY_MRC_CACHE, use mrc_cache data (unless retrain
switch is true)
2. If !HAS_RECOVERY_MRC_CACHE && VBOOT_STARTS_IN_BOOTBLOCK, this
means that memory training will occur after verified boot,
meaning that mrc_cache will be filled with data from executing
RW code. So in this case, we never want to use the training
data in the mrc_cache for recovery mode.
3. If !HAS_RECOVERY_MRC_CACHE && VBOOT_STARTS_IN_ROMSTAGE, this
means that memory training happens before verfied boot, meaning
that the mrc_cache data is generated by RO code, so it is safe
to use for a recovery boot.
4. Any platform that does not use vboot should be unaffected.
Additionally, we have removed the
MRC_CLEAR_NORMAL_CACHE_ON_RECOVERY_RETRAIN config because the
mrc_cache driver takes care of invalidating the mrc_cache data for
normal mode. If the platform:
1. !HAS_RECOVERY_MRC_CACHE, always invalidate mrc_cache data
2. HAS_RECOVERY_MRC_CACHE, only invalidate if retrain switch is set
BUG=b:150502246
BRANCH=None
TEST=1. run dut-control power_state:rec_force_mrc twice on lazor
ensure that memory retraining happens both times
run dut-control power_state:rec twice on lazor
ensure that memory retraining happens only first time
2. remove HAS_RECOVERY_MRC_CACHE from lazor Kconfig
boot twice to ensure caching of memory training occurred
on each boot.
Change-Id: I3875a7b4a4ba3c1aa8a3c1507b3993036a7155fc
Signed-off-by: Shelley Chen <shchen@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/46855
Reviewed-by: Furquan Shaikh <furquan@google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
2020-10-27 23:58:31 +01:00
|
|
|
printk(BIOS_DEBUG, "No MRC cache found.\n");
|
2014-05-01 01:36:13 +02:00
|
|
|
}
|
|
|
|
|
2014-05-05 19:42:35 +02:00
|
|
|
/*
|
|
|
|
* Do not use saved pei data. Can be set by mainboard romstage
|
|
|
|
* to force a full train of memory on every boot.
|
|
|
|
*/
|
|
|
|
if (pei_data->disable_saved_data) {
|
|
|
|
printk(BIOS_DEBUG, "Disabling PEI saved data by request\n");
|
|
|
|
pei_data->saved_data = NULL;
|
|
|
|
pei_data->saved_data_size = 0;
|
|
|
|
}
|
|
|
|
|
2018-12-22 16:11:52 +01:00
|
|
|
/* We don't care about leaking the mapping */
|
2020-01-23 03:00:18 +01:00
|
|
|
entry = cbfs_ro_map("mrc.bin", NULL);
|
|
|
|
if (entry == NULL)
|
|
|
|
die("mrc.bin not found!");
|
2014-05-01 01:36:13 +02:00
|
|
|
|
|
|
|
printk(BIOS_DEBUG, "Starting Memory Reference Code\n");
|
|
|
|
|
|
|
|
ret = entry(pei_data);
|
|
|
|
if (ret < 0)
|
|
|
|
die("pei_data version mismatch\n");
|
|
|
|
|
|
|
|
/* Print the MRC version after executing the UEFI PEI stage. */
|
2021-04-17 14:34:37 +02:00
|
|
|
u32 version = mchbar_read32(MRC_REVISION);
|
2014-05-01 01:36:13 +02:00
|
|
|
printk(BIOS_DEBUG, "MRC Version %d.%d.%d Build %d\n",
|
2020-10-13 23:01:48 +02:00
|
|
|
(version >> 24) & 0xff, (version >> 16) & 0xff,
|
|
|
|
(version >> 8) & 0xff, (version >> 0) & 0xff);
|
2014-05-01 01:36:13 +02:00
|
|
|
|
|
|
|
report_memory_config();
|
2021-01-20 23:09:16 +01:00
|
|
|
}
|
2014-05-01 01:36:13 +02:00
|
|
|
|
2021-01-20 23:09:16 +01:00
|
|
|
void setup_sdram_meminfo(struct pei_data *pei_data)
|
|
|
|
{
|
|
|
|
struct memory_info *mem_info;
|
2014-07-28 19:54:40 +02:00
|
|
|
|
|
|
|
printk(BIOS_DEBUG, "create cbmem for dimm information\n");
|
|
|
|
mem_info = cbmem_add(CBMEM_ID_MEMINFO, sizeof(struct memory_info));
|
2019-05-31 19:44:46 +02:00
|
|
|
|
|
|
|
if (!mem_info) {
|
|
|
|
printk(BIOS_ERR, "Error! Failed to add mem_info to cbmem\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-28 04:51:49 +02:00
|
|
|
memset(mem_info, 0, sizeof(*mem_info));
|
|
|
|
/* Translate pei_memory_info struct data into memory_info struct */
|
|
|
|
mem_info->dimm_cnt = pei_data->meminfo.dimm_cnt;
|
|
|
|
for (int i = 0; i < MIN(DIMM_INFO_TOTAL, PEI_DIMM_INFO_TOTAL); i++) {
|
|
|
|
struct dimm_info *dimm = &mem_info->dimm[i];
|
|
|
|
const struct pei_dimm_info *pei_dimm =
|
|
|
|
&pei_data->meminfo.dimm[i];
|
|
|
|
dimm->dimm_size = pei_dimm->dimm_size;
|
|
|
|
dimm->ddr_type = pei_dimm->ddr_type;
|
|
|
|
dimm->ddr_frequency = pei_dimm->ddr_frequency;
|
|
|
|
dimm->rank_per_dimm = pei_dimm->rank_per_dimm;
|
|
|
|
dimm->channel_num = pei_dimm->channel_num;
|
|
|
|
dimm->dimm_num = pei_dimm->dimm_num;
|
|
|
|
dimm->bank_locator = pei_dimm->bank_locator;
|
|
|
|
memcpy(&dimm->serial, &pei_dimm->serial,
|
|
|
|
MIN(sizeof(dimm->serial), sizeof(pei_dimm->serial)));
|
|
|
|
memcpy(&dimm->module_part_number,
|
|
|
|
&pei_dimm->module_part_number,
|
|
|
|
MIN(sizeof(dimm->module_part_number),
|
|
|
|
sizeof(pei_dimm->module_part_number)));
|
|
|
|
dimm->module_part_number[DIMM_INFO_PART_NUMBER_SIZE - 1] = '\0';
|
|
|
|
dimm->mod_id = pei_dimm->mod_id;
|
|
|
|
dimm->mod_type = pei_dimm->mod_type;
|
|
|
|
dimm->bus_width = pei_dimm->bus_width;
|
|
|
|
}
|
2014-05-01 01:36:13 +02:00
|
|
|
}
|