From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mx.groups.io with SMTP id smtpd.web09.26612.1656212770864849318 for ; Sat, 25 Jun 2022 20:06:16 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=ViL8fKiU; spf=pass (domain: intel.com, ip: 192.55.52.43, mailfrom: min.m.xu@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656212776; x=1687748776; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=g9x6o+TsoF2DXP5MpjqAQyHqzZLglOw4TslTbCA7yPc=; b=ViL8fKiU03NMzi3EkGwIxI0x74CK2JMIW65IMY1As6QbUOOu6mQuzWl1 6CfU7K8YIIt29t9BoEJ10XvADfA8CEMkrZUGzxFjnVbPtKrUSWGmox5iI IlDgw1bltDJLVvxfgtaIY7G9Cwzw7rG9S+ZwHz+V277WaKK1FkOmr2FY8 xNf/WgwWBq6HvxooPnCrDRdCaA7s/y5lOXRRCPd7cNhtDOeCZxiKxh3uR 2JCuIPqL32974yWNnTr+O1uHlHE/ZVvqtCuUQu+vHQuaG4e0/T93ed82Q FdLJXsA+U6Yv2lWvwRGxcXDfo9fhyqL9MwzUH/XbPJRDFJWmzoVPN7oRj w==; X-IronPort-AV: E=McAfee;i="6400,9594,10389"; a="367554827" X-IronPort-AV: E=Sophos;i="5.92,223,1650956400"; d="scan'208";a="367554827" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2022 20:06:16 -0700 X-IronPort-AV: E=Sophos;i="5.92,223,1650956400"; d="scan'208";a="645862100" Received: from mxu9-mobl1.ccr.corp.intel.com ([10.255.30.236]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2022 20:06:14 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Leif Lindholm , Ard Biesheuvel , Abner Chang , Daniel Schaefer , Gerd Hoffmann Subject: [PATCH V2 3/8] EmbeddedPkg: Add AllocateRuntimePages in PrePiMemoryAllocationLib Date: Sun, 26 Jun 2022 11:05:52 +0800 Message-Id: X-Mailer: git-send-email 2.29.2.windows.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Min M Xu AllocateRuntimePages is used to allocate one or more 4KB pages of type EfiRuntimeServicesData. Cc: Leif Lindholm Cc: Ard Biesheuvel Cc: Abner Chang Cc: Daniel Schaefer Cc: Gerd Hoffmann Signed-off-by: Min Xu --- EmbeddedPkg/Include/Library/PrePiLib.h | 19 ++++++ .../MemoryAllocationLib.c | 64 ++++++++++++++----- 2 files changed, 67 insertions(+), 16 deletions(-) diff --git a/EmbeddedPkg/Include/Library/PrePiLib.h b/EmbeddedPkg/Include/Library/PrePiLib.h index 7b2cea296f1c..3741b08c4478 100644 --- a/EmbeddedPkg/Include/Library/PrePiLib.h +++ b/EmbeddedPkg/Include/Library/PrePiLib.h @@ -665,6 +665,25 @@ AllocatePages ( IN UINTN Pages ); +/** + Allocates one or more 4KB pages of type EfiRuntimeServicesData. + + Allocates the number of 4KB pages of type EfiRuntimeServicesData 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 Pages The number of 4 KB pages to allocate. + + @return A pointer to the allocated buffer or NULL if allocation fails. + +**/ +VOID * +EFIAPI +AllocateRuntimePages ( + IN UINTN Pages + ); + /** Allocates a buffer of type EfiBootServicesData. diff --git a/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c b/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c index 78f8da5e9527..9d7b34ad28fa 100644 --- a/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c +++ b/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c @@ -14,23 +14,11 @@ #include #include -/** - Allocates one or more 4KB pages of type EfiBootServicesData. - - 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 Pages The number of 4 KB pages to allocate. - - @return A pointer to the allocated buffer or NULL if allocation fails. - -**/ VOID * EFIAPI -AllocatePages ( - IN UINTN Pages +InternalAllocatePages ( + IN UINTN Pages, + IN EFI_MEMORY_TYPE MemoryType ) { EFI_PEI_HOB_POINTERS Hob; @@ -65,12 +53,56 @@ AllocatePages ( BuildMemoryAllocationHob ( Hob.HandoffInformationTable->EfiFreeMemoryTop, Pages * EFI_PAGE_SIZE, - EfiBootServicesData + MemoryType ); return (VOID *)(UINTN)Hob.HandoffInformationTable->EfiFreeMemoryTop; } } +/** + Allocates one or more 4KB pages of type EfiBootServicesData. + + 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 Pages The number of 4 KB pages to allocate. + + @return A pointer to the allocated buffer or NULL if allocation fails. + +**/ +VOID * +EFIAPI +AllocatePages ( + IN UINTN Pages + ) +{ + return InternalAllocatePages (Pages, EfiBootServicesData); +} + +/** + Allocates one or more 4KB pages of type EfiRuntimeServicesData. + + Allocates the number of 4KB pages of type EfiRuntimeServicesData 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 Pages The number of 4 KB pages to allocate. + + @return A pointer to the allocated buffer or NULL if allocation fails. + +**/ +VOID * +EFIAPI +AllocateRuntimePages ( + IN UINTN Pages + ) +{ + return InternalAllocatePages (Pages, EfiRuntimeServicesData); +} + /** Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment. -- 2.29.2.windows.2