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. |
| 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 Georgi | b890a12 | 2015-03-26 15:17:45 +0100 | [diff] [blame] | 15 | * Foundation, Inc. |
Kyösti Mälkki | e7e847c | 2013-06-27 08:20:09 +0300 | [diff] [blame] | 16 | */ |
| 17 | |
Kyösti Mälkki | 4dba06a | 2014-01-04 09:42:02 +0200 | [diff] [blame] | 18 | #include <stdlib.h> |
Kyösti Mälkki | e7e847c | 2013-06-27 08:20:09 +0300 | [diff] [blame] | 19 | #include <console/console.h> |
| 20 | #include <cbmem.h> |
Kyösti Mälkki | cb28f3f | 2014-01-03 15:15:22 +0200 | [diff] [blame] | 21 | #include <arch/acpi.h> |
Kyösti Mälkki | e7e847c | 2013-06-27 08:20:09 +0300 | [diff] [blame] | 22 | |
Kyösti Mälkki | 823edda | 2014-12-18 18:30:29 +0200 | [diff] [blame] | 23 | /* FIXME: Remove after CBMEM_INIT_HOOKS. */ |
Kyösti Mälkki | 91fac61 | 2014-12-31 20:55:19 +0200 | [diff] [blame] | 24 | #include <arch/early_variables.h> |
Kyösti Mälkki | 823edda | 2014-12-18 18:30:29 +0200 | [diff] [blame] | 25 | #include <cpu/x86/gdt.h> |
Kyösti Mälkki | 0a11a61 | 2014-12-31 19:29:02 +0200 | [diff] [blame] | 26 | #include <console/cbmem_console.h> |
Kyösti Mälkki | 4d10750 | 2014-12-19 10:17:46 +0200 | [diff] [blame] | 27 | #include <timestamp.h> |
Kyösti Mälkki | 823edda | 2014-12-18 18:30:29 +0200 | [diff] [blame] | 28 | |
Kyösti Mälkki | 2fb6b40 | 2014-12-19 08:20:45 +0200 | [diff] [blame] | 29 | #if IS_ENABLED(CONFIG_LATE_CBMEM_INIT) |
Kyösti Mälkki | c04afd6 | 2013-09-04 13:31:39 +0300 | [diff] [blame] | 30 | |
Kyösti Mälkki | 082c19e | 2013-10-12 00:22:57 +0300 | [diff] [blame] | 31 | #if !defined(__PRE_RAM__) |
Kyösti Mälkki | bc90e15 | 2013-09-04 13:26:11 +0300 | [diff] [blame] | 32 | void __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 Durbin | 28d5ec9 | 2015-05-26 11:15:45 -0500 | [diff] [blame^] | 37 | static void *ramtop_pointer; |
| 38 | |
Kyösti Mälkki | 2b790f6 | 2013-09-03 05:25:57 +0300 | [diff] [blame] | 39 | void set_top_of_ram(uint64_t ramtop) |
Kyösti Mälkki | e7e847c | 2013-06-27 08:20:09 +0300 | [diff] [blame] | 40 | { |
Kyösti Mälkki | bc90e15 | 2013-09-04 13:26:11 +0300 | [diff] [blame] | 41 | backup_top_of_ram(ramtop); |
Aaron Durbin | 28d5ec9 | 2015-05-26 11:15:45 -0500 | [diff] [blame^] | 42 | ramtop_pointer = (void *)(uintptr_t)ramtop; |
| 43 | cbmem_set_top(ramtop_pointer); |
| 44 | } |
| 45 | |
| 46 | static inline void *saved_ramtop(void) |
| 47 | { |
| 48 | return ramtop_pointer; |
| 49 | } |
| 50 | #else |
| 51 | static inline void *saved_ramtop(void) |
| 52 | { |
| 53 | return NULL; |
Kyösti Mälkki | e7e847c | 2013-06-27 08:20:09 +0300 | [diff] [blame] | 54 | } |
Kyösti Mälkki | deb2cb2 | 2014-03-28 23:46:45 +0200 | [diff] [blame] | 55 | #endif /* !__PRE_RAM__ */ |
Kyösti Mälkki | 082c19e | 2013-10-12 00:22:57 +0300 | [diff] [blame] | 56 | |
| 57 | unsigned 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älkki | 082c19e | 2013-10-12 00:22:57 +0300 | [diff] [blame] | 62 | |
Kyösti Mälkki | 697927c | 2013-10-13 04:15:40 +0300 | [diff] [blame] | 63 | void *cbmem_top(void) |
| 64 | { |
| 65 | /* Top of cbmem is at lowest usable DRAM address below 4GiB. */ |
Aaron Durbin | 28d5ec9 | 2015-05-26 11:15:45 -0500 | [diff] [blame^] | 66 | void *ptr = saved_ramtop(); |
| 67 | |
| 68 | if (ptr != NULL) |
| 69 | return ptr; |
| 70 | |
Kyösti Mälkki | 697927c | 2013-10-13 04:15:40 +0300 | [diff] [blame] | 71 | return (void *)get_top_of_ram(); |
| 72 | } |
Kyösti Mälkki | 2fb6b40 | 2014-12-19 08:20:45 +0200 | [diff] [blame] | 73 | |
| 74 | #endif /* LATE_CBMEM_INIT */ |
Kyösti Mälkki | cb28f3f | 2014-01-03 15:15:22 +0200 | [diff] [blame] | 75 | |
Kyösti Mälkki | 823edda | 2014-12-18 18:30:29 +0200 | [diff] [blame] | 76 | void cbmem_run_init_hooks(void) |
Kyösti Mälkki | cb28f3f | 2014-01-03 15:15:22 +0200 | [diff] [blame] | 77 | { |
Kyösti Mälkki | 91fac61 | 2014-12-31 20:55:19 +0200 | [diff] [blame] | 78 | /* Migrate car.global_data. */ |
| 79 | car_migrate_variables(); |
| 80 | |
Kyösti Mälkki | 823edda | 2014-12-18 18:30:29 +0200 | [diff] [blame] | 81 | #if !defined(__PRE_RAM__) |
Kyösti Mälkki | 0a11a61 | 2014-12-31 19:29:02 +0200 | [diff] [blame] | 82 | /* Relocate CBMEM console. */ |
| 83 | cbmemc_reinit(); |
| 84 | |
Kyösti Mälkki | 4d10750 | 2014-12-19 10:17:46 +0200 | [diff] [blame] | 85 | /* Relocate timestamps stash. */ |
| 86 | timestamp_reinit(); |
| 87 | |
Kyösti Mälkki | 823edda | 2014-12-18 18:30:29 +0200 | [diff] [blame] | 88 | move_gdt(); |
Kyösti Mälkki | cb28f3f | 2014-01-03 15:15:22 +0200 | [diff] [blame] | 89 | #endif |
| 90 | } |
| 91 | |
Kyösti Mälkki | 823edda | 2014-12-18 18:30:29 +0200 | [diff] [blame] | 92 | /* Something went wrong, our high memory area got wiped */ |
| 93 | void 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 | } |