]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Revert "XhciDxe: Use common buffer for AsyncInterruptTransfer"
authorStar Zeng <star.zeng@intel.com>
Tue, 6 Nov 2018 13:47:39 +0000 (21:47 +0800)
committerStar Zeng <star.zeng@intel.com>
Wed, 7 Nov 2018 14:48:07 +0000 (22:48 +0800)
There is concern at the thread
https://lists.01.org/pipermail/edk2-devel/2018-November/031951.html.
And the time point is a little sensitive as it is near edk2-stable201811.

This reverts commit 777920997152a2e68f664241f6080b64ff21edd6.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.h

index 64855a4c158c0716d6821076e207e2c7b67ebf47..7f64f9c7c982652e866f06fa4b4b2bbda7dcad48 100644 (file)
@@ -769,7 +769,6 @@ XhcTransfer (
           MaximumPacketLength,\r
           Type,\r
           Request,\r
-          FALSE,\r
           Data,\r
           *DataLength,\r
           NULL,\r
index 9dd45e93a272e491f944bd28b1d7ff9e6630db18..75959ae08363eab97b9411e7cfacc10289576d1a 100644 (file)
@@ -118,18 +118,17 @@ ON_EXIT:
 /**\r
   Create a new URB for a new transaction.\r
 \r
-  @param  Xhc                   The XHCI Instance\r
-  @param  BusAddr               The logical device address assigned by UsbBus driver\r
-  @param  EpAddr                Endpoint addrress\r
-  @param  DevSpeed              The device speed\r
-  @param  MaxPacket             The max packet length of the endpoint\r
-  @param  Type                  The transaction type\r
-  @param  Request               The standard USB request for control transfer\r
-  @param  AllocateCommonBuffer  Indicate whether need to allocate common buffer for data transfer\r
-  @param  Data                  The user data to transfer, NULL if AllocateCommonBuffer is TRUE\r
-  @param  DataLen               The length of data buffer\r
-  @param  Callback              The function to call when data is transferred\r
-  @param  Context               The context to the callback\r
+  @param  Xhc       The XHCI Instance\r
+  @param  BusAddr   The logical device address assigned by UsbBus driver\r
+  @param  EpAddr    Endpoint addrress\r
+  @param  DevSpeed  The device speed\r
+  @param  MaxPacket The max packet length of the endpoint\r
+  @param  Type      The transaction type\r
+  @param  Request   The standard USB request for control transfer\r
+  @param  Data      The user data to transfer\r
+  @param  DataLen   The length of data buffer\r
+  @param  Callback  The function to call when data is transferred\r
+  @param  Context   The context to the callback\r
 \r
   @return Created URB or NULL\r
 \r
@@ -143,7 +142,6 @@ XhcCreateUrb (
   IN UINTN                              MaxPacket,\r
   IN UINTN                              Type,\r
   IN EFI_USB_DEVICE_REQUEST             *Request,\r
-  IN BOOLEAN                            AllocateCommonBuffer,\r
   IN VOID                               *Data,\r
   IN UINTN                              DataLen,\r
   IN EFI_ASYNC_USB_TRANSFER_CALLBACK    Callback,\r
@@ -171,24 +169,8 @@ XhcCreateUrb (
   Ep->Type      = Type;\r
 \r
   Urb->Request  = Request;\r
-  if (AllocateCommonBuffer) {\r
-    ASSERT (Data == NULL);\r
-    Status = Xhc->PciIo->AllocateBuffer (\r
-                           Xhc->PciIo,\r
-                           AllocateAnyPages,\r
-                           EfiBootServicesData,\r
-                           EFI_SIZE_TO_PAGES (DataLen),\r
-                           &Data,\r
-                           0\r
-                           );\r
-    if (EFI_ERROR (Status) || (Data == NULL)) {\r
-      FreePool (Urb);\r
-      return NULL;\r
-    }\r
-  }\r
   Urb->Data     = Data;\r
   Urb->DataLen  = DataLen;\r
-  Urb->AllocateCommonBuffer = AllocateCommonBuffer;\r
   Urb->Callback = Callback;\r
   Urb->Context  = Context;\r
 \r
@@ -196,7 +178,7 @@ XhcCreateUrb (
   ASSERT_EFI_ERROR (Status);\r
   if (EFI_ERROR (Status)) {\r
     DEBUG ((EFI_D_ERROR, "XhcCreateUrb: XhcCreateTransferTrb Failed, Status = %r\n", Status));\r
-    XhcFreeUrb (Xhc, Urb);\r
+    FreePool (Urb);\r
     Urb = NULL;\r
   }\r
 \r
@@ -224,14 +206,6 @@ XhcFreeUrb (
     Xhc->PciIo->Unmap (Xhc->PciIo, Urb->DataMap);\r
   }\r
 \r
-  if (Urb->AllocateCommonBuffer) {\r
-    Xhc->PciIo->FreeBuffer (\r
-                  Xhc->PciIo,\r
-                  EFI_SIZE_TO_PAGES (Urb->DataLen),\r
-                  Urb->Data\r
-                  );\r
-  }\r
-\r
   FreePool (Urb);\r
 }\r
 \r
@@ -290,14 +264,10 @@ XhcCreateTransferTrb (
   // No need to remap.\r
   //\r
   if ((Urb->Data != NULL) && (Urb->DataMap == NULL)) {\r
-    if (Urb->AllocateCommonBuffer) {\r
-      MapOp = EfiPciIoOperationBusMasterCommonBuffer;\r
+    if (((UINT8) (Urb->Ep.Direction)) == EfiUsbDataIn) {\r
+      MapOp = EfiPciIoOperationBusMasterWrite;\r
     } else {\r
-      if (((UINT8) (Urb->Ep.Direction)) == EfiUsbDataIn) {\r
-        MapOp = EfiPciIoOperationBusMasterWrite;\r
-      } else {\r
-        MapOp = EfiPciIoOperationBusMasterRead;\r
-      }\r
+      MapOp = EfiPciIoOperationBusMasterRead;\r
     }\r
 \r
     Len = Urb->DataLen;\r
@@ -1397,6 +1367,7 @@ XhciDelAsyncIntTransfer (
       }\r
 \r
       RemoveEntryList (&Urb->UrbList);\r
+      FreePool (Urb->Data);\r
       XhcFreeUrb (Xhc, Urb);\r
       return EFI_SUCCESS;\r
     }\r
@@ -1434,6 +1405,7 @@ XhciDelAllAsyncIntTransfers (
     }\r
 \r
     RemoveEntryList (&Urb->UrbList);\r
+    FreePool (Urb->Data);\r
     XhcFreeUrb (Xhc, Urb);\r
   }\r
 }\r
@@ -1466,8 +1438,15 @@ XhciInsertAsyncIntTransfer (
   IN VOID                               *Context\r
   )\r
 {\r
+  VOID      *Data;\r
   URB       *Urb;\r
 \r
+  Data = AllocateZeroPool (DataLen);\r
+  if (Data == NULL) {\r
+    DEBUG ((DEBUG_ERROR, "%a: failed to allocate buffer\n", __FUNCTION__));\r
+    return NULL;\r
+  }\r
+\r
   Urb = XhcCreateUrb (\r
           Xhc,\r
           BusAddr,\r
@@ -1476,14 +1455,14 @@ XhciInsertAsyncIntTransfer (
           MaxPacket,\r
           XHC_INT_TRANSFER_ASYNC,\r
           NULL,\r
-          TRUE,\r
-          NULL,\r
+          Data,\r
           DataLen,\r
           Callback,\r
           Context\r
           );\r
   if (Urb == NULL) {\r
     DEBUG ((DEBUG_ERROR, "%a: failed to create URB\n", __FUNCTION__));\r
+    FreePool (Data);\r
     return NULL;\r
   }\r
 \r
@@ -1523,6 +1502,61 @@ XhcUpdateAsyncRequest (
   }\r
 }\r
 \r
+/**\r
+  Flush data from PCI controller specific address to mapped system\r
+  memory address.\r
+\r
+  @param  Xhc                The XHCI device.\r
+  @param  Urb                The URB to unmap.\r
+\r
+  @retval EFI_SUCCESS        Success to flush data to mapped system memory.\r
+  @retval EFI_DEVICE_ERROR   Fail to flush data to mapped system memory.\r
+\r
+**/\r
+EFI_STATUS\r
+XhcFlushAsyncIntMap (\r
+  IN  USB_XHCI_INSTANCE   *Xhc,\r
+  IN  URB                 *Urb\r
+  )\r
+{\r
+  EFI_STATUS                    Status;\r
+  EFI_PHYSICAL_ADDRESS          PhyAddr;\r
+  EFI_PCI_IO_PROTOCOL_OPERATION MapOp;\r
+  EFI_PCI_IO_PROTOCOL           *PciIo;\r
+  UINTN                         Len;\r
+  VOID                          *Map;\r
+\r
+  PciIo = Xhc->PciIo;\r
+  Len   = Urb->DataLen;\r
+\r
+  if (Urb->Ep.Direction == EfiUsbDataIn) {\r
+    MapOp = EfiPciIoOperationBusMasterWrite;\r
+  } else {\r
+    MapOp = EfiPciIoOperationBusMasterRead;\r
+  }\r
+\r
+  if (Urb->DataMap != NULL) {\r
+    Status = PciIo->Unmap (PciIo, Urb->DataMap);\r
+    if (EFI_ERROR (Status)) {\r
+      goto ON_ERROR;\r
+    }\r
+  }\r
+\r
+  Urb->DataMap = NULL;\r
+\r
+  Status = PciIo->Map (PciIo, MapOp, Urb->Data, &Len, &PhyAddr, &Map);\r
+  if (EFI_ERROR (Status) || (Len != Urb->DataLen)) {\r
+    goto ON_ERROR;\r
+  }\r
+\r
+  Urb->DataPhy  = (VOID *) ((UINTN) PhyAddr);\r
+  Urb->DataMap  = Map;\r
+  return EFI_SUCCESS;\r
+\r
+ON_ERROR:\r
+  return EFI_DEVICE_ERROR;\r
+}\r
+\r
 /**\r
   Interrupt transfer periodic check handler.\r
 \r
@@ -1543,6 +1577,7 @@ XhcMonitorAsyncRequests (
   UINT8                   *ProcBuf;\r
   URB                     *Urb;\r
   UINT8                   SlotId;\r
+  EFI_STATUS              Status;\r
   EFI_TPL                 OldTpl;\r
 \r
   OldTpl = gBS->RaiseTPL (XHC_TPL);\r
@@ -1570,6 +1605,15 @@ XhcMonitorAsyncRequests (
       continue;\r
     }\r
 \r
+    //\r
+    // Flush any PCI posted write transactions from a PCI host\r
+    // bridge to system memory.\r
+    //\r
+    Status = XhcFlushAsyncIntMap (Xhc, Urb);\r
+    if (EFI_ERROR (Status)) {\r
+      DEBUG ((EFI_D_ERROR, "XhcMonitorAsyncRequests: Fail to Flush AsyncInt Mapped Memeory\n"));\r
+    }\r
+\r
     //\r
     // Allocate a buffer then copy the transferred data for user.\r
     // If failed to allocate the buffer, update the URB for next\r
index 1a95d98996c16e1f5445b91daa3b16d2e92a790b..b5e192c3b58981d0db0e6aa97d2c934647a5f8b7 100644 (file)
@@ -172,7 +172,6 @@ typedef struct _URB {
   //\r
   USB_ENDPOINT                    Ep;\r
   EFI_USB_DEVICE_REQUEST          *Request;\r
-  BOOLEAN                         AllocateCommonBuffer;\r
   VOID                            *Data;\r
   UINTN                           DataLen;\r
   VOID                            *DataPhy;\r
@@ -1433,18 +1432,17 @@ XhcSetTrDequeuePointer (
 /**\r
   Create a new URB for a new transaction.\r
 \r
-  @param  Xhc                   The XHCI Instance\r
-  @param  BusAddr               The logical device address assigned by UsbBus driver\r
-  @param  EpAddr                Endpoint addrress\r
-  @param  DevSpeed              The device speed\r
-  @param  MaxPacket             The max packet length of the endpoint\r
-  @param  Type                  The transaction type\r
-  @param  Request               The standard USB request for control transfer\r
-  @param  AllocateCommonBuffer  Indicate whether need to allocate common buffer for data transfer\r
-  @param  Data                  The user data to transfer, NULL if AllocateCommonBuffer is TRUE\r
-  @param  DataLen               The length of data buffer\r
-  @param  Callback              The function to call when data is transferred\r
-  @param  Context               The context to the callback\r
+  @param  Xhc       The XHCI Instance\r
+  @param  DevAddr   The device address\r
+  @param  EpAddr    Endpoint addrress\r
+  @param  DevSpeed  The device speed\r
+  @param  MaxPacket The max packet length of the endpoint\r
+  @param  Type      The transaction type\r
+  @param  Request   The standard USB request for control transfer\r
+  @param  Data      The user data to transfer\r
+  @param  DataLen   The length of data buffer\r
+  @param  Callback  The function to call when data is transferred\r
+  @param  Context   The context to the callback\r
 \r
   @return Created URB or NULL\r
 \r
@@ -1452,13 +1450,12 @@ XhcSetTrDequeuePointer (
 URB*\r
 XhcCreateUrb (\r
   IN USB_XHCI_INSTANCE                  *Xhc,\r
-  IN UINT8                              BusAddr,\r
+  IN UINT8                              DevAddr,\r
   IN UINT8                              EpAddr,\r
   IN UINT8                              DevSpeed,\r
   IN UINTN                              MaxPacket,\r
   IN UINTN                              Type,\r
   IN EFI_USB_DEVICE_REQUEST             *Request,\r
-  IN BOOLEAN                            AllocateCommonBuffer,\r
   IN VOID                               *Data,\r
   IN UINTN                              DataLen,\r
   IN EFI_ASYNC_USB_TRANSFER_CALLBACK    Callback,\r