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:
bbahnsen
2006-04-21 22:54:32 +00:00
commit 878ddf1fc3
2651 changed files with 624620 additions and 0 deletions

View File

@@ -0,0 +1,190 @@
/*++
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 "bot.h"
//
// EFI Component Name Functions
//
EFI_STATUS
EFIAPI
UsbBotComponentNameGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
);
EFI_STATUS
EFIAPI
UsbBotComponentNameGetControllerName (
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 gUsbBotComponentName = {
UsbBotComponentNameGetDriverName,
UsbBotComponentNameGetControllerName,
"eng"
};
STATIC EFI_UNICODE_STRING_TABLE mUsbBotDriverNameTable[] = {
{ "eng", (CHAR16 *) L"Usb Bot Mass Storage Driver" },
{ NULL , NULL }
};
EFI_STATUS
EFIAPI
UsbBotComponentNameGetDriverName (
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,
gUsbBotComponentName.SupportedLanguages,
mUsbBotDriverNameTable,
DriverName
);
}
EFI_STATUS
EFIAPI
UsbBotComponentNameGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
)
/*++
Routine Description:
Retrieves a Unicode string that is the user readable name of the controller
that is being managed by an EFI Driver.
Arguments:
This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
ControllerHandle - The handle of a controller that the driver specified by
This is managing. This handle specifies the controller
whose name is to be returned.
ChildHandle - The handle of the child controller to retrieve the name
of. This is an optional parameter that may be NULL. It
will be NULL for device drivers. It will also be NULL
for a bus drivers that wish to retrieve the name of the
bus controller. It will not be NULL for a bus driver
that wishes to retrieve the name of a child controller.
Language - A pointer to a three character ISO 639-2 language
identifier. This is the language of the controller name
that that the caller is requesting, and it must match one
of the languages specified in SupportedLanguages. The
number of languages supported by a driver is up to the
driver writer.
ControllerName - A pointer to the Unicode string to return. This Unicode
string is the name of the controller specified by
ControllerHandle and ChildHandle in the language specified
by Language from the point of view of the driver specified
by This.
Returns:
EFI_SUCCESS - The Unicode string for the user readable name in the
language specified by Language for the driver
specified by This was returned in DriverName.
EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.
EFI_INVALID_PARAMETER - Language is NULL.
EFI_INVALID_PARAMETER - ControllerName is NULL.
EFI_UNSUPPORTED - The driver specified by This is not currently managing
the controller specified by ControllerHandle and
ChildHandle.
EFI_UNSUPPORTED - The driver specified by This does not support the
language specified by Language.
--*/
{
EFI_STATUS Status;
USB_BOT_DEVICE *UsbBotDev;
EFI_USB_ATAPI_PROTOCOL *UsbAtapi;
//
// This is a device driver, so ChildHandle must be NULL.
//
if (ChildHandle != NULL) {
return EFI_UNSUPPORTED;
}
//
// Get the device context
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiUsbAtapiProtocolGuid,
(VOID **) &UsbAtapi,
gUsbBotDriverBinding.DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
return Status;
}
UsbBotDev = USB_BOT_DEVICE_FROM_THIS (UsbAtapi);
return LookupUnicodeString (
Language,
gUsbBotComponentName.SupportedLanguages,
UsbBotDev->ControllerNameTable,
ControllerName
);
}

View File

@@ -0,0 +1,43 @@
<?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>UsbBot</BaseName>
<Guid>B40612B9-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>
</Libraries>
</ModuleBuildDescription>

View File

@@ -0,0 +1,69 @@
<?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>UsbBot</BaseName>
<ModuleType>DXE_DRIVER</ModuleType>
<ComponentType>BS_DRIVER</ComponentType>
<Guid>B40612B9-A063-11d4-9A3A-0090273FC14D</Guid>
<Version>0</Version>
<Abstract>Component description file for UsbBot 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>
</LibraryClassDefinitions>
<SourceFiles>
<Filename>bot.h</Filename>
<Filename>bot.c</Filename>
<Filename>ComponentName.c</Filename>
</SourceFiles>
<Includes>
<PackageName>MdePkg</PackageName>
<PackageName>EdkModulePkg</PackageName>
</Includes>
<Protocols>
<Protocol Usage="TO_START">DevicePath</Protocol>
<Protocol Usage="TO_START">UsbIo</Protocol>
<Protocol Usage="BY_START">UsbAtapi</Protocol>
</Protocols>
<Externs>
<Extern>
<ModuleEntryPoint></ModuleEntryPoint>
</Extern>
<Extern>
<DriverBinding>gUsbBotDriverBinding</DriverBinding>
<ComponentName>gUsbBotComponentName</ComponentName>
</Extern>
</Externs>
</ModuleSurfaceArea>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,78 @@
/*++
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:
BOT.h
Abstract:
--*/
#ifndef _BOT_H
#define _BOT_H
#include <IndustryStandard/usb.h>
#pragma pack(1)
//
// Bulk Only device protocol
//
typedef struct {
UINT32 dCBWSignature;
UINT32 dCBWTag;
UINT32 dCBWDataTransferLength;
UINT8 bmCBWFlags;
UINT8 bCBWLUN;
UINT8 bCBWCBLength;
UINT8 CBWCB[16];
} CBW;
typedef struct {
UINT32 dCSWSignature;
UINT32 dCSWTag;
UINT32 dCSWDataResidue;
UINT8 bCSWStatus;
} CSW;
#pragma pack()
#define USB_BOT_DEVICE_SIGNATURE EFI_SIGNATURE_32 ('u', 'b', 'o', 't')
typedef struct {
UINTN Signature;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
EFI_USB_ATAPI_PROTOCOL UsbAtapiProtocol;
EFI_USB_IO_PROTOCOL *UsbIo;
EFI_USB_INTERFACE_DESCRIPTOR *InterfaceDescriptor;
EFI_USB_ENDPOINT_DESCRIPTOR *BulkInEndpointDescriptor;
EFI_USB_ENDPOINT_DESCRIPTOR *BulkOutEndpointDescriptor;
EFI_UNICODE_STRING_TABLE *ControllerNameTable;
} USB_BOT_DEVICE;
#define USB_BOT_DEVICE_FROM_THIS(a) \
CR(a, USB_BOT_DEVICE, UsbAtapiProtocol, USB_BOT_DEVICE_SIGNATURE)
//
// Status code, see Usb Bot device spec
//
#define CSWSIG 0x53425355
#define CBWSIG 0x43425355
//
// Global Variables
//
extern EFI_DRIVER_BINDING_PROTOCOL gUsbBotDriverBinding;
extern EFI_COMPONENT_NAME_PROTOCOL gUsbBotComponentName;
extern EFI_GUID gUsbBotDriverGuid;
#endif

View 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="UsbBot"><!--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\UsbBot\Dxe"/>
<property name="MODULE_DIR" value="${PACKAGE_DIR}\${MODULE_RELATIVE_PATH}"/>
<property name="COMMON_FILE" value="${WORKSPACE_DIR}\Tools\Conf\Common.xml"/>
<target name="UsbBot">
<GenBuild baseName="UsbBot" mbdFilename="${MODULE_DIR}\UsbBot.mbd" msaFilename="${MODULE_DIR}\UsbBot.msa"/>
</target>
<target depends="UsbBot_clean" name="clean"/>
<target depends="UsbBot_cleanall" name="cleanall"/>
<target name="UsbBot_clean">
<OutputDirSetup baseName="UsbBot" mbdFilename="${MODULE_DIR}\UsbBot.mbd" msaFilename="${MODULE_DIR}\UsbBot.msa"/>
<if>
<available file="${DEST_DIR_OUTPUT}\UsbBot_build.xml"/>
<then>
<ant antfile="${DEST_DIR_OUTPUT}\UsbBot_build.xml" target="clean"/>
</then>
</if>
<delete dir="${DEST_DIR_OUTPUT}" excludes="*.xml"/>
</target>
<target name="UsbBot_cleanall">
<OutputDirSetup baseName="UsbBot" mbdFilename="${MODULE_DIR}\UsbBot.mbd" msaFilename="${MODULE_DIR}\UsbBot.msa"/>
<if>
<available file="${DEST_DIR_OUTPUT}\UsbBot_build.xml"/>
<then>
<ant antfile="${DEST_DIR_OUTPUT}\UsbBot_build.xml" target="cleanall"/>
</then>
</if>
<delete dir="${DEST_DIR_OUTPUT}"/>
<delete dir="${DEST_DIR_DEBUG}"/>
<delete>
<fileset dir="${BIN_DIR}" includes="**UsbBot*"/>
</delete>
</target>
</project>

View 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;
}

View 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>

View 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>

View 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>

View 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;
}

View 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

View 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;
}
}

File diff suppressed because it is too large Load Diff

View 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

File diff suppressed because it is too large Load Diff

View 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
);
}

View 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

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,192 @@
/*++
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 "../cbi.h"
extern EFI_DRIVER_BINDING_PROTOCOL gUsbCbi0DriverBinding;
//
// EFI Component Name Functions
//
EFI_STATUS
EFIAPI
UsbCbi0ComponentNameGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
);
EFI_STATUS
EFIAPI
UsbCbi0ComponentNameGetControllerName (
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 gUsbCbi0ComponentName = {
UsbCbi0ComponentNameGetDriverName,
UsbCbi0ComponentNameGetControllerName,
"eng"
};
STATIC EFI_UNICODE_STRING_TABLE mUsbCbi0DriverNameTable[] = {
{ "eng", (CHAR16 *) L"Usb Cbi0 Mass Storage Driver" },
{ NULL , NULL }
};
EFI_STATUS
EFIAPI
UsbCbi0ComponentNameGetDriverName (
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,
gUsbCbi0ComponentName.SupportedLanguages,
mUsbCbi0DriverNameTable,
DriverName
);
}
EFI_STATUS
EFIAPI
UsbCbi0ComponentNameGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
)
/*++
Routine Description:
Retrieves a Unicode string that is the user readable name of the controller
that is being managed by an EFI Driver.
Arguments:
This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
ControllerHandle - The handle of a controller that the driver specified by
This is managing. This handle specifies the controller
whose name is to be returned.
ChildHandle - The handle of the child controller to retrieve the name
of. This is an optional parameter that may be NULL. It
will be NULL for device drivers. It will also be NULL
for a bus drivers that wish to retrieve the name of the
bus controller. It will not be NULL for a bus driver
that wishes to retrieve the name of a child controller.
Language - A pointer to a three character ISO 639-2 language
identifier. This is the language of the controller name
that that the caller is requesting, and it must match one
of the languages specified in SupportedLanguages. The
number of languages supported by a driver is up to the
driver writer.
ControllerName - A pointer to the Unicode string to return. This Unicode
string is the name of the controller specified by
ControllerHandle and ChildHandle in the language specified
by Language from the point of view of the driver specified
by This.
Returns:
EFI_SUCCESS - The Unicode string for the user readable name in the
language specified by Language for the driver
specified by This was returned in DriverName.
EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.
EFI_INVALID_PARAMETER - Language is NULL.
EFI_INVALID_PARAMETER - ControllerName is NULL.
EFI_UNSUPPORTED - The driver specified by This is not currently managing
the controller specified by ControllerHandle and
ChildHandle.
EFI_UNSUPPORTED - The driver specified by This does not support the
language specified by Language.
--*/
{
EFI_STATUS Status;
USB_CBI_DEVICE *UsbCbiDev;
EFI_USB_ATAPI_PROTOCOL *UsbAtapi;
//
// This is a device driver, so ChildHandle must be NULL.
//
if (ChildHandle != NULL) {
return EFI_UNSUPPORTED;
}
//
// Get the device context
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiUsbAtapiProtocolGuid,
(VOID **) &UsbAtapi,
gUsbCbi0DriverBinding.DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
return Status;
}
UsbCbiDev = USB_CBI_DEVICE_FROM_THIS (UsbAtapi);
return LookupUnicodeString (
Language,
gUsbCbi0ComponentName.SupportedLanguages,
UsbCbiDev->ControllerNameTable,
ControllerName
);
}

View File

@@ -0,0 +1,43 @@
<?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>UsbCbi0</BaseName>
<Guid>A3527D16-E6CC-42f5-BADB-BF3DE177742B</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>
</Libraries>
</ModuleBuildDescription>

View File

@@ -0,0 +1,68 @@
<?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>UsbCbi0</BaseName>
<ModuleType>DXE_DRIVER</ModuleType>
<ComponentType>BS_DRIVER</ComponentType>
<Guid>A3527D16-E6CC-42f5-BADB-BF3DE177742B</Guid>
<Version>0</Version>
<Abstract>Component description file for UsbCbi1 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>
</LibraryClassDefinitions>
<SourceFiles>
<Filename>cbi0.c</Filename>
<Filename>componentname.c</Filename>
</SourceFiles>
<Includes>
<PackageName>MdePkg</PackageName>
<PackageName>EdkModulePkg</PackageName>
</Includes>
<Protocols>
<Protocol Usage="TO_START">DevicePath</Protocol>
<Protocol Usage="TO_START">UsbIo</Protocol>
<Protocol Usage="BY_START">UsbAtapi</Protocol>
</Protocols>
<Externs>
<Extern>
<ModuleEntryPoint></ModuleEntryPoint>
</Extern>
<Extern>
<DriverBinding>gUsbCbi0DriverBinding</DriverBinding>
<ComponentName>gUsbCbi0ComponentName</ComponentName>
</Extern>
</Externs>
</ModuleSurfaceArea>

View 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="UsbCbi0"><!--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\UsbCbi\Dxe\Cbi0"/>
<property name="MODULE_DIR" value="${PACKAGE_DIR}\${MODULE_RELATIVE_PATH}"/>
<property name="COMMON_FILE" value="${WORKSPACE_DIR}\Tools\Conf\Common.xml"/>
<target name="UsbCbi0">
<GenBuild baseName="UsbCbi0" mbdFilename="${MODULE_DIR}\UsbCbi0.mbd" msaFilename="${MODULE_DIR}\UsbCbi0.msa"/>
</target>
<target depends="UsbCbi0_clean" name="clean"/>
<target depends="UsbCbi0_cleanall" name="cleanall"/>
<target name="UsbCbi0_clean">
<OutputDirSetup baseName="UsbCbi0" mbdFilename="${MODULE_DIR}\UsbCbi0.mbd" msaFilename="${MODULE_DIR}\UsbCbi0.msa"/>
<if>
<available file="${DEST_DIR_OUTPUT}\UsbCbi0_build.xml"/>
<then>
<ant antfile="${DEST_DIR_OUTPUT}\UsbCbi0_build.xml" target="clean"/>
</then>
</if>
<delete dir="${DEST_DIR_OUTPUT}" excludes="*.xml"/>
</target>
<target name="UsbCbi0_cleanall">
<OutputDirSetup baseName="UsbCbi0" mbdFilename="${MODULE_DIR}\UsbCbi0.mbd" msaFilename="${MODULE_DIR}\UsbCbi0.msa"/>
<if>
<available file="${DEST_DIR_OUTPUT}\UsbCbi0_build.xml"/>
<then>
<ant antfile="${DEST_DIR_OUTPUT}\UsbCbi0_build.xml" target="cleanall"/>
</then>
</if>
<delete dir="${DEST_DIR_OUTPUT}"/>
<delete dir="${DEST_DIR_DEBUG}"/>
<delete>
<fileset dir="${BIN_DIR}" includes="**UsbCbi0*"/>
</delete>
</target>
</project>

View File

@@ -0,0 +1,43 @@
<?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>UsbCbi1</BaseName>
<Guid>B40612B2-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>
</Libraries>
</ModuleBuildDescription>

View File

