]> git.proxmox.com Git - mirror_edk2.git/blame - EdkModulePkg/Bus/Usb/UsbKb/Dxe/efikey.c
Partially make EdkModulePkg pass intel IPF compiler with /W4 /WX switched on.
[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
61fb1657 106 0xa,\r
878ddf1f 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
878ddf1f 470\r
471 Status = gBS->OpenProtocol (\r
472 Controller,\r
473 &gEfiSimpleTextInProtocolGuid,\r
474 (VOID **) &SimpleInput,\r
475 This->DriverBindingHandle,\r
476 Controller,\r
477 EFI_OPEN_PROTOCOL_BY_DRIVER\r
478 );\r
479 if (EFI_ERROR (Status)) {\r
480 return EFI_UNSUPPORTED;\r
481 }\r
482 \r
483 //\r
484 // Get USB_KB_DEV instance.\r
485 //\r
486 UsbKeyboardDevice = USB_KB_DEV_FROM_THIS (SimpleInput);\r
487\r
488 gBS->CloseProtocol (\r
489 Controller,\r
490 &gEfiSimpleTextInProtocolGuid,\r
491 This->DriverBindingHandle,\r
492 Controller\r
493 );\r
494\r
878ddf1f 495 //\r
496 // Uninstall the Asyn Interrupt Transfer from this device\r
497 // will disable the key data input from this device\r
498 //\r
499 KbdReportStatusCode (\r
500 UsbKeyboardDevice->DevicePath,\r
501 EFI_PROGRESS_CODE,\r
502 (EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_DISABLE)\r
503 );\r
504\r
505 //\r
506 // Destroy asynchronous interrupt transfer\r
507 //\r
508 UsbKeyboardDevice->UsbIo->UsbAsyncInterruptTransfer (\r
509 UsbKeyboardDevice->UsbIo,\r
510 UsbKeyboardDevice->IntEndpointDescriptor.EndpointAddress,\r
511 FALSE,\r
512 UsbKeyboardDevice->IntEndpointDescriptor.Interval,\r
513 0,\r
514 NULL,\r
515 NULL\r
516 );\r
517\r
518 gBS->CloseProtocol (\r
519 Controller,\r
520 &gEfiUsbIoProtocolGuid,\r
521 This->DriverBindingHandle,\r
522 Controller\r
523 );\r
524\r
525 Status = gBS->UninstallMultipleProtocolInterfaces (\r
526 Controller,\r
527 &gEfiSimpleTextInProtocolGuid,\r
528 &UsbKeyboardDevice->SimpleInput,\r
529 &gEfiHotPlugDeviceGuid,\r
530 NULL,\r
531 NULL\r
532 );\r
533 //\r
534 // free all the resources.\r
535 //\r
536 gBS->CloseEvent (UsbKeyboardDevice->RepeatTimer);\r
537 gBS->CloseEvent (UsbKeyboardDevice->DelayedRecoveryEvent);\r
538 gBS->CloseEvent ((UsbKeyboardDevice->SimpleInput).WaitForKey);\r
539\r
540 if (UsbKeyboardDevice->ControllerNameTable != NULL) {\r
541 FreeUnicodeStringTable (UsbKeyboardDevice->ControllerNameTable);\r
542 }\r
543\r
544 gBS->FreePool (UsbKeyboardDevice);\r
545\r
546 return Status;\r
547\r
548}\r
549\r
550\r
551EFI_STATUS\r
552EFIAPI\r
553USBKeyboardReset (\r
554 IN EFI_SIMPLE_TEXT_IN_PROTOCOL *This,\r
555 IN BOOLEAN ExtendedVerification\r
556 )\r
557/*++\r
558\r
559 Routine Description:\r
560 Implements EFI_SIMPLE_TEXT_IN_PROTOCOL.Reset() function.\r
561 \r
562 Arguments:\r
563 This The EFI_SIMPLE_TEXT_IN_PROTOCOL instance.\r
564 ExtendedVerification\r
565 Indicates that the driver may perform a more exhaustive\r
566 verification operation of the device during reset. \r
567 \r
568 Returns: \r
569 EFI_SUCCESS - Success\r
570 EFI_DEVICE_ERROR - Hardware Error\r
571--*/ \r
572{\r
573 EFI_STATUS Status;\r
574 USB_KB_DEV *UsbKeyboardDevice;\r
878ddf1f 575\r
576 UsbKeyboardDevice = USB_KB_DEV_FROM_THIS (This);\r
577\r
878ddf1f 578 KbdReportStatusCode (\r
579 UsbKeyboardDevice->DevicePath,\r
580 EFI_PROGRESS_CODE,\r
581 (EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_RESET)\r
582 );\r
583\r
584 //\r
585 // Non Exhaustive reset:\r
586 // only reset private data structures.\r
587 //\r
588 if (!ExtendedVerification) {\r
589 //\r
590 // Clear the key buffer of this Usb keyboard\r
591 //\r
592 KbdReportStatusCode (\r
593 UsbKeyboardDevice->DevicePath,\r
594 EFI_PROGRESS_CODE,\r
595 (EFI_PERIPHERAL_KEYBOARD | EFI_P_KEYBOARD_PC_CLEAR_BUFFER)\r
596 );\r
597\r
598 InitUSBKeyBuffer (&(UsbKeyboardDevice->KeyboardBuffer));\r
599 UsbKeyboardDevice->CurKeyChar = 0;\r
600 return EFI_SUCCESS;\r
601 }\r
602 \r
603 //\r
604 // Exhaustive reset\r
605 //\r
606 Status = InitUSBKeyboard (UsbKeyboardDevice);\r
607 UsbKeyboardDevice->CurKeyChar = 0;\r
608 if (EFI_ERROR (Status)) {\r
609 return EFI_DEVICE_ERROR;\r
610 }\r
611\r
612 return EFI_SUCCESS;\r
613}\r
614\r
615STATIC\r
616EFI_STATUS\r
617EFIAPI\r
618USBKeyboardReadKeyStroke (\r
619 IN EFI_SIMPLE_TEXT_IN_PROTOCOL *This,\r
620 OUT EFI_INPUT_KEY *Key\r
621 )\r
622/*++\r
623\r
624 Routine Description:\r
625 Implements EFI_SIMPLE_TEXT_IN_PROTOCOL.ReadKeyStroke() function.\r
626 \r
627 Arguments:\r
628 This The EFI_SIMPLE_TEXT_IN_PROTOCOL instance.\r
629 Key A pointer to a buffer that is filled in with the keystroke\r
630 information for the key that was pressed.\r
631 \r
632 Returns: \r
633 EFI_SUCCESS - Success\r
634--*/ \r
635{\r
636 USB_KB_DEV *UsbKeyboardDevice;\r
637 EFI_STATUS Status;\r
638 UINT8 KeyChar;\r
639\r
640 UsbKeyboardDevice = USB_KB_DEV_FROM_THIS (This);\r
641\r
642 //\r
643 // if there is no saved ASCII byte, fetch it\r
644 // by calling USBKeyboardCheckForKey().\r
645 //\r
646 if (UsbKeyboardDevice->CurKeyChar == 0) {\r
647 Status = USBKeyboardCheckForKey (UsbKeyboardDevice);\r
648 if (EFI_ERROR (Status)) {\r
649 return Status;\r
650 }\r
651 }\r
652\r
653 Key->UnicodeChar = 0;\r
654 Key->ScanCode = SCAN_NULL;\r
655\r
656 KeyChar = UsbKeyboardDevice->CurKeyChar;\r
657\r
658 UsbKeyboardDevice->CurKeyChar = 0;\r
659\r
660 //\r
661 // Translate saved ASCII byte into EFI_INPUT_KEY\r
662 //\r
663 Status = USBKeyCodeToEFIScanCode (UsbKeyboardDevice, KeyChar, Key);\r
664\r
665 return Status;\r
666\r
667}\r
668\r
669STATIC\r
670VOID\r
671EFIAPI\r
672USBKeyboardWaitForKey (\r
673 IN EFI_EVENT Event,\r
674 IN VOID *Context\r
675 )\r
676/*++\r
677\r
678 Routine Description:\r
679 Handler function for WaitForKey event. \r
680 \r
681 Arguments:\r
682 Event Event to be signaled when a key is pressed.\r
683 Context Points to USB_KB_DEV instance.\r
684 \r
685 Returns: \r
686 VOID\r
687--*/ \r
688{\r
689 USB_KB_DEV *UsbKeyboardDevice;\r
690\r
691 UsbKeyboardDevice = (USB_KB_DEV *) Context;\r
692\r
693 if (UsbKeyboardDevice->CurKeyChar == 0) {\r
694\r
695 if (EFI_ERROR (USBKeyboardCheckForKey (UsbKeyboardDevice))) {\r
696 return ;\r
697 }\r
698 }\r
699 //\r
700 // If has key pending, signal the event.\r
701 //\r
702 gBS->SignalEvent (Event);\r
703}\r
704\r
705\r
706STATIC\r
707EFI_STATUS\r
708USBKeyboardCheckForKey (\r
709 IN USB_KB_DEV *UsbKeyboardDevice\r
710 )\r
711/*++\r
712\r
713 Routine Description:\r
714 Check whether there is key pending.\r
715 \r
716 Arguments:\r
717 UsbKeyboardDevice The USB_KB_DEV instance.\r
718 \r
719 Returns: \r
720 EFI_SUCCESS - Success\r
721--*/ \r
722{\r
723 EFI_STATUS Status;\r
724 UINT8 KeyChar;\r
725\r
726 //\r
727 // Fetch raw data from the USB keyboard input,\r
728 // and translate it into ASCII data.\r
729 //\r
730 Status = USBParseKey (UsbKeyboardDevice, &KeyChar);\r
731 if (EFI_ERROR (Status)) {\r
732 return Status;\r
733 }\r
734\r
735 UsbKeyboardDevice->CurKeyChar = KeyChar;\r
736 return EFI_SUCCESS;\r
737}\r
738\r
739VOID\r
740KbdReportStatusCode (\r
741 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
742 IN EFI_STATUS_CODE_TYPE CodeType,\r
743 IN EFI_STATUS_CODE_VALUE Value\r
744 )\r
745/*++\r
746\r
747 Routine Description:\r
748 Report Status Code in Usb Bot Driver\r
749\r
750 Arguments:\r
751 DevicePath - Use this to get Device Path\r
752 CodeType - Status Code Type\r
753 CodeValue - Status Code Value\r
754\r
755 Returns:\r
756 None\r
757\r
758--*/\r
759{\r
760\r
761 REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
762 CodeType,\r
763 Value,\r
764 DevicePath\r
765 );\r
766}\r