]>
Commit | Line | Data |
---|---|---|
23c98c94 | 1 | /** @file\r |
504214c4 | 2 | Data structure and functions to allocate and free memory space.\r |
28a00297 | 3 | \r |
8ee25f48 | 4 | Copyright (c) 2006 - 2015, 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 | |
18 | #if defined (MDE_CPU_IPF)\r | |
ec90508b | 19 | ///\r |
20 | /// For Itanium machines make the default allocations 8K aligned\r | |
21 | ///\r | |
28a00297 | 22 | #define EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT (EFI_PAGE_SIZE * 2)\r |
23 | #define DEFAULT_PAGE_ALLOCATION (EFI_PAGE_SIZE * 2)\r | |
24 | \r | |
15290510 AB |
25 | #elif defined (MDE_CPU_AARCH64)\r |
26 | ///\r | |
27 | /// 64-bit ARM systems allow the OS to execute with 64 KB page size,\r | |
28 | /// so for improved interoperability with the firmware, align the\r | |
29 | /// runtime regions to 64 KB as well\r | |
30 | ///\r | |
31 | #define EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT (SIZE_64KB)\r | |
32 | #define DEFAULT_PAGE_ALLOCATION (EFI_PAGE_SIZE)\r | |
33 | \r | |
28a00297 | 34 | #else\r |
ec90508b | 35 | ///\r |
36 | /// For genric EFI machines make the default allocations 4K aligned\r | |
37 | ///\r | |
28a00297 | 38 | #define EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT (EFI_PAGE_SIZE)\r |
39 | #define DEFAULT_PAGE_ALLOCATION (EFI_PAGE_SIZE)\r | |
40 | \r | |
41 | #endif\r | |
42 | \r | |
8ee25f48 SZ |
43 | //\r |
44 | // +---------------------------------------------------+\r | |
45 | // | 0..(EfiMaxMemoryType - 1) - Normal memory type |\r | |
46 | // +---------------------------------------------------+\r | |
47 | // | EfiMaxMemoryType..0x6FFFFFFF - Ilegal |\r | |
48 | // +---------------------------------------------------+\r | |
49 | // | 0x70000000..0x7FFFFFFF - OEM reserved |\r | |
50 | // +---------------------------------------------------+\r | |
51 | // | 0x80000000..0xFFFFFFFF - OS reserved |\r | |
52 | // +---------------------------------------------------+\r | |
53 | //\r | |
54 | #define MEMORY_TYPE_OS_RESERVED_MIN 0x80000000\r | |
55 | #define MEMORY_TYPE_OS_RESERVED_MAX 0xFFFFFFFF\r | |
56 | #define MEMORY_TYPE_OEM_RESERVED_MIN 0x70000000\r | |
57 | #define MEMORY_TYPE_OEM_RESERVED_MAX 0x7FFFFFFF\r | |
28a00297 | 58 | \r |
59 | //\r | |
60 | // MEMORY_MAP_ENTRY\r | |
61 | //\r | |
62 | \r | |
f3f2e05d | 63 | #define MEMORY_MAP_SIGNATURE SIGNATURE_32('m','m','a','p')\r |
28a00297 | 64 | typedef struct {\r |
65 | UINTN Signature;\r | |
66 | LIST_ENTRY Link;\r | |
67 | BOOLEAN FromPages;\r | |
68 | \r | |
69 | EFI_MEMORY_TYPE Type;\r | |
70 | UINT64 Start;\r | |
71 | UINT64 End;\r | |
72 | \r | |
73 | UINT64 VirtualStart;\r | |
74 | UINT64 Attribute;\r | |
75 | } MEMORY_MAP;\r | |
76 | \r | |
77 | //\r | |
78 | // Internal prototypes\r | |
79 | //\r | |
80 | \r | |
28a00297 | 81 | \r |
162ed594 | 82 | /**\r |
28a00297 | 83 | Internal function. Used by the pool functions to allocate pages\r |
84 | to back pool allocation requests.\r | |
85 | \r | |
022c6d45 | 86 | @param PoolType The type of memory for the new pool pages\r |
87 | @param NumberOfPages No of pages to allocate\r | |
88 | @param Alignment Bits to align.\r | |
28a00297 | 89 | \r |
162ed594 | 90 | @return The allocated memory, or NULL\r |
28a00297 | 91 | \r |
162ed594 | 92 | **/\r |
93 | VOID *\r | |
94 | CoreAllocatePoolPages (\r | |
23c98c94 | 95 | IN EFI_MEMORY_TYPE PoolType,\r |
96 | IN UINTN NumberOfPages,\r | |
97 | IN UINTN Alignment\r | |
98 | );\r | |
28a00297 | 99 | \r |
28a00297 | 100 | \r |
28a00297 | 101 | \r |
162ed594 | 102 | /**\r |
103 | Internal function. Frees pool pages allocated via AllocatePoolPages ()\r | |
28a00297 | 104 | \r |
022c6d45 | 105 | @param Memory The base address to free\r |
162ed594 | 106 | @param NumberOfPages The number of pages to free\r |
28a00297 | 107 | \r |
162ed594 | 108 | **/\r |
28a00297 | 109 | VOID\r |
110 | CoreFreePoolPages (\r | |
111 | IN EFI_PHYSICAL_ADDRESS Memory,\r | |
112 | IN UINTN NumberOfPages\r | |
23c98c94 | 113 | );\r |
28a00297 | 114 | \r |
28a00297 | 115 | \r |
28a00297 | 116 | \r |
162ed594 | 117 | /**\r |
118 | Internal function to allocate pool of a particular type.\r | |
119 | Caller must have the memory lock held\r | |
28a00297 | 120 | \r |
022c6d45 | 121 | @param PoolType Type of pool to allocate\r |
122 | @param Size The amount of pool to allocate\r | |
28a00297 | 123 | \r |
162ed594 | 124 | @return The allocate pool, or NULL\r |
28a00297 | 125 | \r |
162ed594 | 126 | **/\r |
28a00297 | 127 | VOID *\r |
128 | CoreAllocatePoolI (\r | |
129 | IN EFI_MEMORY_TYPE PoolType,\r | |
130 | IN UINTN Size\r | |
23c98c94 | 131 | );\r |
28a00297 | 132 | \r |
28a00297 | 133 | \r |
28a00297 | 134 | \r |
162ed594 | 135 | /**\r |
136 | Internal function to free a pool entry.\r | |
28a00297 | 137 | Caller must have the memory lock held\r |
138 | \r | |
022c6d45 | 139 | @param Buffer The allocated pool entry to free\r |
28a00297 | 140 | \r |
022c6d45 | 141 | @retval EFI_INVALID_PARAMETER Buffer not valid\r |
162ed594 | 142 | @retval EFI_SUCCESS Buffer successfully freed.\r |
28a00297 | 143 | \r |
162ed594 | 144 | **/\r |
28a00297 | 145 | EFI_STATUS\r |
146 | CoreFreePoolI (\r | |
23c98c94 | 147 | IN VOID *Buffer\r |
148 | );\r | |
28a00297 | 149 | \r |
28a00297 | 150 | \r |
28a00297 | 151 | \r |
162ed594 | 152 | /**\r |
153 | Enter critical section by gaining lock on gMemoryLock.\r | |
28a00297 | 154 | \r |
162ed594 | 155 | **/\r |
28a00297 | 156 | VOID\r |
157 | CoreAcquireMemoryLock (\r | |
158 | VOID\r | |
23c98c94 | 159 | );\r |
28a00297 | 160 | \r |
28a00297 | 161 | \r |
162ed594 | 162 | /**\r |
163 | Exit critical section by releasing lock on gMemoryLock.\r | |
28a00297 | 164 | \r |
162ed594 | 165 | **/\r |
28a00297 | 166 | VOID\r |
167 | CoreReleaseMemoryLock (\r | |
168 | VOID\r | |
23c98c94 | 169 | );\r |
28a00297 | 170 | \r |
171 | \r | |
172 | //\r | |
173 | // Internal Global data\r | |
174 | //\r | |
175 | \r | |
022c6d45 | 176 | extern EFI_LOCK gMemoryLock;\r |
28a00297 | 177 | extern LIST_ENTRY gMemoryMap;\r |
28a00297 | 178 | extern LIST_ENTRY mGcdMemorySpaceMap;\r |
179 | #endif\r |