@@ -0,0 +1,66 @@
<?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>UsbCbi1</BaseName>
<ModuleType>DXE_DRIVER</ModuleType>
<ComponentType>BS_DRIVER</ComponentType>
<Guid>B40612B2-A063-11d4-9A3A-0090273FC14D</Guid>
<Version>0</Version>
<Abstract>Component description file for UsbCbi1 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>
</LibraryClassDefinitions>
<SourceFiles>
<Filename>cbi1.c</Filename>
</SourceFiles>
<Includes>
<PackageName>MdePkg</PackageName>
<PackageName>EdkModulePkg</PackageName>
</Includes>
<Protocols>
<Protocol Usage="TO_START">DevicePath</Protocol>
<Protocol Usage="TO_START">UsbIo</Protocol>
<Protocol Usage="BY_START">UsbAtapi</Protocol>
</Protocols>
<Externs>
<Extern>
<ModuleEntryPoint></ModuleEntryPoint>
</Extern>
<Extern>
<DriverBinding>gCBI1DriverBinding</DriverBinding>
</Extern>
</Externs>
</ModuleSurfaceArea>

View 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="UsbCbi1"><!--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\UsbCbi\Dxe\Cbi1"/>
<property name="MODULE_DIR" value="${PACKAGE_DIR}\${MODULE_RELATIVE_PATH}"/>
<property name="COMMON_FILE" value="${WORKSPACE_DIR}\Tools\Conf\Common.xml"/>
<target name="UsbCbi1">
<GenBuild baseName="UsbCbi1" mbdFilename="${MODULE_DIR}\UsbCbi1.mbd" msaFilename="${MODULE_DIR}\UsbCbi1.msa"/>
</target>
<target depends="UsbCbi1_clean" name="clean"/>
<target depends="UsbCbi1_cleanall" name="cleanall"/>
<target name="UsbCbi1_clean">
<OutputDirSetup baseName="UsbCbi1" mbdFilename="${MODULE_DIR}\UsbCbi1.mbd" msaFilename="${MODULE_DIR}\UsbCbi1.msa"/>
<if>
<available file="${DEST_DIR_OUTPUT}\UsbCbi1_build.xml"/>
<then>
<ant antfile="${DEST_DIR_OUTPUT}\UsbCbi1_build.xml" target="clean"/>
</then>
</if>
<delete dir="${DEST_DIR_OUTPUT}" excludes="*.xml"/>
</target>
<target name="UsbCbi1_cleanall">
<OutputDirSetup baseName="UsbCbi1" mbdFilename="${MODULE_DIR}\UsbCbi1.mbd" msaFilename="${MODULE_DIR}\UsbCbi1.msa"/>
<if>
<available file="${DEST_DIR_OUTPUT}\UsbCbi1_build.xml"/>
<then>
<ant antfile="${DEST_DIR_OUTPUT}\UsbCbi1_build.xml" target="cleanall"/>
</then>
</if>
<delete dir="${DEST_DIR_OUTPUT}"/>
<delete dir="${DEST_DIR_DEBUG}"/>
<delete>
<fileset dir="${BIN_DIR}" includes="**UsbCbi1*"/>
</delete>
</target>
</project>

View File

@@ -0,0 +1,854 @@
/*++
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:
cbi1.c
Abstract:
cbi1 transportation protocol implementation files
--*/
#include "../cbi.h"
EFI_STATUS
EFIAPI
UsbCBI1DriverEntryPoint (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
//
// CBI Function prototypes
//
STATIC
EFI_STATUS
CBI1CommandPhase (
IN USB_CBI_DEVICE *UsbCbiDev,
IN VOID *Command,
IN UINT8 CommandSize,
OUT UINT32 *Result
);
STATIC
EFI_STATUS
CBI1DataPhase (
IN USB_CBI_DEVICE *UsbCbiDev,
IN UINT32 DataSize,
IN OUT VOID *DataBuffer,
IN EFI_USB_DATA_DIRECTION Direction,
IN UINT16 Timeout,
OUT UINT32 *Result
);
//
// USB Atapi implementation
//
STATIC
EFI_STATUS
EFIAPI
CBI1AtapiCommand (
IN EFI_USB_ATAPI_PROTOCOL *This,
IN VOID *Command,
IN UINT8 CommandSize,
IN VOID *DataBuffer,
IN UINT32 BufferLength,
IN EFI_USB_DATA_DIRECTION Direction,
IN UINT16 TimeOutInMilliSeconds
);
STATIC
EFI_STATUS
EFIAPI
CBI1MassStorageReset (
IN EFI_USB_ATAPI_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
);
//
// CBI1 Driver Binding Protocol
//
STATIC
EFI_STATUS
EFIAPI
CBI1DriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
);
STATIC
EFI_STATUS
EFIAPI
CBI1DriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
);
STATIC
EFI_STATUS
EFIAPI
CBI1DriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
);
VOID
Cbi1ReportStatusCode (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
IN EFI_STATUS_CODE_TYPE CodeType,
IN EFI_STATUS_CODE_VALUE Value
);
EFI_DRIVER_BINDING_PROTOCOL gCBI1DriverBinding = {
CBI1DriverBindingSupported,
CBI1DriverBindingStart,
CBI1DriverBindingStop,
0x10,
NULL,
NULL
};
STATIC EFI_USB_ATAPI_PROTOCOL CBI1AtapiProtocol = {
CBI1AtapiCommand,
CBI1MassStorageReset,
0
};
//
// CBI1 Driver Binding implementation
//
STATIC
EFI_STATUS
EFIAPI
CBI1DriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
/*++
Routine Description:
Test to see if this driver supports ControllerHandle. Any ControllerHandle
than contains a BlockIo and DiskIo protocol can be supported.
Arguments:
This - Protocol instance pointer.
ControllerHandle - Handle of device to test
RemainingDevicePath - Not used
Returns:
EFI_SUCCESS - This driver supports this device
EFI_ALREADY_STARTED - This driver is already running on this device
other - This driver does not support this device
--*/
{
EFI_STATUS Status;
EFI_USB_IO_PROTOCOL *UsbIo;
EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
//
// Check if the Controller supports USB IO protocol
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiUsbIoProtocolGuid,
(VOID **) &UsbIo,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Get the Controller interface descriptor
//
Status = UsbIo->UsbGetInterfaceDescriptor (
UsbIo,
&InterfaceDescriptor
);
if (EFI_ERROR (Status)) {
goto Exit;
}
//
// Bug here: just let Vendor specific CBI protocol get supported
//
if (!((InterfaceDescriptor.InterfaceClass == 0xFF) &&
(InterfaceDescriptor.InterfaceProtocol == 0))) {
Status = EFI_UNSUPPORTED;
goto Exit;
}
Exit:
gBS->CloseProtocol (
ControllerHandle,
&gEfiUsbIoProtocolGuid,
This->DriverBindingHandle,
ControllerHandle
);
return Status;
}
STATIC
EFI_STATUS
EFIAPI
CBI1DriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
/*++
Routine Description:
Start this driver on ControllerHandle by opening a Block IO and Disk IO
protocol, reading Device Path, and creating a child handle with a
Disk IO and device path protocol.
Arguments:
This - Protocol instance pointer.
ControllerHandle - Handle of device to bind driver to
RemainingDevicePath - Not used
Returns:
EFI_SUCCESS - This driver is added to DeviceHandle
EFI_ALREADY_STARTED - This driver is already running on DeviceHandle
other - This driver does not support this device
--*/
{
USB_CBI_DEVICE *UsbCbiDev;
UINT8 Index;
EFI_USB_ENDPOINT_DESCRIPTOR EndpointDescriptor;
EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
EFI_STATUS Status;
EFI_USB_IO_PROTOCOL *UsbIo;
BOOLEAN Found;
Found = FALSE;
//
// Check if the Controller supports USB IO protocol
//
UsbCbiDev = NULL;
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiUsbIoProtocolGuid,
(VOID **) &UsbIo,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Get the controller interface descriptor
//
Status = UsbIo->UsbGetInterfaceDescriptor (
UsbIo,
&InterfaceDescriptor
);
if (EFI_ERROR (Status)) {
goto ErrorExit;
}
CBI1AtapiProtocol.CommandProtocol = InterfaceDescriptor.InterfaceSubClass;
UsbCbiDev = AllocateZeroPool (sizeof (USB_CBI_DEVICE));
if (UsbCbiDev == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto ErrorExit;
}
UsbCbiDev->Signature = USB_CBI_DEVICE_SIGNATURE;
UsbCbiDev->UsbIo = UsbIo;
CopyMem (&UsbCbiDev->InterfaceDescriptor, &InterfaceDescriptor, sizeof (InterfaceDescriptor));
CopyMem (&UsbCbiDev->UsbAtapiProtocol , &CBI1AtapiProtocol, sizeof (CBI1AtapiProtocol));
//
// Get the Device Path Protocol on Controller's handle
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiDevicePathProtocolGuid,
(VOID **) &UsbCbiDev->DevicePath,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
goto ErrorExit;
}
for (Index = 0; Index < InterfaceDescriptor.NumEndpoints; Index++) {
UsbIo->UsbGetEndpointDescriptor (
UsbIo,
Index,
&EndpointDescriptor
);
//
// We parse bulk endpoint
//
if (EndpointDescriptor.Attributes == 0x02) {
if (EndpointDescriptor.EndpointAddress & 0x80) {
CopyMem (&UsbCbiDev->BulkInEndpointDescriptor, &EndpointDescriptor, sizeof(EndpointDescriptor));
//UsbCbiDev->BulkInEndpointDescriptor = EndpointDescriptor;
} else {
CopyMem (&UsbCbiDev->BulkOutEndpointDescriptor, &EndpointDescriptor, sizeof(EndpointDescriptor));
//UsbCbiDev->BulkOutEndpointDescriptor = EndpointDescriptor;
}
Found = TRUE;
}
//
// We parse interrupt endpoint
//
if (EndpointDescriptor.Attributes == 0x03) {
CopyMem (&UsbCbiDev->InterruptEndpointDescriptor, &EndpointDescriptor, sizeof(EndpointDescriptor));
//UsbCbiDev->InterruptEndpointDescriptor = EndpointDescriptor;
Found = TRUE;
}
}
//
// Double check we have these
//
if (!Found) {
goto ErrorExit;
}
//
// After installing Usb-Atapi protocol onto this handle
// it will be called by upper layer drivers such as Fat
//
Cbi1ReportStatusCode (
UsbCbiDev->DevicePath,
EFI_PROGRESS_CODE,
(EFI_PERIPHERAL_REMOVABLE_MEDIA | EFI_P_PC_ENABLE)
);
Status = gBS->InstallProtocolInterface (
&ControllerHandle,
&gEfiUsbAtapiProtocolGuid,
EFI_NATIVE_INTERFACE,
&UsbCbiDev->UsbAtapiProtocol
);
if (EFI_ERROR (Status)) {
goto ErrorExit;
}
return EFI_SUCCESS;
ErrorExit:
gBS->CloseProtocol (
ControllerHandle,
&gEfiUsbIoProtocolGuid,
This->DriverBindingHandle,
ControllerHandle
);
if (UsbCbiDev != NULL) {
gBS->FreePool (UsbCbiDev);
}
return Status;
}
STATIC
EFI_STATUS
EFIAPI
CBI1DriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
)
/*++
Routine Description:
Stop this driver on ControllerHandle. Support stoping any child handles
created by this driver.
Arguments:
This - Protocol instance pointer.
ControllerHandle - Handle of device to stop driver on
NumberOfChildren - Number of Children in the ChildHandleBuffer
ChildHandleBuffer - List of handles for the children we need to stop.
Returns:
EFI_SUCCESS - This driver is removed DeviceHandle
EFI_UNSUPPORTED - Can't open the gEfiUsbAtapiProtocolGuid protocol
other - This driver was not removed from this device
--*/
{
EFI_STATUS Status;
EFI_USB_ATAPI_PROTOCOL *CBI1AtapiProtocol;
USB_CBI_DEVICE *UsbCbiDev;
EFI_USB_IO_PROTOCOL *UsbIo;
//
// Get our context back.
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiUsbAtapiProtocolGuid,
(VOID **) &CBI1AtapiProtocol,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
UsbCbiDev = USB_CBI_DEVICE_FROM_THIS (CBI1AtapiProtocol);
UsbIo = UsbCbiDev->UsbIo;
Cbi1ReportStatusCode (
UsbCbiDev->DevicePath,
EFI_PROGRESS_CODE,
(EFI_PERIPHERAL_REMOVABLE_MEDIA | EFI_P_PC_DISABLE)
);
Status = gBS->UninstallProtocolInterface (
ControllerHandle,
&gEfiUsbAtapiProtocolGuid,
&UsbCbiDev->UsbAtapiProtocol
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = gBS->CloseProtocol (
ControllerHandle,
&gEfiUsbIoProtocolGuid,
This->DriverBindingHandle,
ControllerHandle
);
gBS->FreePool (UsbCbiDev);
return Status;
}
//
// CBI1 command
//
STATIC
EFI_STATUS
CBI1CommandPhase (
IN USB_CBI_DEVICE *UsbCbiDev,
IN VOID *Command,
IN UINT8 CommandSize,
OUT UINT32 *Result
)
/*++
Routine Description:
In order to make consistence, CBI transportation protocol does only use
the first 3 parameters. Other parameters are not used here.
Arguments:
UsbCbiDev - USB_CBI_DEVICE
Command - Command to send
CommandSize - Command Size
Result - Result to return
Returns:
EFI_SUCCESS - This driver is removed DeviceHandle
other - This driver was not removed from this device
--*/
{
EFI_STATUS Status;
EFI_USB_IO_PROTOCOL *UsbIo;
EFI_USB_DEVICE_REQUEST Request;
UINT32 TimeOutInMilliSeconds;
UsbIo = UsbCbiDev->UsbIo;
ZeroMem (&Request, sizeof (EFI_USB_DEVICE_REQUEST));
//
// Device request see CBI specification
//
Request.RequestType = 0x21;
Request.Length = CommandSize;
TimeOutInMilliSeconds = 1000;
Status = UsbIo->UsbControlTransfer (
UsbIo,
&Request,
EfiUsbDataOut,
TimeOutInMilliSeconds,
Command,
CommandSize,
Result
);
return Status;
}
STATIC
EFI_STATUS
CBI1DataPhase (
IN USB_CBI_DEVICE *UsbCbiDev,
IN UINT32 DataSize,
IN OUT VOID *DataBuffer,
IN EFI_USB_DATA_DIRECTION Direction,
IN UINT16 Timeout,
OUT UINT32 *Result
)
/*++
Routine Description:
CBI1 Data Phase
Arguments:
UsbCbiDev - USB_CBI_DEVICE
DataSize - Data Size
DataBuffer - Data Buffer
Direction - IN/OUT/NODATA
Timeout - Time out value in milliseconds
Result - Transfer result
Returns:
EFI_SUCCESS - Success
--*/
{
EFI_STATUS Status;
EFI_USB_IO_PROTOCOL *UsbIo;
UINT8 EndpointAddr;
UINTN Remain;
UINTN Increment;
UINT32 MaxPacketLen;
UINT8 *BufferPtr;
UsbIo = UsbCbiDev->UsbIo;
Remain = DataSize;
BufferPtr = (UINT8 *) DataBuffer;
//
// retrieve the the max packet length of the given endpoint
//
if (Direction == EfiUsbDataIn) {
MaxPacketLen = (UsbCbiDev->BulkInEndpointDescriptor).MaxPacketSize;
EndpointAddr = (UsbCbiDev->BulkInEndpointDescriptor).EndpointAddress;
} else {
MaxPacketLen = (UsbCbiDev->BulkOutEndpointDescriptor).MaxPacketSize;
EndpointAddr = (UsbCbiDev->BulkOutEndpointDescriptor).EndpointAddress;
}
while (Remain > 0) {
//
// Using 15 packets to aVOID Bitstuff error
//
if (Remain > 15 * MaxPacketLen) {
Increment = 15 * MaxPacketLen;
} else {
Increment = Remain;
}
Status = UsbIo->UsbBulkTransfer (
UsbIo,
EndpointAddr,
BufferPtr,
&Increment,
Timeout,
Result
);
if (EFI_ERROR (Status)) {
goto ErrorExit;
}
BufferPtr += Increment;
Remain -= Increment;
}
return EFI_SUCCESS;
ErrorExit:
if (Direction == EfiUsbDataIn) {
Cbi1ReportStatusCode (
UsbCbiDev->DevicePath,
EFI_ERROR_CODE | EFI_ERROR_MINOR,
(EFI_PERIPHERAL_REMOVABLE_MEDIA | EFI_P_EC_INPUT_ERROR)
);
} else {
Cbi1ReportStatusCode (
UsbCbiDev->DevicePath,
EFI_ERROR_CODE | EFI_ERROR_MINOR,
(EFI_PERIPHERAL_REMOVABLE_MEDIA | EFI_P_EC_OUTPUT_ERROR)
);
}
if (((*Result) & EFI_USB_ERR_STALL) == EFI_USB_ERR_STALL) {
//
// just endpoint stall happens
//
UsbClearEndpointHalt (
UsbIo,
EndpointAddr,
Result
);
}
return Status;
}
//
// CBI1 USB ATAPI Protocol
//
STATIC
EFI_STATUS
EFIAPI
CBI1MassStorageReset (
IN EFI_USB_ATAPI_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
)
/*++
Routine Description:
Reset CBI Devices
Arguments:
This - Protocol instance pointer.
ExtendedVerification - TRUE if we need to do strictly reset.
Returns:
EFI_SUCCESS - Command succeeded.
EFI_DEVICE_ERROR - Command failed.
--*/
{
UINT8 ResetCommand[12];
EFI_STATUS Status;
EFI_USB_IO_PROTOCOL *UsbIo;
USB_CBI_DEVICE *UsbCbiDev;
UINT8 EndpointAddr;
UINT32 Result;
UsbCbiDev = USB_CBI_DEVICE_FROM_THIS (This);
UsbIo = UsbCbiDev->UsbIo;
Cbi1ReportStatusCode (
UsbCbiDev->DevicePath,
EFI_PROGRESS_CODE,
(EFI_PERIPHERAL_REMOVABLE_MEDIA | EFI_P_PC_RESET)
);
if (ExtendedVerification) {
UsbIo->UsbPortReset (UsbIo);
}
//
// CBI reset command protocol
//
SetMem (ResetCommand, sizeof (ResetCommand), 0xff);
ResetCommand[0] = 0x1d;
ResetCommand[1] = 0x04;
Status = CBI1CommandPhase (
UsbCbiDev,
ResetCommand,
12,
&Result
);
//
// clear bulk in endpoint stall feature
//
EndpointAddr = UsbCbiDev->BulkInEndpointDescriptor.EndpointAddress;
UsbClearEndpointHalt (
UsbIo,
EndpointAddr,
&Result
);
//
// clear bulk out endpoint stall feature
//
EndpointAddr = UsbCbiDev->BulkOutEndpointDescriptor.EndpointAddress;
UsbClearEndpointHalt (
UsbIo,
EndpointAddr,
&Result
);
return EFI_SUCCESS;
}
STATIC
EFI_STATUS
EFIAPI
CBI1AtapiCommand (
IN EFI_USB_ATAPI_PROTOCOL *This,
IN VOID *Command,
IN UINT8 CommandSize,
IN VOID *DataBuffer,
IN UINT32 BufferLength,
IN EFI_USB_DATA_DIRECTION Direction,
IN UINT16 TimeOutInMilliSeconds
)
/*++
Routine Description:
Send ATAPI command using CBI1 protocol.
Arguments:
This - Protocol instance pointer.
Command - Command buffer
CommandSize - Size of Command Buffer
DataBuffer - Data buffer
BufferLength - Length of Data buffer
Direction - Data direction of this command
TimeOutInMilliSeconds - Timeout value in ms
Returns:
EFI_SUCCESS - Command succeeded.
EFI_DEVICE_ERROR - Command failed.
--*/
{
EFI_STATUS Status;
USB_CBI_DEVICE *UsbCbiDev;
UINT32 Result;
UINT8 Index;
UINT8 MaxRetryNum;
UsbCbiDev = USB_CBI_DEVICE_FROM_THIS (This);
MaxRetryNum = 3;
for (Index = 0; Index < MaxRetryNum; Index++) {
//
// First send ATAPI command through CBI1
//
Status = CBI1CommandPhase (
UsbCbiDev,
Command,
CommandSize,
&Result
);
if (EFI_ERROR (Status)) {
switch (Result) {
case EFI_USB_NOERROR:
case EFI_USB_ERR_STALL:
case EFI_USB_ERR_SYSTEM:
return EFI_DEVICE_ERROR;
default:
continue;
break;
}
} else {
break;
}
}
if (Index == MaxRetryNum) {
return EFI_DEVICE_ERROR;
}
for (Index = 0; Index < MaxRetryNum; Index++) {
//
// Send/Get Data if there is a Data Stage
//
switch (Direction) {
case EfiUsbDataIn:
case EfiUsbDataOut:
Status = CBI1DataPhase (
UsbCbiDev,
BufferLength,
DataBuffer,
Direction,
TimeOutInMilliSeconds,
&Result
);
if (EFI_ERROR (Status)) {
switch (Result) {
case EFI_USB_NOERROR:
case EFI_USB_ERR_STALL:
case EFI_USB_ERR_SYSTEM:
return EFI_DEVICE_ERROR;
default:
continue;
break;
}
} else {
return EFI_SUCCESS;
}
break;
case EfiUsbNoData:
return EFI_SUCCESS;
}
}
//
// If goes here, means met error.
//
return EFI_DEVICE_ERROR;
}
VOID
Cbi1ReportStatusCode (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
IN EFI_STATUS_CODE_TYPE CodeType,
IN EFI_STATUS_CODE_VALUE Value
)
/*++
Routine Description:
Report Status Code in Usb Cbi1 Driver
Arguments:
DevicePath - Use this to get Device Path
CodeType - Status Code Type
CodeValue - Status Code Value
Returns:
None
--*/
{
REPORT_STATUS_CODE_WITH_DEVICE_PATH (
CodeType,
Value,
DevicePath
);
}

View File

@@ -0,0 +1,70 @@
/*++
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:
cbi.h
Abstract:
USB CBI transportation protocol definitions.
--*/
#ifndef _CBI_H
#define _CBI_H
#include <IndustryStandard/usb.h>
#define bit(a) (1 << (a))
#define MASS_STORAGE_CLASS 0x08
#define CBI0_INTERFACE_PROTOCOL 0x00
#define CBI1_INTERFACE_PROTOCOL 0x01
//
// in millisecond unit
//
#define STALL_1_SECOND 1000
#pragma pack(1)
//
// Data block definition for transportation through interrupt endpoint
//
typedef struct {
UINT8 bType;
UINT8 bValue;
} INTERRUPT_DATA_BLOCK;
#pragma pack()
#define USB_CBI_DEVICE_SIGNATURE EFI_SIGNATURE_32 ('u', 'c', 'b', 'i')
//
// Device structure for CBI, interrupt endpoint may be not used in
// CBI1 Protocol
//
typedef struct {
UINT32 Signature;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
EFI_USB_ATAPI_PROTOCOL UsbAtapiProtocol;
EFI_USB_IO_PROTOCOL *UsbIo;
EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
EFI_USB_ENDPOINT_DESCRIPTOR BulkInEndpointDescriptor;
EFI_USB_ENDPOINT_DESCRIPTOR BulkOutEndpointDescriptor;
EFI_USB_ENDPOINT_DESCRIPTOR InterruptEndpointDescriptor;
EFI_UNICODE_STRING_TABLE *ControllerNameTable;
} USB_CBI_DEVICE;
#define USB_CBI_DEVICE_FROM_THIS(a) \
CR(a, USB_CBI_DEVICE, UsbAtapiProtocol, USB_CBI_DEVICE_SIGNATURE)
#endif

View File

@@ -0,0 +1,215 @@
/*++
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 "keyboard.h"
//
// EFI Component Name Functions
//
EFI_STATUS
EFIAPI
UsbKeyboardComponentNameGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
);
EFI_STATUS
EFIAPI
UsbKeyboardComponentNameGetControllerName (
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 gUsbKeyboardComponentName = {
UsbKeyboardComponentNameGetDriverName,
UsbKeyboardComponentNameGetControllerName,
"eng"
};
STATIC EFI_UNICODE_STRING_TABLE mUsbKeyboardDriverNameTable[] = {
{ "eng", (CHAR16 *) L"Usb Keyboard Driver" },
{ NULL , NULL }
};
EFI_STATUS
EFIAPI
UsbKeyboardComponentNameGetDriverName (
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,
gUsbKeyboardComponentName.SupportedLanguages,
mUsbKeyboardDriverNameTable,
DriverName
);
}
EFI_STATUS
EFIAPI
UsbKeyboardComponentNameGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
)
/*++
Routine Description:
Retrieves a Unicode string that is the user readable name of the controller
that is being managed by an EFI Driver.
Arguments:
This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
ControllerHandle - The handle of a controller that the driver specified by
This is managing. This handle specifies the controller
whose name is to be returned.
ChildHandle - The handle of the child controller to retrieve the name
of. This is an optional parameter that may be NULL. It
will be NULL for device drivers. It will also be NULL
for a bus drivers that wish to retrieve the name of the
bus controller. It will not be NULL for a bus driver
that wishes to retrieve the name of a child controller.
Language - A pointer to a three character ISO 639-2 language
identifier. This is the language of the controller name
that that the caller is requesting, and it must match one
of the languages specified in SupportedLanguages. The
number of languages supported by a driver is up to the
driver writer.
ControllerName - A pointer to the Unicode string to return. This Unicode
string is the name of the controller specified by
ControllerHandle and ChildHandle in the language specified
by Language from the point of view of the driver specified
by This.
Returns:
EFI_SUCCESS - The Unicode string for the user readable name in the
language specified by Language for the driver
specified by This was returned in DriverName.
EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.
EFI_INVALID_PARAMETER - Language is NULL.
EFI_INVALID_PARAMETER - ControllerName is NULL.
EFI_UNSUPPORTED - The driver specified by This is not currently managing
the controller specified by ControllerHandle and
ChildHandle.
EFI_UNSUPPORTED - The driver specified by This does not support the
language specified by Language.
--*/
{
EFI_STATUS Status;
USB_KB_DEV *UsbKbDev;
EFI_SIMPLE_TEXT_IN_PROTOCOL *SimpleTxtIn;
EFI_USB_IO_PROTOCOL *UsbIoProtocol;
//
// This is a device driver, so ChildHandle must be NULL.
//
if (ChildHandle != NULL) {
return EFI_UNSUPPORTED;
}
//
// Check Controller's handle
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiUsbIoProtocolGuid,
(VOID **) &UsbIoProtocol,
gUsbKeyboardDriverBinding.DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (!EFI_ERROR (Status)) {
gBS->CloseProtocol (
ControllerHandle,
&gEfiUsbIoProtocolGuid,
gUsbKeyboardDriverBinding.DriverBindingHandle,
ControllerHandle
);
return EFI_UNSUPPORTED;
}
if (Status != EFI_ALREADY_STARTED) {
return EFI_UNSUPPORTED;
}
//
// Get the device context
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiSimpleTextInProtocolGuid,
(VOID **) &SimpleTxtIn,
gUsbKeyboardDriverBinding.DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
return Status;
}
UsbKbDev = USB_KB_DEV_FROM_THIS (SimpleTxtIn);
return LookupUnicodeString (
Language,
gUsbKeyboardComponentName.SupportedLanguages,
UsbKbDev->ControllerNameTable,
ControllerName
);
}

