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 <adurbin@chromium.org>
Reviewed-on: https://review.coreboot.org/13020
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Reviewed-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
Reviewed-by: Martin Roth <martinroth@google.com>
Tested-by: build bot (Jenkins)
This commit is contained in:
Aaron Durbin
2016-01-15 21:59:37 -06:00
parent 4a30ab9096
commit 1b915b8904
2 changed files with 40 additions and 26 deletions

View File

@ -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