blob: 488b231a96bfe730b79842e0dc266554070899a8 [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>
18#include <cbfs.h>
19#include <cbmem.h>
20#include <console/console.h>
21#include <device/pci_def.h>
Duncan Laurie61680272014-05-05 12:42:35 -050022#include <lib.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070023#include <string.h>
24#if CONFIG_EC_GOOGLE_CHROMEEC
25#include <ec/google/chromeec/ec.h>
26#include <ec/google/chromeec/ec_commands.h>
27#endif
28#include <vendorcode/google/chromeos/chromeos.h>
29#include <soc/intel/common/mrc_cache.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070030#include <soc/iomap.h>
31#include <soc/pei_data.h>
32#include <soc/pei_wrapper.h>
33#include <soc/pm.h>
34#include <soc/reset.h>
35#include <soc/romstage.h>
36#include <soc/smm.h>
37#include <soc/systemagent.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070038
39/*
40 * Find PEI executable in coreboot filesystem and execute it.
41 */
42void raminit(struct pei_data *pei_data)
43{
44 const struct mrc_saved_data *cache;
Kane Chenebbb0d42014-07-28 10:54:40 -070045 struct memory_info* mem_info;
Duncan Lauriec88c54c2014-04-30 16:36:13 -070046 pei_wrapper_entry_t entry;
47 int ret;
48
49 broadwell_fill_pei_data(pei_data);
50
51 if (recovery_mode_enabled()) {
52 /* Recovery mode does not use MRC cache */
53 printk(BIOS_DEBUG, "Recovery mode: not using MRC cache.\n");
54 } else if (!mrc_cache_get_current(&cache)) {
55 /* MRC cache found */
56 pei_data->saved_data_size = cache->size;
57 pei_data->saved_data = &cache->data[0];
Aaron Durbin9e6d1432016-07-13 23:21:41 -050058 } else if (pei_data->boot_mode == ACPI_S3) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -070059 /* Waking from S3 and no cache. */
60 printk(BIOS_DEBUG, "No MRC cache found in S3 resume path.\n");
61 post_code(POST_RESUME_FAILURE);
62 reset_system();
63 } else {
64 printk(BIOS_DEBUG, "No MRC cache found.\n");
65#if CONFIG_EC_GOOGLE_CHROMEEC
Aaron Durbin9e6d1432016-07-13 23:21:41 -050066 if (pei_data->boot_mode == ACPI_S0) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -070067 /* Ensure EC is running RO firmware. */
68 google_chromeec_check_ec_image(EC_IMAGE_RO);
69 }
70#endif
71 }
72
Duncan Laurie61680272014-05-05 12:42:35 -050073 /*
74 * Do not use saved pei data. Can be set by mainboard romstage
75 * to force a full train of memory on every boot.
76 */
77 if (pei_data->disable_saved_data) {
78 printk(BIOS_DEBUG, "Disabling PEI saved data by request\n");
79 pei_data->saved_data = NULL;
80 pei_data->saved_data_size = 0;
81 }
82
Duncan Lauriec88c54c2014-04-30 16:36:13 -070083 /* Determine if mrc.bin is in the cbfs. */
Aaron Durbin899d13d2015-05-15 23:39:23 -050084 entry = cbfs_boot_map_with_leak("mrc.bin", CBFS_TYPE_MRC, NULL);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070085 if (entry == NULL) {
86 printk(BIOS_DEBUG, "Couldn't find mrc.bin\n");
87 return;
88 }
89
90 printk(BIOS_DEBUG, "Starting Memory Reference Code\n");
91
92 ret = entry(pei_data);
93 if (ret < 0)
94 die("pei_data version mismatch\n");
95
96 /* Print the MRC version after executing the UEFI PEI stage. */
97 u32 version = MCHBAR32(MCHBAR_PEI_VERSION);
98 printk(BIOS_DEBUG, "MRC Version %d.%d.%d Build %d\n",
99 version >> 24 , (version >> 16) & 0xff,
100 (version >> 8) & 0xff, version & 0xff);
101
102 report_memory_config();
103
Duncan Laurie61680272014-05-05 12:42:35 -0500104 /* Basic memory sanity test */
105 quick_ram_check();
106
Aaron Durbin9e6d1432016-07-13 23:21:41 -0500107 if (pei_data->boot_mode != ACPI_S3) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700108 cbmem_initialize_empty();
Aaron Durbin42e68562015-06-09 13:55:51 -0500109 } else if (cbmem_initialize()) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700110#if CONFIG_HAVE_ACPI_RESUME
Aaron Durbin42e68562015-06-09 13:55:51 -0500111 printk(BIOS_DEBUG, "Failed to recover CBMEM in S3 resume.\n");
112 /* Failed S3 resume, reset to come up cleanly */
113 reset_system();
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700114#endif
115 }
116
117 printk(BIOS_DEBUG, "MRC data at %p %d bytes\n", pei_data->data_to_save,
118 pei_data->data_to_save_size);
119
120 if (pei_data->data_to_save != NULL && pei_data->data_to_save_size > 0)
121 mrc_cache_stash_data(pei_data->data_to_save,
122 pei_data->data_to_save_size);
Kane Chenebbb0d42014-07-28 10:54:40 -0700123
124 printk(BIOS_DEBUG, "create cbmem for dimm information\n");
125 mem_info = cbmem_add(CBMEM_ID_MEMINFO, sizeof(struct memory_info));
126 memcpy(mem_info, &pei_data->meminfo, sizeof(struct memory_info));
127
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700128}