blob: bbf70a2a0ffd6396d373519700932169bf71e3af [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
Kyösti Mälkki823edda2014-12-18 18:30:29 +020023/* FIXME: Remove after CBMEM_INIT_HOOKS. */
24#include <cpu/x86/gdt.h>
25
Kyösti Mälkkie7e847c2013-06-27 08:20:09 +030026#if !CONFIG_DYNAMIC_CBMEM
Kyösti Mälkkic04afd62013-09-04 13:31:39 +030027void get_cbmem_table(uint64_t *base, uint64_t *size)
28{
29 uint64_t top_of_ram = get_top_of_ram();
30
31 if (top_of_ram >= HIGH_MEMORY_SIZE) {
32 *base = top_of_ram - HIGH_MEMORY_SIZE;
33 *size = HIGH_MEMORY_SIZE;
34 } else {
35 *base = 0;
36 *size = 0;
37 }
38}
Kyösti Mälkkic04afd62013-09-04 13:31:39 +030039
Kyösti Mälkki082c19e2013-10-12 00:22:57 +030040#if !defined(__PRE_RAM__)
Kyösti Mälkkibc90e152013-09-04 13:26:11 +030041void __attribute__((weak)) backup_top_of_ram(uint64_t ramtop)
42{
43 /* Do nothing. Chipset may have implementation to save ramtop in NVRAM. */
44}
45
Kyösti Mälkkie7e847c2013-06-27 08:20:09 +030046/* This is for compatibility with old boards only. Any new chipset and board
47 * must implement get_top_of_ram() for both romstage and ramstage to support
Kyösti Mälkkicbf5bdf2013-09-10 00:07:21 +030048 * early features like COLLECT_TIMESTAMPS and CBMEM_CONSOLE.
Kyösti Mälkkie7e847c2013-06-27 08:20:09 +030049 */
Kyösti Mälkki2b790f62013-09-03 05:25:57 +030050void set_top_of_ram(uint64_t ramtop)
Kyösti Mälkkie7e847c2013-06-27 08:20:09 +030051{
Kyösti Mälkkibc90e152013-09-04 13:26:11 +030052 backup_top_of_ram(ramtop);
Kyösti Mälkki1ae305e2013-09-04 13:05:01 +030053 cbmem_late_set_table(ramtop - HIGH_MEMORY_SIZE, HIGH_MEMORY_SIZE);
Kyösti Mälkkie7e847c2013-06-27 08:20:09 +030054}
Kyösti Mälkkideb2cb22014-03-28 23:46:45 +020055#endif /* !__PRE_RAM__ */
Kyösti Mälkki082c19e2013-10-12 00:22:57 +030056
Kyösti Mälkkideb2cb22014-03-28 23:46:45 +020057#if CONFIG_BROKEN_CAR_MIGRATE || !defined(__PRE_RAM__)
Kyösti Mälkki082c19e2013-10-12 00:22:57 +030058unsigned long __attribute__((weak)) get_top_of_ram(void)
59{
60 printk(BIOS_WARNING, "WARNING: you need to define get_top_of_ram() for your chipset\n");
61 return 0;
62}
Kyösti Mälkkideb2cb22014-03-28 23:46:45 +020063#endif
Kyösti Mälkki082c19e2013-10-12 00:22:57 +030064
Kyösti Mälkki697927c2013-10-13 04:15:40 +030065#else
66
67void *cbmem_top(void)
68{
69 /* Top of cbmem is at lowest usable DRAM address below 4GiB. */
70 return (void *)get_top_of_ram();
71}
72
73#endif /* DYNAMIC_CBMEM */
Kyösti Mälkkicb28f3f2014-01-03 15:15:22 +020074
Kyösti Mälkki823edda2014-12-18 18:30:29 +020075void cbmem_run_init_hooks(void)
Kyösti Mälkkicb28f3f2014-01-03 15:15:22 +020076{
Kyösti Mälkki823edda2014-12-18 18:30:29 +020077#if !defined(__PRE_RAM__)
78 move_gdt();
Kyösti Mälkkicb28f3f2014-01-03 15:15:22 +020079#endif
80}
81
Kyösti Mälkki823edda2014-12-18 18:30:29 +020082/* Something went wrong, our high memory area got wiped */
83void cbmem_fail_resume(void)
84{
85#if !defined(__PRE_RAM__) && IS_ENABLED(CONFIG_HAVE_ACPI_RESUME)
86 /* ACPI resume needs to be cleared in the fail-to-recover case, but that
87 * condition is only handled during ramstage. */
88 acpi_fail_wakeup();
89#endif
90}