summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxli24 <xli24@6f19259b-4bc3-4df7-8a09-765794883524>2008-12-15 07:17:47 +0000
committerxli24 <xli24@6f19259b-4bc3-4df7-8a09-765794883524>2008-12-15 07:17:47 +0000
commitb4e73a63730e037f7a81d22d48a78207fea56352 (patch)
treea46ed1fae6186ca0833162199a56eb99e0e4835d
parent619c3f082674b90a43d17ecdc6cdb2d860781235 (diff)
downloadedk2-b4e73a63730e037f7a81d22d48a78207fea56352.zip
edk2-b4e73a63730e037f7a81d22d48a78207fea56352.tar.gz
edk2-b4e73a63730e037f7a81d22d48a78207fea56352.tar.bz2
Code Scrub for UsbKbDxe module.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@7028 6f19259b-4bc3-4df7-8a09-765794883524
-rw-r--r--MdeModulePkg/Bus/Usb/UsbKbDxe/ComponentName.c175
-rw-r--r--MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.c212
-rw-r--r--MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.h296
-rw-r--r--MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c548
-rw-r--r--MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.h139
-rw-r--r--MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf6
6 files changed, 714 insertions, 662 deletions
diff --git a/MdeModulePkg/Bus/Usb/UsbKbDxe/ComponentName.c b/MdeModulePkg/Bus/Usb/UsbKbDxe/ComponentName.c
index e40a79b..8f9ad6d 100644
--- a/MdeModulePkg/Bus/Usb/UsbKbDxe/ComponentName.c
+++ b/MdeModulePkg/Bus/Usb/UsbKbDxe/ComponentName.c
@@ -1,6 +1,5 @@
/** @file
-
- UEFI Component Name(2) protocol implementation for Usb Keyboard driver.
+ UEFI Component Name(2) protocol implementation for USB Keyboard driver.
Copyright (c) 2004 - 2008, Intel Corporation
All rights reserved. This program and the accompanying materials
@@ -17,136 +16,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include "KeyBoard.h"
//
-// EFI Component Name Functions
-//
-/**
- Retrieves a Unicode string that is the user readable name of the driver.
-
- This function retrieves the user readable name of a driver in the form of a
- Unicode string. If the driver specified by This has a user readable name in
- the language specified by Language, then a pointer to the driver name is
- returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
- by This does not support the language specified by Language,
- then EFI_UNSUPPORTED is returned.
-
- @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
- EFI_COMPONENT_NAME_PROTOCOL instance.
-
- @param Language[in] A pointer to a Null-terminated ASCII string
- array indicating the language. This is the
- language of the driver name 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. Language is specified
- in RFC 3066 or ISO 639-2 language code format.
-
- @param DriverName[out] 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.
-
- @retval EFI_SUCCESS The Unicode string for the Driver specified by
- This and the language specified by Language was
- returned in DriverName.
-
- @retval EFI_INVALID_PARAMETER Language is NULL.
-
- @retval EFI_INVALID_PARAMETER DriverName is NULL.
-
- @retval EFI_UNSUPPORTED The driver specified by This does not support
- the language specified by Language.
-
-**/
-EFI_STATUS
-EFIAPI
-UsbKeyboardComponentNameGetDriverName (
- IN EFI_COMPONENT_NAME_PROTOCOL *This,
- IN CHAR8 *Language,
- OUT CHAR16 **DriverName
- );
-
-
-/**
- Retrieves a Unicode string that is the user readable name of the controller
- that is being managed by a driver.
-
- This function retrieves the user readable name of the controller specified by
- ControllerHandle and ChildHandle in the form of a Unicode string. If the
- driver specified by This has a user readable name in the language specified by
- Language, then a pointer to the controller name is returned in ControllerName,
- and EFI_SUCCESS is returned. If the driver specified by This is not currently
- managing the controller specified by ControllerHandle and ChildHandle,
- then EFI_UNSUPPORTED is returned. If the driver specified by This does not
- support the language specified by Language, then EFI_UNSUPPORTED is returned.
-
- @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
- EFI_COMPONENT_NAME_PROTOCOL instance.
-
- @param ControllerHandle[in] The handle of a controller that the driver
- specified by This is managing. This handle
- specifies the controller whose name is to be
- returned.
-
- @param ChildHandle[in] 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.
-
- @param Language[in] A pointer to a Null-terminated ASCII string
- array indicating the language. This is the
- language of the driver name 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. Language is specified in
- RFC 3066 or ISO 639-2 language code format.
-
- @param ControllerName[out] 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.
-
- @retval 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.
-
- @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
-
- @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
- EFI_HANDLE.
-
- @retval EFI_INVALID_PARAMETER Language is NULL.
-
- @retval EFI_INVALID_PARAMETER ControllerName is NULL.
-
- @retval EFI_UNSUPPORTED The driver specified by This is not currently
- managing the controller specified by
- ControllerHandle and ChildHandle.
-
- @retval EFI_UNSUPPORTED The driver specified by This does not support
- the language specified by Language.
-
-**/
-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
//
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gUsbKeyboardComponentName = {
@@ -170,7 +39,6 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mUsbKeyboardDriverNameTab
{ NULL , NULL }
};
-
/**
Retrieves a Unicode string that is the user readable name of the driver.
@@ -181,10 +49,9 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mUsbKeyboardDriverNameTab
by This does not support the language specified by Language,
then EFI_UNSUPPORTED is returned.
- @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
+ @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
-
- @param Language[in] A pointer to a Null-terminated ASCII string
+ @param Language A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name that the caller is
requesting, and it must match one of the
@@ -192,8 +59,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mUsbKeyboardDriverNameTab
number of languages supported by a driver is up
to the driver writer. Language is specified
in RFC 3066 or ISO 639-2 language code format.
-
- @param DriverName[out] A pointer to the Unicode string to return.
+ @param 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.
@@ -201,11 +67,8 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mUsbKeyboardDriverNameTab
@retval EFI_SUCCESS The Unicode string for the Driver specified by
This and the language specified by Language was
returned in DriverName.
-
@retval EFI_INVALID_PARAMETER Language is NULL.
-
@retval EFI_INVALID_PARAMETER DriverName is NULL.
-
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
@@ -240,15 +103,13 @@ UsbKeyboardComponentNameGetDriverName (
then EFI_UNSUPPORTED is returned. If the driver specified by This does not
support the language specified by Language, then EFI_UNSUPPORTED is returned.
- @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
+ @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
-
- @param ControllerHandle[in] The handle of a controller that the driver
+ @param 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.
-
- @param ChildHandle[in] The handle of the child controller to retrieve
+ @param 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
@@ -256,8 +117,7 @@ UsbKeyboardComponentNameGetDriverName (
controller. It will not be NULL for a bus
driver that wishes to retrieve the name of a
child controller.
-
- @param Language[in] A pointer to a Null-terminated ASCII string
+ @param Language A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name that the caller is
requesting, and it must match one of the
@@ -265,8 +125,7 @@ UsbKeyboardComponentNameGetDriverName (
number of languages supported by a driver is up
to the driver writer. Language is specified in
RFC 3066 or ISO 639-2 language code format.
-
- @param ControllerName[out] A pointer to the Unicode string to return.
+ @param 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
@@ -277,20 +136,14 @@ UsbKeyboardComponentNameGetDriverName (
the language specified by Language for the
driver specified by This was returned in
DriverName.
-
@retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
-
@retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
EFI_HANDLE.
-
@retval EFI_INVALID_PARAMETER Language is NULL.
-
@retval EFI_INVALID_PARAMETER ControllerName is NULL.
-
@retval EFI_UNSUPPORTED The driver specified by This is not currently
managing the controller specified by
ControllerHandle and ChildHandle.
-
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
@@ -329,11 +182,11 @@ UsbKeyboardComponentNameGetControllerName (
);
if (!EFI_ERROR (Status)) {
gBS->CloseProtocol (
- ControllerHandle,
- &gEfiUsbIoProtocolGuid,
- gUsbKeyboardDriverBinding.DriverBindingHandle,
- ControllerHandle
- );
+ ControllerHandle,
+ &gEfiUsbIoProtocolGuid,
+ gUsbKeyboardDriverBinding.DriverBindingHandle,
+ ControllerHandle
+ );
return EFI_UNSUPPORTED;
}
diff --git a/MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.c b/MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.c
index 79f1633..d889b97 100644
--- a/MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.c
+++ b/MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.c
@@ -1,5 +1,6 @@
/** @file
- USB Keyboard Driver that includes the implementation of interface.
+ USB Keyboard Driver that manages USB keyboard and produces Simple Text Input
+ Protocol and Simple Text Input Ex Protocol.
Copyright (c) 2004 - 2008, Intel Corporation
All rights reserved. This program and the accompanying materials
@@ -99,8 +100,8 @@ USBKeyboardDriverBindingSupported (
}
//
- // Use the USB I/O Protocol interface to check whether the Controller is
- // the Keyboard controller that can be managed by this driver.
+ // Use the USB I/O Protocol interface to check whether Controller is
+ // a keyboard device that can be managed by this driver.
//
Status = EFI_SUCCESS;
@@ -119,7 +120,11 @@ USBKeyboardDriverBindingSupported (
}
/**
- Start running driver on the controller.
+ Starts the device with this driver.
+
+ 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.
@param This The USB keyboard driver binding instance.
@param Controller Handle of device to bind driver to.
@@ -128,7 +133,7 @@ USBKeyboardDriverBindingSupported (
@retval EFI_SUCCESS The controller is controlled by the usb keyboard driver.
@retval EFI_UNSUPPORTED No interrupt endpoint can be found.
- @retval Other The keyboard driver cannot support this controller.
+ @retval Other This controller cannot be started.
**/
EFI_STATUS
@@ -201,9 +206,6 @@ USBKeyboardDriverBindingStart (
UsbKeyboardDevice->DevicePath
);
- //
- // Initialize UsbKeyboardDevice
- //
UsbKeyboardDevice->UsbIo = UsbIo;
//
@@ -405,17 +407,18 @@ ErrorExit:
/**
- Stop handling the controller by this USB keyboard driver.
+ Stop the USB keyboard device handled by this driver.
@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.
- @retval EFI_SUCCESS The controller or children are stopped.
+ @retval EFI_SUCCESS The device was stopped.
@retval EFI_UNSUPPORTED Simple Text In Protocol or Simple Text In Ex Protocol
is not installed on Controller.
- @retval EFI_DEVICE_ERROR Failed to stop the driver.
+ @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.
**/
EFI_STATUS
@@ -454,9 +457,7 @@ USBKeyboardDriverBindingStop (
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
- //
- // Get USB_KB_DEV instance.
- //
+
UsbKeyboardDevice = USB_KB_DEV_FROM_THIS (SimpleInput);
//
@@ -520,28 +521,29 @@ USBKeyboardDriverBindingStop (
}
/**
- Internal function to read the next keystroke from the input device.
+ Internal function to read the next keystroke from the keyboard buffer.
- @param UsbKeyboardDevice Usb keyboard's private structure.
- @param KeyData A pointer to a buffer that is filled in with the keystroke
- state data for the key that was pressed.
+ @param UsbKeyboardDevice USB keyboard's private structure.
+ @param KeyData A pointer to buffer to hold the keystroke
+ data for the key that was pressed.
- @return EFI_SUCCESS The keystroke information was returned.
- @return EFI_NOT_READY There was no keystroke data availiable.
- @return EFI_DEVICE_ERROR The keystroke information was not returned due to
+ @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
hardware errors.
- @return EFI_INVALID_PARAMETER KeyData is NULL.
+ @retval EFI_INVALID_PARAMETER KeyData is NULL.
+ @retval Others Fail to translate keycode into EFI_INPUT_KEY
**/
EFI_STATUS
EFIAPI
USBKeyboardReadKeyStrokeWorker (
- IN USB_KB_DEV *UsbKeyboardDevice,
- OUT EFI_KEY_DATA *KeyData
+ IN OUT USB_KB_DEV *UsbKeyboardDevice,
+ OUT EFI_KEY_DATA *KeyData
)
{
EFI_STATUS Status;
- UINT8 KeyChar;
+ UINT8 KeyCode;
LIST_ENTRY *Link;
KEYBOARD_CONSOLE_IN_EX_NOTIFY *CurrentNotify;
EFI_KEY_DATA OriginalKeyData;
@@ -551,10 +553,10 @@ USBKeyboardReadKeyStrokeWorker (
}
//
- // If there is no saved ASCII byte, fetch it
+ // If there is no saved USB keycode, fetch it
// by calling USBKeyboardCheckForKey().
//
- if (UsbKeyboardDevice->CurKeyChar == 0) {
+ if (UsbKeyboardDevice->CurKeyCode == 0) {
Status = USBKeyboardCheckForKey (UsbKeyboardDevice);
if (EFI_ERROR (Status)) {
return EFI_NOT_READY;
@@ -565,15 +567,15 @@ USBKeyboardReadKeyStrokeWorker (
KeyData->Key.ScanCode = SCAN_NULL;
//
- // Store the key char read by USBKeyboardCheckForKey() and clear it.
+ // Store the current keycode and clear it.
//
- KeyChar = UsbKeyboardDevice->CurKeyChar;
- UsbKeyboardDevice->CurKeyChar = 0;
+ KeyCode = UsbKeyboardDevice->CurKeyCode;
+ UsbKeyboardDevice->CurKeyCode = 0;
//
- // Translate saved ASCII byte into EFI_INPUT_KEY
+ // Translate saved USB keycode into EFI_INPUT_KEY
//
- Status = UsbKeyCodeToEfiInputKey (UsbKeyboardDevice, KeyChar, &KeyData->Key);
+ Status = UsbKeyCodeToEfiInputKey (UsbKeyboardDevice, KeyCode, &KeyData->Key);
if (EFI_ERROR (Status)) {
return Status;
}
@@ -594,9 +596,9 @@ USBKeyboardReadKeyStrokeWorker (
// here switch them back for notification function.
//
CopyMem (&OriginalKeyData, KeyData, sizeof (EFI_KEY_DATA));
- if (UsbKeyboardDevice->CtrlOn != 0) {
+ if (UsbKeyboardDevice->CtrlOn) {
if (OriginalKeyData.Key.UnicodeChar >= 0x01 && OriginalKeyData.Key.UnicodeChar <= 0x1A) {
- if (UsbKeyboardDevice->CapsOn != 0) {
+ if (UsbKeyboardDevice->CapsOn) {
OriginalKeyData.Key.UnicodeChar = (CHAR16)(OriginalKeyData.Key.UnicodeChar + 'A' - 1);
} else {
OriginalKeyData.Key.UnicodeChar = (CHAR16)(OriginalKeyData.Key.UnicodeChar + 'a' - 1);
@@ -617,24 +619,21 @@ USBKeyboardReadKeyStrokeWorker (
}
return EFI_SUCCESS;
-
}
/**
- Reset USB Keyboard.
+ Reset the input device and optionaly run diagnostics
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.
- @param This The protocol instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL.
- @param ExtendedVerification Indicates if exhaustive reset is used.
- TRUE for exhaustive reset.
- FALSE for non-exhaustive reset.
+ @param This Protocol instance pointer.
+ @param ExtendedVerification Driver may perform diagnostics on reset.
- @retval EFI_SUCCESS Keyboard is reset successfully.
- @retval EFI_DEVICE_ERROR Failed to reset keyboard.
+ @retval EFI_SUCCESS The device was reset.
+ @retval EFI_DEVICE_ERROR The device is not functioning properly and could not be reset.
**/
EFI_STATUS
@@ -669,7 +668,7 @@ USBKeyboardReset (
// Clear the key buffer of this USB keyboard
//
InitUSBKeyBuffer (&(UsbKeyboardDevice->KeyboardBuffer));
- UsbKeyboardDevice->CurKeyChar = 0;
+ UsbKeyboardDevice->CurKeyCode = 0;
return EFI_SUCCESS;
}
@@ -678,7 +677,7 @@ USBKeyboardReset (
// Exhaustive reset
//
Status = InitUSBKeyboard (UsbKeyboardDevice);
- UsbKeyboardDevice->CurKeyChar = 0;
+ UsbKeyboardDevice->CurKeyCode = 0;
if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
}
@@ -688,14 +687,16 @@ USBKeyboardReset (
/**
- Implements EFI_SIMPLE_TEXT_INPUT_PROTOCOL.ReadKeyStroke() function.
+ Reads the next keystroke from the input device.
@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.
- @retval EFI_SUCCESS Read key stroke successfully.
- @retval Other Read key stroke failed.
+ @retval EFI_SUCCESS The keystroke information was returned.
+ @retval EFI_NOT_READY There was no keystroke data availiable.
+ @retval EFI_DEVICE_ERROR The keydtroke information was not returned due to
+ hardware errors.
**/
EFI_STATUS
@@ -719,12 +720,12 @@ USBKeyboardReadKeyStroke (
CopyMem (Key, &KeyData.Key, sizeof (EFI_INPUT_KEY));
return EFI_SUCCESS;
-
}
/**
- Handler function for WaitForKey event.
+ Event notification function registered for EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx
+ and EFI_SIMPLE_TEXT_INPUT_PROTOCOL.WaitForKey.
@param Event Event to be signaled when a key is pressed.
@param Context Points to USB_KB_DEV instance.
@@ -741,7 +742,7 @@ USBKeyboardWaitForKey (
UsbKeyboardDevice = (USB_KB_DEV *) Context;
- if (UsbKeyboardDevice->CurKeyChar == 0) {
+ if (UsbKeyboardDevice->CurKeyCode == 0) {
if (EFI_ERROR (USBKeyboardCheckForKey (UsbKeyboardDevice))) {
//
// If no pending key, simply return.
@@ -757,7 +758,7 @@ USBKeyboardWaitForKey (
/**
- Check whether there is key pending.
+ Check whether there is key pending in the keyboard buffer.
@param UsbKeyboardDevice The USB_KB_DEV instance.
@@ -768,53 +769,50 @@ USBKeyboardWaitForKey (
EFI_STATUS
EFIAPI
USBKeyboardCheckForKey (
- IN USB_KB_DEV *UsbKeyboardDevice
+ IN OUT USB_KB_DEV *UsbKeyboardDevice
)
{
EFI_STATUS Status;
- UINT8 KeyChar;
+ UINT8 KeyCode;
//
- // Fetch raw data from the USB keyboard input,
- // and translate it into ASCII data.
+ // Fetch raw data from the USB keyboard buffer,
+ // and translate it into USB keycode.
//
- Status = USBParseKey (UsbKeyboardDevice, &KeyChar);
+ Status = USBParseKey (UsbKeyboardDevice, &KeyCode);
if (EFI_ERROR (Status)) {
return EFI_NOT_READY;
}
- UsbKeyboardDevice->CurKeyChar = KeyChar;
+ UsbKeyboardDevice->CurKeyCode = KeyCode;
return EFI_SUCCESS;
}
/**
Free keyboard notify list.
- @param ListHead The list head.
+ @param NotifyList The keyboard notify list to free.
@retval EFI_SUCCESS Free the notify list successfully.
- @retval EFI_INVALID_PARAMETER ListHead is invalid.
+ @retval EFI_INVALID_PARAMETER NotifyList is NULL.
**/
EFI_STATUS
EFIAPI
KbdFreeNotifyList (
- IN OUT LIST_ENTRY *ListHead
+ IN OUT LIST_ENTRY *NotifyList
)
{
KEYBOARD_CONSOLE_IN_EX_NOTIFY *NotifyNode;
+ LIST_ENTRY *Link;
- if (ListHead == NULL) {
+ if (NotifyList == NULL) {
return EFI_INVALID_PARAMETER;
}
- while (!IsListEmpty (ListHead)) {
- NotifyNode = CR (
- ListHead->ForwardLink,
- KEYBOARD_CONSOLE_IN_EX_NOTIFY,
- NotifyEntry,
- USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE
- );
- RemoveEntryList (ListHead->ForwardLink);
+ while (!IsListEmpty (NotifyList)) {
+ Link = GetFirstNode (NotifyList);
+ NotifyNode = CR (Link, KEYBOARD_CONSOLE_IN_EX_NOTIFY, NotifyEntry, USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE);
+ RemoveEntryList (Link);
gBS->FreePool (NotifyNode);
}
@@ -822,15 +820,13 @@ KbdFreeNotifyList (
}
/**
- Whether the pressed key matches a registered key or not.
+ Check whether the pressed key matches a registered key or not.
- @param RegsiteredData A pointer to a buffer that is filled in with the keystroke
- state data for the key that was registered.
- @param InputData A pointer to a buffer that is filled in with the keystroke
- state data for the key that was pressed.
+ @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.
@retval TRUE Key pressed matches a registered key.
- @retval FLASE Match failed.
+ @retval FLASE Key pressed does not matche a registered key.
**/
BOOLEAN
@@ -860,21 +856,31 @@ IsKeyRegistered (
}
return TRUE;
-
}
//
// Simple Text Input Ex protocol functions
//
/**
- The extension routine to reset the input device.
+ 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.
- @param This Protocol instance pointer.
- @param ExtendedVerification Driver may perform diagnostics on reset.
+ @param This A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance.
- @retval EFI_SUCCESS The device was reset.
- @retval EFI_DEVICE_ERROR The device is not functioning properly and could
- not be reset.
+ @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.
**/
EFI_STATUS
@@ -906,16 +912,17 @@ USBKeyboardResetEx (
}
/**
- Reads the next keystroke from the input device. The WaitForKey Event can
- be used to test for existance of a keystroke via WaitForEvent () call.
+ Reads the next keystroke from the input device.
- @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.
+ @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.
- @return EFI_SUCCESS The keystroke information was returned successfully.
- @retval EFI_INVALID_PARAMETER KeyData is NULL.
- @retval Other Read key stroke information failed.
+ @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.
**/
EFI_STATUS
@@ -944,8 +951,10 @@ USBKeyboardReadKeyStrokeEx (
@param KeyToggleState A pointer to the EFI_KEY_TOGGLE_STATE to set the
state for the input device.
- @retval EFI_SUCCESS The device state was set successfully.
- @retval EFI_UNSUPPORTED The device does not have the ability to set its state.
+ @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.
@retval EFI_INVALID_PARAMETER KeyToggleState is NULL.
**/
@@ -973,18 +982,18 @@ USBKeyboardSetState (
// Update the status light
//
- UsbKeyboardDevice->ScrollOn = 0;
- UsbKeyboardDevice->NumLockOn = 0;
- UsbKeyboardDevice->CapsOn = 0;
+ UsbKeyboardDevice->ScrollOn = FALSE;
+ UsbKeyboardDevice->NumLockOn = FALSE;
+ UsbKeyboardDevice->CapsOn = FALSE;
if ((*KeyToggleState & EFI_SCROLL_LOCK_ACTIVE) == EFI_SCROLL_LOCK_ACTIVE) {
- UsbKeyboardDevice->ScrollOn = 1;
+ UsbKeyboardDevice->ScrollOn = TRUE;
}
if ((*KeyToggleState & EFI_NUM_LOCK_ACTIVE) == EFI_NUM_LOCK_ACTIVE) {
- UsbKeyboardDevice->NumLockOn = 1;
+ UsbKeyboardDevice->NumLockOn = TRUE;
}
if ((*KeyToggleState & EFI_CAPS_LOCK_ACTIVE) == EFI_CAPS_LOCK_ACTIVE) {
- UsbKeyboardDevice->CapsOn = 1;
+ UsbKeyboardDevice->CapsOn = TRUE;
}
SetKeyLED (UsbKeyboardDevice);
@@ -1007,7 +1016,7 @@ USBKeyboardSetState (
@retval EFI_SUCCESS The notification function was registered successfully.
@retval EFI_OUT_OF_RESOURCES Unable to allocate resources for necesssary data structures.
- @retval EFI_INVALID_PARAMETER KeyData or NotifyHandle is NULL.
+ @retval EFI_INVALID_PARAMETER KeyData or NotifyHandle or KeyNotificationFunction is NULL.
**/
EFI_STATUS
@@ -1088,9 +1097,8 @@ USBKeyboardRegisterKeyNotify (
@param NotificationHandle The handle of the notification function being unregistered.
@retval EFI_SUCCESS The notification function was unregistered successfully.
- @retval EFI_INVALID_PARAMETER The NotificationHandle is invalid or opening gSimpleTextInExNotifyGuid
- on NotificationHandle fails.
- @retval EFI_NOT_FOUND Can not find the matching entry in database.
+ @retval EFI_INVALID_PARAMETER The NotificationHandle is invalid
+ @retval EFI_NOT_FOUND Cannot find the matching entry in database.
**/
EFI_STATUS
diff --git a/MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.h b/MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.h
index 506a08c..08bfc68 100644
--- a/MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.h
+++ b/MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.h
@@ -54,8 +54,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#define REPORT_PROTOCOL 1
typedef struct {
- UINT8 Down;
- UINT8 KeyCode;
+ BOOLEAN Down;
+ UINT8 KeyCode;
} USB_KEY;
typedef struct {
@@ -110,31 +110,31 @@ typedef struct {
EFI_USB_ENDPOINT_DESCRIPTOR IntEndpointDescriptor;
USB_KB_BUFFER KeyboardBuffer;
- UINT8 CtrlOn;
- UINT8 AltOn;
- UINT8 ShiftOn;
- UINT8 NumLockOn;
- UINT8 CapsOn;
- UINT8 ScrollOn;
+ BOOLEAN CtrlOn;
+ BOOLEAN AltOn;
+ BOOLEAN ShiftOn;
+ BOOLEAN NumLockOn;
+ BOOLEAN CapsOn;
+ BOOLEAN ScrollOn;
UINT8 LastKeyCodeArray[8];
- UINT8 CurKeyChar;
+ UINT8 CurKeyCode;
UINT8 RepeatKey;
EFI_EVENT RepeatTimer;
EFI_UNICODE_STRING_TABLE *ControllerNameTable;
- UINT8 LeftCtrlOn;
- UINT8 LeftAltOn;
- UINT8 LeftShiftOn;
- UINT8 LeftLogoOn;
- UINT8 RightCtrlOn;
- UINT8 RightAltOn;
- UINT8 RightShiftOn;
- UINT8 RightLogoOn;
- UINT8 MenuKeyOn;
- UINT8 SysReqOn;
- UINT8 AltGrOn;
+ BOOLEAN LeftCtrlOn;
+ BOOLEAN LeftAltOn;
+ BOOLEAN LeftShiftOn;
+ BOOLEAN LeftLogoOn;
+ BOOLEAN RightCtrlOn;
+ BOOLEAN RightAltOn;
+ BOOLEAN RightShiftOn;
+ BOOLEAN RightLogoOn;
+ BOOLEAN MenuKeyOn;
+ BOOLEAN SysReqOn;
+ BOOLEAN AltGrOn;
EFI_KEY_STATE KeyState;
//
@@ -164,24 +164,20 @@ extern EFI_GUID gSimpleTextInExNotifyGuid;
#define TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS(a) \
CR(a, USB_KB_DEV, SimpleInputEx, 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 0x62
-
-#define USBKBD_VALID_KEYCODE(key) ((UINT8) (key) > 3)
+//
+// According to Universal Serial Bus HID Usage Tables document ver 1.12,
+// a Boot Keyboard should support the keycode range from 0x0 to 0x65 and 0xE0 to 0xE7.
+// 0xE0 to 0xE7 are for modifier keys, and 0x0 to 0x3 are reserved for typical
+// keyboard status or keyboard errors.
+// So the number of valid non-modifier USB keycodes is 0x62, and the number of
+// valid keycodes is 0x6A.
+//
+#define NUMBER_OF_VALID_NON_MODIFIER_USB_KEYCODE 0x62
+#define NUMBER_OF_VALID_USB_KEYCODE 0x6A
+//
+// 0x0 to 0x3 are reserved for typical keyboard status or keyboard errors.
+//
+#define USBKBD_VALID_KEYCODE(Key) ((UINT8) (Key) > 3)
typedef struct {
UINT8 NumLock : 1;
@@ -213,7 +209,11 @@ USBKeyboardDriverBindingSupported (
);
/**
- Start running driver on the controller.
+ Starts the device with this driver.
+
+ 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.
@param This The USB keyboard driver binding instance.
@param Controller Handle of device to bind driver to.
@@ -222,7 +222,7 @@ USBKeyboardDriverBindingSupported (
@retval EFI_SUCCESS The controller is controlled by the usb keyboard driver.
@retval EFI_UNSUPPORTED No interrupt endpoint can be found.
- @retval Other The keyboard driver cannot support this controller.
+ @retval Other This controller cannot be started.
**/
EFI_STATUS
@@ -234,17 +234,18 @@ USBKeyboardDriverBindingStart (
);
/**
- Stop handling the controller by this USB keyboard driver.
+ Stop the USB keyboard device handled by this driver.
@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.
- @retval EFI_SUCCESS The controller or children are stopped.
+ @retval EFI_SUCCESS The device was stopped.
@retval EFI_UNSUPPORTED Simple Text In Protocol or Simple Text In Ex Protocol
is not installed on Controller.
- @retval EFI_DEVICE_ERROR Failed to stop the driver.
+ @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.
**/
EFI_STATUS
@@ -257,23 +258,134 @@ USBKeyboardDriverBindingStop (
);
//
+// EFI Component Name Functions
+//
+/**
+ Retrieves a Unicode string that is the user readable name of the driver.
+
+ This function retrieves the user readable name of a driver in the form of a
+ Unicode string. If the driver specified by This has a user readable name in
+ the language specified by Language, then a pointer to the driver name is
+ returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
+ by This does not support the language specified by Language,
+ then EFI_UNSUPPORTED is returned.
+
+ @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
+ EFI_COMPONENT_NAME_PROTOCOL instance.
+ @param Language A pointer to a Null-terminated ASCII string
+ array indicating the language. This is the
+ language of the driver name 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. Language is specified
+ in RFC 3066 or ISO 639-2 language code format.
+ @param 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.
+
+ @retval EFI_SUCCESS The Unicode string for the Driver specified by
+ This and the language specified by Language was
+ returned in DriverName.
+ @retval EFI_INVALID_PARAMETER Language is NULL.
+ @retval EFI_INVALID_PARAMETER DriverName is NULL.
+ @retval EFI_UNSUPPORTED The driver specified by This does not support
+ the language specified by Language.
+
+**/
+EFI_STATUS
+EFIAPI
+UsbKeyboardComponentNameGetDriverName (
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN CHAR8 *Language,
+ OUT CHAR16 **DriverName
+ );
+
+/**
+ Retrieves a Unicode string that is the user readable name of the controller
+ that is being managed by a driver.
+
+ This function retrieves the user readable name of the controller specified by
+ ControllerHandle and ChildHandle in the form of a Unicode string. If the
+ driver specified by This has a user readable name in the language specified by
+ Language, then a pointer to the controller name is returned in ControllerName,
+ and EFI_SUCCESS is returned. If the driver specified by This is not currently
+ managing the controller specified by ControllerHandle and ChildHandle,
+ then EFI_UNSUPPORTED is returned. If the driver specified by This does not
+ support the language specified by Language, then EFI_UNSUPPORTED is returned.
+
+ @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
+ EFI_COMPONENT_NAME_PROTOCOL instance.
+ @param 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.
+ @param 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.
+ @param Language A pointer to a Null-terminated ASCII string
+ array indicating the language. This is the
+ language of the driver name 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. Language is specified in
+ RFC 3066 or ISO 639-2 language code format.
+ @param 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.
+
+ @retval 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.
+ @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
+ @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
+ EFI_HANDLE.
+ @retval EFI_INVALID_PARAMETER Language is NULL.
+ @retval EFI_INVALID_PARAMETER ControllerName is NULL.
+ @retval EFI_UNSUPPORTED The driver specified by This is not currently
+ managing the controller specified by
+ ControllerHandle and ChildHandle.
+ @retval EFI_UNSUPPORTED The driver specified by This does not support
+ the language specified by Language.
+
+**/
+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
+ );
+
+//
// Functions of Simple Text Input Protocol
//
/**
- Reset USB Keyboard.
+ Reset the input device and optionaly run diagnostics
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.
- @param This The protocol instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL.
- @param ExtendedVerification Indicates if exhaustive reset is used.
- TRUE for exhaustive reset.
- FALSE for non-exhaustive reset.
+ @param This Protocol instance pointer.
+ @param ExtendedVerification Driver may perform diagnostics on reset.
- @retval EFI_SUCCESS Keyboard is reset successfully.
- @retval EFI_DEVICE_ERROR Failed to reset keyboard.
+ @retval EFI_SUCCESS The device was reset.
+ @retval EFI_DEVICE_ERROR The device is not functioning properly and could not be reset.
**/
EFI_STATUS
@@ -284,14 +396,16 @@ USBKeyboardReset (
);
/**
- Implements EFI_SIMPLE_TEXT_INPUT_PROTOCOL.ReadKeyStroke() function.
+ Reads the next keystroke from the input device.
@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.
- @retval EFI_SUCCESS Read key stroke successfully.
- @retval Other Read key stroke failed.
+ @retval EFI_SUCCESS The keystroke information was returned.
+ @retval EFI_NOT_READY There was no keystroke data availiable.
+ @retval EFI_DEVICE_ERROR The keydtroke information was not returned due to
+ hardware errors.
**/
EFI_STATUS
@@ -305,14 +419,25 @@ USBKeyboardReadKeyStroke (
// Simple Text Input Ex protocol functions
//
/**
- The extension routine to reset the input device.
+ Resets the input device hardware.
- @param This Protocol instance pointer.
- @param ExtendedVerification Driver may perform diagnostics on reset.
+ 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.
- @retval EFI_SUCCESS The device was reset.
- @retval EFI_DEVICE_ERROR The device is not functioning properly and could
- not be reset.
+ @param This A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance.
+
+ @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.
**/
EFI_STATUS
@@ -323,16 +448,17 @@ USBKeyboardResetEx (
);
/**
- Reads the next keystroke from the input device. The WaitForKey Event can
- be used to test for existance of a keystroke via WaitForEvent () call.
+ Reads the next keystroke from the input device.
- @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.
+ @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.
- @return EFI_SUCCESS The keystroke information was returned successfully.
- @retval EFI_INVALID_PARAMETER KeyData is NULL.
- @retval Other Read key stroke information failed.
+ @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.
**/
EFI_STATUS
@@ -349,8 +475,10 @@ USBKeyboardReadKeyStrokeEx (
@param KeyToggleState A pointer to the EFI_KEY_TOGGLE_STATE to set the
state for the input device.
- @retval EFI_SUCCESS The device state was set successfully.
- @retval EFI_UNSUPPORTED The device does not have the ability to set its state.
+ @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.
@retval EFI_INVALID_PARAMETER KeyToggleState is NULL.
**/
@@ -373,7 +501,7 @@ USBKeyboardSetState (
@retval EFI_SUCCESS The notification function was registered successfully.
@retval EFI_OUT_OF_RESOURCES Unable to allocate resources for necesssary data structures.
- @retval EFI_INVALID_PARAMETER KeyData or NotifyHandle is NULL.
+ @retval EFI_INVALID_PARAMETER KeyData or NotifyHandle or KeyNotificationFunction is NULL.
**/
EFI_STATUS
@@ -392,9 +520,8 @@ USBKeyboardRegisterKeyNotify (
@param NotificationHandle The handle of the notification function being unregistered.
@retval EFI_SUCCESS The notification function was unregistered successfully.
- @retval EFI_INVALID_PARAMETER The NotificationHandle is invalid or opening gSimpleTextInExNotifyGuid
- on NotificationHandle fails.
- @retval EFI_NOT_FOUND Can not find the matching entry in database.
+ @retval EFI_INVALID_PARAMETER The NotificationHandle is invalid
+ @retval EFI_NOT_FOUND Cannot find the matching entry in database.
**/
EFI_STATUS
@@ -405,7 +532,8 @@ USBKeyboardUnregisterKeyNotify (
);
/**
- Handler function for WaitForKey event.
+ Event notification function registered for EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx
+ and EFI_SIMPLE_TEXT_INPUT_PROTOCOL.WaitForKey.
@param Event Event to be signaled when a key is pressed.
@param Context Points to USB_KB_DEV instance.
@@ -421,20 +549,20 @@ USBKeyboardWaitForKey (
/**
Free keyboard notify list.
- @param ListHead The list head.
+ @param NotifyList The keyboard notify list to free.
@retval EFI_SUCCESS Free the notify list successfully.
- @retval EFI_INVALID_PARAMETER ListHead is invalid.
+ @retval EFI_INVALID_PARAMETER NotifyList is NULL.
**/
EFI_STATUS
EFIAPI
KbdFreeNotifyList (
- IN OUT LIST_ENTRY *ListHead
+ IN OUT LIST_ENTRY *NotifyList
);
/**
- Check whether there is key pending.
+ Check whether there is key pending in the keyboard buffer.
@param UsbKeyboardDevice The USB_KB_DEV instance.
@@ -445,19 +573,17 @@ KbdFreeNotifyList (
EFI_STATUS
EFIAPI
USBKeyboardCheckForKey (
- IN USB_KB_DEV *UsbKeyboardDevice
+ IN OUT USB_KB_DEV *UsbKeyboardDevice
);
/**
- Whether the pressed key matches a registered key or not.
+ Check whether the pressed key matches a registered key or not.
- @param RegsiteredData A pointer to a buffer that is filled in with the keystroke
- state data for the key that was registered.
- @param InputData A pointer to a buffer that is filled in with the keystroke
- state data for the key that was pressed.
+ @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.
@retval TRUE Key pressed matches a registered key.
- @retval FLASE Match failed.
+ @retval FLASE Key pressed does not matche a registered key.
**/
BOOLEAN
diff --git a/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c b/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c
index 0d7d3d1..3acdd76 100644
--- a/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c
+++ b/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c
@@ -15,10 +15,14 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include "KeyBoard.h"
//
-// Static English keyboard layout
+// Default English keyboard layout
// Format:<efi key>, <unicode without shift>, <unicode with shift>, <Modifier>, <AffectedAttribute>
//
-UINT8 KeyboardLayoutTable[USB_KEYCODE_MAX_MAKE + 8][5] = {
+// According to Universal Serial Bus HID Usage Tables document ver 1.12,
+// a Boot Keyboard should support the keycode range from 0x0 to 0x65 and 0xE0 to 0xE7.
+// 0x0 to 0x3 are reserved for typical keyboard status or keyboard errors, so they are excluded.
+//
+UINT8 KeyboardLayoutTable[NUMBER_OF_VALID_USB_KEYCODE][5] = {
{EfiKeyC1, 'a', 'A', EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK}, // 0x04
{EfiKeyB5, 'b', 'B', EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK}, // 0x05
{EfiKeyB3, 'c', 'C', EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK}, // 0x06
@@ -129,9 +133,11 @@ UINT8 KeyboardLayoutTable[USB_KEYCODE_MAX_MAKE + 8][5] = {
};
//
-// EFI_KEY to USB Scan Code convertion table
+// EFI_KEY to USB Keycode convertion table
+// EFI_KEY is defined in UEFI spec.
+// USB Keycode is defined in USB HID Firmware spec.
//
-UINT8 UsbScanCodeConvertionTable[] = {
+UINT8 EfiKeyToUsbKeyCodeConvertionTable[] = {
0xe0, // EfiKeyLCtrl
0xe3, // EfiKeyA0
0xe2, // EfiKeyLAlt
@@ -240,9 +246,10 @@ UINT8 UsbScanCodeConvertionTable[] = {
};
//
-// Keyboard Layout Modifier to EFI Scan Code convertion table
+// Keyboard modifier value to EFI Scan Code convertion table
+// EFI Scan Code and the modifier values are defined in UEFI spec.
//
-UINT8 EfiScanCodeConvertionTable[] = {
+UINT8 ModifierValueToEfiScanCodeConvertionTable[] = {
SCAN_NULL, // EFI_NULL_MODIFIER
SCAN_NULL, // EFI_LEFT_CONTROL_MODIFIER
SCAN_NULL, // EFI_RIGHT_CONTROL_MODIFIER
@@ -281,20 +288,8 @@ UINT8 EfiScanCodeConvertionTable[] = {
EFI_GUID mKeyboardLayoutEventGuid = EFI_HII_SET_KEYBOARD_LAYOUT_EVENT_GUID;
-
-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
-};
-
/**
- Initialize KeyConvertionTable by using default keyboard layout.
+ Initialize Key Convertion Table by using default keyboard layout.
@param UsbKeyboardDevice The USB_KB_DEV instance.
@@ -302,7 +297,7 @@ KB_MODIFIER KB_Mod[8] = {
VOID
EFIAPI
LoadDefaultKeyboardLayout (
- IN USB_KB_DEV *UsbKeyboardDevice
+ IN OUT USB_KB_DEV *UsbKeyboardDevice
)
{
UINTN Index;
@@ -313,7 +308,7 @@ LoadDefaultKeyboardLayout (
//
KeyDescriptor = &UsbKeyboardDevice->KeyConvertionTable[0];
- for (Index = 0; Index < (USB_KEYCODE_MAX_MAKE + 8); Index++) {
+ for (Index = 0; Index < (NUMBER_OF_VALID_USB_KEYCODE); Index++) {
KeyDescriptor->Key = (EFI_KEY) KeyboardLayoutTable[Index][0];
KeyDescriptor->Unicode = KeyboardLayoutTable[Index][1];
KeyDescriptor->ShiftedUnicode = KeyboardLayoutTable[Index][2];
@@ -327,9 +322,12 @@ LoadDefaultKeyboardLayout (
}
/**
- Uses USB I/O to check whether the device is a USB Keyboard device.
+ Uses USB I/O to check whether the device is a USB keyboard device.
+
+ @param UsbIo Pointer to a USB I/O protocol instance.
- @param UsbIo Points to a USB I/O protocol instance.
+ @retval TRUE Device is a USB keyboard device.
+ @retval FALSE Device is a not USB keyboard device.
**/
BOOLEAN
@@ -342,8 +340,7 @@ IsUSBKeyboard (
EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
//
- // Get the Default interface descriptor, currently we
- // assume it is interface 1
+ // Get the default interface descriptor
//
Status = UsbIo->UsbGetInterfaceDescriptor (
UsbIo,
@@ -358,7 +355,6 @@ IsUSBKeyboard (
InterfaceDescriptor.InterfaceSubClass == SUBCLASS_BOOT &&
InterfaceDescriptor.InterfaceProtocol == PROTOCOL_KEYBOARD
) {
-
return TRUE;
}
@@ -368,7 +364,8 @@ IsUSBKeyboard (
/**
Get current keyboard layout from HII database.
- @return Pointer to EFI_HII_KEYBOARD_LAYOUT.
+ @return Pointer to HII Keyboard Layout.
+ NULL means failure occurred while trying to get keyboard layout.
**/
EFI_HII_KEYBOARD_LAYOUT *
@@ -383,7 +380,7 @@ GetCurrentKeyboardLayout (
UINT16 Length;
//
- // Locate Hii database protocol
+ // Locate HII Database Protocol
//
Status = gBS->LocateProtocol (
&gEfiHiiDatabaseProtocolGuid,
@@ -425,12 +422,12 @@ GetCurrentKeyboardLayout (
}
/**
- Find Key Descriptor in KeyConvertionTable given its scan code.
+ Find Key Descriptor in Key Convertion Table given its USB keycode.
@param UsbKeyboardDevice The USB_KB_DEV instance.
- @param ScanCode USB scan code.
+ @param KeyCode USB Keycode.
- @return The Key descriptor in KeyConvertionTable.
+ @return The Key Descriptor in Key Convertion Table.
NULL means not found.
**/
@@ -438,26 +435,32 @@ EFI_KEY_DESCRIPTOR *
EFIAPI
GetKeyDescriptor (
IN USB_KB_DEV *UsbKeyboardDevice,
- IN UINT8 ScanCode
+ IN UINT8 KeyCode
)
{
UINT8 Index;
- if (((ScanCode > 0x65) && (ScanCode < 0xe0)) || (ScanCode > 0xe7)) {
+ //
+ // Make sure KeyCode is in the range of [0x4, 0x65] or [0xe0, 0xe7]
+ //
+ if ((!USBKBD_VALID_KEYCODE (KeyCode)) || ((KeyCode > 0x65) && (KeyCode < 0xe0)) || (KeyCode > 0xe7)) {
return NULL;
}
- if (ScanCode <= 0x65) {
- Index = (UINT8) (ScanCode - 4);
+ //
+ // Calculate the index of Key Descriptor in Key Convertion Table
+ //
+ if (KeyCode <= 0x65) {
+ Index = (UINT8) (KeyCode - 4);
} else {
- Index = (UINT8) (ScanCode - 0xe0 + USB_KEYCODE_MAX_MAKE);
+ Index = (UINT8) (KeyCode - 0xe0 + NUMBER_OF_VALID_NON_MODIFIER_USB_KEYCODE);
}
return &UsbKeyboardDevice->KeyConvertionTable[Index];
}
/**
- Find Non-Spacing key for given KeyDescriptor.
+ Find Non-Spacing key for given Key descriptor.
@param UsbKeyboardDevice The USB_KB_DEV instance.
@param KeyDescriptor Key descriptor.
@@ -491,12 +494,18 @@ FindUsbNsKey (
}
/**
- Find physical key definition for a given Key stroke.
+ Find physical key definition for a given key descriptor.
+
+ For a specified non-spacing key, there are a list of physical
+ keys following it. This function traverses the list of
+ physical keys and tries to find the physical key matching
+ the KeyDescriptor.
- @param UsbNsKey The Non-Spacing key information.
- @param KeyDescriptor The key stroke.
+ @param UsbNsKey The non-spacing key information.
+ @param KeyDescriptor The key descriptor.
@return The physical key definition.
+ If no physical key is found, parameter KeyDescriptor is returned.
**/
EFI_KEY_DESCRIPTOR *
@@ -525,17 +534,21 @@ FindPhysicalKey (
}
/**
- The notification function for SET_KEYBOARD_LAYOUT_EVENT.
+ The notification function for EFI_HII_SET_KEYBOARD_LAYOUT_EVENT_GUID.
- @param Event The instance of EFI_EVENT.
- @param Context passing parameter.
+ This function is registered to event of EFI_HII_SET_KEYBOARD_LAYOUT_EVENT_GUID
+ group type, which will be triggered by EFI_HII_DATABASE_PROTOCOL.SetKeyboardLayout().
+ It tries to get curent keyboard layout from HII database.
+
+ @param Event Event being signaled.
+ @param Context Points to USB_KB_DEV instance.
**/
VOID
EFIAPI
SetKeyboardLayoutEvent (
- EFI_EVENT Event,
- VOID *Context
+ IN EFI_EVENT Event,
+ IN VOID *Context
)
{
USB_KB_DEV *UsbKeyboardDevice;
@@ -548,12 +561,12 @@ SetKeyboardLayoutEvent (
UINTN Index;
UINTN Index2;
UINTN KeyCount;
- UINT8 ScanCode;
+ UINT8 KeyCode;
UsbKeyboardDevice = (USB_KB_DEV *) Context;
//
- // Try to get current Keyboard Layout from HII database
+ // Try to get current keyboard layout from HII database
//
KeyboardLayout = GetCurrentKeyboardLayout ();
if (KeyboardLayout == NULL) {
@@ -564,7 +577,7 @@ SetKeyboardLayoutEvent (
// Re-allocate resource for KeyConvertionTable
//
ReleaseKeyboardLayoutResources (UsbKeyboardDevice);
- UsbKeyboardDevice->KeyConvertionTable = AllocateZeroPool ((USB_KEYCODE_MAX_MAKE + 8) * sizeof (EFI_KEY_DESCRIPTOR));
+ UsbKeyboardDevice->KeyConvertionTable = AllocateZeroPool ((NUMBER_OF_VALID_USB_KEYCODE) * sizeof (EFI_KEY_DESCRIPTOR));
ASSERT (UsbKeyboardDevice->KeyConvertionTable != NULL);
//
@@ -578,16 +591,16 @@ SetKeyboardLayoutEvent (
CopyMem (&TempKey, KeyDescriptor, sizeof (EFI_KEY_DESCRIPTOR));
//
- // Fill the key into KeyConvertionTable, whose index is calculated from USB scan code.
+ // Fill the key into KeyConvertionTable, whose index is calculated from USB keycode.
//
- ScanCode = UsbScanCodeConvertionTable [(UINT8) (TempKey.Key)];
- TableEntry = GetKeyDescriptor (UsbKeyboardDevice, ScanCode);
+ KeyCode = EfiKeyToUsbKeyCodeConvertionTable [(UINT8) (TempKey.Key)];
+ TableEntry = GetKeyDescriptor (UsbKeyboardDevice, KeyCode);
CopyMem (TableEntry, KeyDescriptor, sizeof (EFI_KEY_DESCRIPTOR));
+ //
+ // For non-spacing key, create the list with a non-spacing key followed by physical keys.
+ //
if (TempKey.Modifier == EFI_NS_KEY_MODIFIER) {
- //
- // For non-spacing key, create the list with a non-spacing key followed by physical keys.
- //
UsbNsKey = AllocatePool (sizeof (USB_NS_KEY));
ASSERT (UsbNsKey != NULL);
@@ -625,7 +638,7 @@ SetKeyboardLayoutEvent (
}
//
- // There are two EfiKeyEnter, duplicate its Key Descriptor
+ // There are two EfiKeyEnter, duplicate its key descriptor
//
TableEntry = GetKeyDescriptor (UsbKeyboardDevice, 0x58);
KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, 0x28);
@@ -635,7 +648,7 @@ SetKeyboardLayoutEvent (
}
/**
- Destroy resources for Keyboard layout.
+ Destroy resources for keyboard layout.
@param UsbKeyboardDevice The USB_KB_DEV instance.
@@ -643,7 +656,7 @@ SetKeyboardLayoutEvent (
VOID
EFIAPI
ReleaseKeyboardLayoutResources (
- IN USB_KB_DEV *UsbKeyboardDevice
+ IN OUT USB_KB_DEV *UsbKeyboardDevice
)
{
USB_NS_KEY *UsbNsKey;
@@ -665,24 +678,30 @@ ReleaseKeyboardLayoutResources (
}
/**
- Initialize USB Keyboard layout.
+ Initialize USB keyboard layout.
+
+ This function initializes Key Convertion Table for the USB keyboard device.
+ It first tries to retrieve layout from HII database. If failed and default
+ layout is enabled, then it just uses the default layout.
@param UsbKeyboardDevice The USB_KB_DEV instance.
- @retval EFI_SUCCESS Initialization Success.
- @retval Other Keyboard layout initial failed.
+ @retval EFI_SUCCESS Initialization succeeded.
+ @retval EFI_NOT_READY Keyboard layout cannot be retrieve from HII
+ database, and default layout is disabled.
+ @retval Other Fail to register event to EFI_HII_SET_KEYBOARD_LAYOUT_EVENT_GUID group.
**/
EFI_STATUS
EFIAPI
InitKeyboardLayout (
- IN USB_KB_DEV *UsbKeyboardDevice
+ OUT USB_KB_DEV *UsbKeyboardDevice
)
{
EFI_HII_KEYBOARD_LAYOUT *KeyboardLayout;
EFI_STATUS Status;
- UsbKeyboardDevice->KeyConvertionTable = AllocateZeroPool ((USB_KEYCODE_MAX_MAKE + 8) * sizeof (EFI_KEY_DESCRIPTOR));
+ UsbKeyboardDevice->KeyConvertionTable = AllocateZeroPool ((NUMBER_OF_VALID_USB_KEYCODE) * sizeof (EFI_KEY_DESCRIPTOR));
ASSERT (UsbKeyboardDevice->KeyConvertionTable != NULL);
InitializeListHead (&UsbKeyboardDevice->NsKeyList);
@@ -691,7 +710,7 @@ InitKeyboardLayout (
//
// Register event to EFI_HII_SET_KEYBOARD_LAYOUT_EVENT_GUID group,
- // which will be triggered by EFI_HII_DATABASE_PROTOCOL.SetKeyboardLayout.
+ // which will be triggered by EFI_HII_DATABASE_PROTOCOL.SetKeyboardLayout().
//
Status = gBS->CreateEventEx (
EVT_NOTIFY_SIGNAL,
@@ -732,18 +751,18 @@ InitKeyboardLayout (
/**
- Initialize USB Keyboard device and all private data structures.
+ Initialize USB keyboard device and all private data structures.
@param UsbKeyboardDevice The USB_KB_DEV instance.
@retval EFI_SUCCESS Initialization is successful.
- @retval EFI_DEVICE_ERROR Configure hardware failed.
+ @retval EFI_DEVICE_ERROR Keyboard initialization failed.
**/
EFI_STATUS
EFIAPI
InitUSBKeyboard (
- IN USB_KB_DEV *UsbKeyboardDevice
+ IN OUT USB_KB_DEV *UsbKeyboardDevice
)
{
UINT8 ConfigValue;
@@ -762,13 +781,9 @@ InitUSBKeyboard (
InitUSBKeyBuffer (&(UsbKeyboardDevice->KeyboardBuffer));
//
- // default configurations
+ // Uses default configuration to configure the USB keyboard device.
//
ConfigValue = 0x01;
-
- //
- // Uses default configuration to configure the USB Keyboard device.
- //
Status = UsbSetConfiguration (
UsbKeyboardDevice->UsbIo,
(UINT16) ConfigValue,
@@ -812,7 +827,7 @@ InitUSBKeyboard (
//
ReportId = 0;
//
- // Duration is zero, which means the duration is indefinite.
+ // Duration is zero, which means the duration is infinite.
// so the endpoint will inhibit reporting forever,
// and only reporting when a change is detected in the report data.
//
@@ -824,30 +839,30 @@ InitUSBKeyboard (
Duration
);
- UsbKeyboardDevice->CtrlOn = 0;
- UsbKeyboardDevice->AltOn = 0;
- UsbKeyboardDevice->ShiftOn = 0;
- UsbKeyboardDevice->NumLockOn = 0;
- UsbKeyboardDevice->CapsOn = 0;
- UsbKeyboardDevice->ScrollOn = 0;
+ UsbKeyboardDevice->CtrlOn = FALSE;
+ UsbKeyboardDevice->AltOn = FALSE;
+ UsbKeyboardDevice->ShiftOn = FALSE;
+ UsbKeyboardDevice->NumLockOn = FALSE;
+ UsbKeyboardDevice->CapsOn = FALSE;
+ UsbKeyboardDevice->ScrollOn = FALSE;
- UsbKeyboardDevice->LeftCtrlOn = 0;
- UsbKeyboardDevice->LeftAltOn = 0;
- UsbKeyboardDevice->LeftShiftOn = 0;
- UsbKeyboardDevice->LeftLogoOn = 0;
- UsbKeyboardDevice->RightCtrlOn = 0;
- UsbKeyboardDevice->RightAltOn = 0;
- UsbKeyboardDevice->RightShiftOn = 0;
- UsbKeyboardDevice->RightLogoOn = 0;
- UsbKeyboardDevice->MenuKeyOn = 0;
- UsbKeyboardDevice->SysReqOn = 0;
-
- UsbKeyboardDevice->AltGrOn = 0;
+ UsbKeyboardDevice->LeftCtrlOn = FALSE;
+ UsbKeyboardDevice->LeftAltOn = FALSE;
+ UsbKeyboardDevice->LeftShiftOn = FALSE;
+ UsbKeyboardDevice->LeftLogoOn = FALSE;
+ UsbKeyboardDevice->RightCtrlOn = FALSE;
+ UsbKeyboardDevice->RightAltOn = FALSE;
+ UsbKeyboardDevice->RightShiftOn = FALSE;
+ UsbKeyboardDevice->RightLogoOn = FALSE;
+ UsbKeyboardDevice->MenuKeyOn = FALSE;
+ UsbKeyboardDevice->SysReqOn = FALSE;
+
+ UsbKeyboardDevice->AltGrOn = FALSE;
UsbKeyboardDevice->CurrentNsKey = NULL;
//
- // Sync the initial state of lights
+ // Sync the initial state of lights on keyboard.
//
SetKeyLED (UsbKeyboardDevice);
@@ -887,7 +902,12 @@ InitUSBKeyboard (
/**
- Handler function for USB Keyboard's asynchronous interrupt transfer.
+ Handler function for USB keyboard's asynchronous interrupt transfer.
+
+ This function is the handler function for USB keyboard's asynchronous interrupt transfer
+ to manage the keyboard. It parses the USB keyboard input report, and inserts data to
+ keyboard buffer according to state of modifer keys and normal keys. Timer for repeat key
+ is also set accordingly.
@param Data A pointer to a buffer that is filled with key data which is
retrieved via asynchronous interrupt transfer.
@@ -895,8 +915,8 @@ InitUSBKeyboard (
@param Context Pointing to USB_KB_DEV instance.
@param Result Indicates the result of the asynchronous interrupt transfer.
- @retval EFI_SUCCESS Handler is successful.
- @retval EFI_DEVICE_ERROR Hardware Error
+ @retval EFI_SUCCESS Asynchronous interrupt transfer is handled successfully.
+ @retval EFI_DEVICE_ERROR Hardware error occurs.
**/
EFI_STATUS
@@ -914,6 +934,7 @@ KeyboardHandler (
UINT8 *OldKeyCodeBuffer;
UINT8 CurModifierMap;
UINT8 OldModifierMap;
+ UINT8 Mask;
UINT8 Index;
UINT8 Index2;
BOOLEAN Down;
@@ -932,7 +953,7 @@ KeyboardHandler (
UsbIo = UsbKeyboardDevice->UsbIo;
//
- // Analyzes the Result and performs corresponding action.
+ // Analyzes Result and performs corresponding action.
//
if (Result != EFI_USB_NOERROR) {
//
@@ -945,7 +966,7 @@ KeyboardHandler (
);
//
- // stop the repeat key generation if any
+ // Stop the repeat key generation if any
//
UsbKeyboardDevice->RepeatKey = 0;
@@ -977,7 +998,7 @@ KeyboardHandler (
NULL
);
//
- // EFI_USB_INTERRUPT_DELAY is defined in USB standard for error handling
+ // EFI_USB_INTERRUPT_DELAY is defined in USB standard for error handling.
//
gBS->SetTimer (
UsbKeyboardDevice->DelayedRecoveryEvent,
@@ -1029,24 +1050,32 @@ KeyboardHandler (
//
// Handle modifier key's pressing or releasing situation.
+ // According to USB HID Firmware spec, Byte 0 uses folloing map of Modifier keys:
+ // Bit0: Left Control, Keycode: 0xe0
+ // Bit1: Left Shift, Keycode: 0xe1
+ // Bit2: Left Alt, Keycode: 0xe2
+ // Bit3: Left GUI, Keycode: 0xe3
+ // Bit4: Right Control, Keycode: 0xe4
+ // Bit5: Right Shift, Keycode: 0xe5
+ // Bit6: Right Alt, Keycode: 0xe6
+ // Bit7: Right GUI, Keycode: 0xe7
//
for (Index = 0; Index < 8; Index++) {
-
- if ((CurModifierMap & KB_Mod[Index].Mask) != (OldModifierMap & KB_Mod[Index].Mask)) {
+ Mask = (UINT8) (1 << Index);
+ if ((CurModifierMap & Mask) != (OldModifierMap & Mask)) {
//
- // If current modifier key is up, then
- // CurModifierMap & KB_Mod[Index].Mask = 0;
+ // If current modifier key is up, then CurModifierMap & Mask = 0;
// otherwise it is a non-zero value.
- // Inserts the pressed modifier key into key buffer.
+ // Insert the changed modifier key into key buffer.
//
- Down = (UINT8) (CurModifierMap & KB_Mod[Index].Mask);
- InsertKeyCode (&(UsbKeyboardDevice->KeyboardBuffer), KB_Mod[Index].Key, Down);
+ Down = (BOOLEAN) ((CurModifierMap & Mask) != 0);
+ InsertKeyCode (&(UsbKeyboardDevice->KeyboardBuffer), (UINT8) (0xe0 + Index), Down);
}
}
//
// Handle normal key's releasing situation
- // Bytes 2 to 7 are normal keycodes
+ // Bytes 2 to 7 are for normal keycodes
//
KeyRelease = FALSE;
for (Index = 2; Index < 8; Index++) {
@@ -1075,7 +1104,7 @@ KeyboardHandler (
InsertKeyCode (
&(UsbKeyboardDevice->KeyboardBuffer),
OldKeyCodeBuffer[Index],
- 0
+ FALSE
);
//
// The original repeat key is released.
@@ -1124,7 +1153,7 @@ KeyboardHandler (
}
if (KeyPress) {
- InsertKeyCode (&(UsbKeyboardDevice->KeyboardBuffer), CurKeyCodeBuffer[Index], 1);
+ InsertKeyCode (&(UsbKeyboardDevice->KeyboardBuffer), CurKeyCodeBuffer[Index], TRUE);
//
// Handle repeat key
@@ -1146,16 +1175,14 @@ KeyboardHandler (
}
//
- // Update LastKeycodeArray[] buffer in the
- // Usb Keyboard Device data structure.
+ // Update LastKeycodeArray buffer in the UsbKeyboardDevice 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.
+ // Pre-process KeyboardBuffer to check if Ctrl + Alt + Del is pressed.
//
SavedTail = UsbKeyboardDevice->KeyboardBuffer.BufferTail;
Index = UsbKeyboardDevice->KeyboardBuffer.BufferHead;
@@ -1168,27 +1195,27 @@ KeyboardHandler (
case EFI_LEFT_CONTROL_MODIFIER:
case EFI_RIGHT_CONTROL_MODIFIER:
- if (UsbKey.Down != 0) {
- UsbKeyboardDevice->CtrlOn = 1;
+ if (UsbKey.Down) {
+ UsbKeyboardDevice->CtrlOn = TRUE;
} else {
- UsbKeyboardDevice->CtrlOn = 0;
+ UsbKeyboardDevice->CtrlOn = FALSE;
}
break;
case EFI_LEFT_ALT_MODIFIER:
case EFI_RIGHT_ALT_MODIFIER:
- if (UsbKey.Down != 0) {
- UsbKeyboardDevice->AltOn = 1;
+ if (UsbKey.Down) {
+ UsbKeyboardDevice->AltOn = TRUE;
} else {
- UsbKeyboardDevice->AltOn = 0;
+ UsbKeyboardDevice->AltOn = FALSE;
}
break;
case EFI_ALT_GR_MODIFIER:
- if (UsbKey.Down != 0) {
- UsbKeyboardDevice->AltGrOn = 1;
+ if (UsbKey.Down) {
+ UsbKeyboardDevice->AltGrOn = TRUE;
} else {
- UsbKeyboardDevice->AltGrOn = 0;
+ UsbKeyboardDevice->AltGrOn = FALSE;
}
break;
@@ -1196,8 +1223,8 @@ KeyboardHandler (
// For Del Key, check if Ctrl + Alt + Del occurs for reset.
//
case EFI_DELETE_MODIFIER:
- if (UsbKey.Down != 0) {
- if ((UsbKeyboardDevice->CtrlOn != 0) && (UsbKeyboardDevice->AltOn != 0)) {
+ if (UsbKey.Down) {
+ if ((UsbKeyboardDevice->CtrlOn) && (UsbKeyboardDevice->AltOn)) {
gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);
}
}
@@ -1220,7 +1247,7 @@ KeyboardHandler (
}
//
- // If have new key pressed, update the RepeatKey value, and set the
+ // If there is new key pressed, update the RepeatKey value, and set the
// timer to repeate delay timer
//
if (NewRepeatKey != 0) {
@@ -1230,10 +1257,10 @@ KeyboardHandler (
// enough time.
//
gBS->SetTimer (
- UsbKeyboardDevice->RepeatTimer,
- TimerRelative,
- USBKBD_REPEAT_DELAY
- );
+ UsbKeyboardDevice->RepeatTimer,
+ TimerRelative,
+ USBKBD_REPEAT_DELAY
+ );
UsbKeyboardDevice->RepeatKey = NewRepeatKey;
}
@@ -1242,26 +1269,29 @@ KeyboardHandler (
/**
- Retrieves a key character after parsing the raw data in keyboard buffer.
+ Retrieves a USB keycode after parsing the raw data in keyboard buffer.
+
+ This function parses keyboard buffer. It updates state of modifier key for
+ USB_KB_DEV instancem, and returns keycode for output.
@param UsbKeyboardDevice The USB_KB_DEV instance.
- @param KeyChar Points to the Key character after key parsing.
+ @param KeyCode Pointer to the USB keycode for output.
- @retval EFI_SUCCESS Parse key is successful.
- @retval EFI_NOT_READY Device is not ready.
+ @retval EFI_SUCCESS Keycode successfully parsed.
+ @retval EFI_NOT_READY Keyboard buffer is not ready for a valid keycode
**/
EFI_STATUS
EFIAPI
USBParseKey (
IN OUT USB_KB_DEV *UsbKeyboardDevice,
- OUT UINT8 *KeyChar
+ OUT UINT8 *KeyCode
)
{
USB_KEY UsbKey;
EFI_KEY_DESCRIPTOR *KeyDescriptor;
- *KeyChar = 0;
+ *KeyCode = 0;
while (!IsUSBKeyboardBufferEmpty (&UsbKeyboardDevice->KeyboardBuffer)) {
//
@@ -1270,67 +1300,67 @@ USBParseKey (
RemoveKeyCode (&(UsbKeyboardDevice->KeyboardBuffer), &UsbKey);
KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, UsbKey.KeyCode);
- if (UsbKey.Down == 0) {
+ if (!UsbKey.Down) {
//
// Key is released.
//
switch (KeyDescriptor->Modifier) {
//
- // CTRL release
+ // Ctrl release
//
case EFI_LEFT_CONTROL_MODIFIER:
- UsbKeyboardDevice->LeftCtrlOn = 0;
- UsbKeyboardDevice->CtrlOn = 0;
+ UsbKeyboardDevice->LeftCtrlOn = FALSE;
+ UsbKeyboardDevice->CtrlOn = FALSE;
break;
case EFI_RIGHT_CONTROL_MODIFIER:
- UsbKeyboardDevice->RightCtrlOn = 0;
- UsbKeyboardDevice->CtrlOn = 0;
+ UsbKeyboardDevice->RightCtrlOn = FALSE;
+ UsbKeyboardDevice->CtrlOn = FALSE;
break;
//
// Shift release
//
case EFI_LEFT_SHIFT_MODIFIER:
- UsbKeyboardDevice->LeftShiftOn = 0;
- UsbKeyboardDevice->ShiftOn = 0;
+ UsbKeyboardDevice->LeftShiftOn = FALSE;
+ UsbKeyboardDevice->ShiftOn = FALSE;
break;
case EFI_RIGHT_SHIFT_MODIFIER:
- UsbKeyboardDevice->RightShiftOn = 0;
- UsbKeyboardDevice->ShiftOn = 0;
+ UsbKeyboardDevice->RightShiftOn = FALSE;
+ UsbKeyboardDevice->ShiftOn = FALSE;
break;
//
// Alt release
//
case EFI_LEFT_ALT_MODIFIER:
- UsbKeyboardDevice->LeftAltOn = 0;
- UsbKeyboardDevice->AltOn = 0;
+ UsbKeyboardDevice->LeftAltOn = FALSE;
+ UsbKeyboardDevice->AltOn = FALSE;
break;
case EFI_RIGHT_ALT_MODIFIER:
- UsbKeyboardDevice->RightAltOn = 0;
- UsbKeyboardDevice->AltOn = 0;
+ UsbKeyboardDevice->RightAltOn = FALSE;
+ UsbKeyboardDevice->AltOn = FALSE;
break;
//
// Left Logo release
//
case EFI_LEFT_LOGO_MODIFIER:
- UsbKeyboardDevice->LeftLogoOn = 0;
+ UsbKeyboardDevice->LeftLogoOn = FALSE;
break;
//
// Right Logo release
//
case EFI_RIGHT_LOGO_MODIFIER:
- UsbKeyboardDevice->RightLogoOn = 0;
+ UsbKeyboardDevice->RightLogoOn = FALSE;
break;
//
// Menu key release
//
case EFI_MENU_MODIFIER:
- UsbKeyboardDevice->MenuKeyOn = 0;
+ UsbKeyboardDevice->MenuKeyOn = FALSE;
break;
//
@@ -1338,14 +1368,14 @@ USBParseKey (
//
case EFI_PRINT_MODIFIER:
case EFI_SYS_REQUEST_MODIFIER:
- UsbKeyboardDevice->SysReqOn = 0;
+ UsbKeyboardDevice->SysReqOn = FALSE;
break;
//
// AltGr release
//
case EFI_ALT_GR_MODIFIER:
- UsbKeyboardDevice->AltGrOn = 0;
+ UsbKeyboardDevice->AltGrOn = FALSE;
break;
default:
@@ -1361,16 +1391,16 @@ USBParseKey (
switch (KeyDescriptor->Modifier) {
//
- // CTRL press
+ // Ctrl press
//
case EFI_LEFT_CONTROL_MODIFIER:
- UsbKeyboardDevice->LeftCtrlOn = 1;
- UsbKeyboardDevice->CtrlOn = 1;
+ UsbKeyboardDevice->LeftCtrlOn = TRUE;
+ UsbKeyboardDevice->CtrlOn = TRUE;
continue;
break;
case EFI_RIGHT_CONTROL_MODIFIER:
- UsbKeyboardDevice->RightCtrlOn = 1;
- UsbKeyboardDevice->CtrlOn = 1;
+ UsbKeyboardDevice->RightCtrlOn = TRUE;
+ UsbKeyboardDevice->CtrlOn = TRUE;
continue;
break;
@@ -1378,13 +1408,13 @@ USBParseKey (
// Shift press
//
case EFI_LEFT_SHIFT_MODIFIER:
- UsbKeyboardDevice->LeftShiftOn = 1;
- UsbKeyboardDevice->ShiftOn = 1;
+ UsbKeyboardDevice->LeftShiftOn = TRUE;
+ UsbKeyboardDevice->ShiftOn = TRUE;
continue;
break;
case EFI_RIGHT_SHIFT_MODIFIER:
- UsbKeyboardDevice->RightShiftOn = 1;
- UsbKeyboardDevice->ShiftOn = 1;
+ UsbKeyboardDevice->RightShiftOn = TRUE;
+ UsbKeyboardDevice->ShiftOn = TRUE;
continue;
break;
@@ -1392,13 +1422,13 @@ USBParseKey (
// Alt press
//
case EFI_LEFT_ALT_MODIFIER:
- UsbKeyboardDevice->LeftAltOn = 1;
- UsbKeyboardDevice->AltOn = 1;
+ UsbKeyboardDevice->LeftAltOn = TRUE;
+ UsbKeyboardDevice->AltOn = TRUE;
continue;
break;
case EFI_RIGHT_ALT_MODIFIER:
- UsbKeyboardDevice->RightAltOn = 1;
- UsbKeyboardDevice->AltOn = 1;
+ UsbKeyboardDevice->RightAltOn = TRUE;
+ UsbKeyboardDevice->AltOn = TRUE;
continue;
break;
@@ -1406,21 +1436,21 @@ USBParseKey (
// Left Logo press
//
case EFI_LEFT_LOGO_MODIFIER:
- UsbKeyboardDevice->LeftLogoOn = 1;
+ UsbKeyboardDevice->LeftLogoOn = TRUE;
break;
//
// Right Logo press
//
case EFI_RIGHT_LOGO_MODIFIER:
- UsbKeyboardDevice->RightLogoOn = 1;
+ UsbKeyboardDevice->RightLogoOn = TRUE;
break;
//
// Menu key press
//
case EFI_MENU_MODIFIER:
- UsbKeyboardDevice->MenuKeyOn = 1;
+ UsbKeyboardDevice->MenuKeyOn = TRUE;
break;
//
@@ -1428,7 +1458,7 @@ USBParseKey (
//
case EFI_PRINT_MODIFIER:
case EFI_SYS_REQUEST_MODIFIER:
- UsbKeyboardDevice->SysReqOn = 1;
+ UsbKeyboardDevice->SysReqOn = TRUE;
continue;
break;
@@ -1436,32 +1466,32 @@ USBParseKey (
// AltGr press
//
case EFI_ALT_GR_MODIFIER:
- UsbKeyboardDevice->AltGrOn = 1;
+ UsbKeyboardDevice->AltGrOn = TRUE;
break;
case EFI_NUM_LOCK_MODIFIER:
- UsbKeyboardDevice->NumLockOn ^= 1;
//
- // Set the NumLock light on keyboard
+ // Toggle NumLock
//
+ UsbKeyboardDevice->NumLockOn = (BOOLEAN) (!(UsbKeyboardDevice->NumLockOn));
SetKeyLED (UsbKeyboardDevice);
continue;
break;
case EFI_CAPS_LOCK_MODIFIER:
- UsbKeyboardDevice->CapsOn ^= 1;
//
- // Set the CapsLock light on keyboard
+ // Toggle CapsLock
//
+ UsbKeyboardDevice->CapsOn = (BOOLEAN) (!(UsbKeyboardDevice->CapsOn));
SetKeyLED (UsbKeyboardDevice);
continue;
break;
case EFI_SCROLL_LOCK_MODIFIER:
- UsbKeyboardDevice->ScrollOn ^= 1;
//
- // Set the ScrollLock light on keyboard
+ // Toggle ScrollLock
//
+ UsbKeyboardDevice->ScrollOn = (BOOLEAN) (!(UsbKeyboardDevice->ScrollOn));
SetKeyLED (UsbKeyboardDevice);
continue;
break;
@@ -1488,12 +1518,12 @@ USBParseKey (
// When encountering Ctrl + Alt + Del, then warm reset.
//
if (KeyDescriptor->Modifier == EFI_DELETE_MODIFIER) {
- if ((UsbKeyboardDevice->CtrlOn != 0) && (UsbKeyboardDevice->AltOn != 0)) {
+ if ((UsbKeyboardDevice->CtrlOn) && (UsbKeyboardDevice->AltOn)) {
gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);
}
}
- *KeyChar = UsbKey.KeyCode;
+ *KeyCode = UsbKey.KeyCode;
return EFI_SUCCESS;
}
@@ -1502,43 +1532,41 @@ USBParseKey (
/**
- Converts USB Keyboard code to EFI_INPUT_KEY.
+ Converts USB Keycode ranging from 0x4 to 0x65 to EFI_INPUT_KEY.
- @param UsbKeyboardDevice The USB_KB_DEV instance.
- @param KeyChar Indicates the key code that will be interpreted.
- @param Key A pointer to a buffer that is filled in with
- the keystroke information for the key that
- was pressed.
+ @param UsbKeyboardDevice The USB_KB_DEV instance.
+ @param KeyCode Indicates the key code that will be interpreted.
+ @param Key A pointer to a buffer that is filled in with
+ the keystroke information for the key that
+ was pressed.
- @retval EFI_NOT_READY Device is not ready
- @retval EFI_SUCCESS Success.
+ @retval EFI_SUCCESS Success.
+ @retval EFI_INVALID_PARAMETER KeyCode is not in the range of 0x4 to 0x65.
+ @retval EFI_INVALID_PARAMETER Translated EFI_INPUT_KEY has zero for both ScanCode and UnicodeChar.
+ @retval EFI_NOT_READY KeyCode represents a dead key with EFI_NS_KEY_MODIFIER
**/
EFI_STATUS
EFIAPI
UsbKeyCodeToEfiInputKey (
IN USB_KB_DEV *UsbKeyboardDevice,
- IN UINT8 KeyChar,
+ IN UINT8 KeyCode,
OUT EFI_INPUT_KEY *Key
)
{
- UINT8 Index;
EFI_KEY_DESCRIPTOR *KeyDescriptor;
- if (!USBKBD_VALID_KEYCODE (KeyChar)) {
- return EFI_NOT_READY;
- }
-
//
- // Valid USB Key Code starts from 4, so it's safe to minus 4.
+ // KeyCode must in the range of 0x4 to 0x65
//
- Index = (UINT8) (KeyChar - 4);
-
- if (Index >= USB_KEYCODE_MAX_MAKE) {
- return EFI_NOT_READY;
+ if (!USBKBD_VALID_KEYCODE (KeyCode)) {
+ return EFI_INVALID_PARAMETER;
+ }
+ if ((KeyCode - 4) >= NUMBER_OF_VALID_NON_MODIFIER_USB_KEYCODE) {
+ return EFI_INVALID_PARAMETER;
}
- KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, KeyChar);
+ KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, KeyCode);
if (KeyDescriptor->Modifier == EFI_NS_KEY_MODIFIER) {
//
@@ -1557,11 +1585,11 @@ UsbKeyCodeToEfiInputKey (
UsbKeyboardDevice->CurrentNsKey = NULL;
}
- Key->ScanCode = EfiScanCodeConvertionTable[KeyDescriptor->Modifier];
+ Key->ScanCode = ModifierValueToEfiScanCodeConvertionTable[KeyDescriptor->Modifier];
Key->UnicodeChar = KeyDescriptor->Unicode;
if ((KeyDescriptor->AffectedAttribute & EFI_AFFECTED_BY_STANDARD_SHIFT)!= 0) {
- if (UsbKeyboardDevice->ShiftOn != 0) {
+ if (UsbKeyboardDevice->ShiftOn) {
Key->UnicodeChar = KeyDescriptor->ShiftedUnicode;
//
@@ -1569,11 +1597,11 @@ UsbKeyCodeToEfiInputKey (
// are normally adjusted by shift modifiers. e.g. Shift Key + 'f' key = 'F'
//
if ((KeyDescriptor->AffectedAttribute & EFI_AFFECTED_BY_CAPS_LOCK) != 0) {
- UsbKeyboardDevice->LeftShiftOn = 0;
- UsbKeyboardDevice->RightShiftOn = 0;
+ UsbKeyboardDevice->LeftShiftOn = FALSE;
+ UsbKeyboardDevice->RightShiftOn = FALSE;
}
- if (UsbKeyboardDevice->AltGrOn != 0) {
+ if (UsbKeyboardDevice->AltGrOn) {
Key->UnicodeChar = KeyDescriptor->ShiftedAltGrUnicode;
}
} else {
@@ -1582,23 +1610,18 @@ UsbKeyCodeToEfiInputKey (
//
Key->UnicodeChar = KeyDescriptor->Unicode;
- if (UsbKeyboardDevice->AltGrOn != 0) {
+ if (UsbKeyboardDevice->AltGrOn) {
Key->UnicodeChar = KeyDescriptor->AltGrUnicode;
}
}
}
if ((KeyDescriptor->AffectedAttribute & EFI_AFFECTED_BY_CAPS_LOCK) != 0) {
- if (UsbKeyboardDevice->CapsOn != 0) {
-
+ if (UsbKeyboardDevice->CapsOn) {
if (Key->UnicodeChar == KeyDescriptor->Unicode) {
-
Key->UnicodeChar = KeyDescriptor->ShiftedUnicode;
-
} else if (Key->UnicodeChar == KeyDescriptor->ShiftedUnicode) {
-
Key->UnicodeChar = KeyDescriptor->Unicode;
-
}
}
}
@@ -1607,7 +1630,7 @@ UsbKeyCodeToEfiInputKey (
// Translate the CTRL-Alpha characters to their corresponding control value
// (ctrl-a = 0x0001 through ctrl-Z = 0x001A)
//
- if (UsbKeyboardDevice->CtrlOn != 0) {
+ if (UsbKeyboardDevice->CtrlOn) {
if (Key->UnicodeChar >= 'a' && Key->UnicodeChar <= 'z') {
Key->UnicodeChar = (UINT8) (Key->UnicodeChar - 'a' + 1);
} else if (Key->UnicodeChar >= 'A' && Key->UnicodeChar <= 'Z') {
@@ -1621,7 +1644,7 @@ UsbKeyCodeToEfiInputKey (
// normal key, instead of original control key. So the ScanCode should be cleaned.
// Otherwise, it means control key, so preserve the EFI Scan Code and clear the unicode keycode.
//
- if ((UsbKeyboardDevice->NumLockOn != 0) && (UsbKeyboardDevice->ShiftOn == 0)) {
+ if ((UsbKeyboardDevice->NumLockOn) && (!(UsbKeyboardDevice->ShiftOn))) {
Key->ScanCode = SCAN_NULL;
} else {
Key->UnicodeChar = 0x00;
@@ -1647,44 +1670,44 @@ UsbKeyCodeToEfiInputKey (
//
// Save Shift/Toggle state
//
- if (UsbKeyboardDevice->LeftCtrlOn == 1) {
+ if (UsbKeyboardDevice->LeftCtrlOn) {
UsbKeyboardDevice->KeyState.KeyShiftState |= EFI_LEFT_CONTROL_PRESSED;
}
- if (UsbKeyboardDevice->RightCtrlOn == 1) {
+ if (UsbKeyboardDevice->RightCtrlOn) {
UsbKeyboardDevice->KeyState.KeyShiftState |= EFI_RIGHT_CONTROL_PRESSED;
}
- if (UsbKeyboardDevice->LeftAltOn == 1) {
+ if (UsbKeyboardDevice->LeftAltOn) {
UsbKeyboardDevice->KeyState.KeyShiftState |= EFI_LEFT_ALT_PRESSED;
}
- if (UsbKeyboardDevice->RightAltOn == 1) {
+ if (UsbKeyboardDevice->RightAltOn) {
UsbKeyboardDevice->KeyState.KeyShiftState |= EFI_RIGHT_ALT_PRESSED;
}
- if (UsbKeyboardDevice->LeftShiftOn == 1) {
+ if (UsbKeyboardDevice->LeftShiftOn) {
UsbKeyboardDevice->KeyState.KeyShiftState |= EFI_LEFT_SHIFT_PRESSED;
}
- if (UsbKeyboardDevice->RightShiftOn == 1) {
+ if (UsbKeyboardDevice->RightShiftOn) {
UsbKeyboardDevice->KeyState.KeyShiftState |= EFI_RIGHT_SHIFT_PRESSED;
}
- if (UsbKeyboardDevice->LeftLogoOn == 1) {
+ if (UsbKeyboardDevice->LeftLogoOn) {
UsbKeyboardDevice->KeyState.KeyShiftState |= EFI_LEFT_LOGO_PRESSED;
}
- if (UsbKeyboardDevice->RightLogoOn == 1) {
+ if (UsbKeyboardDevice->RightLogoOn) {
UsbKeyboardDevice->KeyState.KeyShiftState |= EFI_RIGHT_LOGO_PRESSED;
}
- if (UsbKeyboardDevice->MenuKeyOn == 1) {
+ if (UsbKeyboardDevice->MenuKeyOn) {
UsbKeyboardDevice->KeyState.KeyShiftState |= EFI_MENU_KEY_PRESSED;
}
- if (UsbKeyboardDevice->SysReqOn == 1) {
+ if (UsbKeyboardDevice->SysReqOn) {
UsbKeyboardDevice->KeyState.KeyShiftState |= EFI_SYS_REQ_PRESSED;
}
- if (UsbKeyboardDevice->ScrollOn == 1) {
+ if (UsbKeyboardDevice->ScrollOn) {
UsbKeyboardDevice->KeyState.KeyToggleState |= EFI_SCROLL_LOCK_ACTIVE;
}
- if (UsbKeyboardDevice->NumLockOn == 1) {
+ if (UsbKeyboardDevice->NumLockOn) {
UsbKeyboardDevice->KeyState.KeyToggleState |= EFI_NUM_LOCK_ACTIVE;
}
- if (UsbKeyboardDevice->CapsOn == 1) {
+ if (UsbKeyboardDevice->CapsOn) {
UsbKeyboardDevice->KeyState.KeyToggleState |= EFI_CAPS_LOCK_ACTIVE;
}
@@ -1694,15 +1717,15 @@ UsbKeyCodeToEfiInputKey (
/**
- Resets USB Keyboard Buffer.
+ Resets USB keyboard buffer.
- @param KeyboardBuffer Points to the USB Keyboard Buffer.
+ @param KeyboardBuffer Points to the USB keyboard buffer.
**/
VOID
EFIAPI
InitUSBKeyBuffer (
- IN OUT USB_KB_BUFFER *KeyboardBuffer
+ OUT USB_KB_BUFFER *KeyboardBuffer
)
{
ZeroMem (KeyboardBuffer, sizeof (USB_KB_BUFFER));
@@ -1712,12 +1735,12 @@ InitUSBKeyBuffer (
/**
- Check whether USB Keyboard buffer is empty.
+ Check whether USB keyboard buffer is empty.
- @param KeyboardBuffer USB Keyboard Buffer.
+ @param KeyboardBuffer USB keyboard buffer
- @retval TRUE Key buffer is empty.
- @retval FALSE Key buffer is not empty.
+ @retval TRUE Keyboard buffer is empty.
+ @retval FALSE Keyboard buffer is not empty.
**/
BOOLEAN
@@ -1727,19 +1750,19 @@ IsUSBKeyboardBufferEmpty (
)
{
//
- // meet FIFO empty condition
+ // Meet FIFO empty condition
//
return (BOOLEAN) (KeyboardBuffer->BufferHead == KeyboardBuffer->BufferTail);
}
/**
- Check whether USB Keyboard buffer is full.
+ Check whether USB keyboard buffer is full.
- @param KeyboardBuffer USB Keyboard Buffer.
+ @param KeyboardBuffer USB keyboard buffer
- @retval TRUE Key buffer is full.
- @retval FALSE Key buffer is not full.
+ @retval TRUE Keyboard buffer is full.
+ @retval FALSE Keyboard buffer is not full.
**/
BOOLEAN
@@ -1753,11 +1776,12 @@ IsUSBKeyboardBufferFull (
/**
- Inserts a key code into keyboard buffer.
+ Inserts a keycode into keyboard buffer.
- @param KeyboardBuffer Points to the USB Keyboard Buffer.
- @param Key Key code
- @param Down Special key
+ @param KeyboardBuffer Points to the USB keyboard buffer.
+ @param Key Keycode to insert.
+ @param Down TRUE means key is pressed.
+ FALSE means key is released.
**/
VOID
@@ -1765,13 +1789,13 @@ EFIAPI
InsertKeyCode (
IN OUT USB_KB_BUFFER *KeyboardBuffer,
IN UINT8 Key,
- IN UINT8 Down
+ IN BOOLEAN Down
)
{
USB_KEY UsbKey;
//
- // if keyboard buffer is full, throw the
+ // If keyboard buffer is full, throw the
// first key out of the keyboard buffer.
//
if (IsUSBKeyboardBufferFull (KeyboardBuffer)) {
@@ -1789,12 +1813,12 @@ InsertKeyCode (
/**
- Pops a key code off from keyboard buffer.
+ Remove a keycode from keyboard buffer and return it.
- @param KeyboardBuffer Points to the USB Keyboard Buffer.
- @param UsbKey Points to the buffer that contains a usb key code.
+ @param KeyboardBuffer Points to the USB keyboard buffer.
+ @param UsbKey Points to the buffer that contains keycode for output.
- @retval EFI_SUCCESS Key code Successfully poped from keyboard buffer.
+ @retval EFI_SUCCESS Keycode successfully removed from keyboard buffer.
@retval EFI_DEVICE_ERROR Keyboard buffer is empty.
**/
@@ -1802,7 +1826,7 @@ EFI_STATUS
EFIAPI
RemoveKeyCode (
IN OUT USB_KB_BUFFER *KeyboardBuffer,
- OUT USB_KEY *UsbKey
+ OUT USB_KEY *UsbKey
)
{
if (IsUSBKeyboardBufferEmpty (KeyboardBuffer)) {
@@ -1822,7 +1846,7 @@ RemoveKeyCode (
/**
- Sets USB Keyboard LED state.
+ Sets USB keyboard LED state.
@param UsbKeyboardDevice The USB_KB_DEV instance.
@@ -1839,9 +1863,9 @@ SetKeyLED (
//
// Set each field in Led map.
//
- Led.NumLock = (UINT8) UsbKeyboardDevice->NumLockOn;
- Led.CapsLock = (UINT8) UsbKeyboardDevice->CapsOn;
- Led.ScrollLock = (UINT8) UsbKeyboardDevice->ScrollOn;
+ Led.NumLock = (UINT8) ((UsbKeyboardDevice->NumLockOn) ? 1 : 0);
+ Led.CapsLock = (UINT8) ((UsbKeyboardDevice->CapsOn) ? 1 : 0);
+ Led.ScrollLock = (UINT8) ((UsbKeyboardDevice->ScrollOn) ? 1 : 0);
Led.Resrvd = 0;
ReportId = 0;
@@ -1860,7 +1884,13 @@ SetKeyLED (
/**
- Timer handler for Repeat Key timer.
+ Handler for Repeat Key event.
+
+ This function is the handler for Repeat Key event triggered
+ by timer.
+ After a repeatable key is pressed, the event would be triggered
+ with interval of USBKBD_REPEAT_DELAY. Once the event is triggered,
+ following trigger will come with interval of USBKBD_REPEAT_RATE.
@param Event The Repeat Key event.
@param Context Points to the USB_KB_DEV instance.
@@ -1882,12 +1912,12 @@ USBKeyboardRepeatHandler (
//
if (UsbKeyboardDevice->RepeatKey != 0) {
//
- // Inserts one Repeat key into keyboard buffer,
+ // Inserts the repeat key into keyboard buffer,
//
InsertKeyCode (
&(UsbKeyboardDevice->KeyboardBuffer),
UsbKeyboardDevice->RepeatKey,
- 1
+ TRUE
);
//
@@ -1903,7 +1933,13 @@ USBKeyboardRepeatHandler (
/**
- Timer handler for Delayed Recovery timer.
+ Handler for Delayed Recovery event.
+
+ This function is the handler for Delayed Recovery event triggered
+ by timer.
+ After a device error occurs, the event would be triggered
+ with interval of EFI_USB_INTERRUPT_DELAY. EFI_USB_INTERRUPT_DELAY
+ is defined in USB standard for error handling.
@param Event The Delayed Recovery event.
@param Context Points to the USB_KB_DEV instance.
diff --git a/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.h b/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.h
index dbf637f..0f43802 100644
--- a/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.h
+++ b/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.h
@@ -19,10 +19,12 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include "EfiKey.h"
/**
- Uses USB I/O to check whether the device is a USB Keyboard device.
+ Uses USB I/O to check whether the device is a USB keyboard device.
- @param UsbIo Points to a USB I/O protocol instance.
- @retval None
+ @param UsbIo Pointer to a USB I/O protocol instance.
+
+ @retval TRUE Device is a USB keyboard device.
+ @retval FALSE Device is a not USB keyboard device.
**/
BOOLEAN
@@ -32,37 +34,43 @@ IsUSBKeyboard (
);
/**
- Initialize USB Keyboard device and all private data structures.
+ Initialize USB keyboard device and all private data structures.
@param UsbKeyboardDevice The USB_KB_DEV instance.
@retval EFI_SUCCESS Initialization is successful.
- @retval EFI_DEVICE_ERROR Configure hardware failed.
+ @retval EFI_DEVICE_ERROR Keyboard initialization failed.
**/
EFI_STATUS
EFIAPI
InitUSBKeyboard (
- IN USB_KB_DEV *UsbKeyboardDevice
+ IN OUT USB_KB_DEV *UsbKeyboardDevice
);
/**
- Initialize USB Keyboard layout.
+ Initialize USB keyboard layout.
+
+ This function initializes Key Convertion Table for the USB keyboard device.
+ It first tries to retrieve layout from HII database. If failed and default
+ layout is enabled, then it just uses the default layout.
@param UsbKeyboardDevice The USB_KB_DEV instance.
- @retval EFI_SUCCESS Initialization Success.
- @retval Other Keyboard layout initial failed.
+ @retval EFI_SUCCESS Initialization succeeded.
+ @retval EFI_NOT_READY Keyboard layout cannot be retrieve from HII
+ database, and default layout is disabled.
+ @retval Other Fail to register event to EFI_HII_SET_KEYBOARD_LAYOUT_EVENT_GUID group.
**/
EFI_STATUS
EFIAPI
InitKeyboardLayout (
- IN USB_KB_DEV *UsbKeyboardDevice
+ OUT USB_KB_DEV *UsbKeyboardDevice
);
/**
- Destroy resources for Keyboard layout.
+ Destroy resources for keyboard layout.
@param UsbKeyboardDevice The USB_KB_DEV instance.
@@ -70,11 +78,16 @@ InitKeyboardLayout (
VOID
EFIAPI
ReleaseKeyboardLayoutResources (
- IN USB_KB_DEV *UsbKeyboardDevice
+ IN OUT USB_KB_DEV *UsbKeyboardDevice
);
/**
- Handler function for USB Keyboard's asynchronous interrupt transfer.
+ Handler function for USB keyboard's asynchronous interrupt transfer.
+
+ This function is the handler function for USB keyboard's asynchronous interrupt transfer
+ to manage the keyboard. It parses the USB keyboard input report, and inserts data to
+ keyboard buffer according to state of modifer keys and normal keys. Timer for repeat key
+ is also set accordingly.
@param Data A pointer to a buffer that is filled with key data which is
retrieved via asynchronous interrupt transfer.
@@ -82,8 +95,8 @@ ReleaseKeyboardLayoutResources (
@param Context Pointing to USB_KB_DEV instance.
@param Result Indicates the result of the asynchronous interrupt transfer.
- @retval EFI_SUCCESS Handler is successful.
- @retval EFI_DEVICE_ERROR Hardware Error
+ @retval EFI_SUCCESS Asynchronous interrupt transfer is handled successfully.
+ @retval EFI_DEVICE_ERROR Hardware error occurs.
**/
EFI_STATUS
@@ -96,12 +109,17 @@ KeyboardHandler (
);
/**
- Timer handler for Delayed Recovery timer.
+ Handler for Delayed Recovery event.
+
+ This function is the handler for Delayed Recovery event triggered
+ by timer.
+ After a device error occurs, the event would be triggered
+ with interval of EFI_USB_INTERRUPT_DELAY. EFI_USB_INTERRUPT_DELAY
+ is defined in USB standard for error handling.
@param Event The Delayed Recovery event.
@param Context Points to the USB_KB_DEV instance.
-
**/
VOID
EFIAPI
@@ -111,62 +129,67 @@ USBKeyboardRecoveryHandler (
);
/**
- Retrieves a key character after parsing the raw data in keyboard buffer.
+ Retrieves a USB keycode after parsing the raw data in keyboard buffer.
+
+ This function parses keyboard buffer. It updates state of modifier key for
+ USB_KB_DEV instancem, and returns keycode for output.
@param UsbKeyboardDevice The USB_KB_DEV instance.
- @param KeyChar Points to the Key character after key parsing.
+ @param KeyCode Pointer to the USB keycode for output.
- @retval EFI_SUCCESS Parse key is successful.
- @retval EFI_NOT_READY Device is not ready.
+ @retval EFI_SUCCESS Keycode successfully parsed.
+ @retval EFI_NOT_READY Keyboard buffer is not ready for a valid keycode
**/
EFI_STATUS
EFIAPI
USBParseKey (
IN OUT USB_KB_DEV *UsbKeyboardDevice,
- OUT UINT8 *KeyChar
+ OUT UINT8 *KeyCode
);
/**
- Converts USB Keyboard code to EFI Scan Code.
+ Converts USB Keycode ranging from 0x4 to 0x65 to EFI_INPUT_KEY.
- @param UsbKeyboardDevice The USB_KB_DEV instance.
- @param KeyChar Indicates the key code that will be interpreted.
- @param Key A pointer to a buffer that is filled in with
- the keystroke information for the key that
- was pressed.
+ @param UsbKeyboardDevice The USB_KB_DEV instance.
+ @param KeyCode Indicates the key code that will be interpreted.
+ @param Key A pointer to a buffer that is filled in with
+ the keystroke information for the key that
+ was pressed.
- @retval EFI_NOT_READY Device is not ready
- @retval EFI_SUCCESS Success.
+ @retval EFI_SUCCESS Success.
+ @retval EFI_INVALID_PARAMETER KeyCode is not in the range of 0x4 to 0x65.
+ @retval EFI_INVALID_PARAMETER Translated EFI_INPUT_KEY has zero for both ScanCode and UnicodeChar.
+ @retval EFI_NOT_READY KeyCode represents a dead key with EFI_NS_KEY_MODIFIER
**/
EFI_STATUS
EFIAPI
UsbKeyCodeToEfiInputKey (
IN USB_KB_DEV *UsbKeyboardDevice,
- IN UINT8 KeyChar,
+ IN UINT8 KeyCode,
OUT EFI_INPUT_KEY *Key
);
/**
- Resets USB Keyboard Buffer.
+ Resets USB keyboard buffer.
- @param KeyboardBuffer Points to the USB Keyboard Buffer.
+ @param KeyboardBuffer Points to the USB keyboard buffer.
**/
VOID
EFIAPI
InitUSBKeyBuffer (
- IN OUT USB_KB_BUFFER *KeyboardBuffer
+ OUT USB_KB_BUFFER *KeyboardBuffer
);
/**
- Check whether USB Keyboard buffer is empty.
+ Check whether USB keyboard buffer is empty.
- @param KeyboardBuffer USB Keyboard Buffer.
+ @param KeyboardBuffer USB keyboard buffer
- @retval TRUE Key buffer is empty.
- @retval FALSE Key buffer is not empty.
+ @retval TRUE Keyboard buffer is empty.
+ @retval FALSE Keyboard buffer is not empty.
**/
BOOLEAN
@@ -176,12 +199,12 @@ IsUSBKeyboardBufferEmpty (
);
/**
- Check whether USB Keyboard buffer is full.
+ Check whether USB keyboard buffer is full.
- @param KeyboardBuffer USB Keyboard Buffer.
+ @param KeyboardBuffer USB keyboard buffer
- @retval TRUE Key buffer is full.
- @retval FALSE Key buffer is not full.
+ @retval TRUE Keyboard buffer is full.
+ @retval FALSE Keyboard buffer is not full.
**/
BOOLEAN
@@ -191,11 +214,12 @@ IsUSBKeyboardBufferFull (
);
/**
- Inserts a key code into keyboard buffer.
+ Inserts a keycode into keyboard buffer.
- @param KeyboardBuffer Points to the USB Keyboard Buffer.
- @param Key Key code
- @param Down Special key
+ @param KeyboardBuffer Points to the USB keyboard buffer.
+ @param Key Keycode to insert.
+ @param Down TRUE means key is pressed.
+ FALSE means key is released.
**/
VOID
@@ -207,29 +231,34 @@ InsertKeyCode (
);
/**
- Pops a key code off from keyboard buffer.
+ Remove a keycode from keyboard buffer and return it.
- @param KeyboardBuffer Points to the USB Keyboard Buffer.
- @param UsbKey Points to the buffer that contains a usb key code.
+ @param KeyboardBuffer Points to the USB keyboard buffer.
+ @param UsbKey Points to the buffer that contains keycode for output.
- @retval EFI_SUCCESS Success
- @retval EFI_DEVICE_ERROR Hardware Error
+ @retval EFI_SUCCESS Keycode successfully removed from keyboard buffer.
+ @retval EFI_DEVICE_ERROR Keyboard buffer is empty.
**/
EFI_STATUS
EFIAPI
RemoveKeyCode (
IN OUT USB_KB_BUFFER *KeyboardBuffer,
- OUT USB_KEY *UsbKey
+ OUT USB_KEY *UsbKey
);
/**
- Timer handler for Repeat Key timer.
+ Handler for Repeat Key event.
+
+ This function is the handler for Repeat Key event triggered
+ by timer.
+ After a repeatable key is pressed, the event would be triggered
+ with interval of USBKBD_REPEAT_DELAY. Once the event is triggered,
+ following trigger will come with interval of USBKBD_REPEAT_RATE.
@param Event The Repeat Key event.
@param Context Points to the USB_KB_DEV instance.
-
**/
VOID
EFIAPI
@@ -239,7 +268,7 @@ USBKeyboardRepeatHandler (
);
/**
- Sets USB Keyboard LED state.
+ Sets USB keyboard LED state.
@param UsbKeyboardDevice The USB_KB_DEV instance.
diff --git a/MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf b/MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf
index f7ef162..5e84288 100644
--- a/MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf
+++ b/MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf
@@ -1,8 +1,8 @@
#/** @file
-# Component name for module UsbKb
+# USB Keyboard Driver that manages USB keyboard and produces Simple Text Input
+# Protocol and Simple Text Input Ex Protocol.
#
-# FIX ME!
-# Copyright (c) 2006, Intel Corporation.
+# Copyright (c) 2006 - 2008, 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