/* One notified function to cleanup the allocated DMA buffers at the end of PEI. */
EFI_STATUS EFIAPI UfsEndOfPei(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)
/* One notified function to cleanup the allocated DMA buffers at the end of PEI. */
EFI_STATUS EFIAPI UfsEndOfPei(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)
{
  UFS_PEIM_HC_PRIVATE_DATA  *Private;
  Private = GET_UFS_PEIM_HC_PRIVATE_DATA_FROM_THIS_NOTIFY (NotifyDescriptor);
  if ((Private->Pool != NULL) && (Private->Pool->Head != NULL)) {
    UfsPeimFreeMemPool (Private->Pool);
  }
  if (Private->UtpTmrlBase != NULL) {
    IoMmuFreeBuffer (
      EFI_SIZE_TO_PAGES (Private->Nutmrs * sizeof (UTP_TMRD)),
      Private->UtpTmrlBase,
      Private->TmrlMapping
      );
  }
  if (Private->UtpTrlBase != NULL) {
    IoMmuFreeBuffer (
      EFI_SIZE_TO_PAGES (Private->Nutrs * sizeof (UTP_TRD)),
      Private->UtpTrlBase,
      Private->TrlMapping
      );
  }
  UfsControllerStop (Private);
  return EFI_SUCCESS;
}