blob: 6bbc18cb00b0e6135e1e400b4fbbf3134f608f44 [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 <console/console.h>
16#include <cbmem.h>
Kyösti Mälkkicb28f3f2014-01-03 15:15:22 +020017#include <arch/acpi.h>
Kyösti Mälkkie7e847c2013-06-27 08:20:09 +030018
Kyösti Mälkki2fb6b402014-12-19 08:20:45 +020019#if IS_ENABLED(CONFIG_LATE_CBMEM_INIT)
Kyösti Mälkkic04afd62013-09-04 13:31:39 +030020
Kyösti Mälkki082c19e2013-10-12 00:22:57 +030021#if !defined(__PRE_RAM__)
Kyösti Mälkkibc90e152013-09-04 13:26:11 +030022void __attribute__((weak)) backup_top_of_ram(uint64_t ramtop)
23{
24 /* Do nothing. Chipset may have implementation to save ramtop in NVRAM. */
25}
26
Aaron Durbin28d5ec92015-05-26 11:15:45 -050027static void *ramtop_pointer;
28
Kyösti Mälkki2b790f62013-09-03 05:25:57 +030029void set_top_of_ram(uint64_t ramtop)
Kyösti Mälkkie7e847c2013-06-27 08:20:09 +030030{
Kyösti Mälkkibc90e152013-09-04 13:26:11 +030031 backup_top_of_ram(ramtop);
Aaron Durbin28d5ec92015-05-26 11:15:45 -050032 ramtop_pointer = (void *)(uintptr_t)ramtop;
Aaron Durbin28d5ec92015-05-26 11:15:45 -050033}
34
35static inline void *saved_ramtop(void)
36{
37 return ramtop_pointer;
38}
39#else
40static inline void *saved_ramtop(void)
41{
42 return NULL;
Kyösti Mälkkie7e847c2013-06-27 08:20:09 +030043}
Kyösti Mälkkideb2cb22014-03-28 23:46:45 +020044#endif /* !__PRE_RAM__ */
Kyösti Mälkki082c19e2013-10-12 00:22:57 +030045
46unsigned long __attribute__((weak)) get_top_of_ram(void)
47{
Kyösti Mälkki082c19e2013-10-12 00:22:57 +030048 return 0;
49}
Kyösti Mälkki082c19e2013-10-12 00:22:57 +030050
Kyösti Mälkki697927c2013-10-13 04:15:40 +030051void *cbmem_top(void)
52{
53 /* Top of cbmem is at lowest usable DRAM address below 4GiB. */
Aaron Durbin28d5ec92015-05-26 11:15:45 -050054 void *ptr = saved_ramtop();
55
56 if (ptr != NULL)
57 return ptr;
58
Kyösti Mälkki697927c2013-10-13 04:15:40 +030059 return (void *)get_top_of_ram();
60}
Kyösti Mälkki2fb6b402014-12-19 08:20:45 +020061
62#endif /* LATE_CBMEM_INIT */
Kyösti Mälkkicb28f3f2014-01-03 15:15:22 +020063
Kyösti Mälkki823edda2014-12-18 18:30:29 +020064/* Something went wrong, our high memory area got wiped */
65void cbmem_fail_resume(void)
66{
67#if !defined(__PRE_RAM__) && IS_ENABLED(CONFIG_HAVE_ACPI_RESUME)
68 /* ACPI resume needs to be cleared in the fail-to-recover case, but that
69 * condition is only handled during ramstage. */
70 acpi_fail_wakeup();
71#endif
72}