OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
KeyBoard.c File Reference
#include "KeyBoard.h"
#include <IndustryStandard/AppleHid.h>
#include <Guid/UsbKeyBoardLayout.h>
#include <Library/ResetSystemLib.h>

Go to the source code of this file.

Functions

BOOLEAN IsUSBKeyboard (IN EFI_USB_IO_PROTOCOL *UsbIo)
 
EFI_KEY_DESCRIPTOR * GetKeyDescriptor (IN USB_KB_DEV *UsbKeyboardDevice, IN UINT8 KeyCode)
 
USB_NS_KEYFindUsbNsKey (IN USB_KB_DEV *UsbKeyboardDevice, IN EFI_KEY_DESCRIPTOR *KeyDescriptor)
 
EFI_KEY_DESCRIPTOR * FindPhysicalKey (IN USB_NS_KEY *UsbNsKey, IN EFI_KEY_DESCRIPTOR *KeyDescriptor)
 
VOID ReleaseKeyboardLayoutResources (IN OUT USB_KB_DEV *UsbKeyboardDevice)
 
EFI_STATUS InitKeyboardLayout (OUT USB_KB_DEV *UsbKeyboardDevice)
 
EFI_STATUS InitUSBKeyboard (IN OUT USB_KB_DEV *UsbKeyboardDevice)
 
EFI_STATUS EFIAPI KeyboardHandler (IN VOID *Data, IN UINTN DataLength, IN VOID *Context, IN UINT32 Result)
 
EFI_STATUS USBParseKey (IN OUT USB_KB_DEV *UsbKeyboardDevice, OUT UINT8 *KeyCode)
 
VOID InitializeKeyState (IN USB_KB_DEV *UsbKeyboardDevice, OUT EFI_KEY_STATE *KeyState)
 
EFI_STATUS UsbKeyCodeToEfiInputKey (IN USB_KB_DEV *UsbKeyboardDevice, IN UINT8 KeyCode, OUT EFI_KEY_DATA *KeyData)
 
VOID InitQueue (IN OUT USB_SIMPLE_QUEUE *Queue, IN UINTN ItemSize)
 
VOID DestroyQueue (IN OUT USB_SIMPLE_QUEUE *Queue)
 
BOOLEAN IsQueueEmpty (IN USB_SIMPLE_QUEUE *Queue)
 
BOOLEAN IsQueueFull (IN USB_SIMPLE_QUEUE *Queue)
 
VOID Enqueue (IN OUT USB_SIMPLE_QUEUE *Queue, IN VOID *Item, IN UINTN ItemSize)
 
EFI_STATUS Dequeue (IN OUT USB_SIMPLE_QUEUE *Queue, OUT VOID *Item, IN UINTN ItemSize)
 
VOID SetKeyLED (IN USB_KB_DEV *UsbKeyboardDevice)
 
VOID EFIAPI USBKeyboardRepeatHandler (IN EFI_EVENT Event, IN VOID *Context)
 
VOID EFIAPI USBKeyboardRecoveryHandler (IN EFI_EVENT Event, IN VOID *Context)
 

Variables

USB_KEYBOARD_LAYOUT_PACK_BIN mUsbKeyboardLayoutBin
 
UINT8 EfiKeyToUsbKeyCodeConvertionTable []
 
UINT8 ModifierValueToEfiScanCodeConvertionTable []
 

Detailed Description

Helper functions for USB Keyboard Driver.

Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.
Portions Copyright (c) 2016 - 2018, Download-Fritz. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file KeyBoard.c.

Function Documentation

◆ Dequeue()

EFI_STATUS Dequeue ( IN OUT USB_SIMPLE_QUEUE * Queue,
OUT VOID * Item,
IN UINTN ItemSize )

Dequeue a item from the queue.

Parameters
QueuePoints to the queue.
ItemReceives the item.
ItemSizeSize of the item.
Return values
EFI_SUCCESSItem was successfully dequeued.
EFI_DEVICE_ERRORThe queue is empty.

Definition at line 1683 of file KeyBoard.c.

◆ DestroyQueue()

VOID DestroyQueue ( IN OUT USB_SIMPLE_QUEUE * Queue)

Destroy the queue

Parameters
QueuePoints to the queue.

Definition at line 1596 of file KeyBoard.c.

◆ Enqueue()

VOID Enqueue ( IN OUT USB_SIMPLE_QUEUE * Queue,
IN VOID * Item,
IN UINTN ItemSize )

