73 IN OUT VOID *CommBufferPhysical,
74 IN OUT VOID *CommBufferVirtual,
83 Status = EFI_ACCESS_DENIED;
91 if ((CommBufferVirtual ==
NULL) || (CommBufferPhysical ==
NULL)) {
92 return EFI_INVALID_PARAMETER;
96 CommunicateHeader = CommBufferVirtual;
106 if (CommSize !=
NULL) {
109 if ((*CommSize == 0) ||
110 (*CommSize > mNsCommBuffMemRegion.Length))
112 *CommSize = mNsCommBuffMemRegion.Length;
113 Status = EFI_BAD_BUFFER_SIZE;
119 if (*CommSize < BufferSize) {
120 Status = EFI_INVALID_PARAMETER;
129 (BufferSize > mNsCommBuffMemRegion.Length))
131 CommunicateHeader->
MessageLength = mNsCommBuffMemRegion.Length -
134 Status = EFI_BAD_BUFFER_SIZE;
138 if (EFI_ERROR (Status)) {
143 CommunicateSmcArgs.Arg0 = ARM_SMC_ID_MM_COMMUNICATE_AARCH64;
146 CommunicateSmcArgs.Arg1 = 0;
149 CopyMem ((VOID *)mNsCommBuffMemRegion.VirtualBase, CommBufferVirtual, BufferSize);
152 CommunicateSmcArgs.Arg2 = (
UINTN)mNsCommBuffMemRegion.PhysicalBase;
155 CommunicateSmcArgs.Arg3 = 0;
160 switch (CommunicateSmcArgs.Arg0) {
161 case ARM_SMC_MM_RET_SUCCESS:
162 ZeroMem (CommBufferVirtual, BufferSize);
172 (VOID *)mNsCommBuffMemRegion.VirtualBase,
178 case ARM_SMC_MM_RET_INVALID_PARAMS:
179 Status = EFI_INVALID_PARAMETER;
182 case ARM_SMC_MM_RET_DENIED:
183 Status = EFI_ACCESS_DENIED;
186 case ARM_SMC_MM_RET_NO_MEMORY:
189 Status = EFI_OUT_OF_RESOURCES;
194 Status = EFI_ACCESS_DENIED;
232 Status =
gRT->ConvertPointer (
234 (VOID **)&mNsCommBuffMemRegion.VirtualBase
236 if (EFI_ERROR (Status)) {
239 "NotifySetVirtualAddressMap():"
240 " Unable to convert MM runtime pointer. Status:0x%r\n",
256 MmVersionArgs.Arg0 = ARM_SMC_ID_MM_VERSION_AARCH32;
260 MmVersion = MmVersionArgs.Arg0;
262 if ((MM_MAJOR_VER (MmVersion) == MM_CALLER_MAJOR_VER) &&
263 (MM_MINOR_VER (MmVersion) >= MM_CALLER_MINOR_VER))
267 "MM Version: Major=0x%x, Minor=0x%x\n",
268 MM_MAJOR_VER (MmVersion),
269 MM_MINOR_VER (MmVersion)
275 "Incompatible MM Versions.\n Current Version: Major=0x%x, Minor=0x%x.\n Expected: Major=0x%x, Minor>=0x%x.\n",
276 MM_MAJOR_VER (MmVersion),
277 MM_MINOR_VER (MmVersion),
281 Status = EFI_UNSUPPORTED;
288 &gEfiEndOfDxeEventGroupGuid,
289 &gEfiEventExitBootServicesGuid,
290 &gEfiEventReadyToBootGuid,
316 CopyGuid (&Header.HeaderGuid, Context);
317 Header.MessageLength = 1;
320 Size =
sizeof (Header);
349 Status = GetMmCompatibility ();
350 if (EFI_ERROR (Status)) {
351 goto ReturnErrorStatus;
354 mNsCommBuffMemRegion.PhysicalBase =
PcdGet64 (PcdMmBufferBase);
356 mNsCommBuffMemRegion.VirtualBase = mNsCommBuffMemRegion.PhysicalBase;
357 mNsCommBuffMemRegion.Length =
PcdGet64 (PcdMmBufferSize);
359 ASSERT (mNsCommBuffMemRegion.PhysicalBase != 0);
361 ASSERT (mNsCommBuffMemRegion.Length != 0);
363 Status =
gDS->AddMemorySpace (
365 mNsCommBuffMemRegion.PhysicalBase,
366 mNsCommBuffMemRegion.Length,
371 if (EFI_ERROR (Status)) {
374 "MmCommunicateInitialize: "
375 "Failed to add MM-NS Buffer Memory Space\n"
377 goto ReturnErrorStatus;
380 Status =
gDS->SetMemorySpaceAttributes (
381 mNsCommBuffMemRegion.PhysicalBase,
382 mNsCommBuffMemRegion.Length,
383 EFI_MEMORY_WB | EFI_MEMORY_XP | EFI_MEMORY_RUNTIME
385 if (EFI_ERROR (Status)) {
388 "MmCommunicateInitialize: "
389 "Failed to set MM-NS Buffer Memory attributes\n"
391 goto CleanAddedMemorySpace;
395 Status =
gBS->InstallProtocolInterface (
396 &mMmCommunicateHandle,
397 &gEfiMmCommunication2ProtocolGuid,
401 if (EFI_ERROR (Status)) {
404 "MmCommunicationInitialize: "
405 "Failed to install MM communication protocol\n"
407 goto CleanAddedMemorySpace;
413 Status =
gBS->CreateEvent (
414 EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,
418 &mSetVirtualAddressMapEvent
422 for (Index = 0; Index <
ARRAY_SIZE (mGuidedEventGuid); Index++) {
423 Status =
gBS->CreateEventEx (
427 mGuidedEventGuid[Index],
428 mGuidedEventGuid[Index],
432 if (EFI_ERROR (Status)) {
433 while (Index-- > 0) {
434 gBS->CloseEvent (mGuidedEvent[Index]);
437 goto UninstallProtocol;
444 gBS->UninstallProtocolInterface (
445 mMmCommunicateHandle,
446 &gEfiMmCommunication2ProtocolGuid,
450CleanAddedMemorySpace:
451 gDS->RemoveMemorySpace (
452 mNsCommBuffMemRegion.PhysicalBase,
453 mNsCommBuffMemRegion.Length
457 return EFI_INVALID_PARAMETER;
VOID ArmCallSmc(IN OUT ARM_SMC_ARGS *Args)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
GUID *EFIAPI CopyGuid(OUT GUID *DestinationGuid, IN CONST GUID *SourceGuid)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
EFI_RUNTIME_SERVICES * gRT
#define ARRAY_SIZE(Array)
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
EFI_STATUS EFIAPI MmCommunication2Initialize(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
STATIC VOID EFIAPI NotifySetVirtualAddressMap(IN EFI_EVENT Event, IN VOID *Context)
EFI_STATUS EFIAPI MmCommunication2Communicate(IN CONST EFI_MM_COMMUNICATION2_PROTOCOL *This, IN OUT VOID *CommBufferPhysical, IN OUT VOID *CommBufferVirtual, IN OUT UINTN *CommSize OPTIONAL)
STATIC VOID EFIAPI MmGuidedEventNotify(IN EFI_EVENT Event, IN VOID *Context)
#define PcdGet64(TokenName)
@ EfiGcdMemoryTypeReserved