View 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>UsbKb</BaseName>
<Guid>2D2E62CF-9ECF-43b7-8219-94E7FC713DFE</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>UefiRuntimeServicesTableLib</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>
</Libraries>
</ModuleBuildDescription>

View File

@@ -0,0 +1,77 @@
<?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>UsbKb</BaseName>
<ModuleType>DXE_DRIVER</ModuleType>
<ComponentType>BS_DRIVER</ComponentType>
<Guid>2D2E62CF-9ECF-43b7-8219-94E7FC713DFE</Guid>
<Version>0</Version>
<Abstract>Component description file for UsbKb 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">UefiRuntimeServicesTableLib</LibraryClass>
</LibraryClassDefinitions>
<SourceFiles>
<Filename>efikey.h</Filename>
<Filename>keyboard.h</Filename>
<Filename>efikey.c</Filename>
<Filename>keyboard.c</Filename>
<Filename>ComponentName.c</Filename>
</SourceFiles>
<Includes>
<PackageName>MdePkg</PackageName>
<PackageName>EdkModulePkg</PackageName>
</Includes>
<Protocols>
<Protocol Usage="TO_START">DevicePath</Protocol>
<Protocol Usage="TO_START">UsbIo</Protocol>
<Protocol Usage="BY_START">SimpleTextIn</Protocol>
</Protocols>
<Guids>
<GuidEntry Usage="SOMETIMES_CONSUMED">
<C_Name>HotPlugDevice</C_Name>
</GuidEntry>
</Guids>
<Externs>
<Extern>
<ModuleEntryPoint></ModuleEntryPoint>
</Extern>
<Extern>
<DriverBinding>gUsbKeyboardDriverBinding</DriverBinding>
<ComponentName>gUsbKeyboardComponentName</ComponentName>
</Extern>
</Externs>
</ModuleSurfaceArea>

View 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="UsbKb"><!--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\UsbKb\Dxe"/>
<property name="MODULE_DIR" value="${PACKAGE_DIR}\${MODULE_RELATIVE_PATH}"/>
<property name="COMMON_FILE" value="${WORKSPACE_DIR}\Tools\Conf\Common.xml"/>
<target name="UsbKb">
<GenBuild baseName="UsbKb" mbdFilename="${MODULE_DIR}\UsbKb.mbd" msaFilename="${MODULE_DIR}\UsbKb.msa"/>
</target>
<target depends="UsbKb_clean" name="clean"/>
<target depends="UsbKb_cleanall" name="cleanall"/>
<target name="UsbKb_clean">
<OutputDirSetup baseName="UsbKb" mbdFilename="${MODULE_DIR}\UsbKb.mbd" msaFilename="${MODULE_DIR}\UsbKb.msa"/>
<if>
<available file="${DEST_DIR_OUTPUT}\UsbKb_build.xml"/>
<then>
<ant antfile="${DEST_DIR_OUTPUT}\UsbKb_build.xml" target="clean"/>
</then>
</if>
<delete dir="${DEST_DIR_OUTPUT}" excludes="*.xml"/>
</target>
<target name="UsbKb_cleanall">
<OutputDirSetup baseName="UsbKb" mbdFilename="${MODULE_DIR}\UsbKb.mbd" msaFilename="${MODULE_DIR}\UsbKb.msa"/>
<if>
<available file="${DEST_DIR_OUTPUT}\UsbKb_build.xml"/>
<then>
<ant antfile="${DEST_DIR_OUTPUT}\UsbKb_build.xml" target="cleanall"/>
</then>
</if>
<delete dir="${DEST_DIR_OUTPUT}"/>
<delete dir="${DEST_DIR_DEBUG}"/>
<delete>
<fileset dir="${BIN_DIR}" includes="**UsbKb*"/>
</delete>
</target>
</project>

View File

