blob: 0c49a800a618accbdcab6a1afa16f27c5039a7d2 [file] [log] [blame]
Aaron Durbinae5d83e2013-10-24 10:21:43 -05001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2013 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.
Aaron Durbinae5d83e2013-10-24 10:21:43 -050018 */
19
Aaron Durbin63fcb4a2013-12-12 10:29:48 -080020#include <string.h>
21#include <arch/acpi.h>
Aaron Durbinae5d83e2013-10-24 10:21:43 -050022#include <cbmem.h>
23#include <console/console.h>
Aaron Durbin43b7db72015-03-27 20:53:30 -050024#include <console/streams.h>
Aaron Durbin8fa62832013-10-28 09:54:22 -050025#include <cpu/x86/tsc.h>
Aaron Durbin460703b2015-03-27 21:17:22 -050026#include <program_loading.h>
Aaron Durbinae5d83e2013-10-24 10:21:43 -050027#include <rmodule.h>
Aaron Durbinbd74a4b2015-03-06 23:17:33 -060028#include <stage_cache.h>
Aaron Durbinae5d83e2013-10-24 10:21:43 -050029
Julius Werner18ea2d32014-10-07 16:42:17 -070030#include <soc/ramstage.h>
31#include <soc/efi_wrapper.h>
Aaron Durbinae5d83e2013-10-24 10:21:43 -050032
33static void ABI_X86 send_to_console(unsigned char b)
34{
35 console_tx_byte(b);
36}
37
Aaron Durbin63fcb4a2013-12-12 10:29:48 -080038static efi_wrapper_entry_t load_refcode_from_cache(void)
39{
Aaron Durbinbd74a4b2015-03-06 23:17:33 -060040 struct prog refcode;
Aaron Durbin63fcb4a2013-12-12 10:29:48 -080041
42 printk(BIOS_DEBUG, "refcode loading from cache.\n");
43
Aaron Durbinbd74a4b2015-03-06 23:17:33 -060044 stage_cache_load_stage(STAGE_REFCODE, &refcode);
Aaron Durbin63fcb4a2013-12-12 10:29:48 -080045
Aaron Durbinbd74a4b2015-03-06 23:17:33 -060046 return (efi_wrapper_entry_t)prog_entry(&refcode);
Aaron Durbin63fcb4a2013-12-12 10:29:48 -080047}
48
Aaron Durbin7f177592013-12-13 13:05:24 -080049static efi_wrapper_entry_t load_reference_code(void)
50{
Aaron Durbin460703b2015-03-27 21:17:22 -050051 struct prog prog = {
Aaron Durbin899d13d2015-05-15 23:39:23 -050052 .type = PROG_REFCODE,
Aaron Durbin460703b2015-03-27 21:17:22 -050053 .name = CONFIG_CBFS_PREFIX "/refcode",
54 };
Aaron Durbin63fcb4a2013-12-12 10:29:48 -080055 struct rmod_stage_load refcode = {
56 .cbmem_id = CBMEM_ID_REFCODE,
Aaron Durbin460703b2015-03-27 21:17:22 -050057 .prog = &prog,
Aaron Durbin63fcb4a2013-12-12 10:29:48 -080058 };
59
Kyösti Mälkkic3ed8862014-06-19 19:50:51 +030060 if (acpi_is_wakeup_s3()) {
Aaron Durbin7f177592013-12-13 13:05:24 -080061 return load_refcode_from_cache();
Aaron Durbin63fcb4a2013-12-12 10:29:48 -080062 }
63
Aaron Durbin899d13d2015-05-15 23:39:23 -050064 if (prog_locate(&prog)) {
65 printk(BIOS_DEBUG, "Couldn't locate reference code.\n");
66 return NULL;
67 }
68
69 if (rmodule_stage_load(&refcode)) {
70 printk(BIOS_DEBUG, "Error loading reference code.\n");
71 return NULL;
72 }
Aaron Durbin7f177592013-12-13 13:05:24 -080073
74 /* Cache loaded reference code. */
Aaron Durbin899d13d2015-05-15 23:39:23 -050075 stage_cache_add(STAGE_REFCODE, &prog);
Aaron Durbin63fcb4a2013-12-12 10:29:48 -080076
Aaron Durbin460703b2015-03-27 21:17:22 -050077 return prog_entry(&prog);
Aaron Durbin63fcb4a2013-12-12 10:29:48 -080078}
79
Aaron Durbinae5d83e2013-10-24 10:21:43 -050080void baytrail_run_reference_code(void)
81{
82 int ret;
83 efi_wrapper_entry_t entry;
84 struct efi_wrapper_params wrp = {
85 .version = EFI_WRAPPER_VER,
86 .console_out = send_to_console,
87 };
Aaron Durbinae5d83e2013-10-24 10:21:43 -050088
Aaron Durbin7f177592013-12-13 13:05:24 -080089 entry = load_reference_code();
Aaron Durbinae5d83e2013-10-24 10:21:43 -050090
Aaron Durbin63fcb4a2013-12-12 10:29:48 -080091 if (entry == NULL)
92 return;
93
Aaron Durbin8fa62832013-10-28 09:54:22 -050094 wrp.tsc_ticks_per_microsecond = tsc_freq_mhz();
Aaron Durbinae5d83e2013-10-24 10:21:43 -050095
96 /* Call into reference code. */
97 ret = entry(&wrp);
98
99 if (ret != 0) {
100 printk(BIOS_DEBUG, "Reference code returned %d\n", ret);
101 return;
102 }
103}