From 5899f27e062001882274589496117eabda9bea94 Mon Sep 17 00:00:00 2001 From: xli24 Date: Fri, 5 Dec 2008 09:19:10 +0000 Subject: [PATCH] Code Scrub for UsbKbDxe module. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@6871 6f19259b-4bc3-4df7-8a09-765794883524 --- MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.c | 572 +++++++---------------- MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.h | 280 ++++++++--- MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c | 333 ++++++------- MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.h | 15 +- 4 files changed, 570 insertions(+), 630 deletions(-) diff --git a/MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.c b/MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.c index b971903a2d..79f163301c 100644 --- a/MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.c +++ b/MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.c @@ -1,5 +1,4 @@ /** @file - USB Keyboard Driver that includes the implementation of interface. Copyright (c) 2004 - 2008, Intel Corporation @@ -16,185 +15,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "EfiKey.h" #include "KeyBoard.h" -/** - The Usb Keyboard Driver Entry Point. - - @param ImageHandle The driver image handle. - @param SystemTable The system table. - - @return EFI_SUCCESS The component name protocol is installed. - @return Others Failed to install. - -**/ -EFI_STATUS -EFIAPI -USBKeyboardDriverBindingEntryPoint ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable - ); - -/** - Check whether USB keyboard driver support this device. - - @param This The USB keyboard driver binding protocol. - @param Controller The controller handle to check. - @param RemainingDevicePath The remaining device path. - - @retval EFI_SUCCESS The driver supports this controller. - @retval EFI_UNSUPPORTED This device isn't supported. -**/ -EFI_STATUS -EFIAPI -USBKeyboardDriverBindingSupported ( - IN EFI_DRIVER_BINDING_PROTOCOL *This, - IN EFI_HANDLE Controller, - IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath - ); - -/** - Start running driver on the controller. - - @param This The USB keyboard driver binding instance. - @param Controller The controller to check. - @param RemainingDevicePath The remaining device patch. - - @retval EFI_SUCCESS The controller is controlled by the usb keyboard driver. - @return Other The keyboard driver doesn't support this controller. - -**/ -EFI_STATUS -EFIAPI -USBKeyboardDriverBindingStart ( - IN EFI_DRIVER_BINDING_PROTOCOL *This, - IN EFI_HANDLE Controller, - IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath - ); - -/** - Stop handle the controller by this USB keyboard driver. - - @param This The USB keyboard driver binding protocol. - @param Controller The controller to release. - @param NumberOfChildren The number of handles in ChildHandleBuffer. - @param ChildHandleBuffer The array of child handle. - - @retval EFI_SUCCESS The controller or children are stopped. - @retval EFI_DEVICE_ERROR Failed to stop the driver. - -**/ -EFI_STATUS -EFIAPI -USBKeyboardDriverBindingStop ( - IN EFI_DRIVER_BINDING_PROTOCOL *This, - IN EFI_HANDLE Controller, - IN UINTN NumberOfChildren, - IN EFI_HANDLE *ChildHandleBuffer - ); - -/** - Reset Usb Keyboard. - - @param This The protocol instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL. - @param ExtendedVerification Whether completely reset keyboard or not. - - @retval EFI_SUCCESS Reset keyboard successfully. - @retval EFI_DEVICE_ERROR Reset keyboard failed. - -**/ -EFI_STATUS -EFIAPI -USBKeyboardReset ( - IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, - IN BOOLEAN ExtendedVerification - ); - -/** - Implements EFI_SIMPLE_TEXT_INPUT_PROTOCOL.ReadKeyStroke() function. - - @param This The EFI_SIMPLE_TEXT_INPUT_PROTOCOL instance. - @param Key A pointer to a buffer that is filled in with the keystroke - information for the key that was pressed. - - @retval EFI_SUCCESS Read key stroke successfully. - @retval Other Read key stroke failed. - -**/ -EFI_STATUS -EFIAPI -USBKeyboardReadKeyStroke ( - IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, - OUT EFI_INPUT_KEY *Key - ); - -/** - Handler function for WaitForKey event. - - @param Event Event to be signaled when a key is pressed. - @param Context Points to USB_KB_DEV instance. - - @return None. -**/ -VOID -EFIAPI -USBKeyboardWaitForKey ( - IN EFI_EVENT Event, - IN VOID *Context - ); - -/** - Check whether there is key pending. - - @param UsbKeyboardDevice The USB_KB_DEV instance. - - @retval EFI_SUCCESS Have key pending to read. - @retval Other Parse key failed. - -**/ -EFI_STATUS -EFIAPI -USBKeyboardCheckForKey ( - IN USB_KB_DEV *UsbKeyboardDevice - ); - -EFI_GUID gEfiUsbKeyboardDriverGuid = { - 0xa05f5f78, 0xfb3, 0x4d10, {0x90, 0x90, 0xac, 0x4, 0x6e, 0xeb, 0x7c, 0x3c} -}; - -/** - Free keyboard notify list. - - @param ListHead The list head. - - @retval EFI_SUCCESS Free the notify list successfully. - @retval EFI_INVALID_PARAMETER ListHead is invalid. - -**/ -EFI_STATUS -EFIAPI -KbdFreeNotifyList ( - IN OUT LIST_ENTRY *ListHead - ); - -/** - Whether the pressed key matches a registered key or not. - - @param RegsiteredData A pointer to a buffer that is filled in with the keystroke - state data for the key that was registered. - @param InputData A pointer to a buffer that is filled in with the keystroke - state data for the key that was pressed. - - @retval TRUE Key pressed matches a registered key. - @retval FLASE Match failed. - -**/ -BOOLEAN -EFIAPI -IsKeyRegistered ( - IN EFI_KEY_DATA *RegsiteredData, - IN EFI_KEY_DATA *InputData - ); - - // // USB Keyboard Driver Global Variables // @@ -208,13 +28,15 @@ EFI_DRIVER_BINDING_PROTOCOL gUsbKeyboardDriverBinding = { }; /** - The Usb Keyboard Driver Entry Point. + Entrypoint of USB Keyboard Driver. + + This function is the entrypoint of USB Keyboard Driver. It installs Driver Binding + Protocols together with Component Name Protocols. - @param ImageHandle The driver image handle. - @param SystemTable The system table. + @param ImageHandle The firmware allocated handle for the EFI image. + @param SystemTable A pointer to the EFI System Table. - @return EFI_SUCCESS The component name protocol is installed. - @return Others Failed to install. + @retval EFI_SUCCESS The entry point is executed successfully. **/ EFI_STATUS @@ -224,25 +46,31 @@ USBKeyboardDriverBindingEntryPoint ( IN EFI_SYSTEM_TABLE *SystemTable ) { - return EfiLibInstallDriverBindingComponentName2 ( - ImageHandle, - SystemTable, - &gUsbKeyboardDriverBinding, - ImageHandle, - &gUsbKeyboardComponentName, - &gUsbKeyboardComponentName2 - ); + EFI_STATUS Status; + + Status = EfiLibInstallDriverBindingComponentName2 ( + ImageHandle, + SystemTable, + &gUsbKeyboardDriverBinding, + ImageHandle, + &gUsbKeyboardComponentName, + &gUsbKeyboardComponentName2 + ); + ASSERT_EFI_ERROR (Status); + + return EFI_SUCCESS; } /** - Check whether USB keyboard driver support this device. + Check whether USB keyboard driver supports this device. @param This The USB keyboard driver binding protocol. @param Controller The controller handle to check. @param RemainingDevicePath The remaining device path. @retval EFI_SUCCESS The driver supports this controller. - @retval EFI_UNSUPPORTED This device isn't supported. + @retval other This device isn't supported. + **/ EFI_STATUS EFIAPI @@ -252,27 +80,26 @@ USBKeyboardDriverBindingSupported ( IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath ) { - EFI_STATUS OpenStatus; - EFI_USB_IO_PROTOCOL *UsbIo; EFI_STATUS Status; + EFI_USB_IO_PROTOCOL *UsbIo; // - // Check if USB_IO protocol is attached on the controller handle. + // Check if USB I/O Protocol is attached on the controller handle. // - OpenStatus = gBS->OpenProtocol ( - Controller, - &gEfiUsbIoProtocolGuid, - (VOID **) &UsbIo, - This->DriverBindingHandle, - Controller, - EFI_OPEN_PROTOCOL_BY_DRIVER - ); - if (EFI_ERROR (OpenStatus)) { - return OpenStatus; + Status = gBS->OpenProtocol ( + Controller, + &gEfiUsbIoProtocolGuid, + (VOID **) &UsbIo, + This->DriverBindingHandle, + Controller, + EFI_OPEN_PROTOCOL_BY_DRIVER + ); + if (EFI_ERROR (Status)) { + return Status; } // - // Use the USB I/O protocol interface to check whether the Controller is + // Use the USB I/O Protocol interface to check whether the Controller is // the Keyboard controller that can be managed by this driver. // Status = EFI_SUCCESS; @@ -282,11 +109,11 @@ USBKeyboardDriverBindingSupported ( } gBS->CloseProtocol ( - Controller, - &gEfiUsbIoProtocolGuid, - This->DriverBindingHandle, - Controller - ); + Controller, + &gEfiUsbIoProtocolGuid, + This->DriverBindingHandle, + Controller + ); return Status; } @@ -295,11 +122,13 @@ USBKeyboardDriverBindingSupported ( Start running driver on the controller. @param This The USB keyboard driver binding instance. - @param Controller The controller to check. - @param RemainingDevicePath The remaining device patch. + @param Controller Handle of device to bind driver to. + @param RemainingDevicePath Optional parameter use to pick a specific child + device to start. @retval EFI_SUCCESS The controller is controlled by the usb keyboard driver. - @return Other The keyboard driver doesn't support this controller. + @retval EFI_UNSUPPORTED No interrupt endpoint can be found. + @retval Other The keyboard driver cannot support this controller. **/ EFI_STATUS @@ -321,11 +150,8 @@ USBKeyboardDriverBindingStart ( UINT8 PacketSize; BOOLEAN Found; - UsbKeyboardDevice = NULL; - Found = FALSE; - // - // Open USB_IO Protocol + // Open USB I/O Protocol // Status = gBS->OpenProtocol ( Controller, @@ -340,15 +166,8 @@ USBKeyboardDriverBindingStart ( } UsbKeyboardDevice = AllocateZeroPool (sizeof (USB_KB_DEV)); - if (UsbKeyboardDevice == NULL) { - gBS->CloseProtocol ( - Controller, - &gEfiUsbIoProtocolGuid, - This->DriverBindingHandle, - Controller - ); - return EFI_OUT_OF_RESOURCES; - } + ASSERT (UsbKeyboardDevice != NULL); + // // Get the Device Path Protocol on Controller's handle // @@ -362,31 +181,24 @@ USBKeyboardDriverBindingStart ( ); if (EFI_ERROR (Status)) { - gBS->FreePool (UsbKeyboardDevice); - gBS->CloseProtocol ( - Controller, - &gEfiUsbIoProtocolGuid, - This->DriverBindingHandle, - Controller - ); - return Status; + goto ErrorExit; } // - // Report that the usb keyboard is being enabled + // Report that the USB keyboard is being enabled // - KbdReportStatusCode ( - UsbKeyboardDevice->DevicePath, + REPORT_STATUS_CODE_WITH_DEVICE_PATH ( EFI_PROGRESS_CODE, - PcdGet32 (PcdStatusCodeValueKeyboardEnable) + PcdGet32 (PcdStatusCodeValueKeyboardEnable), + UsbKeyboardDevice->DevicePath ); // // This is pretty close to keyboard detection, so log progress // - KbdReportStatusCode ( - UsbKeyboardDevice->DevicePath, + REPORT_STATUS_CODE_WITH_DEVICE_PATH ( EFI_PROGRESS_CODE, - PcdGet32 (PcdStatusCodeValueKeyboardPresenceDetect) + PcdGet32 (PcdStatusCodeValueKeyboardPresenceDetect), + UsbKeyboardDevice->DevicePath ); // @@ -398,26 +210,31 @@ USBKeyboardDriverBindingStart ( // Get interface & endpoint descriptor // UsbIo->UsbGetInterfaceDescriptor ( - UsbIo, - &UsbKeyboardDevice->InterfaceDescriptor - ); + UsbIo, + &UsbKeyboardDevice->InterfaceDescriptor + ); EndpointNumber = UsbKeyboardDevice->InterfaceDescriptor.NumEndpoints; + // + // Traverse endpoints to find interrupt endpoints + // + Found = FALSE; for (Index = 0; Index < EndpointNumber; Index++) { UsbIo->UsbGetEndpointDescriptor ( - UsbIo, - Index, - &EndpointDescriptor - ); + UsbIo, + Index, + &EndpointDescriptor + ); - if ((EndpointDescriptor.Attributes & 0x03) == 0x03) { + if ((EndpointDescriptor.Attributes & 0x03) == USB_ENDPOINT_INTERRUPT) { // // We only care interrupt endpoint here // CopyMem(&UsbKeyboardDevice->IntEndpointDescriptor, &EndpointDescriptor, sizeof(EndpointDescriptor)); Found = TRUE; + break; } } @@ -425,14 +242,8 @@ USBKeyboardDriverBindingStart ( // // No interrupt endpoint found, then return unsupported. // - gBS->FreePool (UsbKeyboardDevice); - gBS->CloseProtocol ( - Controller, - &gEfiUsbIoProtocolGuid, - This->DriverBindingHandle, - Controller - ); - return EFI_UNSUPPORTED; + Status = EFI_UNSUPPORTED; + goto ErrorExit; } UsbKeyboardDevice->Signature = USB_KB_DEV_SIGNATURE; @@ -459,11 +270,6 @@ USBKeyboardDriverBindingStart ( goto ErrorExit; } - Status = InitKeyboardLayout (UsbKeyboardDevice); - if (EFI_ERROR (Status)) { - goto ErrorExit; - } - Status = gBS->CreateEvent ( EVT_NOTIFY_WAIT, TPL_NOTIFY, @@ -473,20 +279,18 @@ USBKeyboardDriverBindingStart ( ); if (EFI_ERROR (Status)) { - gBS->FreePool (UsbKeyboardDevice); - gBS->CloseProtocol ( - Controller, - &gEfiUsbIoProtocolGuid, - This->DriverBindingHandle, - Controller - ); - return Status; + goto ErrorExit; + } + + Status = InitKeyboardLayout (UsbKeyboardDevice); + if (EFI_ERROR (Status)) { + goto ErrorExit; } // - // Install simple txt in protocol interface - // for the usb keyboard device. - // Usb keyboard is a hot plug device, and expected to work immediately + // Install Simple Text Input Protocol and Simple Text Input Ex Protocol + // for the USB keyboard device. + // USB keyboard is a hot plug device, and expected to work immediately // when plugging into system, so a HotPlugDeviceGuid is installed onto // the usb keyboard device handle, to distinguish it from other conventional // console devices. @@ -502,19 +306,11 @@ USBKeyboardDriverBindingStart ( NULL ); if (EFI_ERROR (Status)) { - gBS->CloseEvent (UsbKeyboardDevice->SimpleInput.WaitForKey); - gBS->FreePool (UsbKeyboardDevice); - gBS->CloseProtocol ( - Controller, - &gEfiUsbIoProtocolGuid, - This->DriverBindingHandle, - Controller - ); - return Status; + goto ErrorExit; } // - // Reset USB Keyboard Device + // Reset USB Keyboard Device exhaustively. // Status = UsbKeyboardDevice->SimpleInput.Reset ( &UsbKeyboardDevice->SimpleInput, @@ -531,18 +327,11 @@ USBKeyboardDriverBindingStart ( NULL, NULL ); - gBS->CloseEvent (UsbKeyboardDevice->SimpleInput.WaitForKey); - gBS->FreePool (UsbKeyboardDevice); - gBS->CloseProtocol ( - Controller, - &gEfiUsbIoProtocolGuid, - This->DriverBindingHandle, - Controller - ); - return Status; + goto ErrorExit; } + // - // submit async interrupt transfer + // Submit Asynchronous Interrupt Transfer to manage this device. // EndpointAddr = UsbKeyboardDevice->IntEndpointDescriptor.EndpointAddress; PollingInterval = UsbKeyboardDevice->IntEndpointDescriptor.Interval; @@ -559,7 +348,6 @@ USBKeyboardDriverBindingStart ( ); if (EFI_ERROR (Status)) { - gBS->UninstallMultipleProtocolInterfaces ( Controller, &gEfiSimpleTextInProtocolGuid, @@ -570,15 +358,7 @@ USBKeyboardDriverBindingStart ( NULL, NULL ); - gBS->CloseEvent (UsbKeyboardDevice->SimpleInput.WaitForKey); - gBS->FreePool (UsbKeyboardDevice); - gBS->CloseProtocol ( - Controller, - &gEfiUsbIoProtocolGuid, - This->DriverBindingHandle, - Controller - ); - return Status; + goto ErrorExit; } UsbKeyboardDevice->ControllerNameTable = NULL; @@ -597,9 +377,11 @@ USBKeyboardDriverBindingStart ( FALSE ); - return EFI_SUCCESS; +// +// Error handler +// ErrorExit: if (UsbKeyboardDevice != NULL) { if (UsbKeyboardDevice->SimpleInput.WaitForKey != NULL) { @@ -608,7 +390,6 @@ ErrorExit: if (UsbKeyboardDevice->SimpleInputEx.WaitForKeyEx != NULL) { gBS->CloseEvent (UsbKeyboardDevice->SimpleInputEx.WaitForKeyEx); } - KbdFreeNotifyList (&UsbKeyboardDevice->NotifyList); gBS->FreePool (UsbKeyboardDevice); UsbKeyboardDevice = NULL; } @@ -624,7 +405,7 @@ ErrorExit: /** - Stop handle the controller by this USB keyboard driver. + Stop handling the controller by this USB keyboard driver. @param This The USB keyboard driver binding protocol. @param Controller The controller to release. @@ -632,6 +413,8 @@ ErrorExit: @param ChildHandleBuffer The array of child handle. @retval EFI_SUCCESS The controller or children are stopped. + @retval EFI_UNSUPPORTED Simple Text In Protocol or Simple Text In Ex Protocol + is not installed on Controller. @retval EFI_DEVICE_ERROR Failed to stop the driver. **/ @@ -644,9 +427,9 @@ USBKeyboardDriverBindingStop ( IN EFI_HANDLE *ChildHandleBuffer ) { - EFI_STATUS Status; + EFI_STATUS Status; EFI_SIMPLE_TEXT_INPUT_PROTOCOL *SimpleInput; - USB_KB_DEV *UsbKeyboardDevice; + USB_KB_DEV *UsbKeyboardDevice; Status = gBS->OpenProtocol ( Controller, @@ -659,6 +442,7 @@ USBKeyboardDriverBindingStop ( if (EFI_ERROR (Status)) { return EFI_UNSUPPORTED; } + Status = gBS->OpenProtocol ( Controller, &gEfiSimpleTextInputExProtocolGuid, @@ -675,25 +459,17 @@ USBKeyboardDriverBindingStop ( // UsbKeyboardDevice = USB_KB_DEV_FROM_THIS (SimpleInput); - gBS->CloseProtocol ( - Controller, - &gEfiSimpleTextInProtocolGuid, - This->DriverBindingHandle, - Controller - ); - // - // Uninstall the Asyn Interrupt Transfer from this device - // will disable the key data input from this device + // The key data input from this device will be disabled. // - KbdReportStatusCode ( - UsbKeyboardDevice->DevicePath, + REPORT_STATUS_CODE_WITH_DEVICE_PATH ( EFI_PROGRESS_CODE, - PcdGet32 (PcdStatusCodeValueKeyboardDisable) + PcdGet32 (PcdStatusCodeValueKeyboardDisable), + UsbKeyboardDevice->DevicePath ); // - // Destroy asynchronous interrupt transfer + // Delete the Asynchronous Interrupt Transfer from this device // UsbKeyboardDevice->UsbIo->UsbAsyncInterruptTransfer ( UsbKeyboardDevice->UsbIo, @@ -706,11 +482,11 @@ USBKeyboardDriverBindingStop ( ); gBS->CloseProtocol ( - Controller, - &gEfiUsbIoProtocolGuid, - This->DriverBindingHandle, - Controller - ); + Controller, + &gEfiUsbIoProtocolGuid, + This->DriverBindingHandle, + Controller + ); Status = gBS->UninstallMultipleProtocolInterfaces ( Controller, @@ -723,7 +499,7 @@ USBKeyboardDriverBindingStop ( NULL ); // - // free all the resources. + // Free all resources. // gBS->CloseEvent (UsbKeyboardDevice->RepeatTimer); gBS->CloseEvent (UsbKeyboardDevice->DelayedRecoveryEvent); @@ -741,12 +517,10 @@ USBKeyboardDriverBindingStop ( gBS->FreePool (UsbKeyboardDevice); return Status; - } /** - Reads the next keystroke from the input device. The WaitForKey Event can - be used to test for existance of a keystroke via WaitForEvent () call. + Internal function to read the next keystroke from the input device. @param UsbKeyboardDevice Usb keyboard's private structure. @param KeyData A pointer to a buffer that is filled in with the keystroke @@ -766,7 +540,6 @@ USBKeyboardReadKeyStrokeWorker ( OUT EFI_KEY_DATA *KeyData ) { - EFI_STATUS Status; UINT8 KeyChar; LIST_ENTRY *Link; @@ -778,39 +551,47 @@ USBKeyboardReadKeyStrokeWorker ( } // - // if there is no saved ASCII byte, fetch it + // If there is no saved ASCII byte, fetch it // by calling USBKeyboardCheckForKey(). // if (UsbKeyboardDevice->CurKeyChar == 0) { Status = USBKeyboardCheckForKey (UsbKeyboardDevice); if (EFI_ERROR (Status)) { - return Status; + return EFI_NOT_READY; } } KeyData->Key.UnicodeChar = 0; KeyData->Key.ScanCode = SCAN_NULL; + // + // Store the key char read by USBKeyboardCheckForKey() and clear it. + // KeyChar = UsbKeyboardDevice->CurKeyChar; - UsbKeyboardDevice->CurKeyChar = 0; // // Translate saved ASCII byte into EFI_INPUT_KEY // - Status = USBKeyCodeToEFIScanCode (UsbKeyboardDevice, KeyChar, &KeyData->Key); + Status = UsbKeyCodeToEfiInputKey (UsbKeyboardDevice, KeyChar, &KeyData->Key); if (EFI_ERROR (Status)) { return Status; } + // + // Get current state of various toggled attributes as well as input modifier values, + // and set them as valid. + // CopyMem (&KeyData->KeyState, &UsbKeyboardDevice->KeyState, sizeof (KeyData->KeyState)); UsbKeyboardDevice->KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID; UsbKeyboardDevice->KeyState.KeyToggleState = EFI_TOGGLE_STATE_VALID; // - //Switch the control value to their original characters. In USBKeyCodeToEFIScanCode() the CTRL-Alpha characters have been switched to - // their corresponding control value (ctrl-a = 0x0001 through ctrl-Z = 0x001A), here switch them back for notification function. + // Switch the control value to their original characters. + // In UsbKeyCodeToEfiInputKey() the CTRL-Alpha characters have been switched to + // their corresponding control value (ctrl-a = 0x0001 through ctrl-Z = 0x001A), + // here switch them back for notification function. // CopyMem (&OriginalKeyData, KeyData, sizeof (EFI_KEY_DATA)); if (UsbKeyboardDevice->CtrlOn != 0) { @@ -824,15 +605,12 @@ USBKeyboardReadKeyStrokeWorker ( } // - // Invoke notification functions if exist + // Invoke notification functions if the key is registered. // - for (Link = UsbKeyboardDevice->NotifyList.ForwardLink; Link != &UsbKeyboardDevice->NotifyList; Link = Link->ForwardLink) { - CurrentNotify = CR ( - Link, - KEYBOARD_CONSOLE_IN_EX_NOTIFY, - NotifyEntry, - USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE - ); + for (Link = GetFirstNode (&UsbKeyboardDevice->NotifyList); + !IsNull (&UsbKeyboardDevice->NotifyList, Link); + Link = GetNextNode (&UsbKeyboardDevice->NotifyList, Link)) { + CurrentNotify = CR (Link, KEYBOARD_CONSOLE_IN_EX_NOTIFY, NotifyEntry, USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE); if (IsKeyRegistered (&CurrentNotify->KeyData, &OriginalKeyData)) { CurrentNotify->KeyNotificationFn (&OriginalKeyData); } @@ -843,20 +621,27 @@ USBKeyboardReadKeyStrokeWorker ( } /** - Reset Usb Keyboard. + Reset USB Keyboard. + + There are 2 types of reset for USB keyboard. + For non-exhaustive reset, only keyboard buffer is cleared. + For exhaustive reset, in addition to clearance of keyboard buffer, the hardware status + is also re-initialized. @param This The protocol instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL. - @param ExtendedVerification Whether completely reset keyboard or not. + @param ExtendedVerification Indicates if exhaustive reset is used. + TRUE for exhaustive reset. + FALSE for non-exhaustive reset. - @retval EFI_SUCCESS Reset keyboard successfully. - @retval EFI_DEVICE_ERROR Reset keyboard failed. + @retval EFI_SUCCESS Keyboard is reset successfully. + @retval EFI_DEVICE_ERROR Failed to reset keyboard. **/ EFI_STATUS EFIAPI USBKeyboardReset ( IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, - IN BOOLEAN ExtendedVerification + IN BOOLEAN ExtendedVerification ) { EFI_STATUS Status; @@ -864,35 +649,35 @@ USBKeyboardReset ( UsbKeyboardDevice = USB_KB_DEV_FROM_THIS (This); - KbdReportStatusCode ( - UsbKeyboardDevice->DevicePath, + REPORT_STATUS_CODE_WITH_DEVICE_PATH ( EFI_PROGRESS_CODE, - PcdGet32 (PcdStatusCodeValueKeyboardReset) + PcdGet32 (PcdStatusCodeValueKeyboardReset), + UsbKeyboardDevice->DevicePath ); // - // Non Exhaustive reset: + // Non-exhaustive reset: // only reset private data structures. // if (!ExtendedVerification) { - // - // Clear the key buffer of this Usb keyboard - // - KbdReportStatusCode ( - UsbKeyboardDevice->DevicePath, + REPORT_STATUS_CODE_WITH_DEVICE_PATH ( EFI_PROGRESS_CODE, - PcdGet32 (PcdStatusCodeValueKeyboardClearBuffer) + PcdGet32 (PcdStatusCodeValueKeyboardClearBuffer), + UsbKeyboardDevice->DevicePath ); - + // + // Clear the key buffer of this USB keyboard + // InitUSBKeyBuffer (&(UsbKeyboardDevice->KeyboardBuffer)); UsbKeyboardDevice->CurKeyChar = 0; + return EFI_SUCCESS; } // // Exhaustive reset // - Status = InitUSBKeyboard (UsbKeyboardDevice); + Status = InitUSBKeyboard (UsbKeyboardDevice); UsbKeyboardDevice->CurKeyChar = 0; if (EFI_ERROR (Status)) { return EFI_DEVICE_ERROR; @@ -917,7 +702,7 @@ EFI_STATUS EFIAPI USBKeyboardReadKeyStroke ( IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, - OUT EFI_INPUT_KEY *Key + OUT EFI_INPUT_KEY *Key ) { USB_KB_DEV *UsbKeyboardDevice; @@ -944,7 +729,6 @@ USBKeyboardReadKeyStroke ( @param Event Event to be signaled when a key is pressed. @param Context Points to USB_KB_DEV instance. - @return None. **/ VOID EFIAPI @@ -958,13 +742,15 @@ USBKeyboardWaitForKey ( UsbKeyboardDevice = (USB_KB_DEV *) Context; if (UsbKeyboardDevice->CurKeyChar == 0) { - if (EFI_ERROR (USBKeyboardCheckForKey (UsbKeyboardDevice))) { + // + // If no pending key, simply return. + // return ; } } // - // If has key pending, signal the event. + // If there is pending key, signal the event. // gBS->SignalEvent (Event); } @@ -975,8 +761,8 @@ USBKeyboardWaitForKey ( @param UsbKeyboardDevice The USB_KB_DEV instance. - @retval EFI_SUCCESS Have key pending to read. - @retval Other Parse key failed. + @retval EFI_SUCCESS There is pending key to read. + @retval EFI_NOT_READY No pending key to read. **/ EFI_STATUS @@ -994,39 +780,13 @@ USBKeyboardCheckForKey ( // Status = USBParseKey (UsbKeyboardDevice, &KeyChar); if (EFI_ERROR (Status)) { - return Status; + return EFI_NOT_READY; } UsbKeyboardDevice->CurKeyChar = KeyChar; return EFI_SUCCESS; } -/** - Report Status Code in Usb Keyboard Driver. - - @param DevicePath Use this to get Device Path. - @param CodeType Status Code Type. - @param CodeValue Status Code Value. - - @return None. - -**/ -VOID -EFIAPI -KbdReportStatusCode ( - IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, - IN EFI_STATUS_CODE_TYPE CodeType, - IN EFI_STATUS_CODE_VALUE Value - ) -{ - - REPORT_STATUS_CODE_WITH_DEVICE_PATH ( - CodeType, - Value, - DevicePath - ); -} - /** Free keyboard notify list. @@ -1274,7 +1034,9 @@ USBKeyboardRegisterKeyNotify ( // // Return EFI_SUCCESS if the (KeyData, NotificationFunction) is already registered. // - for (Link = UsbKeyboardDevice->NotifyList.ForwardLink; Link != &UsbKeyboardDevice->NotifyList; Link = Link->ForwardLink) { + for (Link = GetFirstNode (&UsbKeyboardDevice->NotifyList); + !IsNull (&UsbKeyboardDevice->NotifyList, Link); + Link = GetNextNode (&UsbKeyboardDevice->NotifyList, Link)) { CurrentNotify = CR ( Link, KEYBOARD_CONSOLE_IN_EX_NOTIFY, @@ -1349,6 +1111,9 @@ USBKeyboardUnregisterKeyNotify ( UsbKeyboardDevice = TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS (This); + // + // Check if NotificationHandle is returned from RegisterKeyNotify(). + // Status = gBS->OpenProtocol ( NotificationHandle, &gSimpleTextInExNotifyGuid, @@ -1361,7 +1126,12 @@ USBKeyboardUnregisterKeyNotify ( return EFI_INVALID_PARAMETER; } - for (Link = UsbKeyboardDevice->NotifyList.ForwardLink; Link != &UsbKeyboardDevice->NotifyList; Link = Link->ForwardLink) { + // + // Traverse notify list of USB keyboard and remove the entry of NotificationHandle. + // + for (Link = GetFirstNode (&UsbKeyboardDevice->NotifyList); + !IsNull (&UsbKeyboardDevice->NotifyList, Link); + Link = GetNextNode (&UsbKeyboardDevice->NotifyList, Link)) { CurrentNotify = CR ( Link, KEYBOARD_CONSOLE_IN_EX_NOTIFY, diff --git a/MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.h b/MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.h index 8edd34d94c..506a08ce24 100644 --- a/MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.h +++ b/MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.h @@ -1,6 +1,5 @@ /** @file - - Header file for USB Keyboard Driver's Data Structures. + Header file for USB Keyboard Driver's Data Structures. Copyright (c) 2004 - 2008, Intel Corporation All rights reserved. This program and the accompanying materials @@ -37,6 +36,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include +#include #include @@ -59,9 +59,9 @@ typedef struct { } USB_KEY; typedef struct { - USB_KEY buffer[MAX_KEY_ALLOWED + 1]; - UINT8 bHead; - UINT8 bTail; + USB_KEY Buffer[MAX_KEY_ALLOWED + 1]; + UINT8 BufferHead; + UINT8 BufferTail; } USB_KB_BUFFER; #define USB_KB_DEV_SIGNATURE EFI_SIGNATURE_32 ('u', 'k', 'b', 'd') @@ -95,57 +95,60 @@ typedef struct { #define USB_NS_KEY_FORM_FROM_LINK(a) CR (a, USB_NS_KEY, Link, USB_NS_KEY_SIGNATURE) +/// +/// Structure to describe USB keyboard device +/// typedef struct { - UINTN Signature; - EFI_DEVICE_PATH_PROTOCOL *DevicePath; - EFI_EVENT DelayedRecoveryEvent; - EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleInput; + UINTN Signature; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + EFI_EVENT DelayedRecoveryEvent; + EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleInput; EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL SimpleInputEx; - EFI_USB_IO_PROTOCOL *UsbIo; + EFI_USB_IO_PROTOCOL *UsbIo; - EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor; - EFI_USB_ENDPOINT_DESCRIPTOR IntEndpointDescriptor; + EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor; + EFI_USB_ENDPOINT_DESCRIPTOR IntEndpointDescriptor; - USB_KB_BUFFER KeyboardBuffer; - UINT8 CtrlOn; - UINT8 AltOn; - UINT8 ShiftOn; - UINT8 NumLockOn; - UINT8 CapsOn; - UINT8 ScrollOn; - UINT8 LastKeyCodeArray[8]; - UINT8 CurKeyChar; + USB_KB_BUFFER KeyboardBuffer; + UINT8 CtrlOn; + UINT8 AltOn; + UINT8 ShiftOn; + UINT8 NumLockOn; + UINT8 CapsOn; + UINT8 ScrollOn; + UINT8 LastKeyCodeArray[8]; + UINT8 CurKeyChar; - UINT8 RepeatKey; - EFI_EVENT RepeatTimer; + UINT8 RepeatKey; + EFI_EVENT RepeatTimer; - EFI_UNICODE_STRING_TABLE *ControllerNameTable; + EFI_UNICODE_STRING_TABLE *ControllerNameTable; - UINT8 LeftCtrlOn; - UINT8 LeftAltOn; - UINT8 LeftShiftOn; - UINT8 LeftLogoOn; - UINT8 RightCtrlOn; - UINT8 RightAltOn; - UINT8 RightShiftOn; - UINT8 RightLogoOn; - UINT8 MenuKeyOn; - UINT8 SysReqOn; - UINT8 AltGrOn; - - EFI_KEY_STATE KeyState; + UINT8 LeftCtrlOn; + UINT8 LeftAltOn; + UINT8 LeftShiftOn; + UINT8 LeftLogoOn; + UINT8 RightCtrlOn; + UINT8 RightAltOn; + UINT8 RightShiftOn; + UINT8 RightLogoOn; + UINT8 MenuKeyOn; + UINT8 SysReqOn; + UINT8 AltGrOn; + + EFI_KEY_STATE KeyState; // // Notification function list // - LIST_ENTRY NotifyList; + LIST_ENTRY NotifyList; // // Non-spacing key list // - LIST_ENTRY NsKeyList; - USB_NS_KEY *CurrentNsKey; - EFI_KEY_DESCRIPTOR *KeyConvertionTable; - EFI_EVENT KeyboardLayoutEvent; + LIST_ENTRY NsKeyList; + USB_NS_KEY *CurrentNsKey; + EFI_KEY_DESCRIPTOR *KeyConvertionTable; + EFI_EVENT KeyboardLayoutEvent; } USB_KB_DEV; // @@ -154,27 +157,8 @@ typedef struct { extern EFI_DRIVER_BINDING_PROTOCOL gUsbKeyboardDriverBinding; extern EFI_COMPONENT_NAME_PROTOCOL gUsbKeyboardComponentName; extern EFI_COMPONENT_NAME2_PROTOCOL gUsbKeyboardComponentName2; -extern EFI_GUID gEfiUsbKeyboardDriverGuid; extern EFI_GUID gSimpleTextInExNotifyGuid; -/** - Report Status Code in Usb Keyboard Driver. - - @param DevicePath Use this to get Device Path. - @param CodeType Status Code Type. - @param CodeValue Status Code Value. - - @return None. - -**/ -VOID -EFIAPI -KbdReportStatusCode ( - IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, - IN EFI_STATUS_CODE_TYPE CodeType, - IN EFI_STATUS_CODE_VALUE Value - ); - #define USB_KB_DEV_FROM_THIS(a) \ CR(a, USB_KB_DEV, SimpleInput, USB_KB_DEV_SIGNATURE) #define TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS(a) \ @@ -206,6 +190,117 @@ typedef struct { UINT8 Resrvd : 5; } LED_MAP; +// +// Functions of Driver Binding Protocol +// +/** + Check whether USB keyboard driver supports this device. + + @param This The USB keyboard driver binding protocol. + @param Controller The controller handle to check. + @param RemainingDevicePath The remaining device path. + + @retval EFI_SUCCESS The driver supports this controller. + @retval other This device isn't supported. + +**/ +EFI_STATUS +EFIAPI +USBKeyboardDriverBindingSupported ( + IN EFI_DRIVER_BINDING_PROTOCOL *This, + IN EFI_HANDLE Controller, + IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath + ); + +/** + Start running driver on the controller. + + @param This The USB keyboard driver binding instance. + @param Controller Handle of device to bind driver to. + @param RemainingDevicePath Optional parameter use to pick a specific child + device to start. + + @retval EFI_SUCCESS The controller is controlled by the usb keyboard driver. + @retval EFI_UNSUPPORTED No interrupt endpoint can be found. + @retval Other The keyboard driver cannot support this controller. + +**/ +EFI_STATUS +EFIAPI +USBKeyboardDriverBindingStart ( + IN EFI_DRIVER_BINDING_PROTOCOL *This, + IN EFI_HANDLE Controller, + IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath + ); + +/** + Stop handling the controller by this USB keyboard driver. + + @param This The USB keyboard driver binding protocol. + @param Controller The controller to release. + @param NumberOfChildren The number of handles in ChildHandleBuffer. + @param ChildHandleBuffer The array of child handle. + + @retval EFI_SUCCESS The controller or children are stopped. + @retval EFI_UNSUPPORTED Simple Text In Protocol or Simple Text In Ex Protocol + is not installed on Controller. + @retval EFI_DEVICE_ERROR Failed to stop the driver. + +**/ +EFI_STATUS +EFIAPI +USBKeyboardDriverBindingStop ( + IN EFI_DRIVER_BINDING_PROTOCOL *This, + IN EFI_HANDLE Controller, + IN UINTN NumberOfChildren, + IN EFI_HANDLE *ChildHandleBuffer + ); + +// +// Functions of Simple Text Input Protocol +// +/** + Reset USB Keyboard. + + There are 2 types of reset for USB keyboard. + For non-exhaustive reset, only keyboard buffer is cleared. + For exhaustive reset, in addition to clearance of keyboard buffer, the hardware status + is also re-initialized. + + @param This The protocol instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL. + @param ExtendedVerification Indicates if exhaustive reset is used. + TRUE for exhaustive reset. + FALSE for non-exhaustive reset. + + @retval EFI_SUCCESS Keyboard is reset successfully. + @retval EFI_DEVICE_ERROR Failed to reset keyboard. + +**/ +EFI_STATUS +EFIAPI +USBKeyboardReset ( + IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, + IN BOOLEAN ExtendedVerification + ); + +/** + Implements EFI_SIMPLE_TEXT_INPUT_PROTOCOL.ReadKeyStroke() function. + + @param This The EFI_SIMPLE_TEXT_INPUT_PROTOCOL instance. + @param Key A pointer to a buffer that is filled in with the keystroke + information for the key that was pressed. + + @retval EFI_SUCCESS Read key stroke successfully. + @retval Other Read key stroke failed. + +**/ +EFI_STATUS +EFIAPI +USBKeyboardReadKeyStroke ( + IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, + OUT EFI_INPUT_KEY *Key + ); + // // Simple Text Input Ex protocol functions // @@ -309,5 +404,68 @@ USBKeyboardUnregisterKeyNotify ( IN EFI_HANDLE NotificationHandle ); +/** + Handler function for WaitForKey event. + + @param Event Event to be signaled when a key is pressed. + @param Context Points to USB_KB_DEV instance. + +**/ +VOID +EFIAPI +USBKeyboardWaitForKey ( + IN EFI_EVENT Event, + IN VOID *Context + ); + +/** + Free keyboard notify list. + + @param ListHead The list head. + + @retval EFI_SUCCESS Free the notify list successfully. + @retval EFI_INVALID_PARAMETER ListHead is invalid. + +**/ +EFI_STATUS +EFIAPI +KbdFreeNotifyList ( + IN OUT LIST_ENTRY *ListHead + ); + +/** + Check whether there is key pending. + + @param UsbKeyboardDevice The USB_KB_DEV instance. + + @retval EFI_SUCCESS There is pending key to read. + @retval EFI_NOT_READY No pending key to read. + +**/ +EFI_STATUS +EFIAPI +USBKeyboardCheckForKey ( + IN USB_KB_DEV *UsbKeyboardDevice + ); + +/** + Whether the pressed key matches a registered key or not. + + @param RegsiteredData A pointer to a buffer that is filled in with the keystroke + state data for the key that was registered. + @param InputData A pointer to a buffer that is filled in with the keystroke + state data for the key that was pressed. + + @retval TRUE Key pressed matches a registered key. + @retval FLASE Match failed. + +**/ +BOOLEAN +EFIAPI +IsKeyRegistered ( + IN EFI_KEY_DATA *RegsiteredData, + IN EFI_KEY_DATA *InputData + ); + #endif diff --git a/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c b/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c index 9af221daad..0d7d3d1bad 100644 --- a/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c +++ b/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c @@ -1,5 +1,4 @@ /** @file - Helper functions for USB Keyboard Driver. Copyright (c) 2004 - 2008, Intel Corporation @@ -14,7 +13,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ #include "KeyBoard.h" -#include // // Static English keyboard layout @@ -295,12 +293,10 @@ KB_MODIFIER KB_Mod[8] = { { MOD_WIN_R, 0xe7 }, // 11100111 }; - /** Initialize KeyConvertionTable by using default keyboard layout. @param UsbKeyboardDevice The USB_KB_DEV instance. - @retval None. **/ VOID @@ -330,12 +326,10 @@ LoadDefaultKeyboardLayout ( } } - /** Uses USB I/O to check whether the device is a USB Keyboard device. @param UsbIo Points to a USB I/O protocol instance. - @retval None **/ BOOLEAN @@ -374,7 +368,7 @@ IsUSBKeyboard ( /** Get current keyboard layout from HII database. - @retval Pointer to EFI_HII_KEYBOARD_LAYOUT. + @return Pointer to EFI_HII_KEYBOARD_LAYOUT. **/ EFI_HII_KEYBOARD_LAYOUT * @@ -437,6 +431,7 @@ GetCurrentKeyboardLayout ( @param ScanCode USB scan code. @return The Key descriptor in KeyConvertionTable. + NULL means not found. **/ EFI_KEY_DESCRIPTOR * @@ -467,8 +462,8 @@ GetKeyDescriptor ( @param UsbKeyboardDevice The USB_KB_DEV instance. @param KeyDescriptor Key descriptor. - @retval NULL Key list is empty. - @return Other The Non-Spacing key. + @return The Non-Spacing key corresponding to KeyDescriptor + NULL means not found. **/ USB_NS_KEY * @@ -566,12 +561,15 @@ SetKeyboardLayoutEvent ( } // - // Allocate resource for KeyConvertionTable + // Re-allocate resource for KeyConvertionTable // ReleaseKeyboardLayoutResources (UsbKeyboardDevice); UsbKeyboardDevice->KeyConvertionTable = AllocateZeroPool ((USB_KEYCODE_MAX_MAKE + 8) * sizeof (EFI_KEY_DESCRIPTOR)); ASSERT (UsbKeyboardDevice->KeyConvertionTable != NULL); + // + // Traverse the list of key descriptors following the header of EFI_HII_KEYBOARD_LAYOUT + // KeyDescriptor = (EFI_KEY_DESCRIPTOR *) (((UINT8 *) KeyboardLayout) + sizeof (EFI_HII_KEYBOARD_LAYOUT)); for (Index = 0; Index < KeyboardLayout->DescriptorCount; Index++) { // @@ -580,7 +578,7 @@ SetKeyboardLayoutEvent ( CopyMem (&TempKey, KeyDescriptor, sizeof (EFI_KEY_DESCRIPTOR)); // - // Fill the key into KeyConvertionTable (which use USB Scan Code as index) + // Fill the key into KeyConvertionTable, whose index is calculated from USB scan code. // ScanCode = UsbScanCodeConvertionTable [(UINT8) (TempKey.Key)]; TableEntry = GetKeyDescriptor (UsbKeyboardDevice, ScanCode); @@ -588,7 +586,7 @@ SetKeyboardLayoutEvent ( if (TempKey.Modifier == EFI_NS_KEY_MODIFIER) { // - // Non-spacing key + // For non-spacing key, create the list with a non-spacing key followed by physical keys. // UsbNsKey = AllocatePool (sizeof (USB_NS_KEY)); ASSERT (UsbNsKey != NULL); @@ -692,7 +690,8 @@ InitKeyboardLayout ( UsbKeyboardDevice->KeyboardLayoutEvent = NULL; // - // Register SET_KEYBOARD_LAYOUT_EVENT notification + // Register event to EFI_HII_SET_KEYBOARD_LAYOUT_EVENT_GUID group, + // which will be triggered by EFI_HII_DATABASE_PROTOCOL.SetKeyboardLayout. // Status = gBS->CreateEventEx ( EVT_NOTIFY_SIGNAL, @@ -706,26 +705,26 @@ InitKeyboardLayout ( return Status; } - // - // Try to get current keyboard layout from HII database - // KeyboardLayout = GetCurrentKeyboardLayout (); if (KeyboardLayout != NULL) { // - // Force to initialize the keyboard layout + // If current keyboard layout is successfully retrieved from HII database, + // force to initialize the keyboard layout. // gBS->SignalEvent (UsbKeyboardDevice->KeyboardLayoutEvent); } else { if (FeaturePcdGet (PcdDisableDefaultKeyboardLayoutInUsbKbDriver)) { - return EFI_NOT_READY; - } else { - // - // Fail to get keyboard layout from HII database, - // use default keyboard layout + // If no keyboard layout can be retrieved from HII database, and default layout + // is disabled, then return EFI_NOT_READY. // - LoadDefaultKeyboardLayout (UsbKeyboardDevice); + return EFI_NOT_READY; } + // + // If no keyboard layout can be retrieved from HII database, and default layout + // is enabled, then load the default keyboard layout. + // + LoadDefaultKeyboardLayout (UsbKeyboardDevice); } return EFI_SUCCESS; @@ -754,10 +753,10 @@ InitUSBKeyboard ( EFI_STATUS Status; UINT32 TransferResult; - KbdReportStatusCode ( - UsbKeyboardDevice->DevicePath, + REPORT_STATUS_CODE_WITH_DEVICE_PATH ( EFI_PROGRESS_CODE, - PcdGet32 (PcdStatusCodeValueKeyboardSelfTest) + PcdGet32 (PcdStatusCodeValueKeyboardSelfTest), + UsbKeyboardDevice->DevicePath ); InitUSBKeyBuffer (&(UsbKeyboardDevice->KeyboardBuffer)); @@ -771,20 +770,20 @@ InitUSBKeyboard ( // Uses default configuration to configure the USB Keyboard device. // Status = UsbSetConfiguration ( - UsbKeyboardDevice->UsbIo, - (UINT16) ConfigValue, - &TransferResult - ); + UsbKeyboardDevice->UsbIo, + (UINT16) ConfigValue, + &TransferResult + ); if (EFI_ERROR (Status)) { // // If configuration could not be set here, it means // the keyboard interface has some errors and could // not be initialized // - KbdReportStatusCode ( - UsbKeyboardDevice->DevicePath, + REPORT_STATUS_CODE_WITH_DEVICE_PATH ( EFI_ERROR_CODE | EFI_ERROR_MINOR, - PcdGet32 (PcdStatusCodeValueKeyboardInterfaceError) + PcdGet32 (PcdStatusCodeValueKeyboardInterfaceError), + UsbKeyboardDevice->DevicePath ); return EFI_DEVICE_ERROR; @@ -796,9 +795,9 @@ InitUSBKeyboard ( &Protocol ); // - // Sets boot protocol for the USB Keyboard. + // Set boot protocol for the USB Keyboard. // This driver only supports boot protocol. - // !!BugBug: How about the device that does not support boot protocol? + // The device that does not support boot protocol is not supported. // if (Protocol != BOOT_PROTOCOL) { UsbSetProtocolRequest ( @@ -807,17 +806,15 @@ InitUSBKeyboard ( BOOT_PROTOCOL ); } - // - // the duration is indefinite, so the endpoint will inhibit reporting forever, - // and only reporting when a change is detected in the report data. - // // - // idle value for all report ID + // ReportId is zero, which means the idle rate applies to all input reports. // ReportId = 0; // - // idle forever until there is a key pressed and released. + // Duration is zero, which means the duration is indefinite. + // so the endpoint will inhibit reporting forever, + // and only reporting when a change is detected in the report data. // Duration = 0; UsbSetIdleRequest ( @@ -861,7 +858,7 @@ InitUSBKeyboard ( // if (UsbKeyboardDevice->RepeatTimer != NULL) { gBS->CloseEvent (UsbKeyboardDevice->RepeatTimer); - UsbKeyboardDevice->RepeatTimer = 0; + UsbKeyboardDevice->RepeatTimer = NULL; } Status = gBS->CreateEvent ( @@ -874,7 +871,7 @@ InitUSBKeyboard ( if (UsbKeyboardDevice->DelayedRecoveryEvent != NULL) { gBS->CloseEvent (UsbKeyboardDevice->DelayedRecoveryEvent); - UsbKeyboardDevice->DelayedRecoveryEvent = 0; + UsbKeyboardDevice->DelayedRecoveryEvent = NULL; } Status = gBS->CreateEvent ( @@ -928,7 +925,7 @@ KeyboardHandler ( UINT32 UsbStatus; EFI_KEY_DESCRIPTOR *KeyDescriptor; - ASSERT (Context); + ASSERT (Context != NULL); NewRepeatKey = 0; UsbKeyboardDevice = (USB_KB_DEV *) Context; @@ -941,10 +938,10 @@ KeyboardHandler ( // // Some errors happen during the process // - KbdReportStatusCode ( - UsbKeyboardDevice->DevicePath, + REPORT_STATUS_CODE_WITH_DEVICE_PATH ( EFI_ERROR_CODE | EFI_ERROR_MINOR, - PcdGet32 (PcdStatusCodeValueKeyboardInputError) + PcdGet32 (PcdStatusCodeValueKeyboardInputError), + UsbKeyboardDevice->DevicePath ); // @@ -968,37 +965,48 @@ KeyboardHandler ( // // Delete & Submit this interrupt again + // Handler of DelayedRecoveryEvent triggered by timer will re-submit the interrupt. // - UsbIo->UsbAsyncInterruptTransfer ( - UsbIo, - UsbKeyboardDevice->IntEndpointDescriptor.EndpointAddress, - FALSE, - 0, - 0, - NULL, - NULL - ); - + UsbIo, + UsbKeyboardDevice->IntEndpointDescriptor.EndpointAddress, + FALSE, + 0, + 0, + NULL, + NULL + ); + // + // EFI_USB_INTERRUPT_DELAY is defined in USB standard for error handling + // gBS->SetTimer ( - UsbKeyboardDevice->DelayedRecoveryEvent, - TimerRelative, - EFI_USB_INTERRUPT_DELAY - ); + UsbKeyboardDevice->DelayedRecoveryEvent, + TimerRelative, + EFI_USB_INTERRUPT_DELAY + ); return EFI_DEVICE_ERROR; } + // + // If no error and no data, just return EFI_SUCCESS. + // if (DataLength == 0 || Data == NULL) { return EFI_SUCCESS; } + // + // Following code checks current keyboard input report against old key code buffer. + // According to USB HID Firmware Specification, the report consists of 8 bytes. + // Byte 0 is map of Modifier keys. + // Byte 1 is reserved. + // Bytes 2 to 7 are keycodes. + // CurKeyCodeBuffer = (UINT8 *) Data; OldKeyCodeBuffer = UsbKeyboardDevice->LastKeyCodeArray; // - // checks for new key stroke. - // if no new key got, return immediately. + // Checks for new key stroke. // for (Index = 0; Index < 8; Index++) { if (OldKeyCodeBuffer[Index] != CurKeyCodeBuffer[Index]) { @@ -1006,26 +1014,29 @@ KeyboardHandler ( } } + // + // If no new key, return EFI_SUCCESS immediately. + // if (Index == 8) { return EFI_SUCCESS; } // - // Parse the modifier key + // Parse the modifier key, which is the first byte of keyboard input report. // CurModifierMap = CurKeyCodeBuffer[0]; OldModifierMap = OldKeyCodeBuffer[0]; // - // handle modifier key's pressing or releasing situation. + // Handle modifier key's pressing or releasing situation. // for (Index = 0; Index < 8; Index++) { if ((CurModifierMap & KB_Mod[Index].Mask) != (OldModifierMap & KB_Mod[Index].Mask)) { // - // if current modifier key is up, then + // If current modifier key is up, then // CurModifierMap & KB_Mod[Index].Mask = 0; - // otherwize it is a non-zero value. + // otherwise it is a non-zero value. // Inserts the pressed modifier key into key buffer. // Down = (UINT8) (CurModifierMap & KB_Mod[Index].Mask); @@ -1034,7 +1045,8 @@ KeyboardHandler ( } // - // handle normal key's releasing situation + // Handle normal key's releasing situation + // Bytes 2 to 7 are normal keycodes // KeyRelease = FALSE; for (Index = 2; Index < 8; Index++) { @@ -1042,7 +1054,10 @@ KeyboardHandler ( if (!USBKBD_VALID_KEYCODE (OldKeyCodeBuffer[Index])) { continue; } - + // + // For any key in old keycode buffer, if it is not in current keycode buffer, + // then it is released. Otherwise, it is not released. + // KeyRelease = TRUE; for (Index2 = 2; Index2 < 8; Index2++) { @@ -1063,7 +1078,7 @@ KeyboardHandler ( 0 ); // - // the original reapeat key is released. + // The original repeat key is released. // if (OldKeyCodeBuffer[Index] == UsbKeyboardDevice->RepeatKey) { UsbKeyboardDevice->RepeatKey = 0; @@ -1072,18 +1087,18 @@ KeyboardHandler ( } // - // original repeat key is released, cancel the repeat timer + // If original repeat key is released, cancel the repeat timer // if (UsbKeyboardDevice->RepeatKey == 0) { gBS->SetTimer ( - UsbKeyboardDevice->RepeatTimer, - TimerCancel, - USBKBD_REPEAT_RATE - ); + UsbKeyboardDevice->RepeatTimer, + TimerCancel, + USBKBD_REPEAT_RATE + ); } // - // handle normal key's pressing situation + // Handle normal key's pressing situation // KeyPress = FALSE; for (Index = 2; Index < 8; Index++) { @@ -1091,7 +1106,10 @@ KeyboardHandler ( if (!USBKBD_VALID_KEYCODE (CurKeyCodeBuffer[Index])) { continue; } - + // + // For any key in current keycode buffer, if it is not in old keycode buffer, + // then it is pressed. Otherwise, it is not pressed. + // KeyPress = TRUE; for (Index2 = 2; Index2 < 8; Index2++) { @@ -1107,17 +1125,21 @@ KeyboardHandler ( if (KeyPress) { InsertKeyCode (&(UsbKeyboardDevice->KeyboardBuffer), CurKeyCodeBuffer[Index], 1); + // - // NumLock pressed or CapsLock pressed + // Handle repeat key // KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, CurKeyCodeBuffer[Index]); if (KeyDescriptor->Modifier == EFI_NUM_LOCK_MODIFIER || KeyDescriptor->Modifier == EFI_CAPS_LOCK_MODIFIER) { + // + // For NumLock or CapsLock pressed, there is no need to handle repeat key for them. + // UsbKeyboardDevice->RepeatKey = 0; } else { - NewRepeatKey = CurKeyCodeBuffer[Index]; // - // do not repeat the original repeated key + // Prepare new repeat key, and clear the original one. // + NewRepeatKey = CurKeyCodeBuffer[Index]; UsbKeyboardDevice->RepeatKey = 0; } } @@ -1132,11 +1154,11 @@ KeyboardHandler ( } // - // pre-process KeyboardBuffer, pop out the ctrl,alt,del key in sequence + // Pre-process KeyboardBuffer. Pop out the Ctrl, Alt, Del key in sequence // and judge whether it will invoke reset event. // - SavedTail = UsbKeyboardDevice->KeyboardBuffer.bTail; - Index = UsbKeyboardDevice->KeyboardBuffer.bHead; + SavedTail = UsbKeyboardDevice->KeyboardBuffer.BufferTail; + Index = UsbKeyboardDevice->KeyboardBuffer.BufferHead; while (Index != SavedTail) { RemoveKeyCode (&(UsbKeyboardDevice->KeyboardBuffer), &UsbKey); @@ -1171,7 +1193,7 @@ KeyboardHandler ( break; // - // Del Key Code + // For Del Key, check if Ctrl + Alt + Del occurs for reset. // case EFI_DELETE_MODIFIER: if (UsbKey.Down != 0) { @@ -1186,7 +1208,7 @@ KeyboardHandler ( } // - // insert the key back to the buffer. + // Insert the key back to the buffer, // so the key sequence will not be destroyed. // InsertKeyCode ( @@ -1194,7 +1216,7 @@ KeyboardHandler ( UsbKey.KeyCode, UsbKey.Down ); - Index = UsbKeyboardDevice->KeyboardBuffer.bHead; + Index = UsbKeyboardDevice->KeyboardBuffer.BufferHead; } // @@ -1203,7 +1225,7 @@ KeyboardHandler ( // if (NewRepeatKey != 0) { // - // sets trigger time to "Repeat Delay Time", + // Sets trigger time to "Repeat Delay Time", // to trigger the repeat timer when the key is hold long // enough time. // @@ -1243,12 +1265,15 @@ USBParseKey ( while (!IsUSBKeyboardBufferEmpty (&UsbKeyboardDevice->KeyboardBuffer)) { // - // pops one raw data off. + // Pops one raw data off. // RemoveKeyCode (&(UsbKeyboardDevice->KeyboardBuffer), &UsbKey); KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, UsbKey.KeyCode); if (UsbKey.Down == 0) { + // + // Key is released. + // switch (KeyDescriptor->Modifier) { // @@ -1417,7 +1442,7 @@ USBParseKey ( case EFI_NUM_LOCK_MODIFIER: UsbKeyboardDevice->NumLockOn ^= 1; // - // Turn on the NumLock light on KB + // Set the NumLock light on keyboard // SetKeyLED (UsbKeyboardDevice); continue; @@ -1426,7 +1451,7 @@ USBParseKey ( case EFI_CAPS_LOCK_MODIFIER: UsbKeyboardDevice->CapsOn ^= 1; // - // Turn on the CapsLock light on KB + // Set the CapsLock light on keyboard // SetKeyLED (UsbKeyboardDevice); continue; @@ -1435,22 +1460,22 @@ USBParseKey ( case EFI_SCROLL_LOCK_MODIFIER: UsbKeyboardDevice->ScrollOn ^= 1; // - // Turn on the ScrollLock light on KB + // Set the ScrollLock light on keyboard // SetKeyLED (UsbKeyboardDevice); continue; break; // - // F11,F12,PrintScreen,Pause/Break - // could not be retrieved via SimpleTxtInEx protocol + // F11, F12, PrintScreen, Pause/Break + // could not be retrieved via SimpleTextInEx protocol // case EFI_FUNCTION_KEY_ELEVEN_MODIFIER: case EFI_FUNCTION_KEY_TWELVE_MODIFIER: case EFI_PAUSE_MODIFIER: case EFI_BREAK_MODIFIER: // - // fall through + // Fall through // continue; break; @@ -1460,7 +1485,7 @@ USBParseKey ( } // - // When encountered Del Key... + // When encountering Ctrl + Alt + Del, then warm reset. // if (KeyDescriptor->Modifier == EFI_DELETE_MODIFIER) { if ((UsbKeyboardDevice->CtrlOn != 0) && (UsbKeyboardDevice->AltOn != 0)) { @@ -1477,7 +1502,7 @@ USBParseKey ( /** - Converts USB Keyboard code to EFI Scan Code. + Converts USB Keyboard code to EFI_INPUT_KEY. @param UsbKeyboardDevice The USB_KB_DEV instance. @param KeyChar Indicates the key code that will be interpreted. @@ -1491,7 +1516,7 @@ USBParseKey ( **/ EFI_STATUS EFIAPI -USBKeyCodeToEFIScanCode ( +UsbKeyCodeToEfiInputKey ( IN USB_KB_DEV *UsbKeyboardDevice, IN UINT8 KeyChar, OUT EFI_INPUT_KEY *Key @@ -1505,7 +1530,7 @@ USBKeyCodeToEFIScanCode ( } // - // valid USB Key Code starts from 4 + // Valid USB Key Code starts from 4, so it's safe to minus 4. // Index = (UINT8) (KeyChar - 4); @@ -1515,18 +1540,19 @@ USBKeyCodeToEFIScanCode ( KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, KeyChar); - // - // Check for Non-spacing key - // if (KeyDescriptor->Modifier == EFI_NS_KEY_MODIFIER) { + // + // If this is a dead key with EFI_NS_KEY_MODIFIER, then record it and return. + // UsbKeyboardDevice->CurrentNsKey = FindUsbNsKey (UsbKeyboardDevice, KeyDescriptor); return EFI_NOT_READY; } - // - // Check whether this keystroke follows a Non-spacing key - // if (UsbKeyboardDevice->CurrentNsKey != NULL) { + // + // If this keystroke follows a non-spacing key, then find the descriptor for corresponding + // physical key. + // KeyDescriptor = FindPhysicalKey (UsbKeyboardDevice->CurrentNsKey, KeyDescriptor); UsbKeyboardDevice->CurrentNsKey = NULL; } @@ -1534,7 +1560,7 @@ USBKeyCodeToEFIScanCode ( Key->ScanCode = EfiScanCodeConvertionTable[KeyDescriptor->Modifier]; Key->UnicodeChar = KeyDescriptor->Unicode; - if (KeyDescriptor->AffectedAttribute & EFI_AFFECTED_BY_STANDARD_SHIFT) { + if ((KeyDescriptor->AffectedAttribute & EFI_AFFECTED_BY_STANDARD_SHIFT)!= 0) { if (UsbKeyboardDevice->ShiftOn != 0) { Key->UnicodeChar = KeyDescriptor->ShiftedUnicode; @@ -1542,7 +1568,7 @@ USBKeyCodeToEFIScanCode ( // Need not return associated shift state if a class of printable characters that // are normally adjusted by shift modifiers. e.g. Shift Key + 'f' key = 'F' // - if (KeyDescriptor->AffectedAttribute & EFI_AFFECTED_BY_CAPS_LOCK) { + if ((KeyDescriptor->AffectedAttribute & EFI_AFFECTED_BY_CAPS_LOCK) != 0) { UsbKeyboardDevice->LeftShiftOn = 0; UsbKeyboardDevice->RightShiftOn = 0; } @@ -1562,7 +1588,7 @@ USBKeyCodeToEFIScanCode ( } } - if (KeyDescriptor->AffectedAttribute & EFI_AFFECTED_BY_CAPS_LOCK) { + if ((KeyDescriptor->AffectedAttribute & EFI_AFFECTED_BY_CAPS_LOCK) != 0) { if (UsbKeyboardDevice->CapsOn != 0) { if (Key->UnicodeChar == KeyDescriptor->Unicode) { @@ -1578,7 +1604,8 @@ USBKeyCodeToEFIScanCode ( } // - // Translate the CTRL-Alpha characters to their corresponding control value (ctrl-a = 0x0001 through ctrl-Z = 0x001A) + // Translate the CTRL-Alpha characters to their corresponding control value + // (ctrl-a = 0x0001 through ctrl-Z = 0x001A) // if (UsbKeyboardDevice->CtrlOn != 0) { if (Key->UnicodeChar >= 'a' && Key->UnicodeChar <= 'z') { @@ -1589,11 +1616,13 @@ USBKeyCodeToEFIScanCode ( } if (KeyDescriptor->AffectedAttribute & EFI_AFFECTED_BY_NUM_LOCK) { - + // + // For key affected by NumLock, if NumLock is on and Shift is not pressed, then it means + // normal key, instead of original control key. So the ScanCode should be cleaned. + // Otherwise, it means control key, so preserve the EFI Scan Code and clear the unicode keycode. + // if ((UsbKeyboardDevice->NumLockOn != 0) && (UsbKeyboardDevice->ShiftOn == 0)) { - Key->ScanCode = SCAN_NULL; - } else { Key->UnicodeChar = 0x00; } @@ -1607,6 +1636,9 @@ USBKeyCodeToEFIScanCode ( Key->UnicodeChar = 0x00; } + // + // Not valid for key without both unicode key code and EFI Scan Code. + // if (Key->UnicodeChar == 0 && Key->ScanCode == SCAN_NULL) { return EFI_NOT_READY; } @@ -1666,10 +1698,8 @@ USBKeyCodeToEFIScanCode ( @param KeyboardBuffer Points to the USB Keyboard Buffer. - @retval EFI_SUCCESS Init key buffer successfully. - **/ -EFI_STATUS +VOID EFIAPI InitUSBKeyBuffer ( IN OUT USB_KB_BUFFER *KeyboardBuffer @@ -1677,9 +1707,7 @@ InitUSBKeyBuffer ( { ZeroMem (KeyboardBuffer, sizeof (USB_KB_BUFFER)); - KeyboardBuffer->bHead = KeyboardBuffer->bTail; - - return EFI_SUCCESS; + KeyboardBuffer->BufferHead = KeyboardBuffer->BufferTail; } @@ -1701,7 +1729,7 @@ IsUSBKeyboardBufferEmpty ( // // meet FIFO empty condition // - return (BOOLEAN) (KeyboardBuffer->bHead == KeyboardBuffer->bTail); + return (BOOLEAN) (KeyboardBuffer->BufferHead == KeyboardBuffer->BufferTail); } @@ -1720,8 +1748,7 @@ IsUSBKeyboardBufferFull ( IN USB_KB_BUFFER *KeyboardBuffer ) { - return (BOOLEAN)(((KeyboardBuffer->bTail + 1) % (MAX_KEY_ALLOWED + 1)) == - KeyboardBuffer->bHead); + return (BOOLEAN)(((KeyboardBuffer->BufferTail + 1) % (MAX_KEY_ALLOWED + 1)) == KeyboardBuffer->BufferHead); } @@ -1732,10 +1759,8 @@ IsUSBKeyboardBufferFull ( @param Key Key code @param Down Special key - @retval EFI_SUCCESS Success - **/ -EFI_STATUS +VOID EFIAPI InsertKeyCode ( IN OUT USB_KB_BUFFER *KeyboardBuffer, @@ -1753,15 +1778,13 @@ InsertKeyCode ( RemoveKeyCode (KeyboardBuffer, &UsbKey); } - KeyboardBuffer->buffer[KeyboardBuffer->bTail].KeyCode = Key; - KeyboardBuffer->buffer[KeyboardBuffer->bTail].Down = Down; + KeyboardBuffer->Buffer[KeyboardBuffer->BufferTail].KeyCode = Key; + KeyboardBuffer->Buffer[KeyboardBuffer->BufferTail].Down = Down; // - // adjust the tail pointer of the FIFO keyboard buffer. + // Adjust the tail pointer of the FIFO keyboard buffer. // - KeyboardBuffer->bTail = (UINT8) ((KeyboardBuffer->bTail + 1) % (MAX_KEY_ALLOWED + 1)); - - return EFI_SUCCESS; + KeyboardBuffer->BufferTail = (UINT8) ((KeyboardBuffer->BufferTail + 1) % (MAX_KEY_ALLOWED + 1)); } @@ -1771,8 +1794,8 @@ InsertKeyCode ( @param KeyboardBuffer Points to the USB Keyboard Buffer. @param UsbKey Points to the buffer that contains a usb key code. - @retval EFI_SUCCESS Success - @retval EFI_DEVICE_ERROR Hardware Error + @retval EFI_SUCCESS Key code Successfully poped from keyboard buffer. + @retval EFI_DEVICE_ERROR Keyboard buffer is empty. **/ EFI_STATUS @@ -1786,13 +1809,13 @@ RemoveKeyCode ( return EFI_DEVICE_ERROR; } - UsbKey->KeyCode = KeyboardBuffer->buffer[KeyboardBuffer->bHead].KeyCode; - UsbKey->Down = KeyboardBuffer->buffer[KeyboardBuffer->bHead].Down; + UsbKey->KeyCode = KeyboardBuffer->Buffer[KeyboardBuffer->BufferHead].KeyCode; + UsbKey->Down = KeyboardBuffer->Buffer[KeyboardBuffer->BufferHead].Down; // - // adjust the head pointer of the FIFO keyboard buffer. + // Adjust the head pointer of the FIFO keyboard buffer. // - KeyboardBuffer->bHead = (UINT8) ((KeyboardBuffer->bHead + 1) % (MAX_KEY_ALLOWED + 1)); + KeyboardBuffer->BufferHead = (UINT8) ((KeyboardBuffer->BufferHead + 1) % (MAX_KEY_ALLOWED + 1)); return EFI_SUCCESS; } @@ -1803,10 +1826,8 @@ RemoveKeyCode ( @param UsbKeyboardDevice The USB_KB_DEV instance. - @retval EFI_SUCCESS Success - **/ -EFI_STATUS +VOID EFIAPI SetKeyLED ( IN USB_KB_DEV *UsbKeyboardDevice @@ -1825,7 +1846,7 @@ SetKeyLED ( ReportId = 0; // - // call Set Report Request to lighten the LED. + // Call Set_Report Request to lighten the LED. // UsbSetReportRequest ( UsbKeyboardDevice->UsbIo, @@ -1835,8 +1856,6 @@ SetKeyLED ( 1, (UINT8 *) &Led ); - - return EFI_SUCCESS; } @@ -1846,7 +1865,6 @@ SetKeyLED ( @param Event The Repeat Key event. @param Context Points to the USB_KB_DEV instance. - **/ VOID EFIAPI @@ -1873,14 +1891,13 @@ USBKeyboardRepeatHandler ( ); // - // set repeate rate for repeat key generation. + // Set repeate rate for next repeat key generation. // gBS->SetTimer ( - UsbKeyboardDevice->RepeatTimer, - TimerRelative, - USBKBD_REPEAT_RATE - ); - + UsbKeyboardDevice->RepeatTimer, + TimerRelative, + USBKBD_REPEAT_RATE + ); } } @@ -1891,7 +1908,6 @@ USBKeyboardRepeatHandler ( @param Event The Delayed Recovery event. @param Context Points to the USB_KB_DEV instance. - **/ VOID EFIAPI @@ -1911,13 +1927,16 @@ USBKeyboardRecoveryHandler ( PacketSize = (UINT8) (UsbKeyboardDevice->IntEndpointDescriptor.MaxPacketSize); + // + // Re-submit Asynchronous Interrupt Transfer for recovery. + // UsbIo->UsbAsyncInterruptTransfer ( - UsbIo, - UsbKeyboardDevice->IntEndpointDescriptor.EndpointAddress, - TRUE, - UsbKeyboardDevice->IntEndpointDescriptor.Interval, - PacketSize, - KeyboardHandler, - UsbKeyboardDevice - ); + UsbIo, + UsbKeyboardDevice->IntEndpointDescriptor.EndpointAddress, + TRUE, + UsbKeyboardDevice->IntEndpointDescriptor.Interval, + PacketSize, + KeyboardHandler, + UsbKeyboardDevice + ); } diff --git a/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.h b/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.h index 22aaf21271..dbf637ff43 100644 --- a/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.h +++ b/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.h @@ -1,5 +1,4 @@ /** @file - Function prototype for USB Keyboard Driver. Copyright (c) 2004 - 2008, Intel Corporation @@ -143,7 +142,7 @@ USBParseKey ( **/ EFI_STATUS EFIAPI -USBKeyCodeToEFIScanCode ( +UsbKeyCodeToEfiInputKey ( IN USB_KB_DEV *UsbKeyboardDevice, IN UINT8 KeyChar, OUT EFI_INPUT_KEY *Key @@ -154,10 +153,8 @@ USBKeyCodeToEFIScanCode ( @param KeyboardBuffer Points to the USB Keyboard Buffer. - @retval EFI_SUCCESS Init key buffer successfully. - **/ -EFI_STATUS +VOID EFIAPI InitUSBKeyBuffer ( IN OUT USB_KB_BUFFER *KeyboardBuffer @@ -200,10 +197,8 @@ IsUSBKeyboardBufferFull ( @param Key Key code @param Down Special key - @retval EFI_SUCCESS Success - **/ -EFI_STATUS +VOID EFIAPI InsertKeyCode ( IN OUT USB_KB_BUFFER *KeyboardBuffer, @@ -248,10 +243,8 @@ USBKeyboardRepeatHandler ( @param UsbKeyboardDevice The USB_KB_DEV instance. - @retval EFI_SUCCESS Success - **/ -EFI_STATUS +VOID EFIAPI SetKeyLED ( IN USB_KB_DEV *UsbKeyboardDevice -- 2.39.2