From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mx.groups.io with SMTP id smtpd.web12.303.1662438976985344787 for ; Mon, 05 Sep 2022 21:36:17 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=bYjTV4su; spf=permerror, err=too many SPF records (domain: intel.com, ip: 192.55.52.115, 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=1662438977; x=1693974977; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LgOnb4rWbzjkTkFvuv0VHMsV1PpMqCSQliJvhqpGfck=; b=bYjTV4su5WZN3YahDIrZJuI34j8U9MyG5D33S+7n3X4N4hXthnbO+HER 723DArmAAnSQ/HVUeeIq2HEAfDQFLW2oldJdXhhsBrwc0k5dxOBx4zrtO 8ZU5RPD5XIaYKnSfYDrcimnJvpJD95BjW9fZGcRu2+i/u11ti0WgR9rWe ArT4j37gg7rvk2tyocBpMfizbu0ugN7Kui4VJIBCMnznBa09DFHld+lN/ YcrWvEjAQwegn51fFpR/+vF2KEDYQE7duYY3mYrspHfzJHrTT7azGvvDU l2L83cCmp6IeY7j/YpHJsSH7q9zE39UpHbO+m5wToSX6nwgYiUNboqm06 Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10461"; a="296502056" X-IronPort-AV: E=Sophos;i="5.93,293,1654585200"; d="scan'208";a="296502056" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Sep 2022 21:36:17 -0700 X-IronPort-AV: E=Sophos;i="5.93,293,1654585200"; d="scan'208";a="675517285" Received: from mxu9-mobl1.ccr.corp.intel.com ([10.238.4.118]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Sep 2022 21:36:16 -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 V5 1/8] EmbeddedPkg: Add AllocateRuntimePages in PrePiMemoryAllocationLib Date: Tue, 6 Sep 2022 12:35:53 +0800 Message-Id: <37f4a6991238ab679abe674d4f48141d59b06e42.1662423715.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-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 Reviewed-by: Ard Biesheuvel Acked-by: Gerd Hoffmann Signed-off-by: Min Xu --- EmbeddedPkg/Include/Library/PrePiLib.h | 19 ++++++ .../MemoryAllocationLib.c | 65 ++++++++++++++----- 2 files changed, 68 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..2cc2a7112197 100644 --- a/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c +++ b/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c @@ -14,23 +14,12 @@ #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. - -**/ +STATIC VOID * EFIAPI -AllocatePages ( - IN UINTN Pages +InternalAllocatePages ( + IN UINTN Pages, + IN EFI_MEMORY_TYPE MemoryType ) { EFI_PEI_HOB_POINTERS Hob; @@ -65,12 +54,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