From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1VgQAY-0000cs-O9 for mharc-grub-devel@gnu.org; Tue, 12 Nov 2013 21:27:02 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39697) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VgQAO-0000Qk-QM for grub-devel@gnu.org; Tue, 12 Nov 2013 21:27:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VgQAH-0005XA-5A for grub-devel@gnu.org; Tue, 12 Nov 2013 21:26:52 -0500 Received: from relay5-d.mail.gandi.net ([2001:4b98:c:538::197]:60738) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VgQAG-0005WT-Qk for grub-devel@gnu.org; Tue, 12 Nov 2013 21:26:45 -0500 Received: from mfilter6-d.gandi.net (mfilter6-d.gandi.net [217.70.178.135]) by relay5-d.mail.gandi.net (Postfix) with ESMTP id 15E7F41C05D for ; Wed, 13 Nov 2013 03:26:44 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mfilter6-d.gandi.net Received: from relay5-d.mail.gandi.net ([217.70.183.197]) by mfilter6-d.gandi.net (mfilter6-d.gandi.net [10.0.15.180]) (amavisd-new, port 10024) with ESMTP id ARohHEkgqpbT for ; Wed, 13 Nov 2013 03:26:42 +0100 (CET) X-Originating-IP: 50.43.14.201 Received: from leaf (static-50-43-14-201.bvtn.or.frontiernet.net [50.43.14.201]) (Authenticated sender: josh@joshtriplett.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id C829441C056 for ; Wed, 13 Nov 2013 03:26:41 +0100 (CET) Date: Tue, 12 Nov 2013 18:26:39 -0800 From: Josh Triplett To: grub-devel@gnu.org Subject: [PATCH 3/4] efi: Support GRUB_MMAP_MALLOC_LOW in the EFI firmware allocator Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4b98:c:538::197 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Nov 2013 02:27:00 -0000 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 * 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