Angel Pons | f94ac9a | 2020-04-05 15:46:48 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 2 | |
| 3 | #include <string.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 4 | #include <acpi/acpi.h> |
Angel Pons | e4c8dc8 | 2021-02-07 23:40:41 +0100 | [diff] [blame] | 5 | #include <cbmem.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 6 | #include <console/console.h> |
Aaron Durbin | 83a8df5 | 2015-03-27 21:01:52 -0500 | [diff] [blame] | 7 | #include <console/streams.h> |
Aaron Durbin | 460703b | 2015-03-27 21:17:22 -0500 | [diff] [blame] | 8 | #include <program_loading.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 9 | #include <rmodule.h> |
Aaron Durbin | bd74a4b | 2015-03-06 23:17:33 -0600 | [diff] [blame] | 10 | #include <stage_cache.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 11 | #include <soc/pei_data.h> |
| 12 | #include <soc/pei_wrapper.h> |
Kyösti Mälkki | 1ec23c9 | 2015-05-29 06:18:18 +0300 | [diff] [blame] | 13 | #include <soc/pm.h> |
Angel Pons | 12fc21b | 2021-06-16 16:57:21 +0200 | [diff] [blame] | 14 | #include <soc/refcode.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 15 | |
Patrick Georgi | e6e9493 | 2015-06-22 22:26:45 +0200 | [diff] [blame] | 16 | static pei_wrapper_entry_t load_reference_code(void) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 17 | { |
Angel Pons | 67df3ff | 2021-01-29 18:20:11 +0100 | [diff] [blame] | 18 | if (resume_from_stage_cache()) { |
| 19 | struct prog prog; |
| 20 | stage_cache_load_stage(STAGE_REFCODE, &prog); |
| 21 | return prog_entry(&prog); |
| 22 | } |
| 23 | |
Aaron Durbin | ac12c66c | 2015-05-20 12:08:55 -0500 | [diff] [blame] | 24 | struct prog prog = |
Aaron Durbin | 7e7a4df | 2015-12-08 14:34:35 -0600 | [diff] [blame] | 25 | PROG_INIT(PROG_REFCODE, CONFIG_CBFS_PREFIX "/refcode"); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 26 | struct rmod_stage_load refcode = { |
| 27 | .cbmem_id = CBMEM_ID_REFCODE, |
Aaron Durbin | 460703b | 2015-03-27 21:17:22 -0500 | [diff] [blame] | 28 | .prog = &prog, |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 29 | }; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 30 | |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 31 | if (rmodule_stage_load(&refcode)) { |
| 32 | printk(BIOS_DEBUG, "Error loading reference code.\n"); |
| 33 | return NULL; |
| 34 | } |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 35 | |
| 36 | /* Cache loaded reference code. */ |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 37 | stage_cache_add(STAGE_REFCODE, &prog); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 38 | |
Patrick Georgi | e6e9493 | 2015-06-22 22:26:45 +0200 | [diff] [blame] | 39 | return (pei_wrapper_entry_t)prog_entry(&prog); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | void broadwell_run_reference_code(void) |
| 43 | { |
Kenji Chen | 89f6388 | 2014-11-13 14:44:46 -0800 | [diff] [blame] | 44 | int ret, dummy; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 45 | struct pei_data pei_data; |
| 46 | pei_wrapper_entry_t entry; |
| 47 | |
| 48 | memset(&pei_data, 0, sizeof(pei_data)); |
| 49 | mainboard_fill_pei_data(&pei_data); |
| 50 | broadwell_fill_pei_data(&pei_data); |
| 51 | |
Aaron Durbin | 9e6d143 | 2016-07-13 23:21:41 -0500 | [diff] [blame] | 52 | pei_data.boot_mode = acpi_is_wakeup_s3() ? ACPI_S3 : 0; |
Kenji Chen | 89f6388 | 2014-11-13 14:44:46 -0800 | [diff] [blame] | 53 | pei_data.saved_data = (void *) &dummy; |
| 54 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 55 | entry = load_reference_code(); |
| 56 | if (entry == NULL) { |
| 57 | printk(BIOS_ERR, "Reference code not found\n"); |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | /* Call into reference code. */ |
| 62 | ret = entry(&pei_data); |
| 63 | if (ret != 0) { |
| 64 | printk(BIOS_ERR, "Reference code returned %d\n", ret); |
| 65 | return; |
| 66 | } |
| 67 | } |