Message ID | 20180627171720.27028-3-leif.lindholm@linaro.org |
---|---|
State | Superseded |
Headers | show |
Series | efi: arm linux loader unification and correctness | expand |
On Wed, Jun 27, 2018 at 06:17:16PM +0100, Leif Lindholm wrote: > Since ARM platforms do not have a common memory map, add a helper > function that finds the lowest address region with the EFI_MEMORY_WB > attribute set in the UEFI memory map. > > Required for the arm64 efi linux loader to restrict the initrd > location to where it will be accessible by the kernel at runtime. > > Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org> > --- > grub-core/kern/efi/mm.c | 36 ++++++++++++++++++++++++++++++++++++ > include/grub/efi/efi.h | 3 +++ > 2 files changed, 39 insertions(+) > > diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c > index fd39d23b4..10ffa2c9b 100644 > --- a/grub-core/kern/efi/mm.c > +++ b/grub-core/kern/efi/mm.c > @@ -629,3 +629,39 @@ grub_efi_mm_init (void) > grub_efi_free_pages ((grub_addr_t) memory_map, > 2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE)); > } > + > +#if defined (__aarch64__) > +grub_err_t > +grub_efi_get_ram_base(grub_addr_t *base_addr) > +{ > + grub_efi_memory_descriptor_t *memory_map; > + grub_efi_memory_descriptor_t *desc; grub_efi_memory_descriptor_t *desc, *memory_map; > + grub_efi_uintn_t mmap_size; > + grub_efi_uintn_t desc_size; grub_efi_uintn_t desc_size, mmap_size; > + int ret; > + > + mmap_size = grub_efi_find_mmap_size(); > + > + memory_map = grub_malloc (mmap_size); > + if (! memory_map) > + return GRUB_ERR_OUT_OF_MEMORY; > + ret = grub_efi_get_memory_map (&mmap_size, memory_map, NULL, > + &desc_size, NULL); > + > + if (ret < 1) > + return GRUB_ERR_BUG; > + > + for (desc = memory_map, *base_addr = GRUB_UINT_MAX; > + (grub_addr_t) desc < ((grub_addr_t) memory_map + mmap_size); > + desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size)) > + { > + if (desc->attribute & GRUB_EFI_MEMORY_WB) *base_addr = grub_min (*base_addr, desc->physical_start); > + if (desc->physical_start < *base_addr) > + *base_addr = desc->physical_start; > + } And then you can drop these curly brackets. Daniel _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Le ven. 6 juil. 2018 à 17:17, Daniel Kiper <daniel.kiper@oracle.com> a écrit : > On Wed, Jun 27, 2018 at 06:17:16PM +0100, Leif Lindholm wrote: > > Since ARM platforms do not have a common memory map, add a helper > > function that finds the lowest address region with the EFI_MEMORY_WB > > attribute set in the UEFI memory map. > > > > Required for the arm64 efi linux loader to restrict the initrd > > location to where it will be accessible by the kernel at runtime. > > > > Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org> > > --- > > grub-core/kern/efi/mm.c | 36 ++++++++++++++++++++++++++++++++++++ > > include/grub/efi/efi.h | 3 +++ > > 2 files changed, 39 insertions(+) > > > > diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c > > index fd39d23b4..10ffa2c9b 100644 > > --- a/grub-core/kern/efi/mm.c > > +++ b/grub-core/kern/efi/mm.c > > @@ -629,3 +629,39 @@ grub_efi_mm_init (void) > > grub_efi_free_pages ((grub_addr_t) memory_map, > > 2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE)); > > } > > + > > +#if defined (__aarch64__) > > +grub_err_t > > +grub_efi_get_ram_base(grub_addr_t *base_addr) > > +{ > > + grub_efi_memory_descriptor_t *memory_map; > > + grub_efi_memory_descriptor_t *desc; > > grub_efi_memory_descriptor_t *desc, *memory_map; > For readability and ease of understanding, I think mmap_size should be renamed to memory_map_size (or the other way around) to explicit/uniformize naming. > > + grub_efi_uintn_t mmap_size; > > + grub_efi_uintn_t desc_size; > > grub_efi_uintn_t desc_size, mmap_size; > > > + int ret; > > + > > + mmap_size = grub_efi_find_mmap_size(); > > + > > + memory_map = grub_malloc (mmap_size); > > + if (! memory_map) > > + return GRUB_ERR_OUT_OF_MEMORY; > > + ret = grub_efi_get_memory_map (&mmap_size, memory_map, NULL, > > + &desc_size, NULL); > > + > > + if (ret < 1) > > + return GRUB_ERR_BUG; > > + > > + for (desc = memory_map, *base_addr = GRUB_UINT_MAX; > > + (grub_addr_t) desc < ((grub_addr_t) memory_map + mmap_size); > > + desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size)) > > + { > > + if (desc->attribute & GRUB_EFI_MEMORY_WB) > *base_addr = grub_min (*base_addr, desc->physical_start); > > > + if (desc->physical_start < *base_addr) > > + *base_addr = desc->physical_start; > > + } > > And then you can drop these curly brackets. > > Daniel > > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > https://lists.gnu.org/mailman/listinfo/grub-devel > <div dir="auto"><div><br><br><div class="gmail_quote"><div dir="ltr">Le ven. 6 juil. 2018 à 17:17, Daniel Kiper <<a href="mailto:daniel.kiper@oracle.com">daniel.kiper@oracle.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Wed, Jun 27, 2018 at 06:17:16PM +0100, Leif Lindholm wrote:<br> > Since ARM platforms do not have a common memory map, add a helper<br> > function that finds the lowest address region with the EFI_MEMORY_WB<br> > attribute set in the UEFI memory map.<br> ><br> > Required for the arm64 efi linux loader to restrict the initrd<br> > location to where it will be accessible by the kernel at runtime.<br> ><br> > Signed-off-by: Leif Lindholm <<a href="mailto:leif.lindholm@linaro.org" target="_blank" rel="noreferrer">leif.lindholm@linaro.org</a>><br> > ---<br> > grub-core/kern/efi/mm.c | 36 ++++++++++++++++++++++++++++++++++++<br> > include/grub/efi/efi.h | 3 +++<br> > 2 files changed, 39 insertions(+)<br> ><br> > diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c<br> > index fd39d23b4..10ffa2c9b 100644<br> > --- a/grub-core/kern/efi/mm.c<br> > +++ b/grub-core/kern/efi/mm.c<br> > @@ -629,3 +629,39 @@ grub_efi_mm_init (void)<br> > grub_efi_free_pages ((grub_addr_t) memory_map,<br> > 2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE));<br> > }<br> > +<br> > +#if defined (__aarch64__)<br> > +grub_err_t<br> > +grub_efi_get_ram_base(grub_addr_t *base_addr)<br> > +{<br> > + grub_efi_memory_descriptor_t *memory_map;<br> > + grub_efi_memory_descriptor_t *desc;<br> <br> grub_efi_memory_descriptor_t *desc, *memory_map;<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">For readability and ease of understanding, I think mmap_size should be renamed to memory_map_size (or the other way around) to explicit/uniformize naming.</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <br> > + grub_efi_uintn_t mmap_size;<br> > + grub_efi_uintn_t desc_size;<br> <br> grub_efi_uintn_t desc_size, mmap_size;<br> <br> > + int ret;<br> > +<br> > + mmap_size = grub_efi_find_mmap_size();<br> > +<br> > + memory_map = grub_malloc (mmap_size);<br> > + if (! memory_map)<br> > + return GRUB_ERR_OUT_OF_MEMORY;<br> > + ret = grub_efi_get_memory_map (&mmap_size, memory_map, NULL,<br> > + &desc_size, NULL);<br> > +<br> > + if (ret < 1)<br> > + return GRUB_ERR_BUG;<br> > +<br> > + for (desc = memory_map, *base_addr = GRUB_UINT_MAX;<br> > + (grub_addr_t) desc < ((grub_addr_t) memory_map + mmap_size);<br> > + desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size))<br> > + {<br> > + if (desc->attribute & GRUB_EFI_MEMORY_WB)<br> *base_addr = grub_min (*base_addr, desc->physical_start);<br> <br> > + if (desc->physical_start < *base_addr)<br> > + *base_addr = desc->physical_start;<br> > + }<br> <br> And then you can drop these curly brackets.<br> <br> Daniel<br> <br> _______________________________________________<br> Grub-devel mailing list<br> <a href="mailto:Grub-devel@gnu.org" target="_blank" rel="noreferrer">Grub-devel@gnu.org</a><br> <a href="https://lists.gnu.org/mailman/listinfo/grub-devel" rel="noreferrer noreferrer" target="_blank">https://lists.gnu.org/mailman/listinfo/grub-devel</a><br> </blockquote></div></div></div> _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
On Fri, Jul 06, 2018 at 05:12:27PM +0200, Daniel Kiper wrote: > On Wed, Jun 27, 2018 at 06:17:16PM +0100, Leif Lindholm wrote: > > Since ARM platforms do not have a common memory map, add a helper > > function that finds the lowest address region with the EFI_MEMORY_WB > > attribute set in the UEFI memory map. > > > > Required for the arm64 efi linux loader to restrict the initrd > > location to where it will be accessible by the kernel at runtime. > > > > Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org> > > --- > > grub-core/kern/efi/mm.c | 36 ++++++++++++++++++++++++++++++++++++ > > include/grub/efi/efi.h | 3 +++ > > 2 files changed, 39 insertions(+) > > > > diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c > > index fd39d23b4..10ffa2c9b 100644 > > --- a/grub-core/kern/efi/mm.c > > +++ b/grub-core/kern/efi/mm.c > > @@ -629,3 +629,39 @@ grub_efi_mm_init (void) > > grub_efi_free_pages ((grub_addr_t) memory_map, > > 2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE)); > > } > > + > > +#if defined (__aarch64__) > > +grub_err_t > > +grub_efi_get_ram_base(grub_addr_t *base_addr) > > +{ > > + grub_efi_memory_descriptor_t *memory_map; > > + grub_efi_memory_descriptor_t *desc; > > grub_efi_memory_descriptor_t *desc, *memory_map; > > > + grub_efi_uintn_t mmap_size; > > + grub_efi_uintn_t desc_size; > > grub_efi_uintn_t desc_size, mmap_size; > > > + int ret; > > + > > + mmap_size = grub_efi_find_mmap_size(); > > + > > + memory_map = grub_malloc (mmap_size); > > + if (! memory_map) > > + return GRUB_ERR_OUT_OF_MEMORY; > > + ret = grub_efi_get_memory_map (&mmap_size, memory_map, NULL, > > + &desc_size, NULL); > > + > > + if (ret < 1) > > + return GRUB_ERR_BUG; > > + > > + for (desc = memory_map, *base_addr = GRUB_UINT_MAX; > > + (grub_addr_t) desc < ((grub_addr_t) memory_map + mmap_size); > > + desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size)) > > + { > > + if (desc->attribute & GRUB_EFI_MEMORY_WB) > *base_addr = grub_min (*base_addr, desc->physical_start); > > > + if (desc->physical_start < *base_addr) > > + *base_addr = desc->physical_start; > > + } > > And then you can drop these curly brackets. Sure, I'll fold these changes into v4. / Leif _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c index fd39d23b4..10ffa2c9b 100644 --- a/grub-core/kern/efi/mm.c +++ b/grub-core/kern/efi/mm.c @@ -629,3 +629,39 @@ grub_efi_mm_init (void) grub_efi_free_pages ((grub_addr_t) memory_map, 2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE)); } + +#if defined (__aarch64__) +grub_err_t +grub_efi_get_ram_base(grub_addr_t *base_addr) +{ + grub_efi_memory_descriptor_t *memory_map; + grub_efi_memory_descriptor_t *desc; + grub_efi_uintn_t mmap_size; + grub_efi_uintn_t desc_size; + int ret; + + mmap_size = grub_efi_find_mmap_size(); + + memory_map = grub_malloc (mmap_size); + if (! memory_map) + return GRUB_ERR_OUT_OF_MEMORY; + ret = grub_efi_get_memory_map (&mmap_size, memory_map, NULL, + &desc_size, NULL); + + if (ret < 1) + return GRUB_ERR_BUG; + + for (desc = memory_map, *base_addr = GRUB_UINT_MAX; + (grub_addr_t) desc < ((grub_addr_t) memory_map + mmap_size); + desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size)) + { + if (desc->attribute & GRUB_EFI_MEMORY_WB) + if (desc->physical_start < *base_addr) + *base_addr = desc->physical_start; + } + + grub_free(memory_map); + + return GRUB_ERR_NONE; +} +#endif diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h index 1021273c1..57db74b57 100644 --- a/include/grub/efi/efi.h +++ b/include/grub/efi/efi.h @@ -93,6 +93,9 @@ extern void (*EXPORT_VAR(grub_efi_net_config)) (grub_efi_handle_t hnd, #if defined(__arm__) || defined(__aarch64__) void *EXPORT_FUNC(grub_efi_get_firmware_fdt)(void); #endif +#if defined(__aarch64__) +grub_err_t EXPORT_FUNC(grub_efi_get_ram_base)(grub_addr_t *); +#endif grub_addr_t grub_efi_modules_addr (void);
Since ARM platforms do not have a common memory map, add a helper function that finds the lowest address region with the EFI_MEMORY_WB attribute set in the UEFI memory map. Required for the arm64 efi linux loader to restrict the initrd location to where it will be accessible by the kernel at runtime. Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org> --- grub-core/kern/efi/mm.c | 36 ++++++++++++++++++++++++++++++++++++ include/grub/efi/efi.h | 3 +++ 2 files changed, 39 insertions(+) -- 2.11.0 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel