Skip to content

Commit fb008db

Browse files
mxu9mergify[bot]
authored andcommitted
EmbeddedPkg: Add AllocateRuntimePages in PrePiMemoryAllocationLib
AllocateRuntimePages is used to allocate one or more 4KB pages of type EfiRuntimeServicesData. Cc: Leif Lindholm <quic_llindhol@quicinc.com> Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Abner Chang <abner.chang@hpe.com> Cc: Daniel Schaefer <daniel.schaefer@hpe.com> Cc: Gerd Hoffmann <kraxel@redhat.com> Reviewed-by: Ard Biesheuvel <ardb+tianocore@kernel.org> Acked-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Min Xu <min.m.xu@intel.com>
1 parent 7cc7c52 commit fb008db

File tree

2 files changed

+68
-16
lines changed

2 files changed

+68
-16
lines changed

EmbeddedPkg/Include/Library/PrePiLib.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,25 @@ AllocatePages (
665665
IN UINTN Pages
666666
);
667667

668+
/**
669+
Allocates one or more 4KB pages of type EfiRuntimeServicesData.
670+
671+
Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the
672+
allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
673+
is returned. If there is not enough memory remaining to satisfy the request, then NULL is
674+
returned.
675+
676+
@param Pages The number of 4 KB pages to allocate.
677+
678+
@return A pointer to the allocated buffer or NULL if allocation fails.
679+
680+
**/
681+
VOID *
682+
EFIAPI
683+
AllocateRuntimePages (
684+
IN UINTN Pages
685+
);
686+
668687
/**
669688
Allocates a buffer of type EfiBootServicesData.
670689

EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,12 @@
1414
#include <Library/PrePiLib.h>
1515
#include <Library/DebugLib.h>
1616

17-
/**
18-
Allocates one or more 4KB pages of type EfiBootServicesData.
19-
20-
Allocates the number of 4KB pages of MemoryType and returns a pointer to the
21-
allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
22-
is returned. If there is not enough memory remaining to satisfy the request, then NULL is
23-
returned.
24-
25-
@param Pages The number of 4 KB pages to allocate.
26-
27-
@return A pointer to the allocated buffer or NULL if allocation fails.
28-
29-
**/
17+
STATIC
3018
VOID *
3119
EFIAPI
32-
AllocatePages (
33-
IN UINTN Pages
20+
InternalAllocatePages (
21+
IN UINTN Pages,
22+
IN EFI_MEMORY_TYPE MemoryType
3423
)
3524
{
3625
EFI_PEI_HOB_POINTERS Hob;
@@ -65,12 +54,56 @@ AllocatePages (
6554
BuildMemoryAllocationHob (
6655
Hob.HandoffInformationTable->EfiFreeMemoryTop,
6756
Pages * EFI_PAGE_SIZE,
68-
EfiBootServicesData
57+
MemoryType
6958
);
7059
return (VOID *)(UINTN)Hob.HandoffInformationTable->EfiFreeMemoryTop;
7160
}
7261
}
7362

63+
/**
64+
Allocates one or more 4KB pages of type EfiBootServicesData.
65+
66+
Allocates the number of 4KB pages of MemoryType and returns a pointer to the
67+
allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
68+
is returned. If there is not enough memory remaining to satisfy the request, then NULL is
69+
returned.
70+
71+
@param Pages The number of 4 KB pages to allocate.
72+
73+
@return A pointer to the allocated buffer or NULL if allocation fails.
74+
75+
**/
76+
VOID *
77+
EFIAPI
78+
AllocatePages (
79+
IN UINTN Pages
80+
)
81+
{
82+
return InternalAllocatePages (Pages, EfiBootServicesData);
83+
}
84+
85+
/**
86+
Allocates one or more 4KB pages of type EfiRuntimeServicesData.
87+
88+
Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the
89+
allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
90+
is returned. If there is not enough memory remaining to satisfy the request, then NULL is
91+
returned.
92+
93+
@param Pages The number of 4 KB pages to allocate.
94+
95+
@return A pointer to the allocated buffer or NULL if allocation fails.
96+
97+
**/
98+
VOID *
99+
EFIAPI
100+
AllocateRuntimePages (
101+
IN UINTN Pages
102+
)
103+
{
104+
return InternalAllocatePages (Pages, EfiRuntimeServicesData);
105+
}
106+
74107
/**
75108
Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment.
76109

0 commit comments

Comments
 (0)