]> git.proxmox.com Git - mirror_edk2.git/blame - EmbeddedPkg/Drivers/VirtualKeyboardDxe/VirtualKeyboard.h
EmbeddedPkg: Apply uncrustify changes
[mirror_edk2.git] / EmbeddedPkg / Drivers / VirtualKeyboardDxe / VirtualKeyboard.h
CommitLineData
1df5fb2d
HZ
1/** @file\r
2\r
3Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
4Copyright (c) 2018, Linaro Ltd. All rights reserved.<BR>\r
5\r
878b807a 6SPDX-License-Identifier: BSD-2-Clause-Patent\r
1df5fb2d
HZ
7\r
8**/\r
9\r
10#ifndef _VIRTUAL_KEYBOARD_H_\r
11#define _VIRTUAL_KEYBOARD_H_\r
12\r
1df5fb2d
HZ
13#include <Guid/StatusCodeDataTypeId.h>\r
14#include <Protocol/DevicePath.h>\r
15#include <Protocol/PlatformVirtualKeyboard.h>\r
16#include <Protocol/SimpleTextIn.h>\r
17#include <Protocol/SimpleTextInEx.h>\r
18\r
19#include <Library/BaseLib.h>\r
20#include <Library/BaseMemoryLib.h>\r
21#include <Library/DebugLib.h>\r
22#include <Library/MemoryAllocationLib.h>\r
23#include <Library/IoLib.h>\r
24#include <Library/PcdLib.h>\r
25#include <Library/ReportStatusCodeLib.h>\r
26#include <Library/UefiBootServicesTableLib.h>\r
27#include <Library/UefiDriverEntryPoint.h>\r
28#include <Library/UefiLib.h>\r
29\r
30//\r
31// Driver Binding Externs\r
32//\r
e7108d0e
MK
33extern EFI_DRIVER_BINDING_PROTOCOL gVirtualKeyboardDriverBinding;\r
34extern EFI_COMPONENT_NAME_PROTOCOL gVirtualKeyboardComponentName;\r
35extern EFI_COMPONENT_NAME2_PROTOCOL gVirtualKeyboardComponentName2;\r
1df5fb2d
HZ
36\r
37//\r
38// VIRTUAL Keyboard Defines\r
39//\r
e7108d0e
MK
40#define CHAR_SCANCODE 0xe0\r
41#define CHAR_ESC 0x1b\r
1df5fb2d 42\r
e7108d0e
MK
43#define KEYBOARD_TIMEOUT 65536 // 0.07s\r
44#define KEYBOARD_WAITFORVALUE_TIMEOUT 1000000 // 1s\r
45#define KEYBOARD_BAT_TIMEOUT 4000000 // 4s\r
46#define KEYBOARD_TIMER_INTERVAL 500000 // 0.5s\r
1df5fb2d 47\r
e7108d0e 48#define QUEUE_MAX_COUNT 32\r
1df5fb2d 49\r
e7108d0e 50#define KEYBOARD_SCAN_CODE_MAX_COUNT 32\r
1df5fb2d
HZ
51\r
52//\r
53// VIRTUAL Keyboard Device Structure\r
54//\r
e7108d0e
MK
55#define VIRTUAL_KEYBOARD_DEV_SIGNATURE SIGNATURE_32 ('V', 'K', 'B', 'D')\r
56#define VIRTUAL_KEYBOARD_CONSOLE_IN_EX_NOTIFY_SIGNATURE SIGNATURE_32 ('v', 'k', 'c', 'n')\r
1df5fb2d
HZ
57\r
58typedef struct _VIRTUAL_KEYBOARD_CONSOLE_IN_EX_NOTIFY {\r
e7108d0e
MK
59 UINTN Signature;\r
60 EFI_KEY_DATA KeyData;\r
61 EFI_KEY_NOTIFY_FUNCTION KeyNotificationFn;\r
62 LIST_ENTRY NotifyEntry;\r
1df5fb2d
HZ
63} VIRTUAL_KEYBOARD_CONSOLE_IN_EX_NOTIFY;\r
64\r
65typedef struct {\r
e7108d0e
MK
66 UINTN Front;\r
67 UINTN Rear;\r
68 EFI_KEY_DATA Buffer[QUEUE_MAX_COUNT];\r
1df5fb2d
HZ
69} SIMPLE_QUEUE;\r
70\r
71typedef struct {\r
e7108d0e
MK
72 UINT8 Buffer[KEYBOARD_SCAN_CODE_MAX_COUNT];\r
73 UINTN Head;\r
74 UINTN Tail;\r
1df5fb2d
HZ
75} SCAN_CODE_QUEUE;\r
76\r
77typedef struct {\r
e7108d0e
MK
78 UINTN Signature;\r
79 EFI_HANDLE Handle;\r
80 PLATFORM_VIRTUAL_KBD_PROTOCOL *PlatformVirtual;\r
81 EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleTextIn;\r
82 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL SimpleTextInputEx;\r
1df5fb2d
HZ
83\r
84 //\r
85 // Buffer storing EFI_KEY_DATA\r
86 //\r
e7108d0e
MK
87 SIMPLE_QUEUE Queue;\r
88 SIMPLE_QUEUE QueueForNotify;\r
1df5fb2d
HZ
89\r
90 //\r
91 // Notification Function List\r
92 //\r
e7108d0e
MK
93 LIST_ENTRY NotifyList;\r
94 EFI_EVENT KeyNotifyProcessEvent;\r
95 EFI_EVENT TimerEvent;\r
1df5fb2d
HZ
96} VIRTUAL_KEYBOARD_DEV;\r
97\r
98#define VIRTUAL_KEYBOARD_DEV_FROM_THIS(a) CR (a, VIRTUAL_KEYBOARD_DEV, SimpleTextIn, VIRTUAL_KEYBOARD_DEV_SIGNATURE)\r
99#define TEXT_INPUT_EX_VIRTUAL_KEYBOARD_DEV_FROM_THIS(a) \\r
100 CR (a, \\r
101 VIRTUAL_KEYBOARD_DEV, \\r
102 SimpleTextInputEx, \\r
103 VIRTUAL_KEYBOARD_DEV_SIGNATURE \\r
104 )\r
105\r
106//\r
107// Global Variables\r
108//\r
e7108d0e 109extern EFI_DRIVER_BINDING_PROTOCOL gVirtualKeyboardDriverBinding;\r
1df5fb2d
HZ
110\r
111//\r
112// Driver Binding Protocol functions\r
113//\r
114\r
115/**\r
116 Check whether the driver supports this device.\r
117\r
118 @param This The Udriver binding protocol.\r
119 @param Controller The controller handle to check.\r
120 @param RemainingDevicePath The remaining device path.\r
121\r
122 @retval EFI_SUCCESS The driver supports this controller.\r
123 @retval other This device isn't supported.\r
124\r
125**/\r
126EFI_STATUS\r
127EFIAPI\r
128VirtualKeyboardDriverBindingSupported (\r
129 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
130 IN EFI_HANDLE Controller,\r
131 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
132 );\r
133\r
134/**\r
135 Starts the device with this driver.\r
136\r
137 @param This The driver binding instance.\r
138 @param Controller Handle of device to bind driver to.\r
139 @param RemainingDevicePath Optional parameter use to pick a specific child\r
140 device to start.\r
141\r
142 @retval EFI_SUCCESS The controller is controlled by the driver.\r
143 @retval Other This controller cannot be started.\r
144\r
145**/\r
146EFI_STATUS\r
147EFIAPI\r
148VirtualKeyboardDriverBindingStart (\r
149 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
150 IN EFI_HANDLE Controller,\r
151 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
152 );\r
153\r
154/**\r
155 Stop the device handled by this driver.\r
156\r
157 @param This The driver binding protocol.\r
158 @param Controller The controller to release.\r
159 @param NumberOfChildren The number of handles in ChildHandleBuffer.\r
160 @param ChildHandleBuffer The array of child handle.\r
161\r
162 @retval EFI_SUCCESS The device was stopped.\r
163 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r
164 @retval Others Fail to uninstall protocols attached on the device.\r
165\r
166**/\r
167EFI_STATUS\r
168EFIAPI\r
169VirtualKeyboardDriverBindingStop (\r
170 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
171 IN EFI_HANDLE Controller,\r
172 IN UINTN NumberOfChildren,\r
173 IN EFI_HANDLE *ChildHandleBuffer\r
174 );\r
175\r
176/**\r
177 Retrieves a Unicode string that is the user readable name of the driver.\r
178\r
179 This function retrieves the user readable name of a driver in the form of a\r
180 Unicode string. If the driver specified by This has a user readable name in\r
181 the language specified by Language, then a pointer to the driver name is\r
182 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
183 by This does not support the language specified by Language,\r
184 then EFI_UNSUPPORTED is returned.\r
185\r
186 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
187 EFI_COMPONENT_NAME_PROTOCOL instance.\r
188\r
189 @param Language[in] A pointer to a Null-terminated ASCII string\r
190 array indicating the language. This is the\r
191 language of the driver name that the caller is\r
192 requesting, and it must match one of the\r
193 languages specified in SupportedLanguages. The\r
194 number of languages supported by a driver is up\r
195 to the driver writer. Language is specified\r
196 in RFC 4646 or ISO 639-2 language code format.\r
197\r
198 @param DriverName[out] A pointer to the Unicode string to return.\r
199 This Unicode string is the name of the\r
200 driver specified by This in the language\r
201 specified by Language.\r
202\r
203 @retval EFI_SUCCESS The Unicode string for the Driver specified by\r
204 This and the language specified by Language was\r
205 returned in DriverName.\r
206\r
513edcec 207 @retval EFI_INVALID_PARAMETER Language is NULL.\r
1df5fb2d 208\r
513edcec 209 @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
1df5fb2d
HZ
210\r
211 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
212 the language specified by Language.\r
213\r
214**/\r
215EFI_STATUS\r
216EFIAPI\r
217VirtualKeyboardComponentNameGetDriverName (\r
218 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
219 IN CHAR8 *Language,\r
220 OUT CHAR16 **DriverName\r
221 );\r
222\r
1df5fb2d
HZ
223/**\r
224 Retrieves a Unicode string that is the user readable name of the controller\r
225 that is being managed by a driver.\r
226\r
227 This function retrieves the user readable name of the controller specified by\r
228 ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
229 driver specified by This has a user readable name in the language specified by\r
230 Language, then a pointer to the controller name is returned in ControllerName,\r
231 and EFI_SUCCESS is returned. If the driver specified by This is not currently\r
232 managing the controller specified by ControllerHandle and ChildHandle,\r
233 then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r
234 support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
235\r
236 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
237 EFI_COMPONENT_NAME_PROTOCOL instance.\r
238\r
239 @param ControllerHandle[in] The handle of a controller that the driver\r
240 specified by This is managing. This handle\r
241 specifies the controller whose name is to be\r
242 returned.\r
243\r
244 @param ChildHandle[in] The handle of the child controller to retrieve\r
245 the name of. This is an optional parameter that\r
246 may be NULL. It will be NULL for device\r
247 drivers. It will also be NULL for a bus drivers\r
248 that wish to retrieve the name of the bus\r
249 controller. It will not be NULL for a bus\r
250 driver that wishes to retrieve the name of a\r
251 child controller.\r
252\r
253 @param Language[in] A pointer to a Null-terminated ASCII string\r
254 array indicating the language. This is the\r
255 language of the driver name that the caller is\r
256 requesting, and it must match one of the\r
257 languages specified in SupportedLanguages. The\r
258 number of languages supported by a driver is up\r
259 to the driver writer. Language is specified in\r
260 RFC 4646 or ISO 639-2 language code format.\r
261\r
262 @param ControllerName[out] A pointer to the Unicode string to return.\r
263 This Unicode string is the name of the\r
264 controller specified by ControllerHandle and\r
265 ChildHandle in the language specified by\r
266 Language from the point of view of the driver\r
267 specified by This.\r
268\r
269 @retval EFI_SUCCESS The Unicode string for the user readable name in\r
270 the language specified by Language for the\r
271 driver specified by This was returned in\r
272 DriverName.\r
273\r
513edcec 274 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
1df5fb2d 275\r
513edcec 276 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
1df5fb2d
HZ
277 EFI_HANDLE.\r
278\r
513edcec 279 @retval EFI_INVALID_PARAMETER Language is NULL.\r
1df5fb2d 280\r
513edcec 281 @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
1df5fb2d
HZ
282\r
283 @retval EFI_UNSUPPORTED The driver specified by This is not currently\r
284 managing the controller specified by\r
285 ControllerHandle and ChildHandle.\r
286\r
287 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
288 the language specified by Language.\r
289\r
290**/\r
291EFI_STATUS\r
292EFIAPI\r
293VirtualKeyboardComponentNameGetControllerName (\r
e7108d0e
MK
294 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
295 IN EFI_HANDLE ControllerHandle,\r
296 IN EFI_HANDLE ChildHandle OPTIONAL,\r
297 IN CHAR8 *Language,\r
298 OUT CHAR16 **ControllerName\r
1df5fb2d
HZ
299 );\r
300\r
1df5fb2d
HZ
301//\r
302// Simple Text Input Protocol functions\r
303//\r
e7108d0e 304\r
1df5fb2d
HZ
305/**\r
306 Reset the Keyboard and do BAT test for it, if (ExtendedVerification == TRUE) then do some extra keyboard validations.\r
307\r
308 @param This Pointer of simple text Protocol.\r
309 @param ExtendedVerification Whether perform the extra validation of keyboard. True: perform; FALSE: skip.\r
310\r
311 @retval EFI_SUCCESS The command byte is written successfully.\r
312 @retval EFI_DEVICE_ERROR Errors occurred during resetting keyboard.\r
313\r
314**/\r
315EFI_STATUS\r
316EFIAPI\r
317VirtualKeyboardReset (\r
318 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,\r
319 IN BOOLEAN ExtendedVerification\r
320 );\r
321\r
322/**\r
e6053675 323 Reset the input device and optionally run diagnostics\r
1df5fb2d
HZ
324\r
325 @param This Protocol instance pointer.\r
326 @param ExtendedVerification Driver may perform diagnostics on reset.\r
327\r
328 @retval EFI_SUCCESS The device was reset.\r
329 @retval EFI_DEVICE_ERROR The device is not functioning properly and could\r
330 not be reset.\r
331\r
332**/\r
333EFI_STATUS\r
334EFIAPI\r
335VirtualKeyboardResetEx (\r
336 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
337 IN BOOLEAN ExtendedVerification\r
338 );\r
339\r
340/**\r
341 Set certain state for the input device.\r
342\r
343 @param This Protocol instance pointer.\r
344 @param KeyToggleState A pointer to the EFI_KEY_TOGGLE_STATE to set the\r
345 state for the input device.\r
346\r
347 @retval EFI_SUCCESS The device state was set successfully.\r
348 @retval EFI_DEVICE_ERROR The device is not functioning correctly and could\r
349 not have the setting adjusted.\r
350 @retval EFI_UNSUPPORTED The device does not have the ability to set its state.\r
513edcec 351 @retval EFI_INVALID_PARAMETER KeyToggleState is NULL.\r
1df5fb2d
HZ
352\r
353**/\r
354EFI_STATUS\r
355EFIAPI\r
356VirtualKeyboardSetState (\r
357 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
358 IN EFI_KEY_TOGGLE_STATE *KeyToggleState\r
359 );\r
360\r
361/**\r
362 Register a notification function for a particular keystroke for the input device.\r
363\r
364 @param This Protocol instance pointer.\r
365 @param KeyData A pointer to a buffer that is filled in with the keystroke\r
366 information data for the key that was pressed.\r
367 @param KeyNotificationFunction Points to the function to be called when the key\r
368 sequence is typed specified by KeyData.\r
369 @param NotifyHandle Points to the unique handle assigned to the registered notification.\r
370\r
371\r
372 @retval EFI_SUCCESS The notification function was registered successfully.\r
e6053675 373 @retval EFI_OUT_OF_RESOURCES Unable to allocate resources for necessary data structures.\r
513edcec 374 @retval EFI_INVALID_PARAMETER KeyData or NotifyHandle is NULL.\r
1df5fb2d
HZ
375\r
376**/\r
377EFI_STATUS\r
378EFIAPI\r
379VirtualKeyboardRegisterKeyNotify (\r
380 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
381 IN EFI_KEY_DATA *KeyData,\r
382 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction,\r
383 OUT VOID **NotifyHandle\r
384 );\r
385\r
386/**\r
387 Remove a registered notification function from a particular keystroke.\r
388\r
389 @param This Protocol instance pointer.\r
390 @param NotificationHandle The handle of the notification function being unregistered.\r
391\r
392 @retval EFI_SUCCESS The notification function was unregistered successfully.\r
513edcec 393 @retval EFI_INVALID_PARAMETER The NotificationHandle is invalid.\r
1df5fb2d
HZ
394\r
395**/\r
396EFI_STATUS\r
397EFIAPI\r
398VirtualKeyboardUnregisterKeyNotify (\r
399 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
400 IN VOID *NotificationHandle\r
401 );\r
402\r
403//\r
404// Private worker functions\r
405//\r
e7108d0e 406\r
1df5fb2d
HZ
407/**\r
408 Free keyboard notify list.\r
409\r
410 @param ListHead The list head\r
411\r
412 @retval EFI_SUCCESS Free the notify list successfully\r
513edcec 413 @retval EFI_INVALID_PARAMETER ListHead is invalid.\r
1df5fb2d
HZ
414\r
415**/\r
416EFI_STATUS\r
417VirtualKeyboardFreeNotifyList (\r
e7108d0e 418 IN OUT LIST_ENTRY *ListHead\r
1df5fb2d
HZ
419 );\r
420\r
421/**\r
422 Check if key is registered.\r
423\r
424 @param RegsiteredData A pointer to a buffer that is filled in with the keystroke\r
425 state data for the key that was registered.\r
426 @param InputData A pointer to a buffer that is filled in with the keystroke\r
427 state data for the key that was pressed.\r
428\r
429 @retval TRUE Key be pressed matches a registered key.\r
e6053675 430 @retval FALSE Match failed.\r
1df5fb2d
HZ
431\r
432**/\r
433BOOLEAN\r
434IsKeyRegistered (\r
435 IN EFI_KEY_DATA *RegsiteredData,\r
436 IN EFI_KEY_DATA *InputData\r
437 );\r
438\r
439/**\r
440 Waiting on the keyboard event, if there's any key pressed by the user, signal the event\r
441\r
e6053675 442 @param Event The event that be signalled when any key has been struck.\r
1df5fb2d
HZ
443 @param Context Pointer of the protocol EFI_SIMPLE_TEXT_INPUT_PROTOCOL.\r
444\r
445**/\r
446VOID\r
447EFIAPI\r
448VirtualKeyboardWaitForKey (\r
449 IN EFI_EVENT Event,\r
450 IN VOID *Context\r
451 );\r
452\r
453/**\r
454 Waiting on the keyboard event, if there's any key pressed by the user, signal the event\r
455\r
e6053675 456 @param Event The event that be signalled when any key has been struck.\r
1df5fb2d
HZ
457 @param Context Pointer of the protocol EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.\r
458\r
459**/\r
460VOID\r
461EFIAPI\r
462VirtualKeyboardWaitForKeyEx (\r
463 IN EFI_EVENT Event,\r
464 IN VOID *Context\r
465 );\r
466\r
467/**\r
468 Timer event handler: read a series of key stroke from 8042\r
469 and put them into memory key buffer.\r
470 It is registered as running under TPL_NOTIFY\r
471\r
472 @param Event The timer event\r
473 @param Context A VIRTUAL_KEYBOARD_DEV pointer\r
474\r
475**/\r
476VOID\r
477EFIAPI\r
478VirtualKeyboardTimerHandler (\r
e7108d0e
MK
479 IN EFI_EVENT Event,\r
480 IN VOID *Context\r
1df5fb2d
HZ
481 );\r
482\r
483/**\r
484 Process key notify.\r
485\r
486 @param Event Indicates the event that invoke this function.\r
487 @param Context Indicates the calling context.\r
488**/\r
489VOID\r
490EFIAPI\r
491KeyNotifyProcessHandler (\r
e7108d0e
MK
492 IN EFI_EVENT Event,\r
493 IN VOID *Context\r
1df5fb2d
HZ
494 );\r
495\r
496/**\r
497 Read out the scan code of the key that has just been stroked.\r
498\r
499 @param This Pointer of simple text Protocol.\r
500 @param Key Pointer for store the key that read out.\r
501\r
502 @retval EFI_SUCCESS The key is read out successfully.\r
503 @retval other The key reading failed.\r
504\r
505**/\r
506EFI_STATUS\r
507EFIAPI\r
508VirtualKeyboardReadKeyStroke (\r
509 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,\r
510 OUT EFI_INPUT_KEY *Key\r
511 );\r
512\r
513/**\r
514 Reads the next keystroke from the input device. The WaitForKey Event can\r
e6053675 515 be used to test for existence of a keystroke via WaitForEvent () call.\r
1df5fb2d
HZ
516\r
517 @param This Protocol instance pointer.\r
518 @param KeyData A pointer to a buffer that is filled in with the keystroke\r
519 state data for the key that was pressed.\r
520\r
521 @retval EFI_SUCCESS The keystroke information was returned.\r
e6053675 522 @retval EFI_NOT_READY There was no keystroke data available.\r
1df5fb2d
HZ
523 @retval EFI_DEVICE_ERROR The keystroke information was not returned due to\r
524 hardware errors.\r
513edcec 525 @retval EFI_INVALID_PARAMETER KeyData is NULL.\r
1df5fb2d
HZ
526\r
527**/\r
528EFI_STATUS\r
529EFIAPI\r
530VirtualKeyboardReadKeyStrokeEx (\r
e7108d0e
MK
531 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
532 OUT EFI_KEY_DATA *KeyData\r
1df5fb2d
HZ
533 );\r
534\r
535#endif /* _VIRTUAL_KEYBOARD_H_ */\r