blob: 82c88cb89319692fd7b81ad65c124efe40b0000e [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
Patrick Georgib890a122015-03-26 15:17:45 +010017 * Foundation, Inc.
Duncan Lauriec88c54c2014-04-30 16:36:13 -070018 */
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>
Julius Werner4ee4bd52014-10-20 13:46:39 -070034#include <soc/iomap.h>
35#include <soc/pei_data.h>
36#include <soc/pei_wrapper.h>
37#include <soc/pm.h>
38#include <soc/reset.h>
39#include <soc/romstage.h>
40#include <soc/smm.h>
41#include <soc/systemagent.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070042
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;
Kane Chenebbb0d42014-07-28 10:54:40 -070049 struct memory_info* mem_info;
Duncan Lauriec88c54c2014-04-30 16:36:13 -070050 pei_wrapper_entry_t entry;
51 int ret;
52
53 broadwell_fill_pei_data(pei_data);
54
55 if (recovery_mode_enabled()) {
56 /* Recovery mode does not use MRC cache */
57 printk(BIOS_DEBUG, "Recovery mode: not using MRC cache.\n");
58 } else if (!mrc_cache_get_current(&cache)) {
59 /* MRC cache found */
60 pei_data->saved_data_size = cache->size;
61 pei_data->saved_data = &cache->data[0];
62 } else if (pei_data->boot_mode == SLEEP_STATE_S3) {
63 /* Waking from S3 and no cache. */
64 printk(BIOS_DEBUG, "No MRC cache found in S3 resume path.\n");
65 post_code(POST_RESUME_FAILURE);
66 reset_system();
67 } else {
68 printk(BIOS_DEBUG, "No MRC cache found.\n");
69#if CONFIG_EC_GOOGLE_CHROMEEC
70 if (pei_data->boot_mode == SLEEP_STATE_S0) {
71 /* Ensure EC is running RO firmware. */
72 google_chromeec_check_ec_image(EC_IMAGE_RO);
73 }
74#endif
75 }
76
Duncan Laurie61680272014-05-05 12:42:35 -050077 /*
78 * Do not use saved pei data. Can be set by mainboard romstage
79 * to force a full train of memory on every boot.
80 */
81 if (pei_data->disable_saved_data) {
82 printk(BIOS_DEBUG, "Disabling PEI saved data by request\n");
83 pei_data->saved_data = NULL;
84 pei_data->saved_data_size = 0;
85 }
86
Duncan Lauriec88c54c2014-04-30 16:36:13 -070087 /* Determine if mrc.bin is in the cbfs. */
Aaron Durbin899d13d2015-05-15 23:39:23 -050088 entry = cbfs_boot_map_with_leak("mrc.bin", CBFS_TYPE_MRC, 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();
Aaron Durbin42e68562015-06-09 13:55:51 -0500113 } else if (cbmem_initialize()) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700114#if CONFIG_HAVE_ACPI_RESUME
Aaron Durbin42e68562015-06-09 13:55:51 -0500115 printk(BIOS_DEBUG, "Failed to recover CBMEM in S3 resume.\n");
116 /* Failed S3 resume, reset to come up cleanly */
117 reset_system();
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700118#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);
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}