From patchwork Thu Aug 3 10:04:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 109301 Delivered-To: patch@linaro.org Received: by 10.140.101.6 with SMTP id t6csp569761qge; Thu, 3 Aug 2017 03:06:54 -0700 (PDT) X-Received: by 10.200.33.188 with SMTP id 57mr1301647qty.101.1501754814268; Thu, 03 Aug 2017 03:06:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501754814; cv=none; d=google.com; s=arc-20160816; b=sGNuVMt78OHfzwdF3oh4/x/6wiRLOz3RM7medCLSHkek8B0zK2yGaFi1Nxm9MJH2EB LGA39AUd22+rvCzlT40t4S6X4u0+1gmp1h7IHTMSVZIWZR9M8pad7/88GShfY7gXNozn RWap+Yrpsv50elw+uF2z7w7AlQ04WVPcEQd0JDYWQiUVaASOEkMv6NugN5KYYk+8WMrD cpKgfbT/Mz+9n6RCNiTXFLWACTNM2ZORvLzacsF+GTTBHSdtYLcxbebNPwV2ti28JD4j EysS5HI86Cf627vufA/+IzUrdoM0f1v61P/TG6F0GZy/qb6KjBkP+eJXV2cSx7jPXXeg 9D7Q== 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=/mLdyWsS5JBscLXD4HB0z8srgUDPG6aWL3QqFmRjUc4=; b=HTWaSW3oYSlf+l0s5D1deFGsdNqU9Rd/fwx5dT7EDt3hTtXjA59Vl/wBMO05E2DF2x mzEraoNxH+yZ/bhcr8mKMGVtRV6e8pw1jJ899U6SBmujjfhghy+ABwail4aAZy9eTOzO ibL241AGR2se4EUafTB0birVG3VaTWT9X1l3W0ioQDixZ4uW5mOPYoPLIVKO54j6yJUB sLM8Uf/UdxuVD+UNB8BM309BQREt2BYwe4Y3hjXQd7Iw1WBmMqErX/BK52rjQQbUg1LQ XbzjcRCaKCP0qsM2pc+RATY+tVrPogJ5WUmaOnucEYUgbHMJ1mDT7Ah36ayQBZhcw9sA Mxzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=ku91cuMJ; 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 h7si30164307qkf.508.2017.08.03.03.06.53 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 03 Aug 2017 03:06:54 -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=ku91cuMJ; 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]:53196 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddD1n-0000Fl-Qq for patch@linaro.org; Thu, 03 Aug 2017 06:06:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45613) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddD1c-0000F2-Bu for grub-devel@gnu.org; Thu, 03 Aug 2017 06:06:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ddD1a-00045x-5J for grub-devel@gnu.org; Thu, 03 Aug 2017 06:06:40 -0400 Received: from mail-wm0-x22f.google.com ([2a00:1450:400c:c09::22f]:33499) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ddD1Z-000459-W4 for grub-devel@gnu.org; Thu, 03 Aug 2017 06:06:38 -0400 Received: by mail-wm0-x22f.google.com with SMTP id k20so3354636wmg.0 for ; Thu, 03 Aug 2017 03:06:37 -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=32S8GFOcbnzTlkBrAHmsW7W0VBoxuYyyyJoVcJReO+I=; b=ku91cuMJv7xOyux13LBvGNTyAIp3WA4yUEYbt/ntalcw/m5j7hexbz2Dq7HcHa7+rY ptBi6ZiYPtncfSYXJwwXYkN7MI8tL5ocGBLQ2a3Ygp/sK8L7RA9GVAp4Q4JzWdNJCcSQ ZWUzOtIZomBoDhLCkmUsZWIW5r1i0ofzKBOLU= 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=32S8GFOcbnzTlkBrAHmsW7W0VBoxuYyyyJoVcJReO+I=; b=Vr3u3GldLCnue8Np+hsIyFktjEbeQ6wAOi43sXJr41A1c1mbKgK8TRhi4gKAusSKzF DnPyWVhjV+DHXOvLL8LB56mfVBUEqy4sIrUY7FNRYv1hTHFYL7FDRnchwp3m+oMOCKv8 GiDW3rlEocxGuWZdm8t1ulLjV54SD1VUjcIPSfPE6FnLZkW7VI58QNc1Jn2TO6dYjQ36 mwfjUKmDBV3nJZTZieXM65BKgX9Uf39bR61GcLEftgqMaXDErytpQ1yfSmINYwfSn29q Aqpp3jpWZhTcGQJLrwMqi5EXC30U4Zz2bAfVA6pnBQjwgqFz2fpy7NdTkWUCJf+qCm8P 9YHg== X-Gm-Message-State: AIVw113XzDZLv0mrzmw3rE+4IFjp/kl/iQmZhPz2xqaANUEUsO8kCUrq aZrYKTuo8XGhfUIYhHvCuQ== X-Received: by 10.28.31.197 with SMTP id f188mr761287wmf.62.1501754796659; Thu, 03 Aug 2017 03:06:36 -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.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 Aug 2017 03:06:36 -0700 (PDT) From: Leif Lindholm To: grub-devel@gnu.org Subject: [PATCH v2 02/14] efi: add central copy of grub_efi_find_mmap_size Date: Thu, 3 Aug 2017 11:04:20 +0100 Message-Id: <20170803100432.29913-3-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:c09::22f 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" There are several implementations of this function in the tree. Add a central version in grub-core/efi/mm.c. Taken from grub-core/loader/i386/linux.c, changing some hard-coded constants to use macros from efi/memory.h. Signed-off-by: Leif Lindholm --- grub-core/kern/efi/mm.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ include/grub/efi/efi.h | 1 + 2 files changed, 45 insertions(+) -- 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 20a47aaf5..31ca703ec 100644 --- a/grub-core/kern/efi/mm.c +++ b/grub-core/kern/efi/mm.c @@ -217,6 +217,50 @@ grub_efi_finish_boot_services (grub_efi_uintn_t *outbuf_size, void *outbuf, return GRUB_ERR_NONE; } +grub_efi_uintn_t +grub_efi_find_mmap_size (void) +{ + static grub_efi_uintn_t mmap_size = 0; + + if (mmap_size != 0) + return mmap_size; + + mmap_size = 1 * GRUB_EFI_PAGE_SIZE; + while (1) + { + int ret; + grub_efi_memory_descriptor_t *mmap; + grub_efi_uintn_t desc_size; + grub_efi_uintn_t cur_mmap_size = mmap_size; + + mmap = grub_malloc (cur_mmap_size); + if (! mmap) + return 0; + + ret = grub_efi_get_memory_map (&cur_mmap_size, mmap, 0, &desc_size, 0); + grub_free (mmap); + + if (ret < 0) + { + grub_error (GRUB_ERR_IO, "cannot get memory map"); + return 0; + } + else if (ret > 0) + break; + + if (mmap_size < cur_mmap_size) + mmap_size = cur_mmap_size; + mmap_size += GRUB_EFI_PAGE_SIZE; + } + + /* Increase the size a bit for safety, because GRUB allocates more on + later, and EFI itself may allocate more. */ + mmap_size += 3 * GRUB_EFI_PAGE_SIZE; + + mmap_size = ALIGN_UP (mmap_size, GRUB_EFI_PAGE_SIZE); + return mmap_size; +} + /* Get the memory map as defined in the EFI spec. Return 1 if successful, return 0 if partial, or return -1 if an error occurs. */ int diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h index e9c601f34..3984de083 100644 --- a/include/grub/efi/efi.h +++ b/include/grub/efi/efi.h @@ -42,6 +42,7 @@ 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, grub_efi_uintn_t pages); +grub_efi_uintn_t EXPORT_FUNC(grub_efi_find_mmap_size) (void); int EXPORT_FUNC(grub_efi_get_memory_map) (grub_efi_uintn_t *memory_map_size, grub_efi_memory_descriptor_t *memory_map,