]>
Commit | Line | Data |
---|---|---|
504214c4 LG |
1 | /** @file \r |
2 | \r | |
3 | Data structure and functions to allocate and free memory space.\r | |
28a00297 | 4 | \r |
504214c4 | 5 | Copyright (c) 2006 - 2008, Intel Corporation \r |
28a00297 | 6 | All rights reserved. This program and the accompanying materials \r |
7 | are licensed and made available under the terms and conditions of the BSD License \r | |
8 | which accompanies this distribution. The full text of the license may be found at \r | |
9 | http://opensource.org/licenses/bsd-license.php \r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
13 | \r | |
162ed594 | 14 | \r |
15 | **/\r | |
28a00297 | 16 | \r |
17 | #ifndef _IMEM_H_\r | |
18 | #define _IMEM_H_\r | |
19 | \r | |
20 | #if defined (MDE_CPU_IPF)\r | |
21 | //\r | |
22 | // For Itanium machines make the default allocations 8K aligned\r | |
23 | //\r | |
24 | #define EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT (EFI_PAGE_SIZE * 2)\r | |
25 | #define DEFAULT_PAGE_ALLOCATION (EFI_PAGE_SIZE * 2)\r | |
26 | \r | |
27 | #else\r | |
28 | //\r | |
29 | // For genric EFI machines make the default allocations 4K aligned\r | |
30 | //\r | |
31 | #define EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT (EFI_PAGE_SIZE)\r | |
32 | #define DEFAULT_PAGE_ALLOCATION (EFI_PAGE_SIZE)\r | |
33 | \r | |
34 | #endif\r | |
35 | \r | |
36 | \r | |
37 | //\r | |
38 | // MEMORY_MAP_ENTRY\r | |
39 | //\r | |
40 | \r | |
41 | #define MEMORY_MAP_SIGNATURE EFI_SIGNATURE_32('m','m','a','p')\r | |
42 | typedef struct {\r | |
43 | UINTN Signature;\r | |
44 | LIST_ENTRY Link;\r | |
45 | BOOLEAN FromPages;\r | |
46 | \r | |
47 | EFI_MEMORY_TYPE Type;\r | |
48 | UINT64 Start;\r | |
49 | UINT64 End;\r | |
50 | \r | |
51 | UINT64 VirtualStart;\r | |
52 | UINT64 Attribute;\r | |
53 | } MEMORY_MAP;\r | |
54 | \r | |
55 | //\r | |
56 | // Internal prototypes\r | |
57 | //\r | |
58 | \r | |
28a00297 | 59 | \r |
162ed594 | 60 | /**\r |
28a00297 | 61 | Internal function. Used by the pool functions to allocate pages\r |
62 | to back pool allocation requests.\r | |
63 | \r | |
162ed594 | 64 | @param PoolType The type of memory for the new pool pages \r |
65 | @param NumberOfPages No of pages to allocate \r | |
66 | @param Alignment Bits to align. \r | |
28a00297 | 67 | \r |
162ed594 | 68 | @return The allocated memory, or NULL\r |
28a00297 | 69 | \r |
162ed594 | 70 | **/\r |
71 | VOID *\r | |
72 | CoreAllocatePoolPages (\r | |
73 | IN EFI_MEMORY_TYPE PoolType,\r | |
74 | IN UINTN NumberOfPages,\r | |
75 | IN UINTN Alignment\r | |
76 | )\r | |
77 | ;\r | |
28a00297 | 78 | \r |
28a00297 | 79 | \r |
28a00297 | 80 | \r |
162ed594 | 81 | /**\r |
82 | Internal function. Frees pool pages allocated via AllocatePoolPages ()\r | |
28a00297 | 83 | \r |
162ed594 | 84 | @param Memory The base address to free \r |
85 | @param NumberOfPages The number of pages to free\r | |
28a00297 | 86 | \r |
162ed594 | 87 | **/\r |
28a00297 | 88 | VOID\r |
89 | CoreFreePoolPages (\r | |
90 | IN EFI_PHYSICAL_ADDRESS Memory,\r | |
91 | IN UINTN NumberOfPages\r | |
92 | )\r | |
162ed594 | 93 | ;\r |
28a00297 | 94 | \r |
28a00297 | 95 | \r |
28a00297 | 96 | \r |
162ed594 | 97 | /**\r |
98 | Internal function to allocate pool of a particular type.\r | |
99 | Caller must have the memory lock held\r | |
28a00297 | 100 | \r |
162ed594 | 101 | @param PoolType Type of pool to allocate \r |
102 | @param Size The amount of pool to allocate \r | |
28a00297 | 103 | \r |
162ed594 | 104 | @return The allocate pool, or NULL\r |
28a00297 | 105 | \r |
162ed594 | 106 | **/\r |
28a00297 | 107 | VOID *\r |
108 | CoreAllocatePoolI (\r | |
109 | IN EFI_MEMORY_TYPE PoolType,\r | |
110 | IN UINTN Size\r | |
111 | )\r | |
162ed594 | 112 | ;\r |
28a00297 | 113 | \r |
28a00297 | 114 | \r |
28a00297 | 115 | \r |
162ed594 | 116 | /**\r |
117 | Internal function to free a pool entry.\r | |
28a00297 | 118 | Caller must have the memory lock held\r |
119 | \r | |
162ed594 | 120 | @param Buffer The allocated pool entry to free \r |
28a00297 | 121 | \r |
162ed594 | 122 | @retval EFI_INVALID_PARAMETER Buffer not valid \r |
123 | @retval EFI_SUCCESS Buffer successfully freed.\r | |
28a00297 | 124 | \r |
162ed594 | 125 | **/\r |
28a00297 | 126 | EFI_STATUS\r |
127 | CoreFreePoolI (\r | |
128 | IN VOID *Buffer\r | |
129 | )\r | |
162ed594 | 130 | ;\r |
28a00297 | 131 | \r |
28a00297 | 132 | \r |
28a00297 | 133 | \r |
162ed594 | 134 | /**\r |
135 | Enter critical section by gaining lock on gMemoryLock.\r | |
28a00297 | 136 | \r |
162ed594 | 137 | **/\r |
28a00297 | 138 | VOID\r |
139 | CoreAcquireMemoryLock (\r | |
140 | VOID\r | |
141 | )\r | |
162ed594 | 142 | ;\r |
28a00297 | 143 | \r |
28a00297 | 144 | \r |
162ed594 | 145 | /**\r |
146 | Exit critical section by releasing lock on gMemoryLock.\r | |
28a00297 | 147 | \r |
162ed594 | 148 | **/\r |
28a00297 | 149 | VOID\r |
150 | CoreReleaseMemoryLock (\r | |
151 | VOID\r | |
152 | )\r | |
28a00297 | 153 | ;\r |
154 | \r | |
155 | \r | |
156 | //\r | |
157 | // Internal Global data\r | |
158 | //\r | |
159 | \r | |
160 | extern EFI_LOCK gMemoryLock; \r | |
161 | extern LIST_ENTRY gMemoryMap;\r | |
162 | extern MEMORY_MAP *gMemoryLastConvert;\r | |
163 | extern LIST_ENTRY mGcdMemorySpaceMap;\r | |
164 | #endif\r |