]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Pci/EhciDxe/EhciUrb.c
MdeModulePkg EhciDxe: Use common buffer for AsyncInterruptTransfer
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / EhciDxe / EhciUrb.c
index 6afb327df165aa81cf559a903a090391fa9e82bf..09c12776ecdbe7445149a95f6c78c690c477d513 100644 (file)
@@ -339,6 +339,14 @@ EhcFreeUrb (
     PciIo->Unmap (PciIo, Urb->DataMap);\r
   }\r
 \r
+  if (Urb->AllocateCommonBuffer) {\r
+    PciIo->FreeBuffer (\r
+             PciIo,\r
+             EFI_SIZE_TO_PAGES (Urb->DataLen),\r
+             Urb->Data\r
+             );\r
+  }\r
+\r
   if (Urb->Qh != NULL) {\r
     //\r
     // Ensure that this queue head has been unlinked from the\r
@@ -529,7 +537,8 @@ ON_ERROR:
   @param  Hub                   The transaction translator to use.\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  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
@@ -549,6 +558,7 @@ EhcCreateUrb (
   IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Hub,\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
@@ -596,8 +606,24 @@ EhcCreateUrb (
   Ep->PollRate    = EhcConvertPollRate (Interval);\r
 \r
   Urb->Request    = Request;\r
+  if (AllocateCommonBuffer) {\r
+    ASSERT (Data == NULL);\r
+    Status = Ehc->PciIo->AllocateBuffer (\r
+                           Ehc->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
@@ -627,10 +653,14 @@ EhcCreateUrb (
   if (Data != NULL) {\r
     Len     = DataLen;\r
 \r
-    if (Ep->Direction == EfiUsbDataIn) {\r
-      MapOp = EfiPciIoOperationBusMasterWrite;\r
+    if (Urb->AllocateCommonBuffer) {\r
+      MapOp = EfiPciIoOperationBusMasterCommonBuffer;\r
     } else {\r
-      MapOp = EfiPciIoOperationBusMasterRead;\r
+      if (Ep->Direction == EfiUsbDataIn) {\r
+        MapOp = EfiPciIoOperationBusMasterWrite;\r
+      } else {\r
+        MapOp = EfiPciIoOperationBusMasterRead;\r
+      }\r
     }\r
 \r
     Status  = PciIo->Map (PciIo, MapOp, Data, &Len, &PhyAddr, &Map);\r