From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1dpKf9-00077X-Dd for mharc-grub-devel@gnu.org; Tue, 05 Sep 2017 16:41:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43677) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpKf2-00073J-UY for grub-devel@gnu.org; Tue, 05 Sep 2017 16:41:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dpKex-0003Gf-R5 for grub-devel@gnu.org; Tue, 05 Sep 2017 16:41:28 -0400 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]:32777) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dpKex-0003GL-Jz for grub-devel@gnu.org; Tue, 05 Sep 2017 16:41:23 -0400 Received: by mail-wm0-x234.google.com with SMTP id f145so13226969wme.0 for ; Tue, 05 Sep 2017 13:41:23 -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=coIcfRNf2R3ZjZIyS1vdbO6GMCOCMFkkwy4kmuqDMU8=; b=cMDfLIS3KhsBOmJXkcb+fUrNw3kgoik76OqI5dBneDO034urcWfKnZt8ujW0y+CCFi h8VsjP72HvqqkROlDpUehwa15AEIQJPYpRFtwxsSVu4M84R5w1IridgsSEX4Sv7gysVT TFJtJU2UkIYzhxiEviB9VmYLRYjvkz6OU0c60= 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=coIcfRNf2R3ZjZIyS1vdbO6GMCOCMFkkwy4kmuqDMU8=; b=TAx+XLnTGt8WD2ir6ryKJN1WTBZfmhEgxW3UdB28tvTEWy/bW3sczVtKS40xhgWg3u eIYx3E2sQVnC63fLoPdEORsr45V5rzGXjptvaTe8YUCk7MQnrlnQ98zOX3wtDY4dngzJ b0iqaLMjXXbl8+1wyHxyylryuKI3TSNnqRIoKMq4uexE7xMssJm+U6ytDISwWWYlD+7l bmbnaHDKr2JOhZdoycxL927/uzyX8kMsc8ZP9Ox5qnFidUQooGjuQ/byBqutbE6sNwnr 1KVc5GtxqNC2xxUh71RSWiYmOw3JSoKTCn4fVCZejbYEe7EAyGZIIZNxkyeP2KOfM9sE GfXg== X-Gm-Message-State: AHPjjUi6q8/mDNTR/v6R44eEjtDXwGtjHBDY+A4y7DXkh8eyBdahQRmw ngzwQDW6+vx0J8ODKHZ7YQ== X-Google-Smtp-Source: ADKCNb6k8OmHwrGB9BZ9M6HivvlG/sss9NOg+jmiyoGVAzZHJeEqKMbOO6Y/7TjkJw4P34WHo+HDgw== X-Received: by 10.28.46.145 with SMTP id u139mr142640wmu.178.1504644082226; Tue, 05 Sep 2017 13:41:22 -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 k52sm2291077wrf.62.2017.09.05.13.41.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Sep 2017 13:41:21 -0700 (PDT) From: Leif Lindholm To: grub-devel@gnu.org Cc: Vladimir 'phcoder' Serbinenko , Daniel Kiper Subject: [PATCH 4/4] loader: drop local implementations of find_efi_mmap_size Date: Tue, 5 Sep 2017 21:41:14 +0100 Message-Id: <20170905204114.9462-5-leif.lindholm@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170905204114.9462-1-leif.lindholm@linaro.org> References: <20170905204114.9462-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::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: , X-List-Received-Date: Tue, 05 Sep 2017 20:41:34 -0000 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(-) diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c index 44301e126..ab02add53 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) -- 2.11.0