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
52 Internal function. Used by the pool functions to allocate pages
53 to back pool allocation requests.
55 @param PoolType The type of memory for the new pool pages
56 @param NumberOfPages No of pages to allocate
57 @param Alignment Bits to align.
58 @param NeedGuard Flag to indicate Guard page is needed or not
60 @return The allocated memory, or NULL
64 CoreAllocatePoolPages (
65 IN EFI_MEMORY_TYPE PoolType
,
66 IN UINTN NumberOfPages
,
74 Internal function. Frees pool pages allocated via AllocatePoolPages ()
76 @param Memory The base address to free
77 @param NumberOfPages The number of pages to free
82 IN EFI_PHYSICAL_ADDRESS Memory
,
83 IN UINTN NumberOfPages
89 Internal function to allocate pool of a particular type.
90 Caller must have the memory lock held
92 @param PoolType Type of pool to allocate
93 @param Size The amount of pool to allocate
94 @param NeedGuard Flag to indicate Guard page is needed or not
96 @return The allocate pool, or NULL
101 IN EFI_MEMORY_TYPE PoolType
,
109 Internal function to free a pool entry.
110 Caller must have the memory lock held
112 @param Buffer The allocated pool entry to free
113 @param PoolType Pointer to pool type
115 @retval EFI_INVALID_PARAMETER Buffer not valid
116 @retval EFI_SUCCESS Buffer successfully freed.
122 OUT EFI_MEMORY_TYPE
*PoolType OPTIONAL
128 Enter critical section by gaining lock on gMemoryLock.
132 CoreAcquireMemoryLock (
138 Exit critical section by releasing lock on gMemoryLock.
142 CoreReleaseMemoryLock (
147 Allocates pages from the memory map.
149 @param Type The type of allocation to perform
150 @param MemoryType The type of memory to turn the allocated pages
152 @param NumberOfPages The number of pages to allocate
153 @param Memory A pointer to receive the base allocated memory
155 @param NeedGuard Flag to indicate Guard page is needed or not
157 @return Status. On success, Memory is filled in with the base address allocated
158 @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in
160 @retval EFI_NOT_FOUND Could not allocate pages match the requirement.
161 @retval EFI_OUT_OF_RESOURCES No enough pages to allocate.
162 @retval EFI_SUCCESS Pages successfully allocated.
167 CoreInternalAllocatePages (
168 IN EFI_ALLOCATE_TYPE Type
,
169 IN EFI_MEMORY_TYPE MemoryType
,
170 IN UINTN NumberOfPages
,
171 IN OUT EFI_PHYSICAL_ADDRESS
*Memory
,
176 // Internal Global data
179 extern EFI_LOCK gMemoryLock
;
180 extern LIST_ENTRY gMemoryMap
;
181 extern LIST_ENTRY mGcdMemorySpaceMap
;