Aaron Durbin | ae5d83e | 2013-10-24 10:21:43 -0500 | [diff] [blame] | 1 | /* |
| 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 Georgi | b890a12 | 2015-03-26 15:17:45 +0100 | [diff] [blame] | 17 | * Foundation, Inc. |
Aaron Durbin | ae5d83e | 2013-10-24 10:21:43 -0500 | [diff] [blame] | 18 | */ |
| 19 | |
Aaron Durbin | 63fcb4a | 2013-12-12 10:29:48 -0800 | [diff] [blame] | 20 | #include <string.h> |
| 21 | #include <arch/acpi.h> |
Aaron Durbin | ae5d83e | 2013-10-24 10:21:43 -0500 | [diff] [blame] | 22 | #include <cbmem.h> |
| 23 | #include <console/console.h> |
Aaron Durbin | 43b7db7 | 2015-03-27 20:53:30 -0500 | [diff] [blame] | 24 | #include <console/streams.h> |
Aaron Durbin | 8fa6283 | 2013-10-28 09:54:22 -0500 | [diff] [blame] | 25 | #include <cpu/x86/tsc.h> |
Aaron Durbin | 460703b | 2015-03-27 21:17:22 -0500 | [diff] [blame] | 26 | #include <program_loading.h> |
Aaron Durbin | ae5d83e | 2013-10-24 10:21:43 -0500 | [diff] [blame] | 27 | #include <rmodule.h> |
Aaron Durbin | bd74a4b | 2015-03-06 23:17:33 -0600 | [diff] [blame] | 28 | #include <stage_cache.h> |
Aaron Durbin | ae5d83e | 2013-10-24 10:21:43 -0500 | [diff] [blame] | 29 | |
Julius Werner | 18ea2d3 | 2014-10-07 16:42:17 -0700 | [diff] [blame] | 30 | #include <soc/ramstage.h> |
| 31 | #include <soc/efi_wrapper.h> |
Aaron Durbin | ae5d83e | 2013-10-24 10:21:43 -0500 | [diff] [blame] | 32 | |
| 33 | static void ABI_X86 send_to_console(unsigned char b) |
| 34 | { |
| 35 | console_tx_byte(b); |
| 36 | } |
| 37 | |
Aaron Durbin | 63fcb4a | 2013-12-12 10:29:48 -0800 | [diff] [blame] | 38 | static efi_wrapper_entry_t load_refcode_from_cache(void) |
| 39 | { |
Aaron Durbin | bd74a4b | 2015-03-06 23:17:33 -0600 | [diff] [blame] | 40 | struct prog refcode; |
Aaron Durbin | 63fcb4a | 2013-12-12 10:29:48 -0800 | [diff] [blame] | 41 | |
| 42 | printk(BIOS_DEBUG, "refcode loading from cache.\n"); |
| 43 | |
Aaron Durbin | bd74a4b | 2015-03-06 23:17:33 -0600 | [diff] [blame] | 44 | stage_cache_load_stage(STAGE_REFCODE, &refcode); |
Aaron Durbin | 63fcb4a | 2013-12-12 10:29:48 -0800 | [diff] [blame] | 45 | |
Aaron Durbin | bd74a4b | 2015-03-06 23:17:33 -0600 | [diff] [blame] | 46 | return (efi_wrapper_entry_t)prog_entry(&refcode); |
Aaron Durbin | 63fcb4a | 2013-12-12 10:29:48 -0800 | [diff] [blame] | 47 | } |
| 48 | |
Aaron Durbin | 7f17759 | 2013-12-13 13:05:24 -0800 | [diff] [blame] | 49 | static efi_wrapper_entry_t load_reference_code(void) |
| 50 | { |
Aaron Durbin | 460703b | 2015-03-27 21:17:22 -0500 | [diff] [blame] | 51 | struct prog prog = { |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame^] | 52 | .type = PROG_REFCODE, |
Aaron Durbin | 460703b | 2015-03-27 21:17:22 -0500 | [diff] [blame] | 53 | .name = CONFIG_CBFS_PREFIX "/refcode", |
| 54 | }; |
Aaron Durbin | 63fcb4a | 2013-12-12 10:29:48 -0800 | [diff] [blame] | 55 | struct rmod_stage_load refcode = { |
| 56 | .cbmem_id = CBMEM_ID_REFCODE, |
Aaron Durbin | 460703b | 2015-03-27 21:17:22 -0500 | [diff] [blame] | 57 | .prog = &prog, |
Aaron Durbin | 63fcb4a | 2013-12-12 10:29:48 -0800 | [diff] [blame] | 58 | }; |
| 59 | |
Kyösti Mälkki | c3ed886 | 2014-06-19 19:50:51 +0300 | [diff] [blame] | 60 | if (acpi_is_wakeup_s3()) { |
Aaron Durbin | 7f17759 | 2013-12-13 13:05:24 -0800 | [diff] [blame] | 61 | return load_refcode_from_cache(); |
Aaron Durbin | 63fcb4a | 2013-12-12 10:29:48 -0800 | [diff] [blame] | 62 | } |
| 63 | |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame^] | 64 | 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 Durbin | 7f17759 | 2013-12-13 13:05:24 -0800 | [diff] [blame] | 73 | |
| 74 | /* Cache loaded reference code. */ |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame^] | 75 | stage_cache_add(STAGE_REFCODE, &prog); |
Aaron Durbin | 63fcb4a | 2013-12-12 10:29:48 -0800 | [diff] [blame] | 76 | |
Aaron Durbin | 460703b | 2015-03-27 21:17:22 -0500 | [diff] [blame] | 77 | return prog_entry(&prog); |
Aaron Durbin | 63fcb4a | 2013-12-12 10:29:48 -0800 | [diff] [blame] | 78 | } |
| 79 | |
Aaron Durbin | ae5d83e | 2013-10-24 10:21:43 -0500 | [diff] [blame] | 80 | void 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 Durbin | ae5d83e | 2013-10-24 10:21:43 -0500 | [diff] [blame] | 88 | |
Aaron Durbin | 7f17759 | 2013-12-13 13:05:24 -0800 | [diff] [blame] | 89 | entry = load_reference_code(); |
Aaron Durbin | ae5d83e | 2013-10-24 10:21:43 -0500 | [diff] [blame] | 90 | |
Aaron Durbin | 63fcb4a | 2013-12-12 10:29:48 -0800 | [diff] [blame] | 91 | if (entry == NULL) |
| 92 | return; |
| 93 | |
Aaron Durbin | 8fa6283 | 2013-10-28 09:54:22 -0500 | [diff] [blame] | 94 | wrp.tsc_ticks_per_microsecond = tsc_freq_mhz(); |
Aaron Durbin | ae5d83e | 2013-10-24 10:21:43 -0500 | [diff] [blame] | 95 | |
| 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 | } |