X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FBus%2FPci%2FUhciDxe%2FUhci.c;h=92567f93e48d565bd626fbfa84b1bfd68fa8af40;hp=00108b87e2b218afad494582bd5ca99032c84d72;hb=cd5ebaa06dca3e6ef3c464081e6defe00d358c69;hpb=41e8ff2781f3ca14f73ef5f39e781ccba8cb373d diff --git a/MdeModulePkg/Bus/Pci/UhciDxe/Uhci.c b/MdeModulePkg/Bus/Pci/UhciDxe/Uhci.c index 00108b87e2..92567f93e4 100644 --- a/MdeModulePkg/Bus/Pci/UhciDxe/Uhci.c +++ b/MdeModulePkg/Bus/Pci/UhciDxe/Uhci.c @@ -1,7 +1,9 @@ /** @file -Copyright (c) 2004 - 2007, Intel Corporation -All rights reserved. This program and the accompanying materials + The UHCI driver model and HC protocol routines. + +Copyright (c) 2004 - 2010, 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 http://opensource.org/licenses/bsd-license.php @@ -9,47 +11,51 @@ http://opensource.org/licenses/bsd-license.php THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -Module Name: - - Uhci.c - -Abstract: - - The UHCI driver model and HC protocol routines. - -Revision History - - **/ #include "Uhci.h" +EFI_DRIVER_BINDING_PROTOCOL gUhciDriverBinding = { + UhciDriverBindingSupported, + UhciDriverBindingStart, + UhciDriverBindingStop, + 0x20, + NULL, + NULL +}; + /** - Provides software reset for the USB host controller. + Provides software reset for the USB host controller according to UEFI 2.0 spec. - This : A pointer to the EFI_USB_HC_PROTOCOL instance. - Attributes: A bit mask of the reset operation to perform. + @param This A pointer to the EFI_USB2_HC_PROTOCOL instance. + @param Attributes A bit mask of the reset operation to perform. See + below for a list of the supported bit mask values. - @return EFI_SUCCESS : The reset operation succeeded. - @return EFI_INVALID_PARAMETER : Attributes is not valid. - @return EFI_DEVICE_ERROR : An error was encountered while attempting - @return to perform the reset operation. + @return EFI_SUCCESS The reset operation succeeded. + @return EFI_INVALID_PARAMETER Attributes is not valid. + @return EFI_UNSUPPORTED This type of reset is not currently supported. + @return EFI_DEVICE_ERROR Other errors. **/ -STATIC EFI_STATUS EFIAPI -UhciReset ( - IN EFI_USB_HC_PROTOCOL *This, - IN UINT16 Attributes +Uhci2Reset ( + IN EFI_USB2_HC_PROTOCOL *This, + IN UINT16 Attributes ) { USB_HC_DEV *Uhc; EFI_TPL OldTpl; + if ((Attributes == EFI_USB_HC_RESET_GLOBAL_WITH_DEBUG) || + (Attributes == EFI_USB_HC_RESET_HOST_WITH_DEBUG)) { + return EFI_UNSUPPORTED; + } + + Uhc = UHC_FROM_USB2_HC_PROTO (This); + OldTpl = gBS->RaiseTPL (UHCI_TPL); - Uhc = UHC_FROM_USB_HC_PROTO (This); switch (Attributes) { case EFI_USB_HC_RESET_GLOBAL: @@ -82,7 +88,7 @@ UhciReset ( default: goto ON_INVAILD_PARAMETER; } - + // // Delete all old transactions on the USB bus, then // reinitialize the frame list @@ -92,35 +98,33 @@ UhciReset ( UhciInitFrameList (Uhc); gBS->RestoreTPL (OldTpl); - + return EFI_SUCCESS; ON_INVAILD_PARAMETER: - + gBS->RestoreTPL (OldTpl); - + return EFI_INVALID_PARAMETER; } /** - Retrieves current state of the USB host controller. + Retrieves current state of the USB host controller according to UEFI 2.0 spec. - This : A pointer to the EFI_USB_HC_PROTOCOL instance. - State : A pointer to the EFI_USB_HC_STATE data structure that - indicates current state of the USB host controller. + @param This A pointer to the EFI_USB2_HC_PROTOCOL instance. + @param State Variable to receive current device state. - @return EFI_SUCCESS : State was returned - @return EFI_INVALID_PARAMETER : State is NULL. - @return EFI_DEVICE_ERROR : An error was encountered + @return EFI_SUCCESS The state is returned. + @return EFI_INVALID_PARAMETER State is not valid. + @return EFI_DEVICE_ERROR Other errors. **/ -STATIC EFI_STATUS EFIAPI -UhciGetState ( - IN EFI_USB_HC_PROTOCOL *This, - OUT EFI_USB_HC_STATE *State +Uhci2GetState ( + IN CONST EFI_USB2_HC_PROTOCOL *This, + OUT EFI_USB_HC_STATE *State ) { USB_HC_DEV *Uhc; @@ -131,12 +135,12 @@ UhciGetState ( return EFI_INVALID_PARAMETER; } - Uhc = UHC_FROM_USB_HC_PROTO (This); + Uhc = UHC_FROM_USB2_HC_PROTO (This); UsbCmd = UhciReadReg (Uhc->PciIo, USBCMD_OFFSET); UsbSts = UhciReadReg (Uhc->PciIo, USBSTS_OFFSET); - if (UsbCmd & USBCMD_EGSM) { + if ((UsbCmd & USBCMD_EGSM) !=0 ) { *State = EfiUsbHcStateSuspend; } else if ((UsbSts & USBSTS_HCH) != 0) { @@ -151,21 +155,21 @@ UhciGetState ( /** - Sets the USB host controller to a specific state. + Sets the USB host controller to a specific state according to UEFI 2.0 spec. - This : A pointer to the EFI_USB_HC_PROTOCOL instance. - State : Indicates the state of the host controller that will be set. + @param This A pointer to the EFI_USB2_HC_PROTOCOL instance. + @param State Indicates the state of the host controller that will + be set. - @return EFI_SUCCESS : The USB host controller was successfully set - @return EFI_INVALID_PARAMETER : State is invalid. - @return EFI_DEVICE_ERROR : Failed to set the state specified + @return EFI_SUCCESS Host controller was successfully placed in the state. + @return EFI_INVALID_PARAMETER State is invalid. + @return EFI_DEVICE_ERROR Failed to set the state. **/ -STATIC EFI_STATUS EFIAPI -UhciSetState ( - IN EFI_USB_HC_PROTOCOL *This, +Uhci2SetState ( + IN EFI_USB2_HC_PROTOCOL *This, IN EFI_USB_HC_STATE State ) { @@ -175,8 +179,8 @@ UhciSetState ( EFI_STATUS Status; UINT16 UsbCmd; - Uhc = UHC_FROM_USB_HC_PROTO (This); - Status = UhciGetState (This, &CurState); + Uhc = UHC_FROM_USB2_HC_PROTO (This); + Status = Uhci2GetState (This, &CurState); if (EFI_ERROR (Status)) { return EFI_DEVICE_ERROR; @@ -213,7 +217,7 @@ UhciSetState ( UsbCmd |= USBCMD_FGR; UhciWriteReg (Uhc->PciIo, USBCMD_OFFSET, UsbCmd); } - + // // wait 20ms to let resume complete (20ms is specified by UHCI spec) // @@ -231,13 +235,13 @@ UhciSetState ( break; case EfiUsbHcStateSuspend: - Status = UhciSetState (This, EfiUsbHcStateHalt); + Status = Uhci2SetState (This, EfiUsbHcStateHalt); if (EFI_ERROR (Status)) { Status = EFI_DEVICE_ERROR; goto ON_EXIT; } - + // // Set Enter Global Suspend Mode bit to 1. // @@ -256,24 +260,28 @@ ON_EXIT: return Status; } - /** - Retrieves the number of root hub ports. + Retrieves capabilities of USB host controller according to UEFI 2.0 spec. - This : A pointer to the EFI_USB_HC_PROTOCOL instance. - PortNumber : A pointer to the number of the root hub ports. + @param This A pointer to the EFI_USB2_HC_PROTOCOL instance. + @param MaxSpeed A pointer to the max speed USB host controller + supports. + @param PortNumber A pointer to the number of root hub ports. + @param Is64BitCapable A pointer to an integer to show whether USB host + controller supports 64-bit memory addressing. - @return EFI_SUCCESS : The port number was retrieved successfully. - @return EFI_INVALID_PARAMETER : PortNumber is NULL. - @return EFI_DEVICE_ERROR : An error was encountered + @return EFI_SUCCESS capabilities were retrieved successfully. + @return EFI_INVALID_PARAMETER MaxSpeed or PortNumber or Is64BitCapable is NULL. + @return EFI_DEVICE_ERROR An error was encountered. **/ -STATIC EFI_STATUS EFIAPI -UhciGetRootHubPortNumber ( - IN EFI_USB_HC_PROTOCOL *This, - OUT UINT8 *PortNumber +Uhci2GetCapability ( + IN EFI_USB2_HC_PROTOCOL *This, + OUT UINT8 *MaxSpeed, + OUT UINT8 *PortNumber, + OUT UINT8 *Is64BitCapable ) { USB_HC_DEV *Uhc; @@ -281,12 +289,15 @@ UhciGetRootHubPortNumber ( UINT16 PortSC; UINT32 Index; - Uhc = UHC_FROM_USB_HC_PROTO (This); + Uhc = UHC_FROM_USB2_HC_PROTO (This); - if (PortNumber == NULL) { + if ((NULL == MaxSpeed) || (NULL == PortNumber) || (NULL == Is64BitCapable)) { return EFI_INVALID_PARAMETER; } + *MaxSpeed = EFI_USB_SPEED_FULL; + *Is64BitCapable = (UINT8) FALSE; + *PortNumber = 0; for (Index = 0; Index < USB_MAX_ROOTHUB_PORT; Index++) { @@ -299,43 +310,45 @@ UhciGetRootHubPortNumber ( // returns 0 in this bit if port number is invalid. Also, if // PciIo IoRead returns error, 0xFFFF is returned to caller. // - if (((PortSC & 0x80) != 0) && (PortSC != 0xFFFF)) { - (*PortNumber)++; + if (((PortSC & 0x80) == 0) || (PortSC == 0xFFFF)) { + break; } + (*PortNumber)++; } Uhc->RootPorts = *PortNumber; - UHCI_DEBUG (("UhciGetRootHubPortNumber: %d ports\n", Uhc->RootPorts)); + DEBUG ((EFI_D_INFO, "Uhci2GetCapability: %d ports\n", (UINT32)Uhc->RootPorts)); return EFI_SUCCESS; } /** - Retrieves the current status of a USB root hub port. + Retrieves the current status of a USB root hub port according to UEFI 2.0 spec. - This : A pointer to the EFI_USB_HC_PROTOCOL. - PortNumber : Specifies the root hub port. This value is zero-based. - PortStatus : A pointer to the current port status bits and port status change bits. + @param This A pointer to the EFI_USB2_HC_PROTOCOL. + @param PortNumber The port to get status. + @param PortStatus A pointer to the current port status bits and port + status change bits. - @return EFI_SUCCESS : The port status was returned in PortStatus. - @return EFI_INVALID_PARAMETER : PortNumber is invalid. - @return EFI_DEVICE_ERROR : Can't read register + @return EFI_SUCCESS status of the USB root hub port was returned in PortStatus. + @return EFI_INVALID_PARAMETER PortNumber is invalid. + @return EFI_DEVICE_ERROR Can't read register. **/ EFI_STATUS EFIAPI -UhciGetRootHubPortStatus ( - IN EFI_USB_HC_PROTOCOL *This, - IN UINT8 PortNumber, - OUT EFI_USB_PORT_STATUS *PortStatus +Uhci2GetRootHubPortStatus ( + IN CONST EFI_USB2_HC_PROTOCOL *This, + IN CONST UINT8 PortNumber, + OUT EFI_USB_PORT_STATUS *PortStatus ) { USB_HC_DEV *Uhc; UINT32 Offset; UINT16 PortSC; - Uhc = UHC_FROM_USB_HC_PROTO (This); + Uhc = UHC_FROM_USB2_HC_PROTO (This); if (PortStatus == NULL) { return EFI_INVALID_PARAMETER; @@ -351,24 +364,24 @@ UhciGetRootHubPortStatus ( PortSC = UhciReadReg (Uhc->PciIo, Offset); - if (PortSC & USBPORTSC_CCS) { + if ((PortSC & USBPORTSC_CCS) != 0) { PortStatus->PortStatus |= USB_PORT_STAT_CONNECTION; } - if (PortSC & USBPORTSC_PED) { + if ((PortSC & USBPORTSC_PED) != 0) { PortStatus->PortStatus |= USB_PORT_STAT_ENABLE; } - if (PortSC & USBPORTSC_SUSP) { - UHCI_DEBUG (("UhciGetRootHubPortStatus: port %d is suspended\n", PortNumber)); + if ((PortSC & USBPORTSC_SUSP) != 0) { + DEBUG ((EFI_D_INFO, "Uhci2GetRootHubPortStatus: port %d is suspended\n", PortNumber)); PortStatus->PortStatus |= USB_PORT_STAT_SUSPEND; } - if (PortSC & USBPORTSC_PR) { + if ((PortSC & USBPORTSC_PR) != 0) { PortStatus->PortStatus |= USB_PORT_STAT_RESET; } - if (PortSC & USBPORTSC_LSDA) { + if ((PortSC & USBPORTSC_LSDA) != 0) { PortStatus->PortStatus |= USB_PORT_STAT_LOW_SPEED; } @@ -377,11 +390,11 @@ UhciGetRootHubPortStatus ( // PortStatus->PortStatus |= USB_PORT_STAT_OWNER; - if (PortSC & USBPORTSC_CSC) { + if ((PortSC & USBPORTSC_CSC) != 0) { PortStatus->PortChangeStatus |= USB_PORT_STAT_C_CONNECTION; } - if (PortSC & USBPORTSC_PEDC) { + if ((PortSC & USBPORTSC_PEDC) != 0) { PortStatus->PortChangeStatus |= USB_PORT_STAT_C_ENABLE; } @@ -390,26 +403,25 @@ UhciGetRootHubPortStatus ( /** - Sets a feature for the specified root hub port. + Sets a feature for the specified root hub port according to UEFI 2.0 spec. - This : A pointer to the EFI_USB_HC_PROTOCOL. - PortNumber : Specifies the root hub port whose feature - is requested to be set. - PortFeature : Indicates the feature selector associated - with the feature set request. + @param This A pointer to the EFI_USB2_HC_PROTOCOL. + @param PortNumber Specifies the root hub port whose feature is + requested to be set. + @param PortFeature Indicates the feature selector associated with the + feature set request. - @return EFI_SUCCESS : The feature was set for the port. - @return EFI_INVALID_PARAMETER : PortNumber is invalid or PortFeature is invalid. - @return EFI_DEVICE_ERROR : Can't read register + @return EFI_SUCCESS PortFeature was set for the root port. + @return EFI_INVALID_PARAMETER PortNumber is invalid or PortFeature is invalid. + @return EFI_DEVICE_ERROR Can't read register. **/ -STATIC EFI_STATUS EFIAPI -UhciSetRootHubPortFeature ( - IN EFI_USB_HC_PROTOCOL *This, - IN UINT8 PortNumber, - IN EFI_USB_PORT_FEATURE PortFeature +Uhci2SetRootHubPortFeature ( + IN EFI_USB2_HC_PROTOCOL *This, + IN UINT8 PortNumber, + IN EFI_USB_PORT_FEATURE PortFeature ) { USB_HC_DEV *Uhc; @@ -418,7 +430,7 @@ UhciSetRootHubPortFeature ( UINT16 PortSC; UINT16 Command; - Uhc = UHC_FROM_USB_HC_PROTO (This); + Uhc = UHC_FROM_USB2_HC_PROTO (This); if (PortNumber >= Uhc->RootPorts) { return EFI_INVALID_PARAMETER; @@ -432,7 +444,7 @@ UhciSetRootHubPortFeature ( switch (PortFeature) { case EfiUsbPortSuspend: Command = UhciReadReg (Uhc->PciIo, USBCMD_OFFSET); - if (!(Command & USBCMD_EGSM)) { + if ((Command & USBCMD_EGSM) == 0) { // // if global suspend is not active, can set port suspend // @@ -470,26 +482,25 @@ UhciSetRootHubPortFeature ( /** - Clears a feature for the specified root hub port. + Clears a feature for the specified root hub port according to Uefi 2.0 spec. - This : A pointer to the EFI_USB_HC_PROTOCOL instance. - PortNumber : Specifies the root hub port whose feature - is requested to be cleared. - PortFeature : Indicates the feature selector associated with the - feature clear request. + @param This A pointer to the EFI_USB2_HC_PROTOCOL instance. + @param PortNumber Specifies the root hub port whose feature is + requested to be cleared. + @param PortFeature Indicates the feature selector associated with the + feature clear request. - @return EFI_SUCCESS : The feature was cleared for the port. - @return EFI_INVALID_PARAMETER : PortNumber is invalid or PortFeature is invalid. - @return EFI_DEVICE_ERROR : Can't read register + @return EFI_SUCCESS PortFeature was cleared for the USB root hub port. + @return EFI_INVALID_PARAMETER PortNumber is invalid or PortFeature is invalid. + @return EFI_DEVICE_ERROR Can't read register. **/ -STATIC EFI_STATUS EFIAPI -UhciClearRootHubPortFeature ( - IN EFI_USB_HC_PROTOCOL *This, - IN UINT8 PortNumber, - IN EFI_USB_PORT_FEATURE PortFeature +Uhci2ClearRootHubPortFeature ( + IN EFI_USB2_HC_PROTOCOL *This, + IN UINT8 PortNumber, + IN EFI_USB_PORT_FEATURE PortFeature ) { USB_HC_DEV *Uhc; @@ -497,7 +508,7 @@ UhciClearRootHubPortFeature ( UINT32 Offset; UINT16 PortSC; - Uhc = UHC_FROM_USB_HC_PROTO (This); + Uhc = UHC_FROM_USB2_HC_PROTO (This); if (PortNumber >= Uhc->RootPorts) { return EFI_INVALID_PARAMETER; @@ -574,40 +585,41 @@ UhciClearRootHubPortFeature ( /** - Submits control transfer to a target USB device. - - This : A pointer to the EFI_USB_HC_PROTOCOL instance. - DeviceAddress : Usb device address - IsSlowDevice : Whether the device is of slow speed or full speed - MaximumPacketLength : maximum packet size of the default control endpoint - Request : USB device request to send - TransferDirection : Specifies the data direction for the transfer. - Data : Data buffer to transmit from or receive into - DataLength : Number of bytes of the data - TimeOut : Maximum time, in microseconds - TransferResult : Return result in this - - @return EFI_SUCCESS : Transfer was completed successfully. - @return EFI_OUT_OF_RESOURCES : Failed due to a lack of resources. - @return EFI_INVALID_PARAMETER : Some parameters are invalid. - @return EFI_TIMEOUT : Failed due to timeout. - @return EFI_DEVICE_ERROR : Failed due to host controller or device error. + Submits control transfer to a target USB device accroding to UEFI 2.0 spec. + + @param This A pointer to the EFI_USB2_HC_PROTOCOL instance. + @param DeviceAddress Target device address. + @param DeviceSpeed Device speed. + @param MaximumPacketLength Maximum packet size of the target endpoint. + @param Request USB device request to send. + @param TransferDirection Data direction of the Data stage in control transfer. + @param Data Data to transmit/receive in data stage. + @param DataLength Length of the data. + @param TimeOut Maximum time, in microseconds, for transfer to complete. + @param Translator Transaction translator to be used by this device. + @param TransferResult Variable to receive the transfer result. + + @return EFI_SUCCESS The control transfer was completed successfully. + @return EFI_OUT_OF_RESOURCES Failed due to lack of resource. + @return EFI_INVALID_PARAMETER Some parameters are invalid. + @return EFI_TIMEOUT Failed due to timeout. + @return EFI_DEVICE_ERROR Failed due to host controller or device error. **/ -STATIC EFI_STATUS EFIAPI -UhciControlTransfer ( - IN EFI_USB_HC_PROTOCOL *This, - IN UINT8 DeviceAddress, - IN BOOLEAN IsSlowDevice, - IN UINT8 MaximumPacketLength, - IN EFI_USB_DEVICE_REQUEST *Request, - IN EFI_USB_DATA_DIRECTION TransferDirection, - IN OUT VOID *Data, OPTIONAL - IN OUT UINTN *DataLength, OPTIONAL - IN UINTN TimeOut, - OUT UINT32 *TransferResult +Uhci2ControlTransfer ( + IN EFI_USB2_HC_PROTOCOL *This, + IN UINT8 DeviceAddress, + IN UINT8 DeviceSpeed, + IN UINTN MaximumPacketLength, + IN EFI_USB_DEVICE_REQUEST *Request, + IN EFI_USB_DATA_DIRECTION TransferDirection, + IN OUT VOID *Data, + IN OUT UINTN *DataLength, + IN UINTN TimeOut, + IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator, + OUT UINT32 *TransferResult ) { USB_HC_DEV *Uhc; @@ -620,14 +632,18 @@ UhciControlTransfer ( VOID *RequestMap; UINT8 *DataPhy; VOID *DataMap; + BOOLEAN IsSlowDevice; + UINTN TransferDataLength; - Uhc = UHC_FROM_USB_HC_PROTO (This); + Uhc = UHC_FROM_USB2_HC_PROTO (This); TDs = NULL; DataPhy = NULL; DataMap = NULL; RequestPhy = NULL; RequestMap = NULL; + IsSlowDevice = (BOOLEAN) ((EFI_USB_SPEED_LOW == DeviceSpeed) ? TRUE : FALSE); + // // Parameters Checking // @@ -645,10 +661,16 @@ UhciControlTransfer ( return EFI_INVALID_PARAMETER; } - if ((TransferDirection != EfiUsbNoData) && (DataLength == NULL)) { + if ((TransferDirection != EfiUsbNoData) && (Data == NULL || DataLength == NULL)) { return EFI_INVALID_PARAMETER; } + if (TransferDirection == EfiUsbNoData) { + TransferDataLength = 0; + } else { + TransferDataLength = *DataLength; + } + *TransferResult = EFI_USB_ERR_SYSTEM; Status = EFI_DEVICE_ERROR; @@ -685,10 +707,12 @@ UhciControlTransfer ( Uhc, DeviceAddress, PktId, + (UINT8*)Request, RequestPhy, + (UINT8*)Data, DataPhy, - *DataLength, - MaximumPacketLength, + TransferDataLength, + (UINT8) MaximumPacketLength, IsSlowDevice ); @@ -702,7 +726,7 @@ UhciControlTransfer ( // the TD to corrosponding queue head, then check // the execution result // - UhciLinkTdToQh (Uhc->CtrlQh, TDs); + UhciLinkTdToQh (Uhc, Uhc->CtrlQh, TDs); Status = UhciExecuteTransfer (Uhc, Uhc->CtrlQh, TDs, TimeOut, IsSlowDevice, &QhResult); UhciUnlinkTdFromQh (Uhc->CtrlQh, TDs); @@ -729,36 +753,42 @@ ON_EXIT: /** Submits bulk transfer to a bulk endpoint of a USB device. - This :A pointer to the EFI_USB_HC_PROTOCOL instance. - DeviceAddress : Usb device address - EndPointAddress : Endpoint number and endpoint direction - MaximumPacketLength : Maximum packet size of the target endpoint - Data : Data buffer to transmit from or receive into - DataLength : Length of the data buffer - DataToggle : On input, data toggle to use, on output, the next toggle - TimeOut : Indicates the maximum time - TransferResult : Variable to receive the transfer result - - @return EFI_SUCCESS : The bulk transfer was completed successfully. - @return EFI_OUT_OF_RESOURCES : Failed due to lack of resource. - @return EFI_INVALID_PARAMETER : Some parameters are invalid. - @return EFI_TIMEOUT : Failed due to timeout. - @return EFI_DEVICE_ERROR : Failed due to host controller or device error. + @param This A pointer to the EFI_USB2_HC_PROTOCOL instance. + @param DeviceAddress Target device address. + @param EndPointAddress Endpoint number and direction. + @param DeviceSpeed Device speed. + @param MaximumPacketLength Maximum packet size of the target endpoint. + @param DataBuffersNumber Number of data buffers prepared for the transfer. + @param Data Array of pointers to the buffers of data. + @param DataLength On input, size of the data buffer, On output, + actually transferred data size. + @param DataToggle On input, data toggle to use; On output, next data toggle. + @param TimeOut Maximum time out, in microseconds. + @param Translator A pointr to the transaction translator data. + @param TransferResult Variable to receive transfer result. + + @return EFI_SUCCESS The bulk transfer was completed successfully. + @return EFI_OUT_OF_RESOURCES Failed due to lack of resource. + @return EFI_INVALID_PARAMETER Some parameters are invalid. + @return EFI_TIMEOUT Failed due to timeout. + @return EFI_DEVICE_ERROR Failed due to host controller or device error. **/ -STATIC EFI_STATUS EFIAPI -UhciBulkTransfer ( - IN EFI_USB_HC_PROTOCOL *This, - IN UINT8 DeviceAddress, - IN UINT8 EndPointAddress, - IN UINT8 MaximumPacketLength, - IN OUT VOID *Data, - IN OUT UINTN *DataLength, - IN OUT UINT8 *DataToggle, - IN UINTN TimeOut, - OUT UINT32 *TransferResult +Uhci2BulkTransfer ( + IN EFI_USB2_HC_PROTOCOL *This, + IN UINT8 DeviceAddress, + IN UINT8 EndPointAddress, + IN UINT8 DeviceSpeed, + IN UINTN MaximumPacketLength, + IN UINT8 DataBuffersNumber, + IN OUT VOID *Data[EFI_USB_MAX_BULK_BUFFER_NUM], + IN OUT UINTN *DataLength, + IN OUT UINT8 *DataToggle, + IN UINTN TimeOut, + IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator, + OUT UINT32 *TransferResult ) { EFI_USB_DATA_DIRECTION Direction; @@ -772,15 +802,15 @@ UhciBulkTransfer ( UINT8 *DataPhy; VOID *DataMap; - Uhc = UHC_FROM_USB_HC_PROTO (This); + Uhc = UHC_FROM_USB2_HC_PROTO (This); DataPhy = NULL; DataMap = NULL; - if ((DataLength == NULL) || (Data == NULL) || (TransferResult == NULL)) { + if (DeviceSpeed == EFI_USB_SPEED_LOW) { return EFI_INVALID_PARAMETER; } - if (*DataLength == 0) { + if ((DataLength == NULL) || (*DataLength == 0) || (Data == NULL) || (TransferResult == NULL)) { return EFI_INVALID_PARAMETER; } @@ -812,13 +842,13 @@ UhciBulkTransfer ( // Map the source data buffer for bus master access, // then create a list of TDs // - if (EndPointAddress & 0x80) { + if ((EndPointAddress & 0x80) != 0) { Direction = EfiUsbDataIn; } else { Direction = EfiUsbDataOut; } - Status = UhciMapUserData (Uhc, Direction, Data, DataLength, &PktId, &DataPhy, &DataMap); + Status = UhciMapUserData (Uhc, Direction, *Data, DataLength, &PktId, &DataPhy, &DataMap); if (EFI_ERROR (Status)) { goto ON_EXIT; @@ -830,10 +860,11 @@ UhciBulkTransfer ( DeviceAddress, EndPointAddress, PktId, + (UINT8 *)*Data, DataPhy, *DataLength, DataToggle, - MaximumPacketLength, + (UINT8) MaximumPacketLength, FALSE ); @@ -850,7 +881,7 @@ UhciBulkTransfer ( // BulkQh = Uhc->BulkQh; - UhciLinkTdToQh (BulkQh, TDs); + UhciLinkTdToQh (Uhc, BulkQh, TDs); Status = UhciExecuteTransfer (Uhc, BulkQh, TDs, TimeOut, FALSE, &QhResult); UhciUnlinkTdFromQh (BulkQh, TDs); @@ -870,60 +901,63 @@ ON_EXIT: /** - Submits an asynchronous interrupt transfer to an interrupt endpoint of a USB device. - - This : A pointer to the EFI_USB_HC_PROTOCOL instance. - DeviceAddress : Target device address - EndPointAddress : Endpoint number with direction - IsSlowDevice : Whether the target device is slow device or full-speed device. - MaximumPacketLength : Maximum packet size of the target endpoint - IsNewTransfer : If TRUE, submit a new async interrupt transfer, otherwise - cancel an existed one - DataToggle : On input, the data toggle to use; On output, next data toggle - PollingInterval : Interrupt poll rate in milliseconds - DataLength : Length of data to receive - CallBackFunction : Function to call periodically - Context : User context - - @return EFI_SUCCESS : Request is submitted or cancelled - @return EFI_INVALID_PARAMETER : Some parameters are invalid. - @return EFI_OUT_OF_RESOURCES : Failed due to a lack of resources. - @return EFI_DEVICE_ERROR : Failed to due to device error + Submits an asynchronous interrupt transfer to an + interrupt endpoint of a USB device according to UEFI 2.0 spec. + + @param This A pointer to the EFI_USB2_HC_PROTOCOL instance. + @param DeviceAddress Target device address. + @param EndPointAddress Endpoint number and direction. + @param DeviceSpeed Device speed. + @param MaximumPacketLength Maximum packet size of the target endpoint. + @param IsNewTransfer If TRUE, submit a new transfer, if FALSE cancel old transfer. + @param DataToggle On input, data toggle to use; On output, next data toggle. + @param PollingInterval Interrupt poll rate in milliseconds. + @param DataLength On input, size of the data buffer, On output, + actually transferred data size. + @param Translator A pointr to the transaction translator data. + @param CallBackFunction Function to call periodically. + @param Context User context. + + @return EFI_SUCCESS Transfer was submitted. + @return EFI_INVALID_PARAMETER Some parameters are invalid. + @return EFI_OUT_OF_RESOURCES Failed due to a lack of resources. + @return EFI_DEVICE_ERROR Can't read register. **/ -STATIC EFI_STATUS EFIAPI -UhciAsyncInterruptTransfer ( - IN EFI_USB_HC_PROTOCOL * This, +Uhci2AsyncInterruptTransfer ( + IN EFI_USB2_HC_PROTOCOL *This, IN UINT8 DeviceAddress, IN UINT8 EndPointAddress, - IN BOOLEAN IsSlowDevice, - IN UINT8 MaximumPacketLength, + IN UINT8 DeviceSpeed, + IN UINTN MaximumPacketLength, IN BOOLEAN IsNewTransfer, IN OUT UINT8 *DataToggle, - IN UINTN PollingInterval, OPTIONAL - IN UINTN DataLength, OPTIONAL - IN EFI_ASYNC_USB_TRANSFER_CALLBACK CallBackFunction, OPTIONAL - IN VOID *Context OPTIONAL + IN UINTN PollingInterval, + IN UINTN DataLength, + IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator, + IN EFI_ASYNC_USB_TRANSFER_CALLBACK CallBackFunction, + IN VOID *Context ) { USB_HC_DEV *Uhc; + BOOLEAN IsSlowDevice; UHCI_QH_SW *Qh; UHCI_TD_SW *IntTds; EFI_TPL OldTpl; EFI_STATUS Status; UINT8 *DataPtr; UINT8 *DataPhy; - VOID *DataMap; UINT8 PktId; - Uhc = UHC_FROM_USB_HC_PROTO (This); + Uhc = UHC_FROM_USB2_HC_PROTO (This); Qh = NULL; IntTds = NULL; DataPtr = NULL; DataPhy = NULL; - DataMap = NULL; + + IsSlowDevice = (BOOLEAN) ((EFI_USB_SPEED_LOW == DeviceSpeed) ? TRUE : FALSE); if ((EndPointAddress & 0x80) == 0) { return EFI_INVALID_PARAMETER; @@ -962,40 +996,30 @@ UhciAsyncInterruptTransfer ( return EFI_DEVICE_ERROR; } + if ((EndPointAddress & 0x80) == 0) { + PktId = OUTPUT_PACKET_ID; + } else { + PktId = INPUT_PACKET_ID; + } + // // Allocate and map source data buffer for bus master access. // - DataPtr = AllocatePool (DataLength); + DataPtr = UsbHcAllocateMem (Uhc->MemPool, DataLength); if (DataPtr == NULL) { return EFI_OUT_OF_RESOURCES; } - OldTpl = gBS->RaiseTPL (UHCI_TPL); - - // - // Map the user data then create a queue head and - // list of TD for it. - // - Status = UhciMapUserData ( - Uhc, - EfiUsbDataIn, - DataPtr, - &DataLength, - &PktId, - &DataPhy, - &DataMap - ); + DataPhy = (UINT8 *) (UINTN) UsbHcGetPciAddressForHostMem (Uhc->MemPool, DataPtr, DataLength); - if (EFI_ERROR (Status)) { - goto FREE_DATA; - } + OldTpl = gBS->RaiseTPL (UHCI_TPL); Qh = UhciCreateQh (Uhc, PollingInterval); if (Qh == NULL) { Status = EFI_OUT_OF_RESOURCES; - goto UNMAP_DATA; + goto FREE_DATA; } IntTds = UhciCreateBulkOrIntTds ( @@ -1003,10 +1027,11 @@ UhciAsyncInterruptTransfer ( DeviceAddress, EndPointAddress, PktId, + DataPtr, DataPhy, DataLength, DataToggle, - MaximumPacketLength, + (UINT8) MaximumPacketLength, IsSlowDevice ); @@ -1015,7 +1040,7 @@ UhciAsyncInterruptTransfer ( goto DESTORY_QH; } - UhciLinkTdToQh (Qh, IntTds); + UhciLinkTdToQh (Uhc, Qh, IntTds); // // Save QH-TD structures to async Interrupt transfer list, @@ -1029,7 +1054,6 @@ UhciAsyncInterruptTransfer ( EndPointAddress, DataLength, PollingInterval, - DataMap, DataPtr, CallBackFunction, Context, @@ -1040,7 +1064,7 @@ UhciAsyncInterruptTransfer ( goto DESTORY_QH; } - UhciLinkQhToFrameList (Uhc->FrameBase, Qh); + UhciLinkQhToFrameList (Uhc, Qh); gBS->RestoreTPL (OldTpl); return EFI_SUCCESS; @@ -1048,54 +1072,53 @@ UhciAsyncInterruptTransfer ( DESTORY_QH: UsbHcFreeMem (Uhc->MemPool, Qh, sizeof (UHCI_QH_SW)); -UNMAP_DATA: - Uhc->PciIo->Unmap (Uhc->PciIo, DataMap); - FREE_DATA: - gBS->FreePool (DataPtr); + UsbHcFreeMem (Uhc->MemPool, DataPtr, DataLength); Uhc->PciIo->Flush (Uhc->PciIo); gBS->RestoreTPL (OldTpl); return Status; } - /** - Submits synchronous interrupt transfer to an interrupt endpoint of a USB device. - - This : A pointer to the EFI_USB_HC_PROTOCOL instance. - DeviceAddress : Device address of the target USB device - EndPointAddress : Endpoint number and direction - IsSlowDevice : Whether the target device is of slow speed or full speed - MaximumPacketLength : Maximum packet size of target endpoint - Data : Data to transmit or receive - DataLength : On input, data length to transmit or buffer size. - On output, the number of bytes transferred. - DataToggle : On input, data toggle to use; On output, next data toggle - TimeOut : Maximum time, in microseconds, transfer is allowed to complete. - TransferResult : Variable to receive transfer result - - @return EFI_SUCCESS : Transfer was completed successfully. - @return EFI_OUT_OF_RESOURCES : Failed due to lack of resource. - @return EFI_INVALID_PARAMETER : Some parameters are invalid. - @return EFI_TIMEOUT : Failed due to timeout. - @return EFI_DEVICE_ERROR : Failed due to host controller or device error + Submits synchronous interrupt transfer to an interrupt endpoint + of a USB device according to UEFI 2.0 spec. + + + @param This A pointer to the EFI_USB2_HC_PROTOCOL instance. + @param DeviceAddress Target device address. + @param EndPointAddress Endpoint number and direction. + @param DeviceSpeed Device speed. + @param MaximumPacketLength Maximum packet size of the target endpoint. + @param Data Array of pointers to the buffers of data. + @param DataLength On input, size of the data buffer, On output, + actually transferred data size. + @param DataToggle On input, data toggle to use; On output, next data toggle. + @param TimeOut Maximum time out, in microseconds. + @param Translator A pointr to the transaction translator data. + @param TransferResult Variable to receive transfer result. + + @return EFI_SUCCESS The transfer was completed successfully. + @return EFI_OUT_OF_RESOURCES Failed due to lack of resource. + @return EFI_INVALID_PARAMETER Some parameters are invalid. + @return EFI_TIMEOUT Failed due to timeout. + @return EFI_DEVICE_ERROR Failed due to host controller or device error. **/ -STATIC EFI_STATUS EFIAPI -UhciSyncInterruptTransfer ( - IN EFI_USB_HC_PROTOCOL *This, - IN UINT8 DeviceAddress, - IN UINT8 EndPointAddress, - IN BOOLEAN IsSlowDevice, - IN UINT8 MaximumPacketLength, - IN OUT VOID *Data, - IN OUT UINTN *DataLength, - IN OUT UINT8 *DataToggle, - IN UINTN TimeOut, - OUT UINT32 *TransferResult +Uhci2SyncInterruptTransfer ( + IN EFI_USB2_HC_PROTOCOL *This, + IN UINT8 DeviceAddress, + IN UINT8 EndPointAddress, + IN UINT8 DeviceSpeed, + IN UINTN MaximumPacketLength, + IN OUT VOID *Data, + IN OUT UINTN *DataLength, + IN OUT UINT8 *DataToggle, + IN UINTN TimeOut, + IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator, + OUT UINT32 *TransferResult ) { EFI_STATUS Status; @@ -1106,12 +1129,19 @@ UhciSyncInterruptTransfer ( UINT8 *DataPhy; VOID *DataMap; UINT8 PktId; + BOOLEAN IsSlowDevice; - Uhc = UHC_FROM_USB_HC_PROTO (This); + Uhc = UHC_FROM_USB2_HC_PROTO (This); DataPhy = NULL; DataMap = NULL; TDs = NULL; + if (DeviceSpeed == EFI_USB_SPEED_HIGH) { + return EFI_INVALID_PARAMETER; + } + + IsSlowDevice = (BOOLEAN) ((EFI_USB_SPEED_LOW == DeviceSpeed) ? TRUE : FALSE); + if ((DataLength == NULL) || (Data == NULL) || (TransferResult == NULL)) { return EFI_INVALID_PARAMETER; } @@ -1167,10 +1197,11 @@ UhciSyncInterruptTransfer ( DeviceAddress, EndPointAddress, PktId, + (UINT8 *)Data, DataPhy, *DataLength, DataToggle, - MaximumPacketLength, + (UINT8) MaximumPacketLength, IsSlowDevice ); @@ -1182,7 +1213,7 @@ UhciSyncInterruptTransfer ( } - UhciLinkTdToQh (Uhc->SyncIntQh, TDs); + UhciLinkTdToQh (Uhc, Uhc->SyncIntQh, TDs); Status = UhciExecuteTransfer (Uhc, Uhc->SyncIntQh, TDs, TimeOut, IsSlowDevice, &QhResult); @@ -1203,30 +1234,36 @@ ON_EXIT: /** - Submits isochronous transfer to a target USB device. + Submits isochronous transfer to a target USB device according to UEFI 2.0 spec. - This : A pointer to the EFI_USB_HC_PROTOCOL instance. - DeviceAddress : Target device address - EndPointAddress : End point address withdirection - MaximumPacketLength : Maximum packet size of the endpoint - Data : Data to transmit or receive - DataLength : Bytes of the data - TransferResult : Variable to receive the result + @param This A pointer to the EFI_USB2_HC_PROTOCOL instance. + @param DeviceAddress Target device address. + @param EndPointAddress Endpoint number and direction. + @param DeviceSpeed Device speed. + @param MaximumPacketLength Maximum packet size of the target endpoint. + @param DataBuffersNumber Number of data buffers prepared for the transfer. + @param Data Array of pointers to the buffers of data. + @param DataLength On input, size of the data buffer, On output, + actually transferred data size. + @param Translator A pointr to the transaction translator data. + @param TransferResult Variable to receive transfer result. @return EFI_UNSUPPORTED **/ -STATIC EFI_STATUS EFIAPI -UhciIsochronousTransfer ( - IN EFI_USB_HC_PROTOCOL *This, - IN UINT8 DeviceAddress, - IN UINT8 EndPointAddress, - IN UINT8 MaximumPacketLength, - IN OUT VOID *Data, - IN UINTN DataLength, - OUT UINT32 *TransferResult +Uhci2IsochronousTransfer ( + IN EFI_USB2_HC_PROTOCOL *This, + IN UINT8 DeviceAddress, + IN UINT8 EndPointAddress, + IN UINT8 DeviceSpeed, + IN UINTN MaximumPacketLength, + IN UINT8 DataBuffersNumber, + IN OUT VOID *Data[EFI_USB_MAX_ISO_BUFFER_NUM], + IN UINTN DataLength, + IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator, + OUT UINT32 *TransferResult ) { return EFI_UNSUPPORTED; @@ -1234,669 +1271,116 @@ UhciIsochronousTransfer ( /** - Submits Async isochronous transfer to a target USB device. + Submits Async isochronous transfer to a target USB device according to UEFI 2.0 spec. - This : A pointer to the EFI_USB_HC_PROTOCOL instance. - DeviceAddress : Target device address - EndPointAddress : End point address withdirection - MaximumPacketLength : Maximum packet size of the endpoint - Data : Data to transmit or receive - IsochronousCallBack : Function to call when the transfer completes - Context : User context + @param This A pointer to the EFI_USB2_HC_PROTOCOL instance. + @param DeviceAddress Target device address. + @param EndPointAddress Endpoint number and direction. + @param DeviceSpeed Device speed. + @param MaximumPacketLength Maximum packet size of the target endpoint. + @param DataBuffersNumber Number of data buffers prepared for the transfer. + @param Data Array of pointers to the buffers of data. + @param DataLength On input, size of the data buffer, On output, + actually transferred data size. + @param Translator A pointr to the transaction translator data. + @param IsochronousCallBack Function to call when the transfer complete. + @param Context Pass to the call back function as parameter. @return EFI_UNSUPPORTED **/ -STATIC EFI_STATUS EFIAPI -UhciAsyncIsochronousTransfer ( - IN EFI_USB_HC_PROTOCOL * This, - IN UINT8 DeviceAddress, - IN UINT8 EndPointAddress, - IN UINT8 MaximumPacketLength, - IN OUT VOID *Data, - IN UINTN DataLength, - IN EFI_ASYNC_USB_TRANSFER_CALLBACK IsochronousCallBack, - IN VOID *Context OPTIONAL +Uhci2AsyncIsochronousTransfer ( + IN EFI_USB2_HC_PROTOCOL *This, + IN UINT8 DeviceAddress, + IN UINT8 EndPointAddress, + IN UINT8 DeviceSpeed, + IN UINTN MaximumPacketLength, + IN UINT8 DataBuffersNumber, + IN OUT VOID *Data[EFI_USB_MAX_ISO_BUFFER_NUM], + IN UINTN DataLength, + IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator, + IN EFI_ASYNC_USB_TRANSFER_CALLBACK IsochronousCallBack, + IN VOID *Context ) { return EFI_UNSUPPORTED; } - - /** - Provides software reset for the USB host controller according to UEFI 2.0 spec. + Entry point for EFI drivers. - @param This A pointer to the EFI_USB2_HC_PROTOCOL instance. - @param Attributes A bit mask of the reset operation to perform. See - below for a list of the supported bit mask values. + @param ImageHandle EFI_HANDLE. + @param SystemTable EFI_SYSTEM_TABLE. - @return EFI_SUCCESS : The reset operation succeeded. - @return EFI_INVALID_PARAMETER : Attributes is not valid. - @return EFI_UNSUPPORTED : This type of reset is not currently supported - @return EFI_DEVICE_ERROR : Other errors + @retval EFI_SUCCESS Driver is successfully loaded. + @return Others Failed. **/ -STATIC EFI_STATUS EFIAPI -Uhci2Reset ( - IN EFI_USB2_HC_PROTOCOL *This, - IN UINT16 Attributes +UhciDriverEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable ) { - USB_HC_DEV *UhciDev; - - UhciDev = UHC_FROM_USB2_HC_PROTO (This); - - if ((Attributes == EFI_USB_HC_RESET_GLOBAL_WITH_DEBUG) || - (Attributes == EFI_USB_HC_RESET_HOST_WITH_DEBUG)) { - return EFI_UNSUPPORTED; - } - - return UhciReset (&UhciDev->UsbHc, Attributes); + return EfiLibInstallDriverBindingComponentName2 ( + ImageHandle, + SystemTable, + &gUhciDriverBinding, + ImageHandle, + &gUhciComponentName, + &gUhciComponentName2 + ); } /** - Retrieves current state of the USB host controller according to UEFI 2.0 spec. + Test to see if this driver supports ControllerHandle. Any + ControllerHandle that has UsbHcProtocol installed will be supported. - @param This A pointer to the EFI_USB_HC_PROTOCOL instance. - @param State Variable to receive current device state + @param This Protocol instance pointer. + @param Controller Handle of device to test. + @param RemainingDevicePath Not used. - @return EFI_SUCCESS : The state is returned - @return EFI_INVALID_PARAMETER : State is not valid. - @return EFI_DEVICE_ERROR : Other errors2006 + @return EFI_SUCCESS This driver supports this device. + @return EFI_UNSUPPORTED This driver does not support this device. **/ -STATIC EFI_STATUS EFIAPI -Uhci2GetState ( - IN CONST EFI_USB2_HC_PROTOCOL *This, - OUT EFI_USB_HC_STATE *State +UhciDriverBindingSupported ( + IN EFI_DRIVER_BINDING_PROTOCOL *This, + IN EFI_HANDLE Controller, + IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath ) { - USB_HC_DEV *Uhc; + EFI_STATUS OpenStatus; + EFI_STATUS Status; + EFI_PCI_IO_PROTOCOL *PciIo; + USB_CLASSC UsbClassCReg; - Uhc = UHC_FROM_USB2_HC_PROTO (This); - return UhciGetState (&Uhc->UsbHc, State); -} + // + // Test whether there is PCI IO Protocol attached on the controller handle. + // + OpenStatus = gBS->OpenProtocol ( + Controller, + &gEfiPciIoProtocolGuid, + (VOID **) &PciIo, + This->DriverBindingHandle, + Controller, + EFI_OPEN_PROTOCOL_BY_DRIVER + ); - -/** - Sets the USB host controller to a specific state according to UEFI 2.0 spec. - - @param This A pointer to the EFI_USB_HC_PROTOCOL instance. - @param State Indicates the state of the host controller that will - be set. - - @return EFI_SUCCESS : Host controller was successfully placed in the state - @return EFI_INVALID_PARAMETER : State is invalid. - @return EFI_DEVICE_ERROR : Failed to set the state - -**/ -STATIC -EFI_STATUS -EFIAPI -Uhci2SetState ( - IN EFI_USB2_HC_PROTOCOL *This, - IN EFI_USB_HC_STATE State - ) -{ - USB_HC_DEV *Uhc; - - Uhc = UHC_FROM_USB2_HC_PROTO (This); - return UhciSetState (&Uhc->UsbHc, State); -} - - -/** - Retrieves capabilities of USB host controller according to UEFI 2.0 spec. - - @param This A pointer to the EFI_USB2_HC_PROTOCOL instance - @param MaxSpeed A pointer to the max speed USB host controller - supports. - @param PortNumber A pointer to the number of root hub ports. - @param Is64BitCapable A pointer to an integer to show whether USB host - controller supports 64-bit memory addressing. - - @return EFI_SUCCESS : capabilities were retrieved successfully. - @return EFI_INVALID_PARAMETER : MaxSpeed or PortNumber or Is64BitCapable is NULL. - @return EFI_DEVICE_ERROR : An error was encountered - -**/ -STATIC -EFI_STATUS -EFIAPI -Uhci2GetCapability ( - IN EFI_USB2_HC_PROTOCOL *This, - OUT UINT8 *MaxSpeed, - OUT UINT8 *PortNumber, - OUT UINT8 *Is64BitCapable - ) -{ - USB_HC_DEV *Uhc; - - Uhc = UHC_FROM_USB2_HC_PROTO (This); - - if ((NULL == MaxSpeed) || (NULL == PortNumber) || (NULL == Is64BitCapable)) { - return EFI_INVALID_PARAMETER; - } - - *MaxSpeed = EFI_USB_SPEED_FULL; - *Is64BitCapable = (UINT8) FALSE; - - return UhciGetRootHubPortNumber (&Uhc->UsbHc, PortNumber); -} - - -/** - Retrieves the current status of a USB root hub port according to UEFI 2.0 spec. - - @param This A pointer to the EFI_USB2_HC_PROTOCOL. - @param PortNumber The port to get status - @param PortStatus A pointer to the current port status bits and port - status change bits. - - @return EFI_SUCCESS : status of the USB root hub port was returned in PortStatus. - @return EFI_INVALID_PARAMETER : PortNumber is invalid. - @return EFI_DEVICE_ERROR : Can't read register - -**/ -STATIC -EFI_STATUS -EFIAPI -Uhci2GetRootHubPortStatus ( - IN CONST EFI_USB2_HC_PROTOCOL *This, - IN CONST UINT8 PortNumber, - OUT EFI_USB_PORT_STATUS *PortStatus - ) -{ - USB_HC_DEV *Uhc; - - Uhc = UHC_FROM_USB2_HC_PROTO (This); - - return UhciGetRootHubPortStatus (&Uhc->UsbHc, PortNumber, PortStatus); -} - - -/** - Sets a feature for the specified root hub port according to UEFI 2.0 spec. - - @param This A pointer to the EFI_USB2_HC_PROTOCOL. - @param PortNumber Specifies the root hub port whose feature is - requested to be set. - @param PortFeature Indicates the feature selector associated with the - feature set request. - - @return EFI_SUCCESS : PortFeature was set for the root port - @return EFI_INVALID_PARAMETER : PortNumber is invalid or PortFeature is invalid. - @return EFI_DEVICE_ERROR : Can't read register - -**/ -STATIC -EFI_STATUS -EFIAPI -Uhci2SetRootHubPortFeature ( - IN EFI_USB2_HC_PROTOCOL *This, - IN UINT8 PortNumber, - IN EFI_USB_PORT_FEATURE PortFeature - ) -{ - USB_HC_DEV *Uhc; - - Uhc = UHC_FROM_USB2_HC_PROTO (This); - - return UhciSetRootHubPortFeature (&Uhc->UsbHc, PortNumber, PortFeature); -} - - -/** - Clears a feature for the specified root hub port according to Uefi 2.0 spec. - - @param This A pointer to the EFI_USB2_HC_PROTOCOL instance. - @param PortNumber Specifies the root hub port whose feature is - requested to be cleared. - @param PortFeature Indicates the feature selector associated with the - feature clear request. - - @return EFI_SUCCESS : PortFeature was cleared for the USB root hub port - @return EFI_INVALID_PARAMETER : PortNumber is invalid or PortFeature is invalid. - @return EFI_DEVICE_ERROR : Can't read register - -**/ -STATIC -EFI_STATUS -EFIAPI -Uhci2ClearRootHubPortFeature ( - IN EFI_USB2_HC_PROTOCOL *This, - IN UINT8 PortNumber, - IN EFI_USB_PORT_FEATURE PortFeature - ) -{ - USB_HC_DEV *Uhc; - - Uhc = UHC_FROM_USB2_HC_PROTO (This); - - return UhciClearRootHubPortFeature (&Uhc->UsbHc, PortNumber, PortFeature); -} - - -/** - Submits control transfer to a target USB device accroding to UEFI 2.0 spec.. - - This : A pointer to the EFI_USB2_HC_PROTOCOL instance. - DeviceAddress : Target device address - DeviceSpeed : Device speed - MaximumPacketLength : Maximum packet size of the target endpoint - Request : USB device request to send - TransferDirection : Data direction of the Data stage in control transfer - Data : Data to transmit/receive in data stage - DataLength : Length of the data - TimeOut : Maximum time, in microseconds, for transfer to complete. - TransferResult : Variable to receive the transfer result - - @return EFI_SUCCESS : The control transfer was completed successfully. - @return EFI_OUT_OF_RESOURCES : Failed due to lack of resource. - @return EFI_INVALID_PARAMETER : Some parameters are invalid. - @return EFI_TIMEOUT : Failed due to timeout. - @return EFI_DEVICE_ERROR : Failed due to host controller or device error. - -**/ -STATIC -EFI_STATUS -EFIAPI -Uhci2ControlTransfer ( - IN EFI_USB2_HC_PROTOCOL *This, - IN UINT8 DeviceAddress, - IN UINT8 DeviceSpeed, - IN UINTN MaximumPacketLength, - IN EFI_USB_DEVICE_REQUEST *Request, - IN EFI_USB_DATA_DIRECTION TransferDirection, - IN OUT VOID *Data, - IN OUT UINTN *DataLength, - IN UINTN TimeOut, - IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator, - OUT UINT32 *TransferResult - ) -{ - USB_HC_DEV *Uhc; - BOOLEAN IsSlow; - - Uhc = UHC_FROM_USB2_HC_PROTO (This); - IsSlow = (BOOLEAN) ((EFI_USB_SPEED_LOW == DeviceSpeed) ? TRUE : FALSE); - - return UhciControlTransfer ( - &Uhc->UsbHc, - DeviceAddress, - IsSlow, - (UINT8) MaximumPacketLength, - Request, - TransferDirection, - Data, - DataLength, - TimeOut, - TransferResult - ); -} - - -/** - Submits bulk transfer to a bulk endpoint of a USB device - - This : A pointer to the EFI_USB2_HC_PROTOCOL instance. - DeviceAddress : Target device address - EndPointAddress : Endpoint number and direction - DeviceSpeed : Device speed - MaximumPacketLength : Maximum packet size of the target endpoint - DataBuffersNumber : Number of data buffers prepared for the transfer. - Data : Array of pointers to the buffers of data - DataLength : On input, size of the data buffer, On output, - actually transferred data size. - DataToggle : On input, data toggle to use; On output, next data toggle - Translator : A pointr to the transaction translator data. - TimeOut : Maximum time out, in microseconds - TransferResult : Variable to receive transfer result - - @return EFI_SUCCESS : The bulk transfer was completed successfully. - @return EFI_OUT_OF_RESOURCES : Failed due to lack of resource. - @return EFI_INVALID_PARAMETER : Some parameters are invalid. - @return EFI_TIMEOUT : Failed due to timeout. - @return EFI_DEVICE_ERROR : Failed due to host controller or device error. - -**/ -STATIC -EFI_STATUS -EFIAPI -Uhci2BulkTransfer ( - IN EFI_USB2_HC_PROTOCOL *This, - IN UINT8 DeviceAddress, - IN UINT8 EndPointAddress, - IN UINT8 DeviceSpeed, - IN UINTN MaximumPacketLength, - IN UINT8 DataBuffersNumber, - IN OUT VOID *Data[EFI_USB_MAX_BULK_BUFFER_NUM], - IN OUT UINTN *DataLength, - IN OUT UINT8 *DataToggle, - IN UINTN TimeOut, - IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator, - OUT UINT32 *TransferResult - ) -{ - USB_HC_DEV *Uhc; - - Uhc = UHC_FROM_USB2_HC_PROTO (This); - - if (Data == NULL || DeviceSpeed == EFI_USB_SPEED_LOW) { - return EFI_INVALID_PARAMETER; - } - - // - // For full-speed bulk transfers only the data pointed by Data[0] shall be used - // - return UhciBulkTransfer ( - &Uhc->UsbHc, - DeviceAddress, - EndPointAddress, - (UINT8) MaximumPacketLength, - *Data, - DataLength, - DataToggle, - TimeOut, - TransferResult - ); -} - - -/** - Submits an asynchronous interrupt transfer to an - interrupt endpoint of a USB device according to UEFI 2.0 spec. - - This : A pointer to the EFI_USB2_HC_PROTOCOL instance. - DeviceAddress : Target device address - EndPointAddress : Endpoint number and direction - DeviceSpeed : Device speed - MaximumPacketLength : Maximum packet size of the target endpoint - IsNewTransfer : If TRUE, submit a new transfer, if FALSE cancel old transfer - DataToggle : On input, data toggle to use; On output, next data toggle - PollingInterval : Interrupt poll rate in milliseconds - DataLength : On input, size of the data buffer, On output, - actually transferred data size. - Translator : A pointr to the transaction translator data. - CallBackFunction : Function to call periodically - Context : User context - - @return EFI_SUCCESS : Transfer was submitted - @return EFI_INVALID_PARAMETER : Some parameters are invalid. - @return EFI_OUT_OF_RESOURCES : Failed due to a lack of resources. - @return EFI_DEVICE_ERROR : Can't read register - -**/ -STATIC -EFI_STATUS -EFIAPI -Uhci2AsyncInterruptTransfer ( - IN EFI_USB2_HC_PROTOCOL *This, - IN UINT8 DeviceAddress, - IN UINT8 EndPointAddress, - IN UINT8 DeviceSpeed, - IN UINTN MaximumPacketLength, - IN BOOLEAN IsNewTransfer, - IN OUT UINT8 *DataToggle, - IN UINTN PollingInterval, - IN UINTN DataLength, - IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator, - IN EFI_ASYNC_USB_TRANSFER_CALLBACK CallBackFunction, - IN VOID *Context - ) -{ - USB_HC_DEV *Uhc; - BOOLEAN IsSlow; - - Uhc = UHC_FROM_USB2_HC_PROTO (This); - IsSlow = (BOOLEAN) ((EFI_USB_SPEED_LOW == DeviceSpeed) ? TRUE : FALSE); - - return UhciAsyncInterruptTransfer ( - &Uhc->UsbHc, - DeviceAddress, - EndPointAddress, - IsSlow, - (UINT8) MaximumPacketLength, - IsNewTransfer, - DataToggle, - PollingInterval, - DataLength, - CallBackFunction, - Context - ); -} - - -/** - Submits synchronous interrupt transfer to an interrupt endpoint - of a USB device according to UEFI 2.0 spec. - - This : A pointer to the EFI_USB2_HC_PROTOCOL instance. - DeviceAddress : Target device address - EndPointAddress : Endpoint number and direction - DeviceSpeed : Device speed - MaximumPacketLength : Maximum packet size of the target endpoint - DataBuffersNumber : Number of data buffers prepared for the transfer. - Data : Array of pointers to the buffers of data - DataLength : On input, size of the data buffer, On output, - actually transferred data size. - DataToggle : On input, data toggle to use; On output, next data toggle - TimeOut : Maximum time out, in microseconds - Translator : A pointr to the transaction translator data. - TransferResult : Variable to receive transfer result - - @return EFI_SUCCESS : The transfer was completed successfully. - @return EFI_OUT_OF_RESOURCES : Failed due to lack of resource. - @return EFI_INVALID_PARAMETER : Some parameters are invalid. - @return EFI_TIMEOUT : Failed due to timeout. - @return EFI_DEVICE_ERROR : Failed due to host controller or device error. - -**/ -STATIC -EFI_STATUS -EFIAPI -Uhci2SyncInterruptTransfer ( - IN EFI_USB2_HC_PROTOCOL *This, - IN UINT8 DeviceAddress, - IN UINT8 EndPointAddress, - IN UINT8 DeviceSpeed, - IN UINTN MaximumPacketLength, - IN OUT VOID *Data, - IN OUT UINTN *DataLength, - IN OUT UINT8 *DataToggle, - IN UINTN TimeOut, - IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator, - OUT UINT32 *TransferResult - ) -{ - USB_HC_DEV *Uhc; - BOOLEAN IsSlow; - - if (DeviceSpeed == EFI_USB_SPEED_HIGH) { - return EFI_INVALID_PARAMETER; - } - - Uhc = UHC_FROM_USB2_HC_PROTO (This); - IsSlow = (BOOLEAN) ((EFI_USB_SPEED_LOW == DeviceSpeed) ? TRUE : FALSE); - - return UhciSyncInterruptTransfer ( - &Uhc->UsbHc, - DeviceAddress, - EndPointAddress, - IsSlow, - (UINT8) MaximumPacketLength, - Data, - DataLength, - DataToggle, - TimeOut, - TransferResult - ); -} - - -/** - Submits isochronous transfer to a target USB device according to UEFI 2.0 spec. - - This : A pointer to the EFI_USB2_HC_PROTOCOL instance. - DeviceAddress : Target device address - EndPointAddress : Endpoint number and direction - DeviceSpeed : Device speed - MaximumPacketLength : Maximum packet size of the target endpoint - DataBuffersNumber : Number of data buffers prepared for the transfer. - Data : Array of pointers to the buffers of data - DataLength : On input, size of the data buffer, On output, - actually transferred data size. - Translator : A pointr to the transaction translator data. - TransferResult : Variable to receive transfer result - - @return EFI_UNSUPPORTED - -**/ -STATIC -EFI_STATUS -EFIAPI -Uhci2IsochronousTransfer ( - IN EFI_USB2_HC_PROTOCOL *This, - IN UINT8 DeviceAddress, - IN UINT8 EndPointAddress, - IN UINT8 DeviceSpeed, - IN UINTN MaximumPacketLength, - IN UINT8 DataBuffersNumber, - IN OUT VOID *Data[EFI_USB_MAX_ISO_BUFFER_NUM], - IN UINTN DataLength, - IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator, - OUT UINT32 *TransferResult - ) -{ - return EFI_UNSUPPORTED; -} - - -/** - Submits Async isochronous transfer to a target USB device according to UEFI 2.0 spec. - - This : A pointer to the EFI_USB2_HC_PROTOCOL instance. - DeviceAddress : Target device address - EndPointAddress : Endpoint number and direction - DeviceSpeed : Device speed - MaximumPacketLength : Maximum packet size of the target endpoint - DataBuffersNumber : Number of data buffers prepared for the transfer. - Data : Array of pointers to the buffers of data - Translator : A pointr to the transaction translator data. - IsochronousCallBack : Function to call when the transfer complete - Context : Pass to the call back function as parameter - - @return EFI_UNSUPPORTED - -**/ -STATIC -EFI_STATUS -EFIAPI -Uhci2AsyncIsochronousTransfer ( - IN EFI_USB2_HC_PROTOCOL *This, - IN UINT8 DeviceAddress, - IN UINT8 EndPointAddress, - IN UINT8 DeviceSpeed, - IN UINTN MaximumPacketLength, - IN UINT8 DataBuffersNumber, - IN OUT VOID *Data[EFI_USB_MAX_ISO_BUFFER_NUM], - IN UINTN DataLength, - IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator, - IN EFI_ASYNC_USB_TRANSFER_CALLBACK IsochronousCallBack, - IN VOID *Context - ) -{ - return EFI_UNSUPPORTED; -} - -EFI_STATUS -EFIAPI -UhciDriverEntryPoint ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable - ) -/*++ - - Routine Description: - - Entry point for EFI drivers. - - Arguments: - - ImageHandle - EFI_HANDLE - SystemTable - EFI_SYSTEM_TABLE - - Returns: - - EFI_SUCCESS : Driver is successfully loaded - Others : Failed - ---*/ -{ - return EfiLibInstallDriverBindingComponentName2 ( - ImageHandle, - SystemTable, - &gUhciDriverBinding, - ImageHandle, - &gUhciComponentName, - &gUhciComponentName2 - ); -} - - -/** - Test to see if this driver supports ControllerHandle. Any - ControllerHandle that has UsbHcProtocol installed will be supported. - - @param This Protocol instance pointer. - @param Controller Handle of device to test - @param RemainingDevicePath Not used - - @return EFI_SUCCESS : This driver supports this device. - @return EFI_UNSUPPORTED : This driver does not support this device. - -**/ -EFI_STATUS -EFIAPI -UhciDriverBindingSupported ( - IN EFI_DRIVER_BINDING_PROTOCOL *This, - IN EFI_HANDLE Controller, - IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath - ) -{ - EFI_STATUS OpenStatus; - EFI_STATUS Status; - EFI_PCI_IO_PROTOCOL *PciIo; - USB_CLASSC UsbClassCReg; - - // - // Test whether there is PCI IO Protocol attached on the controller handle. - // - OpenStatus = gBS->OpenProtocol ( - Controller, - &gEfiPciIoProtocolGuid, - (VOID **) &PciIo, - This->DriverBindingHandle, - Controller, - EFI_OPEN_PROTOCOL_BY_DRIVER - ); - - if (EFI_ERROR (OpenStatus)) { - return OpenStatus; - } + if (EFI_ERROR (OpenStatus)) { + return OpenStatus; + } Status = PciIo->Pci.Read ( PciIo, EfiPciIoWidthUint8, - CLASSC_OFFSET, + PCI_CLASSCODE_OFFSET, sizeof (USB_CLASSC) / sizeof (UINT8), &UsbClassCReg ); @@ -1911,7 +1395,7 @@ UhciDriverBindingSupported ( // if ((UsbClassCReg.BaseCode != PCI_CLASS_SERIAL) || (UsbClassCReg.SubClassCode != PCI_CLASS_SERIAL_USB) || - (UsbClassCReg.PI != PCI_CLASSC_PI_UHCI) + (UsbClassCReg.ProgInterface != PCI_IF_UHCI) ) { Status = EFI_UNSUPPORTED; @@ -1931,17 +1415,18 @@ ON_EXIT: /** - Allocate and initialize the empty UHCI device + Allocate and initialize the empty UHCI device. - @param PciIo The PCIIO to use + @param PciIo The PCIIO to use. + @param OriginalPciAttributes The original PCI attributes. - @return Allocated UHCI device + @return Allocated UHCI device. If err, return NULL. **/ -STATIC USB_HC_DEV * UhciAllocateDev ( - IN EFI_PCI_IO_PROTOCOL *PciIo + IN EFI_PCI_IO_PROTOCOL *PciIo, + IN UINT64 OriginalPciAttributes ) { USB_HC_DEV *Uhc; @@ -1958,22 +1443,6 @@ UhciAllocateDev ( // USB_HC_PROTOCOL is for EFI 1.1 backward compability. // Uhc->Signature = USB_HC_DEV_SIGNATURE; - Uhc->UsbHc.Reset = UhciReset; - Uhc->UsbHc.GetState = UhciGetState; - Uhc->UsbHc.SetState = UhciSetState; - Uhc->UsbHc.ControlTransfer = UhciControlTransfer; - Uhc->UsbHc.BulkTransfer = UhciBulkTransfer; - Uhc->UsbHc.AsyncInterruptTransfer = UhciAsyncInterruptTransfer; - Uhc->UsbHc.SyncInterruptTransfer = UhciSyncInterruptTransfer; - Uhc->UsbHc.IsochronousTransfer = UhciIsochronousTransfer; - Uhc->UsbHc.AsyncIsochronousTransfer = UhciAsyncIsochronousTransfer; - Uhc->UsbHc.GetRootHubPortNumber = UhciGetRootHubPortNumber; - Uhc->UsbHc.GetRootHubPortStatus = UhciGetRootHubPortStatus; - Uhc->UsbHc.SetRootHubPortFeature = UhciSetRootHubPortFeature; - Uhc->UsbHc.ClearRootHubPortFeature = UhciClearRootHubPortFeature; - Uhc->UsbHc.MajorRevision = 0x1; - Uhc->UsbHc.MinorRevision = 0x1; - Uhc->Usb2Hc.GetCapability = Uhci2GetCapability; Uhc->Usb2Hc.Reset = Uhci2Reset; Uhc->Usb2Hc.GetState = Uhci2GetState; @@ -1990,8 +1459,9 @@ UhciAllocateDev ( Uhc->Usb2Hc.MajorRevision = 0x1; Uhc->Usb2Hc.MinorRevision = 0x1; - Uhc->PciIo = PciIo; - Uhc->MemPool = UsbHcInitMemPool (PciIo, TRUE, 0); + Uhc->PciIo = PciIo; + Uhc->OriginalPciAttributes = OriginalPciAttributes; + Uhc->MemPool = UsbHcInitMemPool (PciIo, TRUE, 0); if (Uhc->MemPool == NULL) { Status = EFI_OUT_OF_RESOURCES; @@ -2016,20 +1486,17 @@ UhciAllocateDev ( return Uhc; ON_ERROR: - gBS->FreePool (Uhc); + FreePool (Uhc); return NULL; } /** - Free the UHCI device and release its associated resources - - @param Uhc The UHCI device to release + Free the UHCI device and release its associated resources. - @return None + @param Uhc The UHCI device to release. **/ -STATIC VOID UhciFreeDev ( IN USB_HC_DEV *Uhc @@ -2039,32 +1506,33 @@ UhciFreeDev ( gBS->CloseEvent (Uhc->AsyncIntMonitor); } + if (Uhc->ExitBootServiceEvent != NULL) { + gBS->CloseEvent (Uhc->ExitBootServiceEvent); + } + if (Uhc->MemPool != NULL) { UsbHcFreeMemPool (Uhc->MemPool); } - if (Uhc->CtrlNameTable) { + if (Uhc->CtrlNameTable != NULL) { FreeUnicodeStringTable (Uhc->CtrlNameTable); } - gBS->FreePool (Uhc); + FreePool (Uhc); } /** - Uninstall all Uhci Interface + Uninstall all Uhci Interface. - @param Controller Controller handle + @param Controller Controller handle. @param This Protocol instance pointer. - @return VOID - **/ -STATIC VOID UhciCleanDevUp ( - IN EFI_HANDLE Controller, - IN EFI_USB_HC_PROTOCOL *This + IN EFI_HANDLE Controller, + IN EFI_USB2_HC_PROTOCOL *This ) { USB_HC_DEV *Uhc; @@ -2072,15 +1540,9 @@ UhciCleanDevUp ( // // Uninstall the USB_HC and USB_HC2 protocol, then disable the controller // - Uhc = UHC_FROM_USB_HC_PROTO (This); + Uhc = UHC_FROM_USB2_HC_PROTO (This); UhciStopHc (Uhc, UHC_GENERIC_TIMEOUT); - gBS->UninstallProtocolInterface ( - Controller, - &gEfiUsbHcProtocolGuid, - &Uhc->UsbHc - ); - gBS->UninstallProtocolInterface ( Controller, &gEfiUsb2HcProtocolGuid, @@ -2090,29 +1552,56 @@ UhciCleanDevUp ( UhciFreeAllAsyncReq (Uhc); UhciDestoryFrameList (Uhc); + // + // Restore original PCI attributes + // Uhc->PciIo->Attributes ( - Uhc->PciIo, - EfiPciIoAttributeOperationDisable, - EFI_PCI_DEVICE_ENABLE, - NULL - ); + Uhc->PciIo, + EfiPciIoAttributeOperationSet, + Uhc->OriginalPciAttributes, + NULL + ); UhciFreeDev (Uhc); } +/** + One notified function to stop the Host Controller when gBS->ExitBootServices() called. + + @param Event Pointer to this event + @param Context Event hanlder private data + +**/ +VOID +EFIAPI +UhcExitBootService ( + EFI_EVENT Event, + VOID *Context + ) +{ + USB_HC_DEV *Uhc; + + Uhc = (USB_HC_DEV *) Context; + + // + // Stop the Host Controller + // + UhciStopHc (Uhc, UHC_GENERIC_TIMEOUT); + + return; +} /** - Starting the Usb UHCI Driver + Starting the Usb UHCI Driver. @param This Protocol instance pointer. - @param Controller Handle of device to test - @param RemainingDevicePath Not used + @param Controller Handle of device to test. + @param RemainingDevicePath Not used. @retval EFI_SUCCESS This driver supports this device. @retval EFI_UNSUPPORTED This driver does not support this device. - @retval EFI_DEVICE_ERROR This driver cannot be started due to device Error - EFI_OUT_OF_RESOURCES- Failed due to resource - shortage + @retval EFI_DEVICE_ERROR This driver cannot be started due to device Error. + EFI_OUT_OF_RESOURCES- Failed due to resource shortage. **/ EFI_STATUS @@ -2126,6 +1615,9 @@ UhciDriverBindingStart ( EFI_STATUS Status; EFI_PCI_IO_PROTOCOL *PciIo; USB_HC_DEV *Uhc; + UINT64 Supports; + UINT64 OriginalPciAttributes; + BOOLEAN PciAttributesSaved; // // Open PCIIO, then enable the EHC device and turn off emulation @@ -2144,20 +1636,51 @@ UhciDriverBindingStart ( return Status; } - UhciTurnOffUsbEmulation (PciIo); + PciAttributesSaved = FALSE; + // + // Save original PCI attributes + // + Status = PciIo->Attributes ( + PciIo, + EfiPciIoAttributeOperationGet, + 0, + &OriginalPciAttributes + ); + + if (EFI_ERROR (Status)) { + goto CLOSE_PCIIO; + } + PciAttributesSaved = TRUE; + + // + // Robustnesss improvement such as for UoL + // Default is not required. + // + if (FeaturePcdGet (PcdTurnOffUsbLegacySupport)) { + UhciTurnOffUsbEmulation (PciIo); + } Status = PciIo->Attributes ( PciIo, - EfiPciIoAttributeOperationEnable, - EFI_PCI_DEVICE_ENABLE, - NULL + EfiPciIoAttributeOperationSupported, + 0, + &Supports ); + if (!EFI_ERROR (Status)) { + Supports &= EFI_PCI_DEVICE_ENABLE; + Status = PciIo->Attributes ( + PciIo, + EfiPciIoAttributeOperationEnable, + Supports, + NULL + ); + } if (EFI_ERROR (Status)) { goto CLOSE_PCIIO; } - Uhc = UhciAllocateDev (PciIo); + Uhc = UhciAllocateDev (PciIo, OriginalPciAttributes); if (Uhc == NULL) { Status = EFI_OUT_OF_RESOURCES; @@ -2185,12 +1708,10 @@ UhciDriverBindingStart ( } // - // Install both USB_HC_PROTOCOL and USB2_HC_PROTOCOL + // Install USB2_HC_PROTOCOL // Status = gBS->InstallMultipleProtocolInterfaces ( &Controller, - &gEfiUsbHcProtocolGuid, - &Uhc->UsbHc, &gEfiUsb2HcProtocolGuid, &Uhc->Usb2Hc, NULL @@ -2200,6 +1721,21 @@ UhciDriverBindingStart ( goto FREE_UHC; } + // + // Create event to stop the HC when exit boot service. + // + Status = gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_NOTIFY, + UhcExitBootService, + Uhc, + &gEfiEventExitBootServicesGuid, + &Uhc->ExitBootServiceEvent + ); + if (EFI_ERROR (Status)) { + goto UNINSTALL_USBHC; + } + // // Install the component name protocol // @@ -2227,11 +1763,31 @@ UhciDriverBindingStart ( UhciWriteReg (Uhc->PciIo, USBCMD_OFFSET, USBCMD_RS | USBCMD_MAXP); return EFI_SUCCESS; + +UNINSTALL_USBHC: + gBS->UninstallMultipleProtocolInterfaces ( + Controller, + &gEfiUsb2HcProtocolGuid, + &Uhc->Usb2Hc, + NULL + ); FREE_UHC: UhciFreeDev (Uhc); CLOSE_PCIIO: + if (PciAttributesSaved) { + // + // Restore original PCI attributes + // + PciIo->Attributes ( + PciIo, + EfiPciIoAttributeOperationSet, + OriginalPciAttributes, + NULL + ); + } + gBS->CloseProtocol ( Controller, &gEfiPciIoProtocolGuid, @@ -2248,8 +1804,8 @@ CLOSE_PCIIO: created by this driver. @param This Protocol instance pointer. - @param Controller Handle of device to stop driver on - @param NumberOfChildren Number of Children in the ChildHandleBuffer + @param Controller Handle of device to stop driver on. + @param NumberOfChildren Number of Children in the ChildHandleBuffer. @param ChildHandleBuffer List of handles for the children we need to stop. @return EFI_SUCCESS @@ -2265,28 +1821,10 @@ UhciDriverBindingStop ( IN EFI_HANDLE *ChildHandleBuffer ) { - EFI_USB_HC_PROTOCOL *UsbHc; EFI_USB2_HC_PROTOCOL *Usb2Hc; EFI_STATUS Status; - Status = gBS->OpenProtocol ( - Controller, - &gEfiUsbHcProtocolGuid, - (VOID **) &UsbHc, - This->DriverBindingHandle, - Controller, - EFI_OPEN_PROTOCOL_GET_PROTOCOL - ); - // - // Test whether the Controller handler passed in is a valid - // Usb controller handle that should be supported, if not, - // return the error status directly - // - if (EFI_ERROR (Status)) { - return Status; - } - - Status = gBS->OpenProtocol ( + Status = gBS->OpenProtocol ( Controller, &gEfiUsb2HcProtocolGuid, (VOID **) &Usb2Hc, @@ -2304,7 +1842,7 @@ UhciDriverBindingStop ( return Status; } - UhciCleanDevUp (Controller, UsbHc); + UhciCleanDevUp (Controller, Usb2Hc); gBS->CloseProtocol ( Controller, @@ -2316,11 +1854,3 @@ UhciDriverBindingStop ( return EFI_SUCCESS; } -EFI_DRIVER_BINDING_PROTOCOL gUhciDriverBinding = { - UhciDriverBindingSupported, - UhciDriverBindingStart, - UhciDriverBindingStop, - 0x20, - NULL, - NULL -};