]> git.proxmox.com Git - mirror_edk2.git/blame - EdkModulePkg/Bus/Usb/UsbKb/Dxe/efikey.c
1. Add the GLOBAL_REMOVE_IF_UNREFERENCED to globe variables which are used only in...
[mirror_edk2.git] / EdkModulePkg / Bus / Usb / UsbKb / Dxe / efikey.c
CommitLineData
878ddf1f 1/*++\r
2\r
3Copyright (c) 2006, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 EfiKey.c\r
15 \r
16Abstract:\r
17\r
18 USB Keyboard Driver\r
19\r
20Revision History\r
21\r
22--*/\r
23\r
24#include "efikey.h"\r
25#include "keyboard.h"\r
26\r
27//\r
28// Prototypes\r
29// Driver model protocol interface\r
30//\r
31EFI_STATUS\r
32EFIAPI\r
33USBKeyboardDriverBindingEntryPoint (\r
34 IN EFI_HANDLE ImageHandle,\r
35 IN EFI_SYSTEM_TABLE *SystemTable\r
36 );\r
37\r
38EFI_STATUS\r
39EFIAPI\r
40USBKeyboardDriverBindingSupported (\r
41 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
42 IN EFI_HANDLE Controller,\r
43 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
44 );\r
45\r
46EFI_STATUS\r
47EFIAPI\r
48USBKeyboardDriverBindingStart (\r
49 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
50 IN EFI_HANDLE Controller,\r
51 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
52 );\r
53\r
54EFI_STATUS\r
55EFIAPI\r
56USBKeyboardDriverBindingStop (\r
57 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
58 IN EFI_HANDLE Controller,\r
59 IN UINTN NumberOfChildren,\r
60 IN EFI_HANDLE *ChildHandleBuffer\r
61 );\r
62\r
63//\r
64// Simple Text In Protocol Interface\r
65//\r
66STATIC\r
67EFI_STATUS\r
68EFIAPI\r
69USBKeyboardReset (\r
70 IN EFI_SIMPLE_TEXT_IN_PROTOCOL *This,\r
71 IN BOOLEAN ExtendedVerification\r
72 );\r
73\r
74STATIC\r
75EFI_STATUS\r
76EFIAPI\r
77USBKeyboardReadKeyStroke (\r
78 IN EFI_SIMPLE_TEXT_IN_PROTOCOL *This,\r
79 OUT EFI_INPUT_KEY *Key\r
80 );\r
81\r
82STATIC\r
83VOID\r
84EFIAPI\r
85USBKeyboardWaitForKey (\r
86 IN EFI_EVENT Event,\r
87 IN VOID *Context\r
88 );\r
89\r
90//\r
91// Helper functions\r
92//\r
93STATIC\r
94EFI_STATUS\r
95USBKeyboardCheckForKey (\r
96 IN USB_KB_DEV *UsbKeyboardDevice\r
97 );\r
98\r
99//\r
100// USB Keyboard Driver Global Variables\r
101//\r
102EFI_DRIVER_BINDING_PROTOCOL gUsbKeyboardDriverBinding = {\r
103 USBKeyboardDriverBindingSupported,\r
104 USBKeyboardDriverBindingStart,\r
105 USBKeyboardDriverBindingStop,\r
106 0x10,\r
107 NULL,\r
108 NULL\r
109};\r
110\r
111EFI_STATUS\r
112EFIAPI\r
113USBKeyboardDriverBindingSupported (\r
114 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
115 IN EFI_HANDLE Controller,\r
116 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
117 )\r
118/*++\r
119 \r
120 Routine Description:\r
121 Supported.\r
122 \r
123 Arguments:\r
124 This - EFI_DRIVER_BINDING_PROTOCOL\r
125 Controller - Controller handle\r
126 RemainingDevicePath - EFI_DEVICE_PATH_PROTOCOL \r
127 Returns:\r
128 EFI_STATUS\r
129 \r
130--*/ \r
131{\r
132 EFI_STATUS OpenStatus;\r
133 EFI_USB_IO_PROTOCOL *UsbIo;\r
134 EFI_STATUS Status;\r
135\r
136 //\r
137 // Check if USB_IO protocol is attached on the controller handle.\r
138 //\r
139 OpenStatus = gBS->OpenProtocol (\r
140 Controller,\r
141 &gEfiUsbIoProtocolGuid,\r
142 (VOID **) &UsbIo,\r
143 This->DriverBindingHandle,\r
144 Controller,\r
145 EFI_OPEN_PROTOCOL_BY_DRIVER\r
146 );\r
147 if (EFI_ERROR (OpenStatus)) {\r
148 return OpenStatus;\r
149 }\r
150 \r
151 //\r
152 // Use the USB I/O protocol interface to check whether the Controller is\r
153 // the Keyboard controller that can be managed by this driver.\r
154 //\r
155 Status = EFI_SUCCESS;\r
156\r
157 if (!IsUSBKeyboard (UsbIo)) {\r
158 Status = EFI_UNSUPPORTED;\r
159 }\r
160\r
161 gBS->CloseProtocol (\r
162 Controller,\r
163 &gEfiUsbIoProtocolGuid,\r
164 This->DriverBindingHandle,\r
165 Controller\r
166 );\r
167\r
168 return Status;\r
169}\r
170\r
171EFI_STATUS\r
172EFIAPI\r
173USBKeyboardDriverBindingStart (\r
174 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
175 IN EFI_HANDLE Controller,\r
176 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
177 )\r
178/*++\r
179 \r
180 Routine Description:\r
181 Start.\r
182 \r
183 Arguments:\r
184 This - EFI_DRIVER_BINDING_PROTOCOL\r
185 Controller - Controller handle\r
186 RemainingDevicePath - EFI_DEVICE_PATH_PROTOCOL\r
187 Returns:\r
188 EFI_SUCCESS - Success\r
189 EFI_OUT_OF_RESOURCES - Can't allocate memory\r
190 EFI_UNSUPPORTED - The Start routine fail\r
191--*/ \r
192{ \r
193 EFI_STATUS Status;\r
194 EFI_USB_IO_PROTOCOL *UsbIo;\r
195 USB_KB_DEV *UsbKeyboardDevice;\r
196 UINT8 EndpointNumber;\r
197 EFI_USB_ENDPOINT_DESCRIPTOR EndpointDescriptor;\r
198 UINT8 Index;\r
199 UINT8 EndpointAddr;\r
200 UINT8 PollingInterval;\r
201 UINT8 PacketSize;\r
202 BOOLEAN Found;\r
203 \r
204 UsbKeyboardDevice = NULL;\r
205 Found = FALSE;\r
206\r
207 //\r
208 // Open USB_IO Protocol\r
209 //\r
210 Status = gBS->OpenProtocol (\r
211 Controller,\r
212 &gEfiUsbIoProtocolGuid,\r
213 (VOID **) &UsbIo,\r
214 This->DriverBindingHandle,\r
215 Controller,\r
216 EFI_OPEN_PROTOCOL_BY_DRIVER\r
217 );\r
218 if (EFI_ERROR (Status)) {\r
219 return Status;\r
220 }\r
221\r
222 UsbKeyboardDevice = AllocateZeroPool (sizeof (USB_KB_DEV));\r
223 if (UsbKeyboardDevice == NULL) {\r
224 gBS->CloseProtocol (\r
225 Controller,\r
226 &gEfiUsbIoProtocolGuid,\r
227 This->DriverBindingHandle,\r
228 Controller\r
229 );\r
230 return EFI_OUT_OF_RESOURCES;\r
231 }\r
232 //\r
233 // Get the Device Path Protocol on Controller's handle\r
234 //\r
235 Status = gBS->OpenProtocol (\r
236 Controller,\r
237 &gEfiDevicePathProtocolGuid,\r
238 (VOID **) &UsbKeyboardDevice->DevicePath,\r
239 This->DriverBindingHandle,\r
240 Controller,\r
241 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
242 );\r
243\r
244 if (EFI_ERROR (Status)) {\r
245 gBS->FreePool (UsbKeyboardDevice);\r
246 gBS->CloseProtocol (\r
247 Controller,\r
248 &gEfiUsbIoProtocolGuid,\r
249 This->DriverBindingHandle,\r
250 Controller\r
251 );\r
252 return Status;\r
253 }\r
254 //\r
255 // Report that the usb keyboard is being enabled\r
256 //\r
257 KbdReportStatusCode (\r
258 UsbKeyboardDevice->DevicePath,\r
259 EFI_PROGRESS_CODE,\r
260 (EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_ENABLE)\r
261 );\r
262\r
263 //\r
264 // This is pretty close to keyboard detection, so log progress\r
265 //\r
266 KbdReportStatusCode (\r
267 UsbKeyboardDevice->DevicePath,\r
268 EFI_PROGRESS_CODE,\r
269 (EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_PRESENCE_DETECT)\r
270 );\r
271\r
272 //\r
273 // Initialize UsbKeyboardDevice\r
274 //\r
275 UsbKeyboardDevice->UsbIo = UsbIo;\r
276\r
277 //\r
278 // Get interface & endpoint descriptor\r
279 //\r
280 UsbIo->UsbGetInterfaceDescriptor (\r
281 UsbIo,\r
282 &UsbKeyboardDevice->InterfaceDescriptor\r
283 );\r
284\r
285 EndpointNumber = UsbKeyboardDevice->InterfaceDescriptor.NumEndpoints;\r
286\r
287 for (Index = 0; Index < EndpointNumber; Index++) {\r
288\r
289 UsbIo->UsbGetEndpointDescriptor (\r
290 UsbIo,\r
291 Index,\r
292 &EndpointDescriptor\r
293 );\r
294\r
295 if ((EndpointDescriptor.Attributes & 0x03) == 0x03) {\r
296 //\r
297 // We only care interrupt endpoint here\r
298 //\r
299 CopyMem (&UsbKeyboardDevice->IntEndpointDescriptor, &EndpointDescriptor, sizeof (EndpointDescriptor));\r
878ddf1f 300 Found = TRUE;\r
301 }\r
302 }\r
303\r
304 if (!Found) {\r
305 //\r
306 // No interrupt endpoint found, then return unsupported.\r
307 //\r
308 gBS->FreePool (UsbKeyboardDevice);\r
309 gBS->CloseProtocol (\r
310 Controller,\r
311 &gEfiUsbIoProtocolGuid,\r
312 This->DriverBindingHandle,\r
313 Controller\r
314 );\r
315 return EFI_UNSUPPORTED;\r
316 }\r
317\r
318 UsbKeyboardDevice->Signature = USB_KB_DEV_SIGNATURE;\r
319 UsbKeyboardDevice->SimpleInput.Reset = USBKeyboardReset;\r
320 UsbKeyboardDevice->SimpleInput.ReadKeyStroke = USBKeyboardReadKeyStroke;\r
321 Status = gBS->CreateEvent (\r
322 EFI_EVENT_NOTIFY_WAIT,\r
323 EFI_TPL_NOTIFY,\r
324 USBKeyboardWaitForKey,\r
325 UsbKeyboardDevice,\r
326 &(UsbKeyboardDevice->SimpleInput.WaitForKey)\r
327 );\r
328\r
329 if (EFI_ERROR (Status)) {\r
330 gBS->FreePool (UsbKeyboardDevice);\r
331 gBS->CloseProtocol (\r
332 Controller,\r
333 &gEfiUsbIoProtocolGuid,\r
334 This->DriverBindingHandle,\r
335 Controller\r
336 );\r
337 return Status;\r
338 }\r
339 \r
340 //\r
341 // Install simple txt in protocol interface\r
342 // for the usb keyboard device.\r
343 // Usb keyboard is a hot plug device, and expected to work immediately\r
344 // when plugging into system, so a HotPlugDeviceGuid is installed onto\r
345 // the usb keyboard device handle, to distinguish it from other conventional\r
346 // console devices.\r
347 //\r
348 Status = gBS->InstallMultipleProtocolInterfaces (\r
349 &Controller,\r
350 &gEfiSimpleTextInProtocolGuid,\r
351 &UsbKeyboardDevice->SimpleInput,\r
352 &gEfiHotPlugDeviceGuid,\r
353 NULL,\r
354 NULL\r
355 );\r
356 if (EFI_ERROR (Status)) {\r
357 gBS->CloseEvent (UsbKeyboardDevice->SimpleInput.WaitForKey);\r
358 gBS->FreePool (UsbKeyboardDevice);\r
359 gBS->CloseProtocol (\r
360 Controller,\r
361 &gEfiUsbIoProtocolGuid,\r
362 This->DriverBindingHandle,\r
363 Controller\r
364 );\r
365 return Status;\r
366 }\r
367 \r
368 //\r
369 // Reset USB Keyboard Device\r
370 //\r
371 Status = UsbKeyboardDevice->SimpleInput.Reset (\r
372 &UsbKeyboardDevice->SimpleInput,\r
373 TRUE\r
374 );\r
375 if (EFI_ERROR (Status)) {\r
376 gBS->UninstallMultipleProtocolInterfaces (\r
377 Controller,\r
378 &gEfiSimpleTextInProtocolGuid,\r
379 &UsbKeyboardDevice->SimpleInput,\r
380 &gEfiHotPlugDeviceGuid,\r
381 NULL,\r
382 NULL\r
383 );\r
384 gBS->CloseEvent (UsbKeyboardDevice->SimpleInput.WaitForKey);\r
385 gBS->FreePool (UsbKeyboardDevice);\r
386 gBS->CloseProtocol (\r
387 Controller,\r
388 &gEfiUsbIoProtocolGuid,\r
389 This->DriverBindingHandle,\r
390 Controller\r
391 );\r
392 return Status;\r
393 }\r
394 //\r
395 // submit async interrupt transfer\r
396 //\r
397 EndpointAddr = UsbKeyboardDevice->IntEndpointDescriptor.EndpointAddress;\r
398 PollingInterval = UsbKeyboardDevice->IntEndpointDescriptor.Interval;\r
399 PacketSize = (UINT8) (UsbKeyboardDevice->IntEndpointDescriptor.MaxPacketSize);\r
400\r
401 Status = UsbIo->UsbAsyncInterruptTransfer (\r
402 UsbIo,\r
403 EndpointAddr,\r
404 TRUE,\r
405 PollingInterval,\r
406 PacketSize,\r
407 KeyboardHandler,\r
408 UsbKeyboardDevice\r
409 );\r
410\r
411 if (EFI_ERROR (Status)) {\r
412\r
413 gBS->UninstallMultipleProtocolInterfaces (\r
414 Controller,\r
415 &gEfiSimpleTextInProtocolGuid,\r
416 &UsbKeyboardDevice->SimpleInput,\r
417 &gEfiHotPlugDeviceGuid,\r
418 NULL,\r
419 NULL\r
420 );\r
421 gBS->CloseEvent (UsbKeyboardDevice->SimpleInput.WaitForKey);\r
422 gBS->FreePool (UsbKeyboardDevice);\r
423 gBS->CloseProtocol (\r
424 Controller,\r
425 &gEfiUsbIoProtocolGuid,\r
426 This->DriverBindingHandle,\r
427 Controller\r
428 );\r
429 return Status;\r
430 }\r
431\r
432 UsbKeyboardDevice->ControllerNameTable = NULL;\r
433 AddUnicodeString (\r
434 "eng",\r
435 gUsbKeyboardComponentName.SupportedLanguages,\r
436 &UsbKeyboardDevice->ControllerNameTable,\r
437 (CHAR16 *) L"Generic Usb Keyboard"\r
438 );\r
439\r
440 return EFI_SUCCESS;\r
441}\r
442\r
443\r
444EFI_STATUS\r
445EFIAPI\r
446USBKeyboardDriverBindingStop (\r
447 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
448 IN EFI_HANDLE Controller,\r
449 IN UINTN NumberOfChildren,\r
450 IN EFI_HANDLE *ChildHandleBuffer\r
451 )\r
452/*++\r
453 \r
454 Routine Description:\r
455 Stop.\r
456 \r
457 Arguments:\r
458 This - EFI_DRIVER_BINDING_PROTOCOL\r
459 Controller - Controller handle\r
460 NumberOfChildren - Child handle number\r
461 ChildHandleBuffer - Child handle buffer \r
462 Returns:\r
463 EFI_SUCCESS - Success\r
464 EFI_UNSUPPORTED - Can't support \r
465--*/ \r
466{\r
467 EFI_STATUS Status;\r
468 EFI_SIMPLE_TEXT_IN_PROTOCOL *SimpleInput;\r
469 USB_KB_DEV *UsbKeyboardDevice;\r
470 EFI_USB_IO_PROTOCOL *UsbIo;\r
471\r
472 Status = gBS->OpenProtocol (\r
473 Controller,\r
474 &gEfiSimpleTextInProtocolGuid,\r
475 (VOID **) &SimpleInput,\r
476 This->DriverBindingHandle,\r
477 Controller,\r
478 EFI_OPEN_PROTOCOL_BY_DRIVER\r
479 );\r
480 if (EFI_ERROR (Status)) {\r
481 return EFI_UNSUPPORTED;\r
482 }\r
483 \r
484 //\r
485 // Get USB_KB_DEV instance.\r
486 //\r
487 UsbKeyboardDevice = USB_KB_DEV_FROM_THIS (SimpleInput);\r
488\r
489 gBS->CloseProtocol (\r
490 Controller,\r
491 &gEfiSimpleTextInProtocolGuid,\r
492 This->DriverBindingHandle,\r
493 Controller\r
494 );\r
495\r
496 UsbIo = UsbKeyboardDevice->UsbIo;\r
497 //\r
498 // Uninstall the Asyn Interrupt Transfer from this device\r
499 // will disable the key data input from this device\r
500 //\r
501 KbdReportStatusCode (\r
502 UsbKeyboardDevice->DevicePath,\r
503 EFI_PROGRESS_CODE,\r
504 (EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_DISABLE)\r
505 );\r
506\r
507 //\r
508 // Destroy asynchronous interrupt transfer\r
509 //\r
510 UsbKeyboardDevice->UsbIo->UsbAsyncInterruptTransfer (\r
511 UsbKeyboardDevice->UsbIo,\r
512 UsbKeyboardDevice->IntEndpointDescriptor.EndpointAddress,\r
513 FALSE,\r
514 UsbKeyboardDevice->IntEndpointDescriptor.Interval,\r
515 0,\r
516 NULL,\r
517 NULL\r
518 );\r
519\r
520 gBS->CloseProtocol (\r
521 Controller,\r
522 &gEfiUsbIoProtocolGuid,\r
523 This->DriverBindingHandle,\r
524 Controller\r
525 );\r
526\r
527 Status = gBS->UninstallMultipleProtocolInterfaces (\r
528 Controller,\r
529 &gEfiSimpleTextInProtocolGuid,\r
530 &UsbKeyboardDevice->SimpleInput,\r
531 &gEfiHotPlugDeviceGuid,\r
532 NULL,\r
533 NULL\r
534 );\r
535 //\r
536 // free all the resources.\r
537 //\r
538 gBS->CloseEvent (UsbKeyboardDevice->RepeatTimer);\r
539 gBS->CloseEvent (UsbKeyboardDevice->DelayedRecoveryEvent);\r
540 gBS->CloseEvent ((UsbKeyboardDevice->SimpleInput).WaitForKey);\r
541\r
542 if (UsbKeyboardDevice->ControllerNameTable != NULL) {\r
543 FreeUnicodeStringTable (UsbKeyboardDevice->ControllerNameTable);\r
544 }\r
545\r
546 gBS->FreePool (UsbKeyboardDevice);\r
547\r
548 return Status;\r
549\r
550}\r
551\r
552\r
553EFI_STATUS\r
554EFIAPI\r
555USBKeyboardReset (\r
556 IN EFI_SIMPLE_TEXT_IN_PROTOCOL *This,\r
557 IN BOOLEAN ExtendedVerification\r
558 )\r
559/*++\r
560\r
561 Routine Description:\r
562 Implements EFI_SIMPLE_TEXT_IN_PROTOCOL.Reset() function.\r
563 \r
564 Arguments:\r
565 This The EFI_SIMPLE_TEXT_IN_PROTOCOL instance.\r
566 ExtendedVerification\r
567 Indicates that the driver may perform a more exhaustive\r
568 verification operation of the device during reset. \r
569 \r
570 Returns: \r
571 EFI_SUCCESS - Success\r
572 EFI_DEVICE_ERROR - Hardware Error\r
573--*/ \r
574{\r
575 EFI_STATUS Status;\r
576 USB_KB_DEV *UsbKeyboardDevice;\r
577 EFI_USB_IO_PROTOCOL *UsbIo;\r
578\r
579 UsbKeyboardDevice = USB_KB_DEV_FROM_THIS (This);\r
580\r
581 UsbIo = UsbKeyboardDevice->UsbIo;\r
582\r
583 KbdReportStatusCode (\r
584 UsbKeyboardDevice->DevicePath,\r
585 EFI_PROGRESS_CODE,\r
586 (EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_RESET)\r
587 );\r
588\r
589 //\r
590 // Non Exhaustive reset:\r
591 // only reset private data structures.\r
592 //\r
593 if (!ExtendedVerification) {\r
594 //\r
595 // Clear the key buffer of this Usb keyboard\r
596 //\r
597 KbdReportStatusCode (\r
598 UsbKeyboardDevice->DevicePath,\r
599 EFI_PROGRESS_CODE,\r
600 (EFI_PERIPHERAL_KEYBOARD | EFI_P_KEYBOARD_PC_CLEAR_BUFFER)\r
601 );\r
602\r
603 InitUSBKeyBuffer (&(UsbKeyboardDevice->KeyboardBuffer));\r
604 UsbKeyboardDevice->CurKeyChar = 0;\r
605 return EFI_SUCCESS;\r
606 }\r
607 \r
608 //\r
609 // Exhaustive reset\r
610 //\r
611 Status = InitUSBKeyboard (UsbKeyboardDevice);\r
612 UsbKeyboardDevice->CurKeyChar = 0;\r
613 if (EFI_ERROR (Status)) {\r
614 return EFI_DEVICE_ERROR;\r
615 }\r
616\r
617 return EFI_SUCCESS;\r
618}\r
619\r
620STATIC\r
621EFI_STATUS\r
622EFIAPI\r
623USBKeyboardReadKeyStroke (\r
624 IN EFI_SIMPLE_TEXT_IN_PROTOCOL *This,\r
625 OUT EFI_INPUT_KEY *Key\r
626 )\r
627/*++\r
628\r
629 Routine Description:\r
630 Implements EFI_SIMPLE_TEXT_IN_PROTOCOL.ReadKeyStroke() function.\r
631 \r
632 Arguments:\r
633 This The EFI_SIMPLE_TEXT_IN_PROTOCOL instance.\r
634 Key A pointer to a buffer that is filled in with the keystroke\r
635 information for the key that was pressed.\r
636 \r
637 Returns: \r
638 EFI_SUCCESS - Success\r
639--*/ \r
640{\r
641 USB_KB_DEV *UsbKeyboardDevice;\r
642 EFI_STATUS Status;\r
643 UINT8 KeyChar;\r
644\r
645 UsbKeyboardDevice = USB_KB_DEV_FROM_THIS (This);\r
646\r
647 //\r
648 // if there is no saved ASCII byte, fetch it\r
649 // by calling USBKeyboardCheckForKey().\r
650 //\r
651 if (UsbKeyboardDevice->CurKeyChar == 0) {\r
652 Status = USBKeyboardCheckForKey (UsbKeyboardDevice);\r
653 if (EFI_ERROR (Status)) {\r
654 return Status;\r
655 }\r
656 }\r
657\r
658 Key->UnicodeChar = 0;\r
659 Key->ScanCode = SCAN_NULL;\r
660\r
661 KeyChar = UsbKeyboardDevice->CurKeyChar;\r
662\r
663 UsbKeyboardDevice->CurKeyChar = 0;\r
664\r
665 //\r
666 // Translate saved ASCII byte into EFI_INPUT_KEY\r
667 //\r
668 Status = USBKeyCodeToEFIScanCode (UsbKeyboardDevice, KeyChar, Key);\r
669\r
670 return Status;\r
671\r
672}\r
673\r
674STATIC\r
675VOID\r
676EFIAPI\r
677USBKeyboardWaitForKey (\r
678 IN EFI_EVENT Event,\r
679 IN VOID *Context\r
680 )\r
681/*++\r
682\r
683 Routine Description:\r
684 Handler function for WaitForKey event. \r
685 \r
686 Arguments:\r
687 Event Event to be signaled when a key is pressed.\r
688 Context Points to USB_KB_DEV instance.\r
689 \r
690 Returns: \r
691 VOID\r
692--*/ \r
693{\r
694 USB_KB_DEV *UsbKeyboardDevice;\r
695\r
696 UsbKeyboardDevice = (USB_KB_DEV *) Context;\r
697\r
698 if (UsbKeyboardDevice->CurKeyChar == 0) {\r
699\r
700 if (EFI_ERROR (USBKeyboardCheckForKey (UsbKeyboardDevice))) {\r
701 return ;\r
702 }\r
703 }\r
704 //\r
705 // If has key pending, signal the event.\r
706 //\r
707 gBS->SignalEvent (Event);\r
708}\r
709\r
710\r
711STATIC\r
712EFI_STATUS\r
713USBKeyboardCheckForKey (\r
714 IN USB_KB_DEV *UsbKeyboardDevice\r
715 )\r
716/*++\r
717\r
718 Routine Description:\r
719 Check whether there is key pending.\r
720 \r
721 Arguments:\r
722 UsbKeyboardDevice The USB_KB_DEV instance.\r
723 \r
724 Returns: \r
725 EFI_SUCCESS - Success\r
726--*/ \r
727{\r
728 EFI_STATUS Status;\r
729 UINT8 KeyChar;\r
730\r
731 //\r
732 // Fetch raw data from the USB keyboard input,\r
733 // and translate it into ASCII data.\r
734 //\r
735 Status = USBParseKey (UsbKeyboardDevice, &KeyChar);\r
736 if (EFI_ERROR (Status)) {\r
737 return Status;\r
738 }\r
739\r
740 UsbKeyboardDevice->CurKeyChar = KeyChar;\r
741 return EFI_SUCCESS;\r
742}\r
743\r
744VOID\r
745KbdReportStatusCode (\r
746 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
747 IN EFI_STATUS_CODE_TYPE CodeType,\r
748 IN EFI_STATUS_CODE_VALUE Value\r
749 )\r
750/*++\r
751\r
752 Routine Description:\r
753 Report Status Code in Usb Bot Driver\r
754\r
755 Arguments:\r
756 DevicePath - Use this to get Device Path\r
757 CodeType - Status Code Type\r
758 CodeValue - Status Code Value\r
759\r
760 Returns:\r
761 None\r
762\r
763--*/\r
764{\r
765\r
766 REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
767 CodeType,\r
768 Value,\r
769 DevicePath\r
770 );\r
771}\r