blob: 7217bb9539c582f1086e2681812b7f387302767b [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.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <arch/cbfs.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070021#include <arch/io.h>
22#include <cbfs.h>
23#include <cbmem.h>
24#include <console/console.h>
25#include <device/pci_def.h>
Duncan Laurie61680272014-05-05 12:42:35 -050026#include <lib.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070027#include <string.h>
28#if CONFIG_EC_GOOGLE_CHROMEEC
29#include <ec/google/chromeec/ec.h>
30#include <ec/google/chromeec/ec_commands.h>
31#endif
32#include <vendorcode/google/chromeos/chromeos.h>
33#include <soc/intel/common/mrc_cache.h>
34#include <broadwell/iomap.h>
35#include <broadwell/pei_data.h>
36#include <broadwell/pei_wrapper.h>
37#include <broadwell/pm.h>
38#include <broadwell/reset.h>
39#include <broadwell/romstage.h>
40#include <broadwell/smm.h>
41#include <broadwell/systemagent.h>
42
43/*
44 * Find PEI executable in coreboot filesystem and execute it.
45 */
46void raminit(struct pei_data *pei_data)
47{
48 const struct mrc_saved_data *cache;
49 pei_wrapper_entry_t entry;
50 int ret;
51
52 broadwell_fill_pei_data(pei_data);
53
54 if (recovery_mode_enabled()) {
55 /* Recovery mode does not use MRC cache */
56 printk(BIOS_DEBUG, "Recovery mode: not using MRC cache.\n");
57 } else if (!mrc_cache_get_current(&cache)) {
58 /* MRC cache found */
59 pei_data->saved_data_size = cache->size;
60 pei_data->saved_data = &cache->data[0];
61 } else if (pei_data->boot_mode == SLEEP_STATE_S3) {
62 /* 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");
68#if CONFIG_EC_GOOGLE_CHROMEEC
69 if (pei_data->boot_mode == SLEEP_STATE_S0) {
70 /* 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. */
87 entry = (pei_wrapper_entry_t)cbfs_get_file_content(
Marc Jonesa6354a12014-12-26 22:11:14 -070088 CBFS_DEFAULT_MEDIA, "mrc.bin", 0xab, NULL);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070089 if (entry == NULL) {
90 printk(BIOS_DEBUG, "Couldn't find mrc.bin\n");
91 return;
92 }
93
94 printk(BIOS_DEBUG, "Starting Memory Reference Code\n");
95
96 ret = entry(pei_data);
97 if (ret < 0)
98 die("pei_data version mismatch\n");
99
100 /* Print the MRC version after executing the UEFI PEI stage. */
101 u32 version = MCHBAR32(MCHBAR_PEI_VERSION);
102 printk(BIOS_DEBUG, "MRC Version %d.%d.%d Build %d\n",
103 version >> 24 , (version >> 16) & 0xff,
104 (version >> 8) & 0xff, version & 0xff);
105
106 report_memory_config();
107
Duncan Laurie61680272014-05-05 12:42:35 -0500108 /* Basic memory sanity test */
109 quick_ram_check();
110
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700111 if (pei_data->boot_mode != SLEEP_STATE_S3) {
112 cbmem_initialize_empty();
113 } else if (cbmem_initialize()) {
114#if CONFIG_HAVE_ACPI_RESUME
115 printk(BIOS_DEBUG, "Failed to recover CBMEM in S3 resume.\n");
116 /* Failed S3 resume, reset to come up cleanly */
117 reset_system();
118#endif
119 }
120
121 printk(BIOS_DEBUG, "MRC data at %p %d bytes\n", pei_data->data_to_save,
122 pei_data->data_to_save_size);
123
124 if (pei_data->data_to_save != NULL && pei_data->data_to_save_size > 0)
125 mrc_cache_stash_data(pei_data->data_to_save,
126 pei_data->data_to_save_size);
127}