]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
kern/ieee1275/init/ppc64: Add support for alignment requirements
authorStefan Berger <stefanb@linux.ibm.com>
Thu, 30 Nov 2023 14:17:18 +0000 (09:17 -0500)
committerDaniel Kiper <daniel.kiper@oracle.com>
Tue, 5 Dec 2023 13:29:55 +0000 (14:29 +0100)
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 <stefanb@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Cc: Hari Bathini <hbathini@linux.ibm.com>
Cc: Pavithra Prakash <pavrampu@in.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Carolyn Scherrer <cpscherr@us.ibm.com>
Cc: Mahesh Salgaonkar <mahesh@linux.ibm.com>
Cc: Sourabh Jain <sourabhjain@linux.ibm.com>
grub-core/kern/ieee1275/init.c
include/grub/ieee1275/alloc.h

index 4b9face59a95afee1c56407ad82b625d5b6d6f7f..9a1243639c375b692a3481d6bc69bcf25080eb32 100644 (file)
@@ -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;
 
index f3065ff31fb3c6857634397966f2767c5d44ee3f..e314c989de93f11d6e6ebce6c514582b6d95d195 100644 (file)
@@ -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 */