summaryrefslogtreecommitdiff
path: root/src/include/cbmem.h
diff options
context:
space:
mode:
authorAaron Durbin <adurbin@chromium.org>2013-03-13 12:41:44 -0500
committerRonald G. Minnich <rminnich@gmail.com>2013-03-21 23:24:19 +0100
commitdf3a109b72907419d503c81257ea241becdbb915 (patch)
tree67bcee2a58edad01ab3cb4224b9ed338ed4d36e8 /src/include/cbmem.h
parentc3221183ee4c5280103238a0068086479cf31ded (diff)
cbmem: dynamic cbmem support
This patch adds a parallel implementation of cbmem that supports dynamic sizing. The original implementation relied on reserving a fixed-size block of memory for adding cbmem entries. In order to allow for more flexibility for adding cbmem allocations the dynamic cbmem infrastructure was developed as an alternative to the fixed block approach. Also, the amount of memory to reserve for cbmem allocations does not need to be known prior to the first allocation. The dynamic cbmem code implements the same API as the existing cbmem code except for cbmem_init() and cbmem_reinit(). The add and find routines behave the same way. The dynamic cbmem infrastructure uses a top down allocator that starts allocating from a board/chipset defined function cbmem_top(). A root pointer lives just below cbmem_top(). In turn that pointer points to the root block which contains the entries for all the large alloctations. The corresponding block for each large allocation falls just below the previous entry. It should be noted that this implementation rounds all allocations up to a 4096 byte granularity. Though a packing allocator could be written for small allocations it was deemed OK to just fragment the memory as there shouldn't be that many small allocations. The result is less code with a tradeoff of some wasted memory. +----------------------+ <- cbmem_top() | +----| root pointer | | | +----------------------+ | | | |--------+ | +--->| root block |-----+ | | +----------------------+ | | | | | | | | | | | | | | alloc N |<----+ | | +----------------------+ | | | | | | | | | \|/ | alloc N + 1 |<-------+ v +----------------------+ In addition to preserving the previous cbmem API, the dynamic cbmem API allows for removing blocks from cbmem. This allows for the boot process to allocate memory that can be discarded after it's been used for performing more complex boot tasks in romstage. In order to plumb this support in there were some issues to work around regarding writing of coreboot tables. There were a few assumptions to how cbmem was layed out which dictated some ifdef guarding and other runtime checks so as not to incorrectly tag the e820 and coreboot memory tables. The example shown below is using dynamic cbmem infrastructure. The reserved memory for cbmem is less than 512KiB. coreboot memory table: 0. 0000000000000000-0000000000000fff: CONFIGURATION TABLES 1. 0000000000001000-000000000002ffff: RAM 2. 0000000000030000-000000000003ffff: RESERVED 3. 0000000000040000-000000000009ffff: RAM 4. 00000000000a0000-00000000000fffff: RESERVED 5. 0000000000100000-0000000000efffff: RAM 6. 0000000000f00000-0000000000ffffff: RESERVED 7. 0000000001000000-000000007bf80fff: RAM 8. 000000007bf81000-000000007bffffff: CONFIGURATION TABLES 9. 000000007c000000-000000007e9fffff: RESERVED 10. 00000000f0000000-00000000f3ffffff: RESERVED 11. 00000000fed10000-00000000fed19fff: RESERVED 12. 00000000fed84000-00000000fed84fff: RESERVED 13. 0000000100000000-00000001005fffff: RAM Wrote coreboot table at: 7bf81000, 0x39c bytes, checksum f5bf coreboot table: 948 bytes. CBMEM ROOT 0. 7bfff000 00001000 MRC DATA 1. 7bffe000 00001000 ROMSTAGE 2. 7bffd000 00001000 TIME STAMP 3. 7bffc000 00001000 ROMSTG STCK 4. 7bff7000 00005000 CONSOLE 5. 7bfe7000 00010000 VBOOT 6. 7bfe6000 00001000 RAMSTAGE 7. 7bf98000 0004e000 GDT 8. 7bf97000 00001000 ACPI 9. 7bf8b000 0000c000 ACPI GNVS 10. 7bf8a000 00001000 SMBIOS 11. 7bf89000 00001000 COREBOOT 12. 7bf81000 00008000 And the corresponding e820 entries: BIOS-e820: [mem 0x0000000000000000-0x0000000000000fff] type 16 BIOS-e820: [mem 0x0000000000001000-0x000000000002ffff] usable BIOS-e820: [mem 0x0000000000030000-0x000000000003ffff] reserved BIOS-e820: [mem 0x0000000000040000-0x000000000009ffff] usable BIOS-e820: [mem 0x00000000000a0000-0x00000000000fffff] reserved BIOS-e820: [mem 0x0000000000100000-0x0000000000efffff] usable BIOS-e820: [mem 0x0000000000f00000-0x0000000000ffffff] reserved BIOS-e820: [mem 0x0000000001000000-0x000000007bf80fff] usable BIOS-e820: [mem 0x000000007bf81000-0x000000007bffffff] type 16 BIOS-e820: [mem 0x000000007c000000-0x000000007e9fffff] reserved BIOS-e820: [mem 0x00000000f0000000-0x00000000f3ffffff] reserved BIOS-e820: [mem 0x00000000fed10000-0x00000000fed19fff] reserved BIOS-e820: [mem 0x00000000fed84000-0x00000000fed84fff] reserved BIOS-e820: [mem 0x0000000100000000-0x00000001005fffff] usable Change-Id: Ie3bca52211800a8652a77ca684140cfc9b3b9a6b Signed-off-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: http://review.coreboot.org/2848 Tested-by: build bot (Jenkins) Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
Diffstat (limited to 'src/include/cbmem.h')
-rw-r--r--src/include/cbmem.h104
1 files changed, 95 insertions, 9 deletions
diff --git a/src/include/cbmem.h b/src/include/cbmem.h
index 1212cb2655..41f5971c80 100644
--- a/src/include/cbmem.h
+++ b/src/include/cbmem.h
@@ -2,6 +2,7 @@
* This file is part of the coreboot project.
*
* Copyright (C) 2009 coresystems GmbH
+ * Copyright (C) 2013 Google, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -62,9 +63,72 @@
#define CBMEM_ID_ELOG 0x454c4f47
#define CBMEM_ID_COVERAGE 0x47434f56
#define CBMEM_ID_ROMSTAGE_INFO 0x47545352
+#define CBMEM_ID_ROMSTAGE_RAM_STACK 0x90357ac4
+#define CBMEM_ID_RAMSTAGE 0x9a357a9e
+#define CBMEM_ID_RAMSTAGE_CACHE 0x9a3ca54e
+#define CBMEM_ID_ROOT 0xff4007ff
#define CBMEM_ID_NONE 0x00000000
#ifndef __ASSEMBLER__
+#include <stdint.h>
+
+struct cbmem_entry;
+
+#if CONFIG_DYNAMIC_CBMEM
+
+/*
+ * The dynamic cbmem infrastructure allows for growing cbmem dynamically as
+ * things are added. It requires an external function, cbmem_top(), to be
+ * implemented by the board or chipset to define the upper address where
+ * cbmem lives. This address is required to be a 32-bit address. Additionally,
+ * the address needs to be consistent in both romstage and ramstage. The
+ * dynamic cbmem infrasturue allocates new regions below the last allocated
+ * region. Regions are defined by a cbmem_entry struct that is opaque. Regions
+ * may be removed, but the last one added is the only that can be removed.
+ *
+ * Dynamic cbmem has two allocators within it. All allocators use a top down
+ * allocation scheme. However, there are 2 modes for each allocation depending
+ * on the requested size. There are large allocations and small allocations.
+ * An allocation is considered to be small when it is less than or equal to
+ * DYN_CBMEM_ALIGN_SIZE / 2. The smaller allocations are fit into a larger
+ * allocation region.
+ */
+
+#define DYN_CBMEM_ALIGN_SIZE (4096)
+
+/* Initialze cbmem to be empty. */
+void cbmem_initialize_empty(void);
+
+/* Return the top address for dynamic cbmem. The address returned needs to
+ * be consistent across romstage and ramstage, and it is required to be
+ * below 4GiB. */
+void *cbmem_top(void);
+
+/* Add a cbmem entry of a given size and id. These return NULL on failure. The
+ * add function performs a find first and do not check against the original
+ * size. */
+const struct cbmem_entry *cbmem_entry_add(u32 id, u64 size);
+
+/* Find a cbmem entry of a given id. These return NULL on failure. */
+const struct cbmem_entry *cbmem_entry_find(u32 id);
+
+/* Remove a region defined by a cbmem_entry. Returns 0 on success, < 0 on
+ * error. Note: A cbmem_entry cannot be removed unless it was the last one
+ * added. */
+int cbmem_entry_remove(const struct cbmem_entry *entry);
+
+/* cbmem_entry accessors to get pointer and size of a cbmem_entry. */
+void *cbmem_entry_start(const struct cbmem_entry *entry);
+u64 cbmem_entry_size(const struct cbmem_entry *entry);
+
+#ifndef __PRE_RAM__
+/* Add the cbmem memory used to the memory tables. */
+struct lb_memory;
+void cbmem_add_lb_mem(struct lb_memory *mem);
+#endif /* __PRE_RAM__ */
+
+#else /* !CONFIG_DYNAMIC_CBMEM */
+
#ifndef __PRE_RAM__
extern uint64_t high_tables_base, high_tables_size;
#if CONFIG_EARLY_CBMEM_INIT
@@ -72,22 +136,44 @@ extern uint64_t high_tables_base, high_tables_size;
int __attribute__((weak)) cbmem_get_table_location(uint64_t *tables_base,
uint64_t *tables_size);
#endif
+void set_cbmem_toc(struct cbmem_entry *);
#endif
-int cbmem_initialize(void);
-
void cbmem_init(u64 baseaddr, u64 size);
int cbmem_reinit(u64 baseaddr);
+
+extern struct cbmem_entry *get_cbmem_toc(void);
+
+#endif /* CONFIG_DYNAMIC_CBMEM */
+
+/* Common API between cbmem and dynamic cbmem. */
+
+/* By default cbmem is attempted to be recovered. Returns 0 if cbmem was
+ * recovered or 1 if cbmem had to be reinitialized. */
+int cbmem_initialize(void);
+/* Add a cbmem entry of a given size and id. These return NULL on failure. The
+ * add function performs a find first and do not check against the original
+ * size. */
void *cbmem_add(u32 id, u64 size);
+/* Find a cbmem entry of a given id. These return NULL on failure. */
void *cbmem_find(u32 id);
+
+#ifndef __PRE_RAM__
+/* Ramstage only functions. */
void cbmem_list(void);
void cbmem_arch_init(void);
+void __attribute__((weak)) cbmem_post_handling(void);
+void cbmem_print_entry(int n, u32 id, u64 start, u64 size);
+/* The pre|post device cbmem initialization functions are for the
+ * ramstage main to call. When cbmem is actually initialized depends on
+ * the cbmem implementation. */
+void init_cbmem_pre_device(void);
+void init_cbmem_post_device(void);
+#else
+static inline void cbmem_arch_init(void) {}
+#endif /* __PRE_RAM__ */
-extern struct cbmem_entry *get_cbmem_toc(void);
+#endif /* __ASSEMBLER__ */
-#ifndef __PRE_RAM__
-void set_cbmem_toc(struct cbmem_entry *);
-void __attribute__((weak)) cbmem_post_handling(void);
-#endif
-#endif
-#endif
+
+#endif /* _CBMEM_H_ */