xref: /freebsd/sys/contrib/edk2/Include/Protocol/SimpleTextInEx.h (revision cddbc3b40812213ff00041f79174cac0be360a2a)
1 /** @file
2   Simple Text Input Ex protocol from the UEFI 2.0 specification.
3 
4   This protocol defines an extension to the EFI_SIMPLE_TEXT_INPUT_PROTOCOL
5   which exposes much more state and modifier information from the input device,
6   also allows one to register a notification for a particular keystroke.
7 
8   Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
9   This program and the accompanying materials
10   are licensed and made available under the terms and conditions of the BSD License
11   which accompanies this distribution.  The full text of the license may be found at
12   http://opensource.org/licenses/bsd-license.php
13 
14   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 
17 **/
18 
19 #ifndef __SIMPLE_TEXT_IN_EX_H__
20 #define __SIMPLE_TEXT_IN_EX_H__
21 
22 #include <Protocol/SimpleTextIn.h>
23 
24 #define EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID \
25   {0xdd9e7534, 0x7762, 0x4698, { 0x8c, 0x14, 0xf5, 0x85, 0x17, 0xa6, 0x25, 0xaa } }
26 
27 
28 typedef struct _EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL;
29 
30 /**
31   The Reset() function resets the input device hardware. As part
32   of initialization process, the firmware/device will make a quick
33   but reasonable attempt to verify that the device is functioning.
34   If the ExtendedVerification flag is TRUE the firmware may take
35   an extended amount of time to verify the device is operating on
36   reset. Otherwise the reset operation is to occur as quickly as
37   possible. The hardware verification process is not defined by
38   this specification and is left up to the platform firmware or
39   driver to implement.
40 
41   @param This                 A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance.
42 
43   @param ExtendedVerification Indicates that the driver may
44                               perform a more exhaustive
45                               verification operation of the
46                               device during reset.
47 
48 
49   @retval EFI_SUCCESS       The device was reset.
50 
51   @retval EFI_DEVICE_ERROR  The device is not functioning
52                             correctly and could not be reset.
53 
54 **/
55 typedef
56 EFI_STATUS
57 (EFIAPI *EFI_INPUT_RESET_EX)(
58   IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
59   IN BOOLEAN                           ExtendedVerification
60 );
61 
62 
63 ///
64 /// EFI_KEY_TOGGLE_STATE. The toggle states are defined.
65 /// They are: EFI_TOGGLE_STATE_VALID, EFI_SCROLL_LOCK_ACTIVE
66 /// EFI_NUM_LOCK_ACTIVE, EFI_CAPS_LOCK_ACTIVE
67 ///
68 typedef UINT8 EFI_KEY_TOGGLE_STATE;
69 
70 typedef struct _EFI_KEY_STATE {
71   ///
72   /// Reflects the currently pressed shift
73   /// modifiers for the input device. The
74   /// returned value is valid only if the high
75   /// order bit has been set.
76   ///
77   UINT32                KeyShiftState;
78   ///
79   /// Reflects the current internal state of
80   /// various toggled attributes. The returned
81   /// value is valid only if the high order
82   /// bit has been set.
83   ///
84   EFI_KEY_TOGGLE_STATE  KeyToggleState;
85 } EFI_KEY_STATE;
86 
87 typedef struct {
88   ///
89   /// The EFI scan code and Unicode value returned from the input device.
90   ///
91   EFI_INPUT_KEY   Key;
92   ///
93   /// The current state of various toggled attributes as well as input modifier values.
94   ///
95   EFI_KEY_STATE   KeyState;
96 } EFI_KEY_DATA;
97 
98 //
99 // Any Shift or Toggle State that is valid should have
100 // high order bit set.
101 //
102 // Shift state
103 //
104 #define EFI_SHIFT_STATE_VALID     0x80000000
105 #define EFI_RIGHT_SHIFT_PRESSED   0x00000001
106 #define EFI_LEFT_SHIFT_PRESSED    0x00000002
107 #define EFI_RIGHT_CONTROL_PRESSED 0x00000004
108 #define EFI_LEFT_CONTROL_PRESSED  0x00000008
109 #define EFI_RIGHT_ALT_PRESSED     0x00000010
110 #define EFI_LEFT_ALT_PRESSED      0x00000020
111 #define EFI_RIGHT_LOGO_PRESSED    0x00000040
112 #define EFI_LEFT_LOGO_PRESSED     0x00000080
113 #define EFI_MENU_KEY_PRESSED      0x00000100
114 #define EFI_SYS_REQ_PRESSED       0x00000200
115 
116 //
117 // Toggle state
118 //
119 #define EFI_TOGGLE_STATE_VALID    0x80
120 #define EFI_KEY_STATE_EXPOSED     0x40
121 #define EFI_SCROLL_LOCK_ACTIVE    0x01
122 #define EFI_NUM_LOCK_ACTIVE       0x02
123 #define EFI_CAPS_LOCK_ACTIVE      0x04
124 
125 //
126 // EFI Scan codes
127 //
128 #define SCAN_F11                  0x0015
129 #define SCAN_F12                  0x0016
130 #define SCAN_PAUSE                0x0048
131 #define SCAN_F13                  0x0068
132 #define SCAN_F14                  0x0069
133 #define SCAN_F15                  0x006A
134 #define SCAN_F16                  0x006B
135 #define SCAN_F17                  0x006C
136 #define SCAN_F18                  0x006D
137 #define SCAN_F19                  0x006E
138 #define SCAN_F20                  0x006F
139 #define SCAN_F21                  0x0070
140 #define SCAN_F22                  0x0071
141 #define SCAN_F23                  0x0072
142 #define SCAN_F24                  0x0073
143 #define SCAN_MUTE                 0x007F
144 #define SCAN_VOLUME_UP            0x0080
145 #define SCAN_VOLUME_DOWN          0x0081
146 #define SCAN_BRIGHTNESS_UP        0x0100
147 #define SCAN_BRIGHTNESS_DOWN      0x0101
148 #define SCAN_SUSPEND              0x0102
149 #define SCAN_HIBERNATE            0x0103
150 #define SCAN_TOGGLE_DISPLAY       0x0104
151 #define SCAN_RECOVERY             0x0105
152 #define SCAN_EJECT                0x0106
153 
154 /**
155   The function reads the next keystroke from the input device. If
156   there is no pending keystroke the function returns
157   EFI_NOT_READY. If there is a pending keystroke, then
158   KeyData.Key.ScanCode is the EFI scan code defined in Error!
159   Reference source not found. The KeyData.Key.UnicodeChar is the
160   actual printable character or is zero if the key does not
161   represent a printable character (control key, function key,
162   etc.). The KeyData.KeyState is shift state for the character
163   reflected in KeyData.Key.UnicodeChar or KeyData.Key.ScanCode .
164   When interpreting the data from this function, it should be
165   noted that if a class of printable characters that are
166   normally adjusted by shift modifiers (e.g. Shift Key + "f"
167   key) would be presented solely as a KeyData.Key.UnicodeChar
168   without the associated shift state. So in the previous example
169   of a Shift Key + "f" key being pressed, the only pertinent
170   data returned would be KeyData.Key.UnicodeChar with the value
171   of "F". This of course would not typically be the case for
172   non-printable characters such as the pressing of the Right
173   Shift Key + F10 key since the corresponding returned data
174   would be reflected both in the KeyData.KeyState.KeyShiftState
175   and KeyData.Key.ScanCode values. UEFI drivers which implement
176   the EFI_SIMPLE_TEXT_INPUT_EX protocol are required to return
177   KeyData.Key and KeyData.KeyState values. These drivers must
178   always return the most current state of
179   KeyData.KeyState.KeyShiftState and
180   KeyData.KeyState.KeyToggleState. It should also be noted that
181   certain input devices may not be able to produce shift or toggle
182   state information, and in those cases the high order bit in the
183   respective Toggle and Shift state fields should not be active.
184 
185 
186   @param This     A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance.
187 
188   @param KeyData  A pointer to a buffer that is filled in with
189                   the keystroke state data for the key that was
190                   pressed.
191 
192 
193   @retval EFI_SUCCESS     The keystroke information was
194                           returned.
195 
196   @retval EFI_NOT_READY   There was no keystroke data available.
197                           EFI_DEVICE_ERROR The keystroke
198                           information was not returned due to
199                           hardware errors.
200 
201 
202 **/
203 typedef
204 EFI_STATUS
205 (EFIAPI *EFI_INPUT_READ_KEY_EX)(
206   IN  EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
207   OUT EFI_KEY_DATA                      *KeyData
208 );
209 
210 /**
211   The SetState() function allows the input device hardware to
212   have state settings adjusted.
213 
214   @param This           A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance.
215 
216   @param KeyToggleState Pointer to the EFI_KEY_TOGGLE_STATE to
217                         set the state for the input device.
218 
219 
220   @retval EFI_SUCCESS       The device state was set appropriately.
221 
222   @retval EFI_DEVICE_ERROR  The device is not functioning
223                             correctly and could not have the
224                             setting adjusted.
225 
226   @retval EFI_UNSUPPORTED   The device does not support the
227                             ability to have its state set.
228 
229 **/
230 typedef
231 EFI_STATUS
232 (EFIAPI *EFI_SET_STATE)(
233   IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
234   IN EFI_KEY_TOGGLE_STATE              *KeyToggleState
235 );
236 
237 ///
238 /// The function will be called when the key sequence is typed specified by KeyData.
239 ///
240 typedef
241 EFI_STATUS
242 (EFIAPI *EFI_KEY_NOTIFY_FUNCTION)(
243   IN EFI_KEY_DATA *KeyData
244 );
245 
246 /**
247   The RegisterKeystrokeNotify() function registers a function
248   which will be called when a specified keystroke will occur.
249 
250   @param This                     A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance.
251 
252   @param KeyData                  A pointer to a buffer that is filled in with
253                                   the keystroke information for the key that was
254                                   pressed.
255 
256   @param KeyNotificationFunction  Points to the function to be
257                                   called when the key sequence
258                                   is typed specified by KeyData.
259 
260 
261   @param NotifyHandle             Points to the unique handle assigned to
262                                   the registered notification.
263 
264   @retval EFI_SUCCESS           The device state was set
265                                 appropriately.
266 
267   @retval EFI_OUT_OF_RESOURCES  Unable to allocate necessary
268                                 data structures.
269 
270 **/
271 typedef
272 EFI_STATUS
273 (EFIAPI *EFI_REGISTER_KEYSTROKE_NOTIFY)(
274   IN  EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
275   IN  EFI_KEY_DATA                      *KeyData,
276   IN  EFI_KEY_NOTIFY_FUNCTION           KeyNotificationFunction,
277   OUT VOID                              **NotifyHandle
278 );
279 
280 /**
281   The UnregisterKeystrokeNotify() function removes the
282   notification which was previously registered.
283 
284   @param This               A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance.
285 
286   @param NotificationHandle The handle of the notification
287                             function being unregistered.
288 
289   @retval EFI_SUCCESS The device state was set appropriately.
290 
291   @retval EFI_INVALID_PARAMETER The NotificationHandle is
292                                 invalid.
293 
294 **/
295 typedef
296 EFI_STATUS
297 (EFIAPI *EFI_UNREGISTER_KEYSTROKE_NOTIFY)(
298   IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL  *This,
299   IN VOID                               *NotificationHandle
300 );
301 
302 
303 ///
304 /// The EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL is used on the ConsoleIn
305 /// device. It is an extension to the Simple Text Input protocol
306 /// which allows a variety of extended shift state information to be
307 /// returned.
308 ///
309 struct _EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL{
310   EFI_INPUT_RESET_EX              Reset;
311   EFI_INPUT_READ_KEY_EX           ReadKeyStrokeEx;
312   ///
313   /// Event to use with WaitForEvent() to wait for a key to be available.
314   ///
315   EFI_EVENT                       WaitForKeyEx;
316   EFI_SET_STATE                   SetState;
317   EFI_REGISTER_KEYSTROKE_NOTIFY   RegisterKeyNotify;
318   EFI_UNREGISTER_KEYSTROKE_NOTIFY UnregisterKeyNotify;
319 };
320 
321 
322 extern EFI_GUID gEfiSimpleTextInputExProtocolGuid;
323 
324 #endif
325 
326