TianoCore EDK2 master
Loading...
Searching...
No Matches
VarCheckHiiLibMmDependency.c
Go to the documentation of this file.
1
8#include <Uefi.h>
10#include <Library/DebugLib.h>
14#include "VarCheckHiiGen.h"
15#include "VarCheckHii.h"
16#include <Library/UefiLib.h>
17#include <Guid/EventGroup.h>
18
19extern VAR_CHECK_HII_VARIABLE_HEADER *mVarCheckHiiBin;
20extern UINTN mVarCheckHiiBinSize;
21EFI_GUID gVarCheckReceivedHiiBinHandlerGuid = VAR_CHECK_RECEIVED_HII_BIN_HANDLER_GUID;
22
33VOID
34EFIAPI
36 IN EFI_EVENT Event,
37 IN VOID *Context
38 )
39{
40 EFI_STATUS Status;
41 EFI_MM_COMMUNICATION_PROTOCOL *MmCommunication;
42 EFI_MM_COMMUNICATE_HEADER *CommHeader;
43 EDKII_PI_SMM_COMMUNICATION_REGION_TABLE *PiSmmCommunicationRegionTable;
44 EFI_MEMORY_DESCRIPTOR *MmCommMemRegion;
45 UINTN CommBufferSize;
46 UINTN Index;
47 VAR_CHECK_HII_VARIABLE_HEADER *VarCheckHiiVariable;
48
49 DEBUG ((DEBUG_INFO, "%a starts.\n", __func__));
51 if ((mVarCheckHiiBinSize == 0) || (mVarCheckHiiBin == NULL)) {
52 DEBUG ((DEBUG_INFO, "%a: mVarCheckHiiBinSize = 0x%x, mVarCheckHiiBin = 0x%x \n", __func__, mVarCheckHiiBinSize, mVarCheckHiiBin));
53 return;
54 }
55
56 //
57 // Retrieve SMM Communication Region Table
58 //
60 &gEdkiiPiSmmCommunicationRegionTableGuid,
61 (VOID **)&PiSmmCommunicationRegionTable
62 );
63 if (EFI_ERROR (Status)) {
64 DEBUG ((DEBUG_ERROR, "%a: Failed to get PiSmmCommunicationRegionTable - %r\n", __func__, Status));
65 return;
66 }
67
68 ASSERT (PiSmmCommunicationRegionTable != NULL);
69 //
70 // Find a memory region for MM communication
71 //
72 CommBufferSize = 0;
73 MmCommMemRegion = (EFI_MEMORY_DESCRIPTOR *)(PiSmmCommunicationRegionTable + 1);
74 for (Index = 0; Index < PiSmmCommunicationRegionTable->NumberOfEntries; Index++) {
75 if (MmCommMemRegion->Type == EfiConventionalMemory) {
76 CommBufferSize = EFI_PAGES_TO_SIZE ((UINTN)MmCommMemRegion->NumberOfPages);
77 if (CommBufferSize >= (sizeof (EFI_MM_COMMUNICATE_HEADER) + mVarCheckHiiBinSize)) {
78 break;
79 }
80 }
81
82 MmCommMemRegion = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)MmCommMemRegion + PiSmmCommunicationRegionTable->DescriptorSize);
83 }
84
85 if (Index >= PiSmmCommunicationRegionTable->NumberOfEntries) {
86 DEBUG ((DEBUG_ERROR, "%a: Failed to find a suitable memory region for MM communication!\n", __func__));
87 return;
88 }
89
90 //
91 // Prepare the communication buffer
92 //
93 CommHeader = (EFI_MM_COMMUNICATE_HEADER *)(UINTN)MmCommMemRegion->PhysicalStart;
94 CommBufferSize = OFFSET_OF (EFI_MM_COMMUNICATE_HEADER, Data) + mVarCheckHiiBinSize;
95 ZeroMem (CommHeader, CommBufferSize);
96 CopyGuid (&CommHeader->HeaderGuid, &gVarCheckReceivedHiiBinHandlerGuid);
97 CommHeader->MessageLength = mVarCheckHiiBinSize;
98 VarCheckHiiVariable = (VAR_CHECK_HII_VARIABLE_HEADER *)(CommHeader->Data);
99 CopyMem (VarCheckHiiVariable, mVarCheckHiiBin, mVarCheckHiiBinSize);
100 //
101 // Locate the MM Communication protocol and signal SMI
102 //
103 Status = gBS->LocateProtocol (&gEfiMmCommunicationProtocolGuid, NULL, (VOID **)&MmCommunication);
104
105 if (!EFI_ERROR (Status)) {
106 Status = MmCommunication->Communicate (MmCommunication, CommHeader, &CommBufferSize);
107 DEBUG ((DEBUG_INFO, "%a: Communicate to smm environment = %r\n", __func__, Status));
108 } else {
109 DEBUG ((DEBUG_ERROR, "%a: Failed to locate MmCommunication protocol - %r\n", __func__, Status));
110 return;
111 }
112
113 DEBUG ((DEBUG_INFO, "%a ends.\n", __func__));
114 return;
115}
116
124EFIAPI
126 IN EFI_HANDLE ImageHandle,
127 IN EFI_SYSTEM_TABLE *SystemTable
128 )
129{
130 EFI_STATUS Status;
131 EFI_EVENT Event;
132
133 DEBUG ((DEBUG_INFO, "%a starts.\n", __func__));
134 Status = gBS->CreateEventEx (EVT_NOTIFY_SIGNAL, TPL_NOTIFY, VarCheckHiiLibSmmEndOfDxeNotify, NULL, &gEfiEndOfDxeEventGroupGuid, &Event);
135 ASSERT_EFI_ERROR (Status);
136 DEBUG ((DEBUG_INFO, "%a ends.\n", __func__));
137 return Status;
138}
UINT64 UINTN
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
GUID *EFIAPI CopyGuid(OUT GUID *DestinationGuid, IN CONST GUID *SourceGuid)
Definition: MemLibGuid.c:39
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define OFFSET_OF(TYPE, Field)
Definition: Base.h:758
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define EFI_PAGES_TO_SIZE(Pages)
Definition: UefiBaseType.h:213
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_EVENT
Definition: UefiBaseType.h:37
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
EFI_BOOT_SERVICES * gBS
EFI_STATUS EFIAPI EfiGetSystemConfigurationTable(IN EFI_GUID *TableGuid, OUT VOID **Table)
Definition: UefiLib.c:82
@ EfiConventionalMemory
VOID EFIAPI VarCheckHiiGen(VOID)
EFI_STATUS EFIAPI VarCheckHiiLibMmDependencyConstructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
VOID EFIAPI VarCheckHiiLibSmmEndOfDxeNotify(IN EFI_EVENT Event, IN VOID *Context)
EFI_PHYSICAL_ADDRESS PhysicalStart
Definition: UefiSpec.h:155
Definition: Base.h:213