summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorGabe Black <gabeblack@chromium.org>2011-10-07 06:42:56 -0700
committerGabe Black (Do Not Use) <gabeblack@google.com>2011-10-11 16:08:13 -0700
commitcfb04c97ca4d3e6fb7e365dc784a044c813cac1a (patch)
tree908a845d4f9ae120a9d163c95564a0cf7d45132d /include
parent382230dc8b04fd4d3282223bc63609044ec16346 (diff)
Refactor the memory wipe infrastructure to better support x86
The memory wipe infrastructure in u-boot makes some assumptions about how memory is arranged that make it not quite fit with x86. Specifically, it assumes that there is a single region of memory, and with certain exceptions that's what should be wiped. In x86, specifically in the e820 map, there are multiple regions of RAM, possibly multiple regions to exclued from that that may completely, partially, or not overlap with the others, and then u-boot related regions. This is addressed by making the memory wipe infrastructure a little more generic. Now, areas can be added and subtracted arbitrarily, and will accumulate in the order they're encountered. In the x86 use case, we can add the e820 regions marked as RAM, subtract the areas marked as anything else, and subtract the u-boot related regions. Rather than tracking the actual regions of the address space, this implementation tracks the boundaries between the regions using a linked list. The code itself is short and relatively simple, and I tried to ensure that it was as clear as possible to make any memory (or other) bugs easier to see and fix. BUG=chrome-os-partner:6195 BUG=chrome-os-partner:6194 TEST=Built and booted on kaen using the A-A cable. Ran vboot_test memwipe, and a modified version that took advantage of the new API. Change-Id: I122fbf499ef473350afa27b612cb0e565366b1ad Signed-off-by: Gabe Black <gabeblack@google.com> Reviewed-on: http://gerrit.chromium.org/gerrit/9715 Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'include')
-rw-r--r--include/chromeos/memory_wipe.h47
1 files changed, 32 insertions, 15 deletions
diff --git a/include/chromeos/memory_wipe.h b/include/chromeos/memory_wipe.h
index 5ce0913b75..cc3535a1ba 100644
--- a/include/chromeos/memory_wipe.h
+++ b/include/chromeos/memory_wipe.h
@@ -23,32 +23,49 @@
#include <linux/types.h>
-#define MAX_EXCLUDED_REGIONS 16
+/* A node in a linked list of edges, each at position "pos". */
+typedef struct memory_wipe_edge_t {
+ struct memory_wipe_edge_t *next;
+ uintptr_t pos;
+} memory_wipe_edge_t;
-typedef struct {
- uintptr_t start;
- uintptr_t end;
-} memory_region_t;
-
-typedef struct {
- memory_region_t whole;
- memory_region_t excluded[MAX_EXCLUDED_REGIONS];
- int excluded_count;
+/*
+ * Data describing memory to wipe. Contains a linked list of edges between the
+ * regions of memory to wipe and not wipe.
+ */
+typedef struct memory_wipe_t {
+ memory_wipe_edge_t head;
} memory_wipe_t;
/*
* Initializes the memory region that needs to be cleared.
+ *
+ * @param wipe Wipe structure to initialize.
+ */
+void memory_wipe_init(memory_wipe_t *wipe);
+
+/*
+ * Adds a memory region to be cleared.
+ *
+ * @param wipe Wipe structure to add the region to.
+ * @param start The start of the region.
+ * @param end The end of the region.
*/
-void memory_wipe_init(memory_wipe_t *wipe, uintptr_t start, uintptr_t end);
+void memory_wipe_add(memory_wipe_t *wipe, uintptr_t start, uintptr_t end);
/*
- * Excludes a memory region from the to-be-cleared region.
- * The function returns 0 on success; otherwise -1.
+ * Subtracts a memory region.
+ *
+ * @param wipe Wipe structure to subtract the region from.
+ * @param start The start of the region.
+ * @param end The end of the region.
*/
-int memory_wipe_exclude(memory_wipe_t *wipe, uintptr_t start, uintptr_t end);
+void memory_wipe_sub(memory_wipe_t *wipe, uintptr_t start, uintptr_t end);
/*
- * Executes the memory wipe to the memory regions which was not excluded.
+ * Executes the memory wipe.
+ *
+ * @param wipe Wipe structure to execute.
*/
void memory_wipe_execute(memory_wipe_t *wipe);