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