@@ -0,0 +1,772 @@
/*++
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:
EfiKey.c
Abstract:
USB Keyboard Driver
Revision History
--*/
#include "efikey.h"
#include "keyboard.h"
//
// Prototypes
// Driver model protocol interface
//
EFI_STATUS
EFIAPI
USBKeyboardDriverBindingEntryPoint (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
EFI_STATUS
EFIAPI
USBKeyboardDriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
);
EFI_STATUS
EFIAPI
USBKeyboardDriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
);
EFI_STATUS
EFIAPI
USBKeyboardDriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
);
//
// Simple Text In Protocol Interface
//
STATIC
EFI_STATUS
EFIAPI
USBKeyboardReset (
IN EFI_SIMPLE_TEXT_IN_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
);
STATIC
EFI_STATUS
EFIAPI
USBKeyboardReadKeyStroke (
IN EFI_SIMPLE_TEXT_IN_PROTOCOL *This,
OUT EFI_INPUT_KEY *Key
);
STATIC
VOID
EFIAPI
USBKeyboardWaitForKey (
IN EFI_EVENT Event,
IN VOID *Context
);
//
// Helper functions
//
STATIC
EFI_STATUS
USBKeyboardCheckForKey (
IN USB_KB_DEV *UsbKeyboardDevice
);
//
// USB Keyboard Driver Global Variables
//
EFI_DRIVER_BINDING_PROTOCOL gUsbKeyboardDriverBinding = {
USBKeyboardDriverBindingSupported,
USBKeyboardDriverBindingStart,
USBKeyboardDriverBindingStop,
0x10,
NULL,
NULL
};
EFI_STATUS
EFIAPI
USBKeyboardDriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
/*++
Routine Description:
Supported.
Arguments:
This - EFI_DRIVER_BINDING_PROTOCOL
Controller - Controller handle
RemainingDevicePath - EFI_DEVICE_PATH_PROTOCOL
Returns:
EFI_STATUS
--*/
{
EFI_STATUS OpenStatus;
EFI_USB_IO_PROTOCOL *UsbIo;
EFI_STATUS Status;
//
// Check if USB_IO protocol is attached on the controller handle.
//
OpenStatus = gBS->OpenProtocol (
Controller,
&gEfiUsbIoProtocolGuid,
(VOID **) &UsbIo,
This->DriverBindingHandle,
Controller,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (OpenStatus)) {
return OpenStatus;
}
//
// Use the USB I/O protocol interface to check whether the Controller is
// the Keyboard controller that can be managed by this driver.
//
Status = EFI_SUCCESS;
if (!IsUSBKeyboard (UsbIo)) {
Status = EFI_UNSUPPORTED;
}
gBS->CloseProtocol (
Controller,
&gEfiUsbIoProtocolGuid,
This->DriverBindingHandle,
Controller
);
return Status;
}
EFI_STATUS
EFIAPI
USBKeyboardDriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
/*++
Routine Description:
Start.
Arguments:
This - EFI_DRIVER_BINDING_PROTOCOL
Controller - Controller handle
RemainingDevicePath - EFI_DEVICE_PATH_PROTOCOL
Returns:
EFI_SUCCESS - Success
EFI_OUT_OF_RESOURCES - Can't allocate memory
EFI_UNSUPPORTED - The Start routine fail
--*/
{
EFI_STATUS Status;
EFI_USB_IO_PROTOCOL *UsbIo;
USB_KB_DEV *UsbKeyboardDevice;
UINT8 EndpointNumber;
EFI_USB_ENDPOINT_DESCRIPTOR EndpointDescriptor;
UINT8 Index;
UINT8 EndpointAddr;
UINT8 PollingInterval;
UINT8 PacketSize;
BOOLEAN Found;
UsbKeyboardDevice = NULL;
Found = FALSE;
//
// Open USB_IO Protocol
//
Status = gBS->OpenProtocol (
Controller,
&gEfiUsbIoProtocolGuid,
(VOID **) &UsbIo,
This->DriverBindingHandle,
Controller,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
return Status;
}
UsbKeyboardDevice = AllocateZeroPool (sizeof (USB_KB_DEV));
if (UsbKeyboardDevice == NULL) {
gBS->CloseProtocol (
Controller,
&gEfiUsbIoProtocolGuid,
This->DriverBindingHandle,
Controller
);
return EFI_OUT_OF_RESOURCES;
}
//
// Get the Device Path Protocol on Controller's handle
//
Status = gBS->OpenProtocol (
Controller,
&gEfiDevicePathProtocolGuid,
(VOID **) &UsbKeyboardDevice->DevicePath,
This->DriverBindingHandle,
Controller,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
gBS->FreePool (UsbKeyboardDevice);
gBS->CloseProtocol (
Controller,
&gEfiUsbIoProtocolGuid,
This->DriverBindingHandle,
Controller
);
return Status;
}
//
// Report that the usb keyboard is being enabled
//
KbdReportStatusCode (
UsbKeyboardDevice->DevicePath,
EFI_PROGRESS_CODE,
(EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_ENABLE)
);
//
// This is pretty close to keyboard detection, so log progress
//
KbdReportStatusCode (
UsbKeyboardDevice->DevicePath,
EFI_PROGRESS_CODE,
(EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_PRESENCE_DETECT)
);
//
// Initialize UsbKeyboardDevice
//
UsbKeyboardDevice->UsbIo = UsbIo;
//
// Get interface & endpoint descriptor
//
UsbIo->UsbGetInterfaceDescriptor (
UsbIo,
&UsbKeyboardDevice->InterfaceDescriptor
);
EndpointNumber = UsbKeyboardDevice->InterfaceDescriptor.NumEndpoints;
for (Index = 0; Index < EndpointNumber; Index++) {
UsbIo->UsbGetEndpointDescriptor (
UsbIo,
Index,
&EndpointDescriptor
);
if ((EndpointDescriptor.Attributes & 0x03) == 0x03) {
//
// We only care interrupt endpoint here
//
CopyMem (&UsbKeyboardDevice->IntEndpointDescriptor, &EndpointDescriptor, sizeof (EndpointDescriptor));
//UsbKeyboardDevice->IntEndpointDescriptor = EndpointDescriptor;
Found = TRUE;
}
}
if (!Found) {
//
// No interrupt endpoint found, then return unsupported.
//
gBS->FreePool (UsbKeyboardDevice);
gBS->CloseProtocol (
Controller,
&gEfiUsbIoProtocolGuid,
This->DriverBindingHandle,
Controller
);
return EFI_UNSUPPORTED;
}
UsbKeyboardDevice->Signature = USB_KB_DEV_SIGNATURE;
UsbKeyboardDevice->SimpleInput.Reset = USBKeyboardReset;
UsbKeyboardDevice->SimpleInput.ReadKeyStroke = USBKeyboardReadKeyStroke;
Status = gBS->CreateEvent (
EFI_EVENT_NOTIFY_WAIT,
EFI_TPL_NOTIFY,
USBKeyboardWaitForKey,
UsbKeyboardDevice,
&(UsbKeyboardDevice->SimpleInput.WaitForKey)
);
if (EFI_ERROR (Status)) {
gBS->FreePool (UsbKeyboardDevice);
gBS->CloseProtocol (
Controller,
&gEfiUsbIoProtocolGuid,
This->DriverBindingHandle,
Controller
);
return Status;
}
//
// Install simple txt in protocol interface
// for the usb keyboard device.
// Usb keyboard is a hot plug device, and expected to work immediately
// when plugging into system, so a HotPlugDeviceGuid is installed onto
// the usb keyboard device handle, to distinguish it from other conventional
// console devices.
//
Status = gBS->InstallMultipleProtocolInterfaces (
&Controller,
&gEfiSimpleTextInProtocolGuid,
&UsbKeyboardDevice->SimpleInput,
&gEfiHotPlugDeviceGuid,
NULL,
NULL
);
if (EFI_ERROR (Status)) {
gBS->CloseEvent (UsbKeyboardDevice->SimpleInput.WaitForKey);
gBS->FreePool (UsbKeyboardDevice);
gBS->CloseProtocol (
Controller,
&gEfiUsbIoProtocolGuid,
This->DriverBindingHandle,
Controller
);
return Status;
}
//
// Reset USB Keyboard Device
//
Status = UsbKeyboardDevice->SimpleInput.Reset (
&UsbKeyboardDevice->SimpleInput,
TRUE
);
if (EFI_ERROR (Status)) {
gBS->UninstallMultipleProtocolInterfaces (
Controller,
&gEfiSimpleTextInProtocolGuid,
&UsbKeyboardDevice->SimpleInput,
&gEfiHotPlugDeviceGuid,
NULL,
NULL
);
gBS->CloseEvent (UsbKeyboardDevice->SimpleInput.WaitForKey);
gBS->FreePool (UsbKeyboardDevice);
gBS->CloseProtocol (
Controller,
&gEfiUsbIoProtocolGuid,
This->DriverBindingHandle,
Controller
);
return Status;
}
//
// submit async interrupt transfer
//
EndpointAddr = UsbKeyboardDevice->IntEndpointDescriptor.EndpointAddress;
PollingInterval = UsbKeyboardDevice->IntEndpointDescriptor.Interval;
PacketSize = (UINT8) (UsbKeyboardDevice->IntEndpointDescriptor.MaxPacketSize);
Status = UsbIo->UsbAsyncInterruptTransfer (
UsbIo,
EndpointAddr,
TRUE,
PollingInterval,
PacketSize,
KeyboardHandler,
UsbKeyboardDevice
);
if (EFI_ERROR (Status)) {
gBS->UninstallMultipleProtocolInterfaces (
Controller,
&gEfiSimpleTextInProtocolGuid,
&UsbKeyboardDevice->SimpleInput,
&gEfiHotPlugDeviceGuid,
NULL,
NULL
);
gBS->CloseEvent (UsbKeyboardDevice->SimpleInput.WaitForKey);
gBS->FreePool (UsbKeyboardDevice);
gBS->CloseProtocol (
Controller,
&gEfiUsbIoProtocolGuid,
This->DriverBindingHandle,
Controller
);
return Status;
}
UsbKeyboardDevice->ControllerNameTable = NULL;
AddUnicodeString (
"eng",
gUsbKeyboardComponentName.SupportedLanguages,
&UsbKeyboardDevice->ControllerNameTable,
(CHAR16 *) L"Generic Usb Keyboard"
);
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
USBKeyboardDriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
)
/*++
Routine Description:
Stop.
Arguments:
This - EFI_DRIVER_BINDING_PROTOCOL
Controller - Controller handle
NumberOfChildren - Child handle number
ChildHandleBuffer - Child handle buffer
Returns:
EFI_SUCCESS - Success
EFI_UNSUPPORTED - Can't support
--*/
{
EFI_STATUS Status;
EFI_SIMPLE_TEXT_IN_PROTOCOL *SimpleInput;
USB_KB_DEV *UsbKeyboardDevice;
EFI_USB_IO_PROTOCOL *UsbIo;
Status = gBS->OpenProtocol (
Controller,
&gEfiSimpleTextInProtocolGuid,
(VOID **) &SimpleInput,
This->DriverBindingHandle,
Controller,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
//
// Get USB_KB_DEV instance.
//
UsbKeyboardDevice = USB_KB_DEV_FROM_THIS (SimpleInput);
gBS->CloseProtocol (
Controller,
&gEfiSimpleTextInProtocolGuid,
This->DriverBindingHandle,
Controller
);
UsbIo = UsbKeyboardDevice->UsbIo;
//
// Uninstall the Asyn Interrupt Transfer from this device
// will disable the key data input from this device
//
KbdReportStatusCode (
UsbKeyboardDevice->DevicePath,
EFI_PROGRESS_CODE,
(EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_DISABLE)
);
//
// Destroy asynchronous interrupt transfer
//
UsbKeyboardDevice->UsbIo->UsbAsyncInterruptTransfer (
UsbKeyboardDevice->UsbIo,
UsbKeyboardDevice->IntEndpointDescriptor.EndpointAddress,
FALSE,
UsbKeyboardDevice->IntEndpointDescriptor.Interval,
0,
NULL,
NULL
);
gBS->CloseProtocol (
Controller,
&gEfiUsbIoProtocolGuid,
This->DriverBindingHandle,
Controller
);
Status = gBS->UninstallMultipleProtocolInterfaces (
Controller,
&gEfiSimpleTextInProtocolGuid,
&UsbKeyboardDevice->SimpleInput,
&gEfiHotPlugDeviceGuid,
NULL,
NULL
);
//
// free all the resources.
//
gBS->CloseEvent (UsbKeyboardDevice->RepeatTimer);
gBS->CloseEvent (UsbKeyboardDevice->DelayedRecoveryEvent);
gBS->CloseEvent ((UsbKeyboardDevice->SimpleInput).WaitForKey);
if (UsbKeyboardDevice->ControllerNameTable != NULL) {
FreeUnicodeStringTable (UsbKeyboardDevice->ControllerNameTable);
}
gBS->FreePool (UsbKeyboardDevice);
return Status;
}
EFI_STATUS
EFIAPI
USBKeyboardReset (
IN EFI_SIMPLE_TEXT_IN_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
)
/*++
Routine Description:
Implements EFI_SIMPLE_TEXT_IN_PROTOCOL.Reset() function.
Arguments:
This The EFI_SIMPLE_TEXT_IN_PROTOCOL instance.
ExtendedVerification
Indicates that the driver may perform a more exhaustive
verification operation of the device during reset.
Returns:
EFI_SUCCESS - Success
EFI_DEVICE_ERROR - Hardware Error
--*/
{
EFI_STATUS Status;
USB_KB_DEV *UsbKeyboardDevice;
EFI_USB_IO_PROTOCOL *UsbIo;
UsbKeyboardDevice = USB_KB_DEV_FROM_THIS (This);
UsbIo = UsbKeyboardDevice->UsbIo;
KbdReportStatusCode (
UsbKeyboardDevice->DevicePath,
EFI_PROGRESS_CODE,
(EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_RESET)
);
//
// Non Exhaustive reset:
// only reset private data structures.
//
if (!ExtendedVerification) {
//
// Clear the key buffer of this Usb keyboard
//
KbdReportStatusCode (
UsbKeyboardDevice->DevicePath,
EFI_PROGRESS_CODE,
(EFI_PERIPHERAL_KEYBOARD | EFI_P_KEYBOARD_PC_CLEAR_BUFFER)
);
InitUSBKeyBuffer (&(UsbKeyboardDevice->KeyboardBuffer));
UsbKeyboardDevice->CurKeyChar = 0;
return EFI_SUCCESS;
}
//
// Exhaustive reset
//
Status = InitUSBKeyboard (UsbKeyboardDevice);
UsbKeyboardDevice->CurKeyChar = 0;
if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
}
return EFI_SUCCESS;
}
STATIC
EFI_STATUS
EFIAPI
USBKeyboardReadKeyStroke (
IN EFI_SIMPLE_TEXT_IN_PROTOCOL *This,
OUT EFI_INPUT_KEY *Key
)
/*++
Routine Description:
Implements EFI_SIMPLE_TEXT_IN_PROTOCOL.ReadKeyStroke() function.
Arguments:
This The EFI_SIMPLE_TEXT_IN_PROTOCOL instance.
Key A pointer to a buffer that is filled in with the keystroke
information for the key that was pressed.
Returns:
EFI_SUCCESS - Success
--*/
{
USB_KB_DEV *UsbKeyboardDevice;
EFI_STATUS Status;
UINT8 KeyChar;
UsbKeyboardDevice = USB_KB_DEV_FROM_THIS (This);
//
// if there is no saved ASCII byte, fetch it
// by calling USBKeyboardCheckForKey().
//
if (UsbKeyboardDevice->CurKeyChar == 0) {
Status = USBKeyboardCheckForKey (UsbKeyboardDevice);
if (EFI_ERROR (Status)) {
return Status;
}
}
Key->UnicodeChar = 0;
Key->ScanCode = SCAN_NULL;
KeyChar = UsbKeyboardDevice->CurKeyChar;
UsbKeyboardDevice->CurKeyChar = 0;
//
// Translate saved ASCII byte into EFI_INPUT_KEY
//
Status = USBKeyCodeToEFIScanCode (UsbKeyboardDevice, KeyChar, Key);
return Status;
}
STATIC
VOID
EFIAPI
USBKeyboardWaitForKey (
IN EFI_EVENT Event,
IN VOID *Context
)
/*++
Routine Description:
Handler function for WaitForKey event.
Arguments:
Event Event to be signaled when a key is pressed.
Context Points to USB_KB_DEV instance.
Returns:
VOID
--*/
{
USB_KB_DEV *UsbKeyboardDevice;
UsbKeyboardDevice = (USB_KB_DEV *) Context;
if (UsbKeyboardDevice->CurKeyChar == 0) {
if (EFI_ERROR (USBKeyboardCheckForKey (UsbKeyboardDevice))) {
return ;
}
}
//
// If has key pending, signal the event.
//
gBS->SignalEvent (Event);
}
STATIC
EFI_STATUS
USBKeyboardCheckForKey (
IN USB_KB_DEV *UsbKeyboardDevice
)
/*++
Routine Description:
Check whether there is key pending.
Arguments:
UsbKeyboardDevice The USB_KB_DEV instance.
Returns:
EFI_SUCCESS - Success
--*/
{
EFI_STATUS Status;
UINT8 KeyChar;
//
// Fetch raw data from the USB keyboard input,
// and translate it into ASCII data.
//
Status = USBParseKey (UsbKeyboardDevice, &KeyChar);
if (EFI_ERROR (Status)) {
return Status;
}
UsbKeyboardDevice->CurKeyChar = KeyChar;
return EFI_SUCCESS;
}
VOID
KbdReportStatusCode (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
IN EFI_STATUS_CODE_TYPE CodeType,
IN EFI_STATUS_CODE_VALUE Value
)
/*++
Routine Description:
Report Status Code in Usb Bot Driver
Arguments:
DevicePath - Use this to get Device Path
CodeType - Status Code Type
CodeValue - Status Code Value
Returns:
None
--*/
{
REPORT_STATUS_CODE_WITH_DEVICE_PATH (
CodeType,
Value,
DevicePath
);
}

