From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mx.groups.io with SMTP id smtpd.web09.21069.1628769481864596349 for ; Thu, 12 Aug 2021 04:58:20 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.20, mailfrom: min.m.xu@intel.com) X-IronPort-AV: E=McAfee;i="6200,9189,10073"; a="202524387" X-IronPort-AV: E=Sophos;i="5.84,315,1620716400"; d="scan'208";a="202524387" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Aug 2021 04:58:20 -0700 X-IronPort-AV: E=Sophos;i="5.84,315,1620716400"; d="scan'208";a="517433917" Received: from mxu9-mobl1.ccr.corp.intel.com ([10.249.175.248]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Aug 2021 04:58:17 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min Xu , Michael D Kinney , Liming Gao , Zhiguang Liu , Jiewen Yao Subject: [PATCH 20/23] MdePkg: Add AllocatePagesWithMemoryType support in PeiMemoryAllocationLib Date: Thu, 12 Aug 2021 19:56:59 +0800 Message-Id: <6924228fa3969ae944d6aebbe653d4046b6cef54.1628767741.git.min.m.xu@intel.com> X-Mailer: git-send-email 2.29.2.windows.2 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 Allocates one or more 4KB pages of given type MemoryType. Allocates the number of 4KB pages of 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. Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Cc: Jiewen Yao Signed-off-by: Min Xu --- MdePkg/Include/Library/MemoryAllocationLib.h | 21 +++++++++++++++ .../MemoryAllocationLib.c | 27 +++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/MdePkg/Include/Library/MemoryAllocationLib.h b/MdePkg/Include/Library/MemoryAllocationLib.h index 65a30cf146dd..2bdc0592ef3e 100644 --- a/MdePkg/Include/Library/MemoryAllocationLib.h +++ b/MdePkg/Include/Library/MemoryAllocationLib.h @@ -484,4 +484,25 @@ FreePool ( IN VOID *Buffer ); +/** + Allocates one or more 4KB pages of given type MemoryType. + + Allocates the number of 4KB pages of 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 MemoryType Type of memory to use for this allocation. + @param Pages The number of 4 KB pages to allocate. + + @return A pointer to the allocated buffer or NULL if allocation fails. + +**/ +VOID * +EFIAPI +AllocatePagesWithMemoryType ( + IN UINTN MemoryType, + IN UINTN Pages + ); + #endif diff --git a/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c b/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c index b3f9df74f139..dcb313349729 100644 --- a/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c +++ b/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c @@ -839,4 +839,31 @@ FreePool ( // } +/** + Allocates one or more 4KB pages of given type MemoryType. + Allocates the number of 4KB pages of 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 MemoryType Type of memory to use for this allocation. + @param Pages The number of 4 KB pages to allocate. + + @return A pointer to the allocated buffer or NULL if allocation fails. + +**/ +VOID * +EFIAPI +AllocatePagesWithMemoryType ( + IN UINTN MemoryType, + IN UINTN Pages + ) +{ + if (MemoryType >= EfiMaxMemoryType) { + ASSERT (FALSE); + return NULL; + } + + return InternalAllocatePages (MemoryType, Pages); +} -- 2.29.2.windows.2