]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Include/Guid/MemoryProfile.h
3c1e5e79cafd202ffc2d11175b32b168b67d894e
[mirror_edk2.git] / MdeModulePkg / Include / Guid / MemoryProfile.h
1 /** @file
2 Memory profile data structure.
3
4 Copyright (c) 2014, 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 _MEMORY_PROFILE_H_
16 #define _MEMORY_PROFILE_H_
17
18 //
19 // For BIOS MemoryType (0 ~ EfiMaxMemoryType), it is recorded in UsageByType[MemoryType]. (Each valid entry has one entry)
20 // For OS MemoryType (0x80000000 ~ 0xFFFFFFFF), it is recorded in UsageByType[EfiMaxMemoryType]. (All types are combined into one entry)
21 //
22
23 typedef struct {
24 UINT32 Signature;
25 UINT16 Length;
26 UINT16 Revision;
27 } MEMORY_PROFILE_COMMON_HEADER;
28
29 #define MEMORY_PROFILE_CONTEXT_SIGNATURE SIGNATURE_32 ('M','P','C','T')
30 #define MEMORY_PROFILE_CONTEXT_REVISION 0x0001
31
32 typedef struct {
33 MEMORY_PROFILE_COMMON_HEADER Header;
34 UINT64 CurrentTotalUsage;
35 UINT64 PeakTotalUsage;
36 UINT64 CurrentTotalUsageByType[EfiMaxMemoryType + 1];
37 UINT64 PeakTotalUsageByType[EfiMaxMemoryType + 1];
38 UINT64 TotalImageSize;
39 UINT32 ImageCount;
40 UINT32 SequenceCount;
41 } MEMORY_PROFILE_CONTEXT;
42
43 #define MEMORY_PROFILE_DRIVER_INFO_SIGNATURE SIGNATURE_32 ('M','P','D','I')
44 #define MEMORY_PROFILE_DRIVER_INFO_REVISION 0x0001
45
46 typedef struct {
47 MEMORY_PROFILE_COMMON_HEADER Header;
48 EFI_GUID FileName;
49 PHYSICAL_ADDRESS ImageBase;
50 UINT64 ImageSize;
51 PHYSICAL_ADDRESS EntryPoint;
52 UINT16 ImageSubsystem;
53 EFI_FV_FILETYPE FileType;
54 UINT8 Reserved[1];
55 UINT32 AllocRecordCount;
56 UINT64 CurrentUsage;
57 UINT64 PeakUsage;
58 UINT64 CurrentUsageByType[EfiMaxMemoryType + 1];
59 UINT64 PeakUsageByType[EfiMaxMemoryType + 1];
60 } MEMORY_PROFILE_DRIVER_INFO;
61
62 typedef enum {
63 MemoryProfileActionAllocatePages = 1,
64 MemoryProfileActionFreePages = 2,
65 MemoryProfileActionAllocatePool = 3,
66 MemoryProfileActionFreePool = 4,
67 } MEMORY_PROFILE_ACTION;
68
69 #define MEMORY_PROFILE_ALLOC_INFO_SIGNATURE SIGNATURE_32 ('M','P','A','I')
70 #define MEMORY_PROFILE_ALLOC_INFO_REVISION 0x0001
71
72 typedef struct {
73 MEMORY_PROFILE_COMMON_HEADER Header;
74 PHYSICAL_ADDRESS CallerAddress;
75 UINT32 SequenceId;
76 UINT8 Reserved[4];
77 MEMORY_PROFILE_ACTION Action;
78 EFI_MEMORY_TYPE MemoryType;
79 PHYSICAL_ADDRESS Buffer;
80 UINT64 Size;
81 } MEMORY_PROFILE_ALLOC_INFO;
82
83 #define MEMORY_PROFILE_DESCRIPTOR_SIGNATURE SIGNATURE_32 ('M','P','D','R')
84 #define MEMORY_PROFILE_DESCRIPTOR_REVISION 0x0001
85
86 typedef struct {
87 MEMORY_PROFILE_COMMON_HEADER Header;
88 PHYSICAL_ADDRESS Address;
89 UINT64 Size;
90 } MEMORY_PROFILE_DESCRIPTOR;
91
92 #define MEMORY_PROFILE_FREE_MEMORY_SIGNATURE SIGNATURE_32 ('M','P','R','M')
93 #define MEMORY_PROFILE_FREE_MEMORY_REVISION 0x0001
94
95 typedef struct {
96 MEMORY_PROFILE_COMMON_HEADER Header;
97 UINT64 TotalFreeMemoryPages;
98 UINT32 FreeMemoryEntryCount;
99 UINT8 Reserved[4];
100 //MEMORY_PROFILE_DESCRIPTOR MemoryDescriptor[FreeMemoryEntryCount];
101 } MEMORY_PROFILE_FREE_MEMORY;
102
103 #define MEMORY_PROFILE_MEMORY_RANGE_SIGNATURE SIGNATURE_32 ('M','P','M','R')
104 #define MEMORY_PROFILE_MEMORY_RANGE_REVISION 0x0001
105
106 typedef struct {
107 MEMORY_PROFILE_COMMON_HEADER Header;
108 UINT32 MemoryRangeCount;
109 UINT8 Reserved[4];
110 //MEMORY_PROFILE_DESCRIPTOR MemoryDescriptor[MemoryRangeCount];
111 } MEMORY_PROFILE_MEMORY_RANGE;
112
113 //
114 // UEFI memory profile layout:
115 // +--------------------------------+
116 // | CONTEXT |
117 // +--------------------------------+
118 // | DRIVER_INFO(1) |
119 // +--------------------------------+
120 // | ALLOC_INFO(1, 1) |
121 // +--------------------------------+
122 // | ALLOC_INFO(1, m1) |
123 // +--------------------------------+
124 // | DRIVER_INFO(n) |
125 // +--------------------------------+
126 // | ALLOC_INFO(n, 1) |
127 // +--------------------------------+
128 // | ALLOC_INFO(n, mn) |
129 // +--------------------------------+
130 //
131
132 typedef struct _EDKII_MEMORY_PROFILE_PROTOCOL EDKII_MEMORY_PROFILE_PROTOCOL;
133
134 /**
135 Get memory profile data.
136
137 @param[in] This The EDKII_MEMORY_PROFILE_PROTOCOL instance.
138 @param[in, out] ProfileSize On entry, points to the size in bytes of the ProfileBuffer.
139 On return, points to the size of the data returned in ProfileBuffer.
140 @param[out] ProfileBuffer Profile buffer.
141
142 @return EFI_SUCCESS Get the memory profile data successfully.
143 @return EFI_BUFFER_TO_SMALL The ProfileSize is too small for the resulting data.
144 ProfileSize is updated with the size required.
145
146 **/
147 typedef
148 EFI_STATUS
149 (EFIAPI *EDKII_MEMORY_PROFILE_GET_DATA)(
150 IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
151 IN OUT UINT64 *ProfileSize,
152 OUT VOID *ProfileBuffer
153 );
154
155 /**
156 Register image to memory profile.
157
158 @param[in] This The EDKII_MEMORY_PROFILE_PROTOCOL instance.
159 @param[in] FilePath File path of the image.
160 @param[in] ImageBase Image base address.
161 @param[in] ImageSize Image size.
162 @param[in] FileType File type of the image.
163
164 @return EFI_SUCCESS Register success.
165 @return EFI_OUT_OF_RESOURCE No enough resource for this register.
166
167 **/
168 typedef
169 EFI_STATUS
170 (EFIAPI *EDKII_MEMORY_PROFILE_REGISTER_IMAGE)(
171 IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
172 IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
173 IN PHYSICAL_ADDRESS ImageBase,
174 IN UINT64 ImageSize,
175 IN EFI_FV_FILETYPE FileType
176 );
177
178 /**
179 Unregister image from memory profile.
180
181 @param[in] This The EDKII_MEMORY_PROFILE_PROTOCOL instance.
182 @param[in] FilePath File path of the image.
183 @param[in] ImageBase Image base address.
184 @param[in] ImageSize Image size.
185
186 @return EFI_SUCCESS Unregister success.
187 @return EFI_NOT_FOUND The image is not found.
188
189 **/
190 typedef
191 EFI_STATUS
192 (EFIAPI *EDKII_MEMORY_PROFILE_UNREGISTER_IMAGE)(
193 IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
194 IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
195 IN PHYSICAL_ADDRESS ImageBase,
196 IN UINT64 ImageSize
197 );
198
199 struct _EDKII_MEMORY_PROFILE_PROTOCOL {
200 EDKII_MEMORY_PROFILE_GET_DATA GetData;
201 EDKII_MEMORY_PROFILE_REGISTER_IMAGE RegisterImage;
202 EDKII_MEMORY_PROFILE_UNREGISTER_IMAGE UnregisterImage;
203 };
204
205 //
206 // SMRAM profile layout:
207 // +--------------------------------+
208 // | CONTEXT |
209 // +--------------------------------+
210 // | DRIVER_INFO(1) |
211 // +--------------------------------+
212 // | ALLOC_INFO(1, 1) |
213 // +--------------------------------+
214 // | ALLOC_INFO(1, m1) |
215 // +--------------------------------+
216 // | DRIVER_INFO(n) |
217 // +--------------------------------+
218 // | ALLOC_INFO(n, 1) |
219 // +--------------------------------+
220 // | ALLOC_INFO(n, mn) |
221 // +--------------------------------+
222 // | FREE_MEMORY |
223 // +--------------------------------+
224 // | FREE MEMORY DESCRIPTOR(1) |
225 // +--------------------------------+
226 // | FREE MEMORY DESCRIPTOR(p) |
227 // +--------------------------------+
228 // | MEMORY_RANGE |
229 // +--------------------------------+
230 // | MEMORY RANGE DESCRIPTOR(1) |
231 // +--------------------------------+
232 // | MEMORY RANGE DESCRIPTOR(q) |
233 // +--------------------------------+
234 //
235
236 //
237 // SMRAM profile command
238 //
239 #define SMRAM_PROFILE_COMMAND_GET_PROFILE_INFO 0x1
240 #define SMRAM_PROFILE_COMMAND_GET_PROFILE_DATA 0x2
241 //
242 // Below 2 commands are now used by ECP only and only valid before SmmReadyToLock
243 //
244 #define SMRAM_PROFILE_COMMAND_REGISTER_IMAGE 0x3
245 #define SMRAM_PROFILE_COMMAND_UNREGISTER_IMAGE 0x4
246
247 typedef struct {
248 UINT32 Command;
249 UINT32 DataLength;
250 UINT64 ReturnStatus;
251 } SMRAM_PROFILE_PARAMETER_HEADER;
252
253 typedef struct {
254 SMRAM_PROFILE_PARAMETER_HEADER Header;
255 UINT64 ProfileSize;
256 } SMRAM_PROFILE_PARAMETER_GET_PROFILE_INFO;
257
258 typedef struct {
259 SMRAM_PROFILE_PARAMETER_HEADER Header;
260 UINT64 ProfileSize;
261 PHYSICAL_ADDRESS ProfileBuffer;
262 } SMRAM_PROFILE_PARAMETER_GET_PROFILE_DATA;
263
264 typedef struct {
265 SMRAM_PROFILE_PARAMETER_HEADER Header;
266 EFI_GUID FileName;
267 PHYSICAL_ADDRESS ImageBuffer;
268 UINT64 NumberOfPage;
269 } SMRAM_PROFILE_PARAMETER_REGISTER_IMAGE;
270
271 typedef struct {
272 SMRAM_PROFILE_PARAMETER_HEADER Header;
273 EFI_GUID FileName;
274 PHYSICAL_ADDRESS ImageBuffer;
275 UINT64 NumberOfPage;
276 } SMRAM_PROFILE_PARAMETER_UNREGISTER_IMAGE;
277
278
279 #define EDKII_MEMORY_PROFILE_GUID { \
280 0x821c9a09, 0x541a, 0x40f6, 0x9f, 0x43, 0xa, 0xd1, 0x93, 0xa1, 0x2c, 0xfe \
281 }
282
283 extern EFI_GUID gEdkiiMemoryProfileGuid;
284
285 #endif
286