From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.24; helo=mga09.intel.com; envelope-from=star.zeng@intel.com; receiver=edk2-devel@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 7A82F2034860B for ; Tue, 22 May 2018 18:59:50 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 May 2018 18:59:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,431,1520924400"; d="scan'208";a="57646786" Received: from shzintpr02.sh.intel.com (HELO [10.253.24.23]) ([10.239.4.160]) by fmsmga001.fm.intel.com with ESMTP; 22 May 2018 18:59:48 -0700 To: Ard Biesheuvel , edk2-devel@lists.01.org Cc: Eric Dong , Liming Gao , Dandan Bi , Leif Lindholm , Michael D Kinney , Laszlo Ersek , star.zeng@intel.com References: <20180522140850.30369-1-ard.biesheuvel@linaro.org> <20180522140850.30369-4-ard.biesheuvel@linaro.org> From: "Zeng, Star" Message-ID: <34a78e76-107f-da2d-38f1-b96d1d559c6f@intel.com> Date: Wed, 23 May 2018 09:59:17 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <20180522140850.30369-4-ard.biesheuvel@linaro.org> Subject: Re: [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: , X-List-Received-Date: Wed, 23 May 2018 01:59:50 -0000 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit On 2018/5/22 22:08, Ard Biesheuvel wrote: > 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 Glad to see this patch series. It is the case "PEI for S3", but not "PEI after a warm reboot". Thanks, Star > 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(+) > > 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; > +} >