blob: 5b19207d070f475c07325b6d52e82be7efdf8f2c [file] [log] [blame]
Stefan Reinauer3b314022009-10-26 17:04:28 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2009 coresystems GmbH
Aaron Durbindf3a1092013-03-13 12:41:44 -05005 * Copyright (C) 2013 Google, Inc.
Stefan Reinauer3b314022009-10-26 17:04:28 +00006 *
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 Reinauer294edb22011-08-14 13:52:03 -070024/* Reserve 128k for ACPI and other tables */
Vadim Bendeburyf2f93862011-10-04 10:44:16 -070025#if CONFIG_CONSOLE_CBMEM
26#define HIGH_MEMORY_DEF_SIZE ( 256 * 1024 )
27#else
Stefan Reinauer294edb22011-08-14 13:52:03 -070028#define HIGH_MEMORY_DEF_SIZE ( 128 * 1024 )
Vadim Bendeburyf2f93862011-10-04 10:44:16 -070029#endif
30
Stefan Reinauer3b314022009-10-26 17:04:28 +000031#if CONFIG_HAVE_ACPI_RESUME
Aaron Durbin8e4a3552013-02-08 17:28:04 -060032#if CONFIG_RELOCATABLE_RAMSTAGE
33#define HIGH_MEMORY_SAVE 0
34#else
zbaof7223732012-04-13 13:42:15 +080035#define HIGH_MEMORY_SAVE (CONFIG_RAMTOP - CONFIG_RAMBASE)
Aaron Durbin8e4a3552013-02-08 17:28:04 -060036#endif
37
zbaof7223732012-04-13 13:42:15 +080038#define HIGH_MEMORY_SIZE (HIGH_MEMORY_SAVE + CONFIG_HIGH_SCRATCH_MEMORY_SIZE + HIGH_MEMORY_DEF_SIZE)
Stefan Reinauer61f4a742012-04-03 16:21:04 -070039
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
zbaof7223732012-04-13 13:42:15 +080045
46#else /* CONFIG_HAVE_ACPI_RESUME */
Rudolf Marek97be27e2010-12-13 19:50:25 +000047#define HIGH_MEMORY_SIZE HIGH_MEMORY_DEF_SIZE
zbaof7223732012-04-13 13:42:15 +080048#endif /* CONFIG_HAVE_ACPI_RESUME */
Stefan Reinauer3b314022009-10-26 17:04:28 +000049
50#define CBMEM_ID_FREESPACE 0x46524545
51#define CBMEM_ID_GDT 0x4c474454
52#define CBMEM_ID_ACPI 0x41435049
Duncan Laurie11290c42012-10-03 19:07:05 -070053#define CBMEM_ID_ACPI_GNVS 0x474e5653
Stefan Reinauer3b314022009-10-26 17:04:28 +000054#define CBMEM_ID_CBTABLE 0x43425442
55#define CBMEM_ID_PIRQ 0x49525154
56#define CBMEM_ID_MPTABLE 0x534d5054
57#define CBMEM_ID_RESUME 0x5245534d
zbaof7223732012-04-13 13:42:15 +080058#define CBMEM_ID_RESUME_SCRATCH 0x52455343
Sven Schnelle164bcfd2011-08-14 20:56:34 +020059#define CBMEM_ID_SMBIOS 0x534d4254
Vadim Bendebury6f72d692011-09-21 16:12:39 -070060#define CBMEM_ID_TIMESTAMP 0x54494d45
Stefan Reinauer61f4a742012-04-03 16:21:04 -070061#define CBMEM_ID_MRCDATA 0x4d524344
Vadim Bendeburybe25a4d2011-09-30 11:13:06 -070062#define CBMEM_ID_CONSOLE 0x434f4e53
Duncan Laurie215f27852012-10-10 14:34:49 -070063#define CBMEM_ID_ELOG 0x454c4f47
Stefan Reinauerd37ab452012-12-18 16:23:28 -080064#define CBMEM_ID_COVERAGE 0x47434f56
Aaron Durbina1db81b42013-02-08 17:11:28 -060065#define CBMEM_ID_ROMSTAGE_INFO 0x47545352
Aaron Durbindf3a1092013-03-13 12:41:44 -050066#define CBMEM_ID_ROMSTAGE_RAM_STACK 0x90357ac4
67#define CBMEM_ID_RAMSTAGE 0x9a357a9e
68#define CBMEM_ID_RAMSTAGE_CACHE 0x9a3ca54e
69#define CBMEM_ID_ROOT 0xff4007ff
Aaron Durbin0c6946d2013-03-13 12:48:33 -050070#define CBMEM_ID_VBOOT_HANDOFF 0x780074f0
Stefan Reinauer3b314022009-10-26 17:04:28 +000071#define CBMEM_ID_NONE 0x00000000
72
Stefan Reinauer61f4a742012-04-03 16:21:04 -070073#ifndef __ASSEMBLER__
Aaron Durbindf3a1092013-03-13 12:41:44 -050074#include <stdint.h>
75
76struct cbmem_entry;
77
78#if CONFIG_DYNAMIC_CBMEM
79
80/*
81 * The dynamic cbmem infrastructure allows for growing cbmem dynamically as
82 * things are added. It requires an external function, cbmem_top(), to be
83 * implemented by the board or chipset to define the upper address where
84 * cbmem lives. This address is required to be a 32-bit address. Additionally,
85 * the address needs to be consistent in both romstage and ramstage. The
86 * dynamic cbmem infrasturue allocates new regions below the last allocated
87 * region. Regions are defined by a cbmem_entry struct that is opaque. Regions
88 * may be removed, but the last one added is the only that can be removed.
89 *
90 * Dynamic cbmem has two allocators within it. All allocators use a top down
91 * allocation scheme. However, there are 2 modes for each allocation depending
92 * on the requested size. There are large allocations and small allocations.
93 * An allocation is considered to be small when it is less than or equal to
94 * DYN_CBMEM_ALIGN_SIZE / 2. The smaller allocations are fit into a larger
95 * allocation region.
96 */
97
98#define DYN_CBMEM_ALIGN_SIZE (4096)
99
100/* Initialze cbmem to be empty. */
101void cbmem_initialize_empty(void);
102
103/* Return the top address for dynamic cbmem. The address returned needs to
104 * be consistent across romstage and ramstage, and it is required to be
105 * below 4GiB. */
106void *cbmem_top(void);
107
108/* Add a cbmem entry of a given size and id. These return NULL on failure. The
109 * add function performs a find first and do not check against the original
110 * size. */
111const struct cbmem_entry *cbmem_entry_add(u32 id, u64 size);
112
113/* Find a cbmem entry of a given id. These return NULL on failure. */
114const struct cbmem_entry *cbmem_entry_find(u32 id);
115
116/* Remove a region defined by a cbmem_entry. Returns 0 on success, < 0 on
117 * error. Note: A cbmem_entry cannot be removed unless it was the last one
118 * added. */
119int cbmem_entry_remove(const struct cbmem_entry *entry);
120
121/* cbmem_entry accessors to get pointer and size of a cbmem_entry. */
122void *cbmem_entry_start(const struct cbmem_entry *entry);
123u64 cbmem_entry_size(const struct cbmem_entry *entry);
124
125#ifndef __PRE_RAM__
126/* Add the cbmem memory used to the memory tables. */
127struct lb_memory;
128void cbmem_add_lb_mem(struct lb_memory *mem);
129#endif /* __PRE_RAM__ */
130
131#else /* !CONFIG_DYNAMIC_CBMEM */
132
Stefan Reinauer61f4a742012-04-03 16:21:04 -0700133#ifndef __PRE_RAM__
134extern uint64_t high_tables_base, high_tables_size;
Aaron Durbindf3a1092013-03-13 12:41:44 -0500135void set_cbmem_toc(struct cbmem_entry *);
Stefan Reinauer61f4a742012-04-03 16:21:04 -0700136#endif
137
Stefan Reinauer3b314022009-10-26 17:04:28 +0000138void cbmem_init(u64 baseaddr, u64 size);
139int cbmem_reinit(u64 baseaddr);
Stefan Reinauer3b314022009-10-26 17:04:28 +0000140
Rudolf Marek475916d2010-12-13 20:02:23 +0000141extern struct cbmem_entry *get_cbmem_toc(void);
142
Aaron Durbindf3a1092013-03-13 12:41:44 -0500143#endif /* CONFIG_DYNAMIC_CBMEM */
144
145/* Common API between cbmem and dynamic cbmem. */
146
147/* By default cbmem is attempted to be recovered. Returns 0 if cbmem was
148 * recovered or 1 if cbmem had to be reinitialized. */
149int cbmem_initialize(void);
150/* Add a cbmem entry of a given size and id. These return NULL on failure. The
151 * add function performs a find first and do not check against the original
152 * size. */
153void *cbmem_add(u32 id, u64 size);
154/* Find a cbmem entry of a given id. These return NULL on failure. */
155void *cbmem_find(u32 id);
156
Rudolf Marek33109342010-12-11 22:26:10 +0000157#ifndef __PRE_RAM__
Aaron Durbindf3a1092013-03-13 12:41:44 -0500158/* Ramstage only functions. */
159void cbmem_list(void);
160void cbmem_arch_init(void);
Stefan Reinauerbb11e602012-05-10 12:15:18 -0700161void __attribute__((weak)) cbmem_post_handling(void);
Aaron Durbindf3a1092013-03-13 12:41:44 -0500162void cbmem_print_entry(int n, u32 id, u64 start, u64 size);
163/* The pre|post device cbmem initialization functions are for the
164 * ramstage main to call. When cbmem is actually initialized depends on
165 * the cbmem implementation. */
166void init_cbmem_pre_device(void);
167void init_cbmem_post_device(void);
168#else
169static inline void cbmem_arch_init(void) {}
170#endif /* __PRE_RAM__ */
171
172#endif /* __ASSEMBLER__ */
173
174
175#endif /* _CBMEM_H_ */