]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EmbeddedPkg/Drivers/VirtualKeyboardDxe/VirtualKeyboard.h
EmbeddedPkg/Drivers: add virtual keyboard driver
[mirror_edk2.git] / EmbeddedPkg / Drivers / VirtualKeyboardDxe / VirtualKeyboard.h
diff --git a/EmbeddedPkg/Drivers/VirtualKeyboardDxe/VirtualKeyboard.h b/EmbeddedPkg/Drivers/VirtualKeyboardDxe/VirtualKeyboard.h
new file mode 100644 (file)
index 0000000..6dc8264
--- /dev/null
@@ -0,0 +1,544 @@
+/** @file\r
+\r
+Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2018, Linaro Ltd. All rights reserved.<BR>\r
+\r
+This program and the accompanying materials\r
+are licensed and made available under the terms and conditions\r
+of the BSD License which accompanies this distribution.  The\r
+full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef _VIRTUAL_KEYBOARD_H_\r
+#define _VIRTUAL_KEYBOARD_H_\r
+\r
+\r
+#include <Guid/StatusCodeDataTypeId.h>\r
+#include <Protocol/DevicePath.h>\r
+#include <Protocol/PlatformVirtualKeyboard.h>\r
+#include <Protocol/SimpleTextIn.h>\r
+#include <Protocol/SimpleTextInEx.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/IoLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/ReportStatusCodeLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UefiLib.h>\r
+\r
+//\r
+// Driver Binding Externs\r
+//\r
+extern EFI_DRIVER_BINDING_PROTOCOL  gVirtualKeyboardDriverBinding;\r
+extern EFI_COMPONENT_NAME_PROTOCOL  gVirtualKeyboardComponentName;\r
+extern EFI_COMPONENT_NAME2_PROTOCOL gVirtualKeyboardComponentName2;\r
+\r
+\r
+//\r
+// VIRTUAL Keyboard Defines\r
+//\r
+#define CHAR_SCANCODE                        0xe0\r
+#define CHAR_ESC                             0x1b\r
+\r
+#define KEYBOARD_TIMEOUT                     65536   // 0.07s\r
+#define KEYBOARD_WAITFORVALUE_TIMEOUT        1000000 // 1s\r
+#define KEYBOARD_BAT_TIMEOUT                 4000000 // 4s\r
+#define KEYBOARD_TIMER_INTERVAL              500000  // 0.5s\r
+\r
+#define QUEUE_MAX_COUNT                      32\r
+\r
+#define KEYBOARD_SCAN_CODE_MAX_COUNT         32\r
+\r
+//\r
+// VIRTUAL Keyboard Device Structure\r
+//\r
+#define VIRTUAL_KEYBOARD_DEV_SIGNATURE SIGNATURE_32 ('V', 'K', 'B', 'D')\r
+#define VIRTUAL_KEYBOARD_CONSOLE_IN_EX_NOTIFY_SIGNATURE SIGNATURE_32 ('v', 'k', 'c', 'n')\r
+\r
+typedef struct _VIRTUAL_KEYBOARD_CONSOLE_IN_EX_NOTIFY {\r
+  UINTN                                      Signature;\r
+  EFI_KEY_DATA                               KeyData;\r
+  EFI_KEY_NOTIFY_FUNCTION                    KeyNotificationFn;\r
+  LIST_ENTRY                                 NotifyEntry;\r
+} VIRTUAL_KEYBOARD_CONSOLE_IN_EX_NOTIFY;\r
+\r
+typedef struct {\r
+  UINTN                                      Front;\r
+  UINTN                                      Rear;\r
+  EFI_KEY_DATA                               Buffer[QUEUE_MAX_COUNT];\r
+} SIMPLE_QUEUE;\r
+\r
+typedef struct {\r
+  UINT8                                      Buffer[KEYBOARD_SCAN_CODE_MAX_COUNT];\r
+  UINTN                                      Head;\r
+  UINTN                                      Tail;\r
+} SCAN_CODE_QUEUE;\r
+\r
+typedef struct {\r
+  UINTN                                      Signature;\r
+  EFI_HANDLE                                 Handle;\r
+  PLATFORM_VIRTUAL_KBD_PROTOCOL              *PlatformVirtual;\r
+  EFI_SIMPLE_TEXT_INPUT_PROTOCOL             SimpleTextIn;\r
+  EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL          SimpleTextInputEx;\r
+\r
+  //\r
+  // Buffer storing EFI_KEY_DATA\r
+  //\r
+  SIMPLE_QUEUE                               Queue;\r
+  SIMPLE_QUEUE                               QueueForNotify;\r
+\r
+  //\r
+  // Notification Function List\r
+  //\r
+  LIST_ENTRY                                 NotifyList;\r
+  EFI_EVENT                                  KeyNotifyProcessEvent;\r
+  EFI_EVENT                                  TimerEvent;\r
+} VIRTUAL_KEYBOARD_DEV;\r
+\r
+#define VIRTUAL_KEYBOARD_DEV_FROM_THIS(a)  CR (a, VIRTUAL_KEYBOARD_DEV, SimpleTextIn, VIRTUAL_KEYBOARD_DEV_SIGNATURE)\r
+#define TEXT_INPUT_EX_VIRTUAL_KEYBOARD_DEV_FROM_THIS(a) \\r
+  CR (a, \\r
+      VIRTUAL_KEYBOARD_DEV, \\r
+      SimpleTextInputEx, \\r
+      VIRTUAL_KEYBOARD_DEV_SIGNATURE \\r
+      )\r
+\r
+//\r
+// Global Variables\r
+//\r
+extern EFI_DRIVER_BINDING_PROTOCOL   gVirtualKeyboardDriverBinding;\r
+\r
+//\r
+// Driver Binding Protocol functions\r
+//\r
+\r
+/**\r
+  Check whether the driver supports this device.\r
+\r
+  @param  This                   The Udriver binding protocol.\r
+  @param  Controller             The controller handle to check.\r
+  @param  RemainingDevicePath    The remaining device path.\r
+\r
+  @retval EFI_SUCCESS            The driver supports this controller.\r
+  @retval other                  This device isn't supported.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VirtualKeyboardDriverBindingSupported (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN EFI_HANDLE                   Controller,\r
+  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  );\r
+\r
+/**\r
+  Starts the device with this driver.\r
+\r
+  @param  This                   The driver binding instance.\r
+  @param  Controller             Handle of device to bind driver to.\r
+  @param  RemainingDevicePath    Optional parameter use to pick a specific child\r
+                                 device to start.\r
+\r
+  @retval EFI_SUCCESS            The controller is controlled by the driver.\r
+  @retval Other                  This controller cannot be started.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VirtualKeyboardDriverBindingStart (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN EFI_HANDLE                   Controller,\r
+  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  );\r
+\r
+/**\r
+  Stop the device handled by this driver.\r
+\r
+  @param  This                   The driver binding protocol.\r
+  @param  Controller             The controller to release.\r
+  @param  NumberOfChildren       The number of handles in ChildHandleBuffer.\r
+  @param  ChildHandleBuffer      The array of child handle.\r
+\r
+  @retval EFI_SUCCESS            The device was stopped.\r
+  @retval EFI_DEVICE_ERROR       The device could not be stopped due to a device error.\r
+  @retval Others                 Fail to uninstall protocols attached on the device.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VirtualKeyboardDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Controller,\r
+  IN  UINTN                        NumberOfChildren,\r
+  IN  EFI_HANDLE                   *ChildHandleBuffer\r
+  );\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the driver.\r
+\r
+  This function retrieves the user readable name of a driver in the form of a\r
+  Unicode string. If the driver specified by This has a user readable name in\r
+  the language specified by Language, then a pointer to the driver name is\r
+  returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
+  by This does not support the language specified by Language,\r
+  then EFI_UNSUPPORTED is returned.\r
+\r
+  @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+                                EFI_COMPONENT_NAME_PROTOCOL instance.\r
+\r
+  @param  Language[in]          A pointer to a Null-terminated ASCII string\r
+                                array indicating the language. This is the\r
+                                language of the driver name that the caller is\r
+                                requesting, and it must match one of the\r
+                                languages specified in SupportedLanguages. The\r
+                                number of languages supported by a driver is up\r
+                                to the driver writer. Language is specified\r
+                                in RFC 4646 or ISO 639-2 language code format.\r
+\r
+  @param  DriverName[out]       A pointer to the Unicode string to return.\r
+                                This Unicode string is the name of the\r
+                                driver specified by This in the language\r
+                                specified by Language.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the Driver specified by\r
+                                This and the language specified by Language was\r
+                                returned in DriverName.\r
+\r
+  @retval EFI_INVALID_PAVIRTUALETER Language is NULL.\r
+\r
+  @retval EFI_INVALID_PAVIRTUALETER DriverName is NULL.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
+                                the language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VirtualKeyboardComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  );\r
+\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the controller\r
+  that is being managed by a driver.\r
+\r
+  This function retrieves the user readable name of the controller specified by\r
+  ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
+  driver specified by This has a user readable name in the language specified by\r
+  Language, then a pointer to the controller name is returned in ControllerName,\r
+  and EFI_SUCCESS is returned.  If the driver specified by This is not currently\r
+  managing the controller specified by ControllerHandle and ChildHandle,\r
+  then EFI_UNSUPPORTED is returned.  If the driver specified by This does not\r
+  support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
+\r
+  @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+                                EFI_COMPONENT_NAME_PROTOCOL instance.\r
+\r
+  @param  ControllerHandle[in]  The handle of a controller that the driver\r
+                                specified by This is managing.  This handle\r
+                                specifies the controller whose name is to be\r
+                                returned.\r
+\r
+  @param  ChildHandle[in]       The handle of the child controller to retrieve\r
+                                the name of.  This is an optional parameter that\r
+                                may be NULL.  It will be NULL for device\r
+                                drivers.  It will also be NULL for a bus drivers\r
+                                that wish to retrieve the name of the bus\r
+                                controller.  It will not be NULL for a bus\r
+                                driver that wishes to retrieve the name of a\r
+                                child controller.\r
+\r
+  @param  Language[in]          A pointer to a Null-terminated ASCII string\r
+                                array indicating the language.  This is the\r
+                                language of the driver name that the caller is\r
+                                requesting, and it must match one of the\r
+                                languages specified in SupportedLanguages. The\r
+                                number of languages supported by a driver is up\r
+                                to the driver writer. Language is specified in\r
+                                RFC 4646 or ISO 639-2 language code format.\r
+\r
+  @param  ControllerName[out]   A pointer to the Unicode string to return.\r
+                                This Unicode string is the name of the\r
+                                controller specified by ControllerHandle and\r
+                                ChildHandle in the language specified by\r
+                                Language from the point of view of the driver\r
+                                specified by This.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the user readable name in\r
+                                the language specified by Language for the\r
+                                driver specified by This was returned in\r
+                                DriverName.\r
+\r
+  @retval EFI_INVALID_PAVIRTUALETER ControllerHandle is NULL.\r
+\r
+  @retval EFI_INVALID_PAVIRTUALETER ChildHandle is not NULL and it is not a valid\r
+                                EFI_HANDLE.\r
+\r
+  @retval EFI_INVALID_PAVIRTUALETER Language is NULL.\r
+\r
+  @retval EFI_INVALID_PAVIRTUALETER ControllerName is NULL.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This is not currently\r
+                                managing the controller specified by\r
+                                ControllerHandle and ChildHandle.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
+                                the language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VirtualKeyboardComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL      *This,\r
+  IN  EFI_HANDLE                       ControllerHandle,\r
+  IN  EFI_HANDLE                       ChildHandle        OPTIONAL,\r
+  IN  CHAR8                            *Language,\r
+  OUT CHAR16                           **ControllerName\r
+  );\r
+\r
+\r
+//\r
+// Simple Text Input Protocol functions\r
+//\r
+/**\r
+  Reset the Keyboard and do BAT test for it, if (ExtendedVerification == TRUE) then do some extra keyboard validations.\r
+\r
+  @param  This                  Pointer of simple text Protocol.\r
+  @param  ExtendedVerification  Whether perform the extra validation of keyboard. True: perform; FALSE: skip.\r
+\r
+  @retval EFI_SUCCESS           The command byte is written successfully.\r
+  @retval EFI_DEVICE_ERROR      Errors occurred during resetting keyboard.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VirtualKeyboardReset (\r
+  IN  EFI_SIMPLE_TEXT_INPUT_PROTOCOL  *This,\r
+  IN  BOOLEAN                         ExtendedVerification\r
+  );\r
+\r
+/**\r
+  Reset the input device and optionaly run diagnostics\r
+\r
+  @param  This                  Protocol instance pointer.\r
+  @param  ExtendedVerification  Driver may perform diagnostics on reset.\r
+\r
+  @retval EFI_SUCCESS           The device was reset.\r
+  @retval EFI_DEVICE_ERROR      The device is not functioning properly and could\r
+                                not be reset.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VirtualKeyboardResetEx (\r
+  IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL  *This,\r
+  IN BOOLEAN                            ExtendedVerification\r
+  );\r
+\r
+/**\r
+  Set certain state for the input device.\r
+\r
+  @param  This              Protocol instance pointer.\r
+  @param  KeyToggleState    A pointer to the EFI_KEY_TOGGLE_STATE to set the\r
+                            state for the input device.\r
+\r
+  @retval EFI_SUCCESS           The device state was set successfully.\r
+  @retval EFI_DEVICE_ERROR      The device is not functioning correctly and could\r
+                                not have the setting adjusted.\r
+  @retval EFI_UNSUPPORTED       The device does not have the ability to set its state.\r
+  @retval EFI_INVALID_PAVIRTUALETER KeyToggleState is NULL.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VirtualKeyboardSetState (\r
+  IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL  *This,\r
+  IN EFI_KEY_TOGGLE_STATE               *KeyToggleState\r
+  );\r
+\r
+/**\r
+  Register a notification function for a particular keystroke for the input device.\r
+\r
+  @param  This                    Protocol instance pointer.\r
+  @param  KeyData                 A pointer to a buffer that is filled in with the keystroke\r
+                                  information data for the key that was pressed.\r
+  @param  KeyNotificationFunction Points to the function to be called when the key\r
+                                  sequence is typed specified by KeyData.\r
+  @param  NotifyHandle            Points to the unique handle assigned to the registered notification.\r
+\r
+\r
+  @retval EFI_SUCCESS             The notification function was registered successfully.\r
+  @retval EFI_OUT_OF_RESOURCES    Unable to allocate resources for necesssary data structures.\r
+  @retval EFI_INVALID_PAVIRTUALETER   KeyData or NotifyHandle is NULL.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VirtualKeyboardRegisterKeyNotify (\r
+  IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL  *This,\r
+  IN EFI_KEY_DATA                       *KeyData,\r
+  IN EFI_KEY_NOTIFY_FUNCTION            KeyNotificationFunction,\r
+  OUT VOID                              **NotifyHandle\r
+  );\r
+\r
+/**\r
+  Remove a registered notification function from a particular keystroke.\r
+\r
+  @param  This                 Protocol instance pointer.\r
+  @param  NotificationHandle   The handle of the notification function being unregistered.\r
+\r
+  @retval EFI_SUCCESS             The notification function was unregistered successfully.\r
+  @retval EFI_INVALID_PAVIRTUALETER   The NotificationHandle is invalid.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VirtualKeyboardUnregisterKeyNotify (\r
+  IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL  *This,\r
+  IN VOID                               *NotificationHandle\r
+  );\r
+\r
+//\r
+// Private worker functions\r
+//\r
+/**\r
+  Free keyboard notify list.\r
+\r
+  @param  ListHead   The list head\r
+\r
+  @retval EFI_SUCCESS           Free the notify list successfully\r
+  @retval EFI_INVALID_PAVIRTUALETER ListHead is invalid.\r
+\r
+**/\r
+EFI_STATUS\r
+VirtualKeyboardFreeNotifyList (\r
+  IN OUT LIST_ENTRY           *ListHead\r
+  );\r
+\r
+/**\r
+  Check if key is registered.\r
+\r
+  @param  RegsiteredData    A pointer to a buffer that is filled in with the keystroke\r
+                            state data for the key that was registered.\r
+  @param  InputData         A pointer to a buffer that is filled in with the keystroke\r
+                            state data for the key that was pressed.\r
+\r
+  @retval TRUE              Key be pressed matches a registered key.\r
+  @retval FLASE             Match failed.\r
+\r
+**/\r
+BOOLEAN\r
+IsKeyRegistered (\r
+  IN EFI_KEY_DATA  *RegsiteredData,\r
+  IN EFI_KEY_DATA  *InputData\r
+  );\r
+\r
+/**\r
+  Waiting on the keyboard event, if there's any key pressed by the user, signal the event\r
+\r
+  @param  Event       The event that be siganlled when any key has been stroked.\r
+  @param  Context     Pointer of the protocol EFI_SIMPLE_TEXT_INPUT_PROTOCOL.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+VirtualKeyboardWaitForKey (\r
+  IN  EFI_EVENT  Event,\r
+  IN  VOID       *Context\r
+  );\r
+\r
+/**\r
+  Waiting on the keyboard event, if there's any key pressed by the user, signal the event\r
+\r
+  @param  Event    The event that be siganlled when any key has been stroked.\r
+  @param  Context  Pointer of the protocol EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+VirtualKeyboardWaitForKeyEx (\r
+  IN  EFI_EVENT  Event,\r
+  IN  VOID       *Context\r
+  );\r
+\r
+/**\r
+  Timer event handler: read a series of key stroke from 8042\r
+  and put them into memory key buffer.\r
+  It is registered as running under TPL_NOTIFY\r
+\r
+  @param  Event   The timer event\r
+  @param  Context A VIRTUAL_KEYBOARD_DEV pointer\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+VirtualKeyboardTimerHandler (\r
+  IN EFI_EVENT    Event,\r
+  IN VOID         *Context\r
+  );\r
+\r
+/**\r
+  Process key notify.\r
+\r
+  @param  Event                 Indicates the event that invoke this function.\r
+  @param  Context               Indicates the calling context.\r
+**/\r
+VOID\r
+EFIAPI\r
+KeyNotifyProcessHandler (\r
+  IN  EFI_EVENT                 Event,\r
+  IN  VOID                      *Context\r
+  );\r
+\r
+/**\r
+  Read out the scan code of the key that has just been stroked.\r
+\r
+  @param  This        Pointer of simple text Protocol.\r
+  @param  Key         Pointer for store the key that read out.\r
+\r
+  @retval EFI_SUCCESS The key is read out successfully.\r
+  @retval other       The key reading failed.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VirtualKeyboardReadKeyStroke (\r
+  IN  EFI_SIMPLE_TEXT_INPUT_PROTOCOL  *This,\r
+  OUT EFI_INPUT_KEY                   *Key\r
+  );\r
+\r
+/**\r
+  Reads the next keystroke from the input device. The WaitForKey Event can\r
+  be used to test for existance of a keystroke via WaitForEvent () call.\r
+\r
+  @param  This         Protocol instance pointer.\r
+  @param  KeyData      A pointer to a buffer that is filled in with the keystroke\r
+                       state data for the key that was pressed.\r
+\r
+  @retval  EFI_SUCCESS           The keystroke information was returned.\r
+  @retval  EFI_NOT_READY         There was no keystroke data availiable.\r
+  @retval  EFI_DEVICE_ERROR      The keystroke information was not returned due to\r
+                                 hardware errors.\r
+  @retval  EFI_INVALID_PAVIRTUALETER KeyData is NULL.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VirtualKeyboardReadKeyStrokeEx (\r
+  IN  EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
+  OUT EFI_KEY_DATA                      *KeyData\r
+  );\r
+\r
+#endif /* _VIRTUAL_KEYBOARD_H_ */\r