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