]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Pci/EhciPei/EhciSched.c
MdeModulePkg EhciPei: Support IoMmu
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / EhciPei / EhciSched.c
index e992d4f287978fe5cb3af410d1782d0a43c610e6..606a53db1da1fe21fbdf43676ec1e4b0ab67d527 100644 (file)
@@ -2,7 +2,7 @@
 PEIM to produce gPeiUsb2HostControllerPpiGuid based on gPeiUsbControllerPpiGuid\r
 which is used to enable recovery function from USB Drivers.\r
 \r
-Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2010 - 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
@@ -107,11 +107,13 @@ EhcInitSched (
   IN PEI_USB2_HC_DEV      *Ehc\r
   )\r
 {\r
+  VOID                  *Buf;\r
   EFI_PHYSICAL_ADDRESS  PhyAddr;\r
   VOID                  *Map;\r
   UINTN                 Index;\r
   UINT32                *Desc;\r
   EFI_STATUS            Status;\r
+  EFI_PHYSICAL_ADDRESS  PciAddr;\r
 \r
   //\r
   // First initialize the periodical schedule data:\r
@@ -124,15 +126,19 @@ EhcInitSched (
   // The Frame List ocupies 4K bytes,\r
   // and must be aligned on 4-Kbyte boundaries.\r
   //\r
-  Status = PeiServicesAllocatePages (\r
-             EfiBootServicesCode,\r
+  Status = IoMmuAllocateBuffer (\r
+             Ehc->IoMmu,\r
              1,\r
-             &PhyAddr\r
+             &Buf,\r
+             &PhyAddr,\r
+             &Map\r
              );\r
 \r
-  Map = NULL;\r
-  Ehc->PeriodFrameHost  = (VOID *)(UINTN)PhyAddr;\r
-  Ehc->PeriodFrame      = (VOID *)(UINTN)PhyAddr;\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  Ehc->PeriodFrame      = Buf;\r
   Ehc->PeriodFrameMap   = Map;\r
   Ehc->High32bitAddr    = EHC_HIGH_32BIT (PhyAddr);\r
 \r
@@ -161,19 +167,20 @@ EhcInitSched (
   // Initialize the frame list entries then set the registers\r
   //\r
   Desc = (UINT32 *) Ehc->PeriodFrame;\r
-\r
+  PciAddr  = UsbHcGetPciAddressForHostMem (Ehc->MemPool, Ehc->PeriodOne, sizeof (PEI_EHC_QH));\r
   for (Index = 0; Index < EHC_FRAME_LEN; Index++) {\r
-    Desc[Index] = QH_LINK (Ehc->PeriodOne, EHC_TYPE_QH, FALSE);\r
+    Desc[Index] = QH_LINK (PciAddr, EHC_TYPE_QH, FALSE);\r
   }\r
 \r
-  EhcWriteOpReg (Ehc, EHC_FRAME_BASE_OFFSET, EHC_LOW_32BIT (Ehc->PeriodFrame));\r
+  EhcWriteOpReg (Ehc, EHC_FRAME_BASE_OFFSET, EHC_LOW_32BIT (PhyAddr));\r
 \r
   //\r
   // Second initialize the asynchronous schedule:\r
   // Only need to set the AsynListAddr register to\r
   // the reclamation header\r
   //\r
-  EhcWriteOpReg (Ehc, EHC_ASYNC_HEAD_OFFSET, EHC_LOW_32BIT (Ehc->ReclaimHead));\r
+  PciAddr  = UsbHcGetPciAddressForHostMem (Ehc->MemPool, Ehc->ReclaimHead, sizeof (PEI_EHC_QH));\r
+  EhcWriteOpReg (Ehc, EHC_ASYNC_HEAD_OFFSET, EHC_LOW_32BIT (PciAddr));\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -192,26 +199,27 @@ EhcFreeSched (
   EhcWriteOpReg (Ehc, EHC_ASYNC_HEAD_OFFSET, 0);\r
 \r
   if (Ehc->PeriodOne != NULL) {\r
-    UsbHcFreeMem (Ehc->MemPool, Ehc->PeriodOne, sizeof (PEI_EHC_QH));\r
+    UsbHcFreeMem (Ehc, Ehc->MemPool, Ehc->PeriodOne, sizeof (PEI_EHC_QH));\r
     Ehc->PeriodOne = NULL;\r
   }\r
 \r
   if (Ehc->ReclaimHead != NULL) {\r
-    UsbHcFreeMem (Ehc->MemPool, Ehc->ReclaimHead, sizeof (PEI_EHC_QH));\r
+    UsbHcFreeMem (Ehc, Ehc->MemPool, Ehc->ReclaimHead, sizeof (PEI_EHC_QH));\r
     Ehc->ReclaimHead = NULL;\r
   }\r
 \r
   if (Ehc->ShortReadStop != NULL) {\r
-    UsbHcFreeMem (Ehc->MemPool, Ehc->ShortReadStop, sizeof (PEI_EHC_QTD));\r
+    UsbHcFreeMem (Ehc, Ehc->MemPool, Ehc->ShortReadStop, sizeof (PEI_EHC_QTD));\r
     Ehc->ShortReadStop = NULL;\r
   }\r
 \r
   if (Ehc->MemPool != NULL) {\r
-    UsbHcFreeMemPool (Ehc->MemPool);\r
+    UsbHcFreeMemPool (Ehc, Ehc->MemPool);\r
     Ehc->MemPool = NULL;\r
   }\r
 \r
   if (Ehc->PeriodFrame != NULL) {\r
+    IoMmuFreeBuffer (Ehc->IoMmu, 1, Ehc->PeriodFrame, Ehc->PeriodFrameMap);\r
     Ehc->PeriodFrame = NULL;\r
   }\r
 }\r