From patchwork Mon Jun 12 14:53:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 103631 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp233419qgd; Mon, 12 Jun 2017 07:58:17 -0700 (PDT) X-Received: by 10.200.45.35 with SMTP id n32mr37911851qta.15.1497279496956; Mon, 12 Jun 2017 07:58:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497279496; cv=none; d=google.com; s=arc-20160816; b=WsmqHUFGBYCTp271fWo15ncoQVgKwQQaTE/WvUumNYOlkuF2zaNgBkF0oZ1hCa9Dae ggdhL6F4EbTBlKXtKiYNriQvQo162nJ54KodrN0B6ApHnUb/lVPOdRAtcvEYtd4OX0RB cnQgFE5KFB3hceTh4FaHMeCuHiSeo5voYTh8FWbrdmUAwWCBTcMvQUbLU6L7tBauz945 wMDy0bLLCNE9IxWFxUS3SYoxSQni4ca/6i2cDK8qGMZiJO+s5PHG1FcOC4fuFQWiAb09 9kqDjKGYybtS80UvCMOrGOtIKGYwZxN+nD/Pxhy9J431zxmIC9nK4wkOUvQBIu5N6kxB 4W6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:references:in-reply-to:message-id:date:subject :to:from:dkim-signature:arc-authentication-results; bh=fhWVT6YwVd+x/zk7h3iEPf6uxviLc08VfScRegKP+sU=; b=B6bjSEVRHRfYPUgfb6jZJqmHwr7sUGZpuZDfMXrSNySLs+YFrWvTjiPaobaaWetOOB 4rp+e83wGFKIVT/tzmHiWQ6Y+EMvpbqgK1BegJFFrNLcsmuXOPi5yr0gHMN/sYmDt4NP dvCywu/y13zM2n//sPBRzUXdeZInBb2u9BmyuhSHP0cWxKahYhxcQuNE/aY6574QIfsj N4ephR1hEm9Ov0KbbRi1GySF7s9YcgSQ4Jk5aYwKidnbw9p7cTWeEFp+QJb1167/06rb FvW37u7enQECdGZSucnY/w4ybBlDgsYbAQMiqm3kuUu98vFsNf4TY+A4ftS8w6c1QCG7 V3hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=grub-devel-bounces+patch=linaro.org@gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id c47si1587074qta.277.2017.06.12.07.58.16 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 12 Jun 2017 07:58:16 -0700 (PDT) Received-SPF: pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=grub-devel-bounces+patch=linaro.org@gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:38522 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dKQnG-0001wF-Jm for patch@linaro.org; Mon, 12 Jun 2017 10:58:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58228) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dKQky-0000uI-Ll for grub-devel@gnu.org; Mon, 12 Jun 2017 10:55:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dKQkx-0000uk-ET for grub-devel@gnu.org; Mon, 12 Jun 2017 10:55:52 -0400 Received: from mail-wr0-x230.google.com ([2a00:1450:400c:c0c::230]:32875) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dKQkx-0000uO-2S for grub-devel@gnu.org; Mon, 12 Jun 2017 10:55:51 -0400 Received: by mail-wr0-x230.google.com with SMTP id v104so99060637wrb.0 for ; Mon, 12 Jun 2017 07:55:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YT2qqCsNAUUEhGh7ex2vZyFseNHCB1tlc2xBJM3ZK2g=; b=D3U7ertohlbfN9HQ78MHSP6d+jEmsm1w409ToXtmqTuhpqsFIbtNVgSgW/qkAMyilC rIpONoFuaFI6o6ZHfX5YJWVItpliS8wolyQN9nZ0pNPNkZ6fCsVm8LHyNGWQEwJmhCo3 O6Y9UsY3nAmltBr2z7+z+jjxgA1UfQ6V4jKGE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=YT2qqCsNAUUEhGh7ex2vZyFseNHCB1tlc2xBJM3ZK2g=; b=cKYaDYDPxbb5wuSdXGLLSFuRVizm1PFBMH928YU92cmQq9ESfyaIis1AxOyRlgeAMA PC1fyvuqVJnfCvtCpbVRrXiDG2FFE40Ux0dCU446GOB4hTEKR53jBOAuQykzNwj9ROoQ NYwGVAPsgAQaatQ4b2Zjmmf8XOvpUiPlidZLQqNMplLIe+gujb5Q7foA7fM0Hbo/SZCr JBN8YVrhp0O3sR7SsVXlgCl7IuVTWC1p63kKbBNckuagf9hO/wAT4W1qoqKXPBsDvwk/ 98a0xR/J0cBH771bsHY7F3oO1Zf4AxxX0ykfk5sKJG2yBXff4eEA5yFVDe2Rnjfkw+Kf srkA== X-Gm-Message-State: AODbwcC+DvzTK70kFCDKSZ533swsQWduHi1CYCS4bMRXAsDDP2O6W21O CmXcwcpUMy2ZB1MhIgXZQw== X-Received: by 10.223.154.15 with SMTP id z15mr8140131wrb.136.1497279345545; Mon, 12 Jun 2017 07:55:45 -0700 (PDT) Received: from mohikan.hemma.eciton.net (cpc92316-cmbg19-2-0-cust118.5-4.cable.virginm.net. [82.12.0.119]) by smtp.gmail.com with ESMTPSA id s140sm7722wmd.1.2017.06.12.07.55.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Jun 2017 07:55:44 -0700 (PDT) From: Leif Lindholm To: grub-devel@gnu.org Subject: [PATCH 2/7] efi: refactor grub_efi_allocate_pages Date: Mon, 12 Jun 2017 15:53:36 +0100 Message-Id: <20170612145341.3351-3-leif.lindholm@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170612145341.3351-1-leif.lindholm@linaro.org> References: <20170612145341.3351-1-leif.lindholm@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::230 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The development of GNU GRUB Cc: ard.biesheuvel@linaro.org, lersek@redhat.com, agraf@suse.de, kraxel@redhat.com MIME-Version: 1.0 Errors-To: grub-devel-bounces+patch=linaro.org@gnu.org Sender: "Grub-devel" Expose a new function, grub_efi_allocate_pages_real(), making it possible to specify allocation type and memory type as supported by the UEFI AllocatePages boot service. Make grub_efi_allocate_pages() a consumer of the new function, maintaining its old functionality. Also delete some left-around #if 1/#else blocks in the affected functions. Signed-off-by: Leif Lindholm --- grub-core/kern/efi/mm.c | 46 ++++++++++++++++++++++++---------------------- include/grub/efi/efi.h | 5 +++++ 2 files changed, 29 insertions(+), 22 deletions(-) -- 2.11.0 _______________________________________________ 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 460a4b763..7b1763bc5 100644 --- a/grub-core/kern/efi/mm.c +++ b/grub-core/kern/efi/mm.c @@ -51,36 +51,20 @@ int grub_efi_is_finished = 0; /* Allocate pages. Return the pointer to the first of allocated pages. */ void * -grub_efi_allocate_pages (grub_efi_physical_address_t address, - grub_efi_uintn_t pages) +grub_efi_allocate_pages_real (grub_efi_physical_address_t address, + grub_efi_uintn_t pages, + grub_efi_allocate_type_t alloctype, + grub_efi_memory_type_t memtype) { - grub_efi_allocate_type_t type; grub_efi_status_t status; grub_efi_boot_services_t *b; -#if 1 /* Limit the memory access to less than 4GB for 32-bit platforms. */ if (address > GRUB_EFI_MAX_USABLE_ADDRESS) return 0; -#endif - -#if 1 - if (address == 0) - { - type = GRUB_EFI_ALLOCATE_MAX_ADDRESS; - address = GRUB_EFI_MAX_USABLE_ADDRESS; - } - else - type = GRUB_EFI_ALLOCATE_ADDRESS; -#else - if (address == 0) - type = GRUB_EFI_ALLOCATE_ANY_PAGES; - else - type = GRUB_EFI_ALLOCATE_ADDRESS; -#endif b = grub_efi_system_table->boot_services; - status = efi_call_4 (b->allocate_pages, type, GRUB_EFI_LOADER_DATA, pages, &address); + status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address); if (status != GRUB_EFI_SUCCESS) return 0; @@ -89,7 +73,7 @@ grub_efi_allocate_pages (grub_efi_physical_address_t address, /* Uggh, the address 0 was allocated... This is too annoying, so reallocate another one. */ address = GRUB_EFI_MAX_USABLE_ADDRESS; - status = efi_call_4 (b->allocate_pages, type, GRUB_EFI_LOADER_DATA, pages, &address); + status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address); grub_efi_free_pages (0, pages); if (status != GRUB_EFI_SUCCESS) return 0; @@ -98,6 +82,24 @@ grub_efi_allocate_pages (grub_efi_physical_address_t address, return (void *) ((grub_addr_t) address); } +void * +grub_efi_allocate_pages (grub_efi_physical_address_t address, + grub_efi_uintn_t pages) +{ + grub_efi_allocate_type_t alloctype; + + if (address == 0) + { + alloctype = GRUB_EFI_ALLOCATE_MAX_ADDRESS; + address = GRUB_EFI_MAX_USABLE_ADDRESS; + } + else + alloctype = GRUB_EFI_ALLOCATE_ADDRESS; + + return grub_efi_allocate_pages_real (address, pages, alloctype, + GRUB_EFI_LOADER_DATA); +} + /* Free pages starting from ADDRESS. */ void grub_efi_free_pages (grub_efi_physical_address_t address, diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h index 845fc2438..904722174 100644 --- a/include/grub/efi/efi.h +++ b/include/grub/efi/efi.h @@ -38,6 +38,11 @@ void *EXPORT_FUNC(grub_efi_open_protocol) (grub_efi_handle_t handle, int EXPORT_FUNC(grub_efi_set_text_mode) (int on); void EXPORT_FUNC(grub_efi_stall) (grub_efi_uintn_t microseconds); void * +EXPORT_FUNC(grub_efi_allocate_pages_real) (grub_efi_physical_address_t address, + grub_efi_uintn_t pages, + grub_efi_allocate_type_t alloctype, + grub_efi_memory_type_t memtype); +void * EXPORT_FUNC(grub_efi_allocate_pages) (grub_efi_physical_address_t address, grub_efi_uintn_t pages); void EXPORT_FUNC(grub_efi_free_pages) (grub_efi_physical_address_t address,