]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.h
Code Scrub for UsbKbDxe module.
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbKbDxe / EfiKey.h
CommitLineData
ed838d0c 1/** @file\r
5899f27e 2 Header file for USB Keyboard Driver's Data Structures.\r
a7022cec 3\r
813acf3a 4Copyright (c) 2004 - 2008, Intel Corporation\r
ed838d0c 5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
ed838d0c 13**/\r
a7022cec 14#ifndef _EFI_USB_KB_H_\r
15#define _EFI_USB_KB_H_\r
ed838d0c 16\r
ed7748fe 17\r
60c93673 18#include <Uefi.h>\r
ed7748fe 19\r
ed838d0c 20#include <Protocol/SimpleTextIn.h>\r
66aa04e4 21#include <Protocol/SimpleTextInEx.h>\r
813acf3a 22#include <Protocol/HiiDatabase.h>\r
ed838d0c 23#include <Protocol/UsbIo.h>\r
24#include <Protocol/DevicePath.h>\r
813acf3a 25#include <Guid/HiiKeyBoardLayout.h>\r
26#include <Guid/HotPlugDevice.h>\r
ed7748fe 27\r
ed838d0c 28#include <Library/DebugLib.h>\r
29#include <Library/ReportStatusCodeLib.h>\r
30#include <Library/BaseMemoryLib.h>\r
31#include <Library/UefiRuntimeServicesTableLib.h>\r
32#include <Library/UefiDriverEntryPoint.h>\r
33#include <Library/UefiBootServicesTableLib.h>\r
34#include <Library/UefiLib.h>\r
35#include <Library/MemoryAllocationLib.h>\r
36#include <Library/PcdLib.h>\r
dfb74df5 37#include <Library/UefiUsbLib.h>\r
66aa04e4 38#include <Library/BaseLib.h>\r
5899f27e 39#include <Library/UefiUsbLib.h>\r
ed838d0c 40\r
41#include <IndustryStandard/Usb.h>\r
42\r
43#define MAX_KEY_ALLOWED 32\r
44\r
45#define HZ 1000 * 1000 * 10\r
46#define USBKBD_REPEAT_DELAY ((HZ) / 2)\r
47#define USBKBD_REPEAT_RATE ((HZ) / 50)\r
48\r
49#define CLASS_HID 3\r
50#define SUBCLASS_BOOT 1\r
51#define PROTOCOL_KEYBOARD 1\r
52\r
53#define BOOT_PROTOCOL 0\r
54#define REPORT_PROTOCOL 1\r
55\r
56typedef struct {\r
57 UINT8 Down;\r
58 UINT8 KeyCode;\r
59} USB_KEY;\r
60\r
61typedef struct {\r
5899f27e 62 USB_KEY Buffer[MAX_KEY_ALLOWED + 1];\r
63 UINT8 BufferHead;\r
64 UINT8 BufferTail;\r
ed838d0c 65} USB_KB_BUFFER;\r
66\r
67#define USB_KB_DEV_SIGNATURE EFI_SIGNATURE_32 ('u', 'k', 'b', 'd')\r
66aa04e4 68#define USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE EFI_SIGNATURE_32 ('u', 'k', 'b', 'x')\r
69\r
70typedef struct _KEYBOARD_CONSOLE_IN_EX_NOTIFY {\r
71 UINTN Signature;\r
72 EFI_HANDLE NotifyHandle;\r
73 EFI_KEY_DATA KeyData;\r
74 EFI_KEY_NOTIFY_FUNCTION KeyNotificationFn;\r
75 LIST_ENTRY NotifyEntry;\r
76} KEYBOARD_CONSOLE_IN_EX_NOTIFY;\r
813acf3a 77\r
78#define USB_NS_KEY_SIGNATURE EFI_SIGNATURE_32 ('u', 'n', 's', 'k')\r
79\r
80typedef struct {\r
81 UINTN Signature;\r
82 LIST_ENTRY Link;\r
83\r
84 //\r
85 // The number of EFI_NS_KEY_MODIFIER children definitions\r
86 //\r
87 UINTN KeyCount;\r
88\r
89 //\r
90 // NsKey[0] : Non-spacing key\r
91 // NsKey[1] ~ NsKey[KeyCount] : Physical keys\r
92 //\r
93 EFI_KEY_DESCRIPTOR *NsKey;\r
94} USB_NS_KEY;\r
95\r
96#define USB_NS_KEY_FORM_FROM_LINK(a) CR (a, USB_NS_KEY, Link, USB_NS_KEY_SIGNATURE)\r
97\r
5899f27e 98///\r
99/// Structure to describe USB keyboard device\r
100///\r
ed838d0c 101typedef struct {\r
5899f27e 102 UINTN Signature;\r
103 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
104 EFI_EVENT DelayedRecoveryEvent;\r
105 EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleInput;\r
66aa04e4 106 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL SimpleInputEx;\r
5899f27e 107 EFI_USB_IO_PROTOCOL *UsbIo;\r
ed838d0c 108\r
5899f27e 109 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;\r
110 EFI_USB_ENDPOINT_DESCRIPTOR IntEndpointDescriptor;\r
ed838d0c 111\r
5899f27e 112 USB_KB_BUFFER KeyboardBuffer;\r
113 UINT8 CtrlOn;\r
114 UINT8 AltOn;\r
115 UINT8 ShiftOn;\r
116 UINT8 NumLockOn;\r
117 UINT8 CapsOn;\r
118 UINT8 ScrollOn;\r
119 UINT8 LastKeyCodeArray[8];\r
120 UINT8 CurKeyChar;\r
ed838d0c 121\r
5899f27e 122 UINT8 RepeatKey;\r
123 EFI_EVENT RepeatTimer;\r
ed838d0c 124\r
5899f27e 125 EFI_UNICODE_STRING_TABLE *ControllerNameTable;\r
66aa04e4 126 \r
5899f27e 127 UINT8 LeftCtrlOn;\r
128 UINT8 LeftAltOn;\r
129 UINT8 LeftShiftOn;\r
130 UINT8 LeftLogoOn;\r
131 UINT8 RightCtrlOn;\r
132 UINT8 RightAltOn;\r
133 UINT8 RightShiftOn;\r
134 UINT8 RightLogoOn; \r
135 UINT8 MenuKeyOn;\r
136 UINT8 SysReqOn;\r
137 UINT8 AltGrOn;\r
138\r
139 EFI_KEY_STATE KeyState;\r
66aa04e4 140 //\r
141 // Notification function list\r
142 //\r
5899f27e 143 LIST_ENTRY NotifyList;\r
813acf3a 144\r
145 //\r
146 // Non-spacing key list\r
147 //\r
5899f27e 148 LIST_ENTRY NsKeyList;\r
149 USB_NS_KEY *CurrentNsKey;\r
150 EFI_KEY_DESCRIPTOR *KeyConvertionTable;\r
151 EFI_EVENT KeyboardLayoutEvent;\r
ed838d0c 152} USB_KB_DEV;\r
153\r
154//\r
155// Global Variables\r
156//\r
62b9bb55 157extern EFI_DRIVER_BINDING_PROTOCOL gUsbKeyboardDriverBinding;\r
158extern EFI_COMPONENT_NAME_PROTOCOL gUsbKeyboardComponentName;\r
159extern EFI_COMPONENT_NAME2_PROTOCOL gUsbKeyboardComponentName2;\r
66aa04e4 160extern EFI_GUID gSimpleTextInExNotifyGuid;\r
ed838d0c 161\r
ed838d0c 162#define USB_KB_DEV_FROM_THIS(a) \\r
163 CR(a, USB_KB_DEV, SimpleInput, USB_KB_DEV_SIGNATURE)\r
66aa04e4 164#define TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS(a) \\r
165 CR(a, USB_KB_DEV, SimpleInputEx, USB_KB_DEV_SIGNATURE)\r
166\r
ed838d0c 167\r
168#define MOD_CONTROL_L 0x01\r
169#define MOD_CONTROL_R 0x10\r
170#define MOD_SHIFT_L 0x02\r
171#define MOD_SHIFT_R 0x20\r
172#define MOD_ALT_L 0x04\r
173#define MOD_ALT_R 0x40\r
174#define MOD_WIN_L 0x08\r
175#define MOD_WIN_R 0x80\r
176\r
177typedef struct {\r
178 UINT8 Mask;\r
179 UINT8 Key;\r
180} KB_MODIFIER;\r
181\r
813acf3a 182#define USB_KEYCODE_MAX_MAKE 0x62\r
ed838d0c 183\r
184#define USBKBD_VALID_KEYCODE(key) ((UINT8) (key) > 3)\r
185\r
186typedef struct {\r
187 UINT8 NumLock : 1;\r
188 UINT8 CapsLock : 1;\r
189 UINT8 ScrollLock : 1;\r
190 UINT8 Resrvd : 5;\r
191} LED_MAP;\r
66aa04e4 192\r
5899f27e 193//\r
194// Functions of Driver Binding Protocol\r
195//\r
196/**\r
197 Check whether USB keyboard driver supports this device.\r
198\r
199 @param This The USB keyboard driver binding protocol.\r
200 @param Controller The controller handle to check.\r
201 @param RemainingDevicePath The remaining device path.\r
202\r
203 @retval EFI_SUCCESS The driver supports this controller.\r
204 @retval other This device isn't supported.\r
205\r
206**/\r
207EFI_STATUS\r
208EFIAPI\r
209USBKeyboardDriverBindingSupported (\r
210 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
211 IN EFI_HANDLE Controller,\r
212 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
213 );\r
214\r
215/**\r
216 Start running driver on the controller.\r
217\r
218 @param This The USB keyboard driver binding instance.\r
219 @param Controller Handle of device to bind driver to.\r
220 @param RemainingDevicePath Optional parameter use to pick a specific child\r
221 device to start.\r
222\r
223 @retval EFI_SUCCESS The controller is controlled by the usb keyboard driver.\r
224 @retval EFI_UNSUPPORTED No interrupt endpoint can be found.\r
225 @retval Other The keyboard driver cannot support this controller.\r
226\r
227**/\r
228EFI_STATUS\r
229EFIAPI\r
230USBKeyboardDriverBindingStart (\r
231 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
232 IN EFI_HANDLE Controller,\r
233 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
234 );\r
235\r
236/**\r
237 Stop handling the controller by this USB keyboard driver.\r
238\r
239 @param This The USB keyboard driver binding protocol.\r
240 @param Controller The controller to release.\r
241 @param NumberOfChildren The number of handles in ChildHandleBuffer.\r
242 @param ChildHandleBuffer The array of child handle.\r
243\r
244 @retval EFI_SUCCESS The controller or children are stopped.\r
245 @retval EFI_UNSUPPORTED Simple Text In Protocol or Simple Text In Ex Protocol\r
246 is not installed on Controller.\r
247 @retval EFI_DEVICE_ERROR Failed to stop the driver.\r
248\r
249**/\r
250EFI_STATUS\r
251EFIAPI\r
252USBKeyboardDriverBindingStop (\r
253 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
254 IN EFI_HANDLE Controller,\r
255 IN UINTN NumberOfChildren,\r
256 IN EFI_HANDLE *ChildHandleBuffer\r
257 );\r
258\r
259//\r
260// Functions of Simple Text Input Protocol\r
261//\r
262/**\r
263 Reset USB Keyboard.\r
264\r
265 There are 2 types of reset for USB keyboard.\r
266 For non-exhaustive reset, only keyboard buffer is cleared.\r
267 For exhaustive reset, in addition to clearance of keyboard buffer, the hardware status\r
268 is also re-initialized.\r
269\r
270 @param This The protocol instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL.\r
271 @param ExtendedVerification Indicates if exhaustive reset is used.\r
272 TRUE for exhaustive reset.\r
273 FALSE for non-exhaustive reset.\r
274\r
275 @retval EFI_SUCCESS Keyboard is reset successfully.\r
276 @retval EFI_DEVICE_ERROR Failed to reset keyboard.\r
277\r
278**/\r
279EFI_STATUS\r
280EFIAPI\r
281USBKeyboardReset (\r
282 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,\r
283 IN BOOLEAN ExtendedVerification\r
284 );\r
285\r
286/**\r
287 Implements EFI_SIMPLE_TEXT_INPUT_PROTOCOL.ReadKeyStroke() function.\r
288\r
289 @param This The EFI_SIMPLE_TEXT_INPUT_PROTOCOL instance.\r
290 @param Key A pointer to a buffer that is filled in with the keystroke\r
291 information for the key that was pressed.\r
292\r
293 @retval EFI_SUCCESS Read key stroke successfully.\r
294 @retval Other Read key stroke failed.\r
295\r
296**/\r
297EFI_STATUS\r
298EFIAPI\r
299USBKeyboardReadKeyStroke (\r
300 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,\r
301 OUT EFI_INPUT_KEY *Key\r
302 );\r
303\r
66aa04e4 304//\r
305// Simple Text Input Ex protocol functions\r
306//\r
a7022cec 307/**\r
308 The extension routine to reset the input device.\r
309\r
310 @param This Protocol instance pointer.\r
311 @param ExtendedVerification Driver may perform diagnostics on reset.\r
312\r
313 @retval EFI_SUCCESS The device was reset.\r
314 @retval EFI_DEVICE_ERROR The device is not functioning properly and could\r
315 not be reset.\r
316\r
317**/\r
66aa04e4 318EFI_STATUS\r
319EFIAPI\r
320USBKeyboardResetEx (\r
321 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
322 IN BOOLEAN ExtendedVerification\r
ed66e1bc 323 );\r
66aa04e4 324\r
a7022cec 325/**\r
326 Reads the next keystroke from the input device. The WaitForKey Event can\r
327 be used to test for existance of a keystroke via WaitForEvent () call.\r
66aa04e4 328\r
a7022cec 329 @param This Protocol instance pointer.\r
330 @param KeyData A pointer to a buffer that is filled in with the keystroke\r
331 state data for the key that was pressed.\r
66aa04e4 332\r
a7022cec 333 @return EFI_SUCCESS The keystroke information was returned successfully.\r
334 @retval EFI_INVALID_PARAMETER KeyData is NULL.\r
335 @retval Other Read key stroke information failed.\r
66aa04e4 336\r
a7022cec 337**/\r
66aa04e4 338EFI_STATUS\r
339EFIAPI\r
340USBKeyboardReadKeyStrokeEx (\r
341 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
342 OUT EFI_KEY_DATA *KeyData\r
ed66e1bc 343 );\r
66aa04e4 344\r
a7022cec 345/**\r
346 Set certain state for the input device.\r
66aa04e4 347\r
a7022cec 348 @param This Protocol instance pointer.\r
349 @param KeyToggleState A pointer to the EFI_KEY_TOGGLE_STATE to set the\r
350 state for the input device.\r
66aa04e4 351\r
a7022cec 352 @retval EFI_SUCCESS The device state was set successfully.\r
353 @retval EFI_UNSUPPORTED The device does not have the ability to set its state.\r
354 @retval EFI_INVALID_PARAMETER KeyToggleState is NULL.\r
66aa04e4 355\r
a7022cec 356**/\r
66aa04e4 357EFI_STATUS\r
358EFIAPI\r
359USBKeyboardSetState (\r
360 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
361 IN EFI_KEY_TOGGLE_STATE *KeyToggleState\r
ed66e1bc 362 );\r
66aa04e4 363\r
a7022cec 364/**\r
365 Register a notification function for a particular keystroke for the input device.\r
366\r
367 @param This Protocol instance pointer.\r
368 @param KeyData A pointer to a buffer that is filled in with the keystroke\r
369 information data for the key that was pressed.\r
370 @param KeyNotificationFunction Points to the function to be called when the key\r
371 sequence is typed specified by KeyData.\r
372 @param NotifyHandle Points to the unique handle assigned to the registered notification.\r
373\r
374 @retval EFI_SUCCESS The notification function was registered successfully.\r
375 @retval EFI_OUT_OF_RESOURCES Unable to allocate resources for necesssary data structures.\r
376 @retval EFI_INVALID_PARAMETER KeyData or NotifyHandle is NULL.\r
377\r
378**/\r
66aa04e4 379EFI_STATUS\r
380EFIAPI\r
381USBKeyboardRegisterKeyNotify (\r
382 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
383 IN EFI_KEY_DATA *KeyData,\r
384 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction,\r
385 OUT EFI_HANDLE *NotifyHandle\r
ed66e1bc 386 );\r
66aa04e4 387\r
a7022cec 388/**\r
389 Remove a registered notification function from a particular keystroke.\r
390\r
391 @param This Protocol instance pointer.\r
392 @param NotificationHandle The handle of the notification function being unregistered.\r
393\r
394 @retval EFI_SUCCESS The notification function was unregistered successfully.\r
395 @retval EFI_INVALID_PARAMETER The NotificationHandle is invalid or opening gSimpleTextInExNotifyGuid\r
396 on NotificationHandle fails.\r
397 @retval EFI_NOT_FOUND Can not find the matching entry in database.\r
398\r
399**/\r
66aa04e4 400EFI_STATUS\r
401EFIAPI\r
402USBKeyboardUnregisterKeyNotify (\r
403 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
404 IN EFI_HANDLE NotificationHandle\r
ed66e1bc 405 );\r
66aa04e4 406\r
5899f27e 407/**\r
408 Handler function for WaitForKey event.\r
409\r
410 @param Event Event to be signaled when a key is pressed.\r
411 @param Context Points to USB_KB_DEV instance.\r
412\r
413**/\r
414VOID\r
415EFIAPI\r
416USBKeyboardWaitForKey (\r
417 IN EFI_EVENT Event,\r
418 IN VOID *Context\r
419 );\r
420\r
421/**\r
422 Free keyboard notify list.\r
423\r
424 @param ListHead The list head.\r
425\r
426 @retval EFI_SUCCESS Free the notify list successfully.\r
427 @retval EFI_INVALID_PARAMETER ListHead is invalid.\r
428\r
429**/\r
430EFI_STATUS\r
431EFIAPI\r
432KbdFreeNotifyList (\r
433 IN OUT LIST_ENTRY *ListHead\r
434 );\r
435\r
436/**\r
437 Check whether there is key pending.\r
438\r
439 @param UsbKeyboardDevice The USB_KB_DEV instance.\r
440\r
441 @retval EFI_SUCCESS There is pending key to read.\r
442 @retval EFI_NOT_READY No pending key to read.\r
443\r
444**/\r
445EFI_STATUS\r
446EFIAPI\r
447USBKeyboardCheckForKey (\r
448 IN USB_KB_DEV *UsbKeyboardDevice\r
449 );\r
450\r
451/**\r
452 Whether the pressed key matches a registered key or not.\r
453\r
454 @param RegsiteredData A pointer to a buffer that is filled in with the keystroke\r
455 state data for the key that was registered.\r
456 @param InputData A pointer to a buffer that is filled in with the keystroke\r
457 state data for the key that was pressed.\r
458\r
459 @retval TRUE Key pressed matches a registered key.\r
460 @retval FLASE Match failed.\r
461\r
462**/\r
463BOOLEAN\r
464EFIAPI\r
465IsKeyRegistered (\r
466 IN EFI_KEY_DATA *RegsiteredData,\r
467 IN EFI_KEY_DATA *InputData\r
468 );\r
469\r
ed838d0c 470#endif\r
66aa04e4 471\r