From patchwork Tue May 22 14:08:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 136550 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1682984lji; Tue, 22 May 2018 07:09:08 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrYYNcZYzY7PU8YXbVVe9FdzYAlB+olFRFsPQum88JSEhd5pJFE568h6PzZkmIvzzvGYJHu X-Received: by 2002:a62:5050:: with SMTP id e77-v6mr24716471pfb.16.1526998148438; Tue, 22 May 2018 07:09:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526998148; cv=none; d=google.com; s=arc-20160816; b=FWbLLAjKZWcbnO3M2h6cDtS5N9YtwRIIC2NbOWtczgNr8VLTzVnj7xJUa17l4oorrI 7nCzHZ55iMHlPgs4s+NY9gHH2Y1LS8OKntdZDyMnNxtZhF7yIduIs0pV5Q+OPmHIpEpA mMkdUzNLy1mqA0T6m/KlKxbEbyYIf3Pu58XsMfjllxns2ykLhjFlJa9EMmNKW3QRw55x UC6wBVziOo+MhECYc8V7lK4mNH8XGShW44WK1lWDcwJlt+yTnR+hNP3piyAYn3SVgIUw YF8vjUoEaYxDYb6+O+YyqDebkZzaT1ZXyZBPfLb+F8ZQpyOsv9cyxAjwvsAbKK6f/Djl frqA== 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 :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=RvG/adXqwn3PcoGd1t2P2vEKOuAWU89ayKP0ytV4fHs=; b=K5njUm2hkZkN0KGgg+KSStDi5EX5sjxml/cAIqHW4Wuc3gzTa+3ciNqsVvw3unV9S9 ymhm9PBx3G4BYZmkPnT+O7tTgnUpz9kmi9drnnRhgqdROEqWKFesFQzRPFhT8NeQnX4r LXvWnl5IpAgUSQU/uaIMRB/N2B/Ikhlqg3KD/mcCeUtP2hq5r6emU5OgjxZGWW2As2op GrVmBRtrWqeoE33Z8UX/WOJVj3F9Gw42SdV+j01ZCekHDNlG3flEv8tT7eGQqGC6u7Cn 0NjzrhhCPZHLCLunp4xLOnsBFnVF9ovQxi/CxZ4GKLc5JiSD3ec2U2DPl+Jokzu2OFJO B52w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=djJvkh3Q; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id n22-v6si16605946pfb.126.2018.05.22.07.09.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 May 2018 07:09:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=djJvkh3Q; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 63F95203BB520; Tue, 22 May 2018 07:09:06 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:400c:c09::235; helo=mail-wm0-x235.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wm0-x235.google.com (mail-wm0-x235.google.com [IPv6:2a00:1450:400c:c09::235]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 9CF8B203B992C for ; Tue, 22 May 2018 07:09:04 -0700 (PDT) Received: by mail-wm0-x235.google.com with SMTP id a67-v6so133274wmf.3 for ; Tue, 22 May 2018 07:09:04 -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=LHlwcmVHos8NZgj2kGrntQDGOb8hzisISq9LYld3ZUU=; b=djJvkh3QOuxwTexaH9J75kuD599gt+IXxy1LJFrMjyrUpy7dNp9xJt76FsUeG28eut VKdZMJiEiUKHJNiNTst5Tp8ird0+/jOuzqsCx1mYfu1o3JNRX0sNKEXHrivBfEVlx41Z YN+z1SYnV8Kj5FbDc8eOOv0EeXEUTOnn0op+0= 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=LHlwcmVHos8NZgj2kGrntQDGOb8hzisISq9LYld3ZUU=; b=ZCcjjb6uhc4Ou5pLBH6okmzQG23b2h1otEQCLX2cSQ0UnMtyluXNYG43zUGwlfMHQQ aTSjJd+Zk64c/pGzlkDTbNwNVNyrf7pfxgwJ4M4staiN4ncO2AU4F/9f6Ak9JkRSVeVd GiJUy0/bru0E8MJZsbxkTr8bXHQi0O0isX3t1A9K9OL3gTnB4dMd+vVTUy/XaPFYujPv NqWg4unnFg1v4QuG3mH8aBt1MJeJF0vkbGDa3gc8X59VFzp014R6eQThGt5ptsdMMv3z esy7Pu52vQKVlTa8p9FjTzuxQv5BmuU+Aq6nWFMjVWirgAFVhnDGxxw/WohLQYbpiLcV a23A== X-Gm-Message-State: ALKqPwdOQEdBouP7XikdVdC3Cmc4b/nrib2a/epxlxVMjCGf9wqMxq4f DsLTqREmpKKuiaZ735UG7+TnE1vfJ+E= X-Received: by 2002:a1c:a84d:: with SMTP id r74-v6mr1458905wme.114.1526998142791; Tue, 22 May 2018 07:09:02 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:3995:5470:200:1aff:fe1b:b328]) by smtp.gmail.com with ESMTPSA id r6-v6sm17755545wrg.73.2018.05.22.07.09.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 May 2018 07:09:02 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Tue, 22 May 2018 16:08:47 +0200 Message-Id: <20180522140850.30369-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180522140850.30369-1-ard.biesheuvel@linaro.org> References: <20180522140850.30369-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH 3/6] MdePkg/UefiLib: introduce EfiAllocatePeiAccessiblePages routine X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eric Dong , Ard Biesheuvel , Liming Gao , Dandan Bi , Leif Lindholm , Michael D Kinney , Laszlo Ersek , Star Zeng MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" Add a routine to UefiLib that abstracts the allocation of memory that should be accessible by PEI after a warm reboot. We will use it to replace open coded implementations that limit the address to < 4 GB, which may not be possible on non-Intel systems that have no 32-bit addressable memory at all. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- MdePkg/Include/Library/UefiLib.h | 23 ++++++++++ MdePkg/Library/UefiLib/UefiLib.c | 48 ++++++++++++++++++++ 2 files changed, 71 insertions(+) -- 2.17.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/MdePkg/Include/Library/UefiLib.h b/MdePkg/Include/Library/UefiLib.h index 256498e3fd8d..8fa077af41e0 100644 --- a/MdePkg/Include/Library/UefiLib.h +++ b/MdePkg/Include/Library/UefiLib.h @@ -1520,4 +1520,27 @@ EfiLocateProtocolBuffer ( OUT UINTN *NoProtocols, OUT VOID ***Buffer ); + +/** + Allocates one or more 4KB pages of a given type from a memory region that is + accessible to PEI. + + Allocates the number of 4KB pages of type 'MemoryType' and returns a + pointer to the allocated buffer. The buffer returned is aligned on a 4KB + boundary. If Pages is 0, then NULL is returned. If there is not enough + memory remaining to satisfy the request, then NULL is returned. + + @param[in] MemoryType The memory type to allocate + @param[in] Pages The number of 4 KB pages to allocate. + + @return A pointer to the allocated buffer or NULL if allocation fails. + +**/ +VOID * +EFIAPI +EfiAllocatePeiAccessiblePages ( + IN EFI_MEMORY_TYPE MemoryType, + IN UINTN Pages + ); + #endif diff --git a/MdePkg/Library/UefiLib/UefiLib.c b/MdePkg/Library/UefiLib/UefiLib.c index ba449a1c34ce..3a9d75149dd7 100644 --- a/MdePkg/Library/UefiLib/UefiLib.c +++ b/MdePkg/Library/UefiLib/UefiLib.c @@ -1715,3 +1715,51 @@ EfiLocateProtocolBuffer ( return EFI_SUCCESS; } + +/** + Allocates one or more 4KB pages of a given type from a memory region that is + accessible to PEI. + + Allocates the number of 4KB pages of type 'MemoryType' and returns a + pointer to the allocated buffer. The buffer returned is aligned on a 4KB + boundary. If Pages is 0, then NULL is returned. If there is not enough + memory remaining to satisfy the request, then NULL is returned. + + @param[in] MemoryType The memory type to allocate + @param[in] Pages The number of 4 KB pages to allocate. + + @return A pointer to the allocated buffer or NULL if allocation fails. + +**/ +VOID * +EFIAPI +EfiAllocatePeiAccessiblePages ( + IN EFI_MEMORY_TYPE MemoryType, + IN UINTN Pages + ) +{ + EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS Memory; + EFI_ALLOCATE_TYPE AllocType; + + if (Pages == 0) { + return NULL; + } + +#ifdef MDE_CPU_X64 + // + // On X64 systems, a X64 build of DXE may be combined with a 32-bit build of + // PEI, and so we need to allocate below 4 GB to ensure that the allocation + // is accessible by PEI. + // + AllocType = AllocateMaxAddress; + Memory = MAX_UINT32; +#else + AllocType = AllocateAnyPages; +#endif + Status = gBS->AllocatePages (AllocType, MemoryType, Pages, &Memory); + if (EFI_ERROR (Status)) { + return NULL; + } + return (VOID *)(UINTN)Memory; +}