blob: 01520187f942168c190b76bfb5d6880ab28d762e [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.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
16 */
17
18#include <console/console.h>
19#include <cbmem.h>
Kyösti Mälkkicb28f3f2014-01-03 15:15:22 +020020#include <arch/acpi.h>
Kyösti Mälkkie7e847c2013-06-27 08:20:09 +030021
22#if !CONFIG_DYNAMIC_CBMEM
Kyösti Mälkkic04afd62013-09-04 13:31:39 +030023void get_cbmem_table(uint64_t *base, uint64_t *size)
24{
25 uint64_t top_of_ram = get_top_of_ram();
26
27 if (top_of_ram >= HIGH_MEMORY_SIZE) {
28 *base = top_of_ram - HIGH_MEMORY_SIZE;
29 *size = HIGH_MEMORY_SIZE;
30 } else {
31 *base = 0;
32 *size = 0;
33 }
34}
Kyösti Mälkkic04afd62013-09-04 13:31:39 +030035
Kyösti Mälkki082c19e2013-10-12 00:22:57 +030036#if !defined(__PRE_RAM__)
Kyösti Mälkkibc90e152013-09-04 13:26:11 +030037void __attribute__((weak)) backup_top_of_ram(uint64_t ramtop)
38{
39 /* Do nothing. Chipset may have implementation to save ramtop in NVRAM. */
40}
41
Kyösti Mälkkie7e847c2013-06-27 08:20:09 +030042/* This is for compatibility with old boards only. Any new chipset and board
43 * must implement get_top_of_ram() for both romstage and ramstage to support
Kyösti Mälkkicbf5bdf2013-09-10 00:07:21 +030044 * early features like COLLECT_TIMESTAMPS and CBMEM_CONSOLE.
Kyösti Mälkkie7e847c2013-06-27 08:20:09 +030045 */
Kyösti Mälkki2b790f62013-09-03 05:25:57 +030046void set_top_of_ram(uint64_t ramtop)
Kyösti Mälkkie7e847c2013-06-27 08:20:09 +030047{
Kyösti Mälkkibc90e152013-09-04 13:26:11 +030048 backup_top_of_ram(ramtop);
Kyösti Mälkki1ae305e2013-09-04 13:05:01 +030049 cbmem_late_set_table(ramtop - HIGH_MEMORY_SIZE, HIGH_MEMORY_SIZE);
Kyösti Mälkkie7e847c2013-06-27 08:20:09 +030050}
Kyösti Mälkki082c19e2013-10-12 00:22:57 +030051
52unsigned long __attribute__((weak)) get_top_of_ram(void)
53{
54 printk(BIOS_WARNING, "WARNING: you need to define get_top_of_ram() for your chipset\n");
55 return 0;
56}
57#endif /* !__PRE_RAM__ */
58
Kyösti Mälkki697927c2013-10-13 04:15:40 +030059#else
60
61void *cbmem_top(void)
62{
63 /* Top of cbmem is at lowest usable DRAM address below 4GiB. */
64 return (void *)get_top_of_ram();
65}
66
67#endif /* DYNAMIC_CBMEM */
Kyösti Mälkkicb28f3f2014-01-03 15:15:22 +020068
69#if !defined(__PRE_RAM__)
70
71/* ACPI resume needs to be cleared in the fail-to-recover case, but that
72 * condition is only handled during ramstage. */
73void cbmem_fail_resume(void)
74{
75#if CONFIG_HAVE_ACPI_RESUME
76 /* Something went wrong, our high memory area got wiped */
77 acpi_fail_wakeup();
78#endif
79}
80
81#endif /* !__PRE_RAM__ */