25#define PROFILE_NAME_STRING_LENGTH 64
26CHAR8 mNameString[PROFILE_NAME_STRING_LENGTH + 1];
28VOID *mSmiHandlerProfileDatabase;
29UINTN mSmiHandlerProfileDatabaseSize;
45 for (Index = 0; Index < Size; Index++) {
47 if ((Index + 1) != Size) {
68 UINTN MinimalSizeNeeded;
76 Status =
gBS->LocateProtocol (&gEfiSmmCommunicationProtocolGuid,
NULL, (VOID **)&SmmCommunication);
77 if (EFI_ERROR (Status)) {
78 Print (L
"SmiHandlerProfile: Locate SmmCommunication protocol - %r\n", Status);
82 MinimalSizeNeeded = EFI_PAGE_SIZE;
85 &gEdkiiPiSmmCommunicationRegionTableGuid,
86 (VOID **)&PiSmmCommunicationRegionTable
88 if (EFI_ERROR (Status)) {
89 Print (L
"SmiHandlerProfile: Get PiSmmCommunicationRegionTable - %r\n", Status);
93 ASSERT (PiSmmCommunicationRegionTable !=
NULL);
96 for (Index = 0; Index < PiSmmCommunicationRegionTable->NumberOfEntries; Index++) {
99 if (Size >= MinimalSizeNeeded) {
107 ASSERT (Index < PiSmmCommunicationRegionTable->NumberOfEntries);
108 CommBuffer = (UINT8 *)(
UINTN)Entry->PhysicalStart;
114 CopyMem (&CommHeader->
HeaderGuid, &gSmiHandlerProfileGuid, sizeof (gSmiHandlerProfileGuid));
118 CommGetInfo->Header.Command = SMI_HANDLER_PROFILE_COMMAND_GET_INFO;
119 CommGetInfo->Header.DataLength =
sizeof (*CommGetInfo);
120 CommGetInfo->Header.ReturnStatus = (UINT64)-1;
121 CommGetInfo->DataSize = 0;
124 Status = SmmCommunication->Communicate (SmmCommunication, CommBuffer, &CommSize);
125 if (EFI_ERROR (Status)) {
126 Print (L
"SmiHandlerProfile: SmmCommunication - %r\n", Status);
130 if (CommGetInfo->Header.ReturnStatus != 0) {
131 Print (L
"SmiHandlerProfile: GetInfo - 0x%0x\n", CommGetInfo->Header.ReturnStatus);
135 mSmiHandlerProfileDatabaseSize = (
UINTN)CommGetInfo->DataSize;
140 mSmiHandlerProfileDatabase =
AllocateZeroPool (mSmiHandlerProfileDatabaseSize);
141 if (mSmiHandlerProfileDatabase ==
NULL) {
142 Status = EFI_OUT_OF_RESOURCES;
143 Print (L
"SmiHandlerProfile: AllocateZeroPool (0x%x) for dump buffer - %r\n", mSmiHandlerProfileDatabaseSize, Status);
148 CopyMem (&CommHeader->
HeaderGuid, &gSmiHandlerProfileGuid, sizeof (gSmiHandlerProfileGuid));
152 CommGetData->Header.Command = SMI_HANDLER_PROFILE_COMMAND_GET_DATA_BY_OFFSET;
153 CommGetData->Header.DataLength =
sizeof (*CommGetData);
154 CommGetData->Header.ReturnStatus = (UINT64)-1;
157 Buffer = (UINT8 *)CommHeader + CommSize;
160 CommGetData->DataBuffer = (PHYSICAL_ADDRESS)(
UINTN)Buffer;
161 CommGetData->DataOffset = 0;
162 while (CommGetData->DataOffset < mSmiHandlerProfileDatabaseSize) {
163 Offset = (
UINTN)CommGetData->DataOffset;
164 if (Size <= (mSmiHandlerProfileDatabaseSize - CommGetData->DataOffset)) {
165 CommGetData->DataSize = (UINT64)Size;
167 CommGetData->DataSize = (UINT64)(mSmiHandlerProfileDatabaseSize - CommGetData->DataOffset);
170 Status = SmmCommunication->Communicate (SmmCommunication, CommBuffer, &CommSize);
173 if (CommGetData->Header.ReturnStatus != 0) {
174 FreePool (mSmiHandlerProfileDatabase);
175 mSmiHandlerProfileDatabase =
NULL;
176 Print (L
"SmiHandlerProfile: GetData - 0x%x\n", CommGetData->Header.ReturnStatus);
180 CopyMem ((UINT8 *)mSmiHandlerProfileDatabase + Offset, (VOID *)(
UINTN)CommGetData->DataBuffer, (
UINTN)CommGetData->DataSize);
183 DEBUG ((DEBUG_INFO,
"SmiHandlerProfileSize - 0x%x\n", mSmiHandlerProfileDatabaseSize));
202 IN CHAR8 *PdbFileName,
203 OUT CHAR8 *AsciiBuffer
211 ZeroMem (AsciiBuffer, PROFILE_NAME_STRING_LENGTH + 1);
213 if (PdbFileName ==
NULL) {
214 AsciiStrnCpyS (AsciiBuffer, PROFILE_NAME_STRING_LENGTH + 1,
" ", 1);
217 for (EndIndex = 0; PdbFileName[EndIndex] != 0; EndIndex++) {
220 for (IndexPdb = 0; PdbFileName[IndexPdb] != 0; IndexPdb++) {
221 if ((PdbFileName[IndexPdb] ==
'\\') || (PdbFileName[IndexPdb] ==
'/')) {
222 StartIndex = IndexPdb + 1;
225 if (PdbFileName[IndexPdb] ==
'.') {
231 for (IndexPdb = StartIndex; IndexPdb < EndIndex; IndexPdb++) {
232 AsciiBuffer[IndexBuffer] = PdbFileName[IndexPdb];
234 if (IndexBuffer >= PROFILE_NAME_STRING_LENGTH) {
235 AsciiBuffer[PROFILE_NAME_STRING_LENGTH] = 0;
263 if (ImageStruct ==
NULL) {
270 if (ImageStruct->PdbStringOffset != 0) {
282 &ImageStruct->FileGuid,
283 EFI_SECTION_USER_INTERFACE,
285 (VOID **)&NameString,
288 if (!EFI_ERROR (Status)) {
292 if (
StrLen (NameString) > PROFILE_NAME_STRING_LENGTH) {
293 NameString[PROFILE_NAME_STRING_LENGTH] = 0;
305 AsciiSPrint (mNameString,
sizeof (mNameString),
"%g", &ImageStruct->FileGuid);
323 ImageStruct = (VOID *)mSmiHandlerProfileDatabase;
324 while ((
UINTN)ImageStruct < (
UINTN)mSmiHandlerProfileDatabase + mSmiHandlerProfileDatabaseSize) {
325 if (ImageStruct->Header.Signature == SMM_CORE_IMAGE_DATABASE_SIGNATURE) {
326 if (ImageStruct->ImageRef == ImageRef) {
331 ImageStruct = (VOID *)((
UINTN)ImageStruct + ImageStruct->Header.Length);
349 ImageStruct = (VOID *)mSmiHandlerProfileDatabase;
350 while ((
UINTN)ImageStruct < (
UINTN)mSmiHandlerProfileDatabase + mSmiHandlerProfileDatabaseSize) {
351 if (ImageStruct->Header.Signature == SMM_CORE_IMAGE_DATABASE_SIGNATURE) {
353 Print (L
" <Image Name=\"%a\"", NameString);
354 Print (L
" Base=\"0x%lx\" Size=\"0x%lx\"", ImageStruct->ImageBase, ImageStruct->ImageSize);
355 if (ImageStruct->EntryPoint != 0) {
356 Print (L
" EntryPoint=\"0x%lx\"", ImageStruct->EntryPoint);
359 Print (L
" FvFile=\"%g\"", &ImageStruct->FileGuid);
360 Print (L
" RefId=\"0x%x\"", ImageStruct->ImageRef);
362 if (ImageStruct->PdbStringOffset != 0) {
363 PdbString = (CHAR8 *)((
UINTN)ImageStruct + ImageStruct->PdbStringOffset);
364 Print (L
" <Pdb>%a</Pdb>\n", PdbString);
367 Print (L
" </Image>\n");
370 ImageStruct = (VOID *)((
UINTN)ImageStruct + ImageStruct->Header.Length);
376CHAR8 *mSxTypeString[] = {
397 if ((Type >= 0) && (Type <
ARRAY_SIZE (mSxTypeString))) {
398 return mSxTypeString[Type];
400 AsciiSPrint (mNameString,
sizeof (mNameString),
"0x%x", Type);
405CHAR8 *mSxPhaseString[] = {
422 if ((Phase >= 0) && (Phase <
ARRAY_SIZE (mSxPhaseString))) {
423 return mSxPhaseString[Phase];
425 AsciiSPrint (mNameString,
sizeof (mNameString),
"0x%x", Phase);
430CHAR8 *mPowerButtonPhaseString[] = {
447 if ((Phase >= 0) && (Phase <
ARRAY_SIZE (mPowerButtonPhaseString))) {
448 return mPowerButtonPhaseString[Phase];
450 AsciiSPrint (mNameString,
sizeof (mNameString),
"0x%x", Phase);
455CHAR8 *mStandbyButtonPhaseString[] = {
456 "StandbyButtonEntry",
472 if ((Phase >= 0) && (Phase <
ARRAY_SIZE (mStandbyButtonPhaseString))) {
473 return mStandbyButtonPhaseString[Phase];
475 AsciiSPrint (mNameString,
sizeof (mNameString),
"0x%x", Phase);
480CHAR8 *mIoTrapTypeString[] = {
498 if ((Type >= 0) && (Type <
ARRAY_SIZE (mIoTrapTypeString))) {
499 return mIoTrapTypeString[Type];
501 AsciiSPrint (mNameString,
sizeof (mNameString),
"0x%x", Type);
506CHAR8 *mUsbTypeString[] = {
523 if ((Type >= 0) && (Type <
ARRAY_SIZE (mUsbTypeString))) {
524 return mUsbTypeString[Type];
526 AsciiSPrint (mNameString,
sizeof (mNameString),
"0x%x", Type);
547 if (
CompareGuid (HandlerType, &gEfiSmmSwDispatch2ProtocolGuid)) {
549 }
else if (
CompareGuid (HandlerType, &gEfiSmmSxDispatch2ProtocolGuid)) {
552 }
else if (
CompareGuid (HandlerType, &gEfiSmmPowerButtonDispatch2ProtocolGuid)) {
554 }
else if (
CompareGuid (HandlerType, &gEfiSmmStandbyButtonDispatch2ProtocolGuid)) {
556 }
else if (
CompareGuid (HandlerType, &gEfiSmmPeriodicTimerDispatch2ProtocolGuid)) {
559 }
else if (
CompareGuid (HandlerType, &gEfiSmmGpiDispatch2ProtocolGuid)) {
561 }
else if (
CompareGuid (HandlerType, &gEfiSmmIoTrapDispatch2ProtocolGuid)) {
565 }
else if (
CompareGuid (HandlerType, &gEfiSmmUsbDispatch2ProtocolGuid)) {
568 Print (L
" UsbDevicePath=\"%s\"", Str);
573 Print (L
" Context=\"");
586 IN UINT32 HandlerCategory
595 SmiStruct = (VOID *)mSmiHandlerProfileDatabase;
596 while ((
UINTN)SmiStruct < (
UINTN)mSmiHandlerProfileDatabase + mSmiHandlerProfileDatabaseSize) {
597 if ((SmiStruct->Header.Signature == SMM_CORE_SMI_DATABASE_SIGNATURE) && (SmiStruct->HandlerCategory == HandlerCategory)) {
598 SmiHandlerStruct = (VOID *)(SmiStruct + 1);
599 Print (L
" <SmiEntry");
601 Print (L
" HandlerType=\"%g\"", &SmiStruct->HandlerType);
605 for (Index = 0; Index < SmiStruct->HandlerCount; Index++) {
606 Print (L
" <SmiHandler");
607 if (SmiHandlerStruct->ContextBufferSize != 0) {
608 DumpSmiChildContext (&SmiStruct->HandlerType, (UINT8 *)SmiHandlerStruct + SmiHandlerStruct->ContextBufferOffset, SmiHandlerStruct->ContextBufferSize);
614 Print (L
" <Module RefId=\"0x%x\" Name=\"%a\">\n", SmiHandlerStruct->ImageRef, NameString);
615 if ((ImageStruct !=
NULL) && (ImageStruct->PdbStringOffset != 0)) {
616 Print (L
" <Pdb>%a</Pdb>\n", (UINT8 *)ImageStruct + ImageStruct->PdbStringOffset);
619 Print (L
" </Module>\n");
620 Print (L
" <Handler Address=\"0x%lx\">\n", SmiHandlerStruct->Handler);
621 if (ImageStruct !=
NULL) {
622 Print (L
" <RVA>0x%x</RVA>\n", (
UINTN)(SmiHandlerStruct->Handler - ImageStruct->ImageBase));
625 Print (L
" </Handler>\n", SmiHandlerStruct->Handler);
626 Print (L
" <Caller Address=\"0x%lx\">\n", SmiHandlerStruct->CallerAddr);
627 if (ImageStruct !=
NULL) {
628 Print (L
" <RVA>0x%x</RVA>\n", (
UINTN)(SmiHandlerStruct->CallerAddr - ImageStruct->ImageBase));
631 Print (L
" </Caller>\n", SmiHandlerStruct->Handler);
632 SmiHandlerStruct = (VOID *)((
UINTN)SmiHandlerStruct + SmiHandlerStruct->Length);
633 Print (L
" </SmiHandler>\n");
636 Print (L
" </SmiEntry>\n");
639 SmiStruct = (VOID *)((
UINTN)SmiStruct + SmiStruct->Header.Length);
663 if (mSmiHandlerProfileDatabase ==
NULL) {
670 Print (L
"<?xml version=\"1.0\" encoding=\"utf-16\"?>\n");
671 Print (L
"<SmiHandlerProfile>\n");
672 Print (L
"<ImageDatabase>\n");
673 Print (L
" <!-- SMM image loaded -->\n");
675 Print (L
"</ImageDatabase>\n\n");
680 Print (L
"<SmiHandlerDatabase>\n");
681 Print (L
" <!-- SMI Handler registered -->\n\n");
682 Print (L
" <SmiHandlerCategory Name=\"RootSmi\">\n");
683 Print (L
" <!-- The root SMI Handler registered by SmmCore -->\n");
685 Print (L
" </SmiHandlerCategory>\n\n");
687 Print (L
" <SmiHandlerCategory Name=\"GuidSmi\">\n");
688 Print (L
" <!-- The GUID SMI Handler registered by SmmCore -->\n");
690 Print (L
" </SmiHandlerCategory>\n\n");
692 Print (L
" <SmiHandlerCategory Name=\"HardwareSmi\">\n");
693 Print (L
" <!-- The hardware SMI Handler registered by SmmChildDispatcher -->\n");
695 Print (L
" </SmiHandlerCategory>\n\n");
697 Print (L
"</SmiHandlerDatabase>\n");
698 Print (L
"</SmiHandlerProfile>\n");
700 if (mSmiHandlerProfileDatabase !=
NULL) {
701 FreePool (mSmiHandlerProfileDatabase);
RETURN_STATUS EFIAPI AsciiStrnCpyS(OUT CHAR8 *Destination, IN UINTN DestMax, IN CONST CHAR8 *Source, IN UINTN Length)
RETURN_STATUS EFIAPI UnicodeStrToAsciiStrS(IN CONST CHAR16 *Source, OUT CHAR8 *Destination, IN UINTN DestMax)
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
BOOLEAN EFIAPI IsZeroGuid(IN CONST GUID *Guid)
CHAR16 *EFIAPI ConvertDevicePathToText(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN BOOLEAN DisplayOnly, IN BOOLEAN AllowShortcuts)
EFI_STATUS EFIAPI GetSectionFromAnyFv(IN CONST EFI_GUID *NameGuid, IN EFI_SECTION_TYPE SectionType, IN UINTN SectionInstance, OUT VOID **Buffer, OUT UINTN *Size)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
UINTN EFIAPI AsciiSPrint(OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString,...)
#define ARRAY_SIZE(Array)
#define OFFSET_OF(TYPE, Field)
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
EFI_MM_IO_TRAP_DISPATCH_TYPE
EFI_STATUS EFIAPI SmiHandlerProfileInfoEntrypoint(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
VOID InternalDumpData(IN UINT8 *Data, IN UINTN Size)
VOID DumpSmiHandler(IN UINT32 HandlerCategory)
SMM_CORE_IMAGE_DATABASE_STRUCTURE * GetImageFromRef(IN UINTN ImageRef)
CHAR8 * UsbTypeToString(IN EFI_USB_SMI_TYPE Type)
CHAR8 * SxTypeToString(IN EFI_SLEEP_TYPE Type)
VOID DumpSmmLoadedImage(VOID)
CHAR8 * StandbyButtonPhaseToString(IN EFI_STANDBY_BUTTON_PHASE Phase)
VOID GetSmiHandlerProfileDatabase(VOID)
CHAR8 * IoTrapTypeToString(IN EFI_SMM_IO_TRAP_DISPATCH_TYPE Type)
CHAR8 * PowerButtonPhaseToString(IN EFI_POWER_BUTTON_PHASE Phase)
CHAR8 * GetDriverNameString(IN SMM_CORE_IMAGE_DATABASE_STRUCTURE *ImageStruct)
VOID GetShortPdbFileName(IN CHAR8 *PdbFileName, OUT CHAR8 *AsciiBuffer)
VOID DumpSmiChildContext(IN EFI_GUID *HandlerType, IN VOID *Context, IN UINTN ContextSize)
CHAR8 * SxPhaseToString(IN EFI_SLEEP_PHASE Phase)
#define EFI_PAGES_TO_SIZE(Pages)
EFI_STATUS EFIAPI EfiGetSystemConfigurationTable(IN EFI_GUID *TableGuid, OUT VOID **Table)
UINTN EFIAPI Print(IN CONST CHAR16 *Format,...)