Initial import.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@3 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
154
EdkModulePkg/Bus/Usb/UsbBus/Dxe/ComponentName.c
Normal file
154
EdkModulePkg/Bus/Usb/UsbBus/Dxe/ComponentName.c
Normal file
@@ -0,0 +1,154 @@
|
||||
/*++
|
||||
|
||||
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:
|
||||
|
||||
ComponentName.c
|
||||
|
||||
Abstract:
|
||||
|
||||
--*/
|
||||
|
||||
#include "UsbBus.h"
|
||||
|
||||
//
|
||||
// EFI Component Name Functions
|
||||
//
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
UsbBusComponentNameGetDriverName (
|
||||
IN EFI_COMPONENT_NAME_PROTOCOL *This,
|
||||
IN CHAR8 *Language,
|
||||
OUT CHAR16 **DriverName
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
UsbBusComponentNameGetControllerName (
|
||||
IN EFI_COMPONENT_NAME_PROTOCOL *This,
|
||||
IN EFI_HANDLE ControllerHandle,
|
||||
IN EFI_HANDLE ChildHandle, OPTIONAL
|
||||
IN CHAR8 *Language,
|
||||
OUT CHAR16 **ControllerName
|
||||
);
|
||||
|
||||
//
|
||||
// EFI Component Name Protocol
|
||||
//
|
||||
EFI_COMPONENT_NAME_PROTOCOL gUsbBusComponentName = {
|
||||
UsbBusComponentNameGetDriverName,
|
||||
UsbBusComponentNameGetControllerName,
|
||||
"eng"
|
||||
};
|
||||
|
||||
STATIC EFI_UNICODE_STRING_TABLE mUsbBusDriverNameTable[] = {
|
||||
{ "eng", (CHAR16 *) L"USB Bus Driver" },
|
||||
{ NULL , NULL }
|
||||
};
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
UsbBusComponentNameGetDriverName (
|
||||
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,
|
||||
gUsbBusComponentName.SupportedLanguages,
|
||||
mUsbBusDriverNameTable,
|
||||
DriverName
|
||||
);
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
UsbBusComponentNameGetControllerName (
|
||||
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.
|
||||
|
||||
--*/
|
||||
{
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
44
EdkModulePkg/Bus/Usb/UsbBus/Dxe/UsbBus.mbd
Normal file
44
EdkModulePkg/Bus/Usb/UsbBus/Dxe/UsbBus.mbd
Normal file
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
<ModuleBuildDescription xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.TianoCore.org/2006/Edk2.0 http://www.TianoCore.org/2006/Edk2.0/SurfaceArea.xsd">
|
||||
<MbdHeader>
|
||||
<BaseName>UsbBus</BaseName>
|
||||
<Guid>240612B7-A063-11d4-9A3A-0090273FC14D</Guid>
|
||||
<Version>0</Version>
|
||||
<Description>FIX ME!</Description>
|
||||
<Copyright>Copyright (c) 2004-2006, 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>
|
||||
<Created>2006-03-12 17:09</Created>
|
||||
<Modified>2006-03-19 15:18</Modified>
|
||||
</MbdHeader>
|
||||
<Libraries>
|
||||
<Library>UefiBootServicesTableLib</Library>
|
||||
<Library>UefiMemoryLib</Library>
|
||||
<Library>UefiLib</Library>
|
||||
<Library>UefiDriverEntryPoint</Library>
|
||||
<Library>UefiDriverModelLib</Library>
|
||||
<Library>DxeReportStatusCodeLib</Library>
|
||||
<Library>BaseDebugLibReportStatusCode</Library>
|
||||
<Library>EdkDxePrintLib</Library>
|
||||
<Library>BaseLib</Library>
|
||||
<Library>EdkUsbLib</Library>
|
||||
<Library>DxeMemoryAllocationLib</Library>
|
||||
<Library>UefiDevicePathLib</Library>
|
||||
</Libraries>
|
||||
</ModuleBuildDescription>
|
76
EdkModulePkg/Bus/Usb/UsbBus/Dxe/UsbBus.msa
Normal file
76
EdkModulePkg/Bus/Usb/UsbBus/Dxe/UsbBus.msa
Normal file
@@ -0,0 +1,76 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.TianoCore.org/2006/Edk2.0 http://www.TianoCore.org/2006/Edk2.0/SurfaceArea.xsd">
|
||||
<MsaHeader>
|
||||
<BaseName>UsbBus</BaseName>
|
||||
<ModuleType>DXE_DRIVER</ModuleType>
|
||||
<ComponentType>BS_DRIVER</ComponentType>
|
||||
<Guid>240612B7-A063-11d4-9A3A-0090273FC14D</Guid>
|
||||
<Version>0</Version>
|
||||
<Abstract>Component description file for UsbBus module</Abstract>
|
||||
<Description>FIX ME!</Description>
|
||||
<Copyright>Copyright (c) 2004-2006, 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>0</Specification>
|
||||
<Created>2006-03-12 17:09</Created>
|
||||
<Updated>2006-03-19 15:18</Updated>
|
||||
</MsaHeader>
|
||||
<LibraryClassDefinitions>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">DebugLib</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">UefiDriverModelLib</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">UefiDriverEntryPoint</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">BaseLib</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">UefiLib</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">BaseMemoryLib</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">EdkUsbLib</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">ReportStatusCodeLib</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">MemoryAllocationLib</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">UefiBootServicesTableLib</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">DevicePathLib</LibraryClass>
|
||||
</LibraryClassDefinitions>
|
||||
<SourceFiles>
|
||||
<Filename>UsbBus.h</Filename>
|
||||
<Filename>usbutil.h</Filename>
|
||||
<Filename>hub.h</Filename>
|
||||
<Filename>UsbBus.c</Filename>
|
||||
<Filename>UsbIo.c</Filename>
|
||||
<Filename>usb.c</Filename>
|
||||
<Filename>usbutil.c</Filename>
|
||||
<Filename>Hub.c</Filename>
|
||||
<Filename>ComponentName.c</Filename>
|
||||
</SourceFiles>
|
||||
<Includes>
|
||||
<PackageName>MdePkg</PackageName>
|
||||
<PackageName>EdkModulePkg</PackageName>
|
||||
</Includes>
|
||||
<Protocols>
|
||||
<Protocol Usage="BY_START">UsbIo</Protocol>
|
||||
<Protocol Usage="TO_START">UsbHc</Protocol>
|
||||
<Protocol Usage="TO_START">DevicePath</Protocol>
|
||||
</Protocols>
|
||||
<Externs>
|
||||
<Extern>
|
||||
<ModuleEntryPoint></ModuleEntryPoint>
|
||||
</Extern>
|
||||
<Extern>
|
||||
<DriverBinding>gUsbBusDriverBinding</DriverBinding>
|
||||
<ComponentName>gUsbBusComponentName</ComponentName>
|
||||
</Extern>
|
||||
</Externs>
|
||||
</ModuleSurfaceArea>
|
47
EdkModulePkg/Bus/Usb/UsbBus/Dxe/build.xml
Normal file
47
EdkModulePkg/Bus/Usb/UsbBus/Dxe/build.xml
Normal file
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><!-- 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.-->
|
||||
<project basedir="." default="UsbBus"><!--Apply external ANT tasks-->
|
||||
<taskdef resource="GenBuild.tasks"/>
|
||||
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
|
||||
<property environment="env"/>
|
||||
<property name="WORKSPACE_DIR" value="${env.WORKSPACE}"/>
|
||||
<import file="${WORKSPACE_DIR}\Tools\Conf\BuildMacro.xml"/><!--MODULE_RELATIVE PATH is relative to PACKAGE_DIR-->
|
||||
<property name="MODULE_RELATIVE_PATH" value="Bus\Usb\UsbBus\Dxe"/>
|
||||
<property name="MODULE_DIR" value="${PACKAGE_DIR}\${MODULE_RELATIVE_PATH}"/>
|
||||
<property name="COMMON_FILE" value="${WORKSPACE_DIR}\Tools\Conf\Common.xml"/>
|
||||
<target name="UsbBus">
|
||||
<GenBuild baseName="UsbBus" mbdFilename="${MODULE_DIR}\UsbBus.mbd" msaFilename="${MODULE_DIR}\UsbBus.msa"/>
|
||||
</target>
|
||||
<target depends="UsbBus_clean" name="clean"/>
|
||||
<target depends="UsbBus_cleanall" name="cleanall"/>
|
||||
<target name="UsbBus_clean">
|
||||
<OutputDirSetup baseName="UsbBus" mbdFilename="${MODULE_DIR}\UsbBus.mbd" msaFilename="${MODULE_DIR}\UsbBus.msa"/>
|
||||
<if>
|
||||
<available file="${DEST_DIR_OUTPUT}\UsbBus_build.xml"/>
|
||||
<then>
|
||||
<ant antfile="${DEST_DIR_OUTPUT}\UsbBus_build.xml" target="clean"/>
|
||||
</then>
|
||||
</if>
|
||||
<delete dir="${DEST_DIR_OUTPUT}" excludes="*.xml"/>
|
||||
</target>
|
||||
<target name="UsbBus_cleanall">
|
||||
<OutputDirSetup baseName="UsbBus" mbdFilename="${MODULE_DIR}\UsbBus.mbd" msaFilename="${MODULE_DIR}\UsbBus.msa"/>
|
||||
<if>
|
||||
<available file="${DEST_DIR_OUTPUT}\UsbBus_build.xml"/>
|
||||
<then>
|
||||
<ant antfile="${DEST_DIR_OUTPUT}\UsbBus_build.xml" target="cleanall"/>
|
||||
</then>
|
||||
</if>
|
||||
<delete dir="${DEST_DIR_OUTPUT}"/>
|
||||
<delete dir="${DEST_DIR_DEBUG}"/>
|
||||
<delete>
|
||||
<fileset dir="${BIN_DIR}" includes="**UsbBus*"/>
|
||||
</delete>
|
||||
</target>
|
||||
</project>
|
507
EdkModulePkg/Bus/Usb/UsbBus/Dxe/hub.c
Normal file
507
EdkModulePkg/Bus/Usb/UsbBus/Dxe/hub.c
Normal file
@@ -0,0 +1,507 @@
|
||||
/*++
|
||||
|
||||
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:
|
||||
|
||||
Hub.c
|
||||
|
||||
Abstract:
|
||||
|
||||
Usb Hub Request
|
||||
|
||||
Revision History
|
||||
|
||||
--*/
|
||||
|
||||
#include "usbbus.h"
|
||||
|
||||
EFI_STATUS
|
||||
HubGetPortStatus (
|
||||
IN EFI_USB_IO_PROTOCOL *UsbIo,
|
||||
IN UINT8 Port,
|
||||
OUT UINT32 *PortStatus
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Get a given hub port status
|
||||
|
||||
Arguments:
|
||||
UsbIo - EFI_USB_IO_PROTOCOL instance
|
||||
Port - Usb hub port number (starting from 1).
|
||||
PortStatus - Current Hub port status and change status.
|
||||
|
||||
Returns:
|
||||
EFI_SUCCESS
|
||||
EFI_DEVICE
|
||||
EFI_TIME_OUT
|
||||
EFI_INVALID_PARAMETER
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_USB_DEVICE_REQUEST DevReq;
|
||||
EFI_STATUS EfiStatus;
|
||||
UINT32 UsbStatus;
|
||||
UINT32 Timeout;
|
||||
|
||||
ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));
|
||||
|
||||
//
|
||||
// Fill Device request packet
|
||||
//
|
||||
DevReq.RequestType = HUB_GET_PORT_STATUS_REQ_TYPE;
|
||||
DevReq.Request = HUB_GET_PORT_STATUS;
|
||||
DevReq.Value = 0;
|
||||
DevReq.Index = Port;
|
||||
DevReq.Length = sizeof (UINT32);
|
||||
|
||||
Timeout = 3000;
|
||||
|
||||
EfiStatus = UsbIo->UsbControlTransfer (
|
||||
UsbIo,
|
||||
&DevReq,
|
||||
EfiUsbDataIn,
|
||||
Timeout,
|
||||
PortStatus,
|
||||
sizeof (UINT32),
|
||||
&UsbStatus
|
||||
);
|
||||
|
||||
return EfiStatus;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
HubSetPortFeature (
|
||||
IN EFI_USB_IO_PROTOCOL *UsbIo,
|
||||
IN UINT8 Port,
|
||||
IN UINT8 Value
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Set specified feature to a give hub port
|
||||
|
||||
Arguments:
|
||||
UsbIo - EFI_USB_IO_PROTOCOL instance
|
||||
Port - Usb hub port number (starting from 1).
|
||||
Value - New feature value.
|
||||
|
||||
Returns:
|
||||
EFI_SUCCESS
|
||||
EFI_DEVICE
|
||||
EFI_TIME_OUT
|
||||
EFI_INVALID_PARAMETER
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_USB_DEVICE_REQUEST DevReq;
|
||||
EFI_STATUS EfiStatus;
|
||||
UINT32 UsbStatus;
|
||||
UINT32 Timeout;
|
||||
|
||||
ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));
|
||||
|
||||
//
|
||||
// Fill Device request packet
|
||||
//
|
||||
DevReq.RequestType = HUB_SET_PORT_FEATURE_REQ_TYPE;
|
||||
DevReq.Request = HUB_SET_PORT_FEATURE;
|
||||
DevReq.Value = Value;
|
||||
DevReq.Index = Port;
|
||||
DevReq.Length = 0;
|
||||
|
||||
Timeout = 3000;
|
||||
EfiStatus = UsbIo->UsbControlTransfer (
|
||||
UsbIo,
|
||||
&DevReq,
|
||||
EfiUsbNoData,
|
||||
Timeout,
|
||||
NULL,
|
||||
0,
|
||||
&UsbStatus
|
||||
);
|
||||
|
||||
return EfiStatus;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
HubClearPortFeature (
|
||||
IN EFI_USB_IO_PROTOCOL *UsbIo,
|
||||
IN UINT8 Port,
|
||||
IN UINT8 Value
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Clear a specified feature of a given hub port
|
||||
|
||||
Arguments:
|
||||
UsbIo - EFI_USB_IO_PROTOCOL instance
|
||||
Port - Usb hub port number (starting from 1).
|
||||
Value - Feature value that will be cleared from
|
||||
that hub port.
|
||||
|
||||
Returns:
|
||||
EFI_SUCCESS
|
||||
EFI_DEVICE
|
||||
EFI_TIME_OUT
|
||||
EFI_INVALID_PARAMETER
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_USB_DEVICE_REQUEST DevReq;
|
||||
EFI_STATUS EfiStatus;
|
||||
UINT32 UsbStatus;
|
||||
UINT32 Timeout;
|
||||
|
||||
ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));
|
||||
|
||||
//
|
||||
// Fill Device request packet
|
||||
//
|
||||
DevReq.RequestType = HUB_CLEAR_FEATURE_PORT_REQ_TYPE;
|
||||
DevReq.Request = HUB_CLEAR_FEATURE_PORT;
|
||||
DevReq.Value = Value;
|
||||
DevReq.Index = Port;
|
||||
DevReq.Length = 0;
|
||||
|
||||
Timeout = 3000;
|
||||
EfiStatus = UsbIo->UsbControlTransfer (
|
||||
UsbIo,
|
||||
&DevReq,
|
||||
EfiUsbNoData,
|
||||
Timeout,
|
||||
NULL,
|
||||
0,
|
||||
&UsbStatus
|
||||
);
|
||||
|
||||
return EfiStatus;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
HubGetHubStatus (
|
||||
IN EFI_USB_IO_PROTOCOL *UsbIo,
|
||||
OUT UINT32 *HubStatus
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Get Hub Status
|
||||
|
||||
Arguments:
|
||||
UsbIo - EFI_USB_IO_PROTOCOL instance
|
||||
HubStatus - Current Hub status and change status.
|
||||
|
||||
Returns:
|
||||
EFI_SUCCESS
|
||||
EFI_DEVICE
|
||||
EFI_TIME_OUT
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_USB_DEVICE_REQUEST DevReq;
|
||||
EFI_STATUS EfiStatus;
|
||||
UINT32 UsbStatus;
|
||||
UINT32 Timeout;
|
||||
|
||||
ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));
|
||||
|
||||
//
|
||||
// Fill Device request packet
|
||||
//
|
||||
DevReq.RequestType = HUB_GET_HUB_STATUS_REQ_TYPE;
|
||||
DevReq.Request = HUB_GET_HUB_STATUS;
|
||||
DevReq.Value = 0;
|
||||
DevReq.Index = 0;
|
||||
DevReq.Length = sizeof (UINT32);
|
||||
|
||||
Timeout = 3000;
|
||||
EfiStatus = UsbIo->UsbControlTransfer (
|
||||
UsbIo,
|
||||
&DevReq,
|
||||
EfiUsbDataIn,
|
||||
Timeout,
|
||||
HubStatus,
|
||||
sizeof (UINT32),
|
||||
&UsbStatus
|
||||
);
|
||||
|
||||
return EfiStatus;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
HubSetHubFeature (
|
||||
IN EFI_USB_IO_PROTOCOL *UsbIo,
|
||||
IN UINT8 Value
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Set a specified feature to the hub
|
||||
|
||||
Arguments:
|
||||
UsbIo - EFI_USB_IO_PROTOCOL instance
|
||||
Value - Feature value that will be set to the hub.
|
||||
|
||||
Returns:
|
||||
EFI_SUCCESS
|
||||
EFI_DEVICE
|
||||
EFI_TIME_OUT
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_USB_DEVICE_REQUEST DevReq;
|
||||
EFI_STATUS EfiStatus;
|
||||
UINT32 UsbStatus;
|
||||
UINT32 Timeout;
|
||||
|
||||
ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));
|
||||
|
||||
//
|
||||
// Fill Device request packet
|
||||
//
|
||||
DevReq.RequestType = HUB_SET_HUB_FEATURE_REQ_TYPE;
|
||||
DevReq.Request = HUB_SET_HUB_FEATURE;
|
||||
DevReq.Value = Value;
|
||||
DevReq.Index = 0;
|
||||
DevReq.Length = 0;
|
||||
|
||||
Timeout = 3000;
|
||||
EfiStatus = UsbIo->UsbControlTransfer (
|
||||
UsbIo,
|
||||
&DevReq,
|
||||
EfiUsbNoData,
|
||||
Timeout,
|
||||
NULL,
|
||||
0,
|
||||
&UsbStatus
|
||||
);
|
||||
|
||||
return EfiStatus;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
HubClearHubFeature (
|
||||
IN EFI_USB_IO_PROTOCOL *UsbIo,
|
||||
IN UINT8 Value
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Set a specified feature to the hub
|
||||
|
||||
Arguments:
|
||||
UsbIo - EFI_USB_IO_PROTOCOL instance
|
||||
Value - Feature value that will be cleared from the hub.
|
||||
|
||||
Returns:
|
||||
EFI_SUCCESS
|
||||
EFI_DEVICE
|
||||
EFI_TIME_OUT
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_USB_DEVICE_REQUEST DevReq;
|
||||
EFI_STATUS EfiStatus;
|
||||
UINT32 UsbStatus;
|
||||
UINT32 Timeout;
|
||||
|
||||
ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));
|
||||
|
||||
//
|
||||
// Fill Device request packet
|
||||
//
|
||||
DevReq.RequestType = HUB_CLEAR_FEATURE_REQ_TYPE;
|
||||
DevReq.Request = HUB_CLEAR_FEATURE;
|
||||
DevReq.Value = Value;
|
||||
DevReq.Index = 0;
|
||||
DevReq.Length = 0;
|
||||
|
||||
Timeout = 3000;
|
||||
EfiStatus = UsbIo->UsbControlTransfer (
|
||||
UsbIo,
|
||||
&DevReq,
|
||||
EfiUsbNoData,
|
||||
Timeout,
|
||||
NULL,
|
||||
0,
|
||||
&UsbStatus
|
||||
);
|
||||
|
||||
return EfiStatus;
|
||||
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
GetHubDescriptor (
|
||||
IN EFI_USB_IO_PROTOCOL *UsbIo,
|
||||
IN UINTN DescriptorSize,
|
||||
OUT EFI_USB_HUB_DESCRIPTOR *HubDescriptor
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Get the hub descriptor
|
||||
|
||||
Arguments:
|
||||
UsbIo - EFI_USB_IO_PROTOCOL instance
|
||||
DescriptorSize - The length of Hub Descriptor buffer.
|
||||
HubDescriptor - Caller allocated buffer to store the hub descriptor
|
||||
if successfully returned.
|
||||
|
||||
Returns:
|
||||
EFI_SUCCESS
|
||||
EFI_DEVICE
|
||||
EFI_TIME_OUT
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_USB_DEVICE_REQUEST DevReq;
|
||||
EFI_STATUS EfiStatus;
|
||||
UINT32 UsbStatus;
|
||||
UINT32 Timeout;
|
||||
|
||||
ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));
|
||||
|
||||
//
|
||||
// Fill Device request packet
|
||||
//
|
||||
DevReq.RequestType = USB_RT_HUB | 0x80;
|
||||
DevReq.Request = HUB_GET_DESCRIPTOR;
|
||||
DevReq.Value = USB_DT_HUB << 8;
|
||||
DevReq.Index = 0;
|
||||
DevReq.Length = (UINT16) DescriptorSize;
|
||||
|
||||
Timeout = 3000;
|
||||
EfiStatus = UsbIo->UsbControlTransfer (
|
||||
UsbIo,
|
||||
&DevReq,
|
||||
EfiUsbDataIn,
|
||||
Timeout,
|
||||
HubDescriptor,
|
||||
(UINT16) DescriptorSize,
|
||||
&UsbStatus
|
||||
);
|
||||
|
||||
return EfiStatus;
|
||||
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
DoHubConfig (
|
||||
IN USB_IO_CONTROLLER_DEVICE *HubController
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Configure the hub
|
||||
|
||||
Arguments:
|
||||
HubController - Indicating the hub controller device that
|
||||
will be configured
|
||||
|
||||
Returns:
|
||||
EFI_SUCCESS
|
||||
EFI_DEVICE_ERROR
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_USB_IO_PROTOCOL *UsbIo;
|
||||
EFI_USB_HUB_DESCRIPTOR HubDescriptor;
|
||||
EFI_STATUS Status;
|
||||
EFI_USB_HUB_STATUS HubStatus;
|
||||
UINTN Index;
|
||||
UINT32 PortStatus;
|
||||
|
||||
UsbIo = &HubController->UsbIo;
|
||||
|
||||
ZeroMem (&HubDescriptor, sizeof (HubDescriptor));
|
||||
|
||||
//
|
||||
// First get the hub descriptor length
|
||||
//
|
||||
Status = GetHubDescriptor (UsbIo, 2, &HubDescriptor);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return EFI_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
//
|
||||
// First get the whole descriptor, then
|
||||
// get the number of hub ports
|
||||
//
|
||||
Status = GetHubDescriptor (
|
||||
UsbIo,
|
||||
HubDescriptor.Length,
|
||||
&HubDescriptor
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((gUSBErrorLevel, "Get hub descriptor fail\n"));
|
||||
return EFI_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
HubController->DownstreamPorts = HubDescriptor.NbrPorts;
|
||||
|
||||
Status = HubGetHubStatus (UsbIo, (UINT32 *) &HubStatus);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((gUSBErrorLevel, "Get hub status fail when configure\n"));
|
||||
return EFI_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
//
|
||||
// Get all hub ports status
|
||||
//
|
||||
for (Index = 0; Index < HubController->DownstreamPorts; Index++) {
|
||||
|
||||
Status = HubGetPortStatus (UsbIo, (UINT8) (Index + 1), &PortStatus);
|
||||
if (EFI_ERROR (Status)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
//
|
||||
// Power all the hub ports
|
||||
//
|
||||
for (Index = 0; Index < HubController->DownstreamPorts; Index++) {
|
||||
Status = HubSetPortFeature (
|
||||
UsbIo,
|
||||
(UINT8) (Index + 1),
|
||||
EfiUsbPortPower
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Clear Hub Status Change
|
||||
//
|
||||
Status = HubGetHubStatus (UsbIo, (UINT32 *) &HubStatus);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((gUSBErrorLevel, "Get hub status fail\n"));
|
||||
return EFI_DEVICE_ERROR;
|
||||
} else {
|
||||
//
|
||||
// Hub power supply change happens
|
||||
//
|
||||
if (HubStatus.HubChange & HUB_CHANGE_LOCAL_POWER) {
|
||||
HubClearHubFeature (UsbIo, C_HUB_LOCAL_POWER);
|
||||
}
|
||||
//
|
||||
// Hub change overcurrent happens
|
||||
//
|
||||
if (HubStatus.HubChange & HUB_CHANGE_OVERCURRENT) {
|
||||
HubClearHubFeature (UsbIo, C_HUB_OVER_CURRENT);
|
||||
}
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
|
||||
}
|
138
EdkModulePkg/Bus/Usb/UsbBus/Dxe/hub.h
Normal file
138
EdkModulePkg/Bus/Usb/UsbBus/Dxe/hub.h
Normal file
@@ -0,0 +1,138 @@
|
||||
/*++
|
||||
|
||||
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:
|
||||
|
||||
Hub.h
|
||||
|
||||
Abstract:
|
||||
|
||||
Constants definitions for Usb Hub
|
||||
|
||||
Revision History
|
||||
|
||||
--*/
|
||||
|
||||
#ifndef _HUB_H
|
||||
#define _HUB_H
|
||||
|
||||
//
|
||||
// Hub feature numbers
|
||||
//
|
||||
#define C_HUB_LOCAL_POWER 0
|
||||
#define C_HUB_OVER_CURRENT 1
|
||||
|
||||
//
|
||||
// Hub class code & sub class code
|
||||
//
|
||||
#define CLASS_CODE_HUB 0x09
|
||||
#define SUB_CLASS_CODE_HUB 0
|
||||
|
||||
//
|
||||
// Hub Status & Hub Change bit masks
|
||||
//
|
||||
#define HUB_STATUS_LOCAL_POWER 0x0001
|
||||
#define HUB_STATUS_OVERCURRENT 0x0002
|
||||
|
||||
#define HUB_CHANGE_LOCAL_POWER 0x0001
|
||||
#define HUB_CHANGE_OVERCURRENT 0x0002
|
||||
|
||||
//
|
||||
// Hub Characteristics
|
||||
//
|
||||
#define HUB_CHAR_LPSM 0x0003
|
||||
#define HUB_CHAR_COMPOUND 0x0004
|
||||
#define HUB_CHAR_OCPM 0x0018
|
||||
|
||||
//
|
||||
// Hub specific request
|
||||
//
|
||||
#define HUB_CLEAR_FEATURE 0x01
|
||||
#define HUB_CLEAR_FEATURE_REQ_TYPE 0x20
|
||||
|
||||
#define HUB_CLEAR_FEATURE_PORT 0x01
|
||||
#define HUB_CLEAR_FEATURE_PORT_REQ_TYPE 0x23
|
||||
|
||||
#define HUB_GET_BUS_STATE 0x02
|
||||
#define HUB_GET_BUS_STATE_REQ_TYPE 0xA3
|
||||
|
||||
#define HUB_GET_DESCRIPTOR 0x06
|
||||
#define HUB_GET_DESCRIPTOR_REQ_TYPE 0xA0
|
||||
|
||||
#define HUB_GET_HUB_STATUS 0x00
|
||||
#define HUB_GET_HUB_STATUS_REQ_TYPE 0xA0
|
||||
|
||||
#define HUB_GET_PORT_STATUS 0x00
|
||||
#define HUB_GET_PORT_STATUS_REQ_TYPE 0xA3
|
||||
|
||||
#define HUB_SET_DESCRIPTOR 0x07
|
||||
#define HUB_SET_DESCRIPTOR_REQ_TYPE 0x20
|
||||
|
||||
#define HUB_SET_HUB_FEATURE 0x03
|
||||
#define HUB_SET_HUB_FEATURE_REQ_TYPE 0x20
|
||||
|
||||
#define HUB_SET_PORT_FEATURE 0x03
|
||||
#define HUB_SET_PORT_FEATURE_REQ_TYPE 0x23
|
||||
|
||||
#pragma pack(1)
|
||||
typedef struct usb_hub_status {
|
||||
UINT16 HubStatus;
|
||||
UINT16 HubChange;
|
||||
} EFI_USB_HUB_STATUS;
|
||||
#pragma pack()
|
||||
|
||||
EFI_STATUS
|
||||
HubGetPortStatus (
|
||||
IN EFI_USB_IO_PROTOCOL *UsbIo,
|
||||
IN UINT8 Port,
|
||||
OUT UINT32 *PortStatus
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
HubSetPortFeature (
|
||||
IN EFI_USB_IO_PROTOCOL *UsbIo,
|
||||
IN UINT8 Port,
|
||||
IN UINT8 Value
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
HubSetHubFeature (
|
||||
IN EFI_USB_IO_PROTOCOL *UsbIo,
|
||||
IN UINT8 Value
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
HubGetHubStatus (
|
||||
IN EFI_USB_IO_PROTOCOL *UsbIo,
|
||||
OUT UINT32 *HubStatus
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
HubClearPortFeature (
|
||||
IN EFI_USB_IO_PROTOCOL *UsbIo,
|
||||
IN UINT8 Port,
|
||||
IN UINT8 Value
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
HubClearHubFeature (
|
||||
IN EFI_USB_IO_PROTOCOL *UsbIo,
|
||||
IN UINT8 Value
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
GetHubDescriptor (
|
||||
IN EFI_USB_IO_PROTOCOL *UsbIo,
|
||||
IN UINTN DescriptorSize,
|
||||
OUT EFI_USB_HUB_DESCRIPTOR *HubDescriptor
|
||||
);
|
||||
|
||||
#endif
|
825
EdkModulePkg/Bus/Usb/UsbBus/Dxe/usb.c
Normal file
825
EdkModulePkg/Bus/Usb/UsbBus/Dxe/usb.c
Normal file
@@ -0,0 +1,825 @@
|
||||
/*++
|
||||
|
||||
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:
|
||||
|
||||
Usb.c
|
||||
|
||||
Abstract:
|
||||
|
||||
Parse usb device configurations.
|
||||
|
||||
Revision History
|
||||
|
||||
--*/
|
||||
|
||||
#include "usbbus.h"
|
||||
|
||||
//
|
||||
// Here are some internal helper functions
|
||||
//
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
GetExpectedDescriptor (
|
||||
IN UINT8 *Buffer,
|
||||
IN UINTN Length,
|
||||
IN UINT8 DescType,
|
||||
IN UINT8 DescLength,
|
||||
OUT UINTN *ParsedBytes
|
||||
);
|
||||
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
ParseThisEndpoint (
|
||||
IN ENDPOINT_DESC_LIST_ENTRY *EndpointEntry,
|
||||
IN UINT8 *Buffer,
|
||||
IN UINTN BufferLength,
|
||||
OUT UINTN *ParsedBytes
|
||||
);
|
||||
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
ParseThisInterface (
|
||||
IN INTERFACE_DESC_LIST_ENTRY *InterfaceEntry,
|
||||
IN UINT8 *Buffer,
|
||||
IN UINTN *BufferLen,
|
||||
OUT UINTN *ParsedBytes
|
||||
);
|
||||
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
ParseThisConfig (
|
||||
IN CONFIG_DESC_LIST_ENTRY *ConfigDescEntry,
|
||||
IN UINT8 *Buffer,
|
||||
IN UINTN Length
|
||||
);
|
||||
|
||||
//
|
||||
// Implementations
|
||||
//
|
||||
BOOLEAN
|
||||
IsHub (
|
||||
IN USB_IO_CONTROLLER_DEVICE *Dev
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Tell if a usb controller is a hub controller.
|
||||
|
||||
Arguments:
|
||||
Dev - UsbIoController device structure.
|
||||
|
||||
Returns:
|
||||
TRUE/FALSE
|
||||
--*/
|
||||
{
|
||||
EFI_USB_INTERFACE_DESCRIPTOR Interface;
|
||||
EFI_USB_IO_PROTOCOL *UsbIo;
|
||||
EFI_USB_ENDPOINT_DESCRIPTOR EndpointDescriptor;
|
||||
UINT8 Index;
|
||||
|
||||
if (Dev == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
UsbIo = &Dev->UsbIo;
|
||||
|
||||
UsbIo->UsbGetInterfaceDescriptor (
|
||||
UsbIo,
|
||||
&Interface
|
||||
);
|
||||
|
||||
//
|
||||
// Check classcode
|
||||
//
|
||||
if (Interface.InterfaceClass != 0x09) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//
|
||||
// Check protocol
|
||||
//
|
||||
if (Interface.InterfaceProtocol != 0x0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
for (Index = 0; Index < Interface.NumEndpoints; Index++) {
|
||||
UsbIo->UsbGetEndpointDescriptor (
|
||||
UsbIo,
|
||||
Index,
|
||||
&EndpointDescriptor
|
||||
);
|
||||
|
||||
if ((EndpointDescriptor.EndpointAddress & 0x80) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (EndpointDescriptor.Attributes != 0x03) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Dev->HubEndpointAddress = EndpointDescriptor.EndpointAddress;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
UsbGetStringtable (
|
||||
IN USB_IO_DEVICE *Dev
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Get the string table stored in a usb device.
|
||||
|
||||
Arguments:
|
||||
Dev - UsbIoController device structure.
|
||||
|
||||
Returns:
|
||||
EFI_SUCCESS
|
||||
EFI_UNSUPPORTED
|
||||
EFI_OUT_OF_RESOURCES
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_STATUS Result;
|
||||
UINT32 Status;
|
||||
EFI_USB_SUPPORTED_LANGUAGES *LanguageTable;
|
||||
UINT8 *Buffer;
|
||||
UINT8 *ptr;
|
||||
UINTN Index;
|
||||
UINTN LangTableSize;
|
||||
EFI_USB_IO_PROTOCOL *UsbIo;
|
||||
UINT16 TempBuffer;
|
||||
|
||||
UsbIo = &(Dev->UsbController[0]->UsbIo);
|
||||
|
||||
//
|
||||
// We get first 2 byte of langID table,
|
||||
// so we can have the whole table length
|
||||
//
|
||||
Result = UsbGetString (
|
||||
UsbIo,
|
||||
0,
|
||||
0,
|
||||
&TempBuffer,
|
||||
2,
|
||||
&Status
|
||||
);
|
||||
if (EFI_ERROR (Result)) {
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
LanguageTable = (EFI_USB_SUPPORTED_LANGUAGES *) &TempBuffer;
|
||||
|
||||
if (LanguageTable->Length == 0) {
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
//
|
||||
// If length is 2, then there is no string table
|
||||
//
|
||||
if (LanguageTable->Length == 2) {
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
Buffer = AllocateZeroPool (LanguageTable->Length);
|
||||
if (Buffer == NULL) {
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
//
|
||||
// Now we get the whole LangID table
|
||||
//
|
||||
Result = UsbGetString (
|
||||
UsbIo,
|
||||
0,
|
||||
0,
|
||||
Buffer,
|
||||
LanguageTable->Length,
|
||||
&Status
|
||||
);
|
||||
if (EFI_ERROR (Result)) {
|
||||
gBS->FreePool (Buffer);
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
LanguageTable = (EFI_USB_SUPPORTED_LANGUAGES *) Buffer;
|
||||
|
||||
//
|
||||
// ptr point to the LangID table
|
||||
//
|
||||
ptr = Buffer + 2;
|
||||
LangTableSize = (LanguageTable->Length - 2) / 2;
|
||||
|
||||
for (Index = 0; Index < LangTableSize && Index < USB_MAXLANID; Index++) {
|
||||
Dev->LangID[Index] = *((UINT16 *) ptr);
|
||||
ptr += 2;
|
||||
}
|
||||
|
||||
gBS->FreePool (Buffer);
|
||||
LanguageTable = NULL;
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
EFI_STATUS
|
||||
UsbGetAllConfigurations (
|
||||
IN USB_IO_DEVICE *UsbIoDevice
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
This function is to parse all the configuration descriptor.
|
||||
|
||||
Arguments:
|
||||
UsbIoDevice - USB_IO_DEVICE device structure.
|
||||
|
||||
Returns:
|
||||
EFI_SUCCESS
|
||||
EFI_DEVICE_ERROR
|
||||
EFI_OUT_OF_RESOURCES
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_STATUS Result;
|
||||
UINT32 Status;
|
||||
UINTN Index;
|
||||
UINTN TotalLength;
|
||||
UINT8 *Buffer;
|
||||
CONFIG_DESC_LIST_ENTRY *ConfigDescEntry;
|
||||
EFI_USB_IO_PROTOCOL *UsbIo;
|
||||
|
||||
InitializeListHead (&UsbIoDevice->ConfigDescListHead);
|
||||
UsbIo = &(UsbIoDevice->UsbController[0]->UsbIo);
|
||||
|
||||
for (Index = 0; Index < UsbIoDevice->DeviceDescriptor.NumConfigurations; Index++) {
|
||||
ConfigDescEntry = NULL;
|
||||
|
||||
ConfigDescEntry = AllocateZeroPool (sizeof (CONFIG_DESC_LIST_ENTRY));
|
||||
if (ConfigDescEntry == NULL) {
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
//
|
||||
// 1st only get 1st 4 bytes config descriptor,
|
||||
// so we can know the whole length
|
||||
//
|
||||
Result = UsbGetDescriptor (
|
||||
UsbIo,
|
||||
(UINT16) ((USB_DT_CONFIG << 8) | Index),
|
||||
0,
|
||||
4,
|
||||
&ConfigDescEntry->CongfigDescriptor,
|
||||
&Status
|
||||
);
|
||||
if (EFI_ERROR (Result)) {
|
||||
DEBUG ((gUSBErrorLevel, "First get config descriptor error\n"));
|
||||
gBS->FreePool (ConfigDescEntry);
|
||||
return EFI_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
TotalLength = ConfigDescEntry->CongfigDescriptor.TotalLength;
|
||||
|
||||
Buffer = AllocateZeroPool (TotalLength);
|
||||
if (Buffer == NULL) {
|
||||
gBS->FreePool (ConfigDescEntry);
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
//
|
||||
// Then we get the total descriptors for this configuration
|
||||
//
|
||||
Result = UsbGetDescriptor (
|
||||
UsbIo,
|
||||
(UINT16) ((USB_DT_CONFIG << 8) | Index),
|
||||
0,
|
||||
(UINT16) TotalLength,
|
||||
Buffer,
|
||||
&Status
|
||||
);
|
||||
if (EFI_ERROR (Result)) {
|
||||
DEBUG ((gUSBErrorLevel, "Get whole config descriptor error\n"));
|
||||
gBS->FreePool (ConfigDescEntry);
|
||||
gBS->FreePool (Buffer);
|
||||
return EFI_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
InitializeListHead (&ConfigDescEntry->InterfaceDescListHead);
|
||||
|
||||
//
|
||||
// Parse this whole configuration
|
||||
//
|
||||
Result = ParseThisConfig (ConfigDescEntry, Buffer, TotalLength);
|
||||
|
||||
if (EFI_ERROR (Result)) {
|
||||
//
|
||||
// Ignore this configuration, parse next one
|
||||
//
|
||||
gBS->FreePool (ConfigDescEntry);
|
||||
gBS->FreePool (Buffer);
|
||||
continue;
|
||||
}
|
||||
|
||||
InsertTailList (&UsbIoDevice->ConfigDescListHead, &ConfigDescEntry->Link);
|
||||
|
||||
gBS->FreePool (Buffer);
|
||||
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
GetExpectedDescriptor (
|
||||
IN UINT8 *Buffer,
|
||||
IN UINTN Length,
|
||||
IN UINT8 DescType,
|
||||
IN UINT8 DescLength,
|
||||
OUT UINTN *ParsedBytes
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Get the start position of next wanted descriptor.
|
||||
|
||||
Arguments:
|
||||
Buffer - Buffer to parse
|
||||
Length - Buffer length
|
||||
DescType - Descriptor type
|
||||
DescLength - Descriptor length
|
||||
ParsedBytes - Parsed Bytes to return
|
||||
Returns:
|
||||
EFI_SUCCESS
|
||||
EFI_DEVICE_ERROR
|
||||
|
||||
--*/
|
||||
{
|
||||
UINT16 DescriptorHeader;
|
||||
UINT8 Len;
|
||||
UINT8 *ptr;
|
||||
UINTN Parsed;
|
||||
|
||||
Parsed = 0;
|
||||
ptr = Buffer;
|
||||
|
||||
while (TRUE) {
|
||||
//
|
||||
// Buffer length should not less than Desc length
|
||||
//
|
||||
if (Length < DescLength) {
|
||||
return EFI_DEVICE_ERROR;
|
||||
}
|
||||
//
|
||||
// DescriptorHeader = *((UINT16 *)ptr), compatible with IPF
|
||||
//
|
||||
DescriptorHeader = (UINT16) ((*(ptr + 1) << 8) | *ptr);
|
||||
|
||||
Len = ptr[0];
|
||||
|
||||
//
|
||||
// Check to see if it is a start of expected descriptor
|
||||
//
|
||||
if (DescriptorHeader == ((DescType << 8) | DescLength)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if ((UINT8) (DescriptorHeader >> 8) == DescType) {
|
||||
if (Len > DescLength) {
|
||||
return EFI_DEVICE_ERROR;
|
||||
}
|
||||
}
|
||||
//
|
||||
// Descriptor length should be at least 2
|
||||
// and should not exceed the buffer length
|
||||
//
|
||||
if (Len < 2) {
|
||||
return EFI_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
if (Len > Length) {
|
||||
return EFI_DEVICE_ERROR;
|
||||
}
|
||||
//
|
||||
// Skip this mismatch descriptor
|
||||
//
|
||||
Length -= Len;
|
||||
ptr += Len;
|
||||
Parsed += Len;
|
||||
}
|
||||
|
||||
*ParsedBytes = Parsed;
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
ParseThisEndpoint (
|
||||
IN ENDPOINT_DESC_LIST_ENTRY *EndpointEntry,
|
||||
IN UINT8 *Buffer,
|
||||
IN UINTN BufferLength,
|
||||
OUT UINTN *ParsedBytes
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Get the start position of next wanted endpoint descriptor.
|
||||
|
||||
Arguments:
|
||||
EndpointEntry - ENDPOINT_DESC_LIST_ENTRY
|
||||
Buffer - Buffer to parse
|
||||
BufferLength - Buffer Length
|
||||
ParsedBytes - Parsed Bytes to return
|
||||
Returns:
|
||||
EFI_SUCCESS
|
||||
EFI_DEVICE_ERROR
|
||||
|
||||
--*/
|
||||
{
|
||||
UINT8 *ptr;
|
||||
EFI_STATUS Status;
|
||||
UINTN SkipBytes;
|
||||
|
||||
//
|
||||
// Skip some data for this interface
|
||||
//
|
||||
Status = GetExpectedDescriptor (
|
||||
Buffer,
|
||||
BufferLength,
|
||||
USB_DT_ENDPOINT,
|
||||
sizeof (EFI_USB_ENDPOINT_DESCRIPTOR),
|
||||
&SkipBytes
|
||||
);
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
|
||||
ptr = Buffer + SkipBytes;
|
||||
*ParsedBytes = SkipBytes;
|
||||
|
||||
CopyMem (
|
||||
&EndpointEntry->EndpointDescriptor,
|
||||
ptr,
|
||||
sizeof (EFI_USB_ENDPOINT_DESCRIPTOR)
|
||||
);
|
||||
|
||||
*ParsedBytes += sizeof (EFI_USB_ENDPOINT_DESCRIPTOR);
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
ParseThisInterface (
|
||||
IN INTERFACE_DESC_LIST_ENTRY *InterfaceEntry,
|
||||
IN UINT8 *Buffer,
|
||||
IN UINTN *BufferLen,
|
||||
OUT UINTN *ParsedBytes
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Get the start position of next wanted interface descriptor.
|
||||
|
||||
Arguments:
|
||||
InterfaceEntry - INTERFACE_DESC_LIST_ENTRY
|
||||
Buffer - Buffer to parse
|
||||
BufferLength - Buffer Length
|
||||
ParsedBytes - Parsed Bytes to return
|
||||
|
||||
Returns:
|
||||
EFI_SUCCESS
|
||||
EFI_DEVICE_ERROR
|
||||
|
||||
--*/
|
||||
{
|
||||
UINT8 *ptr;
|
||||
UINTN SkipBytes;
|
||||
UINTN Index;
|
||||
UINTN Length;
|
||||
UINTN Parsed;
|
||||
ENDPOINT_DESC_LIST_ENTRY *EndpointEntry;
|
||||
EFI_STATUS Status;
|
||||
|
||||
Parsed = 0;
|
||||
|
||||
//
|
||||
// Skip some data for this interface
|
||||
//
|
||||
Status = GetExpectedDescriptor (
|
||||
Buffer,
|
||||
*BufferLen,
|
||||
USB_DT_INTERFACE,
|
||||
sizeof (EFI_USB_INTERFACE_DESCRIPTOR),
|
||||
&SkipBytes
|
||||
);
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
|
||||
ptr = Buffer + SkipBytes;
|
||||
*ParsedBytes = SkipBytes;
|
||||
|
||||
//
|
||||
// Copy the interface descriptor
|
||||
//
|
||||
CopyMem (
|
||||
&InterfaceEntry->InterfaceDescriptor,
|
||||
ptr,
|
||||
sizeof (EFI_USB_INTERFACE_DESCRIPTOR)
|
||||
);
|
||||
|
||||
ptr = Buffer + sizeof (EFI_USB_INTERFACE_DESCRIPTOR);
|
||||
*ParsedBytes += sizeof (EFI_USB_INTERFACE_DESCRIPTOR);
|
||||
|
||||
InitializeListHead (&InterfaceEntry->EndpointDescListHead);
|
||||
|
||||
Length = *BufferLen - SkipBytes - sizeof (EFI_USB_INTERFACE_DESCRIPTOR);
|
||||
|
||||
for (Index = 0; Index < InterfaceEntry->InterfaceDescriptor.NumEndpoints; Index++) {
|
||||
EndpointEntry = AllocateZeroPool (sizeof (ENDPOINT_DESC_LIST_ENTRY));
|
||||
if (EndpointEntry == NULL) {
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
//
|
||||
// Parses all the endpoint descriptors within this interface.
|
||||
//
|
||||
Status = ParseThisEndpoint (EndpointEntry, ptr, Length, &Parsed);
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
gBS->FreePool (EndpointEntry);
|
||||
return Status;
|
||||
}
|
||||
|
||||
InsertTailList (
|
||||
&InterfaceEntry->EndpointDescListHead,
|
||||
&EndpointEntry->Link
|
||||
);
|
||||
|
||||
Length -= Parsed;
|
||||
ptr += Parsed;
|
||||
*ParsedBytes += Parsed;
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
ParseThisConfig (
|
||||
IN CONFIG_DESC_LIST_ENTRY *ConfigDescEntry,
|
||||
IN UINT8 *Buffer,
|
||||
IN UINTN Length
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Parse the current configuration descriptior.
|
||||
|
||||
Arguments:
|
||||
ConfigDescEntry - CONFIG_DESC_LIST_ENTRY
|
||||
Buffer - Buffer to parse
|
||||
Length - Buffer Length
|
||||
|
||||
Returns
|
||||
EFI_SUCCESS
|
||||
EFI_DEVICE_ERROR
|
||||
|
||||
--*/
|
||||
{
|
||||
UINT8 *ptr;
|
||||
UINT8 NumInterface;
|
||||
UINTN Index;
|
||||
INTERFACE_DESC_LIST_ENTRY *InterfaceEntry;
|
||||
UINTN SkipBytes;
|
||||
UINTN Parsed;
|
||||
EFI_STATUS Status;
|
||||
UINTN LengthLeft;
|
||||
|
||||
Parsed = 0;
|
||||
|
||||
//
|
||||
// First skip the current config descriptor;
|
||||
//
|
||||
Status = GetExpectedDescriptor (
|
||||
Buffer,
|
||||
Length,
|
||||
USB_DT_CONFIG,
|
||||
sizeof (EFI_USB_CONFIG_DESCRIPTOR),
|
||||
&SkipBytes
|
||||
);
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
|
||||
ptr = Buffer + SkipBytes;
|
||||
|
||||
CopyMem (
|
||||
&ConfigDescEntry->CongfigDescriptor,
|
||||
ptr,
|
||||
sizeof (EFI_USB_CONFIG_DESCRIPTOR)
|
||||
);
|
||||
|
||||
NumInterface = ConfigDescEntry->CongfigDescriptor.NumInterfaces;
|
||||
|
||||
//
|
||||
// Skip size of Configuration Descriptor
|
||||
//
|
||||
ptr += sizeof (EFI_USB_CONFIG_DESCRIPTOR);
|
||||
|
||||
LengthLeft = Length - SkipBytes - sizeof (EFI_USB_CONFIG_DESCRIPTOR);
|
||||
|
||||
for (Index = 0; Index < NumInterface; Index++) {
|
||||
//
|
||||
// Parse all Interface
|
||||
//
|
||||
InterfaceEntry = AllocateZeroPool (sizeof (INTERFACE_DESC_LIST_ENTRY));
|
||||
if (InterfaceEntry == NULL) {
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
Status = ParseThisInterface (InterfaceEntry, ptr, &LengthLeft, &Parsed);
|
||||
if (EFI_ERROR (Status)) {
|
||||
gBS->FreePool (InterfaceEntry);
|
||||
return Status;
|
||||
}
|
||||
|
||||
InsertTailList (
|
||||
&ConfigDescEntry->InterfaceDescListHead,
|
||||
&InterfaceEntry->Link
|
||||
);
|
||||
|
||||
//
|
||||
// Parsed for next interface
|
||||
//
|
||||
LengthLeft -= Parsed;
|
||||
ptr += Parsed;
|
||||
}
|
||||
//
|
||||
// Parse for additional alt setting;
|
||||
//
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
UsbSetConfiguration (
|
||||
IN USB_IO_DEVICE *UsbIoDev,
|
||||
IN UINTN ConfigurationValue
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Set the device to a configuration value.
|
||||
|
||||
Arguments:
|
||||
UsbIoDev - USB_IO_DEVICE to be set configuration
|
||||
ConfigrationValue - The configuration value to be set to that device
|
||||
|
||||
Returns:
|
||||
EFI_SUCCESS
|
||||
EFI_DEVICE_ERROR
|
||||
|
||||
--*/
|
||||
{
|
||||
LIST_ENTRY *NextEntry;
|
||||
CONFIG_DESC_LIST_ENTRY *ConfigEntry;
|
||||
UINT32 Status;
|
||||
EFI_STATUS Result;
|
||||
EFI_USB_IO_PROTOCOL *UsbIo;
|
||||
|
||||
UsbIo = &(UsbIoDev->UsbController[0]->UsbIo);
|
||||
NextEntry = UsbIoDev->ConfigDescListHead.ForwardLink;
|
||||
|
||||
while (NextEntry != &UsbIoDev->ConfigDescListHead) {
|
||||
//
|
||||
// Get one entry
|
||||
//
|
||||
ConfigEntry = (CONFIG_DESC_LIST_ENTRY *) NextEntry;
|
||||
if (ConfigEntry->CongfigDescriptor.ConfigurationValue == ConfigurationValue) {
|
||||
//
|
||||
// Find one, set to the active configuration
|
||||
//
|
||||
UsbIoDev->ActiveConfig = ConfigEntry;
|
||||
break;
|
||||
}
|
||||
|
||||
NextEntry = NextEntry->ForwardLink;
|
||||
}
|
||||
//
|
||||
// Next Entry should not be null
|
||||
//
|
||||
Result = UsbSetDeviceConfiguration (
|
||||
UsbIo,
|
||||
(UINT16) ConfigurationValue,
|
||||
&Status
|
||||
);
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
UsbSetDefaultConfiguration (
|
||||
IN USB_IO_DEVICE *UsbIoDev
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Set the device to a default configuration value.
|
||||
|
||||
Arguments:
|
||||
UsbIoDev - USB_IO_DEVICE to be set configuration
|
||||
|
||||
Returns
|
||||
EFI_SUCCESS
|
||||
EFI_DEVICE_ERROR
|
||||
|
||||
--*/
|
||||
{
|
||||
CONFIG_DESC_LIST_ENTRY *ConfigEntry;
|
||||
UINT16 ConfigValue;
|
||||
LIST_ENTRY *NextEntry;
|
||||
|
||||
if (IsListEmpty (&UsbIoDev->ConfigDescListHead)) {
|
||||
return EFI_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
NextEntry = UsbIoDev->ConfigDescListHead.ForwardLink;
|
||||
|
||||
ConfigEntry = (CONFIG_DESC_LIST_ENTRY *) NextEntry;
|
||||
ConfigValue = ConfigEntry->CongfigDescriptor.ConfigurationValue;
|
||||
|
||||
return UsbSetConfiguration (UsbIoDev, ConfigValue);
|
||||
}
|
||||
|
||||
VOID
|
||||
UsbDestroyAllConfiguration (
|
||||
IN USB_IO_DEVICE *UsbIoDevice
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Delete all configuration data when device is not used.
|
||||
|
||||
Arguments:
|
||||
UsbIoDevice - USB_IO_DEVICE to be set configuration
|
||||
|
||||
Returns:
|
||||
N/A
|
||||
|
||||
--*/
|
||||
{
|
||||
CONFIG_DESC_LIST_ENTRY *ConfigEntry;
|
||||
INTERFACE_DESC_LIST_ENTRY *InterfaceEntry;
|
||||
ENDPOINT_DESC_LIST_ENTRY *EndpointEntry;
|
||||
LIST_ENTRY *NextEntry;
|
||||
|
||||
//
|
||||
// Delete all configuration descriptor data
|
||||
//
|
||||
ConfigEntry = (CONFIG_DESC_LIST_ENTRY *) UsbIoDevice->ConfigDescListHead.ForwardLink;
|
||||
|
||||
while (ConfigEntry != (CONFIG_DESC_LIST_ENTRY *) &UsbIoDevice->ConfigDescListHead) {
|
||||
//
|
||||
// Delete all its interface descriptors
|
||||
//
|
||||
InterfaceEntry = (INTERFACE_DESC_LIST_ENTRY *) ConfigEntry->InterfaceDescListHead.ForwardLink;
|
||||
|
||||
while (InterfaceEntry != (INTERFACE_DESC_LIST_ENTRY *) &ConfigEntry->InterfaceDescListHead) {
|
||||
//
|
||||
// Delete all its endpoint descriptors
|
||||
//
|
||||
EndpointEntry = (ENDPOINT_DESC_LIST_ENTRY *) InterfaceEntry->EndpointDescListHead.ForwardLink;
|
||||
while (EndpointEntry != (ENDPOINT_DESC_LIST_ENTRY *) &InterfaceEntry->EndpointDescListHead) {
|
||||
NextEntry = ((LIST_ENTRY *) EndpointEntry)->ForwardLink;
|
||||
RemoveEntryList ((LIST_ENTRY *) EndpointEntry);
|
||||
gBS->FreePool (EndpointEntry);
|
||||
EndpointEntry = (ENDPOINT_DESC_LIST_ENTRY *) NextEntry;
|
||||
}
|
||||
|
||||
NextEntry = ((LIST_ENTRY *) InterfaceEntry)->ForwardLink;
|
||||
RemoveEntryList ((LIST_ENTRY *) InterfaceEntry);
|
||||
gBS->FreePool (InterfaceEntry);
|
||||
InterfaceEntry = (INTERFACE_DESC_LIST_ENTRY *) NextEntry;
|
||||
}
|
||||
|
||||
NextEntry = ((LIST_ENTRY *) ConfigEntry)->ForwardLink;
|
||||
RemoveEntryList ((LIST_ENTRY *) ConfigEntry);
|
||||
gBS->FreePool (ConfigEntry);
|
||||
ConfigEntry = (CONFIG_DESC_LIST_ENTRY *) NextEntry;
|
||||
}
|
||||
}
|
2305
EdkModulePkg/Bus/Usb/UsbBus/Dxe/usbbus.c
Normal file
2305
EdkModulePkg/Bus/Usb/UsbBus/Dxe/usbbus.c
Normal file
File diff suppressed because it is too large
Load Diff
261
EdkModulePkg/Bus/Usb/UsbBus/Dxe/usbbus.h
Normal file
261
EdkModulePkg/Bus/Usb/UsbBus/Dxe/usbbus.h
Normal file
@@ -0,0 +1,261 @@
|
||||
/*++
|
||||
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:
|
||||
|
||||
usbbus.h
|
||||
|
||||
Abstract:
|
||||
|
||||
Header file for USB bus driver Interface
|
||||
|
||||
Revision History
|
||||
|
||||
|
||||
|
||||
--*/
|
||||
|
||||
#ifndef _EFI_USB_BUS_H
|
||||
#define _EFI_USB_BUS_H
|
||||
|
||||
|
||||
#include <IndustryStandard/usb.h>
|
||||
#include "Hub.h"
|
||||
#include "Usbutil.h"
|
||||
|
||||
//#ifdef EFI_DEBUG
|
||||
extern UINTN gUSBDebugLevel;
|
||||
extern UINTN gUSBErrorLevel;
|
||||
//#endif
|
||||
|
||||
#define MICROSECOND 10000
|
||||
#define ONESECOND (1000 * MICROSECOND)
|
||||
#define BUSPOLLING_PERIOD ONESECOND
|
||||
//
|
||||
// We define some maximun value here
|
||||
//
|
||||
#define USB_MAXCONFIG 8
|
||||
#define USB_MAXALTSETTING 4
|
||||
#define USB_MAXINTERFACES 32
|
||||
#define USB_MAXENDPOINTS 16
|
||||
#define USB_MAXSTRINGS 16
|
||||
#define USB_MAXLANID 16
|
||||
#define USB_MAXCHILDREN 8
|
||||
#define USB_MAXCONTROLLERS 4
|
||||
|
||||
#define USB_IO_CONTROLLER_SIGNATURE EFI_SIGNATURE_32 ('u', 's', 'b', 'd')
|
||||
|
||||
typedef struct {
|
||||
LIST_ENTRY Link;
|
||||
UINT16 StringIndex;
|
||||
CHAR16 *String;
|
||||
} STR_LIST_ENTRY;
|
||||
|
||||
typedef struct {
|
||||
LIST_ENTRY Link;
|
||||
UINT16 Toggle;
|
||||
EFI_USB_ENDPOINT_DESCRIPTOR EndpointDescriptor;
|
||||
} ENDPOINT_DESC_LIST_ENTRY;
|
||||
|
||||
typedef struct {
|
||||
LIST_ENTRY Link;
|
||||
EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
|
||||
LIST_ENTRY EndpointDescListHead;
|
||||
} INTERFACE_DESC_LIST_ENTRY;
|
||||
|
||||
typedef struct {
|
||||
LIST_ENTRY Link;
|
||||
EFI_USB_CONFIG_DESCRIPTOR CongfigDescriptor;
|
||||
LIST_ENTRY InterfaceDescListHead;
|
||||
UINTN ActiveInterface;
|
||||
} CONFIG_DESC_LIST_ENTRY;
|
||||
|
||||
//
|
||||
// Forward declaring
|
||||
//
|
||||
struct usb_io_device;
|
||||
|
||||
//
|
||||
// This is used to form the USB Controller Handle
|
||||
//
|
||||
typedef struct usb_io_controller_device {
|
||||
UINTN Signature;
|
||||
EFI_HANDLE Handle;
|
||||
EFI_USB_IO_PROTOCOL UsbIo;
|
||||
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
|
||||
EFI_HANDLE HostController;
|
||||
UINT8 CurrentConfigValue;
|
||||
UINT8 InterfaceNumber;
|
||||
struct usb_io_device *UsbDevice;
|
||||
|
||||
BOOLEAN IsUsbHub;
|
||||
BOOLEAN IsManagedByDriver;
|
||||
|
||||
//
|
||||
// Fields specified for USB Hub
|
||||
//
|
||||
EFI_EVENT HubNotify;
|
||||
UINT8 HubEndpointAddress;
|
||||
UINT8 StatusChangePort;
|
||||
UINT8 DownstreamPorts;
|
||||
|
||||
UINT8 ParentPort;
|
||||
struct usb_io_controller_device *Parent;
|
||||
struct usb_io_device *Children[USB_MAXCHILDREN];
|
||||
} USB_IO_CONTROLLER_DEVICE;
|
||||
|
||||
#define USB_IO_CONTROLLER_DEVICE_FROM_USB_IO_THIS(a) \
|
||||
CR(a, USB_IO_CONTROLLER_DEVICE, UsbIo, USB_IO_CONTROLLER_SIGNATURE)
|
||||
|
||||
//
|
||||
// This is used to keep the topology of USB bus
|
||||
//
|
||||
struct _usb_bus_controller_device;
|
||||
|
||||
typedef struct usb_io_device {
|
||||
UINT8 DeviceAddress;
|
||||
BOOLEAN IsConfigured;
|
||||
BOOLEAN IsSlowDevice;
|
||||
EFI_USB_DEVICE_DESCRIPTOR DeviceDescriptor;
|
||||
LIST_ENTRY ConfigDescListHead;
|
||||
CONFIG_DESC_LIST_ENTRY *ActiveConfig;
|
||||
UINT16 LangID[USB_MAXLANID];
|
||||
|
||||
struct _usb_bus_controller_device *BusController;
|
||||
|
||||
//
|
||||
// Track the controller handle
|
||||
//
|
||||
UINT8 NumOfControllers;
|
||||
USB_IO_CONTROLLER_DEVICE *UsbController[USB_MAXCONTROLLERS];
|
||||
|
||||
} USB_IO_DEVICE;
|
||||
|
||||
//
|
||||
// Usb Bus Controller device strcuture
|
||||
//
|
||||
#define EFI_USB_BUS_PROTOCOL_GUID \
|
||||
{ 0x2B2F68CC, 0x0CD2, 0x44cf, { 0x8E, 0x8B, 0xBB, 0xA2, 0x0B, 0x1B, 0x5B, 0x75 } }
|
||||
|
||||
typedef struct _EFI_USB_BUS_PROTOCOL {
|
||||
UINT64 Reserved;
|
||||
} EFI_USB_BUS_PROTOCOL;
|
||||
|
||||
#define USB_BUS_DEVICE_SIGNATURE EFI_SIGNATURE_32 ('u', 'b', 'u', 's')
|
||||
|
||||
typedef struct _usb_bus_controller_device {
|
||||
UINTN Signature;
|
||||
|
||||
EFI_USB_BUS_PROTOCOL BusIdentify;
|
||||
EFI_USB_HC_PROTOCOL *UsbHCInterface;
|
||||
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
|
||||
UINT8 AddressPool[16];
|
||||
USB_IO_DEVICE *Root;
|
||||
} USB_BUS_CONTROLLER_DEVICE;
|
||||
|
||||
#define USB_BUS_CONTROLLER_DEVICE_FROM_THIS(a) \
|
||||
CR(a, USB_BUS_CONTROLLER_DEVICE, BusIdentify, USB_BUS_DEVICE_SIGNATURE)
|
||||
|
||||
|
||||
//
|
||||
// Global Variables
|
||||
//
|
||||
extern EFI_DRIVER_BINDING_PROTOCOL gUsbBusDriverBinding;
|
||||
extern EFI_COMPONENT_NAME_PROTOCOL gUsbBusComponentName;
|
||||
extern EFI_GUID gUSBBusDriverGuid;
|
||||
|
||||
//
|
||||
// Usb Device Configuration functions
|
||||
//
|
||||
BOOLEAN
|
||||
IsHub (
|
||||
IN USB_IO_CONTROLLER_DEVICE *Dev
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
UsbGetStringtable (
|
||||
IN USB_IO_DEVICE *UsbIoDevice
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
UsbGetAllConfigurations (
|
||||
IN USB_IO_DEVICE *UsbIoDevice
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
UsbSetConfiguration (
|
||||
IN USB_IO_DEVICE *Dev,
|
||||
IN UINTN ConfigurationValue
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
UsbSetDefaultConfiguration (
|
||||
IN USB_IO_DEVICE *Dev
|
||||
);
|
||||
|
||||
//
|
||||
// Device Deconfiguration functions
|
||||
//
|
||||
VOID
|
||||
UsbDestroyAllConfiguration (
|
||||
IN USB_IO_DEVICE *UsbIoDevice
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
DoHubConfig (
|
||||
IN USB_IO_CONTROLLER_DEVICE *HubIoDevice
|
||||
);
|
||||
|
||||
VOID
|
||||
GetDeviceEndPointMaxPacketLength (
|
||||
IN EFI_USB_IO_PROTOCOL *UsbIo,
|
||||
IN UINT8 EndpointAddr,
|
||||
OUT UINT8 *MaxPacketLength
|
||||
);
|
||||
|
||||
VOID
|
||||
GetDataToggleBit (
|
||||
IN EFI_USB_IO_PROTOCOL *UsbIo,
|
||||
IN UINT8 EndpointAddr,
|
||||
OUT UINT8 *DataToggle
|
||||
);
|
||||
|
||||
VOID
|
||||
SetDataToggleBit (
|
||||
IN EFI_USB_IO_PROTOCOL *UsbIo,
|
||||
IN UINT8 EndpointAddr,
|
||||
IN UINT8 DataToggle
|
||||
);
|
||||
|
||||
INTERFACE_DESC_LIST_ENTRY *
|
||||
FindInterfaceListEntry (
|
||||
IN EFI_USB_IO_PROTOCOL *This
|
||||
);
|
||||
|
||||
ENDPOINT_DESC_LIST_ENTRY *
|
||||
FindEndPointListEntry (
|
||||
IN EFI_USB_IO_PROTOCOL *This,
|
||||
IN UINT8 EndPointAddress
|
||||
);
|
||||
|
||||
|
||||
EFI_STATUS
|
||||
IsDeviceDisconnected (
|
||||
IN USB_IO_CONTROLLER_DEVICE *UsbIoController,
|
||||
IN OUT BOOLEAN *Disconnected
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
UsbDeviceDeConfiguration (
|
||||
IN USB_IO_DEVICE *UsbIoDevice
|
||||
);
|
||||
|
||||
|
||||
#endif
|
1176
EdkModulePkg/Bus/Usb/UsbBus/Dxe/usbio.c
Normal file
1176
EdkModulePkg/Bus/Usb/UsbBus/Dxe/usbio.c
Normal file
File diff suppressed because it is too large
Load Diff
556
EdkModulePkg/Bus/Usb/UsbBus/Dxe/usbutil.c
Normal file
556
EdkModulePkg/Bus/Usb/UsbBus/Dxe/usbutil.c
Normal file
@@ -0,0 +1,556 @@
|
||||
/*++
|
||||
|
||||
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:
|
||||
usbutil.c
|
||||
|
||||
Abstract:
|
||||
|
||||
Helper functions for USB
|
||||
|
||||
Revision History
|
||||
|
||||
--*/
|
||||
|
||||
#include "usbbus.h"
|
||||
|
||||
//
|
||||
// Following APIs are used to query Port Status
|
||||
//
|
||||
BOOLEAN
|
||||
IsPortConnect (
|
||||
IN UINT16 PortStatus
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Tell if there is a device connected to that port according to
|
||||
the Port Status.
|
||||
|
||||
Parameters:
|
||||
PortStatus - The status value of that port.
|
||||
|
||||
Return Value:
|
||||
TRUE
|
||||
FALSE
|
||||
|
||||
--*/
|
||||
{
|
||||
//
|
||||
// return the bit 0 value of PortStatus
|
||||
//
|
||||
if ((PortStatus & USB_PORT_STAT_CONNECTION) != 0) {
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
IsPortEnable (
|
||||
IN UINT16 PortStatus
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Tell if Port is enabled.
|
||||
|
||||
Arguments:
|
||||
PortStatus - The status value of that port.
|
||||
|
||||
Returns:
|
||||
TRUE - Port is enable
|
||||
FALSE - Port is disable
|
||||
|
||||
--*/
|
||||
{
|
||||
//
|
||||
// return the bit 1 value of PortStatus
|
||||
//
|
||||
if ((PortStatus & USB_PORT_STAT_ENABLE) != 0) {
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
IsPortInReset (
|
||||
IN UINT16 PortStatus
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Tell if the port is being reset.
|
||||
|
||||
Arguments:
|
||||
PortStatus - The status value of that port.
|
||||
|
||||
Returns:
|
||||
TRUE
|
||||
FALSE
|
||||
|
||||
--*/
|
||||
{
|
||||
//
|
||||
// return the bit 4 value of PortStatus
|
||||
//
|
||||
if ((PortStatus & USB_PORT_STAT_RESET) != 0) {
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
IsPortPowerApplied (
|
||||
IN UINT16 PortStatus
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Tell if there is power applied to that port.
|
||||
|
||||
Arguments:
|
||||
PortStatus - The status value of that port.
|
||||
|
||||
Returns:
|
||||
TRUE
|
||||
FALSE
|
||||
|
||||
--*/
|
||||
{
|
||||
//
|
||||
// return the bit 8 value of PortStatus
|
||||
//
|
||||
if ((PortStatus & USB_PORT_STAT_POWER) != 0) {
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
IsPortLowSpeedDeviceAttached (
|
||||
IN UINT16 PortStatus
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Tell if the connected device is a low device.
|
||||
|
||||
Arguments:
|
||||
PortStatus - The status value of that port.
|
||||
|
||||
Returns:
|
||||
TRUE
|
||||
FALSE
|
||||
|
||||
--*/
|
||||
{
|
||||
//
|
||||
// return the bit 9 value of PortStatus
|
||||
//
|
||||
if ((PortStatus & USB_PORT_STAT_LOW_SPEED) != 0) {
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
IsPortSuspend (
|
||||
IN UINT16 PortStatus
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Tell if the port is suspend.
|
||||
|
||||
Arguments:
|
||||
PortStatus - The status value of that port.
|
||||
|
||||
Returns:
|
||||
TRUE
|
||||
FALSE
|
||||
|
||||
--*/
|
||||
{
|
||||
//
|
||||
// return the bit 2 value of PortStatus
|
||||
//
|
||||
if ((PortStatus & USB_PORT_STAT_SUSPEND) != 0) {
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
//
|
||||
// Following APIs are used to query Port Change Status
|
||||
//
|
||||
BOOLEAN
|
||||
IsPortConnectChange (
|
||||
IN UINT16 PortChangeStatus
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Tell if there is a Connect Change status in that port.
|
||||
|
||||
Arguments:
|
||||
PortChangeStatus - The status value of that port.
|
||||
|
||||
Returns:
|
||||
TRUE
|
||||
FALSE
|
||||
|
||||
--*/
|
||||
{
|
||||
//
|
||||
// return the bit 0 value of PortChangeStatus
|
||||
//
|
||||
if ((PortChangeStatus & USB_PORT_STAT_C_CONNECTION) != 0) {
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
IsPortEnableDisableChange (
|
||||
IN UINT16 PortChangeStatus
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Tell if there is a Enable/Disable change in that port.
|
||||
|
||||
Arguments:
|
||||
PortChangeStatus - The status value of that port.
|
||||
|
||||
Returns:
|
||||
TRUE
|
||||
FALSE
|
||||
|
||||
--*/
|
||||
{
|
||||
//
|
||||
// return the bit 1 value of PortChangeStatus
|
||||
//
|
||||
if ((PortChangeStatus & USB_PORT_STAT_C_ENABLE) != 0) {
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
IsPortResetChange (
|
||||
IN UINT16 PortChangeStatus
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Tell if there is a Port Reset Change status in that port.
|
||||
|
||||
Arguments:
|
||||
PortChangeStatus - The status value of that port.
|
||||
|
||||
Returns:
|
||||
TRUE
|
||||
FALSE
|
||||
|
||||
--*/
|
||||
{
|
||||
//
|
||||
// return the bit 4 value of PortChangeStatus
|
||||
//
|
||||
if ((PortChangeStatus & USB_PORT_STAT_C_RESET) != 0) {
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BOOLEAN
|
||||
IsPortSuspendChange (
|
||||
IN UINT16 PortChangeStatus
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Tell if there is a Suspend Change Status in that port.
|
||||
|
||||
Arguments:
|
||||
PortChangeStatus - The status value of that port.
|
||||
|
||||
Returns:
|
||||
TRUE
|
||||
FALSE
|
||||
|
||||
--*/
|
||||
{
|
||||
//
|
||||
// return the bit 2 value of PortChangeStatus
|
||||
//
|
||||
if ((PortChangeStatus & USB_PORT_STAT_C_SUSPEND) != 0) {
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
INTERFACE_DESC_LIST_ENTRY*
|
||||
FindInterfaceListEntry (
|
||||
IN EFI_USB_IO_PROTOCOL *This
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Find Interface ListEntry.
|
||||
|
||||
Arguments:
|
||||
This - EFI_USB_IO_PROTOCOL
|
||||
|
||||
Returns:
|
||||
INTERFACE_DESC_LIST_ENTRY pointer
|
||||
|
||||
--*/
|
||||
{
|
||||
USB_IO_CONTROLLER_DEVICE *UsbIoController;
|
||||
USB_IO_DEVICE *UsbIoDev;
|
||||
LIST_ENTRY *InterfaceListHead;
|
||||
INTERFACE_DESC_LIST_ENTRY *InterfaceListEntry;
|
||||
|
||||
UsbIoController = USB_IO_CONTROLLER_DEVICE_FROM_USB_IO_THIS (This);
|
||||
UsbIoDev = UsbIoController->UsbDevice;
|
||||
|
||||
if (!UsbIoDev->IsConfigured) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
InterfaceListHead = &UsbIoDev->ActiveConfig->InterfaceDescListHead;
|
||||
InterfaceListEntry = (INTERFACE_DESC_LIST_ENTRY *) (InterfaceListHead->ForwardLink);
|
||||
|
||||
//
|
||||
// Loop all interface descriptor to get match one.
|
||||
//
|
||||
while (InterfaceListEntry != (INTERFACE_DESC_LIST_ENTRY *) InterfaceListHead) {
|
||||
if (InterfaceListEntry->InterfaceDescriptor.InterfaceNumber == UsbIoController->InterfaceNumber) {
|
||||
return InterfaceListEntry;
|
||||
}
|
||||
|
||||
InterfaceListEntry = (INTERFACE_DESC_LIST_ENTRY *) InterfaceListEntry->Link.ForwardLink;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ENDPOINT_DESC_LIST_ENTRY*
|
||||
FindEndPointListEntry (
|
||||
IN EFI_USB_IO_PROTOCOL *This,
|
||||
IN UINT8 EndPointAddress
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Find EndPoint ListEntry.
|
||||
|
||||
Arguments:
|
||||
This - EFI_USB_IO_PROTOCOL
|
||||
EndpointAddr - Endpoint address.
|
||||
|
||||
Returns:
|
||||
ENDPOINT_DESC_LIST_ENTRY pointer
|
||||
|
||||
--*/
|
||||
{
|
||||
INTERFACE_DESC_LIST_ENTRY *InterfaceListEntry;
|
||||
LIST_ENTRY *EndpointDescListHead;
|
||||
ENDPOINT_DESC_LIST_ENTRY *EndPointListEntry;
|
||||
|
||||
InterfaceListEntry = FindInterfaceListEntry (This);
|
||||
if (InterfaceListEntry != NULL) {
|
||||
EndpointDescListHead = &InterfaceListEntry->EndpointDescListHead;
|
||||
EndPointListEntry = (ENDPOINT_DESC_LIST_ENTRY *) (EndpointDescListHead->ForwardLink);
|
||||
|
||||
//
|
||||
// Loop all interface descriptor to get match one.
|
||||
//
|
||||
while (EndPointListEntry != (ENDPOINT_DESC_LIST_ENTRY *) EndpointDescListHead) {
|
||||
if (EndPointListEntry->EndpointDescriptor.EndpointAddress == EndPointAddress) {
|
||||
return EndPointListEntry;
|
||||
}
|
||||
|
||||
EndPointListEntry = (ENDPOINT_DESC_LIST_ENTRY *) EndPointListEntry->Link.ForwardLink;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
VOID
|
||||
GetDataToggleBit (
|
||||
IN EFI_USB_IO_PROTOCOL *UsbIo,
|
||||
IN UINT8 EndpointAddr,
|
||||
OUT UINT8 *DataToggle
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Get the datatoggle of a specified endpoint.
|
||||
|
||||
Arguments:
|
||||
UsbIo - Given Usb Controller device.
|
||||
EndpointAddr - Given Endpoint address.
|
||||
DataToggle - The current data toggle of that endpoint
|
||||
|
||||
Returns:
|
||||
N/A
|
||||
|
||||
--*/
|
||||
{
|
||||
|
||||
ENDPOINT_DESC_LIST_ENTRY *EndpointListEntry;
|
||||
|
||||
*DataToggle = 0;
|
||||
|
||||
EndpointListEntry = FindEndPointListEntry (UsbIo, EndpointAddr);
|
||||
if (EndpointListEntry == NULL) {
|
||||
return ;
|
||||
}
|
||||
|
||||
*DataToggle = (UINT8) (EndpointListEntry->Toggle);
|
||||
return ;
|
||||
}
|
||||
|
||||
VOID
|
||||
SetDataToggleBit (
|
||||
IN EFI_USB_IO_PROTOCOL *UsbIo,
|
||||
IN UINT8 EndpointAddr,
|
||||
IN UINT8 DataToggle
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Set the datatoggle of a specified endpoint
|
||||
|
||||
Arguments:
|
||||
UsbIo - Given Usb Controller device.
|
||||
EndpointAddr - Given Endpoint address.
|
||||
DataToggle - The current data toggle of that endpoint to be set
|
||||
|
||||
Returns:
|
||||
N/A
|
||||
|
||||
--*/
|
||||
{
|
||||
|
||||
ENDPOINT_DESC_LIST_ENTRY *EndpointListEntry;
|
||||
|
||||
EndpointListEntry = FindEndPointListEntry (UsbIo, EndpointAddr);
|
||||
if (EndpointListEntry == NULL) {
|
||||
return ;
|
||||
}
|
||||
|
||||
EndpointListEntry->Toggle = DataToggle;
|
||||
return ;
|
||||
}
|
||||
|
||||
VOID
|
||||
GetDeviceEndPointMaxPacketLength (
|
||||
IN EFI_USB_IO_PROTOCOL *UsbIo,
|
||||
IN UINT8 EndpointAddr,
|
||||
OUT UINT8 *MaxPacketLength
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Get the Max Packet Length of the speified Endpoint.
|
||||
|
||||
Arguments:
|
||||
UsbIo - Given Usb Controller device.
|
||||
EndpointAddr - Given Endpoint address.
|
||||
MaxPacketLength - The max packet length of that endpoint
|
||||
|
||||
Returns:
|
||||
N/A
|
||||
|
||||
--*/
|
||||
{
|
||||
|
||||
ENDPOINT_DESC_LIST_ENTRY *EndpointListEntry;
|
||||
|
||||
*MaxPacketLength = 0;
|
||||
|
||||
EndpointListEntry = FindEndPointListEntry (UsbIo, EndpointAddr);
|
||||
if (EndpointListEntry == NULL) {
|
||||
return ;
|
||||
}
|
||||
|
||||
*MaxPacketLength = (UINT8) (EndpointListEntry->EndpointDescriptor.MaxPacketSize);
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
|
||||
EFI_STATUS
|
||||
UsbSetDeviceAddress (
|
||||
IN EFI_USB_IO_PROTOCOL *UsbIo,
|
||||
IN UINT16 AddressValue,
|
||||
OUT UINT32 *Status
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Usb Set Device Address
|
||||
|
||||
Arguments:
|
||||
|
||||
UsbIo - EFI_USB_IO_PROTOCOL
|
||||
AddressValue - Device address
|
||||
Status - Transfer status
|
||||
|
||||
Returns:
|
||||
|
||||
EFI_INVALID_PARAMETER - Parameter is error
|
||||
EFI_SUCCESS - Success
|
||||
EFI_TIMEOUT - Device has no response
|
||||
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_USB_DEVICE_REQUEST DevReq;
|
||||
|
||||
if (UsbIo == NULL) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));
|
||||
|
||||
DevReq.RequestType = USB_DEV_SET_ADDRESS_REQ_TYPE;
|
||||
DevReq.Request = USB_DEV_SET_ADDRESS;
|
||||
DevReq.Value = AddressValue;
|
||||
|
||||
return UsbIo->UsbControlTransfer (
|
||||
UsbIo,
|
||||
&DevReq,
|
||||
EfiUsbNoData,
|
||||
TIMEOUT_VALUE,
|
||||
NULL,
|
||||
0,
|
||||
Status
|
||||
);
|
||||
}
|
||||
|
94
EdkModulePkg/Bus/Usb/UsbBus/Dxe/usbutil.h
Normal file
94
EdkModulePkg/Bus/Usb/UsbBus/Dxe/usbutil.h
Normal file
@@ -0,0 +1,94 @@
|
||||
/*++
|
||||
|
||||
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:
|
||||
usbutil.h
|
||||
|
||||
Abstract:
|
||||
|
||||
Helper functions for USB
|
||||
|
||||
Revision History
|
||||
|
||||
|
||||
--*/
|
||||
|
||||
#ifndef _USB_UTIL_H
|
||||
#define _USB_UTIL_H
|
||||
|
||||
//
|
||||
// Following APIs are used to query Port Status
|
||||
//
|
||||
BOOLEAN
|
||||
IsPortConnect (
|
||||
IN UINT16 PortStatus
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
IsPortEnable (
|
||||
IN UINT16 PortStatus
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
IsPortInReset (
|
||||
IN UINT16 PortStatus
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
IsPortPowerApplied (
|
||||
IN UINT16 PortStatus
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
IsPortLowSpeedDeviceAttached (
|
||||
IN UINT16 PortStatus
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
IsPortSuspend (
|
||||
IN UINT16 PortStatus
|
||||
);
|
||||
|
||||
//
|
||||
// Following APIs are used to query Port Change Status
|
||||
//
|
||||
BOOLEAN
|
||||
IsPortConnectChange (
|
||||
IN UINT16 PortChangeStatus
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
IsPortEnableDisableChange (
|
||||
IN UINT16 PortChangeStatus
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
IsPortResetChange (
|
||||
IN UINT16 PortChangeStatus
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
IsPortSuspendChange (
|
||||
IN UINT16 PortChangeStatus
|
||||
);
|
||||
|
||||
//
|
||||
// Set device address;
|
||||
//
|
||||
EFI_STATUS
|
||||
UsbSetDeviceAddress (
|
||||
IN EFI_USB_IO_PROTOCOL *UsbIo,
|
||||
IN UINT16 AddressValue,
|
||||
OUT UINT32 *Status
|
||||
);
|
||||
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user