From patchwork Thu Aug 3 10:04:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 109305 Delivered-To: patch@linaro.org Received: by 10.140.101.6 with SMTP id t6csp571188qge; Thu, 3 Aug 2017 03:08:15 -0700 (PDT) X-Received: by 10.200.52.56 with SMTP id u53mr1374106qtb.217.1501754895448; Thu, 03 Aug 2017 03:08:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501754895; cv=none; d=google.com; s=arc-20160816; b=yJRYqKERpmmVdsvn3gOm6dz6Y4wMXJkDHz9owrsfCDzW+TgC1Tbl6ewl9Gw93gqil1 GcH03lwVp1HxvvZY9s3ad0RG38oKNjY8XbgVfasd1Noat1/vdHnVR/jcs0NItkBtnNPJ mg5gzsKv9cdYj+tTVfe1PgvA/daHFk1GzGvO/cL9K4xHGp9RbkaodHAlXnREk34VgOLS D65myfTbNPsvimbwvaUjgidOAZpv4Q4vH4yN+Pz7f3JBSp5+E+KvlcH2qP0C4SN1NcHW JpkDoy+CnLpf2h7KpkbyrcZGocolmIVuw4NUbEV0UoIKVIiUK4Vc7QMtAa9ppUYi2OEo quDQ== 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=gqh7wbYWIMgap8yIEspKk+waNf0/oB8xlQsIhV5dB2s=; b=vCu0Tqs0vj2KmXsLmbA6zJ3b158i4R8WMlMw+6K9EmK+B6sNArlb9i5ayhoHWGLWeL 6I0ZEC/TRoMlPULATxogiqH8N+BiAzjKLH3hvqvl9VkN3xPbDkzfh07BTHiscybF9Ixy vYMo3gZNSazw8xJRhbgKs5itRQFci7EOKohf0bC4WcDyjynA/sya4dRP5KSHgfd0Rz4m 1PU8CkqGz3rNxc4KuzfNYuiEWeBfqHhHZEUhBlShCosfamDbo0XTMn27K7G1Jg/AWEcx jSK+tdeq67LNm0/3wa/MvI/D79rte2OtPjdCPTa1jtUSfKWC0yR1Ys3kmHA0uKXgOIc/ 7rjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=Dqkt0Ifi; 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 u13si16414058qki.491.2017.08.03.03.08.14 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 03 Aug 2017 03:08:15 -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 header.b=Dqkt0Ifi; 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]:53201 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddD36-0001Jt-MT for patch@linaro.org; Thu, 03 Aug 2017 06:08:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45706) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddD1e-0000Fb-RF for grub-devel@gnu.org; Thu, 03 Aug 2017 06:06:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ddD1d-00049O-0C for grub-devel@gnu.org; Thu, 03 Aug 2017 06:06:42 -0400 Received: from mail-wr0-x233.google.com ([2a00:1450:400c:c0c::233]:38099) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ddD1c-00047g-HR for grub-devel@gnu.org; Thu, 03 Aug 2017 06:06:40 -0400 Received: by mail-wr0-x233.google.com with SMTP id f21so3672193wrf.5 for ; Thu, 03 Aug 2017 03:06:40 -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=wn+A0nQJ8FBf7rAkB9bwDeKM6oqavvFm8rPFncyeqMU=; b=Dqkt0Ifi6qwg4wj0q8Nj+4w3WRAe5DXZXok1QX/GSW2cYR2ek87mGX+AyfELcdy4IE Ncg3hxAq3F5zx5HOl/3+YWOgxdmUiLxc+pRvf7qGiTzuLWXUJIFKSvNxXOm1GGz2vl/B FxQNp71gZ0yXtvtR7cVd7nRbEenNZmjguTmls= 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=wn+A0nQJ8FBf7rAkB9bwDeKM6oqavvFm8rPFncyeqMU=; b=NmZuh5IY19Dz5m/tj1qdXR4hYKb2/IcUWsjbhNGSAtaR+UU4MZ47X2bhszKvCvKTLE WCao6dwIAatfgBV0FuhJl405h5fVMVpWWQf2MKNFlBgfmBuGgMAxiL4otKGQdw4KDs/Z +OXHPof88L7MzdtlKDRuHzX49O9aQ7UrZJws0Ar7tTCVS+PRuqc2JKObV86NKYUBlUeO 77uptqYy+xTJvKY9KuFk7a9HuFkbK4dBwrnIQKiZ9qjxF3wfJ2SVNO41LvcYocya7Wfg WFWrsFTDL/Gw0x0pE5FnFXCfLOCxQU9aetzXvHgMB/XgzRzh2Xaj6yUvjNAKMrNK4PAs 8iIw== X-Gm-Message-State: AIVw111KLOd4fWH5H5GoxIOeXNd3OOAwmRqLY8QyfSohV2qe4t57TT3j Qvctrsj+m0yXbrCKObDGoA== X-Received: by 10.223.154.203 with SMTP id a69mr894883wrc.139.1501754799341; Thu, 03 Aug 2017 03:06:39 -0700 (PDT) Received: from vanye.hemma.eciton.net (cpc92316-cmbg19-2-0-cust118.5-4.cable.virginm.net. [82.12.0.119]) by smtp.gmail.com with ESMTPSA id e5sm2274543wre.24.2017.08.03.03.06.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 Aug 2017 03:06:38 -0700 (PDT) From: Leif Lindholm To: grub-devel@gnu.org Subject: [PATCH v2 05/14] efi: refactor grub_efi_allocate_pages Date: Thu, 3 Aug 2017 11:04:23 +0100 Message-Id: <20170803100432.29913-6-leif.lindholm@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170803100432.29913-1-leif.lindholm@linaro.org> References: <20170803100432.29913-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::233 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: Daniel Kiper 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 8413c19e5..1e62eff8f 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 80ab56795..a58774efc 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,