TianoCore EDK2 master
Loading...
Searching...
No Matches
MemoryProfile.h
Go to the documentation of this file.
1
9#ifndef _MEMORY_PROFILE_H_
10#define _MEMORY_PROFILE_H_
11
12#include <Pi/PiFirmwareFile.h>
13
14//
15// For BIOS MemoryType (0 ~ EfiMaxMemoryType - 1), it is recorded in UsageByType[MemoryType]. (Each valid entry has one entry)
16// For OS MemoryType (0x80000000 ~ 0xFFFFFFFF), it is recorded in UsageByType[EfiMaxMemoryType]. (All types are combined into one entry)
17// For OEM MemoryType (0x70000000 ~ 0x7FFFFFFF), it is recorded in UsageByType[EfiMaxMemoryType + 1]. (All types are combined into one entry)
18//
19
20typedef struct {
21 UINT32 Signature;
22 UINT16 Length;
23 UINT16 Revision;
25
26#define MEMORY_PROFILE_CONTEXT_SIGNATURE SIGNATURE_32 ('M','P','C','T')
27#define MEMORY_PROFILE_CONTEXT_REVISION 0x0002
28
29typedef struct {
31 UINT64 CurrentTotalUsage;
32 UINT64 PeakTotalUsage;
33 UINT64 CurrentTotalUsageByType[EfiMaxMemoryType + 2];
34 UINT64 PeakTotalUsageByType[EfiMaxMemoryType + 2];
35 UINT64 TotalImageSize;
36 UINT32 ImageCount;
37 UINT32 SequenceCount;
39
40#define MEMORY_PROFILE_DRIVER_INFO_SIGNATURE SIGNATURE_32 ('M','P','D','I')
41#define MEMORY_PROFILE_DRIVER_INFO_REVISION 0x0003
42
43typedef struct {
45 EFI_GUID FileName;
46 PHYSICAL_ADDRESS ImageBase;
47 UINT64 ImageSize;
48 PHYSICAL_ADDRESS EntryPoint;
49 UINT16 ImageSubsystem;
50 EFI_FV_FILETYPE FileType;
51 UINT8 Reserved[1];
52 UINT32 AllocRecordCount;
53 UINT64 CurrentUsage;
54 UINT64 PeakUsage;
55 UINT64 CurrentUsageByType[EfiMaxMemoryType + 2];
56 UINT64 PeakUsageByType[EfiMaxMemoryType + 2];
57 UINT16 PdbStringOffset;
58 UINT8 Reserved2[6];
59 // CHAR8 PdbString[];
61
62typedef enum {
63 MemoryProfileActionAllocatePages = 1,
64 MemoryProfileActionFreePages = 2,
65 MemoryProfileActionAllocatePool = 3,
66 MemoryProfileActionFreePool = 4,
67} MEMORY_PROFILE_ACTION;
68
69//
70// Below is the detailed MEMORY_PROFILE_ACTION definition.
71//
72// 31 15 9 8 8 7 7 6 6 5-4 3 - 0
73// +----------------------------------------------+
74// |User | |Lib| |Re|Copy|Zero|Align|Type|Basic|
75// +----------------------------------------------+
76//
77
78//
79// Basic Action
80// 1 : AllocatePages
81// 2 : FreePages
82// 3 : AllocatePool
83// 4 : FreePool
84//
85#define MEMORY_PROFILE_ACTION_BASIC_MASK 0xF
86
87//
88// Extension
89//
90#define MEMORY_PROFILE_ACTION_EXTENSION_MASK 0xFFF0
91#define MEMORY_PROFILE_ACTION_EXTENSION_LIB_MASK 0x8000
92#define MEMORY_PROFILE_ACTION_EXTENSION_REALLOC_MASK 0x0200
93#define MEMORY_PROFILE_ACTION_EXTENSION_COPY_MASK 0x0100
94#define MEMORY_PROFILE_ACTION_EXTENSION_ZERO_MASK 0x0080
95#define MEMORY_PROFILE_ACTION_EXTENSION_ALIGN_MASK 0x0040
96#define MEMORY_PROFILE_ACTION_EXTENSION_MEM_TYPE_MASK 0x0030
97#define MEMORY_PROFILE_ACTION_EXTENSION_MEM_TYPE_BASIC 0x0000
98#define MEMORY_PROFILE_ACTION_EXTENSION_MEM_TYPE_RUNTIME 0x0010
99#define MEMORY_PROFILE_ACTION_EXTENSION_MEM_TYPE_RESERVED 0x0020
100
101//
102// Extension (used by memory allocation lib)
103//
104#define MEMORY_PROFILE_ACTION_LIB_ALLOCATE_PAGES 0x8001
105#define MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_PAGES 0x8011
106#define MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_PAGES 0x8021
107#define MEMORY_PROFILE_ACTION_LIB_FREE_PAGES 0x8002
108#define MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ALIGNED_PAGES 0x8041
109#define MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ALIGNED_RUNTIME_PAGES 0x8051
110#define MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ALIGNED_RESERVED_PAGES 0x8061
111#define MEMORY_PROFILE_ACTION_LIB_FREE_ALIGNED_PAGES 0x8042
112#define MEMORY_PROFILE_ACTION_LIB_ALLOCATE_POOL 0x8003
113#define MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_POOL 0x8013
114#define MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_POOL 0x8023
115#define MEMORY_PROFILE_ACTION_LIB_FREE_POOL 0x8004
116#define MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ZERO_POOL 0x8083
117#define MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_ZERO_POOL 0x8093
118#define MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_ZERO_POOL 0x80a3
119#define MEMORY_PROFILE_ACTION_LIB_ALLOCATE_COPY_POOL 0x8103
120#define MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_COPY_POOL 0x8113
121#define MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_COPY_POOL 0x8123
122#define MEMORY_PROFILE_ACTION_LIB_REALLOCATE_POOL 0x8203
123#define MEMORY_PROFILE_ACTION_LIB_REALLOCATE_RUNTIME_POOL 0x8213
124#define MEMORY_PROFILE_ACTION_LIB_REALLOCATE_RESERVED_POOL 0x8223
125
126//
127// User defined: 0x80000000~0xFFFFFFFF
128//
129// NOTE: User defined action MUST OR the basic action,
130// so that core can know the action is allocate or free,
131// and the type is pages (can be freed partially)
132// or pool (cannot be freed partially).
133//
134#define MEMORY_PROFILE_ACTION_USER_DEFINED_MASK 0x80000000
135
136#define MEMORY_PROFILE_ALLOC_INFO_SIGNATURE SIGNATURE_32 ('M','P','A','I')
137#define MEMORY_PROFILE_ALLOC_INFO_REVISION 0x0002
138
139typedef struct {
141 PHYSICAL_ADDRESS CallerAddress;
142 UINT32 SequenceId;
143 UINT8 Reserved[2];
144 UINT16 ActionStringOffset;
145 MEMORY_PROFILE_ACTION Action;
146 EFI_MEMORY_TYPE MemoryType;
147 PHYSICAL_ADDRESS Buffer;
148 UINT64 Size;
149 // CHAR8 ActionString[];
151
152#define MEMORY_PROFILE_DESCRIPTOR_SIGNATURE SIGNATURE_32 ('M','P','D','R')
153#define MEMORY_PROFILE_DESCRIPTOR_REVISION 0x0001
154
155typedef struct {
157 PHYSICAL_ADDRESS Address;
158 UINT64 Size;
160
161#define MEMORY_PROFILE_FREE_MEMORY_SIGNATURE SIGNATURE_32 ('M','P','R','M')
162#define MEMORY_PROFILE_FREE_MEMORY_REVISION 0x0001
163
164typedef struct {
166 UINT64 TotalFreeMemoryPages;
167 UINT32 FreeMemoryEntryCount;
168 UINT8 Reserved[4];
169 // MEMORY_PROFILE_DESCRIPTOR MemoryDescriptor[FreeMemoryEntryCount];
171
172#define MEMORY_PROFILE_MEMORY_RANGE_SIGNATURE SIGNATURE_32 ('M','P','M','R')
173#define MEMORY_PROFILE_MEMORY_RANGE_REVISION 0x0001
174
175typedef struct {
177 UINT32 MemoryRangeCount;
178 UINT8 Reserved[4];
179 // MEMORY_PROFILE_DESCRIPTOR MemoryDescriptor[MemoryRangeCount];
181
182//
183// UEFI memory profile layout:
184// +--------------------------------+
185// | CONTEXT |
186// +--------------------------------+
187// | DRIVER_INFO(1) |
188// +--------------------------------+
189// | ALLOC_INFO(1, 1) |
190// +--------------------------------+
191// | ALLOC_INFO(1, m1) |
192// +--------------------------------+
193// | DRIVER_INFO(n) |
194// +--------------------------------+
195// | ALLOC_INFO(n, 1) |
196// +--------------------------------+
197// | ALLOC_INFO(n, mn) |
198// +--------------------------------+
199//
200
202
217typedef
221 IN OUT UINT64 *ProfileSize,
222 OUT VOID *ProfileBuffer
223 );
224
240typedef
245 IN PHYSICAL_ADDRESS ImageBase,
246 IN UINT64 ImageSize,
247 IN EFI_FV_FILETYPE FileType
248 );
249
264typedef
269 IN PHYSICAL_ADDRESS ImageBase,
270 IN UINT64 ImageSize
271 );
272
273#define MEMORY_PROFILE_RECORDING_ENABLE TRUE
274#define MEMORY_PROFILE_RECORDING_DISABLE FALSE
275
287typedef
291 OUT BOOLEAN *RecordingState
292 );
293
304typedef
308 IN BOOLEAN RecordingState
309 );
310
334typedef
338 IN PHYSICAL_ADDRESS CallerAddress,
339 IN MEMORY_PROFILE_ACTION Action,
340 IN EFI_MEMORY_TYPE MemoryType,
341 IN VOID *Buffer,
342 IN UINTN Size,
343 IN CHAR8 *ActionString OPTIONAL
344 );
345
353};
354
355//
356// SMRAM profile layout:
357// +--------------------------------+
358// | CONTEXT |
359// +--------------------------------+
360// | DRIVER_INFO(1) |
361// +--------------------------------+
362// | ALLOC_INFO(1, 1) |
363// +--------------------------------+
364// | ALLOC_INFO(1, m1) |
365// +--------------------------------+
366// | DRIVER_INFO(n) |
367// +--------------------------------+
368// | ALLOC_INFO(n, 1) |
369// +--------------------------------+
370// | ALLOC_INFO(n, mn) |
371// +--------------------------------+
372// | FREE_MEMORY |
373// +--------------------------------+
374// | FREE MEMORY DESCRIPTOR(1) |
375// +--------------------------------+
376// | FREE MEMORY DESCRIPTOR(p) |
377// +--------------------------------+
378// | MEMORY_RANGE |
379// +--------------------------------+
380// | MEMORY RANGE DESCRIPTOR(1) |
381// +--------------------------------+
382// | MEMORY RANGE DESCRIPTOR(q) |
383// +--------------------------------+
384//
385
386//
387// SMRAM profile command
388//
389#define SMRAM_PROFILE_COMMAND_GET_PROFILE_INFO 0x1
390#define SMRAM_PROFILE_COMMAND_GET_PROFILE_DATA 0x2
391//
392// Below 2 commands have been deprecated. They may not be re-used.
393//
394#define SMRAM_PROFILE_COMMAND_DEPRECATED1 0x3
395#define SMRAM_PROFILE_COMMAND_DEPRECATED2 0x4
396
397#define SMRAM_PROFILE_COMMAND_GET_PROFILE_DATA_BY_OFFSET 0x5
398#define SMRAM_PROFILE_COMMAND_GET_RECORDING_STATE 0x6
399#define SMRAM_PROFILE_COMMAND_SET_RECORDING_STATE 0x7
400
401typedef struct {
402 UINT32 Command;
403 UINT32 DataLength;
404 UINT64 ReturnStatus;
406
407typedef struct {
409 UINT64 ProfileSize;
411
412typedef struct {
414 UINT64 ProfileSize;
415 PHYSICAL_ADDRESS ProfileBuffer;
417
418typedef struct {
420 //
421 // On input, profile buffer size.
422 // On output, actual profile data size copied.
423 //
424 UINT64 ProfileSize;
425 PHYSICAL_ADDRESS ProfileBuffer;
426 //
427 // On input, profile buffer offset to copy.
428 // On output, next time profile buffer offset to copy.
429 //
430 UINT64 ProfileOffset;
432
433typedef struct {
435 BOOLEAN RecordingState;
437
438typedef struct {
440 EFI_GUID FileName;
441 PHYSICAL_ADDRESS ImageBuffer;
442 UINT64 NumberOfPage;
444
445typedef struct {
447 EFI_GUID FileName;
448 PHYSICAL_ADDRESS ImageBuffer;
449 UINT64 NumberOfPage;
451
452#define EDKII_MEMORY_PROFILE_GUID {\
453 0x821c9a09, 0x541a, 0x40f6, { 0x9f, 0x43, 0xa, 0xd1, 0x93, 0xa1, 0x2c, 0xfe } \
454}
455
456extern EFI_GUID gEdkiiMemoryProfileGuid;
457
459
460#define EDKII_SMM_MEMORY_PROFILE_GUID {\
461 0xe22bbcca, 0x516a, 0x46a8, { 0x80, 0xe2, 0x67, 0x45, 0xe8, 0x36, 0x93, 0xbd } \
462}
463
464extern EFI_GUID gEdkiiSmmMemoryProfileGuid;
465
466#endif
UINT64 UINTN
#define OPTIONAL
Definition: Base.h:290
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
EFI_STATUS(EFIAPI * EDKII_MEMORY_PROFILE_UNREGISTER_IMAGE)(IN EDKII_MEMORY_PROFILE_PROTOCOL *This, IN EFI_DEVICE_PATH_PROTOCOL *FilePath, IN PHYSICAL_ADDRESS ImageBase, IN UINT64 ImageSize)
EFI_STATUS(EFIAPI * EDKII_MEMORY_PROFILE_GET_RECORDING_STATE)(IN EDKII_MEMORY_PROFILE_PROTOCOL *This, OUT BOOLEAN *RecordingState)
EFI_STATUS(EFIAPI * EDKII_MEMORY_PROFILE_REGISTER_IMAGE)(IN EDKII_MEMORY_PROFILE_PROTOCOL *This, IN EFI_DEVICE_PATH_PROTOCOL *FilePath, IN PHYSICAL_ADDRESS ImageBase, IN UINT64 ImageSize, IN EFI_FV_FILETYPE FileType)
EFI_STATUS(EFIAPI * EDKII_MEMORY_PROFILE_SET_RECORDING_STATE)(IN EDKII_MEMORY_PROFILE_PROTOCOL *This, IN BOOLEAN RecordingState)
EFI_STATUS(EFIAPI * EDKII_MEMORY_PROFILE_GET_DATA)(IN EDKII_MEMORY_PROFILE_PROTOCOL *This, IN OUT UINT64 *ProfileSize, OUT VOID *ProfileBuffer)
EFI_STATUS(EFIAPI * EDKII_MEMORY_PROFILE_RECORD)(IN EDKII_MEMORY_PROFILE_PROTOCOL *This, IN PHYSICAL_ADDRESS CallerAddress, IN MEMORY_PROFILE_ACTION Action, IN EFI_MEMORY_TYPE MemoryType, IN VOID *Buffer, IN UINTN Size, IN CHAR8 *ActionString OPTIONAL)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
EFI_MEMORY_TYPE
Definition: Base.h:213