2007-07-12 19:31:28 +02:00
|
|
|
/** @file
|
2008-12-15 08:17:47 +01:00
|
|
|
USB Keyboard Driver that manages USB keyboard and produces Simple Text Input
|
|
|
|
Protocol and Simple Text Input Ex Protocol.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>
|
2010-04-19 07:34:25 +02:00
|
|
|
This program and the accompanying materials
|
2007-07-12 19:31:28 +02:00
|
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
2008-07-23 08:29:46 +02:00
|
|
|
**/
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2008-07-23 08:29:46 +02:00
|
|
|
#include "EfiKey.h"
|
|
|
|
#include "KeyBoard.h"
|
2007-07-12 19:31:28 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// USB Keyboard Driver Global Variables
|
|
|
|
//
|
|
|
|
EFI_DRIVER_BINDING_PROTOCOL gUsbKeyboardDriverBinding = {
|
|
|
|
USBKeyboardDriverBindingSupported,
|
|
|
|
USBKeyboardDriverBindingStart,
|
|
|
|
USBKeyboardDriverBindingStop,
|
|
|
|
0xa,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2008-07-23 08:29:46 +02:00
|
|
|
/**
|
2008-12-05 10:19:10 +01:00
|
|
|
Entrypoint of USB Keyboard Driver.
|
|
|
|
|
|
|
|
This function is the entrypoint of USB Keyboard Driver. It installs Driver Binding
|
|
|
|
Protocols together with Component Name Protocols.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
2008-12-05 10:19:10 +01:00
|
|
|
@param ImageHandle The firmware allocated handle for the EFI image.
|
|
|
|
@param SystemTable A pointer to the EFI System Table.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
2008-12-05 10:19:10 +01:00
|
|
|
@retval EFI_SUCCESS The entry point is executed successfully.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
**/
|
2007-07-12 19:31:28 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
USBKeyboardDriverBindingEntryPoint (
|
|
|
|
IN EFI_HANDLE ImageHandle,
|
|
|
|
IN EFI_SYSTEM_TABLE *SystemTable
|
|
|
|
)
|
|
|
|
{
|
2008-12-05 10:19:10 +01:00
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
Status = EfiLibInstallDriverBindingComponentName2 (
|
|
|
|
ImageHandle,
|
|
|
|
SystemTable,
|
|
|
|
&gUsbKeyboardDriverBinding,
|
|
|
|
ImageHandle,
|
|
|
|
&gUsbKeyboardComponentName,
|
|
|
|
&gUsbKeyboardComponentName2
|
|
|
|
);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
2007-07-12 19:31:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-12-05 10:19:10 +01:00
|
|
|
Check whether USB keyboard driver supports this device.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2008-07-23 08:29:46 +02:00
|
|
|
@param This The USB keyboard driver binding protocol.
|
|
|
|
@param Controller The controller handle to check.
|
|
|
|
@param RemainingDevicePath The remaining device path.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2008-07-23 08:29:46 +02:00
|
|
|
@retval EFI_SUCCESS The driver supports this controller.
|
2008-12-05 10:19:10 +01:00
|
|
|
@retval other This device isn't supported.
|
|
|
|
|
2007-07-12 19:31:28 +02:00
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
USBKeyboardDriverBindingSupported (
|
|
|
|
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
|
|
|
IN EFI_HANDLE Controller,
|
|
|
|
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
2008-12-05 10:19:10 +01:00
|
|
|
EFI_USB_IO_PROTOCOL *UsbIo;
|
2007-07-12 19:31:28 +02:00
|
|
|
|
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
// Check if USB I/O Protocol is attached on the controller handle.
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
Status = gBS->OpenProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiUsbIoProtocolGuid,
|
|
|
|
(VOID **) &UsbIo,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller,
|
|
|
|
EFI_OPEN_PROTOCOL_BY_DRIVER
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
2007-07-12 19:31:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2008-12-15 08:17:47 +01:00
|
|
|
// Use the USB I/O Protocol interface to check whether Controller is
|
|
|
|
// a keyboard device that can be managed by this driver.
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
|
|
|
Status = EFI_SUCCESS;
|
|
|
|
|
|
|
|
if (!IsUSBKeyboard (UsbIo)) {
|
|
|
|
Status = EFI_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
gBS->CloseProtocol (
|
2008-12-05 10:19:10 +01:00
|
|
|
Controller,
|
|
|
|
&gEfiUsbIoProtocolGuid,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller
|
|
|
|
);
|
2007-07-12 19:31:28 +02:00
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-01-13 09:46:31 +01:00
|
|
|
Starts the keyboard device with this driver.
|
2008-12-15 08:17:47 +01:00
|
|
|
|
|
|
|
This function produces Simple Text Input Protocol and Simple Text Input Ex Protocol,
|
|
|
|
initializes the keyboard device, and submit Asynchronous Interrupt Transfer to manage
|
|
|
|
this keyboard device.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2008-07-23 08:29:46 +02:00
|
|
|
@param This The USB keyboard driver binding instance.
|
2008-12-05 10:19:10 +01:00
|
|
|
@param Controller Handle of device to bind driver to.
|
|
|
|
@param RemainingDevicePath Optional parameter use to pick a specific child
|
|
|
|
device to start.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2008-07-23 08:29:46 +02:00
|
|
|
@retval EFI_SUCCESS The controller is controlled by the usb keyboard driver.
|
2008-12-05 10:19:10 +01:00
|
|
|
@retval EFI_UNSUPPORTED No interrupt endpoint can be found.
|
2008-12-15 08:17:47 +01:00
|
|
|
@retval Other This controller cannot be started.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
USBKeyboardDriverBindingStart (
|
|
|
|
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
|
|
|
IN EFI_HANDLE Controller,
|
|
|
|
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
|
|
|
|
)
|
|
|
|
{
|
|
|
|
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;
|
2010-05-05 07:21:38 +02:00
|
|
|
EFI_TPL OldTpl;
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2010-05-05 07:21:38 +02:00
|
|
|
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
// Open USB I/O Protocol
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
|
|
|
Status = gBS->OpenProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiUsbIoProtocolGuid,
|
2007-07-17 03:48:09 +02:00
|
|
|
(VOID **) &UsbIo,
|
2007-07-12 19:31:28 +02:00
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller,
|
|
|
|
EFI_OPEN_PROTOCOL_BY_DRIVER
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
2010-05-05 07:21:38 +02:00
|
|
|
goto ErrorExit1;
|
2007-07-12 19:31:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
UsbKeyboardDevice = AllocateZeroPool (sizeof (USB_KB_DEV));
|
2008-12-05 10:19:10 +01:00
|
|
|
ASSERT (UsbKeyboardDevice != NULL);
|
|
|
|
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
|
|
|
// 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)) {
|
2008-12-05 10:19:10 +01:00
|
|
|
goto ErrorExit;
|
2007-07-12 19:31:28 +02:00
|
|
|
}
|
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
// Report that the USB keyboard is being enabled
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
REPORT_STATUS_CODE_WITH_DEVICE_PATH (
|
2007-07-12 19:31:28 +02:00
|
|
|
EFI_PROGRESS_CODE,
|
2010-01-27 05:00:58 +01:00
|
|
|
(EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_ENABLE),
|
2008-12-05 10:19:10 +01:00
|
|
|
UsbKeyboardDevice->DevicePath
|
2007-07-12 19:31:28 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
//
|
|
|
|
// This is pretty close to keyboard detection, so log progress
|
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
REPORT_STATUS_CODE_WITH_DEVICE_PATH (
|
2007-07-12 19:31:28 +02:00
|
|
|
EFI_PROGRESS_CODE,
|
2010-01-27 05:00:58 +01:00
|
|
|
(EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_PRESENCE_DETECT),
|
2008-12-05 10:19:10 +01:00
|
|
|
UsbKeyboardDevice->DevicePath
|
2007-07-12 19:31:28 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
UsbKeyboardDevice->UsbIo = UsbIo;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get interface & endpoint descriptor
|
|
|
|
//
|
|
|
|
UsbIo->UsbGetInterfaceDescriptor (
|
2008-12-05 10:19:10 +01:00
|
|
|
UsbIo,
|
|
|
|
&UsbKeyboardDevice->InterfaceDescriptor
|
|
|
|
);
|
2007-07-12 19:31:28 +02:00
|
|
|
|
|
|
|
EndpointNumber = UsbKeyboardDevice->InterfaceDescriptor.NumEndpoints;
|
|
|
|
|
2008-12-05 10:19:10 +01:00
|
|
|
//
|
2009-01-13 09:46:31 +01:00
|
|
|
// Traverse endpoints to find interrupt endpoint
|
2008-12-05 10:19:10 +01:00
|
|
|
//
|
|
|
|
Found = FALSE;
|
2007-07-12 19:31:28 +02:00
|
|
|
for (Index = 0; Index < EndpointNumber; Index++) {
|
|
|
|
|
|
|
|
UsbIo->UsbGetEndpointDescriptor (
|
2008-12-05 10:19:10 +01:00
|
|
|
UsbIo,
|
|
|
|
Index,
|
|
|
|
&EndpointDescriptor
|
|
|
|
);
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2009-01-13 09:46:31 +01:00
|
|
|
if ((EndpointDescriptor.Attributes & (BIT0 | BIT1)) == USB_ENDPOINT_INTERRUPT) {
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
|
|
|
// We only care interrupt endpoint here
|
|
|
|
//
|
2007-08-27 05:33:51 +02:00
|
|
|
CopyMem(&UsbKeyboardDevice->IntEndpointDescriptor, &EndpointDescriptor, sizeof(EndpointDescriptor));
|
2007-07-12 19:31:28 +02:00
|
|
|
Found = TRUE;
|
2008-12-05 10:19:10 +01:00
|
|
|
break;
|
2007-07-12 19:31:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Found) {
|
|
|
|
//
|
|
|
|
// No interrupt endpoint found, then return unsupported.
|
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
Status = EFI_UNSUPPORTED;
|
|
|
|
goto ErrorExit;
|
2007-07-12 19:31:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
UsbKeyboardDevice->Signature = USB_KB_DEV_SIGNATURE;
|
|
|
|
UsbKeyboardDevice->SimpleInput.Reset = USBKeyboardReset;
|
|
|
|
UsbKeyboardDevice->SimpleInput.ReadKeyStroke = USBKeyboardReadKeyStroke;
|
2007-10-19 04:35:29 +02:00
|
|
|
|
|
|
|
UsbKeyboardDevice->SimpleInputEx.Reset = USBKeyboardResetEx;
|
|
|
|
UsbKeyboardDevice->SimpleInputEx.ReadKeyStrokeEx = USBKeyboardReadKeyStrokeEx;
|
|
|
|
UsbKeyboardDevice->SimpleInputEx.SetState = USBKeyboardSetState;
|
|
|
|
UsbKeyboardDevice->SimpleInputEx.RegisterKeyNotify = USBKeyboardRegisterKeyNotify;
|
2009-04-10 06:28:13 +02:00
|
|
|
UsbKeyboardDevice->SimpleInputEx.UnregisterKeyNotify = USBKeyboardUnregisterKeyNotify;
|
2007-10-19 04:35:29 +02:00
|
|
|
|
|
|
|
InitializeListHead (&UsbKeyboardDevice->NotifyList);
|
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
Status = gBS->CreateEvent (
|
|
|
|
EVT_TIMER | EVT_NOTIFY_SIGNAL,
|
|
|
|
TPL_NOTIFY,
|
|
|
|
USBKeyboardTimerHandler,
|
|
|
|
UsbKeyboardDevice,
|
|
|
|
&UsbKeyboardDevice->TimerEvent
|
|
|
|
);
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
Status = gBS->SetTimer (UsbKeyboardDevice->TimerEvent, TimerPeriodic, KEYBOARD_TIMER_INTERVAL);
|
|
|
|
}
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto ErrorExit;
|
|
|
|
}
|
|
|
|
|
2007-10-19 04:35:29 +02:00
|
|
|
Status = gBS->CreateEvent (
|
|
|
|
EVT_NOTIFY_WAIT,
|
|
|
|
TPL_NOTIFY,
|
|
|
|
USBKeyboardWaitForKey,
|
|
|
|
UsbKeyboardDevice,
|
|
|
|
&(UsbKeyboardDevice->SimpleInputEx.WaitForKeyEx)
|
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto ErrorExit;
|
|
|
|
}
|
|
|
|
|
2007-07-12 19:31:28 +02:00
|
|
|
Status = gBS->CreateEvent (
|
|
|
|
EVT_NOTIFY_WAIT,
|
|
|
|
TPL_NOTIFY,
|
|
|
|
USBKeyboardWaitForKey,
|
|
|
|
UsbKeyboardDevice,
|
|
|
|
&(UsbKeyboardDevice->SimpleInput.WaitForKey)
|
|
|
|
);
|
2008-12-05 10:19:10 +01:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto ErrorExit;
|
2007-07-12 19:31:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
// Install Simple Text Input Protocol and Simple Text Input Ex Protocol
|
|
|
|
// for the USB keyboard device.
|
|
|
|
// USB keyboard is a hot plug device, and expected to work immediately
|
2009-02-23 03:51:45 +01:00
|
|
|
// when plugging into system, other conventional console devices could
|
|
|
|
// distinguish it by its device path.
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
|
|
|
Status = gBS->InstallMultipleProtocolInterfaces (
|
|
|
|
&Controller,
|
|
|
|
&gEfiSimpleTextInProtocolGuid,
|
|
|
|
&UsbKeyboardDevice->SimpleInput,
|
2007-10-19 04:35:29 +02:00
|
|
|
&gEfiSimpleTextInputExProtocolGuid,
|
|
|
|
&UsbKeyboardDevice->SimpleInputEx,
|
2007-07-12 19:31:28 +02:00
|
|
|
NULL
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
2008-12-05 10:19:10 +01:00
|
|
|
goto ErrorExit;
|
2007-07-12 19:31:28 +02:00
|
|
|
}
|
|
|
|
|
2009-04-10 06:28:13 +02:00
|
|
|
UsbKeyboardDevice->ControllerHandle = Controller;
|
|
|
|
Status = InitKeyboardLayout (UsbKeyboardDevice);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
gBS->UninstallMultipleProtocolInterfaces (
|
|
|
|
Controller,
|
|
|
|
&gEfiSimpleTextInProtocolGuid,
|
|
|
|
&UsbKeyboardDevice->SimpleInput,
|
|
|
|
&gEfiSimpleTextInputExProtocolGuid,
|
|
|
|
&UsbKeyboardDevice->SimpleInputEx,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
goto ErrorExit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
// Reset USB Keyboard Device exhaustively.
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
2010-04-19 07:34:25 +02:00
|
|
|
Status = UsbKeyboardDevice->SimpleInputEx.Reset (
|
|
|
|
&UsbKeyboardDevice->SimpleInputEx,
|
2007-07-12 19:31:28 +02:00
|
|
|
TRUE
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
gBS->UninstallMultipleProtocolInterfaces (
|
2007-10-19 04:35:29 +02:00
|
|
|
Controller,
|
|
|
|
&gEfiSimpleTextInProtocolGuid,
|
|
|
|
&UsbKeyboardDevice->SimpleInput,
|
|
|
|
&gEfiSimpleTextInputExProtocolGuid,
|
|
|
|
&UsbKeyboardDevice->SimpleInputEx,
|
|
|
|
NULL
|
|
|
|
);
|
2008-12-05 10:19:10 +01:00
|
|
|
goto ErrorExit;
|
2007-07-12 19:31:28 +02:00
|
|
|
}
|
2008-12-05 10:19:10 +01:00
|
|
|
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
// Submit Asynchronous Interrupt Transfer to manage this device.
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
|
|
|
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 (
|
2007-10-19 04:35:29 +02:00
|
|
|
Controller,
|
|
|
|
&gEfiSimpleTextInProtocolGuid,
|
|
|
|
&UsbKeyboardDevice->SimpleInput,
|
|
|
|
&gEfiSimpleTextInputExProtocolGuid,
|
|
|
|
&UsbKeyboardDevice->SimpleInputEx,
|
|
|
|
NULL
|
|
|
|
);
|
2008-12-05 10:19:10 +01:00
|
|
|
goto ErrorExit;
|
2007-07-12 19:31:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
UsbKeyboardDevice->ControllerNameTable = NULL;
|
2007-09-30 04:47:05 +02:00
|
|
|
AddUnicodeString2 (
|
2007-07-12 19:31:28 +02:00
|
|
|
"eng",
|
|
|
|
gUsbKeyboardComponentName.SupportedLanguages,
|
|
|
|
&UsbKeyboardDevice->ControllerNameTable,
|
2007-09-30 04:47:05 +02:00
|
|
|
L"Generic Usb Keyboard",
|
|
|
|
TRUE
|
2007-07-12 19:31:28 +02:00
|
|
|
);
|
2007-09-30 04:47:05 +02:00
|
|
|
AddUnicodeString2 (
|
|
|
|
"en",
|
|
|
|
gUsbKeyboardComponentName2.SupportedLanguages,
|
|
|
|
&UsbKeyboardDevice->ControllerNameTable,
|
|
|
|
L"Generic Usb Keyboard",
|
|
|
|
FALSE
|
|
|
|
);
|
|
|
|
|
2010-05-05 07:21:38 +02:00
|
|
|
gBS->RestoreTPL (OldTpl);
|
2007-07-12 19:31:28 +02:00
|
|
|
return EFI_SUCCESS;
|
2007-10-19 04:35:29 +02:00
|
|
|
|
2008-12-05 10:19:10 +01:00
|
|
|
//
|
|
|
|
// Error handler
|
|
|
|
//
|
2007-10-19 04:35:29 +02:00
|
|
|
ErrorExit:
|
|
|
|
if (UsbKeyboardDevice != NULL) {
|
2011-04-19 08:52:20 +02:00
|
|
|
if (UsbKeyboardDevice->TimerEvent != NULL) {
|
|
|
|
gBS->CloseEvent (UsbKeyboardDevice->TimerEvent);
|
|
|
|
}
|
2007-10-19 04:35:29 +02:00
|
|
|
if (UsbKeyboardDevice->SimpleInput.WaitForKey != NULL) {
|
|
|
|
gBS->CloseEvent (UsbKeyboardDevice->SimpleInput.WaitForKey);
|
|
|
|
}
|
|
|
|
if (UsbKeyboardDevice->SimpleInputEx.WaitForKeyEx != NULL) {
|
|
|
|
gBS->CloseEvent (UsbKeyboardDevice->SimpleInputEx.WaitForKeyEx);
|
|
|
|
}
|
2009-08-24 08:24:24 +02:00
|
|
|
if (UsbKeyboardDevice->KeyboardLayoutEvent != NULL) {
|
2010-02-11 03:47:10 +01:00
|
|
|
ReleaseKeyboardLayoutResources (UsbKeyboardDevice);
|
2009-08-24 08:24:24 +02:00
|
|
|
gBS->CloseEvent (UsbKeyboardDevice->KeyboardLayoutEvent);
|
|
|
|
}
|
2009-01-13 09:46:31 +01:00
|
|
|
FreePool (UsbKeyboardDevice);
|
2007-10-19 04:35:29 +02:00
|
|
|
UsbKeyboardDevice = NULL;
|
|
|
|
}
|
|
|
|
gBS->CloseProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiUsbIoProtocolGuid,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller
|
|
|
|
);
|
2010-05-05 07:21:38 +02:00
|
|
|
|
|
|
|
ErrorExit1:
|
|
|
|
gBS->RestoreTPL (OldTpl);
|
|
|
|
|
2007-10-19 04:35:29 +02:00
|
|
|
return Status;
|
|
|
|
|
2007-07-12 19:31:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-12-15 08:17:47 +01:00
|
|
|
Stop the USB keyboard device handled by this driver.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2008-07-23 08:29:46 +02:00
|
|
|
@param This The USB keyboard driver binding protocol.
|
|
|
|
@param Controller The controller to release.
|
|
|
|
@param NumberOfChildren The number of handles in ChildHandleBuffer.
|
|
|
|
@param ChildHandleBuffer The array of child handle.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
@retval EFI_SUCCESS The device was stopped.
|
2008-12-05 10:19:10 +01:00
|
|
|
@retval EFI_UNSUPPORTED Simple Text In Protocol or Simple Text In Ex Protocol
|
|
|
|
is not installed on Controller.
|
2008-12-15 08:17:47 +01:00
|
|
|
@retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
|
|
|
|
@retval Others Fail to uninstall protocols attached on the device.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
USBKeyboardDriverBindingStop (
|
|
|
|
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
|
|
|
IN EFI_HANDLE Controller,
|
|
|
|
IN UINTN NumberOfChildren,
|
|
|
|
IN EFI_HANDLE *ChildHandleBuffer
|
|
|
|
)
|
|
|
|
{
|
2008-12-05 10:19:10 +01:00
|
|
|
EFI_STATUS Status;
|
2007-07-12 19:31:28 +02:00
|
|
|
EFI_SIMPLE_TEXT_INPUT_PROTOCOL *SimpleInput;
|
2008-12-05 10:19:10 +01:00
|
|
|
USB_KB_DEV *UsbKeyboardDevice;
|
2007-07-12 19:31:28 +02:00
|
|
|
|
|
|
|
Status = gBS->OpenProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiSimpleTextInProtocolGuid,
|
2007-07-17 03:48:09 +02:00
|
|
|
(VOID **) &SimpleInput,
|
2007-07-12 19:31:28 +02:00
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller,
|
2007-12-26 10:02:05 +01:00
|
|
|
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
2007-07-12 19:31:28 +02:00
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return EFI_UNSUPPORTED;
|
|
|
|
}
|
2008-12-05 10:19:10 +01:00
|
|
|
|
2007-10-19 04:35:29 +02:00
|
|
|
Status = gBS->OpenProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiSimpleTextInputExProtocolGuid,
|
|
|
|
NULL,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller,
|
|
|
|
EFI_OPEN_PROTOCOL_TEST_PROTOCOL
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return EFI_UNSUPPORTED;
|
|
|
|
}
|
2008-12-15 08:17:47 +01:00
|
|
|
|
2007-07-12 19:31:28 +02:00
|
|
|
UsbKeyboardDevice = USB_KB_DEV_FROM_THIS (SimpleInput);
|
|
|
|
|
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
// The key data input from this device will be disabled.
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
REPORT_STATUS_CODE_WITH_DEVICE_PATH (
|
2007-07-12 19:31:28 +02:00
|
|
|
EFI_PROGRESS_CODE,
|
2010-01-27 05:00:58 +01:00
|
|
|
(EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_DISABLE),
|
2008-12-05 10:19:10 +01:00
|
|
|
UsbKeyboardDevice->DevicePath
|
2007-07-12 19:31:28 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
// Delete the Asynchronous Interrupt Transfer from this device
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
|
|
|
UsbKeyboardDevice->UsbIo->UsbAsyncInterruptTransfer (
|
|
|
|
UsbKeyboardDevice->UsbIo,
|
|
|
|
UsbKeyboardDevice->IntEndpointDescriptor.EndpointAddress,
|
|
|
|
FALSE,
|
|
|
|
UsbKeyboardDevice->IntEndpointDescriptor.Interval,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
|
|
|
|
gBS->CloseProtocol (
|
2008-12-05 10:19:10 +01:00
|
|
|
Controller,
|
|
|
|
&gEfiUsbIoProtocolGuid,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller
|
|
|
|
);
|
2007-07-12 19:31:28 +02:00
|
|
|
|
|
|
|
Status = gBS->UninstallMultipleProtocolInterfaces (
|
|
|
|
Controller,
|
|
|
|
&gEfiSimpleTextInProtocolGuid,
|
|
|
|
&UsbKeyboardDevice->SimpleInput,
|
2007-10-19 04:35:29 +02:00
|
|
|
&gEfiSimpleTextInputExProtocolGuid,
|
|
|
|
&UsbKeyboardDevice->SimpleInputEx,
|
2007-07-12 19:31:28 +02:00
|
|
|
NULL
|
|
|
|
);
|
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
// Free all resources.
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
2011-04-19 08:52:20 +02:00
|
|
|
gBS->CloseEvent (UsbKeyboardDevice->TimerEvent);
|
2007-07-12 19:31:28 +02:00
|
|
|
gBS->CloseEvent (UsbKeyboardDevice->RepeatTimer);
|
|
|
|
gBS->CloseEvent (UsbKeyboardDevice->DelayedRecoveryEvent);
|
2011-04-19 08:52:20 +02:00
|
|
|
gBS->CloseEvent (UsbKeyboardDevice->SimpleInput.WaitForKey);
|
|
|
|
gBS->CloseEvent (UsbKeyboardDevice->SimpleInputEx.WaitForKeyEx);
|
|
|
|
KbdFreeNotifyList (&UsbKeyboardDevice->NotifyList);
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2008-06-23 11:41:33 +02:00
|
|
|
ReleaseKeyboardLayoutResources (UsbKeyboardDevice);
|
|
|
|
gBS->CloseEvent (UsbKeyboardDevice->KeyboardLayoutEvent);
|
|
|
|
|
2007-07-12 19:31:28 +02:00
|
|
|
if (UsbKeyboardDevice->ControllerNameTable != NULL) {
|
|
|
|
FreeUnicodeStringTable (UsbKeyboardDevice->ControllerNameTable);
|
|
|
|
}
|
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
DestroyQueue (&UsbKeyboardDevice->UsbKeyQueue);
|
|
|
|
DestroyQueue (&UsbKeyboardDevice->EfiKeyQueue);
|
|
|
|
|
2009-01-13 09:46:31 +01:00
|
|
|
FreePool (UsbKeyboardDevice);
|
2007-07-12 19:31:28 +02:00
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2008-07-23 08:29:46 +02:00
|
|
|
/**
|
2008-12-15 08:17:47 +01:00
|
|
|
Internal function to read the next keystroke from the keyboard buffer.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
@param UsbKeyboardDevice USB keyboard's private structure.
|
|
|
|
@param KeyData A pointer to buffer to hold the keystroke
|
|
|
|
data for the key that was pressed.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
@retval EFI_SUCCESS The keystroke information was returned.
|
|
|
|
@retval EFI_NOT_READY There was no keystroke data availiable.
|
|
|
|
@retval EFI_DEVICE_ERROR The keystroke information was not returned due to
|
2008-07-23 08:29:46 +02:00
|
|
|
hardware errors.
|
2008-12-15 08:17:47 +01:00
|
|
|
@retval EFI_INVALID_PARAMETER KeyData is NULL.
|
|
|
|
@retval Others Fail to translate keycode into EFI_INPUT_KEY
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
**/
|
2007-10-19 04:35:29 +02:00
|
|
|
EFI_STATUS
|
|
|
|
USBKeyboardReadKeyStrokeWorker (
|
2008-12-15 08:17:47 +01:00
|
|
|
IN OUT USB_KB_DEV *UsbKeyboardDevice,
|
|
|
|
OUT EFI_KEY_DATA *KeyData
|
2007-10-19 04:35:29 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
if (KeyData == NULL) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
if (IsQueueEmpty (&UsbKeyboardDevice->EfiKeyQueue)) {
|
|
|
|
return EFI_NOT_READY;
|
2007-10-19 04:35:29 +02:00
|
|
|
}
|
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
Dequeue (&UsbKeyboardDevice->EfiKeyQueue, KeyData, sizeof (*KeyData));
|
2007-10-19 04:35:29 +02:00
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
/**
|
2008-12-26 10:18:12 +01:00
|
|
|
Reset the input device and optionally run diagnostics
|
2008-12-05 10:19:10 +01:00
|
|
|
|
|
|
|
There are 2 types of reset for USB keyboard.
|
|
|
|
For non-exhaustive reset, only keyboard buffer is cleared.
|
|
|
|
For exhaustive reset, in addition to clearance of keyboard buffer, the hardware status
|
|
|
|
is also re-initialized.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
@param This Protocol instance pointer.
|
|
|
|
@param ExtendedVerification Driver may perform diagnostics on reset.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
@retval EFI_SUCCESS The device was reset.
|
|
|
|
@retval EFI_DEVICE_ERROR The device is not functioning properly and could not be reset.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
**/
|
2007-07-12 19:31:28 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
USBKeyboardReset (
|
|
|
|
IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
|
2008-12-05 10:19:10 +01:00
|
|
|
IN BOOLEAN ExtendedVerification
|
2007-07-12 19:31:28 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
USB_KB_DEV *UsbKeyboardDevice;
|
|
|
|
|
|
|
|
UsbKeyboardDevice = USB_KB_DEV_FROM_THIS (This);
|
|
|
|
|
2008-12-05 10:19:10 +01:00
|
|
|
REPORT_STATUS_CODE_WITH_DEVICE_PATH (
|
2007-07-12 19:31:28 +02:00
|
|
|
EFI_PROGRESS_CODE,
|
2010-01-27 05:00:58 +01:00
|
|
|
(EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_RESET),
|
2008-12-05 10:19:10 +01:00
|
|
|
UsbKeyboardDevice->DevicePath
|
2007-07-12 19:31:28 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
// Non-exhaustive reset:
|
2007-07-12 19:31:28 +02:00
|
|
|
// only reset private data structures.
|
|
|
|
//
|
|
|
|
if (!ExtendedVerification) {
|
2008-12-05 10:19:10 +01:00
|
|
|
REPORT_STATUS_CODE_WITH_DEVICE_PATH (
|
2007-07-12 19:31:28 +02:00
|
|
|
EFI_PROGRESS_CODE,
|
2010-01-27 05:00:58 +01:00
|
|
|
(EFI_PERIPHERAL_KEYBOARD | EFI_P_KEYBOARD_PC_CLEAR_BUFFER),
|
2008-12-05 10:19:10 +01:00
|
|
|
UsbKeyboardDevice->DevicePath
|
2007-07-12 19:31:28 +02:00
|
|
|
);
|
2008-12-05 10:19:10 +01:00
|
|
|
//
|
|
|
|
// Clear the key buffer of this USB keyboard
|
|
|
|
//
|
2011-04-19 08:52:20 +02:00
|
|
|
InitQueue (&UsbKeyboardDevice->UsbKeyQueue, sizeof (USB_KEY));
|
|
|
|
InitQueue (&UsbKeyboardDevice->EfiKeyQueue, sizeof (EFI_KEY_DATA));
|
2008-12-05 10:19:10 +01:00
|
|
|
|
2007-07-12 19:31:28 +02:00
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Exhaustive reset
|
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
Status = InitUSBKeyboard (UsbKeyboardDevice);
|
2007-07-12 19:31:28 +02:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return EFI_DEVICE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-12-15 08:17:47 +01:00
|
|
|
Reads the next keystroke from the input device.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2008-07-23 08:29:46 +02:00
|
|
|
@param This The EFI_SIMPLE_TEXT_INPUT_PROTOCOL instance.
|
|
|
|
@param Key A pointer to a buffer that is filled in with the keystroke
|
|
|
|
information for the key that was pressed.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
@retval EFI_SUCCESS The keystroke information was returned.
|
|
|
|
@retval EFI_NOT_READY There was no keystroke data availiable.
|
2008-12-26 10:18:12 +01:00
|
|
|
@retval EFI_DEVICE_ERROR The keystroke information was not returned due to
|
2008-12-15 08:17:47 +01:00
|
|
|
hardware errors.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
USBKeyboardReadKeyStroke (
|
|
|
|
IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
|
2008-12-05 10:19:10 +01:00
|
|
|
OUT EFI_INPUT_KEY *Key
|
2007-07-12 19:31:28 +02:00
|
|
|
)
|
|
|
|
{
|
2007-10-19 04:35:29 +02:00
|
|
|
USB_KB_DEV *UsbKeyboardDevice;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_KEY_DATA KeyData;
|
2007-07-12 19:31:28 +02:00
|
|
|
|
|
|
|
UsbKeyboardDevice = USB_KB_DEV_FROM_THIS (This);
|
|
|
|
|
2007-10-19 04:35:29 +02:00
|
|
|
Status = USBKeyboardReadKeyStrokeWorker (UsbKeyboardDevice, &KeyData);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
2007-07-12 19:31:28 +02:00
|
|
|
}
|
|
|
|
|
2007-10-19 04:35:29 +02:00
|
|
|
CopyMem (Key, &KeyData.Key, sizeof (EFI_INPUT_KEY));
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2007-10-19 04:35:29 +02:00
|
|
|
return EFI_SUCCESS;
|
2007-07-12 19:31:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-12-15 08:17:47 +01:00
|
|
|
Event notification function registered for EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx
|
|
|
|
and EFI_SIMPLE_TEXT_INPUT_PROTOCOL.WaitForKey.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2008-07-23 08:29:46 +02:00
|
|
|
@param Event Event to be signaled when a key is pressed.
|
|
|
|
@param Context Points to USB_KB_DEV instance.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
USBKeyboardWaitForKey (
|
|
|
|
IN EFI_EVENT Event,
|
|
|
|
IN VOID *Context
|
|
|
|
)
|
|
|
|
{
|
|
|
|
USB_KB_DEV *UsbKeyboardDevice;
|
|
|
|
|
|
|
|
UsbKeyboardDevice = (USB_KB_DEV *) Context;
|
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
if (!IsQueueEmpty (&UsbKeyboardDevice->EfiKeyQueue)) {
|
|
|
|
//
|
|
|
|
// If there is pending key, signal the event.
|
|
|
|
//
|
|
|
|
gBS->SignalEvent (Event);
|
2007-07-12 19:31:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-04-19 08:52:20 +02:00
|
|
|
Timer handler to convert the key from USB.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
@param Event Indicates the event that invoke this function.
|
|
|
|
@param Context Indicates the calling context.
|
2007-07-12 19:31:28 +02:00
|
|
|
**/
|
2011-04-19 08:52:20 +02:00
|
|
|
VOID
|
2008-07-23 08:29:46 +02:00
|
|
|
EFIAPI
|
2011-04-19 08:52:20 +02:00
|
|
|
USBKeyboardTimerHandler (
|
|
|
|
IN EFI_EVENT Event,
|
|
|
|
IN VOID *Context
|
2007-07-12 19:31:28 +02:00
|
|
|
)
|
|
|
|
{
|
2011-04-19 08:52:20 +02:00
|
|
|
EFI_STATUS Status;
|
|
|
|
USB_KB_DEV *UsbKeyboardDevice;
|
|
|
|
UINT8 KeyCode;
|
|
|
|
EFI_KEY_DATA KeyData;
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
UsbKeyboardDevice = (USB_KB_DEV *) Context;
|
|
|
|
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
2008-12-15 08:17:47 +01:00
|
|
|
// Fetch raw data from the USB keyboard buffer,
|
|
|
|
// and translate it into USB keycode.
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
2008-12-15 08:17:47 +01:00
|
|
|
Status = USBParseKey (UsbKeyboardDevice, &KeyCode);
|
2007-07-12 19:31:28 +02:00
|
|
|
if (EFI_ERROR (Status)) {
|
2011-04-19 08:52:20 +02:00
|
|
|
return ;
|
2007-07-12 19:31:28 +02:00
|
|
|
}
|
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
//
|
|
|
|
// Translate saved USB keycode into EFI_INPUT_KEY
|
|
|
|
//
|
|
|
|
Status = UsbKeyCodeToEfiInputKey (UsbKeyboardDevice, KeyCode, &KeyData);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Insert to the EFI Key queue
|
|
|
|
//
|
|
|
|
Enqueue (&UsbKeyboardDevice->EfiKeyQueue, &KeyData, sizeof (KeyData));
|
2007-07-12 19:31:28 +02:00
|
|
|
}
|
|
|
|
|
2008-07-23 08:29:46 +02:00
|
|
|
/**
|
|
|
|
Free keyboard notify list.
|
2007-10-19 04:35:29 +02:00
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
@param NotifyList The keyboard notify list to free.
|
2007-10-19 04:35:29 +02:00
|
|
|
|
2008-07-23 08:29:46 +02:00
|
|
|
@retval EFI_SUCCESS Free the notify list successfully.
|
2008-12-15 08:17:47 +01:00
|
|
|
@retval EFI_INVALID_PARAMETER NotifyList is NULL.
|
2007-10-19 04:35:29 +02:00
|
|
|
|
2008-07-23 08:29:46 +02:00
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
KbdFreeNotifyList (
|
2008-12-15 08:17:47 +01:00
|
|
|
IN OUT LIST_ENTRY *NotifyList
|
2008-07-23 08:29:46 +02:00
|
|
|
)
|
2007-10-19 04:35:29 +02:00
|
|
|
{
|
|
|
|
KEYBOARD_CONSOLE_IN_EX_NOTIFY *NotifyNode;
|
2008-12-15 08:17:47 +01:00
|
|
|
LIST_ENTRY *Link;
|
2007-10-19 04:35:29 +02:00
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
if (NotifyList == NULL) {
|
2007-10-19 04:35:29 +02:00
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
2008-12-15 08:17:47 +01:00
|
|
|
while (!IsListEmpty (NotifyList)) {
|
|
|
|
Link = GetFirstNode (NotifyList);
|
|
|
|
NotifyNode = CR (Link, KEYBOARD_CONSOLE_IN_EX_NOTIFY, NotifyEntry, USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE);
|
|
|
|
RemoveEntryList (Link);
|
2009-01-13 09:46:31 +01:00
|
|
|
FreePool (NotifyNode);
|
2007-10-19 04:35:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-07-23 08:29:46 +02:00
|
|
|
/**
|
2008-12-15 08:17:47 +01:00
|
|
|
Check whether the pressed key matches a registered key or not.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
@param RegsiteredData A pointer to keystroke data for the key that was registered.
|
|
|
|
@param InputData A pointer to keystroke data for the key that was pressed.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
@retval TRUE Key pressed matches a registered key.
|
2008-12-26 10:18:12 +01:00
|
|
|
@retval FLASE Key pressed does not matches a registered key.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
**/
|
2007-10-19 04:35:29 +02:00
|
|
|
BOOLEAN
|
|
|
|
IsKeyRegistered (
|
|
|
|
IN EFI_KEY_DATA *RegsiteredData,
|
|
|
|
IN EFI_KEY_DATA *InputData
|
|
|
|
)
|
|
|
|
{
|
|
|
|
ASSERT (RegsiteredData != NULL && InputData != NULL);
|
|
|
|
|
|
|
|
if ((RegsiteredData->Key.ScanCode != InputData->Key.ScanCode) ||
|
|
|
|
(RegsiteredData->Key.UnicodeChar != InputData->Key.UnicodeChar)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Assume KeyShiftState/KeyToggleState = 0 in Registered key data means these state could be ignored.
|
|
|
|
//
|
|
|
|
if (RegsiteredData->KeyState.KeyShiftState != 0 &&
|
|
|
|
RegsiteredData->KeyState.KeyShiftState != InputData->KeyState.KeyShiftState) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (RegsiteredData->KeyState.KeyToggleState != 0 &&
|
|
|
|
RegsiteredData->KeyState.KeyToggleState != InputData->KeyState.KeyToggleState) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Simple Text Input Ex protocol functions
|
|
|
|
//
|
2008-07-23 08:29:46 +02:00
|
|
|
/**
|
2008-12-15 08:17:47 +01:00
|
|
|
Resets the input device hardware.
|
|
|
|
|
|
|
|
The Reset() function resets the input device hardware. As part
|
|
|
|
of initialization process, the firmware/device will make a quick
|
|
|
|
but reasonable attempt to verify that the device is functioning.
|
|
|
|
If the ExtendedVerification flag is TRUE the firmware may take
|
|
|
|
an extended amount of time to verify the device is operating on
|
|
|
|
reset. Otherwise the reset operation is to occur as quickly as
|
|
|
|
possible. The hardware verification process is not defined by
|
|
|
|
this specification and is left up to the platform firmware or
|
|
|
|
driver to implement.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
@param This A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
@param ExtendedVerification Indicates that the driver may perform a more exhaustive
|
|
|
|
verification operation of the device during reset.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The device was reset.
|
|
|
|
@retval EFI_DEVICE_ERROR The device is not functioning correctly and could not be reset.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
**/
|
2007-10-19 04:35:29 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
USBKeyboardResetEx (
|
|
|
|
IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
|
|
|
|
IN BOOLEAN ExtendedVerification
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
USB_KB_DEV *UsbKeyboardDevice;
|
|
|
|
|
|
|
|
UsbKeyboardDevice = TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS (This);
|
|
|
|
|
|
|
|
Status = UsbKeyboardDevice->SimpleInput.Reset (&UsbKeyboardDevice->SimpleInput, ExtendedVerification);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return EFI_DEVICE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-07-23 08:29:46 +02:00
|
|
|
/**
|
2008-12-15 08:17:47 +01:00
|
|
|
Reads the next keystroke from the input device.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
@param This Protocol instance pointer.
|
|
|
|
@param KeyData A pointer to a buffer that is filled in with the keystroke
|
|
|
|
state data for the key that was pressed.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
@retval EFI_SUCCESS The keystroke information was returned.
|
|
|
|
@retval EFI_NOT_READY There was no keystroke data available.
|
|
|
|
@retval EFI_DEVICE_ERROR The keystroke information was not returned due to
|
|
|
|
hardware errors.
|
|
|
|
@retval EFI_INVALID_PARAMETER KeyData is NULL.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
**/
|
2007-10-19 04:35:29 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
USBKeyboardReadKeyStrokeEx (
|
|
|
|
IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
|
|
|
|
OUT EFI_KEY_DATA *KeyData
|
|
|
|
)
|
|
|
|
{
|
|
|
|
USB_KB_DEV *UsbKeyboardDevice;
|
|
|
|
|
|
|
|
if (KeyData == NULL) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
UsbKeyboardDevice = TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS (This);
|
|
|
|
|
|
|
|
return USBKeyboardReadKeyStrokeWorker (UsbKeyboardDevice, KeyData);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-07-23 08:29:46 +02:00
|
|
|
/**
|
|
|
|
Set certain state for the input device.
|
|
|
|
|
|
|
|
@param This Protocol instance pointer.
|
|
|
|
@param KeyToggleState A pointer to the EFI_KEY_TOGGLE_STATE to set the
|
|
|
|
state for the input device.
|
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
@retval EFI_SUCCESS The device state was set appropriately.
|
|
|
|
@retval EFI_DEVICE_ERROR The device is not functioning correctly and could
|
|
|
|
not have the setting adjusted.
|
|
|
|
@retval EFI_UNSUPPORTED The device does not support the ability to have its state set.
|
2008-07-23 08:29:46 +02:00
|
|
|
@retval EFI_INVALID_PARAMETER KeyToggleState is NULL.
|
|
|
|
|
|
|
|
**/
|
2007-10-19 04:35:29 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
USBKeyboardSetState (
|
|
|
|
IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
|
|
|
|
IN EFI_KEY_TOGGLE_STATE *KeyToggleState
|
|
|
|
)
|
|
|
|
{
|
|
|
|
USB_KB_DEV *UsbKeyboardDevice;
|
|
|
|
|
|
|
|
if (KeyToggleState == NULL) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
UsbKeyboardDevice = TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS (This);
|
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
if ((*KeyToggleState & EFI_TOGGLE_STATE_VALID) != EFI_TOGGLE_STATE_VALID) {
|
2007-10-19 04:35:29 +02:00
|
|
|
return EFI_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Update the status light
|
|
|
|
//
|
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
UsbKeyboardDevice->ScrollOn = FALSE;
|
|
|
|
UsbKeyboardDevice->NumLockOn = FALSE;
|
|
|
|
UsbKeyboardDevice->CapsOn = FALSE;
|
2007-10-19 04:35:29 +02:00
|
|
|
|
|
|
|
if ((*KeyToggleState & EFI_SCROLL_LOCK_ACTIVE) == EFI_SCROLL_LOCK_ACTIVE) {
|
2008-12-15 08:17:47 +01:00
|
|
|
UsbKeyboardDevice->ScrollOn = TRUE;
|
2007-10-19 04:35:29 +02:00
|
|
|
}
|
|
|
|
if ((*KeyToggleState & EFI_NUM_LOCK_ACTIVE) == EFI_NUM_LOCK_ACTIVE) {
|
2008-12-15 08:17:47 +01:00
|
|
|
UsbKeyboardDevice->NumLockOn = TRUE;
|
2007-10-19 04:35:29 +02:00
|
|
|
}
|
|
|
|
if ((*KeyToggleState & EFI_CAPS_LOCK_ACTIVE) == EFI_CAPS_LOCK_ACTIVE) {
|
2008-12-15 08:17:47 +01:00
|
|
|
UsbKeyboardDevice->CapsOn = TRUE;
|
2007-10-19 04:35:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SetKeyLED (UsbKeyboardDevice);
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-07-23 08:29:46 +02:00
|
|
|
/**
|
|
|
|
Register a notification function for a particular keystroke for the input device.
|
|
|
|
|
|
|
|
@param This Protocol instance pointer.
|
|
|
|
@param KeyData A pointer to a buffer that is filled in with the keystroke
|
|
|
|
information data for the key that was pressed.
|
|
|
|
@param KeyNotificationFunction Points to the function to be called when the key
|
|
|
|
sequence is typed specified by KeyData.
|
|
|
|
@param NotifyHandle Points to the unique handle assigned to the registered notification.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The notification function was registered successfully.
|
2008-12-26 10:18:12 +01:00
|
|
|
@retval EFI_OUT_OF_RESOURCES Unable to allocate resources for necessary data structures.
|
2008-12-15 08:17:47 +01:00
|
|
|
@retval EFI_INVALID_PARAMETER KeyData or NotifyHandle or KeyNotificationFunction is NULL.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
**/
|
2007-10-19 04:35:29 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
USBKeyboardRegisterKeyNotify (
|
|
|
|
IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
|
|
|
|
IN EFI_KEY_DATA *KeyData,
|
|
|
|
IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction,
|
2008-07-23 08:29:46 +02:00
|
|
|
OUT EFI_HANDLE *NotifyHandle
|
2007-10-19 04:35:29 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
USB_KB_DEV *UsbKeyboardDevice;
|
|
|
|
KEYBOARD_CONSOLE_IN_EX_NOTIFY *NewNotify;
|
|
|
|
LIST_ENTRY *Link;
|
2008-12-26 10:18:12 +01:00
|
|
|
LIST_ENTRY *NotifyList;
|
2007-10-19 04:35:29 +02:00
|
|
|
KEYBOARD_CONSOLE_IN_EX_NOTIFY *CurrentNotify;
|
|
|
|
|
|
|
|
if (KeyData == NULL || NotifyHandle == NULL || KeyNotificationFunction == NULL) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
UsbKeyboardDevice = TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS (This);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Return EFI_SUCCESS if the (KeyData, NotificationFunction) is already registered.
|
|
|
|
//
|
2008-12-26 10:18:12 +01:00
|
|
|
NotifyList = &UsbKeyboardDevice->NotifyList;
|
|
|
|
|
|
|
|
for (Link = GetFirstNode (NotifyList);
|
|
|
|
!IsNull (NotifyList, Link);
|
|
|
|
Link = GetNextNode (NotifyList, Link)) {
|
2007-10-19 04:35:29 +02:00
|
|
|
CurrentNotify = CR (
|
|
|
|
Link,
|
|
|
|
KEYBOARD_CONSOLE_IN_EX_NOTIFY,
|
|
|
|
NotifyEntry,
|
|
|
|
USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE
|
|
|
|
);
|
|
|
|
if (IsKeyRegistered (&CurrentNotify->KeyData, KeyData)) {
|
|
|
|
if (CurrentNotify->KeyNotificationFn == KeyNotificationFunction) {
|
|
|
|
*NotifyHandle = CurrentNotify->NotifyHandle;
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Allocate resource to save the notification function
|
|
|
|
//
|
|
|
|
NewNotify = (KEYBOARD_CONSOLE_IN_EX_NOTIFY *) AllocateZeroPool (sizeof (KEYBOARD_CONSOLE_IN_EX_NOTIFY));
|
|
|
|
if (NewNotify == NULL) {
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
NewNotify->Signature = USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE;
|
|
|
|
NewNotify->KeyNotificationFn = KeyNotificationFunction;
|
2009-02-25 06:35:12 +01:00
|
|
|
NewNotify->NotifyHandle = (EFI_HANDLE) NewNotify;
|
2007-10-19 04:35:29 +02:00
|
|
|
CopyMem (&NewNotify->KeyData, KeyData, sizeof (EFI_KEY_DATA));
|
|
|
|
InsertTailList (&UsbKeyboardDevice->NotifyList, &NewNotify->NotifyEntry);
|
|
|
|
|
2009-02-25 06:35:12 +01:00
|
|
|
|
2007-10-19 04:35:29 +02:00
|
|
|
*NotifyHandle = NewNotify->NotifyHandle;
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-07-23 08:29:46 +02:00
|
|
|
/**
|
|
|
|
Remove a registered notification function from a particular keystroke.
|
|
|
|
|
|
|
|
@param This Protocol instance pointer.
|
|
|
|
@param NotificationHandle The handle of the notification function being unregistered.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The notification function was unregistered successfully.
|
2008-12-15 08:17:47 +01:00
|
|
|
@retval EFI_INVALID_PARAMETER The NotificationHandle is invalid
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
**/
|
2007-10-19 04:35:29 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
USBKeyboardUnregisterKeyNotify (
|
|
|
|
IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
|
|
|
|
IN EFI_HANDLE NotificationHandle
|
|
|
|
)
|
|
|
|
{
|
|
|
|
USB_KB_DEV *UsbKeyboardDevice;
|
|
|
|
KEYBOARD_CONSOLE_IN_EX_NOTIFY *CurrentNotify;
|
|
|
|
LIST_ENTRY *Link;
|
2008-12-26 10:18:12 +01:00
|
|
|
LIST_ENTRY *NotifyList;
|
2007-10-19 04:35:29 +02:00
|
|
|
|
|
|
|
if (NotificationHandle == NULL) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
2009-03-04 05:31:46 +01:00
|
|
|
|
|
|
|
if (((KEYBOARD_CONSOLE_IN_EX_NOTIFY *) NotificationHandle)->Signature != USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
2007-10-19 04:35:29 +02:00
|
|
|
|
|
|
|
UsbKeyboardDevice = TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS (This);
|
|
|
|
|
2008-12-05 10:19:10 +01:00
|
|
|
//
|
|
|
|
// Traverse notify list of USB keyboard and remove the entry of NotificationHandle.
|
|
|
|
//
|
2008-12-26 10:18:12 +01:00
|
|
|
NotifyList = &UsbKeyboardDevice->NotifyList;
|
|
|
|
for (Link = GetFirstNode (NotifyList);
|
|
|
|
!IsNull (NotifyList, Link);
|
|
|
|
Link = GetNextNode (NotifyList, Link)) {
|
2007-10-19 04:35:29 +02:00
|
|
|
CurrentNotify = CR (
|
|
|
|
Link,
|
|
|
|
KEYBOARD_CONSOLE_IN_EX_NOTIFY,
|
|
|
|
NotifyEntry,
|
|
|
|
USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE
|
|
|
|
);
|
|
|
|
if (CurrentNotify->NotifyHandle == NotificationHandle) {
|
|
|
|
//
|
|
|
|
// Remove the notification function from NotifyList and free resources
|
|
|
|
//
|
|
|
|
RemoveEntryList (&CurrentNotify->NotifyEntry);
|
2009-02-25 06:35:12 +01:00
|
|
|
|
2009-01-13 09:46:31 +01:00
|
|
|
FreePool (CurrentNotify);
|
2007-10-19 04:35:29 +02:00
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-07 04:29:49 +02:00
|
|
|
//
|
|
|
|
// Cannot find the matching entry in database.
|
|
|
|
//
|
|
|
|
return EFI_INVALID_PARAMETER;
|
2007-10-19 04:35:29 +02:00
|
|
|
}
|
|
|
|
|