From grub-devel Fri Jul 06 16:17:34 2018 From: Michel Hermier Date: Fri, 06 Jul 2018 16:17:34 +0000 To: grub-devel Subject: Re: [PATCH v3 2/6] efi: add grub_efi_get_ram_base() function for arm64 Message-Id: X-MARC-Message: https://marc.info/?l=grub-devel&m=153089390611040 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--===============9004807092054591880==" --===============9004807092054591880== Content-Type: multipart/alternative; boundary="00000000000023548d05705701e4" --00000000000023548d05705701e4 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Le ven. 6 juil. 2018 =C3=A0 17:17, Daniel Kiper a =C3=A9crit : > 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 > > --- > > 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 =3D grub_efi_find_mmap_size(); > > + > > + memory_map =3D grub_malloc (mmap_size); > > + if (! memory_map) > > + return GRUB_ERR_OUT_OF_MEMORY; > > + ret =3D grub_efi_get_memory_map (&mmap_size, memory_map, NULL, > > + &desc_size, NULL); > > + > > + if (ret < 1) > > + return GRUB_ERR_BUG; > > + > > + for (desc =3D memory_map, *base_addr =3D GRUB_UINT_MAX; > > + (grub_addr_t) desc < ((grub_addr_t) memory_map + mmap_size); > > + desc =3D NEXT_MEMORY_DESCRIPTOR (desc, desc_size)) > > + { > > + if (desc->attribute & GRUB_EFI_MEMORY_WB) > *base_addr =3D grub_min (*base_addr, desc->physical_start); > > > + if (desc->physical_start < *base_addr) > > + *base_addr =3D 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 > --00000000000023548d05705701e4 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


= Le ven. 6 juil. 2018 =C3=A0 17:17, Daniel Kiper <daniel.kiper@oracle.com> a =C3=A9crit=C2=A0:
=
On Wed, Jun 27, 2018 at 06:17:16PM +01= 00, 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>= ;
> ---
>=C2=A0 grub-core/kern/efi/mm.c | 36 +++++++++++++++++++++++++++++++++++= +
>=C2=A0 include/grub/efi/efi.h=C2=A0 |=C2=A0 3 +++
>=C2=A0 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)
>=C2=A0 =C2=A0 grub_efi_free_pages ((grub_addr_t) memory_map,
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE));
>=C2=A0 }
> +
> +#if defined (__aarch64__)
> +grub_err_t
> +grub_efi_get_ram_base(grub_addr_t *base_addr)
> +{
> +=C2=A0 grub_efi_memory_descriptor_t *memory_map;
> +=C2=A0 grub_efi_memory_descriptor_t *desc;

=C2=A0 =C2=A0 =C2=A0grub_efi_memory_descriptor_t *desc, *memory_map;

For rea= dability and ease of understanding, I think mmap_size should be renamed to = memory_map_size (or the other way around) to explicit/uniformize naming.


> +=C2=A0 grub_efi_uintn_t mmap_size;
> +=C2=A0 grub_efi_uintn_t desc_size;

=C2=A0 =C2=A0 =C2=A0grub_efi_uintn_t desc_size, mmap_size;

> +=C2=A0 int ret;
> +
> +=C2=A0 mmap_size =3D grub_efi_find_mmap_size();
> +
> +=C2=A0 memory_map =3D grub_malloc (mmap_size);
> +=C2=A0 if (! memory_map)
> +=C2=A0 =C2=A0 return GRUB_ERR_OUT_OF_MEMORY;
> +=C2=A0 ret =3D grub_efi_get_memory_map (&mmap_size, memory_map, N= ULL,
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &desc_size, NULL);
> +
> +=C2=A0 if (ret < 1)
> +=C2=A0 =C2=A0 return GRUB_ERR_BUG;
> +
> +=C2=A0 for (desc =3D memory_map, *base_addr =3D GRUB_UINT_MAX;
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0(grub_addr_t) desc < ((grub_addr_t) mem= ory_map + mmap_size);
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0desc =3D NEXT_MEMORY_DESCRIPTOR (desc, des= c_size))
> +=C2=A0 =C2=A0 {
> +=C2=A0 =C2=A0 =C2=A0 if (desc->attribute & GRUB_EFI_MEMORY_WB)=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0*base_addr =3D grub_min (*base_add= r, desc->physical_start);

> +=C2=A0 =C2=A0 =C2=A0if (desc->physical_start < *base_addr)
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0*base_addr =3D desc->physical_start; > +=C2=A0 =C2=A0 }

And then you can drop these curly brackets.

Daniel

_______________________________________________
Grub-devel mailing list
= Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/g= rub-devel
--00000000000023548d05705701e4-- --===============9004807092054591880== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel --===============9004807092054591880==--