]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/Dxe/Mem/Imem.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[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 - 2017, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #ifndef _IMEM_H_
10 #define _IMEM_H_
11
12 //
13 // +---------------------------------------------------+
14 // | 0..(EfiMaxMemoryType - 1) - Normal memory type |
15 // +---------------------------------------------------+
16 // | EfiMaxMemoryType..0x6FFFFFFF - Invalid |
17 // +---------------------------------------------------+
18 // | 0x70000000..0x7FFFFFFF - OEM reserved |
19 // +---------------------------------------------------+
20 // | 0x80000000..0xFFFFFFFF - OS reserved |
21 // +---------------------------------------------------+
22 //
23 #define MEMORY_TYPE_OS_RESERVED_MIN 0x80000000
24 #define MEMORY_TYPE_OS_RESERVED_MAX 0xFFFFFFFF
25 #define MEMORY_TYPE_OEM_RESERVED_MIN 0x70000000
26 #define MEMORY_TYPE_OEM_RESERVED_MAX 0x7FFFFFFF
27
28 //
29 // MEMORY_MAP_ENTRY
30 //
31
32 #define MEMORY_MAP_SIGNATURE SIGNATURE_32('m','m','a','p')
33 typedef struct {
34 UINTN Signature;
35 LIST_ENTRY Link;
36 BOOLEAN FromPages;
37
38 EFI_MEMORY_TYPE Type;
39 UINT64 Start;
40 UINT64 End;
41
42 UINT64 VirtualStart;
43 UINT64 Attribute;
44 } MEMORY_MAP;
45
46 //
47 // Internal prototypes
48 //
49
50 /**
51 Internal function. Used by the pool functions to allocate pages
52 to back pool allocation requests.
53
54 @param PoolType The type of memory for the new pool pages
55 @param NumberOfPages No of pages to allocate
56 @param Alignment Bits to align.
57 @param NeedGuard Flag to indicate Guard page is needed or not
58
59 @return The allocated memory, or NULL
60
61 **/
62 VOID *
63 CoreAllocatePoolPages (
64 IN EFI_MEMORY_TYPE PoolType,
65 IN UINTN NumberOfPages,
66 IN UINTN Alignment,
67 IN BOOLEAN NeedGuard
68 );
69
70 /**
71 Internal function. Frees pool pages allocated via AllocatePoolPages ()
72
73 @param Memory The base address to free
74 @param NumberOfPages The number of pages to free
75
76 **/
77 VOID
78 CoreFreePoolPages (
79 IN EFI_PHYSICAL_ADDRESS Memory,
80 IN UINTN NumberOfPages
81 );
82
83 /**
84 Internal function to allocate pool of a particular type.
85 Caller must have the memory lock held
86
87 @param PoolType Type of pool to allocate
88 @param Size The amount of pool to allocate
89 @param NeedGuard Flag to indicate Guard page is needed or not
90
91 @return The allocate pool, or NULL
92
93 **/
94 VOID *
95 CoreAllocatePoolI (
96 IN EFI_MEMORY_TYPE PoolType,
97 IN UINTN Size,
98 IN BOOLEAN NeedGuard
99 );
100
101 /**
102 Internal function to free a pool entry.
103 Caller must have the memory lock held
104
105 @param Buffer The allocated pool entry to free
106 @param PoolType Pointer to pool type
107
108 @retval EFI_INVALID_PARAMETER Buffer not valid
109 @retval EFI_SUCCESS Buffer successfully freed.
110
111 **/
112 EFI_STATUS
113 CoreFreePoolI (
114 IN VOID *Buffer,
115 OUT EFI_MEMORY_TYPE *PoolType OPTIONAL
116 );
117
118 /**
119 Enter critical section by gaining lock on gMemoryLock.
120
121 **/
122 VOID
123 CoreAcquireMemoryLock (
124 VOID
125 );
126
127 /**
128 Exit critical section by releasing lock on gMemoryLock.
129
130 **/
131 VOID
132 CoreReleaseMemoryLock (
133 VOID
134 );
135
136 /**
137 Allocates pages from the memory map.
138
139 @param Type The type of allocation to perform
140 @param MemoryType The type of memory to turn the allocated pages
141 into
142 @param NumberOfPages The number of pages to allocate
143 @param Memory A pointer to receive the base allocated memory
144 address
145 @param NeedGuard Flag to indicate Guard page is needed or not
146
147 @return Status. On success, Memory is filled in with the base address allocated
148 @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in
149 spec.
150 @retval EFI_NOT_FOUND Could not allocate pages match the requirement.
151 @retval EFI_OUT_OF_RESOURCES No enough pages to allocate.
152 @retval EFI_SUCCESS Pages successfully allocated.
153
154 **/
155 EFI_STATUS
156 EFIAPI
157 CoreInternalAllocatePages (
158 IN EFI_ALLOCATE_TYPE Type,
159 IN EFI_MEMORY_TYPE MemoryType,
160 IN UINTN NumberOfPages,
161 IN OUT EFI_PHYSICAL_ADDRESS *Memory,
162 IN BOOLEAN NeedGuard
163 );
164
165 //
166 // Internal Global data
167 //
168
169 extern EFI_LOCK gMemoryLock;
170 extern LIST_ENTRY gMemoryMap;
171 extern LIST_ENTRY mGcdMemorySpaceMap;
172 #endif