Kyösti Mälkki | e7e847c | 2013-06-27 08:20:09 +0300 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; version 2 of the License. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
Kyösti Mälkki | e7e847c | 2013-06-27 08:20:09 +0300 | [diff] [blame] | 12 | */ |
| 13 | |
Kyösti Mälkki | 4dba06a | 2014-01-04 09:42:02 +0200 | [diff] [blame] | 14 | #include <stdlib.h> |
Kyösti Mälkki | e7e847c | 2013-06-27 08:20:09 +0300 | [diff] [blame] | 15 | #include <cbmem.h> |
Kyösti Mälkki | cb28f3f | 2014-01-03 15:15:22 +0200 | [diff] [blame] | 16 | #include <arch/acpi.h> |
Kyösti Mälkki | e7e847c | 2013-06-27 08:20:09 +0300 | [diff] [blame] | 17 | |
Kyösti Mälkki | a7dd645 | 2017-04-19 07:37:38 +0300 | [diff] [blame] | 18 | #if IS_ENABLED(CONFIG_CBMEM_TOP_BACKUP) |
| 19 | |
Kyösti Mälkki | 697927c | 2013-10-13 04:15:40 +0300 | [diff] [blame] | 20 | void *cbmem_top(void) |
| 21 | { |
Kyösti Mälkki | 513a1a8 | 2018-06-03 12:29:50 +0300 | [diff] [blame] | 22 | static void *cbmem_top_backup; |
| 23 | void *top_backup; |
Aaron Durbin | 28d5ec9 | 2015-05-26 11:15:45 -0500 | [diff] [blame] | 24 | |
Kyösti Mälkki | 70d92b9 | 2017-04-19 19:57:01 +0300 | [diff] [blame] | 25 | if (ENV_RAMSTAGE && cbmem_top_backup != NULL) |
| 26 | return cbmem_top_backup; |
Aaron Durbin | 28d5ec9 | 2015-05-26 11:15:45 -0500 | [diff] [blame] | 27 | |
Kyösti Mälkki | 513a1a8 | 2018-06-03 12:29:50 +0300 | [diff] [blame] | 28 | /* Top of CBMEM is at highest usable DRAM address below 4GiB. */ |
| 29 | top_backup = (void *)restore_top_of_low_cacheable(); |
Kyösti Mälkki | a7dd645 | 2017-04-19 07:37:38 +0300 | [diff] [blame] | 30 | |
| 31 | if (ENV_RAMSTAGE) |
Kyösti Mälkki | 513a1a8 | 2018-06-03 12:29:50 +0300 | [diff] [blame] | 32 | cbmem_top_backup = top_backup; |
Kyösti Mälkki | a7dd645 | 2017-04-19 07:37:38 +0300 | [diff] [blame] | 33 | |
Kyösti Mälkki | 513a1a8 | 2018-06-03 12:29:50 +0300 | [diff] [blame] | 34 | return top_backup; |
Kyösti Mälkki | 697927c | 2013-10-13 04:15:40 +0300 | [diff] [blame] | 35 | } |
Kyösti Mälkki | 2fb6b40 | 2014-12-19 08:20:45 +0200 | [diff] [blame] | 36 | |
Kyösti Mälkki | a7dd645 | 2017-04-19 07:37:38 +0300 | [diff] [blame] | 37 | #endif /* CBMEM_TOP_BACKUP */ |
Kyösti Mälkki | cb28f3f | 2014-01-03 15:15:22 +0200 | [diff] [blame] | 38 | |
Kyösti Mälkki | 823edda | 2014-12-18 18:30:29 +0200 | [diff] [blame] | 39 | /* Something went wrong, our high memory area got wiped */ |
| 40 | void cbmem_fail_resume(void) |
| 41 | { |
| 42 | #if !defined(__PRE_RAM__) && IS_ENABLED(CONFIG_HAVE_ACPI_RESUME) |
| 43 | /* ACPI resume needs to be cleared in the fail-to-recover case, but that |
| 44 | * condition is only handled during ramstage. */ |
| 45 | acpi_fail_wakeup(); |
| 46 | #endif |
| 47 | } |