From patchwork Mon Jul 9 17:33:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 141476 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2923671ljj; Mon, 9 Jul 2018 10:34:25 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdS9fE3ITpMaR7vioZd2RDYzNKbO7GzLEN23AlN1GIx2tzolZOeolQzXadcF3PFXKHXT5ER X-Received: by 2002:a37:2711:: with SMTP id n17-v6mr10617436qkn.109.1531157665683; Mon, 09 Jul 2018 10:34:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531157665; cv=none; d=google.com; s=arc-20160816; b=LezA9COozxItU35usJq4Y+52zrXZaAcAu8KHhVjBcGfxATRzobZ5JA5JssQVDC8LX4 K/+5O4rymbUbFz736f7bkhxOHyUHDXcSuieQ2J+dWeCN0rMXSgcZEUk/+CFlMlb4efGI nnPB2tWq1VD/lIc80ab4AyFlbgDdXHUdetNr3AZyQRtWveTaOg6sHZNUABy4ExgDIRp6 V+jYnybkNRTQJGmTtm9TU95c8TqR7zP/0W42RduOEoBkCFvuhNYAtB6G9Ai2AxHDlREM AkUMwI1ZvhQQT5+J1W9lbl7WerYVp7vMfcxFP4fkmSMhcOk/0LdY0b1MmQU+1kxq3WIs Q4BA== 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=g5LxAi21zjTnek3uOSNvwIYONtnuGm3j8k0V0EgIZps=; b=syvqEZ9kPSaFcHpHVFRKflxsyJIdZk6rUeGXtcNEZK7bavnZeelBJjRjzKvQLMG4jH gEhxTNSaMfWH3Mhx4XrbBH3v6esgtlee1adaFPNUECmGx4FqfGP0UmEm4dtgb1R5J/mx 738DnBCia2PFhXZSBwd6YAnfHzQ8HyC4admd36t46M9it8dEcO0p9WsVS9/bJNBkmGcE +EIZkihjgO4ybXroZuR9tNyCOyz5YiS3AMVgACEfgnkEWGlguC1e2kEyUY5u5sxsR2Qb /encEeIeNQMizTX/csxClrCGhIkaHy2rCGzVIAMnzUOpCCCXIT1q4wdcu4cc8EpERfQ2 evDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=DLHR8k4r; 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 u26-v6si1223521qtf.173.2018.07.09.10.34.25 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 09 Jul 2018 10:34:25 -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=DLHR8k4r; 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]:43607 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fca3N-0000KH-27 for patch@linaro.org; Mon, 09 Jul 2018 13:34:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44241) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fca2D-0000H7-QX for grub-devel@gnu.org; Mon, 09 Jul 2018 13:33:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fca2A-0002fP-BD for grub-devel@gnu.org; Mon, 09 Jul 2018 13:33:13 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:34626) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fca2A-0002f3-45 for grub-devel@gnu.org; Mon, 09 Jul 2018 13:33:10 -0400 Received: by mail-wr1-x442.google.com with SMTP id c13-v6so11785853wrt.1 for ; Mon, 09 Jul 2018 10:33:10 -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=0cYpTbGsvEvA8ODG7yCjNOLULulzByq9vMajAfVdP8o=; b=DLHR8k4rAszQAm0MeFj10dDrzgPxUWTZ8JT3k82XmazQ13+RwQz1N7TDlJQT6JLodv 5ifVyMX/u02+hou7odXKvCtmuCTxB+MNuTzl53essmffb+2BnQJxG/C92vTx+9gezFRg 5Rn7PhKF5y5odNmZ1jdrzgNVvn9/mvsOhJJ/o= 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=0cYpTbGsvEvA8ODG7yCjNOLULulzByq9vMajAfVdP8o=; b=tCZIHHjxWkXs7CjxeDn5v8Ut/0Sc5DojFmizYcRAc1cuMJ/hvg4Wze7EwxS9iqJ4NF +1tLr+ujzqN77mEJFNBuPIAjKk6xnssFotpvu129iPXbbaZlFh++yzWE34p2FATUoHOf iE42AfeBvJkJyQ38FGNhZdYnrq1oto9fnYLorD1Pr08EzVmdRQViUecTM1ZSKmJsk3Bv FeQgDGGY9Jfq7ZRJRZPrekvGDkLodxYPhqRA2mJ5CBewq5NxvzhJtqFD0mErscovByJi tPT43d7B5sETd/Z9q5omE/pmDtFxfmhoAb/JEEoxfWiySLgnRw6TOVr9EBg33mTulY9I GsWA== X-Gm-Message-State: APt69E0REa/NCbkaIICBiNKcAMPdrI/sNAY9bDZPFZnUh27Kt4tiFulc 6rDe4iQdkQ/rihs/VrXN9rFuxNNqshY= X-Received: by 2002:adf:9582:: with SMTP id p2-v6mr14943782wrp.252.1531157588831; Mon, 09 Jul 2018 10:33:08 -0700 (PDT) Received: from vanye.hemma.eciton.net (cpc92302-cmbg19-2-0-cust304.5-4.cable.virginm.net. [82.1.209.49]) by smtp.gmail.com with ESMTPSA id p3-v6sm27742988wrg.47.2018.07.09.10.33.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Jul 2018 10:33:07 -0700 (PDT) From: Leif Lindholm To: grub-devel@gnu.org Subject: [PATCH v4 1/6] efi: add central copy of grub_efi_find_mmap_size Date: Mon, 9 Jul 2018 18:33:00 +0100 Message-Id: <20180709173305.17588-2-leif.lindholm@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180709173305.17588-1-leif.lindholm@linaro.org> References: <20180709173305.17588-1-leif.lindholm@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 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. Signed-off-by: Leif Lindholm --- grub-core/kern/efi/mm.c | 20 ++++++++++++++++++++ include/grub/efi/efi.h | 1 + 2 files changed, 21 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 c48e9b5c7..fd39d23b4 100644 --- a/grub-core/kern/efi/mm.c +++ b/grub-core/kern/efi/mm.c @@ -286,6 +286,26 @@ 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) +{ + grub_efi_uintn_t mmap_size = 0; + grub_efi_uintn_t desc_size; + + if (grub_efi_get_memory_map (&mmap_size, NULL, NULL, &desc_size, 0) < 0) + { + grub_error (GRUB_ERR_IO, "cannot get EFI memory map size"); + return 0; + } + + /* Add an extra page, since UEFI can alter the memory map itself on + callbacks or explicit calls, including console output. */ + return ALIGN_UP (mmap_size + GRUB_EFI_PAGE_SIZE, GRUB_EFI_PAGE_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 c996913e5..1021273c1 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,