3 Copyright (c) 2004 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
30 // Driver model protocol interface
34 USBKeyboardDriverBindingEntryPoint (
35 IN EFI_HANDLE ImageHandle
,
36 IN EFI_SYSTEM_TABLE
*SystemTable
41 USBKeyboardDriverBindingSupported (
42 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
43 IN EFI_HANDLE Controller
,
44 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
49 USBKeyboardDriverBindingStart (
50 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
51 IN EFI_HANDLE Controller
,
52 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
57 USBKeyboardDriverBindingStop (
58 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
59 IN EFI_HANDLE Controller
,
60 IN UINTN NumberOfChildren
,
61 IN EFI_HANDLE
*ChildHandleBuffer
65 // Simple Text In Protocol Interface
71 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
72 IN BOOLEAN ExtendedVerification
78 USBKeyboardReadKeyStroke (
79 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
80 OUT EFI_INPUT_KEY
*Key
86 USBKeyboardWaitForKey (
96 USBKeyboardCheckForKey (
97 IN USB_KB_DEV
*UsbKeyboardDevice
100 EFI_GUID gEfiUsbKeyboardDriverGuid
= {
101 0xa05f5f78, 0xfb3, 0x4d10, {0x90, 0x90, 0xac, 0x4, 0x6e, 0xeb, 0x7c, 0x3c}
106 IN OUT LIST_ENTRY
*ListHead
111 IN EFI_KEY_DATA
*RegsiteredData
,
112 IN EFI_KEY_DATA
*InputData
117 // USB Keyboard Driver Global Variables
119 EFI_DRIVER_BINDING_PROTOCOL gUsbKeyboardDriverBinding
= {
120 USBKeyboardDriverBindingSupported
,
121 USBKeyboardDriverBindingStart
,
122 USBKeyboardDriverBindingStop
,
130 USBKeyboardDriverBindingEntryPoint (
131 IN EFI_HANDLE ImageHandle
,
132 IN EFI_SYSTEM_TABLE
*SystemTable
140 ImageHandle - EFI_HANDLE
141 SystemTable - EFI_SYSTEM_TABLE
147 return EfiLibInstallDriverBindingComponentName2 (
150 &gUsbKeyboardDriverBinding
,
152 &gUsbKeyboardComponentName
,
153 &gUsbKeyboardComponentName2
162 @param This EFI_DRIVER_BINDING_PROTOCOL
163 @param Controller Controller handle
164 @param RemainingDevicePath EFI_DEVICE_PATH_PROTOCOL
170 USBKeyboardDriverBindingSupported (
171 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
172 IN EFI_HANDLE Controller
,
173 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
176 EFI_STATUS OpenStatus
;
177 EFI_USB_IO_PROTOCOL
*UsbIo
;
181 // Check if USB_IO protocol is attached on the controller handle.
183 OpenStatus
= gBS
->OpenProtocol (
185 &gEfiUsbIoProtocolGuid
,
187 This
->DriverBindingHandle
,
189 EFI_OPEN_PROTOCOL_BY_DRIVER
191 if (EFI_ERROR (OpenStatus
)) {
196 // Use the USB I/O protocol interface to check whether the Controller is
197 // the Keyboard controller that can be managed by this driver.
199 Status
= EFI_SUCCESS
;
201 if (!IsUSBKeyboard (UsbIo
)) {
202 Status
= EFI_UNSUPPORTED
;
207 &gEfiUsbIoProtocolGuid
,
208 This
->DriverBindingHandle
,
219 @param This EFI_DRIVER_BINDING_PROTOCOL
220 @param Controller Controller handle
221 @param RemainingDevicePath EFI_DEVICE_PATH_PROTOCOL
223 @retval EFI_SUCCESS Success
224 @retval EFI_OUT_OF_RESOURCES Can't allocate memory
225 @retval EFI_UNSUPPORTED The Start routine fail
230 USBKeyboardDriverBindingStart (
231 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
232 IN EFI_HANDLE Controller
,
233 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
237 EFI_USB_IO_PROTOCOL
*UsbIo
;
238 USB_KB_DEV
*UsbKeyboardDevice
;
239 UINT8 EndpointNumber
;
240 EFI_USB_ENDPOINT_DESCRIPTOR EndpointDescriptor
;
243 UINT8 PollingInterval
;
247 UsbKeyboardDevice
= NULL
;
251 // Open USB_IO Protocol
253 Status
= gBS
->OpenProtocol (
255 &gEfiUsbIoProtocolGuid
,
257 This
->DriverBindingHandle
,
259 EFI_OPEN_PROTOCOL_BY_DRIVER
261 if (EFI_ERROR (Status
)) {
265 UsbKeyboardDevice
= AllocateZeroPool (sizeof (USB_KB_DEV
));
266 if (UsbKeyboardDevice
== NULL
) {
269 &gEfiUsbIoProtocolGuid
,
270 This
->DriverBindingHandle
,
273 return EFI_OUT_OF_RESOURCES
;
276 // Get the Device Path Protocol on Controller's handle
278 Status
= gBS
->OpenProtocol (
280 &gEfiDevicePathProtocolGuid
,
281 (VOID
**) &UsbKeyboardDevice
->DevicePath
,
282 This
->DriverBindingHandle
,
284 EFI_OPEN_PROTOCOL_GET_PROTOCOL
287 if (EFI_ERROR (Status
)) {
288 gBS
->FreePool (UsbKeyboardDevice
);
291 &gEfiUsbIoProtocolGuid
,
292 This
->DriverBindingHandle
,
298 // Report that the usb keyboard is being enabled
300 KbdReportStatusCode (
301 UsbKeyboardDevice
->DevicePath
,
303 PcdGet32 (PcdStatusCodeValueKeyboardEnable
)
307 // This is pretty close to keyboard detection, so log progress
309 KbdReportStatusCode (
310 UsbKeyboardDevice
->DevicePath
,
312 PcdGet32 (PcdStatusCodeValueKeyboardPresenceDetect
)
316 // Initialize UsbKeyboardDevice
318 UsbKeyboardDevice
->UsbIo
= UsbIo
;
321 // Get interface & endpoint descriptor
323 UsbIo
->UsbGetInterfaceDescriptor (
325 &UsbKeyboardDevice
->InterfaceDescriptor
328 EndpointNumber
= UsbKeyboardDevice
->InterfaceDescriptor
.NumEndpoints
;
330 for (Index
= 0; Index
< EndpointNumber
; Index
++) {
332 UsbIo
->UsbGetEndpointDescriptor (
338 if ((EndpointDescriptor
.Attributes
& 0x03) == 0x03) {
340 // We only care interrupt endpoint here
342 CopyMem(&UsbKeyboardDevice
->IntEndpointDescriptor
, &EndpointDescriptor
, sizeof(EndpointDescriptor
));
349 // No interrupt endpoint found, then return unsupported.
351 gBS
->FreePool (UsbKeyboardDevice
);
354 &gEfiUsbIoProtocolGuid
,
355 This
->DriverBindingHandle
,
358 return EFI_UNSUPPORTED
;
361 UsbKeyboardDevice
->Signature
= USB_KB_DEV_SIGNATURE
;
362 UsbKeyboardDevice
->SimpleInput
.Reset
= USBKeyboardReset
;
363 UsbKeyboardDevice
->SimpleInput
.ReadKeyStroke
= USBKeyboardReadKeyStroke
;
365 UsbKeyboardDevice
->SimpleInputEx
.Reset
= USBKeyboardResetEx
;
366 UsbKeyboardDevice
->SimpleInputEx
.ReadKeyStrokeEx
= USBKeyboardReadKeyStrokeEx
;
367 UsbKeyboardDevice
->SimpleInputEx
.SetState
= USBKeyboardSetState
;
368 UsbKeyboardDevice
->SimpleInputEx
.RegisterKeyNotify
= USBKeyboardRegisterKeyNotify
;
369 UsbKeyboardDevice
->SimpleInputEx
.UnregisterKeyNotify
= USBKeyboardUnregisterKeyNotify
;
371 InitializeListHead (&UsbKeyboardDevice
->NotifyList
);
373 Status
= gBS
->CreateEvent (
376 USBKeyboardWaitForKey
,
378 &(UsbKeyboardDevice
->SimpleInputEx
.WaitForKeyEx
)
381 if (EFI_ERROR (Status
)) {
385 Status
= gBS
->CreateEvent (
388 USBKeyboardWaitForKey
,
390 &(UsbKeyboardDevice
->SimpleInput
.WaitForKey
)
393 if (EFI_ERROR (Status
)) {
394 gBS
->FreePool (UsbKeyboardDevice
);
397 &gEfiUsbIoProtocolGuid
,
398 This
->DriverBindingHandle
,
405 // Install simple txt in protocol interface
406 // for the usb keyboard device.
407 // Usb keyboard is a hot plug device, and expected to work immediately
408 // when plugging into system, so a HotPlugDeviceGuid is installed onto
409 // the usb keyboard device handle, to distinguish it from other conventional
412 Status
= gBS
->InstallMultipleProtocolInterfaces (
414 &gEfiSimpleTextInProtocolGuid
,
415 &UsbKeyboardDevice
->SimpleInput
,
416 &gEfiSimpleTextInputExProtocolGuid
,
417 &UsbKeyboardDevice
->SimpleInputEx
,
418 &gEfiHotPlugDeviceGuid
,
422 if (EFI_ERROR (Status
)) {
423 gBS
->CloseEvent (UsbKeyboardDevice
->SimpleInput
.WaitForKey
);
424 gBS
->FreePool (UsbKeyboardDevice
);
427 &gEfiUsbIoProtocolGuid
,
428 This
->DriverBindingHandle
,
435 // Reset USB Keyboard Device
437 Status
= UsbKeyboardDevice
->SimpleInput
.Reset (
438 &UsbKeyboardDevice
->SimpleInput
,
441 if (EFI_ERROR (Status
)) {
442 gBS
->UninstallMultipleProtocolInterfaces (
444 &gEfiSimpleTextInProtocolGuid
,
445 &UsbKeyboardDevice
->SimpleInput
,
446 &gEfiSimpleTextInputExProtocolGuid
,
447 &UsbKeyboardDevice
->SimpleInputEx
,
448 &gEfiHotPlugDeviceGuid
,
452 gBS
->CloseEvent (UsbKeyboardDevice
->SimpleInput
.WaitForKey
);
453 gBS
->FreePool (UsbKeyboardDevice
);
456 &gEfiUsbIoProtocolGuid
,
457 This
->DriverBindingHandle
,
463 // submit async interrupt transfer
465 EndpointAddr
= UsbKeyboardDevice
->IntEndpointDescriptor
.EndpointAddress
;
466 PollingInterval
= UsbKeyboardDevice
->IntEndpointDescriptor
.Interval
;
467 PacketSize
= (UINT8
) (UsbKeyboardDevice
->IntEndpointDescriptor
.MaxPacketSize
);
469 Status
= UsbIo
->UsbAsyncInterruptTransfer (
479 if (EFI_ERROR (Status
)) {
481 gBS
->UninstallMultipleProtocolInterfaces (
483 &gEfiSimpleTextInProtocolGuid
,
484 &UsbKeyboardDevice
->SimpleInput
,
485 &gEfiSimpleTextInputExProtocolGuid
,
486 &UsbKeyboardDevice
->SimpleInputEx
,
487 &gEfiHotPlugDeviceGuid
,
491 gBS
->CloseEvent (UsbKeyboardDevice
->SimpleInput
.WaitForKey
);
492 gBS
->FreePool (UsbKeyboardDevice
);
495 &gEfiUsbIoProtocolGuid
,
496 This
->DriverBindingHandle
,
502 UsbKeyboardDevice
->ControllerNameTable
= NULL
;
505 gUsbKeyboardComponentName
.SupportedLanguages
,
506 &UsbKeyboardDevice
->ControllerNameTable
,
507 L
"Generic Usb Keyboard",
512 gUsbKeyboardComponentName2
.SupportedLanguages
,
513 &UsbKeyboardDevice
->ControllerNameTable
,
514 L
"Generic Usb Keyboard",
522 if (UsbKeyboardDevice
!= NULL
) {
523 if (UsbKeyboardDevice
->SimpleInput
.WaitForKey
!= NULL
) {
524 gBS
->CloseEvent (UsbKeyboardDevice
->SimpleInput
.WaitForKey
);
526 if (UsbKeyboardDevice
->SimpleInputEx
.WaitForKeyEx
!= NULL
) {
527 gBS
->CloseEvent (UsbKeyboardDevice
->SimpleInputEx
.WaitForKeyEx
);
529 KbdFreeNotifyList (&UsbKeyboardDevice
->NotifyList
);
530 gBS
->FreePool (UsbKeyboardDevice
);
531 UsbKeyboardDevice
= NULL
;
535 &gEfiUsbIoProtocolGuid
,
536 This
->DriverBindingHandle
,
548 @param This EFI_DRIVER_BINDING_PROTOCOL
549 @param Controller Controller handle
550 @param NumberOfChildren Child handle number
551 @param ChildHandleBuffer Child handle buffer
553 @retval EFI_SUCCESS Success
554 @retval EFI_UNSUPPORTED Can't support
559 USBKeyboardDriverBindingStop (
560 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
561 IN EFI_HANDLE Controller
,
562 IN UINTN NumberOfChildren
,
563 IN EFI_HANDLE
*ChildHandleBuffer
567 EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*SimpleInput
;
568 USB_KB_DEV
*UsbKeyboardDevice
;
570 Status
= gBS
->OpenProtocol (
572 &gEfiSimpleTextInProtocolGuid
,
573 (VOID
**) &SimpleInput
,
574 This
->DriverBindingHandle
,
576 EFI_OPEN_PROTOCOL_GET_PROTOCOL
578 if (EFI_ERROR (Status
)) {
579 return EFI_UNSUPPORTED
;
581 Status
= gBS
->OpenProtocol (
583 &gEfiSimpleTextInputExProtocolGuid
,
585 This
->DriverBindingHandle
,
587 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
589 if (EFI_ERROR (Status
)) {
590 return EFI_UNSUPPORTED
;
593 // Get USB_KB_DEV instance.
595 UsbKeyboardDevice
= USB_KB_DEV_FROM_THIS (SimpleInput
);
599 &gEfiSimpleTextInProtocolGuid
,
600 This
->DriverBindingHandle
,
605 // Uninstall the Asyn Interrupt Transfer from this device
606 // will disable the key data input from this device
608 KbdReportStatusCode (
609 UsbKeyboardDevice
->DevicePath
,
611 PcdGet32 (PcdStatusCodeValueKeyboardDisable
)
615 // Destroy asynchronous interrupt transfer
617 UsbKeyboardDevice
->UsbIo
->UsbAsyncInterruptTransfer (
618 UsbKeyboardDevice
->UsbIo
,
619 UsbKeyboardDevice
->IntEndpointDescriptor
.EndpointAddress
,
621 UsbKeyboardDevice
->IntEndpointDescriptor
.Interval
,
629 &gEfiUsbIoProtocolGuid
,
630 This
->DriverBindingHandle
,
634 Status
= gBS
->UninstallMultipleProtocolInterfaces (
636 &gEfiSimpleTextInProtocolGuid
,
637 &UsbKeyboardDevice
->SimpleInput
,
638 &gEfiSimpleTextInputExProtocolGuid
,
639 &UsbKeyboardDevice
->SimpleInputEx
,
640 &gEfiHotPlugDeviceGuid
,
645 // free all the resources.
647 gBS
->CloseEvent (UsbKeyboardDevice
->RepeatTimer
);
648 gBS
->CloseEvent (UsbKeyboardDevice
->DelayedRecoveryEvent
);
649 gBS
->CloseEvent ((UsbKeyboardDevice
->SimpleInput
).WaitForKey
);
650 gBS
->CloseEvent (UsbKeyboardDevice
->SimpleInputEx
.WaitForKeyEx
);
651 KbdFreeNotifyList (&UsbKeyboardDevice
->NotifyList
);
653 if (UsbKeyboardDevice
->ControllerNameTable
!= NULL
) {
654 FreeUnicodeStringTable (UsbKeyboardDevice
->ControllerNameTable
);
657 gBS
->FreePool (UsbKeyboardDevice
);
665 USBKeyboardReadKeyStrokeWorker (
666 IN USB_KB_DEV
*UsbKeyboardDevice
,
667 OUT EFI_KEY_DATA
*KeyData
672 Reads the next keystroke from the input device. The WaitForKey Event can
673 be used to test for existance of a keystroke via WaitForEvent () call.
676 UsbKeyboardDevice - Usb keyboard private structure.
677 KeyData - A pointer to a buffer that is filled in with the keystroke
678 state data for the key that was pressed.
681 EFI_SUCCESS - The keystroke information was returned.
682 EFI_NOT_READY - There was no keystroke data availiable.
683 EFI_DEVICE_ERROR - The keystroke information was not returned due to
685 EFI_INVALID_PARAMETER - KeyData is NULL.
693 KEYBOARD_CONSOLE_IN_EX_NOTIFY
*CurrentNotify
;
694 EFI_KEY_DATA OriginalKeyData
;
696 if (KeyData
== NULL
) {
697 return EFI_INVALID_PARAMETER
;
701 // if there is no saved ASCII byte, fetch it
702 // by calling USBKeyboardCheckForKey().
704 if (UsbKeyboardDevice
->CurKeyChar
== 0) {
705 Status
= USBKeyboardCheckForKey (UsbKeyboardDevice
);
706 if (EFI_ERROR (Status
)) {
711 KeyData
->Key
.UnicodeChar
= 0;
712 KeyData
->Key
.ScanCode
= SCAN_NULL
;
714 KeyChar
= UsbKeyboardDevice
->CurKeyChar
;
716 UsbKeyboardDevice
->CurKeyChar
= 0;
719 // Translate saved ASCII byte into EFI_INPUT_KEY
721 Status
= USBKeyCodeToEFIScanCode (UsbKeyboardDevice
, KeyChar
, &KeyData
->Key
);
722 if (EFI_ERROR (Status
)) {
726 CopyMem (&KeyData
->KeyState
, &UsbKeyboardDevice
->KeyState
, sizeof (KeyData
->KeyState
));
728 UsbKeyboardDevice
->KeyState
.KeyShiftState
= EFI_SHIFT_STATE_VALID
;
729 UsbKeyboardDevice
->KeyState
.KeyToggleState
= EFI_TOGGLE_STATE_VALID
;
732 //Switch the control value to their original characters. In USBKeyCodeToEFIScanCode() the CTRL-Alpha characters have been switched to
733 // their corresponding control value (ctrl-a = 0x0001 through ctrl-Z = 0x001A), here switch them back for notification function.
735 CopyMem (&OriginalKeyData
, KeyData
, sizeof (EFI_KEY_DATA
));
736 if (UsbKeyboardDevice
->CtrlOn
) {
737 if (OriginalKeyData
.Key
.UnicodeChar
>= 0x01 && OriginalKeyData
.Key
.UnicodeChar
<= 0x1A) {
738 if (UsbKeyboardDevice
->CapsOn
) {
739 OriginalKeyData
.Key
.UnicodeChar
= (CHAR16
)(OriginalKeyData
.Key
.UnicodeChar
+ 'A' - 1);
741 OriginalKeyData
.Key
.UnicodeChar
= (CHAR16
)(OriginalKeyData
.Key
.UnicodeChar
+ 'a' - 1);
747 // Invoke notification functions if exist
749 for (Link
= UsbKeyboardDevice
->NotifyList
.ForwardLink
; Link
!= &UsbKeyboardDevice
->NotifyList
; Link
= Link
->ForwardLink
) {
752 KEYBOARD_CONSOLE_IN_EX_NOTIFY
,
754 USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE
756 if (IsKeyRegistered (&CurrentNotify
->KeyData
, &OriginalKeyData
)) {
757 CurrentNotify
->KeyNotificationFn (&OriginalKeyData
);
767 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
768 IN BOOLEAN ExtendedVerification
772 USB_KB_DEV
*UsbKeyboardDevice
;
774 UsbKeyboardDevice
= USB_KB_DEV_FROM_THIS (This
);
776 KbdReportStatusCode (
777 UsbKeyboardDevice
->DevicePath
,
779 PcdGet32 (PcdStatusCodeValueKeyboardReset
)
783 // Non Exhaustive reset:
784 // only reset private data structures.
786 if (!ExtendedVerification
) {
788 // Clear the key buffer of this Usb keyboard
790 KbdReportStatusCode (
791 UsbKeyboardDevice
->DevicePath
,
793 PcdGet32 (PcdStatusCodeValueKeyboardClearBuffer
)
796 InitUSBKeyBuffer (&(UsbKeyboardDevice
->KeyboardBuffer
));
797 UsbKeyboardDevice
->CurKeyChar
= 0;
804 Status
= InitUSBKeyboard (UsbKeyboardDevice
);
805 UsbKeyboardDevice
->CurKeyChar
= 0;
806 if (EFI_ERROR (Status
)) {
807 return EFI_DEVICE_ERROR
;
815 Implements EFI_SIMPLE_TEXT_INPUT_PROTOCOL.ReadKeyStroke() function.
817 This The EFI_SIMPLE_TEXT_INPUT_PROTOCOL instance.
818 Key A pointer to a buffer that is filled in with the keystroke
819 information for the key that was pressed.
821 @retval EFI_SUCCESS Success
827 USBKeyboardReadKeyStroke (
828 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
829 OUT EFI_INPUT_KEY
*Key
832 USB_KB_DEV
*UsbKeyboardDevice
;
834 EFI_KEY_DATA KeyData
;
836 UsbKeyboardDevice
= USB_KB_DEV_FROM_THIS (This
);
838 Status
= USBKeyboardReadKeyStrokeWorker (UsbKeyboardDevice
, &KeyData
);
839 if (EFI_ERROR (Status
)) {
843 CopyMem (Key
, &KeyData
.Key
, sizeof (EFI_INPUT_KEY
));
851 Handler function for WaitForKey event.
853 Event Event to be signaled when a key is pressed.
854 Context Points to USB_KB_DEV instance.
862 USBKeyboardWaitForKey (
867 USB_KB_DEV
*UsbKeyboardDevice
;
869 UsbKeyboardDevice
= (USB_KB_DEV
*) Context
;
871 if (UsbKeyboardDevice
->CurKeyChar
== 0) {
873 if (EFI_ERROR (USBKeyboardCheckForKey (UsbKeyboardDevice
))) {
878 // If has key pending, signal the event.
880 gBS
->SignalEvent (Event
);
886 Check whether there is key pending.
888 UsbKeyboardDevice The USB_KB_DEV instance.
890 @retval EFI_SUCCESS Success
895 USBKeyboardCheckForKey (
896 IN USB_KB_DEV
*UsbKeyboardDevice
903 // Fetch raw data from the USB keyboard input,
904 // and translate it into ASCII data.
906 Status
= USBParseKey (UsbKeyboardDevice
, &KeyChar
);
907 if (EFI_ERROR (Status
)) {
911 UsbKeyboardDevice
->CurKeyChar
= KeyChar
;
917 Report Status Code in Usb Bot Driver
919 @param DevicePath Use this to get Device Path
920 @param CodeType Status Code Type
921 @param CodeValue Status Code Value
927 KbdReportStatusCode (
928 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
929 IN EFI_STATUS_CODE_TYPE CodeType
,
930 IN EFI_STATUS_CODE_VALUE Value
934 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
943 IN OUT LIST_ENTRY
*ListHead
951 ListHead - The list head
955 EFI_SUCCESS - Free the notify list successfully
956 EFI_INVALID_PARAMETER - ListHead is invalid.
960 KEYBOARD_CONSOLE_IN_EX_NOTIFY
*NotifyNode
;
962 if (ListHead
== NULL
) {
963 return EFI_INVALID_PARAMETER
;
965 while (!IsListEmpty (ListHead
)) {
967 ListHead
->ForwardLink
,
968 KEYBOARD_CONSOLE_IN_EX_NOTIFY
,
970 USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE
972 RemoveEntryList (ListHead
->ForwardLink
);
973 gBS
->FreePool (NotifyNode
);
982 IN EFI_KEY_DATA
*RegsiteredData
,
983 IN EFI_KEY_DATA
*InputData
991 RegsiteredData - A pointer to a buffer that is filled in with the keystroke
992 state data for the key that was registered.
993 InputData - A pointer to a buffer that is filled in with the keystroke
994 state data for the key that was pressed.
997 TRUE - Key be pressed matches a registered key.
998 FLASE - Match failed.
1002 ASSERT (RegsiteredData
!= NULL
&& InputData
!= NULL
);
1004 if ((RegsiteredData
->Key
.ScanCode
!= InputData
->Key
.ScanCode
) ||
1005 (RegsiteredData
->Key
.UnicodeChar
!= InputData
->Key
.UnicodeChar
)) {
1010 // Assume KeyShiftState/KeyToggleState = 0 in Registered key data means these state could be ignored.
1012 if (RegsiteredData
->KeyState
.KeyShiftState
!= 0 &&
1013 RegsiteredData
->KeyState
.KeyShiftState
!= InputData
->KeyState
.KeyShiftState
) {
1016 if (RegsiteredData
->KeyState
.KeyToggleState
!= 0 &&
1017 RegsiteredData
->KeyState
.KeyToggleState
!= InputData
->KeyState
.KeyToggleState
) {
1026 // Simple Text Input Ex protocol functions
1030 USBKeyboardResetEx (
1031 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
1032 IN BOOLEAN ExtendedVerification
1036 Routine Description:
1037 Reset the input device and optionaly run diagnostics
1040 This - Protocol instance pointer.
1041 ExtendedVerification - Driver may perform diagnostics on reset.
1044 EFI_SUCCESS - The device was reset.
1045 EFI_DEVICE_ERROR - The device is not functioning properly and could
1051 USB_KB_DEV
*UsbKeyboardDevice
;
1055 UsbKeyboardDevice
= TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS (This
);
1057 Status
= UsbKeyboardDevice
->SimpleInput
.Reset (&UsbKeyboardDevice
->SimpleInput
, ExtendedVerification
);
1058 if (EFI_ERROR (Status
)) {
1059 return EFI_DEVICE_ERROR
;
1062 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1063 UsbKeyboardDevice
->KeyState
.KeyShiftState
= EFI_SHIFT_STATE_VALID
;
1064 UsbKeyboardDevice
->KeyState
.KeyToggleState
= EFI_TOGGLE_STATE_VALID
;
1065 gBS
->RestoreTPL (OldTpl
);
1073 USBKeyboardReadKeyStrokeEx (
1074 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
1075 OUT EFI_KEY_DATA
*KeyData
1079 Routine Description:
1080 Reads the next keystroke from the input device. The WaitForKey Event can
1081 be used to test for existance of a keystroke via WaitForEvent () call.
1084 This - Protocol instance pointer.
1085 KeyData - A pointer to a buffer that is filled in with the keystroke
1086 state data for the key that was pressed.
1089 EFI_SUCCESS - The keystroke information was returned.
1090 EFI_NOT_READY - There was no keystroke data availiable.
1091 EFI_DEVICE_ERROR - The keystroke information was not returned due to
1093 EFI_INVALID_PARAMETER - KeyData is NULL.
1097 USB_KB_DEV
*UsbKeyboardDevice
;
1099 if (KeyData
== NULL
) {
1100 return EFI_INVALID_PARAMETER
;
1103 UsbKeyboardDevice
= TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS (This
);
1105 return USBKeyboardReadKeyStrokeWorker (UsbKeyboardDevice
, KeyData
);
1111 USBKeyboardSetState (
1112 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
1113 IN EFI_KEY_TOGGLE_STATE
*KeyToggleState
1117 Routine Description:
1118 Set certain state for the input device.
1121 This - Protocol instance pointer.
1122 KeyToggleState - A pointer to the EFI_KEY_TOGGLE_STATE to set the
1123 state for the input device.
1126 EFI_SUCCESS - The device state was set successfully.
1127 EFI_DEVICE_ERROR - The device is not functioning correctly and could
1128 not have the setting adjusted.
1129 EFI_UNSUPPORTED - The device does not have the ability to set its state.
1130 EFI_INVALID_PARAMETER - KeyToggleState is NULL.
1134 USB_KB_DEV
*UsbKeyboardDevice
;
1136 if (KeyToggleState
== NULL
) {
1137 return EFI_INVALID_PARAMETER
;
1140 UsbKeyboardDevice
= TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS (This
);
1142 if (((UsbKeyboardDevice
->KeyState
.KeyToggleState
& EFI_TOGGLE_STATE_VALID
) != EFI_TOGGLE_STATE_VALID
) ||
1143 ((*KeyToggleState
& EFI_TOGGLE_STATE_VALID
) != EFI_TOGGLE_STATE_VALID
)) {
1144 return EFI_UNSUPPORTED
;
1148 // Update the status light
1151 UsbKeyboardDevice
->ScrollOn
= 0;
1152 UsbKeyboardDevice
->NumLockOn
= 0;
1153 UsbKeyboardDevice
->CapsOn
= 0;
1155 if ((*KeyToggleState
& EFI_SCROLL_LOCK_ACTIVE
) == EFI_SCROLL_LOCK_ACTIVE
) {
1156 UsbKeyboardDevice
->ScrollOn
= 1;
1158 if ((*KeyToggleState
& EFI_NUM_LOCK_ACTIVE
) == EFI_NUM_LOCK_ACTIVE
) {
1159 UsbKeyboardDevice
->NumLockOn
= 1;
1161 if ((*KeyToggleState
& EFI_CAPS_LOCK_ACTIVE
) == EFI_CAPS_LOCK_ACTIVE
) {
1162 UsbKeyboardDevice
->CapsOn
= 1;
1165 SetKeyLED (UsbKeyboardDevice
);
1167 UsbKeyboardDevice
->KeyState
.KeyToggleState
= *KeyToggleState
;
1175 USBKeyboardRegisterKeyNotify (
1176 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
1177 IN EFI_KEY_DATA
*KeyData
,
1178 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction
,
1179 OUT EFI_HANDLE
*NotifyHandle
1183 Routine Description:
1184 Register a notification function for a particular keystroke for the input device.
1187 This - Protocol instance pointer.
1188 KeyData - A pointer to a buffer that is filled in with the keystroke
1189 information data for the key that was pressed.
1190 KeyNotificationFunction - Points to the function to be called when the key
1191 sequence is typed specified by KeyData.
1192 NotifyHandle - Points to the unique handle assigned to the registered notification.
1195 EFI_SUCCESS - The notification function was registered successfully.
1196 EFI_OUT_OF_RESOURCES - Unable to allocate resources for necesssary data structures.
1197 EFI_INVALID_PARAMETER - KeyData or NotifyHandle is NULL.
1201 USB_KB_DEV
*UsbKeyboardDevice
;
1203 KEYBOARD_CONSOLE_IN_EX_NOTIFY
*NewNotify
;
1205 KEYBOARD_CONSOLE_IN_EX_NOTIFY
*CurrentNotify
;
1207 if (KeyData
== NULL
|| NotifyHandle
== NULL
|| KeyNotificationFunction
== NULL
) {
1208 return EFI_INVALID_PARAMETER
;
1211 UsbKeyboardDevice
= TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS (This
);
1214 // Return EFI_SUCCESS if the (KeyData, NotificationFunction) is already registered.
1216 for (Link
= UsbKeyboardDevice
->NotifyList
.ForwardLink
; Link
!= &UsbKeyboardDevice
->NotifyList
; Link
= Link
->ForwardLink
) {
1217 CurrentNotify
= CR (
1219 KEYBOARD_CONSOLE_IN_EX_NOTIFY
,
1221 USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE
1223 if (IsKeyRegistered (&CurrentNotify
->KeyData
, KeyData
)) {
1224 if (CurrentNotify
->KeyNotificationFn
== KeyNotificationFunction
) {
1225 *NotifyHandle
= CurrentNotify
->NotifyHandle
;
1232 // Allocate resource to save the notification function
1234 NewNotify
= (KEYBOARD_CONSOLE_IN_EX_NOTIFY
*) AllocateZeroPool (sizeof (KEYBOARD_CONSOLE_IN_EX_NOTIFY
));
1235 if (NewNotify
== NULL
) {
1236 return EFI_OUT_OF_RESOURCES
;
1239 NewNotify
->Signature
= USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE
;
1240 NewNotify
->KeyNotificationFn
= KeyNotificationFunction
;
1241 CopyMem (&NewNotify
->KeyData
, KeyData
, sizeof (EFI_KEY_DATA
));
1242 InsertTailList (&UsbKeyboardDevice
->NotifyList
, &NewNotify
->NotifyEntry
);
1245 // Use gSimpleTextInExNotifyGuid to get a valid EFI_HANDLE
1247 Status
= gBS
->InstallMultipleProtocolInterfaces (
1248 &NewNotify
->NotifyHandle
,
1249 &gSimpleTextInExNotifyGuid
,
1253 ASSERT_EFI_ERROR (Status
);
1255 *NotifyHandle
= NewNotify
->NotifyHandle
;
1263 USBKeyboardUnregisterKeyNotify (
1264 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
1265 IN EFI_HANDLE NotificationHandle
1269 Routine Description:
1270 Remove a registered notification function from a particular keystroke.
1273 This - Protocol instance pointer.
1274 NotificationHandle - The handle of the notification function being unregistered.
1277 EFI_SUCCESS - The notification function was unregistered successfully.
1278 EFI_INVALID_PARAMETER - The NotificationHandle is invalid.
1279 EFI_NOT_FOUND - Can not find the matching entry in database.
1283 USB_KB_DEV
*UsbKeyboardDevice
;
1285 KEYBOARD_CONSOLE_IN_EX_NOTIFY
*CurrentNotify
;
1288 if (NotificationHandle
== NULL
) {
1289 return EFI_INVALID_PARAMETER
;
1292 UsbKeyboardDevice
= TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS (This
);
1294 Status
= gBS
->OpenProtocol (
1296 &gSimpleTextInExNotifyGuid
,
1300 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
1302 if (EFI_ERROR (Status
)) {
1303 return EFI_INVALID_PARAMETER
;
1306 for (Link
= UsbKeyboardDevice
->NotifyList
.ForwardLink
; Link
!= &UsbKeyboardDevice
->NotifyList
; Link
= Link
->ForwardLink
) {
1307 CurrentNotify
= CR (
1309 KEYBOARD_CONSOLE_IN_EX_NOTIFY
,
1311 USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE
1313 if (CurrentNotify
->NotifyHandle
== NotificationHandle
) {
1315 // Remove the notification function from NotifyList and free resources
1317 RemoveEntryList (&CurrentNotify
->NotifyEntry
);
1318 Status
= gBS
->UninstallMultipleProtocolInterfaces (
1319 CurrentNotify
->NotifyHandle
,
1320 &gSimpleTextInExNotifyGuid
,
1324 ASSERT_EFI_ERROR (Status
);
1325 gBS
->FreePool (CurrentNotify
);
1330 return EFI_NOT_FOUND
;