Angel Pons | c3f58f6 | 2020-04-05 15:46:41 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Aaron Durbin | ae5d83e | 2013-10-24 10:21:43 -0500 | [diff] [blame] | 2 | |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 3 | #include <acpi/acpi.h> |
Angel Pons | e4c8dc8 | 2021-02-07 23:40:41 +0100 | [diff] [blame] | 4 | #include <cbmem.h> |
Aaron Durbin | ae5d83e | 2013-10-24 10:21:43 -0500 | [diff] [blame] | 5 | #include <console/console.h> |
Aaron Durbin | 43b7db7 | 2015-03-27 20:53:30 -0500 | [diff] [blame] | 6 | #include <console/streams.h> |
Aaron Durbin | 8fa6283 | 2013-10-28 09:54:22 -0500 | [diff] [blame] | 7 | #include <cpu/x86/tsc.h> |
Aaron Durbin | 460703b | 2015-03-27 21:17:22 -0500 | [diff] [blame] | 8 | #include <program_loading.h> |
Aaron Durbin | ae5d83e | 2013-10-24 10:21:43 -0500 | [diff] [blame] | 9 | #include <rmodule.h> |
Aaron Durbin | bd74a4b | 2015-03-06 23:17:33 -0600 | [diff] [blame] | 10 | #include <stage_cache.h> |
Aaron Durbin | ae5d83e | 2013-10-24 10:21:43 -0500 | [diff] [blame] | 11 | |
Julius Werner | 18ea2d3 | 2014-10-07 16:42:17 -0700 | [diff] [blame] | 12 | #include <soc/ramstage.h> |
| 13 | #include <soc/efi_wrapper.h> |
Aaron Durbin | ae5d83e | 2013-10-24 10:21:43 -0500 | [diff] [blame] | 14 | |
| 15 | static void ABI_X86 send_to_console(unsigned char b) |
| 16 | { |
| 17 | console_tx_byte(b); |
| 18 | } |
| 19 | |
Aaron Durbin | 7f17759 | 2013-12-13 13:05:24 -0800 | [diff] [blame] | 20 | static efi_wrapper_entry_t load_reference_code(void) |
| 21 | { |
Angel Pons | 67df3ff | 2021-01-29 18:20:11 +0100 | [diff] [blame] | 22 | if (resume_from_stage_cache()) { |
| 23 | struct prog prog; |
| 24 | stage_cache_load_stage(STAGE_REFCODE, &prog); |
| 25 | return prog_entry(&prog); |
| 26 | } |
| 27 | |
Aaron Durbin | ac12c66c | 2015-05-20 12:08:55 -0500 | [diff] [blame] | 28 | struct prog prog = |
Aaron Durbin | 7e7a4df | 2015-12-08 14:34:35 -0600 | [diff] [blame] | 29 | PROG_INIT(PROG_REFCODE, CONFIG_CBFS_PREFIX "/refcode"); |
Aaron Durbin | 63fcb4a | 2013-12-12 10:29:48 -0800 | [diff] [blame] | 30 | struct rmod_stage_load refcode = { |
| 31 | .cbmem_id = CBMEM_ID_REFCODE, |
Aaron Durbin | 460703b | 2015-03-27 21:17:22 -0500 | [diff] [blame] | 32 | .prog = &prog, |
Aaron Durbin | 63fcb4a | 2013-12-12 10:29:48 -0800 | [diff] [blame] | 33 | }; |
| 34 | |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 35 | if (rmodule_stage_load(&refcode)) { |
| 36 | printk(BIOS_DEBUG, "Error loading reference code.\n"); |
| 37 | return NULL; |
| 38 | } |
Aaron Durbin | 7f17759 | 2013-12-13 13:05:24 -0800 | [diff] [blame] | 39 | |
| 40 | /* Cache loaded reference code. */ |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 41 | stage_cache_add(STAGE_REFCODE, &prog); |
Aaron Durbin | 63fcb4a | 2013-12-12 10:29:48 -0800 | [diff] [blame] | 42 | |
Aaron Durbin | 460703b | 2015-03-27 21:17:22 -0500 | [diff] [blame] | 43 | return prog_entry(&prog); |
Aaron Durbin | 63fcb4a | 2013-12-12 10:29:48 -0800 | [diff] [blame] | 44 | } |
| 45 | |
Aaron Durbin | ae5d83e | 2013-10-24 10:21:43 -0500 | [diff] [blame] | 46 | void baytrail_run_reference_code(void) |
| 47 | { |
| 48 | int ret; |
| 49 | efi_wrapper_entry_t entry; |
| 50 | struct efi_wrapper_params wrp = { |
| 51 | .version = EFI_WRAPPER_VER, |
| 52 | .console_out = send_to_console, |
| 53 | }; |
Aaron Durbin | ae5d83e | 2013-10-24 10:21:43 -0500 | [diff] [blame] | 54 | |
Aaron Durbin | 7f17759 | 2013-12-13 13:05:24 -0800 | [diff] [blame] | 55 | entry = load_reference_code(); |
Aaron Durbin | ae5d83e | 2013-10-24 10:21:43 -0500 | [diff] [blame] | 56 | |
Aaron Durbin | 63fcb4a | 2013-12-12 10:29:48 -0800 | [diff] [blame] | 57 | if (entry == NULL) |
| 58 | return; |
| 59 | |
Aaron Durbin | 8fa6283 | 2013-10-28 09:54:22 -0500 | [diff] [blame] | 60 | wrp.tsc_ticks_per_microsecond = tsc_freq_mhz(); |
Aaron Durbin | ae5d83e | 2013-10-24 10:21:43 -0500 | [diff] [blame] | 61 | |
| 62 | /* Call into reference code. */ |
| 63 | ret = entry(&wrp); |
| 64 | |
| 65 | if (ret != 0) { |
| 66 | printk(BIOS_DEBUG, "Reference code returned %d\n", ret); |
| 67 | return; |
| 68 | } |
| 69 | } |