2013-10-24 17:21:43 +02:00
|
|
|
/*
|
|
|
|
* This file is part of the coreboot project.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
2013-12-12 19:29:48 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include <arch/acpi.h>
|
2013-10-24 17:21:43 +02:00
|
|
|
#include <cbmem.h>
|
|
|
|
#include <console/console.h>
|
2015-03-28 02:53:30 +01:00
|
|
|
#include <console/streams.h>
|
2013-10-28 15:54:22 +01:00
|
|
|
#include <cpu/x86/tsc.h>
|
2015-03-28 03:17:22 +01:00
|
|
|
#include <program_loading.h>
|
2013-10-24 17:21:43 +02:00
|
|
|
#include <rmodule.h>
|
2015-03-07 06:17:33 +01:00
|
|
|
#include <stage_cache.h>
|
2013-10-24 17:21:43 +02:00
|
|
|
|
2014-10-08 01:42:17 +02:00
|
|
|
#include <soc/ramstage.h>
|
|
|
|
#include <soc/efi_wrapper.h>
|
2013-10-24 17:21:43 +02:00
|
|
|
|
|
|
|
static void ABI_X86 send_to_console(unsigned char b)
|
|
|
|
{
|
|
|
|
console_tx_byte(b);
|
|
|
|
}
|
|
|
|
|
2013-12-12 19:29:48 +01:00
|
|
|
static efi_wrapper_entry_t load_refcode_from_cache(void)
|
|
|
|
{
|
2015-03-07 06:17:33 +01:00
|
|
|
struct prog refcode;
|
2013-12-12 19:29:48 +01:00
|
|
|
|
|
|
|
printk(BIOS_DEBUG, "refcode loading from cache.\n");
|
|
|
|
|
2015-03-07 06:17:33 +01:00
|
|
|
stage_cache_load_stage(STAGE_REFCODE, &refcode);
|
2013-12-12 19:29:48 +01:00
|
|
|
|
2015-03-07 06:17:33 +01:00
|
|
|
return (efi_wrapper_entry_t)prog_entry(&refcode);
|
2013-12-12 19:29:48 +01:00
|
|
|
}
|
|
|
|
|
2013-12-13 22:05:24 +01:00
|
|
|
static efi_wrapper_entry_t load_reference_code(void)
|
|
|
|
{
|
2015-05-20 19:08:55 +02:00
|
|
|
struct prog prog =
|
|
|
|
PROG_INIT(ASSET_REFCODE, CONFIG_CBFS_PREFIX "/refcode");
|
2013-12-12 19:29:48 +01:00
|
|
|
struct rmod_stage_load refcode = {
|
|
|
|
.cbmem_id = CBMEM_ID_REFCODE,
|
2015-03-28 03:17:22 +01:00
|
|
|
.prog = &prog,
|
2013-12-12 19:29:48 +01:00
|
|
|
};
|
|
|
|
|
2014-06-19 18:50:51 +02:00
|
|
|
if (acpi_is_wakeup_s3()) {
|
2013-12-13 22:05:24 +01:00
|
|
|
return load_refcode_from_cache();
|
|
|
|
}
|
2013-12-12 19:29:48 +01:00
|
|
|
|
2015-05-16 06:39:23 +02:00
|
|
|
if (prog_locate(&prog)) {
|
|
|
|
printk(BIOS_DEBUG, "Couldn't locate reference code.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rmodule_stage_load(&refcode)) {
|
|
|
|
printk(BIOS_DEBUG, "Error loading reference code.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-12-13 22:05:24 +01:00
|
|
|
|
|
|
|
/* Cache loaded reference code. */
|
2015-05-16 06:39:23 +02:00
|
|
|
stage_cache_add(STAGE_REFCODE, &prog);
|
2013-12-12 19:29:48 +01:00
|
|
|
|
2015-03-28 03:17:22 +01:00
|
|
|
return prog_entry(&prog);
|
2013-12-12 19:29:48 +01:00
|
|
|
}
|
|
|
|
|
2013-10-24 17:21:43 +02:00
|
|
|
void baytrail_run_reference_code(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
efi_wrapper_entry_t entry;
|
|
|
|
struct efi_wrapper_params wrp = {
|
|
|
|
.version = EFI_WRAPPER_VER,
|
|
|
|
.console_out = send_to_console,
|
|
|
|
};
|
|
|
|
|
2013-12-13 22:05:24 +01:00
|
|
|
entry = load_reference_code();
|
2013-10-24 17:21:43 +02:00
|
|
|
|
2013-12-12 19:29:48 +01:00
|
|
|
if (entry == NULL)
|
|
|
|
return;
|
|
|
|
|
2013-10-28 15:54:22 +01:00
|
|
|
wrp.tsc_ticks_per_microsecond = tsc_freq_mhz();
|
2013-10-24 17:21:43 +02:00
|
|
|
|
|
|
|
/* Call into reference code. */
|
|
|
|
ret = entry(&wrp);
|
|
|
|
|
|
|
|
if (ret != 0) {
|
|
|
|
printk(BIOS_DEBUG, "Reference code returned %d\n", ret);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|