From: Stefan Berger Date: Thu, 30 Nov 2023 14:17:18 +0000 (-0500) Subject: kern/ieee1275/init/ppc64: Add support for alignment requirements X-Git-Tag: grub-2.12~37 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d49e86db2c15dd20f42262c0977f739ddf7bd6f6;p=thirdparty%2Fgrub.git kern/ieee1275/init/ppc64: Add support for alignment requirements Add support for memory alignment requirements and adjust a candidate address to it before checking whether the block is large enough. This must be done in this order since the alignment adjustment can make a block smaller than what was requested. None of the current callers has memory alignment requirements but the ieee1275 loader for kernel and initrd will use it to convey them. Signed-off-by: Stefan Berger Reviewed-by: Daniel Kiper Cc: Hari Bathini Cc: Pavithra Prakash Cc: Michael Ellerman Cc: Carolyn Scherrer Cc: Mahesh Salgaonkar Cc: Sourabh Jain --- diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c index 4b9face59..9a1243639 100644 --- a/grub-core/kern/ieee1275/init.c +++ b/grub-core/kern/ieee1275/init.c @@ -502,6 +502,20 @@ regions_claim (grub_uint64_t addr, grub_uint64_t len, grub_memory_type_t type, } } } + + /* Honor alignment restrictions on candidate addr */ + if (rcr->align) + { + grub_uint64_t align_addr = ALIGN_UP (addr, rcr->align); + grub_uint64_t d = align_addr - addr; + + if (d > len) + return 0; + + len -= d; + addr = align_addr; + } + if (rcr->flags & GRUB_MM_ADD_REGION_CONSECUTIVE && len < rcr->total) return 0; diff --git a/include/grub/ieee1275/alloc.h b/include/grub/ieee1275/alloc.h index f3065ff31..e314c989d 100644 --- a/include/grub/ieee1275/alloc.h +++ b/include/grub/ieee1275/alloc.h @@ -30,6 +30,7 @@ struct regions_claim_request { grub_uint32_t total; /* number of requested bytes */ bool init_region; /* whether to add memory to the heap using grub_mm_init_region() */ grub_uint64_t addr; /* result address */ + grub_size_t align; /* alignment restrictions */ }; #endif /* GRUB_IEEE1275_ALLOC_HEADER */