]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsBlockIoPei.c
MdeModulePkg/UfsBlockIoPei: Support IoMmu
[mirror_edk2.git] / MdeModulePkg / Bus / Ufs / UfsBlockIoPei / UfsBlockIoPei.c
index ddeee3e1bc53e440303c375797a9a24165835042..9282309e84f522cc756fb694fb66f40dbda3a563 100644 (file)
@@ -107,13 +107,20 @@ UFS_PEIM_HC_PRIVATE_DATA   gUfsHcPeimTemplate = {
       0\r
     }\r
   },\r
+  {                               // EndOfPeiNotifyList\r
+    (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
+    &gEfiEndOfPeiSignalPpiGuid,\r
+    UfsEndOfPei\r
+  },\r
   0,                              // UfsHcBase\r
   0,                              // Capabilities\r
   0,                              // TaskTag\r
   0,                              // UtpTrlBase\r
   0,                              // Nutrs\r
+  NULL,                           // TrlMapping\r
   0,                              // UtpTmrlBase\r
   0,                              // Nutmrs\r
+  NULL,                           // TmrlMapping\r
   {                               // Luns\r
     {\r
       UFS_LUN_0,                      // Ufs Common Lun 0\r
@@ -1061,6 +1068,54 @@ UfsBlockIoPeimReadBlocks2 (
   return Status;\r
 }\r
 \r
+/**\r
+  One notified function to cleanup the allocated DMA buffers at the end of PEI.\r
+\r
+  @param[in]  PeiServices        Pointer to PEI Services Table.\r
+  @param[in]  NotifyDescriptor   Pointer to the descriptor for the Notification\r
+                                 event that caused this function to execute.\r
+  @param[in]  Ppi                Pointer to the PPI data associated with this function.\r
+\r
+  @retval     EFI_SUCCESS  The function completes successfully\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+UfsEndOfPei (\r
+  IN EFI_PEI_SERVICES           **PeiServices,\r
+  IN EFI_PEI_NOTIFY_DESCRIPTOR  *NotifyDescriptor,\r
+  IN VOID                       *Ppi\r
+  )\r
+{\r
+  UFS_PEIM_HC_PRIVATE_DATA    *Private;\r
+\r
+  Private = GET_UFS_PEIM_HC_PRIVATE_DATA_FROM_THIS_NOTIFY (NotifyDescriptor);\r
+\r
+  if ((Private->Pool != NULL) && (Private->Pool->Head != NULL)) {\r
+    UfsPeimFreeMemPool (Private->Pool);\r
+  }\r
+\r
+  if (Private->UtpTmrlBase != NULL) {\r
+    IoMmuFreeBuffer (\r
+      EFI_SIZE_TO_PAGES (Private->Nutmrs * sizeof (UTP_TMRD)),\r
+      Private->UtpTmrlBase,\r
+      Private->TmrlMapping\r
+      );\r
+  }\r
+\r
+  if (Private->UtpTrlBase != NULL) {\r
+    IoMmuFreeBuffer (\r
+      EFI_SIZE_TO_PAGES (Private->Nutrs * sizeof (UTP_TRD)),\r
+      Private->UtpTrlBase,\r
+      Private->TrlMapping\r
+      );\r
+  }\r
+\r
+  UfsControllerStop (Private);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
 /**\r
   The user code starts with this function.\r
   \r
@@ -1106,6 +1161,8 @@ InitializeUfsBlockIoPeim (
     return EFI_DEVICE_ERROR;\r
   }\r
 \r
+  IoMmuInit ();\r
+\r
   Controller = 0;\r
   MmioBase   = 0;\r
   while (TRUE) {\r
@@ -1185,7 +1242,8 @@ InitializeUfsBlockIoPeim (
       }\r
     }\r
     \r
-    Status = PeiServicesInstallPpi (&Private->BlkIoPpiList);\r
+    PeiServicesInstallPpi (&Private->BlkIoPpiList);\r
+    PeiServicesNotifyPpi (&Private->EndOfPeiNotifyList);\r
     Controller++;\r
   }\r
 \r