From patchwork Thu Aug 3 10:04:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 109302 Delivered-To: patch@linaro.org Received: by 10.140.101.6 with SMTP id t6csp569889qge; Thu, 3 Aug 2017 03:07:00 -0700 (PDT) X-Received: by 10.237.42.88 with SMTP id k24mr1446095qtf.58.1501754820425; Thu, 03 Aug 2017 03:07:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501754820; cv=none; d=google.com; s=arc-20160816; b=W1YCOQBVEwYTujw5QETJGD1KgVlQ7VIedZ3PrEZJcMtM3JlmH/Y27QYUsnH00uSNFj qc+zfXR0xUPNqiS/olvCg6UwVFDFrHYCZ/aM+JPrgxW/oGM0kqtuCWg7x1S/LJPsyX9X bpBIusp49ijhcAuKSJa6lz/CL7uHXVa/+2Ouy6xku3471DzOh9NDKRUefWXiaFae7Gxn wNXNMDPBvUChfrZ7WrMQ3J86J7wJSDVIL20QSkEKeq0Bosss+lTlY+WNOjquqbtEw4tO w2lhw08KfzYLNiO9xQWVZxpFs5V/eYGsc9O/H9ZRjaMDE7FbzDcUE8fq/qo+0zVr7e9H TUdA== 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=RwaclreH+kiB/5CwvAbJJHUj95WOJrSobGAiyOSyqMo=; b=EZ80w/TKVFKBrZJi6XV22G3lz2HNPLblmEW4wE88ACXwBqg19JCk5o3cQHIoRWQmJR 5bl9HP/iaiXs3l8dsPFyWDXRGGG3vAyLGDM6H61rln61ikhIC+Hy43KxeqyFOYU8TOc4 9o71v7en0rbTn5KbiEoX6jf4OeAuNpM8y7TWIMgIAuXZXTK1t8bvsYKrKLkizPPkJkNG 9Ry+G+4qr9+gWzz1ugxpPlyHN13DNF0fNy/pa3Viw4Jf+/MzPbGT/PUYtMV+7rG8WN2d kf1nMLC66KCXjR9oeBhjD0MZqy29wROvVSV0m99PRVnSpESaoQsOuHMPw2FlvC7BrXjk KBEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=NlJ350Dg; 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 k14si22939983qtg.204.2017.08.03.03.06.59 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 03 Aug 2017 03:07:00 -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=NlJ350Dg; 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]:53199 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddD1t-0000IJ-QG for patch@linaro.org; Thu, 03 Aug 2017 06:06:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45612) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddD1c-0000F1-Ar 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 1ddD1b-00046n-1Z for grub-devel@gnu.org; Thu, 03 Aug 2017 06:06:40 -0400 Received: from mail-wr0-x234.google.com ([2a00:1450:400c:c0c::234]:35145) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ddD1a-000461-S8 for grub-devel@gnu.org; Thu, 03 Aug 2017 06:06:38 -0400 Received: by mail-wr0-x234.google.com with SMTP id k71so3722354wrc.2 for ; Thu, 03 Aug 2017 03:06:38 -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=UHJLEQi9MiLVbvMz5x0a8Mu2VAAb8gH08kT+/sjXfcY=; b=NlJ350DgLuKqzgiMoeaci+fd/i/PfE+7VKUIuk1EfIzppIiT9RmgLgSsAU8cipI2l4 IXQxV4ir1eafPYAqDFuFoYJ9XrVs4BrKK3a3TTud6oxRmk3PEk+tM4wf333mhfnWvkTd pBnzWwu2GnZaut2Jm174kq0HKHW46tRO5cUC0= 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=UHJLEQi9MiLVbvMz5x0a8Mu2VAAb8gH08kT+/sjXfcY=; b=TxPL7f0gHn1sMV3gU8aoBJwwm4eN1R1T/zuUMCZV4o0/tdCc8UT01Zb04I66xgJ9Fi YiiKHH8OOaHwWXtpOHQPMM5+YQFqjKbCVwKeO2LUZFWU8rXF2Xe4qeCb3Odq0UANJCVO 5jn9Arj/B6e0mi0w3NLkowmXub7uTIn3cXQfbLT51O4+hmEhXUHeEQC1B/06BYWmqRRp 0lAiCeFo+Zvf9xfW4kpcunPG/BEvrVc+fEpBetHdrWspgOfIEt6Fk4olkDZBUif54THO Z2nGz9Yt972WOJndXvY/+jJk06vKJrfO5EiWSI1a7+L0YrC6irbghD2F1z1n/XewNeib lbZA== X-Gm-Message-State: AIVw113jh4/E+Ghfde9dHyv1gA+l/gnaoAXJh86iKAa8yCSO+oWr0xG1 QlE9/2mKpBFYoLiYnb/mOg== X-Received: by 10.223.130.202 with SMTP id 68mr910478wrc.46.1501754797563; Thu, 03 Aug 2017 03:06:37 -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.36 (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 03/14] loader: drop local implementations of find_efi_mmap_size Date: Thu, 3 Aug 2017 11:04:21 +0100 Message-Id: <20170803100432.29913-4-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::234 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" Now we have a grub_efi_find_mmap_size, replace near-identical implementations in i386/linux and mbi2 loaders with calls to that one. Signed-off-by: Leif Lindholm --- grub-core/loader/i386/linux.c | 51 +-------------------------------------- grub-core/loader/multiboot_mbi2.c | 38 +---------------------------- 2 files changed, 2 insertions(+), 87 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/loader/i386/linux.c b/grub-core/loader/i386/linux.c index 083f9417c..dfd50472f 100644 --- a/grub-core/loader/i386/linux.c +++ b/grub-core/loader/i386/linux.c @@ -101,55 +101,6 @@ page_align (grub_size_t size) return (size + (1 << 12) - 1) & (~((1 << 12) - 1)); } -#ifdef GRUB_MACHINE_EFI -/* Find the optimal number of pages for the memory map. Is it better to - move this code to efi/mm.c? */ -static grub_efi_uintn_t -find_efi_mmap_size (void) -{ - static grub_efi_uintn_t mmap_size = 0; - - if (mmap_size != 0) - return mmap_size; - - mmap_size = (1 << 12); - 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 += (1 << 12); - } - - /* Increase the size a bit for safety, because GRUB allocates more on - later, and EFI itself may allocate more. */ - mmap_size += (3 << 12); - - mmap_size = page_align (mmap_size); - return mmap_size; -} - -#endif - /* Helper for find_mmap_size. */ static int count_hook (grub_uint64_t addr __attribute__ ((unused)), @@ -560,7 +511,7 @@ grub_linux_boot (void) ctx.real_size = ALIGN_UP (cl_offset + maximal_cmdline_size, 4096); #ifdef GRUB_MACHINE_EFI - efi_mmap_size = find_efi_mmap_size (); + efi_mmap_size = grub_efi_find_mmap_size (); if (efi_mmap_size == 0) return grub_errno; #endif diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c index b0679a9f6..b5f961494 100644 --- a/grub-core/loader/multiboot_mbi2.c +++ b/grub-core/loader/multiboot_mbi2.c @@ -407,42 +407,6 @@ acpiv2_size (void) static grub_efi_uintn_t efi_mmap_size = 0; -/* Find the optimal number of pages for the memory map. Is it better to - move this code to efi/mm.c? */ -static void -find_efi_mmap_size (void) -{ - efi_mmap_size = (1 << 12); - while (1) - { - int ret; - grub_efi_memory_descriptor_t *mmap; - grub_efi_uintn_t desc_size; - grub_efi_uintn_t cur_mmap_size = efi_mmap_size; - - mmap = grub_malloc (cur_mmap_size); - if (! mmap) - return; - - ret = grub_efi_get_memory_map (&cur_mmap_size, mmap, 0, &desc_size, 0); - grub_free (mmap); - - if (ret < 0) - return; - else if (ret > 0) - break; - - if (efi_mmap_size < cur_mmap_size) - efi_mmap_size = cur_mmap_size; - efi_mmap_size += (1 << 12); - } - - /* Increase the size a bit for safety, because GRUB allocates more on - later, and EFI itself may allocate more. */ - efi_mmap_size += (3 << 12); - - efi_mmap_size = ALIGN_UP (efi_mmap_size, 4096); -} #endif static grub_size_t @@ -463,7 +427,7 @@ grub_multiboot_get_mbi_size (void) { #ifdef GRUB_MACHINE_EFI if (!keep_bs && !efi_mmap_size) - find_efi_mmap_size (); + efi_mmap_size = grub_efi_find_mmap_size (); #endif return 2 * sizeof (grub_uint32_t) + sizeof (struct multiboot_tag) + sizeof (struct multiboot_tag)