blob: 73967e17f848dd767087ca6a3d73884900c93130 [file] [log] [blame]
Kyösti Mälkkie7e847c2013-06-27 08:20:09 +03001/*
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älkkie7e847c2013-06-27 08:20:09 +030012 */
13
Kyösti Mälkki4dba06a2014-01-04 09:42:02 +020014#include <stdlib.h>
Kyösti Mälkkie7e847c2013-06-27 08:20:09 +030015#include <cbmem.h>
Kyösti Mälkkicb28f3f2014-01-03 15:15:22 +020016#include <arch/acpi.h>
Kyösti Mälkkie7e847c2013-06-27 08:20:09 +030017
Kyösti Mälkkia7dd6452017-04-19 07:37:38 +030018#if IS_ENABLED(CONFIG_CBMEM_TOP_BACKUP)
19
Kyösti Mälkki697927c2013-10-13 04:15:40 +030020void *cbmem_top(void)
21{
Kyösti Mälkki513a1a82018-06-03 12:29:50 +030022 static void *cbmem_top_backup;
23 void *top_backup;
Aaron Durbin28d5ec92015-05-26 11:15:45 -050024
Kyösti Mälkki70d92b92017-04-19 19:57:01 +030025 if (ENV_RAMSTAGE && cbmem_top_backup != NULL)
26 return cbmem_top_backup;
Aaron Durbin28d5ec92015-05-26 11:15:45 -050027
Kyösti Mälkki513a1a82018-06-03 12:29:50 +030028 /* Top of CBMEM is at highest usable DRAM address below 4GiB. */
29 top_backup = (void *)restore_top_of_low_cacheable();
Kyösti Mälkkia7dd6452017-04-19 07:37:38 +030030
31 if (ENV_RAMSTAGE)
Kyösti Mälkki513a1a82018-06-03 12:29:50 +030032 cbmem_top_backup = top_backup;
Kyösti Mälkkia7dd6452017-04-19 07:37:38 +030033
Kyösti Mälkki513a1a82018-06-03 12:29:50 +030034 return top_backup;
Kyösti Mälkki697927c2013-10-13 04:15:40 +030035}
Kyösti Mälkki2fb6b402014-12-19 08:20:45 +020036
Kyösti Mälkkia7dd6452017-04-19 07:37:38 +030037#endif /* CBMEM_TOP_BACKUP */
Kyösti Mälkkicb28f3f2014-01-03 15:15:22 +020038
Kyösti Mälkki823edda2014-12-18 18:30:29 +020039/* Something went wrong, our high memory area got wiped */
40void 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}