]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / XhciDxe / Xhci.c
index 20ad3f1611979ff187abb7fb47c0ed800be32fa8..43c53bad4e4a654f4ca10c9d50a6a6d85327054e 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
   The XHCI controller driver.\r
 \r
-Copyright (c) 2011 - 2017, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution.  The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -159,7 +153,7 @@ XhcReset (
   EFI_TPL            OldTpl;\r
 \r
   Xhc = XHC_FROM_THIS (This);\r
-  \r
+\r
   if (Xhc->DevicePath != NULL) {\r
     //\r
     // Report Status Code to indicate reset happens\r
@@ -169,7 +163,7 @@ XhcReset (
       (EFI_IO_BUS_USB | EFI_IOB_PC_RESET),\r
       Xhc->DevicePath\r
       );\r
-  }  \r
+  }\r
 \r
   OldTpl = gBS->RaiseTPL (XHC_TPL);\r
 \r
@@ -403,7 +397,8 @@ XhcGetRootHubPortStatus (
   State = XhcReadOpReg (Xhc, Offset);\r
 \r
   //\r
-  // According to XHCI 1.0 spec, bit 10~13 of the root port status register identifies the speed of the attached device.\r
+  // According to XHCI 1.1 spec November 2017,\r
+  // bit 10~13 of the root port status register identifies the speed of the attached device.\r
   //\r
   switch ((State & XHC_PORTSC_PS) >> 10) {\r
   case 2:\r
@@ -415,6 +410,7 @@ XhcGetRootHubPortStatus (
     break;\r
 \r
   case 4:\r
+  case 5:\r
     PortStatus->PortStatus |= USB_PORT_STAT_SUPER_SPEED;\r
     break;\r
 \r
@@ -801,7 +797,7 @@ XhcTransfer (
   *TransferResult = Urb->Result;\r
   *DataLength     = Urb->Completed;\r
 \r
-  if (*TransferResult == EFI_USB_ERR_STALL) {\r
+  if ((*TransferResult == EFI_USB_ERR_STALL) || (*TransferResult == EFI_USB_ERR_BABBLE)) {\r
     ASSERT (Status == EFI_DEVICE_ERROR);\r
     RecoveryStatus = XhcRecoverHaltedEndpoint(Xhc, Urb);\r
     if (EFI_ERROR (RecoveryStatus)) {\r
@@ -995,7 +991,7 @@ XhcControlTransfer (
   // Hook Set_Config request from UsbBus as we need configure device endpoint.\r
   //\r
   if ((Request->Request     == USB_REQ_GET_DESCRIPTOR) &&\r
-      ((Request->RequestType == USB_REQUEST_TYPE (EfiUsbDataIn, USB_REQ_TYPE_STANDARD, USB_TARGET_DEVICE)) || \r
+      ((Request->RequestType == USB_REQUEST_TYPE (EfiUsbDataIn, USB_REQ_TYPE_STANDARD, USB_TARGET_DEVICE)) ||\r
       ((Request->RequestType == USB_REQUEST_TYPE (EfiUsbDataIn, USB_REQ_TYPE_CLASS, USB_TARGET_DEVICE))))) {\r
     DescriptorType = (UINT8)(Request->Value >> 8);\r
     if ((DescriptorType == USB_DESC_TYPE_DEVICE) && ((*DataLength == sizeof (EFI_USB_DEVICE_DESCRIPTOR)) || ((DeviceSpeed == EFI_USB_SPEED_FULL) && (*DataLength == 8)))) {\r
@@ -1144,7 +1140,7 @@ XhcControlTransfer (
         ClearPortRequest.Length       = 0;\r
 \r
         XhcControlTransfer (\r
-          This, \r
+          This,\r
           DeviceAddress,\r
           DeviceSpeed,\r
           MaximumPacketLength,\r
@@ -1344,7 +1340,6 @@ XhcAsyncInterruptTransfer (
   EFI_STATUS              Status;\r
   UINT8                   SlotId;\r
   UINT8                   Index;\r
-  UINT8                   *Data;\r
   EFI_TPL                 OldTpl;\r
 \r
   //\r
@@ -1411,36 +1406,21 @@ XhcAsyncInterruptTransfer (
     goto ON_EXIT;\r
   }\r
 \r
-  Data = AllocateZeroPool (DataLength);\r
-\r
-  if (Data == NULL) {\r
-    DEBUG ((EFI_D_ERROR, "XhcAsyncInterruptTransfer: failed to allocate buffer\n"));\r
-    Status = EFI_OUT_OF_RESOURCES;\r
-    goto ON_EXIT;\r
-  }\r
-\r
-  Urb = XhcCreateUrb (\r
+  Urb = XhciInsertAsyncIntTransfer (\r
           Xhc,\r
           DeviceAddress,\r
           EndPointAddress,\r
           DeviceSpeed,\r
           MaximumPacketLength,\r
-          XHC_INT_TRANSFER_ASYNC,\r
-          NULL,\r
-          Data,\r
           DataLength,\r
           CallBackFunction,\r
           Context\r
           );\r
-\r
   if (Urb == NULL) {\r
-    DEBUG ((EFI_D_ERROR, "XhcAsyncInterruptTransfer: failed to create URB\n"));\r
-    FreePool (Data);\r
     Status = EFI_OUT_OF_RESOURCES;\r
     goto ON_EXIT;\r
   }\r
 \r
-  InsertHeadList (&Xhc->AsyncIntTransfers, &Urb->UrbList);\r
   //\r
   // Ring the doorbell\r
   //\r
@@ -1770,6 +1750,7 @@ XhcCreateUsbHc (
   EFI_STATUS              Status;\r
   UINT32                  PageSize;\r
   UINT16                  ExtCapReg;\r
+  UINT8                   ReleaseNumber;\r
 \r
   Xhc = AllocateZeroPool (sizeof (USB_XHCI_INSTANCE));\r
 \r
@@ -1786,6 +1767,19 @@ XhcCreateUsbHc (
   Xhc->OriginalPciAttributes = OriginalPciAttributes;\r
   CopyMem (&Xhc->Usb2Hc, &gXhciUsb2HcTemplate, sizeof (EFI_USB2_HC_PROTOCOL));\r
 \r
+  Status = PciIo->Pci.Read (\r
+                        PciIo,\r
+                        EfiPciIoWidthUint8,\r
+                        XHC_PCI_SBRN_OFFSET,\r
+                        1,\r
+                        &ReleaseNumber\r
+                        );\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    Xhc->Usb2Hc.MajorRevision = (ReleaseNumber & 0xF0) >> 4;\r
+    Xhc->Usb2Hc.MinorRevision = (ReleaseNumber & 0x0F);\r
+  }\r
+\r
   InitializeListHead (&Xhc->AsyncIntTransfers);\r
 \r
   //\r