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