2 Data structure and functions to allocate and free memory space.
4 Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
13 // +---------------------------------------------------+
14 // | 0..(EfiMaxMemoryType - 1) - Normal memory type |
15 // +---------------------------------------------------+
16 // | EfiMaxMemoryType..0x6FFFFFFF - Invalid |
17 // +---------------------------------------------------+
18 // | 0x70000000..0x7FFFFFFF - OEM reserved |
19 // +---------------------------------------------------+
20 // | 0x80000000..0xFFFFFFFF - OS reserved |
21 // +---------------------------------------------------+
23 #define MEMORY_TYPE_OS_RESERVED_MIN 0x80000000
24 #define MEMORY_TYPE_OS_RESERVED_MAX 0xFFFFFFFF
25 #define MEMORY_TYPE_OEM_RESERVED_MIN 0x70000000
26 #define MEMORY_TYPE_OEM_RESERVED_MAX 0x7FFFFFFF
32 #define MEMORY_MAP_SIGNATURE SIGNATURE_32('m','m','a','p')
47 // Internal prototypes
51 Internal function. Used by the pool functions to allocate pages
52 to back pool allocation requests.
54 @param PoolType The type of memory for the new pool pages
55 @param NumberOfPages No of pages to allocate
56 @param Alignment Bits to align.
57 @param NeedGuard Flag to indicate Guard page is needed or not
59 @return The allocated memory, or NULL
63 CoreAllocatePoolPages (
64 IN EFI_MEMORY_TYPE PoolType
,
65 IN UINTN NumberOfPages
,
71 Internal function. Frees pool pages allocated via AllocatePoolPages ()
73 @param Memory The base address to free
74 @param NumberOfPages The number of pages to free
79 IN EFI_PHYSICAL_ADDRESS Memory
,
80 IN UINTN NumberOfPages
84 Internal function to allocate pool of a particular type.
85 Caller must have the memory lock held
87 @param PoolType Type of pool to allocate
88 @param Size The amount of pool to allocate
89 @param NeedGuard Flag to indicate Guard page is needed or not
91 @return The allocate pool, or NULL
96 IN EFI_MEMORY_TYPE PoolType
,
102 Internal function to free a pool entry.
103 Caller must have the memory lock held
105 @param Buffer The allocated pool entry to free
106 @param PoolType Pointer to pool type
108 @retval EFI_INVALID_PARAMETER Buffer not valid
109 @retval EFI_SUCCESS Buffer successfully freed.
115 OUT EFI_MEMORY_TYPE
*PoolType OPTIONAL
119 Enter critical section by gaining lock on gMemoryLock.
123 CoreAcquireMemoryLock (
128 Exit critical section by releasing lock on gMemoryLock.
132 CoreReleaseMemoryLock (
137 Allocates pages from the memory map.
139 @param Type The type of allocation to perform
140 @param MemoryType The type of memory to turn the allocated pages
142 @param NumberOfPages The number of pages to allocate
143 @param Memory A pointer to receive the base allocated memory
145 @param NeedGuard Flag to indicate Guard page is needed or not
147 @return Status. On success, Memory is filled in with the base address allocated
148 @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in
150 @retval EFI_NOT_FOUND Could not allocate pages match the requirement.
151 @retval EFI_OUT_OF_RESOURCES No enough pages to allocate.
152 @retval EFI_SUCCESS Pages successfully allocated.
157 CoreInternalAllocatePages (
158 IN EFI_ALLOCATE_TYPE Type
,
159 IN EFI_MEMORY_TYPE MemoryType
,
160 IN UINTN NumberOfPages
,
161 IN OUT EFI_PHYSICAL_ADDRESS
*Memory
,
166 // Internal Global data
169 extern EFI_LOCK gMemoryLock
;
170 extern LIST_ENTRY gMemoryMap
;
171 extern LIST_ENTRY mGcdMemorySpaceMap
;