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 |
| 15 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA |
| 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 | |
| 23 | #if !CONFIG_DYNAMIC_CBMEM |
Kyösti Mälkki | c04afd6 | 2013-09-04 13:31:39 +0300 | [diff] [blame] | 24 | void 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älkki | c04afd6 | 2013-09-04 13:31:39 +0300 | [diff] [blame] | 36 | |
Kyösti Mälkki | 082c19e | 2013-10-12 00:22:57 +0300 | [diff] [blame] | 37 | #if !defined(__PRE_RAM__) |
Kyösti Mälkki | bc90e15 | 2013-09-04 13:26:11 +0300 | [diff] [blame] | 38 | void __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älkki | e7e847c | 2013-06-27 08:20:09 +0300 | [diff] [blame] | 43 | /* 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älkki | cbf5bdf | 2013-09-10 00:07:21 +0300 | [diff] [blame] | 45 | * early features like COLLECT_TIMESTAMPS and CBMEM_CONSOLE. |
Kyösti Mälkki | e7e847c | 2013-06-27 08:20:09 +0300 | [diff] [blame] | 46 | */ |
Kyösti Mälkki | 2b790f6 | 2013-09-03 05:25:57 +0300 | [diff] [blame] | 47 | void set_top_of_ram(uint64_t ramtop) |
Kyösti Mälkki | e7e847c | 2013-06-27 08:20:09 +0300 | [diff] [blame] | 48 | { |
Kyösti Mälkki | bc90e15 | 2013-09-04 13:26:11 +0300 | [diff] [blame] | 49 | backup_top_of_ram(ramtop); |
Kyösti Mälkki | 1ae305e | 2013-09-04 13:05:01 +0300 | [diff] [blame] | 50 | cbmem_late_set_table(ramtop - HIGH_MEMORY_SIZE, HIGH_MEMORY_SIZE); |
Kyösti Mälkki | e7e847c | 2013-06-27 08:20:09 +0300 | [diff] [blame] | 51 | } |
Kyösti Mälkki | 082c19e | 2013-10-12 00:22:57 +0300 | [diff] [blame] | 52 | |
| 53 | unsigned long __attribute__((weak)) get_top_of_ram(void) |
| 54 | { |
| 55 | printk(BIOS_WARNING, "WARNING: you need to define get_top_of_ram() for your chipset\n"); |
| 56 | return 0; |
| 57 | } |
| 58 | #endif /* !__PRE_RAM__ */ |
| 59 | |
Kyösti Mälkki | 697927c | 2013-10-13 04:15:40 +0300 | [diff] [blame] | 60 | #else |
| 61 | |
| 62 | void *cbmem_top(void) |
| 63 | { |
| 64 | /* Top of cbmem is at lowest usable DRAM address below 4GiB. */ |
| 65 | return (void *)get_top_of_ram(); |
| 66 | } |
| 67 | |
| 68 | #endif /* DYNAMIC_CBMEM */ |
Kyösti Mälkki | cb28f3f | 2014-01-03 15:15:22 +0200 | [diff] [blame] | 69 | |
| 70 | #if !defined(__PRE_RAM__) |
| 71 | |
| 72 | /* ACPI resume needs to be cleared in the fail-to-recover case, but that |
| 73 | * condition is only handled during ramstage. */ |
| 74 | void cbmem_fail_resume(void) |
| 75 | { |
| 76 | #if CONFIG_HAVE_ACPI_RESUME |
| 77 | /* Something went wrong, our high memory area got wiped */ |
| 78 | acpi_fail_wakeup(); |
| 79 | #endif |
| 80 | } |
| 81 | |
| 82 | #endif /* !__PRE_RAM__ */ |