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