summaryrefslogtreecommitdiff
path: root/EdkModulePkg/Bus/Pci/Ehci
diff options
context:
space:
mode:
Diffstat (limited to 'EdkModulePkg/Bus/Pci/Ehci')
-rw-r--r--EdkModulePkg/Bus/Pci/Ehci/Dxe/ComponentName.c179
-rw-r--r--EdkModulePkg/Bus/Pci/Ehci/Dxe/Debug.c55
-rw-r--r--EdkModulePkg/Bus/Pci/Ehci/Dxe/Ehci.c2679
-rw-r--r--EdkModulePkg/Bus/Pci/Ehci/Dxe/Ehci.h2918
-rw-r--r--EdkModulePkg/Bus/Pci/Ehci/Dxe/Ehci.msa78
-rw-r--r--EdkModulePkg/Bus/Pci/Ehci/Dxe/EhciMem.c771
-rw-r--r--EdkModulePkg/Bus/Pci/Ehci/Dxe/EhciReg.c1730
-rw-r--r--EdkModulePkg/Bus/Pci/Ehci/Dxe/EhciSched.c3240
8 files changed, 0 insertions, 11650 deletions
diff --git a/EdkModulePkg/Bus/Pci/Ehci/Dxe/ComponentName.c b/EdkModulePkg/Bus/Pci/Ehci/Dxe/ComponentName.c
deleted file mode 100644
index 5d332e018d..0000000000
--- a/EdkModulePkg/Bus/Pci/Ehci/Dxe/ComponentName.c
+++ /dev/null
@@ -1,179 +0,0 @@
-/*++
-
-Copyright 2006, 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
-
-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:
-
- ComponentName.c
-
-Abstract:
-
---*/
-
-#include "Ehci.h"
-
-//
-// EFI Component Name Protocol
-//
-EFI_COMPONENT_NAME_PROTOCOL gEhciComponentName = {
- EhciComponentNameGetDriverName,
- EhciComponentNameGetControllerName,
- "eng"
-};
-
-static EFI_UNICODE_STRING_TABLE mEhciDriverNameTable[] = {
- { "eng", L"UEFI Usb Ehci Driver" },
- { NULL , NULL }
-};
-
-EFI_STATUS
-EFIAPI
-EhciComponentNameGetDriverName (
- IN EFI_COMPONENT_NAME_PROTOCOL *This,
- IN CHAR8 *Language,
- OUT CHAR16 **DriverName
- )
-/*++
-
- Routine Description:
- Retrieves a Unicode string that is the user readable name of the EFI Driver.
-
- Arguments:
- This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
- Language - A pointer to a three character ISO 639-2 language identifier.
- This is the language of the driver name that that the caller
- is requesting, and it must match one of the languages specified
- in SupportedLanguages. The number of languages supported by a
- driver is up to the driver writer.
- DriverName - A pointer to the Unicode string to return. This Unicode string
- is the name of the driver specified by This in the language
- specified by Language.
-
- Returns:
- EFI_SUCCESS - The Unicode string for the Driver specified by This
- and the language specified by Language was returned
- in DriverName.
- EFI_INVALID_PARAMETER - Language is NULL.
- EFI_INVALID_PARAMETER - DriverName is NULL.
- EFI_UNSUPPORTED - The driver specified by This does not support the
- language specified by Language.
-
---*/
-{
- return LookupUnicodeString (
- Language,
- gEhciComponentName.SupportedLanguages,
- mEhciDriverNameTable,
- DriverName
- );
-}
-
-EFI_STATUS
-EFIAPI
-EhciComponentNameGetControllerName (
- IN EFI_COMPONENT_NAME_PROTOCOL *This,
- IN EFI_HANDLE ControllerHandle,
- IN EFI_HANDLE ChildHandle, OPTIONAL
- IN CHAR8 *Language,
- OUT CHAR16 **ControllerName
- )
-/*++
-
- Routine Description:
- Retrieves a Unicode string that is the user readable name of the controller
- that is being managed by an EFI Driver.
-
- Arguments:
- This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
- ControllerHandle - The handle of a controller that the driver specified by
- This is managing. This handle specifies the controller
- whose name is to be returned.
- ChildHandle - The handle of the child controller to retrieve the name
- of. This is an optional parameter that may be NULL. It
- will be NULL for device drivers. It will also be NULL
- for a bus drivers that wish to retrieve the name of the
- bus controller. It will not be NULL for a bus driver
- that wishes to retrieve the name of a child controller.
- Language - A pointer to a three character ISO 639-2 language
- identifier. This is the language of the controller name
- that that the caller is requesting, and it must match one
- of the languages specified in SupportedLanguages. The
- number of languages supported by a driver is up to the
- driver writer.
- ControllerName - A pointer to the Unicode string to return. This Unicode
- string is the name of the controller specified by
- ControllerHandle and ChildHandle in the language
- specified by Language from the point of view of the
- driver specified by This.
-
- Returns:
- EFI_SUCCESS - The Unicode string for the user readable name in the
- language specified by Language for the driver
- specified by This was returned in DriverName.
- EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
- EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid
- EFI_HANDLE.
- EFI_INVALID_PARAMETER - Language is NULL.
- EFI_INVALID_PARAMETER - ControllerName is NULL.
- EFI_UNSUPPORTED - The driver specified by This is not currently
- managing the controller specified by
- ControllerHandle and ChildHandle.
- EFI_UNSUPPORTED - The driver specified by This does not support the
- language specified by Language.
-
---*/
-{
- EFI_STATUS Status;
- USB2_HC_DEV *EhciDev;
- EFI_USB2_HC_PROTOCOL *Usb2Hc;
-
- //
- // This is a device driver, so ChildHandle must be NULL.
- //
- if (ChildHandle != NULL) {
- return EFI_UNSUPPORTED;
- }
- //
- // Make sure this driver is currently managing ControllerHandle
- //
- Status = EfiTestManagedDevice (
- ControllerHandle,
- gEhciDriverBinding.DriverBindingHandle,
- &gEfiPciIoProtocolGuid
- );
- if (EFI_ERROR (Status)) {
- return Status;
- }
- //
- // Get the device context
- //
- Status = gBS->OpenProtocol (
- ControllerHandle,
- &gEfiUsb2HcProtocolGuid,
- (VOID **) &Usb2Hc,
- gEhciDriverBinding.DriverBindingHandle,
- ControllerHandle,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL
- );
-
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- EhciDev = USB2_HC_DEV_FROM_THIS (Usb2Hc);
-
- return LookupUnicodeString (
- Language,
- gEhciComponentName.SupportedLanguages,
- EhciDev->ControllerNameTable,
- ControllerName
- );
-
-}
diff --git a/EdkModulePkg/Bus/Pci/Ehci/Dxe/Debug.c b/EdkModulePkg/Bus/Pci/Ehci/Dxe/Debug.c
deleted file mode 100644
index a700d8f2cf..0000000000
--- a/EdkModulePkg/Bus/Pci/Ehci/Dxe/Debug.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/*++
-
-Copyright (c) 2006, 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
-
-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:
-
- Debug.c
-
-Abstract:
-
-
-Revision History
---*/
-
-
-#include "Ehci.h"
-
-
-VOID
-DumpEHCIPortsStatus (
- IN USB2_HC_DEV *HcDev
- )
-{
- UINT8 PortNumber;
- UINT8 Index;
- UINT32 Value;
-
- ReadEhcCapabiltiyReg (
- HcDev,
- HCSPARAMS,
- &Value
- );
-
- PortNumber = (UINT8) (Value & HCSP_NPORTS);
-
- for (Index = 0; Index < PortNumber; Index++) {
- ReadEhcOperationalReg (
- HcDev,
- PORTSC + 4 * Index,
- &Value
- );
- DEBUG((gEHCDebugLevel, "Port[%d] = 0x%x\n", Index, Value));
- }
-
-
-}
-
-
diff --git a/EdkModulePkg/Bus/Pci/Ehci/Dxe/Ehci.c b/EdkModulePkg/Bus/Pci/Ehci/Dxe/Ehci.c
deleted file mode 100644
index 9065a2a886..0000000000
--- a/EdkModulePkg/Bus/Pci/Ehci/Dxe/Ehci.c
+++ /dev/null
@@ -1,2679 +0,0 @@
-/*++
-
-Copyright (c) 2006, 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
-
-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:
-
- Ehci.c
-
-Abstract:
-
-
-Revision History
---*/
-
-
-#include "Ehci.h"
-
-
-GLOBAL_REMOVE_IF_UNREFERENCED UINTN gEHCDebugLevel = EFI_D_ERROR;
-GLOBAL_REMOVE_IF_UNREFERENCED UINTN gEHCErrorLevel = EFI_D_ERROR;
-
-
-//
-// Ehci Driver Global Variables
-//
-EFI_DRIVER_BINDING_PROTOCOL gEhciDriverBinding = {
- EhciDriverBindingSupported,
- EhciDriverBindingStart,
- EhciDriverBindingStop,
- 0xa,
- NULL,
- NULL
-};
-
-
-EFI_STATUS
-EFIAPI
-EhciDriverBindingSupported (
- IN EFI_DRIVER_BINDING_PROTOCOL *This,
- IN EFI_HANDLE Controller,
- IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
- )
-/*++
-
- Routine Description:
-
- Test to see if this driver supports ControllerHandle. Any ControllerHandle
- that has Usb2HcProtocol installed will be supported.
-
- Arguments:
-
- This - Protocol instance pointer.
- Controlle - Handle of device to test
- RemainingDevicePath - Not used
-
- Returns:
-
- EFI_SUCCESS This driver supports this device.
- EFI_UNSUPPORTED This driver does not support this device.
-
---*/
-{
- EFI_STATUS Status;
- EFI_PCI_IO_PROTOCOL *PciIo;
- USB_CLASSC UsbClassCReg;
-
-
- //
- // Test whether there is PCI IO Protocol attached on the controller handle.
- //
- Status = gBS->OpenProtocol (
- Controller,
- &gEfiPciIoProtocolGuid,
- (VOID **) &PciIo,
- This->DriverBindingHandle,
- Controller,
- EFI_OPEN_PROTOCOL_BY_DRIVER
- );
- if (EFI_ERROR (Status)) {
- goto exit;
- }
-
- Status = PciIo->Pci.Read (
- PciIo,
- EfiPciIoWidthUint8,
- CLASSC,
- sizeof (USB_CLASSC) / sizeof (UINT8),
- &UsbClassCReg
- );
- if (EFI_ERROR (Status)) {
- gBS->CloseProtocol (
- Controller,
- &gEfiPciIoProtocolGuid,
- This->DriverBindingHandle,
- Controller
- );
- Status = EFI_UNSUPPORTED;
- goto exit;
- }
-
- //
- // Test whether the controller belongs to Ehci type
- //
- if ((UsbClassCReg.BaseCode != PCI_CLASS_SERIAL) ||
- (UsbClassCReg.SubClassCode != PCI_CLASS_SERIAL_USB) ||
- (UsbClassCReg.PI != PCI_CLASSC_PI_EHCI)
- ) {
-
- gBS->CloseProtocol (
- Controller,
- &gEfiPciIoProtocolGuid,
- This->DriverBindingHandle,
- Controller
- );
-
- Status = EFI_UNSUPPORTED;
- goto exit;
- }
-
- gBS->CloseProtocol (
- Controller,
- &gEfiPciIoProtocolGuid,
- This->DriverBindingHandle,
- Controller
- );
-
-exit:
- return Status;
-}
-
-EFI_STATUS
-EFIAPI
-EhciDriverBindingStart (
- IN EFI_DRIVER_BINDING_PROTOCOL *This,
- IN EFI_HANDLE Controller,
- IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
- )
-/*++
-
- Routine Description:
-
- Starting the Usb EHCI Driver
-
- Arguments:
-
- This - Protocol instance pointer.
- Controller - Handle of device to test
- RemainingDevicePath - Not used
-
- Returns:
-
- EFI_SUCCESS supports this device.
- EFI_UNSUPPORTED do not support this device.
- EFI_DEVICE_ERROR cannot be started due to device Error
- EFI_OUT_OF_RESOURCES cannot allocate resources
-
---*/
-{
- EFI_STATUS Status;
- USB2_HC_DEV *HcDev;
- EFI_PCI_IO_PROTOCOL *PciIo;
- UINT8 MaxSpeed;
- UINT8 PortNumber;
- UINT8 Is64BitCapable;
- UINT64 Supports;
-
- //
- // Open the PciIo Protocol
- //
- Status = gBS->OpenProtocol (
- Controller,
- &gEfiPciIoProtocolGuid,
- (VOID **) &PciIo,
- This->DriverBindingHandle,
- Controller,
- EFI_OPEN_PROTOCOL_BY_DRIVER
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_OUT_OF_RESOURCES;
- goto exit;
- }
-
- //
- // Enable the USB Host Controller
- //
- Status = PciIo->Attributes (
- PciIo,
- EfiPciIoAttributeOperationSupported,
- 0,
- &Supports
- );
- if (!EFI_ERROR (Status)) {
- Supports &= EFI_PCI_DEVICE_ENABLE;
- Status = PciIo->Attributes (
- PciIo,
- EfiPciIoAttributeOperationEnable,
- Supports,
- NULL
- );
- }
- if (EFI_ERROR (Status)) {
- Status = EFI_OUT_OF_RESOURCES;
- goto close_pciio_protocol;
- }
-
- //
- // Allocate memory for EHC private data structure
- //
- HcDev = AllocateZeroPool (sizeof (USB2_HC_DEV));
- if (NULL == HcDev) {
- Status = EFI_OUT_OF_RESOURCES;
- goto close_pciio_protocol;
- }
-
- //
- // Init EFI_USB2_HC_PROTOCOL interface and private data structure
- //
- HcDev->Usb2Hc.GetCapability = EhciGetCapability;
- HcDev->Usb2Hc.Reset = EhciReset;
- HcDev->Usb2Hc.GetState = EhciGetState;
- HcDev->Usb2Hc.SetState = EhciSetState;
- HcDev->Usb2Hc.ControlTransfer = EhciControlTransfer;
- HcDev->Usb2Hc.BulkTransfer = EhciBulkTransfer;
- HcDev->Usb2Hc.AsyncInterruptTransfer = EhciAsyncInterruptTransfer;
- HcDev->Usb2Hc.SyncInterruptTransfer = EhciSyncInterruptTransfer;
- HcDev->Usb2Hc.IsochronousTransfer = EhciIsochronousTransfer;
- HcDev->Usb2Hc.AsyncIsochronousTransfer = EhciAsyncIsochronousTransfer;
- HcDev->Usb2Hc.GetRootHubPortStatus = EhciGetRootHubPortStatus;
- HcDev->Usb2Hc.SetRootHubPortFeature = EhciSetRootHubPortFeature;
- HcDev->Usb2Hc.ClearRootHubPortFeature = EhciClearRootHubPortFeature;
- HcDev->Usb2Hc.MajorRevision = 0x1;
- HcDev->Usb2Hc.MinorRevision = 0x1;
-
- HcDev->AsyncRequestList = NULL;
- HcDev->ControllerNameTable = NULL;
- HcDev->Signature = USB2_HC_DEV_SIGNATURE;
- HcDev->PciIo = PciIo;
-
- //
- // Install USB2_HC_PROTOCOL
- //
- Status = gBS->InstallProtocolInterface (
- &Controller,
- &gEfiUsb2HcProtocolGuid,
- EFI_NATIVE_INTERFACE,
- &HcDev->Usb2Hc
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_OUT_OF_RESOURCES;
- goto free_pool;
- }
-
- //
- // Get Capability Register Length
- //
- Status = GetCapabilityLen (HcDev);
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto uninstall_usb2hc_protocol;
- }
-
- ClearLegacySupport (HcDev);
- HostReset (HcDev);
-
- DEBUG_CODE (
- DumpEHCIPortsStatus (HcDev);
- );
-
- //
- // Create and Init Perodic Frame List
- //
- Status = EhciGetCapability (
- &HcDev->Usb2Hc,
- &MaxSpeed,
- &PortNumber,
- &Is64BitCapable
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_OUT_OF_RESOURCES;
- goto uninstall_usb2hc_protocol;
- }
- HcDev->Is64BitCapable = Is64BitCapable;
-
- //
- // Create and Init Perodic Frame List
- //
- Status = InitialPeriodicFrameList (
- HcDev,
- EHCI_MAX_FRAME_LIST_LENGTH
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_OUT_OF_RESOURCES;
- goto uninstall_usb2hc_protocol;
- }
-
- //
- // Init memory pool management
- //
- Status = InitialMemoryManagement (HcDev);
- if (EFI_ERROR (Status)) {
- Status = EFI_OUT_OF_RESOURCES;
- goto deinit_perodic_frame_list;
- }
-
- Status = CreateNULLQH (HcDev);
- if (EFI_ERROR (Status)) {
- Status = EFI_OUT_OF_RESOURCES;
- goto deinit_perodic_frame_list;
- }
- //
- // Create AsyncRequest Polling Timer
- //
- Status = CreatePollingTimer (HcDev, (EFI_EVENT_NOTIFY) AsyncRequestMoniter);
- if (EFI_ERROR (Status)) {
- Status = EFI_OUT_OF_RESOURCES;
- goto deinit_null_qh;
- }
-
- //
- // Default Maxximum Interrupt Interval is 8,
- // it means that 8 micro frame = 1ms
- //
-
- //
- // Start the Host Controller
- //
- if (IsEhcHalted (HcDev)) {
- Status = StartScheduleExecution (HcDev);
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto deinit_timer;
- }
- }
-
- //
- // Set all ports routing to EHC
- //
- Status = SetPortRoutingEhc (HcDev);
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto deinit_timer;
- }
-
- //
- // Component name protocol
- //
- Status = AddUnicodeString (
- "eng",
- gEhciComponentName.SupportedLanguages,
- &HcDev->ControllerNameTable,
- L"Usb Enhanced Host Controller"
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_OUT_OF_RESOURCES;
- goto deinit_timer;
- }
-
- goto exit;
-
- //
- // Error handle process
- //
-deinit_timer:
- DestoryPollingTimer (HcDev);
-deinit_null_qh:
- DestroyNULLQH(HcDev);
- DeinitialMemoryManagement (HcDev);
-deinit_perodic_frame_list:
- DeinitialPeriodicFrameList (HcDev);
-uninstall_usb2hc_protocol:
- gBS->UninstallProtocolInterface (
- Controller,
- &gEfiUsb2HcProtocolGuid,
- &HcDev->Usb2Hc
- );
-free_pool:
- gBS->FreePool (HcDev);
-close_pciio_protocol:
- gBS->CloseProtocol (
- Controller,
- &gEfiPciIoProtocolGuid,
- This->DriverBindingHandle,
- Controller
- );
-
-exit:
- return Status;
-}
-
-EFI_STATUS
-EFIAPI
-EhciDriverBindingStop (
- IN EFI_DRIVER_BINDING_PROTOCOL *This,
- IN EFI_HANDLE Controller,
- IN UINTN NumberOfChildren,
- IN EFI_HANDLE *ChildHandleBuffer
- )
-/*++
-
- Routine Description:
-
- Stop this driver on ControllerHandle. Support stoping any child handles
- created by this driver.
-
- Arguments:
-
- This - Protocol instance pointer.
- Controller - Handle of device to stop driver on
- NumberOfChildren - Number of Children in the ChildHandleBuffer
- ChildHandleBuffer - List of handles for the children we need to stop.
-
- Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
---*/
-{
- EFI_STATUS Status;
- EFI_USB2_HC_PROTOCOL *Usb2Hc;
- USB2_HC_DEV *HcDev;
- UINT64 Supports;
-
- //
- // Test whether the Controller handler passed in is a valid
- // Usb controller handle that should be supported, if not,
- // return the error status directly
- //
- Status = gBS->OpenProtocol (
- Controller,
- &gEfiUsb2HcProtocolGuid,
- (VOID **) &Usb2Hc,
- This->DriverBindingHandle,
- Controller,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- HcDev = USB2_HC_DEV_FROM_THIS (Usb2Hc);
-
- //
- // free all the controller related memory and uninstall UHCI Protocol.
- //
- Status = gBS->UninstallProtocolInterface (
- Controller,
- &gEfiUsb2HcProtocolGuid,
- Usb2Hc
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- //
- // Set Host Controller state as halt
- //
- Status = Usb2Hc->SetState (
- Usb2Hc,
- EfiUsbHcStateHalt
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- //
- // Stop AsyncRequest Polling Timer
- //
- Status = StopPollingTimer (HcDev);
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- //
- // Destroy Asynchronous Request Event
- //
- DestoryPollingTimer (HcDev);
-
- //
- // Destroy Perodic Frame List
- //
- DeinitialPeriodicFrameList (HcDev);
-
- //
- // Destroy NULLQH
- //
- DestroyNULLQH (HcDev);
-
- //
- // Deinit Ehci pool memory management
- //
- DeinitialMemoryManagement (HcDev);
-
- //
- // Denint Unicode String Table
- //
- FreeUnicodeStringTable (HcDev->ControllerNameTable);
-
- //
- // Disable the USB Host Controller
- //
- Status = HcDev->PciIo->Attributes (
- HcDev->PciIo,
- EfiPciIoAttributeOperationSupported,
- 0,
- &Supports
- );
- if (!EFI_ERROR (Status)) {
- Supports &= EFI_PCI_DEVICE_ENABLE;
- Status = HcDev->PciIo->Attributes (
- HcDev->PciIo,
- EfiPciIoAttributeOperationDisable,
- Supports,
- NULL
- );
- }
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- gBS->FreePool (HcDev);
-
- gBS->CloseProtocol (
- Controller,
- &gEfiPciIoProtocolGuid,
- This->DriverBindingHandle,
- Controller
- );
-
-exit:
- return Status;
-}
-
-EFI_STATUS
-EFIAPI
-EhciGetCapability (
- IN EFI_USB2_HC_PROTOCOL *This,
- OUT UINT8 *MaxSpeed,
- OUT UINT8 *PortNumber,
- OUT UINT8 *Is64BitCapable
- )
-/*++
-
- Routine Description:
-
- Retrieves the capablility of root hub ports.
-
- Arguments:
-
- This - A pointer to the EFI_USB_HC_PROTOCOL instance.
- MaxSpeed - A pointer to the number of the host controller.
- PortNumber - A pointer to the number of the root hub ports.
- Is64BitCapable - A pointer to the flag for whether controller supports
- 64-bit memory addressing.
-
- Returns:
-
- EFI_SUCCESS host controller capability were retrieved successfully.
- EFI_INVALID_PARAMETER MaxSpeed or PortNumber or Is64BitCapable is NULL.
- EFI_DEVICE_ERROR An error was encountered while attempting to retrieve the capabilities.
-
---*/
-{
- EFI_STATUS Status;
- USB2_HC_DEV *HcDev;
- UINT32 HcStructParamsAddr;
- UINT32 HcStructParamsReg;
- UINT32 HcCapParamsAddr;
- UINT32 HcCapParamsReg;
-
- if (MaxSpeed == NULL || PortNumber == NULL || Is64BitCapable == NULL) {
- Status = EFI_INVALID_PARAMETER;
- goto exit;
- }
-
- HcStructParamsAddr = HCSPARAMS;
- HcCapParamsAddr = HCCPARAMS;
- HcDev = USB2_HC_DEV_FROM_THIS (This);
-
- Status = ReadEhcCapabiltiyReg (
- HcDev,
- HcStructParamsAddr,
- &HcStructParamsReg
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- Status = ReadEhcCapabiltiyReg (
- HcDev,
- HcCapParamsAddr,
- &HcCapParamsReg
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- *MaxSpeed = EFI_USB_SPEED_HIGH;
- *PortNumber = (UINT8) (HcStructParamsReg & HCSP_NPORTS);
- *Is64BitCapable = (UINT8) (HcCapParamsReg & HCCP_64BIT);
-
-exit:
- return Status;
-}
-
-EFI_STATUS
-EFIAPI
-EhciReset (
- IN EFI_USB2_HC_PROTOCOL *This,
- IN UINT16 Attributes
- )
-/*++
-
- Routine Description:
-
- Provides software reset for the USB host controller.
-
- Arguments:
-
- This - A pointer to the EFI_USB2_HC_PROTOCOL instance.
- Attributes - A bit mask of the reset operation to perform.
- See below for a list of the supported bit mask values.
-
- #define EFI_USB_HC_RESET_GLOBAL 0x0001
- #define EFI_USB_HC_RESET_HOST_CONTROLLER 0x0002
- #define EFI_USB_HC_RESET_GLOBAL_WITH_DEBUG 0x0004
- #define EFI_USB_HC_RESET_HOST_WITH_DEBUG 0x0008
-
- EFI_USB_HC_RESET_GLOBAL
- If this bit is set, a global reset signal will be sent to the USB bus.
- This resets all of the USB bus logic, including the USB host
- controller hardware and all the devices attached on the USB bus.
- EFI_USB_HC_RESET_HOST_CONTROLLER
- If this bit is set, the USB host controller hardware will be reset.
- No reset signal will be sent to the USB bus.
- EFI_USB_HC_RESET_GLOBAL_WITH_DEBUG
- If this bit is set, a global reset signal will be sent to the USB bus.
- This resets all of the USB bus logic, including the USB host
- controller hardware and all the devices attached on the USB bus.
- If this is an EHCI controller and the debug port has configured, then
- this is will still reset the host controller.
- EFI_USB_HC_RESET_HOST_WITH_DEBUG
- If this bit is set, the USB host controller hardware will be reset.
- If this is an EHCI controller and the debug port has been configured,
- then this will still reset the host controller.
-
- Returns:
-
- EFI_SUCCESS
- The reset operation succeeded.
- EFI_INVALID_PARAMETER
- Attributes is not valid.
- EFI_UNSUPPOURTED
- The type of reset specified by Attributes is not currently supported by
- the host controller hardware.
- EFI_ACCESS_DENIED
- Reset operation is rejected due to the debug port being configured and
- active; only EFI_USB_HC_RESET_GLOBAL_WITH_DEBUG or
- EFI_USB_HC_RESET_HOST_WITH_DEBUG reset Atrributes can be used to
- perform reset operation for this host controller.
- EFI_DEVICE_ERROR
- An error was encountered while attempting to perform
- the reset operation.
-
---*/
-{
- EFI_STATUS Status;
- USB2_HC_DEV *HcDev;
- UINTN FrameIndex;
- FRAME_LIST_ENTRY *FrameEntryPtr;
-
- HcDev = USB2_HC_DEV_FROM_THIS (This);
-
- switch (Attributes) {
-
- case EFI_USB_HC_RESET_GLOBAL:
-
- //
- // Same behavior as Host Controller Reset
- //
-
- case EFI_USB_HC_RESET_HOST_CONTROLLER:
-
- //
- // Host Controller must be Halt when Reset it
- //
- if (IsEhcHalted (HcDev)) {
- Status = ResetEhc (HcDev);
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
- //
- // Set to zero by Host Controller when reset process completes
- //
- Status = WaitForEhcReset (HcDev, EHCI_GENERIC_TIMEOUT);
- if (EFI_ERROR (Status)) {
- Status = EFI_TIMEOUT;
- goto exit;
- }
- } else {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- //
- // only asynchronous interrupt transfers are always alive on the bus, need to cleanup
- //
- CleanUpAllAsyncRequestTransfer (HcDev);
- Status = ClearEhcAllStatus (HcDev);
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- //
- // Set appropriate 4G Segment Selector
- //
- Status = SetCtrlDataStructSeg (HcDev);
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- //
- // Init Perodic List Base Addr and Frame List
- //
- Status = SetFrameListBaseAddr (
- HcDev,
- (UINT32)GET_0B_TO_31B (HcDev->PeriodicFrameListBuffer)
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
- FrameEntryPtr = (FRAME_LIST_ENTRY *) HcDev->PeriodicFrameListBuffer;
- for (FrameIndex = 0; FrameIndex < HcDev->PeriodicFrameListLength; FrameIndex++) {
- FrameEntryPtr->LinkTerminate = TRUE;
- FrameEntryPtr++;
- }
-
- //
- // Start the Host Controller
- //
- if (IsEhcHalted (HcDev)) {
- Status = StartScheduleExecution (HcDev);
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
- }
-
- //
- // Set all ports routing to EHC
- //
- Status = SetPortRoutingEhc (HcDev);
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
- break;
-
- case EFI_USB_HC_RESET_GLOBAL_WITH_DEBUG:
-
- Status = EFI_UNSUPPORTED;
- break;
-
- case EFI_USB_HC_RESET_HOST_WITH_DEBUG:
-
- Status = EFI_UNSUPPORTED;
- break;
-
- default:
- Status = EFI_INVALID_PARAMETER;
- }
-
-exit:
- return Status;
-}
-
-EFI_STATUS
-EFIAPI
-EhciGetState (
- IN EFI_USB2_HC_PROTOCOL *This,
- OUT EFI_USB_HC_STATE *State
- )
-/*++
-
- Routine Description:
-
- Retrieves current state of the USB host controller.
-
- Arguments:
-
- This A pointer to the EFI_USB2_HC_PROTOCOL instance.
- State A pointer to the EFI_USB_HC_STATE data structure that
- indicates current state of the USB host controller.
- Type EFI_USB_HC_STATE is defined below.
-
- typedef enum {
- EfiUsbHcStateHalt,
- EfiUsbHcStateOperational,
- EfiUsbHcStateSuspend,
- EfiUsbHcStateMaximum
- } EFI_USB_HC_STATE;
-
- Returns:
-
- EFI_SUCCESS
- The state information of the host controller was returned in State.
- EFI_INVALID_PARAMETER
- State is NULL.
- EFI_DEVICE_ERROR
- An error was encountered while attempting to retrieve the
- host controller's current state.
---*/
-{
- EFI_STATUS Status;
- USB2_HC_DEV *HcDev;
- UINT32 UsbStatusAddr;
- UINT32 UsbStatusReg;
-
- if (State == NULL) {
- Status = EFI_INVALID_PARAMETER;
- goto exit;
- }
-
- UsbStatusAddr = USBSTS;
- HcDev = USB2_HC_DEV_FROM_THIS (This);
-
- Status = ReadEhcOperationalReg (
- HcDev,
- UsbStatusAddr,
- &UsbStatusReg
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- if (UsbStatusReg & USBSTS_HCH) {
- *State = EfiUsbHcStateHalt;
- } else {
- *State = EfiUsbHcStateOperational;
- }
-
-exit:
- return Status;
-}
-
-EFI_STATUS
-EFIAPI
-EhciSetState (
- IN EFI_USB2_HC_PROTOCOL *This,
- IN EFI_USB_HC_STATE State
- )
-/*++
-
- Routine Description:
-
- Sets the USB host controller to a specific state.
-
- Arguments:
-
- This - A pointer to the EFI_USB2_HC_PROTOCOL instance.
- State - Indicates the state of the host controller that will be set.
-
- Returns:
-
- EFI_SUCCESS
- The USB host controller was successfully placed in the state
- specified by State.
- EFI_INVALID_PARAMETER
- State is invalid.
- EFI_DEVICE_ERROR
- Failed to set the state specified by State due to device error.
-
---*/
-{
- EFI_STATUS Status;
- USB2_HC_DEV *HcDev;
- UINT32 UsbCommandAddr;
- UINT32 UsbCommandReg;
- EFI_USB_HC_STATE CurrentState;
-
- UsbCommandAddr = USBCMD;
- HcDev = USB2_HC_DEV_FROM_THIS (This);
-
- Status = EhciGetState (This, &CurrentState);
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- switch (State) {
-
- case EfiUsbHcStateHalt:
-
- if (EfiUsbHcStateHalt == CurrentState) {
- Status = EFI_SUCCESS;
- goto exit;
- } else if (EfiUsbHcStateOperational == CurrentState) {
- Status = ReadEhcOperationalReg (
- HcDev,
- UsbCommandAddr,
- &UsbCommandReg
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- UsbCommandReg &= ~USBCMD_RS;
- Status = WriteEhcOperationalReg (
- HcDev,
- UsbCommandAddr,
- UsbCommandReg
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
- //
- // Ensure the HC is in halt status after send the stop command
- //
- Status = WaitForEhcHalt (HcDev, EHCI_GENERIC_TIMEOUT);
- if (EFI_ERROR (Status)) {
- Status = EFI_TIMEOUT;
- goto exit;
- }
- }
- break;
-
- case EfiUsbHcStateOperational:
-
- if (IsEhcSysError (HcDev)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
- if (EfiUsbHcStateOperational == CurrentState) {
- Status = EFI_SUCCESS;
- goto exit;
- } else if (EfiUsbHcStateHalt == CurrentState) {
- //
- // Set Host Controller Run
- //
- Status = ReadEhcOperationalReg (
- HcDev,
- UsbCommandAddr,
- &UsbCommandReg
- );
- if (EFI_ERROR (Status)) {
- return EFI_DEVICE_ERROR;
- }
-
- UsbCommandReg |= USBCMD_RS;
- Status = WriteEhcOperationalReg (
- HcDev,
- UsbCommandAddr,
- UsbCommandReg
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
- }
- break;
-
- case EfiUsbHcStateSuspend:
-
- Status = EFI_UNSUPPORTED;
- break;
-
- default:
-
- Status = EFI_INVALID_PARAMETER;
- }
-
-exit:
- return Status;
-}
-
-EFI_STATUS
-EFIAPI
-EhciGetRootHubPortStatus (
- IN EFI_USB2_HC_PROTOCOL *This,
- IN UINT8 PortNumber,
- OUT EFI_USB_PORT_STATUS *PortStatus
- )
-/*++
-
- Routine Description:
-
- Retrieves the current status of a USB root hub port.
-
- Arguments:
-
- This - A pointer to the EFI_USB2_HC_PROTOCOL.
- PortNumber - Specifies the root hub port from which the status
- is to be retrieved. This value is zero-based. For example,
- if a root hub has two ports, then the first port is numbered 0,
- and the second port is numbered 1.
- PortStatus - A pointer to the current port status bits and
- port status change bits.
-
- Returns:
-
- EFI_SUCCESS The status of the USB root hub port specified
- by PortNumber was returned in PortStatus.
- EFI_INVALID_PARAMETER PortNumber is invalid.
- EFI_DEVICE_ERROR Can't read register
-
---*/
-{
- EFI_STATUS Status;
- USB2_HC_DEV *HcDev;
- UINT32 PortStatusControlAddr;
- UINT32 PortStatusControlReg;
- UINT8 MaxSpeed;
- UINT8 TotalPortNumber;
- UINT8 Is64BitCapable;
-
- if (PortStatus == NULL) {
- Status = EFI_INVALID_PARAMETER;
- goto exit;
- }
-
- EhciGetCapability (
- This,
- &MaxSpeed,
- &TotalPortNumber,
- &Is64BitCapable
- );
-
- if (PortNumber >= TotalPortNumber) {
- Status = EFI_INVALID_PARAMETER;
- goto exit;
- }
-
- HcDev = USB2_HC_DEV_FROM_THIS (This);
- PortStatusControlAddr = (UINT32) (PORTSC + (4 * PortNumber));
-
- //
- // Clear port status
- //
- PortStatus->PortStatus = 0;
- PortStatus->PortChangeStatus = 0;
-
- Status = ReadEhcOperationalReg (
- HcDev,
- PortStatusControlAddr,
- &PortStatusControlReg
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- //
- // Fill Port Status bits
- //
-
- //
- // Current Connect Status
- //
- if (PORTSC_CCS & PortStatusControlReg) {
- PortStatus->PortStatus |= USB_PORT_STAT_CONNECTION;
- }
- //
- // Port Enabled/Disabled
- //
- if (PORTSC_PED & PortStatusControlReg) {
- PortStatus->PortStatus |= USB_PORT_STAT_ENABLE;
- }
- //
- // Port Suspend
- //
- if (PORTSC_SUSP & PortStatusControlReg) {
- PortStatus->PortStatus |= USB_PORT_STAT_SUSPEND;
- }
- //
- // Over-current Active
- //
- if (PORTSC_OCA & PortStatusControlReg) {
- PortStatus->PortStatus |= USB_PORT_STAT_OVERCURRENT;
- }
- //
- // Port Reset
- //
- if (PORTSC_PR & PortStatusControlReg) {
- PortStatus->PortStatus |= USB_PORT_STAT_RESET;
- }
- //
- // Port Power
- //
- if (PORTSC_PP & PortStatusControlReg) {
- PortStatus->PortStatus |= USB_PORT_STAT_POWER;
- }
- //
- // Port Owner
- //
- if (PORTSC_PO & PortStatusControlReg) {
- PortStatus->PortStatus |= USB_PORT_STAT_OWNER;
- }
- //
- // Identify device speed
- //
- if (PORTSC_LS_KSTATE & PortStatusControlReg) {
- //
- // Low Speed Device Attached
- //
- PortStatus->PortStatus |= USB_PORT_STAT_LOW_SPEED;
- } else {
- //
- // Not Low Speed Device Attached
- //
- if ((PORTSC_CCS & PortStatusControlReg) && (PORTSC_CSC & PortStatusControlReg)) {
- HcDev->DeviceSpeed[PortNumber] = (UINT16) (IsHighSpeedDevice (This, PortNumber) ? USB_PORT_STAT_HIGH_SPEED : 0);
- }
- PortStatus->PortStatus = (UINT16) (PortStatus->PortStatus | HcDev->DeviceSpeed[PortNumber]);
- }
- //
- // Fill Port Status Change bits
- //
- //
- // Connect Status Change
- //
- if (PORTSC_CSC & PortStatusControlReg) {
- PortStatus->PortChangeStatus |= USB_PORT_STAT_C_CONNECTION;
- }
- //
- // Port Enabled/Disabled Change
- //
- if (PORTSC_PEDC & PortStatusControlReg) {
- PortStatus->PortChangeStatus |= USB_PORT_STAT_C_ENABLE;
- }
- //
- // Port Over Current Change
- //
- if (PORTSC_OCC & PortStatusControlReg) {
- PortStatus->PortChangeStatus |= USB_PORT_STAT_C_OVERCURRENT;
- }
-
-exit:
- return Status;
-}
-
-EFI_STATUS
-EFIAPI
-EhciSetRootHubPortFeature (
- IN EFI_USB2_HC_PROTOCOL *This,
- IN UINT8 PortNumber,
- IN EFI_USB_PORT_FEATURE PortFeature
- )
-/*++
-
- Routine Description:
-
- Sets a feature for the specified root hub port.
-
- Arguments:
-
- This - A pointer to the EFI_USB2_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.
-
- Returns:
-
- EFI_SUCCESS
- The feature specified by PortFeature was set for the
- USB root hub port specified by PortNumber.
- EFI_INVALID_PARAMETER
- PortNumber is invalid or PortFeature is invalid.
- EFI_DEVICE_ERROR
- Can't read register
-
---*/
-{
- EFI_STATUS Status;
- USB2_HC_DEV *HcDev;
- UINT32 PortStatusControlAddr;
- UINT32 PortStatusControlReg;
- UINT8 MaxSpeed;
- UINT8 TotalPortNumber;
- UINT8 Is64BitCapable;
-
- EhciGetCapability (
- This,
- &MaxSpeed,
- &TotalPortNumber,
- &Is64BitCapable
- );
-
- if (PortNumber >= TotalPortNumber) {
- Status = EFI_INVALID_PARAMETER;
- goto exit;
- }
-
- HcDev = USB2_HC_DEV_FROM_THIS (This);
- PortStatusControlAddr = (UINT32) (PORTSC + (4 * PortNumber));
-
- Status = ReadEhcOperationalReg (
- HcDev,
- PortStatusControlAddr,
- &PortStatusControlReg
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- switch (PortFeature) {
-
- case EfiUsbPortEnable:
-
- //
- // Sofeware can't set this bit, Port can only be enable by the Host Controller
- // as a part of the reset and enable
- //
- PortStatusControlReg &= 0xffffffd5;
- PortStatusControlReg |= PORTSC_PED;
- break;
-
- case EfiUsbPortSuspend:
-
- PortStatusControlReg &= 0xffffffd5;
- PortStatusControlReg |= PORTSC_SUSP;
- break;
-
- case EfiUsbPortReset:
-
- //
- // Make sure Host Controller not halt before reset it
- //
- if (IsEhcHalted (HcDev)) {
- Status = StartScheduleExecution (HcDev);
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
- Status = WaitForEhcNotHalt (HcDev, EHCI_GENERIC_TIMEOUT);
- if (EFI_ERROR (Status)) {
- DEBUG ((gEHCDebugLevel, "EHCI: WaitForEhcNotHalt TimeOut\n"));
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
- }
- PortStatusControlReg &= 0xffffffd5;
- PortStatusControlReg |= PORTSC_PR;
- //
- // Set one to PortReset bit must also set zero to PortEnable bit
- //
- PortStatusControlReg &= ~PORTSC_PED;
- break;
-
- case EfiUsbPortPower:
-
- //
- // No support, no operation
- //
- goto exit;
-
- case EfiUsbPortOwner:
-
- PortStatusControlReg &= 0xffffffd5;
- PortStatusControlReg |= PORTSC_PO;
- break;
-
- default:
-
- Status = EFI_INVALID_PARAMETER;
- goto exit;
- }
-
- Status = WriteEhcOperationalReg (
- HcDev,
- PortStatusControlAddr,
- PortStatusControlReg
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- }
-
-exit:
- return Status;
-}
-
-EFI_STATUS
-EFIAPI
-EhciClearRootHubPortFeature (
- IN EFI_USB2_HC_PROTOCOL *This,
- IN UINT8 PortNumber,
- IN EFI_USB_PORT_FEATURE PortFeature
- )
-/*++
-
- Routine Description:
-
- Clears a feature for the specified root hub port.
-
- Arguments:
-
- This - A pointer to the EFI_USB2_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.
-
- Returns:
-
- EFI_SUCCESS
- The feature specified by PortFeature was cleared for the
- USB root hub port specified by PortNumber.
- EFI_INVALID_PARAMETER
- PortNumber is invalid or PortFeature is invalid.
- EFI_DEVICE_ERROR
- Can't read register
-
---*/
-{
- EFI_STATUS Status;
- USB2_HC_DEV *HcDev;
- UINT32 PortStatusControlAddr;
- UINT32 PortStatusControlReg;
- UINT8 MaxSpeed;
- UINT8 TotalPortNumber;
- UINT8 Is64BitCapable;
-
- EhciGetCapability (
- This,
- &MaxSpeed,
- &TotalPortNumber,
- &Is64BitCapable
- );
-
- if (PortNumber >= TotalPortNumber) {
- Status = EFI_INVALID_PARAMETER;
- goto exit;
- }
-
- HcDev = USB2_HC_DEV_FROM_THIS (This);
- PortStatusControlAddr = (UINT32) (PORTSC + (4 * PortNumber));
-
- Status = ReadEhcOperationalReg (
- HcDev,
- PortStatusControlAddr,
- &PortStatusControlReg
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- switch (PortFeature) {
-
- case EfiUsbPortEnable:
-
- //
- // Clear PORT_ENABLE feature means disable port.
- //
- PortStatusControlReg &= 0xffffffd5;
- PortStatusControlReg &= ~PORTSC_PED;
- break;
-
- case EfiUsbPortSuspend:
-
- //
- // A write of zero to this bit is ignored by the host controller.
- // The host controller will unconditionally set this bit to a zero when:
- // 1. software sets the Forct Port Resume bit to a zero from a one.
- // 2. software sets the Port Reset bit to a one frome a zero.
- //
- PortStatusControlReg &= 0xffffffd5;
- PortStatusControlReg &= ~PORTSC_FPR;
- break;
-
- case EfiUsbPortReset:
-
- //
- // Clear PORT_RESET means clear the reset signal.
- //
- PortStatusControlReg &= 0xffffffd5;
- PortStatusControlReg &= ~PORTSC_PR;
- break;
-
- case EfiUsbPortPower:
-
- //
- // No support, no operation
- //
- goto exit;
-
- case EfiUsbPortOwner:
-
- //
- // Clear port owner means this port owned by EHC
- //
- PortStatusControlReg &= 0xffffffd5;
- PortStatusControlReg &= ~PORTSC_PO;
- break;
-
- case EfiUsbPortConnectChange:
-
- //
- // Clear connect status change
- //
- PortStatusControlReg &= 0xffffffd5;
- PortStatusControlReg |= PORTSC_CSC;
- break;
-
- case EfiUsbPortEnableChange:
-
- //
- // Clear enable status change
- //
- PortStatusControlReg &= 0xffffffd5;
- PortStatusControlReg |= PORTSC_PEDC;
- break;
-
- case EfiUsbPortSuspendChange:
-
- //
- // No related bit, no operation
- //
- goto exit;
-
- case EfiUsbPortOverCurrentChange:
-
- //
- // Clear PortOverCurrent change
- //
- PortStatusControlReg &= 0xffffffd5;
- PortStatusControlReg |= PORTSC_OCC;
- break;
-
- case EfiUsbPortResetChange:
-
- //
- // No related bit, no operation
- //
- goto exit;
-
- default:
-
- Status = EFI_INVALID_PARAMETER;
- goto exit;
- }
-
- Status = WriteEhcOperationalReg (
- HcDev,
- PortStatusControlAddr,
- PortStatusControlReg
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
-exit:
- return Status;
-}
-
-EFI_STATUS
-EFIAPI
-EhciControlTransfer (
- 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
- )
-/*++
-
- Routine Description:
-
- Submits control transfer to a target USB device.
-
- Arguments:
-
- This - A pointer to the EFI_USB2_HC_PROTOCOL instance.
- DeviceAddress - Represents the address of the target device on the USB,
- which is assigned during USB enumeration.
- DeviceSpeed - Indicates target device speed.
- MaximumPacketLength - Indicates the maximum packet size that the
- default control transfer endpoint is capable of
- sending or receiving.
- Request - A pointer to the USB device request that will be sent
- to the USB device.
- TransferDirection - Specifies the data direction for the transfer.
- There are three values available, DataIn, DataOut
- and NoData.
- Data - A pointer to the buffer of data that will be transmitted
- to USB device or received from USB device.
- DataLength - Indicates the size, in bytes, of the data buffer
- specified by Data.
- TimeOut - Indicates the maximum time, in microseconds,
- which the transfer is allowed to complete.
- Translator - A pointr to the transaction translator data.
- TransferResult - A pointer to the detailed result information generated
- by this control transfer.
-
- Returns:
-
- EFI_SUCCESS
- The control transfer was completed successfully.
- EFI_OUT_OF_RESOURCES
- The control transfer could not be completed due to a lack of resources.
- EFI_INVALID_PARAMETER
- Some parameters are invalid.
- EFI_TIMEOUT
- The control transfer failed due to timeout.
- EFI_DEVICE_ERROR
- The control transfer failed due to host controller or device error.
- Caller should check TranferResult for detailed error information.
-
---*/
-{
- EFI_STATUS Status;
- USB2_HC_DEV *HcDev;
- UINT8 PktId;
- EHCI_QH_ENTITY *QhPtr;
- EHCI_QTD_ENTITY *ControlQtdsPtr;
- UINT8 *DataCursor;
- VOID *DataMap;
- UINT8 *RequestCursor;
- VOID *RequestMap;
-
- QhPtr = NULL;
- ControlQtdsPtr = NULL;
- DataCursor = NULL;
- DataMap = NULL;
- RequestCursor = NULL;
- RequestMap = NULL;
- HcDev = USB2_HC_DEV_FROM_THIS (This);
-
- //
- // Parameters Checking
- //
- if (TransferDirection != EfiUsbDataIn &&
- TransferDirection != EfiUsbDataOut &&
- TransferDirection != EfiUsbNoData
- ) {
- Status = EFI_INVALID_PARAMETER;
- goto exit;
- }
-
- if (EfiUsbNoData == TransferDirection) {
- if (NULL != Data || 0 != *DataLength) {
- Status = EFI_INVALID_PARAMETER;
- goto exit;
- }
- } else {
- if (NULL == Data || 0 == *DataLength) {
- Status = EFI_INVALID_PARAMETER;
- goto exit;
- }
- }
-
- if (Request == NULL || TransferResult == NULL) {
- Status = EFI_INVALID_PARAMETER;
- goto exit;
- }
-
- if (EFI_USB_SPEED_LOW == DeviceSpeed) {
- if (MaximumPacketLength != 8) {
- Status = EFI_INVALID_PARAMETER;
- goto exit;
- }
- } else if (MaximumPacketLength != 8 &&
- MaximumPacketLength != 16 &&
- MaximumPacketLength != 32 &&
- MaximumPacketLength != 64
- ) {
- Status = EFI_INVALID_PARAMETER;
- goto exit;
- }
-
- //
- // If errors exist that cause host controller halt,
- // then return EFI_DEVICE_ERROR.
- //
- if (IsEhcHalted (HcDev) || IsEhcSysError (HcDev)) {
- ClearEhcAllStatus (HcDev);
- *TransferResult = EFI_USB_ERR_SYSTEM;
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- //
- // Map the Request for bus master access.
- // BusMasterRead means cpu write
- //
- Status = MapRequestBuffer (
- HcDev,
- Request,
- &RequestCursor,
- &RequestMap
- );
- if (EFI_ERROR (Status)) {
- *TransferResult = EFI_USB_ERR_SYSTEM;
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- //
- // Map the source data buffer for bus master access.
- //
- Status = MapDataBuffer (
- HcDev,
- TransferDirection,
- Data,
- DataLength,
- &PktId,
- &DataCursor,
- &DataMap
- );
- if (EFI_ERROR (Status)) {
- *TransferResult = EFI_USB_ERR_SYSTEM;
- Status = EFI_DEVICE_ERROR;
- goto unmap_request;
- }
-
- //
- // Create and init control Qh
- //
- Status = CreateControlQh (
- HcDev,
- DeviceAddress,
- DeviceSpeed,
- MaximumPacketLength,
- Translator,
- &QhPtr
- );
- if (EFI_ERROR (Status)) {
- *TransferResult = EFI_USB_ERR_SYSTEM;
- Status = EFI_OUT_OF_RESOURCES;
- goto unmap_data;
- }
-
- //
- // Create and init control Qtds
- //
- Status = CreateControlQtds (
- HcDev,
- PktId,
- RequestCursor,
- DataCursor,
- *DataLength,
- Translator,
- &ControlQtdsPtr
- );
- if (EFI_ERROR (Status)) {
- *TransferResult = EFI_USB_ERR_SYSTEM;
- Status = EFI_OUT_OF_RESOURCES;
- goto destory_qh;
- }
-
- //
- // Link Qtds to Qh
- //
- LinkQtdToQh (QhPtr, ControlQtdsPtr);
-
- ClearEhcAllStatus (HcDev);
-
- //
- // Link Qh and Qtds to Async Schedule List
- //
- Status = LinkQhToAsyncList (HcDev, QhPtr);
- if (EFI_ERROR (Status)) {
- *TransferResult = EFI_USB_ERR_SYSTEM;
- Status = EFI_DEVICE_ERROR;
- goto destory_qtds;
- }
-
- //
- // Poll Qh-Qtds execution and get result.
- // detail status is returned
- //
- Status = ExecuteTransfer (
- HcDev,
- TRUE,
- QhPtr,
- DataLength,
- 0,
- TimeOut,
- TransferResult
- );
- if (EFI_ERROR (Status)) {
- goto destory_qtds;
- }
-
- //
- // If has errors that cause host controller halt,
- // then return EFI_DEVICE_ERROR directly.
- //
- if (IsEhcHalted (HcDev) || IsEhcSysError (HcDev)) {
- *TransferResult |= EFI_USB_ERR_SYSTEM;
- }
-
- ClearEhcAllStatus (HcDev);
-
-destory_qtds:
- UnlinkQhFromAsyncList (HcDev, QhPtr);
- DestoryQtds (HcDev, ControlQtdsPtr);
-destory_qh:
- DestoryQh (HcDev, QhPtr);
-unmap_data:
- HcDev->PciIo->Unmap (HcDev->PciIo, DataMap);
-unmap_request:
- HcDev->PciIo->Unmap (HcDev->PciIo, RequestMap);
-exit:
- HcDev->PciIo->Flush (HcDev->PciIo);
- return Status;
-}
-
-EFI_STATUS
-EFIAPI
-EhciBulkTransfer (
- 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
- )
-/*++
-
- Routine Description:
-
- Submits bulk transfer to a bulk endpoint of a USB device.
-
- Arguments:
-
- This - A pointer to the EFI_USB2_HC_PROTOCOL instance.
- DeviceAddress - Represents the address of the target device on the USB,
- which is assigned during USB enumeration.
- EndPointAddress - The combination of an endpoint number and an
- endpoint direction of the target USB device.
- Each endpoint address supports data transfer in
- one direction except the control endpoint
- (whose default endpoint address is 0).
- It is the caller's responsibility to make sure that
- the EndPointAddress represents a bulk endpoint.
- DeviceSpeed - Indicates device speed. The supported values are EFI_USB_SPEED_FULL
- and EFI_USB_SPEED_HIGH.
- MaximumPacketLength - Indicates the maximum packet size the target endpoint
- is capable of sending or receiving.
- DataBuffersNumber - Number of data buffers prepared for the transfer.
- Data - Array of pointers to the buffers of data that will be transmitted
- to USB device or received from USB device.
- DataLength - When input, indicates the size, in bytes, of the data buffer
- specified by Data. When output, indicates the actually
- transferred data size.
- DataToggle - A pointer to the data toggle value. On input, it indicates
- the initial data toggle value the bulk transfer should adopt;
- on output, it is updated to indicate the data toggle value
- of the subsequent bulk transfer.
- Translator - A pointr to the transaction translator data.
- TimeOut - Indicates the maximum time, in microseconds, which the
- transfer is allowed to complete.
- TransferResult - A pointer to the detailed result information of the
- bulk transfer.
-
- Returns:
-
- EFI_SUCCESS
- The bulk transfer was completed successfully.
- EFI_OUT_OF_RESOURCES
- The bulk transfer could not be submitted due to lack of resource.
- EFI_INVALID_PARAMETER
- Some parameters are invalid.
- EFI_TIMEOUT
- The bulk transfer failed due to timeout.
- EFI_DEVICE_ERROR
- The bulk transfer failed due to host controller or device error.
- Caller should check TranferResult for detailed error information.
-
---*/
-{
- EFI_STATUS Status;
- USB2_HC_DEV *HcDev;
- UINT8 PktId;
- EHCI_QH_ENTITY *QhPtr;
- EHCI_QTD_ENTITY *BulkQtdsPtr;
- UINT8 *DataCursor;
- VOID *DataMap;
- EFI_USB_DATA_DIRECTION TransferDirection;
-
- QhPtr = NULL;
- BulkQtdsPtr = NULL;
- DataCursor = NULL;
- DataMap = NULL;
- HcDev = USB2_HC_DEV_FROM_THIS (This);
-
- //
- // Parameters Checking
- //
- if (NULL == DataLength ||
- NULL == Data ||
- NULL == Data[0] ||
- NULL == TransferResult
- ) {
- Status = EFI_INVALID_PARAMETER;
- goto exit;
- }
-
- if (*DataLength == 0) {
- Status = EFI_INVALID_PARAMETER;
- goto exit;
- }
-
- if (1 != *DataToggle && 0 != *DataToggle) {
- Status = EFI_INVALID_PARAMETER;
- goto exit;
- }
-
- if (EFI_USB_SPEED_LOW == DeviceSpeed) {
- Status = EFI_INVALID_PARAMETER;
- goto exit;
- }
-
- if (EFI_USB_SPEED_FULL == DeviceSpeed) {
- if (MaximumPacketLength > 64) {
- Status = EFI_INVALID_PARAMETER;
- goto exit;
- }
- }
-
- if (EFI_USB_SPEED_HIGH == DeviceSpeed) {
- if (MaximumPacketLength > 512) {
- Status = EFI_INVALID_PARAMETER;
- goto exit;
- }
- }
-
- //
- // if has errors that cause host controller halt,
- // then return EFI_DEVICE_ERROR directly.
- //
- if (IsEhcHalted (HcDev) || IsEhcSysError (HcDev)) {
- ClearEhcAllStatus (HcDev);
- *TransferResult = EFI_USB_ERR_SYSTEM;
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- Status = ClearEhcAllStatus (HcDev);
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- //
- // construct QH and TD data structures,
- // and link them together
- //
- if (EndPointAddress & 0x80) {
- TransferDirection = EfiUsbDataIn;
- } else {
- TransferDirection = EfiUsbDataOut;
- }
-
- Status = MapDataBuffer (
- HcDev,
- TransferDirection,
- Data[0],
- DataLength,
- &PktId,
- &DataCursor,
- &DataMap
- );
- if (EFI_ERROR (Status)) {
- *TransferResult = EFI_USB_ERR_SYSTEM;
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- //
- // Create and init Bulk Qh
- //
- Status = CreateBulkQh (
- HcDev,
- DeviceAddress,
- EndPointAddress,
- DeviceSpeed,
- *DataToggle,
- MaximumPacketLength,
- Translator,
- &QhPtr
- );
- if (EFI_ERROR (Status)) {
- *TransferResult = EFI_USB_ERR_SYSTEM;
- Status = EFI_OUT_OF_RESOURCES;
- goto unmap_data;
- }
-
- //
- // Create and init Bulk Qtds
- //
- Status = CreateBulkOrInterruptQtds (
- HcDev,
- PktId,
- DataCursor,
- *DataLength,
- Translator,
- &BulkQtdsPtr
- );
- if (EFI_ERROR (Status)) {
- *TransferResult = EFI_USB_ERR_SYSTEM;
- Status = EFI_OUT_OF_RESOURCES;
- goto destory_qh;
- }
-
- //
- // Link Qtds to Qh
- //
- LinkQtdToQh (QhPtr, BulkQtdsPtr);
-
- ClearEhcAllStatus (HcDev);
-
- //
- // Link Qh and qtds to Async Schedule List
- //
- Status = LinkQhToAsyncList (HcDev, QhPtr);
- if (EFI_ERROR (Status)) {
- *TransferResult = EFI_USB_ERR_SYSTEM;
- Status = EFI_DEVICE_ERROR;
- goto destory_qtds;
- }
-
- //
- // Poll QH-TDs execution and get result.
- // detail status is returned
- //
- Status = ExecuteTransfer (
- HcDev,
- FALSE,
- QhPtr,
- DataLength,
- DataToggle,
- TimeOut,
- TransferResult
- );
- if (EFI_ERROR (Status)) {
- goto destory_qtds;
- }
-
- //
- // if has errors that cause host controller halt,
- // then return EFI_DEVICE_ERROR directly.
- //
- if (IsEhcHalted (HcDev) || IsEhcSysError (HcDev)) {
- *TransferResult |= EFI_USB_ERR_SYSTEM;
- }
-
- ClearEhcAllStatus (HcDev);
-
-destory_qtds:
- UnlinkQhFromAsyncList (HcDev, QhPtr);
- DestoryQtds (HcDev, BulkQtdsPtr);
-destory_qh:
- DestoryQh (HcDev, QhPtr);
-unmap_data:
- HcDev->PciIo->Unmap (HcDev->PciIo, DataMap);
-exit:
- HcDev->PciIo->Flush (HcDev->PciIo);
- return Status;
-}
-
-EFI_STATUS
-EFIAPI
-EhciAsyncInterruptTransfer (
- 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 OPTIONAL
- )
-/*++
-
- Routine Description:
-
- Submits an asynchronous interrupt transfer to an
- interrupt endpoint of a USB device.
- Translator parameter doesn't exist in UEFI2.0 spec, but it will be updated
- in the following specification version.
-
- Arguments:
-
- This - A pointer to the EFI_USB2_HC_PROTOCOL instance.
- DeviceAddress - Represents the address of the target device on the USB,
- which is assigned during USB enumeration.
- EndPointAddress - The combination of an endpoint number and an endpoint
- direction of the target USB device. Each endpoint address
- supports data transfer in one direction except the
- control endpoint (whose default endpoint address is 0).
- It is the caller's responsibility to make sure that
- the EndPointAddress represents an interrupt endpoint.
- DeviceSpeed - Indicates device speed.
- MaximumPacketLength - Indicates the maximum packet size the target endpoint
- is capable of sending or receiving.
- IsNewTransfer - If TRUE, an asynchronous interrupt pipe is built between
- the host and the target interrupt endpoint.
- If FALSE, the specified asynchronous interrupt pipe
- is canceled.
- DataToggle - A pointer to the data toggle value. On input, it is valid
- when IsNewTransfer is TRUE, and it indicates the initial
- data toggle value the asynchronous interrupt transfer
- should adopt.
- On output, it is valid when IsNewTransfer is FALSE,
- and it is updated to indicate the data toggle value of
- the subsequent asynchronous interrupt transfer.
- PollingInterval - Indicates the interval, in milliseconds, that the
- asynchronous interrupt transfer is polled.
- This parameter is required when IsNewTransfer is TRUE.
- DataLength - Indicates the length of data to be received at the
- rate specified by PollingInterval from the target
- asynchronous interrupt endpoint. This parameter
- is only required when IsNewTransfer is TRUE.
- Translator - A pointr to the transaction translator data.
- CallBackFunction - The Callback function.This function is called at the
- rate specified by PollingInterval.This parameter is
- only required when IsNewTransfer is TRUE.
- Context - The context that is passed to the CallBackFunction.
- - This is an optional parameter and may be NULL.
-
- Returns:
-
- EFI_SUCCESS
- The asynchronous interrupt transfer request has been successfully
- submitted or canceled.
- EFI_INVALID_PARAMETER
- Some parameters are invalid.
- EFI_OUT_OF_RESOURCES
- The request could not be completed due to a lack of resources.
- EFI_DEVICE_ERROR
- Can't read register
-
---*/
-{
- EFI_STATUS Status;
- USB2_HC_DEV *HcDev;
- UINT8 PktId;
- EHCI_QH_ENTITY *QhPtr;
- EHCI_QTD_ENTITY *InterruptQtdsPtr;
- UINT8 *DataPtr;
- UINT8 *DataCursor;
- VOID *DataMap;
- UINTN MappedLength;
- EHCI_ASYNC_REQUEST *AsyncRequestPtr;
- EFI_TPL OldTpl;
-
- QhPtr = NULL;
- InterruptQtdsPtr = NULL;
- DataPtr = NULL;
- DataCursor = NULL;
- DataMap = NULL;
- AsyncRequestPtr = NULL;
- HcDev = USB2_HC_DEV_FROM_THIS (This);
-
- //
- // Parameters Checking
- //
- if (!IsDataInTransfer (EndPointAddress)) {
- Status = EFI_INVALID_PARAMETER;
- goto exit;
- }
-
- if (IsNewTransfer) {
- if (0 == DataLength) {
- Status = EFI_INVALID_PARAMETER;
- goto exit;
- }
-
- if (*DataToggle != 1 && *DataToggle != 0) {
- Status = EFI_INVALID_PARAMETER;
- goto exit;
- }
-
- if (PollingInterval > 255 || PollingInterval < 1) {
- Status = EFI_INVALID_PARAMETER;
- goto exit;
- }
- }
-
- //
- // if has errors that cause host controller halt,
- // then return EFI_DEVICE_ERROR directly.
- //
- if (IsEhcHalted (HcDev) || IsEhcSysError (HcDev)) {
- ClearEhcAllStatus (HcDev);
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- Status = ClearEhcAllStatus (HcDev);
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- //
- // Delete Async interrupt transfer request
- //
- if (!IsNewTransfer) {
-
- OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
-
- Status = DeleteAsyncRequestTransfer (
- HcDev,
- DeviceAddress,
- EndPointAddress,
- DataToggle
- );
-
- gBS->RestoreTPL (OldTpl);
-
- goto exit;
- }
-
- Status = EhciAllocatePool (
- HcDev,
- (UINT8 **) &AsyncRequestPtr,
- sizeof (EHCI_ASYNC_REQUEST)
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_OUT_OF_RESOURCES;
- goto exit;
- }
-
- Status = EhciAllocatePool (HcDev, &DataPtr, DataLength);
- if (EFI_ERROR (Status)) {
- Status = EFI_OUT_OF_RESOURCES;
- goto free_request;
- }
-
- MappedLength = DataLength;
- Status = MapDataBuffer (
- HcDev,
- EfiUsbDataIn,
- DataPtr,
- &MappedLength,
- &PktId,
- &DataCursor,
- &DataMap
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto free_data;
- }
-
- //
- // Create and init Interrupt Qh
- //
- Status = CreateInterruptQh (
- HcDev,
- DeviceAddress,
- EndPointAddress,
- DeviceSpeed,
- *DataToggle,
- MaximumPacketLength,
- PollingInterval,
- Translator,
- &QhPtr
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_OUT_OF_RESOURCES;
- goto unmap_data;
- }
-
- //
- // Create and init Interrupt Qtds
- //
- Status = CreateBulkOrInterruptQtds (
- HcDev,
- PktId,
- DataCursor,
- MappedLength,
- Translator,
- &InterruptQtdsPtr
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_OUT_OF_RESOURCES;
- goto destory_qh;
- }
-
- //
- // Link Qtds to Qh
- //
- LinkQtdToQh (QhPtr, InterruptQtdsPtr);
-
- //
- // Init AsyncRequest Entry
- //
- AsyncRequestPtr->Context = Context;
- AsyncRequestPtr->CallBackFunc = CallBackFunction;
- AsyncRequestPtr->TransferType = ASYNC_INTERRUPT_TRANSFER;
- AsyncRequestPtr->QhPtr = QhPtr;
- AsyncRequestPtr->Prev = NULL;
- AsyncRequestPtr->Next = NULL;
-
- if (NULL == HcDev->AsyncRequestList) {
- Status = StartPollingTimer (HcDev);
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- CleanUpAllAsyncRequestTransfer (HcDev);
- goto exit;
- }
- }
-
- //
- // Link Entry to AsyncRequest List
- //
- LinkToAsyncReqeust (HcDev, AsyncRequestPtr);
-
- ClearEhcAllStatus (HcDev);
-
- Status = DisablePeriodicSchedule (HcDev);
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- Status = WaitForPeriodicScheduleDisable (HcDev, EHCI_GENERIC_TIMEOUT);
- if (EFI_ERROR (Status)) {
- Status = EFI_TIMEOUT;
- goto exit;
- }
-
- //
- // Link Qh and Qtds to Periodic Schedule List
- //
- LinkQhToPeriodicList (HcDev, QhPtr);
-
- Status = EnablePeriodicSchedule (HcDev);
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- Status = WaitForPeriodicScheduleEnable (HcDev, EHCI_GENERIC_TIMEOUT);
- if (EFI_ERROR (Status)) {
- Status = EFI_TIMEOUT;
- goto exit;
- }
-
- if (IsEhcHalted (HcDev)) {
- Status = StartScheduleExecution (HcDev);
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
- }
-
- HcDev->PciIo->Flush (HcDev->PciIo);
- goto exit;
-
-destory_qh:
- DestoryQh (HcDev, QhPtr);
-free_data:
- EhciFreePool (HcDev, DataPtr, DataLength);
-free_request:
- EhciFreePool (
- HcDev,
- (UINT8 *) AsyncRequestPtr,
- sizeof (EHCI_ASYNC_REQUEST)
- );
-unmap_data:
- HcDev->PciIo->Unmap (HcDev->PciIo, DataMap);
-exit:
- return Status;
-}
-
-EFI_STATUS
-EFIAPI
-EhciSyncInterruptTransfer (
- 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
- )
-/*++
-
- Routine Description:
-
- Submits synchronous interrupt transfer to an interrupt endpoint
- of a USB device.
- Translator parameter doesn't exist in UEFI2.0 spec, but it will be updated
- in the following specification version.
-
- Arguments:
-
- This - A pointer to the EFI_USB2_HC_PROTOCOL instance.
- DeviceAddress - Represents the address of the target device on the USB,
- which is assigned during USB enumeration.
- EndPointAddress - The combination of an endpoint number and an endpoint
- direction of the target USB device. Each endpoint
- address supports data transfer in one direction
- except the control endpoint (whose default
- endpoint address is 0). It is the caller's responsibility
- to make sure that the EndPointAddress represents
- an interrupt endpoint.
- DeviceSpeed - Indicates device speed.
- MaximumPacketLength - Indicates the maximum packet size the target endpoint
- is capable of sending or receiving.
- Data - A pointer to the buffer of data that will be transmitted
- to USB device or received from USB device.
- DataLength - On input, the size, in bytes, of the data buffer specified
- by Data. On output, the number of bytes transferred.
- DataToggle - A pointer to the data toggle value. On input, it indicates
- the initial data toggle value the synchronous interrupt
- transfer should adopt;
- on output, it is updated to indicate the data toggle value
- of the subsequent synchronous interrupt transfer.
- TimeOut - Indicates the maximum time, in microseconds, which the
- transfer is allowed to complete.
- Translator - A pointr to the transaction translator data.
- TransferResult - A pointer to the detailed result information from
- the synchronous interrupt transfer.
-
- Returns:
-
- EFI_SUCCESS
- The synchronous interrupt transfer was completed successfully.
- EFI_OUT_OF_RESOURCES
- The synchronous interrupt transfer could not be submitted due
- to lack of resource.
- EFI_INVALID_PARAMETER
- Some parameters are invalid.
- EFI_TIMEOUT
- The synchronous interrupt transfer failed due to timeout.
- EFI_DEVICE_ERROR
- The synchronous interrupt transfer failed due to host controller
- or device error. Caller should check TranferResult for detailed
- error information.
-
---*/
-{
- EFI_STATUS Status;
- USB2_HC_DEV *HcDev;
- UINT8 PktId;
- EHCI_QH_ENTITY *QhPtr;
- EHCI_QTD_ENTITY *InterruptQtdsPtr;
- UINT8 *DataCursor;
- VOID *DataMap;
-
- QhPtr = NULL;
- InterruptQtdsPtr = NULL;
- DataCursor = NULL;
- DataMap = NULL;
- HcDev = USB2_HC_DEV_FROM_THIS (This);
-
- //
- // Parameters Checking
- //
- if (DataLength == NULL ||
- Data == NULL ||
- TransferResult == NULL
- ) {
- Status = EFI_INVALID_PARAMETER;
- goto exit;
- }
-
- if (!IsDataInTransfer (EndPointAddress)) {
- Status = EFI_INVALID_PARAMETER;
- goto exit;
- }
-
- if (0 == *DataLength) {
- Status = EFI_INVALID_PARAMETER;
- goto exit;
- }
-
- if (*DataToggle != 1 && *DataToggle != 0) {
- Status = EFI_INVALID_PARAMETER;
- goto exit;
- }
-
- if (EFI_USB_SPEED_LOW == DeviceSpeed && 8 != MaximumPacketLength) {
- Status = EFI_INVALID_PARAMETER;
- goto exit;
- }
-
- if (EFI_USB_SPEED_FULL == DeviceSpeed && MaximumPacketLength > 64) {
- Status = EFI_INVALID_PARAMETER;
- goto exit;
- }
-
- if (EFI_USB_SPEED_HIGH == DeviceSpeed && MaximumPacketLength > 3072) {
- Status = EFI_INVALID_PARAMETER;
- goto exit;
- }
-
- //
- // if has errors that cause host controller halt,
- // then return EFI_DEVICE_ERROR directly.
- //
- if (IsEhcHalted (HcDev) || IsEhcSysError (HcDev)) {
- ClearEhcAllStatus (HcDev);
- *TransferResult = EFI_USB_ERR_SYSTEM;
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- Status = ClearEhcAllStatus (HcDev);
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- Status = MapDataBuffer (
- HcDev,
- EfiUsbDataIn,
- Data,
- DataLength,
- &PktId,
- &DataCursor,
- &DataMap
- );
- if (EFI_ERROR (Status)) {
- *TransferResult = EFI_USB_ERR_SYSTEM;
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- //
- // Create and init Interrupt Qh
- //
- Status = CreateInterruptQh (
- HcDev,
- DeviceAddress,
- EndPointAddress,
- DeviceSpeed,
- *DataToggle,
- MaximumPacketLength,
- 0,
- Translator,
- &QhPtr
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_OUT_OF_RESOURCES;
- goto unmap_data;
- }
-
- //
- // Create and init Interrupt Qtds
- //
- Status = CreateBulkOrInterruptQtds (
- HcDev,
- PktId,
- DataCursor,
- *DataLength,
- Translator,
- &InterruptQtdsPtr
- );
- if (EFI_ERROR (Status)) {
- *TransferResult = EFI_USB_ERR_SYSTEM;
- Status = EFI_OUT_OF_RESOURCES;
- goto destory_qh;
- }
-
- //
- // Link Qtds to Qh
- //
- LinkQtdToQh (QhPtr, InterruptQtdsPtr);
-
- ClearEhcAllStatus (HcDev);
-
- Status = DisablePeriodicSchedule (HcDev);
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- Status = WaitForPeriodicScheduleDisable (HcDev, EHCI_GENERIC_TIMEOUT);
- if (EFI_ERROR (Status)) {
- Status = EFI_TIMEOUT;
- goto exit;
- }
-
- //
- // Link Qh and Qtds to Periodic Schedule List
- //
- LinkQhToPeriodicList (HcDev, QhPtr);
-
- Status = EnablePeriodicSchedule (HcDev);
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- Status = WaitForPeriodicScheduleEnable (HcDev, EHCI_GENERIC_TIMEOUT);
- if (EFI_ERROR (Status)) {
- Status = EFI_TIMEOUT;
- goto exit;
- }
-
- if (IsEhcHalted (HcDev)) {
- Status = StartScheduleExecution (HcDev);
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
- }
-
- //
- // Poll QH-TDs execution and get result.
- // detail status is returned
- //
- Status = ExecuteTransfer (
- HcDev,
- FALSE,
- QhPtr,
- DataLength,
- DataToggle,
- TimeOut,
- TransferResult
- );
- if (EFI_ERROR (Status)) {
- goto destory_qtds;
- }
-
- //
- // if has errors that cause host controller halt,
- // then return EFI_DEVICE_ERROR directly.
- //
- if (IsEhcHalted (HcDev) || IsEhcSysError (HcDev)) {
- *TransferResult |= EFI_USB_ERR_SYSTEM;
- }
-
- ClearEhcAllStatus (HcDev);
-
-destory_qtds:
- UnlinkQhFromPeriodicList (HcDev, QhPtr, 0);
- DestoryQtds (HcDev, InterruptQtdsPtr);
-destory_qh:
- DestoryQh (HcDev, QhPtr);
-unmap_data:
- HcDev->PciIo->Unmap (HcDev->PciIo, DataMap);
-exit:
- HcDev->PciIo->Flush (HcDev->PciIo);
- return Status;
-}
-
-EFI_STATUS
-EFIAPI
-EhciIsochronousTransfer (
- 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
- )
-/*++
-
- Routine Description:
-
- Submits isochronous transfer to a target USB device.
-
- Arguments:
-
- This - A pointer to the EFI_USB2_HC_PROTOCOL instance.
- DeviceAddress - Represents the address of the target device on the USB,
- which is assigned during USB enumeration.
- EndPointAddress - End point address
- DeviceSpeed - Indicates device speed.
- MaximumPacketLength - Indicates the maximum packet size that the
- default control transfer endpoint is capable of
- sending or receiving.
- DataBuffersNumber - Number of data buffers prepared for the transfer.
- Data - Array of pointers to the buffers of data that will be
- transmitted to USB device or received from USB device.
- DataLength - Indicates the size, in bytes, of the data buffer
- specified by Data.
- Translator - A pointr to the transaction translator data.
- TransferResult - A pointer to the detailed result information generated
- by this control transfer.
-
- Returns:
-
- EFI_UNSUPPORTED
-
---*/
-{
- return EFI_UNSUPPORTED;
-}
-
-EFI_STATUS
-EFIAPI
-EhciAsyncIsochronousTransfer (
- 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
- )
-/*++
-
- Routine Description:
-
- Submits Async isochronous transfer to a target USB device.
-
- Arguments:
-
- This - A pointer to the EFI_USB2_HC_PROTOCOL instance.
- DeviceAddress - Represents the address of the target device on the USB,
- which is assigned during USB enumeration.
- EndPointAddress - End point address
- DeviceSpeed - Indicates device speed.
- MaximumPacketLength - Indicates the maximum packet size that the
- default control transfer endpoint is capable of
- sending or receiving.
- DataBuffersNumber - Number of data buffers prepared for the transfer.
- Data - Array of pointers to the buffers of data that will be transmitted
- to USB device or received from USB device.
- Translator - A pointr to the transaction translator data.
- IsochronousCallBack - When the transfer complete, the call back function will be called
- Context - Pass to the call back function as parameter
-
- Returns:
-
- EFI_UNSUPPORTED
-
---*/
-{
- return EFI_UNSUPPORTED;
-}
diff --git a/EdkModulePkg/Bus/Pci/Ehci/Dxe/Ehci.h b/EdkModulePkg/Bus/Pci/Ehci/Dxe/Ehci.h
deleted file mode 100644
index 7ac5d28676..0000000000
--- a/EdkModulePkg/Bus/Pci/Ehci/Dxe/Ehci.h
+++ /dev/null
@@ -1,2918 +0,0 @@
-/*++
-
-Copyright (c) 2006 - 2007, 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
-
-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:
-
- Ehci.h
-
-Abstract:
-
-
-Revision History
---*/
-
-#ifndef _EHCI_H
-#define _EHCI_H
-
-//
-// Universal Host Controller Interface data structures and defines
-//
-#include <IndustryStandard/pci22.h>
-
-
-extern UINTN gEHCDebugLevel;
-extern UINTN gEHCErrorLevel;
-
-
-#define STALL_1_MACRO_SECOND 1
-#define STALL_1_MILLI_SECOND 1000 * STALL_1_MACRO_SECOND
-#define STALL_1_SECOND 1000 * STALL_1_MILLI_SECOND
-
-#define MEM_UNIT_SIZE 128
-
-
-#define SETUP_PACKET_PID_CODE 0x02
-#define INPUT_PACKET_PID_CODE 0x01
-#define OUTPUT_PACKET_PID_CODE 0x0
-
-#define ITD_SELECT_TYPE 0x0
-#define QH_SELECT_TYPE 0x01
-#define SITD_SELECT_TYPE 0x02
-#define FSTN_SELECT_TYPE 0x03
-
-#define EHCI_SET_PORT_RESET_RECOVERY_TIME 50 * STALL_1_MILLI_SECOND
-#define EHCI_CLEAR_PORT_RESET_RECOVERY_TIME STALL_1_MILLI_SECOND
-#define EHCI_GENERIC_TIMEOUT 50 * STALL_1_MILLI_SECOND
-#define EHCI_GENERIC_RECOVERY_TIME 50 * STALL_1_MACRO_SECOND
-#define EHCI_SYNC_REQUEST_POLLING_TIME 50 * STALL_1_MACRO_SECOND
-#define EHCI_ASYNC_REQUEST_POLLING_TIME 50 * STALL_1_MILLI_SECOND
-
-#define USB_BAR_INDEX 0 /* how many bytes away from USB_BASE to 0x10 */
-
-#define NORMAL_MEMORY_BLOCK_UNIT_IN_PAGES 16
-
-#define EHCI_MIN_PACKET_SIZE 8
-#define EHCI_MAX_PACKET_SIZE 1024
-#define EHCI_MAX_FRAME_LIST_LENGTH 1024
-#define EHCI_BLOCK_SIZE_WITH_TT 64
-#define EHCI_BLOCK_SIZE 512
-#define EHCI_MAX_QTD_CAPACITY (EFI_PAGE_SIZE * 5)
-
-#define NAK_COUNT_RELOAD 3
-#define QTD_ERROR_COUNTER 3
-#define HIGH_BANDWIDTH_PIPE_MULTIPLIER 1
-
-#define QTD_STATUS_ACTIVE 0x80
-#define QTD_STATUS_HALTED 0x40
-#define QTD_STATUS_BUFFER_ERR 0x20
-#define QTD_STATUS_BABBLE_ERR 0x10
-#define QTD_STATUS_TRANSACTION_ERR 0x08
-#define QTD_STATUS_DO_STOP_SPLIT 0x02
-#define QTD_STATUS_DO_START_SPLIT 0
-#define QTD_STATUS_DO_PING 0x01
-#define QTD_STATUS_DO_OUT 0
-
-#define DATA0 0
-#define DATA1 1
-
-#define MICRO_FRAME_0_CHANNEL 0x01
-#define MICRO_FRAME_1_CHANNEL 0x02
-#define MICRO_FRAME_2_CHANNEL 0x04
-#define MICRO_FRAME_3_CHANNEL 0x08
-#define MICRO_FRAME_4_CHANNEL 0x10
-#define MICRO_FRAME_5_CHANNEL 0x20
-#define MICRO_FRAME_6_CHANNEL 0x40
-#define MICRO_FRAME_7_CHANNEL 0x80
-
-#define CONTROL_TRANSFER 0x01
-#define BULK_TRANSFER 0x02
-#define SYNC_INTERRUPT_TRANSFER 0x04
-#define ASYNC_INTERRUPT_TRANSFER 0x08
-#define SYNC_ISOCHRONOUS_TRANSFER 0x10
-#define ASYNC_ISOCHRONOUS_TRANSFER 0x20
-
-
-//
-// Enhanced Host Controller Registers definitions
-//
-extern EFI_DRIVER_BINDING_PROTOCOL gEhciDriverBinding;
-extern EFI_COMPONENT_NAME_PROTOCOL gEhciComponentName;
-
-#define USBCMD 0x0 /* Command Register Offset 00-03h */
-#define USBCMD_RS 0x01 /* Run / Stop */
-#define USBCMD_HCRESET 0x02 /* Host controller reset */
-#define USBCMD_FLS_512 0x04 /* 512 elements (2048bytes) in Frame List */
-#define USBCMD_FLS_256 0x08 /* 256 elements (1024bytes) in Frame List */
-#define USBCMD_PSE 0x10 /* Periodic schedule enable */
-#define USBCMD_ASE 0x20 /* Asynchronous schedule enable */
-#define USBCMD_IAAD 0x40 /* Interrupt on async advance doorbell */
-
-#define USBSTS 0x04 /* Statue Register Offset 04-07h */
-#define USBSTS_HSE 0x10 /* Host system error */
-#define USBSTS_IAA 0x20 /* Interrupt on async advance */
-#define USBSTS_HCH 0x1000 /* Host controller halted */
-#define USBSTS_PSS 0x4000 /* Periodic schedule status */
-#define USBSTS_ASS 0x8000 /* Asynchronous schedule status */
-
-#define USBINTR 0x08 /* Command Register Offset 08-0bh */
-
-#define FRINDEX 0x0c /* Frame Index Offset 0c-0fh */
-
-#define CTRLDSSGMENT 0x10 /* 4G Segment Selector Offset 10-13h */
-
-#define PERIODICLISTBASE 0x14 /* Frame List Base Address Offset 14-17h */
-
-#define ASYNCLISTADDR 0x18 /* Next Asynchronous List Address Offset 18-1bh */
-
-#define CONFIGFLAG 0x40 /* Configured Flag Register Offset 40-43h */
-#define CONFIGFLAG_CF 0x01 /* Configure Flag */
-
-#define PORTSC 0x44 /* Port Status/Control Offset 44-47h */
-#define PORTSC_CCS 0x01 /* Current Connect Status*/
-#define PORTSC_CSC 0x02 /* Connect Status Change */
-#define PORTSC_PED 0x04 /* Port Enable / Disable */
-#define PORTSC_PEDC 0x08 /* Port Enable / Disable Change */
-#define PORTSC_OCA 0x10 /* Over current Active */
-#define PORTSC_OCC 0x20 /* Over current Change */
-#define PORTSC_FPR 0x40 /* Force Port Resume */
-#define PORTSC_SUSP 0x80 /* Port Suspend State */
-#define PORTSC_PR 0x100 /* Port Reset */
-#define PORTSC_LS_KSTATE 0x400 /* Line Status K-state */
-#define PORTSC_LS_JSTATE 0x800 /* Line Status J-state */
-#define PORTSC_PP 0x1000 /* Port Power */
-#define PORTSC_PO 0x2000 /* Port Owner */
-
-#define CAPLENGTH 0 /* Capability Register Length 00h */
-
-#define HCIVERSION 0x02 /* Interface Version Number 02-03h */
-
-#define HCSPARAMS 0x04 /* Structural Parameters 04-07h */
-#define HCSP_NPORTS 0x0f /* Number of physical downstream ports on host controller */
-
-#define HCCPARAMS 0x08 /* Capability Parameters 08-0bh */
-#define HCCP_64BIT 0x01 /* 64-bit Addressing Capability */
-#define HCCP_PFLF 0x02 /* Programmable Frame List Flag */
-#define HCCP_EECP 0xff00 /* EHCI Extemded Capabilities Pointer */
-
-#define HCSPPORTROUTE 0x0c /* Companion Port Route Description 60b */
-
-#define CLASSC 0x09 /* Class Code 09-0bh */
-
-#define USBBASE 0x10 /* Base Address to Memory-mapped Host Controller Register Space 10-13h */
-
-#define SBRN 0x60 /* Serial Bus Release Number 60h */
-
-#define FLADJ 0x61 /* Frame Length Adjustment Register 61h */
-
-#define PORTWAKECAP 0x62 /* Port wake capablilities register(OPIONAL) 61-62h */
-
-//
-// PCI Configuration Registers
-//
-#define EHCI_PCI_CLASSC 0x09
-#define EHCI_PCI_MEMORY_BASE 0x10
-
-//
-// Memory Offset Registers
-//
-#define EHCI_MEMORY_CAPLENGTH 0x0
-#define EHCI_MEMORY_CONFIGFLAG 0x40
-
-//
-// USB Base Class Code,Sub-Class Code and Programming Interface
-//
-#define PCI_CLASSC_PI_EHCI PCI_IF_EHCI
-
-#define SETUP_PACKET_ID 0x2D
-#define INPUT_PACKET_ID 0x69
-#define OUTPUT_PACKET_ID 0xE1
-#define ERROR_PACKET_ID 0x55
-
-#define bit(a) (1 << (a))
-
-#define GET_0B_TO_31B(Addr) (((UINTN) Addr) & (0xffffffff))
-#define GET_32B_TO_63B(Addr) ((UINTN)RShiftU64((UINTN) Addr, 32) & (0xffffffff))
-
-
-//
-// Ehci Data and Ctrl Structures
-//
-#pragma pack(1)
-
-typedef struct {
- UINT8 PI;
- UINT8 SubClassCode;
- UINT8 BaseCode;
-} USB_CLASSC;
-
-//
-//32 Bytes Aligned
-//
-typedef struct {
- UINT32 NextQtdTerminate : 1;
- UINT32 Rsvd1 : 4;
- UINT32 NextQtdPointer : 27;
-
- UINT32 AltNextQtdTerminate : 1;
- UINT32 Rsvd2 : 4;
- UINT32 AltNextQtdPointer : 27;
-
- UINT32 Status : 8;
- UINT32 PidCode : 2;
- UINT32 ErrorCount : 2;
- UINT32 CurrentPage : 3;
- UINT32 InterruptOnComplete : 1;
- UINT32 TotalBytes : 15;
- UINT32 DataToggle : 1;
-
- UINT32 CurrentOffset : 12;
- UINT32 BufferPointer0 : 20;
-
- UINT32 Rsvd3 : 12;
- UINT32 BufferPointer1 : 20;
-
- UINT32 Rsvd4 : 12;
- UINT32 BufferPointer2 : 20;
-
- UINT32 Rsvd5 : 12;
- UINT32 BufferPointer3 : 20;
-
- UINT32 Rsvd6 : 12;
- UINT32 BufferPointer4 : 20;
-
- UINT32 PAD[5];
-} EHCI_QTD_HW;
-
-//
-//32 Bytes Aligned
-//
-typedef struct {
- UINT32 QhTerminate : 1;
- UINT32 SelectType : 2;
- UINT32 Rsvd1 : 2;
- UINT32 QhHorizontalPointer : 27;
-
- UINT32 DeviceAddr : 7;
- UINT32 Inactive : 1;
- UINT32 EndpointNum : 4;
- UINT32 EndpointSpeed : 2;
- UINT32 DataToggleControl : 1;
- UINT32 HeadReclamationFlag : 1;
- UINT32 MaxPacketLen : 11;
- UINT32 ControlEndpointFlag : 1;
- UINT32 NakCountReload : 4;
-
- UINT32 InerruptScheduleMask : 8;
- UINT32 SplitComletionMask : 8;
- UINT32 HubAddr : 7;
- UINT32 PortNum : 7;
- UINT32 Multiplier : 2;
-
- UINT32 Rsvd2 : 5;
- UINT32 CurrentQtdPointer : 27;
-
- UINT32 NextQtdTerminate : 1;
- UINT32 Rsvd3 : 4;
- UINT32 NextQtdPointer : 27;
-
- UINT32 AltNextQtdTerminate : 1;
- UINT32 NakCount : 4;
- UINT32 AltNextQtdPointer : 27;
-
- UINT32 Status : 8;
- UINT32 PidCode : 2;
- UINT32 ErrorCount : 2;
- UINT32 CurrentPage : 3;
- UINT32 InterruptOnComplete : 1;
- UINT32 TotalBytes : 15;
- UINT32 DataToggle : 1;
-
- UINT32 CurrentOffset : 12;
- UINT32 BufferPointer0 : 20;
-
- UINT32 CompleteSplitMask : 8;
- UINT32 Rsvd4 : 4;
- UINT32 BufferPointer1 : 20;
-
- UINT32 FrameTag : 5;
- UINT32 SplitBytes : 7;
- UINT32 BufferPointer2 : 20;
-
- UINT32 Rsvd5 : 12;
- UINT32 BufferPointer3 : 20;
-
- UINT32 Rsvd6 : 12;
- UINT32 BufferPointer4 : 20;
-
- UINT32 Pad[5];
-} EHCI_QH_HW;
-
-typedef struct {
- UINT32 LinkTerminate : 1;
- UINT32 SelectType : 2;
- UINT32 Rsvd : 2;
- UINT32 LinkPointer : 27;
-} FRAME_LIST_ENTRY;
-
-#pragma pack()
-
-typedef struct _EHCI_QTD_ENTITY EHCI_QTD_ENTITY;
-typedef struct _EHCI_QH_ENTITY EHCI_QH_ENTITY;
-typedef struct _EHCI_ASYNC_REQUEST EHCI_ASYNC_REQUEST;
-//
-//Aligan On 32 Bytes
-//
-struct _EHCI_QTD_ENTITY {
- EHCI_QTD_HW Qtd;
- UINT32 TotalBytes;
- UINT32 StaticTotalBytes;
- UINT32 StaticCurrentOffset;
- EHCI_QTD_ENTITY *Prev;
- EHCI_QTD_ENTITY *Next;
- EHCI_QTD_ENTITY *AltNext;
- EHCI_QH_ENTITY *SelfQh;
-};
-//
-//Aligan On 32 Bytes
-//
-struct _EHCI_QH_ENTITY {
- EHCI_QH_HW Qh;
- EHCI_QH_ENTITY *Next;
- EHCI_QH_ENTITY *Prev;
- EHCI_QTD_ENTITY *FirstQtdPtr;
- EHCI_QTD_ENTITY *LastQtdPtr;
- EHCI_QTD_ENTITY *AltQtdPtr;
- UINTN Interval;
- UINT8 TransferType;
-};
-
-#define GET_QH_ENTITY_ADDR(a) ((EHCI_QH_ENTITY *) a)
-#define GET_QTD_ENTITY_ADDR(a) ((EHCI_QTD_ENTITY *) a)
-
-
-//
-// Ehci Managment Structures
-//
-#define USB2_HC_DEV_FROM_THIS(a) CR (a, USB2_HC_DEV, Usb2Hc, USB2_HC_DEV_SIGNATURE)
-
-#define USB2_HC_DEV_SIGNATURE EFI_SIGNATURE_32 ('e', 'h', 'c', 'i')
-
-struct _EHCI_ASYNC_REQUEST {
- UINT8 TransferType;
- EFI_ASYNC_USB_TRANSFER_CALLBACK CallBackFunc;
- VOID *Context;
- EHCI_ASYNC_REQUEST *Prev;
- EHCI_ASYNC_REQUEST *Next;
- EHCI_QH_ENTITY *QhPtr;
-};
-
-typedef struct _MEMORY_MANAGE_HEADER {
- UINT8 *BitArrayPtr;
- UINTN BitArraySizeInBytes;
- UINT8 *MemoryBlockPtr;
- UINTN MemoryBlockSizeInBytes;
- VOID *Mapping;
- struct _MEMORY_MANAGE_HEADER *Next;
-} MEMORY_MANAGE_HEADER;
-
-typedef struct _USB2_HC_DEV {
- UINTN Signature;
- EFI_PCI_IO_PROTOCOL *PciIo;
- EFI_USB2_HC_PROTOCOL Usb2Hc;
- UINTN PeriodicFrameListLength;
- VOID *PeriodicFrameListBuffer;
- VOID *PeriodicFrameListMap;
- VOID *AsyncList;
- EHCI_ASYNC_REQUEST *AsyncRequestList;
- EFI_EVENT AsyncRequestEvent;
- EFI_UNICODE_STRING_TABLE *ControllerNameTable;
- MEMORY_MANAGE_HEADER *MemoryHeader;
- UINT8 Is64BitCapable;
- UINT32 High32BitAddr;
- EHCI_QH_ENTITY *NULLQH;
- UINT32 UsbCapabilityLen;
- UINT16 DeviceSpeed[16];
-} USB2_HC_DEV;
-
-
-//
-// Prototypes
-// Driver model protocol interface
-//
-
-EFI_STATUS
-EFIAPI
-EhciDriverBindingSupported (
- IN EFI_DRIVER_BINDING_PROTOCOL *This,
- IN EFI_HANDLE Controller,
- IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
- );
-
-EFI_STATUS
-EFIAPI
-EhciDriverBindingStart (
- IN EFI_DRIVER_BINDING_PROTOCOL *This,
- IN EFI_HANDLE Controller,
- IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
- );
-
-EFI_STATUS
-EFIAPI
-EhciDriverBindingStop (
- IN EFI_DRIVER_BINDING_PROTOCOL *This,
- IN EFI_HANDLE Controller,
- IN UINTN NumberOfChildren,
- IN EFI_HANDLE *ChildHandleBuffer
- );
-
-//
-// Ehci protocol interface
-//
-EFI_STATUS
-EFIAPI
-EhciGetCapability (
- IN EFI_USB2_HC_PROTOCOL *This,
- OUT UINT8 *MaxSpeed,
- OUT UINT8 *PortNumber,
- OUT UINT8 *Is64BitCapable
- );
-
-EFI_STATUS
-EFIAPI
-EhciReset (
- IN EFI_USB2_HC_PROTOCOL *This,
- IN UINT16 Attributes
- );
-
-EFI_STATUS
-EFIAPI
-EhciGetState (
- IN EFI_USB2_HC_PROTOCOL *This,
- OUT EFI_USB_HC_STATE *State
- );
-
-EFI_STATUS
-EFIAPI
-EhciSetState (
- IN EFI_USB2_HC_PROTOCOL *This,
- IN EFI_USB_HC_STATE State
- );
-
-EFI_STATUS
-EFIAPI
-EhciControlTransfer (
- 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
- );
-
-EFI_STATUS
-EFIAPI
-EhciBulkTransfer (
- 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_STATUS
-EFIAPI
-EhciAsyncInterruptTransfer (
- IN EFI_USB2_HC_PROTOCOL * This,
- IN UINT8 DeviceAddress,
- IN UINT8 EndPointAddress,
- IN UINT8 DeviceSpeed,
- IN UINTN MaxiumPacketLength,
- 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 OPTIONAL
- );
-
-EFI_STATUS
-EFIAPI
-EhciSyncInterruptTransfer (
- 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
-EFIAPI
-EhciIsochronousTransfer (
- 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
- );
-
-EFI_STATUS
-EFIAPI
-EhciAsyncIsochronousTransfer (
- 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
- );
-
-EFI_STATUS
-EFIAPI
-EhciGetRootHubPortStatus (
- IN EFI_USB2_HC_PROTOCOL *This,
- IN UINT8 PortNumber,
- OUT EFI_USB_PORT_STATUS *PortStatus
- );
-
-EFI_STATUS
-EFIAPI
-EhciSetRootHubPortFeature (
- IN EFI_USB2_HC_PROTOCOL *This,
- IN UINT8 PortNumber,
- IN EFI_USB_PORT_FEATURE PortFeature
- );
-
-EFI_STATUS
-EFIAPI
-EhciClearRootHubPortFeature (
- IN EFI_USB2_HC_PROTOCOL *This,
- IN UINT8 PortNumber,
- IN EFI_USB_PORT_FEATURE PortFeature
- );
-
-//
-// EFI Component Name Functions
-//
-EFI_STATUS
-EFIAPI
-EhciComponentNameGetDriverName (
- IN EFI_COMPONENT_NAME_PROTOCOL *This,
- IN CHAR8 *Language,
- OUT CHAR16 **DriverName
- );
-
-EFI_STATUS
-EFIAPI
-EhciComponentNameGetControllerName (
- IN EFI_COMPONENT_NAME_PROTOCOL *This,
- IN EFI_HANDLE ControllerHandle,
- IN EFI_HANDLE ChildHandle, OPTIONAL
- IN CHAR8 *Language,
- OUT CHAR16 **ControllerName
- );
-
-//
-// Internal Functions Declaration
-//
-
-//
-// EhciMem Functions
-//
-EFI_STATUS
-CreateMemoryBlock (
- IN USB2_HC_DEV *HcDev,
- OUT MEMORY_MANAGE_HEADER **MemoryHeader,
- IN UINTN MemoryBlockSizeInPages
- )
-/*++
-
-Routine Description:
-
- Use PciIo->AllocateBuffer to allocate common buffer for the memory block,
- and use PciIo->Map to map the common buffer for Bus Master Read/Write.
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- MemoryHeader - MEMORY_MANAGE_HEADER to output
- MemoryBlockSizeInPages - MemoryBlockSizeInPages
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_OUT_OF_RESOURCES Fail for no resources
- EFI_UNSUPPORTED Unsupported currently
-
---*/
-;
-
-EFI_STATUS
-FreeMemoryHeader (
- IN USB2_HC_DEV *HcDev,
- IN MEMORY_MANAGE_HEADER *MemoryHeader
- )
-/*++
-
-Routine Description:
-
- Free Memory Header
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- MemoryHeader - MemoryHeader to be freed
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_INVALID_PARAMETER Parameter is error
-
---*/
-;
-
-VOID
-InsertMemoryHeaderToList (
- IN MEMORY_MANAGE_HEADER *MemoryHeader,
- IN MEMORY_MANAGE_HEADER *NewMemoryHeader
- )
-/*++
-
-Routine Description:
-
- Insert Memory Header To List
-
-Arguments:
-
- MemoryHeader - MEMORY_MANAGE_HEADER
- NewMemoryHeader - MEMORY_MANAGE_HEADER
-
-Returns:
-
- VOID
-
---*/
-;
-
-EFI_STATUS
-AllocMemInMemoryBlock (
- IN MEMORY_MANAGE_HEADER *MemoryHeader,
- OUT VOID **Pool,
- IN UINTN NumberOfMemoryUnit
- )
-/*++
-
-Routine Description:
-
- Alloc Memory In MemoryBlock
-
-Arguments:
-
- MemoryHeader - MEMORY_MANAGE_HEADER
- Pool - Place to store pointer to memory
- NumberOfMemoryUnit - Number Of Memory Unit
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_NOT_FOUND Can't find the free memory
-
---*/
-;
-
-BOOLEAN
-IsMemoryBlockEmptied (
- IN MEMORY_MANAGE_HEADER *MemoryHeaderPtr
- )
-/*++
-
-Routine Description:
-
- Is Memory Block Emptied
-
-Arguments:
-
- MemoryHeaderPtr - MEMORY_MANAGE_HEADER
-
-Returns:
-
- TRUE Empty
- FALSE Not Empty
-
---*/
-;
-
-VOID
-DelinkMemoryBlock (
- IN MEMORY_MANAGE_HEADER *FirstMemoryHeader,
- IN MEMORY_MANAGE_HEADER *NeedFreeMemoryHeader
- )
-/*++
-
-Routine Description:
-
- Delink Memory Block
-
-Arguments:
-
- FirstMemoryHeader - MEMORY_MANAGE_HEADER
- NeedFreeMemoryHeader - MEMORY_MANAGE_HEADER
-
-Returns:
-
- VOID
-
---*/
-;
-
-EFI_STATUS
-InitialMemoryManagement (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Initialize Memory Management
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-;
-
-EFI_STATUS
-DeinitialMemoryManagement (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Deinitialize Memory Management
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-;
-
-EFI_STATUS
-EhciAllocatePool (
- IN USB2_HC_DEV *HcDev,
- OUT UINT8 **Pool,
- IN UINTN AllocSize
- )
-/*++
-
-Routine Description:
-
- Ehci Allocate Pool
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- Pool - Place to store pointer to the memory buffer
- AllocSize - Alloc Size
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-;
-
-VOID
-EhciFreePool (
- IN USB2_HC_DEV *HcDev,
- IN UINT8 *Pool,
- IN UINTN AllocSize
- )
-/*++
-
-Routine Description:
-
- Uhci Free Pool
-
-Arguments:
-
- HcDev - USB_HC_DEV
- Pool - Pool to free
- AllocSize - Pool size
-
-Returns:
-
- VOID
-
---*/
-;
-
-//
-// EhciReg Functions
-//
-EFI_STATUS
-ReadEhcCapabiltiyReg (
- IN USB2_HC_DEV *HcDev,
- IN UINT32 CapabiltiyRegAddr,
- IN OUT UINT32 *Data
- )
-/*++
-
-Routine Description:
-
- Read Ehc Capabitlity register
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- CapabiltiyRegAddr - Ehc Capability register address
- Data - A pointer to data read from register
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-;
-
-EFI_STATUS
-ReadEhcOperationalReg (
- IN USB2_HC_DEV *HcDev,
- IN UINT32 OperationalRegAddr,
- IN OUT UINT32 *Data
- )
-/*++
-
-Routine Description:
-
- Read Ehc Operation register
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- OperationalRegAddr - Ehc Operation register address
- Data - A pointer to data read from register
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-;
-
-EFI_STATUS
-WriteEhcOperationalReg (
- IN USB2_HC_DEV *HcDev,
- IN UINT32 OperationalRegAddr,
- IN UINT32 Data
- )
-/*++
-
-Routine Description:
-
- Write Ehc Operation register
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- OperationalRegAddr - Ehc Operation register address
- Data - 32bit write to register
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-;
-
-EFI_STATUS
-SetEhcDoorbell (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Set Ehc door bell bit
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-;
-
-EFI_STATUS
-SetFrameListLen (
- IN USB2_HC_DEV *HcDev,
- IN UINTN Length
- )
-/*++
-
-Routine Description:
-
- Set the length of Frame List
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- Length - the required length of frame list
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_INVALID_PARAMETER Invalid parameter
- EFI_DEVICE_ERROR Fail
-
---*/
-;
-
-BOOLEAN
-IsFrameListProgrammable (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Whether frame list is programmable
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- TRUE Programmable
- FALSE Unprogrammable
-
---*/
-;
-
-BOOLEAN
-IsPeriodicScheduleEnabled (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Whether periodic schedule is enabled
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- TRUE Enabled
- FALSE Disabled
-
---*/
-;
-
-BOOLEAN
-IsAsyncScheduleEnabled (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Whether asynchronous schedule is enabled
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- TRUE Enabled
- FALSE Disabled
-
---*/
-;
-
-BOOLEAN
-IsEhcPortEnabled (
- IN USB2_HC_DEV *HcDev,
- IN UINT8 PortNum
- )
-/*++
-
-Routine Description:
-
- Whether port is enabled
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- TRUE Enabled
- FALSE Disabled
-
---*/
-;
-
-BOOLEAN
-IsEhcReseted (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Whether Ehc is halted
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- TRUE Reseted
- FALSE Unreseted
-
---*/
-;
-
-BOOLEAN
-IsEhcHalted (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Whether Ehc is halted
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- TRUE Halted
- FALSE Not halted
-
---*/
-;
-
-BOOLEAN
-IsEhcSysError (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Whether Ehc is system error
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- TRUE System error
- FALSE No system error
-
---*/
-;
-
-BOOLEAN
-IsHighSpeedDevice (
- IN EFI_USB2_HC_PROTOCOL *This,
- IN UINT8 PortNum
- )
-/*++
-
-Routine Description:
-
- Whether high speed device attached
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- TRUE High speed
- FALSE Full speed
-
---*/
-;
-
-EFI_STATUS
-WaitForEhcReset (
- IN USB2_HC_DEV *HcDev,
- IN UINTN Timeout
- )
-/*++
-
-Routine Description:
-
- wait for Ehc reset or timeout
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- Timeout - timeout threshold
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_TIMEOUT Timeout
-
---*/
-;
-
-EFI_STATUS
-WaitForEhcHalt (
- IN USB2_HC_DEV *HcDev,
- IN UINTN Timeout
- )
-/*++
-
-Routine Description:
-
- wait for Ehc halt or timeout
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- Timeout - timeout threshold
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_TIMEOUT Timeout
-
---*/
-;
-
-EFI_STATUS
-WaitForEhcNotHalt (
- IN USB2_HC_DEV *HcDev,
- IN UINTN Timeout
- )
-/*++
-
-Routine Description:
-
- wait for Ehc not halt or timeout
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- Timeout - timeout threshold
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_TIMEOUT Timeout
-
---*/
-;
-
-EFI_STATUS
-WaitForEhcDoorbell (
- IN USB2_HC_DEV *HcDev,
- IN UINTN Timeout
- )
-/*++
-
-Routine Description:
-
- Wait for periodic schedule disable or timeout
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- Timeout - timeout threshold
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_TIMEOUT Timeout
-
---*/
-;
-
-EFI_STATUS
-WaitForAsyncScheduleEnable (
- IN USB2_HC_DEV *HcDev,
- IN UINTN Timeout
- )
-/*++
-
-Routine Description:
-
- Wait for Ehc asynchronous schedule enable or timeout
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- Timeout - timeout threshold
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_TIMEOUT Timeout
-
---*/
-;
-
-EFI_STATUS
-WaitForAsyncScheduleDisable (
- IN USB2_HC_DEV *HcDev,
- IN UINTN Timeout
- )
-/*++
-
-Routine Description:
-
- Wait for Ehc asynchronous schedule disable or timeout
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- Timeout - timeout threshold
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_TIMEOUT Timeout
-
---*/
-;
-
-EFI_STATUS
-WaitForPeriodicScheduleEnable (
- IN USB2_HC_DEV *HcDev,
- IN UINTN Timeout
- )
-/*++
-
-Routine Description:
-
- Wait for Ehc periodic schedule enable or timeout
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- Timeout - timeout threshold
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_TIMEOUT Timeout
-
---*/
-;
-
-EFI_STATUS
-WaitForPeriodicScheduleDisable (
- IN USB2_HC_DEV *HcDev,
- IN UINTN Timeout
- )
-/*++
-
-Routine Description:
-
- Wait for periodic schedule disable or timeout
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- Timeout - timeout threshold
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_TIMEOUT Timeout
-
---*/
-;
-
-EFI_STATUS
-GetCapabilityLen (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Get the length of capability register
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-;
-
-EFI_STATUS
-SetFrameListBaseAddr (
- IN USB2_HC_DEV *HcDev,
- IN UINT32 FrameBuffer
- )
-/*++
-
-Routine Description:
-
- Set base address of frame list first entry
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- FrameBuffer - base address of first entry of frame list
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-;
-
-EFI_STATUS
-SetAsyncListAddr (
- IN USB2_HC_DEV *HcDev,
- IN EHCI_QH_ENTITY *QhPtr
- )
-/*++
-
-Routine Description:
-
- Set address of first Async schedule Qh
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- QhPtr - A pointer to first Qh in the Async schedule
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-;
-
-EFI_STATUS
-SetCtrlDataStructSeg (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Set address of first Async schedule Qh
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- QhPtr - A pointer to first Qh in the Async schedule
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-;
-
-EFI_STATUS
-SetPortRoutingEhc (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Set Ehc port routing bit
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-;
-
-EFI_STATUS
-EnablePeriodicSchedule (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Enable periodic schedule
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-;
-
-EFI_STATUS
-DisablePeriodicSchedule (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Disable periodic schedule
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-;
-
-EFI_STATUS
-EnableAsynchronousSchedule (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Enable asynchrounous schedule
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-;
-
-EFI_STATUS
-DisableAsynchronousSchedule (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Disable asynchrounous schedule
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-;
-
-EFI_STATUS
-StartScheduleExecution (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Start Ehc schedule execution
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-;
-
-EFI_STATUS
-ResetEhc (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Reset Ehc
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-;
-
-EFI_STATUS
-ClearEhcAllStatus (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Clear Ehc all status bits
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-;
-
-//
-// EhciSched Functions
-//
-EFI_STATUS
-InitialPeriodicFrameList (
- IN USB2_HC_DEV *HcDev,
- IN UINTN Length
- )
-/*++
-
-Routine Description:
-
- Initialize Periodic Schedule Frame List
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- Length - Frame List Length
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-;
-
-VOID
-DeinitialPeriodicFrameList (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Deinitialize Periodic Schedule Frame List
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- VOID
-
---*/
-;
-
-EFI_STATUS
-CreatePollingTimer (
- IN USB2_HC_DEV *HcDev,
- IN EFI_EVENT_NOTIFY NotifyFunction
- )
-/*++
-
-Routine Description:
-
- Create Async Request Polling Timer
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- NotifyFunction - Timer Notify Function
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-;
-
-EFI_STATUS
-DestoryPollingTimer (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Destory Async Request Polling Timer
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-;
-
-EFI_STATUS
-StartPollingTimer (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Start Async Request Polling Timer
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-;
-
-EFI_STATUS
-StopPollingTimer (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Stop Async Request Polling Timer
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-;
-
-EFI_STATUS
-CreateQh (
- IN USB2_HC_DEV *HcDev,
- IN UINT8 DeviceAddr,
- IN UINT8 Endpoint,
- IN UINT8 DeviceSpeed,
- IN UINTN MaxPacketLen,
- OUT EHCI_QH_ENTITY **QhPtrPtr
- )
-/*++
-
-Routine Description:
-
- Create Qh Structure and Pre-Initialize
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- DeviceAddr - Address of Device
- Endpoint - Endpoint Number
- DeviceSpeed - Device Speed
- MaxPacketLen - Max Length of one Packet
- QhPtrPtr - A pointer of pointer to Qh for return
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-;
-
-EFI_STATUS
-CreateControlQh (
- IN USB2_HC_DEV *HcDev,
- IN UINT8 DeviceAddr,
- IN UINT8 DeviceSpeed,
- IN UINTN MaxPacketLen,
- IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator,
- OUT EHCI_QH_ENTITY **QhPtrPtr
- )
-/*++
-
-Routine Description:
-
- Create Qh for Control Transfer
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- DeviceAddr - Address of Device
- DeviceSpeed - Device Speed
- MaxPacketLen - Max Length of one Packet
- Translator - Translator Transaction for SplitX
- QhPtrPtr - A pointer of pointer to Qh for return
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-;
-
-EFI_STATUS
-CreateBulkQh (
- IN USB2_HC_DEV *HcDev,
- IN UINT8 DeviceAddr,
- IN UINT8 EndPointAddr,
- IN UINT8 DeviceSpeed,
- IN UINT8 DataToggle,
- IN UINTN MaxPacketLen,
- IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator,
- OUT EHCI_QH_ENTITY **QhPtrPtr
- )
-/*++
-
-Routine Description:
-
- Create Qh for Bulk Transfer
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- DeviceAddr - Address of Device
- EndPointAddr - Address of Endpoint
- DeviceSpeed - Device Speed
- MaxPacketLen - Max Length of one Packet
- Translator - Translator Transaction for SplitX
- QhPtrPtr - A pointer of pointer to Qh for return
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-;
-
-EFI_STATUS
-CreateInterruptQh (
- IN USB2_HC_DEV *HcDev,
- IN UINT8 DeviceAddr,
- IN UINT8 EndPointAddr,
- IN UINT8 DeviceSpeed,
- IN UINT8 DataToggle,
- IN UINTN MaxPacketLen,
- IN UINTN Interval,
- IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator,
- OUT EHCI_QH_ENTITY **QhPtrPtr
- )
-/*++
-
-Routine Description:
-
- Create Qh for Control Transfer
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- DeviceAddr - Address of Device
- EndPointAddr - Address of Endpoint
- DeviceSpeed - Device Speed
- MaxPacketLen - Max Length of one Packet
- Interval - value of interval
- Translator - Translator Transaction for SplitX
- QhPtrPtr - A pointer of pointer to Qh for return
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-;
-
-VOID
-DestoryQh (
- IN USB2_HC_DEV *HcDev,
- IN EHCI_QH_ENTITY *QhPtr
- )
-/*++
-
-Routine Description:
-
- Destory Qh Structure
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- QhPtr - A pointer to Qh
-
-Returns:
-
- VOID
-
---*/
-;
-
-EFI_STATUS
-CreateQtd (
- IN USB2_HC_DEV *HcDev,
- IN UINT8 *DataPtr,
- IN UINTN DataLen,
- IN UINT8 PktId,
- IN UINT8 Toggle,
- IN UINT8 QtdStatus,
- OUT EHCI_QTD_ENTITY **QtdPtrPtr
- )
-/*++
-
-Routine Description:
-
- Create Qtd Structure and Pre-Initialize it
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- DataPtr - A pointer to user data buffer to transfer
- DataLen - Length of user data to transfer
- PktId - Packet Identification of this Qtd
- Toggle - Data Toggle of this Qtd
- QtdStatus - Default value of status of this Qtd
- QtdPtrPtr - A pointer of pointer to Qtd for return
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_OUT_OF_RESOURCES Cannot allocate resources
-
---*/
-;
-
-EFI_STATUS
-CreateSetupQtd (
- IN USB2_HC_DEV *HcDev,
- IN UINT8 *DevReqPtr,
- OUT EHCI_QTD_ENTITY **QtdPtrPtr
- )
-/*++
-
-Routine Description:
-
- Create Qtd Structure for Setup
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- DevReqPtr - A pointer to Device Request Data
- QtdPtrPtr - A pointer of pointer to Qtd for return
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_OUT_OF_RESOURCES Cannot allocate resources
-
---*/
-;
-
-EFI_STATUS
-CreateDataQtd (
- IN USB2_HC_DEV *HcDev,
- IN UINT8 *DataPtr,
- IN UINTN DataLen,
- IN UINT8 PktId,
- IN UINT8 Toggle,
- OUT EHCI_QTD_ENTITY **QtdPtrPtr
- )
-/*++
-
-Routine Description:
-
- Create Qtd Structure for data
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- DataPtr - A pointer to user data buffer to transfer
- DataLen - Length of user data to transfer
- PktId - Packet Identification of this Qtd
- Toggle - Data Toggle of this Qtd
- QtdPtrPtr - A pointer of pointer to Qtd for return
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_OUT_OF_RESOURCES Cannot allocate resources
-
---*/
-;
-
-EFI_STATUS
-CreateStatusQtd (
- IN USB2_HC_DEV *HcDev,
- IN UINT8 PktId,
- OUT EHCI_QTD_ENTITY **QtdPtrPtr
- )
-/*++
-
-Routine Description:
-
- Create Qtd Structure for status
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- PktId - Packet Identification of this Qtd
- QtdPtrPtr - A pointer of pointer to Qtd for return
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_OUT_OF_RESOURCES Cannot allocate resources
-
---*/
-;
-
-EFI_STATUS
-CreateAltQtd (
- IN USB2_HC_DEV *HcDev,
- IN UINT8 PktId,
- OUT EHCI_QTD_ENTITY **QtdPtrPtr
- )
-/*++
-
-Routine Description:
-
- Create Qtd Structure for Alternative
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- PktId - Packet Identification of this Qtd
- QtdPtrPtr - A pointer of pointer to Qtd for return
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_OUT_OF_RESOURCES Cannot allocate resources
-
---*/
-;
-
-EFI_STATUS
-CreateControlQtds (
- IN USB2_HC_DEV *HcDev,
- IN UINT8 DataPktId,
- IN UINT8 *RequestCursor,
- IN UINT8 *DataCursor,
- IN UINTN DataLen,
- IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator,
- OUT EHCI_QTD_ENTITY **ControlQtdsHead
- )
-/*++
-
-Routine Description:
-
- Create Qtds list for Control Transfer
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- DataPktId - Packet Identification of Data Qtds
- RequestCursor - A pointer to request structure buffer to transfer
- DataCursor - A pointer to user data buffer to transfer
- DataLen - Length of user data to transfer
- ControlQtdsHead - A pointer of pointer to first Qtd for control tranfer for return
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-;
-
-EFI_STATUS
-CreateBulkOrInterruptQtds (
- IN USB2_HC_DEV *HcDev,
- IN UINT8 PktId,
- IN UINT8 *DataCursor,
- IN UINTN DataLen,
- IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator,
- OUT EHCI_QTD_ENTITY **QtdsHead
- )
-/*++
-
-Routine Description:
-
- Create Qtds list for Bulk or Interrupt Transfer
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- PktId - Packet Identification of Qtds
- DataCursor - A pointer to user data buffer to transfer
- DataLen - Length of user data to transfer
- DataToggle - Data Toggle to start
- Translator - Translator Transaction for SplitX
- QtdsHead - A pointer of pointer to first Qtd for control tranfer for return
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-;
-
-VOID
-DestoryQtds (
- IN USB2_HC_DEV *HcDev,
- IN EHCI_QTD_ENTITY *FirstQtdPtr
- )
-/*++
-
-Routine Description:
-
- Destory all Qtds in the list
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- FirstQtdPtr - A pointer to first Qtd in the list
-
-Returns:
-
- VOID
-
---*/
-;
-
-VOID
-LinkQtdToQtd (
- IN EHCI_QTD_ENTITY *PreQtdPtr,
- IN EHCI_QTD_ENTITY *QtdPtr
- )
-/*++
-
-Routine Description:
-
- Link Qtds together
-
-Arguments:
-
- PreQtdPtr - A pointer to pre Qtd
- QtdPtr - A pointer to next Qtd
-
-Returns:
-
- VOID
-
---*/
-;
-
-VOID
-LinkQtdsToAltQtd (
- IN EHCI_QTD_ENTITY *FirstQtdPtr,
- IN EHCI_QTD_ENTITY *AltQtdPtr
- )
-/*++
-
-Routine Description:
-
- Link AlterQtds together
-
-Arguments:
-
- FirstQtdPtr - A pointer to first Qtd in the list
- AltQtdPtr - A pointer to alternative Qtd
-
-Returns:
- VOID
-
---*/
-;
-
-VOID
-LinkQtdToQh (
- IN EHCI_QH_ENTITY *QhPtr,
- IN EHCI_QTD_ENTITY *QtdEntryPtr
- )
-/*++
-
-Routine Description:
-
- Link Qtds list to Qh
-
-Arguments:
-
- QhPtr - A pointer to Qh
- QtdPtr - A pointer to first Qtd in the list
-
-Returns:
-
- VOID
-
---*/
-;
-
-EFI_STATUS
-LinkQhToAsyncList (
- IN USB2_HC_DEV *HcDev,
- IN EHCI_QH_ENTITY *QhPtr
- )
-/*++
-
-Routine Description:
-
- Link Qh to Async Schedule List
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- QhPtr - A pointer to Qh
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-;
-
-EFI_STATUS
-UnlinkQhFromAsyncList (
- IN USB2_HC_DEV *HcDev,
- IN EHCI_QH_ENTITY *QhPtr
- )
-/*++
-
-Routine Description:
-
- Unlink Qh from Async Schedule List
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- QhPtr - A pointer to Qh
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-;
-
-VOID
-LinkQhToPeriodicList (
- IN USB2_HC_DEV *HcDev,
- IN EHCI_QH_ENTITY *QhPtr
- )
-/*++
-
-Routine Description:
-
- Link Qh to Periodic Schedule List
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- QhPtr - A pointer to Qh
-
-Returns:
-
- VOID
-
---*/
-;
-
-VOID
-UnlinkQhFromPeriodicList (
- IN USB2_HC_DEV *HcDev,
- IN EHCI_QH_ENTITY *QhPtr,
- IN UINTN Interval
- )
-/*++
-
-Routine Description:
-
- Unlink Qh from Periodic Schedule List
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- QhPtr - A pointer to Qh
- Interval - Interval of this periodic transfer
-
-Returns:
-
- VOID
-
---*/
-;
-
-VOID
-LinkToAsyncReqeust (
- IN USB2_HC_DEV *HcDev,
- IN EHCI_ASYNC_REQUEST *AsyncRequestPtr
- )
-/*++
-
-Routine Description:
-
- Llink AsyncRequest Entry to Async Request List
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- AsyncRequestPtr - A pointer to Async Request Entry
-
-Returns:
-
- VOID
-
---*/
-;
-
-VOID
-UnlinkFromAsyncReqeust (
- IN USB2_HC_DEV *HcDev,
- IN EHCI_ASYNC_REQUEST *AsyncRequestPtr
- )
-/*++
-
-Routine Description:
-
- Unlink AsyncRequest Entry from Async Request List
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- AsyncRequestPtr - A pointer to Async Request Entry
-
-Returns:
-
- VOID
-
---*/
-;
-
-UINTN
-GetNumberOfQtd (
- IN EHCI_QTD_ENTITY *FirstQtdPtr
- )
-/*++
-
-Routine Description:
-
- Number of Qtds in the list
-
-Arguments:
-
- FirstQtdPtr - A pointer to first Qtd in the list
-
-Returns:
-
- Number of Qtds in the list
-
---*/
-;
-
-
-
-UINTN
-GetCapacityOfQtd (
- IN UINT8 *BufferCursor
- )
-/*++
-
-Routine Description:
-
- Get Capacity of Qtd
-
-Arguments:
-
- BufferCursor - BufferCursor of the Qtd
-
-Returns:
-
- Capacity of Qtd
-
---*/
-;
-
-UINTN
-GetApproxiOfInterval (
- IN UINTN Interval
- )
-/*++
-
-Routine Description:
-
- Get the approximate value in the 2 index sequence
-
-Arguments:
-
- Interval - the value of interval
-
-Returns:
-
- approximate value of interval in the 2 index sequence
-
---*/
-;
-
-EHCI_QTD_HW *
-GetQtdNextPointer (
- IN EHCI_QTD_HW *HwQtdPtr
- )
-/*++
-
-Routine Description:
-
- Get Qtd next pointer field
-
-Arguments:
-
- HwQtdPtr - A pointer to hardware Qtd structure
-
-Returns:
-
- A pointer to next hardware Qtd structure
-
---*/
-;
-
-BOOLEAN
-IsQtdStatusActive (
- IN EHCI_QTD_HW *HwQtdPtr
- )
-/*++
-
-Routine Description:
-
- Whether Qtd status is active or not
-
-Arguments:
-
- HwQtdPtr - A pointer to hardware Qtd structure
-
-Returns:
-
- TRUE Active
- FALSE Inactive
-
---*/
-;
-
-BOOLEAN
-IsQtdStatusHalted (
- IN EHCI_QTD_HW *HwQtdPtr
- )
-/*++
-
-Routine Description:
-
- Whether Qtd status is halted or not
-
-Arguments:
-
- HwQtdPtr - A pointer to hardware Qtd structure
-
-Returns:
-
- TRUE Halted
- FALSE Not halted
-
---*/
-;
-
-BOOLEAN
-IsQtdStatusBufferError (
- IN EHCI_QTD_HW *HwQtdPtr
- )
-/*++
-
-Routine Description:
-
- Whether Qtd status is buffer error or not
-
-Arguments:
-
- HwQtdPtr - A pointer to hardware Qtd structure
-
-Returns:
-
- TRUE Buffer error
- FALSE No buffer error
-
---*/
-;
-
-BOOLEAN
-IsQtdStatusBabbleError (
- IN EHCI_QTD_HW *HwQtdPtr
- )
-/*++
-
-Routine Description:
-
- Whether Qtd status is babble error or not
-
-Arguments:
-
- HwQtdPtr - A pointer to hardware Qtd structure
-
-Returns:
-
- TRUE Babble error
- FALSE No babble error
-
---*/
-;
-
-BOOLEAN
-IsQtdStatusTransactionError (
- IN EHCI_QTD_HW *HwQtdPtr
- )
-/*++
-
-Routine Description:
-
- Whether Qtd status is transaction error or not
-
-Arguments:
-
- HwQtdPtr - A pointer to hardware Qtd structure
-
-Returns:
-
- TRUE Transaction error
- FALSE No transaction error
-
---*/
-;
-
-BOOLEAN
-IsDataInTransfer (
- IN UINT8 EndPointAddress
- )
-/*++
-
-Routine Description:
-
- Whether is a DataIn direction transfer
-
-Arguments:
-
- EndPointAddress - address of the endpoint
-
-Returns:
-
- TRUE DataIn
- FALSE DataOut
-
---*/
-;
-
-EFI_STATUS
-MapDataBuffer (
- IN USB2_HC_DEV *HcDev,
- IN EFI_USB_DATA_DIRECTION TransferDirection,
- IN OUT VOID *Data,
- IN OUT UINTN *DataLength,
- OUT UINT8 *PktId,
- OUT UINT8 **DataCursor,
- OUT VOID **DataMap
- )
-/*++
-
-Routine Description:
-
- Map address of user data buffer
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- TransferDirection - direction of transfer
- Data - A pointer to user data buffer
- DataLength - length of user data
- PktId - Packte Identificaion
- DataCursor - mapped address to return
- DataMap - identificaion of this mapping to return
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-;
-
-EFI_STATUS
-MapRequestBuffer (
- IN USB2_HC_DEV *HcDev,
- IN OUT VOID *Request,
- OUT UINT8 **RequestCursor,
- OUT VOID **RequestMap
- )
-/*++
-
-Routine Description:
-
- Map address of request structure buffer
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- Request - A pointer to request structure
- RequestCursor - Mapped address of request structure to return
- RequestMap - Identificaion of this mapping to return
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-;
-
-VOID
-SetQtdBufferPointer (
- IN EHCI_QTD_HW *QtdHwPtr,
- IN VOID *DataPtr,
- IN UINTN DataLen
- )
-/*++
-
-Routine Description:
-
- Set data buffer pointers in Qtd
-
-Arguments:
-
- QtdHwPtr - A pointer to Qtd hardware structure
- DataPtr - A pointer to user data buffer
- DataLen - Length of the user data buffer
-
-Returns:
-
- VOID
-
---*/
-;
-
-EHCI_QTD_HW *
-GetQtdAlternateNextPointer (
- IN EHCI_QTD_HW *HwQtdPtr
- )
-/*++
-
-Routine Description:
-
- Get Qtd alternate next pointer field
-
-Arguments:
-
- HwQtdPtr - A pointer to hardware Qtd structure
-
-Returns:
-
- A pointer to hardware alternate Qtd
-
---*/
-;
-
-VOID
-ZeroOutQhOverlay (
- IN EHCI_QH_ENTITY *QhPtr
- )
-/*++
-
-Routine Description:
-
- Zero out the fields in Qh structure
-
-Arguments:
-
- QhPtr - A pointer to Qh structure
-
-Returns:
-
- VOID
-
---*/
-;
-
-VOID
-UpdateAsyncRequestTransfer (
- IN EHCI_ASYNC_REQUEST *AsyncRequestPtr,
- IN UINT32 TransferResult,
- IN UINTN ErrTDPos
- )
-/*++
-
-Routine Description:
-
- Update asynchronous request transfer
-
-Arguments:
-
- AsyncRequestPtr - A pointer to async request
- TransferResult - transfer result
- ErrQtdPos - postion of error Qtd
-
-Returns:
-
- VOID
-
---*/
-;
-
-
-EFI_STATUS
-DeleteAsyncRequestTransfer (
- IN USB2_HC_DEV *HcDev,
- IN UINT8 DeviceAddress,
- IN UINT8 EndPointAddress,
- OUT UINT8 *DataToggle
- )
-/*++
-
-Routine Description:
-
- Delete all asynchronous request transfer
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- DeviceAddress - address of usb device
- EndPointAddress - address of endpoint
- DataToggle - stored data toggle
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-;
-
-VOID
-CleanUpAllAsyncRequestTransfer (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Clean up all asynchronous request transfer
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
- VOID
-
---*/
-;
-
-EFI_STATUS
-ExecuteTransfer (
- IN USB2_HC_DEV *HcDev,
- IN BOOLEAN IsControl,
- IN EHCI_QH_ENTITY *QhPtr,
- IN OUT UINTN *ActualLen,
- OUT UINT8 *DataToggle,
- IN UINTN TimeOut,
- OUT UINT32 *TransferResult
- )
-/*++
-
-Routine Description:
-
- Execute Bulk or SyncInterrupt Transfer
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- IsControl - Is control transfer or not
- QhPtr - A pointer to Qh
- ActualLen - Actual transfered Len
- DataToggle - Data Toggle
- TimeOut - TimeOut threshold
- TransferResult - Transfer result
-
-Returns:
-
- EFI_SUCCESS Sucess
- EFI_DEVICE_ERROR Error
-
---*/
-;
-
-BOOLEAN
-CheckQtdsTransferResult (
- IN BOOLEAN IsControl,
- IN EHCI_QH_ENTITY *QhPtr,
- OUT UINT32 *Result,
- OUT UINTN *ErrQtdPos,
- OUT UINTN *ActualLen
- )
-/*++
-
-Routine Description:
-
- Check transfer result of Qtds
-
-Arguments:
-
- IsControl - Is control transfer or not
- QhPtr - A pointer to Qh
- Result - Transfer result
- ErrQtdPos - Error TD Position
- ActualLen - Actual Transfer Size
-
-Returns:
-
- TRUE Qtds finished
- FALSE Not finish
-
---*/
-;
-
-EFI_STATUS
-AsyncRequestMoniter (
- IN EFI_EVENT Event,
- IN VOID *Context
- )
-/*++
-
-Routine Description:
-
- Interrupt transfer periodic check handler
-
-Arguments:
-
- Event - Interrupt event
- Context - Pointer to USB2_HC_DEV
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-;
-
-
-EFI_STATUS
-CreateNULLQH (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Create the NULL QH to make it as the Async QH header
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- EFI_SUCCESS Success
---*/
-;
-
-VOID
-DestroyNULLQH (
- IN USB2_HC_DEV *HcDev
- );
-
-VOID
-ClearLegacySupport (
- IN USB2_HC_DEV *HcDev
- );
-
-VOID
-HostReset (
- IN USB2_HC_DEV *HcDev
- );
-
-
-VOID
-DumpEHCIPortsStatus (
- IN USB2_HC_DEV *HcDev
- );
-
-
-#endif
diff --git a/EdkModulePkg/Bus/Pci/Ehci/Dxe/Ehci.msa b/EdkModulePkg/Bus/Pci/Ehci/Dxe/Ehci.msa
deleted file mode 100644
index 9e71d0e970..0000000000
--- a/EdkModulePkg/Bus/Pci/Ehci/Dxe/Ehci.msa
+++ /dev/null
@@ -1,78 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <MsaHeader>
- <ModuleName>Ehci</ModuleName>
- <ModuleType>UEFI_DRIVER</ModuleType>
- <GuidValue>BDFE430E-8F2A-4db0-9991-6F856594777E</GuidValue>
- <Version>1.0</Version>
- <Abstract>Component description file for Ehci module</Abstract>
- <Description>This module provides USB2 Host Controller Protocol implementation for Enhanced Host Controller Interface</Description>
- <Copyright>Copyright (c) 2006 - 2007, Intel Corporation</Copyright>
- <License>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
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.</License>
- <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052</Specification>
- </MsaHeader>
- <ModuleDefinitions>
- <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>
- <BinaryModule>false</BinaryModule>
- <OutputFileBasename>Ehci</OutputFileBasename>
- </ModuleDefinitions>
- <LibraryClassDefinitions>
- <LibraryClass Usage="ALWAYS_CONSUMED">
- <Keyword>DebugLib</Keyword>
- </LibraryClass>
- <LibraryClass Usage="ALWAYS_CONSUMED">
- <Keyword>UefiDriverModelLib</Keyword>
- </LibraryClass>
- <LibraryClass Usage="ALWAYS_CONSUMED">
- <Keyword>UefiDriverEntryPoint</Keyword>
- </LibraryClass>
- <LibraryClass Usage="ALWAYS_CONSUMED">
- <Keyword>BaseLib</Keyword>
- </LibraryClass>
- <LibraryClass Usage="ALWAYS_CONSUMED">
- <Keyword>UefiLib</Keyword>
- </LibraryClass>
- <LibraryClass Usage="ALWAYS_CONSUMED">
- <Keyword>BaseMemoryLib</Keyword>
- </LibraryClass>
- <LibraryClass Usage="ALWAYS_CONSUMED">
- <Keyword>MemoryAllocationLib</Keyword>
- </LibraryClass>
- <LibraryClass Usage="ALWAYS_CONSUMED">
- <Keyword>UefiBootServicesTableLib</Keyword>
- </LibraryClass>
- </LibraryClassDefinitions>
- <SourceFiles>
- <Filename>Ehci.c</Filename>
- <Filename>Debug.c</Filename>
- <Filename>EhciMem.c</Filename>
- <Filename>EhciReg.c</Filename>
- <Filename>EhciSched.c</Filename>
- <Filename>ComponentName.c</Filename>
- <Filename>Ehci.h</Filename>
- </SourceFiles>
- <PackageDependencies>
- <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>
- </PackageDependencies>
- <Protocols>
- <Protocol Usage="TO_START">
- <ProtocolCName>gEfiPciIoProtocolGuid</ProtocolCName>
- </Protocol>
- <Protocol Usage="BY_START">
- <ProtocolCName>gEfiUsb2HcProtocolGuid</ProtocolCName>
- </Protocol>
- </Protocols>
- <Externs>
- <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
- <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
- <Extern>
- <DriverBinding>gEhciDriverBinding</DriverBinding>
- <ComponentName>gEhciComponentName</ComponentName>
- </Extern>
- </Externs>
-</ModuleSurfaceArea> \ No newline at end of file
diff --git a/EdkModulePkg/Bus/Pci/Ehci/Dxe/EhciMem.c b/EdkModulePkg/Bus/Pci/Ehci/Dxe/EhciMem.c
deleted file mode 100644
index db7412b938..0000000000
--- a/EdkModulePkg/Bus/Pci/Ehci/Dxe/EhciMem.c
+++ /dev/null
@@ -1,771 +0,0 @@
-/*++
-
-Copyright (c) 2006, 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
-
-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:
-
- EhciMem.c
-
-Abstract:
-
-
-Revision History
---*/
-
-#include "Ehci.h"
-
-
-EFI_STATUS
-CreateMemoryBlock (
- IN USB2_HC_DEV *HcDev,
- OUT MEMORY_MANAGE_HEADER **MemoryHeader,
- IN UINTN MemoryBlockSizeInPages
- )
-/*++
-
-Routine Description:
-
- Use PciIo->AllocateBuffer to allocate common buffer for the memory block,
- and use PciIo->Map to map the common buffer for Bus Master Read/Write.
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- MemoryHeader - MEMORY_MANAGE_HEADER to output
- MemoryBlockSizeInPages - MemoryBlockSizeInPages
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_OUT_OF_RESOURCES Fail for no resources
- EFI_UNSUPPORTED Unsupported currently
-
---*/
-{
- EFI_STATUS Status;
- VOID *CommonBuffer;
- EFI_PHYSICAL_ADDRESS MappedAddress;
- UINTN MemoryBlockSizeInBytes;
- VOID *Mapping;
-
- //
- // Allocate memory for MemoryHeader
- //
- *MemoryHeader = AllocateZeroPool (sizeof (MEMORY_MANAGE_HEADER));
- if (*MemoryHeader == NULL) {
- return EFI_OUT_OF_RESOURCES;
- }
-
- (*MemoryHeader)->Next = NULL;
-
- //
- // set Memory block size
- //
- (*MemoryHeader)->MemoryBlockSizeInBytes = EFI_PAGES_TO_SIZE (MemoryBlockSizeInPages);
-
- //
- // each bit in Bit Array will manage 32 bytes memory in memory block
- //
- (*MemoryHeader)->BitArraySizeInBytes = ((*MemoryHeader)->MemoryBlockSizeInBytes / MEM_UNIT_SIZE) / 8;
-
- //
- // Allocate memory for BitArray
- //
- (*MemoryHeader)->BitArrayPtr = AllocateZeroPool ((*MemoryHeader)->BitArraySizeInBytes);
- if ((*MemoryHeader)->BitArrayPtr == NULL) {
- gBS->FreePool (*MemoryHeader);
- return EFI_OUT_OF_RESOURCES;
- }
-
- //
- // Memory Block uses MemoryBlockSizeInPages pages,
- // and it is allocated as common buffer use.
- //
- Status = HcDev->PciIo->AllocateBuffer (
- HcDev->PciIo,
- AllocateAnyPages,
- EfiBootServicesData,
- MemoryBlockSizeInPages,
- &CommonBuffer,
- 0
- );
- if (EFI_ERROR (Status)) {
- gBS->FreePool ((*MemoryHeader)->BitArrayPtr);
- gBS->FreePool (*MemoryHeader);
- return EFI_OUT_OF_RESOURCES;
- }
-
- MemoryBlockSizeInBytes = EFI_PAGES_TO_SIZE (MemoryBlockSizeInPages);
- Status = HcDev->PciIo->Map (
- HcDev->PciIo,
- EfiPciIoOperationBusMasterCommonBuffer,
- CommonBuffer,
- &MemoryBlockSizeInBytes,
- &MappedAddress,
- &Mapping
- );
- //
- // If returned Mapped size is less than the size
- // we request,do not support.
- //
- if (EFI_ERROR (Status) || (MemoryBlockSizeInBytes != EFI_PAGES_TO_SIZE (MemoryBlockSizeInPages))) {
- HcDev->PciIo->FreeBuffer (HcDev->PciIo, MemoryBlockSizeInPages, CommonBuffer);
- gBS->FreePool ((*MemoryHeader)->BitArrayPtr);
- gBS->FreePool (*MemoryHeader);
- return EFI_UNSUPPORTED;
- }
-
- //
- // Data structure involved by host controller
- // should be restricted into the same 4G
- //
- if (HcDev->Is64BitCapable != 0) {
- if (HcDev->High32BitAddr != GET_32B_TO_63B (MappedAddress)) {
- HcDev->PciIo->Unmap (HcDev->PciIo, Mapping);
- HcDev->PciIo->FreeBuffer (HcDev->PciIo, MemoryBlockSizeInPages, CommonBuffer);
- gBS->FreePool ((*MemoryHeader)->BitArrayPtr);
- gBS->FreePool (*MemoryHeader);
- return EFI_UNSUPPORTED;
- }
- }
-
- //
- // Set Memory block initial address
- //
- (*MemoryHeader)->MemoryBlockPtr = (UINT8 *) ((UINTN) MappedAddress);
- (*MemoryHeader)->Mapping = Mapping;
-
- ZeroMem (
- (*MemoryHeader)->MemoryBlockPtr,
- EFI_PAGES_TO_SIZE (MemoryBlockSizeInPages)
- );
-
- return EFI_SUCCESS;
-}
-
-EFI_STATUS
-FreeMemoryHeader (
- IN USB2_HC_DEV *HcDev,
- IN MEMORY_MANAGE_HEADER *MemoryHeader
- )
-/*++
-
-Routine Description:
-
- Free Memory Header
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- MemoryHeader - MemoryHeader to be freed
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_INVALID_PARAMETER Parameter is error
-
---*/
-{
- if ((MemoryHeader == NULL) || (HcDev == NULL)) {
- return EFI_INVALID_PARAMETER;
- }
- //
- // unmap the common buffer used by the memory block
- //
- HcDev->PciIo->Unmap (HcDev->PciIo, MemoryHeader->Mapping);
-
- //
- // free common buffer
- //
- HcDev->PciIo->FreeBuffer (
- HcDev->PciIo,
- EFI_SIZE_TO_PAGES (MemoryHeader->MemoryBlockSizeInBytes),
- MemoryHeader->MemoryBlockPtr
- );
- //
- // free bit array
- //
- gBS->FreePool (MemoryHeader->BitArrayPtr);
- //
- // free memory header
- //
- gBS->FreePool (MemoryHeader);
-
- return EFI_SUCCESS;
-}
-
-EFI_STATUS
-EhciAllocatePool (
- IN USB2_HC_DEV *HcDev,
- OUT UINT8 **Pool,
- IN UINTN AllocSize
- )
-/*++
-
-Routine Description:
-
- Ehci Allocate Pool
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- Pool - Place to store pointer to the memory buffer
- AllocSize - Alloc Size
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-{
- MEMORY_MANAGE_HEADER *MemoryHeader;
- MEMORY_MANAGE_HEADER *TempHeaderPtr;
- MEMORY_MANAGE_HEADER *NewMemoryHeader;
- UINTN RealAllocSize;
- UINTN MemoryBlockSizeInPages;
- EFI_STATUS Status;
- EFI_TPL OldTpl;
-
- *Pool = NULL;
-
- MemoryHeader = HcDev->MemoryHeader;
- ASSERT (MemoryHeader != NULL);
-
- OldTpl = gBS->RaiseTPL (TPL_NOTIFY + 1);
-
- //
- // allocate unit is 32 bytes (align on 32 byte)
- //
- if (AllocSize & (MEM_UNIT_SIZE - 1)) {
- RealAllocSize = (AllocSize / MEM_UNIT_SIZE + 1) * MEM_UNIT_SIZE;
- } else {
- RealAllocSize = AllocSize;
- }
-
- //
- // There may be linked MemoryHeaders.
- // To allocate a free pool in Memory blocks,
- // must search in the MemoryHeader link list
- // until enough free pool is found.
- //
- Status = EFI_NOT_FOUND;
- for (TempHeaderPtr = MemoryHeader; TempHeaderPtr != NULL; TempHeaderPtr = TempHeaderPtr->Next) {
-
- Status = AllocMemInMemoryBlock (
- TempHeaderPtr,
- (VOID **) Pool,
- RealAllocSize / MEM_UNIT_SIZE
- );
- if (!EFI_ERROR (Status)) {
- break;
- }
- }
-
- gBS->RestoreTPL (OldTpl);
-
- if (!EFI_ERROR (Status)) {
- ZeroMem (*Pool, AllocSize);
- return EFI_SUCCESS;
- }
-
-
- //
- // There is no enough memory,
- // Create a new Memory Block
- //
-
- //
- // if pool size is larger than NORMAL_MEMORY_BLOCK_UNIT_IN_PAGES,
- // just allocate a large enough memory block.
- //
- if (RealAllocSize > EFI_PAGES_TO_SIZE (NORMAL_MEMORY_BLOCK_UNIT_IN_PAGES)) {
- MemoryBlockSizeInPages = EFI_SIZE_TO_PAGES (RealAllocSize) + 1;
- } else {
- MemoryBlockSizeInPages = NORMAL_MEMORY_BLOCK_UNIT_IN_PAGES;
- }
-
- Status = CreateMemoryBlock (HcDev, &NewMemoryHeader, MemoryBlockSizeInPages);
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- OldTpl = gBS->RaiseTPL (TPL_NOTIFY + 1);
-
- //
- // Link the new Memory Block to the Memory Header list
- //
- InsertMemoryHeaderToList (MemoryHeader, NewMemoryHeader);
-
- Status = AllocMemInMemoryBlock (
- NewMemoryHeader,
- (VOID **) Pool,
- RealAllocSize / MEM_UNIT_SIZE
- );
-
- gBS->RestoreTPL (OldTpl);
-
- if (!EFI_ERROR (Status)) {
- ZeroMem (*Pool, AllocSize);
- }
-
- return Status;
-}
-
-VOID
-EhciFreePool (
- IN USB2_HC_DEV *HcDev,
- IN UINT8 *Pool,
- IN UINTN AllocSize
- )
-/*++
-
-Routine Description:
-
- Uhci Free Pool
-
-Arguments:
-
- HcDev - USB_HC_DEV
- Pool - Pool to free
- AllocSize - Pool size
-
-Returns:
-
- VOID
-
---*/
-{
- MEMORY_MANAGE_HEADER *MemoryHeader;
- MEMORY_MANAGE_HEADER *TempHeaderPtr;
- UINTN StartBytePos;
- UINTN Index;
- UINT8 StartBitPos;
- UINT8 Index2;
- UINTN Count;
- UINTN RealAllocSize;
- EFI_TPL OldTpl;
-
- OldTpl = gBS->RaiseTPL (TPL_NOTIFY + 1);
-
- MemoryHeader = HcDev->MemoryHeader;
-
- //
- // allocate unit is 32 byte (align on 32 byte)
- //
- if (AllocSize & (MEM_UNIT_SIZE - 1)) {
- RealAllocSize = (AllocSize / MEM_UNIT_SIZE + 1) * MEM_UNIT_SIZE;
- } else {
- RealAllocSize = AllocSize;
- }
-
- //
- // scan the memory header linked list for
- // the asigned memory to free.
- //
- for (TempHeaderPtr = MemoryHeader; TempHeaderPtr != NULL; TempHeaderPtr = TempHeaderPtr->Next) {
-
- if ((Pool >= TempHeaderPtr->MemoryBlockPtr) &&
- ((Pool + RealAllocSize) <= (TempHeaderPtr->MemoryBlockPtr + TempHeaderPtr->MemoryBlockSizeInBytes))
- ) {
- //
- // Pool is in the Memory Block area,
- // find the start byte and bit in the bit array
- //
- StartBytePos = ((Pool - TempHeaderPtr->MemoryBlockPtr) / MEM_UNIT_SIZE) / 8;
- StartBitPos = (UINT8) (((Pool - TempHeaderPtr->MemoryBlockPtr) / MEM_UNIT_SIZE) & 0x7);
-
- //
- // reset associated bits in bit arry
- //
- for (Index = StartBytePos, Index2 = StartBitPos, Count = 0; Count < (RealAllocSize / MEM_UNIT_SIZE); Count++) {
- ASSERT ((TempHeaderPtr->BitArrayPtr[Index] & bit (Index2) )== bit (Index2));
-
- TempHeaderPtr->BitArrayPtr[Index] = (UINT8) (TempHeaderPtr->BitArrayPtr[Index] ^ (bit (Index2)));
- Index2++;
- if (Index2 == 8) {
- Index += 1;
- Index2 = 0;
- }
- }
- //
- // break the loop
- //
- break;
- }
- }
-
- //
- // Release emptied memory blocks (only if the memory block is not
- // the first one in the memory header list
- //
- for (TempHeaderPtr = MemoryHeader->Next; TempHeaderPtr != NULL;) {
-
- ASSERT (MemoryHeader->Next != NULL);
-
- if (IsMemoryBlockEmptied (TempHeaderPtr)) {
-
- DelinkMemoryBlock (MemoryHeader, TempHeaderPtr);
- //
- // when the TempHeaderPtr is freed in FreeMemoryHeader(),
- // the TempHeaderPtr is pointing to nonsense content.
- //
- gBS->RestoreTPL (OldTpl);
- FreeMemoryHeader (HcDev, TempHeaderPtr);
- OldTpl = gBS->RaiseTPL (TPL_NOTIFY + 1);
- //
- // reset the TempHeaderPtr, continue search for
- // another empty memory block.
- //
- TempHeaderPtr = MemoryHeader->Next;
- continue;
- }
-
- TempHeaderPtr = TempHeaderPtr->Next;
- }
-
- gBS->RestoreTPL (OldTpl);
-}
-
-VOID
-InsertMemoryHeaderToList (
- IN MEMORY_MANAGE_HEADER *MemoryHeader,
- IN MEMORY_MANAGE_HEADER *NewMemoryHeader
- )
-/*++
-
-Routine Description:
-
- Insert Memory Header To List
-
-Arguments:
-
- MemoryHeader - MEMORY_MANAGE_HEADER
- NewMemoryHeader - MEMORY_MANAGE_HEADER
-
-Returns:
-
- VOID
-
---*/
-{
- MEMORY_MANAGE_HEADER *TempHeaderPtr;
-
- for (TempHeaderPtr = MemoryHeader; TempHeaderPtr != NULL; TempHeaderPtr = TempHeaderPtr->Next) {
- if (TempHeaderPtr->Next == NULL) {
- TempHeaderPtr->Next = NewMemoryHeader;
- break;
- }
- }
-}
-
-EFI_STATUS
-AllocMemInMemoryBlock (
- IN MEMORY_MANAGE_HEADER *MemoryHeader,
- OUT VOID **Pool,
- IN UINTN NumberOfMemoryUnit
- )
-/*++
-
-Routine Description:
-
- Alloc Memory In MemoryBlock
-
-Arguments:
-
- MemoryHeader - MEMORY_MANAGE_HEADER
- Pool - Place to store pointer to memory
- NumberOfMemoryUnit - Number Of Memory Unit
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_NOT_FOUND Can't find the free memory
-
---*/
-{
- UINTN TempBytePos;
- UINTN FoundBytePos;
- UINT8 Index;
- UINT8 FoundBitPos;
- UINT8 ByteValue;
- UINT8 BitValue;
- UINTN NumberOfZeros;
- UINTN Count;
-
- FoundBytePos = 0;
- FoundBitPos = 0;
- ByteValue = MemoryHeader->BitArrayPtr[0];
- NumberOfZeros = 0;
- Index = 0;
-
- for (TempBytePos = 0; TempBytePos < MemoryHeader->BitArraySizeInBytes;) {
-
- //
- // Pop out BitValue from a byte in TempBytePos.
- //
- BitValue = (UINT8) (ByteValue & 0x1);
-
- //
- // right shift the byte
- //
- ByteValue = (UINT8) (ByteValue >> 1);
-
- if (BitValue == 0) {
- //
- // Found a free bit, the NumberOfZeros only record the number
- // of those consecutive zeros
- //
- NumberOfZeros++;
- //
- // Found enough consecutive free space, break the loop
- //
- if (NumberOfZeros >= NumberOfMemoryUnit) {
- break;
- }
- } else {
- //
- // Encountering a '1', meant the bit is ocupied.
- //
- if (NumberOfZeros >= NumberOfMemoryUnit) {
- //
- // Found enough consecutive free space,break the loop
- //
- break;
- } else {
- //
- // the NumberOfZeros only record the number of those consecutive zeros,
- // so reset the NumberOfZeros to 0 when encountering '1' before finding
- // enough consecutive '0's
- //
- NumberOfZeros = 0;
- //
- // reset the (FoundBytePos,FoundBitPos) to the position of '1'
- //
- FoundBytePos = TempBytePos;
- FoundBitPos = Index;
- }
- }
-
- //
- // step forward a bit
- //
- Index++;
- if (Index == 8) {
- //
- // step forward a byte, getting the byte value,
- // and reset the bit pos.
- //
- TempBytePos += 1;
- ByteValue = MemoryHeader->BitArrayPtr[TempBytePos];
- Index = 0;
- }
- }
-
- if (NumberOfZeros < NumberOfMemoryUnit) {
- return EFI_NOT_FOUND;
- }
-
- //
- // Found enough free space.
- //
-
- //
- // The values recorded in (FoundBytePos,FoundBitPos) have two conditions:
- // 1)(FoundBytePos,FoundBitPos) record the position
- // of the last '1' before the consecutive '0's, it must
- // be adjusted to the start position of the consecutive '0's.
- // 2)the start address of the consecutive '0's is just the start of
- // the bitarray. so no need to adjust the values of
- // (FoundBytePos,FoundBitPos).
- //
- if ((MemoryHeader->BitArrayPtr[FoundBytePos] & bit (FoundBitPos)) != 0) {
- FoundBitPos += 1;
- }
-
- //
- // Have the (FoundBytePos,FoundBitPos) make sense.
- //
- if (FoundBitPos > 7) {
- FoundBytePos += 1;
- FoundBitPos -= 8;
- }
-
- //
- // Set the memory as allocated
- //
- for (TempBytePos = FoundBytePos, Index = FoundBitPos, Count = 0; Count < NumberOfMemoryUnit; Count++) {
-
- ASSERT ((MemoryHeader->BitArrayPtr[TempBytePos] & bit (Index) )== 0);
- MemoryHeader->BitArrayPtr[TempBytePos] = (UINT8) (MemoryHeader->BitArrayPtr[TempBytePos] | bit (Index));
- Index++;
- if (Index == 8) {
- TempBytePos += 1;
- Index = 0;
- }
- }
-
- *Pool = MemoryHeader->MemoryBlockPtr + (FoundBytePos * 8 + FoundBitPos) * MEM_UNIT_SIZE;
-
- return EFI_SUCCESS;
-}
-
-BOOLEAN
-IsMemoryBlockEmptied (
- IN MEMORY_MANAGE_HEADER *MemoryHeaderPtr
- )
-/*++
-
-Routine Description:
-
- Is Memory Block Emptied
-
-Arguments:
-
- MemoryHeaderPtr - MEMORY_MANAGE_HEADER
-
-Returns:
-
- TRUE Empty
- FALSE Not Empty
-
---*/
-{
- UINTN Index;
-
- for (Index = 0; Index < MemoryHeaderPtr->BitArraySizeInBytes; Index++) {
- if (MemoryHeaderPtr->BitArrayPtr[Index] != 0) {
- return FALSE;
- }
- }
-
- return TRUE;
-}
-
-VOID
-DelinkMemoryBlock (
- IN MEMORY_MANAGE_HEADER *FirstMemoryHeader,
- IN MEMORY_MANAGE_HEADER *NeedFreeMemoryHeader
- )
-/*++
-
-Routine Description:
-
- Delink Memory Block
-
-Arguments:
-
- FirstMemoryHeader - MEMORY_MANAGE_HEADER
- NeedFreeMemoryHeader - MEMORY_MANAGE_HEADER
-
-Returns:
-
- VOID
-
---*/
-{
- MEMORY_MANAGE_HEADER *TempHeaderPtr;
-
- if ((FirstMemoryHeader == NULL) || (NeedFreeMemoryHeader == NULL)) {
- return ;
- }
-
- for (TempHeaderPtr = FirstMemoryHeader; TempHeaderPtr != NULL; TempHeaderPtr = TempHeaderPtr->Next) {
-
- if (TempHeaderPtr->Next == NeedFreeMemoryHeader) {
- //
- // Link the before and after
- //
- TempHeaderPtr->Next = NeedFreeMemoryHeader->Next;
- NeedFreeMemoryHeader->Next = NULL;
- break;
- }
- }
-}
-
-EFI_STATUS
-InitialMemoryManagement (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Initialize Memory Management
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-{
- EFI_STATUS Status;
- MEMORY_MANAGE_HEADER *MemoryHeader;
- UINTN MemPages;
-
- MemPages = NORMAL_MEMORY_BLOCK_UNIT_IN_PAGES;
- Status = CreateMemoryBlock (HcDev, &MemoryHeader, MemPages);
- if (EFI_ERROR (Status)) {
- Status = EFI_OUT_OF_RESOURCES;
- goto exit;
- }
-
- HcDev->MemoryHeader = MemoryHeader;
-
-exit:
- return Status;
-}
-
-EFI_STATUS
-DeinitialMemoryManagement (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Deinitialize Memory Management
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-{
- MEMORY_MANAGE_HEADER *TempHeaderPtr;
-
- for (TempHeaderPtr = HcDev->MemoryHeader->Next; TempHeaderPtr != NULL;) {
-
- DelinkMemoryBlock (HcDev->MemoryHeader, TempHeaderPtr);
- //
- // when the TempHeaderPtr is freed in FreeMemoryHeader(),
- // the TempHeaderPtr is pointing to nonsense content.
- //
- FreeMemoryHeader (HcDev, TempHeaderPtr);
- //
- // reset the TempHeaderPtr,continue free another memory block.
- //
- TempHeaderPtr = HcDev->MemoryHeader->Next;
- }
-
- FreeMemoryHeader (HcDev, HcDev->MemoryHeader);
-
- return EFI_SUCCESS;
-}
diff --git a/EdkModulePkg/Bus/Pci/Ehci/Dxe/EhciReg.c b/EdkModulePkg/Bus/Pci/Ehci/Dxe/EhciReg.c
deleted file mode 100644
index 78bca3b767..0000000000
--- a/EdkModulePkg/Bus/Pci/Ehci/Dxe/EhciReg.c
+++ /dev/null
@@ -1,1730 +0,0 @@
-/*++
-
-Copyright (c) 2006, 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
-
-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:
-
- Ehchlp.c
-
-Abstract:
-
-
-Revision History
---*/
-
-#include "Ehci.h"
-
-
-VOID
-HostReset (
- IN USB2_HC_DEV *HcDev
- )
-{
- UINT32 Value;
- UINT32 TimeOut;
-
- ReadEhcOperationalReg (
- HcDev,
- USBCMD,
- &Value
- );
-
- Value = Value & (~USBCMD_RS);
- WriteEhcOperationalReg (
- HcDev,
- USBCMD,
- Value
- );
-
- TimeOut = 40;
- while (TimeOut --) {
- gBS->Stall (500);
- ReadEhcOperationalReg (
- HcDev,
- USBSTS,
- &Value
- );
- if ((Value & USBSTS_HCH) != 0) {
- break;
- }
- }
-
- if (TimeOut == 0) {
- DEBUG((gEHCErrorLevel, "TimeOut for clearing Run/Stop bit\n"));
- }
-
- ReadEhcOperationalReg (
- HcDev,
- USBCMD,
- &Value
- );
- Value = Value | USBCMD_HCRESET;
- WriteEhcOperationalReg (
- HcDev,
- USBCMD,
- Value
- );
-
- TimeOut = 40;
- while (TimeOut --) {
- gBS->Stall (500);
- ReadEhcOperationalReg (
- HcDev,
- USBCMD,
- &Value
- );
- if ((Value & USBCMD_HCRESET) == 0) {
- break;
- }
- }
-
- if (TimeOut == 0) {
- DEBUG((gEHCErrorLevel, "TimeOut for Host Reset\n"));
- }
-
-}
-
-EFI_STATUS
-ReadEhcCapabiltiyReg (
- IN USB2_HC_DEV *HcDev,
- IN UINT32 CapabiltiyRegAddr,
- IN OUT UINT32 *Data
- )
-/*++
-
-Routine Description:
-
- Read Ehc Capabitlity register
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- CapabiltiyRegAddr - Ehc Capability register address
- Data - A pointer to data read from register
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-{
- return HcDev->PciIo->Mem.Read (
- HcDev->PciIo,
- EfiPciIoWidthUint32,
- USB_BAR_INDEX,
- (UINT64) CapabiltiyRegAddr,
- 1,
- Data
- );
-}
-
-EFI_STATUS
-ReadEhcOperationalReg (
- IN USB2_HC_DEV *HcDev,
- IN UINT32 OperationalRegAddr,
- IN OUT UINT32 *Data
- )
-/*++
-
-Routine Description:
-
- Read Ehc Operation register
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- OperationalRegAddr - Ehc Operation register address
- Data - A pointer to data read from register
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-{
- ASSERT (HcDev->UsbCapabilityLen);
- return HcDev->PciIo->Mem.Read (
- HcDev->PciIo,
- EfiPciIoWidthUint32,
- USB_BAR_INDEX,
- (UINT64) (OperationalRegAddr + HcDev->UsbCapabilityLen),
- 1,
- Data
- );
-}
-
-EFI_STATUS
-WriteEhcOperationalReg (
- IN USB2_HC_DEV *HcDev,
- IN UINT32 OperationalRegAddr,
- IN UINT32 Data
- )
-/*++
-
-Routine Description:
-
- Write Ehc Operation register
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- OperationalRegAddr - Ehc Operation register address
- Data - 32bit write to register
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-{
- ASSERT (HcDev->UsbCapabilityLen);
- return HcDev->PciIo->Mem.Write (
- HcDev->PciIo,
- EfiPciIoWidthUint32,
- USB_BAR_INDEX,
- (UINT64) (OperationalRegAddr + HcDev->UsbCapabilityLen),
- 1,
- &Data
- );
-}
-
-
-
-VOID
-ClearLegacySupport (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Stop the legacy USB SMI
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-{
- UINT32 EECP;
- UINT32 Value;
- UINT32 TimeOut;
-
- ReadEhcCapabiltiyReg (
- HcDev,
- HCCPARAMS,
- &EECP
- );
-
- EECP = (EECP >> 8) & 0xFF;
-
- DEBUG ((gEHCDebugLevel, "EHCI: EECPBase = 0x%x\n", EECP));
-
-
- HcDev->PciIo->Pci.Read (
- HcDev->PciIo,
- EfiPciIoWidthUint32,
- EECP,
- 1,
- &Value
- );
-
- DEBUG((gEHCDebugLevel, "EECP[0] = 0x%x\n", Value));
-
- HcDev->PciIo->Pci.Read (
- HcDev->PciIo,
- EfiPciIoWidthUint32,
- EECP + 0x4,
- 1,
- &Value
- );
-
- DEBUG((gEHCDebugLevel, "EECP[4] = 0x%x\n", Value));
-
- HcDev->PciIo->Pci.Read (
- HcDev->PciIo,
- EfiPciIoWidthUint32,
- EECP,
- 1,
- &Value
- );
-
- Value = Value | (0x1 << 24);
- DEBUG((gEHCErrorLevel, "Value Written = 0x%x\n", Value));
-
- HcDev->PciIo->Pci.Write (
- HcDev->PciIo,
- EfiPciIoWidthUint32,
- EECP,
- 1,
- &Value
- );
-
- TimeOut = 40;
- while (TimeOut --) {
- gBS->Stall (500);
-
- HcDev->PciIo->Pci.Read (
- HcDev->PciIo,
- EfiPciIoWidthUint32,
- EECP,
- 1,
- &Value
- );
- if ((Value & 0x01010000) == 0x01000000) {
- break;
- }
- }
-
- if (TimeOut == 0) {
- DEBUG((gEHCErrorLevel, "Timeout for getting HC OS Owned Semaphore\n" ));
- }
-
- DEBUG((gEHCErrorLevel, "After Release Value\n" ));
-
- HcDev->PciIo->Pci.Read (
- HcDev->PciIo,
- EfiPciIoWidthUint32,
- EECP,
- 1,
- &Value
- );
-
- DEBUG((gEHCDebugLevel, "EECP[0] = 0x%x\n", Value));
-
- HcDev->PciIo->Pci.Read (
- HcDev->PciIo,
- EfiPciIoWidthUint32,
- EECP + 0x4,
- 1,
- &Value
- );
-
- DEBUG((gEHCDebugLevel, "EECP[4] = 0x%x\n", Value));
-
-
-}
-
-EFI_STATUS
-GetCapabilityLen (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Get the length of capability register
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-{
- EFI_STATUS Status;
- UINT32 CapabilityLenAddr;
-
- CapabilityLenAddr = CAPLENGTH;
-
- Status = ReadEhcCapabiltiyReg (
- HcDev,
- CapabilityLenAddr,
- &(HcDev->UsbCapabilityLen)
- );
- HcDev->UsbCapabilityLen = (UINT8) HcDev->UsbCapabilityLen;
-
- return Status;
-}
-
-EFI_STATUS
-SetFrameListLen (
- IN USB2_HC_DEV *HcDev,
- IN UINTN Length
- )
-/*++
-
-Routine Description:
-
- Set the length of Frame List
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- Length - the required length of frame list
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_INVALID_PARAMETER Invalid parameter
- EFI_DEVICE_ERROR Fail
-
---*/
-{
- EFI_STATUS Status;
- UINT32 UsbCommandAddr;
- UINT32 UsbCommandReg;
-
- UsbCommandAddr = USBCMD;
-
- if (256 != Length && 512 != Length) {
- Status = EFI_INVALID_PARAMETER;
- goto exit;
- }
-
- Status = ReadEhcOperationalReg (
- HcDev,
- UsbCommandAddr,
- &UsbCommandReg
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- if (256 == Length) {
- UsbCommandReg |= USBCMD_FLS_256;
- } else {
- UsbCommandReg |= USBCMD_FLS_512;
- }
-
- Status = WriteEhcOperationalReg (
- HcDev,
- UsbCommandAddr,
- UsbCommandReg
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- }
-
-exit:
- return Status;
-}
-
-EFI_STATUS
-SetFrameListBaseAddr (
- IN USB2_HC_DEV *HcDev,
- IN UINT32 FrameBuffer
- )
-/*++
-
-Routine Description:
-
- Set base address of frame list first entry
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- FrameBuffer - base address of first entry of frame list
-
-Returns:
-
---*/
-{
- EFI_STATUS Status;
- UINT32 PeriodicListBaseAddr;
- UINT32 PeriodicListBaseReg;
-
- Status = EFI_SUCCESS;
- PeriodicListBaseAddr = PERIODICLISTBASE;
- PeriodicListBaseReg = FrameBuffer & 0xfffff000;
-
- if (IsEhcHalted (HcDev)) {
-
- Status = WriteEhcOperationalReg (
- HcDev,
- PeriodicListBaseAddr,
- PeriodicListBaseReg
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- }
-
-exit:
- return Status;
-}
-
-EFI_STATUS
-SetAsyncListAddr (
- IN USB2_HC_DEV *HcDev,
- IN EHCI_QH_ENTITY *QhPtr
- )
-/*++
-
-Routine Description:
-
- Set address of first Async schedule Qh
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- QhPtr - A pointer to first Qh in the Async schedule
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-{
- EFI_STATUS Status;
- UINT32 AsyncListAddr;
- UINT32 AsyncListReg;
-
- AsyncListAddr = ASYNCLISTADDR;
- AsyncListReg = (UINT32) GET_0B_TO_31B (&(QhPtr->Qh));
-
- Status = WriteEhcOperationalReg (
- HcDev,
- AsyncListAddr,
- AsyncListReg
- );
-
- return Status;
-}
-
-EFI_STATUS
-SetCtrlDataStructSeg (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Set register of control and data structure segment
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
-
---*/
-{
- EFI_STATUS Status;
- UINT32 CtrlDsSegmentAddr;
- UINT32 CtrlDsSegmentReg;
-
- CtrlDsSegmentAddr = CTRLDSSGMENT;
- CtrlDsSegmentReg = HcDev->High32BitAddr;
-
- Status = WriteEhcOperationalReg (
- HcDev,
- CtrlDsSegmentAddr,
- CtrlDsSegmentReg
- );
-
- return Status;
-}
-
-EFI_STATUS
-SetPortRoutingEhc (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Set Ehc port routing bit
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-{
- EFI_STATUS Status;
- UINT32 ConfigFlagAddr;
- UINT32 ConfigFlagReg;
-
- ConfigFlagAddr = CONFIGFLAG;
-
- Status = ReadEhcOperationalReg (
- HcDev,
- ConfigFlagAddr,
- &ConfigFlagReg
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- ConfigFlagReg |= CONFIGFLAG_CF;
- Status = WriteEhcOperationalReg (
- HcDev,
- ConfigFlagAddr,
- ConfigFlagReg
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- }
-
-exit:
- return Status;
-}
-
-EFI_STATUS
-SetEhcDoorbell (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Set Ehc door bell bit
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-{
- EFI_STATUS Status;
- UINT32 UsbCommandAddr;
- UINT32 UsbCommandReg;
-
- UsbCommandAddr = USBCMD;
-
- Status = ReadEhcOperationalReg (
- HcDev,
- UsbCommandAddr,
- &UsbCommandReg
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- UsbCommandReg |= USBCMD_IAAD;
- Status = WriteEhcOperationalReg (
- HcDev,
- UsbCommandAddr,
- UsbCommandReg
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- }
-
-exit:
- return Status;
-}
-
-EFI_STATUS
-ClearEhcAllStatus (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Clear Ehc all status bits
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-{
- UINT32 UsbStatusAddr;
-
- UsbStatusAddr = USBSTS;
-
- return WriteEhcOperationalReg (
- HcDev,
- UsbStatusAddr,
- 0x003F
- );
-}
-
-EFI_STATUS
-EnablePeriodicSchedule (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Enable periodic schedule
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-{
- EFI_STATUS Status;
- UINT32 UsbCommandAddr;
- UINT32 UsbCommandReg;
-
- UsbCommandAddr = USBCMD;
-
- Status = ReadEhcOperationalReg (
- HcDev,
- UsbCommandAddr,
- &UsbCommandReg
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- UsbCommandReg |= USBCMD_PSE;
- Status = WriteEhcOperationalReg (
- HcDev,
- UsbCommandAddr,
- UsbCommandReg
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- }
-
-exit:
- return Status;
-}
-
-EFI_STATUS
-DisablePeriodicSchedule (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Disable periodic schedule
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-{
- EFI_STATUS Status;
- UINT32 UsbCommandAddr;
- UINT32 UsbCommandReg;
-
- UsbCommandAddr = USBCMD;
-
- Status = ReadEhcOperationalReg (
- HcDev,
- UsbCommandAddr,
- &UsbCommandReg
- );
- if (EFI_ERROR (Status)) {
- return EFI_DEVICE_ERROR;
- }
-
- UsbCommandReg &= ~USBCMD_PSE;
- Status = WriteEhcOperationalReg (
- HcDev,
- UsbCommandAddr,
- UsbCommandReg
- );
- if (EFI_ERROR (Status)) {
- return EFI_DEVICE_ERROR;
- }
-
- return Status;
-}
-
-EFI_STATUS
-EnableAsynchronousSchedule (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Enable asynchrounous schedule
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-{
- EFI_STATUS Status;
- UINT32 UsbCommandAddr;
- UINT32 UsbCommandReg;
-
- UsbCommandAddr = USBCMD;
-
- Status = ReadEhcOperationalReg (
- HcDev,
- UsbCommandAddr,
- &UsbCommandReg
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- UsbCommandReg |= USBCMD_ASE;
- Status = WriteEhcOperationalReg (
- HcDev,
- UsbCommandAddr,
- UsbCommandReg
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- }
-
-exit:
- return Status;
-}
-
-EFI_STATUS
-DisableAsynchronousSchedule (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Disable asynchrounous schedule
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-{
- EFI_STATUS Status;
- UINT32 UsbCommandAddr;
- UINT32 UsbCommandReg;
-
- UsbCommandAddr = USBCMD;
-
- Status = ReadEhcOperationalReg (
- HcDev,
- UsbCommandAddr,
- &UsbCommandReg
- );
- if (EFI_ERROR (Status)) {
- return EFI_DEVICE_ERROR;
- }
-
- UsbCommandReg &= ~USBCMD_ASE;
- Status = WriteEhcOperationalReg (
- HcDev,
- UsbCommandAddr,
- UsbCommandReg
- );
- if (EFI_ERROR (Status)) {
- return EFI_DEVICE_ERROR;
- }
-
- return Status;
-}
-
-EFI_STATUS
-ResetEhc (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Reset Ehc
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-{
- EFI_STATUS Status;
- UINT32 UsbCommandAddr;
- UINT32 UsbCommandReg;
-
- UsbCommandAddr = USBCMD;
-
- Status = ReadEhcOperationalReg (
- HcDev,
- UsbCommandAddr,
- &UsbCommandReg
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- UsbCommandReg |= USBCMD_HCRESET;
- Status = WriteEhcOperationalReg (
- HcDev,
- UsbCommandAddr,
- UsbCommandReg
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- }
-
-exit:
- return Status;
-}
-
-EFI_STATUS
-StartScheduleExecution (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Start Ehc schedule execution
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-{
- EFI_STATUS Status;
- UINT32 UsbCommandAddr;
- UINT32 UsbCommandReg;
-
- UsbCommandAddr = USBCMD;
-
- Status = ReadEhcOperationalReg (
- HcDev,
- UsbCommandAddr,
- &UsbCommandReg
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- UsbCommandReg |= USBCMD_RS;
- Status = WriteEhcOperationalReg (
- HcDev,
- UsbCommandAddr,
- UsbCommandReg
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- }
-
-exit:
- return Status;
-}
-
-BOOLEAN
-IsFrameListProgrammable (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Whether frame list is programmable
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- TRUE Programmable
- FALSE Unprogrammable
-
---*/
-{
- BOOLEAN Value;
- UINT32 HcCapParamsAddr;
- UINT32 HcCapParamsReg;
-
- HcCapParamsAddr = HCCPARAMS;
-
- ReadEhcCapabiltiyReg(
- HcDev,
- HcCapParamsAddr,
- &HcCapParamsReg
- );
-
- if (HcCapParamsReg & HCCP_PFLF) {
- Value = TRUE;
- } else {
- Value = FALSE;
- }
-
- return Value;
-}
-
-BOOLEAN
-IsPeriodicScheduleEnabled (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Whether periodic schedule is enabled
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- TRUE Enabled
- FALSE Disabled
-
---*/
-{
- BOOLEAN Value;
- UINT32 UsbStatusAddr;
- UINT32 UsbStatusReg;
-
- UsbStatusAddr = USBSTS;
-
- ReadEhcOperationalReg (
- HcDev,
- UsbStatusAddr,
- &UsbStatusReg
- );
-
- if (UsbStatusReg & USBSTS_PSS) {
- Value = TRUE;
- } else {
- Value = FALSE;
- }
-
- return Value;
-}
-
-BOOLEAN
-IsAsyncScheduleEnabled (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Whether asynchronous schedule is enabled
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- TRUE Enabled
- FALSE Disabled
-
---*/
-{
- BOOLEAN Value;
- UINT32 UsbStatusAddr;
- UINT32 UsbStatusReg;
-
- UsbStatusAddr = USBSTS;
-
- ReadEhcOperationalReg (
- HcDev,
- UsbStatusAddr,
- &UsbStatusReg
- );
-
- if (UsbStatusReg & USBSTS_ASS) {
- Value = TRUE;
- } else {
- Value = FALSE;
- }
-
- return Value;
-}
-
-BOOLEAN
-IsEhcPortEnabled (
- IN USB2_HC_DEV *HcDev,
- IN UINT8 PortNum
- )
-/*++
-
-Routine Description:
-
- Whether port is enabled
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- TRUE Enabled
- FALSE Disabled
-
---*/
-{
- UINT32 PortStatusControlAddr;
- UINT32 PortStatusControlReg;
-
- PortStatusControlAddr = (UINT32) (PORTSC + (4 * PortNum));
-
- ReadEhcOperationalReg (
- HcDev,
- PortStatusControlAddr,
- &PortStatusControlReg
- );
-
- return ((BOOLEAN) ((PortStatusControlReg & PORTSC_PED) ? TRUE : FALSE));
-}
-
-BOOLEAN
-IsEhcReseted (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Whether Ehc is reseted
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- TRUE Reseted
- FALSE Unreseted
-
---*/
-{
- BOOLEAN Value;
- UINT32 UsbCommandAddr;
- UINT32 UsbCommandReg;
-
- UsbCommandAddr = USBCMD;
-
- ReadEhcOperationalReg (
- HcDev,
- UsbCommandAddr,
- &UsbCommandReg
- );
-
- if (UsbCommandReg & USBCMD_HCRESET) {
- Value = FALSE;
- } else {
- Value = TRUE;
- }
-
- return Value;
-}
-
-BOOLEAN
-IsEhcHalted (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Whether Ehc is halted
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- TRUE Halted
- FALSE Not halted
-
---*/
-{
- BOOLEAN Value;
- UINT32 UsbStatusAddr;
- UINT32 UsbStatusReg;
-
- UsbStatusAddr = USBSTS;
-
- ReadEhcOperationalReg (
- HcDev,
- UsbStatusAddr,
- &UsbStatusReg
- );
-
- if (UsbStatusReg & USBSTS_HCH) {
- Value = TRUE;
- } else {
- Value = FALSE;
- }
-
- return Value;
-}
-
-BOOLEAN
-IsEhcSysError (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Whether Ehc is system error
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- TRUE System error
- FALSE No system error
-
---*/
-{
- BOOLEAN Value;
- UINT32 UsbStatusAddr;
- UINT32 UsbStatusReg;
-
- UsbStatusAddr = USBSTS;
-
- ReadEhcOperationalReg (
- HcDev,
- UsbStatusAddr,
- &UsbStatusReg
- );
-
- if (UsbStatusReg & USBSTS_HSE) {
- Value = TRUE;
- } else {
- Value = FALSE;
- }
-
- return Value;
-}
-
-BOOLEAN
-IsHighSpeedDevice (
- IN EFI_USB2_HC_PROTOCOL *This,
- IN UINT8 PortNum
- )
-/*++
-
-Routine Description:
-
- Whether high speed device attached
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- TRUE High speed
- FALSE Full speed
-
---*/
-{
- USB2_HC_DEV *HcDev;
- UINT32 PortStatusControlAddr;
- UINT32 PortStatusControlReg;
-
- HcDev = USB2_HC_DEV_FROM_THIS (This);
- PortStatusControlAddr = (UINT32) (PORTSC + (4 * PortNum));
-
- //
- // Set port reset bit
- //
- ReadEhcOperationalReg (
- HcDev,
- PortStatusControlAddr,
- &PortStatusControlReg
- );
- //
- // Make sure Host Controller not halt before reset it
- //
- if (IsEhcHalted (HcDev)) {
- StartScheduleExecution (HcDev);
- WaitForEhcNotHalt (HcDev, EHCI_GENERIC_TIMEOUT);
- }
- PortStatusControlReg &= 0xffffffd5;
- PortStatusControlReg |= PORTSC_PR;
- //
- // Set one to PortReset bit must also set zero to PortEnable bit
- //
- PortStatusControlReg &= ~PORTSC_PED;
- WriteEhcOperationalReg (
- HcDev,
- PortStatusControlAddr,
- PortStatusControlReg
- );
-
- //
- // Set Port reset recovery time
- //
- gBS->Stall (EHCI_SET_PORT_RESET_RECOVERY_TIME);
-
- //
- // Clear port reset bit
- //
- ReadEhcOperationalReg (
- HcDev,
- PortStatusControlAddr,
- &PortStatusControlReg
- );
- PortStatusControlReg &= 0xffffffd5;
- PortStatusControlReg &= ~PORTSC_PR;
- WriteEhcOperationalReg (
- HcDev,
- PortStatusControlAddr,
- PortStatusControlReg
- );
-
- //
- // Clear port reset recovery time
- //
- gBS->Stall (EHCI_CLEAR_PORT_RESET_RECOVERY_TIME);
-
- return ((BOOLEAN) (IsEhcPortEnabled (HcDev, PortNum) ? TRUE : FALSE));
-}
-
-EFI_STATUS
-WaitForEhcReset (
- IN USB2_HC_DEV *HcDev,
- IN UINTN Timeout
- )
-/*++
-
-Routine Description:
-
- wait for Ehc reset or timeout
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- Timeout - timeout threshold
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_TIMEOUT Timeout
-
---*/
-{
- EFI_STATUS Status;
- UINTN Delay;
-
- //
- // Timeout is in US unit
- //
- Delay = (Timeout / 50) + 1;
- do {
-
- if (IsEhcReseted (HcDev)) {
- Status = EFI_SUCCESS;
- goto exit;
- }
- gBS->Stall (EHCI_GENERIC_RECOVERY_TIME);
-
- } while (Delay--);
-
- Status = EFI_TIMEOUT;
-
-exit:
- return Status;
-}
-
-EFI_STATUS
-WaitForEhcHalt (
- IN USB2_HC_DEV *HcDev,
- IN UINTN Timeout
- )
-/*++
-
-Routine Description:
-
- wait for Ehc halt or timeout
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- Timeout - timeout threshold
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_TIMEOUT Timeout
-
---*/
-{
- EFI_STATUS Status;
- UINTN Delay;
-
- //
- // Timeout is in US unit
- //
- Delay = (Timeout / 50) + 1;
- do {
-
- if (IsEhcHalted (HcDev)) {
- Status = EFI_SUCCESS;
- goto exit;
- }
- gBS->Stall (EHCI_GENERIC_RECOVERY_TIME);
-
- } while (Delay--);
-
- Status = EFI_TIMEOUT;
-
-exit:
- return Status;
-}
-
-EFI_STATUS
-WaitForEhcNotHalt (
- IN USB2_HC_DEV *HcDev,
- IN UINTN Timeout
- )
-/*++
-
-Routine Description:
-
- wait for Ehc not halt or timeout
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- Timeout - timeout threshold
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_TIMEOUT Timeout
-
---*/
-{
- EFI_STATUS Status;
- UINTN Delay;
-
- //
- // Timeout is in US unit
- //
- Delay = (Timeout / 50) + 1;
- do {
-
- if (!IsEhcHalted (HcDev)) {
- Status = EFI_SUCCESS;
- goto exit;
- }
- gBS->Stall (EHCI_GENERIC_RECOVERY_TIME);
-
- } while (Delay--);
-
- Status = EFI_TIMEOUT;
-
-exit:
- return Status;
-}
-
-EFI_STATUS
-WaitForAsyncScheduleEnable (
- IN USB2_HC_DEV *HcDev,
- IN UINTN Timeout
- )
-/*++
-
-Routine Description:
-
- Wait for Ehc asynchronous schedule enable or timeout
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- Timeout - timeout threshold
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_TIMEOUT Timeout
-
---*/
-{
- EFI_STATUS Status;
- UINTN Delay;
-
- //
- // Timeout is in US unit
- //
- Delay = (Timeout / 50) + 1;
- do {
-
- if (IsAsyncScheduleEnabled (HcDev)) {
- Status = EFI_SUCCESS;
- goto exit;
- }
- gBS->Stall (EHCI_GENERIC_RECOVERY_TIME);
-
- } while (Delay--);
-
- Status = EFI_TIMEOUT;
-
-exit:
- return Status;
-}
-
-EFI_STATUS
-WaitForAsyncScheduleDisable (
- IN USB2_HC_DEV *HcDev,
- IN UINTN Timeout
- )
-/*++
-
-Routine Description:
-
- Wait for Ehc asynchronous schedule disable or timeout
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- Timeout - timeout threshold
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_TIMEOUT Timeout
-
---*/
-{
- EFI_STATUS Status;
- UINTN Delay;
-
- //
- // Timeout is in US unit
- //
- Delay = (Timeout / 50) + 1;
- do {
-
- if (!IsAsyncScheduleEnabled (HcDev)) {
- Status = EFI_SUCCESS;
- goto exit;
- }
- gBS->Stall (EHCI_GENERIC_RECOVERY_TIME);
-
- } while (Delay--);
-
- Status = EFI_TIMEOUT;
-
-exit:
- return Status;
-}
-
-EFI_STATUS
-WaitForPeriodicScheduleEnable (
- IN USB2_HC_DEV *HcDev,
- IN UINTN Timeout
- )
-/*++
-
-Routine Description:
-
- Wait for Ehc periodic schedule enable or timeout
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- Timeout - timeout threshold
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_TIMEOUT Timeout
-
---*/
-{
- EFI_STATUS Status;
- UINTN Delay;
-
- //
- // Timeout is in US unit
- //
- Delay = (Timeout / 50) + 1;
- do {
-
- if (IsPeriodicScheduleEnabled (HcDev)) {
- Status = EFI_SUCCESS;
- goto exit;
- }
- gBS->Stall (EHCI_GENERIC_RECOVERY_TIME);
-
- } while (Delay--);
-
- Status = EFI_TIMEOUT;
-
-exit:
- return Status;
-}
-
-EFI_STATUS
-WaitForPeriodicScheduleDisable (
- IN USB2_HC_DEV *HcDev,
- IN UINTN Timeout
- )
-/*++
-
-Routine Description:
-
- Wait for periodic schedule disable or timeout
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- Timeout - timeout threshold
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_TIMEOUT Timeout
-
---*/
-{
- EFI_STATUS Status;
- UINTN Delay;
-
- //
- // Timeout is in US unit
- //
- Delay = (Timeout / 50) + 1;
- do {
-
- if (!IsPeriodicScheduleEnabled (HcDev)) {
- Status = EFI_SUCCESS;
- goto exit;
- }
- gBS->Stall (EHCI_GENERIC_RECOVERY_TIME);
-
- } while (Delay--);
-
- Status = EFI_TIMEOUT;
-
-exit:
- return Status;
-}
-
-EFI_STATUS
-WaitForEhcDoorbell (
- IN USB2_HC_DEV *HcDev,
- IN UINTN Timeout
- )
-/*++
-
-Routine Description:
-
- Wait for periodic schedule disable or timeout
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- Timeout - timeout threshold
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_TIMEOUT Timeout
-
---*/
-{
- EFI_STATUS Status;
- UINT32 UsbCommandAddr;
- UINT32 UsbCommandReg;
- UINTN Delay;
-
- UsbCommandAddr = USBCMD;
- Delay = (Timeout / 50) + 1;
-
- do {
- Status = ReadEhcOperationalReg (
- HcDev,
- UsbCommandAddr,
- &UsbCommandReg
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
- if (!(UsbCommandReg & USBCMD_IAAD)) {
- break;
- }
-
- } while (--Delay);
-
- if (0 == Delay) {
- Status = EFI_TIMEOUT;
- }
-
-exit:
- return Status;
-}
diff --git a/EdkModulePkg/Bus/Pci/Ehci/Dxe/EhciSched.c b/EdkModulePkg/Bus/Pci/Ehci/Dxe/EhciSched.c
deleted file mode 100644
index 4e4a54c926..0000000000
--- a/EdkModulePkg/Bus/Pci/Ehci/Dxe/EhciSched.c
+++ /dev/null
@@ -1,3240 +0,0 @@
-/*++
-
-Copyright (c) 2006, 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
-
-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:
-
- EhciSched.c
-
-Abstract:
-
-
-Revision History
---*/
-
-#include "Ehci.h"
-
-STATIC
-EFI_STATUS
-SetAndWaitDoorBell (
- IN USB2_HC_DEV *HcDev,
- IN UINTN Timeout
- )
-/*++
-
-Routine Description:
-
- Set DoorBell and wait it to complete
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-{
- EFI_STATUS Status;
- UINT32 Data;
- UINTN Delay;
-
- Status = ReadEhcOperationalReg (
- HcDev,
- USBCMD,
- &Data
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- Data |= USBCMD_IAAD;
- Status = WriteEhcOperationalReg (
- HcDev,
- USBCMD,
- Data
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- }
-
- //
- // Timeout is in US unit
- //
- Delay = (Timeout / 50) + 1;
- do {
- Status = ReadEhcOperationalReg (
- HcDev,
- USBSTS,
- &Data
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- if ((Data & USBSTS_IAA) == USBSTS_IAA) {
- break;
- }
-
- gBS->Stall (EHCI_GENERIC_RECOVERY_TIME);
-
- } while (Delay--);
-
- Data = Data & 0xFFFFFFC0;
- Data |= USBSTS_IAA;
- Status = WriteEhcOperationalReg (
- HcDev,
- USBSTS,
- Data
- );
-
-exit:
- return Status;
-}
-
-
-
-
-
-EFI_STATUS
-CreateNULLQH (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Create the NULL QH to make it as the Async QH header
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- EFI_SUCCESS Success
---*/
-{
- EFI_STATUS Status;
- EHCI_QH_ENTITY *NULLQhPtr;
- //
- // Allocate memory for Qh structure
- //
- Status = EhciAllocatePool (
- HcDev,
- (UINT8 **) &NULLQhPtr,
- sizeof (EHCI_QH_ENTITY)
- );
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- NULLQhPtr->Qh.Status = QTD_STATUS_HALTED;
- NULLQhPtr->Qh.HeadReclamationFlag = 1;
- NULLQhPtr->Qh.QhHorizontalPointer = (UINT32) (GET_0B_TO_31B (&(NULLQhPtr->Qh) >> 5));
- NULLQhPtr->Qh.SelectType = QH_SELECT_TYPE;
- NULLQhPtr->Qh.NextQtdTerminate = 1;
-
- NULLQhPtr->Next = NULLQhPtr;
- NULLQhPtr->Prev = NULLQhPtr;
-
- HcDev->NULLQH = NULLQhPtr;
-
- return Status;
-}
-
-
-
-VOID
-DestroyNULLQH (
- IN USB2_HC_DEV *HcDev
- )
-{
-
- if (HcDev->NULLQH != NULL) {
- EhciFreePool (HcDev, (UINT8 *)HcDev->NULLQH, sizeof (EHCI_QH_ENTITY));
- HcDev->NULLQH = NULL;
- }
-}
-
-
-
-EFI_STATUS
-InitialPeriodicFrameList (
- IN USB2_HC_DEV *HcDev,
- IN UINTN Length
- )
-/*++
-
-Routine Description:
-
- Initialize Periodic Schedule Frame List
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- Length - Frame List Length
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-{
- EFI_STATUS Status;
- VOID *CommonBuffer;
- EFI_PHYSICAL_ADDRESS FrameBuffer;
- VOID *Map;
- UINTN BufferSizeInPages;
- UINTN BufferSizeInBytes;
- UINTN FrameIndex;
- FRAME_LIST_ENTRY *FrameEntryPtr;
-
- //
- // The Frame List is a common buffer that will be
- // accessed by both the cpu and the usb bus master
- // at the same time.
- // The Frame List ocupies 4K bytes,
- // and must be aligned on 4-Kbyte boundaries.
- //
- if (EHCI_MAX_FRAME_LIST_LENGTH != Length && IsFrameListProgrammable (HcDev)) {
- Status = SetFrameListLen (HcDev, Length);
- if (EFI_ERROR (Status)) {
- Status = EFI_INVALID_PARAMETER;
- goto exit;
- }
- }
-
- BufferSizeInBytes = EFI_PAGE_SIZE;
- BufferSizeInPages = EFI_SIZE_TO_PAGES (BufferSizeInBytes);
- Status = HcDev->PciIo->AllocateBuffer (
- HcDev->PciIo,
- AllocateAnyPages,
- EfiBootServicesData,
- BufferSizeInPages,
- &CommonBuffer,
- 0
- );
- if (EFI_ERROR (Status)) {
- DEBUG ((gEHCErrorLevel, "EHCI: PciIo->AllocateBuffer Failed\n"));
- Status = EFI_OUT_OF_RESOURCES;
- goto exit;
- }
-
- Status = HcDev->PciIo->Map (
- HcDev->PciIo,
- EfiPciIoOperationBusMasterCommonBuffer,
- CommonBuffer,
- &BufferSizeInBytes,
- &FrameBuffer,
- &Map
- );
- if (EFI_ERROR (Status) || (BufferSizeInBytes != EFI_PAGE_SIZE)) {
- DEBUG ((gEHCErrorLevel, "EHCI: PciIo->MapBuffer Failed\n"));
- Status = EFI_OUT_OF_RESOURCES;
- goto free_buffer;
- }
-
- //
- // Put high 32bit into CtrlDataStructSeg reg
- // when 64bit addressing range capability
- //
- if (HcDev->Is64BitCapable != 0) {
- HcDev->High32BitAddr = (UINT32) GET_32B_TO_63B (FrameBuffer);
-
- Status = SetCtrlDataStructSeg (HcDev);
- if (EFI_ERROR (Status)) {
- DEBUG ((gEHCErrorLevel, "EHCI: SetCtrlDataStructSeg Failed\n"));
- Status = EFI_DEVICE_ERROR;
- goto unmap_buffer;
- }
- }
-
- //
- // Tell the Host Controller where the Frame List lies,
- // by set the Frame List Base Address Register.
- //
- Status = SetFrameListBaseAddr (HcDev, (UINT32) FrameBuffer);
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto unmap_buffer;
- }
-
- HcDev->PeriodicFrameListLength = Length;
- HcDev->PeriodicFrameListBuffer = (VOID *) ((UINTN) FrameBuffer);
- HcDev->PeriodicFrameListMap = Map;
-
- //
- // Init Frame List Array fields
- //
- FrameEntryPtr = (FRAME_LIST_ENTRY *) HcDev->PeriodicFrameListBuffer;
- for (FrameIndex = 0; FrameIndex < HcDev->PeriodicFrameListLength; FrameIndex++) {
- FrameEntryPtr->LinkPointer = 0;
- FrameEntryPtr->Rsvd = 0;
- FrameEntryPtr->SelectType = 0;
- FrameEntryPtr->LinkTerminate = TRUE;
- FrameEntryPtr++;
- }
-
- goto exit;
-
-unmap_buffer:
- HcDev->PciIo->Unmap (HcDev->PciIo, Map);
-free_buffer:
- HcDev->PciIo->FreeBuffer (HcDev->PciIo, BufferSizeInPages, CommonBuffer);
-exit:
- return Status;
-}
-
-VOID
-DeinitialPeriodicFrameList (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Deinitialize Periodic Schedule Frame List
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- VOID
-
---*/
-{
- HcDev->PciIo->Unmap (HcDev->PciIo, HcDev->PeriodicFrameListMap);
- HcDev->PciIo->FreeBuffer (HcDev->PciIo, EFI_SIZE_TO_PAGES (EFI_PAGE_SIZE), HcDev->PeriodicFrameListBuffer);
- return ;
-}
-
-EFI_STATUS
-CreatePollingTimer (
- IN USB2_HC_DEV *HcDev,
- IN EFI_EVENT_NOTIFY NotifyFunction
- )
-/*++
-
-Routine Description:
-
- Create Async Request Polling Timer
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- NotifyFunction - Timer Notify Function
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-{
- return gBS->CreateEvent (
- EVT_TIMER | EVT_NOTIFY_SIGNAL,
- TPL_NOTIFY,
- NotifyFunction,
- HcDev,
- &HcDev->AsyncRequestEvent
- );
-}
-
-EFI_STATUS
-DestoryPollingTimer (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Destory Async Request Polling Timer
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-{
- return gBS->CloseEvent (HcDev->AsyncRequestEvent);
-}
-
-EFI_STATUS
-StartPollingTimer (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Start Async Request Polling Timer
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-{
- return gBS->SetTimer (
- HcDev->AsyncRequestEvent,
- TimerPeriodic,
- EHCI_ASYNC_REQUEST_POLLING_TIME
- );
-}
-
-EFI_STATUS
-StopPollingTimer (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Stop Async Request Polling Timer
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-{
- return gBS->SetTimer (
- HcDev->AsyncRequestEvent,
- TimerCancel,
- EHCI_ASYNC_REQUEST_POLLING_TIME
- );
-}
-
-EFI_STATUS
-CreateQh (
- IN USB2_HC_DEV *HcDev,
- IN UINT8 DeviceAddr,
- IN UINT8 Endpoint,
- IN UINT8 DeviceSpeed,
- IN UINTN MaxPacketLen,
- OUT EHCI_QH_ENTITY **QhPtrPtr
- )
-/*++
-
-Routine Description:
-
- Create Qh Structure and Pre-Initialize
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- DeviceAddr - Address of Device
- Endpoint - Endpoint Number
- DeviceSpeed - Device Speed
- MaxPacketLen - Max Length of one Packet
- QhPtrPtr - A pointer of pointer to Qh for return
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_OUT_OF_RESOURCES Cannot allocate resources
-
---*/
-{
- EFI_STATUS Status;
- EHCI_QH_HW *QhHwPtr;
-
- ASSERT (HcDev);
- ASSERT (QhPtrPtr);
-
- *QhPtrPtr = NULL;
-
- //
- // Allocate memory for Qh structure
- //
- Status = EhciAllocatePool (
- HcDev,
- (UINT8 **) QhPtrPtr,
- sizeof (EHCI_QH_ENTITY)
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_OUT_OF_RESOURCES;
- goto exit;
- }
-
- //
- // Software field
- //
- (*QhPtrPtr)->Next = NULL;
- (*QhPtrPtr)->Prev = NULL;
- (*QhPtrPtr)->FirstQtdPtr = NULL;
- (*QhPtrPtr)->AltQtdPtr = NULL;
- (*QhPtrPtr)->LastQtdPtr = NULL;
-
- //
- // Hardware field
- //
- QhHwPtr = &((*QhPtrPtr)->Qh);
- QhHwPtr->QhHorizontalPointer = 0;
- QhHwPtr->SelectType = 0;
- QhHwPtr->MaxPacketLen = (UINT32) MaxPacketLen;
- QhHwPtr->EndpointSpeed = (DeviceSpeed & 0x3);
- QhHwPtr->EndpointNum = (Endpoint & 0x0F);
- QhHwPtr->DeviceAddr = (DeviceAddr & 0x7F);
- QhHwPtr->Multiplier = HIGH_BANDWIDTH_PIPE_MULTIPLIER;
- QhHwPtr->Rsvd1 = 0;
- QhHwPtr->Rsvd2 = 0;
- QhHwPtr->Rsvd3 = 0;
- QhHwPtr->Rsvd4 = 0;
- QhHwPtr->Rsvd5 = 0;
- QhHwPtr->Rsvd6 = 0;
-
-exit:
- return Status;
-}
-
-VOID
-DestoryQh (
- IN USB2_HC_DEV *HcDev,
- IN EHCI_QH_ENTITY *QhPtr
- )
-/*++
-
-Routine Description:
-
- Destory Qh Structure
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- QhPtr - A pointer to Qh
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-{
- ASSERT (HcDev);
- ASSERT (QhPtr);
-
- EhciFreePool (HcDev, (UINT8 *) QhPtr, sizeof (EHCI_QH_ENTITY));
- return ;
-}
-
-EFI_STATUS
-CreateControlQh (
- IN USB2_HC_DEV *HcDev,
- IN UINT8 DeviceAddr,
- IN UINT8 DeviceSpeed,
- IN UINTN MaxPacketLen,
- IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator,
- OUT EHCI_QH_ENTITY **QhPtrPtr
- )
-/*++
-
-Routine Description:
-
- Create Qh for Control Transfer
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- DeviceAddr - Address of Device
- DeviceSpeed - Device Speed
- MaxPacketLen - Max Length of one Packet
- Translator - Translator Transaction for SplitX
- QhPtrPtr - A pointer of pointer to Qh for return
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_OUT_OF_RESOURCES Cannot allocate resources
-
---*/
-{
- EFI_STATUS Status;
-
- //
- // Create and init Control Qh
- //
- Status = CreateQh (
- HcDev,
- DeviceAddr,
- 0,
- DeviceSpeed,
- MaxPacketLen,
- QhPtrPtr
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_OUT_OF_RESOURCES;
- goto exit;
- }
- //
- // Software field
- //
- (*QhPtrPtr)->Next = (*QhPtrPtr);
- (*QhPtrPtr)->Prev = (*QhPtrPtr);
- (*QhPtrPtr)->TransferType = CONTROL_TRANSFER;
-
- //
- // Hardware field
- //
- // Control Transfer use DataToggleControl
- //
- (*QhPtrPtr)->Qh.DataToggleControl = TRUE;
- (*QhPtrPtr)->Qh.QhHorizontalPointer = (UINT32) (GET_0B_TO_31B (&((*QhPtrPtr)->Qh)) >> 5);
- (*QhPtrPtr)->Qh.SelectType = QH_SELECT_TYPE;
- (*QhPtrPtr)->Qh.QhTerminate = FALSE;
- if (EFI_USB_SPEED_HIGH != DeviceSpeed) {
- (*QhPtrPtr)->Qh.ControlEndpointFlag = TRUE;
- }
- (*QhPtrPtr)->Qh.NakCountReload = NAK_COUNT_RELOAD;
- if (NULL != Translator) {
- (*QhPtrPtr)->Qh.PortNum = Translator->TranslatorPortNumber;
- (*QhPtrPtr)->Qh.HubAddr = Translator->TranslatorHubAddress;
- (*QhPtrPtr)->Qh.Status |= QTD_STATUS_DO_START_SPLIT;
- }
-
-exit:
- return Status;
-}
-
-EFI_STATUS
-CreateBulkQh (
- IN USB2_HC_DEV *HcDev,
- IN UINT8 DeviceAddr,
- IN UINT8 EndPointAddr,
- IN UINT8 DeviceSpeed,
- IN UINT8 DataToggle,
- IN UINTN MaxPacketLen,
- IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator,
- OUT EHCI_QH_ENTITY **QhPtrPtr
- )
-/*++
-
-Routine Description:
-
- Create Qh for Bulk Transfer
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- DeviceAddr - Address of Device
- EndPointAddr - Address of Endpoint
- DeviceSpeed - Device Speed
- MaxPacketLen - Max Length of one Packet
- Translator - Translator Transaction for SplitX
- QhPtrPtr - A pointer of pointer to Qh for return
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_OUT_OF_RESOURCES Cannot allocate resources
-
---*/
-{
- EFI_STATUS Status;
-
- //
- // Create and init Bulk Qh
- //
- Status = CreateQh (
- HcDev,
- DeviceAddr,
- EndPointAddr,
- DeviceSpeed,
- MaxPacketLen,
- QhPtrPtr
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_OUT_OF_RESOURCES;
- goto exit;
- }
-
- //
- // Software fields
- //
- (*QhPtrPtr)->Next = (*QhPtrPtr);
- (*QhPtrPtr)->Prev = (*QhPtrPtr);
- (*QhPtrPtr)->TransferType = BULK_TRANSFER;
-
- //
- // Hardware fields
- //
- // BulkTransfer don't use DataToggleControl
- //
- (*QhPtrPtr)->Qh.DataToggleControl = FALSE;
- (*QhPtrPtr)->Qh.QhHorizontalPointer = (UINT32) (GET_0B_TO_31B (&((*QhPtrPtr)->Qh)) >> 5);
- (*QhPtrPtr)->Qh.SelectType = QH_SELECT_TYPE;
- (*QhPtrPtr)->Qh.QhTerminate = FALSE;
- (*QhPtrPtr)->Qh.NakCountReload = NAK_COUNT_RELOAD;
- (*QhPtrPtr)->Qh.DataToggle = DataToggle;
- if (NULL != Translator) {
- (*QhPtrPtr)->Qh.PortNum = Translator->TranslatorPortNumber;
- (*QhPtrPtr)->Qh.HubAddr = Translator->TranslatorHubAddress;
- (*QhPtrPtr)->Qh.Status |= QTD_STATUS_DO_START_SPLIT;
- }
-
-exit:
- return Status;
-}
-
-EFI_STATUS
-CreateInterruptQh (
- IN USB2_HC_DEV *HcDev,
- IN UINT8 DeviceAddr,
- IN UINT8 EndPointAddr,
- IN UINT8 DeviceSpeed,
- IN UINT8 DataToggle,
- IN UINTN MaxPacketLen,
- IN UINTN Interval,
- IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator,
- OUT EHCI_QH_ENTITY **QhPtrPtr
- )
-/*++
-
-Routine Description:
-
- Create Qh for Control Transfer
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- DeviceAddr - Address of Device
- EndPointAddr - Address of Endpoint
- DeviceSpeed - Device Speed
- MaxPacketLen - Max Length of one Packet
- Interval - value of interval
- Translator - Translator Transaction for SplitX
- QhPtrPtr - A pointer of pointer to Qh for return
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_OUT_OF_RESOURCES Cannot allocate resources
-
---*/
-{
- EFI_STATUS Status;
-
- //
- // Create and init InterruptQh
- //
- Status = CreateQh (
- HcDev,
- DeviceAddr,
- EndPointAddr,
- DeviceSpeed,
- MaxPacketLen,
- QhPtrPtr
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_OUT_OF_RESOURCES;
- goto exit;
- }
-
- //
- // Software fields
- //
- if (Interval == 0) {
- (*QhPtrPtr)->TransferType = SYNC_INTERRUPT_TRANSFER;
- } else {
- (*QhPtrPtr)->TransferType = ASYNC_INTERRUPT_TRANSFER;
- }
- (*QhPtrPtr)->Interval = GetApproxiOfInterval (Interval);
-
- //
- // Hardware fields
- //
- // InterruptTranfer don't use DataToggleControl
- //
- (*QhPtrPtr)->Qh.DataToggleControl = FALSE;
- (*QhPtrPtr)->Qh.QhHorizontalPointer = 0;
- (*QhPtrPtr)->Qh.QhTerminate = TRUE;
- (*QhPtrPtr)->Qh.NakCountReload = 0;
- (*QhPtrPtr)->Qh.InerruptScheduleMask = MICRO_FRAME_0_CHANNEL;
- (*QhPtrPtr)->Qh.SplitComletionMask = (MICRO_FRAME_2_CHANNEL | MICRO_FRAME_3_CHANNEL | MICRO_FRAME_4_CHANNEL);
- (*QhPtrPtr)->Qh.DataToggle = DataToggle;
- if (NULL != Translator) {
- (*QhPtrPtr)->Qh.PortNum = Translator->TranslatorPortNumber;
- (*QhPtrPtr)->Qh.HubAddr = Translator->TranslatorHubAddress;
- (*QhPtrPtr)->Qh.Status |= QTD_STATUS_DO_START_SPLIT;
- }
-
-exit:
- return Status;
-}
-
-EFI_STATUS
-CreateQtd (
- IN USB2_HC_DEV *HcDev,
- IN UINT8 *DataPtr,
- IN UINTN DataLen,
- IN UINT8 PktId,
- IN UINT8 Toggle,
- IN UINT8 QtdStatus,
- OUT EHCI_QTD_ENTITY **QtdPtrPtr
- )
-/*++
-
-Routine Description:
-
- Create Qtd Structure and Pre-Initialize it
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- DataPtr - A pointer to user data buffer to transfer
- DataLen - Length of user data to transfer
- PktId - Packet Identification of this Qtd
- Toggle - Data Toggle of this Qtd
- QtdStatus - Default value of status of this Qtd
- QtdPtrPtr - A pointer of pointer to Qtd for return
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_OUT_OF_RESOURCES Cannot allocate resources
-
---*/
-{
- EFI_STATUS Status;
- EHCI_QTD_HW *QtdHwPtr;
-
- ASSERT (HcDev);
- ASSERT (QtdPtrPtr);
-
- //
- // Create memory for Qtd structure
- //
- Status = EhciAllocatePool (
- HcDev,
- (UINT8 **) QtdPtrPtr,
- sizeof (EHCI_QTD_ENTITY)
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_OUT_OF_RESOURCES;
- goto exit;
- }
-
- //
- // Software field
- //
- (*QtdPtrPtr)->TotalBytes = (UINT32) DataLen;
- (*QtdPtrPtr)->StaticTotalBytes = (UINT32) DataLen;
- (*QtdPtrPtr)->Prev = NULL;
- (*QtdPtrPtr)->Next = NULL;
-
- //
- // Hardware field
- //
- QtdHwPtr = &((*QtdPtrPtr)->Qtd);
- QtdHwPtr->NextQtdPointer = 0;
- QtdHwPtr->NextQtdTerminate = TRUE;
- QtdHwPtr->AltNextQtdPointer = 0;
- QtdHwPtr->AltNextQtdTerminate = TRUE;
- QtdHwPtr->DataToggle = Toggle;
- QtdHwPtr->TotalBytes = (UINT32) DataLen;
- QtdHwPtr->CurrentPage = 0;
- QtdHwPtr->ErrorCount = QTD_ERROR_COUNTER;
- QtdHwPtr->Status = QtdStatus;
- QtdHwPtr->Rsvd1 = 0;
- QtdHwPtr->Rsvd2 = 0;
- QtdHwPtr->Rsvd3 = 0;
- QtdHwPtr->Rsvd4 = 0;
- QtdHwPtr->Rsvd5 = 0;
- QtdHwPtr->Rsvd6 = 0;
-
- //
- // Set PacketID [Setup/Data/Status]
- //
- switch (PktId) {
- case SETUP_PACKET_ID:
- QtdHwPtr->PidCode = SETUP_PACKET_PID_CODE;
- break;
-
- case INPUT_PACKET_ID:
- QtdHwPtr->PidCode = INPUT_PACKET_PID_CODE;
- break;
-
- case OUTPUT_PACKET_ID:
- QtdHwPtr->PidCode = OUTPUT_PACKET_PID_CODE;
- break;
-
- default:
- Status = EFI_INVALID_PARAMETER;
- goto exit;
- }
-
- //
- // Set Data Buffer Pointers
- //
- if (NULL != DataPtr) {
- SetQtdBufferPointer (
- QtdHwPtr,
- DataPtr,
- DataLen
- );
- (*QtdPtrPtr)->StaticCurrentOffset = QtdHwPtr->CurrentOffset;
- }
-
-exit:
- return Status;
-}
-
-EFI_STATUS
-CreateSetupQtd (
- IN USB2_HC_DEV *HcDev,
- IN UINT8 *DevReqPtr,
- OUT EHCI_QTD_ENTITY **QtdPtrPtr
- )
-/*++
-
-Routine Description:
-
- Create Qtd Structure for Setup
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- DevReqPtr - A pointer to Device Request Data
- QtdPtrPtr - A pointer of pointer to Qtd for return
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_OUT_OF_RESOURCES Cannot allocate resources
-
---*/
-{
- return CreateQtd (
- HcDev,
- DevReqPtr,
- sizeof (EFI_USB_DEVICE_REQUEST),
- SETUP_PACKET_ID,
- DATA0,
- QTD_STATUS_ACTIVE,
- QtdPtrPtr
- );
-}
-
-EFI_STATUS
-CreateDataQtd (
- IN USB2_HC_DEV *HcDev,
- IN UINT8 *DataPtr,
- IN UINTN DataLen,
- IN UINT8 PktId,
- IN UINT8 Toggle,
- OUT EHCI_QTD_ENTITY **QtdPtrPtr
- )
-/*++
-
-Routine Description:
-
- Create Qtd Structure for data
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- DataPtr - A pointer to user data buffer to transfer
- DataLen - Length of user data to transfer
- PktId - Packet Identification of this Qtd
- Toggle - Data Toggle of this Qtd
- QtdPtrPtr - A pointer of pointer to Qtd for return
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_OUT_OF_RESOURCES Cannot allocate resources
-
---*/
-{
- return CreateQtd (
- HcDev,
- DataPtr,
- DataLen,
- PktId,
- Toggle,
- QTD_STATUS_ACTIVE,
- QtdPtrPtr
- );
-}
-
-EFI_STATUS
-CreateAltQtd (
- IN USB2_HC_DEV *HcDev,
- IN UINT8 PktId,
- OUT EHCI_QTD_ENTITY **QtdPtrPtr
- )
-/*++
-
-Routine Description:
-
- Create Qtd Structure for Alternative
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- PktId - Packet Identification of this Qtd
- QtdPtrPtr - A pointer of pointer to Qtd for return
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_OUT_OF_RESOURCES Cannot allocate resources
-
---*/
-{
- return CreateQtd (
- HcDev,
- NULL,
- 0,
- PktId,
- 0,
- QTD_STATUS_ACTIVE,
- QtdPtrPtr
- );
-}
-
-EFI_STATUS
-CreateStatusQtd (
- IN USB2_HC_DEV *HcDev,
- IN UINT8 PktId,
- OUT EHCI_QTD_ENTITY **QtdPtrPtr
- )
-/*++
-
-Routine Description:
-
- Create Qtd Structure for status
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- PktId - Packet Identification of this Qtd
- QtdPtrPtr - A pointer of pointer to Qtd for return
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_OUT_OF_RESOURCES Cannot allocate resources
-
---*/
-{
- return CreateQtd (
- HcDev,
- NULL,
- 0,
- PktId,
- DATA1,
- QTD_STATUS_ACTIVE,
- QtdPtrPtr
- );
-}
-
-EFI_STATUS
-CreateControlQtds (
- IN USB2_HC_DEV *HcDev,
- IN UINT8 DataPktId,
- IN UINT8 *RequestCursor,
- IN UINT8 *DataCursor,
- IN UINTN DataLen,
- IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator,
- OUT EHCI_QTD_ENTITY **ControlQtdsHead
- )
-/*++
-
-Routine Description:
-
- Create Qtds list for Control Transfer
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- DataPktId - Packet Identification of Data Qtds
- RequestCursor - A pointer to request structure buffer to transfer
- DataCursor - A pointer to user data buffer to transfer
- DataLen - Length of user data to transfer
- ControlQtdsHead - A pointer of pointer to first Qtd for control tranfer for return
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_OUT_OF_RESOURCES Cannot allocate resources
-
---*/
-{
- EFI_STATUS Status;
- EHCI_QTD_ENTITY *QtdPtr;
- EHCI_QTD_ENTITY *PreQtdPtr;
- EHCI_QTD_ENTITY *SetupQtdPtr;
- EHCI_QTD_ENTITY *FirstDataQtdPtr;
- EHCI_QTD_ENTITY *LastDataQtdPtr;
- EHCI_QTD_ENTITY *StatusQtdPtr;
- UINT8 DataToggle;
- UINT8 StatusPktId;
- UINTN CapacityOfQtd;
- UINTN SizePerQtd;
- UINTN DataCount;
-
- QtdPtr = NULL;
- PreQtdPtr = NULL;
- SetupQtdPtr = NULL;
- FirstDataQtdPtr = NULL;
- LastDataQtdPtr = NULL;
- StatusQtdPtr = NULL;
- CapacityOfQtd = 0;
-
- //
- // Setup Stage of Control Transfer
- //
- Status = CreateSetupQtd (
- HcDev,
- RequestCursor,
- &SetupQtdPtr
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_OUT_OF_RESOURCES;
- goto exit;
- }
-
- //
- // Data Stage of Control Transfer
- //
- DataToggle = 1;
- DataCount = DataLen;
-
- //
- // Create Qtd structure and link together
- //
- while (DataCount > 0) {
- //
- // PktSize is the data load size that each Qtd.
- //
- CapacityOfQtd = GetCapacityOfQtd (DataCursor);
- SizePerQtd = DataCount;
- if (DataCount > CapacityOfQtd) {
- SizePerQtd = CapacityOfQtd;
- }
-
- Status = CreateDataQtd (
- HcDev,
- DataCursor,
- SizePerQtd,
- DataPktId,
- DataToggle,
- &QtdPtr
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_OUT_OF_RESOURCES;
- if (NULL == FirstDataQtdPtr) {
- goto destory_setup_qtd;
- } else {
- goto destory_qtds;
- }
- }
-
- if (NULL == FirstDataQtdPtr) {
- FirstDataQtdPtr = QtdPtr;
- } else {
- LinkQtdToQtd (PreQtdPtr, QtdPtr);
- }
-
- DataToggle ^= 1;
-
- PreQtdPtr = QtdPtr;
- DataCursor += SizePerQtd;
- DataCount -= SizePerQtd;
- }
-
- LastDataQtdPtr = QtdPtr;
-
- //
- // Status Stage of Control Transfer
- //
- if (OUTPUT_PACKET_ID == DataPktId) {
- StatusPktId = INPUT_PACKET_ID;
- } else {
- StatusPktId = OUTPUT_PACKET_ID;
- }
-
- Status = CreateStatusQtd (
- HcDev,
- StatusPktId,
- &StatusQtdPtr
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_OUT_OF_RESOURCES;
- goto destory_qtds;
- }
-
- //
- // Link setup Qtd -> data Qtds -> status Qtd
- //
- if (FirstDataQtdPtr != NULL) {
- LinkQtdToQtd (SetupQtdPtr, FirstDataQtdPtr);
- LinkQtdToQtd (LastDataQtdPtr, StatusQtdPtr);
- } else {
- LinkQtdToQtd (SetupQtdPtr, StatusQtdPtr);
- }
-
- *ControlQtdsHead = SetupQtdPtr;
-
- goto exit;
-
-destory_qtds:
- DestoryQtds (HcDev, FirstDataQtdPtr);
-destory_setup_qtd:
- DestoryQtds (HcDev, SetupQtdPtr);
-exit:
- return Status;
-}
-
-EFI_STATUS
-CreateBulkOrInterruptQtds (
- IN USB2_HC_DEV *HcDev,
- IN UINT8 PktId,
- IN UINT8 *DataCursor,
- IN UINTN DataLen,
- IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator,
- OUT EHCI_QTD_ENTITY **QtdsHead
- )
-/*++
-
-Routine Description:
-
- Create Qtds list for Bulk or Interrupt Transfer
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- PktId - Packet Identification of Qtds
- DataCursor - A pointer to user data buffer to transfer
- DataLen - Length of user data to transfer
- DataToggle - Data Toggle to start
- Translator - Translator Transaction for SplitX
- QtdsHead - A pointer of pointer to first Qtd for control tranfer for return
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_OUT_OF_RESOURCES Cannot allocate resources
-
---*/
-{
- EFI_STATUS Status;
- EHCI_QTD_ENTITY *QtdPtr;
- EHCI_QTD_ENTITY *PreQtdPtr;
- EHCI_QTD_ENTITY *FirstQtdPtr;
- EHCI_QTD_ENTITY *AltQtdPtr;
- UINTN DataCount;
- UINTN CapacityOfQtd;
- UINTN SizePerQtd;
-
- Status = EFI_SUCCESS;
- QtdPtr = NULL;
- PreQtdPtr = NULL;
- FirstQtdPtr = NULL;
- AltQtdPtr = NULL;
- CapacityOfQtd = 0;
-
- DataCount = DataLen;
- while (DataCount > 0) {
-
- CapacityOfQtd = GetCapacityOfQtd (DataCursor);
- SizePerQtd = DataCount;
- if (DataCount > CapacityOfQtd) {
- SizePerQtd = CapacityOfQtd;
- }
-
- Status = CreateDataQtd (
- HcDev,
- DataCursor,
- SizePerQtd,
- PktId,
- 0,
- &QtdPtr
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_OUT_OF_RESOURCES;
- if (NULL == FirstQtdPtr) {
- goto exit;
- } else {
- goto destory_qtds;
- }
- }
-
- if (NULL == FirstQtdPtr) {
- FirstQtdPtr = QtdPtr;
- } else {
- LinkQtdToQtd (PreQtdPtr, QtdPtr);
- }
-
- PreQtdPtr = QtdPtr;
- DataCursor += SizePerQtd;
- DataCount -= SizePerQtd;
- }
-
- //
- // Set Alternate Qtd
- //
- if (INPUT_PACKET_ID == PktId && 0 < GetNumberOfQtd (FirstQtdPtr)) {
- Status = CreateAltQtd (
- HcDev,
- PktId,
- &AltQtdPtr
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_OUT_OF_RESOURCES;
- goto destory_qtds;
- }
-
- LinkQtdsToAltQtd (FirstQtdPtr, AltQtdPtr);
- }
-
- *QtdsHead = FirstQtdPtr;
- goto exit;
-
-destory_qtds:
- DestoryQtds (HcDev, FirstQtdPtr);
-exit:
- return Status;
-}
-
-VOID
-DestoryQtds (
- IN USB2_HC_DEV *HcDev,
- IN EHCI_QTD_ENTITY *FirstQtdPtr
- )
-/*++
-
-Routine Description:
-
- Destory all Qtds in the list
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- FirstQtdPtr - A pointer to first Qtd in the list
-
-Returns:
-
- VOID
-
---*/
-{
- EHCI_QTD_ENTITY *PrevQtd;
- EHCI_QTD_ENTITY *NextQtd;
-
- if (!FirstQtdPtr) {
- goto exit;
- }
-
- PrevQtd = FirstQtdPtr;
-
- //
- // Delete all the Qtds.
- //
- do {
- NextQtd = PrevQtd->Next;
- EhciFreePool (HcDev, (UINT8 *) PrevQtd, sizeof (EHCI_QTD_ENTITY));
- PrevQtd = NextQtd;
- } while (NULL != PrevQtd);
-
-exit:
- return ;
-}
-
-UINTN
-GetNumberOfQtd (
- IN EHCI_QTD_ENTITY *FirstQtdPtr
- )
-/*++
-
-Routine Description:
-
- Number of Qtds in the list
-
-Arguments:
-
- FirstQtdPtr - A pointer to first Qtd in the list
-
-Returns:
-
- Number of Qtds in the list
-
---*/
-{
- UINTN Count;
- EHCI_QTD_ENTITY *QtdPtr;
- Count = 0;
- QtdPtr = FirstQtdPtr;
-
- while (NULL != QtdPtr) {
- Count++;
- QtdPtr = QtdPtr->Next;
- }
-
- return Count;
-}
-
-UINTN
-GetCapacityOfQtd (
- IN UINT8 *BufferCursor
- )
-/*++
-
-Routine Description:
-
- Get Size of First Qtd
-
-Arguments:
-
- BufferCursor - BufferCursor of the Qtd
-
-Returns:
-
- Size of First Qtd
-
---*/
-{
-
- if (EFI_PAGE_MASK & GET_0B_TO_31B (BufferCursor)) {
- return EFI_PAGE_SIZE * 4;
- } else {
- return EFI_PAGE_SIZE * 5;
- }
-
-}
-
-UINTN
-GetApproxiOfInterval (
- IN UINTN Interval
- )
-/*++
-
-Routine Description:
-
- Get the approximate value in the 2 index sequence
-
-Arguments:
-
- Interval - the value of interval
-
-Returns:
-
- approximate value of interval in the 2 index sequence
-
---*/
-{
- UINTN Orignate;
- UINTN Approxi;
-
- Orignate = Interval;
- Approxi = 1;
-
- while (Orignate != 1 && Orignate != 0) {
- Orignate = Orignate >> 1;
- Approxi = Approxi << 1;
- }
-
- if (Interval & (Approxi >> 1)) {
- Approxi = Approxi << 1;
- }
-
- return Approxi;
-}
-
-EHCI_QTD_HW *
-GetQtdAlternateNextPointer (
- IN EHCI_QTD_HW *HwQtdPtr
- )
-/*++
-
-Routine Description:
-
- Get Qtd alternate next pointer field
-
-Arguments:
-
- HwQtdPtr - A pointer to hardware Qtd structure
-
-Returns:
-
- A pointer to hardware alternate Qtd
-
---*/
-{
- EHCI_QTD_HW *Value;
-
- Value = NULL;
-
- if (!HwQtdPtr->AltNextQtdTerminate) {
- Value = (EHCI_QTD_HW *) GET_0B_TO_31B (HwQtdPtr->AltNextQtdPointer << 5);
- }
-
- return Value;
-}
-
-EHCI_QTD_HW *
-GetQtdNextPointer (
- IN EHCI_QTD_HW *HwQtdPtr
- )
-/*++
-
-Routine Description:
-
- Get Qtd next pointer field
-
-Arguments:
-
- HwQtdPtr - A pointer to hardware Qtd structure
-
-Returns:
-
- A pointer to next hardware Qtd structure
-
---*/
-{
- EHCI_QTD_HW *Value;
-
- Value = NULL;
-
- if (!HwQtdPtr->NextQtdTerminate) {
- Value = (EHCI_QTD_HW *) GET_0B_TO_31B (HwQtdPtr->NextQtdPointer << 5);
- }
-
- return Value;
-}
-
-VOID
-LinkQtdToQtd (
- IN EHCI_QTD_ENTITY * PreQtdPtr,
- IN EHCI_QTD_ENTITY * QtdPtr
- )
-/*++
-
-Routine Description:
-
- Link Qtds together
-
-Arguments:
-
- PreQtdPtr - A pointer to pre Qtd
- QtdPtr - A pointer to next Qtd
-
-Returns:
-
- VOID
-
---*/
-{
- EHCI_QTD_HW *QtdHwPtr;
-
- ASSERT(PreQtdPtr);
- ASSERT(QtdPtr);
-
- //
- // Software link
- //
- PreQtdPtr->Next = QtdPtr;
- QtdPtr->Prev = PreQtdPtr;
-
- //
- // Hardware link
- //
- QtdHwPtr = &(QtdPtr->Qtd);
- PreQtdPtr->Qtd.NextQtdPointer = (UINT32) (GET_0B_TO_31B(QtdHwPtr) >> 5);
- PreQtdPtr->Qtd.NextQtdTerminate = FALSE;
-
- return ;
-}
-
-
-VOID
-LinkQtdsToAltQtd (
- IN EHCI_QTD_ENTITY * FirstQtdPtr,
- IN EHCI_QTD_ENTITY * AltQtdPtr
- )
-/*++
-
-Routine Description:
-
- Link AlterQtds together
-
-Arguments:
-
- FirstQtdPtr - A pointer to first Qtd in the list
- AltQtdPtr - A pointer to alternative Qtd
-
-Returns:
-
- VOID
-
---*/
-{
- EHCI_QTD_ENTITY *QtdPtr;
- EHCI_QTD_HW *AltQtdHwPtr;
-
- ASSERT(FirstQtdPtr);
- ASSERT(AltQtdPtr);
-
- AltQtdHwPtr = &(AltQtdPtr->Qtd);
- QtdPtr = FirstQtdPtr;
-
- while (NULL != QtdPtr) {
- //
- // Software link
- //
- QtdPtr->AltNext = AltQtdPtr;
- //
- // Hardware link
- //
- QtdPtr->Qtd.AltNextQtdPointer = (UINT32) (GET_0B_TO_31B(AltQtdHwPtr) >> 5);
- QtdPtr->Qtd.AltNextQtdTerminate = FALSE;
- QtdPtr = QtdPtr->Next;
- }
-
- return ;
-}
-
-VOID
-LinkQtdToQh (
- IN EHCI_QH_ENTITY *QhPtr,
- IN EHCI_QTD_ENTITY *QtdPtr
- )
-/*++
-
-Routine Description:
-
- Link Qtds list to Qh
-
-Arguments:
-
- QhPtr - A pointer to Qh
- QtdPtr - A pointer to first Qtd in the list
-
-Returns:
-
- VOID
-
---*/
-{
- EHCI_QTD_ENTITY *Cursor;
- EHCI_QTD_HW *QtdHwPtr;
-
- ASSERT (QhPtr);
- ASSERT (QtdPtr);
-
- QhPtr->FirstQtdPtr = QtdPtr;
- if (NULL != QtdPtr->AltNext) {
- QhPtr->AltQtdPtr = QtdPtr->AltNext;
- }
-
- Cursor = QtdPtr;
- while (NULL != Cursor) {
- Cursor->SelfQh = QhPtr;
- if (NULL == Cursor->Next) {
- QhPtr->LastQtdPtr = Cursor;
- }
-
- Cursor = Cursor->Next;
- }
-
- QtdHwPtr = &(QtdPtr->Qtd);
- QhPtr->Qh.NextQtdPointer = (UINT32) (GET_0B_TO_31B (QtdHwPtr) >> 5);
- QhPtr->Qh.NextQtdTerminate = FALSE;
-
- QhPtr->Qh.AltNextQtdPointer = 0;
- QhPtr->Qh.AltNextQtdTerminate = TRUE;
-
-
- if ((QtdPtr->Qtd.PidCode == OUTPUT_PACKET_PID_CODE) &&
- (QhPtr->TransferType == BULK_TRANSFER)) {
- //
- //Start PING first
- //
- QhPtr->Qh.Status |= QTD_STATUS_DO_PING;
- }
-
- return ;
-}
-
-EFI_STATUS
-LinkQhToAsyncList (
- IN USB2_HC_DEV *HcDev,
- IN EHCI_QH_ENTITY *QhPtr
- )
-/*++
-
-Routine Description:
-
- Link Qh to Async Schedule List
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- QhPtr - A pointer to Qh
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-{
- EFI_STATUS Status;
-
- ASSERT (HcDev);
- ASSERT (QhPtr);
-
-
- //
- // NULL QH created before
- //
-
- HcDev->NULLQH->Next = QhPtr;
- HcDev->NULLQH->Prev = QhPtr;
-
- QhPtr->Next = HcDev->NULLQH;
- QhPtr->Prev = HcDev->NULLQH;
-
-
- HcDev->NULLQH->Qh.QhHorizontalPointer = (UINT32) (GET_0B_TO_31B (&(QhPtr->Qh) >> 5));
- QhPtr->Qh.QhHorizontalPointer = (UINT32) (GET_0B_TO_31B (&(HcDev->NULLQH->Qh) >> 5));
-
-
- Status = SetAsyncListAddr (HcDev, HcDev->NULLQH);
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- if (!IsAsyncScheduleEnabled (HcDev)) {
-
- Status = EnableAsynchronousSchedule (HcDev);
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- Status = WaitForAsyncScheduleEnable (HcDev, EHCI_GENERIC_TIMEOUT);
- if (EFI_ERROR (Status)) {
- DEBUG ((gEHCDebugLevel, "EHCI: WaitForAsyncScheduleEnable TimeOut"));
- Status = EFI_TIMEOUT;
- goto exit;
- }
-
- if (IsEhcHalted (HcDev)) {
- Status = StartScheduleExecution (HcDev);
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- }
- }
-
- }
-
-exit:
- return Status;
-}
-
-EFI_STATUS
-UnlinkQhFromAsyncList (
- IN USB2_HC_DEV *HcDev,
- IN EHCI_QH_ENTITY *QhPtr
- )
-/*++
-
-Routine Description:
-
- Unlink Qh from Async Schedule List
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- QhPtr - A pointer to Qh
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-{
- EFI_STATUS Status;
-
- Status = EFI_SUCCESS;
-
- ASSERT (HcDev);
- ASSERT (QhPtr);
-
-
- HcDev->NULLQH->Next = HcDev->NULLQH;
- HcDev->NULLQH->Prev = HcDev->NULLQH;
-
-
- QhPtr->Next = QhPtr;
- QhPtr->Prev = QhPtr;
-
- HcDev->NULLQH->Qh.QhHorizontalPointer = (UINT32) (GET_0B_TO_31B (&(HcDev->NULLQH->Qh) >> 5));
-
-
- SetAndWaitDoorBell (HcDev, 2 * EHCI_GENERIC_TIMEOUT);
-
- QhPtr->Qh.QhTerminate = 1;
- QhPtr->Qh.QhHorizontalPointer = 0;
-
-
- Status = DisableAsynchronousSchedule (HcDev);
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- Status = WaitForAsyncScheduleDisable (HcDev, EHCI_GENERIC_TIMEOUT);
- if (EFI_ERROR (Status)) {
- DEBUG ((gEHCErrorLevel, "EHCI: WaitForAsyncScheduleDisable TimeOut\n"));
- Status = EFI_TIMEOUT;
- goto exit;
- }
-
-
-exit:
- return Status;
-}
-
-VOID
-LinkQhToPeriodicList (
- IN USB2_HC_DEV *HcDev,
- IN EHCI_QH_ENTITY *QhPtr
- )
-/*++
-
-Routine Description:
-
- Link Qh to Periodic Schedule List
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- QhPtr - A pointer to Qh
-
-Returns:
-
- VOID
-
---*/
-{
- FRAME_LIST_ENTRY *FrameEntryPtr;
- EHCI_QH_ENTITY *FindQhPtr;
- EHCI_QH_HW *FindQhHwPtr;
- UINTN FrameIndex;
-
- ASSERT (HcDev);
- ASSERT (QhPtr);
-
- FindQhPtr = NULL;
- FindQhHwPtr = NULL;
- FrameIndex = 0;
- FrameEntryPtr = (FRAME_LIST_ENTRY *) HcDev->PeriodicFrameListBuffer;
-
- QhPtr->Qh.HeadReclamationFlag = FALSE;
-
- if (QhPtr->TransferType == ASYNC_INTERRUPT_TRANSFER) {
-
- //
- // AsyncInterruptTransfer Qh
- //
-
- //
- // Link to Frame[0] List
- //
- if (!FrameEntryPtr->LinkTerminate) {
- //
- // Not Null FrameList
- //
- FindQhHwPtr = (EHCI_QH_HW *) GET_0B_TO_31B (FrameEntryPtr->LinkPointer << 5);
- FindQhPtr = (EHCI_QH_ENTITY *) GET_QH_ENTITY_ADDR (FindQhHwPtr);
- //
- // FindQh is Left/Right to Qh
- //
- while ((NULL != FindQhPtr->Next) && (FindQhPtr->Interval > QhPtr->Interval)) {
- FindQhPtr = FindQhPtr->Next;
- }
-
- if (FindQhPtr->Interval == QhPtr->Interval) {
- //
- // Link Qh after FindQh
- //
- if (NULL != FindQhPtr->Next) {
- FindQhPtr->Next->Prev = QhPtr;
- QhPtr->Qh.QhHorizontalPointer = (UINT32) GET_0B_TO_31B (&(FindQhPtr->Next->Qh) >> 5);
- QhPtr->Qh.SelectType = QH_SELECT_TYPE;
- QhPtr->Qh.QhTerminate = FALSE;
- }
-
- FindQhPtr->Qh.QhHorizontalPointer = (UINT32) GET_0B_TO_31B (&(QhPtr->Qh) >> 5);
- FindQhPtr->Qh.SelectType = QH_SELECT_TYPE;
- FindQhPtr->Qh.QhTerminate = FALSE;
-
- QhPtr->Prev = FindQhPtr;
- QhPtr->Next = FindQhPtr->Next;
- FindQhPtr->Next = QhPtr;
- } else if (FindQhPtr->Interval < QhPtr->Interval) {
- //
- // Link Qh before FindQh
- //
- if (NULL == FindQhPtr->Prev) {
- //
- // Qh is the First one in Frame[0] List
- //
- FrameEntryPtr->LinkPointer = (UINT32) GET_0B_TO_31B (&(QhPtr->Qh) >> 5);
- FrameEntryPtr->SelectType = QH_SELECT_TYPE;
- FrameEntryPtr->LinkTerminate = FALSE;
- } else {
- //
- // Qh is not the First one in Frame[0] List
- //
- FindQhPtr->Prev->Next = QhPtr;
- FindQhPtr->Prev->Qh.QhHorizontalPointer = (UINT32) GET_0B_TO_31B (&(QhPtr->Qh) >> 5);
- FindQhPtr->Prev->Qh.SelectType = QH_SELECT_TYPE;
- FindQhPtr->Prev->Qh.QhTerminate = FALSE;
- }
-
- QhPtr->Qh.QhHorizontalPointer = (UINT32) GET_0B_TO_31B (&(FindQhPtr->Qh) >> 5);
- QhPtr->Qh.SelectType = QH_SELECT_TYPE;
- QhPtr->Qh.QhTerminate = FALSE;
-
- QhPtr->Next = FindQhPtr;
- QhPtr->Prev = FindQhPtr->Prev;
- FindQhPtr->Prev = QhPtr;
- } else {
- //
- // Link Qh after FindQh, Qh is the Last one
- //
- FindQhPtr->Qh.QhHorizontalPointer = (UINT32) GET_0B_TO_31B (&(QhPtr->Qh) >> 5);
- FindQhPtr->Prev->Qh.SelectType = QH_SELECT_TYPE;
- FindQhPtr->Qh.QhTerminate = FALSE;
-
- QhPtr->Prev = FindQhPtr;
- QhPtr->Next = NULL;
- FindQhPtr->Next = QhPtr;
- }
- } else {
- //
- // Null FrameList
- //
- FrameEntryPtr->LinkPointer = (UINT32) GET_0B_TO_31B (&(QhPtr->Qh) >> 5);
- FrameEntryPtr->SelectType = QH_SELECT_TYPE;
- FrameEntryPtr->LinkTerminate = FALSE;
- }
- //
- // Other Frame[X]
- //
- if (NULL == QhPtr->Prev) {
- //
- // Qh is the First one in Frame[0] List
- //
- FrameIndex += QhPtr->Interval;
- while (FrameIndex < HcDev->PeriodicFrameListLength) {
- FrameEntryPtr = (FRAME_LIST_ENTRY *) (FrameEntryPtr + QhPtr->Interval);
- FrameEntryPtr->LinkPointer = (UINT32) GET_0B_TO_31B (&(QhPtr->Qh) >> 5);
- FrameEntryPtr->SelectType = QH_SELECT_TYPE;
- FrameEntryPtr->LinkTerminate = FALSE;
- FrameIndex += QhPtr->Interval;
- }
- } else if (QhPtr->Interval < QhPtr->Prev->Interval) {
- //
- // Qh is not the First one in Frame[0] List, and Prev.interval > Qh.interval
- //
- FrameIndex += QhPtr->Interval;
- while (FrameIndex < HcDev->PeriodicFrameListLength) {
- FrameEntryPtr = (FRAME_LIST_ENTRY *) (FrameEntryPtr + QhPtr->Interval);
- if ((FrameIndex % QhPtr->Prev->Interval) != 0) {
- FrameEntryPtr->LinkPointer = (UINT32) GET_0B_TO_31B (&(QhPtr->Qh) >> 5);
- FrameEntryPtr->SelectType = QH_SELECT_TYPE;
- FrameEntryPtr->LinkTerminate = FALSE;
- }
-
- FrameIndex += QhPtr->Interval;
- }
- }
- } else {
-
- //
- // SyncInterruptTransfer Qh
- //
-
- if (!FrameEntryPtr->LinkTerminate) {
- //
- // Not Null FrameList
- //
- FindQhHwPtr = (EHCI_QH_HW *) GET_0B_TO_31B (FrameEntryPtr->LinkPointer << 5);
- FindQhPtr = (EHCI_QH_ENTITY *) GET_QH_ENTITY_ADDR (FindQhHwPtr);
- //
- // FindQh is Last Qh in the Asynchronous List, Link Qh after FindQh
- //
- while (NULL != FindQhPtr->Next) {
- FindQhPtr = FindQhPtr->Next;
- }
-
- FindQhPtr->Qh.QhHorizontalPointer = (UINT32) GET_0B_TO_31B (&(QhPtr->Qh) >> 5);
- FindQhPtr->Qh.SelectType = QH_SELECT_TYPE;
- FindQhPtr->Qh.QhTerminate = FALSE;
-
- FindQhPtr->Next = QhPtr;
- QhPtr->Prev = FindQhPtr;
- } else {
- //
- // Null FrameList
- //
- FrameEntryPtr->LinkPointer = (UINT32) GET_0B_TO_31B (&(QhPtr->Qh) >> 5);
- FrameEntryPtr->SelectType = QH_SELECT_TYPE;
- FrameEntryPtr->LinkTerminate = FALSE;
- }
- }
-
- return ;
-}
-
-VOID
-UnlinkQhFromPeriodicList (
- IN USB2_HC_DEV *HcDev,
- IN EHCI_QH_ENTITY *QhPtr,
- IN UINTN Interval
- )
-/*++
-
-Routine Description:
-
- Unlink Qh from Periodic Schedule List
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- QhPtr - A pointer to Qh
- Interval - Interval of this periodic transfer
-
-Returns:
-
- VOID
-
---*/
-{
- FRAME_LIST_ENTRY *FrameEntryPtr;
- UINTN FrameIndex;
-
- FrameIndex = 0;
-
- ASSERT (HcDev);
- ASSERT (QhPtr);
-
- FrameIndex = 0;
- FrameEntryPtr = (FRAME_LIST_ENTRY *) HcDev->PeriodicFrameListBuffer;
-
- if (QhPtr->TransferType == ASYNC_INTERRUPT_TRANSFER) {
-
- //
- // AsyncInterruptTransfer Qh
- //
-
- if (NULL == QhPtr->Prev) {
- //
- // Qh is the First one on Frame[0] List
- //
- if (NULL == QhPtr->Next) {
- //
- // Only one on Frame[0] List
- //
- while (FrameIndex < HcDev->PeriodicFrameListLength) {
- FrameEntryPtr->LinkPointer = 0;
- FrameEntryPtr->SelectType = 0;
- FrameEntryPtr->LinkTerminate = TRUE;
- FrameEntryPtr += Interval;
- FrameIndex += Interval;
- }
- } else {
- while (FrameIndex < HcDev->PeriodicFrameListLength) {
- FrameEntryPtr->LinkPointer = (UINT32) GET_0B_TO_31B (&(QhPtr->Next->Qh) >> 5);
- FrameEntryPtr->SelectType = QH_SELECT_TYPE;
- FrameEntryPtr->LinkTerminate = FALSE;
- FrameEntryPtr += Interval;
- FrameIndex += Interval;
- }
- }
- } else {
-
- //
- // Not First one on Frame[0] List
- //
- if (NULL == QhPtr->Next) {
- //
- // Qh is the Last one on Frame[0] List
- //
- QhPtr->Prev->Qh.QhHorizontalPointer = 0;
- QhPtr->Prev->Qh.SelectType = 0;
- QhPtr->Prev->Qh.QhTerminate = TRUE;
- } else {
- QhPtr->Prev->Qh.QhHorizontalPointer = (UINT32) GET_0B_TO_31B (&(QhPtr->Next->Qh) >> 5);
- QhPtr->Prev->Qh.SelectType = QH_SELECT_TYPE;
- QhPtr->Prev->Qh.QhTerminate = FALSE;
- }
-
- if (Interval == QhPtr->Prev->Interval) {
- //
- // Interval is the same as Prev
- // Not involed Frame[X]
- //
- } else {
- //
- // Other Frame[X]
- //
- while (FrameIndex < HcDev->PeriodicFrameListLength) {
- if ((FrameIndex % QhPtr->Prev->Interval) != 0) {
- FrameEntryPtr->LinkPointer = QhPtr->Prev->Qh.QhHorizontalPointer;
- FrameEntryPtr->SelectType = QhPtr->Prev->Qh.SelectType;
- FrameEntryPtr->LinkTerminate = QhPtr->Prev->Qh.QhTerminate;
- }
- FrameEntryPtr += Interval;
- FrameIndex += Interval;
- }
- }
- }
-
- if (NULL != QhPtr->Next) {
- QhPtr->Next->Prev = QhPtr->Prev;
- }
-
- if (NULL != QhPtr->Prev) {
- QhPtr->Prev->Next = QhPtr->Next;
- }
- } else {
- //
- // SyncInterruptTransfer Qh
- //
- if (NULL == QhPtr->Prev) {
- //
- // Qh is the only one Qh on Frame[0] List
- //
- FrameEntryPtr->LinkPointer = 0;
- FrameEntryPtr->SelectType = 0;
- FrameEntryPtr->LinkTerminate = TRUE;
- } else {
- QhPtr->Prev->Qh.QhHorizontalPointer = 0;
- QhPtr->Prev->Qh.SelectType = 0;
- QhPtr->Prev->Qh.QhTerminate = TRUE;
- }
-
- if (NULL != QhPtr->Prev) {
- QhPtr->Prev->Next = NULL;
- }
- }
-
- return ;
-}
-
-VOID
-LinkToAsyncReqeust (
- IN USB2_HC_DEV *HcDev,
- IN EHCI_ASYNC_REQUEST *AsyncRequestPtr
- )
-/*++
-
-Routine Description:
-
- Llink AsyncRequest Entry to Async Request List
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- AsyncRequestPtr - A pointer to Async Request Entry
-
-Returns:
-
- VOID
-
---*/
-{
- EHCI_ASYNC_REQUEST *CurrentPtr;
-
- CurrentPtr = HcDev->AsyncRequestList;
- HcDev->AsyncRequestList = AsyncRequestPtr;
- AsyncRequestPtr->Prev = NULL;
- AsyncRequestPtr->Next = CurrentPtr;
-
- if (NULL != CurrentPtr) {
- CurrentPtr->Prev = AsyncRequestPtr;
- }
-
- return ;
-}
-
-VOID
-UnlinkFromAsyncReqeust (
- IN USB2_HC_DEV *HcDev,
- IN EHCI_ASYNC_REQUEST *AsyncRequestPtr
- )
-/*++
-
-Routine Description:
-
- Unlink AsyncRequest Entry from Async Request List
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- AsyncRequestPtr - A pointer to Async Request Entry
-
-Returns:
-
- VOID
-
---*/
-{
- if (NULL == AsyncRequestPtr->Prev) {
- HcDev->AsyncRequestList = AsyncRequestPtr->Next;
- if (NULL != AsyncRequestPtr->Next) {
- AsyncRequestPtr->Next->Prev = NULL;
- }
- } else {
- AsyncRequestPtr->Prev->Next = AsyncRequestPtr->Next;
- if (NULL != AsyncRequestPtr->Next) {
- AsyncRequestPtr->Next->Prev = AsyncRequestPtr->Prev;
- }
- }
-
- return ;
-}
-
-VOID
-SetQtdBufferPointer (
- IN EHCI_QTD_HW *QtdHwPtr,
- IN VOID *DataPtr,
- IN UINTN DataLen
- )
-/*++
-
-Routine Description:
-
- Set data buffer pointers in Qtd
-
-Arguments:
-
- QtdHwPtr - A pointer to Qtd hardware structure
- DataPtr - A pointer to user data buffer
- DataLen - Length of the user data buffer
-
-Returns:
-
- VOID
-
---*/
-{
- UINTN RemainLen;
-
- ASSERT (QtdHwPtr);
- ASSERT (DataLen <= 5 * EFI_PAGE_SIZE);
-
- RemainLen = DataLen;
- //
- // Allow buffer address range across 4G.
- // But EFI_USB_MAX_BULK_BUFFER_NUM = 1, so don't allow
- // seperate buffer array.
- //
- //
- // Set BufferPointer0, ExtBufferPointer0 and Offset
- //
- QtdHwPtr->BufferPointer0 = (UINT32) (GET_0B_TO_31B (DataPtr) >> EFI_PAGE_SHIFT);
- QtdHwPtr->CurrentOffset = (UINT32) (GET_0B_TO_31B (DataPtr) & EFI_PAGE_MASK);
-
- //
- // Set BufferPointer1 and ExtBufferPointer1
- //
- RemainLen = RemainLen > (EFI_PAGE_SIZE - QtdHwPtr->CurrentOffset) ? (RemainLen - (EFI_PAGE_SIZE - QtdHwPtr->CurrentOffset)) : 0;
- if (RemainLen == 0) {
- goto exit;
- }
-
- QtdHwPtr->BufferPointer1 = QtdHwPtr->BufferPointer0 + 1;
-
- //
- // Set BufferPointer2 and ExtBufferPointer2
- //
- RemainLen = RemainLen > EFI_PAGE_SIZE ? (RemainLen - EFI_PAGE_SIZE) : 0;
- if (RemainLen == 0) {
- goto exit;
- }
-
- QtdHwPtr->BufferPointer2 = QtdHwPtr->BufferPointer1 + 1;
-
- //
- // Set BufferPointer3 and ExtBufferPointer3
- //
- RemainLen = RemainLen > EFI_PAGE_SIZE ? (RemainLen - EFI_PAGE_SIZE) : 0;
- if (RemainLen == 0) {
- goto exit;
- }
-
- QtdHwPtr->BufferPointer3 = QtdHwPtr->BufferPointer2 + 1;
-
- //
- // Set BufferPointer4 and ExtBufferPointer4
- //
- RemainLen = RemainLen > EFI_PAGE_SIZE ? (RemainLen - EFI_PAGE_SIZE) : 0;
- if (RemainLen == 0) {
- goto exit;
- }
-
- QtdHwPtr->BufferPointer4 = QtdHwPtr->BufferPointer3 + 1;
-
-exit:
- return ;
-}
-
-BOOLEAN
-IsQtdStatusActive (
- IN EHCI_QTD_HW *HwQtdPtr
- )
-/*++
-
-Routine Description:
-
- Whether Qtd status is active or not
-
-Arguments:
-
- HwQtdPtr - A pointer to hardware Qtd structure
-
-Returns:
-
- TRUE Active
- FALSE Inactive
-
---*/
-{
- UINT8 QtdStatus;
- BOOLEAN Value;
-
- QtdStatus = (UINT8) (HwQtdPtr->Status);
- Value = (BOOLEAN) (QtdStatus & QTD_STATUS_ACTIVE);
- //DEBUG ((gEHCErrorLevel, "EHCI: IsQtdStatusActive 0x%X, Address = %x\r\n",HwQtdPtr->Status, HwQtdPtr));
-
- return Value;
-}
-
-BOOLEAN
-IsQtdStatusHalted (
- IN EHCI_QTD_HW *HwQtdPtr
- )
-/*++
-
-Routine Description:
-
- Whether Qtd status is halted or not
-
-Arguments:
-
- HwQtdPtr - A pointer to hardware Qtd structure
-
-Returns:
-
- TRUE Halted
- FALSE Not halted
-
---*/
-{
- UINT8 QtdStatus;
- BOOLEAN Value;
-
- QtdStatus = (UINT8) (HwQtdPtr->Status);
- Value = (BOOLEAN) (QtdStatus & QTD_STATUS_HALTED);
-
- return Value;
-}
-
-BOOLEAN
-IsQtdStatusBufferError (
- IN EHCI_QTD_HW *HwQtdPtr
- )
-/*++
-
-Routine Description:
-
- Whether Qtd status is buffer error or not
-
-Arguments:
-
- HwQtdPtr - A pointer to hardware Qtd structure
-
-Returns:
-
- TRUE Buffer error
- FALSE No buffer error
-
---*/
-{
- UINT8 QtdStatus;
- BOOLEAN Value;
-
- QtdStatus = (UINT8) (HwQtdPtr->Status);
- Value = (BOOLEAN) (QtdStatus & QTD_STATUS_BUFFER_ERR);
-
- return Value;
-}
-
-BOOLEAN
-IsQtdStatusBabbleError (
- IN EHCI_QTD_HW *HwQtdPtr
- )
-/*++
-
-Routine Description:
-
- Whether Qtd status is babble error or not
-
-Arguments:
-
- HwQtdPtr - A pointer to hardware Qtd structure
-
-Returns:
-
- TRUE Babble error
- FALSE No babble error
-
---*/
-{
- UINT8 QtdStatus;
- BOOLEAN Value;
-
- QtdStatus = (UINT8) (HwQtdPtr->Status);
- Value = (BOOLEAN) (QtdStatus & QTD_STATUS_BABBLE_ERR);
-
- return Value;
-}
-
-BOOLEAN
-IsQtdStatusTransactionError (
- IN EHCI_QTD_HW *HwQtdPtr
- )
-/*++
-
-Routine Description:
-
- Whether Qtd status is transaction error or not
-
-Arguments:
-
- HwQtdPtr - A pointer to hardware Qtd structure
-
-Returns:
-
- TRUE Transaction error
- FALSE No transaction error
-
---*/
-{
- UINT8 QtdStatus;
- BOOLEAN Value;
-
- QtdStatus = (UINT8) (HwQtdPtr->Status);
- Value = (BOOLEAN) (QtdStatus & QTD_STATUS_TRANSACTION_ERR);
-
- return Value;
-}
-
-BOOLEAN
-IsDataInTransfer (
- IN UINT8 EndPointAddress
- )
-/*++
-
-Routine Description:
-
- Whether is a DataIn direction transfer
-
-Arguments:
-
- EndPointAddress - address of the endpoint
-
-Returns:
-
- TRUE DataIn
- FALSE DataOut
-
---*/
-{
- BOOLEAN Value;
-
- if (EndPointAddress & 0x80) {
- Value = TRUE;
- } else {
- Value = FALSE;
- }
-
- return Value;
-}
-
-EFI_STATUS
-MapDataBuffer (
- IN USB2_HC_DEV *HcDev,
- IN EFI_USB_DATA_DIRECTION TransferDirection,
- IN VOID *Data,
- IN OUT UINTN *DataLength,
- OUT UINT8 *PktId,
- OUT UINT8 **DataCursor,
- OUT VOID **DataMap
- )
-/*++
-
-Routine Description:
-
- Map address of user data buffer
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- TransferDirection - direction of transfer
- Data - A pointer to user data buffer
- DataLength - length of user data
- PktId - Packte Identificaion
- DataCursor - mapped address to return
- DataMap - identificaion of this mapping to return
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-{
- EFI_STATUS Status;
- EFI_PHYSICAL_ADDRESS TempPhysicalAddr;
-
- Status = EFI_SUCCESS;
-
- switch (TransferDirection) {
-
- case EfiUsbDataIn:
-
- *PktId = INPUT_PACKET_ID;
- //
- // BusMasterWrite means cpu read
- //
- Status = HcDev->PciIo->Map (
- HcDev->PciIo,
- EfiPciIoOperationBusMasterWrite,
- Data,
- DataLength,
- &TempPhysicalAddr,
- DataMap
- );
- if (EFI_ERROR (Status)) {
- DEBUG ((gEHCDebugLevel, "EHCI: MapDataBuffer Failed\n"));
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- *DataCursor = (UINT8 *) ((UINTN) TempPhysicalAddr);
- break;
-
- case EfiUsbDataOut:
-
- *PktId = OUTPUT_PACKET_ID;
- //
- // BusMasterRead means cpu write
- //
- Status = HcDev->PciIo->Map (
- HcDev->PciIo,
- EfiPciIoOperationBusMasterRead,
- Data,
- DataLength,
- &TempPhysicalAddr,
- DataMap
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- *DataCursor = (UINT8 *) ((UINTN) TempPhysicalAddr);
- break;
-
- case EfiUsbNoData:
-
- *PktId = OUTPUT_PACKET_ID;
- Data = NULL;
- *DataLength = 0;
- *DataCursor = NULL;
- *DataMap = NULL;
- break;
-
- default:
-
- Status = EFI_INVALID_PARAMETER;
- }
-
-exit:
- return Status;
-}
-
-EFI_STATUS
-MapRequestBuffer (
- IN USB2_HC_DEV *HcDev,
- IN OUT VOID *Request,
- OUT UINT8 **RequestCursor,
- OUT VOID **RequestMap
- )
-/*++
-
-Routine Description:
-
- Map address of request structure buffer
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- Request - A pointer to request structure
- RequestCursor - Mapped address of request structure to return
- RequestMap - Identificaion of this mapping to return
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-{
- EFI_STATUS Status;
- UINTN RequestLen;
- EFI_PHYSICAL_ADDRESS TempPhysicalAddr;
-
- RequestLen = sizeof (EFI_USB_DEVICE_REQUEST);
- Status = HcDev->PciIo->Map (
- HcDev->PciIo,
- EfiPciIoOperationBusMasterRead,
- (UINT8 *) Request,
- (UINTN *) &RequestLen,
- &TempPhysicalAddr,
- RequestMap
- );
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- *RequestCursor = (UINT8 *) ((UINTN) TempPhysicalAddr);
-
-exit:
- return Status;
-}
-
-EFI_STATUS
-DeleteAsyncRequestTransfer (
- IN USB2_HC_DEV *HcDev,
- IN UINT8 DeviceAddress,
- IN UINT8 EndPointAddress,
- OUT UINT8 *DataToggle
- )
-/*++
-
-Routine Description:
-
- Delete all asynchronous request transfer
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- DeviceAddress - address of usb device
- EndPointAddress - address of endpoint
- DataToggle - stored data toggle
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-{
- EFI_STATUS Status;
- EHCI_ASYNC_REQUEST *AsyncRequestPtr;
- EHCI_ASYNC_REQUEST *MatchPtr;
- EHCI_QH_HW *QhHwPtr;
- UINT8 EndPointNum;
-
- if (NULL == HcDev->AsyncRequestList) {
- Status = EFI_INVALID_PARAMETER;
- goto exit;
- }
-
- MatchPtr = NULL;
- QhHwPtr = NULL;
- EndPointNum = (UINT8) (EndPointAddress & 0x0f);
- AsyncRequestPtr = HcDev->AsyncRequestList;
-
- //
- // Find QH of AsyncRequest by DeviceAddress and EndPointNum
- //
- do {
-
- QhHwPtr = &(AsyncRequestPtr->QhPtr->Qh);
- if (QhHwPtr->DeviceAddr == DeviceAddress && QhHwPtr->EndpointNum == EndPointNum) {
- MatchPtr = AsyncRequestPtr;
- break;
- }
-
- AsyncRequestPtr = AsyncRequestPtr->Next;
-
- } while (NULL != AsyncRequestPtr);
-
- if (NULL == MatchPtr) {
- Status = EFI_INVALID_PARAMETER;
- goto exit;
- }
-
- Status = DisablePeriodicSchedule (HcDev);
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- Status = WaitForPeriodicScheduleDisable (HcDev, EHCI_GENERIC_TIMEOUT);
- if (EFI_ERROR (Status)) {
- DEBUG ((gEHCErrorLevel, "EHCI: WaitForPeriodicScheduleDisable TimeOut\n"));
- Status = EFI_TIMEOUT;
- goto exit;
- }
-
- *DataToggle = (UINT8) MatchPtr->QhPtr->Qh.DataToggle;
- UnlinkQhFromPeriodicList (HcDev, MatchPtr->QhPtr, MatchPtr->QhPtr->Interval);
- UnlinkFromAsyncReqeust (HcDev, MatchPtr);
-
- if (NULL == HcDev->AsyncRequestList) {
-
- Status = StopPollingTimer (HcDev);
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- } else {
-
- Status = EnablePeriodicSchedule (HcDev);
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
-
- Status = WaitForPeriodicScheduleEnable (HcDev, EHCI_GENERIC_TIMEOUT);
- if (EFI_ERROR (Status)) {
- DEBUG ((gEHCErrorLevel, "EHCI: WaitForPeriodicScheduleEnable TimeOut\n"));
- Status = EFI_TIMEOUT;
- goto exit;
- }
-
- if (IsEhcHalted (HcDev)) {
- Status = StartScheduleExecution (HcDev);
- if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto exit;
- }
- }
-
- }
-
- DestoryQtds (HcDev, MatchPtr->QhPtr->FirstQtdPtr);
- DestoryQh (HcDev, MatchPtr->QhPtr);
- EhciFreePool (HcDev, (UINT8 *) MatchPtr, sizeof (EHCI_ASYNC_REQUEST));
-
-exit:
- return Status;
-}
-
-VOID
-CleanUpAllAsyncRequestTransfer (
- IN USB2_HC_DEV *HcDev
- )
-/*++
-
-Routine Description:
-
- Clean up all asynchronous request transfer
-
-Arguments:
-
- HcDev - USB2_HC_DEV
-
-Returns:
-
- VOID
-
---*/
-{
- EHCI_ASYNC_REQUEST *AsyncRequestPtr;
- EHCI_ASYNC_REQUEST *FreePtr;
-
- AsyncRequestPtr = NULL;
- FreePtr = NULL;
-
- StopPollingTimer (HcDev);
-
- AsyncRequestPtr = HcDev->AsyncRequestList;
- while (NULL != AsyncRequestPtr) {
-
- FreePtr = AsyncRequestPtr;
- AsyncRequestPtr = AsyncRequestPtr->Next;
- UnlinkFromAsyncReqeust (HcDev, FreePtr);
- UnlinkQhFromPeriodicList (HcDev, FreePtr->QhPtr, FreePtr->QhPtr->Interval);
- DestoryQtds (HcDev, FreePtr->QhPtr->FirstQtdPtr);
- DestoryQh (HcDev, FreePtr->QhPtr);
- EhciFreePool (HcDev, (UINT8 *) FreePtr, sizeof (EHCI_ASYNC_REQUEST));
-
- }
-
- return ;
-}
-
-VOID
-ZeroOutQhOverlay (
- IN EHCI_QH_ENTITY *QhPtr
- )
-/*++
-
-Routine Description:
-
- Zero out the fields in Qh structure
-
-Arguments:
-
- QhPtr - A pointer to Qh structure
-
-Returns:
-
- VOID
-
---*/
-{
- QhPtr->Qh.CurrentQtdPointer = 0;
- QhPtr->Qh.AltNextQtdPointer = 0;
- QhPtr->Qh.NakCount = 0;
- QhPtr->Qh.AltNextQtdTerminate = 0;
- QhPtr->Qh.TotalBytes = 0;
- QhPtr->Qh.InterruptOnComplete = 0;
- QhPtr->Qh.CurrentPage = 0;
- QhPtr->Qh.ErrorCount = 0;
- QhPtr->Qh.PidCode = 0;
- QhPtr->Qh.Status = 0;
- QhPtr->Qh.BufferPointer0 = 0;
- QhPtr->Qh.CurrentOffset = 0;
- QhPtr->Qh.BufferPointer1 = 0;
- QhPtr->Qh.CompleteSplitMask = 0;
- QhPtr->Qh.BufferPointer2 = 0;
- QhPtr->Qh.SplitBytes = 0;
- QhPtr->Qh.FrameTag = 0;
- QhPtr->Qh.BufferPointer3 = 0;
- QhPtr->Qh.BufferPointer4 = 0;
-}
-
-VOID
-UpdateAsyncRequestTransfer (
- IN EHCI_ASYNC_REQUEST *AsyncRequestPtr,
- IN UINT32 TransferResult,
- IN UINTN ErrQtdPos
- )
-/*++
-
-Routine Description:
-
- Update asynchronous request transfer
-
-Arguments:
-
- AsyncRequestPtr - A pointer to async request
- TransferResult - transfer result
- ErrQtdPos - postion of error Qtd
-
-Returns:
-
- VOID
-
---*/
-{
- EHCI_QTD_ENTITY *QtdPtr;
-
- QtdPtr = NULL;
-
- if (EFI_USB_NOERROR == TransferResult) {
-
- //
- // Update Qh for next trigger
- //
-
- QtdPtr = AsyncRequestPtr->QhPtr->FirstQtdPtr;
-
- //
- // Update fields in Qh
- //
-
- //
- // Get DataToggle from Overlay in Qh
- //
- // ZeroOut Overlay in Qh except DataToggle, HostController will update this field
- //
- ZeroOutQhOverlay (AsyncRequestPtr->QhPtr);
- AsyncRequestPtr->QhPtr->Qh.NextQtdPointer = (UINT32) (GET_0B_TO_31B (&(QtdPtr->Qtd)) >> 5);
- AsyncRequestPtr->QhPtr->Qh.NextQtdTerminate = FALSE;
-
- //
- // Update fields in Qtd
- //
- while (NULL != QtdPtr) {
- QtdPtr->Qtd.TotalBytes = QtdPtr->StaticTotalBytes;
- QtdPtr->Qtd.CurrentOffset = QtdPtr->StaticCurrentOffset;
- QtdPtr->Qtd.CurrentPage = 0;
- QtdPtr->Qtd.ErrorCount = QTD_ERROR_COUNTER;
- QtdPtr->Qtd.Status = QTD_STATUS_ACTIVE;
-
- QtdPtr->TotalBytes = QtdPtr->StaticTotalBytes;
- QtdPtr = QtdPtr->Next;
- }
- }
-
- return ;
-}
-
-BOOLEAN
-CheckQtdsTransferResult (
- IN BOOLEAN IsControl,
- IN EHCI_QH_ENTITY *QhPtr,
- OUT UINT32 *Result,
- OUT UINTN *ErrQtdPos,
- OUT UINTN *ActualLen
- )
-/*++
-
-Routine Description:
-
- Check transfer result of Qtds
-
-Arguments:
-
- IsControl - Is control transfer or not
- QhPtr - A pointer to Qh
- Result - Transfer result
- ErrQtdPos - Error TD Position
- ActualLen - Actual Transfer Size
-
-Returns:
-
- TRUE Qtds finished
- FALSE Not finish
-
---*/
-{
- UINTN ActualLenPerQtd;
- EHCI_QTD_ENTITY *QtdPtr;
- EHCI_QTD_HW *QtdHwPtr;
- BOOLEAN Value;
-
- ASSERT (QhPtr);
- ASSERT (Result);
- ASSERT (ErrQtdPos);
- ASSERT (ActualLen);
-
- Value = TRUE;
- QtdPtr = QhPtr->FirstQtdPtr;
- QtdHwPtr = &(QtdPtr->Qtd);
-
- while (NULL != QtdHwPtr) {
- if (IsQtdStatusActive (QtdHwPtr)) {
- *Result |= EFI_USB_ERR_NOTEXECUTE;
- }
-
- if (IsQtdStatusHalted (QtdHwPtr)) {
-
- DEBUG ((gEHCErrorLevel, "EHCI: QTD_STATUS_HALTED 0x%X\n", QtdHwPtr->Status));
- *Result |= EFI_USB_ERR_STALL;
- }
-
- if (IsQtdStatusBufferError (QtdHwPtr)) {
- DEBUG ((gEHCErrorLevel, "EHCI: QTD_STATUS_BUFFER_ERR 0x%X\n", QtdHwPtr->Status));
- *Result |= EFI_USB_ERR_BUFFER;
- }
-
- if (IsQtdStatusBabbleError (QtdHwPtr)) {
- DEBUG ((gEHCErrorLevel, "EHCI: StatusBufferError 0x%X\n", QtdHwPtr->Status));
- *Result |= EFI_USB_ERR_BABBLE;
- }
-
- if (IsQtdStatusTransactionError (QtdHwPtr)) {
-
- //
- //Exclude Special Case
- //
- if (((QtdHwPtr->Status & QTD_STATUS_HALTED) == QTD_STATUS_HALTED) ||
- ((QtdHwPtr->Status & QTD_STATUS_ACTIVE) == QTD_STATUS_ACTIVE) ||
- ((QtdHwPtr->ErrorCount != QTD_ERROR_COUNTER))) {
- *Result |= EFI_USB_ERR_TIMEOUT;
- DEBUG ((gEHCErrorLevel, "EHCI: QTD_STATUS_TRANSACTION_ERR: 0x%X\n", QtdHwPtr->Status));
- }
- }
-
- ActualLenPerQtd = QtdPtr->TotalBytes - QtdHwPtr->TotalBytes;
- QtdPtr->TotalBytes = QtdHwPtr->TotalBytes;
- //
- // Accumulate actual transferred data length in each DataQtd.
- //
- if (SETUP_PACKET_PID_CODE != QtdHwPtr->PidCode) {
- *ActualLen += ActualLenPerQtd;
- }
-
- if (*Result) {
- Value = FALSE;
- break;
- }
-
- if ((INPUT_PACKET_PID_CODE == QtdHwPtr->PidCode)&& (QtdPtr->TotalBytes > 0)) {
- //
- // Short Packet: IN, Short
- //
- DEBUG ((gEHCDebugLevel, "EHCI: Short Packet Status: 0x%x\n", QtdHwPtr->Status));
- break;
- }
-
- if (QtdPtr->Next != NULL) {
- (*ErrQtdPos)++;
- QtdPtr = QtdPtr->Next;
- QtdHwPtr = &(QtdPtr->Qtd);
- } else {
- QtdHwPtr = NULL;
- }
-
- }
-
- return Value;
-}
-
-EFI_STATUS
-ExecuteTransfer (
- IN USB2_HC_DEV *HcDev,
- IN BOOLEAN IsControl,
- IN EHCI_QH_ENTITY *QhPtr,
- IN OUT UINTN *ActualLen,
- OUT UINT8 *DataToggle,
- IN UINTN TimeOut,
- OUT UINT32 *TransferResult
- )
-/*++
-
-Routine Description:
-
- Execute Bulk or SyncInterrupt Transfer
-
-Arguments:
-
- HcDev - USB2_HC_DEV
- IsControl - Is control transfer or not
- QhPtr - A pointer to Qh
- ActualLen - Actual transfered Len
- DataToggle - Data Toggle
- TimeOut - TimeOut threshold
- TransferResult - Transfer result
-
-Returns:
-
- EFI_SUCCESS Sucess
- EFI_DEVICE_ERROR Fail
-
---*/
-{
- EFI_STATUS Status;
- UINTN ErrQtdPos;
- UINTN Delay;
- BOOLEAN Finished;
-
- Status = EFI_SUCCESS;
- ErrQtdPos = 0;
- *TransferResult = EFI_USB_NOERROR;
- *ActualLen = 0;
- Finished = FALSE;
-
- Delay = (TimeOut * STALL_1_MILLI_SECOND / 50);
-
- do {
- *TransferResult = 0;
- Finished = CheckQtdsTransferResult (
- IsControl,
- QhPtr,
- TransferResult,
- &ErrQtdPos,
- ActualLen
- );
- if (Finished) {
- break;
- }
- //
- // Qtd is inactive, which means bulk or interrupt transfer's end.
- //
- if (!(*TransferResult & EFI_USB_ERR_NOTEXECUTE)) {
- break;
- }
-
- gBS->Stall (EHCI_SYNC_REQUEST_POLLING_TIME);
-
- } while (--Delay);
-
- if (EFI_USB_NOERROR != *TransferResult) {
- if (0 == Delay) {
- DEBUG((gEHCErrorLevel, "EHCI: QTDS TimeOut\n"));
- Status = EFI_TIMEOUT;
- } else {
- Status = EFI_DEVICE_ERROR;
- }
- }
-
- //
- // Special for Bulk and Interrupt Transfer
- //
- *DataToggle = (UINT8) QhPtr->Qh.DataToggle;
-
- return Status;
-}
-
-EFI_STATUS
-AsyncRequestMoniter (
- IN EFI_EVENT Event,
- IN VOID *Context
- )
-/*++
-Routine Description:
-
- Interrupt transfer periodic check handler
-
-Arguments:
- Event - Interrupt event
- Context - Pointer to USB2_HC_DEV
-
-Returns:
-
- EFI_SUCCESS Success
- EFI_DEVICE_ERROR Fail
-
---*/
-{
- EFI_STATUS Status;
- USB2_HC_DEV *HcDev;
- EHCI_ASYNC_REQUEST *AsyncRequestPtr;
- EHCI_ASYNC_REQUEST *NextPtr;
- EHCI_QTD_HW *QtdHwPtr;
- UINTN ErrQtdPos;
- UINTN ActualLen;
- UINT32 TransferResult;
- UINT8 *ReceiveBuffer;
- UINT8 *ProcessBuffer;
-
- Status = EFI_SUCCESS;
- QtdHwPtr = NULL;
- ReceiveBuffer = NULL;
- ProcessBuffer = NULL;
- HcDev = (USB2_HC_DEV *) Context;
- AsyncRequestPtr = HcDev->AsyncRequestList;
-
- while (NULL != AsyncRequestPtr) {
-
- TransferResult = 0;
- ErrQtdPos = 0;
- ActualLen = 0;
-
- CheckQtdsTransferResult (
- FALSE,
- AsyncRequestPtr->QhPtr,
- &TransferResult,
- &ErrQtdPos,
- &ActualLen
- );
-
- if ((TransferResult & EFI_USB_ERR_NAK) || (TransferResult & EFI_USB_ERR_NOTEXECUTE)) {
- AsyncRequestPtr = AsyncRequestPtr->Next;
- continue;
- }
- //
- // Allocate memory for EHC private data structure
- //
- ProcessBuffer = AllocateZeroPool (ActualLen);
- if (NULL == ProcessBuffer) {
- Status = EFI_OUT_OF_RESOURCES;
- goto exit;
- }
-
- QtdHwPtr = &(AsyncRequestPtr->QhPtr->FirstQtdPtr->Qtd);
- ReceiveBuffer = (UINT8 *) GET_0B_TO_31B ((QtdHwPtr->BufferPointer0 << EFI_PAGE_SHIFT) | AsyncRequestPtr->QhPtr->FirstQtdPtr->StaticCurrentOffset);
- CopyMem (
- ProcessBuffer,
- ReceiveBuffer,
- ActualLen
- );
-
- UpdateAsyncRequestTransfer (AsyncRequestPtr, TransferResult, ErrQtdPos);
-
- NextPtr = AsyncRequestPtr->Next;
-
- if (EFI_USB_NOERROR == TransferResult) {
-
- if (AsyncRequestPtr->CallBackFunc != NULL) {
- (AsyncRequestPtr->CallBackFunc) (ProcessBuffer, ActualLen, AsyncRequestPtr->Context, TransferResult);
- }
-
- } else {
-
- //
- // leave error recovery to its related device driver. A common case of
- // the error recovery is to re-submit the interrupt transfer.
- // When an interrupt transfer is re-submitted, its position in the linked
- // list is changed. It is inserted to the head of the linked list, while
- // this function scans the whole list from head to tail. Thus, the
- // re-submitted interrupt transfer's callback function will not be called
- // again in this round.
- //
- if (AsyncRequestPtr->CallBackFunc != NULL) {
- (AsyncRequestPtr->CallBackFunc) (NULL, 0, AsyncRequestPtr->Context, TransferResult);
- }
-
- }
-
- if (NULL != ProcessBuffer) {
- gBS->FreePool (ProcessBuffer);
- }
-
- AsyncRequestPtr = NextPtr;
- }
-
-exit:
- return Status;
-}
-