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