]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Pci/EhciPei/EhcPeim.c
MdeModulePkg EhciPei: Support IoMmu
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / EhciPei / EhcPeim.c
index 6c179b093584f459273edff1e5171227427c1feb..5cad25e926c578df51411af22b2f25c9c78c4bda 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, 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
@@ -400,6 +400,34 @@ EhcRunHC (
   return Status;\r
 }\r
 \r
+/**\r
+  Power On All EHCI Ports.\r
+  \r
+  @param  Ehc             The EHCI device.\r
+\r
+**/\r
+VOID\r
+EhcPowerOnAllPorts (\r
+  IN PEI_USB2_HC_DEV          *Ehc\r
+  )\r
+{\r
+  UINT8     PortNumber;\r
+  UINT8     Index;\r
+  UINT32    RegVal;\r
+  \r
+  PortNumber = (UINT8)(Ehc->HcStructParams & HCSP_NPORTS);\r
+  for (Index = 0; Index < PortNumber; Index++) {\r
+    //\r
+    // Do not clear port status bits on initialization.  Otherwise devices will\r
+    // not enumerate properly at startup.\r
+    //\r
+    RegVal  = EhcReadOpReg(Ehc, EHC_PORT_STAT_OFFSET + 4 * Index);\r
+    RegVal &= ~PORTSC_CHANGE_MASK;\r
+    RegVal |= PORTSC_POWER;\r
+    EhcWriteOpReg (Ehc, EHC_PORT_STAT_OFFSET + 4 * Index, RegVal);\r
+  }\r
+}\r
+\r
 /**\r
   Initialize the HC hardware. \r
   EHCI spec lists the five things to do to initialize the hardware.\r
@@ -443,6 +471,9 @@ EhcInitHC (
   if (Ehc->Urb  == NULL) {\r
     return Status;\r
   }\r
+\r
+  EhcPowerOnAllPorts (Ehc);  \r
+  MicroSecondDelay (EHC_ROOT_PORT_RECOVERY_STALL);\r
   \r
   Status = EhcInitSched (Ehc);\r
 \r
@@ -509,6 +540,8 @@ EhcInitHC (
                                 the subsequent bulk transfer.\r
   @param  TimeOut               Indicates the maximum time, in millisecond, which the\r
                                 transfer is allowed to complete.\r
+                                If Timeout is 0, then the caller must wait for the function\r
+                                to be completed until EFI_SUCCESS or EFI_DEVICE_ERROR is returned.\r
   @param  Translator            A pointr to the transaction translator data.                                \r
   @param  TransferResult        A pointer to the detailed result information of the\r
                                 bulk transfer.\r
@@ -972,6 +1005,8 @@ ON_EXIT:
   @param  Data                   Data buffer to be transmitted or received from USB device.\r
   @param  DataLength             The size (in bytes) of the data buffer.\r
   @param  TimeOut                Indicates the maximum timeout, in millisecond.\r
+                                 If Timeout is 0, then the caller must wait for the function\r
+                                 to be completed until EFI_SUCCESS or EFI_DEVICE_ERROR is returned.\r
   @param  Translator             Transaction translator to be used by this device.\r
   @param  TransferResult         Return the result of this control transfer.\r
 \r
@@ -1105,6 +1140,36 @@ ON_EXIT:
   return Status;\r
 }\r
 \r
+/**\r
+  One notified function to stop the Host Controller 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 event that\r
+                                 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
+  @retval     others\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EhcEndOfPei (\r
+  IN EFI_PEI_SERVICES           **PeiServices,\r
+  IN EFI_PEI_NOTIFY_DESCRIPTOR  *NotifyDescriptor,\r
+  IN VOID                       *Ppi\r
+  )\r
+{\r
+  PEI_USB2_HC_DEV   *Ehc;\r
+\r
+  Ehc = PEI_RECOVERY_USB_EHC_DEV_FROM_THIS_NOTIFY (NotifyDescriptor);\r
+\r
+  EhcHaltHC (Ehc, EHC_GENERIC_TIMEOUT);\r
+\r
+  EhcFreeSched (Ehc);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
 /**\r
   @param  FileHandle  Handle of the file being invoked.\r
   @param  PeiServices Describes the list of possible PEI Services.\r
@@ -1184,6 +1249,8 @@ EhcPeimEntry (
 \r
     EhcDev->Signature = USB2_HC_DEV_SIGNATURE;\r
 \r
+    IoMmuInit (&EhcDev->IoMmu);\r
+\r
     EhcDev->UsbHostControllerBaseAddress = (UINT32) BaseAddress;\r
 \r
 \r
@@ -1215,6 +1282,12 @@ EhcPeimEntry (
       continue;\r
     }\r
 \r
+    EhcDev->EndOfPeiNotifyList.Flags = (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);\r
+    EhcDev->EndOfPeiNotifyList.Guid = &gEfiEndOfPeiSignalPpiGuid;\r
+    EhcDev->EndOfPeiNotifyList.Notify = EhcEndOfPei;\r
+\r
+    PeiServicesNotifyPpi (&EhcDev->EndOfPeiNotifyList);\r
+\r
     Index++;\r
   }\r
 \r