From 1b915b89044c06ae7957544b97d6c30d496366e0 Mon Sep 17 00:00:00 2001 From: Aaron Durbin Date: Fri, 15 Jan 2016 21:59:37 -0600 Subject: lib/memrange: allow stack allocated free list Instead of solely relying on malloc for building up an address space for the range_entry objects allow one to supply a list of free entries to memranges_init_empty(). Doing this and only calling malloc() in ramstage allows a memranges oboject to be used in a malloc()-free environment. Change-Id: I96c0f744fc04031a7ec228620a690b20bad36804 Signed-off-by: Aaron Durbin Reviewed-on: https://review.coreboot.org/13020 Reviewed-by: Paul Menzel Reviewed-by: Alexandru Gagniuc Reviewed-by: Martin Roth Tested-by: build bot (Jenkins) --- src/include/memrange.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/include') diff --git a/src/include/memrange.h b/src/include/memrange.h index 9e8c70457a..a4f7742c5b 100644 --- a/src/include/memrange.h +++ b/src/include/memrange.h @@ -21,6 +21,9 @@ * is exposed so that a memranges can be used on the stack if needed. */ struct memranges { struct range_entry *entries; + /* Coreboot doesn't have a free() function. Therefore, keep a cache of + * free'd entries. */ + struct range_entry *free_list; }; /* Each region within a memranges structure is represented by a @@ -71,8 +74,10 @@ static inline void range_entry_update_tag(struct range_entry *r, #define memranges_each_entry(r, ranges) \ for (r = (ranges)->entries; r != NULL; r = r->next) -/* Initialize memranges structure */ -void memranges_init_empty(struct memranges *ranges); +/* Initialize memranges structure providing an optional array of range_entry + * to use as the free list. */ +void memranges_init_empty(struct memranges *ranges, struct range_entry *free, + size_t num_free); /* Initialize and fill a memranges structure according to the * mask and match type for all memory resources. Tag each entry with the -- cgit v1.2.3