]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Include/Guid/MemoryProfile.h
Merge branch 'master' of https://github.com/tianocore/edk2
[mirror_edk2.git] / MdeModulePkg / Include / Guid / MemoryProfile.h
1 /** @file
2 Memory profile data structure.
3
4 Copyright (c) 2014 - 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 _MEMORY_PROFILE_H_
16 #define _MEMORY_PROFILE_H_
17
18 #include <Pi/PiFirmwareFile.h>
19
20 //
21 // For BIOS MemoryType (0 ~ EfiMaxMemoryType - 1), it is recorded in UsageByType[MemoryType]. (Each valid entry has one entry)
22 // For OS MemoryType (0x80000000 ~ 0xFFFFFFFF), it is recorded in UsageByType[EfiMaxMemoryType]. (All types are combined into one entry)
23 // For OEM MemoryType (0x70000000 ~ 0x7FFFFFFF), it is recorded in UsageByType[EfiMaxMemoryType + 1]. (All types are combined into one entry)
24 //
25
26 typedef struct {
27 UINT32 Signature;
28 UINT16 Length;
29 UINT16 Revision;
30 } MEMORY_PROFILE_COMMON_HEADER;
31
32 #define MEMORY_PROFILE_CONTEXT_SIGNATURE SIGNATURE_32 ('M','P','C','T')
33 #define MEMORY_PROFILE_CONTEXT_REVISION 0x0002
34
35 typedef struct {
36 MEMORY_PROFILE_COMMON_HEADER Header;
37 UINT64 CurrentTotalUsage;
38 UINT64 PeakTotalUsage;
39 UINT64 CurrentTotalUsageByType[EfiMaxMemoryType + 2];
40 UINT64 PeakTotalUsageByType[EfiMaxMemoryType + 2];
41 UINT64 TotalImageSize;
42 UINT32 ImageCount;
43 UINT32 SequenceCount;
44 } MEMORY_PROFILE_CONTEXT;
45
46 #define MEMORY_PROFILE_DRIVER_INFO_SIGNATURE SIGNATURE_32 ('M','P','D','I')
47 #define MEMORY_PROFILE_DRIVER_INFO_REVISION 0x0003
48
49 typedef struct {
50 MEMORY_PROFILE_COMMON_HEADER Header;
51 EFI_GUID FileName;
52 PHYSICAL_ADDRESS ImageBase;
53 UINT64 ImageSize;
54 PHYSICAL_ADDRESS EntryPoint;
55 UINT16 ImageSubsystem;
56 EFI_FV_FILETYPE FileType;
57 UINT8 Reserved[1];
58 UINT32 AllocRecordCount;
59 UINT64 CurrentUsage;
60 UINT64 PeakUsage;
61 UINT64 CurrentUsageByType[EfiMaxMemoryType + 2];
62 UINT64 PeakUsageByType[EfiMaxMemoryType + 2];
63 UINT16 PdbStringOffset;
64 UINT8 Reserved2[6];
65 //CHAR8 PdbString[];
66 } MEMORY_PROFILE_DRIVER_INFO;
67
68 typedef enum {
69 MemoryProfileActionAllocatePages = 1,
70 MemoryProfileActionFreePages = 2,
71 MemoryProfileActionAllocatePool = 3,
72 MemoryProfileActionFreePool = 4,
73 } MEMORY_PROFILE_ACTION;
74
75 //
76 // Below is the detailed MEMORY_PROFILE_ACTION definition.
77 //
78 // 31 15 9 8 8 7 7 6 6 5-4 3 - 0
79 // +----------------------------------------------+
80 // |User | |Lib| |Re|Copy|Zero|Align|Type|Basic|
81 // +----------------------------------------------+
82 //
83
84 //
85 // Basic Action
86 // 1 : AllocatePages
87 // 2 : FreePages
88 // 3 : AllocatePool
89 // 4 : FreePool
90 //
91 #define MEMORY_PROFILE_ACTION_BASIC_MASK 0xF
92
93 //
94 // Extension
95 //
96 #define MEMORY_PROFILE_ACTION_EXTENSION_MASK 0xFFF0
97 #define MEMORY_PROFILE_ACTION_EXTENSION_LIB_MASK 0x8000
98 #define MEMORY_PROFILE_ACTION_EXTENSION_REALLOC_MASK 0x0200
99 #define MEMORY_PROFILE_ACTION_EXTENSION_COPY_MASK 0x0100
100 #define MEMORY_PROFILE_ACTION_EXTENSION_ZERO_MASK 0x0080
101 #define MEMORY_PROFILE_ACTION_EXTENSION_ALIGN_MASK 0x0040
102 #define MEMORY_PROFILE_ACTION_EXTENSION_MEM_TYPE_MASK 0x0030
103 #define MEMORY_PROFILE_ACTION_EXTENSION_MEM_TYPE_BASIC 0x0000
104 #define MEMORY_PROFILE_ACTION_EXTENSION_MEM_TYPE_RUNTIME 0x0010
105 #define MEMORY_PROFILE_ACTION_EXTENSION_MEM_TYPE_RESERVED 0x0020
106
107 //
108 // Extension (used by memory allocation lib)
109 //
110 #define MEMORY_PROFILE_ACTION_LIB_ALLOCATE_PAGES 0x8001
111 #define MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_PAGES 0x8011
112 #define MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_PAGES 0x8021
113 #define MEMORY_PROFILE_ACTION_LIB_FREE_PAGES 0x8002
114 #define MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ALIGNED_PAGES 0x8041
115 #define MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ALIGNED_RUNTIME_PAGES 0x8051
116 #define MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ALIGNED_RESERVED_PAGES 0x8061
117 #define MEMORY_PROFILE_ACTION_LIB_FREE_ALIGNED_PAGES 0x8042
118 #define MEMORY_PROFILE_ACTION_LIB_ALLOCATE_POOL 0x8003
119 #define MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_POOL 0x8013
120 #define MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_POOL 0x8023
121 #define MEMORY_PROFILE_ACTION_LIB_FREE_POOL 0x8004
122 #define MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ZERO_POOL 0x8083
123 #define MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_ZERO_POOL 0x8093
124 #define MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_ZERO_POOL 0x80a3
125 #define MEMORY_PROFILE_ACTION_LIB_ALLOCATE_COPY_POOL 0x8103
126 #define MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_COPY_POOL 0x8113
127 #define MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_COPY_POOL 0x8123
128 #define MEMORY_PROFILE_ACTION_LIB_REALLOCATE_POOL 0x8203
129 #define MEMORY_PROFILE_ACTION_LIB_REALLOCATE_RUNTIME_POOL 0x8213
130 #define MEMORY_PROFILE_ACTION_LIB_REALLOCATE_RESERVED_POOL 0x8223
131
132 //
133 // User defined: 0x80000000~0xFFFFFFFF
134 //
135 // NOTE: User defined action MUST OR the basic action,
136 // so that core can know the action is allocate or free,
137 // and the type is pages (can be freed partially)
138 // or pool (cannot be freed partially).
139 //
140 #define MEMORY_PROFILE_ACTION_USER_DEFINED_MASK 0x80000000
141
142 #define MEMORY_PROFILE_ALLOC_INFO_SIGNATURE SIGNATURE_32 ('M','P','A','I')
143 #define MEMORY_PROFILE_ALLOC_INFO_REVISION 0x0002
144
145 typedef struct {
146 MEMORY_PROFILE_COMMON_HEADER Header;
147 PHYSICAL_ADDRESS CallerAddress;
148 UINT32 SequenceId;
149 UINT8 Reserved[4];
150 MEMORY_PROFILE_ACTION Action;
151 EFI_MEMORY_TYPE MemoryType;
152 PHYSICAL_ADDRESS Buffer;
153 UINT64 Size;
154 UINT16 ActionStringOffset;
155 UINT8 Reserved2[6];
156 //CHAR8 ActionString[];
157 } MEMORY_PROFILE_ALLOC_INFO;
158
159 #define MEMORY_PROFILE_DESCRIPTOR_SIGNATURE SIGNATURE_32 ('M','P','D','R')
160 #define MEMORY_PROFILE_DESCRIPTOR_REVISION 0x0001
161
162 typedef struct {
163 MEMORY_PROFILE_COMMON_HEADER Header;
164 PHYSICAL_ADDRESS Address;
165 UINT64 Size;
166 } MEMORY_PROFILE_DESCRIPTOR;
167
168 #define MEMORY_PROFILE_FREE_MEMORY_SIGNATURE SIGNATURE_32 ('M','P','R','M')
169 #define MEMORY_PROFILE_FREE_MEMORY_REVISION 0x0001
170
171 typedef struct {
172 MEMORY_PROFILE_COMMON_HEADER Header;
173 UINT64 TotalFreeMemoryPages;
174 UINT32 FreeMemoryEntryCount;
175 UINT8 Reserved[4];
176 //MEMORY_PROFILE_DESCRIPTOR MemoryDescriptor[FreeMemoryEntryCount];
177 } MEMORY_PROFILE_FREE_MEMORY;
178
179 #define MEMORY_PROFILE_MEMORY_RANGE_SIGNATURE SIGNATURE_32 ('M','P','M','R')
180 #define MEMORY_PROFILE_MEMORY_RANGE_REVISION 0x0001
181
182 typedef struct {
183 MEMORY_PROFILE_COMMON_HEADER Header;
184 UINT32 MemoryRangeCount;
185 UINT8 Reserved[4];
186 //MEMORY_PROFILE_DESCRIPTOR MemoryDescriptor[MemoryRangeCount];
187 } MEMORY_PROFILE_MEMORY_RANGE;
188
189 //
190 // UEFI memory profile layout:
191 // +--------------------------------+
192 // | CONTEXT |
193 // +--------------------------------+
194 // | DRIVER_INFO(1) |
195 // +--------------------------------+
196 // | ALLOC_INFO(1, 1) |
197 // +--------------------------------+
198 // | ALLOC_INFO(1, m1) |
199 // +--------------------------------+
200 // | DRIVER_INFO(n) |
201 // +--------------------------------+
202 // | ALLOC_INFO(n, 1) |
203 // +--------------------------------+
204 // | ALLOC_INFO(n, mn) |
205 // +--------------------------------+
206 //
207
208 typedef struct _EDKII_MEMORY_PROFILE_PROTOCOL EDKII_MEMORY_PROFILE_PROTOCOL;
209
210 /**
211 Get memory profile data.
212
213 @param[in] This The EDKII_MEMORY_PROFILE_PROTOCOL instance.
214 @param[in, out] ProfileSize On entry, points to the size in bytes of the ProfileBuffer.
215 On return, points to the size of the data returned in ProfileBuffer.
216 @param[out] ProfileBuffer Profile buffer.
217
218 @return EFI_SUCCESS Get the memory profile data successfully.
219 @return EFI_UNSUPPORTED Memory profile is unsupported.
220 @return EFI_BUFFER_TO_SMALL The ProfileSize is too small for the resulting data.
221 ProfileSize is updated with the size required.
222
223 **/
224 typedef
225 EFI_STATUS
226 (EFIAPI *EDKII_MEMORY_PROFILE_GET_DATA)(
227 IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
228 IN OUT UINT64 *ProfileSize,
229 OUT VOID *ProfileBuffer
230 );
231
232 /**
233 Register image to memory profile.
234
235 @param[in] This The EDKII_MEMORY_PROFILE_PROTOCOL instance.
236 @param[in] FilePath File path of the image.
237 @param[in] ImageBase Image base address.
238 @param[in] ImageSize Image size.
239 @param[in] FileType File type of the image.
240
241 @return EFI_SUCCESS Register successfully.
242 @return EFI_UNSUPPORTED Memory profile is unsupported,
243 or memory profile for the image is not required.
244 @return EFI_OUT_OF_RESOURCES No enough resource for this register.
245
246 **/
247 typedef
248 EFI_STATUS
249 (EFIAPI *EDKII_MEMORY_PROFILE_REGISTER_IMAGE)(
250 IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
251 IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
252 IN PHYSICAL_ADDRESS ImageBase,
253 IN UINT64 ImageSize,
254 IN EFI_FV_FILETYPE FileType
255 );
256
257 /**
258 Unregister image from memory profile.
259
260 @param[in] This The EDKII_MEMORY_PROFILE_PROTOCOL instance.
261 @param[in] FilePath File path of the image.
262 @param[in] ImageBase Image base address.
263 @param[in] ImageSize Image size.
264
265 @return EFI_SUCCESS Unregister successfully.
266 @return EFI_UNSUPPORTED Memory profile is unsupported,
267 or memory profile for the image is not required.
268 @return EFI_NOT_FOUND The image is not found.
269
270 **/
271 typedef
272 EFI_STATUS
273 (EFIAPI *EDKII_MEMORY_PROFILE_UNREGISTER_IMAGE)(
274 IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
275 IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
276 IN PHYSICAL_ADDRESS ImageBase,
277 IN UINT64 ImageSize
278 );
279
280 #define MEMORY_PROFILE_RECORDING_ENABLE TRUE
281 #define MEMORY_PROFILE_RECORDING_DISABLE FALSE
282
283 /**
284 Get memory profile recording state.
285
286 @param[in] This The EDKII_MEMORY_PROFILE_PROTOCOL instance.
287 @param[out] RecordingState Recording state.
288
289 @return EFI_SUCCESS Memory profile recording state is returned.
290 @return EFI_UNSUPPORTED Memory profile is unsupported.
291 @return EFI_INVALID_PARAMETER RecordingState is NULL.
292
293 **/
294 typedef
295 EFI_STATUS
296 (EFIAPI *EDKII_MEMORY_PROFILE_GET_RECORDING_STATE) (
297 IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
298 OUT BOOLEAN *RecordingState
299 );
300
301 /**
302 Set memory profile recording state.
303
304 @param[in] This The EDKII_MEMORY_PROFILE_PROTOCOL instance.
305 @param[in] RecordingState Recording state.
306
307 @return EFI_SUCCESS Set memory profile recording state successfully.
308 @return EFI_UNSUPPORTED Memory profile is unsupported.
309
310 **/
311 typedef
312 EFI_STATUS
313 (EFIAPI *EDKII_MEMORY_PROFILE_SET_RECORDING_STATE) (
314 IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
315 IN BOOLEAN RecordingState
316 );
317
318 /**
319 Record memory profile of multilevel caller.
320
321 @param[in] This The EDKII_MEMORY_PROFILE_PROTOCOL instance.
322 @param[in] CallerAddress Address of caller.
323 @param[in] Action Memory profile action.
324 @param[in] MemoryType Memory type.
325 EfiMaxMemoryType means the MemoryType is unknown.
326 @param[in] Buffer Buffer address.
327 @param[in] Size Buffer size.
328 @param[in] ActionString String for memory profile action.
329 Only needed for user defined allocate action.
330
331 @return EFI_SUCCESS Memory profile is updated.
332 @return EFI_UNSUPPORTED Memory profile is unsupported,
333 or memory profile for the image is not required,
334 or memory profile for the memory type is not required.
335 @return EFI_ACCESS_DENIED It is during memory profile data getting.
336 @return EFI_ABORTED Memory profile recording is not enabled.
337 @return EFI_OUT_OF_RESOURCES No enough resource to update memory profile for allocate action.
338 @return EFI_NOT_FOUND No matched allocate info found for free action.
339
340 **/
341 typedef
342 EFI_STATUS
343 (EFIAPI *EDKII_MEMORY_PROFILE_RECORD) (
344 IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
345 IN PHYSICAL_ADDRESS CallerAddress,
346 IN MEMORY_PROFILE_ACTION Action,
347 IN EFI_MEMORY_TYPE MemoryType,
348 IN VOID *Buffer,
349 IN UINTN Size,
350 IN CHAR8 *ActionString OPTIONAL
351 );
352
353 struct _EDKII_MEMORY_PROFILE_PROTOCOL {
354 EDKII_MEMORY_PROFILE_GET_DATA GetData;
355 EDKII_MEMORY_PROFILE_REGISTER_IMAGE RegisterImage;
356 EDKII_MEMORY_PROFILE_UNREGISTER_IMAGE UnregisterImage;
357 EDKII_MEMORY_PROFILE_GET_RECORDING_STATE GetRecordingState;
358 EDKII_MEMORY_PROFILE_SET_RECORDING_STATE SetRecordingState;
359 EDKII_MEMORY_PROFILE_RECORD Record;
360 };
361
362 //
363 // SMRAM profile layout:
364 // +--------------------------------+
365 // | CONTEXT |
366 // +--------------------------------+
367 // | DRIVER_INFO(1) |
368 // +--------------------------------+
369 // | ALLOC_INFO(1, 1) |
370 // +--------------------------------+
371 // | ALLOC_INFO(1, m1) |
372 // +--------------------------------+
373 // | DRIVER_INFO(n) |
374 // +--------------------------------+
375 // | ALLOC_INFO(n, 1) |
376 // +--------------------------------+
377 // | ALLOC_INFO(n, mn) |
378 // +--------------------------------+
379 // | FREE_MEMORY |
380 // +--------------------------------+
381 // | FREE MEMORY DESCRIPTOR(1) |
382 // +--------------------------------+
383 // | FREE MEMORY DESCRIPTOR(p) |
384 // +--------------------------------+
385 // | MEMORY_RANGE |
386 // +--------------------------------+
387 // | MEMORY RANGE DESCRIPTOR(1) |
388 // +--------------------------------+
389 // | MEMORY RANGE DESCRIPTOR(q) |
390 // +--------------------------------+
391 //
392
393 //
394 // SMRAM profile command
395 //
396 #define SMRAM_PROFILE_COMMAND_GET_PROFILE_INFO 0x1
397 #define SMRAM_PROFILE_COMMAND_GET_PROFILE_DATA 0x2
398 //
399 // Below 2 commands are now used by ECP only and only valid before SmmReadyToLock
400 //
401 #define SMRAM_PROFILE_COMMAND_REGISTER_IMAGE 0x3
402 #define SMRAM_PROFILE_COMMAND_UNREGISTER_IMAGE 0x4
403
404 #define SMRAM_PROFILE_COMMAND_GET_PROFILE_DATA_BY_OFFSET 0x5
405 #define SMRAM_PROFILE_COMMAND_GET_RECORDING_STATE 0x6
406 #define SMRAM_PROFILE_COMMAND_SET_RECORDING_STATE 0x7
407
408 typedef struct {
409 UINT32 Command;
410 UINT32 DataLength;
411 UINT64 ReturnStatus;
412 } SMRAM_PROFILE_PARAMETER_HEADER;
413
414 typedef struct {
415 SMRAM_PROFILE_PARAMETER_HEADER Header;
416 UINT64 ProfileSize;
417 } SMRAM_PROFILE_PARAMETER_GET_PROFILE_INFO;
418
419 typedef struct {
420 SMRAM_PROFILE_PARAMETER_HEADER Header;
421 UINT64 ProfileSize;
422 PHYSICAL_ADDRESS ProfileBuffer;
423 } SMRAM_PROFILE_PARAMETER_GET_PROFILE_DATA;
424
425 typedef struct {
426 SMRAM_PROFILE_PARAMETER_HEADER Header;
427 //
428 // On input, profile buffer size.
429 // On output, actual profile data size copied.
430 //
431 UINT64 ProfileSize;
432 PHYSICAL_ADDRESS ProfileBuffer;
433 //
434 // On input, profile buffer offset to copy.
435 // On output, next time profile buffer offset to copy.
436 //
437 UINT64 ProfileOffset;
438 } SMRAM_PROFILE_PARAMETER_GET_PROFILE_DATA_BY_OFFSET;
439
440 typedef struct {
441 SMRAM_PROFILE_PARAMETER_HEADER Header;
442 BOOLEAN RecordingState;
443 } SMRAM_PROFILE_PARAMETER_RECORDING_STATE;
444
445 typedef struct {
446 SMRAM_PROFILE_PARAMETER_HEADER Header;
447 EFI_GUID FileName;
448 PHYSICAL_ADDRESS ImageBuffer;
449 UINT64 NumberOfPage;
450 } SMRAM_PROFILE_PARAMETER_REGISTER_IMAGE;
451
452 typedef struct {
453 SMRAM_PROFILE_PARAMETER_HEADER Header;
454 EFI_GUID FileName;
455 PHYSICAL_ADDRESS ImageBuffer;
456 UINT64 NumberOfPage;
457 } SMRAM_PROFILE_PARAMETER_UNREGISTER_IMAGE;
458
459
460 #define EDKII_MEMORY_PROFILE_GUID { \
461 0x821c9a09, 0x541a, 0x40f6, { 0x9f, 0x43, 0xa, 0xd1, 0x93, 0xa1, 0x2c, 0xfe } \
462 }
463
464 extern EFI_GUID gEdkiiMemoryProfileGuid;
465
466 typedef EDKII_MEMORY_PROFILE_PROTOCOL EDKII_SMM_MEMORY_PROFILE_PROTOCOL;
467
468 #define EDKII_SMM_MEMORY_PROFILE_GUID { \
469 0xe22bbcca, 0x516a, 0x46a8, { 0x80, 0xe2, 0x67, 0x45, 0xe8, 0x36, 0x93, 0xbd } \
470 }
471
472 extern EFI_GUID gEdkiiSmmMemoryProfileGuid;
473
474 #endif
475