]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.h
1. Retired HotPlugDevice protocol.
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbKbDxe / EfiKey.h
1 /** @file
2 Header file for USB Keyboard Driver's Data Structures.
3
4 Copyright (c) 2004 - 2008, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14 #ifndef _EFI_USB_KB_H_
15 #define _EFI_USB_KB_H_
16
17
18 #include <Uefi.h>
19
20 #include <Protocol/SimpleTextIn.h>
21 #include <Protocol/SimpleTextInEx.h>
22 #include <Protocol/HiiDatabase.h>
23 #include <Protocol/UsbIo.h>
24 #include <Protocol/DevicePath.h>
25 #include <Protocol/SimpleTextInExNotify.h>
26
27 #include <Guid/HiiKeyBoardLayout.h>
28
29 #include <Library/DebugLib.h>
30 #include <Library/ReportStatusCodeLib.h>
31 #include <Library/BaseMemoryLib.h>
32 #include <Library/UefiRuntimeServicesTableLib.h>
33 #include <Library/UefiDriverEntryPoint.h>
34 #include <Library/UefiBootServicesTableLib.h>
35 #include <Library/UefiLib.h>
36 #include <Library/MemoryAllocationLib.h>
37 #include <Library/PcdLib.h>
38 #include <Library/UefiUsbLib.h>
39
40 #include <IndustryStandard/Usb.h>
41
42 #define MAX_KEY_ALLOWED 32
43
44 #define HZ 1000 * 1000 * 10
45 #define USBKBD_REPEAT_DELAY ((HZ) / 2)
46 #define USBKBD_REPEAT_RATE ((HZ) / 50)
47
48 #define CLASS_HID 3
49 #define SUBCLASS_BOOT 1
50 #define PROTOCOL_KEYBOARD 1
51
52 #define BOOT_PROTOCOL 0
53 #define REPORT_PROTOCOL 1
54
55 typedef struct {
56 BOOLEAN Down;
57 UINT8 KeyCode;
58 } USB_KEY;
59
60 typedef struct {
61 USB_KEY Buffer[MAX_KEY_ALLOWED + 1];
62 UINT8 BufferHead;
63 UINT8 BufferTail;
64 } USB_KB_BUFFER;
65
66 #define USB_KB_DEV_SIGNATURE SIGNATURE_32 ('u', 'k', 'b', 'd')
67 #define USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE SIGNATURE_32 ('u', 'k', 'b', 'x')
68
69 typedef struct _KEYBOARD_CONSOLE_IN_EX_NOTIFY {
70 UINTN Signature;
71 EFI_HANDLE NotifyHandle;
72 EFI_KEY_DATA KeyData;
73 EFI_KEY_NOTIFY_FUNCTION KeyNotificationFn;
74 LIST_ENTRY NotifyEntry;
75 } KEYBOARD_CONSOLE_IN_EX_NOTIFY;
76
77 #define USB_NS_KEY_SIGNATURE SIGNATURE_32 ('u', 'n', 's', 'k')
78
79 typedef struct {
80 UINTN Signature;
81 LIST_ENTRY Link;
82
83 //
84 // The number of EFI_NS_KEY_MODIFIER children definitions
85 //
86 UINTN KeyCount;
87
88 //
89 // NsKey[0] : Non-spacing key
90 // NsKey[1] ~ NsKey[KeyCount] : Physical keys
91 //
92 EFI_KEY_DESCRIPTOR *NsKey;
93 } USB_NS_KEY;
94
95 #define USB_NS_KEY_FORM_FROM_LINK(a) CR (a, USB_NS_KEY, Link, USB_NS_KEY_SIGNATURE)
96
97 ///
98 /// Structure to describe USB keyboard device
99 ///
100 typedef struct {
101 UINTN Signature;
102 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
103 EFI_EVENT DelayedRecoveryEvent;
104 EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleInput;
105 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL SimpleInputEx;
106 EFI_USB_IO_PROTOCOL *UsbIo;
107
108 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
109 EFI_USB_ENDPOINT_DESCRIPTOR IntEndpointDescriptor;
110
111 USB_KB_BUFFER KeyboardBuffer;
112 BOOLEAN CtrlOn;
113 BOOLEAN AltOn;
114 BOOLEAN ShiftOn;
115 BOOLEAN NumLockOn;
116 BOOLEAN CapsOn;
117 BOOLEAN ScrollOn;
118 UINT8 LastKeyCodeArray[8];
119 UINT8 CurKeyCode;
120
121 UINT8 RepeatKey;
122 EFI_EVENT RepeatTimer;
123
124 EFI_UNICODE_STRING_TABLE *ControllerNameTable;
125
126 BOOLEAN LeftCtrlOn;
127 BOOLEAN LeftAltOn;
128 BOOLEAN LeftShiftOn;
129 BOOLEAN LeftLogoOn;
130 BOOLEAN RightCtrlOn;
131 BOOLEAN RightAltOn;
132 BOOLEAN RightShiftOn;
133 BOOLEAN RightLogoOn;
134 BOOLEAN MenuKeyOn;
135 BOOLEAN SysReqOn;
136 BOOLEAN AltGrOn;
137
138 EFI_KEY_STATE KeyState;
139 //
140 // Notification function list
141 //
142 LIST_ENTRY NotifyList;
143
144 //
145 // Non-spacing key list
146 //
147 LIST_ENTRY NsKeyList;
148 USB_NS_KEY *CurrentNsKey;
149 EFI_KEY_DESCRIPTOR *KeyConvertionTable;
150 EFI_EVENT KeyboardLayoutEvent;
151 } USB_KB_DEV;
152
153 //
154 // Global Variables
155 //
156 extern EFI_DRIVER_BINDING_PROTOCOL gUsbKeyboardDriverBinding;
157 extern EFI_COMPONENT_NAME_PROTOCOL gUsbKeyboardComponentName;
158 extern EFI_COMPONENT_NAME2_PROTOCOL gUsbKeyboardComponentName2;
159
160 #define USB_KB_DEV_FROM_THIS(a) \
161 CR(a, USB_KB_DEV, SimpleInput, USB_KB_DEV_SIGNATURE)
162 #define TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS(a) \
163 CR(a, USB_KB_DEV, SimpleInputEx, USB_KB_DEV_SIGNATURE)
164
165 //
166 // According to Universal Serial Bus HID Usage Tables document ver 1.12,
167 // a Boot Keyboard should support the keycode range from 0x0 to 0x65 and 0xE0 to 0xE7.
168 // 0xE0 to 0xE7 are for modifier keys, and 0x0 to 0x3 are reserved for typical
169 // keyboard status or keyboard errors.
170 // So the number of valid non-modifier USB keycodes is 0x62, and the number of
171 // valid keycodes is 0x6A.
172 //
173 #define NUMBER_OF_VALID_NON_MODIFIER_USB_KEYCODE 0x62
174 #define NUMBER_OF_VALID_USB_KEYCODE 0x6A
175 //
176 // 0x0 to 0x3 are reserved for typical keyboard status or keyboard errors.
177 //
178 #define USBKBD_VALID_KEYCODE(Key) ((UINT8) (Key) > 3)
179
180 typedef struct {
181 UINT8 NumLock : 1;
182 UINT8 CapsLock : 1;
183 UINT8 ScrollLock : 1;
184 UINT8 Resrvd : 5;
185 } LED_MAP;
186
187 //
188 // Functions of Driver Binding Protocol
189 //
190 /**
191 Check whether USB keyboard driver supports this device.
192
193 @param This The USB keyboard driver binding protocol.
194 @param Controller The controller handle to check.
195 @param RemainingDevicePath The remaining device path.
196
197 @retval EFI_SUCCESS The driver supports this controller.
198 @retval other This device isn't supported.
199
200 **/
201 EFI_STATUS
202 EFIAPI
203 USBKeyboardDriverBindingSupported (
204 IN EFI_DRIVER_BINDING_PROTOCOL *This,
205 IN EFI_HANDLE Controller,
206 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
207 );
208
209 /**
210 Starts the keyboard device with this driver.
211
212 This function produces Simple Text Input Protocol and Simple Text Input Ex Protocol,
213 initializes the keyboard device, and submit Asynchronous Interrupt Transfer to manage
214 this keyboard device.
215
216 @param This The USB keyboard driver binding instance.
217 @param Controller Handle of device to bind driver to.
218 @param RemainingDevicePath Optional parameter use to pick a specific child
219 device to start.
220
221 @retval EFI_SUCCESS The controller is controlled by the usb keyboard driver.
222 @retval EFI_UNSUPPORTED No interrupt endpoint can be found.
223 @retval Other This controller cannot be started.
224
225 **/
226 EFI_STATUS
227 EFIAPI
228 USBKeyboardDriverBindingStart (
229 IN EFI_DRIVER_BINDING_PROTOCOL *This,
230 IN EFI_HANDLE Controller,
231 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
232 );
233
234 /**
235 Stop the USB keyboard device handled by this driver.
236
237 @param This The USB keyboard driver binding protocol.
238 @param Controller The controller to release.
239 @param NumberOfChildren The number of handles in ChildHandleBuffer.
240 @param ChildHandleBuffer The array of child handle.
241
242 @retval EFI_SUCCESS The device was stopped.
243 @retval EFI_UNSUPPORTED Simple Text In Protocol or Simple Text In Ex Protocol
244 is not installed on Controller.
245 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
246 @retval Others Fail to uninstall protocols attached on the device.
247
248 **/
249 EFI_STATUS
250 EFIAPI
251 USBKeyboardDriverBindingStop (
252 IN EFI_DRIVER_BINDING_PROTOCOL *This,
253 IN EFI_HANDLE Controller,
254 IN UINTN NumberOfChildren,
255 IN EFI_HANDLE *ChildHandleBuffer
256 );
257
258 //
259 // EFI Component Name Functions
260 //
261 /**
262 Retrieves a Unicode string that is the user readable name of the driver.
263
264 This function retrieves the user readable name of a driver in the form of a
265 Unicode string. If the driver specified by This has a user readable name in
266 the language specified by Language, then a pointer to the driver name is
267 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
268 by This does not support the language specified by Language,
269 then EFI_UNSUPPORTED is returned.
270
271 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
272 EFI_COMPONENT_NAME_PROTOCOL instance.
273 @param Language A pointer to a Null-terminated ASCII string
274 array indicating the language. This is the
275 language of the driver name that the caller is
276 requesting, and it must match one of the
277 languages specified in SupportedLanguages. The
278 number of languages supported by a driver is up
279 to the driver writer. Language is specified
280 in RFC 3066 or ISO 639-2 language code format.
281 @param DriverName A pointer to the Unicode string to return.
282 This Unicode string is the name of the
283 driver specified by This in the language
284 specified by Language.
285
286 @retval EFI_SUCCESS The Unicode string for the Driver specified by
287 This and the language specified by Language was
288 returned in DriverName.
289 @retval EFI_INVALID_PARAMETER Language is NULL.
290 @retval EFI_INVALID_PARAMETER DriverName is NULL.
291 @retval EFI_UNSUPPORTED The driver specified by This does not support
292 the language specified by Language.
293
294 **/
295 EFI_STATUS
296 EFIAPI
297 UsbKeyboardComponentNameGetDriverName (
298 IN EFI_COMPONENT_NAME_PROTOCOL *This,
299 IN CHAR8 *Language,
300 OUT CHAR16 **DriverName
301 );
302
303 /**
304 Retrieves a Unicode string that is the user readable name of the controller
305 that is being managed by a driver.
306
307 This function retrieves the user readable name of the controller specified by
308 ControllerHandle and ChildHandle in the form of a Unicode string. If the
309 driver specified by This has a user readable name in the language specified by
310 Language, then a pointer to the controller name is returned in ControllerName,
311 and EFI_SUCCESS is returned. If the driver specified by This is not currently
312 managing the controller specified by ControllerHandle and ChildHandle,
313 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
314 support the language specified by Language, then EFI_UNSUPPORTED is returned.
315
316 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
317 EFI_COMPONENT_NAME_PROTOCOL instance.
318 @param ControllerHandle The handle of a controller that the driver
319 specified by This is managing. This handle
320 specifies the controller whose name is to be
321 returned.
322 @param ChildHandle The handle of the child controller to retrieve
323 the name of. This is an optional parameter that
324 may be NULL. It will be NULL for device
325 drivers. It will also be NULL for a bus drivers
326 that wish to retrieve the name of the bus
327 controller. It will not be NULL for a bus
328 driver that wishes to retrieve the name of a
329 child controller.
330 @param Language A pointer to a Null-terminated ASCII string
331 array indicating the language. This is the
332 language of the driver name that the caller is
333 requesting, and it must match one of the
334 languages specified in SupportedLanguages. The
335 number of languages supported by a driver is up
336 to the driver writer. Language is specified in
337 RFC 3066 or ISO 639-2 language code format.
338 @param ControllerName A pointer to the Unicode string to return.
339 This Unicode string is the name of the
340 controller specified by ControllerHandle and
341 ChildHandle in the language specified by
342 Language from the point of view of the driver
343 specified by This.
344
345 @retval EFI_SUCCESS The Unicode string for the user readable name in
346 the language specified by Language for the
347 driver specified by This was returned in
348 DriverName.
349 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
350 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
351 EFI_HANDLE.
352 @retval EFI_INVALID_PARAMETER Language is NULL.
353 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
354 @retval EFI_UNSUPPORTED The driver specified by This is not currently
355 managing the controller specified by
356 ControllerHandle and ChildHandle.
357 @retval EFI_UNSUPPORTED The driver specified by This does not support
358 the language specified by Language.
359
360 **/
361 EFI_STATUS
362 EFIAPI
363 UsbKeyboardComponentNameGetControllerName (
364 IN EFI_COMPONENT_NAME_PROTOCOL *This,
365 IN EFI_HANDLE ControllerHandle,
366 IN EFI_HANDLE ChildHandle OPTIONAL,
367 IN CHAR8 *Language,
368 OUT CHAR16 **ControllerName
369 );
370
371 //
372 // Functions of Simple Text Input Protocol
373 //
374 /**
375 Reset the input device and optionaly run diagnostics
376
377 There are 2 types of reset for USB keyboard.
378 For non-exhaustive reset, only keyboard buffer is cleared.
379 For exhaustive reset, in addition to clearance of keyboard buffer, the hardware status
380 is also re-initialized.
381
382 @param This Protocol instance pointer.
383 @param ExtendedVerification Driver may perform diagnostics on reset.
384
385 @retval EFI_SUCCESS The device was reset.
386 @retval EFI_DEVICE_ERROR The device is not functioning properly and could not be reset.
387
388 **/
389 EFI_STATUS
390 EFIAPI
391 USBKeyboardReset (
392 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
393 IN BOOLEAN ExtendedVerification
394 );
395
396 /**
397 Reads the next keystroke from the input device.
398
399 @param This The EFI_SIMPLE_TEXT_INPUT_PROTOCOL instance.
400 @param Key A pointer to a buffer that is filled in with the keystroke
401 information for the key that was pressed.
402
403 @retval EFI_SUCCESS The keystroke information was returned.
404 @retval EFI_NOT_READY There was no keystroke data availiable.
405 @retval EFI_DEVICE_ERROR The keydtroke information was not returned due to
406 hardware errors.
407
408 **/
409 EFI_STATUS
410 EFIAPI
411 USBKeyboardReadKeyStroke (
412 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
413 OUT EFI_INPUT_KEY *Key
414 );
415
416 //
417 // Simple Text Input Ex protocol functions
418 //
419 /**
420 Resets the input device hardware.
421
422 The Reset() function resets the input device hardware. As part
423 of initialization process, the firmware/device will make a quick
424 but reasonable attempt to verify that the device is functioning.
425 If the ExtendedVerification flag is TRUE the firmware may take
426 an extended amount of time to verify the device is operating on
427 reset. Otherwise the reset operation is to occur as quickly as
428 possible. The hardware verification process is not defined by
429 this specification and is left up to the platform firmware or
430 driver to implement.
431
432 @param This A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance.
433
434 @param ExtendedVerification Indicates that the driver may perform a more exhaustive
435 verification operation of the device during reset.
436
437 @retval EFI_SUCCESS The device was reset.
438 @retval EFI_DEVICE_ERROR The device is not functioning correctly and could not be reset.
439
440 **/
441 EFI_STATUS
442 EFIAPI
443 USBKeyboardResetEx (
444 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
445 IN BOOLEAN ExtendedVerification
446 );
447
448 /**
449 Reads the next keystroke from the input device.
450
451 @param This Protocol instance pointer.
452 @param KeyData A pointer to a buffer that is filled in with the keystroke
453 state data for the key that was pressed.
454
455 @retval EFI_SUCCESS The keystroke information was returned.
456 @retval EFI_NOT_READY There was no keystroke data available.
457 @retval EFI_DEVICE_ERROR The keystroke information was not returned due to
458 hardware errors.
459 @retval EFI_INVALID_PARAMETER KeyData is NULL.
460
461 **/
462 EFI_STATUS
463 EFIAPI
464 USBKeyboardReadKeyStrokeEx (
465 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
466 OUT EFI_KEY_DATA *KeyData
467 );
468
469 /**
470 Set certain state for the input device.
471
472 @param This Protocol instance pointer.
473 @param KeyToggleState A pointer to the EFI_KEY_TOGGLE_STATE to set the
474 state for the input device.
475
476 @retval EFI_SUCCESS The device state was set appropriately.
477 @retval EFI_DEVICE_ERROR The device is not functioning correctly and could
478 not have the setting adjusted.
479 @retval EFI_UNSUPPORTED The device does not support the ability to have its state set.
480 @retval EFI_INVALID_PARAMETER KeyToggleState is NULL.
481
482 **/
483 EFI_STATUS
484 EFIAPI
485 USBKeyboardSetState (
486 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
487 IN EFI_KEY_TOGGLE_STATE *KeyToggleState
488 );
489
490 /**
491 Register a notification function for a particular keystroke for the input device.
492
493 @param This Protocol instance pointer.
494 @param KeyData A pointer to a buffer that is filled in with the keystroke
495 information data for the key that was pressed.
496 @param KeyNotificationFunction Points to the function to be called when the key
497 sequence is typed specified by KeyData.
498 @param NotifyHandle Points to the unique handle assigned to the registered notification.
499
500 @retval EFI_SUCCESS The notification function was registered successfully.
501 @retval EFI_OUT_OF_RESOURCES Unable to allocate resources for necesssary data structures.
502 @retval EFI_INVALID_PARAMETER KeyData or NotifyHandle or KeyNotificationFunction is NULL.
503
504 **/
505 EFI_STATUS
506 EFIAPI
507 USBKeyboardRegisterKeyNotify (
508 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
509 IN EFI_KEY_DATA *KeyData,
510 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction,
511 OUT EFI_HANDLE *NotifyHandle
512 );
513
514 /**
515 Remove a registered notification function from a particular keystroke.
516
517 @param This Protocol instance pointer.
518 @param NotificationHandle The handle of the notification function being unregistered.
519
520 @retval EFI_SUCCESS The notification function was unregistered successfully.
521 @retval EFI_INVALID_PARAMETER The NotificationHandle is invalid
522 @retval EFI_NOT_FOUND Cannot find the matching entry in database.
523
524 **/
525 EFI_STATUS
526 EFIAPI
527 USBKeyboardUnregisterKeyNotify (
528 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
529 IN EFI_HANDLE NotificationHandle
530 );
531
532 /**
533 Event notification function registered for EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx
534 and EFI_SIMPLE_TEXT_INPUT_PROTOCOL.WaitForKey.
535
536 @param Event Event to be signaled when a key is pressed.
537 @param Context Points to USB_KB_DEV instance.
538
539 **/
540 VOID
541 EFIAPI
542 USBKeyboardWaitForKey (
543 IN EFI_EVENT Event,
544 IN VOID *Context
545 );
546
547 /**
548 Free keyboard notify list.
549
550 @param NotifyList The keyboard notify list to free.
551
552 @retval EFI_SUCCESS Free the notify list successfully.
553 @retval EFI_INVALID_PARAMETER NotifyList is NULL.
554
555 **/
556 EFI_STATUS
557 EFIAPI
558 KbdFreeNotifyList (
559 IN OUT LIST_ENTRY *NotifyList
560 );
561
562 /**
563 Check whether there is key pending in the keyboard buffer.
564
565 @param UsbKeyboardDevice The USB_KB_DEV instance.
566
567 @retval EFI_SUCCESS There is pending key to read.
568 @retval EFI_NOT_READY No pending key to read.
569
570 **/
571 EFI_STATUS
572 EFIAPI
573 USBKeyboardCheckForKey (
574 IN OUT USB_KB_DEV *UsbKeyboardDevice
575 );
576
577 /**
578 Check whether the pressed key matches a registered key or not.
579
580 @param RegsiteredData A pointer to keystroke data for the key that was registered.
581 @param InputData A pointer to keystroke data for the key that was pressed.
582
583 @retval TRUE Key pressed matches a registered key.
584 @retval FLASE Key pressed does not matche a registered key.
585
586 **/
587 BOOLEAN
588 EFIAPI
589 IsKeyRegistered (
590 IN EFI_KEY_DATA *RegsiteredData,
591 IN EFI_KEY_DATA *InputData
592 );
593
594 #endif
595