]>
Commit | Line | Data |
---|---|---|
23c98c94 | 1 | /** @file\r |
504214c4 | 2 | Data structure and functions to allocate and free memory space.\r |
28a00297 | 3 | \r |
e63da9f0 | 4 | Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r |
cd5ebaa0 | 5 | This program and the accompanying materials\r |
23c98c94 | 6 | are licensed and made available under the terms and conditions of the BSD License\r |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
28a00297 | 9 | \r |
23c98c94 | 10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
162ed594 | 12 | \r |
13 | **/\r | |
28a00297 | 14 | \r |
15 | #ifndef _IMEM_H_\r | |
16 | #define _IMEM_H_\r | |
17 | \r | |
8ee25f48 SZ |
18 | //\r |
19 | // +---------------------------------------------------+\r | |
20 | // | 0..(EfiMaxMemoryType - 1) - Normal memory type |\r | |
21 | // +---------------------------------------------------+\r | |
2eb989bc | 22 | // | EfiMaxMemoryType..0x6FFFFFFF - Invalid |\r |
8ee25f48 SZ |
23 | // +---------------------------------------------------+\r |
24 | // | 0x70000000..0x7FFFFFFF - OEM reserved |\r | |
25 | // +---------------------------------------------------+\r | |
26 | // | 0x80000000..0xFFFFFFFF - OS reserved |\r | |
27 | // +---------------------------------------------------+\r | |
28 | //\r | |
29 | #define MEMORY_TYPE_OS_RESERVED_MIN 0x80000000\r | |
30 | #define MEMORY_TYPE_OS_RESERVED_MAX 0xFFFFFFFF\r | |
31 | #define MEMORY_TYPE_OEM_RESERVED_MIN 0x70000000\r | |
32 | #define MEMORY_TYPE_OEM_RESERVED_MAX 0x7FFFFFFF\r | |
28a00297 | 33 | \r |
34 | //\r | |
35 | // MEMORY_MAP_ENTRY\r | |
36 | //\r | |
37 | \r | |
f3f2e05d | 38 | #define MEMORY_MAP_SIGNATURE SIGNATURE_32('m','m','a','p')\r |
28a00297 | 39 | typedef struct {\r |
40 | UINTN Signature;\r | |
41 | LIST_ENTRY Link;\r | |
42 | BOOLEAN FromPages;\r | |
43 | \r | |
44 | EFI_MEMORY_TYPE Type;\r | |
45 | UINT64 Start;\r | |
46 | UINT64 End;\r | |
47 | \r | |
48 | UINT64 VirtualStart;\r | |
49 | UINT64 Attribute;\r | |
50 | } MEMORY_MAP;\r | |
51 | \r | |
52 | //\r | |
53 | // Internal prototypes\r | |
54 | //\r | |
55 | \r | |
28a00297 | 56 | \r |
162ed594 | 57 | /**\r |
28a00297 | 58 | Internal function. Used by the pool functions to allocate pages\r |
59 | to back pool allocation requests.\r | |
60 | \r | |
022c6d45 | 61 | @param PoolType The type of memory for the new pool pages\r |
62 | @param NumberOfPages No of pages to allocate\r | |
63 | @param Alignment Bits to align.\r | |
e63da9f0 | 64 | @param NeedGuard Flag to indicate Guard page is needed or not\r |
28a00297 | 65 | \r |
162ed594 | 66 | @return The allocated memory, or NULL\r |
28a00297 | 67 | \r |
162ed594 | 68 | **/\r |
69 | VOID *\r | |
70 | CoreAllocatePoolPages (\r | |
23c98c94 | 71 | IN EFI_MEMORY_TYPE PoolType,\r |
72 | IN UINTN NumberOfPages,\r | |
e63da9f0 JW |
73 | IN UINTN Alignment,\r |
74 | IN BOOLEAN NeedGuard\r | |
23c98c94 | 75 | );\r |
28a00297 | 76 | \r |
28a00297 | 77 | \r |
28a00297 | 78 | \r |
162ed594 | 79 | /**\r |
80 | Internal function. Frees pool pages allocated via AllocatePoolPages ()\r | |
28a00297 | 81 | \r |
022c6d45 | 82 | @param Memory The base address to free\r |
162ed594 | 83 | @param NumberOfPages The number of pages to free\r |
28a00297 | 84 | \r |
162ed594 | 85 | **/\r |
28a00297 | 86 | VOID\r |
87 | CoreFreePoolPages (\r | |
88 | IN EFI_PHYSICAL_ADDRESS Memory,\r | |
89 | IN UINTN NumberOfPages\r | |
23c98c94 | 90 | );\r |
28a00297 | 91 | \r |
28a00297 | 92 | \r |
28a00297 | 93 | \r |
162ed594 | 94 | /**\r |
95 | Internal function to allocate pool of a particular type.\r | |
96 | Caller must have the memory lock held\r | |
28a00297 | 97 | \r |
022c6d45 | 98 | @param PoolType Type of pool to allocate\r |
99 | @param Size The amount of pool to allocate\r | |
e63da9f0 | 100 | @param NeedGuard Flag to indicate Guard page is needed or not\r |
28a00297 | 101 | \r |
162ed594 | 102 | @return The allocate pool, or NULL\r |
28a00297 | 103 | \r |
162ed594 | 104 | **/\r |
28a00297 | 105 | VOID *\r |
106 | CoreAllocatePoolI (\r | |
107 | IN EFI_MEMORY_TYPE PoolType,\r | |
e63da9f0 JW |
108 | IN UINTN Size,\r |
109 | IN BOOLEAN NeedGuard\r | |
23c98c94 | 110 | );\r |
28a00297 | 111 | \r |
28a00297 | 112 | \r |
28a00297 | 113 | \r |
162ed594 | 114 | /**\r |
115 | Internal function to free a pool entry.\r | |
28a00297 | 116 | Caller must have the memory lock held\r |
117 | \r | |
022c6d45 | 118 | @param Buffer The allocated pool entry to free\r |
925f0d1a | 119 | @param PoolType Pointer to pool type\r |
28a00297 | 120 | \r |
022c6d45 | 121 | @retval EFI_INVALID_PARAMETER Buffer not valid\r |
162ed594 | 122 | @retval EFI_SUCCESS Buffer successfully freed.\r |
28a00297 | 123 | \r |
162ed594 | 124 | **/\r |
28a00297 | 125 | EFI_STATUS\r |
126 | CoreFreePoolI (\r | |
925f0d1a SZ |
127 | IN VOID *Buffer,\r |
128 | OUT EFI_MEMORY_TYPE *PoolType OPTIONAL\r | |
23c98c94 | 129 | );\r |
28a00297 | 130 | \r |
28a00297 | 131 | \r |
28a00297 | 132 | \r |
162ed594 | 133 | /**\r |
134 | Enter critical section by gaining lock on gMemoryLock.\r | |
28a00297 | 135 | \r |
162ed594 | 136 | **/\r |
28a00297 | 137 | VOID\r |
138 | CoreAcquireMemoryLock (\r | |
139 | VOID\r | |
23c98c94 | 140 | );\r |
28a00297 | 141 | \r |
28a00297 | 142 | \r |
162ed594 | 143 | /**\r |
144 | Exit critical section by releasing lock on gMemoryLock.\r | |
28a00297 | 145 | \r |
162ed594 | 146 | **/\r |
28a00297 | 147 | VOID\r |
148 | CoreReleaseMemoryLock (\r | |
149 | VOID\r | |
23c98c94 | 150 | );\r |
28a00297 | 151 | \r |
e63da9f0 JW |
152 | /**\r |
153 | Allocates pages from the memory map.\r | |
154 | \r | |
155 | @param Type The type of allocation to perform\r | |
156 | @param MemoryType The type of memory to turn the allocated pages\r | |
157 | into\r | |
158 | @param NumberOfPages The number of pages to allocate\r | |
159 | @param Memory A pointer to receive the base allocated memory\r | |
160 | address\r | |
161 | @param NeedGuard Flag to indicate Guard page is needed or not\r | |
162 | \r | |
163 | @return Status. On success, Memory is filled in with the base address allocated\r | |
164 | @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in\r | |
165 | spec.\r | |
166 | @retval EFI_NOT_FOUND Could not allocate pages match the requirement.\r | |
167 | @retval EFI_OUT_OF_RESOURCES No enough pages to allocate.\r | |
168 | @retval EFI_SUCCESS Pages successfully allocated.\r | |
169 | \r | |
170 | **/\r | |
171 | EFI_STATUS\r | |
172 | EFIAPI\r | |
173 | CoreInternalAllocatePages (\r | |
174 | IN EFI_ALLOCATE_TYPE Type,\r | |
175 | IN EFI_MEMORY_TYPE MemoryType,\r | |
176 | IN UINTN NumberOfPages,\r | |
177 | IN OUT EFI_PHYSICAL_ADDRESS *Memory,\r | |
178 | IN BOOLEAN NeedGuard\r | |
179 | );\r | |
28a00297 | 180 | \r |
181 | //\r | |
182 | // Internal Global data\r | |
183 | //\r | |
184 | \r | |
022c6d45 | 185 | extern EFI_LOCK gMemoryLock;\r |
28a00297 | 186 | extern LIST_ENTRY gMemoryMap;\r |
28a00297 | 187 | extern LIST_ENTRY mGcdMemorySpaceMap;\r |
188 | #endif\r |