summaryrefslogtreecommitdiffstats
path: root/EdkModulePkg/Bus/Usb/UsbKb
diff options
context:
space:
mode:
authorbbahnsen <bbahnsen@6f19259b-4bc3-4df7-8a09-765794883524>2006-04-21 22:54:32 +0000
committerbbahnsen <bbahnsen@6f19259b-4bc3-4df7-8a09-765794883524>2006-04-21 22:54:32 +0000
commit878ddf1fc3540a715f63594ed22b6929e881afb4 (patch)
treec56c44dac138137b510e1fba7c3efe5e4d84bea2 /EdkModulePkg/Bus/Usb/UsbKb
downloadedk2-878ddf1fc3540a715f63594ed22b6929e881afb4.tar.gz
edk2-878ddf1fc3540a715f63594ed22b6929e881afb4.tar.bz2
edk2-878ddf1fc3540a715f63594ed22b6929e881afb4.zip
Initial import.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@3 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'EdkModulePkg/Bus/Usb/UsbKb')
-rw-r--r--EdkModulePkg/Bus/Usb/UsbKb/Dxe/ComponentName.c215
-rw-r--r--EdkModulePkg/Bus/Usb/UsbKb/Dxe/UsbKb.mbd44
-rw-r--r--EdkModulePkg/Bus/Usb/UsbKb/Dxe/UsbKb.msa77
-rw-r--r--EdkModulePkg/Bus/Usb/UsbKb/Dxe/build.xml47
-rw-r--r--EdkModulePkg/Bus/Usb/UsbKb/Dxe/efikey.c772
-rw-r--r--EdkModulePkg/Bus/Usb/UsbKb/Dxe/efikey.h118
-rw-r--r--EdkModulePkg/Bus/Usb/UsbKb/Dxe/keyboard.c1150
-rw-r--r--EdkModulePkg/Bus/Usb/UsbKb/Dxe/keyboard.h106
8 files changed, 2529 insertions, 0 deletions
diff --git a/EdkModulePkg/Bus/Usb/UsbKb/Dxe/ComponentName.c b/EdkModulePkg/Bus/Usb/UsbKb/Dxe/ComponentName.c
new file mode 100644
index 0000000000..3e139f9d9a
--- /dev/null
+++ b/EdkModulePkg/Bus/Usb/UsbKb/Dxe/ComponentName.c
@@ -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
+ );
+
+}
diff --git a/EdkModulePkg/Bus/Usb/UsbKb/Dxe/UsbKb.mbd b/EdkModulePkg/Bus/Usb/UsbKb/Dxe/UsbKb.mbd
new file mode 100644
index 0000000000..ecb6af6c96
--- /dev/null
+++ b/EdkModulePkg/Bus/Usb/UsbKb/Dxe/UsbKb.mbd
@@ -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>
diff --git a/EdkModulePkg/Bus/Usb/UsbKb/Dxe/UsbKb.msa b/EdkModulePkg/Bus/Usb/UsbKb/Dxe/UsbKb.msa
new file mode 100644
index 0000000000..0ff6464825
--- /dev/null
+++ b/EdkModulePkg/Bus/Usb/UsbKb/Dxe/UsbKb.msa
@@ -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>
diff --git a/EdkModulePkg/Bus/Usb/UsbKb/Dxe/build.xml b/EdkModulePkg/Bus/Usb/UsbKb/Dxe/build.xml
new file mode 100644
index 0000000000..2608381d96
--- /dev/null
+++ b/EdkModulePkg/Bus/Usb/UsbKb/Dxe/build.xml
@@ -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> \ No newline at end of file
diff --git a/EdkModulePkg/Bus/Usb/UsbKb/Dxe/efikey.c b/EdkModulePkg/Bus/Usb/UsbKb/Dxe/efikey.c
new file mode 100644
index 0000000000..a9cdbc8760
--- /dev/null
+++ b/EdkModulePkg/Bus/Usb/UsbKb/Dxe/efikey.c
@@ -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
+ );
+}
diff --git a/EdkModulePkg/Bus/Usb/UsbKb/Dxe/efikey.h b/EdkModulePkg/Bus/Usb/UsbKb/Dxe/efikey.h
new file mode 100644
index 0000000000..bf9f47732d
--- /dev/null
+++ b/EdkModulePkg/Bus/Usb/UsbKb/Dxe/efikey.h
@@ -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
diff --git a/EdkModulePkg/Bus/Usb/UsbKb/Dxe/keyboard.c b/EdkModulePkg/Bus/Usb/UsbKb/Dxe/keyboard.c
new file mode 100644
index 0000000000..1328e6a098
--- /dev/null
+++ b/EdkModulePkg/Bus/Usb/UsbKb/Dxe/keyboard.c
@@ -0,0 +1,1150 @@
+/*++
+
+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.c
+
+Abstract:
+
+ Helper functions for USB Keyboard Driver
+
+Revision History
+
+--*/
+
+#include "keyboard.h"
+
+//
+// USB Key Code to Efi key mapping table
+// Format:<efi scan code>, <unicode without shift>, <unicode with shift>
+//
+STATIC
+UINT8 KeyConvertionTable[USB_KEYCODE_MAX_MAKE][3] = {
+ { SCAN_NULL, 'a', 'A' }, // 0x04
+ { SCAN_NULL, 'b', 'B' }, // 0x05
+ { SCAN_NULL, 'c', 'C' }, // 0x06
+ { SCAN_NULL, 'd', 'D' }, // 0x07
+ { SCAN_NULL, 'e', 'E' }, // 0x08
+ { SCAN_NULL, 'f', 'F' }, // 0x09
+ { SCAN_NULL, 'g', 'G' }, // 0x0A
+ { SCAN_NULL, 'h', 'H' }, // 0x0B
+ { SCAN_NULL, 'i', 'I' }, // 0x0C
+ { SCAN_NULL, 'j', 'J' }, // 0x0D
+ { SCAN_NULL, 'k', 'K' }, // 0x0E
+ { SCAN_NULL, 'l', 'L' }, // 0x0F
+ { SCAN_NULL, 'm', 'M' }, // 0x10
+ { SCAN_NULL, 'n', 'N' }, // 0x11
+ { SCAN_NULL, 'o', 'O' }, // 0x12
+ { SCAN_NULL, 'p', 'P' }, // 0x13
+ { SCAN_NULL, 'q', 'Q' }, // 0x14
+ { SCAN_NULL, 'r', 'R' }, // 0x15
+ { SCAN_NULL, 's', 'S' }, // 0x16
+ { SCAN_NULL, 't', 'T' }, // 0x17
+ { SCAN_NULL, 'u', 'U' }, // 0x18
+ { SCAN_NULL, 'v', 'V' }, // 0x19
+ { SCAN_NULL, 'w', 'W' }, // 0x1A
+ { SCAN_NULL, 'x', 'X' }, // 0x1B
+ { SCAN_NULL, 'y', 'Y' }, // 0x1C
+ { SCAN_NULL, 'z', 'Z' }, // 0x1D
+ { SCAN_NULL, '1', '!' }, // 0x1E
+ { SCAN_NULL, '2', '@' }, // 0x1F
+ { SCAN_NULL, '3', '#' }, // 0x20
+ { SCAN_NULL, '4', '$' }, // 0x21
+ { SCAN_NULL, '5', '%' }, // 0x22
+ { SCAN_NULL, '6', '^' }, // 0x23
+ { SCAN_NULL, '7', '&' }, // 0x24
+ { SCAN_NULL, '8', '*' }, // 0x25
+ { SCAN_NULL, '9', '(' }, // 0x26
+ { SCAN_NULL, '0', ')' }, // 0x27
+ { SCAN_NULL, 0x0d, 0x0d }, // 0x28 Enter
+ { SCAN_ESC, 0x00, 0x00 }, // 0x29 Esc
+ { SCAN_NULL, 0x08, 0x08 }, // 0x2A Backspace
+ { SCAN_NULL, 0x09, 0x09 }, // 0x2B Tab
+ { SCAN_NULL, ' ', ' ' }, // 0x2C Spacebar
+ { SCAN_NULL, '-', '_' }, // 0x2D
+ { SCAN_NULL, '=', '+' }, // 0x2E
+ { SCAN_NULL, '[', '{' }, // 0x2F
+ { SCAN_NULL, ']', '}' }, // 0x30
+ { SCAN_NULL, '\\', '|' }, // 0x31
+ { SCAN_NULL, '\\', '|' }, // 0x32 Keyboard US \ and |
+ { SCAN_NULL, ';', ':' }, // 0x33
+ { SCAN_NULL, '\'', '"' }, // 0x34
+ { SCAN_NULL, '`', '~' }, // 0x35 Keyboard Grave Accent and Tlide
+ { SCAN_NULL, ',', '<' }, // 0x36
+ { SCAN_NULL, '.', '>' }, // 0x37
+ { SCAN_NULL, '/', '?' }, // 0x38
+ { SCAN_NULL, 0x00, 0x00 }, // 0x39 CapsLock
+ { SCAN_F1, 0x00, 0x00 }, // 0x3A
+ { SCAN_F2, 0x00, 0x00 }, // 0x3B
+ { SCAN_F3, 0x00, 0x00 }, // 0x3C
+ { SCAN_F4, 0x00, 0x00 }, // 0x3D
+ { SCAN_F5, 0x00, 0x00 }, // 0x3E
+ { SCAN_F6, 0x00, 0x00 }, // 0x3F
+ { SCAN_F7, 0x00, 0x00 }, // 0x40
+ { SCAN_F8, 0x00, 0x00 }, // 0x41
+ { SCAN_F9, 0x00, 0x00 }, // 0x42
+ { SCAN_F10, 0x00, 0x00 }, // 0x43
+ { SCAN_NULL, 0x00, 0x00 }, // 0x44 F11
+ { SCAN_NULL, 0x00, 0x00 }, // 0x45 F12
+ { SCAN_NULL, 0x00, 0x00 }, // 0x46 PrintScreen
+ { SCAN_NULL, 0x00, 0x00 }, // 0x47 Scroll Lock
+ { SCAN_NULL, 0x00, 0x00 }, // 0x48 Pause
+ { SCAN_INSERT, 0x00, 0x00 }, // 0x49
+ { SCAN_HOME, 0x00, 0x00 }, // 0x4A
+ { SCAN_PAGE_UP, 0x00, 0x00 }, // 0x4B
+ { SCAN_DELETE, 0x00, 0x00 }, // 0x4C
+ { SCAN_END, 0x00, 0x00 }, // 0x4D
+ { SCAN_PAGE_DOWN, 0x00, 0x00 }, // 0x4E
+ { SCAN_RIGHT, 0x00, 0x00 }, // 0x4F
+ { SCAN_LEFT, 0x00, 0x00 }, // 0x50
+ { SCAN_DOWN, 0x00, 0x00 }, // 0x51
+ { SCAN_UP, 0x00, 0x00 }, // 0x52
+ { SCAN_NULL, 0x00, 0x00 }, // 0x53 NumLock
+ { SCAN_NULL, '/', '/' }, // 0x54
+ { SCAN_NULL, '*', '*' }, // 0x55
+ { SCAN_NULL, '-', '-' }, // 0x56
+ { SCAN_NULL, '+', '+' }, // 0x57
+ { SCAN_NULL, 0x0d, 0x0d }, // 0x58
+ { SCAN_END, '1', '1' }, // 0x59
+ { SCAN_DOWN, '2', '2' }, // 0x5A
+ { SCAN_PAGE_DOWN, '3', '3' }, // 0x5B
+ { SCAN_LEFT, '4', '4' }, // 0x5C
+ { SCAN_NULL, '5', '5' }, // 0x5D
+ { SCAN_RIGHT, '6', '6' }, // 0x5E
+ { SCAN_HOME, '7', '7' }, // 0x5F
+ { SCAN_UP, '8', '8' }, // 0x60
+ { SCAN_PAGE_UP, '9', '9' }, // 0x61
+ { SCAN_INSERT, '0', '0' }, // 0x62
+ { SCAN_DELETE, '.', '.' }, // 0x63
+ { SCAN_NULL, '\\', '|' }, // 0x64 Keyboard Non-US \ and |
+ { SCAN_NULL, 0x00, 0x00 }, // 0x65 Keyboard Application
+ { SCAN_NULL, 0x00, 0x00 }, // 0x66 Keyboard Power
+ { SCAN_NULL, '=' , '=' } // 0x67 Keypad =
+};
+
+STATIC KB_MODIFIER KB_Mod[8] = {
+ { MOD_CONTROL_L, 0xe0 }, // 11100000
+ { MOD_CONTROL_R, 0xe4 }, // 11100100
+ { MOD_SHIFT_L, 0xe1 }, // 11100001
+ { MOD_SHIFT_R, 0xe5 }, // 11100101
+ { MOD_ALT_L, 0xe2 }, // 11100010
+ { MOD_ALT_R, 0xe6 }, // 11100110
+ { MOD_WIN_L, 0xe3 }, // 11100011
+ { MOD_WIN_R, 0xe7 } // 11100111
+};
+
+
+BOOLEAN
+IsUSBKeyboard (
+ IN EFI_USB_IO_PROTOCOL *UsbIo
+ )
+/*++
+
+ Routine Description:
+ Uses USB I/O to check whether the device is a USB Keyboard device.
+
+ Arguments:
+ UsbIo: Points to a USB I/O protocol instance.
+
+ Returns:
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
+
+ //
+ // Get the Default interface descriptor, currently we
+ // assume it is interface 1
+ //
+ Status = UsbIo->UsbGetInterfaceDescriptor (
+ UsbIo,
+ &InterfaceDescriptor
+ );
+
+ if (EFI_ERROR (Status)) {
+ return FALSE;
+ }
+
+ if (InterfaceDescriptor.InterfaceClass == CLASS_HID &&
+ InterfaceDescriptor.InterfaceSubClass == SUBCLASS_BOOT &&
+ InterfaceDescriptor.InterfaceProtocol == PROTOCOL_KEYBOARD
+ ) {
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+
+EFI_STATUS
+InitUSBKeyboard (
+ IN USB_KB_DEV *UsbKeyboardDevice
+ )
+/*++
+
+ Routine Description:
+ Initialize USB Keyboard device and all private data structures.
+
+ Arguments:
+ UsbKeyboardDevice The USB_KB_DEV instance.
+
+ Returns:
+ EFI_SUCCESS - Success
+ EFI_DEVICE_ERROR - Hardware Error
+--*/
+{
+ UINT8 ConfigValue;
+ UINT8 Protocol;
+ UINT8 ReportId;
+ UINT8 Duration;
+ EFI_STATUS Status;
+ UINT32 TransferResult;
+ EFI_USB_IO_PROTOCOL *UsbIo;
+
+ UsbIo = UsbKeyboardDevice->UsbIo;
+
+ KbdReportStatusCode (
+ UsbKeyboardDevice->DevicePath,
+ EFI_PROGRESS_CODE,
+ (EFI_PERIPHERAL_KEYBOARD | EFI_P_KEYBOARD_PC_SELF_TEST)
+ );
+
+ InitUSBKeyBuffer (&(UsbKeyboardDevice->KeyboardBuffer));
+
+ //
+ // default configurations
+ //
+ ConfigValue = 0x01;
+
+ //
+ // Uses default configuration to configure the USB Keyboard device.
+ //
+ Status = UsbSetDeviceConfiguration (
+ UsbKeyboardDevice->UsbIo,
+ (UINT16) ConfigValue,
+ &TransferResult
+ );
+ if (EFI_ERROR (Status)) {
+ //
+ // If configuration could not be set here, it means
+ // the keyboard interface has some errors and could
+ // not be initialized
+ //
+ KbdReportStatusCode (
+ UsbKeyboardDevice->DevicePath,
+ EFI_ERROR_CODE | EFI_ERROR_MINOR,
+ (EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_INTERFACE_ERROR)
+ );
+
+ return EFI_DEVICE_ERROR;
+ }
+
+ UsbGetProtocolRequest (
+ UsbKeyboardDevice->UsbIo,
+ UsbKeyboardDevice->InterfaceDescriptor.InterfaceNumber,
+ &Protocol
+ );
+ //
+ // Sets boot protocol for the USB Keyboard.
+ // This driver only supports boot protocol.
+ // !!BugBug: How about the device that does not support boot protocol?
+ //
+ if (Protocol != BOOT_PROTOCOL) {
+ UsbSetProtocolRequest (
+ UsbKeyboardDevice->UsbIo,
+ UsbKeyboardDevice->InterfaceDescriptor.InterfaceNumber,
+ BOOT_PROTOCOL
+ );
+ }
+ //
+ // the duration is indefinite, so the endpoint will inhibit reporting forever,
+ // and only reporting when a change is detected in the report data.
+ //
+
+ //
+ // idle value for all report ID
+ //
+ ReportId = 0;
+ //
+ // idle forever until there is a key pressed and released.
+ //
+ Duration = 0;
+ UsbSetIdleRequest (
+ UsbKeyboardDevice->UsbIo,
+ UsbKeyboardDevice->InterfaceDescriptor.InterfaceNumber,
+ ReportId,
+ Duration
+ );
+
+ UsbKeyboardDevice->CtrlOn = 0;
+ UsbKeyboardDevice->AltOn = 0;
+ UsbKeyboardDevice->ShiftOn = 0;
+ UsbKeyboardDevice->NumLockOn = 0;
+ UsbKeyboardDevice->CapsOn = 0;
+ ZeroMem (UsbKeyboardDevice->LastKeyCodeArray, sizeof (UINT8) * 8);
+
+ //
+ // Set a timer for repeat keys' generation.
+ //
+ if (UsbKeyboardDevice->RepeatTimer) {
+ gBS->CloseEvent (UsbKeyboardDevice->RepeatTimer);
+ UsbKeyboardDevice->RepeatTimer = 0;
+ }
+
+ Status = gBS->CreateEvent (
+ EFI_EVENT_TIMER | EFI_EVENT_NOTIFY_SIGNAL,
+ EFI_TPL_NOTIFY,
+ USBKeyboardRepeatHandler,
+ UsbKeyboardDevice,
+ &UsbKeyboardDevice->RepeatTimer
+ );
+
+ if (UsbKeyboardDevice->DelayedRecoveryEvent) {
+ gBS->CloseEvent (UsbKeyboardDevice->DelayedRecoveryEvent);
+ UsbKeyboardDevice->DelayedRecoveryEvent = 0;
+ }
+
+ Status = gBS->CreateEvent (
+ EFI_EVENT_TIMER | EFI_EVENT_NOTIFY_SIGNAL,
+ EFI_TPL_NOTIFY,
+ USBKeyboardRecoveryHandler,
+ UsbKeyboardDevice,
+ &UsbKeyboardDevice->DelayedRecoveryEvent
+ );
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+KeyboardHandler (
+ IN VOID *Data,
+ IN UINTN DataLength,
+ IN VOID *Context,
+ IN UINT32 Result
+ )
+/*++
+
+ Routine Description:
+ Handler function for USB Keyboard's asynchronous interrupt transfer.
+
+ Arguments:
+ Data A pointer to a buffer that is filled with key data which is
+ retrieved via asynchronous interrupt transfer.
+ DataLength Indicates the size of the data buffer.
+ Context Pointing to USB_KB_DEV instance.
+ Result Indicates the result of the asynchronous interrupt transfer.
+
+ Returns:
+ EFI_SUCCESS - Success
+ EFI_DEVICE_ERROR - Hardware Error
+--*/
+{
+ USB_KB_DEV *UsbKeyboardDevice;
+ EFI_USB_IO_PROTOCOL *UsbIo;
+ UINT8 *CurKeyCodeBuffer;
+ UINT8 *OldKeyCodeBuffer;
+ UINT8 CurModifierMap;
+ UINT8 OldModifierMap;
+ UINT8 Index;
+ UINT8 Index2;
+ BOOLEAN Down;
+ EFI_STATUS Status;
+ BOOLEAN KeyRelease;
+ BOOLEAN KeyPress;
+ UINT8 SavedTail;
+ USB_KEY UsbKey;
+ UINT8 NewRepeatKey;
+ UINT32 UsbStatus;
+ UINT8 *DataPtr;
+
+ ASSERT (Context);
+
+ NewRepeatKey = 0;
+ DataPtr = (UINT8 *) Data;
+ UsbKeyboardDevice = (USB_KB_DEV *) Context;
+ UsbIo = UsbKeyboardDevice->UsbIo;
+
+ //
+ // Analyzes the Result and performs corresponding action.
+ //
+ if (Result != EFI_USB_NOERROR) {
+ //
+ // Some errors happen during the process
+ //
+ KbdReportStatusCode (
+ UsbKeyboardDevice->DevicePath,
+ EFI_ERROR_CODE | EFI_ERROR_MINOR,
+ (EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_INPUT_ERROR)
+ );
+
+ //
+ // stop the repeat key generation if any
+ //
+ UsbKeyboardDevice->RepeatKey = 0;
+
+ gBS->SetTimer (
+ UsbKeyboardDevice->RepeatTimer,
+ TimerCancel,
+ USBKBD_REPEAT_RATE
+ );
+
+ if ((Result & EFI_USB_ERR_STALL) == EFI_USB_ERR_STALL) {
+ UsbClearEndpointHalt (
+ UsbIo,
+ UsbKeyboardDevice->IntEndpointDescriptor.EndpointAddress,
+ &UsbStatus
+ );
+ }
+
+ //
+ // Delete & Submit this interrupt again
+ //
+
+ Status = UsbIo->UsbAsyncInterruptTransfer (
+ UsbIo,
+ UsbKeyboardDevice->IntEndpointDescriptor.EndpointAddress,
+ FALSE,
+ 0,
+ 0,
+ NULL,
+ NULL
+ );
+
+ gBS->SetTimer (
+ UsbKeyboardDevice->DelayedRecoveryEvent,
+ TimerRelative,
+ EFI_USB_INTERRUPT_DELAY
+ );
+
+ return EFI_DEVICE_ERROR;
+ }
+
+ if (DataLength == 0 || Data == NULL) {
+ return EFI_SUCCESS;
+ }
+
+ CurKeyCodeBuffer = (UINT8 *) Data;
+ OldKeyCodeBuffer = UsbKeyboardDevice->LastKeyCodeArray;
+
+ //
+ // checks for new key stroke.
+ // if no new key got, return immediately.
+ //
+ for (Index = 0; Index < 8; Index++) {
+ if (OldKeyCodeBuffer[Index] != CurKeyCodeBuffer[Index]) {
+ break;
+ }
+ }
+
+ if (Index == 8) {
+ return EFI_SUCCESS;
+ }
+
+ //
+ // Parse the modifier key
+ //
+ CurModifierMap = CurKeyCodeBuffer[0];
+ OldModifierMap = OldKeyCodeBuffer[0];
+
+ //
+ // handle modifier key's pressing or releasing situation.
+ //
+ for (Index = 0; Index < 8; Index++) {
+
+ if ((CurModifierMap & KB_Mod[Index].Mask) != (OldModifierMap & KB_Mod[Index].Mask)) {
+ //
+ // if current modifier key is up, then
+ // CurModifierMap & KB_Mod[Index].Mask = 0;
+ // otherwize it is a non-zero value.
+ // Inserts the pressed modifier key into key buffer.
+ //
+ Down = (UINT8) (CurModifierMap & KB_Mod[Index].Mask);
+ InsertKeyCode (&(UsbKeyboardDevice->KeyboardBuffer), KB_Mod[Index].Key, Down);
+ }
+ }
+
+ //
+ // handle normal key's releasing situation
+ //
+ KeyRelease = FALSE;
+ for (Index = 2; Index < 8; Index++) {
+
+ if (!USBKBD_VALID_KEYCODE (OldKeyCodeBuffer[Index])) {
+ continue;
+ }
+
+ KeyRelease = TRUE;
+ for (Index2 = 2; Index2 < 8; Index2++) {
+
+ if (!USBKBD_VALID_KEYCODE (CurKeyCodeBuffer[Index2])) {
+ continue;
+ }
+
+ if (OldKeyCodeBuffer[Index] == CurKeyCodeBuffer[Index2]) {
+ KeyRelease = FALSE;
+ break;
+ }
+ }
+
+ if (KeyRelease) {
+ InsertKeyCode (
+ &(UsbKeyboardDevice->KeyboardBuffer),
+ OldKeyCodeBuffer[Index],
+ 0
+ );
+ //
+ // the original reapeat key is released.
+ //
+ if (OldKeyCodeBuffer[Index] == UsbKeyboardDevice->RepeatKey) {
+ UsbKeyboardDevice->RepeatKey = 0;
+ }
+ }
+ }
+
+ //
+ // original repeat key is released, cancel the repeat timer
+ //
+ if (UsbKeyboardDevice->RepeatKey == 0) {
+ gBS->SetTimer (
+ UsbKeyboardDevice->RepeatTimer,
+ TimerCancel,
+ USBKBD_REPEAT_RATE
+ );
+ }
+
+ //
+ // handle normal key's pressing situation
+ //
+ KeyPress = FALSE;
+ for (Index = 2; Index < 8; Index++) {
+
+ if (!USBKBD_VALID_KEYCODE (CurKeyCodeBuffer[Index])) {
+ continue;
+ }
+
+ KeyPress = TRUE;
+ for (Index2 = 2; Index2 < 8; Index2++) {
+
+ if (!USBKBD_VALID_KEYCODE (OldKeyCodeBuffer[Index2])) {
+ continue;
+ }
+
+ if (CurKeyCodeBuffer[Index] == OldKeyCodeBuffer[Index2]) {
+ KeyPress = FALSE;
+ break;
+ }
+ }
+
+ if (KeyPress) {
+ InsertKeyCode (&(UsbKeyboardDevice->KeyboardBuffer), CurKeyCodeBuffer[Index], 1);
+ //
+ // NumLock pressed or CapsLock pressed
+ //
+ if (CurKeyCodeBuffer[Index] == 0x53 || CurKeyCodeBuffer[Index] == 0x39) {
+ UsbKeyboardDevice->RepeatKey = 0;
+ } else {
+ NewRepeatKey = CurKeyCodeBuffer[Index];
+ //
+ // do not repeat the original repeated key
+ //
+ UsbKeyboardDevice->RepeatKey = 0;
+ }
+ }
+ }
+
+ //
+ // Update LastKeycodeArray[] buffer in the
+ // Usb Keyboard Device data structure.
+ //
+ for (Index = 0; Index < 8; Index++) {
+ UsbKeyboardDevice->LastKeyCodeArray[Index] = CurKeyCodeBuffer[Index];
+ }
+
+ //
+ // pre-process KeyboardBuffer, pop out the ctrl,alt,del key in sequence
+ // and judge whether it will invoke reset event.
+ //
+ SavedTail = UsbKeyboardDevice->KeyboardBuffer.bTail;
+ Index = UsbKeyboardDevice->KeyboardBuffer.bHead;
+ while (Index != SavedTail) {
+ RemoveKeyCode (&(UsbKeyboardDevice->KeyboardBuffer), &UsbKey);
+
+ switch (UsbKey.KeyCode) {
+
+ case 0xe0:
+ case 0xe4:
+ if (UsbKey.Down) {
+ UsbKeyboardDevice->CtrlOn = 1;
+ } else {
+ UsbKeyboardDevice->CtrlOn = 0;
+ }
+ break;
+
+ case 0xe2:
+ case 0xe6:
+ if (UsbKey.Down) {
+ UsbKeyboardDevice->AltOn = 1;
+ } else {
+ UsbKeyboardDevice->AltOn = 0;
+ }
+ break;
+
+ //
+ // Del Key Code
+ //
+ case 0x4c:
+ case 0x63:
+ if (UsbKey.Down) {
+ if (UsbKeyboardDevice->CtrlOn && UsbKeyboardDevice->AltOn) {
+ gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);
+ }
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ //
+ // insert the key back to the buffer.
+ // so the key sequence will not be destroyed.
+ //
+ InsertKeyCode (
+ &(UsbKeyboardDevice->KeyboardBuffer),
+ UsbKey.KeyCode,
+ UsbKey.Down
+ );
+ Index = UsbKeyboardDevice->KeyboardBuffer.bHead;
+
+ }
+ //
+ // If have new key pressed, update the RepeatKey value, and set the
+ // timer to repeate delay timer
+ //
+ if (NewRepeatKey != 0) {
+ //
+ // sets trigger time to "Repeat Delay Time",
+ // to trigger the repeat timer when the key is hold long
+ // enough time.
+ //
+ gBS->SetTimer (
+ UsbKeyboardDevice->RepeatTimer,
+ TimerRelative,
+ USBKBD_REPEAT_DELAY
+ );
+ UsbKeyboardDevice->RepeatKey = NewRepeatKey;
+ }
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+USBParseKey (
+ IN OUT USB_KB_DEV *UsbKeyboardDevice,
+ OUT UINT8 *KeyChar
+ )
+/*++
+
+ Routine Description:
+ Retrieves a key character after parsing the raw data in keyboard buffer.
+
+ Arguments:
+ UsbKeyboardDevice The USB_KB_DEV instance.
+ KeyChar Points to the Key character after key parsing.
+
+ Returns:
+ EFI_SUCCESS - Success
+ EFI_NOT_READY - Device is not ready
+--*/
+{
+ USB_KEY UsbKey;
+
+ *KeyChar = 0;
+
+ while (!IsUSBKeyboardBufferEmpty (&UsbKeyboardDevice->KeyboardBuffer)) {
+ //
+ // pops one raw data off.
+ //
+ RemoveKeyCode (&(UsbKeyboardDevice->KeyboardBuffer), &UsbKey);
+
+ if (!UsbKey.Down) {
+ switch (UsbKey.KeyCode) {
+
+ case 0xe0:
+ case 0xe4:
+ UsbKeyboardDevice->CtrlOn = 0;
+ break;
+
+ case 0xe1:
+ case 0xe5:
+ UsbKeyboardDevice->ShiftOn = 0;
+ break;
+
+ case 0xe2:
+ case 0xe6:
+ UsbKeyboardDevice->AltOn = 0;
+ break;
+
+ default:
+ break;
+ }
+
+ continue;
+ }
+
+ //
+ // Analyzes key pressing situation
+ //
+ switch (UsbKey.KeyCode) {
+
+ case 0xe0:
+ case 0xe4:
+ UsbKeyboardDevice->CtrlOn = 1;
+ continue;
+ break;
+
+ case 0xe1:
+ case 0xe5:
+ UsbKeyboardDevice->ShiftOn = 1;
+ continue;
+ break;
+
+ case 0xe2:
+ case 0xe6:
+ UsbKeyboardDevice->AltOn = 1;
+ continue;
+ break;
+
+ case 0xe3:
+ case 0xe7:
+ continue;
+ break;
+
+ case 0x53:
+ UsbKeyboardDevice->NumLockOn ^= 1;
+ SetKeyLED (UsbKeyboardDevice);
+ continue;
+ break;
+
+ case 0x39:
+ UsbKeyboardDevice->CapsOn ^= 1;
+ SetKeyLED (UsbKeyboardDevice);
+ continue;
+ break;
+
+ //
+ // F11,F12,PrintScreen,ScrollLock,Pause,Application,Power
+ // keys are not valid EFI key
+ //
+ case 0x44:
+ //
+ // fall through
+ //
+ case 0x45:
+ //
+ // fall through
+ //
+ case 0x46:
+ //
+ // fall through
+ //
+ case 0x47:
+ //
+ // fall through
+ //
+ case 0x48:
+ //
+ // fall through
+ //
+ case 0x65:
+ case 0x66:
+ continue;
+ break;
+
+ default:
+ break;
+ }
+
+ //
+ // When encountered Del Key...
+ //
+ if (UsbKey.KeyCode == 0x4c || UsbKey.KeyCode == 0x63) {
+ if (UsbKeyboardDevice->CtrlOn && UsbKeyboardDevice->AltOn) {
+ gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);
+ }
+ }
+
+ *KeyChar = UsbKey.KeyCode;
+ return EFI_SUCCESS;
+ }
+
+ return EFI_NOT_READY;
+
+}
+
+
+EFI_STATUS
+USBKeyCodeToEFIScanCode (
+ IN USB_KB_DEV *UsbKeyboardDevice,
+ IN UINT8 KeyChar,
+ OUT EFI_INPUT_KEY *Key
+ )
+/*++
+
+ Routine Description:
+ Converts USB Keyboard code to EFI Scan Code.
+
+ Arguments:
+ UsbKeyboardDevice The USB_KB_DEV instance.
+ KeyChar Indicates the key code that will be interpreted.
+ Key A pointer to a buffer that is filled in with
+ the keystroke information for the key that
+ was pressed.
+ Returns:
+ EFI_NOT_READY - Device is not ready
+ EFI_SUCCESS - Success
+--*/
+{
+ UINT8 Index;
+
+ if (!USBKBD_VALID_KEYCODE (KeyChar)) {
+ return EFI_NOT_READY;
+ }
+
+ //
+ // valid USB Key Code starts from 4
+ //
+ Index = (UINT8) (KeyChar - 4);
+
+ if (Index >= USB_KEYCODE_MAX_MAKE) {
+ return EFI_NOT_READY;
+ }
+
+ Key->ScanCode = KeyConvertionTable[Index][0];
+
+ if (UsbKeyboardDevice->ShiftOn) {
+
+ Key->UnicodeChar = KeyConvertionTable[Index][2];
+
+ } else {
+
+ Key->UnicodeChar = KeyConvertionTable[Index][1];
+ }
+
+ if (UsbKeyboardDevice->CapsOn) {
+
+ if (Key->UnicodeChar >= 'a' && Key->UnicodeChar <= 'z') {
+
+ Key->UnicodeChar = KeyConvertionTable[Index][2];
+
+ } else if (Key->UnicodeChar >= 'A' && Key->UnicodeChar <= 'Z') {
+
+ Key->UnicodeChar = KeyConvertionTable[Index][1];
+
+ }
+ }
+
+ if (KeyChar >= 0x59 && KeyChar <= 0x63) {
+
+ if (UsbKeyboardDevice->NumLockOn && !UsbKeyboardDevice->ShiftOn) {
+
+ Key->ScanCode = SCAN_NULL;
+
+ } else {
+
+ Key->UnicodeChar = 0x00;
+ }
+ }
+
+ if (Key->UnicodeChar == 0 && Key->ScanCode == SCAN_NULL) {
+ return EFI_NOT_READY;
+ }
+
+ return EFI_SUCCESS;
+
+}
+
+
+EFI_STATUS
+InitUSBKeyBuffer (
+ IN OUT USB_KB_BUFFER *KeyboardBuffer
+ )
+/*++
+
+ Routine Description:
+ Resets USB Keyboard Buffer.
+
+ Arguments:
+ KeyboardBuffer - Points to the USB Keyboard Buffer.
+
+ Returns:
+ EFI_SUCCESS - Success
+--*/
+{
+ ZeroMem (KeyboardBuffer, sizeof (USB_KB_BUFFER));
+
+ KeyboardBuffer->bHead = KeyboardBuffer->bTail;
+
+ return EFI_SUCCESS;
+}
+
+BOOLEAN
+IsUSBKeyboardBufferEmpty (
+ IN USB_KB_BUFFER *KeyboardBuffer
+ )
+/*++
+
+ Routine Description:
+ Check whether USB Keyboard buffer is empty.
+
+ Arguments:
+ KeyboardBuffer - USB Keyboard Buffer.
+
+ Returns:
+
+--*/
+{
+ //
+ // meet FIFO empty condition
+ //
+ return (BOOLEAN) (KeyboardBuffer->bHead == KeyboardBuffer->bTail);
+}
+
+
+BOOLEAN
+IsUSBKeyboardBufferFull (
+ IN USB_KB_BUFFER *KeyboardBuffer
+ )
+/*++
+
+ Routine Description:
+ Check whether USB Keyboard buffer is full.
+
+ Arguments:
+ KeyboardBuffer - USB Keyboard Buffer.
+
+ Returns:
+
+--*/
+{
+ return (BOOLEAN)(((KeyboardBuffer->bTail + 1) % (MAX_KEY_ALLOWED + 1)) ==
+ KeyboardBuffer->bHead);
+}
+
+
+EFI_STATUS
+InsertKeyCode (
+ IN OUT USB_KB_BUFFER *KeyboardBuffer,
+ IN UINT8 Key,
+ IN UINT8 Down
+ )
+/*++
+
+ Routine Description:
+ Inserts a key code into keyboard buffer.
+
+ Arguments:
+ KeyboardBuffer - Points to the USB Keyboard Buffer.
+ Key - Key code
+ Down - Special key
+ Returns:
+ EFI_SUCCESS - Success
+--*/
+{
+ USB_KEY UsbKey;
+
+ //
+ // if keyboard buffer is full, throw the
+ // first key out of the keyboard buffer.
+ //
+ if (IsUSBKeyboardBufferFull (KeyboardBuffer)) {
+ RemoveKeyCode (KeyboardBuffer, &UsbKey);
+ }
+
+ KeyboardBuffer->buffer[KeyboardBuffer->bTail].KeyCode = Key;
+ KeyboardBuffer->buffer[KeyboardBuffer->bTail].Down = Down;
+
+ //
+ // adjust the tail pointer of the FIFO keyboard buffer.
+ //
+ KeyboardBuffer->bTail = (UINT8) ((KeyboardBuffer->bTail + 1) % (MAX_KEY_ALLOWED + 1));
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+RemoveKeyCode (
+ IN OUT USB_KB_BUFFER *KeyboardBuffer,
+ OUT USB_KEY *UsbKey
+ )
+/*++
+
+ Routine Description:
+ Pops a key code off from keyboard buffer.
+
+ Arguments:
+ KeyboardBuffer - Points to the USB Keyboard Buffer.
+ UsbKey - Points to the buffer that contains a usb key code.
+
+ Returns:
+ EFI_SUCCESS - Success
+ EFI_DEVICE_ERROR - Hardware Error
+--*/
+{
+ if (IsUSBKeyboardBufferEmpty (KeyboardBuffer)) {
+ return EFI_DEVICE_ERROR;
+ }
+
+ UsbKey->KeyCode = KeyboardBuffer->buffer[KeyboardBuffer->bHead].KeyCode;
+ UsbKey->Down = KeyboardBuffer->buffer[KeyboardBuffer->bHead].Down;
+
+ //
+ // adjust the head pointer of the FIFO keyboard buffer.
+ //
+ KeyboardBuffer->bHead = (UINT8) ((KeyboardBuffer->bHead + 1) % (MAX_KEY_ALLOWED + 1));
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+SetKeyLED (
+ IN USB_KB_DEV *UsbKeyboardDevice
+ )
+/*++
+
+ Routine Description:
+ Sets USB Keyboard LED state.
+
+ Arguments:
+ UsbKeyboardDevice - The USB_KB_DEV instance.
+
+ Returns:
+ EFI_SUCCESS - Success
+--*/
+{
+ LED_MAP Led;
+ UINT8 ReportId;
+
+ //
+ // Set each field in Led map.
+ //
+ Led.NumLock = (UINT8) UsbKeyboardDevice->NumLockOn;
+ Led.CapsLock = (UINT8) UsbKeyboardDevice->CapsOn;
+ Led.Resrvd = 0;
+
+ ReportId = 0;
+ //
+ // call Set Report Request to lighten the LED.
+ //
+ UsbSetReportRequest (
+ UsbKeyboardDevice->UsbIo,
+ UsbKeyboardDevice->InterfaceDescriptor.InterfaceNumber,
+ ReportId,
+ HID_OUTPUT_REPORT,
+ 1,
+ (UINT8 *) &Led
+ );
+
+ return EFI_SUCCESS;
+}
+
+VOID
+EFIAPI
+USBKeyboardRepeatHandler (
+ IN EFI_EVENT Event,
+ IN VOID *Context
+ )
+/*++
+
+ Routine Description:
+ Timer handler for Repeat Key timer.
+
+ Arguments:
+ Event - The Repeat Key event.
+ Context - Points to the USB_KB_DEV instance.
+
+ Returns:
+
+--*/
+{
+ USB_KB_DEV *UsbKeyboardDevice;
+
+ UsbKeyboardDevice = (USB_KB_DEV *) Context;
+
+ //
+ // Do nothing when there is no repeat key.
+ //
+ if (UsbKeyboardDevice->RepeatKey != 0) {
+ //
+ // Inserts one Repeat key into keyboard buffer,
+ //
+ InsertKeyCode (
+ &(UsbKeyboardDevice->KeyboardBuffer),
+ UsbKeyboardDevice->RepeatKey,
+ 1
+ );
+
+ //
+ // set repeate rate for repeat key generation.
+ //
+ gBS->SetTimer (
+ UsbKeyboardDevice->RepeatTimer,
+ TimerRelative,
+ USBKBD_REPEAT_RATE
+ );
+
+ }
+}
+
+VOID
+EFIAPI
+USBKeyboardRecoveryHandler (
+ IN EFI_EVENT Event,
+ IN VOID *Context
+ )
+/*++
+
+ Routine Description:
+ Timer handler for Delayed Recovery timer.
+
+ Arguments:
+ Event - The Delayed Recovery event.
+ Context - Points to the USB_KB_DEV instance.
+
+ Returns:
+
+--*/
+{
+
+ USB_KB_DEV *UsbKeyboardDevice;
+ EFI_USB_IO_PROTOCOL *UsbIo;
+ UINT8 PacketSize;
+
+ UsbKeyboardDevice = (USB_KB_DEV *) Context;
+
+ UsbIo = UsbKeyboardDevice->UsbIo;
+
+ PacketSize = (UINT8) (UsbKeyboardDevice->IntEndpointDescriptor.MaxPacketSize);
+
+ UsbIo->UsbAsyncInterruptTransfer (
+ UsbIo,
+ UsbKeyboardDevice->IntEndpointDescriptor.EndpointAddress,
+ TRUE,
+ UsbKeyboardDevice->IntEndpointDescriptor.Interval,
+ PacketSize,
+ KeyboardHandler,
+ UsbKeyboardDevice
+ );
+}
diff --git a/EdkModulePkg/Bus/Usb/UsbKb/Dxe/keyboard.h b/EdkModulePkg/Bus/Usb/UsbKb/Dxe/keyboard.h
new file mode 100644
index 0000000000..a01fda3ca4
--- /dev/null
+++ b/EdkModulePkg/Bus/Usb/UsbKb/Dxe/keyboard.h
@@ -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