2 Data structure and functions to allocate and free memory space.
4 Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 // +---------------------------------------------------+
20 // | 0..(EfiMaxMemoryType - 1) - Normal memory type |
21 // +---------------------------------------------------+
22 // | EfiMaxMemoryType..0x6FFFFFFF - Invalid |
23 // +---------------------------------------------------+
24 // | 0x70000000..0x7FFFFFFF - OEM reserved |
25 // +---------------------------------------------------+
26 // | 0x80000000..0xFFFFFFFF - OS reserved |
27 // +---------------------------------------------------+
29 #define MEMORY_TYPE_OS_RESERVED_MIN 0x80000000
30 #define MEMORY_TYPE_OS_RESERVED_MAX 0xFFFFFFFF
31 #define MEMORY_TYPE_OEM_RESERVED_MIN 0x70000000
32 #define MEMORY_TYPE_OEM_RESERVED_MAX 0x7FFFFFFF
38 #define MEMORY_MAP_SIGNATURE SIGNATURE_32('m','m','a','p')
53 // Internal prototypes
58 Internal function. Used by the pool functions to allocate pages
59 to back pool allocation requests.
61 @param PoolType The type of memory for the new pool pages
62 @param NumberOfPages No of pages to allocate
63 @param Alignment Bits to align.
64 @param NeedGuard Flag to indicate Guard page is needed or not
66 @return The allocated memory, or NULL
70 CoreAllocatePoolPages (
71 IN EFI_MEMORY_TYPE PoolType
,
72 IN UINTN NumberOfPages
,
80 Internal function. Frees pool pages allocated via AllocatePoolPages ()
82 @param Memory The base address to free
83 @param NumberOfPages The number of pages to free
88 IN EFI_PHYSICAL_ADDRESS Memory
,
89 IN UINTN NumberOfPages
95 Internal function to allocate pool of a particular type.
96 Caller must have the memory lock held
98 @param PoolType Type of pool to allocate
99 @param Size The amount of pool to allocate
100 @param NeedGuard Flag to indicate Guard page is needed or not
102 @return The allocate pool, or NULL
107 IN EFI_MEMORY_TYPE PoolType
,
115 Internal function to free a pool entry.
116 Caller must have the memory lock held
118 @param Buffer The allocated pool entry to free
119 @param PoolType Pointer to pool type
121 @retval EFI_INVALID_PARAMETER Buffer not valid
122 @retval EFI_SUCCESS Buffer successfully freed.
128 OUT EFI_MEMORY_TYPE
*PoolType OPTIONAL
134 Enter critical section by gaining lock on gMemoryLock.
138 CoreAcquireMemoryLock (
144 Exit critical section by releasing lock on gMemoryLock.
148 CoreReleaseMemoryLock (
153 Allocates pages from the memory map.
155 @param Type The type of allocation to perform
156 @param MemoryType The type of memory to turn the allocated pages
158 @param NumberOfPages The number of pages to allocate
159 @param Memory A pointer to receive the base allocated memory
161 @param NeedGuard Flag to indicate Guard page is needed or not
163 @return Status. On success, Memory is filled in with the base address allocated
164 @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in
166 @retval EFI_NOT_FOUND Could not allocate pages match the requirement.
167 @retval EFI_OUT_OF_RESOURCES No enough pages to allocate.
168 @retval EFI_SUCCESS Pages successfully allocated.
173 CoreInternalAllocatePages (
174 IN EFI_ALLOCATE_TYPE Type
,
175 IN EFI_MEMORY_TYPE MemoryType
,
176 IN UINTN NumberOfPages
,
177 IN OUT EFI_PHYSICAL_ADDRESS
*Memory
,
182 // Internal Global data
185 extern EFI_LOCK gMemoryLock
;
186 extern LIST_ENTRY gMemoryMap
;
187 extern LIST_ENTRY mGcdMemorySpaceMap
;