blob: edc87905d778974923f4ed88bb12e73753f42b65 [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
Aaron Durbinbd74a4b2015-03-06 23:17:33 -060032#include <stage_cache.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070033#include <vendorcode/google/chromeos/chromeos.h>
34#include <soc/intel/common/mrc_cache.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070035#include <soc/iomap.h>
36#include <soc/pei_data.h>
37#include <soc/pei_wrapper.h>
38#include <soc/pm.h>
39#include <soc/reset.h>
40#include <soc/romstage.h>
41#include <soc/smm.h>
42#include <soc/systemagent.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070043
44/*
45 * Find PEI executable in coreboot filesystem and execute it.
46 */
47void raminit(struct pei_data *pei_data)
48{
49 const struct mrc_saved_data *cache;
Kane Chenebbb0d42014-07-28 10:54:40 -070050 struct memory_info* mem_info;
Duncan Lauriec88c54c2014-04-30 16:36:13 -070051 pei_wrapper_entry_t entry;
52 int ret;
53
54 broadwell_fill_pei_data(pei_data);
55
56 if (recovery_mode_enabled()) {
57 /* Recovery mode does not use MRC cache */
58 printk(BIOS_DEBUG, "Recovery mode: not using MRC cache.\n");
59 } else if (!mrc_cache_get_current(&cache)) {
60 /* MRC cache found */
61 pei_data->saved_data_size = cache->size;
62 pei_data->saved_data = &cache->data[0];
63 } else if (pei_data->boot_mode == SLEEP_STATE_S3) {
64 /* Waking from S3 and no cache. */
65 printk(BIOS_DEBUG, "No MRC cache found in S3 resume path.\n");
66 post_code(POST_RESUME_FAILURE);
67 reset_system();
68 } else {
69 printk(BIOS_DEBUG, "No MRC cache found.\n");
70#if CONFIG_EC_GOOGLE_CHROMEEC
71 if (pei_data->boot_mode == SLEEP_STATE_S0) {
72 /* Ensure EC is running RO firmware. */
73 google_chromeec_check_ec_image(EC_IMAGE_RO);
74 }
75#endif
76 }
77
Duncan Laurie61680272014-05-05 12:42:35 -050078 /*
79 * Do not use saved pei data. Can be set by mainboard romstage
80 * to force a full train of memory on every boot.
81 */
82 if (pei_data->disable_saved_data) {
83 printk(BIOS_DEBUG, "Disabling PEI saved data by request\n");
84 pei_data->saved_data = NULL;
85 pei_data->saved_data_size = 0;
86 }
87
Duncan Lauriec88c54c2014-04-30 16:36:13 -070088 /* Determine if mrc.bin is in the cbfs. */
Aaron Durbin899d13d2015-05-15 23:39:23 -050089 entry = cbfs_boot_map_with_leak("mrc.bin", CBFS_TYPE_MRC, NULL);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070090 if (entry == NULL) {
91 printk(BIOS_DEBUG, "Couldn't find mrc.bin\n");
92 return;
93 }
94
95 printk(BIOS_DEBUG, "Starting Memory Reference Code\n");
96
97 ret = entry(pei_data);
98 if (ret < 0)
99 die("pei_data version mismatch\n");
100
101 /* Print the MRC version after executing the UEFI PEI stage. */
102 u32 version = MCHBAR32(MCHBAR_PEI_VERSION);
103 printk(BIOS_DEBUG, "MRC Version %d.%d.%d Build %d\n",
104 version >> 24 , (version >> 16) & 0xff,
105 (version >> 8) & 0xff, version & 0xff);
106
107 report_memory_config();
108
Duncan Laurie61680272014-05-05 12:42:35 -0500109 /* Basic memory sanity test */
110 quick_ram_check();
111
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700112 if (pei_data->boot_mode != SLEEP_STATE_S3) {
113 cbmem_initialize_empty();
Aaron Durbinbd74a4b2015-03-06 23:17:33 -0600114 stage_cache_create_empty();
115 } else {
116 stage_cache_recover();
117 if (cbmem_initialize()) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700118#if CONFIG_HAVE_ACPI_RESUME
Aaron Durbinbd74a4b2015-03-06 23:17:33 -0600119 printk(BIOS_DEBUG, "Failed to recover CBMEM in S3 resume.\n");
120 /* Failed S3 resume, reset to come up cleanly */
121 reset_system();
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700122#endif
Aaron Durbinbd74a4b2015-03-06 23:17:33 -0600123 }
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700124 }
125
126 printk(BIOS_DEBUG, "MRC data at %p %d bytes\n", pei_data->data_to_save,
127 pei_data->data_to_save_size);
128
129 if (pei_data->data_to_save != NULL && pei_data->data_to_save_size > 0)
130 mrc_cache_stash_data(pei_data->data_to_save,
131 pei_data->data_to_save_size);
Kane Chenebbb0d42014-07-28 10:54:40 -0700132
133 printk(BIOS_DEBUG, "create cbmem for dimm information\n");
134 mem_info = cbmem_add(CBMEM_ID_MEMINFO, sizeof(struct memory_info));
135 memcpy(mem_info, &pei_data->meminfo, sizeof(struct memory_info));
136
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700137}