Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2009 coresystems GmbH |
Aaron Durbin | df3a109 | 2013-03-13 12:41:44 -0500 | [diff] [blame] | 5 | * Copyright (C) 2013 Google, Inc. |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA |
| 19 | */ |
| 20 | |
| 21 | #ifndef _CBMEM_H_ |
| 22 | #define _CBMEM_H_ |
| 23 | |
Stefan Reinauer | 294edb2 | 2011-08-14 13:52:03 -0700 | [diff] [blame] | 24 | /* Reserve 128k for ACPI and other tables */ |
Vadim Bendebury | f2f9386 | 2011-10-04 10:44:16 -0700 | [diff] [blame] | 25 | #if CONFIG_CONSOLE_CBMEM |
| 26 | #define HIGH_MEMORY_DEF_SIZE ( 256 * 1024 ) |
| 27 | #else |
Stefan Reinauer | 294edb2 | 2011-08-14 13:52:03 -0700 | [diff] [blame] | 28 | #define HIGH_MEMORY_DEF_SIZE ( 128 * 1024 ) |
Vadim Bendebury | f2f9386 | 2011-10-04 10:44:16 -0700 | [diff] [blame] | 29 | #endif |
| 30 | |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 31 | #if CONFIG_HAVE_ACPI_RESUME |
Aaron Durbin | 8e4a355 | 2013-02-08 17:28:04 -0600 | [diff] [blame] | 32 | #if CONFIG_RELOCATABLE_RAMSTAGE |
| 33 | #define HIGH_MEMORY_SAVE 0 |
| 34 | #else |
zbao | f722373 | 2012-04-13 13:42:15 +0800 | [diff] [blame] | 35 | #define HIGH_MEMORY_SAVE (CONFIG_RAMTOP - CONFIG_RAMBASE) |
Aaron Durbin | 8e4a355 | 2013-02-08 17:28:04 -0600 | [diff] [blame] | 36 | #endif |
| 37 | |
zbao | f722373 | 2012-04-13 13:42:15 +0800 | [diff] [blame] | 38 | #define HIGH_MEMORY_SIZE (HIGH_MEMORY_SAVE + CONFIG_HIGH_SCRATCH_MEMORY_SIZE + HIGH_MEMORY_DEF_SIZE) |
Stefan Reinauer | 61f4a74 | 2012-04-03 16:21:04 -0700 | [diff] [blame] | 39 | |
| 40 | /* Delegation of resume backup memory so we don't have to |
| 41 | * (slowly) handle backing up OS memory in romstage.c |
| 42 | */ |
| 43 | #define CBMEM_BOOT_MODE 0x610 |
| 44 | #define CBMEM_RESUME_BACKUP 0x614 |
zbao | f722373 | 2012-04-13 13:42:15 +0800 | [diff] [blame] | 45 | |
| 46 | #else /* CONFIG_HAVE_ACPI_RESUME */ |
Rudolf Marek | 97be27e | 2010-12-13 19:50:25 +0000 | [diff] [blame] | 47 | #define HIGH_MEMORY_SIZE HIGH_MEMORY_DEF_SIZE |
zbao | f722373 | 2012-04-13 13:42:15 +0800 | [diff] [blame] | 48 | #endif /* CONFIG_HAVE_ACPI_RESUME */ |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 49 | |
| 50 | #define CBMEM_ID_FREESPACE 0x46524545 |
| 51 | #define CBMEM_ID_GDT 0x4c474454 |
| 52 | #define CBMEM_ID_ACPI 0x41435049 |
Duncan Laurie | 11290c4 | 2012-10-03 19:07:05 -0700 | [diff] [blame] | 53 | #define CBMEM_ID_ACPI_GNVS 0x474e5653 |
Duncan Laurie | 9c07c8f | 2013-03-22 11:08:39 -0700 | [diff] [blame] | 54 | #define CBMEM_ID_ACPI_GNVS_PTR 0x474e5650 |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 55 | #define CBMEM_ID_CBTABLE 0x43425442 |
| 56 | #define CBMEM_ID_PIRQ 0x49525154 |
| 57 | #define CBMEM_ID_MPTABLE 0x534d5054 |
| 58 | #define CBMEM_ID_RESUME 0x5245534d |
zbao | f722373 | 2012-04-13 13:42:15 +0800 | [diff] [blame] | 59 | #define CBMEM_ID_RESUME_SCRATCH 0x52455343 |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 60 | #define CBMEM_ID_SMBIOS 0x534d4254 |
Vadim Bendebury | 6f72d69 | 2011-09-21 16:12:39 -0700 | [diff] [blame] | 61 | #define CBMEM_ID_TIMESTAMP 0x54494d45 |
Stefan Reinauer | 61f4a74 | 2012-04-03 16:21:04 -0700 | [diff] [blame] | 62 | #define CBMEM_ID_MRCDATA 0x4d524344 |
Vadim Bendebury | be25a4d | 2011-09-30 11:13:06 -0700 | [diff] [blame] | 63 | #define CBMEM_ID_CONSOLE 0x434f4e53 |
Duncan Laurie | 215f2785 | 2012-10-10 14:34:49 -0700 | [diff] [blame] | 64 | #define CBMEM_ID_ELOG 0x454c4f47 |
Stefan Reinauer | d37ab45 | 2012-12-18 16:23:28 -0800 | [diff] [blame] | 65 | #define CBMEM_ID_COVERAGE 0x47434f56 |
Aaron Durbin | a1db81b4 | 2013-02-08 17:11:28 -0600 | [diff] [blame] | 66 | #define CBMEM_ID_ROMSTAGE_INFO 0x47545352 |
Aaron Durbin | df3a109 | 2013-03-13 12:41:44 -0500 | [diff] [blame] | 67 | #define CBMEM_ID_ROMSTAGE_RAM_STACK 0x90357ac4 |
| 68 | #define CBMEM_ID_RAMSTAGE 0x9a357a9e |
| 69 | #define CBMEM_ID_RAMSTAGE_CACHE 0x9a3ca54e |
| 70 | #define CBMEM_ID_ROOT 0xff4007ff |
Aaron Durbin | 0c6946d | 2013-03-13 12:48:33 -0500 | [diff] [blame] | 71 | #define CBMEM_ID_VBOOT_HANDOFF 0x780074f0 |
Aaron Durbin | 716738a | 2013-05-10 00:33:32 -0500 | [diff] [blame] | 72 | #define CBMEM_ID_CAR_GLOBALS 0xcac4e6a3 |
Kyösti Mälkki | 690bf2f | 2013-07-06 11:41:21 +0300 | [diff] [blame] | 73 | #define CBMEM_ID_EHCI_DEBUG 0xe4c1deb9 |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 74 | #define CBMEM_ID_NONE 0x00000000 |
Rudolf Marek | 5ce0506 | 2013-05-27 16:09:44 +0200 | [diff] [blame] | 75 | #define CBMEM_ID_AGESA_RUNTIME 0x41474553 |
Marc Jones | 54b8e7a | 2013-10-29 17:57:30 -0600 | [diff] [blame] | 76 | #define CBMEM_ID_HOB_POINTER 0x484f4221 |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 77 | |
Stefan Reinauer | 61f4a74 | 2012-04-03 16:21:04 -0700 | [diff] [blame] | 78 | #ifndef __ASSEMBLER__ |
Aaron Durbin | df3a109 | 2013-03-13 12:41:44 -0500 | [diff] [blame] | 79 | #include <stdint.h> |
| 80 | |
| 81 | struct cbmem_entry; |
| 82 | |
| 83 | #if CONFIG_DYNAMIC_CBMEM |
| 84 | |
| 85 | /* |
| 86 | * The dynamic cbmem infrastructure allows for growing cbmem dynamically as |
| 87 | * things are added. It requires an external function, cbmem_top(), to be |
| 88 | * implemented by the board or chipset to define the upper address where |
| 89 | * cbmem lives. This address is required to be a 32-bit address. Additionally, |
| 90 | * the address needs to be consistent in both romstage and ramstage. The |
Martin Roth | 0cb07e3 | 2013-07-09 21:46:01 -0600 | [diff] [blame] | 91 | * dynamic cbmem infrastructure allocates new regions below the last allocated |
Aaron Durbin | df3a109 | 2013-03-13 12:41:44 -0500 | [diff] [blame] | 92 | * region. Regions are defined by a cbmem_entry struct that is opaque. Regions |
| 93 | * may be removed, but the last one added is the only that can be removed. |
| 94 | * |
| 95 | * Dynamic cbmem has two allocators within it. All allocators use a top down |
| 96 | * allocation scheme. However, there are 2 modes for each allocation depending |
| 97 | * on the requested size. There are large allocations and small allocations. |
| 98 | * An allocation is considered to be small when it is less than or equal to |
| 99 | * DYN_CBMEM_ALIGN_SIZE / 2. The smaller allocations are fit into a larger |
| 100 | * allocation region. |
| 101 | */ |
| 102 | |
| 103 | #define DYN_CBMEM_ALIGN_SIZE (4096) |
| 104 | |
Martin Roth | 0cb07e3 | 2013-07-09 21:46:01 -0600 | [diff] [blame] | 105 | /* Initialize cbmem to be empty. */ |
Aaron Durbin | df3a109 | 2013-03-13 12:41:44 -0500 | [diff] [blame] | 106 | void cbmem_initialize_empty(void); |
| 107 | |
| 108 | /* Return the top address for dynamic cbmem. The address returned needs to |
| 109 | * be consistent across romstage and ramstage, and it is required to be |
| 110 | * below 4GiB. */ |
| 111 | void *cbmem_top(void); |
| 112 | |
| 113 | /* Add a cbmem entry of a given size and id. These return NULL on failure. The |
| 114 | * add function performs a find first and do not check against the original |
| 115 | * size. */ |
| 116 | const struct cbmem_entry *cbmem_entry_add(u32 id, u64 size); |
| 117 | |
| 118 | /* Find a cbmem entry of a given id. These return NULL on failure. */ |
| 119 | const struct cbmem_entry *cbmem_entry_find(u32 id); |
| 120 | |
| 121 | /* Remove a region defined by a cbmem_entry. Returns 0 on success, < 0 on |
| 122 | * error. Note: A cbmem_entry cannot be removed unless it was the last one |
| 123 | * added. */ |
| 124 | int cbmem_entry_remove(const struct cbmem_entry *entry); |
| 125 | |
| 126 | /* cbmem_entry accessors to get pointer and size of a cbmem_entry. */ |
| 127 | void *cbmem_entry_start(const struct cbmem_entry *entry); |
| 128 | u64 cbmem_entry_size(const struct cbmem_entry *entry); |
| 129 | |
Aaron Durbin | df3a109 | 2013-03-13 12:41:44 -0500 | [diff] [blame] | 130 | |
| 131 | #else /* !CONFIG_DYNAMIC_CBMEM */ |
| 132 | |
Stefan Reinauer | 61f4a74 | 2012-04-03 16:21:04 -0700 | [diff] [blame] | 133 | #ifndef __PRE_RAM__ |
Kyösti Mälkki | 2b790f6 | 2013-09-03 05:25:57 +0300 | [diff] [blame] | 134 | void set_top_of_ram(uint64_t ramtop); |
Kyösti Mälkki | bc90e15 | 2013-09-04 13:26:11 +0300 | [diff] [blame] | 135 | void backup_top_of_ram(uint64_t ramtop); |
Kyösti Mälkki | 1ae305e | 2013-09-04 13:05:01 +0300 | [diff] [blame] | 136 | void cbmem_late_set_table(uint64_t base, uint64_t size); |
Kyösti Mälkki | e1ea802 | 2013-09-04 14:11:08 +0300 | [diff] [blame] | 137 | int cbmem_base_check(void); |
Stefan Reinauer | 61f4a74 | 2012-04-03 16:21:04 -0700 | [diff] [blame] | 138 | #endif |
| 139 | |
Kyösti Mälkki | d50cdf1 | 2013-06-23 17:01:29 +0300 | [diff] [blame] | 140 | int cbmem_reinit(void); |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 141 | |
Kyösti Mälkki | c04afd6 | 2013-09-04 13:31:39 +0300 | [diff] [blame] | 142 | void get_cbmem_table(uint64_t *base, uint64_t *size); |
Kyösti Mälkki | f9f74af | 2013-09-06 10:46:22 +0300 | [diff] [blame] | 143 | struct cbmem_entry *get_cbmem_toc(void); |
Rudolf Marek | 475916d | 2010-12-13 20:02:23 +0000 | [diff] [blame] | 144 | |
Aaron Durbin | df3a109 | 2013-03-13 12:41:44 -0500 | [diff] [blame] | 145 | #endif /* CONFIG_DYNAMIC_CBMEM */ |
| 146 | |
| 147 | /* Common API between cbmem and dynamic cbmem. */ |
| 148 | |
Kyösti Mälkki | dcb688e | 2013-09-04 01:11:16 +0300 | [diff] [blame] | 149 | unsigned long get_top_of_ram(void); |
| 150 | |
Aaron Durbin | df3a109 | 2013-03-13 12:41:44 -0500 | [diff] [blame] | 151 | /* By default cbmem is attempted to be recovered. Returns 0 if cbmem was |
| 152 | * recovered or 1 if cbmem had to be reinitialized. */ |
| 153 | int cbmem_initialize(void); |
| 154 | /* Add a cbmem entry of a given size and id. These return NULL on failure. The |
| 155 | * add function performs a find first and do not check against the original |
| 156 | * size. */ |
| 157 | void *cbmem_add(u32 id, u64 size); |
| 158 | /* Find a cbmem entry of a given id. These return NULL on failure. */ |
| 159 | void *cbmem_find(u32 id); |
| 160 | |
Rudolf Marek | 3310934 | 2010-12-11 22:26:10 +0000 | [diff] [blame] | 161 | #ifndef __PRE_RAM__ |
Aaron Durbin | df3a109 | 2013-03-13 12:41:44 -0500 | [diff] [blame] | 162 | /* Ramstage only functions. */ |
Kyösti Mälkki | e1ea802 | 2013-09-04 14:11:08 +0300 | [diff] [blame] | 163 | /* Add the cbmem memory used to the memory tables. */ |
| 164 | struct lb_memory; |
| 165 | void cbmem_add_lb_mem(struct lb_memory *mem); |
Aaron Durbin | df3a109 | 2013-03-13 12:41:44 -0500 | [diff] [blame] | 166 | void cbmem_list(void); |
| 167 | void cbmem_arch_init(void); |
Aaron Durbin | df3a109 | 2013-03-13 12:41:44 -0500 | [diff] [blame] | 168 | void cbmem_print_entry(int n, u32 id, u64 start, u64 size); |
Kyösti Mälkki | cb28f3f | 2014-01-03 15:15:22 +0200 | [diff] [blame^] | 169 | void cbmem_fail_resume(void); |
Aaron Durbin | df3a109 | 2013-03-13 12:41:44 -0500 | [diff] [blame] | 170 | #else |
| 171 | static inline void cbmem_arch_init(void) {} |
Kyösti Mälkki | cb28f3f | 2014-01-03 15:15:22 +0200 | [diff] [blame^] | 172 | static inline void cbmem_fail_resume(void) {} |
Aaron Durbin | df3a109 | 2013-03-13 12:41:44 -0500 | [diff] [blame] | 173 | #endif /* __PRE_RAM__ */ |
| 174 | |
| 175 | #endif /* __ASSEMBLER__ */ |
| 176 | |
| 177 | |
| 178 | #endif /* _CBMEM_H_ */ |