]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.h
clean up the un-suitable ';' location when declaring the functions.
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbKbDxe / EfiKey.h
1 /** @file
2
3 Header file for USB Keyboard Driver's Data Structures.
4
5 Copyright (c) 2004 - 2008, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15 #ifndef _EFI_USB_KB_H_
16 #define _EFI_USB_KB_H_
17
18
19 #include <Uefi.h>
20
21 #include <Protocol/SimpleTextIn.h>
22 #include <Protocol/SimpleTextInEx.h>
23 #include <Protocol/HiiDatabase.h>
24 #include <Protocol/UsbIo.h>
25 #include <Protocol/DevicePath.h>
26 #include <Guid/HiiKeyBoardLayout.h>
27 #include <Guid/HotPlugDevice.h>
28
29 #include <Library/DebugLib.h>
30 #include <Library/ReportStatusCodeLib.h>
31 #include <Library/BaseMemoryLib.h>
32 #include <Library/UefiRuntimeServicesTableLib.h>
33 #include <Library/UefiDriverEntryPoint.h>
34 #include <Library/UefiBootServicesTableLib.h>
35 #include <Library/UefiLib.h>
36 #include <Library/MemoryAllocationLib.h>
37 #include <Library/PcdLib.h>
38 #include <Library/UsbLib.h>
39 #include <Library/BaseLib.h>
40
41 #include <IndustryStandard/Usb.h>
42
43 #define MAX_KEY_ALLOWED 32
44
45 #define HZ 1000 * 1000 * 10
46 #define USBKBD_REPEAT_DELAY ((HZ) / 2)
47 #define USBKBD_REPEAT_RATE ((HZ) / 50)
48
49 #define CLASS_HID 3
50 #define SUBCLASS_BOOT 1
51 #define PROTOCOL_KEYBOARD 1
52
53 #define BOOT_PROTOCOL 0
54 #define REPORT_PROTOCOL 1
55
56 typedef struct {
57 UINT8 Down;
58 UINT8 KeyCode;
59 } USB_KEY;
60
61 typedef struct {
62 USB_KEY buffer[MAX_KEY_ALLOWED + 1];
63 UINT8 bHead;
64 UINT8 bTail;
65 } USB_KB_BUFFER;
66
67 #define USB_KB_DEV_SIGNATURE EFI_SIGNATURE_32 ('u', 'k', 'b', 'd')
68 #define USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE EFI_SIGNATURE_32 ('u', 'k', 'b', 'x')
69
70 typedef struct _KEYBOARD_CONSOLE_IN_EX_NOTIFY {
71 UINTN Signature;
72 EFI_HANDLE NotifyHandle;
73 EFI_KEY_DATA KeyData;
74 EFI_KEY_NOTIFY_FUNCTION KeyNotificationFn;
75 LIST_ENTRY NotifyEntry;
76 } KEYBOARD_CONSOLE_IN_EX_NOTIFY;
77
78 #define USB_NS_KEY_SIGNATURE EFI_SIGNATURE_32 ('u', 'n', 's', 'k')
79
80 typedef struct {
81 UINTN Signature;
82 LIST_ENTRY Link;
83
84 //
85 // The number of EFI_NS_KEY_MODIFIER children definitions
86 //
87 UINTN KeyCount;
88
89 //
90 // NsKey[0] : Non-spacing key
91 // NsKey[1] ~ NsKey[KeyCount] : Physical keys
92 //
93 EFI_KEY_DESCRIPTOR *NsKey;
94 } USB_NS_KEY;
95
96 #define USB_NS_KEY_FORM_FROM_LINK(a) CR (a, USB_NS_KEY, Link, USB_NS_KEY_SIGNATURE)
97
98 typedef struct {
99 UINTN Signature;
100 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
101 EFI_EVENT DelayedRecoveryEvent;
102 EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleInput;
103 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL SimpleInputEx;
104 EFI_USB_IO_PROTOCOL *UsbIo;
105
106 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
107 EFI_USB_ENDPOINT_DESCRIPTOR IntEndpointDescriptor;
108
109 USB_KB_BUFFER KeyboardBuffer;
110 UINT8 CtrlOn;
111 UINT8 AltOn;
112 UINT8 ShiftOn;
113 UINT8 NumLockOn;
114 UINT8 CapsOn;
115 UINT8 ScrollOn;
116 UINT8 LastKeyCodeArray[8];
117 UINT8 CurKeyChar;
118
119 UINT8 RepeatKey;
120 EFI_EVENT RepeatTimer;
121
122 EFI_UNICODE_STRING_TABLE *ControllerNameTable;
123
124 UINT8 LeftCtrlOn;
125 UINT8 LeftAltOn;
126 UINT8 LeftShiftOn;
127 UINT8 LeftLogoOn;
128 UINT8 RightCtrlOn;
129 UINT8 RightAltOn;
130 UINT8 RightShiftOn;
131 UINT8 RightLogoOn;
132 UINT8 MenuKeyOn;
133 UINT8 SysReqOn;
134 UINT8 AltGrOn;
135
136 EFI_KEY_STATE KeyState;
137 //
138 // Notification function list
139 //
140 LIST_ENTRY NotifyList;
141
142 //
143 // Non-spacing key list
144 //
145 LIST_ENTRY NsKeyList;
146 USB_NS_KEY *CurrentNsKey;
147 EFI_KEY_DESCRIPTOR *KeyConvertionTable;
148 EFI_EVENT KeyboardLayoutEvent;
149 } USB_KB_DEV;
150
151 //
152 // Global Variables
153 //
154 extern EFI_DRIVER_BINDING_PROTOCOL gUsbKeyboardDriverBinding;
155 extern EFI_COMPONENT_NAME_PROTOCOL gUsbKeyboardComponentName;
156 extern EFI_COMPONENT_NAME2_PROTOCOL gUsbKeyboardComponentName2;
157 extern EFI_GUID gEfiUsbKeyboardDriverGuid;
158 extern EFI_GUID gSimpleTextInExNotifyGuid;
159
160 /**
161 Report Status Code in Usb Keyboard Driver.
162
163 @param DevicePath Use this to get Device Path.
164 @param CodeType Status Code Type.
165 @param CodeValue Status Code Value.
166
167 @return None.
168
169 **/
170 VOID
171 EFIAPI
172 KbdReportStatusCode (
173 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
174 IN EFI_STATUS_CODE_TYPE CodeType,
175 IN EFI_STATUS_CODE_VALUE Value
176 );
177
178 #define USB_KB_DEV_FROM_THIS(a) \
179 CR(a, USB_KB_DEV, SimpleInput, USB_KB_DEV_SIGNATURE)
180 #define TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS(a) \
181 CR(a, USB_KB_DEV, SimpleInputEx, USB_KB_DEV_SIGNATURE)
182
183
184 #define MOD_CONTROL_L 0x01
185 #define MOD_CONTROL_R 0x10
186 #define MOD_SHIFT_L 0x02
187 #define MOD_SHIFT_R 0x20
188 #define MOD_ALT_L 0x04
189 #define MOD_ALT_R 0x40
190 #define MOD_WIN_L 0x08
191 #define MOD_WIN_R 0x80
192
193 typedef struct {
194 UINT8 Mask;
195 UINT8 Key;
196 } KB_MODIFIER;
197
198 #define USB_KEYCODE_MAX_MAKE 0x62
199
200 #define USBKBD_VALID_KEYCODE(key) ((UINT8) (key) > 3)
201
202 typedef struct {
203 UINT8 NumLock : 1;
204 UINT8 CapsLock : 1;
205 UINT8 ScrollLock : 1;
206 UINT8 Resrvd : 5;
207 } LED_MAP;
208
209 //
210 // Simple Text Input Ex protocol functions
211 //
212 /**
213 The extension routine to reset the input device.
214
215 @param This Protocol instance pointer.
216 @param ExtendedVerification Driver may perform diagnostics on reset.
217
218 @retval EFI_SUCCESS The device was reset.
219 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
220 not be reset.
221
222 **/
223 EFI_STATUS
224 EFIAPI
225 USBKeyboardResetEx (
226 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
227 IN BOOLEAN ExtendedVerification
228 );
229
230 /**
231 Reads the next keystroke from the input device. The WaitForKey Event can
232 be used to test for existance of a keystroke via WaitForEvent () call.
233
234 @param This Protocol instance pointer.
235 @param KeyData A pointer to a buffer that is filled in with the keystroke
236 state data for the key that was pressed.
237
238 @return EFI_SUCCESS The keystroke information was returned successfully.
239 @retval EFI_INVALID_PARAMETER KeyData is NULL.
240 @retval Other Read key stroke information failed.
241
242 **/
243 EFI_STATUS
244 EFIAPI
245 USBKeyboardReadKeyStrokeEx (
246 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
247 OUT EFI_KEY_DATA *KeyData
248 );
249
250 /**
251 Set certain state for the input device.
252
253 @param This Protocol instance pointer.
254 @param KeyToggleState A pointer to the EFI_KEY_TOGGLE_STATE to set the
255 state for the input device.
256
257 @retval EFI_SUCCESS The device state was set successfully.
258 @retval EFI_UNSUPPORTED The device does not have the ability to set its state.
259 @retval EFI_INVALID_PARAMETER KeyToggleState is NULL.
260
261 **/
262 EFI_STATUS
263 EFIAPI
264 USBKeyboardSetState (
265 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
266 IN EFI_KEY_TOGGLE_STATE *KeyToggleState
267 );
268
269 /**
270 Register a notification function for a particular keystroke for the input device.
271
272 @param This Protocol instance pointer.
273 @param KeyData A pointer to a buffer that is filled in with the keystroke
274 information data for the key that was pressed.
275 @param KeyNotificationFunction Points to the function to be called when the key
276 sequence is typed specified by KeyData.
277 @param NotifyHandle Points to the unique handle assigned to the registered notification.
278
279 @retval EFI_SUCCESS The notification function was registered successfully.
280 @retval EFI_OUT_OF_RESOURCES Unable to allocate resources for necesssary data structures.
281 @retval EFI_INVALID_PARAMETER KeyData or NotifyHandle is NULL.
282
283 **/
284 EFI_STATUS
285 EFIAPI
286 USBKeyboardRegisterKeyNotify (
287 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
288 IN EFI_KEY_DATA *KeyData,
289 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction,
290 OUT EFI_HANDLE *NotifyHandle
291 );
292
293 /**
294 Remove a registered notification function from a particular keystroke.
295
296 @param This Protocol instance pointer.
297 @param NotificationHandle The handle of the notification function being unregistered.
298
299 @retval EFI_SUCCESS The notification function was unregistered successfully.
300 @retval EFI_INVALID_PARAMETER The NotificationHandle is invalid or opening gSimpleTextInExNotifyGuid
301 on NotificationHandle fails.
302 @retval EFI_NOT_FOUND Can not find the matching entry in database.
303
304 **/
305 EFI_STATUS
306 EFIAPI
307 USBKeyboardUnregisterKeyNotify (
308 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
309 IN EFI_HANDLE NotificationHandle
310 );
311
312 #endif
313