blob: 8b2b6da6784921818da985fa4a5bfcb2f51866d4 [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
Kyösti Mälkki4dba06a2014-01-04 09:42:02 +020018#include <stdlib.h>
Kyösti Mälkkie7e847c2013-06-27 08:20:09 +030019#include <console/console.h>
20#include <cbmem.h>
Kyösti Mälkkicb28f3f2014-01-03 15:15:22 +020021#include <arch/acpi.h>
Kyösti Mälkkie7e847c2013-06-27 08:20:09 +030022
23#if !CONFIG_DYNAMIC_CBMEM
Kyösti Mälkkic04afd62013-09-04 13:31:39 +030024void get_cbmem_table(uint64_t *base, uint64_t *size)
25{
26 uint64_t top_of_ram = get_top_of_ram();
27
28 if (top_of_ram >= HIGH_MEMORY_SIZE) {
29 *base = top_of_ram - HIGH_MEMORY_SIZE;
30 *size = HIGH_MEMORY_SIZE;
31 } else {
32 *base = 0;
33 *size = 0;
34 }
35}
Kyösti Mälkkic04afd62013-09-04 13:31:39 +030036
Kyösti Mälkki082c19e2013-10-12 00:22:57 +030037#if !defined(__PRE_RAM__)
Kyösti Mälkkibc90e152013-09-04 13:26:11 +030038void __attribute__((weak)) backup_top_of_ram(uint64_t ramtop)
39{
40 /* Do nothing. Chipset may have implementation to save ramtop in NVRAM. */
41}
42
Kyösti Mälkkie7e847c2013-06-27 08:20:09 +030043/* This is for compatibility with old boards only. Any new chipset and board
44 * must implement get_top_of_ram() for both romstage and ramstage to support
Kyösti Mälkkicbf5bdf2013-09-10 00:07:21 +030045 * early features like COLLECT_TIMESTAMPS and CBMEM_CONSOLE.
Kyösti Mälkkie7e847c2013-06-27 08:20:09 +030046 */
Kyösti Mälkki2b790f62013-09-03 05:25:57 +030047void set_top_of_ram(uint64_t ramtop)
Kyösti Mälkkie7e847c2013-06-27 08:20:09 +030048{
Kyösti Mälkkibc90e152013-09-04 13:26:11 +030049 backup_top_of_ram(ramtop);
Kyösti Mälkki1ae305e2013-09-04 13:05:01 +030050 cbmem_late_set_table(ramtop - HIGH_MEMORY_SIZE, HIGH_MEMORY_SIZE);
Kyösti Mälkkie7e847c2013-06-27 08:20:09 +030051}
Kyösti Mälkkideb2cb22014-03-28 23:46:45 +020052#endif /* !__PRE_RAM__ */
Kyösti Mälkki082c19e2013-10-12 00:22:57 +030053
Kyösti Mälkkideb2cb22014-03-28 23:46:45 +020054#if CONFIG_BROKEN_CAR_MIGRATE || !defined(__PRE_RAM__)
Kyösti Mälkki082c19e2013-10-12 00:22:57 +030055unsigned long __attribute__((weak)) get_top_of_ram(void)
56{
57 printk(BIOS_WARNING, "WARNING: you need to define get_top_of_ram() for your chipset\n");
58 return 0;
59}
Kyösti Mälkkideb2cb22014-03-28 23:46:45 +020060#endif
Kyösti Mälkki082c19e2013-10-12 00:22:57 +030061
Kyösti Mälkki697927c2013-10-13 04:15:40 +030062#else
63
64void *cbmem_top(void)
65{
66 /* Top of cbmem is at lowest usable DRAM address below 4GiB. */
67 return (void *)get_top_of_ram();
68}
69
70#endif /* DYNAMIC_CBMEM */
Kyösti Mälkkicb28f3f2014-01-03 15:15:22 +020071
72#if !defined(__PRE_RAM__)
73
74/* ACPI resume needs to be cleared in the fail-to-recover case, but that
75 * condition is only handled during ramstage. */
76void cbmem_fail_resume(void)
77{
78#if CONFIG_HAVE_ACPI_RESUME
79 /* Something went wrong, our high memory area got wiped */
80 acpi_fail_wakeup();
81#endif
82}
83
84#endif /* !__PRE_RAM__ */