View File

@@ -0,0 +1,118 @@
/*++
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:
EfiKey.h
Abstract:
Header file for USB Keyboard Driver's Data Structures
Revision History
--*/
#ifndef _USB_KB_H
#define _USB_KB_H
#include <IndustryStandard/usb.h>
#define MAX_KEY_ALLOWED 32
#define HZ 1000 * 1000 * 10
#define USBKBD_REPEAT_DELAY ((HZ) / 2)
#define USBKBD_REPEAT_RATE ((HZ) / 50)
#define CLASS_HID 3
#define SUBCLASS_BOOT 1
#define PROTOCOL_KEYBOARD 1
#define BOOT_PROTOCOL 0
#define REPORT_PROTOCOL 1
typedef struct {
UINT8 Down;
UINT8 KeyCode;
} USB_KEY;
typedef struct {
USB_KEY buffer[MAX_KEY_ALLOWED + 1];
UINT8 bHead;
UINT8 bTail;
} USB_KB_BUFFER;
#define USB_KB_DEV_SIGNATURE EFI_SIGNATURE_32 ('u', 'k', 'b', 'd')
typedef struct {
UINTN Signature;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
EFI_EVENT DelayedRecoveryEvent;
EFI_SIMPLE_TEXT_IN_PROTOCOL SimpleInput;
EFI_USB_IO_PROTOCOL *UsbIo;
EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
EFI_USB_ENDPOINT_DESCRIPTOR IntEndpointDescriptor;
USB_KB_BUFFER KeyboardBuffer;
UINT8 CtrlOn;
UINT8 AltOn;
UINT8 ShiftOn;
UINT8 NumLockOn;
UINT8 CapsOn;
UINT8 LastKeyCodeArray[8];
UINT8 CurKeyChar;
UINT8 RepeatKey;
EFI_EVENT RepeatTimer;
EFI_UNICODE_STRING_TABLE *ControllerNameTable;
} USB_KB_DEV;
//
// Global Variables
//
extern EFI_DRIVER_BINDING_PROTOCOL gUsbKeyboardDriverBinding;
extern EFI_COMPONENT_NAME_PROTOCOL gUsbKeyboardComponentName;
extern EFI_GUID gEfiUsbKeyboardDriverGuid;
VOID
KbdReportStatusCode (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
IN EFI_STATUS_CODE_TYPE CodeType,
IN EFI_STATUS_CODE_VALUE Value
);
#define USB_KB_DEV_FROM_THIS(a) \
CR(a, USB_KB_DEV, SimpleInput, USB_KB_DEV_SIGNATURE)
#define MOD_CONTROL_L 0x01
#define MOD_CONTROL_R 0x10
#define MOD_SHIFT_L 0x02
#define MOD_SHIFT_R 0x20
#define MOD_ALT_L 0x04
#define MOD_ALT_R 0x40
#define MOD_WIN_L 0x08
#define MOD_WIN_R 0x80
typedef struct {
UINT8 Mask;
UINT8 Key;
} KB_MODIFIER;
#define USB_KEYCODE_MAX_MAKE 0x64
#define USBKBD_VALID_KEYCODE(key) ((UINT8) (key) > 3)
typedef struct {
UINT8 NumLock : 1;
UINT8 CapsLock : 1;
UINT8 Resrvd : 6;
} LED_MAP;
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,106 @@
/*++
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:
Keyboard.h
Abstract:
Function prototype for USB Keyboard Driver
Revision History
--*/
#ifndef _KEYBOARD_H
#define _KEYBOARD_H
#include "efikey.h"
BOOLEAN
IsUSBKeyboard (
IN EFI_USB_IO_PROTOCOL *UsbIo
);
EFI_STATUS
InitUSBKeyboard (
IN USB_KB_DEV *UsbKeyboardDevice
);
EFI_STATUS
EFIAPI
KeyboardHandler (
IN VOID *Data,
IN UINTN DataLength,
IN VOID *Context,
IN UINT32 Result
);
VOID
EFIAPI
USBKeyboardRecoveryHandler (
IN EFI_EVENT Event,
IN VOID *Context
);
EFI_STATUS
USBParseKey (
IN OUT USB_KB_DEV *UsbKeyboardDevice,
OUT UINT8 *KeyChar
);
EFI_STATUS
USBKeyCodeToEFIScanCode (
IN USB_KB_DEV *UsbKeyboardDevice,
IN UINT8 KeyChar,
OUT EFI_INPUT_KEY *Key
);
EFI_STATUS
InitUSBKeyBuffer (
IN OUT USB_KB_BUFFER *KeyboardBuffer
);
BOOLEAN
IsUSBKeyboardBufferEmpty (
IN USB_KB_BUFFER *KeyboardBuffer
);
BOOLEAN
IsUSBKeyboardBufferFull (
IN USB_KB_BUFFER *KeyboardBuffer
);
EFI_STATUS
InsertKeyCode (
IN OUT USB_KB_BUFFER *KeyboardBuffer,
IN UINT8 Key,
IN UINT8 Down
);
EFI_STATUS
RemoveKeyCode (
IN OUT USB_KB_BUFFER *KeyboardBuffer,
OUT USB_KEY *UsbKey
);
VOID
EFIAPI
USBKeyboardRepeatHandler (
IN EFI_EVENT Event,
IN VOID *Context
);
EFI_STATUS
SetKeyLED (
IN USB_KB_DEV *UsbKeyboardDevice
);
#endif

View 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 "UsbMassStorage.h"
//
// EFI Component Name Functions
//
EFI_STATUS
EFIAPI
UsbMassStorageComponentNameGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
);
EFI_STATUS
EFIAPI
UsbMassStorageComponentNameGetControllerName (
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 gUsbMassStorageComponentName = {
UsbMassStorageComponentNameGetDriverName,
UsbMassStorageComponentNameGetControllerName,
"eng"
};
STATIC EFI_UNICODE_STRING_TABLE mUsbMassStorageDriverNameTable[] = {
{ "eng", (CHAR16 *) L"Generic USB Mass Storage Driver" },
{ NULL , NULL }
};
EFI_STATUS
EFIAPI
UsbMassStorageComponentNameGetDriverName (
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,
gUsbMassStorageComponentName.SupportedLanguages,
mUsbMassStorageDriverNameTable,
DriverName
);
}
EFI_STATUS
EFIAPI
UsbMassStorageComponentNameGetControllerName (
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;
}

View File