Enqueue the item to the queue.

Parameters
QueuePoints to the queue.
ItemPoints to the item to be enqueued.
ItemSizeSize of the item.

Definition at line 1648 of file KeyBoard.c.

◆ FindPhysicalKey()

EFI_KEY_DESCRIPTOR * FindPhysicalKey ( IN USB_NS_KEY * UsbNsKey,
IN EFI_KEY_DESCRIPTOR * KeyDescriptor )

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.

Parameters
UsbNsKeyThe non-spacing key information.
KeyDescriptorThe key descriptor.
Returns
The physical key definition. If no physical key is found, parameter KeyDescriptor is returned.

Definition at line 442 of file KeyBoard.c.

◆ FindUsbNsKey()

USB_NS_KEY * FindUsbNsKey ( IN USB_KB_DEV * UsbKeyboardDevice,
IN EFI_KEY_DESCRIPTOR * KeyDescriptor )

Find Non-Spacing key for given Key descriptor.

Parameters
UsbKeyboardDeviceThe USB_KB_DEV instance.
KeyDescriptorKey descriptor.
Returns
The Non-Spacing key corresponding to KeyDescriptor NULL means not found.

Definition at line 402 of file KeyBoard.c.

◆ GetKeyDescriptor()

EFI_KEY_DESCRIPTOR * GetKeyDescriptor ( IN USB_KB_DEV * UsbKeyboardDevice,
IN UINT8 KeyCode )

Find Key Descriptor in Key Convertion Table given its USB keycode.

Parameters
UsbKeyboardDeviceThe USB_KB_DEV instance.
KeyCodeUSB Keycode.
Returns
The Key Descriptor in Key Convertion Table. NULL means not found.

Definition at line 365 of file KeyBoard.c.

◆ InitializeKeyState()

VOID InitializeKeyState ( IN USB_KB_DEV * UsbKeyboardDevice,
OUT EFI_KEY_STATE * KeyState )

Initialize the key state.

Parameters
UsbKeyboardDeviceThe USB_KB_DEV instance.
KeyStateA pointer to receive the key state information.

Definition at line 1335 of file KeyBoard.c.

◆ InitKeyboardLayout()

EFI_STATUS InitKeyboardLayout ( OUT USB_KB_DEV * UsbKeyboardDevice)

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.

Parameters
UsbKeyboardDeviceThe USB_KB_DEV instance.
Return values
EFI_SUCCESSInitialization succeeded.
EFI_NOT_READYKeyboard layout cannot be retrieve from HII database, and default layout is disabled.
OtherFail to register event to EFI_HII_SET_KEYBOARD_LAYOUT_EVENT_GUID group.

Definition at line 515 of file KeyBoard.c.

◆ InitQueue()

VOID InitQueue ( IN OUT USB_SIMPLE_QUEUE * Queue,
IN UINTN ItemSize )

Create the queue.

Parameters
QueuePoints to the queue.
ItemSizeSize of the single item.

Definition at line 1567 of file KeyBoard.c.

◆ InitUSBKeyboard()

EFI_STATUS InitUSBKeyboard ( IN OUT USB_KB_DEV * UsbKeyboardDevice)

Initialize USB keyboard device and all private data structures.

Parameters
UsbKeyboardDeviceThe USB_KB_DEV instance.
Return values
EFI_SUCCESSInitialization is successful.
EFI_DEVICE_ERRORKeyboard initialization failed.

Definition at line 618 of file KeyBoard.c.

◆ IsQueueEmpty()

BOOLEAN IsQueueEmpty ( IN USB_SIMPLE_QUEUE * Queue)

Check whether the queue is empty.

Parameters
QueuePoints to the queue.
Return values
TRUEQueue is empty.
FALSEQueue is not empty.

Definition at line 1613 of file KeyBoard.c.

◆ IsQueueFull()

BOOLEAN IsQueueFull ( IN USB_SIMPLE_QUEUE * Queue)

Check whether the queue is full.

Parameters
QueuePoints to the queue.
Return values
TRUEQueue is full.
FALSEQueue is not full.

Definition at line 1633 of file KeyBoard.c.

◆ IsUSBKeyboard()

BOOLEAN IsUSBKeyboard ( IN EFI_USB_IO_PROTOCOL * UsbIo)

Uses USB I/O to check whether the device is a USB keyboard device.

