MdeModulePkg: Add Unmap Callback

Add Unmap callback for when PEI and SEC need to invalidate the
Rx/Tx buffer HOB on a call to Unmap.

Signed-off-by: Raymond Diaz <raymonddiaz@microsoft.com>
diff --git a/MdeModulePkg/Library/ArmFfaLib/ArmFfaDxeLib.c b/MdeModulePkg/Library/ArmFfaLib/ArmFfaDxeLib.c
index 8e0eecf..4d53dcf 100644
--- a/MdeModulePkg/Library/ArmFfaLib/ArmFfaDxeLib.c
+++ b/MdeModulePkg/Library/ArmFfaLib/ArmFfaDxeLib.c
@@ -231,3 +231,17 @@
 {

   return mIsFfaSupported;

 }

+

+/**

+  Callback for when Unmap is called to handle any post unmap

+  functionality.

+

+**/

+VOID

+EFIAPI

+UnmapCallback (

+  IN VOID

+  )

+{

+  // Do nothing

+}

diff --git a/MdeModulePkg/Library/ArmFfaLib/ArmFfaPeiLib.c b/MdeModulePkg/Library/ArmFfaLib/ArmFfaPeiLib.c
index 7a9080a..7ce6bf6 100644
--- a/MdeModulePkg/Library/ArmFfaLib/ArmFfaPeiLib.c
+++ b/MdeModulePkg/Library/ArmFfaLib/ArmFfaPeiLib.c
@@ -291,3 +291,33 @@
 

   return ArmFfaLibIsFfaSupported ();

 }

+

+/**

+  Callback for when Unmap is called to handle any post unmap

+  functionality. In PEI the Rx/Tx buffer HOB needs to be

+  invalidated.

+

+**/

+VOID

+EFIAPI

+UnmapCallback (

+  IN VOID

+  )

+{

+  EFI_HOB_MEMORY_ALLOCATION  *RxTxBufferAllocationHob;

+

+  /*

+   * Rx/Tx buffers are allocated with continuous pages.

+   * See ArmFfaLibRxTxMap(). If HOB is not found, the Rx/Tx

+   * buffers were not successfully mapped.

+   */

+  RxTxBufferAllocationHob = FindRxTxBufferAllocationHob (TRUE);

+  if (RxTxBufferAllocationHob == NULL) {

+    return;

+  }

+

+  /*

+   * Invalidate the HOB.

+   */

+  ZeroMem (RxTxBufferAllocationHob, sizeof (ARM_FFA_RX_TX_BUFFER_INFO));

+}

diff --git a/MdeModulePkg/Library/ArmFfaLib/ArmFfaRxTxMap.c b/MdeModulePkg/Library/ArmFfaLib/ArmFfaRxTxMap.c
index ceb3010..411d880 100644
--- a/MdeModulePkg/Library/ArmFfaLib/ArmFfaRxTxMap.c
+++ b/MdeModulePkg/Library/ArmFfaLib/ArmFfaRxTxMap.c
@@ -218,6 +218,8 @@
   PcdSet64S (PcdFfaTxBuffer, 0x00);

   PcdSet64S (PcdFfaRxBuffer, 0x00);

 

+  UnmapCallback ();

+

   return EFI_SUCCESS;

 }

 

diff --git a/MdeModulePkg/Library/ArmFfaLib/ArmFfaRxTxMap.h b/MdeModulePkg/Library/ArmFfaLib/ArmFfaRxTxMap.h
index 5140865..87e2545 100644
--- a/MdeModulePkg/Library/ArmFfaLib/ArmFfaRxTxMap.h
+++ b/MdeModulePkg/Library/ArmFfaLib/ArmFfaRxTxMap.h
@@ -96,4 +96,15 @@
   IN OUT ARM_FFA_RX_TX_BUFFER_INFO  *BufferInfo

   );

 

+/**

+  Callback for when Unmap is called to handle any post unmap

+  functionality.

+

+**/

+VOID

+EFIAPI

+UnmapCallback (

+  IN VOID

+  );

+

 #endif

diff --git a/MdeModulePkg/Library/ArmFfaLib/ArmFfaSecLib.c b/MdeModulePkg/Library/ArmFfaLib/ArmFfaSecLib.c
index c0468dd..4f20674 100644
--- a/MdeModulePkg/Library/ArmFfaLib/ArmFfaSecLib.c
+++ b/MdeModulePkg/Library/ArmFfaLib/ArmFfaSecLib.c
@@ -132,3 +132,33 @@
 {

   return ArmFfaLibIsFfaSupported ();

 }

+

+/**

+  Callback for when Unmap is called to handle any post unmap

+  functionality. In SEC, the Rx/Tx buffer HOB needs to be

+  invalidated.

+

+**/

+VOID

+EFIAPI

+UnmapCallback (

+  IN VOID

+  )

+{

+  EFI_HOB_MEMORY_ALLOCATION  *RxTxBufferAllocationHob;

+

+  /*

+   * Rx/Tx buffers are allocated with continuous pages.

+   * See ArmFfaLibRxTxMap(). If HOB is not found, the Rx/Tx

+   * buffers were not successfully mapped.

+   */

+  RxTxBufferAllocationHob = FindRxTxBufferAllocationHob (TRUE);

+  if (RxTxBufferAllocationHob == NULL) {

+    return;

+  }

+

+  /*

+   * Invalidate the HOB.

+   */

+  ZeroMem (RxTxBufferAllocationHob, sizeof (ARM_FFA_RX_TX_BUFFER_INFO));

+}

diff --git a/MdeModulePkg/Library/ArmFfaLib/ArmFfaSecRxTxMap.c b/MdeModulePkg/Library/ArmFfaLib/ArmFfaSecRxTxMap.c
index 80fc5a5..7840213 100644
--- a/MdeModulePkg/Library/ArmFfaLib/ArmFfaSecRxTxMap.c
+++ b/MdeModulePkg/Library/ArmFfaLib/ArmFfaSecRxTxMap.c
@@ -332,6 +332,8 @@
     FreePages (Buffers, (PcdGet64 (PcdFfaTxRxPageCount) * 2));

   }

 

+  UnmapCallback ();

+

   return EFI_SUCCESS;

 }

 

diff --git a/MdeModulePkg/Library/ArmFfaLib/ArmFfaStandaloneMmLib.c b/MdeModulePkg/Library/ArmFfaLib/ArmFfaStandaloneMmLib.c
index b1e8af3..9e05fb0 100644
--- a/MdeModulePkg/Library/ArmFfaLib/ArmFfaStandaloneMmLib.c
+++ b/MdeModulePkg/Library/ArmFfaLib/ArmFfaStandaloneMmLib.c
@@ -127,3 +127,17 @@
 {

   return mIsFfaSupported;

 }

+

+/**

+  Callback for when Unmap is called to handle any post unmap

+  functionality.

+

+**/

+VOID

+EFIAPI

+UnmapCallback (

+  IN VOID

+  )

+{

+  // Do nothing

+}