]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/EmmcBlockIoPei: Support IoMmu
authorHao Wu <hao.a.wu@intel.com>
Mon, 30 Oct 2017 03:15:08 +0000 (11:15 +0800)
committerHao Wu <hao.a.wu@intel.com>
Fri, 17 Nov 2017 03:38:43 +0000 (11:38 +0800)
Update the EmmcBlockIoPei driver to consume IOMMU_PPI to allocate DMA
buffer.

If no IOMMU_PPI exists, this driver still calls PEI service
to allocate DMA buffer, with assumption that DRAM==DMA.

This is a compatible change.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
MdeModulePkg/Bus/Sd/EmmcBlockIoPei/DmaMem.c [new file with mode: 0644]
MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcBlockIoPei.c
MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcBlockIoPei.h
MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcBlockIoPei.inf
MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcHcMem.c
MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcHcMem.h
MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcHci.c

diff --git a/MdeModulePkg/Bus/Sd/EmmcBlockIoPei/DmaMem.c b/MdeModulePkg/Bus/Sd/EmmcBlockIoPei/DmaMem.c
new file mode 100644 (file)
index 0000000..29fb37c
--- /dev/null
@@ -0,0 +1,249 @@
+/** @file\r
+  The DMA memory help function.\r
+\r
+  Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions\r
+  of the BSD License which accompanies this distribution.  The\r
+  full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "EmmcBlockIoPei.h"\r
+\r
+EDKII_IOMMU_PPI  *mIoMmu;\r
+\r
+/**\r
+  Provides the controller-specific addresses required to access system memory from a\r
+  DMA bus master.\r
+\r
+  @param  Operation             Indicates if the bus master is going to read or write to system memory.\r
+  @param  HostAddress           The system memory address to map to the PCI controller.\r
+  @param  NumberOfBytes         On input the number of bytes to map. On output the number of bytes\r
+                                that were mapped.\r
+  @param  DeviceAddress         The resulting map address for the bus master PCI controller to use to\r
+                                access the hosts HostAddress.\r
+  @param  Mapping               A resulting value to pass to Unmap().\r
+\r
+  @retval EFI_SUCCESS           The range was mapped for the returned NumberOfBytes.\r
+  @retval EFI_UNSUPPORTED       The HostAddress cannot be mapped as a common buffer.\r
+  @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
+  @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack of resources.\r
+  @retval EFI_DEVICE_ERROR      The system hardware could not map the requested address.\r
+\r
+**/\r
+EFI_STATUS\r
+IoMmuMap (\r
+  IN  EDKII_IOMMU_OPERATION Operation,\r
+  IN VOID                   *HostAddress,\r
+  IN  OUT UINTN             *NumberOfBytes,\r
+  OUT EFI_PHYSICAL_ADDRESS  *DeviceAddress,\r
+  OUT VOID                  **Mapping\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  UINT64      Attribute;\r
+\r
+  if (mIoMmu != NULL) {\r
+    Status = mIoMmu->Map (\r
+                       mIoMmu,\r
+                       Operation,\r
+                       HostAddress,\r
+                       NumberOfBytes,\r
+                       DeviceAddress,\r
+                       Mapping\r
+                       );\r
+    if (EFI_ERROR (Status)) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    switch (Operation) {\r
+    case EdkiiIoMmuOperationBusMasterRead:\r
+    case EdkiiIoMmuOperationBusMasterRead64:\r
+      Attribute = EDKII_IOMMU_ACCESS_READ;\r
+      break;\r
+    case EdkiiIoMmuOperationBusMasterWrite:\r
+    case EdkiiIoMmuOperationBusMasterWrite64:\r
+      Attribute = EDKII_IOMMU_ACCESS_WRITE;\r
+      break;\r
+    case EdkiiIoMmuOperationBusMasterCommonBuffer:\r
+    case EdkiiIoMmuOperationBusMasterCommonBuffer64:\r
+      Attribute = EDKII_IOMMU_ACCESS_READ | EDKII_IOMMU_ACCESS_WRITE;\r
+      break;\r
+    default:\r
+      ASSERT(FALSE);\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+    Status = mIoMmu->SetAttribute (\r
+                       mIoMmu,\r
+                       *Mapping,\r
+                       Attribute\r
+                       );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+  } else {\r
+    *DeviceAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)HostAddress;\r
+    *Mapping = NULL;\r
+    Status = EFI_SUCCESS;\r
+  }\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Completes the Map() operation and releases any corresponding resources.\r
+\r
+  @param  Mapping               The mapping value returned from Map().\r
+\r
+  @retval EFI_SUCCESS           The range was unmapped.\r
+  @retval EFI_INVALID_PARAMETER Mapping is not a value that was returned by Map().\r
+  @retval EFI_DEVICE_ERROR      The data was not committed to the target system memory.\r
+**/\r
+EFI_STATUS\r
+IoMmuUnmap (\r
+  IN VOID                  *Mapping\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  if (mIoMmu != NULL) {\r
+    Status = mIoMmu->SetAttribute (mIoMmu, Mapping, 0);\r
+    Status = mIoMmu->Unmap (mIoMmu, Mapping);\r
+  } else {\r
+    Status = EFI_SUCCESS;\r
+  }\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Allocates pages that are suitable for an OperationBusMasterCommonBuffer or\r
+  OperationBusMasterCommonBuffer64 mapping.\r
+\r
+  @param  Pages                 The number of pages to allocate.\r
+  @param  HostAddress           A pointer to store the base system memory address of the\r
+                                allocated range.\r
+  @param  DeviceAddress         The resulting map address for the bus master PCI controller to use to\r
+                                access the hosts HostAddress.\r
+  @param  Mapping               A resulting value to pass to Unmap().\r
+\r
+  @retval EFI_SUCCESS           The requested memory pages were allocated.\r
+  @retval EFI_UNSUPPORTED       Attributes is unsupported. The only legal attribute bits are\r
+                                MEMORY_WRITE_COMBINE and MEMORY_CACHED.\r
+  @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
+  @retval EFI_OUT_OF_RESOURCES  The memory pages could not be allocated.\r
+\r
+**/\r
+EFI_STATUS\r
+IoMmuAllocateBuffer (\r
+  IN UINTN                  Pages,\r
+  OUT VOID                  **HostAddress,\r
+  OUT EFI_PHYSICAL_ADDRESS  *DeviceAddress,\r
+  OUT VOID                  **Mapping\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  UINTN                 NumberOfBytes;\r
+  EFI_PHYSICAL_ADDRESS  HostPhyAddress;\r
+\r
+  *HostAddress = NULL;\r
+  *DeviceAddress = 0;\r
+\r
+  if (mIoMmu != NULL) {\r
+    Status = mIoMmu->AllocateBuffer (\r
+                       mIoMmu,\r
+                       EfiBootServicesData,\r
+                       Pages,\r
+                       HostAddress,\r
+                       0\r
+                       );\r
+    if (EFI_ERROR (Status)) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+\r
+    NumberOfBytes = EFI_PAGES_TO_SIZE(Pages);\r
+    Status = mIoMmu->Map (\r
+                       mIoMmu,\r
+                       EdkiiIoMmuOperationBusMasterCommonBuffer,\r
+                       *HostAddress,\r
+                       &NumberOfBytes,\r
+                       DeviceAddress,\r
+                       Mapping\r
+                       );\r
+    if (EFI_ERROR (Status)) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    Status = mIoMmu->SetAttribute (\r
+                       mIoMmu,\r
+                       *Mapping,\r
+                       EDKII_IOMMU_ACCESS_READ | EDKII_IOMMU_ACCESS_WRITE\r
+                       );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+  } else {\r
+    Status = PeiServicesAllocatePages (\r
+               EfiBootServicesData,\r
+               Pages,\r
+               &HostPhyAddress\r
+               );\r
+    if (EFI_ERROR (Status)) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    *HostAddress = (VOID *)(UINTN)HostPhyAddress;\r
+    *DeviceAddress = HostPhyAddress;\r
+    *Mapping = NULL;\r
+  }\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Frees memory that was allocated with AllocateBuffer().\r
+\r
+  @param  Pages                 The number of pages to free.\r
+  @param  HostAddress           The base system memory address of the allocated range.\r
+  @param  Mapping               The mapping value returned from Map().\r
+\r
+  @retval EFI_SUCCESS           The requested memory pages were freed.\r
+  @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages\r
+                                was not allocated with AllocateBuffer().\r
+\r
+**/\r
+EFI_STATUS\r
+IoMmuFreeBuffer (\r
+  IN UINTN                  Pages,\r
+  IN VOID                   *HostAddress,\r
+  IN VOID                   *Mapping\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  if (mIoMmu != NULL) {\r
+    Status = mIoMmu->SetAttribute (mIoMmu, Mapping, 0);\r
+    Status = mIoMmu->Unmap (mIoMmu, Mapping);\r
+    Status = mIoMmu->FreeBuffer (mIoMmu, Pages, HostAddress);\r
+  } else {\r
+    Status = EFI_SUCCESS;\r
+  }\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Initialize IOMMU.\r
+**/\r
+VOID\r
+IoMmuInit (\r
+  VOID\r
+  )\r
+{\r
+  PeiServicesLocatePpi (\r
+    &gEdkiiIoMmuPpiGuid,\r
+    0,\r
+    NULL,\r
+    (VOID **)&mIoMmu\r
+    );\r
+}\r
+\r
index 004670cb28c7ae6cb858f99838aecc39c7fe4475..9ed4e8f95ae960d7bb735e2207840a146565a3a0 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-  Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -136,6 +136,11 @@ EMMC_PEIM_HC_PRIVATE_DATA gEmmcHcPrivateTemplate = {
     &gEfiPeiVirtualBlockIo2PpiGuid,\r
     NULL\r
   },\r
+  {                               // EndOfPeiNotifyList\r
+    (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
+    &gEfiEndOfPeiSignalPpiGuid,\r
+    EmmcBlockIoPeimEndOfPei\r
+  },\r
   {                               // Slot\r
     {\r
       0,\r
@@ -618,6 +623,36 @@ EmmcBlockIoPeimReadBlocks2 (
   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
+EmmcBlockIoPeimEndOfPei (\r
+  IN EFI_PEI_SERVICES           **PeiServices,\r
+  IN EFI_PEI_NOTIFY_DESCRIPTOR  *NotifyDescriptor,\r
+  IN VOID                       *Ppi\r
+  )\r
+{\r
+  EMMC_PEIM_HC_PRIVATE_DATA       *Private;\r
+\r
+  Private = GET_EMMC_PEIM_HC_PRIVATE_DATA_FROM_THIS_NOTIFY (NotifyDescriptor);\r
+\r
+  if ((Private->Pool != NULL) && (Private->Pool->Head != NULL)) {\r
+    EmmcPeimFreeMemPool (Private->Pool);\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
 /**\r
   The user code starts with this function.\r
 \r
@@ -672,6 +707,8 @@ InitializeEmmcBlockIoPeim (
     return EFI_DEVICE_ERROR;\r
   }\r
 \r
+  IoMmuInit ();\r
+\r
   Controller = 0;\r
   MmioBase   = NULL;\r
   while (TRUE) {\r
@@ -800,6 +837,11 @@ InitializeEmmcBlockIoPeim (
 \r
     if (!EFI_ERROR (Status)) {\r
       PeiServicesInstallPpi (&Private->BlkIoPpiList);\r
+      PeiServicesNotifyPpi (&Private->EndOfPeiNotifyList);\r
+    } else {\r
+      if (Private->Pool->Head != NULL) {\r
+        EmmcPeimFreeMemPool (Private->Pool);\r
+      }\r
     }\r
   }\r
 \r
index 5c8b740e4f47b3d7685abac997562bf25654525a..b89db8a03f55dcf3ce96b41a05f446d07247759c 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-  Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -19,6 +19,8 @@
 #include <Ppi/SdMmcHostController.h>\r
 #include <Ppi/BlockIo.h>\r
 #include <Ppi/BlockIo2.h>\r
+#include <Ppi/IoMmu.h>\r
+#include <Ppi/EndOfPeiPhase.h>\r
 \r
 #include <Library/DebugLib.h>\r
 #include <Library/BaseLib.h>\r
@@ -64,6 +66,12 @@ struct _EMMC_PEIM_HC_PRIVATE_DATA {
   EFI_PEI_RECOVERY_BLOCK_IO2_PPI    BlkIo2Ppi;\r
   EFI_PEI_PPI_DESCRIPTOR            BlkIoPpiList;\r
   EFI_PEI_PPI_DESCRIPTOR            BlkIo2PpiList;\r
+\r
+  //\r
+  // EndOfPei callback is used to do the cleanups before exit of PEI phase.\r
+  //\r
+  EFI_PEI_NOTIFY_DESCRIPTOR         EndOfPeiNotifyList;\r
+\r
   EMMC_PEIM_HC_SLOT                 Slot[EMMC_PEIM_MAX_SLOTS];\r
   UINT8                             SlotNum;\r
   UINT8                             TotalBlkIoDevices;\r
@@ -72,6 +80,7 @@ struct _EMMC_PEIM_HC_PRIVATE_DATA {
 #define EMMC_TIMEOUT                MultU64x32((UINT64)(3), 1000000)\r
 #define GET_EMMC_PEIM_HC_PRIVATE_DATA_FROM_THIS(a) CR (a, EMMC_PEIM_HC_PRIVATE_DATA, BlkIoPpi, EMMC_PEIM_SIG)\r
 #define GET_EMMC_PEIM_HC_PRIVATE_DATA_FROM_THIS2(a) CR (a, EMMC_PEIM_HC_PRIVATE_DATA, BlkIo2Ppi, EMMC_PEIM_SIG)\r
+#define GET_EMMC_PEIM_HC_PRIVATE_DATA_FROM_THIS_NOTIFY(a) CR (a, EMMC_PEIM_HC_PRIVATE_DATA, EndOfPeiNotifyList, EMMC_PEIM_SIG)\r
 \r
 struct _EMMC_TRB {\r
   EMMC_PEIM_HC_SLOT                   *Slot;\r
@@ -81,6 +90,8 @@ struct _EMMC_TRB {
   VOID                                *Data;\r
   UINT32                              DataLen;\r
   BOOLEAN                             Read;\r
+  EFI_PHYSICAL_ADDRESS                DataPhy;\r
+  VOID                                *DataMap;\r
   EMMC_HC_TRANSFER_MODE               Mode;\r
 \r
   UINT64                              Timeout;\r
@@ -347,6 +358,20 @@ EmmcPeimInitMemPool (
   IN  EMMC_PEIM_HC_PRIVATE_DATA      *Private\r
   );\r
 \r
+/**\r
+  Release the memory management pool.\r
+\r
+  @param  Pool                  The memory pool to free.\r
+\r
+  @retval EFI_DEVICE_ERROR      Fail to free the memory pool.\r
+  @retval EFI_SUCCESS           The memory pool is freed.\r
+\r
+**/\r
+EFI_STATUS\r
+EmmcPeimFreeMemPool (\r
+  IN EMMC_PEIM_MEM_POOL       *Pool\r
+  );\r
+\r
 /**\r
   Allocate some memory from the host controller's memory pool\r
   which can be used to communicate with host controller.\r
@@ -378,4 +403,118 @@ EmmcPeimFreeMem (
   IN UINTN                Size\r
   );\r
 \r
+/**\r
+  Initialize IOMMU.\r
+**/\r
+VOID\r
+IoMmuInit (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Provides the controller-specific addresses required to access system memory from a\r
+  DMA bus master.\r
+\r
+  @param  Operation             Indicates if the bus master is going to read or write to system memory.\r
+  @param  HostAddress           The system memory address to map to the PCI controller.\r
+  @param  NumberOfBytes         On input the number of bytes to map. On output the number of bytes\r
+                                that were mapped.\r
+  @param  DeviceAddress         The resulting map address for the bus master PCI controller to use to\r
+                                access the hosts HostAddress.\r
+  @param  Mapping               A resulting value to pass to Unmap().\r
+\r
+  @retval EFI_SUCCESS           The range was mapped for the returned NumberOfBytes.\r
+  @retval EFI_UNSUPPORTED       The HostAddress cannot be mapped as a common buffer.\r
+  @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
+  @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack of resources.\r
+  @retval EFI_DEVICE_ERROR      The system hardware could not map the requested address.\r
+\r
+**/\r
+EFI_STATUS\r
+IoMmuMap (\r
+  IN  EDKII_IOMMU_OPERATION Operation,\r
+  IN  VOID                  *HostAddress,\r
+  IN  OUT UINTN             *NumberOfBytes,\r
+  OUT EFI_PHYSICAL_ADDRESS  *DeviceAddress,\r
+  OUT VOID                  **Mapping\r
+  );\r
+\r
+/**\r
+  Completes the Map() operation and releases any corresponding resources.\r
+\r
+  @param  Mapping               The mapping value returned from Map().\r
+\r
+  @retval EFI_SUCCESS           The range was unmapped.\r
+  @retval EFI_INVALID_PARAMETER Mapping is not a value that was returned by Map().\r
+  @retval EFI_DEVICE_ERROR      The data was not committed to the target system memory.\r
+**/\r
+EFI_STATUS\r
+IoMmuUnmap (\r
+  IN VOID                  *Mapping\r
+  );\r
+\r
+/**\r
+  Allocates pages that are suitable for an OperationBusMasterCommonBuffer or\r
+  OperationBusMasterCommonBuffer64 mapping.\r
+\r
+  @param  Pages                 The number of pages to allocate.\r
+  @param  HostAddress           A pointer to store the base system memory address of the\r
+                                allocated range.\r
+  @param  DeviceAddress         The resulting map address for the bus master PCI controller to use to\r
+                                access the hosts HostAddress.\r
+  @param  Mapping               A resulting value to pass to Unmap().\r
+\r
+  @retval EFI_SUCCESS           The requested memory pages were allocated.\r
+  @retval EFI_UNSUPPORTED       Attributes is unsupported. The only legal attribute bits are\r
+                                MEMORY_WRITE_COMBINE and MEMORY_CACHED.\r
+  @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
+  @retval EFI_OUT_OF_RESOURCES  The memory pages could not be allocated.\r
+\r
+**/\r
+EFI_STATUS\r
+IoMmuAllocateBuffer (\r
+  IN UINTN                  Pages,\r
+  OUT VOID                  **HostAddress,\r
+  OUT EFI_PHYSICAL_ADDRESS  *DeviceAddress,\r
+  OUT VOID                  **Mapping\r
+  );\r
+\r
+/**\r
+  Frees memory that was allocated with AllocateBuffer().\r
+\r
+  @param  Pages                 The number of pages to free.\r
+  @param  HostAddress           The base system memory address of the allocated range.\r
+  @param  Mapping               The mapping value returned from Map().\r
+\r
+  @retval EFI_SUCCESS           The requested memory pages were freed.\r
+  @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages\r
+                                was not allocated with AllocateBuffer().\r
+\r
+**/\r
+EFI_STATUS\r
+IoMmuFreeBuffer (\r
+  IN UINTN                  Pages,\r
+  IN VOID                   *HostAddress,\r
+  IN VOID                   *Mapping\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
+EmmcBlockIoPeimEndOfPei (\r
+  IN EFI_PEI_SERVICES           **PeiServices,\r
+  IN EFI_PEI_NOTIFY_DESCRIPTOR  *NotifyDescriptor,\r
+  IN VOID                       *Ppi\r
+  );\r
+\r
 #endif\r
index 4163b528b8930f4f7f4b58213d5696fa076cd9a6..b4127b791dce2cac00bd83f5a14af37473a8b828 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # Description file for the Embedded MMC (eMMC) Peim driver.\r
 #\r
-# Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -36,6 +36,7 @@
   EmmcHci.h\r
   EmmcHcMem.c\r
   EmmcHcMem.h\r
+  DmaMem.c\r
 \r
 [Packages]\r
   MdePkg/MdePkg.dec\r
@@ -53,6 +54,8 @@
   gEfiPeiVirtualBlockIoPpiGuid                  ## PRODUCES\r
   gEfiPeiVirtualBlockIo2PpiGuid                 ## PRODUCES\r
   gEdkiiPeiSdMmcHostControllerPpiGuid           ## CONSUMES\r
+  gEdkiiIoMmuPpiGuid                            ## CONSUMES\r
+  gEfiEndOfPeiSignalPpiGuid                     ## CONSUMES\r
 \r
 [Depex]\r
   gEfiPeiMemoryDiscoveredPpiGuid AND gEdkiiPeiSdMmcHostControllerPpiGuid\r
index 0708fab047ca35a6a435ec79cee79f2cc7798804..a6f188f38555bba08fe0505be853a65e544a3505 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.<BR>\r
 \r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions\r
@@ -29,9 +29,11 @@ EmmcPeimAllocMemBlock (
   )\r
 {\r
   EMMC_PEIM_MEM_BLOCK          *Block;\r
+  VOID                         *BufHost;\r
+  VOID                         *Mapping;\r
+  EFI_PHYSICAL_ADDRESS         MappedAddr;\r
   EFI_STATUS                   Status;\r
   VOID                         *TempPtr;\r
-  EFI_PHYSICAL_ADDRESS         Address;\r
 \r
   TempPtr = NULL;\r
   Block   = NULL;\r
@@ -62,19 +64,22 @@ EmmcPeimAllocMemBlock (
 \r
   Block->Bits = (UINT8*)(UINTN)TempPtr;\r
 \r
-  Status = PeiServicesAllocatePages (\r
-             EfiBootServicesCode,\r
+  Status = IoMmuAllocateBuffer (\r
              Pages,\r
-             &Address\r
+             &BufHost,\r
+             &MappedAddr,\r
+             &Mapping\r
              );\r
   if (EFI_ERROR (Status)) {\r
     return NULL;\r
   }\r
 \r
-  ZeroMem ((VOID*)(UINTN)Address, EFI_PAGES_TO_SIZE (Pages));\r
+  ZeroMem ((VOID*)(UINTN)BufHost, EFI_PAGES_TO_SIZE (Pages));\r
 \r
-  Block->Buf  = (UINT8*)((UINTN)Address);\r
-  Block->Next = NULL;\r
+  Block->BufHost = (UINT8 *) (UINTN) BufHost;\r
+  Block->Buf     = (UINT8 *) (UINTN) MappedAddr;\r
+  Block->Mapping = Mapping;\r
+  Block->Next    = NULL;\r
 \r
   return Block;\r
 }\r
@@ -93,6 +98,8 @@ EmmcPeimFreeMemBlock (
   )\r
 {\r
   ASSERT ((Pool != NULL) && (Block != NULL));\r
+\r
+  IoMmuFreeBuffer (EFI_SIZE_TO_PAGES (Block->BufLen), Block->BufHost, Block->Mapping);\r
 }\r
 \r
 /**\r
index af0c93c61081823bc39cd611d4616f62c152539a..026064479e0db6729a4182c21a783f230de949c7 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>\r
 \r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions\r
@@ -27,7 +27,9 @@ struct _EMMC_PEIM_MEM_BLOCK {
   UINT8                   *Bits;    // Bit array to record which unit is allocated\r
   UINTN                   BitsLen;\r
   UINT8                   *Buf;\r
+  UINT8                   *BufHost;\r
   UINTN                   BufLen;   // Memory size in bytes\r
+  VOID                    *Mapping;\r
   EMMC_PEIM_MEM_BLOCK     *Next;\r
 };\r
 \r
index 7c40892da063ae6b66300e54f1d148d077eb3978..97b8dac8f5f4ced8f852a13b8b018a96bcf92f93 100644 (file)
@@ -929,7 +929,7 @@ BuildAdmaDescTable (
   UINT64                    Remaining;\r
   UINT32                    Address;\r
 \r
-  Data    = (EFI_PHYSICAL_ADDRESS)(UINTN)Trb->Data;\r
+  Data    = Trb->DataPhy;\r
   DataLen = Trb->DataLen;\r
   //\r
   // Only support 32bit ADMA Descriptor Table\r
@@ -998,6 +998,8 @@ EmmcPeimCreateTrb (
   EMMC_TRB                      *Trb;\r
   EFI_STATUS                    Status;\r
   EMMC_HC_SLOT_CAP              Capability;\r
+  EDKII_IOMMU_OPERATION         MapOp;\r
+  UINTN                         MapLength;\r
 \r
   //\r
   // Calculate a divisor for SD clock frequency\r
@@ -1007,7 +1009,7 @@ EmmcPeimCreateTrb (
     return NULL;\r
   }\r
 \r
-  Trb = EmmcPeimAllocateMem (Slot->Private->Pool, sizeof (EMMC_TRB));\r
+  Trb = AllocateZeroPool (sizeof (EMMC_TRB));\r
   if (Trb == NULL) {\r
     return NULL;\r
   }\r
@@ -1039,6 +1041,22 @@ EmmcPeimCreateTrb (
   if (Packet->EmmcCmdBlk->CommandIndex == EMMC_SEND_TUNING_BLOCK) {\r
     Trb->Mode = EmmcPioMode;\r
   } else {\r
+    if (Trb->Read) {\r
+      MapOp = EdkiiIoMmuOperationBusMasterWrite;\r
+    } else {\r
+      MapOp = EdkiiIoMmuOperationBusMasterRead;\r
+    }\r
+\r
+    if (Trb->DataLen != 0) {\r
+      MapLength = Trb->DataLen;\r
+      Status = IoMmuMap (MapOp, Trb->Data, &MapLength, &Trb->DataPhy, &Trb->DataMap);\r
+\r
+      if (EFI_ERROR (Status) || (MapLength != Trb->DataLen)) {\r
+        DEBUG ((DEBUG_ERROR, "EmmcPeimCreateTrb: Fail to map data buffer.\n"));\r
+        goto Error;\r
+      }\r
+    }\r
+\r
     if (Trb->DataLen == 0) {\r
       Trb->Mode = EmmcNoData;\r
     } else if (Capability.Adma2 != 0) {\r
@@ -1071,12 +1089,16 @@ EmmcPeimFreeTrb (
   IN EMMC_TRB           *Trb\r
   )\r
 {\r
+  if ((Trb != NULL) && (Trb->DataMap != NULL)) {\r
+    IoMmuUnmap (Trb->DataMap);\r
+  }\r
+\r
   if ((Trb != NULL) && (Trb->AdmaDesc != NULL)) {\r
     EmmcPeimFreeMem (Trb->Slot->Private->Pool, Trb->AdmaDesc, Trb->AdmaDescSize);\r
   }\r
 \r
   if (Trb != NULL) {\r
-    EmmcPeimFreeMem (Trb->Slot->Private->Pool, Trb, sizeof (EMMC_TRB));\r
+    FreePool (Trb);\r
   }\r
   return;\r
 }\r
@@ -1241,11 +1263,11 @@ EmmcPeimExecTrb (
   EmmcPeimHcLedOnOff (Bar, TRUE);\r
 \r
   if (Trb->Mode == EmmcSdmaMode) {\r
-    if ((UINT64)(UINTN)Trb->Data >= 0x100000000ul) {\r
+    if ((UINT64)(UINTN)Trb->DataPhy >= 0x100000000ul) {\r
       return EFI_INVALID_PARAMETER;\r
     }\r
 \r
-    SdmaAddr = (UINT32)(UINTN)Trb->Data;\r
+    SdmaAddr = (UINT32)(UINTN)Trb->DataPhy;\r
     Status   = EmmcPeimHcRwMmio (Bar + EMMC_HC_SDMA_ADDR, FALSE, sizeof (SdmaAddr), &SdmaAddr);\r
     if (EFI_ERROR (Status)) {\r
       return Status;\r
@@ -1480,7 +1502,7 @@ EmmcPeimCheckTrbResult (
     //\r
     // Update SDMA Address register.\r
     //\r
-    SdmaAddr = EMMC_SDMA_ROUND_UP ((UINT32)(UINTN)Trb->Data, EMMC_SDMA_BOUNDARY);\r
+    SdmaAddr = EMMC_SDMA_ROUND_UP ((UINT32)(UINTN)Trb->DataPhy, EMMC_SDMA_BOUNDARY);\r
     Status   = EmmcPeimHcRwMmio (\r
                  Bar + EMMC_HC_SDMA_ADDR,\r
                  FALSE,\r
@@ -1490,7 +1512,7 @@ EmmcPeimCheckTrbResult (
     if (EFI_ERROR (Status)) {\r
       goto Done;\r
     }\r
-    Trb->Data = (VOID*)(UINTN)SdmaAddr;\r
+    Trb->DataPhy = (UINT32)(UINTN)SdmaAddr;\r
   }\r
 \r
   if ((Packet->EmmcCmdBlk->CommandType != EmmcCommandTypeAdtc) &&\r