Parameters
UsbIoPointer to a USB I/O protocol instance.
Return values
TRUEDevice is a USB keyboard device.
FALSEDevice is a not USB keyboard device.

Definition at line 324 of file KeyBoard.c.

◆ KeyboardHandler()

EFI_STATUS EFIAPI KeyboardHandler ( IN VOID * Data,
IN UINTN DataLength,
IN VOID * Context,
IN UINT32 Result )

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.

Parameters
DataA pointer to a buffer that is filled with key data which is retrieved via asynchronous interrupt transfer.
DataLengthIndicates the size of the data buffer.
ContextPointing to USB_KB_DEV instance.
ResultIndicates the result of the asynchronous interrupt transfer.
Return values
EFI_SUCCESSAsynchronous interrupt transfer is handled successfully.
EFI_DEVICE_ERRORHardware error occurs.

Definition at line 773 of file KeyBoard.c.

◆ ReleaseKeyboardLayoutResources()

VOID ReleaseKeyboardLayoutResources ( IN OUT USB_KB_DEV * UsbKeyboardDevice)

Destroy resources for keyboard layout.

Parameters
UsbKeyboardDeviceThe USB_KB_DEV instance.

Definition at line 472 of file KeyBoard.c.

◆ SetKeyLED()

VOID SetKeyLED ( IN USB_KB_DEV * UsbKeyboardDevice)

Sets USB keyboard LED state.

Parameters
UsbKeyboardDeviceThe USB_KB_DEV instance.

Definition at line 1712 of file KeyBoard.c.

◆ USBKeyboardRecoveryHandler()

VOID EFIAPI USBKeyboardRecoveryHandler ( IN EFI_EVENT Event,
IN VOID * Context )

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.

Parameters
EventThe Delayed Recovery event.
ContextPoints to the USB_KB_DEV instance.

Definition at line 1803 of file KeyBoard.c.

◆ USBKeyboardRepeatHandler()

VOID EFIAPI USBKeyboardRepeatHandler ( IN EFI_EVENT Event,
IN VOID * Context )

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.

Parameters
EventThe Repeat Key event.
ContextPoints to the USB_KB_DEV instance.

Definition at line 1756 of file KeyBoard.c.

◆ UsbKeyCodeToEfiInputKey()

EFI_STATUS UsbKeyCodeToEfiInputKey ( IN USB_KB_DEV * UsbKeyboardDevice,
IN UINT8 KeyCode,
OUT EFI_KEY_DATA * KeyData )

Converts USB Keycode ranging from 0x4 to 0x65 to EFI_INPUT_KEY.

Parameters
UsbKeyboardDeviceThe USB_KB_DEV instance.
KeyCodeIndicates the key code that will be interpreted.
KeyDataA pointer to a buffer that is filled in with the keystroke information for the key that was pressed.
Return values
EFI_SUCCESSSuccess.
EFI_INVALID_PARAMETERKeyCode is not in the range of 0x4 to 0x65.
EFI_INVALID_PARAMETERTranslated EFI_INPUT_KEY has zero for both ScanCode and UnicodeChar.
EFI_NOT_READYKeyCode represents a dead key with EFI_NS_KEY_MODIFIER
EFI_DEVICE_ERRORKeyboard layout is invalid.

Definition at line 1417 of file KeyBoard.c.

◆ USBParseKey()

EFI_STATUS USBParseKey ( IN OUT USB_KB_DEV * UsbKeyboardDevice,
OUT UINT8 * KeyCode )

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.

Parameters
UsbKeyboardDeviceThe USB_KB_DEV instance.
KeyCodePointer to the USB keycode for output.
Return values
EFI_SUCCESSKeycode successfully parsed.
EFI_NOT_READYKeyboard buffer is not ready for a valid keycode

Definition at line 1100 of file KeyBoard.c.

Variable Documentation

◆ EfiKeyToUsbKeyCodeConvertionTable

UINT8 EfiKeyToUsbKeyCodeConvertionTable[]

Definition at line 154 of file KeyBoard.c.

◆ ModifierValueToEfiScanCodeConvertionTable

UINT8 ModifierValueToEfiScanCodeConvertionTable[]

Definition at line 266 of file KeyBoard.c.

◆ mUsbKeyboardLayoutBin

USB_KEYBOARD_LAYOUT_PACK_BIN mUsbKeyboardLayoutBin

Definition at line 18 of file KeyBoard.c.