diff options
author | Furquan Shaikh <furquan@google.com> | 2020-03-11 14:35:35 -0700 |
---|---|---|
committer | Patrick Georgi <pgeorgi@google.com> | 2020-03-17 08:17:16 +0000 |
commit | 1429092d02e8157c8e6c26849e0c8aa096da9c0c (patch) | |
tree | 1f02861a6e0d751493d8a54291a08f29e6d71af4 /src/include | |
parent | 672f7d7b2d7adbd7e2d041d627d96a33de9b8b11 (diff) | |
download | coreboot-1429092d02e8157c8e6c26849e0c8aa096da9c0c.tar.xz |
memrange: Enable memranges to support different alignments
This change enables memranges library to support addresses with
different alignments. Before this change, memranges library supported
aligning addresses to 4KiB only. Though this works for most cases, it
might not be the right alignment for every use case. Example: There
are some resource allocator changes coming up that require a different
alignment when handling the range list.
This change adds a align parameter to struct memranges that determines
the alignment of all range lists in that memrange. In order to
continue supporting current users of memranges, default alignment is
maintained as 4KiB.
BUG=b:149186922
Signed-off-by: Furquan Shaikh <furquan@google.com>
Change-Id: I1da0743ff89da734c9a0972e3c56d9f512b3d1e8
Reviewed-on: https://review.coreboot.org/c/coreboot/+/39483
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/memrange.h | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/src/include/memrange.h b/src/include/memrange.h index 7f42aa2b0b..0d20236d61 100644 --- a/src/include/memrange.h +++ b/src/include/memrange.h @@ -24,6 +24,8 @@ struct memranges { /* coreboot doesn't have a free() function. Therefore, keep a cache of * free'd entries. */ struct range_entry *free_list; + /* Alignment for base and end addresses of the range. (Must be power of 2). */ + size_t align; }; /* Each region within a memranges structure is represented by a @@ -86,17 +88,32 @@ 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 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); + * to use as the free list. Additionally, it accepts an align parameter that + * determines the alignment of addresses. (Alignment must be a power of 2). */ +void memranges_init_empty_with_alignment(struct memranges *ranges, + struct range_entry *free, + size_t num_free, size_t align); /* Initialize and fill a memranges structure according to the * mask and match type for all memory resources. Tag each entry with the - * specified type. */ -void memranges_init(struct memranges *ranges, + * specified type. Additionally, it accepts an align parameter that + * determines the alignment of addresses. (Alignment must be a power of 2). */ +void memranges_init_with_alignment(struct memranges *ranges, unsigned long mask, unsigned long match, - unsigned long tag); + unsigned long tag, size_t align); + +/* Initialize memranges structure providing an optional array of range_entry + * to use as the free list. Addresses are default aligned to 4KiB. */ +#define memranges_init_empty(__ranges, __free, __num_free) \ + memranges_init_empty_with_alignment(__ranges, __free, __num_free, 4 * KiB) + +/* Initialize and fill a memranges structure according to the + * mask and match type for all memory resources. Tag each entry with the + * specified type. Addresses are default aligned to 4KiB. */ +#define memranges_init(__ranges, __mask, __match, __tag) \ + memranges_init_with_alignment(__ranges, __mask, __match, __tag, 4 * KiB) /* Clone a memrange. The new memrange has the same entries as the old one. */ void memranges_clone(struct memranges *newranges, struct memranges *oldranges); |