[OpenBIOS] [PATCH 4/7] OFMEM: Fix bad alignments passed into the OFMEM claim words
Mark Cave-Ayland
mark.cave-ayland at ilande.co.uk
Fri Apr 12 14:57:44 CEST 2013
If a memory claim is made with an alignment that is not an exact power of
2, round up to the nearest power of 2 as per the IEEE1275 specification
rather than switching to a 4K default.
Also we make sure that the minimum alignment is equivalent to PAGE_SIZE.
Signed-off-by: Mark Cave-Ayland <mark.cave-ayland at ilande.co.uk>
---
openbios-devel/libopenbios/ofmem_common.c | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/openbios-devel/libopenbios/ofmem_common.c b/openbios-devel/libopenbios/ofmem_common.c
index 4c464c8..ee8ee82 100644
--- a/openbios-devel/libopenbios/ofmem_common.c
+++ b/openbios-devel/libopenbios/ofmem_common.c
@@ -425,13 +425,27 @@ static ucell find_area( ucell align, ucell size, range_t *r,
{
phys_addr_t base = min;
range_t *r2;
+ ucell old_align;
+ int i;
if( (align & (align-1)) ) {
- OFMEM_TRACE("bad alignment " FMT_ucell "\n", align);
- align = 0x1000;
+
+ /* As per IEEE1275 specification, round up to the nearest power of 2 */
+ old_align = align;
+ if (old_align <= PAGE_SIZE) {
+ align = PAGE_SIZE;
+ } else {
+ align--;
+ for (i = 1; i < sizeof(ucell) * 8; i<<=1) {
+ align |= align >> i;
+ }
+ align++;
+ }
+
+ OFMEM_TRACE("warning: bad alignment " FMT_ucellx " rounded up to " FMT_ucellx "\n", old_align, align);
}
if( !align )
- align = 0x1000;
+ align = PAGE_SIZE;
base = reverse ? max - size : min;
r2 = reverse ? NULL : r;
--
1.7.10.4
More information about the OpenBIOS
mailing list