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