]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Pci/UhciPei/UhcPeim.h
MdeModulePkg: Clean up source files
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / UhciPei / UhcPeim.h
index dc697ce105edbf0be3bd19715564ced52e4da4ae..33d4f2f65f05f68785cfdd7a5a107468f3a9027c 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
 Private Header file for Usb Host Controller PEIM\r
 \r
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
-  \r
+Copyright (c) 2006 - 2018, 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
@@ -22,6 +22,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include <Ppi/UsbController.h>\r
 #include <Ppi/UsbHostController.h>\r
+#include <Ppi/IoMmu.h>\r
+#include <Ppi/EndOfPeiPhase.h>\r
 \r
 #include <Library/DebugLib.h>\r
 #include <Library/PeimEntryPoint.h>\r
@@ -94,6 +96,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #define OUTPUT_PACKET_ID      0xE1\r
 #define ERROR_PACKET_ID       0x55\r
 \r
+#define STALL_1_MICRO_SECOND  1\r
 #define STALL_1_MILLI_SECOND  1000\r
 \r
 \r
@@ -176,7 +179,13 @@ struct _MEMORY_MANAGE_HEADER {
 typedef struct {\r
   UINTN                       Signature;\r
   PEI_USB_HOST_CONTROLLER_PPI UsbHostControllerPpi;\r
+  EDKII_IOMMU_PPI             *IoMmu;\r
   EFI_PEI_PPI_DESCRIPTOR      PpiDescriptor;\r
+  //\r
+  // EndOfPei callback is used to stop the UHC DMA operation\r
+  // after exit PEI phase.\r
+  //\r
+  EFI_PEI_NOTIFY_DESCRIPTOR   EndOfPeiNotifyList;\r
 \r
   UINT32                      UsbHostControllerBaseAddress;\r
   FRAMELIST_ENTRY             *FrameListEntry;\r
@@ -190,15 +199,16 @@ typedef struct {
 } USB_UHC_DEV;\r
 \r
 #define PEI_RECOVERY_USB_UHC_DEV_FROM_UHCI_THIS(a)  CR (a, USB_UHC_DEV, UsbHostControllerPpi, USB_UHC_DEV_SIGNATURE)\r
+#define PEI_RECOVERY_USB_UHC_DEV_FROM_THIS_NOTIFY(a) CR (a, USB_UHC_DEV, EndOfPeiNotifyList, USB_UHC_DEV_SIGNATURE)\r
 \r
 /**\r
   Submits control transfer to a target USB device.\r
-  \r
+\r
   @param  PeiServices            The pointer of EFI_PEI_SERVICES.\r
   @param  This                   The pointer of PEI_USB_HOST_CONTROLLER_PPI.\r
   @param  DeviceAddress          The target device address.\r
   @param  DeviceSpeed            Target device speed.\r
-  @param  MaximumPacketLength    Maximum packet size the default control transfer \r
+  @param  MaximumPacketLength    Maximum packet size the default control transfer\r
                                  endpoint is capable of sending or receiving.\r
   @param  Request                USB device request to send.\r
   @param  TransferDirection      Specifies the data direction for the data stage.\r
@@ -232,18 +242,18 @@ UhcControlTransfer (
 \r
 /**\r
   Submits bulk transfer to a bulk endpoint of a USB device.\r
-  \r
+\r
   @param  PeiServices           The pointer of EFI_PEI_SERVICES.\r
   @param  This                  The pointer of PEI_USB_HOST_CONTROLLER_PPI.\r
   @param  DeviceAddress         Target device address.\r
   @param  EndPointAddress       Endpoint number and its direction in bit 7.\r
-  @param  MaximumPacketLength   Maximum packet size the endpoint is capable of \r
+  @param  MaximumPacketLength   Maximum packet size the endpoint is capable of\r
                                 sending or receiving.\r
-  @param  Data                  Array of pointers to the buffers of data to transmit \r
+  @param  Data                  Array of pointers to the buffers of data to transmit\r
                                 from or receive into.\r
   @param  DataLength            The lenght of the data buffer.\r
   @param  DataToggle            On input, the initial data toggle for the transfer;\r
-                                On output, it is updated to to next data toggle to use of \r
+                                On output, it is updated to to next data toggle to use of\r
                                 the subsequent bulk transfer.\r
   @param  TimeOut               Indicates the maximum time, in millisecond, which the\r
                                 transfer is allowed to complete.\r
@@ -276,10 +286,10 @@ UhcBulkTransfer (
   Retrieves the number of root hub ports.\r
 \r
   @param[in]  PeiServices   The pointer to the PEI Services Table.\r
-  @param[in]  This          The pointer to this instance of the \r
+  @param[in]  This          The pointer to this instance of the\r
                             PEI_USB_HOST_CONTROLLER_PPI.\r
-  @param[out] PortNumber    The pointer to the number of the root hub ports.                                \r
-                                \r
+  @param[out] PortNumber    The pointer to the number of the root hub ports.\r
+\r
   @retval EFI_SUCCESS           The port number was retrieved successfully.\r
   @retval EFI_INVALID_PARAMETER PortNumber is NULL.\r
 \r
@@ -294,10 +304,10 @@ UhcGetRootHubPortNumber (
 \r
 /**\r
   Retrieves the current status of a USB root hub port.\r
-  \r
+\r
   @param  PeiServices            The pointer of EFI_PEI_SERVICES.\r
   @param  This                   The pointer of PEI_USB_HOST_CONTROLLER_PPI.\r
-  @param  PortNumber             The root hub port to retrieve the state from.  \r
+  @param  PortNumber             The root hub port to retrieve the state from.\r
   @param  PortStatus             Variable to receive the port state.\r
 \r
   @retval EFI_SUCCESS            The status of the USB root hub port specified.\r
@@ -316,7 +326,7 @@ UhcGetRootHubPortStatus (
 \r
 /**\r
   Sets a feature for the specified root hub port.\r
-  \r
+\r
   @param  PeiServices           The pointer of EFI_PEI_SERVICES\r
   @param  This                  The pointer of PEI_USB_HOST_CONTROLLER_PPI\r
   @param  PortNumber            Root hub port to set.\r
@@ -338,7 +348,7 @@ UhcSetRootHubPortFeature (
 \r
 /**\r
   Clears a feature for the specified root hub port.\r
-  \r
+\r
   @param  PeiServices           The pointer of EFI_PEI_SERVICES.\r
   @param  This                  The pointer of PEI_USB_HOST_CONTROLLER_PPI.\r
   @param  PortNumber            Specifies the root hub port whose feature\r
@@ -346,7 +356,7 @@ UhcSetRootHubPortFeature (
   @param  PortFeature           Indicates the feature selector associated with the\r
                                 feature clear request.\r
 \r
-  @retval EFI_SUCCESS            The feature specified by PortFeature was cleared \r
+  @retval EFI_SUCCESS            The feature specified by PortFeature was cleared\r
                                  for the USB root hub port specified by PortNumber.\r
   @retval EFI_INVALID_PARAMETER  PortNumber is invalid or PortFeature is invalid.\r
 \r
@@ -390,7 +400,7 @@ CreateFrameList (
 \r
 /**\r
   Read a 16bit width data from Uhc HC IO space register.\r
-  \r
+\r
   @param  UhcDev  The UHCI device.\r
   @param  Port    The IO space address of the register.\r
 \r
@@ -405,7 +415,7 @@ USBReadPortW (
 \r
 /**\r
   Write a 16bit width data into Uhc HC IO space register.\r
-  \r
+\r
   @param  UhcDev  The UHCI device.\r
   @param  Port    The IO space address of the register.\r
   @param  Data    The data written into the register.\r
@@ -420,7 +430,7 @@ USBWritePortW (
 \r
 /**\r
   Write a 32bit width data into Uhc HC IO space register.\r
-  \r
+\r
   @param  UhcDev  The UHCI device.\r
   @param  Port    The IO space address of the register.\r
   @param  Data    The data written into the register.\r
@@ -435,7 +445,7 @@ USBWritePortDW (
 \r
 /**\r
   Clear the content of UHCI's Status Register.\r
-  \r
+\r
   @param  UhcDev       The UHCI device.\r
   @param  StatusAddr   The IO space address of the register.\r
 \r
@@ -653,7 +663,8 @@ CreateTD (
   @param  DevAddr      Device address.\r
   @param  Endpoint     Endpoint number.\r
   @param  DeviceSpeed  Device Speed.\r
-  @param  DevRequest   Device reuquest.\r
+  @param  DevRequest   CPU memory address of request structure buffer to transfer.\r
+  @param  RequestPhy   PCI memory address of request structure buffer to transfer.\r
   @param  RequestLen   Request length.\r
   @param  PtrTD        TD_STRUCT generated.\r
 \r
@@ -668,6 +679,7 @@ GenSetupStageTD (
   IN  UINT8           Endpoint,\r
   IN  UINT8           DeviceSpeed,\r
   IN  UINT8           *DevRequest,\r
+  IN  UINT8           *RequestPhy,\r
   IN  UINT8           RequestLen,\r
   OUT TD_STRUCT       **PtrTD\r
   );\r
@@ -678,7 +690,8 @@ GenSetupStageTD (
   @param  UhcDev       The UHCI device.\r
   @param  DevAddr      Device address.\r
   @param  Endpoint     Endpoint number.\r
-  @param  PtrData      Data buffer.\r
+  @param  PtrData      CPU memory address of user data buffer to transfer.\r
+  @param  DataPhy      PCI memory address of user data buffer to transfer.\r
   @param  Len          Data length.\r
   @param  PktID        PacketID.\r
   @param  Toggle       Data toggle value.\r
@@ -695,6 +708,7 @@ GenDataTD (
   IN  UINT8           DevAddr,\r
   IN  UINT8           Endpoint,\r
   IN  UINT8           *PtrData,\r
+  IN  UINT8           *DataPhy,\r
   IN  UINT8           Len,\r
   IN  UINT8           PktID,\r
   IN  UINT8           Toggle,\r
@@ -1329,4 +1343,149 @@ DelinkMemoryBlock (
   IN MEMORY_MANAGE_HEADER    *FreeMemoryHeader\r
   );\r
 \r
+/**\r
+  Map address of request structure buffer.\r
+\r
+  @param  Uhc                The UHCI device.\r
+  @param  Request            The user request buffer.\r
+  @param  MappedAddr         Mapped address of request.\r
+  @param  Map                Identificaion of this mapping to return.\r
+\r
+  @return EFI_SUCCESS        Success.\r
+  @return EFI_DEVICE_ERROR   Fail to map the user request.\r
+\r
+**/\r
+EFI_STATUS\r
+UhciMapUserRequest (\r
+  IN  USB_UHC_DEV         *Uhc,\r
+  IN  OUT VOID            *Request,\r
+  OUT UINT8               **MappedAddr,\r
+  OUT VOID                **Map\r
+  );\r
+\r
+/**\r
+  Map address of user data buffer.\r
+\r
+  @param  Uhc                The UHCI device.\r
+  @param  Direction          Direction of the data transfer.\r
+  @param  Data               The user data buffer.\r
+  @param  Len                Length of the user data.\r
+  @param  PktId              Packet identificaion.\r
+  @param  MappedAddr         Mapped address to return.\r
+  @param  Map                Identificaion of this mapping to return.\r
+\r
+  @return EFI_SUCCESS        Success.\r
+  @return EFI_DEVICE_ERROR   Fail to map the user data.\r
+\r
+**/\r
+EFI_STATUS\r
+UhciMapUserData (\r
+  IN  USB_UHC_DEV             *Uhc,\r
+  IN  EFI_USB_DATA_DIRECTION  Direction,\r
+  IN  VOID                    *Data,\r
+  IN  OUT UINTN               *Len,\r
+  OUT UINT8                   *PktId,\r
+  OUT UINT8                   **MappedAddr,\r
+  OUT VOID                    **Map\r
+  );\r
+\r
+/**\r
+  Provides the controller-specific addresses required to access system memory from a\r
+  DMA bus master.\r
+\r
+  @param IoMmu                  Pointer to IOMMU PPI.\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_PPI        *IoMmu,\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 IoMmu              Pointer to IOMMU PPI.\r
+  @param Mapping            The mapping value returned from Map().\r
+\r
+**/\r
+VOID\r
+IoMmuUnmap (\r
+  IN EDKII_IOMMU_PPI        *IoMmu,\r
+  IN VOID                  *Mapping\r
+  );\r
+\r
+/**\r
+  Allocates pages that are suitable for an OperationBusMasterCommonBuffer or\r
+  OperationBusMasterCommonBuffer64 mapping.\r
+\r
+  @param IoMmu                  Pointer to IOMMU PPI.\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 EDKII_IOMMU_PPI        *IoMmu,\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 IoMmu              Pointer to IOMMU PPI.\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
+**/\r
+VOID\r
+IoMmuFreeBuffer (\r
+  IN EDKII_IOMMU_PPI        *IoMmu,\r
+  IN UINTN                  Pages,\r
+  IN VOID                   *HostAddress,\r
+  IN VOID                   *Mapping\r
+  );\r
+\r
+/**\r
+  Initialize IOMMU.\r
+\r
+  @param IoMmu              Pointer to pointer to IOMMU PPI.\r
+\r
+**/\r
+VOID\r
+IoMmuInit (\r
+  OUT EDKII_IOMMU_PPI       **IoMmu\r
+  );\r
+\r
 #endif\r