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 |
Patrick Georgi | b890a12 | 2015-03-26 15:17:45 +0100 | [diff] [blame^] | 18 | * Foundation, Inc. |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #ifndef _CBMEM_H_ |
| 22 | #define _CBMEM_H_ |
| 23 | |
Kyösti Mälkki | 2ca2afe | 2014-06-17 15:41:37 +0300 | [diff] [blame] | 24 | #if IS_ENABLED(CONFIG_HAVE_ACPI_RESUME) && \ |
| 25 | ! IS_ENABLED(CONFIG_RELOCATABLE_RAMSTAGE) |
zbao | f722373 | 2012-04-13 13:42:15 +0800 | [diff] [blame] | 26 | #define HIGH_MEMORY_SAVE (CONFIG_RAMTOP - CONFIG_RAMBASE) |
Kyösti Mälkki | 2ca2afe | 2014-06-17 15:41:37 +0300 | [diff] [blame] | 27 | #else |
| 28 | #define HIGH_MEMORY_SAVE 0 |
| 29 | #endif |
| 30 | |
| 31 | #if IS_ENABLED(CONFIG_HAVE_ACPI_RESUME) && \ |
Kyösti Mälkki | b393fa0 | 2014-06-21 23:50:53 +0300 | [diff] [blame] | 32 | defined(CONFIG_HIGH_SCRATCH_MEMORY_SIZE) |
Kyösti Mälkki | 2ca2afe | 2014-06-17 15:41:37 +0300 | [diff] [blame] | 33 | #define HIGH_MEMORY_SCRATCH CONFIG_HIGH_SCRATCH_MEMORY_SIZE |
| 34 | #else |
| 35 | #define HIGH_MEMORY_SCRATCH 0 |
Aaron Durbin | 8e4a355 | 2013-02-08 17:28:04 -0600 | [diff] [blame] | 36 | #endif |
| 37 | |
Stefan Reinauer | 61f4a74 | 2012-04-03 16:21:04 -0700 | [diff] [blame] | 38 | /* Delegation of resume backup memory so we don't have to |
| 39 | * (slowly) handle backing up OS memory in romstage.c |
| 40 | */ |
| 41 | #define CBMEM_BOOT_MODE 0x610 |
| 42 | #define CBMEM_RESUME_BACKUP 0x614 |
Martin Roth | 582b2ae | 2015-01-11 14:29:29 -0700 | [diff] [blame] | 43 | #define CBMEM_FSP_HOB_PTR 0x614 |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 44 | |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 45 | #define CBMEM_ID_ACPI 0x41435049 |
Duncan Laurie | 11290c4 | 2012-10-03 19:07:05 -0700 | [diff] [blame] | 46 | #define CBMEM_ID_ACPI_GNVS 0x474e5653 |
Duncan Laurie | 9c07c8f | 2013-03-22 11:08:39 -0700 | [diff] [blame] | 47 | #define CBMEM_ID_ACPI_GNVS_PTR 0x474e5650 |
Vadim Bendebury | f92edfe | 2014-10-23 10:21:52 -0700 | [diff] [blame] | 48 | #define CBMEM_ID_AGESA_RUNTIME 0x41474553 |
| 49 | #define CBMEM_ID_AMDMCT_MEMINFO 0x494D454E |
| 50 | #define CBMEM_ID_CAR_GLOBALS 0xcac4e6a3 |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 51 | #define CBMEM_ID_CBTABLE 0x43425442 |
Vadim Bendebury | be25a4d | 2011-09-30 11:13:06 -0700 | [diff] [blame] | 52 | #define CBMEM_ID_CONSOLE 0x434f4e53 |
Stefan Reinauer | d37ab45 | 2012-12-18 16:23:28 -0800 | [diff] [blame] | 53 | #define CBMEM_ID_COVERAGE 0x47434f56 |
Vadim Bendebury | f92edfe | 2014-10-23 10:21:52 -0700 | [diff] [blame] | 54 | #define CBMEM_ID_EHCI_DEBUG 0xe4c1deb9 |
| 55 | #define CBMEM_ID_ELOG 0x454c4f47 |
| 56 | #define CBMEM_ID_FREESPACE 0x46524545 |
Lee Leahy | bdd9825 | 2015-04-28 18:21:25 -0700 | [diff] [blame] | 57 | #define CBMEM_ID_FSP_RESERVED_MEMORY 0x46535052 |
| 58 | #define CBMEM_ID_FSP_RUNTIME 0x52505346 |
Vadim Bendebury | f92edfe | 2014-10-23 10:21:52 -0700 | [diff] [blame] | 59 | #define CBMEM_ID_GDT 0x4c474454 |
| 60 | #define CBMEM_ID_HOB_POINTER 0x484f4221 |
| 61 | #define CBMEM_ID_IGD_OPREGION 0x4f444749 |
Aaron Durbin | 20686d8 | 2015-03-05 14:11:27 -0600 | [diff] [blame] | 62 | #define CBMEM_ID_IMD_ROOT 0xff4017ff |
Aaron Durbin | cac5050 | 2015-03-24 23:14:46 -0500 | [diff] [blame] | 63 | #define CBMEM_ID_IMD_SMALL 0x53a11439 |
Vadim Bendebury | f92edfe | 2014-10-23 10:21:52 -0700 | [diff] [blame] | 64 | #define CBMEM_ID_MEMINFO 0x494D454D |
| 65 | #define CBMEM_ID_MPTABLE 0x534d5054 |
| 66 | #define CBMEM_ID_MRCDATA 0x4d524344 |
| 67 | #define CBMEM_ID_NONE 0x00000000 |
| 68 | #define CBMEM_ID_PIRQ 0x49525154 |
| 69 | #define CBMEM_ID_POWER_STATE 0x50535454 |
| 70 | #define CBMEM_ID_RAM_OOPS 0x05430095 |
Aaron Durbin | df3a109 | 2013-03-13 12:41:44 -0500 | [diff] [blame] | 71 | #define CBMEM_ID_RAMSTAGE 0x9a357a9e |
| 72 | #define CBMEM_ID_RAMSTAGE_CACHE 0x9a3ca54e |
Aaron Durbin | bf18b17 | 2013-10-24 10:11:08 -0500 | [diff] [blame] | 73 | #define CBMEM_ID_REFCODE 0x04efc0de |
| 74 | #define CBMEM_ID_REFCODE_CACHE 0x4efc0de5 |
Vadim Bendebury | f92edfe | 2014-10-23 10:21:52 -0700 | [diff] [blame] | 75 | #define CBMEM_ID_RESUME 0x5245534d |
| 76 | #define CBMEM_ID_RESUME_SCRATCH 0x52455343 |
| 77 | #define CBMEM_ID_ROMSTAGE_INFO 0x47545352 |
| 78 | #define CBMEM_ID_ROMSTAGE_RAM_STACK 0x90357ac4 |
| 79 | #define CBMEM_ID_ROOT 0xff4007ff |
| 80 | #define CBMEM_ID_SMBIOS 0x534d4254 |
Aaron Durbin | b4b9eb3 | 2014-02-13 10:26:18 -0600 | [diff] [blame] | 81 | #define CBMEM_ID_SMM_SAVE_SPACE 0x07e9acee |
Aaron Durbin | 5add435 | 2014-09-17 11:43:20 -0500 | [diff] [blame] | 82 | #define CBMEM_ID_SPINTABLE 0x59175917 |
Aaron Durbin | bd74a4b | 2015-03-06 23:17:33 -0600 | [diff] [blame] | 83 | #define CBMEM_ID_STAGEx_META 0x57a9e000 |
| 84 | #define CBMEM_ID_STAGEx_CACHE 0x57a9e100 |
Vadim Bendebury | f92edfe | 2014-10-23 10:21:52 -0700 | [diff] [blame] | 85 | #define CBMEM_ID_TIMESTAMP 0x54494d45 |
| 86 | #define CBMEM_ID_VBOOT_HANDOFF 0x780074f0 |
Aaron Durbin | 0e571fd | 2015-05-08 17:14:15 -0500 | [diff] [blame] | 87 | #define CBMEM_ID_VBOOT_WORKBUF 0x78007343 |
Vadim Bendebury | f92edfe | 2014-10-23 10:21:52 -0700 | [diff] [blame] | 88 | #define CBMEM_ID_WIFI_CALIBRATION 0x57494649 |
Stefan Reinauer | 3b31402 | 2009-10-26 17:04:28 +0000 | [diff] [blame] | 89 | |
Stefan Reinauer | 61f4a74 | 2012-04-03 16:21:04 -0700 | [diff] [blame] | 90 | #ifndef __ASSEMBLER__ |
Aaron Durbin | 0f33307 | 2014-01-30 17:19:46 -0600 | [diff] [blame] | 91 | #include <stddef.h> |
Aaron Durbin | df3a109 | 2013-03-13 12:41:44 -0500 | [diff] [blame] | 92 | #include <stdint.h> |
| 93 | |
Vadim Bendebury | 8b143c5 | 2014-05-14 10:12:55 -0700 | [diff] [blame] | 94 | #define CBMEM_ID_TO_NAME_TABLE \ |
Vadim Bendebury | 8b143c5 | 2014-05-14 10:12:55 -0700 | [diff] [blame] | 95 | { CBMEM_ID_ACPI, "ACPI " }, \ |
Vadim Bendebury | 8b143c5 | 2014-05-14 10:12:55 -0700 | [diff] [blame] | 96 | { CBMEM_ID_ACPI_GNVS, "ACPI GNVS " }, \ |
| 97 | { CBMEM_ID_ACPI_GNVS_PTR, "GNVS PTR " }, \ |
Vadim Bendebury | 8b143c5 | 2014-05-14 10:12:55 -0700 | [diff] [blame] | 98 | { CBMEM_ID_AGESA_RUNTIME, "AGESA RSVD " }, \ |
Vadim Bendebury | f92edfe | 2014-10-23 10:21:52 -0700 | [diff] [blame] | 99 | { CBMEM_ID_AMDMCT_MEMINFO, "AMDMEM INFO" }, \ |
| 100 | { CBMEM_ID_CAR_GLOBALS, "CAR GLOBALS" }, \ |
| 101 | { CBMEM_ID_CBTABLE, "COREBOOT " }, \ |
| 102 | { CBMEM_ID_CONSOLE, "CONSOLE " }, \ |
| 103 | { CBMEM_ID_COVERAGE, "COVERAGE " }, \ |
Vadim Bendebury | 8b143c5 | 2014-05-14 10:12:55 -0700 | [diff] [blame] | 104 | { CBMEM_ID_EHCI_DEBUG, "USBDEBUG " }, \ |
Vadim Bendebury | f92edfe | 2014-10-23 10:21:52 -0700 | [diff] [blame] | 105 | { CBMEM_ID_ELOG, "ELOG " }, \ |
| 106 | { CBMEM_ID_FREESPACE, "FREE SPACE " }, \ |
Lee Leahy | bdd9825 | 2015-04-28 18:21:25 -0700 | [diff] [blame] | 107 | { CBMEM_ID_FSP_RESERVED_MEMORY, "FSP MEMORY " }, \ |
| 108 | { CBMEM_ID_FSP_RUNTIME, "FSP RUNTIME" }, \ |
Vadim Bendebury | f92edfe | 2014-10-23 10:21:52 -0700 | [diff] [blame] | 109 | { CBMEM_ID_GDT, "GDT " }, \ |
Aaron Durbin | 20686d8 | 2015-03-05 14:11:27 -0600 | [diff] [blame] | 110 | { CBMEM_ID_IMD_ROOT, "IMD ROOT " }, \ |
Aaron Durbin | cac5050 | 2015-03-24 23:14:46 -0500 | [diff] [blame] | 111 | { CBMEM_ID_IMD_SMALL, "IMD SMALL " }, \ |
Vadim Bendebury | f92edfe | 2014-10-23 10:21:52 -0700 | [diff] [blame] | 112 | { CBMEM_ID_MEMINFO, "MEM INFO " }, \ |
| 113 | { CBMEM_ID_MPTABLE, "SMP TABLE " }, \ |
| 114 | { CBMEM_ID_MRCDATA, "MRC DATA " }, \ |
| 115 | { CBMEM_ID_PIRQ, "IRQ TABLE " }, \ |
Vadim Bendebury | 8b143c5 | 2014-05-14 10:12:55 -0700 | [diff] [blame] | 116 | { CBMEM_ID_POWER_STATE, "POWER STATE" }, \ |
Kane Chen | 33faac6 | 2014-07-27 12:54:44 -0700 | [diff] [blame] | 117 | { CBMEM_ID_RAM_OOPS, "RAMOOPS " }, \ |
Vadim Bendebury | f92edfe | 2014-10-23 10:21:52 -0700 | [diff] [blame] | 118 | { CBMEM_ID_RAMSTAGE_CACHE, "RAMSTAGE $ " }, \ |
| 119 | { CBMEM_ID_RAMSTAGE, "RAMSTAGE " }, \ |
| 120 | { CBMEM_ID_REFCODE_CACHE, "REFCODE $ " }, \ |
| 121 | { CBMEM_ID_REFCODE, "REFCODE " }, \ |
| 122 | { CBMEM_ID_RESUME, "ACPI RESUME" }, \ |
| 123 | { CBMEM_ID_RESUME_SCRATCH, "ACPISCRATCH" }, \ |
| 124 | { CBMEM_ID_ROMSTAGE_INFO, "ROMSTAGE " }, \ |
| 125 | { CBMEM_ID_ROMSTAGE_RAM_STACK, "ROMSTG STCK" }, \ |
| 126 | { CBMEM_ID_ROOT, "CBMEM ROOT " }, \ |
| 127 | { CBMEM_ID_SMBIOS, "SMBIOS " }, \ |
| 128 | { CBMEM_ID_SMM_SAVE_SPACE, "SMM BACKUP " }, \ |
| 129 | { CBMEM_ID_SPINTABLE, "SPIN TABLE " }, \ |
| 130 | { CBMEM_ID_TIMESTAMP, "TIME STAMP " }, \ |
| 131 | { CBMEM_ID_VBOOT_HANDOFF, "VBOOT " }, \ |
Aaron Durbin | 0e571fd | 2015-05-08 17:14:15 -0500 | [diff] [blame] | 132 | { CBMEM_ID_VBOOT_WORKBUF, "VBOOT WORK " }, \ |
Vadim Bendebury | f92edfe | 2014-10-23 10:21:52 -0700 | [diff] [blame] | 133 | { CBMEM_ID_WIFI_CALIBRATION, "WIFI CLBR " }, |
Vadim Bendebury | 8b143c5 | 2014-05-14 10:12:55 -0700 | [diff] [blame] | 134 | |
Aaron Durbin | df3a109 | 2013-03-13 12:41:44 -0500 | [diff] [blame] | 135 | struct cbmem_entry; |
| 136 | |
Aaron Durbin | df3a109 | 2013-03-13 12:41:44 -0500 | [diff] [blame] | 137 | /* |
| 138 | * The dynamic cbmem infrastructure allows for growing cbmem dynamically as |
| 139 | * things are added. It requires an external function, cbmem_top(), to be |
| 140 | * implemented by the board or chipset to define the upper address where |
| 141 | * cbmem lives. This address is required to be a 32-bit address. Additionally, |
| 142 | * the address needs to be consistent in both romstage and ramstage. The |
Martin Roth | 0cb07e3 | 2013-07-09 21:46:01 -0600 | [diff] [blame] | 143 | * dynamic cbmem infrastructure allocates new regions below the last allocated |
Aaron Durbin | df3a109 | 2013-03-13 12:41:44 -0500 | [diff] [blame] | 144 | * region. Regions are defined by a cbmem_entry struct that is opaque. Regions |
| 145 | * may be removed, but the last one added is the only that can be removed. |
Aaron Durbin | df3a109 | 2013-03-13 12:41:44 -0500 | [diff] [blame] | 146 | */ |
| 147 | |
| 148 | #define DYN_CBMEM_ALIGN_SIZE (4096) |
Lee Leahy | 522149c | 2015-05-08 11:33:55 -0700 | [diff] [blame] | 149 | #define CBMEM_ROOT_SIZE DYN_CBMEM_ALIGN_SIZE |
| 150 | |
| 151 | /* The root region is at least DYN_CBMEM_ALIGN_SIZE . */ |
| 152 | #define CBMEM_ROOT_MIN_SIZE DYN_CBMEM_ALIGN_SIZE |
| 153 | #define CBMEM_LG_ALIGN CBMEM_ROOT_MIN_SIZE |
| 154 | |
| 155 | /* Small allocation parameters. */ |
| 156 | #define CBMEM_SM_ROOT_SIZE 1024 |
| 157 | #define CBMEM_SM_ALIGN 32 |
| 158 | |
| 159 | /* Determine the size for CBMEM root and the small allocations */ |
| 160 | static inline size_t cbmem_overhead_size(void) |
| 161 | { |
| 162 | return 2 * CBMEM_ROOT_MIN_SIZE; |
| 163 | } |
Aaron Durbin | df3a109 | 2013-03-13 12:41:44 -0500 | [diff] [blame] | 164 | |
Kyösti Mälkki | 2d8520b | 2014-01-06 17:20:31 +0200 | [diff] [blame] | 165 | /* By default cbmem is attempted to be recovered. Returns 0 if cbmem was |
| 166 | * recovered or 1 if cbmem had to be reinitialized. */ |
| 167 | int cbmem_initialize(void); |
Lee Leahy | 522149c | 2015-05-08 11:33:55 -0700 | [diff] [blame] | 168 | int cbmem_initialize_id_size(u32 id, u64 size); |
| 169 | |
Martin Roth | 0cb07e3 | 2013-07-09 21:46:01 -0600 | [diff] [blame] | 170 | /* Initialize cbmem to be empty. */ |
Aaron Durbin | df3a109 | 2013-03-13 12:41:44 -0500 | [diff] [blame] | 171 | void cbmem_initialize_empty(void); |
Lee Leahy | 522149c | 2015-05-08 11:33:55 -0700 | [diff] [blame] | 172 | void cbmem_initialize_empty_id_size(u32 id, u64 size); |
Aaron Durbin | df3a109 | 2013-03-13 12:41:44 -0500 | [diff] [blame] | 173 | |
| 174 | /* Return the top address for dynamic cbmem. The address returned needs to |
| 175 | * be consistent across romstage and ramstage, and it is required to be |
| 176 | * below 4GiB. */ |
| 177 | void *cbmem_top(void); |
| 178 | |
Kyösti Mälkki | 2fb6b40 | 2014-12-19 08:20:45 +0200 | [diff] [blame] | 179 | /* Set the top address for dynamic cbmem. Not for new designs. */ |
| 180 | void cbmem_set_top(void *ramtop); |
| 181 | |
Aaron Durbin | df3a109 | 2013-03-13 12:41:44 -0500 | [diff] [blame] | 182 | /* Add a cbmem entry of a given size and id. These return NULL on failure. The |
| 183 | * add function performs a find first and do not check against the original |
| 184 | * size. */ |
| 185 | const struct cbmem_entry *cbmem_entry_add(u32 id, u64 size); |
| 186 | |
| 187 | /* Find a cbmem entry of a given id. These return NULL on failure. */ |
| 188 | const struct cbmem_entry *cbmem_entry_find(u32 id); |
| 189 | |
| 190 | /* Remove a region defined by a cbmem_entry. Returns 0 on success, < 0 on |
| 191 | * error. Note: A cbmem_entry cannot be removed unless it was the last one |
| 192 | * added. */ |
| 193 | int cbmem_entry_remove(const struct cbmem_entry *entry); |
| 194 | |
| 195 | /* cbmem_entry accessors to get pointer and size of a cbmem_entry. */ |
| 196 | void *cbmem_entry_start(const struct cbmem_entry *entry); |
| 197 | u64 cbmem_entry_size(const struct cbmem_entry *entry); |
| 198 | |
Kyösti Mälkki | 2d8520b | 2014-01-06 17:20:31 +0200 | [diff] [blame] | 199 | /* Returns 0 if old cbmem was recovered. Recovery is only attempted if |
| 200 | * s3resume is non-zero. */ |
| 201 | int cbmem_recovery(int s3resume); |
Aaron Durbin | df3a109 | 2013-03-13 12:41:44 -0500 | [diff] [blame] | 202 | /* Add a cbmem entry of a given size and id. These return NULL on failure. The |
| 203 | * add function performs a find first and do not check against the original |
| 204 | * size. */ |
| 205 | void *cbmem_add(u32 id, u64 size); |
| 206 | /* Find a cbmem entry of a given id. These return NULL on failure. */ |
| 207 | void *cbmem_find(u32 id); |
| 208 | |
Kyösti Mälkki | 823edda | 2014-12-18 18:30:29 +0200 | [diff] [blame] | 209 | void cbmem_run_init_hooks(void); |
| 210 | void cbmem_fail_resume(void); |
| 211 | |
Rudolf Marek | 3310934 | 2010-12-11 22:26:10 +0000 | [diff] [blame] | 212 | #ifndef __PRE_RAM__ |
Aaron Durbin | df3a109 | 2013-03-13 12:41:44 -0500 | [diff] [blame] | 213 | /* Ramstage only functions. */ |
Aaron Durbin | 4904802 | 2014-02-18 21:55:02 -0600 | [diff] [blame] | 214 | /* Add the cbmem memory used to the memory map at boot. */ |
| 215 | void cbmem_add_bootmem(void); |
Aaron Durbin | df3a109 | 2013-03-13 12:41:44 -0500 | [diff] [blame] | 216 | void cbmem_list(void); |
Aaron Durbin | df3a109 | 2013-03-13 12:41:44 -0500 | [diff] [blame] | 217 | #endif /* __PRE_RAM__ */ |
| 218 | |
Kyösti Mälkki | 2fb6b40 | 2014-12-19 08:20:45 +0200 | [diff] [blame] | 219 | /* These are for compatibility with old boards only. Any new chipset and board |
| 220 | * must implement cbmem_top() for both romstage and ramstage to support |
| 221 | * early features like COLLECT_TIMESTAMPS and CBMEM_CONSOLE. |
| 222 | */ |
| 223 | #if IS_ENABLED(CONFIG_ARCH_X86) && IS_ENABLED(CONFIG_LATE_CBMEM_INIT) |
| 224 | unsigned long get_top_of_ram(void); |
| 225 | void set_top_of_ram(uint64_t ramtop); |
| 226 | void backup_top_of_ram(uint64_t ramtop); |
| 227 | #endif |
| 228 | |
Aaron Durbin | df3a109 | 2013-03-13 12:41:44 -0500 | [diff] [blame] | 229 | #endif /* __ASSEMBLER__ */ |
| 230 | |
| 231 | |
| 232 | #endif /* _CBMEM_H_ */ |