blob: 34ab39cad7bdfe19ef1272353e007c5702bd3819 [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>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070017#include <arch/io.h>
Aaron Durbin31be2c92016-12-03 22:08:20 -060018#include <assert.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070019#include <cbfs.h>
20#include <cbmem.h>
21#include <console/console.h>
22#include <device/pci_def.h>
Duncan Laurie61680272014-05-05 12:42:35 -050023#include <lib.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070024#include <string.h>
Martin Rothe6ff1592017-06-24 21:34:29 -060025#if IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC)
Duncan Lauriec88c54c2014-04-30 16:36:13 -070026#include <ec/google/chromeec/ec.h>
27#include <ec/google/chromeec/ec_commands.h>
28#endif
29#include <vendorcode/google/chromeos/chromeos.h>
30#include <soc/intel/common/mrc_cache.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>
35#include <soc/reset.h>
36#include <soc/romstage.h>
37#include <soc/smm.h>
38#include <soc/systemagent.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070039
40/*
41 * Find PEI executable in coreboot filesystem and execute it.
42 */
43void raminit(struct pei_data *pei_data)
44{
Aaron Durbin31be2c92016-12-03 22:08:20 -060045 struct region_device rdev;
Lee Leahy26b7cd02017-03-16 18:47:55 -070046 struct memory_info *mem_info;
Duncan Lauriec88c54c2014-04-30 16:36:13 -070047 pei_wrapper_entry_t entry;
48 int ret;
49
50 broadwell_fill_pei_data(pei_data);
51
Furquan Shaikh0325dc62016-07-25 13:02:36 -070052 if (vboot_recovery_mode_enabled()) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -070053 /* Recovery mode does not use MRC cache */
54 printk(BIOS_DEBUG, "Recovery mode: not using MRC cache.\n");
Aaron Durbin31be2c92016-12-03 22:08:20 -060055 } else if (!mrc_cache_get_current(MRC_TRAINING_DATA, 0, &rdev)) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -070056 /* MRC cache found */
Aaron Durbin31be2c92016-12-03 22:08:20 -060057 pei_data->saved_data_size = region_device_sz(&rdev);
58 pei_data->saved_data = rdev_mmap_full(&rdev);
59 /* Assume boot device is memory mapped. */
60 assert(IS_ENABLED(CONFIG_BOOT_DEVICE_MEMORY_MAPPED));
Aaron Durbin9e6d1432016-07-13 23:21:41 -050061 } else if (pei_data->boot_mode == ACPI_S3) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -070062 /* Waking from S3 and no cache. */
63 printk(BIOS_DEBUG, "No MRC cache found in S3 resume path.\n");
64 post_code(POST_RESUME_FAILURE);
65 reset_system();
66 } else {
67 printk(BIOS_DEBUG, "No MRC cache found.\n");
Martin Rothe6ff1592017-06-24 21:34:29 -060068#if IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC)
Aaron Durbin9e6d1432016-07-13 23:21:41 -050069 if (pei_data->boot_mode == ACPI_S0) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -070070 /* Ensure EC is running RO firmware. */
71 google_chromeec_check_ec_image(EC_IMAGE_RO);
72 }
73#endif
74 }
75
Duncan Laurie61680272014-05-05 12:42:35 -050076 /*
77 * Do not use saved pei data. Can be set by mainboard romstage
78 * to force a full train of memory on every boot.
79 */
80 if (pei_data->disable_saved_data) {
81 printk(BIOS_DEBUG, "Disabling PEI saved data by request\n");
82 pei_data->saved_data = NULL;
83 pei_data->saved_data_size = 0;
84 }
85
Duncan Lauriec88c54c2014-04-30 16:36:13 -070086 /* Determine if mrc.bin is in the cbfs. */
Aaron Durbin899d13d2015-05-15 23:39:23 -050087 entry = cbfs_boot_map_with_leak("mrc.bin", CBFS_TYPE_MRC, NULL);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070088 if (entry == NULL) {
89 printk(BIOS_DEBUG, "Couldn't find mrc.bin\n");
90 return;
91 }
92
93 printk(BIOS_DEBUG, "Starting Memory Reference Code\n");
94
95 ret = entry(pei_data);
96 if (ret < 0)
97 die("pei_data version mismatch\n");
98
99 /* Print the MRC version after executing the UEFI PEI stage. */
100 u32 version = MCHBAR32(MCHBAR_PEI_VERSION);
101 printk(BIOS_DEBUG, "MRC Version %d.%d.%d Build %d\n",
Lee Leahy26b7cd02017-03-16 18:47:55 -0700102 version >> 24, (version >> 16) & 0xff,
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700103 (version >> 8) & 0xff, version & 0xff);
104
105 report_memory_config();
106
Duncan Laurie61680272014-05-05 12:42:35 -0500107 /* Basic memory sanity test */
108 quick_ram_check();
109
Aaron Durbin9e6d1432016-07-13 23:21:41 -0500110 if (pei_data->boot_mode != ACPI_S3) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700111 cbmem_initialize_empty();
Aaron Durbin42e68562015-06-09 13:55:51 -0500112 } else if (cbmem_initialize()) {
Martin Rothe6ff1592017-06-24 21:34:29 -0600113#if IS_ENABLED(CONFIG_HAVE_ACPI_RESUME)
Aaron Durbin42e68562015-06-09 13:55:51 -0500114 printk(BIOS_DEBUG, "Failed to recover CBMEM in S3 resume.\n");
115 /* Failed S3 resume, reset to come up cleanly */
116 reset_system();
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700117#endif
118 }
119
120 printk(BIOS_DEBUG, "MRC data at %p %d bytes\n", pei_data->data_to_save,
121 pei_data->data_to_save_size);
122
123 if (pei_data->data_to_save != NULL && pei_data->data_to_save_size > 0)
Aaron Durbin31be2c92016-12-03 22:08:20 -0600124 mrc_cache_stash_data(MRC_TRAINING_DATA, 0,
125 pei_data->data_to_save,
126 pei_data->data_to_save_size);
Kane Chenebbb0d42014-07-28 10:54:40 -0700127
128 printk(BIOS_DEBUG, "create cbmem for dimm information\n");
129 mem_info = cbmem_add(CBMEM_ID_MEMINFO, sizeof(struct memory_info));
130 memcpy(mem_info, &pei_data->meminfo, sizeof(struct memory_info));
131
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700132}