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