Author: mcayland Date: Fri Apr 19 09:03:59 2013 New Revision: 1121 URL: http://tracker.coreboot.org/trac/openbios/changeset/1121
Log: OFMEM: Fix bad alignments passed into the OFMEM claim words
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@ilande.co.uk
Modified: trunk/openbios-devel/libopenbios/ofmem_common.c
Modified: trunk/openbios-devel/libopenbios/ofmem_common.c ============================================================================== --- trunk/openbios-devel/libopenbios/ofmem_common.c Fri Apr 19 09:03:38 2013 (r1120) +++ trunk/openbios-devel/libopenbios/ofmem_common.c Fri Apr 19 09:03:59 2013 (r1121) @@ -425,13 +425,27 @@ { 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;