]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/Dxe/Mem/Imem.h
MdeModulePkg DxeCore: Return memory type from internal free pool/pages
[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 - 2016, 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 //
19 // +---------------------------------------------------+
20 // | 0..(EfiMaxMemoryType - 1) - Normal memory type |
21 // +---------------------------------------------------+
22 // | EfiMaxMemoryType..0x6FFFFFFF - Invalid |
23 // +---------------------------------------------------+
24 // | 0x70000000..0x7FFFFFFF - OEM reserved |
25 // +---------------------------------------------------+
26 // | 0x80000000..0xFFFFFFFF - OS reserved |
27 // +---------------------------------------------------+
28 //
29 #define MEMORY_TYPE_OS_RESERVED_MIN 0x80000000
30 #define MEMORY_TYPE_OS_RESERVED_MAX 0xFFFFFFFF
31 #define MEMORY_TYPE_OEM_RESERVED_MIN 0x70000000
32 #define MEMORY_TYPE_OEM_RESERVED_MAX 0x7FFFFFFF
33
34 //
35 // MEMORY_MAP_ENTRY
36 //
37
38 #define MEMORY_MAP_SIGNATURE SIGNATURE_32('m','m','a','p')
39 typedef struct {
40 UINTN Signature;
41 LIST_ENTRY Link;
42 BOOLEAN FromPages;
43
44 EFI_MEMORY_TYPE Type;
45 UINT64 Start;
46 UINT64 End;
47
48 UINT64 VirtualStart;
49 UINT64 Attribute;
50 } MEMORY_MAP;
51
52 //
53 // Internal prototypes
54 //
55
56
57 /**
58 Internal function. Used by the pool functions to allocate pages
59 to back pool allocation requests.
60
61 @param PoolType The type of memory for the new pool pages
62 @param NumberOfPages No of pages to allocate
63 @param Alignment Bits to align.
64
65 @return The allocated memory, or NULL
66
67 **/
68 VOID *
69 CoreAllocatePoolPages (
70 IN EFI_MEMORY_TYPE PoolType,
71 IN UINTN NumberOfPages,
72 IN UINTN Alignment
73 );
74
75
76
77 /**
78 Internal function. Frees pool pages allocated via AllocatePoolPages ()
79
80 @param Memory The base address to free
81 @param NumberOfPages The number of pages to free
82
83 **/
84 VOID
85 CoreFreePoolPages (
86 IN EFI_PHYSICAL_ADDRESS Memory,
87 IN UINTN NumberOfPages
88 );
89
90
91
92 /**
93 Internal function to allocate pool of a particular type.
94 Caller must have the memory lock held
95
96 @param PoolType Type of pool to allocate
97 @param Size The amount of pool to allocate
98
99 @return The allocate pool, or NULL
100
101 **/
102 VOID *
103 CoreAllocatePoolI (
104 IN EFI_MEMORY_TYPE PoolType,
105 IN UINTN Size
106 );
107
108
109
110 /**
111 Internal function to free a pool entry.
112 Caller must have the memory lock held
113
114 @param Buffer The allocated pool entry to free
115 @param PoolType Pointer to pool type
116
117 @retval EFI_INVALID_PARAMETER Buffer not valid
118 @retval EFI_SUCCESS Buffer successfully freed.
119
120 **/
121 EFI_STATUS
122 CoreFreePoolI (
123 IN VOID *Buffer,
124 OUT EFI_MEMORY_TYPE *PoolType OPTIONAL
125 );
126
127
128
129 /**
130 Enter critical section by gaining lock on gMemoryLock.
131
132 **/
133 VOID
134 CoreAcquireMemoryLock (
135 VOID
136 );
137
138
139 /**
140 Exit critical section by releasing lock on gMemoryLock.
141
142 **/
143 VOID
144 CoreReleaseMemoryLock (
145 VOID
146 );
147
148
149 //
150 // Internal Global data
151 //
152
153 extern EFI_LOCK gMemoryLock;
154 extern LIST_ENTRY gMemoryMap;
155 extern LIST_ENTRY mGcdMemorySpaceMap;
156 #endif