@@ -0,0 +1,727 @@
/*++
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:
UsbMassStorage.c
Abstract:
USB Mass Storage Driver
Revision History
--*/
#include "UsbMassStorage.h"
#include "UsbMassStorageHelper.h"
extern EFI_COMPONENT_NAME_PROTOCOL gUsbMassStorageComponentName;
//
// Prototypes
// Driver model protocol interface
//
EFI_STATUS
EFIAPI
USBMassStorageDriverBindingEntryPoint (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
EFI_STATUS
EFIAPI
USBFloppyDriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
);
EFI_STATUS
EFIAPI
USBFloppyDriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
);
EFI_STATUS
EFIAPI
USBFloppyDriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
);
//
// Block I/O Protocol Interface
//
STATIC
EFI_STATUS
EFIAPI
USBFloppyReset (
IN EFI_BLOCK_IO_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
);
STATIC
EFI_STATUS
EFIAPI
USBFloppyReadBlocks (
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA LBA,
IN UINTN BufferSize,
OUT VOID *Buffer
);
STATIC
EFI_STATUS
EFIAPI
USBFloppyWriteBlocks (
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA LBA,
IN UINTN BufferSize,
IN VOID *Buffer
);
STATIC
EFI_STATUS
EFIAPI
USBFloppyFlushBlocks (
IN EFI_BLOCK_IO_PROTOCOL *This
);
//
// USB Floppy Driver Global Variables
//
EFI_DRIVER_BINDING_PROTOCOL gUSBFloppyDriverBinding = {
USBFloppyDriverBindingSupported,
USBFloppyDriverBindingStart,
USBFloppyDriverBindingStop,
0x10,
NULL,
NULL
};
EFI_STATUS
EFIAPI
USBFloppyDriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
/*++
Routine Description:
Test to see if this driver supports ControllerHandle. Any ControllerHandle
that has UsbHcProtocol installed will be supported.
Arguments:
This - Protocol instance pointer.
Controller - Handle of device to test
RemainingDevicePath - Not used
Returns:
EFI_SUCCESS - This driver supports this device.
EFI_UNSUPPORTED - This driver does not support this device.
--*/
{
EFI_STATUS OpenStatus;
EFI_USB_ATAPI_PROTOCOL *AtapiProtocol;
//
// check whether EFI_USB_ATAPI_PROTOCOL exists, if it does,
// then the controller must be a USB Mass Storage Controller
//
OpenStatus = gBS->OpenProtocol (
Controller,
&gEfiUsbAtapiProtocolGuid,
(VOID **) &AtapiProtocol,
This->DriverBindingHandle,
Controller,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (OpenStatus)) {
return OpenStatus;
}
gBS->CloseProtocol (
Controller,
&gEfiUsbAtapiProtocolGuid,
This->DriverBindingHandle,
Controller
);
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
USBFloppyDriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
/*++
Routine Description:
Starting the Usb Bus Driver
Arguments:
This - Protocol instance pointer.
Controller - Handle of device to test
RemainingDevicePath - Not used
Returns:
EFI_SUCCESS - This driver supports this device.
EFI_UNSUPPORTED - This driver does not support this device.
EFI_DEVICE_ERROR - This driver cannot be started due to device
Error
EFI_OUT_OF_RESOURCES- Can't allocate memory resources
EFI_ALREADY_STARTED - Thios driver has been started
--*/
{
EFI_STATUS Status;
EFI_USB_ATAPI_PROTOCOL *AtapiProtocol;
USB_FLOPPY_DEV *UsbFloppyDevice;
UsbFloppyDevice = NULL;
//
// Check whether Usb Atapi Protocol attached on the controller handle.
//
Status = gBS->OpenProtocol (
Controller,
&gEfiUsbAtapiProtocolGuid,
(VOID **) &AtapiProtocol,
This->DriverBindingHandle,
Controller,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = gBS->AllocatePool (
EfiBootServicesData,
sizeof (USB_FLOPPY_DEV),
(VOID **) &UsbFloppyDevice
);
if (EFI_ERROR (Status)) {
gBS->CloseProtocol (
Controller,
&gEfiUsbAtapiProtocolGuid,
This->DriverBindingHandle,
Controller
);
return Status;
}
ZeroMem (UsbFloppyDevice, sizeof (USB_FLOPPY_DEV));
UsbFloppyDevice->Handle = Controller;
UsbFloppyDevice->BlkIo.Media = &UsbFloppyDevice->BlkMedia;
UsbFloppyDevice->Signature = USB_FLOPPY_DEV_SIGNATURE;
UsbFloppyDevice->BlkIo.Reset = USBFloppyReset;
UsbFloppyDevice->BlkIo.ReadBlocks = USBFloppyReadBlocks;
UsbFloppyDevice->BlkIo.WriteBlocks = USBFloppyWriteBlocks;
UsbFloppyDevice->BlkIo.FlushBlocks = USBFloppyFlushBlocks;
UsbFloppyDevice->AtapiProtocol = AtapiProtocol;
//
// Identify drive type and retrieve media information.
//
Status = USBFloppyIdentify (UsbFloppyDevice);
if (EFI_ERROR (Status)) {
if (UsbFloppyDevice->SenseData != NULL) {
gBS->FreePool (UsbFloppyDevice->SenseData);
}
gBS->FreePool (UsbFloppyDevice);
gBS->CloseProtocol (
Controller,
&gEfiUsbAtapiProtocolGuid,
This->DriverBindingHandle,
Controller
);
return Status;
}
//
// Install Block I/O protocol for the usb floppy device.
//
Status = gBS->InstallProtocolInterface (
&Controller,
&gEfiBlockIoProtocolGuid,
EFI_NATIVE_INTERFACE,
&UsbFloppyDevice->BlkIo
);
if (EFI_ERROR (Status)) {
if (UsbFloppyDevice->SenseData != NULL) {
gBS->FreePool (UsbFloppyDevice->SenseData);
}
gBS->FreePool (UsbFloppyDevice);
gBS->CloseProtocol (
Controller,
&gEfiUsbAtapiProtocolGuid,
This->DriverBindingHandle,
Controller
);
return Status;
}
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
USBFloppyDriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
)
/*++
Routine Description:
Stop this driver on ControllerHandle. Support stoping any child handles
created by this driver.
Arguments:
This - Protocol instance pointer.
Controller - Handle of device to stop driver on
NumberOfChildren - Number of Children in the ChildHandleBuffer
ChildHandleBuffer - List of handles for the children we need to stop.
Returns:
EFI_SUCCESS
EFI_DEVICE_ERROR
others
--*/
{
EFI_STATUS Status;
USB_FLOPPY_DEV *UsbFloppyDevice;
EFI_BLOCK_IO_PROTOCOL *BlkIo;
//
// First find USB_FLOPPY_DEV
//
gBS->OpenProtocol (
Controller,
&gEfiBlockIoProtocolGuid,
(VOID **) &BlkIo,
This->DriverBindingHandle,
Controller,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
UsbFloppyDevice = USB_FLOPPY_DEV_FROM_THIS (BlkIo);
//
// Uninstall Block I/O protocol from the device handle
//
Status = gBS->UninstallProtocolInterface (
Controller,
&gEfiBlockIoProtocolGuid,
&UsbFloppyDevice->BlkIo
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Stop using EFI_USB_ATAPI_PROTOCOL
//
gBS->CloseProtocol (
Controller,
&gEfiUsbAtapiProtocolGuid,
This->DriverBindingHandle,
Controller
);
if (UsbFloppyDevice->SenseData != NULL) {
gBS->FreePool (UsbFloppyDevice->SenseData);
}
gBS->FreePool (UsbFloppyDevice);
return EFI_SUCCESS;
}
STATIC
EFI_STATUS
EFIAPI
USBFloppyReset (
IN EFI_BLOCK_IO_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
)
/*++
Routine Description:
Implements EFI_BLOCK_IO_PROTOCOL.Reset() function.
Arguments:
This The EFI_BLOCK_IO_PROTOCOL instance.
ExtendedVerification
Indicates that the driver may perform a more exhaustive
verification operation of the device during reset.
(This parameter is ingored in this driver.)
Returns:
EFI_SUCCESS - Success
--*/
{
USB_FLOPPY_DEV *UsbFloppyDevice;
EFI_USB_ATAPI_PROTOCOL *UsbAtapiInterface;
EFI_STATUS Status;
UsbFloppyDevice = USB_FLOPPY_DEV_FROM_THIS (This);
UsbAtapiInterface = UsbFloppyDevice->AtapiProtocol;
//
// directly calling EFI_USB_ATAPI_PROTOCOL.Reset() to implement reset.
//
Status = UsbAtapiInterface->UsbAtapiReset (UsbAtapiInterface, TRUE);
return Status;
}
STATIC
EFI_STATUS
EFIAPI
USBFloppyReadBlocks (
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA LBA,
IN UINTN BufferSize,
OUT VOID *Buffer
)
/*++
Routine Description:
Implements EFI_BLOCK_IO_PROTOCOL.ReadBlocks() function.
Arguments:
This The EFI_BLOCK_IO_PROTOCOL instance.
MediaId The media id that the read request is for.
LBA The starting logical block address to read from on the device.
BufferSize
The size of the Buffer in bytes. This must be a multiple of
the intrinsic block size of the device.
Buffer A pointer to the destination buffer for the data. The caller
is responsible for either having implicit or explicit ownership
of the buffer.
Returns:
EFI_INVALID_PARAMETER - Parameter is error
EFI_SUCCESS - Success
EFI_DEVICE_ERROR - Hardware Error
EFI_NO_MEDIA - No media
EFI_MEDIA_CHANGED - Media Change
EFI_BAD_BUFFER_SIZE - Buffer size is bad
--*/
{
USB_FLOPPY_DEV *UsbFloppyDevice;
EFI_STATUS Status;
EFI_BLOCK_IO_MEDIA *Media;
UINTN BlockSize;
UINTN NumberOfBlocks;
BOOLEAN MediaChange;
EFI_TPL OldTpl;
UINT32 Retry;
OldTpl = gBS->RaiseTPL (EFI_TPL_NOTIFY);
Status = EFI_SUCCESS;
MediaChange = FALSE;
Retry = 0;
UsbFloppyDevice = USB_FLOPPY_DEV_FROM_THIS (This);
//
// Check parameters
//
if (!Buffer) {
Status = EFI_INVALID_PARAMETER;
goto Done;
}
if (BufferSize == 0) {
Status = EFI_SUCCESS;
goto Done;
}
UsbFloppyTestUnitReady (UsbFloppyDevice);
Status = UsbFloppyDetectMedia (UsbFloppyDevice, &MediaChange);
if (EFI_ERROR (Status)) {
Status = EFI_DEVICE_ERROR;
goto Done;
}
if (MediaChange) {
gBS->RestoreTPL (OldTpl);
gBS->ReinstallProtocolInterface (
UsbFloppyDevice->Handle,
&gEfiBlockIoProtocolGuid,
&UsbFloppyDevice->BlkIo,
&UsbFloppyDevice->BlkIo
);
gBS->RaiseTPL (EFI_TPL_NOTIFY);
}
Media = UsbFloppyDevice->BlkIo.Media;
BlockSize = Media->BlockSize;
NumberOfBlocks = BufferSize / BlockSize;
if (!(Media->MediaPresent)) {
Status = EFI_NO_MEDIA;
goto Done;
}
if (MediaId != Media->MediaId) {
Status = EFI_MEDIA_CHANGED;
goto Done;
}
if (BufferSize % BlockSize != 0) {
Status = EFI_BAD_BUFFER_SIZE;
goto Done;
}
if (LBA > Media->LastBlock) {
Status = EFI_INVALID_PARAMETER;
goto Done;
}
if ((LBA + NumberOfBlocks - 1) > Media->LastBlock) {
Status = EFI_INVALID_PARAMETER;
goto Done;
}
if ((Media->IoAlign > 1) && (((UINTN) Buffer & (Media->IoAlign - 1)) != 0)) {
Status = EFI_INVALID_PARAMETER;
goto Done;
}
if (!EFI_ERROR (Status)) {
Status = USBFloppyRead10 (UsbFloppyDevice, Buffer, LBA, 1);
if (EFI_ERROR (Status)) {
This->Reset (This, TRUE);
Status = EFI_DEVICE_ERROR;
goto Done;
}
LBA += 1;
NumberOfBlocks -= 1;
Buffer = (UINT8 *) Buffer + This->Media->BlockSize;
if (NumberOfBlocks == 0) {
Status = EFI_SUCCESS;
goto Done;
}
Status = USBFloppyRead10 (UsbFloppyDevice, Buffer, LBA, NumberOfBlocks);
if (EFI_ERROR (Status)) {
This->Reset (This, TRUE);
Status = EFI_DEVICE_ERROR;
}
}
Done:
gBS->RestoreTPL (OldTpl);
return Status;
}
STATIC
EFI_STATUS
EFIAPI
USBFloppyWriteBlocks (
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA LBA,
IN UINTN BufferSize,
IN VOID *Buffer
)
/*++
Routine Description:
Implements EFI_BLOCK_IO_PROTOCOL.WriteBlocks() function.
Arguments:
This The EFI_BLOCK_IO_PROTOCOL instance.
MediaId The media id that the write request is for.
LBA The starting logical block address to be written.
The caller is responsible for writing to only
legitimate locations.
BufferSize
The size of the Buffer in bytes. This must be a multiple of
the intrinsic block size of the device.
Buffer A pointer to the source buffer for the data. The caller
is responsible for either having implicit or explicit ownership
of the buffer.
Returns:
EFI_INVALID_PARAMETER - Parameter is error
EFI_SUCCESS - Success
EFI_DEVICE_ERROR - Hardware Error
EFI_NO_MEDIA - No media
EFI_MEDIA_CHANGED - Media Change
EFI_BAD_BUFFER_SIZE - Buffer size is bad
--*/
{
USB_FLOPPY_DEV *UsbFloppyDevice;
EFI_STATUS Status;
EFI_BLOCK_IO_MEDIA *Media;
UINTN BlockSize;
UINTN NumberOfBlocks;
BOOLEAN MediaChange;
EFI_TPL OldTpl;
UINT32 Retry;
OldTpl = gBS->RaiseTPL (EFI_TPL_NOTIFY);
Status = EFI_SUCCESS;
MediaChange = FALSE;
Retry = 0;
UsbFloppyDevice = USB_FLOPPY_DEV_FROM_THIS (This);
//
// Check parameters
//
if (!Buffer) {
Status = EFI_INVALID_PARAMETER;
goto Done;
}
if (BufferSize == 0) {
Status = EFI_SUCCESS;
goto Done;
}
UsbFloppyTestUnitReady (UsbFloppyDevice);
Status = UsbFloppyDetectMedia (UsbFloppyDevice, &MediaChange);
if (EFI_ERROR (Status)) {
Status = EFI_DEVICE_ERROR;
goto Done;
}
if (MediaChange) {
gBS->RestoreTPL (OldTpl);
gBS->ReinstallProtocolInterface (
UsbFloppyDevice->Handle,
&gEfiBlockIoProtocolGuid,
&UsbFloppyDevice->BlkIo,
&UsbFloppyDevice->BlkIo
);
gBS->RaiseTPL (EFI_TPL_NOTIFY);
}
Media = UsbFloppyDevice->BlkIo.Media;
BlockSize = Media->BlockSize;
NumberOfBlocks = BufferSize / BlockSize;
if (!(Media->MediaPresent)) {
Status = EFI_NO_MEDIA;
goto Done;
}
if (MediaId != Media->MediaId) {
Status = EFI_MEDIA_CHANGED;
goto Done;
}
if (BufferSize % BlockSize != 0) {
Status = EFI_BAD_BUFFER_SIZE;
goto Done;
}
if (LBA > Media->LastBlock) {
Status = EFI_INVALID_PARAMETER;
goto Done;
}
if ((LBA + NumberOfBlocks - 1) > Media->LastBlock) {
Status = EFI_INVALID_PARAMETER;
goto Done;
}
if ((Media->IoAlign > 1) && (((UINTN) Buffer & (Media->IoAlign - 1)) != 0)) {
Status = EFI_INVALID_PARAMETER;
goto Done;
}
if (UsbFloppyDevice->BlkMedia.ReadOnly) {
Status = EFI_WRITE_PROTECTED;
goto Done;
}
if (!EFI_ERROR (Status)) {
Status = USBFloppyWrite10 (UsbFloppyDevice, Buffer, LBA, 1);
if (EFI_ERROR (Status)) {
This->Reset (This, TRUE);
Status = EFI_DEVICE_ERROR;
goto Done;
}
LBA += 1;
NumberOfBlocks -= 1;
Buffer = (UINT8 *) Buffer + This->Media->BlockSize;
if (NumberOfBlocks == 0) {
Status = EFI_SUCCESS;
goto Done;
}
Status = USBFloppyWrite10 (UsbFloppyDevice, Buffer, LBA, NumberOfBlocks);
if (EFI_ERROR (Status)) {
This->Reset (This, TRUE);
Status = EFI_DEVICE_ERROR;
}
}
Done:
gBS->RestoreTPL (OldTpl);
return Status;
}
STATIC
EFI_STATUS
EFIAPI
USBFloppyFlushBlocks (
IN EFI_BLOCK_IO_PROTOCOL *This
)
/*++
Routine Description:
Implements EFI_BLOCK_IO_PROTOCOL.FlushBlocks() function.
(In this driver, this function just returns EFI_SUCCESS.)
Arguments:
This The EFI_BLOCK_IO_PROTOCOL instance.
Returns:
EFI_SUCCESS - Success
--*/
{
return EFI_SUCCESS;
}

View File

@@ -0,0 +1,59 @@
/*++
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:
UsbMassStorage.h
Abstract:
Header file for USB Mass Storage Driver's Data Structures
Revision History
--*/
#ifndef _USB_FLP_H
#define _USB_FLP_H
#include <IndustryStandard/usb.h>
#include "UsbMassStorageData.h"
#define CLASS_MASSTORAGE 8
#define SUBCLASS_UFI 4
#define SUBCLASS_8070 5
#define PROTOCOL_BOT 0x50
#define PROTOCOL_CBI0 0
#define PROTOCOL_CBI1 1
#define USBFLOPPY 1
#define USBFLOPPY2 2 // for those that use ReadCapacity(0x25) command to retrieve media capacity
#define USBCDROM 3
#define USB_FLOPPY_DEV_SIGNATURE EFI_SIGNATURE_32 ('u', 'f', 'l', 'p')
typedef struct {
UINTN Signature;
EFI_HANDLE Handle;
EFI_BLOCK_IO_PROTOCOL BlkIo;
EFI_BLOCK_IO_MEDIA BlkMedia;
EFI_USB_ATAPI_PROTOCOL *AtapiProtocol;
REQUEST_SENSE_DATA *SenseData;
UINT8 SenseDataNumber;
UINT8 DeviceType;
} USB_FLOPPY_DEV;
#define USB_FLOPPY_DEV_FROM_THIS(a) \
CR(a, USB_FLOPPY_DEV, BlkIo, USB_FLOPPY_DEV_SIGNATURE)
#endif

View File

@@ -0,0 +1,43 @@
<?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>UsbMassStorage</BaseName>
<Guid>A5C6D68B-E78A-4426-9278-A8F0D9EB4D8F</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>
</Libraries>
</ModuleBuildDescription>

View File

@@ -0,0 +1,70 @@
<?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>UsbMassStorage</BaseName>
<ModuleType>DXE_DRIVER</ModuleType>
<ComponentType>BS_DRIVER</ComponentType>
<Guid>A5C6D68B-E78A-4426-9278-A8F0D9EB4D8F</Guid>
<Version>0</Version>
<Abstract>Component description file for UsbMassStorage 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">MemoryAllocationLib</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">UefiBootServicesTableLib</LibraryClass>
</LibraryClassDefinitions>
<SourceFiles>
<Filename>UsbMassStorage.h</Filename>
<Filename>UsbMassStorageData.h</Filename>
<Filename>UsbMassStorageHelper.h</Filename>
<Filename>UsbMassStorage.c</Filename>
<Filename>UsbMassStorageHelper.c</Filename>
<Filename>ComponentName.c</Filename>
</SourceFiles>
<Includes>
<PackageName>MdePkg</PackageName>
<PackageName>EdkModulePkg</PackageName>
</Includes>
<Protocols>
<Protocol Usage="TO_START">UsbAtapi</Protocol>
<Protocol Usage="BY_START">BlockIo</Protocol>
</Protocols>
<Externs>
<Extern>
<ModuleEntryPoint></ModuleEntryPoint>
</Extern>
<Extern>
<DriverBinding>gUSBFloppyDriverBinding</DriverBinding>
<ComponentName>gUsbMassStorageComponentName</ComponentName>
</Extern>
</Externs>
</ModuleSurfaceArea>

View File

@@ -0,0 +1,394 @@
/*++
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:
UsbMassStorageData.h
Abstract:
Header file for USB Mass Storage Device related Data Structures
Revision History
--*/
#ifndef _USB_FLP_DATA_H
#define _USB_FLP_DATA_H
//
// bit definition
//
#define bit(a) 1 << (a)
//
// timeout unit is in millisecond.
//
#define USBFLPTIMEOUT 2000
#define STALL_1_MILLI_SECOND 1000
//
// ATAPI Packet Command
//
#pragma pack(1)
typedef struct {
UINT8 opcode;
UINT8 reserved_1;
UINT8 reserved_2;
UINT8 reserved_3;
UINT8 reserved_4;
UINT8 reserved_5;
UINT8 reserved_6;
UINT8 reserved_7;
UINT8 reserved_8;
UINT8 reserved_9;
UINT8 reserved_10;
UINT8 reserved_11;
} TEST_UNIT_READY_CMD;
typedef struct {
UINT8 opcode;
UINT8 reserved_1 : 4;
UINT8 lun : 4;
UINT8 page_code;
UINT8 reserved_3;
UINT8 allocation_length;
UINT8 reserved_5;
UINT8 reserved_6;
UINT8 reserved_7;
UINT8 reserved_8;
UINT8 reserved_9;
UINT8 reserved_10;
UINT8 reserved_11;
} INQUIRY_CMD;
typedef struct {
UINT8 opcode;
UINT8 reserved_1 : 4;
UINT8 lun : 4;
UINT8 reserved_2;
UINT8 reserved_3;
UINT8 allocation_length;
UINT8 reserved_5;
UINT8 reserved_6;
UINT8 reserved_7;
UINT8 reserved_8;
UINT8 reserved_9;
UINT8 reserved_10;
UINT8 reserved_11;
} REQUEST_SENSE_CMD;
typedef struct {
UINT8 opcode;
UINT8 reserved_1 : 4;
UINT8 lun : 4;
UINT8 page_code : 6;
UINT8 page_control : 2;
UINT8 reserved_3;
UINT8 reserved_4;
UINT8 reserved_5;
UINT8 reserved_6;
UINT8 parameter_list_length_hi;
UINT8 parameter_list_length_lo;
UINT8 reserved_9;
UINT8 reserved_10;
UINT8 reserved_11;
} MODE_SENSE_CMD_UFI;
typedef struct {
UINT8 opcode;
UINT8 reserved_1 : 3;
UINT8 dbd : 1;
UINT8 reserved_2 : 1;
UINT8 lun : 3;
UINT8 page_code : 6;
UINT8 page_control : 2;
UINT8 reserved_3;
UINT8 allocation_length;
UINT8 control;
} MODE_SENSE_CMD_SCSI;
typedef struct {
UINT8 opcode;
UINT8 reserved_1 : 5;
UINT8 lun : 3;
UINT8 Lba0;
UINT8 Lba1;
UINT8 Lba2;
UINT8 Lba3;
UINT8 reserved_6;
UINT8 TranLen0;
UINT8 TranLen1;
UINT8 reserved_9;
UINT8 reserved_10;
UINT8 reserved_11;
} READ10_CMD;
typedef struct {
UINT8 opcode;
UINT8 reserved_1;
UINT8 reserved_2;
UINT8 reserved_3;
UINT8 reserved_4;
UINT8 reserved_5;
UINT8 reserved_6;
UINT8 allocation_length_hi;
UINT8 allocation_length_lo;
UINT8 reserved_9;
UINT8 reserved_10;
UINT8 reserved_11;
} READ_FORMAT_CAP_CMD;
typedef union {
UINT16 Data16[6];
TEST_UNIT_READY_CMD TestUnitReady;
READ10_CMD Read10;
REQUEST_SENSE_CMD RequestSense;
INQUIRY_CMD Inquiry;
MODE_SENSE_CMD_UFI ModeSenseUFI;
READ_FORMAT_CAP_CMD ReadFormatCapacity;
MODE_SENSE_CMD_SCSI ModeSenseSCSI;
} ATAPI_PACKET_COMMAND;
#pragma pack()
//
// Packet Command Code
//
#define TEST_UNIT_READY 0x00
#define REZERO 0x01
#define REQUEST_SENSE 0x03
#define FORMAT_UNIT 0x04
#define REASSIGN_BLOCKS 0x07
#define INQUIRY 0x12
#define START_STOP_UNIT 0x1B
#define PREVENT_ALLOW_MEDIA_REMOVAL 0x1E
#define READ_FORMAT_CAPACITY 0x23
#define OLD_FORMAT_UNIT 0x24
#define READ_CAPACITY 0x25
#define READ_10 0x28
#define WRITE_10 0x2A
#define SEEK 0x2B
#define SEND_DIAGNOSTICS 0x3D
#define WRITE_VERIFY 0x2E
#define VERIFY 0x2F
#define READ_DEFECT_DATA 0x37
#define WRITE_BUFFER 0x38
#define READ_BUFFER 0x3C
#define READ_LONG 0x3E
#define WRITE_LONG 0x3F
#define MODE_SELECT 0x55
#define UFI_MODE_SENSE5A 0x5A
#define SCSI_MODE_SENSE1A 0x1A
#define READ_12 0xA8
#define WRITE_12 0xAA
#define MAX_ATAPI_BYTE_COUNT (0xfffe)
//
// Sense Key
//
#define REQUEST_SENSE_ERROR (0x70)
#define SK_NO_SENSE (0x0)
#define SK_RECOVERY_ERROR (0x1)
#define SK_NOT_READY (0x2)
#define SK_MEDIUM_ERROR (0x3)
#define SK_HARDWARE_ERROR (0x4)
#define SK_ILLEGAL_REQUEST (0x5)
#define SK_UNIT_ATTENTION (0x6)
#define SK_DATA_PROTECT (0x7)
#define SK_BLANK_CHECK (0x8)
#define SK_VENDOR_SPECIFIC (0x9)
#define SK_RESERVED_A (0xA)
#define SK_ABORT (0xB)
#define SK_RESERVED_C (0xC)
#define SK_OVERFLOW (0xD)
#define SK_MISCOMPARE (0xE)
#define SK_RESERVED_F (0xF)
//
// Additional Sense Codes
//
#define ASC_NOT_READY (0x04)
#define ASC_MEDIA_ERR1 (0x10)
#define ASC_MEDIA_ERR2 (0x11)
#define ASC_MEDIA_ERR3 (0x14)
#define ASC_MEDIA_ERR4 (0x30)
#define ASC_MEDIA_UPSIDE_DOWN (0x06)
#define ASC_INVALID_CMD (0x20)
#define ASC_LBA_OUT_OF_RANGE (0x21)
#define ASC_INVALID_FIELD (0x24)
#define ASC_WRITE_PROTECTED (0x27)
#define ASC_MEDIA_CHANGE (0x28)
#define ASC_RESET (0x29) /* Power On Reset or Bus Reset occurred */
#define ASC_ILLEGAL_FIELD (0x26)
#define ASC_NO_MEDIA (0x3A)
#define ASC_ILLEGAL_MODE_FOR_THIS_TRACK (0x64)
#define ASC_LOGICAL_UNIT_STATUS (0x08)
//
// Additional Sense Code Qualifier
//
#define ASCQ_IN_PROGRESS (0x01)
#define ASCQ_DEVICE_BUSY (0xff)
#define ASCQ_LOGICAL_UNIT_FAILURE (0x00)
#define ASCQ_LOGICAL_UNIT_TIMEOUT (0x01)
#define ASCQ_LOGICAL_UNIT_OVERRUN (0x80)
#define SETFEATURE TRUE
#define CLEARFEATURE FALSE
//
// ATAPI Data structure
//
#pragma pack(1)
typedef struct {
UINT8 peripheral_type;
UINT8 RMB;
UINT8 version;
UINT8 response_data_format;
UINT8 addnl_length;
UINT8 reserved_5;
UINT8 reserved_6;
UINT8 reserved_7;
UINT8 vendor_info[8];
UINT8 product_id[12];
UINT8 eeprom_product_code[4];
UINT8 firmware_rev_level[4];
} USB_INQUIRY_DATA;
typedef struct {
UINT8 error_code : 7;
UINT8 valid : 1;
UINT8 reserved_1;
UINT8 sense_key : 4;
UINT8 reserved_21 : 1;
UINT8 ILI : 1;
UINT8 reserved_22 : 2;
UINT8 vendor_specific_3;
UINT8 vendor_specific_4;
UINT8 vendor_specific_5;
UINT8 vendor_specific_6;
UINT8 addnl_sense_length; // n - 7
UINT8 vendor_specific_8;
UINT8 vendor_specific_9;
UINT8 vendor_specific_10;
UINT8 vendor_specific_11;
UINT8 addnl_sense_code; // mandatory
UINT8 addnl_sense_code_qualifier; // mandatory
UINT8 field_replaceable_unit_code; // optional
UINT8 reserved_15;
UINT8 reserved_16;
UINT8 reserved_17;
//
// Followed by additional sense bytes : FIXME
//
} REQUEST_SENSE_DATA;
typedef struct {
UINT8 LastLba3;
UINT8 LastLba2;
UINT8 LastLba1;
UINT8 LastLba0;
UINT8 BlockSize3;
UINT8 BlockSize2;
UINT8 BlockSize1;
UINT8 BlockSize0;
} READ_CAPACITY_DATA;
typedef struct {
UINT8 reserved_0;
UINT8 reserved_1;
UINT8 reserved_2;
UINT8 Capacity_Length;
UINT8 LastLba3;
UINT8 LastLba2;
UINT8 LastLba1;
UINT8 LastLba0;
UINT8 DesCode : 2;
UINT8 reserved_9 : 6;
UINT8 BlockSize2;
UINT8 BlockSize1;
UINT8 BlockSize0;
} READ_FORMAT_CAPACITY_DATA;
typedef struct {
UINT8 mode_data_len_hi;
UINT8 mode_data_len_lo;
UINT8 media_type_code;
UINT8 reserved_3_0 : 4;
UINT8 dpofua : 1;
UINT8 reserved_3_1 : 2;
UINT8 write_protected : 1;
UINT8 reserved_4;
UINT8 reserved_5;
UINT8 reserved_6;
UINT8 reserved_7;
} UFI_MODE_PARAMETER_HEADER;
typedef struct {
UINT8 mode_data_len;
UINT8 media_type_code;
UINT8 speed : 4;
UINT8 buffered_mode : 3;
UINT8 write_protected : 1;
UINT8 block_descritptor_length;
} SCSI_MODE_PARAMETER_HEADER6;
typedef struct {
UINT8 page_code : 6;
UINT8 reserved_0 : 1;
UINT8 parameter_savable : 1;
UINT8 page_length;
UINT8 transfer_rate_msb;
UINT8 transfer_rate_lsb;
UINT8 number_of_heads;
UINT8 sectors_per_track;
UINT8 databytes_per_sector_msb;
UINT8 databytes_per_sector_lsb;
UINT8 number_of_cylinders_msb;
UINT8 number_of_cylinders_lsb;
UINT8 reserved_10_18[9];
UINT8 motor_on_delay;
UINT8 motor_off_delay;
UINT8 reserved_21_27[7];
UINT8 medium_rotation_rate_msb;
UINT8 medium_rotation_rate_lsb;
UINT8 reserved_30_31[2];
} FLEXIBLE_DISK_PAGE;
typedef struct {
UFI_MODE_PARAMETER_HEADER mode_param_header;
FLEXIBLE_DISK_PAGE flex_disk_page;
} UFI_MODE_PARAMETER_PAGE_5;
typedef struct {
UINT8 page_code : 6;
UINT8 reserved_0 : 1;
UINT8 parameter_savable : 1;
UINT8 page_length;
UINT8 reserved_2;
UINT8 inactive_time_multplier : 4;
UINT8 reserved_3 : 4;
UINT8 software_write_protect : 1;
UINT8 disable_media_access : 1;
UINT8 reserved_4 : 6;
UINT8 reserved_5;
UINT8 reserved_6;
UINT8 reserved_7;
} TIMER_AND_PROTECT_PAGE;
typedef struct {
UFI_MODE_PARAMETER_HEADER mode_param_header;
TIMER_AND_PROTECT_PAGE time_and_protect_page;
} UFI_MODE_PARAMETER_PAGE_1C;
#pragma pack()
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,111 @@
/*++
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:
UsbMassStorageHelper.h
Abstract:
Function prototype for USB Mass Storage Driver
Revision History
--*/
#ifndef _USB_FLPHLP_H
#define _USB_FLPHLP_H
#include "UsbMassStorage.h"
EFI_STATUS
USBFloppyIdentify (
IN USB_FLOPPY_DEV *UsbFloppyDevice
);
EFI_STATUS
USBFloppyPacketCommand (
USB_FLOPPY_DEV *UsbFloppyDevice,
VOID *Command,
UINT8 CommandSize,
VOID *DataBuffer,
UINT32 BufferLength,
EFI_USB_DATA_DIRECTION Direction,
UINT16 TimeOutInMilliSeconds
);
EFI_STATUS
USBFloppyInquiry (
IN USB_FLOPPY_DEV *UsbFloppyDevice,
OUT USB_INQUIRY_DATA **Idata
);
EFI_STATUS
USBFloppyRead10 (
IN USB_FLOPPY_DEV *UsbFloppyDevice,
IN VOID *Buffer,
IN EFI_LBA Lba,
IN UINTN NumberOfBlocks
);
EFI_STATUS
USBFloppyReadFormatCapacity (
IN USB_FLOPPY_DEV *UsbFloppyDevice
);
EFI_STATUS
UsbFloppyRequestSense (
IN USB_FLOPPY_DEV *UsbFloppyDevice,
OUT UINTN *SenseCounts
);
EFI_STATUS
UsbFloppyTestUnitReady (
IN USB_FLOPPY_DEV *UsbFloppyDevice
);
EFI_STATUS
USBFloppyWrite10 (
IN USB_FLOPPY_DEV *UsbFloppyDevice,
IN VOID *Buffer,
IN EFI_LBA Lba,
IN UINTN NumberOfBlocks
);
EFI_STATUS
UsbFloppyDetectMedia (
IN USB_FLOPPY_DEV *UsbFloppyDevice,
OUT BOOLEAN *MediaChange
);
EFI_STATUS
UsbFloppyModeSense5APage5 (
IN USB_FLOPPY_DEV *UsbFloppyDevice
);
EFI_STATUS
UsbFloppyModeSense5APage1C (
IN USB_FLOPPY_DEV *UsbFloppyDevice
);
EFI_STATUS
UsbFloppyModeSense5APage3F (
IN USB_FLOPPY_DEV *UsbFloppyDevice
);
EFI_STATUS
UsbSCSIModeSense1APage3F (
IN USB_FLOPPY_DEV *UsbFloppyDevice
);
EFI_STATUS
UsbMassStorageModeSense (
IN USB_FLOPPY_DEV *UsbFloppyDevice
);
#endif

View 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="UsbMassStorage"><!--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\UsbMassStorage\Dxe"/>
<property name="MODULE_DIR" value="${PACKAGE_DIR}\${MODULE_RELATIVE_PATH}"/>
<property name="COMMON_FILE" value="${WORKSPACE_DIR}\Tools\Conf\Common.xml"/>
<target name="UsbMassStorage">
<GenBuild baseName="UsbMassStorage" mbdFilename="${MODULE_DIR}\UsbMassStorage.mbd" msaFilename="${MODULE_DIR}\UsbMassStorage.msa"/>
</target>
<target depends="UsbMassStorage_clean" name="clean"/>
<target depends="UsbMassStorage_cleanall" name="cleanall"/>
<target name="UsbMassStorage_clean">
<OutputDirSetup baseName="UsbMassStorage" mbdFilename="${MODULE_DIR}\UsbMassStorage.mbd" msaFilename="${MODULE_DIR}\UsbMassStorage.msa"/>
<if>
<available file="${DEST_DIR_OUTPUT}\UsbMassStorage_build.xml"/>
<then>
<ant antfile="${DEST_DIR_OUTPUT}\UsbMassStorage_build.xml" target="clean"/>
</then>
</if>
<delete dir="${DEST_DIR_OUTPUT}" excludes="*.xml"/>
</target>
<target name="UsbMassStorage_cleanall">
<OutputDirSetup baseName="UsbMassStorage" mbdFilename="${MODULE_DIR}\UsbMassStorage.mbd" msaFilename="${MODULE_DIR}\UsbMassStorage.msa"/>
<if>
<available file="${DEST_DIR_OUTPUT}\UsbMassStorage_build.xml"/>
<then>
<ant antfile="${DEST_DIR_OUTPUT}\UsbMassStorage_build.xml" target="cleanall"/>
</then>
</if>
<delete dir="${DEST_DIR_OUTPUT}"/>
<delete dir="${DEST_DIR_DEBUG}"/>
<delete>
<fileset dir="${BIN_DIR}" includes="**UsbMassStorage*"/>
</delete>
</target>
</project>

View File

@@ -0,0 +1,216 @@
/*++
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 "usbmouse.h"
//
// EFI Component Name Functions
//
EFI_STATUS
EFIAPI
UsbMouseComponentNameGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
);
EFI_STATUS
EFIAPI
UsbMouseComponentNameGetControllerName (
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 gUsbMouseComponentName = {
UsbMouseComponentNameGetDriverName,
UsbMouseComponentNameGetControllerName,
"eng"
};
STATIC EFI_UNICODE_STRING_TABLE mUsbMouseDriverNameTable[] = {
{ "eng", (CHAR16 *) L"Usb Mouse Driver" },
{ NULL , NULL }
};
EFI_STATUS
EFIAPI
UsbMouseComponentNameGetDriverName (
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,
gUsbMouseComponentName.SupportedLanguages,
mUsbMouseDriverNameTable,
DriverName
);
}
EFI_STATUS
EFIAPI
UsbMouseComponentNameGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
)
/*++
Routine Description:
Retrieves a Unicode string that is the user readable name of the controller
that is being managed by an EFI Driver.
Arguments:
This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
ControllerHandle - The handle of a controller that the driver specified by
This is managing. This handle specifies the controller
whose name is to be returned.
ChildHandle - The handle of the child controller to retrieve the name
of. This is an optional parameter that may be NULL. It
will be NULL for device drivers. It will also be NULL
for a bus drivers that wish to retrieve the name of the
bus controller. It will not be NULL for a bus driver
that wishes to retrieve the name of a child controller.
Language - A pointer to a three character ISO 639-2 language
identifier. This is the language of the controller name
that that the caller is requesting, and it must match one
of the languages specified in SupportedLanguages. The
number of languages supported by a driver is up to the
driver writer.
ControllerName - A pointer to the Unicode string to return. This Unicode
string is the name of the controller specified by
ControllerHandle and ChildHandle in the language specified
by Language from the point of view of the driver specified
by This.
Returns:
EFI_SUCCESS - The Unicode string for the user readable name in the
language specified by Language for the driver
specified by This was returned in DriverName.
EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.
EFI_INVALID_PARAMETER - Language is NULL.
EFI_INVALID_PARAMETER - ControllerName is NULL.
EFI_UNSUPPORTED - The driver specified by This is not currently managing
the controller specified by ControllerHandle and
ChildHandle.
EFI_UNSUPPORTED - The driver specified by This does not support the
language specified by Language.
--*/
{
EFI_STATUS Status;
USB_MOUSE_DEV *UsbMouseDev;
EFI_SIMPLE_POINTER_PROTOCOL *SimplePointerProtocol;
EFI_USB_IO_PROTOCOL *UsbIoProtocol;
//
// This is a device driver, so ChildHandle must be NULL.
//
if (ChildHandle != NULL) {
return EFI_UNSUPPORTED;
}
//
// Check Controller's handle
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiUsbIoProtocolGuid,
(VOID **) &UsbIoProtocol,
gUsbMouseDriverBinding.DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (!EFI_ERROR (Status)) {
gBS->CloseProtocol (
ControllerHandle,
&gEfiUsbIoProtocolGuid,
gUsbMouseDriverBinding.DriverBindingHandle,
ControllerHandle
);
return EFI_UNSUPPORTED;
}
if (Status != EFI_ALREADY_STARTED) {
return EFI_UNSUPPORTED;
}
//
// Get the device context
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiSimplePointerProtocolGuid,
(VOID **) &SimplePointerProtocol,
gUsbMouseDriverBinding.DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
return Status;
}
UsbMouseDev = USB_MOUSE_DEV_FROM_MOUSE_PROTOCOL (SimplePointerProtocol);
return LookupUnicodeString (
Language,
gUsbMouseComponentName.SupportedLanguages,
UsbMouseDev->ControllerNameTable,
ControllerName
);
}

View File

@@ -0,0 +1,43 @@
<?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>UsbMouse</BaseName>
<Guid>2D2E62AA-9ECF-43b7-8219-94E7FC713DFE</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>
</Libraries>
</ModuleBuildDescription>

View File

@@ -0,0 +1,71 @@
<?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>UsbMouse</BaseName>
<ModuleType>DXE_DRIVER</ModuleType>
<ComponentType>BS_DRIVER</ComponentType>
<Guid>2D2E62AA-9ECF-43b7-8219-94E7FC713DFE</Guid>
<Version>0</Version>
<Abstract>Component description file for UsbMouse 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>
</LibraryClassDefinitions>
<SourceFiles>
<Filename>usbmouse.h</Filename>
<Filename>usbmouse.c</Filename>
<Filename>mousehid.h</Filename>
<Filename>mousehid.c</Filename>
<Filename>ComponentName.c</Filename>
</SourceFiles>
<Includes>
<PackageName>MdePkg</PackageName>
<PackageName>EdkModulePkg</PackageName>
</Includes>
<Protocols>
<Protocol Usage="TO_START">DevicePath</Protocol>
<Protocol Usage="TO_START">UsbIo</Protocol>
<Protocol Usage="BY_START">SimplePointer</Protocol>
</Protocols>
<Externs>
<Extern>
<ModuleEntryPoint></ModuleEntryPoint>
</Extern>
<Extern>
<DriverBinding>gUsbMouseDriverBinding</DriverBinding>
<ComponentName>gUsbMouseComponentName</ComponentName>
</Extern>
</Externs>
</ModuleSurfaceArea>

View 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="UsbMouse"><!--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\UsbMouse\Dxe"/>
<property name="MODULE_DIR" value="${PACKAGE_DIR}\${MODULE_RELATIVE_PATH}"/>
<property name="COMMON_FILE" value="${WORKSPACE_DIR}\Tools\Conf\Common.xml"/>
<target name="UsbMouse">
<GenBuild baseName="UsbMouse" mbdFilename="${MODULE_DIR}\UsbMouse.mbd" msaFilename="${MODULE_DIR}\UsbMouse.msa"/>
</target>
<target depends="UsbMouse_clean" name="clean"/>
<target depends="UsbMouse_cleanall" name="cleanall"/>
<target name="UsbMouse_clean">
<OutputDirSetup baseName="UsbMouse" mbdFilename="${MODULE_DIR}\UsbMouse.mbd" msaFilename="${MODULE_DIR}\UsbMouse.msa"/>
<if>
<available file="${DEST_DIR_OUTPUT}\UsbMouse_build.xml"/>
<then>
<ant antfile="${DEST_DIR_OUTPUT}\UsbMouse_build.xml" target="clean"/>
</then>
</if>
<delete dir="${DEST_DIR_OUTPUT}" excludes="*.xml"/>
</target>
<target name="UsbMouse_cleanall">
<OutputDirSetup baseName="UsbMouse" mbdFilename="${MODULE_DIR}\UsbMouse.mbd" msaFilename="${MODULE_DIR}\UsbMouse.msa"/>
<if>
<available file="${DEST_DIR_OUTPUT}\UsbMouse_build.xml"/>
<then>
<ant antfile="${DEST_DIR_OUTPUT}\UsbMouse_build.xml" target="cleanall"/>
</then>
</if>
<delete dir="${DEST_DIR_OUTPUT}"/>
<delete dir="${DEST_DIR_DEBUG}"/>
<delete>
<fileset dir="${BIN_DIR}" includes="**UsbMouse*"/>
</delete>
</target>
</project>

View File

@@ -0,0 +1,395 @@
/*++
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:
Mousehid.c
Abstract:
Parse mouse hid descriptor
--*/
#include "usbmouse.h"
#include "mousehid.h"
//
// Get an item from report descriptor
//
STATIC
UINT8 *
GetNextItem (
IN UINT8 *StartPos,
IN UINT8 *EndPos,
OUT HID_ITEM *HidItem
)
/*++
Routine Description:
Get Next Item
Arguments:
StartPos - Start Position
EndPos - End Position
HidItem - HidItem to return
Returns:
Position
--*/
{
UINT8 Temp;
if ((EndPos - StartPos) <= 0) {
return NULL;
}
Temp = *StartPos;
StartPos++;
//
// bit 2,3
//
HidItem->Type = (UINT8) ((Temp >> 2) & 0x03);
//
// bit 4-7
//
HidItem->Tag = (UINT8) ((Temp >> 4) & 0x0F);
if (HidItem->Tag == HID_ITEM_TAG_LONG) {
//
// Long Items are not supported by HID rev1.0,
// although we try to parse it.
//
HidItem->Format = HID_ITEM_FORMAT_LONG;
if ((EndPos - StartPos) >= 2) {
HidItem->Size = *StartPos++;
HidItem->Tag = *StartPos++;
if ((EndPos - StartPos) >= HidItem->Size) {
HidItem->Data.LongData = StartPos;
StartPos += HidItem->Size;
return StartPos;
}
}
} else {
HidItem->Format = HID_ITEM_FORMAT_SHORT;
//
// bit 0, 1
//
HidItem->Size = (UINT8) (Temp & 0x03);
switch (HidItem->Size) {
case 0:
//
// No data
//
return StartPos;
case 1:
//
// One byte data
//
if ((EndPos - StartPos) >= 1) {
HidItem->Data.U8 = *StartPos++;
return StartPos;
}
case 2:
//
// Two byte data
//
if ((EndPos - StartPos) >= 2) {
CopyMem (&HidItem->Data.U16, StartPos, sizeof (UINT16));
StartPos += 2;
return StartPos;
}
case 3:
//
// 4 byte data, adjust size
//
HidItem->Size++;
if ((EndPos - StartPos) >= 4) {
CopyMem (&HidItem->Data.U32, StartPos, sizeof (UINT32));
StartPos += 4;
return StartPos;
}
}
}
return NULL;
}
STATIC
UINT32
GetItemData (
IN HID_ITEM *HidItem
)
/*++
Routine Description:
Get Item Data
Arguments:
HidItem - HID_ITEM
Returns:
HidItem Data
--*/
{
//
// Get Data from HID_ITEM structure
//
switch (HidItem->Size) {
case 1:
return HidItem->Data.U8;
case 2:
return HidItem->Data.U16;
case 4:
return HidItem->Data.U32;
}
return 0;
}
STATIC
VOID
ParseLocalItem (
IN USB_MOUSE_DEV *UsbMouse,
IN HID_ITEM *LocalItem
)
/*++
Routine Description:
Parse Local Item
Arguments:
UsbMouse - USB_MOUSE_DEV
LocalItem - Local Item
Returns:
--*/
{
UINT32 Data;
if (LocalItem->Size == 0) {
//
// No expected data for local item
//
return ;
}
Data = GetItemData (LocalItem);
switch (LocalItem->Tag) {
case HID_LOCAL_ITEM_TAG_DELIMITER:
//
// we don't support delimiter here
//
return ;
case HID_LOCAL_ITEM_TAG_USAGE:
return ;
case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM:
if (UsbMouse->PrivateData.ButtonDetected) {
UsbMouse->PrivateData.ButtonMinIndex = (UINT8) Data;
}
return ;
case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM:
{
if (UsbMouse->PrivateData.ButtonDetected) {
UsbMouse->PrivateData.ButtonMaxIndex = (UINT8) Data;
}
return ;
}
}
}
STATIC
VOID
ParseGlobalItem (
IN USB_MOUSE_DEV *UsbMouse,
IN HID_ITEM *GlobalItem
)
{
UINT8 UsagePage;
switch (GlobalItem->Tag) {
case HID_GLOBAL_ITEM_TAG_USAGE_PAGE:
{
UsagePage = (UINT8) GetItemData (GlobalItem);
//
// We only care Button Page here
//
if (UsagePage == 0x09) {
//
// Button Page
//
UsbMouse->PrivateData.ButtonDetected = TRUE;
return ;
}
break;
}
}
}
STATIC
VOID
ParseMainItem (
IN USB_MOUSE_DEV *UsbMouse,
IN HID_ITEM *MainItem
)
/*++
Routine Description:
Parse Main Item
Arguments:
UsbMouse - TODO: add argument description
MainItem - HID_ITEM to parse
Returns:
VOID
--*/
{
//
// we don't care any main items, just skip
//
return ;
}
STATIC
VOID
ParseHidItem (
IN USB_MOUSE_DEV *UsbMouse,
IN HID_ITEM *HidItem
)
/*++
Routine Description:
Parse Hid Item
Arguments:
UsbMouse - USB_MOUSE_DEV
HidItem - HidItem to parse
Returns:
VOID
--*/
{
switch (HidItem->Type) {
case HID_ITEM_TYPE_MAIN:
//
// For Main Item, parse main item
//
ParseMainItem (UsbMouse, HidItem);
break;
case HID_ITEM_TYPE_GLOBAL:
//
// For global Item, parse global item
//
ParseGlobalItem (UsbMouse, HidItem);
break;
case HID_ITEM_TYPE_LOCAL:
//
// For Local Item, parse local item
//
ParseLocalItem (UsbMouse, HidItem);
break;
}
}
//
// A simple parse just read some field we are interested in
//
EFI_STATUS
ParseMouseReportDescriptor (
IN USB_MOUSE_DEV *UsbMouse,
IN UINT8 *ReportDescriptor,
IN UINTN ReportSize
)
/*++
Routine Description:
Parse Mouse Report Descriptor
Arguments:
UsbMouse - USB_MOUSE_DEV
ReportDescriptor - Report descriptor to parse
ReportSize - Report descriptor size
Returns:
EFI_DEVICE_ERROR - Report descriptor error
EFI_SUCCESS - Success
--*/
{
UINT8 *DescriptorEnd;
UINT8 *ptr;
HID_ITEM HidItem;
DescriptorEnd = ReportDescriptor + ReportSize;
ptr = GetNextItem (ReportDescriptor, DescriptorEnd, &HidItem);
while (ptr != NULL) {
if (HidItem.Format != HID_ITEM_FORMAT_SHORT) {
//
// Long Format Item is not supported at current HID revision
//
return EFI_DEVICE_ERROR;
}
ParseHidItem (UsbMouse, &HidItem);
ptr = GetNextItem (ptr, DescriptorEnd, &HidItem);
}
UsbMouse->NumberOfButtons = (UINT8) (UsbMouse->PrivateData.ButtonMaxIndex - UsbMouse->PrivateData.ButtonMinIndex + 1);
UsbMouse->XLogicMax = UsbMouse->YLogicMax = 127;
UsbMouse->XLogicMin = UsbMouse->YLogicMin = -127;
return EFI_SUCCESS;
}

View File

@@ -0,0 +1,84 @@
/*++
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:
MouseHid.h
Abstract:
--*/
#ifndef __MOUSE_HID_H
#define __MOUSE_HID_H
#include "usbmouse.h"
//
// HID Item general structure
//
typedef struct _hid_item {
UINT16 Format;
UINT8 Size;
UINT8 Type;
UINT8 Tag;
union {
UINT8 U8;
UINT16 U16;
UINT32 U32;
INT8 I8;
INT16 I16;
INT32 I32;
UINT8 *LongData;
} Data;
} HID_ITEM;
typedef struct {
UINT16 UsagePage;
INT32 LogicMin;
INT32 LogicMax;
INT32 PhysicalMin;
INT32 PhysicalMax;
UINT16 UnitExp;
UINT16 UINT;
UINT16 ReportId;
UINT16 ReportSize;
UINT16 ReportCount;
} HID_GLOBAL;
typedef struct {
UINT16 Usage[16]; /* usage array */
UINT16 UsageIndex;
UINT16 UsageMin;
} HID_LOCAL;
typedef struct {
UINT16 Type;
UINT16 Usage;
} HID_COLLECTION;
typedef struct {
HID_GLOBAL Global;
HID_GLOBAL GlobalStack[8];
UINT32 GlobalStackPtr;
HID_LOCAL Local;
HID_COLLECTION CollectionStack[8];
UINT32 CollectionStackPtr;
} HID_PARSER;
EFI_STATUS
ParseMouseReportDescriptor (
IN USB_MOUSE_DEV *UsbMouse,
IN UINT8 *ReportDescriptor,
IN UINTN ReportSize
);
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,85 @@
/*++
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:
UsbMouse.h
Abstract:
--*/
#ifndef _USB_MOUSE_H
#define _USB_MOUSE_H
#include <IndustryStandard/usb.h>
#define CLASS_HID 3
#define SUBCLASS_BOOT 1
#define PROTOCOL_MOUSE 2
#define BOOT_PROTOCOL 0
#define REPORT_PROTOCOL 1
#define USB_MOUSE_DEV_SIGNATURE EFI_SIGNATURE_32 ('u', 'm', 'o', 'u')
typedef struct {
BOOLEAN ButtonDetected;
UINT8 ButtonMinIndex;
UINT8 ButtonMaxIndex;
UINT8 Reserved;
} PRIVATE_DATA;
typedef struct {
UINTN Signature;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
EFI_EVENT DelayedRecoveryEvent;
EFI_USB_IO_PROTOCOL *UsbIo;
EFI_USB_INTERFACE_DESCRIPTOR *InterfaceDescriptor;
EFI_USB_ENDPOINT_DESCRIPTOR *IntEndpointDescriptor;
UINT8 NumberOfButtons;
INT32 XLogicMax;
INT32 XLogicMin;
INT32 YLogicMax;
INT32 YLogicMin;
EFI_SIMPLE_POINTER_PROTOCOL SimplePointerProtocol;
EFI_SIMPLE_POINTER_STATE State;
EFI_SIMPLE_POINTER_MODE Mode;
BOOLEAN StateChanged;
PRIVATE_DATA PrivateData;
EFI_UNICODE_STRING_TABLE *ControllerNameTable;
} USB_MOUSE_DEV;
#define USB_MOUSE_DEV_FROM_MOUSE_PROTOCOL(a) \
CR(a, USB_MOUSE_DEV, SimplePointerProtocol, USB_MOUSE_DEV_SIGNATURE)
VOID
EFIAPI
USBMouseRecoveryHandler (
IN EFI_EVENT Event,
IN VOID *Context
);
//
// Global Variables
//
extern EFI_DRIVER_BINDING_PROTOCOL gUsbMouseDriverBinding;
extern EFI_COMPONENT_NAME_PROTOCOL gUsbMouseComponentName;
extern EFI_GUID gEfiUsbMouseDriverGuid;
VOID
MouseReportStatusCode (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
IN EFI_STATUS_CODE_TYPE CodeType,
IN EFI_STATUS_CODE_VALUE Value
);
#endif