]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.c
MdeModulePkg ConSplitterDxe: Support toggle state sync
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbKbDxe / EfiKey.c
... / ...
CommitLineData
1/** @file\r
2 USB Keyboard Driver that manages USB keyboard and produces Simple Text Input\r
3 Protocol and Simple Text Input Ex Protocol.\r
4\r
5Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>\r
6This program and the accompanying materials\r
7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include "EfiKey.h"\r
17#include "KeyBoard.h"\r
18\r
19//\r
20// USB Keyboard Driver Global Variables\r
21//\r
22EFI_DRIVER_BINDING_PROTOCOL gUsbKeyboardDriverBinding = {\r
23 USBKeyboardDriverBindingSupported,\r
24 USBKeyboardDriverBindingStart,\r
25 USBKeyboardDriverBindingStop,\r
26 0xa,\r
27 NULL,\r
28 NULL\r
29};\r
30\r
31/**\r
32 Entrypoint of USB Keyboard Driver.\r
33\r
34 This function is the entrypoint of USB Keyboard Driver. It installs Driver Binding\r
35 Protocols together with Component Name Protocols.\r
36\r
37 @param ImageHandle The firmware allocated handle for the EFI image.\r
38 @param SystemTable A pointer to the EFI System Table.\r
39\r
40 @retval EFI_SUCCESS The entry point is executed successfully.\r
41\r
42**/\r
43EFI_STATUS\r
44EFIAPI\r
45USBKeyboardDriverBindingEntryPoint (\r
46 IN EFI_HANDLE ImageHandle,\r
47 IN EFI_SYSTEM_TABLE *SystemTable\r
48 )\r
49{\r
50 EFI_STATUS Status;\r
51\r
52 Status = EfiLibInstallDriverBindingComponentName2 (\r
53 ImageHandle,\r
54 SystemTable,\r
55 &gUsbKeyboardDriverBinding,\r
56 ImageHandle,\r
57 &gUsbKeyboardComponentName,\r
58 &gUsbKeyboardComponentName2\r
59 );\r
60 ASSERT_EFI_ERROR (Status);\r
61\r
62 return EFI_SUCCESS;\r
63}\r
64\r
65/**\r
66 Check whether USB keyboard driver supports this device.\r
67\r
68 @param This The USB keyboard driver binding protocol.\r
69 @param Controller The controller handle to check.\r
70 @param RemainingDevicePath The remaining device path.\r
71\r
72 @retval EFI_SUCCESS The driver supports this controller.\r
73 @retval other This device isn't supported.\r
74\r
75**/\r
76EFI_STATUS\r
77EFIAPI\r
78USBKeyboardDriverBindingSupported (\r
79 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
80 IN EFI_HANDLE Controller,\r
81 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
82 )\r
83{\r
84 EFI_STATUS Status;\r
85 EFI_USB_IO_PROTOCOL *UsbIo;\r
86\r
87 //\r
88 // Check if USB I/O Protocol is attached on the controller handle.\r
89 //\r
90 Status = gBS->OpenProtocol (\r
91 Controller,\r
92 &gEfiUsbIoProtocolGuid,\r
93 (VOID **) &UsbIo,\r
94 This->DriverBindingHandle,\r
95 Controller,\r
96 EFI_OPEN_PROTOCOL_BY_DRIVER\r
97 );\r
98 if (EFI_ERROR (Status)) {\r
99 return Status;\r
100 }\r
101\r
102 //\r
103 // Use the USB I/O Protocol interface to check whether Controller is\r
104 // a keyboard device that can be managed by this driver.\r
105 //\r
106 Status = EFI_SUCCESS;\r
107\r
108 if (!IsUSBKeyboard (UsbIo)) {\r
109 Status = EFI_UNSUPPORTED;\r
110 }\r
111\r
112 gBS->CloseProtocol (\r
113 Controller,\r
114 &gEfiUsbIoProtocolGuid,\r
115 This->DriverBindingHandle,\r
116 Controller\r
117 );\r
118\r
119 return Status;\r
120}\r
121\r
122/**\r
123 Starts the keyboard device with this driver.\r
124\r
125 This function produces Simple Text Input Protocol and Simple Text Input Ex Protocol,\r
126 initializes the keyboard device, and submit Asynchronous Interrupt Transfer to manage\r
127 this keyboard device.\r
128\r
129 @param This The USB keyboard driver binding instance.\r
130 @param Controller Handle of device to bind driver to.\r
131 @param RemainingDevicePath Optional parameter use to pick a specific child\r
132 device to start.\r
133\r
134 @retval EFI_SUCCESS The controller is controlled by the usb keyboard driver.\r
135 @retval EFI_UNSUPPORTED No interrupt endpoint can be found.\r
136 @retval Other This controller cannot be started.\r
137\r
138**/\r
139EFI_STATUS\r
140EFIAPI\r
141USBKeyboardDriverBindingStart (\r
142 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
143 IN EFI_HANDLE Controller,\r
144 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
145 )\r
146{\r
147 EFI_STATUS Status;\r
148 EFI_USB_IO_PROTOCOL *UsbIo;\r
149 USB_KB_DEV *UsbKeyboardDevice;\r
150 UINT8 EndpointNumber;\r
151 EFI_USB_ENDPOINT_DESCRIPTOR EndpointDescriptor;\r
152 UINT8 Index;\r
153 UINT8 EndpointAddr;\r
154 UINT8 PollingInterval;\r
155 UINT8 PacketSize;\r
156 BOOLEAN Found;\r
157 EFI_TPL OldTpl;\r
158\r
159 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
160 //\r
161 // Open USB I/O Protocol\r
162 //\r
163 Status = gBS->OpenProtocol (\r
164 Controller,\r
165 &gEfiUsbIoProtocolGuid,\r
166 (VOID **) &UsbIo,\r
167 This->DriverBindingHandle,\r
168 Controller,\r
169 EFI_OPEN_PROTOCOL_BY_DRIVER\r
170 );\r
171 if (EFI_ERROR (Status)) {\r
172 goto ErrorExit1;\r
173 }\r
174\r
175 UsbKeyboardDevice = AllocateZeroPool (sizeof (USB_KB_DEV));\r
176 ASSERT (UsbKeyboardDevice != NULL);\r
177\r
178 //\r
179 // Get the Device Path Protocol on Controller's handle\r
180 //\r
181 Status = gBS->OpenProtocol (\r
182 Controller,\r
183 &gEfiDevicePathProtocolGuid,\r
184 (VOID **) &UsbKeyboardDevice->DevicePath,\r
185 This->DriverBindingHandle,\r
186 Controller,\r
187 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
188 );\r
189\r
190 if (EFI_ERROR (Status)) {\r
191 goto ErrorExit;\r
192 }\r
193 //\r
194 // Report that the USB keyboard is being enabled\r
195 //\r
196 REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
197 EFI_PROGRESS_CODE,\r
198 (EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_ENABLE),\r
199 UsbKeyboardDevice->DevicePath\r
200 );\r
201\r
202 //\r
203 // This is pretty close to keyboard detection, so log progress\r
204 //\r
205 REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
206 EFI_PROGRESS_CODE,\r
207 (EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_PRESENCE_DETECT),\r
208 UsbKeyboardDevice->DevicePath\r
209 );\r
210\r
211 UsbKeyboardDevice->UsbIo = UsbIo;\r
212\r
213 //\r
214 // Get interface & endpoint descriptor\r
215 //\r
216 UsbIo->UsbGetInterfaceDescriptor (\r
217 UsbIo,\r
218 &UsbKeyboardDevice->InterfaceDescriptor\r
219 );\r
220\r
221 EndpointNumber = UsbKeyboardDevice->InterfaceDescriptor.NumEndpoints;\r
222\r
223 //\r
224 // Traverse endpoints to find interrupt endpoint\r
225 //\r
226 Found = FALSE;\r
227 for (Index = 0; Index < EndpointNumber; Index++) {\r
228\r
229 UsbIo->UsbGetEndpointDescriptor (\r
230 UsbIo,\r
231 Index,\r
232 &EndpointDescriptor\r
233 );\r
234\r
235 if ((EndpointDescriptor.Attributes & (BIT0 | BIT1)) == USB_ENDPOINT_INTERRUPT) {\r
236 //\r
237 // We only care interrupt endpoint here\r
238 //\r
239 CopyMem(&UsbKeyboardDevice->IntEndpointDescriptor, &EndpointDescriptor, sizeof(EndpointDescriptor));\r
240 Found = TRUE;\r
241 break;\r
242 }\r
243 }\r
244\r
245 if (!Found) {\r
246 //\r
247 // Report Status Code to indicate that there is no USB keyboard\r
248 //\r
249 REPORT_STATUS_CODE (\r
250 EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
251 (EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_NOT_DETECTED)\r
252 );\r
253 //\r
254 // No interrupt endpoint found, then return unsupported.\r
255 //\r
256 Status = EFI_UNSUPPORTED;\r
257 goto ErrorExit;\r
258 }\r
259\r
260 REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
261 EFI_PROGRESS_CODE,\r
262 (EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_DETECTED),\r
263 UsbKeyboardDevice->DevicePath\r
264 );\r
265\r
266 UsbKeyboardDevice->Signature = USB_KB_DEV_SIGNATURE;\r
267 UsbKeyboardDevice->SimpleInput.Reset = USBKeyboardReset;\r
268 UsbKeyboardDevice->SimpleInput.ReadKeyStroke = USBKeyboardReadKeyStroke;\r
269\r
270 UsbKeyboardDevice->SimpleInputEx.Reset = USBKeyboardResetEx;\r
271 UsbKeyboardDevice->SimpleInputEx.ReadKeyStrokeEx = USBKeyboardReadKeyStrokeEx;\r
272 UsbKeyboardDevice->SimpleInputEx.SetState = USBKeyboardSetState;\r
273 UsbKeyboardDevice->SimpleInputEx.RegisterKeyNotify = USBKeyboardRegisterKeyNotify;\r
274 UsbKeyboardDevice->SimpleInputEx.UnregisterKeyNotify = USBKeyboardUnregisterKeyNotify;\r
275\r
276 InitializeListHead (&UsbKeyboardDevice->NotifyList);\r
277\r
278 Status = gBS->CreateEvent (\r
279 EVT_TIMER | EVT_NOTIFY_SIGNAL,\r
280 TPL_NOTIFY,\r
281 USBKeyboardTimerHandler,\r
282 UsbKeyboardDevice,\r
283 &UsbKeyboardDevice->TimerEvent\r
284 );\r
285 if (!EFI_ERROR (Status)) {\r
286 Status = gBS->SetTimer (UsbKeyboardDevice->TimerEvent, TimerPeriodic, KEYBOARD_TIMER_INTERVAL);\r
287 }\r
288 if (EFI_ERROR (Status)) {\r
289 goto ErrorExit;\r
290 }\r
291\r
292 Status = gBS->CreateEvent (\r
293 EVT_NOTIFY_WAIT,\r
294 TPL_NOTIFY,\r
295 USBKeyboardWaitForKey,\r
296 UsbKeyboardDevice,\r
297 &(UsbKeyboardDevice->SimpleInputEx.WaitForKeyEx)\r
298 );\r
299\r
300 if (EFI_ERROR (Status)) {\r
301 goto ErrorExit;\r
302 }\r
303\r
304 Status = gBS->CreateEvent (\r
305 EVT_NOTIFY_WAIT,\r
306 TPL_NOTIFY,\r
307 USBKeyboardWaitForKey,\r
308 UsbKeyboardDevice,\r
309 &(UsbKeyboardDevice->SimpleInput.WaitForKey)\r
310 );\r
311 if (EFI_ERROR (Status)) {\r
312 goto ErrorExit;\r
313 }\r
314\r
315 //\r
316 // Install Simple Text Input Protocol and Simple Text Input Ex Protocol\r
317 // for the USB keyboard device.\r
318 // USB keyboard is a hot plug device, and expected to work immediately\r
319 // when plugging into system, other conventional console devices could\r
320 // distinguish it by its device path.\r
321 //\r
322 Status = gBS->InstallMultipleProtocolInterfaces (\r
323 &Controller,\r
324 &gEfiSimpleTextInProtocolGuid,\r
325 &UsbKeyboardDevice->SimpleInput,\r
326 &gEfiSimpleTextInputExProtocolGuid,\r
327 &UsbKeyboardDevice->SimpleInputEx,\r
328 NULL\r
329 );\r
330 if (EFI_ERROR (Status)) {\r
331 goto ErrorExit;\r
332 }\r
333\r
334 UsbKeyboardDevice->ControllerHandle = Controller;\r
335 Status = InitKeyboardLayout (UsbKeyboardDevice);\r
336 if (EFI_ERROR (Status)) {\r
337 gBS->UninstallMultipleProtocolInterfaces (\r
338 Controller,\r
339 &gEfiSimpleTextInProtocolGuid,\r
340 &UsbKeyboardDevice->SimpleInput,\r
341 &gEfiSimpleTextInputExProtocolGuid,\r
342 &UsbKeyboardDevice->SimpleInputEx,\r
343 NULL\r
344 );\r
345 goto ErrorExit;\r
346 }\r
347\r
348\r
349 //\r
350 // Reset USB Keyboard Device exhaustively.\r
351 //\r
352 Status = UsbKeyboardDevice->SimpleInputEx.Reset (\r
353 &UsbKeyboardDevice->SimpleInputEx,\r
354 TRUE\r
355 );\r
356 if (EFI_ERROR (Status)) {\r
357 gBS->UninstallMultipleProtocolInterfaces (\r
358 Controller,\r
359 &gEfiSimpleTextInProtocolGuid,\r
360 &UsbKeyboardDevice->SimpleInput,\r
361 &gEfiSimpleTextInputExProtocolGuid,\r
362 &UsbKeyboardDevice->SimpleInputEx,\r
363 NULL\r
364 );\r
365 goto ErrorExit;\r
366 }\r
367\r
368 //\r
369 // Submit Asynchronous Interrupt Transfer to manage this device.\r
370 //\r
371 EndpointAddr = UsbKeyboardDevice->IntEndpointDescriptor.EndpointAddress;\r
372 PollingInterval = UsbKeyboardDevice->IntEndpointDescriptor.Interval;\r
373 PacketSize = (UINT8) (UsbKeyboardDevice->IntEndpointDescriptor.MaxPacketSize);\r
374\r
375 Status = UsbIo->UsbAsyncInterruptTransfer (\r
376 UsbIo,\r
377 EndpointAddr,\r
378 TRUE,\r
379 PollingInterval,\r
380 PacketSize,\r
381 KeyboardHandler,\r
382 UsbKeyboardDevice\r
383 );\r
384\r
385 if (EFI_ERROR (Status)) {\r
386 gBS->UninstallMultipleProtocolInterfaces (\r
387 Controller,\r
388 &gEfiSimpleTextInProtocolGuid,\r
389 &UsbKeyboardDevice->SimpleInput,\r
390 &gEfiSimpleTextInputExProtocolGuid,\r
391 &UsbKeyboardDevice->SimpleInputEx,\r
392 NULL\r
393 );\r
394 goto ErrorExit;\r
395 }\r
396\r
397 UsbKeyboardDevice->ControllerNameTable = NULL;\r
398 AddUnicodeString2 (\r
399 "eng",\r
400 gUsbKeyboardComponentName.SupportedLanguages,\r
401 &UsbKeyboardDevice->ControllerNameTable,\r
402 L"Generic Usb Keyboard",\r
403 TRUE\r
404 );\r
405 AddUnicodeString2 (\r
406 "en",\r
407 gUsbKeyboardComponentName2.SupportedLanguages,\r
408 &UsbKeyboardDevice->ControllerNameTable,\r
409 L"Generic Usb Keyboard",\r
410 FALSE\r
411 );\r
412\r
413 gBS->RestoreTPL (OldTpl);\r
414 return EFI_SUCCESS;\r
415\r
416//\r
417// Error handler\r
418//\r
419ErrorExit:\r
420 if (UsbKeyboardDevice != NULL) {\r
421 if (UsbKeyboardDevice->TimerEvent != NULL) {\r
422 gBS->CloseEvent (UsbKeyboardDevice->TimerEvent);\r
423 }\r
424 if (UsbKeyboardDevice->SimpleInput.WaitForKey != NULL) {\r
425 gBS->CloseEvent (UsbKeyboardDevice->SimpleInput.WaitForKey);\r
426 }\r
427 if (UsbKeyboardDevice->SimpleInputEx.WaitForKeyEx != NULL) {\r
428 gBS->CloseEvent (UsbKeyboardDevice->SimpleInputEx.WaitForKeyEx);\r
429 }\r
430 if (UsbKeyboardDevice->KeyboardLayoutEvent != NULL) {\r
431 ReleaseKeyboardLayoutResources (UsbKeyboardDevice);\r
432 gBS->CloseEvent (UsbKeyboardDevice->KeyboardLayoutEvent);\r
433 }\r
434 FreePool (UsbKeyboardDevice);\r
435 UsbKeyboardDevice = NULL;\r
436 }\r
437 gBS->CloseProtocol (\r
438 Controller,\r
439 &gEfiUsbIoProtocolGuid,\r
440 This->DriverBindingHandle,\r
441 Controller\r
442 );\r
443\r
444ErrorExit1:\r
445 gBS->RestoreTPL (OldTpl);\r
446\r
447 return Status;\r
448\r
449}\r
450\r
451\r
452/**\r
453 Stop the USB keyboard device handled by this driver.\r
454\r
455 @param This The USB keyboard driver binding protocol.\r
456 @param Controller The controller to release.\r
457 @param NumberOfChildren The number of handles in ChildHandleBuffer.\r
458 @param ChildHandleBuffer The array of child handle.\r
459\r
460 @retval EFI_SUCCESS The device was stopped.\r
461 @retval EFI_UNSUPPORTED Simple Text In Protocol or Simple Text In Ex Protocol\r
462 is not installed on Controller.\r
463 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r
464 @retval Others Fail to uninstall protocols attached on the device.\r
465\r
466**/\r
467EFI_STATUS\r
468EFIAPI\r
469USBKeyboardDriverBindingStop (\r
470 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
471 IN EFI_HANDLE Controller,\r
472 IN UINTN NumberOfChildren,\r
473 IN EFI_HANDLE *ChildHandleBuffer\r
474 )\r
475{\r
476 EFI_STATUS Status;\r
477 EFI_SIMPLE_TEXT_INPUT_PROTOCOL *SimpleInput;\r
478 USB_KB_DEV *UsbKeyboardDevice;\r
479\r
480 Status = gBS->OpenProtocol (\r
481 Controller,\r
482 &gEfiSimpleTextInProtocolGuid,\r
483 (VOID **) &SimpleInput,\r
484 This->DriverBindingHandle,\r
485 Controller,\r
486 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
487 );\r
488 if (EFI_ERROR (Status)) {\r
489 return EFI_UNSUPPORTED;\r
490 }\r
491\r
492 Status = gBS->OpenProtocol (\r
493 Controller,\r
494 &gEfiSimpleTextInputExProtocolGuid,\r
495 NULL,\r
496 This->DriverBindingHandle,\r
497 Controller,\r
498 EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
499 );\r
500 if (EFI_ERROR (Status)) {\r
501 return EFI_UNSUPPORTED;\r
502 }\r
503\r
504 UsbKeyboardDevice = USB_KB_DEV_FROM_THIS (SimpleInput);\r
505\r
506 //\r
507 // The key data input from this device will be disabled.\r
508 //\r
509 REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
510 EFI_PROGRESS_CODE,\r
511 (EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_DISABLE),\r
512 UsbKeyboardDevice->DevicePath\r
513 );\r
514\r
515 //\r
516 // Delete the Asynchronous Interrupt Transfer from this device\r
517 //\r
518 UsbKeyboardDevice->UsbIo->UsbAsyncInterruptTransfer (\r
519 UsbKeyboardDevice->UsbIo,\r
520 UsbKeyboardDevice->IntEndpointDescriptor.EndpointAddress,\r
521 FALSE,\r
522 UsbKeyboardDevice->IntEndpointDescriptor.Interval,\r
523 0,\r
524 NULL,\r
525 NULL\r
526 );\r
527\r
528 gBS->CloseProtocol (\r
529 Controller,\r
530 &gEfiUsbIoProtocolGuid,\r
531 This->DriverBindingHandle,\r
532 Controller\r
533 );\r
534\r
535 Status = gBS->UninstallMultipleProtocolInterfaces (\r
536 Controller,\r
537 &gEfiSimpleTextInProtocolGuid,\r
538 &UsbKeyboardDevice->SimpleInput,\r
539 &gEfiSimpleTextInputExProtocolGuid,\r
540 &UsbKeyboardDevice->SimpleInputEx,\r
541 NULL\r
542 );\r
543 //\r
544 // Free all resources.\r
545 //\r
546 gBS->CloseEvent (UsbKeyboardDevice->TimerEvent);\r
547 gBS->CloseEvent (UsbKeyboardDevice->RepeatTimer);\r
548 gBS->CloseEvent (UsbKeyboardDevice->DelayedRecoveryEvent);\r
549 gBS->CloseEvent (UsbKeyboardDevice->SimpleInput.WaitForKey);\r
550 gBS->CloseEvent (UsbKeyboardDevice->SimpleInputEx.WaitForKeyEx);\r
551 KbdFreeNotifyList (&UsbKeyboardDevice->NotifyList);\r
552\r
553 ReleaseKeyboardLayoutResources (UsbKeyboardDevice);\r
554 gBS->CloseEvent (UsbKeyboardDevice->KeyboardLayoutEvent);\r
555\r
556 if (UsbKeyboardDevice->ControllerNameTable != NULL) {\r
557 FreeUnicodeStringTable (UsbKeyboardDevice->ControllerNameTable);\r
558 }\r
559\r
560 DestroyQueue (&UsbKeyboardDevice->UsbKeyQueue);\r
561 DestroyQueue (&UsbKeyboardDevice->EfiKeyQueue);\r
562\r
563 FreePool (UsbKeyboardDevice);\r
564\r
565 return Status;\r
566}\r
567\r
568/**\r
569 Internal function to read the next keystroke from the keyboard buffer.\r
570\r
571 @param UsbKeyboardDevice USB keyboard's private structure.\r
572 @param KeyData A pointer to buffer to hold the keystroke\r
573 data for the key that was pressed.\r
574\r
575 @retval EFI_SUCCESS The keystroke information was returned.\r
576 @retval EFI_NOT_READY There was no keystroke data availiable.\r
577 @retval EFI_DEVICE_ERROR The keystroke information was not returned due to\r
578 hardware errors.\r
579 @retval EFI_INVALID_PARAMETER KeyData is NULL.\r
580 @retval Others Fail to translate keycode into EFI_INPUT_KEY\r
581\r
582**/\r
583EFI_STATUS\r
584USBKeyboardReadKeyStrokeWorker (\r
585 IN OUT USB_KB_DEV *UsbKeyboardDevice,\r
586 OUT EFI_KEY_DATA *KeyData\r
587 )\r
588{\r
589 if (KeyData == NULL) {\r
590 return EFI_INVALID_PARAMETER;\r
591 }\r
592\r
593 if (IsQueueEmpty (&UsbKeyboardDevice->EfiKeyQueue)) {\r
594 return EFI_NOT_READY;\r
595 }\r
596\r
597 Dequeue (&UsbKeyboardDevice->EfiKeyQueue, KeyData, sizeof (*KeyData));\r
598\r
599 return EFI_SUCCESS;\r
600}\r
601\r
602/**\r
603 Reset the input device and optionally run diagnostics\r
604\r
605 There are 2 types of reset for USB keyboard.\r
606 For non-exhaustive reset, only keyboard buffer is cleared.\r
607 For exhaustive reset, in addition to clearance of keyboard buffer, the hardware status\r
608 is also re-initialized.\r
609\r
610 @param This Protocol instance pointer.\r
611 @param ExtendedVerification Driver may perform diagnostics on reset.\r
612\r
613 @retval EFI_SUCCESS The device was reset.\r
614 @retval EFI_DEVICE_ERROR The device is not functioning properly and could not be reset.\r
615\r
616**/\r
617EFI_STATUS\r
618EFIAPI\r
619USBKeyboardReset (\r
620 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,\r
621 IN BOOLEAN ExtendedVerification\r
622 )\r
623{\r
624 EFI_STATUS Status;\r
625 USB_KB_DEV *UsbKeyboardDevice;\r
626\r
627 UsbKeyboardDevice = USB_KB_DEV_FROM_THIS (This);\r
628\r
629 REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
630 EFI_PROGRESS_CODE,\r
631 (EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_RESET),\r
632 UsbKeyboardDevice->DevicePath\r
633 );\r
634\r
635 //\r
636 // Non-exhaustive reset:\r
637 // only reset private data structures.\r
638 //\r
639 if (!ExtendedVerification) {\r
640 REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
641 EFI_PROGRESS_CODE,\r
642 (EFI_PERIPHERAL_KEYBOARD | EFI_P_KEYBOARD_PC_CLEAR_BUFFER),\r
643 UsbKeyboardDevice->DevicePath\r
644 );\r
645 //\r
646 // Clear the key buffer of this USB keyboard\r
647 //\r
648 InitQueue (&UsbKeyboardDevice->UsbKeyQueue, sizeof (USB_KEY));\r
649 InitQueue (&UsbKeyboardDevice->EfiKeyQueue, sizeof (EFI_KEY_DATA));\r
650\r
651 return EFI_SUCCESS;\r
652 }\r
653\r
654 //\r
655 // Exhaustive reset\r
656 //\r
657 Status = InitUSBKeyboard (UsbKeyboardDevice);\r
658 if (EFI_ERROR (Status)) {\r
659 return EFI_DEVICE_ERROR;\r
660 }\r
661\r
662 return EFI_SUCCESS;\r
663}\r
664\r
665\r
666/**\r
667 Reads the next keystroke from the input device.\r
668\r
669 @param This The EFI_SIMPLE_TEXT_INPUT_PROTOCOL instance.\r
670 @param Key A pointer to a buffer that is filled in with the keystroke\r
671 information for the key that was pressed.\r
672\r
673 @retval EFI_SUCCESS The keystroke information was returned.\r
674 @retval EFI_NOT_READY There was no keystroke data availiable.\r
675 @retval EFI_DEVICE_ERROR The keystroke information was not returned due to\r
676 hardware errors.\r
677\r
678**/\r
679EFI_STATUS\r
680EFIAPI\r
681USBKeyboardReadKeyStroke (\r
682 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,\r
683 OUT EFI_INPUT_KEY *Key\r
684 )\r
685{\r
686 USB_KB_DEV *UsbKeyboardDevice;\r
687 EFI_STATUS Status;\r
688 EFI_KEY_DATA KeyData;\r
689\r
690 UsbKeyboardDevice = USB_KB_DEV_FROM_THIS (This);\r
691\r
692 //\r
693 // Considering if the partial keystroke is enabled, there maybe a partial\r
694 // keystroke in the queue, so here skip the partial keystroke and get the\r
695 // next key from the queue\r
696 //\r
697 while (1) {\r
698 Status = USBKeyboardReadKeyStrokeWorker (UsbKeyboardDevice, &KeyData);\r
699 if (EFI_ERROR (Status)) {\r
700 return Status;\r
701 }\r
702 //\r
703 // SimpleTextIn Protocol doesn't support partial keystroke;\r
704 //\r
705 if (KeyData.Key.ScanCode == CHAR_NULL && KeyData.Key.UnicodeChar == SCAN_NULL) {\r
706 continue;\r
707 }\r
708 //\r
709 // Translate the CTRL-Alpha characters to their corresponding control value\r
710 // (ctrl-a = 0x0001 through ctrl-Z = 0x001A)\r
711 //\r
712 if ((KeyData.KeyState.KeyShiftState & (EFI_LEFT_CONTROL_PRESSED | EFI_RIGHT_CONTROL_PRESSED)) != 0) {\r
713 if (KeyData.Key.UnicodeChar >= L'a' && KeyData.Key.UnicodeChar <= L'z') {\r
714 KeyData.Key.UnicodeChar = (CHAR16) (KeyData.Key.UnicodeChar - L'a' + 1);\r
715 } else if (KeyData.Key.UnicodeChar >= L'A' && KeyData.Key.UnicodeChar <= L'Z') {\r
716 KeyData.Key.UnicodeChar = (CHAR16) (KeyData.Key.UnicodeChar - L'A' + 1);\r
717 }\r
718 }\r
719\r
720 CopyMem (Key, &KeyData.Key, sizeof (EFI_INPUT_KEY));\r
721 return EFI_SUCCESS;\r
722 }\r
723}\r
724\r
725\r
726/**\r
727 Event notification function registered for EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx\r
728 and EFI_SIMPLE_TEXT_INPUT_PROTOCOL.WaitForKey.\r
729\r
730 @param Event Event to be signaled when a key is pressed.\r
731 @param Context Points to USB_KB_DEV instance.\r
732\r
733**/\r
734VOID\r
735EFIAPI\r
736USBKeyboardWaitForKey (\r
737 IN EFI_EVENT Event,\r
738 IN VOID *Context\r
739 )\r
740{\r
741 USB_KB_DEV *UsbKeyboardDevice;\r
742 EFI_KEY_DATA KeyData;\r
743 EFI_TPL OldTpl;\r
744\r
745 UsbKeyboardDevice = (USB_KB_DEV *) Context;\r
746\r
747 //\r
748 // Enter critical section\r
749 // \r
750 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
751 \r
752 //\r
753 // WaitforKey doesn't suppor the partial key.\r
754 // Considering if the partial keystroke is enabled, there maybe a partial\r
755 // keystroke in the queue, so here skip the partial keystroke and get the\r
756 // next key from the queue\r
757 //\r
758 while (!IsQueueEmpty (&UsbKeyboardDevice->EfiKeyQueue)) {\r
759 //\r
760 // If there is pending key, signal the event.\r
761 //\r
762 CopyMem (\r
763 &KeyData,\r
764 UsbKeyboardDevice->EfiKeyQueue.Buffer[UsbKeyboardDevice->EfiKeyQueue.Head],\r
765 sizeof (EFI_KEY_DATA)\r
766 );\r
767 if (KeyData.Key.ScanCode == SCAN_NULL && KeyData.Key.UnicodeChar == CHAR_NULL) {\r
768 Dequeue (&UsbKeyboardDevice->EfiKeyQueue, &KeyData, sizeof (EFI_KEY_DATA));\r
769 continue;\r
770 }\r
771 gBS->SignalEvent (Event);\r
772 break;\r
773 }\r
774 //\r
775 // Leave critical section and return\r
776 //\r
777 gBS->RestoreTPL (OldTpl);\r
778}\r
779\r
780/**\r
781 Timer handler to convert the key from USB.\r
782\r
783 @param Event Indicates the event that invoke this function.\r
784 @param Context Indicates the calling context.\r
785**/\r
786VOID\r
787EFIAPI\r
788USBKeyboardTimerHandler (\r
789 IN EFI_EVENT Event,\r
790 IN VOID *Context\r
791 )\r
792{\r
793 EFI_STATUS Status;\r
794 USB_KB_DEV *UsbKeyboardDevice;\r
795 UINT8 KeyCode;\r
796 EFI_KEY_DATA KeyData;\r
797\r
798 UsbKeyboardDevice = (USB_KB_DEV *) Context;\r
799\r
800 //\r
801 // Fetch raw data from the USB keyboard buffer,\r
802 // and translate it into USB keycode.\r
803 //\r
804 Status = USBParseKey (UsbKeyboardDevice, &KeyCode);\r
805 if (EFI_ERROR (Status)) {\r
806 return ;\r
807 }\r
808\r
809 //\r
810 // Translate saved USB keycode into EFI_INPUT_KEY\r
811 //\r
812 Status = UsbKeyCodeToEfiInputKey (UsbKeyboardDevice, KeyCode, &KeyData);\r
813 if (EFI_ERROR (Status)) {\r
814 return ;\r
815 }\r
816\r
817 //\r
818 // Insert to the EFI Key queue\r
819 //\r
820 Enqueue (&UsbKeyboardDevice->EfiKeyQueue, &KeyData, sizeof (KeyData));\r
821}\r
822\r
823/**\r
824 Free keyboard notify list.\r
825\r
826 @param NotifyList The keyboard notify list to free.\r
827\r
828 @retval EFI_SUCCESS Free the notify list successfully.\r
829 @retval EFI_INVALID_PARAMETER NotifyList is NULL.\r
830\r
831**/\r
832EFI_STATUS\r
833KbdFreeNotifyList (\r
834 IN OUT LIST_ENTRY *NotifyList\r
835 )\r
836{\r
837 KEYBOARD_CONSOLE_IN_EX_NOTIFY *NotifyNode;\r
838 LIST_ENTRY *Link;\r
839\r
840 if (NotifyList == NULL) {\r
841 return EFI_INVALID_PARAMETER;\r
842 }\r
843 while (!IsListEmpty (NotifyList)) {\r
844 Link = GetFirstNode (NotifyList);\r
845 NotifyNode = CR (Link, KEYBOARD_CONSOLE_IN_EX_NOTIFY, NotifyEntry, USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE);\r
846 RemoveEntryList (Link);\r
847 FreePool (NotifyNode);\r
848 }\r
849\r
850 return EFI_SUCCESS;\r
851}\r
852\r
853/**\r
854 Check whether the pressed key matches a registered key or not.\r
855\r
856 @param RegsiteredData A pointer to keystroke data for the key that was registered.\r
857 @param InputData A pointer to keystroke data for the key that was pressed.\r
858\r
859 @retval TRUE Key pressed matches a registered key.\r
860 @retval FLASE Key pressed does not matches a registered key.\r
861\r
862**/\r
863BOOLEAN\r
864IsKeyRegistered (\r
865 IN EFI_KEY_DATA *RegsiteredData,\r
866 IN EFI_KEY_DATA *InputData\r
867 )\r
868{\r
869 ASSERT (RegsiteredData != NULL && InputData != NULL);\r
870\r
871 if ((RegsiteredData->Key.ScanCode != InputData->Key.ScanCode) ||\r
872 (RegsiteredData->Key.UnicodeChar != InputData->Key.UnicodeChar)) {\r
873 return FALSE;\r
874 }\r
875\r
876 //\r
877 // Assume KeyShiftState/KeyToggleState = 0 in Registered key data means these state could be ignored.\r
878 //\r
879 if (RegsiteredData->KeyState.KeyShiftState != 0 &&\r
880 RegsiteredData->KeyState.KeyShiftState != InputData->KeyState.KeyShiftState) {\r
881 return FALSE;\r
882 }\r
883 if (RegsiteredData->KeyState.KeyToggleState != 0 &&\r
884 RegsiteredData->KeyState.KeyToggleState != InputData->KeyState.KeyToggleState) {\r
885 return FALSE;\r
886 }\r
887\r
888 return TRUE;\r
889}\r
890\r
891//\r
892// Simple Text Input Ex protocol functions\r
893//\r
894/**\r
895 Resets the input device hardware.\r
896\r
897 The Reset() function resets the input device hardware. As part\r
898 of initialization process, the firmware/device will make a quick\r
899 but reasonable attempt to verify that the device is functioning.\r
900 If the ExtendedVerification flag is TRUE the firmware may take\r
901 an extended amount of time to verify the device is operating on\r
902 reset. Otherwise the reset operation is to occur as quickly as\r
903 possible. The hardware verification process is not defined by\r
904 this specification and is left up to the platform firmware or\r
905 driver to implement.\r
906\r
907 @param This A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance.\r
908\r
909 @param ExtendedVerification Indicates that the driver may perform a more exhaustive\r
910 verification operation of the device during reset.\r
911\r
912 @retval EFI_SUCCESS The device was reset.\r
913 @retval EFI_DEVICE_ERROR The device is not functioning correctly and could not be reset.\r
914\r
915**/\r
916EFI_STATUS\r
917EFIAPI\r
918USBKeyboardResetEx (\r
919 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
920 IN BOOLEAN ExtendedVerification\r
921 )\r
922{\r
923 EFI_STATUS Status;\r
924 USB_KB_DEV *UsbKeyboardDevice;\r
925\r
926 UsbKeyboardDevice = TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS (This);\r
927\r
928 Status = UsbKeyboardDevice->SimpleInput.Reset (&UsbKeyboardDevice->SimpleInput, ExtendedVerification);\r
929 if (EFI_ERROR (Status)) {\r
930 return EFI_DEVICE_ERROR;\r
931 }\r
932\r
933 UsbKeyboardDevice->KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID;\r
934 UsbKeyboardDevice->KeyState.KeyToggleState = EFI_TOGGLE_STATE_VALID;\r
935\r
936 return EFI_SUCCESS;\r
937\r
938}\r
939\r
940/**\r
941 Reads the next keystroke from the input device.\r
942\r
943 @param This Protocol instance pointer.\r
944 @param KeyData A pointer to a buffer that is filled in with the keystroke\r
945 state data for the key that was pressed.\r
946\r
947 @retval EFI_SUCCESS The keystroke information was returned.\r
948 @retval EFI_NOT_READY There was no keystroke data available.\r
949 @retval EFI_DEVICE_ERROR The keystroke information was not returned due to\r
950 hardware errors.\r
951 @retval EFI_INVALID_PARAMETER KeyData is NULL.\r
952\r
953**/\r
954EFI_STATUS\r
955EFIAPI\r
956USBKeyboardReadKeyStrokeEx (\r
957 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
958 OUT EFI_KEY_DATA *KeyData\r
959 )\r
960{\r
961 USB_KB_DEV *UsbKeyboardDevice;\r
962\r
963 if (KeyData == NULL) {\r
964 return EFI_INVALID_PARAMETER;\r
965 }\r
966\r
967 UsbKeyboardDevice = TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS (This);\r
968\r
969 return USBKeyboardReadKeyStrokeWorker (UsbKeyboardDevice, KeyData);\r
970\r
971}\r
972\r
973/**\r
974 Set certain state for the input device.\r
975\r
976 @param This Protocol instance pointer.\r
977 @param KeyToggleState A pointer to the EFI_KEY_TOGGLE_STATE to set the\r
978 state for the input device.\r
979\r
980 @retval EFI_SUCCESS The device state was set appropriately.\r
981 @retval EFI_DEVICE_ERROR The device is not functioning correctly and could\r
982 not have the setting adjusted.\r
983 @retval EFI_UNSUPPORTED The device does not support the ability to have its state set.\r
984 @retval EFI_INVALID_PARAMETER KeyToggleState is NULL.\r
985\r
986**/\r
987EFI_STATUS\r
988EFIAPI\r
989USBKeyboardSetState (\r
990 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
991 IN EFI_KEY_TOGGLE_STATE *KeyToggleState\r
992 )\r
993{\r
994 USB_KB_DEV *UsbKeyboardDevice;\r
995\r
996 if (KeyToggleState == NULL) {\r
997 return EFI_INVALID_PARAMETER;\r
998 }\r
999\r
1000 UsbKeyboardDevice = TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS (This);\r
1001\r
1002 if (((UsbKeyboardDevice->KeyState.KeyToggleState & EFI_TOGGLE_STATE_VALID) != EFI_TOGGLE_STATE_VALID) ||\r
1003 ((*KeyToggleState & EFI_TOGGLE_STATE_VALID) != EFI_TOGGLE_STATE_VALID)) {\r
1004 return EFI_UNSUPPORTED;\r
1005 }\r
1006\r
1007 //\r
1008 // Update the status light\r
1009 //\r
1010\r
1011 UsbKeyboardDevice->ScrollOn = FALSE;\r
1012 UsbKeyboardDevice->NumLockOn = FALSE;\r
1013 UsbKeyboardDevice->CapsOn = FALSE;\r
1014 UsbKeyboardDevice->IsSupportPartialKey = FALSE;\r
1015\r
1016 if ((*KeyToggleState & EFI_SCROLL_LOCK_ACTIVE) == EFI_SCROLL_LOCK_ACTIVE) {\r
1017 UsbKeyboardDevice->ScrollOn = TRUE;\r
1018 }\r
1019 if ((*KeyToggleState & EFI_NUM_LOCK_ACTIVE) == EFI_NUM_LOCK_ACTIVE) {\r
1020 UsbKeyboardDevice->NumLockOn = TRUE;\r
1021 }\r
1022 if ((*KeyToggleState & EFI_CAPS_LOCK_ACTIVE) == EFI_CAPS_LOCK_ACTIVE) {\r
1023 UsbKeyboardDevice->CapsOn = TRUE;\r
1024 }\r
1025 if ((*KeyToggleState & EFI_KEY_STATE_EXPOSED) == EFI_KEY_STATE_EXPOSED) {\r
1026 UsbKeyboardDevice->IsSupportPartialKey = TRUE;\r
1027 }\r
1028\r
1029 SetKeyLED (UsbKeyboardDevice);\r
1030\r
1031 UsbKeyboardDevice->KeyState.KeyToggleState = *KeyToggleState;\r
1032\r
1033 return EFI_SUCCESS;\r
1034\r
1035}\r
1036\r
1037/**\r
1038 Register a notification function for a particular keystroke for the input device.\r
1039\r
1040 @param This Protocol instance pointer.\r
1041 @param KeyData A pointer to a buffer that is filled in with the keystroke\r
1042 information data for the key that was pressed.\r
1043 @param KeyNotificationFunction Points to the function to be called when the key\r
1044 sequence is typed specified by KeyData.\r
1045 @param NotifyHandle Points to the unique handle assigned to the registered notification.\r
1046\r
1047 @retval EFI_SUCCESS The notification function was registered successfully.\r
1048 @retval EFI_OUT_OF_RESOURCES Unable to allocate resources for necessary data structures.\r
1049 @retval EFI_INVALID_PARAMETER KeyData or NotifyHandle or KeyNotificationFunction is NULL.\r
1050\r
1051**/\r
1052EFI_STATUS\r
1053EFIAPI\r
1054USBKeyboardRegisterKeyNotify (\r
1055 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
1056 IN EFI_KEY_DATA *KeyData,\r
1057 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction,\r
1058 OUT VOID **NotifyHandle\r
1059 )\r
1060{\r
1061 USB_KB_DEV *UsbKeyboardDevice;\r
1062 KEYBOARD_CONSOLE_IN_EX_NOTIFY *NewNotify;\r
1063 LIST_ENTRY *Link;\r
1064 LIST_ENTRY *NotifyList;\r
1065 KEYBOARD_CONSOLE_IN_EX_NOTIFY *CurrentNotify;\r
1066\r
1067 if (KeyData == NULL || NotifyHandle == NULL || KeyNotificationFunction == NULL) {\r
1068 return EFI_INVALID_PARAMETER;\r
1069 }\r
1070\r
1071 UsbKeyboardDevice = TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS (This);\r
1072\r
1073 //\r
1074 // Return EFI_SUCCESS if the (KeyData, NotificationFunction) is already registered.\r
1075 //\r
1076 NotifyList = &UsbKeyboardDevice->NotifyList;\r
1077\r
1078 for (Link = GetFirstNode (NotifyList);\r
1079 !IsNull (NotifyList, Link);\r
1080 Link = GetNextNode (NotifyList, Link)) {\r
1081 CurrentNotify = CR (\r
1082 Link,\r
1083 KEYBOARD_CONSOLE_IN_EX_NOTIFY,\r
1084 NotifyEntry,\r
1085 USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE\r
1086 );\r
1087 if (IsKeyRegistered (&CurrentNotify->KeyData, KeyData)) {\r
1088 if (CurrentNotify->KeyNotificationFn == KeyNotificationFunction) {\r
1089 *NotifyHandle = CurrentNotify;\r
1090 return EFI_SUCCESS;\r
1091 }\r
1092 }\r
1093 }\r
1094\r
1095 //\r
1096 // Allocate resource to save the notification function\r
1097 //\r
1098 NewNotify = (KEYBOARD_CONSOLE_IN_EX_NOTIFY *) AllocateZeroPool (sizeof (KEYBOARD_CONSOLE_IN_EX_NOTIFY));\r
1099 if (NewNotify == NULL) {\r
1100 return EFI_OUT_OF_RESOURCES;\r
1101 }\r
1102\r
1103 NewNotify->Signature = USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE;\r
1104 NewNotify->KeyNotificationFn = KeyNotificationFunction;\r
1105 CopyMem (&NewNotify->KeyData, KeyData, sizeof (EFI_KEY_DATA));\r
1106 InsertTailList (&UsbKeyboardDevice->NotifyList, &NewNotify->NotifyEntry);\r
1107\r
1108\r
1109 *NotifyHandle = NewNotify;\r
1110\r
1111 return EFI_SUCCESS;\r
1112\r
1113}\r
1114\r
1115/**\r
1116 Remove a registered notification function from a particular keystroke.\r
1117\r
1118 @param This Protocol instance pointer.\r
1119 @param NotificationHandle The handle of the notification function being unregistered.\r
1120\r
1121 @retval EFI_SUCCESS The notification function was unregistered successfully.\r
1122 @retval EFI_INVALID_PARAMETER The NotificationHandle is invalid\r
1123\r
1124**/\r
1125EFI_STATUS\r
1126EFIAPI\r
1127USBKeyboardUnregisterKeyNotify (\r
1128 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
1129 IN VOID *NotificationHandle\r
1130 )\r
1131{\r
1132 USB_KB_DEV *UsbKeyboardDevice;\r
1133 KEYBOARD_CONSOLE_IN_EX_NOTIFY *CurrentNotify;\r
1134 LIST_ENTRY *Link;\r
1135 LIST_ENTRY *NotifyList;\r
1136\r
1137 if (NotificationHandle == NULL) {\r
1138 return EFI_INVALID_PARAMETER;\r
1139 }\r
1140\r
1141 UsbKeyboardDevice = TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS (This);\r
1142\r
1143 //\r
1144 // Traverse notify list of USB keyboard and remove the entry of NotificationHandle.\r
1145 //\r
1146 NotifyList = &UsbKeyboardDevice->NotifyList;\r
1147 for (Link = GetFirstNode (NotifyList);\r
1148 !IsNull (NotifyList, Link);\r
1149 Link = GetNextNode (NotifyList, Link)) {\r
1150 CurrentNotify = CR (\r
1151 Link,\r
1152 KEYBOARD_CONSOLE_IN_EX_NOTIFY,\r
1153 NotifyEntry,\r
1154 USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE\r
1155 );\r
1156 if (CurrentNotify == NotificationHandle) {\r
1157 //\r
1158 // Remove the notification function from NotifyList and free resources\r
1159 //\r
1160 RemoveEntryList (&CurrentNotify->NotifyEntry);\r
1161\r
1162 FreePool (CurrentNotify);\r
1163 return EFI_SUCCESS;\r
1164 }\r
1165 }\r
1166\r
1167 //\r
1168 // Cannot find the matching entry in database.\r
1169 //\r
1170 return EFI_INVALID_PARAMETER;\r
1171}\r
1172\r