grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 3/4] efi: Support GRUB_MMAP_MALLOC_LOW in the EFI firmware al


From: Vladimir 'φ-coder/phcoder' Serbinenko
Subject: Re: [PATCH 3/4] efi: Support GRUB_MMAP_MALLOC_LOW in the EFI firmware allocator
Date: Thu, 14 Nov 2013 09:05:09 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131005 Icedove/17.0.9

On 13.11.2013 03:26, Josh Triplett wrote:
> EFI supports allocating memory below a specified address; use that to
> implement GRUB_MMAP_MALLOC_LOW by requesting memory below 1M.
As discussed on the IRC, using mmap isn't right way to allocate
transient low memory space. This would merit a separate functions
(alloc_low_page and free_low_page) which uses EFI calls on EFI and
returns the scratch address GRUB_MEMORY_MACHINE_SCRATCH_ADDR on other
platforms. These would be subjected to following rules:
- Always gives only 4k
- Consumer has to ensure the transient nature of allocation since low
memory is scarce.
> ---
> 
> ChangeLog entry:
> 
> 2013-11-13  Josh Triplett  <address@hidden>
> 
>       * include/grub/efi/memory.h (GRUB_MMAP_MALLOC_LOW): Define.
>       * grub-core/mmap/efi/mmap.c (grub_mmap_malign_and_register): Add
>         support for GRUB_MMAP_MALLOC_LOW, to allocate memory below 1M via the
>         EFI firmware.
> 
>  grub-core/mmap/efi/mmap.c | 15 ++++++++++-----
>  include/grub/efi/memory.h |  2 ++
>  2 files changed, 12 insertions(+), 5 deletions(-)
> 
> diff --git a/grub-core/mmap/efi/mmap.c b/grub-core/mmap/efi/mmap.c
> index e6cd185..64ad05c 100644
> --- a/grub-core/mmap/efi/mmap.c
> +++ b/grub-core/mmap/efi/mmap.c
> @@ -239,9 +239,9 @@ void *
>  grub_mmap_malign_and_register (grub_uint64_t align __attribute__ ((unused)),
>                              grub_uint64_t size,
>                              int *handle, int type,
> -                            int flags __attribute__ ((unused)))
> +                            int flags)
>  {
> -  grub_efi_physical_address_t address;
> +  grub_efi_physical_address_t address, max_address;
>    grub_efi_boot_services_t *b;
>    grub_efi_uintn_t pages;
>    grub_efi_status_t status;
> @@ -254,13 +254,18 @@ grub_mmap_malign_and_register (grub_uint64_t align 
> __attribute__ ((unused)),
>  
>    b = grub_efi_system_table->boot_services;
>  
> -  address = 0xffffffff;
> +  if (flags & GRUB_MMAP_MALLOC_LOW)
> +      max_address = 0xfffff;
> +  else
> +      max_address = 0xffffffff;
> +  address = max_address;
>  
>  #if GRUB_TARGET_SIZEOF_VOID_P < 8
>    /* Limit the memory access to less than 4GB for 32-bit platforms.  */
>    atype = GRUB_EFI_ALLOCATE_MAX_ADDRESS;
>  #else
> -  atype = GRUB_EFI_ALLOCATE_ANY_PAGES;
> +  atype = (flags & GRUB_MMAP_MALLOC_LOW) ? GRUB_EFI_ALLOCATE_MAX_ADDRESS
> +                                         : GRUB_EFI_ALLOCATE_ANY_PAGES;
>  #endif
>  
>    pages = (size + 0xfff) >> 12;
> @@ -276,7 +281,7 @@ grub_mmap_malign_and_register (grub_uint64_t align 
> __attribute__ ((unused)),
>      {
>        /* Uggh, the address 0 was allocated... This is too annoying,
>        so reallocate another one.  */
> -      address = 0xffffffff;
> +      address = max_address;
>        status = efi_call_4 (b->allocate_pages, atype,
>                          make_efi_memtype (type), pages, &address);
>        grub_efi_free_pages (0, pages);
> diff --git a/include/grub/efi/memory.h b/include/grub/efi/memory.h
> index 20526b1..b4940af 100644
> --- a/include/grub/efi/memory.h
> +++ b/include/grub/efi/memory.h
> @@ -24,6 +24,8 @@
>  
>  #define GRUB_MMAP_REGISTER_BY_FIRMWARE  1
>  
> +#define GRUB_MMAP_MALLOC_LOW 1
> +
>  grub_err_t grub_machine_mmap_register (grub_uint64_t start, grub_uint64_t 
> size,
>                                      int type, int handle);
>  grub_err_t grub_machine_mmap_unregister (int handle);
> 


Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]