]>
Commit | Line | Data |
---|---|---|
23c98c94 | 1 | /** @file\r |
504214c4 | 2 | Data structure and functions to allocate and free memory space.\r |
28a00297 | 3 | \r |
cd5ebaa0 HT |
4 | Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r |
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 | |
43 | \r | |
44 | //\r | |
45 | // MEMORY_MAP_ENTRY\r | |
46 | //\r | |
47 | \r | |
f3f2e05d | 48 | #define MEMORY_MAP_SIGNATURE SIGNATURE_32('m','m','a','p')\r |
28a00297 | 49 | typedef struct {\r |
50 | UINTN Signature;\r | |
51 | LIST_ENTRY Link;\r | |
52 | BOOLEAN FromPages;\r | |
53 | \r | |
54 | EFI_MEMORY_TYPE Type;\r | |
55 | UINT64 Start;\r | |
56 | UINT64 End;\r | |
57 | \r | |
58 | UINT64 VirtualStart;\r | |
59 | UINT64 Attribute;\r | |
60 | } MEMORY_MAP;\r | |
61 | \r | |
62 | //\r | |
63 | // Internal prototypes\r | |
64 | //\r | |
65 | \r | |
28a00297 | 66 | \r |
162ed594 | 67 | /**\r |
28a00297 | 68 | Internal function. Used by the pool functions to allocate pages\r |
69 | to back pool allocation requests.\r | |
70 | \r | |
022c6d45 | 71 | @param PoolType The type of memory for the new pool pages\r |
72 | @param NumberOfPages No of pages to allocate\r | |
73 | @param Alignment Bits to align.\r | |
28a00297 | 74 | \r |
162ed594 | 75 | @return The allocated memory, or NULL\r |
28a00297 | 76 | \r |
162ed594 | 77 | **/\r |
78 | VOID *\r | |
79 | CoreAllocatePoolPages (\r | |
23c98c94 | 80 | IN EFI_MEMORY_TYPE PoolType,\r |
81 | IN UINTN NumberOfPages,\r | |
82 | IN UINTN Alignment\r | |
83 | );\r | |
28a00297 | 84 | \r |
28a00297 | 85 | \r |
28a00297 | 86 | \r |
162ed594 | 87 | /**\r |
88 | Internal function. Frees pool pages allocated via AllocatePoolPages ()\r | |
28a00297 | 89 | \r |
022c6d45 | 90 | @param Memory The base address to free\r |
162ed594 | 91 | @param NumberOfPages The number of pages to free\r |
28a00297 | 92 | \r |
162ed594 | 93 | **/\r |
28a00297 | 94 | VOID\r |
95 | CoreFreePoolPages (\r | |
96 | IN EFI_PHYSICAL_ADDRESS Memory,\r | |
97 | IN UINTN NumberOfPages\r | |
23c98c94 | 98 | );\r |
28a00297 | 99 | \r |
28a00297 | 100 | \r |
28a00297 | 101 | \r |
162ed594 | 102 | /**\r |
103 | Internal function to allocate pool of a particular type.\r | |
104 | Caller must have the memory lock held\r | |
28a00297 | 105 | \r |
022c6d45 | 106 | @param PoolType Type of pool to allocate\r |
107 | @param Size The amount of pool to allocate\r | |
28a00297 | 108 | \r |
162ed594 | 109 | @return The allocate pool, or NULL\r |
28a00297 | 110 | \r |
162ed594 | 111 | **/\r |
28a00297 | 112 | VOID *\r |
113 | CoreAllocatePoolI (\r | |
114 | IN EFI_MEMORY_TYPE PoolType,\r | |
115 | IN UINTN Size\r | |
23c98c94 | 116 | );\r |
28a00297 | 117 | \r |
28a00297 | 118 | \r |
28a00297 | 119 | \r |
162ed594 | 120 | /**\r |
121 | Internal function to free a pool entry.\r | |
28a00297 | 122 | Caller must have the memory lock held\r |
123 | \r | |
022c6d45 | 124 | @param Buffer The allocated pool entry to free\r |
28a00297 | 125 | \r |
022c6d45 | 126 | @retval EFI_INVALID_PARAMETER Buffer not valid\r |
162ed594 | 127 | @retval EFI_SUCCESS Buffer successfully freed.\r |
28a00297 | 128 | \r |
162ed594 | 129 | **/\r |
28a00297 | 130 | EFI_STATUS\r |
131 | CoreFreePoolI (\r | |
23c98c94 | 132 | IN VOID *Buffer\r |
133 | );\r | |
28a00297 | 134 | \r |
28a00297 | 135 | \r |
28a00297 | 136 | \r |
162ed594 | 137 | /**\r |
138 | Enter critical section by gaining lock on gMemoryLock.\r | |
28a00297 | 139 | \r |
162ed594 | 140 | **/\r |
28a00297 | 141 | VOID\r |
142 | CoreAcquireMemoryLock (\r | |
143 | VOID\r | |
23c98c94 | 144 | );\r |
28a00297 | 145 | \r |
28a00297 | 146 | \r |
162ed594 | 147 | /**\r |
148 | Exit critical section by releasing lock on gMemoryLock.\r | |
28a00297 | 149 | \r |
162ed594 | 150 | **/\r |
28a00297 | 151 | VOID\r |
152 | CoreReleaseMemoryLock (\r | |
153 | VOID\r | |
23c98c94 | 154 | );\r |
28a00297 | 155 | \r |
156 | \r | |
157 | //\r | |
158 | // Internal Global data\r | |
159 | //\r | |
160 | \r | |
022c6d45 | 161 | extern EFI_LOCK gMemoryLock;\r |
28a00297 | 162 | extern LIST_ENTRY gMemoryMap;\r |
28a00297 | 163 | extern LIST_ENTRY mGcdMemorySpaceMap;\r |
164 | #endif\r |