From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1fca2F-0000JX-JU for mharc-grub-devel@gnu.org; Mon, 09 Jul 2018 13:33:15 -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-Google-Smtp-Source: AAOMgpd7i43qWZHvMgOw2DJ+PJ3450BX+QVERDnesA2bd/uQJAjzTqSuuYnKS89ect/VSEPbNMf3Vw== 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 Cc: Daniel Kiper 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: , X-List-Received-Date: Mon, 09 Jul 2018 17:33:14 -0000 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(+) 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, -- 2.11.0