X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FBus%2FPci%2FXhciDxe%2FXhci.c;h=390ca0a3762eb1f2956892986c671915538c9499;hb=3cf6450eb581961e3618d29117b09b22605c99cd;hp=0c08301e9ba4b92b3ad8a9ac1fbfafecdd37c3e5;hpb=16d718a55b65b1f51d450226879c48f709e5a791;p=mirror_edk2.git diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c index 0c08301e9b..390ca0a376 100644 --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c @@ -1,7 +1,7 @@ /** @file The XHCI controller driver. -Copyright (c) 2011 - 2012, Intel Corporation. All rights reserved.
+Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -32,6 +32,35 @@ USB_PORT_STATE_MAP mUsbPortChangeMap[] = { {XHC_PORTSC_PRC, USB_PORT_STAT_C_RESET} }; +USB_CLEAR_PORT_MAP mUsbClearPortChangeMap[] = { + {XHC_PORTSC_CSC, EfiUsbPortConnectChange}, + {XHC_PORTSC_PEC, EfiUsbPortEnableChange}, + {XHC_PORTSC_OCC, EfiUsbPortOverCurrentChange}, + {XHC_PORTSC_PRC, EfiUsbPortResetChange} +}; + +USB_PORT_STATE_MAP mUsbHubPortStateMap[] = { + {XHC_HUB_PORTSC_CCS, USB_PORT_STAT_CONNECTION}, + {XHC_HUB_PORTSC_PED, USB_PORT_STAT_ENABLE}, + {XHC_HUB_PORTSC_OCA, USB_PORT_STAT_OVERCURRENT}, + {XHC_HUB_PORTSC_RESET, USB_PORT_STAT_RESET} +}; + +USB_PORT_STATE_MAP mUsbHubPortChangeMap[] = { + {XHC_HUB_PORTSC_CSC, USB_PORT_STAT_C_CONNECTION}, + {XHC_HUB_PORTSC_PEC, USB_PORT_STAT_C_ENABLE}, + {XHC_HUB_PORTSC_OCC, USB_PORT_STAT_C_OVERCURRENT}, + {XHC_HUB_PORTSC_PRC, USB_PORT_STAT_C_RESET} +}; + +USB_CLEAR_PORT_MAP mUsbHubClearPortChangeMap[] = { + {XHC_HUB_PORTSC_CSC, EfiUsbPortConnectChange}, + {XHC_HUB_PORTSC_PEC, EfiUsbPortEnableChange}, + {XHC_HUB_PORTSC_OCC, EfiUsbPortOverCurrentChange}, + {XHC_HUB_PORTSC_PRC, EfiUsbPortResetChange}, + {XHC_HUB_PORTSC_BHRC, Usb3PortBHPortResetChange} +}; + EFI_DRIVER_BINDING_PROTOCOL gXhciDriverBinding = { XhcDriverBindingSupported, XhcDriverBindingStart, @@ -129,9 +158,20 @@ XhcReset ( EFI_STATUS Status; EFI_TPL OldTpl; - OldTpl = gBS->RaiseTPL (XHC_TPL); + Xhc = XHC_FROM_THIS (This); + + if (Xhc->DevicePath != NULL) { + // + // Report Status Code to indicate reset happens + // + REPORT_STATUS_CODE_WITH_DEVICE_PATH ( + EFI_PROGRESS_CODE, + (EFI_IO_BUS_USB | EFI_IOB_PC_RESET), + Xhc->DevicePath + ); + } - Xhc = XHC_FROM_THIS (This); + OldTpl = gBS->RaiseTPL (XHC_TPL); switch (Attributes) { case EFI_USB_HC_RESET_GLOBAL: @@ -139,6 +179,11 @@ XhcReset ( // Flow through, same behavior as Host Controller Reset // case EFI_USB_HC_RESET_HOST_CONTROLLER: + if ((Xhc->DebugCapSupOffset != 0xFFFFFFFF) && ((XhcReadExtCapReg (Xhc, Xhc->DebugCapSupOffset) & 0xFF) == XHC_CAP_USB_DEBUG) && + ((XhcReadExtCapReg (Xhc, Xhc->DebugCapSupOffset + XHC_DC_DCCTRL) & BIT0) != 0)) { + Status = EFI_SUCCESS; + goto ON_EXIT; + } // // Host Controller must be Halt when Reset it // @@ -402,6 +447,14 @@ XhcGetRootHubPortStatus ( } } + MapSize = sizeof (mUsbClearPortChangeMap) / sizeof (USB_CLEAR_PORT_MAP); + + for (Index = 0; Index < MapSize; Index++) { + if (XHC_BIT_IS_SET (State, mUsbClearPortChangeMap[Index].HwState)) { + XhcClearRootHubPortFeature (This, PortNumber, (EFI_USB_PORT_FEATURE)mUsbClearPortChangeMap[Index].Selector); + } + } + // // Poll the root port status register to enable/disable corresponding device slot if there is a device attached/detached. // For those devices behind hub, we get its attach/detach event by hooking Get_Port_Status request at control transfer for those hub. @@ -439,8 +492,6 @@ XhcSetRootHubPortFeature ( UINT32 Offset; UINT32 State; UINT32 TotalPort; - UINT8 SlotId; - USB_DEV_ROUTE RouteChart; EFI_STATUS Status; EFI_TPL OldTpl; @@ -496,24 +547,13 @@ XhcSetRootHubPortFeature ( } } - RouteChart.Route.RouteString = 0; - RouteChart.Route.RootPortNum = PortNumber + 1; - RouteChart.Route.TierNum = 1; // - // If the port reset operation happens after the usb super speed device is enabled, - // The subsequent configuration, such as getting device descriptor, will fail. - // So here a workaround is introduced to skip the reset operation if the device is enabled. + // 4.3.1 Resetting a Root Hub Port + // 1) Write the PORTSC register with the Port Reset (PR) bit set to '1'. // - SlotId = XhcRouteStringToSlotId (Xhc, RouteChart); - if (SlotId == 0) { - // - // 4.3.1 Resetting a Root Hub Port - // 1) Write the PORTSC register with the Port Reset (PR) bit set to '1'. - // - State |= XHC_PORTSC_RESET; - XhcWriteOpReg (Xhc, Offset, State); - XhcWaitOpRegBit(Xhc, Offset, XHC_PORTSC_PRC, TRUE, XHC_GENERIC_TIMEOUT); - } + State |= XHC_PORTSC_RESET; + XhcWriteOpReg (Xhc, Offset, State); + XhcWaitOpRegBit(Xhc, Offset, XHC_PORTSC_PRC, TRUE, XHC_GENERIC_TIMEOUT); break; case EfiUsbPortPower: @@ -733,6 +773,8 @@ XhcControlTransfer ( UINTN MapSize; EFI_USB_PORT_STATUS PortStatus; UINT32 State; + EFI_USB_DEVICE_REQUEST ClearPortRequest; + UINTN Len; // // Validate parameters @@ -778,6 +820,7 @@ XhcControlTransfer ( Status = EFI_DEVICE_ERROR; *TransferResult = EFI_USB_ERR_SYSTEM; + Len = 0; if (XhcIsHalt (Xhc) || XhcIsSysError (Xhc)) { DEBUG ((EFI_D_ERROR, "XhcControlTransfer: HC halted at entrance\n")); @@ -809,6 +852,11 @@ XhcControlTransfer ( Xhc->UsbDevContext[Index + 1].BusDevAddr = 0; } } + + if (Xhc->UsbDevContext[SlotId].XhciDevAddr == 0) { + Status = EFI_DEVICE_ERROR; + goto ON_EXIT; + } // // The actual device address has been assigned by XHCI during initializing the device slot. // So we just need establish the mapping relationship between the device address requested from UsbBus @@ -819,20 +867,6 @@ XhcControlTransfer ( Status = EFI_SUCCESS; goto ON_EXIT; } - - // - // If the port reset operation happens after the usb super speed device is enabled, - // The subsequent configuration, such as getting device descriptor, will fail. - // So here a workaround is introduced to skip the reset operation if the device is enabled. - // - if ((Request->Request == USB_REQ_SET_FEATURE) && - (Request->RequestType == USB_REQUEST_TYPE (EfiUsbNoData, USB_REQ_TYPE_CLASS, USB_TARGET_OTHER)) && - (Request->Value == EfiUsbPortReset)) { - if (DeviceSpeed == EFI_USB_SPEED_SUPER) { - Status = EFI_SUCCESS; - goto ON_EXIT; - } - } // // Create a new URB, insert it into the asynchronous @@ -861,7 +895,7 @@ XhcControlTransfer ( Status = EFI_OUT_OF_RESOURCES; goto ON_EXIT; } - ASSERT (Urb->EvtRing == &Xhc->EventRing); + Status = XhcExecTransfer (Xhc, FALSE, Urb, Timeout); // @@ -875,13 +909,26 @@ XhcControlTransfer ( Status = EFI_SUCCESS; } else if (*TransferResult == EFI_USB_ERR_STALL) { RecoveryStatus = XhcRecoverHaltedEndpoint(Xhc, Urb); - ASSERT_EFI_ERROR (RecoveryStatus); + if (EFI_ERROR (RecoveryStatus)) { + DEBUG ((EFI_D_ERROR, "XhcControlTransfer: XhcRecoverHaltedEndpoint failed\n")); + } Status = EFI_DEVICE_ERROR; goto FREE_URB; } else { goto FREE_URB; } + Xhc->PciIo->Flush (Xhc->PciIo); + + if (Urb->DataMap != NULL) { + Status = Xhc->PciIo->Unmap (Xhc->PciIo, Urb->DataMap); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + Status = EFI_DEVICE_ERROR; + goto FREE_URB; + } + } + // // Hook Get_Descriptor request from UsbBus as we need evaluate context and configure endpoint. // Hook Get_Status request form UsbBus as we need trace device attach/detach event happened at hub. @@ -891,7 +938,7 @@ XhcControlTransfer ( ((Request->RequestType == USB_REQUEST_TYPE (EfiUsbDataIn, USB_REQ_TYPE_STANDARD, USB_TARGET_DEVICE)) || ((Request->RequestType == USB_REQUEST_TYPE (EfiUsbDataIn, USB_REQ_TYPE_CLASS, USB_TARGET_DEVICE))))) { DescriptorType = (UINT8)(Request->Value >> 8); - if ((DescriptorType == USB_DESC_TYPE_DEVICE) && (*DataLength == sizeof (EFI_USB_DEVICE_DESCRIPTOR))) { + if ((DescriptorType == USB_DESC_TYPE_DEVICE) && ((*DataLength == sizeof (EFI_USB_DEVICE_DESCRIPTOR)) || ((DeviceSpeed == EFI_USB_SPEED_FULL) && (*DataLength == 8)))) { ASSERT (Data != NULL); // // Store a copy of device scriptor as hub device need this info to configure endpoint. @@ -907,11 +954,10 @@ XhcControlTransfer ( } Xhc->UsbDevContext[SlotId].ConfDesc = AllocateZeroPool (Xhc->UsbDevContext[SlotId].DevDesc.NumConfigurations * sizeof (EFI_USB_CONFIG_DESCRIPTOR *)); if (Xhc->HcCParams.Data.Csz == 0) { - Status = XhcEvaluateContext (Xhc, SlotId, MaxPacket0); + Status = XhcEvaluateContext (Xhc, SlotId, MaxPacket0); } else { - Status = XhcEvaluateContext64 (Xhc, SlotId, MaxPacket0); + Status = XhcEvaluateContext64 (Xhc, SlotId, MaxPacket0); } - ASSERT_EFI_ERROR (Status); } else if (DescriptorType == USB_DESC_TYPE_CONFIG) { ASSERT (Data != NULL); if (*DataLength == ((UINT16 *)Data)[1]) { @@ -922,6 +968,10 @@ XhcControlTransfer ( ASSERT (Index < Xhc->UsbDevContext[SlotId].DevDesc.NumConfigurations); Xhc->UsbDevContext[SlotId].ConfDesc[Index] = AllocateZeroPool(*DataLength); CopyMem (Xhc->UsbDevContext[SlotId].ConfDesc[Index], Data, *DataLength); + // + // Default to use AlternateSetting 0 for all interfaces. + // + Xhc->UsbDevContext[SlotId].ActiveAlternateSetting = AllocateZeroPool (Xhc->UsbDevContext[SlotId].ConfDesc[Index]->NumInterfaces * sizeof (UINT8)); } } else if (((DescriptorType == USB_DESC_TYPE_HUB) || (DescriptorType == USB_DESC_TYPE_HUB_SUPER_SPEED)) && (*DataLength > 2)) { @@ -947,7 +997,6 @@ XhcControlTransfer ( } else { Status = XhcConfigHubContext64 (Xhc, SlotId, HubDesc->NumPorts, TTT, MTT); } - ASSERT_EFI_ERROR (Status); } } else if ((Request->Request == USB_REQ_SET_CONFIG) && (Request->RequestType == USB_REQUEST_TYPE (EfiUsbNoData, USB_REQ_TYPE_STANDARD, USB_TARGET_DEVICE))) { @@ -961,10 +1010,23 @@ XhcControlTransfer ( } else { Status = XhcSetConfigCmd64 (Xhc, SlotId, DeviceSpeed, Xhc->UsbDevContext[SlotId].ConfDesc[Index]); } - ASSERT_EFI_ERROR (Status); break; } } + } else if ((Request->Request == USB_REQ_SET_INTERFACE) && + (Request->RequestType == USB_REQUEST_TYPE (EfiUsbNoData, USB_REQ_TYPE_STANDARD, USB_TARGET_INTERFACE))) { + // + // Hook Set_Interface request from UsbBus as we need configure interface setting. + // Request->Value indicates AlterlateSetting to set + // Request->Index indicates Interface to set + // + if (Xhc->UsbDevContext[SlotId].ActiveAlternateSetting[(UINT8) Request->Index] != (UINT8) Request->Value) { + if (Xhc->HcCParams.Data.Csz == 0) { + Status = XhcSetInterface (Xhc, SlotId, DeviceSpeed, Xhc->UsbDevContext[SlotId].ConfDesc[Xhc->UsbDevContext[SlotId].ActiveConfiguration - 1], Request); + } else { + Status = XhcSetInterface64 (Xhc, SlotId, DeviceSpeed, Xhc->UsbDevContext[SlotId].ConfDesc[Xhc->UsbDevContext[SlotId].ActiveConfiguration - 1], Request); + } + } } else if ((Request->Request == USB_REQ_GET_STATUS) && (Request->RequestType == USB_REQUEST_TYPE (EfiUsbDataIn, USB_REQ_TYPE_CLASS, USB_TARGET_OTHER))) { ASSERT (Data != NULL); @@ -982,37 +1044,64 @@ XhcControlTransfer ( if ((State & XHC_PORTSC_PS) >> 10 == 0) { PortStatus.PortStatus |= USB_PORT_STAT_SUPER_SPEED; } - } else if (DeviceSpeed == EFI_USB_SPEED_HIGH) { + } else { // - // For high speed hub, its bit9~10 presents the attached device speed. + // For high or full/low speed hub, its bit9~10 presents the attached device speed. // if (XHC_BIT_IS_SET (State, BIT9)) { PortStatus.PortStatus |= USB_PORT_STAT_LOW_SPEED; } else if (XHC_BIT_IS_SET (State, BIT10)) { PortStatus.PortStatus |= USB_PORT_STAT_HIGH_SPEED; } - } else { - ASSERT (0); } // // Convert the XHCI port/port change state to UEFI status // - MapSize = sizeof (mUsbPortStateMap) / sizeof (USB_PORT_STATE_MAP); + MapSize = sizeof (mUsbHubPortStateMap) / sizeof (USB_PORT_STATE_MAP); + for (Index = 0; Index < MapSize; Index++) { + if (XHC_BIT_IS_SET (State, mUsbHubPortStateMap[Index].HwState)) { + PortStatus.PortStatus = (UINT16) (PortStatus.PortStatus | mUsbHubPortStateMap[Index].UefiState); + } + } + + MapSize = sizeof (mUsbHubPortChangeMap) / sizeof (USB_PORT_STATE_MAP); for (Index = 0; Index < MapSize; Index++) { - if (XHC_BIT_IS_SET (State, mUsbPortStateMap[Index].HwState)) { - PortStatus.PortStatus = (UINT16) (PortStatus.PortStatus | mUsbPortStateMap[Index].UefiState); + if (XHC_BIT_IS_SET (State, mUsbHubPortChangeMap[Index].HwState)) { + PortStatus.PortChangeStatus = (UINT16) (PortStatus.PortChangeStatus | mUsbHubPortChangeMap[Index].UefiState); } } - MapSize = sizeof (mUsbPortChangeMap) / sizeof (USB_PORT_STATE_MAP); + + MapSize = sizeof (mUsbHubClearPortChangeMap) / sizeof (USB_CLEAR_PORT_MAP); for (Index = 0; Index < MapSize; Index++) { - if (XHC_BIT_IS_SET (State, mUsbPortChangeMap[Index].HwState)) { - PortStatus.PortChangeStatus = (UINT16) (PortStatus.PortChangeStatus | mUsbPortChangeMap[Index].UefiState); + if (XHC_BIT_IS_SET (State, mUsbHubClearPortChangeMap[Index].HwState)) { + ZeroMem (&ClearPortRequest, sizeof (EFI_USB_DEVICE_REQUEST)); + ClearPortRequest.RequestType = USB_REQUEST_TYPE (EfiUsbNoData, USB_REQ_TYPE_CLASS, USB_TARGET_OTHER); + ClearPortRequest.Request = (UINT8) USB_REQ_CLEAR_FEATURE; + ClearPortRequest.Value = mUsbHubClearPortChangeMap[Index].Selector; + ClearPortRequest.Index = Request->Index; + ClearPortRequest.Length = 0; + + XhcControlTransfer ( + This, + DeviceAddress, + DeviceSpeed, + MaximumPacketLength, + &ClearPortRequest, + EfiUsbNoData, + NULL, + &Len, + Timeout, + Translator, + TransferResult + ); } } XhcPollPortStatusChange (Xhc, Xhc->UsbDevContext[SlotId].RouteString, (UINT8)Request->Index, &PortStatus); + + *(UINT32 *)Data = *(UINT32*)&PortStatus; } FREE_URB: @@ -1147,8 +1236,6 @@ XhcBulkTransfer ( goto ON_EXIT; } - ASSERT (Urb->EvtRing == &Xhc->EventRing); - Status = XhcExecTransfer (Xhc, FALSE, Urb, Timeout); *TransferResult = Urb->Result; @@ -1158,11 +1245,14 @@ XhcBulkTransfer ( Status = EFI_SUCCESS; } else if (*TransferResult == EFI_USB_ERR_STALL) { RecoveryStatus = XhcRecoverHaltedEndpoint(Xhc, Urb); - ASSERT_EFI_ERROR (RecoveryStatus); + if (EFI_ERROR (RecoveryStatus)) { + DEBUG ((EFI_D_ERROR, "XhcBulkTransfer: XhcRecoverHaltedEndpoint failed\n")); + } Status = EFI_DEVICE_ERROR; } - FreePool (Urb); + Xhc->PciIo->Flush (Xhc->PciIo); + XhcFreeUrb (Xhc, Urb); ON_EXIT: @@ -1272,7 +1362,7 @@ XhcAsyncInterruptTransfer ( } Status = XhciDelAsyncIntTransfer (Xhc, DeviceAddress, EndPointAddress); - DEBUG ((EFI_D_INFO, "XhcAsyncInterruptTransfer: remove old transfer, Status = %r\n", Status)); + DEBUG ((EFI_D_INFO, "XhcAsyncInterruptTransfer: remove old transfer for addr %d, Status = %r\n", DeviceAddress, Status)); goto ON_EXIT; } @@ -1321,8 +1411,6 @@ XhcAsyncInterruptTransfer ( goto ON_EXIT; } - ASSERT (Urb->EvtRing == &Xhc->EventRing); - InsertHeadList (&Xhc->AsyncIntTransfers, &Urb->UrbList); // // Ring the doorbell @@ -1330,6 +1418,7 @@ XhcAsyncInterruptTransfer ( Status = RingIntTransferDoorBell (Xhc, Urb); ON_EXIT: + Xhc->PciIo->Flush (Xhc->PciIo); gBS->RestoreTPL (OldTpl); return Status; @@ -1394,10 +1483,6 @@ XhcSyncInterruptTransfer ( return EFI_INVALID_PARAMETER; } - if (!XHCI_IS_DATAIN (EndPointAddress)) { - return EFI_INVALID_PARAMETER; - } - if ((*DataToggle != 1) && (*DataToggle != 0)) { return EFI_INVALID_PARAMETER; } @@ -1457,11 +1542,14 @@ XhcSyncInterruptTransfer ( Status = EFI_SUCCESS; } else if (*TransferResult == EFI_USB_ERR_STALL) { RecoveryStatus = XhcRecoverHaltedEndpoint(Xhc, Urb); - ASSERT_EFI_ERROR (RecoveryStatus); + if (EFI_ERROR (RecoveryStatus)) { + DEBUG ((EFI_D_ERROR, "XhcSyncInterruptTransfer: XhcRecoverHaltedEndpoint failed\n")); + } Status = EFI_DEVICE_ERROR; } - FreePool (Urb); + Xhc->PciIo->Flush (Xhc->PciIo); + XhcFreeUrb (Xhc, Urb); ON_EXIT: if (EFI_ERROR (Status)) { @@ -1661,6 +1749,7 @@ ON_EXIT: Create and initialize a USB_XHCI_INSTANCE structure. @param PciIo The PciIo on this device. + @param DevicePath The device path of host controller. @param OriginalPciAttributes Original PCI attributes. @return The allocated and initialized USB_XHCI_INSTANCE structure if created, @@ -1669,8 +1758,9 @@ ON_EXIT: **/ USB_XHCI_INSTANCE* XhcCreateUsbHc ( - IN EFI_PCI_IO_PROTOCOL *PciIo, - IN UINT64 OriginalPciAttributes + IN EFI_PCI_IO_PROTOCOL *PciIo, + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, + IN UINT64 OriginalPciAttributes ) { USB_XHCI_INSTANCE *Xhc; @@ -1689,6 +1779,7 @@ XhcCreateUsbHc ( // Xhc->Signature = XHCI_INSTANCE_SIG; Xhc->PciIo = PciIo; + Xhc->DevicePath = DevicePath; Xhc->OriginalPciAttributes = OriginalPciAttributes; CopyMem (&Xhc->Usb2Hc, &gXhciUsb2HcTemplate, sizeof (EFI_USB2_HC_PROTOCOL)); @@ -1714,7 +1805,8 @@ XhcCreateUsbHc ( ExtCapReg = (UINT16) (Xhc->HcCParams.Data.ExtCapReg); Xhc->ExtCapRegBase = ExtCapReg << 2; - Xhc->UsbLegSupOffset = XhcGetLegSupCapAddr (Xhc); + Xhc->UsbLegSupOffset = XhcGetCapabilityAddr (Xhc, XHC_CAP_USB_LEGACY); + Xhc->DebugCapSupOffset = XhcGetCapabilityAddr (Xhc, XHC_CAP_USB_DEBUG); DEBUG ((EFI_D_INFO, "XhcCreateUsb3Hc: Capability length 0x%x\n", Xhc->CapLength)); DEBUG ((EFI_D_INFO, "XhcCreateUsb3Hc: HcSParams1 0x%x\n", Xhc->HcSParams1)); @@ -1723,13 +1815,14 @@ XhcCreateUsbHc ( DEBUG ((EFI_D_INFO, "XhcCreateUsb3Hc: DBOff 0x%x\n", Xhc->DBOff)); DEBUG ((EFI_D_INFO, "XhcCreateUsb3Hc: RTSOff 0x%x\n", Xhc->RTSOff)); DEBUG ((EFI_D_INFO, "XhcCreateUsb3Hc: UsbLegSupOffset 0x%x\n", Xhc->UsbLegSupOffset)); + DEBUG ((EFI_D_INFO, "XhcCreateUsb3Hc: DebugCapSupOffset 0x%x\n", Xhc->DebugCapSupOffset)); // // Create AsyncRequest Polling Timer // Status = gBS->CreateEvent ( EVT_TIMER | EVT_NOTIFY_SIGNAL, - TPL_CALLBACK, + TPL_NOTIFY, XhcMonitorAsyncRequests, Xhc, &Xhc->PollTimer @@ -1750,7 +1843,7 @@ ON_ERROR: One notified function to stop the Host Controller when gBS->ExitBootServices() called. @param Event Pointer to this event - @param Context Event hanlder private data + @param Context Event handler private data **/ VOID @@ -1778,6 +1871,8 @@ XhcExitBootService ( gBS->CloseEvent (Xhc->PollTimer); } + XhcClearBiosOwnership (Xhc); + // // Restore original PCI attributes // @@ -1787,8 +1882,6 @@ XhcExitBootService ( Xhc->OriginalPciAttributes, NULL ); - - XhcClearBiosOwnership (Xhc); } /** @@ -1818,6 +1911,7 @@ XhcDriverBindingStart ( UINT64 OriginalPciAttributes; BOOLEAN PciAttributesSaved; USB_XHCI_INSTANCE *Xhc; + EFI_DEVICE_PATH_PROTOCOL *HcDevicePath; // // Open the PciIo Protocol, then enable the USB host controller @@ -1835,6 +1929,19 @@ XhcDriverBindingStart ( return Status; } + // + // Open Device Path Protocol for on USB host controller + // + HcDevicePath = NULL; + Status = gBS->OpenProtocol ( + Controller, + &gEfiDevicePathProtocolGuid, + (VOID **) &HcDevicePath, + This->DriverBindingHandle, + Controller, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + PciAttributesSaved = FALSE; // // Save original PCI attributes @@ -1858,7 +1965,7 @@ XhcDriverBindingStart ( &Supports ); if (!EFI_ERROR (Status)) { - Supports &= EFI_PCI_DEVICE_ENABLE; + Supports &= (UINT64)EFI_PCI_DEVICE_ENABLE; Status = PciIo->Attributes ( PciIo, EfiPciIoAttributeOperationEnable, @@ -1875,7 +1982,7 @@ XhcDriverBindingStart ( // // Create then install USB2_HC_PROTOCOL // - Xhc = XhcCreateUsbHc (PciIo, OriginalPciAttributes); + Xhc = XhcCreateUsbHc (PciIo, HcDevicePath, OriginalPciAttributes); if (Xhc == NULL) { DEBUG ((EFI_D_ERROR, "XhcDriverBindingStart: failed to create USB2_HC\n")); @@ -2036,6 +2143,16 @@ XhcDriverBindingStop ( return Status; } + Status = gBS->UninstallProtocolInterface ( + Controller, + &gEfiUsb2HcProtocolGuid, + Usb2Hc + ); + + if (EFI_ERROR (Status)) { + return Status; + } + Xhc = XHC_FROM_THIS (Usb2Hc); PciIo = Xhc->PciIo; @@ -2061,19 +2178,6 @@ XhcDriverBindingStop ( } } - XhcHaltHC (Xhc, XHC_GENERIC_TIMEOUT); - XhcClearBiosOwnership (Xhc); - - Status = gBS->UninstallProtocolInterface ( - Controller, - &gEfiUsb2HcProtocolGuid, - Usb2Hc - ); - - if (EFI_ERROR (Status)) { - return Status; - } - if (Xhc->PollTimer != NULL) { gBS->CloseEvent (Xhc->PollTimer); } @@ -2082,6 +2186,8 @@ XhcDriverBindingStop ( gBS->CloseEvent (Xhc->ExitBootServiceEvent); } + XhcHaltHC (Xhc, XHC_GENERIC_TIMEOUT); + XhcClearBiosOwnership (Xhc); XhciDelAllAsyncIntTransfers (Xhc); XhcFreeSched (Xhc);