UsbBus.h revision 4fd606d1f5abe38e1f42c38de1d2e895166bd0f4
/** @file
Usb Bus Driver Binding and Bus IO Protocol.
Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
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
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_USB_BUS_H_
#define _EFI_USB_BUS_H_
#include <Uefi.h>
#include <Protocol/Usb2HostController.h>
#include <Protocol/UsbHostController.h>
#include <Protocol/DevicePath.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/UefiDriverEntryPoint.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/DevicePathLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/ReportStatusCodeLib.h>
#include <IndustryStandard/Usb.h>
typedef struct _USB_DEVICE USB_DEVICE;
typedef struct _USB_INTERFACE USB_INTERFACE;
typedef struct _USB_HUB_API USB_HUB_API;
#include "UsbUtility.h"
#include "UsbDesc.h"
#include "UsbHub.h"
#include "UsbEnumer.h"
//
// USB bus timeout experience values
//
#define USB_MAX_LANG_ID 16
#define USB_MAX_INTERFACE 16
#define USB_MAX_DEVICES 128
#define USB_BUS_1_MILLISECOND 1000
//
// Roothub and hub's polling interval, set by experience,
// The unit of roothub is 100us, means 1s as interval, and
// the unit of hub is 1ms, means 64ms as interval.
//
#define USB_HUB_POLL_INTERVAL 64
//
// Wait for port stable to work, refers to specification
// [USB20-9.1.2]
//
//
// Wait for port statue reg change, set by experience
//
//
// Wait for set device address, refers to specification
// [USB20-9.2.6.3, it says 2ms]
//
//
// Wait for retry max packet size, set by experience
//
//
// Wait for hub port power-on, refers to specification
// [USB20-11.23.2]
//
//
// Wait for port reset, refers to specification
// [USB20-7.1.7.5, it says 10ms for hub and 50ms for
// root hub]
//
//
// Wait for clear roothub port reset, set by experience
//
//
// Wait for set roothub port enable, set by experience
//
//
// Send general device request timeout.
//
// The USB Specification 2.0, section 11.24.1 recommends a value of
// 50 milliseconds. We use a value of 500 milliseconds to work
// around slower hubs and devices.
//
#define USB_GENERAL_DEVICE_REQUEST_TIMEOUT 500
//
// Send clear feature request timeout, set by experience
//
#define USB_CLEAR_FEATURE_REQUEST_TIMEOUT 10
//
// Bus raises TPL to TPL_NOTIFY to serialize all its operations
// to protect shared data structures.
//
#define USB_BUS_TPL TPL_NOTIFY
#define USB_INTERFACE_FROM_USBIO(a) \
#define USB_BUS_FROM_THIS(a) \
//
// Used to locate USB_BUS
// UsbBusProtocol is the private protocol.
// gEfiCallerIdGuid will be used as its protocol guid.
//
typedef struct _EFI_USB_BUS_PROTOCOL {
//
// Stands for the real USB device. Each device may
// has several seperately working interfaces.
//
struct _USB_DEVICE {
//
// Configuration information
//
//
// The device's descriptors and its configuration
//
//
// Parent child relationship
//
};
//
// Stands for different functions of USB device
//
struct _USB_INTERFACE {
//
// Handles and protocols
//
//
// Hub device special data
//
//
// Data used only by normal hub devices
//
//
// Data used only by root hub to hand over device to
// connected to EHCI.
//
};
//
// Stands for the current USB Bus
//
struct _USB_BUS {
//
// Managed USB host controller
//
//
// Recorded the max supported usb devices.
// XHCI can support up to 255 devices.
//
//
// An array of device that is on the bus. Devices[0] is
// for root hub. Device with address i is at Devices[i].
//
//
// USB Bus driver need to control the recursive connect policy of the bus, only those wanted
// usb child device will be recursively connected.
//
// WantedUsbIoDPList tracks the Usb child devices which user want to recursivly fully connecte,
// every wanted child device is stored in a item of the WantedUsbIoDPList, whose structrure is
// DEVICE_PATH_LIST_ITEM
//
};
//
// USB Hub Api
//
struct _USB_HUB_API{
};
#define USB_US_LAND_ID 0x0409
typedef struct _DEVICE_PATH_LIST_ITEM{
typedef struct {
/**
Free a DEVICE_PATH_LIST_ITEM list.
@param UsbIoDPList a DEVICE_PATH_LIST_ITEM list pointer.
@retval EFI_INVALID_PARAMETER If parameters are invalid, return this value.
@retval EFI_SUCCESS If free operation is successful, return this value.
**/
);
/**
Store a wanted usb child device info (its Usb part of device path) which is indicated by
RemainingDevicePath in a Usb bus which is indicated by UsbBusId.
@param UsbBusId Point to EFI_USB_BUS_PROTOCOL interface.
@param RemainingDevicePath The remaining device patch.
@retval EFI_SUCCESS Add operation is successful.
@retval EFI_INVALID_PARAMETER The parameters are invalid.
**/
);
/**
Check whether a usb child device is the wanted device in a bus.
@param Bus The Usb bus's private data pointer.
@param UsbIf The usb child device inferface.
@retval True If a usb child device is the wanted device in a bus.
@retval False If a usb child device is *NOT* the wanted device in a bus.
**/
);
/**
Recursively connnect every wanted usb child device to ensure they all fully connected.
Check all the child Usb IO handles in this bus, recursively connecte if it is wanted usb child device.
@param UsbBusId Point to EFI_USB_BUS_PROTOCOL interface.
@retval EFI_SUCCESS Connect is done successfully.
@retval EFI_INVALID_PARAMETER The parameter is invalid.
**/
);
/**
USB_IO function to execute a control transfer. This
function will execute the USB transfer. If transfer
successes, it will sync the internal state of USB bus
with device state.
@param This The USB_IO instance
@param Request The control transfer request
@param Direction Direction for data stage
@param Timeout The time to wait before timeout
@param Data The buffer holding the data
@param DataLength Then length of the data
@param UsbStatus USB result
@retval EFI_INVALID_PARAMETER The parameters are invalid
@retval EFI_SUCCESS The control transfer succeded.
@retval Others Failed to execute the transfer
**/
);
/**
Execute a bulk transfer to the device endpoint.
@param This The USB IO instance.
@param Endpoint The device endpoint.
@param Data The data to transfer.
@param DataLength The length of the data to transfer.
@param Timeout Time to wait before timeout.
@param UsbStatus The result of USB transfer.
@retval EFI_SUCCESS The bulk transfer is OK.
@retval EFI_INVALID_PARAMETER Some parameters are invalid.
@retval Others Failed to execute transfer, reason returned in
UsbStatus.
**/
);
/**
Execute a synchronous interrupt transfer.
@param This The USB IO instance.
@param Endpoint The device endpoint.
@param Data The data to transfer.
@param DataLength The length of the data to transfer.
@param Timeout Time to wait before timeout.
@param UsbStatus The result of USB transfer.
@retval EFI_SUCCESS The synchronous interrupt transfer is OK.
@retval EFI_INVALID_PARAMETER Some parameters are invalid.
@retval Others Failed to execute transfer, reason returned in
UsbStatus.
**/
);
/**
Queue a new asynchronous interrupt transfer, or remove the old
request if (IsNewTransfer == FALSE).
@param This The USB_IO instance.
@param Endpoint The device endpoint.
@param IsNewTransfer Whether this is a new request, if it's old, remove
the request.
@param PollInterval The interval to poll the transfer result, (in ms).
@param DataLength The length of perodic data transfer.
@param Callback The function to call periodicaly when transfer is
ready.
@param Context The context to the callback.
@retval EFI_SUCCESS New transfer is queued or old request is removed.
@retval EFI_INVALID_PARAMETER Some parameters are invalid.
@retval Others Failed to queue the new request or remove the old
request.
**/
);
/**
Execute a synchronous isochronous transfer.
@param This The USB IO instance.
@param DeviceEndpoint The device endpoint.
@param Data The data to transfer.
@param DataLength The length of the data to transfer.
@param UsbStatus The result of USB transfer.
@retval EFI_UNSUPPORTED Currently isochronous transfer isn't supported.
**/
);
/**
Queue an asynchronous isochronous transfer.
@param This The USB_IO instance.
@param DeviceEndpoint The device endpoint.
@param Data The data to transfer.
@param DataLength The length of perodic data transfer.
@param IsochronousCallBack The function to call periodicaly when transfer is
ready.
@param Context The context to the callback.
@retval EFI_UNSUPPORTED Currently isochronous transfer isn't supported.
**/
);
/**
Retrieve the device descriptor of the device.
@param This The USB IO instance.
@param Descriptor The variable to receive the device descriptor.
@retval EFI_SUCCESS The device descriptor is returned.
@retval EFI_INVALID_PARAMETER The parameter is invalid.
**/
);
/**
Return the configuration descriptor of the current active configuration.
@param This The USB IO instance.
@param Descriptor The USB configuration descriptor.
@retval EFI_SUCCESS The active configuration descriptor is returned.
@retval EFI_INVALID_PARAMETER Some parameter is invalid.
@retval EFI_NOT_FOUND Currently no active configuration is selected.
**/
);
/**
Retrieve the active interface setting descriptor for this USB IO instance.
@param This The USB IO instance.
@param Descriptor The variable to receive active interface setting.
@retval EFI_SUCCESS The active interface setting is returned.
@retval EFI_INVALID_PARAMETER Some parameter is invalid.
**/
);
/**
Retrieve the endpoint descriptor from this interface setting.
@param This The USB IO instance.
@param Index The index (start from zero) of the endpoint to
retrieve.
@param Descriptor The variable to receive the descriptor.
@retval EFI_SUCCESS The endpoint descriptor is returned.
@retval EFI_INVALID_PARAMETER Some parameter is invalid.
**/
);
/**
Retrieve the supported language ID table from the device.
@param This The USB IO instance.
@param LangIDTable The table to return the language IDs.
@param TableSize The size, in bytes, of the table LangIDTable.
@retval EFI_SUCCESS The language ID is return.
**/
);
/**
Retrieve an indexed string in the language of LangID.
@param This The USB IO instance.
@param LangID The language ID of the string to retrieve.
@param StringIndex The index of the string.
@param String The variable to receive the string.
@retval EFI_SUCCESS The string is returned.
@retval EFI_NOT_FOUND No such string existed.
**/
);
/**
Reset the device, then if that succeeds, reconfigure the
device with its address and current active configuration.
@param This The USB IO instance.
@retval EFI_SUCCESS The device is reset and configured.
@retval Others Failed to reset the device.
**/
);
/**
Install Usb Bus Protocol on host controller, and start the Usb bus.
@param This The USB bus driver binding instance.
@param Controller The controller to check.
@param RemainingDevicePath The remaining device patch.
@retval EFI_SUCCESS The controller is controlled by the usb bus.
@retval EFI_ALREADY_STARTED The controller is already controlled by the usb bus.
@retval EFI_OUT_OF_RESOURCES Failed to allocate resources.
**/
);
/**
The USB bus driver entry pointer.
@param ImageHandle The driver image handle.
@param SystemTable The system table.
@return EFI_SUCCESS The component name protocol is installed.
@return Others Failed to init the usb driver.
**/
);
/**
Check whether USB bus driver support this device.
@param This The USB bus driver binding protocol.
@param Controller The controller handle to check.
@param RemainingDevicePath The remaining device path.
@retval EFI_SUCCESS The bus supports this controller.
@retval EFI_UNSUPPORTED This device isn't supported.
**/
);
/**
Start to process the controller.
@param This The USB bus driver binding instance.
@param Controller The controller to check.
@param RemainingDevicePath The remaining device patch.
@retval EFI_SUCCESS The controller is controlled by the usb bus.
@retval EFI_ALREADY_STARTED The controller is already controlled by the usb
bus.
@retval EFI_OUT_OF_RESOURCES Failed to allocate resources.
**/
);
/**
Stop handle the controller by this USB bus driver.
@param This The USB bus driver binding protocol.
@param Controller The controller to release.
@param NumberOfChildren The child of USB bus that opened controller
BY_CHILD.
@param ChildHandleBuffer The array of child handle.
@retval EFI_SUCCESS The controller or children are stopped.
@retval EFI_DEVICE_ERROR Failed to stop the driver.
**/
);
extern EFI_USB_IO_PROTOCOL mUsbIoProtocol;
#endif