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