2007-07-11 08:46:38 +02:00
|
|
|
/** @file
|
|
|
|
|
2008-07-08 12:26:16 +02:00
|
|
|
This file contains the definination for host controller register operation routines.
|
|
|
|
|
2012-04-28 07:02:54 +02:00
|
|
|
Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.<BR>
|
2010-04-24 11:49:11 +02:00
|
|
|
This program and the accompanying materials
|
2007-07-11 08:46:38 +02:00
|
|
|
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.
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#ifndef _EFI_EHCI_REG_H_
|
|
|
|
#define _EFI_EHCI_REG_H_
|
|
|
|
|
2010-01-19 07:42:21 +01:00
|
|
|
//
|
|
|
|
// EHCI register offset
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Capability register offset
|
|
|
|
//
|
|
|
|
#define EHC_CAPLENGTH_OFFSET 0 // Capability register length offset
|
|
|
|
#define EHC_HCSPARAMS_OFFSET 0x04 // Structural Parameters 04-07h
|
|
|
|
#define EHC_HCCPARAMS_OFFSET 0x08 // Capability parameters offset
|
|
|
|
|
|
|
|
//
|
|
|
|
// Capability register bit definition
|
|
|
|
//
|
|
|
|
#define HCSP_NPORTS 0x0F // Number of root hub port
|
2011-11-16 11:24:47 +01:00
|
|
|
#define HCSP_PPC 0x10 // Port Power Control
|
2010-01-19 07:42:21 +01:00
|
|
|
#define HCCP_64BIT 0x01 // 64-bit addressing capability
|
|
|
|
|
|
|
|
//
|
|
|
|
// Operational register offset
|
|
|
|
//
|
|
|
|
#define EHC_USBCMD_OFFSET 0x0 // USB command register offset
|
|
|
|
#define EHC_USBSTS_OFFSET 0x04 // Statue register offset
|
|
|
|
#define EHC_USBINTR_OFFSET 0x08 // USB interrutp offset
|
|
|
|
#define EHC_FRINDEX_OFFSET 0x0C // Frame index offset
|
|
|
|
#define EHC_CTRLDSSEG_OFFSET 0x10 // Control data structure segment offset
|
|
|
|
#define EHC_FRAME_BASE_OFFSET 0x14 // Frame list base address offset
|
|
|
|
#define EHC_ASYNC_HEAD_OFFSET 0x18 // Next asynchronous list address offset
|
|
|
|
#define EHC_CONFIG_FLAG_OFFSET 0x40 // Configure flag register offset
|
|
|
|
#define EHC_PORT_STAT_OFFSET 0x44 // Port status/control offset
|
|
|
|
|
|
|
|
#define EHC_FRAME_LEN 1024
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2010-01-19 07:42:21 +01:00
|
|
|
//
|
|
|
|
// Register bit definition
|
|
|
|
//
|
|
|
|
#define CONFIGFLAG_ROUTE_EHC 0x01 // Route port to EHC
|
|
|
|
|
|
|
|
#define USBCMD_RUN 0x01 // Run/stop
|
|
|
|
#define USBCMD_RESET 0x02 // Start the host controller reset
|
|
|
|
#define USBCMD_ENABLE_PERIOD 0x10 // Enable periodic schedule
|
|
|
|
#define USBCMD_ENABLE_ASYNC 0x20 // Enable asynchronous schedule
|
|
|
|
#define USBCMD_IAAD 0x40 // Interrupt on async advance doorbell
|
|
|
|
|
|
|
|
#define USBSTS_IAA 0x20 // Interrupt on async advance
|
|
|
|
#define USBSTS_PERIOD_ENABLED 0x4000 // Periodic schedule status
|
|
|
|
#define USBSTS_ASYNC_ENABLED 0x8000 // Asynchronous schedule status
|
|
|
|
#define USBSTS_HALT 0x1000 // Host controller halted
|
|
|
|
#define USBSTS_SYS_ERROR 0x10 // Host system error
|
|
|
|
#define USBSTS_INTACK_MASK 0x003F // Mask for the interrupt ACK, the WC
|
|
|
|
// (write clean) bits in USBSTS register
|
|
|
|
|
|
|
|
#define PORTSC_CONN 0x01 // Current Connect Status
|
|
|
|
#define PORTSC_CONN_CHANGE 0x02 // Connect Status Change
|
|
|
|
#define PORTSC_ENABLED 0x04 // Port Enable / Disable
|
|
|
|
#define PORTSC_ENABLE_CHANGE 0x08 // Port Enable / Disable Change
|
|
|
|
#define PORTSC_OVERCUR 0x10 // Over current Active
|
|
|
|
#define PORTSC_OVERCUR_CHANGE 0x20 // Over current Change
|
|
|
|
#define PORSTSC_RESUME 0x40 // Force Port Resume
|
|
|
|
#define PORTSC_SUSPEND 0x80 // Port Suspend State
|
|
|
|
#define PORTSC_RESET 0x100 // Port Reset
|
|
|
|
#define PORTSC_LINESTATE_K 0x400 // Line Status K-state
|
|
|
|
#define PORTSC_LINESTATE_J 0x800 // Line Status J-state
|
|
|
|
#define PORTSC_POWER 0x1000 // Port Power
|
|
|
|
#define PORTSC_OWNER 0x2000 // Port Owner
|
|
|
|
#define PORTSC_CHANGE_MASK 0x2A // Mask of the port change bits,
|
|
|
|
// they are WC (write clean)
|
|
|
|
//
|
|
|
|
// PCI Configuration Registers
|
|
|
|
//
|
|
|
|
#define EHC_BAR_INDEX 0 // how many bytes away from USB_BASE to 0x10
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2012-04-28 07:02:54 +02:00
|
|
|
//
|
|
|
|
// Debug port capability id
|
|
|
|
//
|
|
|
|
#define EHC_DEBUG_PORT_CAP_ID 0x0A
|
|
|
|
|
2007-07-11 08:46:38 +02:00
|
|
|
#define EHC_LINK_TERMINATED(Link) (((Link) & 0x01) != 0)
|
|
|
|
|
|
|
|
#define EHC_ADDR(High, QhHw32) \
|
|
|
|
((VOID *) (UINTN) (LShiftU64 ((High), 32) | ((QhHw32) & 0xFFFFFFF0)))
|
|
|
|
|
|
|
|
#define EHCI_IS_DATAIN(EndpointAddr) EHC_BIT_IS_SET((EndpointAddr), 0x80)
|
|
|
|
|
|
|
|
//
|
|
|
|
// Structure to map the hardware port states to the
|
|
|
|
// UEFI's port states.
|
|
|
|
//
|
|
|
|
typedef struct {
|
|
|
|
UINT16 HwState;
|
|
|
|
UINT16 UefiState;
|
|
|
|
} USB_PORT_STATE_MAP;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Ehci Data and Ctrl Structures
|
|
|
|
//
|
|
|
|
#pragma pack(1)
|
|
|
|
typedef struct {
|
2010-01-19 07:42:21 +01:00
|
|
|
UINT8 ProgInterface;
|
2007-07-11 08:46:38 +02:00
|
|
|
UINT8 SubClassCode;
|
|
|
|
UINT8 BaseCode;
|
|
|
|
} USB_CLASSC;
|
|
|
|
#pragma pack()
|
|
|
|
|
2008-07-08 12:26:16 +02:00
|
|
|
/**
|
|
|
|
Read EHCI capability register.
|
|
|
|
|
|
|
|
@param Ehc The EHCI device.
|
|
|
|
@param Offset Capability register address.
|
|
|
|
|
|
|
|
@return The register content.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-08 12:26:16 +02:00
|
|
|
**/
|
2007-07-11 08:46:38 +02:00
|
|
|
UINT32
|
|
|
|
EhcReadCapRegister (
|
|
|
|
IN USB2_HC_DEV *Ehc,
|
|
|
|
IN UINT32 Offset
|
2008-09-04 11:37:28 +02:00
|
|
|
);
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2012-04-28 07:02:54 +02:00
|
|
|
/**
|
|
|
|
Read EHCI debug port register.
|
|
|
|
|
|
|
|
@param Ehc The EHCI device.
|
|
|
|
@param Offset Debug port register address.
|
|
|
|
|
|
|
|
@return The register content read.
|
|
|
|
@retval If err, return 0xffff.
|
|
|
|
|
|
|
|
**/
|
|
|
|
UINT32
|
|
|
|
EhcReadDbgRegister (
|
|
|
|
IN USB2_HC_DEV *Ehc,
|
|
|
|
IN UINT32 Offset
|
|
|
|
);
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
/**
|
2008-07-08 12:26:16 +02:00
|
|
|
Read EHCI Operation register.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-08 12:26:16 +02:00
|
|
|
@param Ehc The EHCI device.
|
|
|
|
@param Offset The operation register offset.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-08 12:26:16 +02:00
|
|
|
@return The register content.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
UINT32
|
|
|
|
EhcReadOpReg (
|
|
|
|
IN USB2_HC_DEV *Ehc,
|
|
|
|
IN UINT32 Offset
|
2008-09-04 11:37:28 +02:00
|
|
|
);
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-07-08 12:26:16 +02:00
|
|
|
Write the data to the EHCI operation register.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-08 12:26:16 +02:00
|
|
|
@param Ehc The EHCI device.
|
|
|
|
@param Offset EHCI operation register offset.
|
|
|
|
@param Data The data to write.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
EhcWriteOpReg (
|
|
|
|
IN USB2_HC_DEV *Ehc,
|
|
|
|
IN UINT32 Offset,
|
|
|
|
IN UINT32 Data
|
2008-09-04 11:37:28 +02:00
|
|
|
);
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2009-12-16 01:58:46 +01:00
|
|
|
/**
|
|
|
|
Set one bit of the operational register while keeping other bits.
|
|
|
|
|
|
|
|
@param Ehc The EHCI device.
|
|
|
|
@param Offset The offset of the operational register.
|
|
|
|
@param Bit The bit mask of the register to set.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
EhcSetOpRegBit (
|
|
|
|
IN USB2_HC_DEV *Ehc,
|
|
|
|
IN UINT32 Offset,
|
|
|
|
IN UINT32 Bit
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Clear one bit of the operational register while keeping other bits.
|
|
|
|
|
|
|
|
@param Ehc The EHCI device.
|
|
|
|
@param Offset The offset of the operational register.
|
|
|
|
@param Bit The bit mask of the register to clear.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
EhcClearOpRegBit (
|
|
|
|
IN USB2_HC_DEV *Ehc,
|
|
|
|
IN UINT32 Offset,
|
|
|
|
IN UINT32 Bit
|
|
|
|
);
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
Add support for UEFI Over Legacy (UoL) feature, stop
|
2008-07-08 12:26:16 +02:00
|
|
|
the legacy USB SMI support.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
@param Ehc The EHCI device.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
EhcClearLegacySupport (
|
|
|
|
IN USB2_HC_DEV *Ehc
|
2008-09-04 11:37:28 +02:00
|
|
|
);
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Set door bell and wait it to be ACKed by host controller.
|
|
|
|
This function is used to synchronize with the hardware.
|
|
|
|
|
2008-07-08 12:26:16 +02:00
|
|
|
@param Ehc The EHCI device.
|
|
|
|
@param Timeout The time to wait before abort (in millisecond, ms).
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-08 12:26:16 +02:00
|
|
|
@retval EFI_SUCCESS Synchronized with the hardware.
|
|
|
|
@retval EFI_TIMEOUT Time out happened while waiting door bell to set.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EhcSetAndWaitDoorBell (
|
|
|
|
IN USB2_HC_DEV *Ehc,
|
|
|
|
IN UINT32 Timeout
|
2008-09-04 11:37:28 +02:00
|
|
|
);
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-07-08 12:26:16 +02:00
|
|
|
Clear all the interrutp status bits, these bits are Write-Clean.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-08 12:26:16 +02:00
|
|
|
@param Ehc The EHCI device.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
EhcAckAllInterrupt (
|
|
|
|
IN USB2_HC_DEV *Ehc
|
2008-09-04 11:37:28 +02:00
|
|
|
);
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-07-08 12:26:16 +02:00
|
|
|
Whether Ehc is halted.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-08 12:26:16 +02:00
|
|
|
@param Ehc The EHCI device.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-08 12:26:16 +02:00
|
|
|
@retval TRUE The controller is halted.
|
|
|
|
@retval FALSE It isn't halted.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
BOOLEAN
|
|
|
|
EhcIsHalt (
|
|
|
|
IN USB2_HC_DEV *Ehc
|
2008-09-04 11:37:28 +02:00
|
|
|
);
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-07-08 12:26:16 +02:00
|
|
|
Whether system error occurred.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-08 12:26:16 +02:00
|
|
|
@param Ehc The EHCI device.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-08 12:26:16 +02:00
|
|
|
@retval TRUE System error happened.
|
|
|
|
@retval FALSE No system error.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
BOOLEAN
|
|
|
|
EhcIsSysError (
|
|
|
|
IN USB2_HC_DEV *Ehc
|
2008-09-04 11:37:28 +02:00
|
|
|
);
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-07-08 12:26:16 +02:00
|
|
|
Reset the host controller.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-08 12:26:16 +02:00
|
|
|
@param Ehc The EHCI device.
|
|
|
|
@param Timeout Time to wait before abort (in millisecond, ms).
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-08 12:26:16 +02:00
|
|
|
@retval EFI_SUCCESS The host controller is reset.
|
|
|
|
@return Others Failed to reset the host.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EhcResetHC (
|
|
|
|
IN USB2_HC_DEV *Ehc,
|
|
|
|
IN UINT32 Timeout
|
2008-09-04 11:37:28 +02:00
|
|
|
);
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-07-08 12:26:16 +02:00
|
|
|
Halt the host controller.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-08 12:26:16 +02:00
|
|
|
@param Ehc The EHCI device.
|
|
|
|
@param Timeout Time to wait before abort.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-08 12:26:16 +02:00
|
|
|
@return EFI_SUCCESS The EHCI is halt.
|
|
|
|
@return EFI_TIMEOUT Failed to halt the controller before Timeout.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EhcHaltHC (
|
|
|
|
IN USB2_HC_DEV *Ehc,
|
|
|
|
IN UINT32 Timeout
|
2008-09-04 11:37:28 +02:00
|
|
|
);
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-07-08 12:26:16 +02:00
|
|
|
Set the EHCI to run.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-08 12:26:16 +02:00
|
|
|
@param Ehc The EHCI device.
|
|
|
|
@param Timeout Time to wait before abort.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-08 12:26:16 +02:00
|
|
|
@return EFI_SUCCESS The EHCI is running.
|
|
|
|
@return Others Failed to set the EHCI to run.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EhcRunHC (
|
|
|
|
IN USB2_HC_DEV *Ehc,
|
|
|
|
IN UINT32 Timeout
|
2008-09-04 11:37:28 +02:00
|
|
|
);
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Initialize the HC hardware.
|
2008-07-08 12:26:16 +02:00
|
|
|
EHCI spec lists the five things to do to initialize the hardware:
|
2007-07-11 08:46:38 +02:00
|
|
|
1. Program CTRLDSSEGMENT
|
|
|
|
2. Set USBINTR to enable interrupts
|
|
|
|
3. Set periodic list base
|
|
|
|
4. Set USBCMD, interrupt threshold, frame list size etc
|
|
|
|
5. Write 1 to CONFIGFLAG to route all ports to EHCI
|
|
|
|
|
2008-07-08 12:26:16 +02:00
|
|
|
@param Ehc The EHCI device.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-08 12:26:16 +02:00
|
|
|
@return EFI_SUCCESS The EHCI has come out of halt state.
|
|
|
|
@return EFI_TIMEOUT Time out happened.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EhcInitHC (
|
|
|
|
IN USB2_HC_DEV *Ehc
|
2008-09-04 11:37:28 +02:00
|
|
|
);
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
#endif
|