]>
Commit | Line | Data |
---|---|---|
216b942d JY |
1 | /** @file\r |
2 | Shell application to dump SMI handler profile information.\r | |
3 | \r | |
4 | Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>\r | |
9d510e61 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
216b942d JY |
6 | \r |
7 | **/\r | |
8 | \r | |
9 | #include <PiDxe.h>\r | |
10 | #include <Library/BaseLib.h>\r | |
11 | #include <Library/BaseMemoryLib.h>\r | |
12 | #include <Library/MemoryAllocationLib.h>\r | |
13 | #include <Library/UefiBootServicesTableLib.h>\r | |
14 | #include <Library/UefiRuntimeServicesTableLib.h>\r | |
15 | #include <Library/DebugLib.h>\r | |
16 | #include <Library/PrintLib.h>\r | |
17 | #include <Library/UefiLib.h>\r | |
18 | #include <Library/DevicePathLib.h>\r | |
216b942d JY |
19 | #include <Library/DxeServicesLib.h>\r |
20 | #include <Protocol/SmmCommunication.h>\r | |
21 | #include <Guid/PiSmmCommunicationRegionTable.h>\r | |
22 | \r | |
23 | #include <Guid/SmiHandlerProfile.h>\r | |
24 | \r | |
25 | #define PROFILE_NAME_STRING_LENGTH 64\r | |
1436aea4 | 26 | CHAR8 mNameString[PROFILE_NAME_STRING_LENGTH + 1];\r |
216b942d JY |
27 | \r |
28 | VOID *mSmiHandlerProfileDatabase;\r | |
29 | UINTN mSmiHandlerProfileDatabaseSize;\r | |
30 | \r | |
31 | /**\r | |
32 | This function dump raw data.\r | |
33 | \r | |
34 | @param Data raw data\r | |
35 | @param Size raw data size\r | |
36 | **/\r | |
37 | VOID\r | |
38 | InternalDumpData (\r | |
39 | IN UINT8 *Data,\r | |
40 | IN UINTN Size\r | |
41 | )\r | |
42 | {\r | |
43 | UINTN Index;\r | |
1436aea4 | 44 | \r |
216b942d JY |
45 | for (Index = 0; Index < Size; Index++) {\r |
46 | Print (L"%02x", (UINTN)Data[Index]);\r | |
47 | if ((Index + 1) != Size) {\r | |
48 | Print (L" ");\r | |
49 | }\r | |
50 | }\r | |
51 | }\r | |
52 | \r | |
53 | /**\r | |
54 | Get SMI handler profile database.\r | |
55 | **/\r | |
56 | VOID\r | |
1436aea4 | 57 | GetSmiHandlerProfileDatabase (\r |
216b942d JY |
58 | VOID\r |
59 | )\r | |
60 | {\r | |
1436aea4 MK |
61 | EFI_STATUS Status;\r |
62 | UINTN CommSize;\r | |
63 | UINT8 *CommBuffer;\r | |
64 | EFI_SMM_COMMUNICATE_HEADER *CommHeader;\r | |
65 | SMI_HANDLER_PROFILE_PARAMETER_GET_INFO *CommGetInfo;\r | |
66 | SMI_HANDLER_PROFILE_PARAMETER_GET_DATA_BY_OFFSET *CommGetData;\r | |
67 | EFI_SMM_COMMUNICATION_PROTOCOL *SmmCommunication;\r | |
68 | UINTN MinimalSizeNeeded;\r | |
69 | EDKII_PI_SMM_COMMUNICATION_REGION_TABLE *PiSmmCommunicationRegionTable;\r | |
70 | UINT32 Index;\r | |
71 | EFI_MEMORY_DESCRIPTOR *Entry;\r | |
72 | VOID *Buffer;\r | |
73 | UINTN Size;\r | |
74 | UINTN Offset;\r | |
75 | \r | |
76 | Status = gBS->LocateProtocol (&gEfiSmmCommunicationProtocolGuid, NULL, (VOID **)&SmmCommunication);\r | |
77 | if (EFI_ERROR (Status)) {\r | |
78 | Print (L"SmiHandlerProfile: Locate SmmCommunication protocol - %r\n", Status);\r | |
79 | return;\r | |
216b942d JY |
80 | }\r |
81 | \r | |
82 | MinimalSizeNeeded = EFI_PAGE_SIZE;\r | |
83 | \r | |
1436aea4 | 84 | Status = EfiGetSystemConfigurationTable (\r |
216b942d JY |
85 | &gEdkiiPiSmmCommunicationRegionTableGuid,\r |
86 | (VOID **)&PiSmmCommunicationRegionTable\r | |
87 | );\r | |
1436aea4 MK |
88 | if (EFI_ERROR (Status)) {\r |
89 | Print (L"SmiHandlerProfile: Get PiSmmCommunicationRegionTable - %r\n", Status);\r | |
90 | return;\r | |
216b942d | 91 | }\r |
1436aea4 MK |
92 | \r |
93 | ASSERT (PiSmmCommunicationRegionTable != NULL);\r | |
216b942d | 94 | Entry = (EFI_MEMORY_DESCRIPTOR *)(PiSmmCommunicationRegionTable + 1);\r |
1436aea4 | 95 | Size = 0;\r |
216b942d JY |
96 | for (Index = 0; Index < PiSmmCommunicationRegionTable->NumberOfEntries; Index++) {\r |
97 | if (Entry->Type == EfiConventionalMemory) {\r | |
1436aea4 | 98 | Size = EFI_PAGES_TO_SIZE ((UINTN)Entry->NumberOfPages);\r |
216b942d JY |
99 | if (Size >= MinimalSizeNeeded) {\r |
100 | break;\r | |
101 | }\r | |
102 | }\r | |
1436aea4 | 103 | \r |
216b942d JY |
104 | Entry = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)Entry + PiSmmCommunicationRegionTable->DescriptorSize);\r |
105 | }\r | |
1436aea4 MK |
106 | \r |
107 | ASSERT (Index < PiSmmCommunicationRegionTable->NumberOfEntries);\r | |
216b942d JY |
108 | CommBuffer = (UINT8 *)(UINTN)Entry->PhysicalStart;\r |
109 | \r | |
110 | //\r | |
111 | // Get Size\r | |
112 | //\r | |
113 | CommHeader = (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0];\r | |
1436aea4 MK |
114 | CopyMem (&CommHeader->HeaderGuid, &gSmiHandlerProfileGuid, sizeof (gSmiHandlerProfileGuid));\r |
115 | CommHeader->MessageLength = sizeof (SMI_HANDLER_PROFILE_PARAMETER_GET_INFO);\r | |
216b942d | 116 | \r |
1436aea4 MK |
117 | CommGetInfo = (SMI_HANDLER_PROFILE_PARAMETER_GET_INFO *)&CommBuffer[OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data)];\r |
118 | CommGetInfo->Header.Command = SMI_HANDLER_PROFILE_COMMAND_GET_INFO;\r | |
119 | CommGetInfo->Header.DataLength = sizeof (*CommGetInfo);\r | |
216b942d | 120 | CommGetInfo->Header.ReturnStatus = (UINT64)-1;\r |
1436aea4 | 121 | CommGetInfo->DataSize = 0;\r |
216b942d | 122 | \r |
1436aea4 MK |
123 | CommSize = sizeof (EFI_GUID) + sizeof (UINTN) + CommHeader->MessageLength;\r |
124 | Status = SmmCommunication->Communicate (SmmCommunication, CommBuffer, &CommSize);\r | |
125 | if (EFI_ERROR (Status)) {\r | |
126 | Print (L"SmiHandlerProfile: SmmCommunication - %r\n", Status);\r | |
127 | return;\r | |
216b942d JY |
128 | }\r |
129 | \r | |
130 | if (CommGetInfo->Header.ReturnStatus != 0) {\r | |
1436aea4 MK |
131 | Print (L"SmiHandlerProfile: GetInfo - 0x%0x\n", CommGetInfo->Header.ReturnStatus);\r |
132 | return;\r | |
216b942d JY |
133 | }\r |
134 | \r | |
135 | mSmiHandlerProfileDatabaseSize = (UINTN)CommGetInfo->DataSize;\r | |
136 | \r | |
137 | //\r | |
138 | // Get Data\r | |
139 | //\r | |
1436aea4 | 140 | mSmiHandlerProfileDatabase = AllocateZeroPool (mSmiHandlerProfileDatabaseSize);\r |
216b942d JY |
141 | if (mSmiHandlerProfileDatabase == NULL) {\r |
142 | Status = EFI_OUT_OF_RESOURCES;\r | |
1436aea4 MK |
143 | Print (L"SmiHandlerProfile: AllocateZeroPool (0x%x) for dump buffer - %r\n", mSmiHandlerProfileDatabaseSize, Status);\r |
144 | return;\r | |
216b942d JY |
145 | }\r |
146 | \r | |
147 | CommHeader = (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0];\r | |
1436aea4 MK |
148 | CopyMem (&CommHeader->HeaderGuid, &gSmiHandlerProfileGuid, sizeof (gSmiHandlerProfileGuid));\r |
149 | CommHeader->MessageLength = sizeof (SMI_HANDLER_PROFILE_PARAMETER_GET_DATA_BY_OFFSET);\r | |
216b942d | 150 | \r |
1436aea4 MK |
151 | CommGetData = (SMI_HANDLER_PROFILE_PARAMETER_GET_DATA_BY_OFFSET *)&CommBuffer[OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data)];\r |
152 | CommGetData->Header.Command = SMI_HANDLER_PROFILE_COMMAND_GET_DATA_BY_OFFSET;\r | |
153 | CommGetData->Header.DataLength = sizeof (*CommGetData);\r | |
216b942d JY |
154 | CommGetData->Header.ReturnStatus = (UINT64)-1;\r |
155 | \r | |
1436aea4 MK |
156 | CommSize = sizeof (EFI_GUID) + sizeof (UINTN) + CommHeader->MessageLength;\r |
157 | Buffer = (UINT8 *)CommHeader + CommSize;\r | |
158 | Size -= CommSize;\r | |
216b942d JY |
159 | \r |
160 | CommGetData->DataBuffer = (PHYSICAL_ADDRESS)(UINTN)Buffer;\r | |
161 | CommGetData->DataOffset = 0;\r | |
162 | while (CommGetData->DataOffset < mSmiHandlerProfileDatabaseSize) {\r | |
163 | Offset = (UINTN)CommGetData->DataOffset;\r | |
164 | if (Size <= (mSmiHandlerProfileDatabaseSize - CommGetData->DataOffset)) {\r | |
165 | CommGetData->DataSize = (UINT64)Size;\r | |
166 | } else {\r | |
167 | CommGetData->DataSize = (UINT64)(mSmiHandlerProfileDatabaseSize - CommGetData->DataOffset);\r | |
168 | }\r | |
1436aea4 MK |
169 | \r |
170 | Status = SmmCommunication->Communicate (SmmCommunication, CommBuffer, &CommSize);\r | |
171 | ASSERT_EFI_ERROR (Status);\r | |
216b942d JY |
172 | \r |
173 | if (CommGetData->Header.ReturnStatus != 0) {\r | |
1436aea4 | 174 | FreePool (mSmiHandlerProfileDatabase);\r |
216b942d | 175 | mSmiHandlerProfileDatabase = NULL;\r |
1436aea4 MK |
176 | Print (L"SmiHandlerProfile: GetData - 0x%x\n", CommGetData->Header.ReturnStatus);\r |
177 | return;\r | |
216b942d | 178 | }\r |
1436aea4 MK |
179 | \r |
180 | CopyMem ((UINT8 *)mSmiHandlerProfileDatabase + Offset, (VOID *)(UINTN)CommGetData->DataBuffer, (UINTN)CommGetData->DataSize);\r | |
216b942d JY |
181 | }\r |
182 | \r | |
183 | DEBUG ((DEBUG_INFO, "SmiHandlerProfileSize - 0x%x\n", mSmiHandlerProfileDatabaseSize));\r | |
184 | \r | |
1436aea4 | 185 | return;\r |
216b942d JY |
186 | }\r |
187 | \r | |
188 | /**\r | |
189 | Get the file name portion of the Pdb File Name.\r | |
190 | \r | |
191 | The portion of the Pdb File Name between the last backslash and\r | |
192 | either a following period or the end of the string is copied into\r | |
193 | AsciiBuffer. The name is truncated, if necessary, to ensure that\r | |
194 | AsciiBuffer is not overrun.\r | |
195 | \r | |
196 | @param[in] PdbFileName Pdb file name.\r | |
197 | @param[out] AsciiBuffer The resultant Ascii File Name.\r | |
198 | \r | |
199 | **/\r | |
200 | VOID\r | |
201 | GetShortPdbFileName (\r | |
1436aea4 MK |
202 | IN CHAR8 *PdbFileName,\r |
203 | OUT CHAR8 *AsciiBuffer\r | |
216b942d JY |
204 | )\r |
205 | {\r | |
1436aea4 MK |
206 | UINTN IndexPdb; // Current work location within a Pdb string.\r |
207 | UINTN IndexBuffer; // Current work location within a Buffer string.\r | |
208 | UINTN StartIndex;\r | |
209 | UINTN EndIndex;\r | |
216b942d JY |
210 | \r |
211 | ZeroMem (AsciiBuffer, PROFILE_NAME_STRING_LENGTH + 1);\r | |
212 | \r | |
213 | if (PdbFileName == NULL) {\r | |
214 | AsciiStrnCpyS (AsciiBuffer, PROFILE_NAME_STRING_LENGTH + 1, " ", 1);\r | |
215 | } else {\r | |
216 | StartIndex = 0;\r | |
1436aea4 MK |
217 | for (EndIndex = 0; PdbFileName[EndIndex] != 0; EndIndex++) {\r |
218 | }\r | |
219 | \r | |
216b942d JY |
220 | for (IndexPdb = 0; PdbFileName[IndexPdb] != 0; IndexPdb++) {\r |
221 | if ((PdbFileName[IndexPdb] == '\\') || (PdbFileName[IndexPdb] == '/')) {\r | |
222 | StartIndex = IndexPdb + 1;\r | |
223 | }\r | |
224 | \r | |
225 | if (PdbFileName[IndexPdb] == '.') {\r | |
226 | EndIndex = IndexPdb;\r | |
227 | }\r | |
228 | }\r | |
229 | \r | |
230 | IndexBuffer = 0;\r | |
231 | for (IndexPdb = StartIndex; IndexPdb < EndIndex; IndexPdb++) {\r | |
232 | AsciiBuffer[IndexBuffer] = PdbFileName[IndexPdb];\r | |
233 | IndexBuffer++;\r | |
234 | if (IndexBuffer >= PROFILE_NAME_STRING_LENGTH) {\r | |
235 | AsciiBuffer[PROFILE_NAME_STRING_LENGTH] = 0;\r | |
236 | break;\r | |
237 | }\r | |
238 | }\r | |
239 | }\r | |
240 | }\r | |
241 | \r | |
242 | /**\r | |
243 | Get a human readable name for an image.\r | |
244 | The following methods will be tried orderly:\r | |
245 | 1. Image PDB\r | |
246 | 2. FFS UI section\r | |
247 | 3. Image GUID\r | |
248 | \r | |
c325e415 | 249 | @param[in] ImageStruct Point to the image structure.\r |
216b942d JY |
250 | \r |
251 | @return The resulting Ascii name string is stored in the mNameString global array.\r | |
252 | \r | |
253 | **/\r | |
254 | CHAR8 *\r | |
255 | GetDriverNameString (\r | |
256 | IN SMM_CORE_IMAGE_DATABASE_STRUCTURE *ImageStruct\r | |
257 | )\r | |
258 | {\r | |
1436aea4 MK |
259 | EFI_STATUS Status;\r |
260 | CHAR16 *NameString;\r | |
261 | UINTN StringSize;\r | |
216b942d JY |
262 | \r |
263 | if (ImageStruct == NULL) {\r | |
264 | return "???";\r | |
265 | }\r | |
266 | \r | |
267 | //\r | |
268 | // Method 1: Get the name string from image PDB\r | |
269 | //\r | |
8ced192d | 270 | if (ImageStruct->PdbStringOffset != 0) {\r |
1436aea4 | 271 | GetShortPdbFileName ((CHAR8 *)((UINTN)ImageStruct + ImageStruct->PdbStringOffset), mNameString);\r |
216b942d JY |
272 | return mNameString;\r |
273 | }\r | |
274 | \r | |
275 | if (!IsZeroGuid (&ImageStruct->FileGuid)) {\r | |
276 | //\r | |
277 | // Try to get the image's FFS UI section by image GUID\r | |
278 | //\r | |
279 | NameString = NULL;\r | |
280 | StringSize = 0;\r | |
1436aea4 MK |
281 | Status = GetSectionFromAnyFv (\r |
282 | &ImageStruct->FileGuid,\r | |
283 | EFI_SECTION_USER_INTERFACE,\r | |
284 | 0,\r | |
285 | (VOID **)&NameString,\r | |
286 | &StringSize\r | |
287 | );\r | |
216b942d JY |
288 | if (!EFI_ERROR (Status)) {\r |
289 | //\r | |
290 | // Method 2: Get the name string from FFS UI section\r | |
291 | //\r | |
292 | if (StrLen (NameString) > PROFILE_NAME_STRING_LENGTH) {\r | |
293 | NameString[PROFILE_NAME_STRING_LENGTH] = 0;\r | |
294 | }\r | |
1436aea4 | 295 | \r |
216b942d JY |
296 | UnicodeStrToAsciiStrS (NameString, mNameString, sizeof (mNameString));\r |
297 | FreePool (NameString);\r | |
298 | return mNameString;\r | |
299 | }\r | |
300 | }\r | |
301 | \r | |
302 | //\r | |
303 | // Method 3: Get the name string from image GUID\r | |
304 | //\r | |
305 | AsciiSPrint (mNameString, sizeof (mNameString), "%g", &ImageStruct->FileGuid);\r | |
306 | return mNameString;\r | |
307 | }\r | |
308 | \r | |
309 | /**\r | |
310 | Get image structure from reference index.\r | |
311 | \r | |
312 | @param ImageRef the image reference index\r | |
313 | \r | |
314 | @return image structure\r | |
315 | **/\r | |
316 | SMM_CORE_IMAGE_DATABASE_STRUCTURE *\r | |
317 | GetImageFromRef (\r | |
1436aea4 | 318 | IN UINTN ImageRef\r |
216b942d JY |
319 | )\r |
320 | {\r | |
321 | SMM_CORE_IMAGE_DATABASE_STRUCTURE *ImageStruct;\r | |
322 | \r | |
323 | ImageStruct = (VOID *)mSmiHandlerProfileDatabase;\r | |
324 | while ((UINTN)ImageStruct < (UINTN)mSmiHandlerProfileDatabase + mSmiHandlerProfileDatabaseSize) {\r | |
325 | if (ImageStruct->Header.Signature == SMM_CORE_IMAGE_DATABASE_SIGNATURE) {\r | |
326 | if (ImageStruct->ImageRef == ImageRef) {\r | |
327 | return ImageStruct;\r | |
328 | }\r | |
329 | }\r | |
1436aea4 | 330 | \r |
216b942d JY |
331 | ImageStruct = (VOID *)((UINTN)ImageStruct + ImageStruct->Header.Length);\r |
332 | }\r | |
333 | \r | |
334 | return NULL;\r | |
335 | }\r | |
336 | \r | |
337 | /**\r | |
338 | Dump SMM loaded image information.\r | |
339 | **/\r | |
340 | VOID\r | |
1436aea4 | 341 | DumpSmmLoadedImage (\r |
216b942d JY |
342 | VOID\r |
343 | )\r | |
344 | {\r | |
345 | SMM_CORE_IMAGE_DATABASE_STRUCTURE *ImageStruct;\r | |
346 | CHAR8 *PdbString;\r | |
347 | CHAR8 *NameString;\r | |
348 | \r | |
349 | ImageStruct = (VOID *)mSmiHandlerProfileDatabase;\r | |
350 | while ((UINTN)ImageStruct < (UINTN)mSmiHandlerProfileDatabase + mSmiHandlerProfileDatabaseSize) {\r | |
351 | if (ImageStruct->Header.Signature == SMM_CORE_IMAGE_DATABASE_SIGNATURE) {\r | |
352 | NameString = GetDriverNameString (ImageStruct);\r | |
1436aea4 MK |
353 | Print (L" <Image Name=\"%a\"", NameString);\r |
354 | Print (L" Base=\"0x%lx\" Size=\"0x%lx\"", ImageStruct->ImageBase, ImageStruct->ImageSize);\r | |
216b942d | 355 | if (ImageStruct->EntryPoint != 0) {\r |
1436aea4 | 356 | Print (L" EntryPoint=\"0x%lx\"", ImageStruct->EntryPoint);\r |
216b942d | 357 | }\r |
1436aea4 MK |
358 | \r |
359 | Print (L" FvFile=\"%g\"", &ImageStruct->FileGuid);\r | |
360 | Print (L" RefId=\"0x%x\"", ImageStruct->ImageRef);\r | |
361 | Print (L">\n");\r | |
8ced192d SZ |
362 | if (ImageStruct->PdbStringOffset != 0) {\r |
363 | PdbString = (CHAR8 *)((UINTN)ImageStruct + ImageStruct->PdbStringOffset);\r | |
1436aea4 | 364 | Print (L" <Pdb>%a</Pdb>\n", PdbString);\r |
8ced192d | 365 | }\r |
1436aea4 MK |
366 | \r |
367 | Print (L" </Image>\n");\r | |
216b942d JY |
368 | }\r |
369 | \r | |
370 | ImageStruct = (VOID *)((UINTN)ImageStruct + ImageStruct->Header.Length);\r | |
371 | }\r | |
372 | \r | |
373 | return;\r | |
374 | }\r | |
375 | \r | |
1436aea4 | 376 | CHAR8 *mSxTypeString[] = {\r |
216b942d JY |
377 | "SxS0",\r |
378 | "SxS1",\r | |
379 | "SxS2",\r | |
380 | "SxS3",\r | |
381 | "SxS4",\r | |
382 | "SxS5",\r | |
383 | };\r | |
384 | \r | |
385 | /**\r | |
386 | Convert SxType to a string.\r | |
387 | \r | |
388 | @param Type SxType\r | |
389 | \r | |
390 | @return SxType string\r | |
391 | **/\r | |
392 | CHAR8 *\r | |
393 | SxTypeToString (\r | |
394 | IN EFI_SLEEP_TYPE Type\r | |
395 | )\r | |
396 | {\r | |
1436aea4 | 397 | if ((Type >= 0) && (Type < ARRAY_SIZE (mSxTypeString))) {\r |
216b942d JY |
398 | return mSxTypeString[Type];\r |
399 | } else {\r | |
1436aea4 | 400 | AsciiSPrint (mNameString, sizeof (mNameString), "0x%x", Type);\r |
216b942d JY |
401 | return mNameString;\r |
402 | }\r | |
403 | }\r | |
404 | \r | |
1436aea4 | 405 | CHAR8 *mSxPhaseString[] = {\r |
216b942d JY |
406 | "SxEntry",\r |
407 | "SxExit",\r | |
408 | };\r | |
409 | \r | |
410 | /**\r | |
411 | Convert SxPhase to a string.\r | |
412 | \r | |
413 | @param Phase SxPhase\r | |
414 | \r | |
415 | @return SxPhase string\r | |
416 | **/\r | |
417 | CHAR8 *\r | |
418 | SxPhaseToString (\r | |
1436aea4 | 419 | IN EFI_SLEEP_PHASE Phase\r |
216b942d JY |
420 | )\r |
421 | {\r | |
1436aea4 | 422 | if ((Phase >= 0) && (Phase < ARRAY_SIZE (mSxPhaseString))) {\r |
216b942d JY |
423 | return mSxPhaseString[Phase];\r |
424 | } else {\r | |
1436aea4 | 425 | AsciiSPrint (mNameString, sizeof (mNameString), "0x%x", Phase);\r |
216b942d JY |
426 | return mNameString;\r |
427 | }\r | |
428 | }\r | |
429 | \r | |
1436aea4 | 430 | CHAR8 *mPowerButtonPhaseString[] = {\r |
216b942d JY |
431 | "PowerButtonEntry",\r |
432 | "PowerButtonExit",\r | |
433 | };\r | |
434 | \r | |
435 | /**\r | |
436 | Convert PowerButtonPhase to a string.\r | |
437 | \r | |
438 | @param Phase PowerButtonPhase\r | |
439 | \r | |
440 | @return PowerButtonPhase string\r | |
441 | **/\r | |
442 | CHAR8 *\r | |
443 | PowerButtonPhaseToString (\r | |
444 | IN EFI_POWER_BUTTON_PHASE Phase\r | |
445 | )\r | |
446 | {\r | |
1436aea4 | 447 | if ((Phase >= 0) && (Phase < ARRAY_SIZE (mPowerButtonPhaseString))) {\r |
216b942d JY |
448 | return mPowerButtonPhaseString[Phase];\r |
449 | } else {\r | |
1436aea4 | 450 | AsciiSPrint (mNameString, sizeof (mNameString), "0x%x", Phase);\r |
216b942d JY |
451 | return mNameString;\r |
452 | }\r | |
453 | }\r | |
454 | \r | |
1436aea4 | 455 | CHAR8 *mStandbyButtonPhaseString[] = {\r |
216b942d JY |
456 | "StandbyButtonEntry",\r |
457 | "StandbyButtonExit",\r | |
458 | };\r | |
459 | \r | |
460 | /**\r | |
461 | Convert StandbyButtonPhase to a string.\r | |
462 | \r | |
463 | @param Phase StandbyButtonPhase\r | |
464 | \r | |
465 | @return StandbyButtonPhase string\r | |
466 | **/\r | |
467 | CHAR8 *\r | |
468 | StandbyButtonPhaseToString (\r | |
469 | IN EFI_STANDBY_BUTTON_PHASE Phase\r | |
470 | )\r | |
471 | {\r | |
1436aea4 | 472 | if ((Phase >= 0) && (Phase < ARRAY_SIZE (mStandbyButtonPhaseString))) {\r |
216b942d JY |
473 | return mStandbyButtonPhaseString[Phase];\r |
474 | } else {\r | |
1436aea4 | 475 | AsciiSPrint (mNameString, sizeof (mNameString), "0x%x", Phase);\r |
216b942d JY |
476 | return mNameString;\r |
477 | }\r | |
478 | }\r | |
479 | \r | |
1436aea4 | 480 | CHAR8 *mIoTrapTypeString[] = {\r |
216b942d JY |
481 | "WriteTrap",\r |
482 | "ReadTrap",\r | |
483 | "ReadWriteTrap",\r | |
484 | };\r | |
485 | \r | |
486 | /**\r | |
487 | Convert IoTrapType to a string.\r | |
488 | \r | |
489 | @param Type IoTrapType\r | |
490 | \r | |
491 | @return IoTrapType string\r | |
492 | **/\r | |
493 | CHAR8 *\r | |
494 | IoTrapTypeToString (\r | |
495 | IN EFI_SMM_IO_TRAP_DISPATCH_TYPE Type\r | |
496 | )\r | |
497 | {\r | |
1436aea4 | 498 | if ((Type >= 0) && (Type < ARRAY_SIZE (mIoTrapTypeString))) {\r |
216b942d JY |
499 | return mIoTrapTypeString[Type];\r |
500 | } else {\r | |
1436aea4 | 501 | AsciiSPrint (mNameString, sizeof (mNameString), "0x%x", Type);\r |
216b942d JY |
502 | return mNameString;\r |
503 | }\r | |
504 | }\r | |
505 | \r | |
1436aea4 | 506 | CHAR8 *mUsbTypeString[] = {\r |
216b942d JY |
507 | "UsbLegacy",\r |
508 | "UsbWake",\r | |
509 | };\r | |
510 | \r | |
511 | /**\r | |
512 | Convert UsbType to a string.\r | |
513 | \r | |
514 | @param Type UsbType\r | |
515 | \r | |
516 | @return UsbType string\r | |
517 | **/\r | |
518 | CHAR8 *\r | |
519 | UsbTypeToString (\r | |
1436aea4 | 520 | IN EFI_USB_SMI_TYPE Type\r |
216b942d JY |
521 | )\r |
522 | {\r | |
1436aea4 | 523 | if ((Type >= 0) && (Type < ARRAY_SIZE (mUsbTypeString))) {\r |
216b942d JY |
524 | return mUsbTypeString[Type];\r |
525 | } else {\r | |
1436aea4 | 526 | AsciiSPrint (mNameString, sizeof (mNameString), "0x%x", Type);\r |
216b942d JY |
527 | return mNameString;\r |
528 | }\r | |
529 | }\r | |
530 | \r | |
531 | /**\r | |
532 | Dump SMI child context.\r | |
533 | \r | |
534 | @param HandlerType the handler type\r | |
535 | @param Context the handler context\r | |
536 | @param ContextSize the handler context size\r | |
537 | **/\r | |
538 | VOID\r | |
539 | DumpSmiChildContext (\r | |
1436aea4 MK |
540 | IN EFI_GUID *HandlerType,\r |
541 | IN VOID *Context,\r | |
542 | IN UINTN ContextSize\r | |
216b942d JY |
543 | )\r |
544 | {\r | |
1436aea4 | 545 | CHAR16 *Str;\r |
fb1c81a1 | 546 | \r |
216b942d | 547 | if (CompareGuid (HandlerType, &gEfiSmmSwDispatch2ProtocolGuid)) {\r |
1436aea4 | 548 | Print (L" SwSmi=\"0x%lx\"", ((SMI_HANDLER_PROFILE_SW_REGISTER_CONTEXT *)Context)->SwSmiInputValue);\r |
216b942d | 549 | } else if (CompareGuid (HandlerType, &gEfiSmmSxDispatch2ProtocolGuid)) {\r |
1436aea4 MK |
550 | Print (L" SxType=\"%a\"", SxTypeToString (((EFI_SMM_SX_REGISTER_CONTEXT *)Context)->Type));\r |
551 | Print (L" SxPhase=\"%a\"", SxPhaseToString (((EFI_SMM_SX_REGISTER_CONTEXT *)Context)->Phase));\r | |
216b942d | 552 | } else if (CompareGuid (HandlerType, &gEfiSmmPowerButtonDispatch2ProtocolGuid)) {\r |
1436aea4 | 553 | Print (L" PowerButtonPhase=\"%a\"", PowerButtonPhaseToString (((EFI_SMM_POWER_BUTTON_REGISTER_CONTEXT *)Context)->Phase));\r |
216b942d | 554 | } else if (CompareGuid (HandlerType, &gEfiSmmStandbyButtonDispatch2ProtocolGuid)) {\r |
1436aea4 | 555 | Print (L" StandbyButtonPhase=\"%a\"", StandbyButtonPhaseToString (((EFI_SMM_STANDBY_BUTTON_REGISTER_CONTEXT *)Context)->Phase));\r |
216b942d | 556 | } else if (CompareGuid (HandlerType, &gEfiSmmPeriodicTimerDispatch2ProtocolGuid)) {\r |
1436aea4 MK |
557 | Print (L" PeriodicTimerPeriod=\"%ld\"", ((EFI_SMM_PERIODIC_TIMER_REGISTER_CONTEXT *)Context)->Period);\r |
558 | Print (L" PeriodicTimerSmiTickInterval=\"%ld\"", ((EFI_SMM_PERIODIC_TIMER_REGISTER_CONTEXT *)Context)->SmiTickInterval);\r | |
216b942d | 559 | } else if (CompareGuid (HandlerType, &gEfiSmmGpiDispatch2ProtocolGuid)) {\r |
1436aea4 | 560 | Print (L" GpiNum=\"0x%lx\"", ((EFI_SMM_GPI_REGISTER_CONTEXT *)Context)->GpiNum);\r |
216b942d | 561 | } else if (CompareGuid (HandlerType, &gEfiSmmIoTrapDispatch2ProtocolGuid)) {\r |
1436aea4 MK |
562 | Print (L" IoTrapAddress=\"0x%x\"", ((EFI_SMM_IO_TRAP_REGISTER_CONTEXT *)Context)->Address);\r |
563 | Print (L" IoTrapLength=\"0x%x\"", ((EFI_SMM_IO_TRAP_REGISTER_CONTEXT *)Context)->Length);\r | |
564 | Print (L" IoTrapType=\"%a\"", IoTrapTypeToString (((EFI_SMM_IO_TRAP_REGISTER_CONTEXT *)Context)->Type));\r | |
216b942d | 565 | } else if (CompareGuid (HandlerType, &gEfiSmmUsbDispatch2ProtocolGuid)) {\r |
1436aea4 MK |
566 | Print (L" UsbType=\"0x%x\"", UsbTypeToString (((SMI_HANDLER_PROFILE_USB_REGISTER_CONTEXT *)Context)->Type));\r |
567 | Str = ConvertDevicePathToText ((EFI_DEVICE_PATH_PROTOCOL *)(((SMI_HANDLER_PROFILE_USB_REGISTER_CONTEXT *)Context) + 1), TRUE, TRUE);\r | |
568 | Print (L" UsbDevicePath=\"%s\"", Str);\r | |
fb1c81a1 SZ |
569 | if (Str != NULL) {\r |
570 | FreePool (Str);\r | |
571 | }\r | |
216b942d | 572 | } else {\r |
1436aea4 | 573 | Print (L" Context=\"");\r |
216b942d | 574 | InternalDumpData (Context, ContextSize);\r |
1436aea4 | 575 | Print (L"\"");\r |
216b942d JY |
576 | }\r |
577 | }\r | |
578 | \r | |
579 | /**\r | |
580 | Dump SMI handler in HandlerCategory.\r | |
581 | \r | |
582 | @param HandlerCategory SMI handler category\r | |
583 | **/\r | |
584 | VOID\r | |
1436aea4 MK |
585 | DumpSmiHandler (\r |
586 | IN UINT32 HandlerCategory\r | |
216b942d JY |
587 | )\r |
588 | {\r | |
589 | SMM_CORE_SMI_DATABASE_STRUCTURE *SmiStruct;\r | |
590 | SMM_CORE_SMI_HANDLER_STRUCTURE *SmiHandlerStruct;\r | |
591 | UINTN Index;\r | |
592 | SMM_CORE_IMAGE_DATABASE_STRUCTURE *ImageStruct;\r | |
593 | CHAR8 *NameString;\r | |
594 | \r | |
595 | SmiStruct = (VOID *)mSmiHandlerProfileDatabase;\r | |
596 | while ((UINTN)SmiStruct < (UINTN)mSmiHandlerProfileDatabase + mSmiHandlerProfileDatabaseSize) {\r | |
597 | if ((SmiStruct->Header.Signature == SMM_CORE_SMI_DATABASE_SIGNATURE) && (SmiStruct->HandlerCategory == HandlerCategory)) {\r | |
598 | SmiHandlerStruct = (VOID *)(SmiStruct + 1);\r | |
1436aea4 | 599 | Print (L" <SmiEntry");\r |
216b942d | 600 | if (!IsZeroGuid (&SmiStruct->HandlerType)) {\r |
1436aea4 | 601 | Print (L" HandlerType=\"%g\"", &SmiStruct->HandlerType);\r |
216b942d | 602 | }\r |
1436aea4 MK |
603 | \r |
604 | Print (L">\n");\r | |
216b942d | 605 | for (Index = 0; Index < SmiStruct->HandlerCount; Index++) {\r |
1436aea4 | 606 | Print (L" <SmiHandler");\r |
216b942d JY |
607 | if (SmiHandlerStruct->ContextBufferSize != 0) {\r |
608 | DumpSmiChildContext (&SmiStruct->HandlerType, (UINT8 *)SmiHandlerStruct + SmiHandlerStruct->ContextBufferOffset, SmiHandlerStruct->ContextBufferSize);\r | |
609 | }\r | |
1436aea4 MK |
610 | \r |
611 | Print (L">\n");\r | |
612 | ImageStruct = GetImageFromRef ((UINTN)SmiHandlerStruct->ImageRef);\r | |
613 | NameString = GetDriverNameString (ImageStruct);\r | |
614 | Print (L" <Module RefId=\"0x%x\" Name=\"%a\">\n", SmiHandlerStruct->ImageRef, NameString);\r | |
216b942d | 615 | if ((ImageStruct != NULL) && (ImageStruct->PdbStringOffset != 0)) {\r |
1436aea4 | 616 | Print (L" <Pdb>%a</Pdb>\n", (UINT8 *)ImageStruct + ImageStruct->PdbStringOffset);\r |
216b942d | 617 | }\r |
1436aea4 MK |
618 | \r |
619 | Print (L" </Module>\n");\r | |
620 | Print (L" <Handler Address=\"0x%lx\">\n", SmiHandlerStruct->Handler);\r | |
216b942d | 621 | if (ImageStruct != NULL) {\r |
1436aea4 | 622 | Print (L" <RVA>0x%x</RVA>\n", (UINTN)(SmiHandlerStruct->Handler - ImageStruct->ImageBase));\r |
216b942d | 623 | }\r |
1436aea4 MK |
624 | \r |
625 | Print (L" </Handler>\n", SmiHandlerStruct->Handler);\r | |
626 | Print (L" <Caller Address=\"0x%lx\">\n", SmiHandlerStruct->CallerAddr);\r | |
216b942d | 627 | if (ImageStruct != NULL) {\r |
1436aea4 | 628 | Print (L" <RVA>0x%x</RVA>\n", (UINTN)(SmiHandlerStruct->CallerAddr - ImageStruct->ImageBase));\r |
216b942d | 629 | }\r |
1436aea4 MK |
630 | \r |
631 | Print (L" </Caller>\n", SmiHandlerStruct->Handler);\r | |
216b942d | 632 | SmiHandlerStruct = (VOID *)((UINTN)SmiHandlerStruct + SmiHandlerStruct->Length);\r |
1436aea4 | 633 | Print (L" </SmiHandler>\n");\r |
216b942d | 634 | }\r |
1436aea4 MK |
635 | \r |
636 | Print (L" </SmiEntry>\n");\r | |
216b942d | 637 | }\r |
1436aea4 | 638 | \r |
216b942d JY |
639 | SmiStruct = (VOID *)((UINTN)SmiStruct + SmiStruct->Header.Length);\r |
640 | }\r | |
641 | \r | |
642 | return;\r | |
643 | }\r | |
644 | \r | |
645 | /**\r | |
646 | The Entry Point for SMI handler profile info application.\r | |
647 | \r | |
648 | @param ImageHandle The firmware allocated handle for the EFI image.\r | |
649 | @param SystemTable A pointer to the EFI System Table.\r | |
650 | \r | |
651 | @retval EFI_SUCCESS The entry point is executed successfully.\r | |
652 | @retval Other Some error occurred when executing this entry point.\r | |
653 | **/\r | |
654 | EFI_STATUS\r | |
655 | EFIAPI\r | |
656 | SmiHandlerProfileInfoEntrypoint (\r | |
1436aea4 MK |
657 | IN EFI_HANDLE ImageHandle,\r |
658 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
216b942d JY |
659 | )\r |
660 | {\r | |
1436aea4 | 661 | GetSmiHandlerProfileDatabase ();\r |
216b942d JY |
662 | \r |
663 | if (mSmiHandlerProfileDatabase == NULL) {\r | |
664 | return EFI_SUCCESS;\r | |
665 | }\r | |
666 | \r | |
667 | //\r | |
668 | // Dump all image\r | |
669 | //\r | |
1436aea4 MK |
670 | Print (L"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");\r |
671 | Print (L"<SmiHandlerProfile>\n");\r | |
672 | Print (L"<ImageDatabase>\n");\r | |
673 | Print (L" <!-- SMM image loaded -->\n");\r | |
674 | DumpSmmLoadedImage ();\r | |
675 | Print (L"</ImageDatabase>\n\n");\r | |
216b942d JY |
676 | \r |
677 | //\r | |
678 | // Dump SMI Handler\r | |
679 | //\r | |
1436aea4 MK |
680 | Print (L"<SmiHandlerDatabase>\n");\r |
681 | Print (L" <!-- SMI Handler registered -->\n\n");\r | |
682 | Print (L" <SmiHandlerCategory Name=\"RootSmi\">\n");\r | |
683 | Print (L" <!-- The root SMI Handler registered by SmmCore -->\n");\r | |
684 | DumpSmiHandler (SmmCoreSmiHandlerCategoryRootHandler);\r | |
685 | Print (L" </SmiHandlerCategory>\n\n");\r | |
686 | \r | |
687 | Print (L" <SmiHandlerCategory Name=\"GuidSmi\">\n");\r | |
688 | Print (L" <!-- The GUID SMI Handler registered by SmmCore -->\n");\r | |
689 | DumpSmiHandler (SmmCoreSmiHandlerCategoryGuidHandler);\r | |
690 | Print (L" </SmiHandlerCategory>\n\n");\r | |
691 | \r | |
692 | Print (L" <SmiHandlerCategory Name=\"HardwareSmi\">\n");\r | |
693 | Print (L" <!-- The hardware SMI Handler registered by SmmChildDispatcher -->\n");\r | |
694 | DumpSmiHandler (SmmCoreSmiHandlerCategoryHardwareHandler);\r | |
695 | Print (L" </SmiHandlerCategory>\n\n");\r | |
696 | \r | |
697 | Print (L"</SmiHandlerDatabase>\n");\r | |
698 | Print (L"</SmiHandlerProfile>\n");\r | |
216b942d JY |
699 | \r |
700 | if (mSmiHandlerProfileDatabase != NULL) {\r | |
1436aea4 | 701 | FreePool (mSmiHandlerProfileDatabase);\r |
216b942d JY |
702 | }\r |
703 | \r | |
704 | return EFI_SUCCESS;\r | |
705 | }\r |