Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2014 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. |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <string.h> |
| 17 | #include <arch/acpi.h> |
| 18 | #include <cbmem.h> |
| 19 | #include <console/console.h> |
Aaron Durbin | 83a8df5 | 2015-03-27 21:01:52 -0500 | [diff] [blame] | 20 | #include <console/streams.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 21 | #include <cpu/x86/tsc.h> |
Aaron Durbin | 460703b | 2015-03-27 21:17:22 -0500 | [diff] [blame] | 22 | #include <program_loading.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 23 | #include <rmodule.h> |
Aaron Durbin | bd74a4b | 2015-03-06 23:17:33 -0600 | [diff] [blame] | 24 | #include <stage_cache.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 25 | #include <string.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 26 | #include <soc/pei_data.h> |
| 27 | #include <soc/pei_wrapper.h> |
Kyösti Mälkki | 1ec23c9 | 2015-05-29 06:18:18 +0300 | [diff] [blame] | 28 | #include <soc/pm.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 29 | #include <soc/ramstage.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 30 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 31 | static pei_wrapper_entry_t load_refcode_from_cache(void) |
| 32 | { |
Aaron Durbin | bd74a4b | 2015-03-06 23:17:33 -0600 | [diff] [blame] | 33 | struct prog refcode; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 34 | |
| 35 | printk(BIOS_DEBUG, "refcode loading from cache.\n"); |
| 36 | |
Aaron Durbin | bd74a4b | 2015-03-06 23:17:33 -0600 | [diff] [blame] | 37 | stage_cache_load_stage(STAGE_REFCODE, &refcode); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 38 | |
Aaron Durbin | bd74a4b | 2015-03-06 23:17:33 -0600 | [diff] [blame] | 39 | return (pei_wrapper_entry_t)prog_entry(&refcode); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Patrick Georgi | e6e9493 | 2015-06-22 22:26:45 +0200 | [diff] [blame] | 42 | static pei_wrapper_entry_t load_reference_code(void) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 43 | { |
Aaron Durbin | ac12c66c | 2015-05-20 12:08:55 -0500 | [diff] [blame] | 44 | struct prog prog = |
Aaron Durbin | 7e7a4df | 2015-12-08 14:34:35 -0600 | [diff] [blame] | 45 | PROG_INIT(PROG_REFCODE, CONFIG_CBFS_PREFIX "/refcode"); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 46 | struct rmod_stage_load refcode = { |
| 47 | .cbmem_id = CBMEM_ID_REFCODE, |
Aaron Durbin | 460703b | 2015-03-27 21:17:22 -0500 | [diff] [blame] | 48 | .prog = &prog, |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 49 | }; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 50 | |
Kyösti Mälkki | 9e94dbf | 2015-01-08 20:03:18 +0200 | [diff] [blame] | 51 | if (acpi_is_wakeup_s3()) { |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 52 | return load_refcode_from_cache(); |
| 53 | } |
| 54 | |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 55 | if (prog_locate(&prog)) { |
| 56 | printk(BIOS_DEBUG, "Couldn't locate reference code.\n"); |
| 57 | return NULL; |
| 58 | } |
| 59 | |
| 60 | if (rmodule_stage_load(&refcode)) { |
| 61 | printk(BIOS_DEBUG, "Error loading reference code.\n"); |
| 62 | return NULL; |
| 63 | } |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 64 | |
| 65 | /* Cache loaded reference code. */ |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 66 | stage_cache_add(STAGE_REFCODE, &prog); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 67 | |
Patrick Georgi | e6e9493 | 2015-06-22 22:26:45 +0200 | [diff] [blame] | 68 | return (pei_wrapper_entry_t)prog_entry(&prog); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | void broadwell_run_reference_code(void) |
| 72 | { |
Kenji Chen | 89f6388 | 2014-11-13 14:44:46 -0800 | [diff] [blame] | 73 | int ret, dummy; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 74 | struct pei_data pei_data; |
| 75 | pei_wrapper_entry_t entry; |
| 76 | |
| 77 | memset(&pei_data, 0, sizeof(pei_data)); |
| 78 | mainboard_fill_pei_data(&pei_data); |
| 79 | broadwell_fill_pei_data(&pei_data); |
| 80 | |
Aaron Durbin | 9e6d143 | 2016-07-13 23:21:41 -0500 | [diff] [blame] | 81 | pei_data.boot_mode = acpi_is_wakeup_s3() ? ACPI_S3 : 0; |
Kenji Chen | 89f6388 | 2014-11-13 14:44:46 -0800 | [diff] [blame] | 82 | pei_data.saved_data = (void *) &dummy; |
| 83 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 84 | entry = load_reference_code(); |
| 85 | if (entry == NULL) { |
| 86 | printk(BIOS_ERR, "Reference code not found\n"); |
| 87 | return; |
| 88 | } |
| 89 | |
| 90 | /* Call into reference code. */ |
| 91 | ret = entry(&pei_data); |
| 92 | if (ret != 0) { |
| 93 | printk(BIOS_ERR, "Reference code returned %d\n", ret); |
| 94 | return; |
| 95 | } |
| 96 | } |