grub-devel.gnu.org archive mirror
 help / color / mirror / Atom feed
From: Josh Triplett <josh@joshtriplett.org>
To: grub-devel@gnu.org
Subject: [PATCH 3/4] efi: Support GRUB_MMAP_MALLOC_LOW in the EFI firmware allocator
Date: Tue, 12 Nov 2013 18:26:39 -0800	[thread overview]
Message-ID: <b8909a17f77610f4207cdc126c159cfbb0d2008a.1384309081.git.josh@joshtriplett.org> (raw)
In-Reply-To: <cover.1384309081.git.josh@joshtriplett.org>

EFI supports allocating memory below a specified address; use that to
implement GRUB_MMAP_MALLOC_LOW by requesting memory below 1M.
---

ChangeLog entry:

2013-11-13  Josh Triplett  <josh@joshtriplett.org>

	* 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);
-- 
1.8.4.3



  parent reply	other threads:[~2013-11-13  2:27 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-13  2:25 [PATCH 0/4] i386-efi and x86_64-efi fixes Josh Triplett
2013-11-13  2:26 ` [PATCH 1/4] efi: Fix firmware memory allocation to round to 4k pages, not 1k Josh Triplett
2013-11-18 17:01   ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-11-13  2:26 ` [PATCH 2/4] efi: Fix requests to allocate GRUB_MEMORY_AVAILABLE Josh Triplett
2013-11-18 16:58   ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-11-13  2:26 ` Josh Triplett [this message]
2013-11-13  3:59   ` [PATCH 3/4] efi: Support GRUB_MMAP_MALLOC_LOW in the EFI firmware allocator Andrey Borzenkov
2013-11-14  8:08     ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-11-14  8:05   ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-11-13  2:27 ` [PATCH 4/4] efi: On x86-64, align the stack to a 16-byte boundary as required by ABI Josh Triplett
2013-11-14  8:01   ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-11-15  7:15   ` Jordan Justen
2013-11-15 11:01     ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-11-19 13:32   ` Vladimir 'φ-coder/phcoder' Serbinenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b8909a17f77610f4207cdc126c159cfbb0d2008a.1384309081.git.josh@joshtriplett.org \
    --to=josh@joshtriplett.org \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).