blob: f48e46aa8022120d457e30cf970cedf473d39639 [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
Patrick Georgib890a122015-03-26 15:17:45 +010015 * Foundation, Inc.
Kyösti Mälkkie7e847c2013-06-27 08:20:09 +030016 */
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. */
Kyösti Mälkki91fac612014-12-31 20:55:19 +020024#include <arch/early_variables.h>
Kyösti Mälkki823edda2014-12-18 18:30:29 +020025#include <cpu/x86/gdt.h>
Kyösti Mälkki0a11a612014-12-31 19:29:02 +020026#include <console/cbmem_console.h>
Kyösti Mälkki4d107502014-12-19 10:17:46 +020027#include <timestamp.h>
Kyösti Mälkki823edda2014-12-18 18:30:29 +020028
Kyösti Mälkki2fb6b402014-12-19 08:20:45 +020029#if IS_ENABLED(CONFIG_LATE_CBMEM_INIT)
Kyösti Mälkkic04afd62013-09-04 13:31:39 +030030
Kyösti Mälkki082c19e2013-10-12 00:22:57 +030031#if !defined(__PRE_RAM__)
Kyösti Mälkkibc90e152013-09-04 13:26:11 +030032void __attribute__((weak)) backup_top_of_ram(uint64_t ramtop)
33{
34 /* Do nothing. Chipset may have implementation to save ramtop in NVRAM. */
35}
36
Aaron Durbin28d5ec92015-05-26 11:15:45 -050037static void *ramtop_pointer;
38
Kyösti Mälkki2b790f62013-09-03 05:25:57 +030039void set_top_of_ram(uint64_t ramtop)
Kyösti Mälkkie7e847c2013-06-27 08:20:09 +030040{
Kyösti Mälkkibc90e152013-09-04 13:26:11 +030041 backup_top_of_ram(ramtop);
Aaron Durbin28d5ec92015-05-26 11:15:45 -050042 ramtop_pointer = (void *)(uintptr_t)ramtop;
43 cbmem_set_top(ramtop_pointer);
44}
45
46static inline void *saved_ramtop(void)
47{
48 return ramtop_pointer;
49}
50#else
51static inline void *saved_ramtop(void)
52{
53 return NULL;
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
57unsigned long __attribute__((weak)) get_top_of_ram(void)
58{
59 printk(BIOS_WARNING, "WARNING: you need to define get_top_of_ram() for your chipset\n");
60 return 0;
61}
Kyösti Mälkki082c19e2013-10-12 00:22:57 +030062
Kyösti Mälkki697927c2013-10-13 04:15:40 +030063void *cbmem_top(void)
64{
65 /* Top of cbmem is at lowest usable DRAM address below 4GiB. */
Aaron Durbin28d5ec92015-05-26 11:15:45 -050066 void *ptr = saved_ramtop();
67
68 if (ptr != NULL)
69 return ptr;
70
Kyösti Mälkki697927c2013-10-13 04:15:40 +030071 return (void *)get_top_of_ram();
72}
Kyösti Mälkki2fb6b402014-12-19 08:20:45 +020073
74#endif /* LATE_CBMEM_INIT */
Kyösti Mälkkicb28f3f2014-01-03 15:15:22 +020075
Kyösti Mälkki823edda2014-12-18 18:30:29 +020076void cbmem_run_init_hooks(void)
Kyösti Mälkkicb28f3f2014-01-03 15:15:22 +020077{
Kyösti Mälkki91fac612014-12-31 20:55:19 +020078 /* Migrate car.global_data. */
79 car_migrate_variables();
80
Kyösti Mälkki823edda2014-12-18 18:30:29 +020081#if !defined(__PRE_RAM__)
Kyösti Mälkki0a11a612014-12-31 19:29:02 +020082 /* Relocate CBMEM console. */
83 cbmemc_reinit();
84
Kyösti Mälkki4d107502014-12-19 10:17:46 +020085 /* Relocate timestamps stash. */
86 timestamp_reinit();
87
Kyösti Mälkki823edda2014-12-18 18:30:29 +020088 move_gdt();
Kyösti Mälkkicb28f3f2014-01-03 15:15:22 +020089#endif
90}
91
Kyösti Mälkki823edda2014-12-18 18:30:29 +020092/* Something went wrong, our high memory area got wiped */
93void cbmem_fail_resume(void)
94{
95#if !defined(__PRE_RAM__) && IS_ENABLED(CONFIG_HAVE_ACPI_RESUME)
96 /* ACPI resume needs to be cleared in the fail-to-recover case, but that
97 * condition is only handled during ramstage. */
98 acpi_fail_wakeup();
99#endif
100}