From patchwork Wed Jun 27 17:17:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 140371 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1152251ljj; Wed, 27 Jun 2018 10:19:05 -0700 (PDT) X-Google-Smtp-Source: AAOMgpciJAIlgPsCW1HWk/leF3eag1AHyWr26MzCpvKS1YB9VYPljCU5jtUYKzedMawcaocGfRT9 X-Received: by 2002:aed:3fa3:: with SMTP id s32-v6mr6295749qth.229.1530119945337; Wed, 27 Jun 2018 10:19:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530119945; cv=none; d=google.com; s=arc-20160816; b=yTSvmJ7aPo8CuwEhqrfQHAal3EgPO4KQ3tgDWQ96UFJrLiYcIYYyTHLuQFbdomR/a6 8kA+gCKoTD89pmWnHTDrfxL6pDU69BIaze63TIFhD6vOFd0NwkmsBpd5HlRuRotgY0Q/ Ftjo55fU9ZrTVbAFLWCID60nsdG0EIbAM4hSCtcFSpAYCdY6MP1sve5BdyusgdF7o7aL 3gWpWKr1szki915doF3U1ojtJPImr3AEOds7UKKwBFikJ/ifTBPoidKFcGb5SjPUTIbY ySSSBNcpgmYLEXnnRm6edaJ8QzyU4X9yX/UEK66nQjrPVsPD7rGfW3J1MmfTGT9igl27 ZSBA== 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=u+8QKdzz8kMP8i7y3xZGNnIQj4jUn6kOAF8cUXzEziMS0K3RGVfC0MeeGl0gKmloNZ Vh/uOMsgToMmHP95AyuOhQ40Vpdte9eiUEKqEZUEFP5j7cTnra7sAqeP+IJut0kndPQz CPFMO3VSr5sZyGpg29SbP/td8BickrBrhWYaPS15wnF6uk+SANz6DaQRmbSdvu97dEob Bzq6/gsScBKOPyZqy2bT/5BgguDVFZR4CD6R11FfnjVAK5kC3asYaqioPtczUK36SHUQ /XMxl7z2/e9d0ws3V3RhXSbcyIngfG2nCMDJgdNcZMzOGh7U09nog3PZW4DrEv2P9kjf Qgag== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=ktmqbJ8i; 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 a126-v6si3615102qkf.46.2018.06.27.10.19.05 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 27 Jun 2018 10:19:05 -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=ktmqbJ8i; 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]:60573 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYE5w-0005XT-Ho for patch@linaro.org; Wed, 27 Jun 2018 13:19:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57570) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYE4P-0004aT-8d for grub-devel@gnu.org; Wed, 27 Jun 2018 13:17:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYE4M-0006KC-J3 for grub-devel@gnu.org; Wed, 27 Jun 2018 13:17:29 -0400 Received: from mail-wr0-x244.google.com ([2a00:1450:400c:c0c::244]:34528) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fYE4M-0006JB-Bl for grub-devel@gnu.org; Wed, 27 Jun 2018 13:17:26 -0400 Received: by mail-wr0-x244.google.com with SMTP id a12-v6so2823327wro.1 for ; Wed, 27 Jun 2018 10:17:26 -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=ktmqbJ8i4lTaiRhkFA/N+5Rr6IPrLSLjvsqaRXCKCPoQHGf5U2e/kVLMvx+wKAU1rQ yauueL3RpY2bH0fHMNS+GKfDLGk390Ry0i5vNy0IbDIyW+oVjMQu8M8T3VhStPSYzpFS sOQPEvvjliABr6L4neRQTX0AsF3lBDuGtpi1U= 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=AmsTl3cCUV7/fBwO3fvCQFJAVDW5VejAxojHWG+bxoBDAqxbIZvDwXgzQfsvvrazh0 FTEwzaD+4RxPd3Pw7lCC8Rq4+/KfTm0KpCoCiIRaUkyuX2ondWu88oeoP11Nn2Q0ey1E kvv40+eXMY2JaChZjFdOQ/iNEYl88La00VJ+3lsWcDsPzK+WXOUaDnPMiRkDg+35fezX MvzUcBzYLM0nYdnYVN0SnTnPhh5hNkxQZB8IPEmagDqtwVuBPoeS9ogmHPZdkWAE+sNW MGujtfbrv0528rQ1d6jv8bQwvkj7ToSNNvTp/s7cfQE8ATOVnP9lSN/ioaIYwOP7TAib qluw== X-Gm-Message-State: APt69E0inRPSGEjT21fnLjGLcpSz21nUI+zU6ldc9q2Rewpg+z/+OFLP akiYlLJXEjLXw+puGj2mYsrtLbXMOpY= X-Received: by 2002:adf:8e49:: with SMTP id n67-v6mr5785907wrb.131.1530119843860; Wed, 27 Jun 2018 10:17:23 -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 a2-v6sm3406572wmb.6.2018.06.27.10.17.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Jun 2018 10:17:22 -0700 (PDT) From: Leif Lindholm To: grub-devel@gnu.org Subject: [PATCH v3 1/6] efi: add central copy of grub_efi_find_mmap_size Date: Wed, 27 Jun 2018 18:17:15 +0100 Message-Id: <20180627171720.27028-2-leif.lindholm@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180627171720.27028-1-leif.lindholm@linaro.org> References: <20180627171720.27028-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::244 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,