2 Memory profile data structure.
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
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.
15 #ifndef _MEMORY_PROFILE_H_
16 #define _MEMORY_PROFILE_H_
18 #include <Pi/PiFirmwareFile.h>
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)
30 } MEMORY_PROFILE_COMMON_HEADER
;
32 #define MEMORY_PROFILE_CONTEXT_SIGNATURE SIGNATURE_32 ('M','P','C','T')
33 #define MEMORY_PROFILE_CONTEXT_REVISION 0x0002
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
;
44 } MEMORY_PROFILE_CONTEXT
;
46 #define MEMORY_PROFILE_DRIVER_INFO_SIGNATURE SIGNATURE_32 ('M','P','D','I')
47 #define MEMORY_PROFILE_DRIVER_INFO_REVISION 0x0003
50 MEMORY_PROFILE_COMMON_HEADER Header
;
52 PHYSICAL_ADDRESS ImageBase
;
54 PHYSICAL_ADDRESS EntryPoint
;
55 UINT16 ImageSubsystem
;
56 EFI_FV_FILETYPE FileType
;
58 UINT32 AllocRecordCount
;
61 UINT64 CurrentUsageByType
[EfiMaxMemoryType
+ 2];
62 UINT64 PeakUsageByType
[EfiMaxMemoryType
+ 2];
63 UINT16 PdbStringOffset
;
66 } MEMORY_PROFILE_DRIVER_INFO
;
69 MemoryProfileActionAllocatePages
= 1,
70 MemoryProfileActionFreePages
= 2,
71 MemoryProfileActionAllocatePool
= 3,
72 MemoryProfileActionFreePool
= 4,
73 } MEMORY_PROFILE_ACTION
;
76 // Below is the detailed MEMORY_PROFILE_ACTION definition.
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 // +----------------------------------------------+
91 #define MEMORY_PROFILE_ACTION_BASIC_MASK 0xF
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
108 // Extension (used by memory allocation lib)
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
133 // User defined: 0x80000000~0xFFFFFFFF
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).
140 #define MEMORY_PROFILE_ACTION_USER_DEFINED_MASK 0x80000000
142 #define MEMORY_PROFILE_ALLOC_INFO_SIGNATURE SIGNATURE_32 ('M','P','A','I')
143 #define MEMORY_PROFILE_ALLOC_INFO_REVISION 0x0002
146 MEMORY_PROFILE_COMMON_HEADER Header
;
147 PHYSICAL_ADDRESS CallerAddress
;
150 MEMORY_PROFILE_ACTION Action
;
151 EFI_MEMORY_TYPE MemoryType
;
152 PHYSICAL_ADDRESS Buffer
;
154 UINT16 ActionStringOffset
;
156 //CHAR8 ActionString[];
157 } MEMORY_PROFILE_ALLOC_INFO
;
159 #define MEMORY_PROFILE_DESCRIPTOR_SIGNATURE SIGNATURE_32 ('M','P','D','R')
160 #define MEMORY_PROFILE_DESCRIPTOR_REVISION 0x0001
163 MEMORY_PROFILE_COMMON_HEADER Header
;
164 PHYSICAL_ADDRESS Address
;
166 } MEMORY_PROFILE_DESCRIPTOR
;
168 #define MEMORY_PROFILE_FREE_MEMORY_SIGNATURE SIGNATURE_32 ('M','P','R','M')
169 #define MEMORY_PROFILE_FREE_MEMORY_REVISION 0x0001
172 MEMORY_PROFILE_COMMON_HEADER Header
;
173 UINT64 TotalFreeMemoryPages
;
174 UINT32 FreeMemoryEntryCount
;
176 //MEMORY_PROFILE_DESCRIPTOR MemoryDescriptor[FreeMemoryEntryCount];
177 } MEMORY_PROFILE_FREE_MEMORY
;
179 #define MEMORY_PROFILE_MEMORY_RANGE_SIGNATURE SIGNATURE_32 ('M','P','M','R')
180 #define MEMORY_PROFILE_MEMORY_RANGE_REVISION 0x0001
183 MEMORY_PROFILE_COMMON_HEADER Header
;
184 UINT32 MemoryRangeCount
;
186 //MEMORY_PROFILE_DESCRIPTOR MemoryDescriptor[MemoryRangeCount];
187 } MEMORY_PROFILE_MEMORY_RANGE
;
190 // UEFI memory profile layout:
191 // +--------------------------------+
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 // +--------------------------------+
208 typedef struct _EDKII_MEMORY_PROFILE_PROTOCOL EDKII_MEMORY_PROFILE_PROTOCOL
;
211 Get memory profile data.
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.
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.
226 (EFIAPI
*EDKII_MEMORY_PROFILE_GET_DATA
)(
227 IN EDKII_MEMORY_PROFILE_PROTOCOL
*This
,
228 IN OUT UINT64
*ProfileSize
,
229 OUT VOID
*ProfileBuffer
233 Register image to memory profile.
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.
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.
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
,
254 IN EFI_FV_FILETYPE FileType
258 Unregister image from memory profile.
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.
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.
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
,
280 #define MEMORY_PROFILE_RECORDING_ENABLE TRUE
281 #define MEMORY_PROFILE_RECORDING_DISABLE FALSE
284 Get memory profile recording state.
286 @param[in] This The EDKII_MEMORY_PROFILE_PROTOCOL instance.
287 @param[out] RecordingState Recording state.
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.
296 (EFIAPI
*EDKII_MEMORY_PROFILE_GET_RECORDING_STATE
) (
297 IN EDKII_MEMORY_PROFILE_PROTOCOL
*This
,
298 OUT BOOLEAN
*RecordingState
302 Set memory profile recording state.
304 @param[in] This The EDKII_MEMORY_PROFILE_PROTOCOL instance.
305 @param[in] RecordingState Recording state.
307 @return EFI_SUCCESS Set memory profile recording state successfully.
308 @return EFI_UNSUPPORTED Memory profile is unsupported.
313 (EFIAPI
*EDKII_MEMORY_PROFILE_SET_RECORDING_STATE
) (
314 IN EDKII_MEMORY_PROFILE_PROTOCOL
*This
,
315 IN BOOLEAN RecordingState
319 Record memory profile of multilevel caller.
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.
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.
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
,
350 IN CHAR8
*ActionString OPTIONAL
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
;
363 // SMRAM profile layout:
364 // +--------------------------------+
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 // +--------------------------------+
380 // +--------------------------------+
381 // | FREE MEMORY DESCRIPTOR(1) |
382 // +--------------------------------+
383 // | FREE MEMORY DESCRIPTOR(p) |
384 // +--------------------------------+
386 // +--------------------------------+
387 // | MEMORY RANGE DESCRIPTOR(1) |
388 // +--------------------------------+
389 // | MEMORY RANGE DESCRIPTOR(q) |
390 // +--------------------------------+
394 // SMRAM profile command
396 #define SMRAM_PROFILE_COMMAND_GET_PROFILE_INFO 0x1
397 #define SMRAM_PROFILE_COMMAND_GET_PROFILE_DATA 0x2
399 // Below 2 commands are now used by ECP only and only valid before SmmReadyToLock
401 #define SMRAM_PROFILE_COMMAND_REGISTER_IMAGE 0x3
402 #define SMRAM_PROFILE_COMMAND_UNREGISTER_IMAGE 0x4
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
412 } SMRAM_PROFILE_PARAMETER_HEADER
;
415 SMRAM_PROFILE_PARAMETER_HEADER Header
;
417 } SMRAM_PROFILE_PARAMETER_GET_PROFILE_INFO
;
420 SMRAM_PROFILE_PARAMETER_HEADER Header
;
422 PHYSICAL_ADDRESS ProfileBuffer
;
423 } SMRAM_PROFILE_PARAMETER_GET_PROFILE_DATA
;
426 SMRAM_PROFILE_PARAMETER_HEADER Header
;
428 // On input, profile buffer size.
429 // On output, actual profile data size copied.
432 PHYSICAL_ADDRESS ProfileBuffer
;
434 // On input, profile buffer offset to copy.
435 // On output, next time profile buffer offset to copy.
437 UINT64 ProfileOffset
;
438 } SMRAM_PROFILE_PARAMETER_GET_PROFILE_DATA_BY_OFFSET
;
441 SMRAM_PROFILE_PARAMETER_HEADER Header
;
442 BOOLEAN RecordingState
;
443 } SMRAM_PROFILE_PARAMETER_RECORDING_STATE
;
446 SMRAM_PROFILE_PARAMETER_HEADER Header
;
448 PHYSICAL_ADDRESS ImageBuffer
;
450 } SMRAM_PROFILE_PARAMETER_REGISTER_IMAGE
;
453 SMRAM_PROFILE_PARAMETER_HEADER Header
;
455 PHYSICAL_ADDRESS ImageBuffer
;
457 } SMRAM_PROFILE_PARAMETER_UNREGISTER_IMAGE
;
460 #define EDKII_MEMORY_PROFILE_GUID { \
461 0x821c9a09, 0x541a, 0x40f6, { 0x9f, 0x43, 0xa, 0xd1, 0x93, 0xa1, 0x2c, 0xfe } \
464 extern EFI_GUID gEdkiiMemoryProfileGuid
;
466 typedef EDKII_MEMORY_PROFILE_PROTOCOL EDKII_SMM_MEMORY_PROFILE_PROTOCOL
;
468 #define EDKII_SMM_MEMORY_PROFILE_GUID { \
469 0xe22bbcca, 0x516a, 0x46a8, { 0x80, 0xe2, 0x67, 0x45, 0xe8, 0x36, 0x93, 0xbd } \
472 extern EFI_GUID gEdkiiSmmMemoryProfileGuid
;