TianoCore EDK2 master
Loading...
Searching...
No Matches
SmiHandlerProfile.c
Go to the documentation of this file.
1
10#include <PiSmm.h>
11#include <Library/BaseLib.h>
16#include <Library/DebugLib.h>
17#include <Library/PrintLib.h>
18#include <Library/UefiLib.h>
22#include <Protocol/SmmAccess2.h>
25
27
28#include "PiSmmCore.h"
29
30#define GET_OCCUPIED_SIZE(ActualSize, Alignment) \
31 ((ActualSize) + (((Alignment) - ((ActualSize) & ((Alignment) - 1))) & ((Alignment) - 1)))
32
33typedef struct {
34 EFI_GUID FileGuid;
35 PHYSICAL_ADDRESS EntryPoint;
36 PHYSICAL_ADDRESS ImageBase;
37 UINT64 ImageSize;
38 UINT32 ImageRef;
39 UINT16 PdbStringSize;
40 CHAR8 *PdbString;
42
46VOID
48 VOID
49 );
50
54VOID
56 VOID
57 );
58
76RETURN_STATUS
78 IN VOID *Pe32Data,
79 OUT VOID **EntryPoint
80 );
81
82extern LIST_ENTRY mSmiEntryList;
83extern LIST_ENTRY mHardwareSmiEntryList;
84extern SMI_ENTRY mRootSmiEntry;
85
86extern SMI_HANDLER_PROFILE_PROTOCOL mSmiHandlerProfile;
87
88GLOBAL_REMOVE_IF_UNREFERENCED LIST_ENTRY mHardwareSmiEntryList = INITIALIZE_LIST_HEAD_VARIABLE (mHardwareSmiEntryList);
89
90GLOBAL_REMOVE_IF_UNREFERENCED LIST_ENTRY mRootSmiEntryList = INITIALIZE_LIST_HEAD_VARIABLE (mRootSmiEntryList);
91
92GLOBAL_REMOVE_IF_UNREFERENCED LIST_ENTRY *mSmmCoreRootSmiEntryList = &mRootSmiEntryList;
93GLOBAL_REMOVE_IF_UNREFERENCED LIST_ENTRY *mSmmCoreSmiEntryList = &mSmiEntryList;
94GLOBAL_REMOVE_IF_UNREFERENCED LIST_ENTRY *mSmmCoreHardwareSmiEntryList = &mHardwareSmiEntryList;
95
97GLOBAL_REMOVE_IF_UNREFERENCED UINT32 mImageStructCountMax;
98GLOBAL_REMOVE_IF_UNREFERENCED UINT32 mImageStructCount;
99
100GLOBAL_REMOVE_IF_UNREFERENCED VOID *mSmiHandlerProfileDatabase;
101GLOBAL_REMOVE_IF_UNREFERENCED UINTN mSmiHandlerProfileDatabaseSize;
102
103GLOBAL_REMOVE_IF_UNREFERENCED UINTN mSmmImageDatabaseSize;
104GLOBAL_REMOVE_IF_UNREFERENCED UINTN mSmmRootSmiDatabaseSize;
105GLOBAL_REMOVE_IF_UNREFERENCED UINTN mSmmSmiDatabaseSize;
106GLOBAL_REMOVE_IF_UNREFERENCED UINTN mSmmHardwareSmiDatabaseSize;
107
108GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mSmiHandlerProfileRecordingStatus;
109
113};
114
121VOID
123 IN UINT8 *Data,
124 IN UINTN Size
125 )
126{
127 UINTN Index;
128
129 for (Index = 0; Index < Size; Index++) {
130 DEBUG ((DEBUG_INFO, "%02x ", (UINTN)Data[Index]));
131 }
132}
133
140VOID
142 IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,
143 OUT EFI_GUID *Guid
144 )
145{
146 EFI_GUID *FileName;
147
148 FileName = NULL;
149 if ((DevicePathType (LoadedImage->FilePath) == MEDIA_DEVICE_PATH) &&
150 (DevicePathSubType (LoadedImage->FilePath) == MEDIA_PIWG_FW_FILE_DP))
151 {
152 FileName = &((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)LoadedImage->FilePath)->FvFileName;
153 }
154
155 if (FileName != NULL) {
156 CopyGuid (Guid, FileName);
157 } else {
158 ZeroMem (Guid, sizeof (EFI_GUID));
159 }
160}
161
171VOID
173 IN PHYSICAL_ADDRESS ImageBase,
174 IN UINT64 ImageSize,
175 IN PHYSICAL_ADDRESS EntryPoint,
176 IN EFI_GUID *Guid,
177 IN CHAR8 *PdbString
178 )
179{
180 UINTN PdbStringSize;
181
182 if (mImageStructCount >= mImageStructCountMax) {
183 ASSERT (FALSE);
184 return;
185 }
186
187 CopyGuid (&mImageStruct[mImageStructCount].FileGuid, Guid);
188 mImageStruct[mImageStructCount].ImageRef = mImageStructCount;
189 mImageStruct[mImageStructCount].ImageBase = ImageBase;
190 mImageStruct[mImageStructCount].ImageSize = ImageSize;
191 mImageStruct[mImageStructCount].EntryPoint = EntryPoint;
192 if (PdbString != NULL) {
193 PdbStringSize = AsciiStrSize (PdbString);
194 mImageStruct[mImageStructCount].PdbString = AllocateCopyPool (PdbStringSize, PdbString);
195 if (mImageStruct[mImageStructCount].PdbString != NULL) {
196 mImageStruct[mImageStructCount].PdbStringSize = (UINT16)PdbStringSize;
197 }
198 }
199
200 mImageStructCount++;
201}
202
212 IN UINTN Address
213 )
214{
215 UINTN Index;
216
217 for (Index = 0; Index < mImageStructCount; Index++) {
218 if ((Address >= mImageStruct[Index].ImageBase) &&
219 (Address < mImageStruct[Index].ImageBase + mImageStruct[Index].ImageSize))
220 {
221 return &mImageStruct[Index];
222 }
223 }
224
225 return NULL;
226}
227
235UINT32
237 IN UINTN Address
238 )
239{
240 IMAGE_STRUCT *ImageStruct;
241
242 ImageStruct = AddressToImageStruct (Address);
243 if (ImageStruct != NULL) {
244 return ImageStruct->ImageRef;
245 }
246
247 return (UINT32)-1;
248}
249
253VOID
255 VOID
256 )
257{
258 EFI_STATUS Status;
259 UINTN NoHandles;
260 UINTN HandleBufferSize;
261 EFI_HANDLE *HandleBuffer;
262 UINTN Index;
263 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
264 CHAR16 *PathStr;
265 EFI_SMM_DRIVER_ENTRY *LoadedImagePrivate;
266 PHYSICAL_ADDRESS EntryPoint;
267 VOID *EntryPointInImage;
268 EFI_GUID Guid;
269 CHAR8 *PdbString;
270 PHYSICAL_ADDRESS RealImageBase;
271
272 HandleBufferSize = 0;
273 HandleBuffer = NULL;
274 Status = gSmst->SmmLocateHandle (
276 &gEfiLoadedImageProtocolGuid,
277 NULL,
278 &HandleBufferSize,
279 HandleBuffer
280 );
281 if (Status != EFI_BUFFER_TOO_SMALL) {
282 return;
283 }
284
285 HandleBuffer = AllocateZeroPool (HandleBufferSize);
286 if (HandleBuffer == NULL) {
287 return;
288 }
289
290 Status = gSmst->SmmLocateHandle (
292 &gEfiLoadedImageProtocolGuid,
293 NULL,
294 &HandleBufferSize,
295 HandleBuffer
296 );
297 if (EFI_ERROR (Status)) {
298 return;
299 }
300
301 NoHandles = HandleBufferSize/sizeof (EFI_HANDLE);
302 mImageStructCountMax = (UINT32)NoHandles;
303 mImageStruct = AllocateZeroPool (mImageStructCountMax * sizeof (IMAGE_STRUCT));
304 if (mImageStruct == NULL) {
305 goto Done;
306 }
307
308 for (Index = 0; Index < NoHandles; Index++) {
309 Status = gSmst->SmmHandleProtocol (
310 HandleBuffer[Index],
311 &gEfiLoadedImageProtocolGuid,
312 (VOID **)&LoadedImage
313 );
314 if (EFI_ERROR (Status)) {
315 continue;
316 }
317
318 PathStr = ConvertDevicePathToText (LoadedImage->FilePath, TRUE, TRUE);
319 GetDriverGuid (LoadedImage, &Guid);
320 DEBUG ((DEBUG_INFO, "Image: %g ", &Guid));
321
322 EntryPoint = 0;
323 LoadedImagePrivate = BASE_CR (LoadedImage, EFI_SMM_DRIVER_ENTRY, SmmLoadedImage);
324 RealImageBase = (UINTN)LoadedImage->ImageBase;
325 if (LoadedImagePrivate->Signature == EFI_SMM_DRIVER_ENTRY_SIGNATURE) {
326 EntryPoint = LoadedImagePrivate->ImageEntryPoint;
327 if ((EntryPoint != 0) && ((EntryPoint < (UINTN)LoadedImage->ImageBase) || (EntryPoint >= ((UINTN)LoadedImage->ImageBase + LoadedImage->ImageSize)))) {
328 //
329 // If the EntryPoint is not in the range of image buffer, it should come from emulation environment.
330 // So patch ImageBuffer here to align the EntryPoint.
331 //
332 Status = InternalPeCoffGetEntryPoint (LoadedImage->ImageBase, &EntryPointInImage);
333 ASSERT_EFI_ERROR (Status);
334 RealImageBase = (UINTN)LoadedImage->ImageBase + EntryPoint - (UINTN)EntryPointInImage;
335 }
336 }
337
338 DEBUG ((DEBUG_INFO, "(0x%lx - 0x%lx", RealImageBase, LoadedImage->ImageSize));
339 if (EntryPoint != 0) {
340 DEBUG ((DEBUG_INFO, ", EntryPoint:0x%lx", EntryPoint));
341 }
342
343 DEBUG ((DEBUG_INFO, ")\n"));
344
345 if (RealImageBase != 0) {
346 PdbString = PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)RealImageBase);
347 DEBUG ((DEBUG_INFO, " pdb - %a\n", PdbString));
348 } else {
349 PdbString = NULL;
350 }
351
352 DEBUG ((DEBUG_INFO, " (%s)\n", PathStr));
353
354 AddImageStruct (RealImageBase, LoadedImage->ImageSize, EntryPoint, &Guid, PdbString);
355 }
356
357Done:
358 FreePool (HandleBuffer);
359 return;
360}
361
369VOID
371 IN EFI_GUID *HandlerType,
372 IN VOID *Context,
373 IN UINTN ContextSize
374 )
375{
376 CHAR16 *Str;
377
378 if (CompareGuid (HandlerType, &gEfiSmmSwDispatch2ProtocolGuid)) {
379 DEBUG ((DEBUG_INFO, " SwSmi - 0x%lx\n", ((SMI_HANDLER_PROFILE_SW_REGISTER_CONTEXT *)Context)->SwSmiInputValue));
380 } else if (CompareGuid (HandlerType, &gEfiSmmSxDispatch2ProtocolGuid)) {
381 DEBUG ((DEBUG_INFO, " SxType - 0x%x\n", ((EFI_SMM_SX_REGISTER_CONTEXT *)Context)->Type));
382 DEBUG ((DEBUG_INFO, " SxPhase - 0x%x\n", ((EFI_SMM_SX_REGISTER_CONTEXT *)Context)->Phase));
383 } else if (CompareGuid (HandlerType, &gEfiSmmPowerButtonDispatch2ProtocolGuid)) {
384 DEBUG ((DEBUG_INFO, " PowerButtonPhase - 0x%x\n", ((EFI_SMM_POWER_BUTTON_REGISTER_CONTEXT *)Context)->Phase));
385 } else if (CompareGuid (HandlerType, &gEfiSmmStandbyButtonDispatch2ProtocolGuid)) {
386 DEBUG ((DEBUG_INFO, " StandbyButtonPhase - 0x%x\n", ((EFI_SMM_STANDBY_BUTTON_REGISTER_CONTEXT *)Context)->Phase));
387 } else if (CompareGuid (HandlerType, &gEfiSmmPeriodicTimerDispatch2ProtocolGuid)) {
388 DEBUG ((DEBUG_INFO, " PeriodicTimerPeriod - %ld\n", ((EFI_SMM_PERIODIC_TIMER_REGISTER_CONTEXT *)Context)->Period));
389 DEBUG ((DEBUG_INFO, " PeriodicTimerSmiTickInterval - %ld\n", ((EFI_SMM_PERIODIC_TIMER_REGISTER_CONTEXT *)Context)->SmiTickInterval));
390 } else if (CompareGuid (HandlerType, &gEfiSmmGpiDispatch2ProtocolGuid)) {
391 DEBUG ((DEBUG_INFO, " GpiNum - 0x%lx\n", ((EFI_SMM_GPI_REGISTER_CONTEXT *)Context)->GpiNum));
392 } else if (CompareGuid (HandlerType, &gEfiSmmIoTrapDispatch2ProtocolGuid)) {
393 DEBUG ((DEBUG_INFO, " IoTrapAddress - 0x%x\n", ((EFI_SMM_IO_TRAP_REGISTER_CONTEXT *)Context)->Address));
394 DEBUG ((DEBUG_INFO, " IoTrapLength - 0x%x\n", ((EFI_SMM_IO_TRAP_REGISTER_CONTEXT *)Context)->Length));
395 DEBUG ((DEBUG_INFO, " IoTrapType - 0x%x\n", ((EFI_SMM_IO_TRAP_REGISTER_CONTEXT *)Context)->Type));
396 } else if (CompareGuid (HandlerType, &gEfiSmmUsbDispatch2ProtocolGuid)) {
397 DEBUG ((DEBUG_INFO, " UsbType - 0x%x\n", ((SMI_HANDLER_PROFILE_USB_REGISTER_CONTEXT *)Context)->Type));
399 DEBUG ((DEBUG_INFO, " UsbDevicePath - %s\n", Str));
400 if (Str != NULL) {
401 FreePool (Str);
402 }
403 } else {
404 DEBUG ((DEBUG_INFO, " Context - "));
405 InternalDumpData (Context, ContextSize);
406 DEBUG ((DEBUG_INFO, "\n"));
407 }
408}
409
415VOID
417 IN SMI_ENTRY *SmiEntry
418 )
419{
420 LIST_ENTRY *ListEntry;
421 SMI_HANDLER *SmiHandler;
422 IMAGE_STRUCT *ImageStruct;
423
424 ListEntry = &SmiEntry->SmiHandlers;
425 for (ListEntry = ListEntry->ForwardLink;
426 ListEntry != &SmiEntry->SmiHandlers;
427 ListEntry = ListEntry->ForwardLink)
428 {
429 SmiHandler = CR (ListEntry, SMI_HANDLER, Link, SMI_HANDLER_SIGNATURE);
430 ImageStruct = AddressToImageStruct ((UINTN)SmiHandler->Handler);
431 if (ImageStruct != NULL) {
432 DEBUG ((DEBUG_INFO, " Module - %g", &ImageStruct->FileGuid));
433 }
434
435 if ((ImageStruct != NULL) && (ImageStruct->PdbString[0] != 0)) {
436 DEBUG ((DEBUG_INFO, " (Pdb - %a)", ImageStruct->PdbString));
437 }
438
439 DEBUG ((DEBUG_INFO, "\n"));
440 if (SmiHandler->ContextSize != 0) {
441 DumpSmiChildContext (&SmiEntry->HandlerType, SmiHandler->Context, SmiHandler->ContextSize);
442 }
443
444 DEBUG ((DEBUG_INFO, " Handler - 0x%x", SmiHandler->Handler));
445 if (ImageStruct != NULL) {
446 DEBUG ((DEBUG_INFO, " <== RVA - 0x%x", (UINTN)SmiHandler->Handler - (UINTN)ImageStruct->ImageBase));
447 }
448
449 DEBUG ((DEBUG_INFO, "\n"));
450 DEBUG ((DEBUG_INFO, " CallerAddr - 0x%x", SmiHandler->CallerAddr));
451 if (ImageStruct != NULL) {
452 DEBUG ((DEBUG_INFO, " <== RVA - 0x%x", SmiHandler->CallerAddr - (UINTN)ImageStruct->ImageBase));
453 }
454
455 DEBUG ((DEBUG_INFO, "\n"));
456 }
457
458 return;
459}
460
466VOID
468 IN LIST_ENTRY *SmiEntryList
469 )
470{
471 LIST_ENTRY *ListEntry;
472 SMI_ENTRY *SmiEntry;
473
474 ListEntry = SmiEntryList;
475 for (ListEntry = ListEntry->ForwardLink;
476 ListEntry != SmiEntryList;
477 ListEntry = ListEntry->ForwardLink)
478 {
479 SmiEntry = CR (ListEntry, SMI_ENTRY, AllEntries, SMI_ENTRY_SIGNATURE);
480 DEBUG ((DEBUG_INFO, "SmiEntry - %g\n", &SmiEntry->HandlerType));
481 DumpSmiHandlerOnSmiEntry (SmiEntry);
482 }
483
484 return;
485}
486
500EFIAPI
502 IN CONST EFI_GUID *Protocol,
503 IN VOID *Interface,
504 IN EFI_HANDLE Handle
505 )
506{
508
509 //
510 // Dump all image
511 //
512 DEBUG ((DEBUG_INFO, "##################\n"));
513 DEBUG ((DEBUG_INFO, "# IMAGE DATABASE #\n"));
514 DEBUG ((DEBUG_INFO, "##################\n"));
516 DEBUG ((DEBUG_INFO, "\n"));
517
518 //
519 // Dump SMI Handler
520 //
521 DEBUG ((DEBUG_INFO, "########################\n"));
522 DEBUG ((DEBUG_INFO, "# SMI Handler DATABASE #\n"));
523 DEBUG ((DEBUG_INFO, "########################\n"));
524
525 DEBUG ((DEBUG_INFO, "# 1. ROOT SMI Handler #\n"));
526 DEBUG_CODE (
527 DumpSmiEntryList (mSmmCoreRootSmiEntryList);
528 );
529
530 DEBUG ((DEBUG_INFO, "# 2. GUID SMI Handler #\n"));
531 DEBUG_CODE (
532 DumpSmiEntryList (mSmmCoreSmiEntryList);
533 );
534
535 DEBUG ((DEBUG_INFO, "# 3. Hardware SMI Handler #\n"));
536 DEBUG_CODE (
537 DumpSmiEntryList (mSmmCoreHardwareSmiEntryList);
538 );
539
540 DEBUG ((DEBUG_INFO, "\n"));
541
543
544 if (mImageStruct != NULL) {
545 FreePool (mImageStruct);
546 }
547
548 return EFI_SUCCESS;
549}
550
556UINTN
558 VOID
559 )
560{
561 UINTN Size;
562 UINT32 Index;
563
564 Size = 0;
565 for (Index = 0; Index < mImageStructCount; Index++) {
566 Size += sizeof (SMM_CORE_IMAGE_DATABASE_STRUCTURE) + GET_OCCUPIED_SIZE (mImageStruct[Index].PdbStringSize, sizeof (UINT64));
567 }
568
569 return Size;
570}
571
579UINTN
581 IN SMI_ENTRY *SmiEntry
582 )
583{
584 LIST_ENTRY *ListEntry;
585 SMI_HANDLER *SmiHandler;
586 UINTN Size;
587
588 Size = 0;
589 ListEntry = &SmiEntry->SmiHandlers;
590 for (ListEntry = ListEntry->ForwardLink;
591 ListEntry != &SmiEntry->SmiHandlers;
592 ListEntry = ListEntry->ForwardLink)
593 {
594 SmiHandler = CR (ListEntry, SMI_HANDLER, Link, SMI_HANDLER_SIGNATURE);
595 Size += sizeof (SMM_CORE_SMI_HANDLER_STRUCTURE) + GET_OCCUPIED_SIZE (SmiHandler->ContextSize, sizeof (UINT64));
596 }
597
598 return Size;
599}
600
608UINTN
610 IN LIST_ENTRY *SmiEntryList
611 )
612{
613 LIST_ENTRY *ListEntry;
614 SMI_ENTRY *SmiEntry;
615 UINTN Size;
616
617 Size = 0;
618 ListEntry = SmiEntryList;
619 for (ListEntry = ListEntry->ForwardLink;
620 ListEntry != SmiEntryList;
621 ListEntry = ListEntry->ForwardLink)
622 {
623 SmiEntry = CR (ListEntry, SMI_ENTRY, AllEntries, SMI_ENTRY_SIGNATURE);
624 Size += sizeof (SMM_CORE_SMI_DATABASE_STRUCTURE);
625 Size += GetSmmSmiHandlerSizeOnSmiEntry (SmiEntry);
626 }
627
628 return Size;
629}
630
636UINTN
638 VOID
639 )
640{
641 mSmmImageDatabaseSize = GetSmmImageDatabaseSize ();
642 mSmmRootSmiDatabaseSize = GetSmmSmiDatabaseSize (mSmmCoreRootSmiEntryList);
643 mSmmSmiDatabaseSize = GetSmmSmiDatabaseSize (mSmmCoreSmiEntryList);
644 mSmmHardwareSmiDatabaseSize = GetSmmSmiDatabaseSize (mSmmCoreHardwareSmiEntryList);
645
646 return mSmmImageDatabaseSize + mSmmSmiDatabaseSize + mSmmRootSmiDatabaseSize + mSmmHardwareSmiDatabaseSize;
647}
648
657UINTN
659 IN OUT VOID *Data,
660 IN UINTN ExpectedSize
661 )
662{
664 UINTN Size;
665 UINTN Index;
666
667 ImageStruct = Data;
668 Size = 0;
669 for (Index = 0; Index < mImageStructCount; Index++) {
670 if (Size >= ExpectedSize) {
671 return 0;
672 }
673
674 if (sizeof (SMM_CORE_IMAGE_DATABASE_STRUCTURE) + GET_OCCUPIED_SIZE (mImageStruct[Index].PdbStringSize, sizeof (UINT64)) > ExpectedSize - Size) {
675 return 0;
676 }
677
678 ImageStruct->Header.Signature = SMM_CORE_IMAGE_DATABASE_SIGNATURE;
679 ImageStruct->Header.Length = (UINT32)(sizeof (SMM_CORE_IMAGE_DATABASE_STRUCTURE) + GET_OCCUPIED_SIZE (mImageStruct[Index].PdbStringSize, sizeof (UINT64)));
680 ImageStruct->Header.Revision = SMM_CORE_IMAGE_DATABASE_REVISION;
681 CopyGuid (&ImageStruct->FileGuid, &mImageStruct[Index].FileGuid);
682 ImageStruct->ImageRef = mImageStruct[Index].ImageRef;
683 ImageStruct->EntryPoint = mImageStruct[Index].EntryPoint;
684 ImageStruct->ImageBase = mImageStruct[Index].ImageBase;
685 ImageStruct->ImageSize = mImageStruct[Index].ImageSize;
686 if (mImageStruct[Index].PdbStringSize != 0) {
687 ImageStruct->PdbStringOffset = sizeof (SMM_CORE_IMAGE_DATABASE_STRUCTURE);
688 CopyMem ((VOID *)((UINTN)ImageStruct + ImageStruct->PdbStringOffset), mImageStruct[Index].PdbString, mImageStruct[Index].PdbStringSize);
689 } else {
690 ImageStruct->PdbStringOffset = 0;
691 }
692
693 ImageStruct = (SMM_CORE_IMAGE_DATABASE_STRUCTURE *)((UINTN)ImageStruct + ImageStruct->Header.Length);
694 Size += sizeof (SMM_CORE_IMAGE_DATABASE_STRUCTURE) + GET_OCCUPIED_SIZE (mImageStruct[Index].PdbStringSize, sizeof (UINT64));
695 }
696
697 if (ExpectedSize != Size) {
698 return 0;
699 }
700
701 return Size;
702}
703
714UINTN
716 IN SMI_ENTRY *SmiEntry,
717 IN OUT VOID *Data,
718 IN UINTN MaxSize,
719 OUT UINT32 *Count
720 )
721{
722 SMM_CORE_SMI_HANDLER_STRUCTURE *SmiHandlerStruct;
723 LIST_ENTRY *ListEntry;
724 SMI_HANDLER *SmiHandler;
725 UINTN Size;
726
727 SmiHandlerStruct = Data;
728 Size = 0;
729 *Count = 0;
730 ListEntry = &SmiEntry->SmiHandlers;
731 for (ListEntry = ListEntry->ForwardLink;
732 ListEntry != &SmiEntry->SmiHandlers;
733 ListEntry = ListEntry->ForwardLink)
734 {
735 SmiHandler = CR (ListEntry, SMI_HANDLER, Link, SMI_HANDLER_SIGNATURE);
736 if (Size >= MaxSize) {
737 *Count = 0;
738 return 0;
739 }
740
741 if (sizeof (SMM_CORE_SMI_HANDLER_STRUCTURE) + GET_OCCUPIED_SIZE (SmiHandler->ContextSize, sizeof (UINT64)) > MaxSize - Size) {
742 *Count = 0;
743 return 0;
744 }
745
746 SmiHandlerStruct->Length = (UINT32)(sizeof (SMM_CORE_SMI_HANDLER_STRUCTURE) + GET_OCCUPIED_SIZE (SmiHandler->ContextSize, sizeof (UINT64)));
747 SmiHandlerStruct->CallerAddr = (UINTN)SmiHandler->CallerAddr;
748 SmiHandlerStruct->Handler = (UINTN)SmiHandler->Handler;
749 SmiHandlerStruct->ImageRef = AddressToImageRef ((UINTN)SmiHandler->Handler);
750 SmiHandlerStruct->ContextBufferSize = (UINT32)SmiHandler->ContextSize;
751 if (SmiHandler->ContextSize != 0) {
752 SmiHandlerStruct->ContextBufferOffset = sizeof (SMM_CORE_SMI_HANDLER_STRUCTURE);
753 CopyMem ((UINT8 *)SmiHandlerStruct + SmiHandlerStruct->ContextBufferOffset, SmiHandler->Context, SmiHandler->ContextSize);
754 } else {
755 SmiHandlerStruct->ContextBufferOffset = 0;
756 }
757
758 Size += sizeof (SMM_CORE_SMI_HANDLER_STRUCTURE) + GET_OCCUPIED_SIZE (SmiHandler->ContextSize, sizeof (UINT64));
759 SmiHandlerStruct = (SMM_CORE_SMI_HANDLER_STRUCTURE *)((UINTN)SmiHandlerStruct + SmiHandlerStruct->Length);
760 *Count = *Count + 1;
761 }
762
763 return Size;
764}
765
776UINTN
778 IN LIST_ENTRY *SmiEntryList,
779 IN UINT32 HandlerCategory,
780 IN OUT VOID *Data,
781 IN UINTN ExpectedSize
782 )
783{
785 LIST_ENTRY *ListEntry;
786 SMI_ENTRY *SmiEntry;
787 UINTN Size;
788 UINTN SmiHandlerSize;
789 UINT32 SmiHandlerCount;
790
791 SmiStruct = Data;
792 Size = 0;
793 ListEntry = SmiEntryList;
794 for (ListEntry = ListEntry->ForwardLink;
795 ListEntry != SmiEntryList;
796 ListEntry = ListEntry->ForwardLink)
797 {
798 SmiEntry = CR (ListEntry, SMI_ENTRY, AllEntries, SMI_ENTRY_SIGNATURE);
799 if (Size >= ExpectedSize) {
800 return 0;
801 }
802
803 if (sizeof (SMM_CORE_SMI_DATABASE_STRUCTURE) > ExpectedSize - Size) {
804 return 0;
805 }
806
807 SmiStruct->Header.Signature = SMM_CORE_SMI_DATABASE_SIGNATURE;
808 SmiStruct->Header.Length = sizeof (SMM_CORE_SMI_DATABASE_STRUCTURE);
809 SmiStruct->Header.Revision = SMM_CORE_SMI_DATABASE_REVISION;
810 SmiStruct->HandlerCategory = HandlerCategory;
811 CopyGuid (&SmiStruct->HandlerType, &SmiEntry->HandlerType);
812 Size += sizeof (SMM_CORE_SMI_DATABASE_STRUCTURE);
813 SmiHandlerSize = GetSmmSmiHandlerDataOnSmiEntry (SmiEntry, (UINT8 *)SmiStruct + SmiStruct->Header.Length, ExpectedSize - Size, &SmiHandlerCount);
814 SmiStruct->HandlerCount = SmiHandlerCount;
815 Size += SmiHandlerSize;
816 SmiStruct->Header.Length += (UINT32)SmiHandlerSize;
817 SmiStruct = (VOID *)((UINTN)SmiStruct + SmiStruct->Header.Length);
818 }
819
820 if (ExpectedSize != Size) {
821 return 0;
822 }
823
824 return Size;
825}
826
837 IN OUT VOID *Data
838 )
839{
840 UINTN SmmImageDatabaseSize;
841 UINTN SmmSmiDatabaseSize;
842 UINTN SmmRootSmiDatabaseSize;
843 UINTN SmmHardwareSmiDatabaseSize;
844
845 DEBUG ((DEBUG_VERBOSE, "GetSmiHandlerProfileDatabaseData\n"));
846 SmmImageDatabaseSize = GetSmmImageDatabaseData (Data, mSmmImageDatabaseSize);
847 if (SmmImageDatabaseSize != mSmmImageDatabaseSize) {
848 DEBUG ((DEBUG_ERROR, "GetSmiHandlerProfileDatabaseData - SmmImageDatabaseSize mismatch!\n"));
849 return EFI_INVALID_PARAMETER;
850 }
851
852 SmmRootSmiDatabaseSize = GetSmmSmiDatabaseData (mSmmCoreRootSmiEntryList, SmmCoreSmiHandlerCategoryRootHandler, (UINT8 *)Data + SmmImageDatabaseSize, mSmmRootSmiDatabaseSize);
853 if (SmmRootSmiDatabaseSize != mSmmRootSmiDatabaseSize) {
854 DEBUG ((DEBUG_ERROR, "GetSmiHandlerProfileDatabaseData - SmmRootSmiDatabaseSize mismatch!\n"));
855 return EFI_INVALID_PARAMETER;
856 }
857
858 SmmSmiDatabaseSize = GetSmmSmiDatabaseData (mSmmCoreSmiEntryList, SmmCoreSmiHandlerCategoryGuidHandler, (UINT8 *)Data + SmmImageDatabaseSize + mSmmRootSmiDatabaseSize, mSmmSmiDatabaseSize);
859 if (SmmSmiDatabaseSize != mSmmSmiDatabaseSize) {
860 DEBUG ((DEBUG_ERROR, "GetSmiHandlerProfileDatabaseData - SmmSmiDatabaseSize mismatch!\n"));
861 return EFI_INVALID_PARAMETER;
862 }
863
864 SmmHardwareSmiDatabaseSize = GetSmmSmiDatabaseData (mSmmCoreHardwareSmiEntryList, SmmCoreSmiHandlerCategoryHardwareHandler, (UINT8 *)Data + SmmImageDatabaseSize + SmmRootSmiDatabaseSize + SmmSmiDatabaseSize, mSmmHardwareSmiDatabaseSize);
865 if (SmmHardwareSmiDatabaseSize != mSmmHardwareSmiDatabaseSize) {
866 DEBUG ((DEBUG_ERROR, "GetSmiHandlerProfileDatabaseData - SmmHardwareSmiDatabaseSize mismatch!\n"));
867 return EFI_INVALID_PARAMETER;
868 }
869
870 return EFI_SUCCESS;
871}
872
876VOID
878 VOID
879 )
880{
881 EFI_STATUS Status;
882
883 mSmiHandlerProfileDatabaseSize = GetSmiHandlerProfileDatabaseSize ();
884 mSmiHandlerProfileDatabase = AllocatePool (mSmiHandlerProfileDatabaseSize);
885 if (mSmiHandlerProfileDatabase == NULL) {
886 return;
887 }
888
889 Status = GetSmiHandlerProfileDatabaseData (mSmiHandlerProfileDatabase);
890 if (EFI_ERROR (Status)) {
891 FreePool (mSmiHandlerProfileDatabase);
892 mSmiHandlerProfileDatabase = NULL;
893 }
894}
895
906VOID
908 OUT VOID *DataBuffer,
909 IN OUT UINT64 *DataSize,
910 IN OUT UINT64 *DataOffset
911 )
912{
913 if (*DataOffset >= mSmiHandlerProfileDatabaseSize) {
914 *DataOffset = mSmiHandlerProfileDatabaseSize;
915 return;
916 }
917
918 if (mSmiHandlerProfileDatabaseSize - *DataOffset < *DataSize) {
919 *DataSize = mSmiHandlerProfileDatabaseSize - *DataOffset;
920 }
921
922 CopyMem (
923 DataBuffer,
924 (UINT8 *)mSmiHandlerProfileDatabase + *DataOffset,
925 (UINTN)*DataSize
926 );
927 *DataOffset = *DataOffset + *DataSize;
928}
929
936VOID
938 IN SMI_HANDLER_PROFILE_PARAMETER_GET_INFO *SmiHandlerProfileParameterGetInfo
939 )
940{
941 BOOLEAN SmiHandlerProfileRecordingStatus;
942
943 SmiHandlerProfileRecordingStatus = mSmiHandlerProfileRecordingStatus;
944 mSmiHandlerProfileRecordingStatus = FALSE;
945
946 SmiHandlerProfileParameterGetInfo->DataSize = mSmiHandlerProfileDatabaseSize;
947 SmiHandlerProfileParameterGetInfo->Header.ReturnStatus = 0;
948
949 mSmiHandlerProfileRecordingStatus = SmiHandlerProfileRecordingStatus;
950}
951
958VOID
960 IN SMI_HANDLER_PROFILE_PARAMETER_GET_DATA_BY_OFFSET *SmiHandlerProfileParameterGetDataByOffset
961 )
962{
963 SMI_HANDLER_PROFILE_PARAMETER_GET_DATA_BY_OFFSET SmiHandlerProfileGetDataByOffset;
964 BOOLEAN SmiHandlerProfileRecordingStatus;
965
966 SmiHandlerProfileRecordingStatus = mSmiHandlerProfileRecordingStatus;
967 mSmiHandlerProfileRecordingStatus = FALSE;
968
969 CopyMem (&SmiHandlerProfileGetDataByOffset, SmiHandlerProfileParameterGetDataByOffset, sizeof (SmiHandlerProfileGetDataByOffset));
970
971 //
972 // Sanity check
973 //
974 if (!SmmIsBufferOutsideSmmValid ((UINTN)SmiHandlerProfileGetDataByOffset.DataBuffer, (UINTN)SmiHandlerProfileGetDataByOffset.DataSize)) {
975 DEBUG ((DEBUG_ERROR, "SmiHandlerProfileHandlerGetDataByOffset: SMI handler profile get data in SMRAM or overflow!\n"));
976 SmiHandlerProfileParameterGetDataByOffset->Header.ReturnStatus = (UINT64)(INT64)(INTN)EFI_ACCESS_DENIED;
977 goto Done;
978 }
979
980 SmiHandlerProfileCopyData ((VOID *)(UINTN)SmiHandlerProfileGetDataByOffset.DataBuffer, &SmiHandlerProfileGetDataByOffset.DataSize, &SmiHandlerProfileGetDataByOffset.DataOffset);
981 CopyMem (SmiHandlerProfileParameterGetDataByOffset, &SmiHandlerProfileGetDataByOffset, sizeof (SmiHandlerProfileGetDataByOffset));
982 SmiHandlerProfileParameterGetDataByOffset->Header.ReturnStatus = 0;
983
984Done:
985 mSmiHandlerProfileRecordingStatus = SmiHandlerProfileRecordingStatus;
986}
987
1004EFIAPI
1006 IN EFI_HANDLE DispatchHandle,
1007 IN CONST VOID *Context OPTIONAL,
1008 IN OUT VOID *CommBuffer OPTIONAL,
1009 IN OUT UINTN *CommBufferSize OPTIONAL
1010 )
1011{
1012 SMI_HANDLER_PROFILE_PARAMETER_HEADER *SmiHandlerProfileParameterHeader;
1013 UINTN TempCommBufferSize;
1014
1015 DEBUG ((DEBUG_ERROR, "SmiHandlerProfileHandler Enter\n"));
1016
1017 if (mSmiHandlerProfileDatabase == NULL) {
1018 return EFI_SUCCESS;
1019 }
1020
1021 //
1022 // If input is invalid, stop processing this SMI
1023 //
1024 if ((CommBuffer == NULL) || (CommBufferSize == NULL)) {
1025 return EFI_SUCCESS;
1026 }
1027
1028 TempCommBufferSize = *CommBufferSize;
1029
1030 if (TempCommBufferSize < sizeof (SMI_HANDLER_PROFILE_PARAMETER_HEADER)) {
1031 DEBUG ((DEBUG_ERROR, "SmiHandlerProfileHandler: SMM communication buffer size invalid!\n"));
1032 return EFI_SUCCESS;
1033 }
1034
1035 if (!SmmIsBufferOutsideSmmValid ((UINTN)CommBuffer, TempCommBufferSize)) {
1036 DEBUG ((DEBUG_ERROR, "SmiHandlerProfileHandler: SMM communication buffer in SMRAM or overflow!\n"));
1037 return EFI_SUCCESS;
1038 }
1039
1040 SmiHandlerProfileParameterHeader = (SMI_HANDLER_PROFILE_PARAMETER_HEADER *)((UINTN)CommBuffer);
1041 SmiHandlerProfileParameterHeader->ReturnStatus = (UINT64)-1;
1042
1043 switch (SmiHandlerProfileParameterHeader->Command) {
1044 case SMI_HANDLER_PROFILE_COMMAND_GET_INFO:
1045 DEBUG ((DEBUG_ERROR, "SmiHandlerProfileHandlerGetInfo\n"));
1046 if (TempCommBufferSize != sizeof (SMI_HANDLER_PROFILE_PARAMETER_GET_INFO)) {
1047 DEBUG ((DEBUG_ERROR, "SmiHandlerProfileHandler: SMM communication buffer size invalid!\n"));
1048 return EFI_SUCCESS;
1049 }
1050
1052 break;
1053 case SMI_HANDLER_PROFILE_COMMAND_GET_DATA_BY_OFFSET:
1054 DEBUG ((DEBUG_ERROR, "SmiHandlerProfileHandlerGetDataByOffset\n"));
1055 if (TempCommBufferSize != sizeof (SMI_HANDLER_PROFILE_PARAMETER_GET_DATA_BY_OFFSET)) {
1056 DEBUG ((DEBUG_ERROR, "SmiHandlerProfileHandler: SMM communication buffer size invalid!\n"));
1057 return EFI_SUCCESS;
1058 }
1059
1061 break;
1062 default:
1063 break;
1064 }
1065
1066 DEBUG ((DEBUG_ERROR, "SmiHandlerProfileHandler Exit\n"));
1067
1068 return EFI_SUCCESS;
1069}
1070
1074VOID
1076 VOID
1077 )
1078{
1079 EFI_STATUS Status;
1080 EFI_HANDLE DispatchHandle;
1081
1082 Status = gSmst->SmiHandlerRegister (
1084 &gSmiHandlerProfileGuid,
1085 &DispatchHandle
1086 );
1087 ASSERT_EFI_ERROR (Status);
1088}
1089
1098SMI_ENTRY *
1100 IN EFI_GUID *HandlerType,
1101 IN BOOLEAN Create
1102 )
1103{
1104 LIST_ENTRY *Link;
1105 SMI_ENTRY *Item;
1106 SMI_ENTRY *SmiEntry;
1107
1108 //
1109 // Search the SMI entry list for the matching GUID
1110 //
1111 SmiEntry = NULL;
1112 for (Link = mHardwareSmiEntryList.ForwardLink;
1113 Link != &mHardwareSmiEntryList;
1114 Link = Link->ForwardLink)
1115 {
1116 Item = CR (Link, SMI_ENTRY, AllEntries, SMI_ENTRY_SIGNATURE);
1117 if (CompareGuid (&Item->HandlerType, HandlerType)) {
1118 //
1119 // This is the SMI entry
1120 //
1121 SmiEntry = Item;
1122 break;
1123 }
1124 }
1125
1126 //
1127 // If the protocol entry was not found and Create is TRUE, then
1128 // allocate a new entry
1129 //
1130 if ((SmiEntry == NULL) && Create) {
1131 SmiEntry = AllocatePool (sizeof (SMI_ENTRY));
1132 if (SmiEntry != NULL) {
1133 //
1134 // Initialize new SMI entry structure
1135 //
1136 SmiEntry->Signature = SMI_ENTRY_SIGNATURE;
1137 CopyGuid ((VOID *)&SmiEntry->HandlerType, HandlerType);
1138 InitializeListHead (&SmiEntry->SmiHandlers);
1139
1140 //
1141 // Add it to SMI entry list
1142 //
1143 InsertTailList (&mHardwareSmiEntryList, &SmiEntry->AllEntries);
1144 }
1145 }
1146
1147 return SmiEntry;
1148}
1149
1161 IN EFI_SMM_USB_REGISTER_CONTEXT *UsbContext,
1162 IN UINTN UsbContextSize,
1163 OUT UINTN *SmiHandlerUsbContextSize
1164 )
1165{
1166 UINTN DevicePathSize;
1167 SMI_HANDLER_PROFILE_USB_REGISTER_CONTEXT *SmiHandlerUsbContext;
1168
1169 ASSERT (UsbContextSize == sizeof (EFI_SMM_USB_REGISTER_CONTEXT));
1170
1171 DevicePathSize = GetDevicePathSize (UsbContext->Device);
1172 SmiHandlerUsbContext = AllocatePool (sizeof (SMI_HANDLER_PROFILE_USB_REGISTER_CONTEXT) + DevicePathSize);
1173 if (SmiHandlerUsbContext == NULL) {
1174 *SmiHandlerUsbContextSize = 0;
1175 return NULL;
1176 }
1177
1178 SmiHandlerUsbContext->Type = UsbContext->Type;
1179 SmiHandlerUsbContext->DevicePathSize = (UINT32)DevicePathSize;
1180 CopyMem (SmiHandlerUsbContext + 1, UsbContext->Device, DevicePathSize);
1181 *SmiHandlerUsbContextSize = sizeof (SMI_HANDLER_PROFILE_USB_REGISTER_CONTEXT) + DevicePathSize;
1182 return SmiHandlerUsbContext;
1183}
1184
1197 IN UINTN SwContextSize,
1198 OUT UINTN *SmiHandlerSwContextSize
1199 )
1200{
1201 SMI_HANDLER_PROFILE_SW_REGISTER_CONTEXT *SmiHandlerSwContext;
1202
1203 ASSERT (SwContextSize == sizeof (EFI_SMM_SW_REGISTER_CONTEXT));
1204
1205 SmiHandlerSwContext = AllocatePool (sizeof (SMI_HANDLER_PROFILE_SW_REGISTER_CONTEXT));
1206 if (SmiHandlerSwContext == NULL) {
1207 *SmiHandlerSwContextSize = 0;
1208 return NULL;
1209 }
1210
1211 SmiHandlerSwContext->SwSmiInputValue = SwContext->SwSmiInputValue;
1212 *SmiHandlerSwContextSize = sizeof (SMI_HANDLER_PROFILE_SW_REGISTER_CONTEXT);
1213 return SmiHandlerSwContext;
1214}
1215
1237EFIAPI
1240 IN EFI_GUID *HandlerGuid,
1241 IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler,
1242 IN PHYSICAL_ADDRESS CallerAddress,
1243 IN VOID *Context OPTIONAL,
1244 IN UINTN ContextSize OPTIONAL
1245 )
1246{
1247 SMI_HANDLER *SmiHandler;
1248 SMI_ENTRY *SmiEntry;
1249 LIST_ENTRY *List;
1250
1251 if (((ContextSize == 0) && (Context != NULL)) ||
1252 ((ContextSize != 0) && (Context == NULL)))
1253 {
1254 return EFI_INVALID_PARAMETER;
1255 }
1256
1257 SmiHandler = AllocateZeroPool (sizeof (SMI_HANDLER));
1258 if (SmiHandler == NULL) {
1259 return EFI_OUT_OF_RESOURCES;
1260 }
1261
1262 SmiHandler->Signature = SMI_HANDLER_SIGNATURE;
1263 SmiHandler->Handler = Handler;
1264 SmiHandler->CallerAddr = (UINTN)CallerAddress;
1265 SmiHandler->Context = Context;
1266 SmiHandler->ContextSize = ContextSize;
1267
1268 if (Context != NULL) {
1269 if (CompareGuid (HandlerGuid, &gEfiSmmUsbDispatch2ProtocolGuid)) {
1270 SmiHandler->Context = ConvertSmiHandlerUsbContext (Context, ContextSize, &SmiHandler->ContextSize);
1271 } else if (CompareGuid (HandlerGuid, &gEfiSmmSwDispatch2ProtocolGuid)) {
1272 SmiHandler->Context = ConvertSmiHandlerSwContext (Context, ContextSize, &SmiHandler->ContextSize);
1273 } else {
1274 SmiHandler->Context = AllocateCopyPool (ContextSize, Context);
1275 }
1276 }
1277
1278 if (SmiHandler->Context == NULL) {
1279 SmiHandler->ContextSize = 0;
1280 }
1281
1282 SmiEntry = SmmCoreFindHardwareSmiEntry (HandlerGuid, TRUE);
1283 if (SmiEntry == NULL) {
1284 if (SmiHandler->Context != NULL) {
1285 FreePool (SmiHandler->Context);
1286 }
1287
1288 FreePool (SmiHandler);
1289 return EFI_OUT_OF_RESOURCES;
1290 }
1291
1292 List = &SmiEntry->SmiHandlers;
1293
1294 SmiHandler->SmiEntry = SmiEntry;
1295 InsertTailList (List, &SmiHandler->Link);
1296
1297 return EFI_SUCCESS;
1298}
1299
1318EFIAPI
1321 IN EFI_GUID *HandlerGuid,
1322 IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler,
1323 IN VOID *Context OPTIONAL,
1324 IN UINTN ContextSize OPTIONAL
1325 )
1326{
1327 LIST_ENTRY *Link;
1328 LIST_ENTRY *Head;
1329 SMI_HANDLER *SmiHandler;
1330 SMI_ENTRY *SmiEntry;
1331 SMI_HANDLER *TargetSmiHandler;
1332 VOID *SearchContext;
1333 UINTN SearchContextSize;
1334
1335 if (((ContextSize == 0) && (Context != NULL)) ||
1336 ((ContextSize != 0) && (Context == NULL)))
1337 {
1338 return EFI_INVALID_PARAMETER;
1339 }
1340
1341 SmiEntry = SmmCoreFindHardwareSmiEntry (HandlerGuid, FALSE);
1342 if (SmiEntry == NULL) {
1343 return EFI_NOT_FOUND;
1344 }
1345
1346 SearchContext = Context;
1347 SearchContextSize = ContextSize;
1348 if (Context != NULL) {
1349 if (CompareGuid (HandlerGuid, &gEfiSmmUsbDispatch2ProtocolGuid)) {
1350 SearchContext = ConvertSmiHandlerUsbContext (Context, ContextSize, &SearchContextSize);
1351 } else if (CompareGuid (HandlerGuid, &gEfiSmmSwDispatch2ProtocolGuid)) {
1352 SearchContext = ConvertSmiHandlerSwContext (Context, ContextSize, &SearchContextSize);
1353 }
1354 }
1355
1356 TargetSmiHandler = NULL;
1357 Head = &SmiEntry->SmiHandlers;
1358 for (Link = Head->ForwardLink; Link != Head; Link = Link->ForwardLink) {
1359 SmiHandler = CR (Link, SMI_HANDLER, Link, SMI_HANDLER_SIGNATURE);
1360 if (SmiHandler->Handler == Handler) {
1361 if ((SearchContext == NULL) ||
1362 ((SearchContextSize == SmiHandler->ContextSize) && (CompareMem (SearchContext, SmiHandler->Context, SearchContextSize) == 0)))
1363 {
1364 TargetSmiHandler = SmiHandler;
1365 break;
1366 }
1367 }
1368 }
1369
1370 if (SearchContext != NULL) {
1371 if (CompareGuid (HandlerGuid, &gEfiSmmUsbDispatch2ProtocolGuid)) {
1372 FreePool (SearchContext);
1373 }
1374 }
1375
1376 if (TargetSmiHandler == NULL) {
1377 return EFI_NOT_FOUND;
1378 }
1379
1380 SmiHandler = TargetSmiHandler;
1381
1382 RemoveEntryList (&SmiHandler->Link);
1383 if (SmiHandler->Context != NULL) {
1384 FreePool (SmiHandler->Context);
1385 }
1386
1387 FreePool (SmiHandler);
1388
1389 if (IsListEmpty (&SmiEntry->SmiHandlers)) {
1390 RemoveEntryList (&SmiEntry->AllEntries);
1391 FreePool (SmiEntry);
1392 }
1393
1394 return EFI_SUCCESS;
1395}
1396
1400VOID
1402 VOID
1403 )
1404{
1405 EFI_STATUS Status;
1406 VOID *Registration;
1407 EFI_HANDLE Handle;
1408
1409 if ((PcdGet8 (PcdSmiHandlerProfilePropertyMask) & 0x1) != 0) {
1410 InsertTailList (&mRootSmiEntryList, &mRootSmiEntry.AllEntries);
1411
1412 Status = gSmst->SmmRegisterProtocolNotify (
1413 &gEfiSmmReadyToLockProtocolGuid,
1415 &Registration
1416 );
1417 ASSERT_EFI_ERROR (Status);
1418
1419 Handle = NULL;
1421 &Handle,
1422 &gSmiHandlerProfileGuid,
1424 &mSmiHandlerProfile
1425 );
1426 ASSERT_EFI_ERROR (Status);
1427 }
1428}
UINT64 UINTN
INT64 INTN
BOOLEAN EFIAPI IsListEmpty(IN CONST LIST_ENTRY *ListHead)
Definition: LinkedList.c:403
LIST_ENTRY *EFIAPI RemoveEntryList(IN CONST LIST_ENTRY *Entry)
Definition: LinkedList.c:590
LIST_ENTRY *EFIAPI InitializeListHead(IN OUT LIST_ENTRY *ListHead)
Definition: LinkedList.c:182
#define INITIALIZE_LIST_HEAD_VARIABLE(ListHead)
Definition: BaseLib.h:2904
UINTN EFIAPI AsciiStrSize(IN CONST CHAR8 *String)
Definition: String.c:681
LIST_ENTRY *EFIAPI InsertTailList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
Definition: LinkedList.c:259
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
Definition: MemLibGuid.c:73
GUID *EFIAPI CopyGuid(OUT GUID *DestinationGuid, IN CONST GUID *SourceGuid)
Definition: MemLibGuid.c:39
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
#define MEDIA_PIWG_FW_FILE_DP
Definition: DevicePath.h:1130
UINT8 EFIAPI DevicePathType(IN CONST VOID *Node)
UINT8 EFIAPI DevicePathSubType(IN CONST VOID *Node)
CHAR16 *EFIAPI ConvertDevicePathToText(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN BOOLEAN DisplayOnly, IN BOOLEAN AllowShortcuts)
UINTN EFIAPI GetDevicePathSize(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define GLOBAL_REMOVE_IF_UNREFERENCED
Definition: Base.h:48
#define BASE_CR(Record, TYPE, Field)
Definition: Base.h:891
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define CR(Record, TYPE, Field, TestSignature)
Definition: DebugLib.h:659
#define DEBUG_CODE(Expression)
Definition: DebugLib.h:590
#define PcdGet8(TokenName)
Definition: PcdLib.h:336
EFI_SMM_SYSTEM_TABLE2 * gSmst
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
VOID InternalDumpData(IN UINT8 *Data, IN UINTN Size)
UINTN GetSmmSmiDatabaseSize(IN LIST_ENTRY *SmiEntryList)
VOID RegisterSmiHandlerProfileHandler(VOID)
VOID SmmCoreInitializeSmiHandlerProfile(VOID)
SMI_ENTRY * SmmCoreFindHardwareSmiEntry(IN EFI_GUID *HandlerType, IN BOOLEAN Create)
SMI_HANDLER_PROFILE_SW_REGISTER_CONTEXT * ConvertSmiHandlerSwContext(IN EFI_SMM_SW_REGISTER_CONTEXT *SwContext, IN UINTN SwContextSize, OUT UINTN *SmiHandlerSwContextSize)
UINTN GetSmiHandlerProfileDatabaseSize(VOID)
UINT32 AddressToImageRef(IN UINTN Address)
VOID GetSmmLoadedImage(VOID)
VOID SmiHandlerProfileHandlerGetDataByOffset(IN SMI_HANDLER_PROFILE_PARAMETER_GET_DATA_BY_OFFSET *SmiHandlerProfileParameterGetDataByOffset)
EFI_STATUS GetSmiHandlerProfileDatabaseData(IN OUT VOID *Data)
SMI_HANDLER_PROFILE_USB_REGISTER_CONTEXT * ConvertSmiHandlerUsbContext(IN EFI_SMM_USB_REGISTER_CONTEXT *UsbContext, IN UINTN UsbContextSize, OUT UINTN *SmiHandlerUsbContextSize)
EFI_STATUS EFIAPI SmiHandlerProfileRegisterHandler(IN SMI_HANDLER_PROFILE_PROTOCOL *This, IN EFI_GUID *HandlerGuid, IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler, IN PHYSICAL_ADDRESS CallerAddress, IN VOID *Context OPTIONAL, IN UINTN ContextSize OPTIONAL)
UINTN GetSmmSmiDatabaseData(IN LIST_ENTRY *SmiEntryList, IN UINT32 HandlerCategory, IN OUT VOID *Data, IN UINTN ExpectedSize)
VOID AddImageStruct(IN PHYSICAL_ADDRESS ImageBase, IN UINT64 ImageSize, IN PHYSICAL_ADDRESS EntryPoint, IN EFI_GUID *Guid, IN CHAR8 *PdbString)
UINTN GetSmmSmiHandlerDataOnSmiEntry(IN SMI_ENTRY *SmiEntry, IN OUT VOID *Data, IN UINTN MaxSize, OUT UINT32 *Count)
VOID DumpSmiHandlerOnSmiEntry(IN SMI_ENTRY *SmiEntry)
UINTN GetSmmImageDatabaseData(IN OUT VOID *Data, IN UINTN ExpectedSize)
VOID DumpSmiEntryList(IN LIST_ENTRY *SmiEntryList)
UINTN GetSmmSmiHandlerSizeOnSmiEntry(IN SMI_ENTRY *SmiEntry)
VOID SmiHandlerProfileCopyData(OUT VOID *DataBuffer, IN OUT UINT64 *DataSize, IN OUT UINT64 *DataOffset)
UINTN GetSmmImageDatabaseSize(VOID)
VOID BuildSmiHandlerProfileDatabase(VOID)
VOID SmiHandlerProfileHandlerGetInfo(IN SMI_HANDLER_PROFILE_PARAMETER_GET_INFO *SmiHandlerProfileParameterGetInfo)
EFI_STATUS EFIAPI SmiHandlerProfileUnregisterHandler(IN SMI_HANDLER_PROFILE_PROTOCOL *This, IN EFI_GUID *HandlerGuid, IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler, IN VOID *Context OPTIONAL, IN UINTN ContextSize OPTIONAL)
RETURN_STATUS InternalPeCoffGetEntryPoint(IN VOID *Pe32Data, OUT VOID **EntryPoint)
VOID DumpSmiChildContext(IN EFI_GUID *HandlerType, IN VOID *Context, IN UINTN ContextSize)
IMAGE_STRUCT * AddressToImageStruct(IN UINTN Address)
EFI_STATUS EFIAPI SmmReadyToLockInSmiHandlerProfile(IN CONST EFI_GUID *Protocol, IN VOID *Interface, IN EFI_HANDLE Handle)
EFI_STATUS EFIAPI SmiHandlerProfileHandler(IN EFI_HANDLE DispatchHandle, IN CONST VOID *Context OPTIONAL, IN OUT VOID *CommBuffer OPTIONAL, IN OUT UINTN *CommBufferSize OPTIONAL)
VOID GetDriverGuid(IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage, OUT EFI_GUID *Guid)
BOOLEAN EFIAPI SmmIsBufferOutsideSmmValid(IN EFI_PHYSICAL_ADDRESS Buffer, IN UINT64 Length)
Definition: SmmMemLib.c:114
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
@ EFI_NATIVE_INTERFACE
Definition: UefiSpec.h:1193
@ ByProtocol
Definition: UefiSpec.h:1518
EFI_INSTALL_PROTOCOL_INTERFACE SmmInstallProtocolInterface
Definition: PiSmmCis.h:185
Definition: Base.h:213