Kyösti Mälkki | e7e847c | 2013-06-27 08:20:09 +0300 | [diff] [blame] | 1 | /* |
| 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älkki | e7e847c | 2013-06-27 08:20:09 +0300 | [diff] [blame] | 12 | */ |
| 13 | |
Kyösti Mälkki | 4dba06a | 2014-01-04 09:42:02 +0200 | [diff] [blame] | 14 | #include <stdlib.h> |
Kyösti Mälkki | e7e847c | 2013-06-27 08:20:09 +0300 | [diff] [blame] | 15 | #include <console/console.h> |
| 16 | #include <cbmem.h> |
Kyösti Mälkki | cb28f3f | 2014-01-03 15:15:22 +0200 | [diff] [blame] | 17 | #include <arch/acpi.h> |
Kyösti Mälkki | e7e847c | 2013-06-27 08:20:09 +0300 | [diff] [blame] | 18 | |
Kyösti Mälkki | 2fb6b40 | 2014-12-19 08:20:45 +0200 | [diff] [blame] | 19 | #if IS_ENABLED(CONFIG_LATE_CBMEM_INIT) |
Kyösti Mälkki | c04afd6 | 2013-09-04 13:31:39 +0300 | [diff] [blame] | 20 | |
Kyösti Mälkki | 082c19e | 2013-10-12 00:22:57 +0300 | [diff] [blame] | 21 | #if !defined(__PRE_RAM__) |
Kyösti Mälkki | bc90e15 | 2013-09-04 13:26:11 +0300 | [diff] [blame] | 22 | void __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 Durbin | 28d5ec9 | 2015-05-26 11:15:45 -0500 | [diff] [blame] | 27 | static void *ramtop_pointer; |
| 28 | |
Kyösti Mälkki | 2b790f6 | 2013-09-03 05:25:57 +0300 | [diff] [blame] | 29 | void set_top_of_ram(uint64_t ramtop) |
Kyösti Mälkki | e7e847c | 2013-06-27 08:20:09 +0300 | [diff] [blame] | 30 | { |
Kyösti Mälkki | bc90e15 | 2013-09-04 13:26:11 +0300 | [diff] [blame] | 31 | backup_top_of_ram(ramtop); |
Aaron Durbin | 28d5ec9 | 2015-05-26 11:15:45 -0500 | [diff] [blame] | 32 | ramtop_pointer = (void *)(uintptr_t)ramtop; |
Aaron Durbin | 28d5ec9 | 2015-05-26 11:15:45 -0500 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | static inline void *saved_ramtop(void) |
| 36 | { |
| 37 | return ramtop_pointer; |
| 38 | } |
| 39 | #else |
| 40 | static inline void *saved_ramtop(void) |
| 41 | { |
| 42 | return NULL; |
Kyösti Mälkki | e7e847c | 2013-06-27 08:20:09 +0300 | [diff] [blame] | 43 | } |
Kyösti Mälkki | deb2cb2 | 2014-03-28 23:46:45 +0200 | [diff] [blame] | 44 | #endif /* !__PRE_RAM__ */ |
Kyösti Mälkki | 082c19e | 2013-10-12 00:22:57 +0300 | [diff] [blame] | 45 | |
| 46 | unsigned long __attribute__((weak)) get_top_of_ram(void) |
| 47 | { |
Kyösti Mälkki | 082c19e | 2013-10-12 00:22:57 +0300 | [diff] [blame] | 48 | return 0; |
| 49 | } |
Kyösti Mälkki | 082c19e | 2013-10-12 00:22:57 +0300 | [diff] [blame] | 50 | |
Kyösti Mälkki | 697927c | 2013-10-13 04:15:40 +0300 | [diff] [blame] | 51 | void *cbmem_top(void) |
| 52 | { |
| 53 | /* Top of cbmem is at lowest usable DRAM address below 4GiB. */ |
Aaron Durbin | 28d5ec9 | 2015-05-26 11:15:45 -0500 | [diff] [blame] | 54 | void *ptr = saved_ramtop(); |
| 55 | |
| 56 | if (ptr != NULL) |
| 57 | return ptr; |
| 58 | |
Kyösti Mälkki | 697927c | 2013-10-13 04:15:40 +0300 | [diff] [blame] | 59 | return (void *)get_top_of_ram(); |
| 60 | } |
Kyösti Mälkki | 2fb6b40 | 2014-12-19 08:20:45 +0200 | [diff] [blame] | 61 | |
| 62 | #endif /* LATE_CBMEM_INIT */ |
Kyösti Mälkki | cb28f3f | 2014-01-03 15:15:22 +0200 | [diff] [blame] | 63 | |
Kyösti Mälkki | 823edda | 2014-12-18 18:30:29 +0200 | [diff] [blame] | 64 | /* Something went wrong, our high memory area got wiped */ |
| 65 | void 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 | } |