From patchwork Tue Sep 5 20:41:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 111749 Delivered-To: patch@linaro.org Received: by 10.140.94.166 with SMTP id g35csp3337669qge; Tue, 5 Sep 2017 13:42:43 -0700 (PDT) X-Received: by 10.200.35.123 with SMTP id b56mr577554qtb.62.1504644163822; Tue, 05 Sep 2017 13:42:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504644163; cv=none; d=google.com; s=arc-20160816; b=wAPwyDiy581pCLozhVb922+R/mjaknBwGwmo+aKOI58918k1KIVoL807cRV/6G6nRM v1Rsx7Ox0pk8SVoHv6lGMSyyMLrMoIiwvK0B2l4xnoEyCa2Iy8e8a2jI0fHb2PNliwQ6 th6p+IWvmLIvfBVlxXor9cD5vTE2rebaSlA5pDKt2AOnqb14PLnt1WGfuE+VhIfkBgKE ACaDKVhwotHE0LmYxj4RbFnF4zpt5ivBEd1RnoMpMUWF9U1TGRpkkdjVingvwehaAomC SjYUAvMHg0rGlLV0B1wHpgINKLv92NVBdyH27TaVNtp4PwIV+BZIuA5C+LU1uNK53IWC cc9Q== 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=ubNwHm8BiOKShaSXJRuxYTmaUT4w0V9swTGrtpkEQVI=; b=CreJv/lAF1HJ0ZseD0VJHrQHbzjbfkd6A632a3QoODZKyhudg3WvBVNq/z4cL6MSpE ji7q+GvZikUFEhsfffS7ozd2zKKzs/60EmQauQtjeibEeBPr4UoONJN4krITIWFVscpI dMvvYzTJ1WCRxvW/RvVQnBxUQkfBZ8f0Czle0SadnqajvKWDVK0w0oLfa9vd8d0BtaRM 7HC4Z7lQT+rHfa4WxCMzzXHQahQDjC119/SlxeN20ZV4ZwgHHovafa+ZvSYvJY76fIVC Z+jWJYbh3WwTp9baF4+BCxcMfKV/6quowOVoImv73kLC0lxT6+OH1pux7YuSkPXX9KK6 G9DQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=DjhjRKgK; 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 j4si1062512qtd.456.2017.09.05.13.42.43 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 05 Sep 2017 13:42:43 -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.s=google header.b=DjhjRKgK; 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]:33136 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpKgD-00075I-P5 for patch@linaro.org; Tue, 05 Sep 2017 16:42:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43657) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpKf1-00073D-4n for grub-devel@gnu.org; Tue, 05 Sep 2017 16:41:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dpKew-0003Fo-Ci for grub-devel@gnu.org; Tue, 05 Sep 2017 16:41:27 -0400 Received: from mail-wr0-x22b.google.com ([2a00:1450:400c:c0c::22b]:34289) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dpKew-0003FM-6f for grub-devel@gnu.org; Tue, 05 Sep 2017 16:41:22 -0400 Received: by mail-wr0-x22b.google.com with SMTP id a47so9041528wra.1 for ; Tue, 05 Sep 2017 13:41:22 -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=BZ9Px02dTLL9ncj4JBS6kvzCHiLbj6l7QNDhSw7fMLg=; b=DjhjRKgKnWOMF8ha5miPIASL9KLvmfW111FVOE4mIUGO0qTI/FVz39dgFYrqVhMZTU DMwYuJEWIP2VI5MntILH96GkZqlcxoh3AbY7oT2+bzenUgYe631Fa/H9yxGuq37bcnW3 L7pIOcSbd478R/6vP7PjMP+fBNGsvoXfvtrkw= 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=BZ9Px02dTLL9ncj4JBS6kvzCHiLbj6l7QNDhSw7fMLg=; b=dRcPjNbZ1pQfAr8kN/RzdBg880PRjdGH9Bk3HBCZAPiREtUnuVPO1esY7bgdCc+kvf gq6FF+Rg8AQVnXaX/ukVuPDc8BKLz4E3X6h+mkzcML4wm1BUIKOtQKlJ2Mxl9Mlg6b+L oCbFAfSMXOj/hjv84EI47talxs5a2Y6DJZ+IuNDz9xoReJsjnVcB+2giWkiKiU45t1uO IJxvXkveGanMq0jtwGow0dTP4Yz78LppeVS7b1pN0dKOw+j/t6z5LzYsxk7XPseptnp+ coQuAYJQwAa67QG9jgmZSDJLWIGAA8EpCsB4KWegLs4UlP52v/3k10LbnipyOi83IvHU VtFA== X-Gm-Message-State: AHPjjUiBVVGj284tvQFYmGyQlca2Mro5rpuAtB884MldbZ4xHEIEelpW 8fEyRiWytwLdhgmEj9O6mw== X-Google-Smtp-Source: ADKCNb699eC03BzKPYm0pLNEA2hMdPL5hy+l31QXNva6JfMh8sq8wMX0z6kyWlY2Mh4OjcbXOC/2Dg== X-Received: by 10.223.165.137 with SMTP id g9mr171972wrc.269.1504644080885; Tue, 05 Sep 2017 13:41:20 -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:20 -0700 (PDT) From: Leif Lindholm To: grub-devel@gnu.org Subject: [PATCH 3/4] efi: add central copy of grub_efi_find_mmap_size Date: Tue, 5 Sep 2017 21:41:13 +0100 Message-Id: <20170905204114.9462-4-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:c0c::22b 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: Vladimir 'phcoder' Serbinenko , 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 | 47 +++++++++++++++++++++++++++++++++++++++++++++++ include/grub/efi/efi.h | 1 + 2 files changed, 48 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 ac2a4c556..8795aa1e0 100644 --- a/grub-core/kern/efi/mm.c +++ b/grub-core/kern/efi/mm.c @@ -218,6 +218,53 @@ grub_efi_finish_boot_services (grub_efi_uintn_t *outbuf_size, void *outbuf, return GRUB_ERR_NONE; } +/* To obtain the UEFI memory map, we must pass a buffer of sufficient size + to hold the entire map. This function returns a sane start value for + buffer size. */ +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 3fa082816..8f1f36c8c 100644 --- a/include/grub/efi/efi.h +++ b/include/grub/efi/efi.h @@ -49,6 +49,7 @@ void * EXPORT_FUNC(grub_efi_allocate_any_pages) (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,