[PATCH 2/2] MdeModulePkg/Usb/Keyboard.c: don't request protocol before setting


Patrick Rudolph
 

From: Matt DeVillier <matt.devillier@gmail.com>

No need to check the interface protocol then conditionally setting,
just set it to BOOT_PROTOCOL and check for error.

This is what Linux does for HID devices as some don't follow the USB spec.
One example is the Aspeed BMC HID keyboard device, which adds a massive
boot delay without this patch as it doesn't respond to 'GetProtocolRequest'.

Signed-off-by: Matt DeVillier <matt.devillier@gmail.com>
Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
---
MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c | 28 ++++++++++++--------
1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c b/MdeModulePkg/Bus/Us=
b/UsbKbDxe/KeyBoard.c
index 77e20b203f..5914174b4d 100644
--- a/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c
+++ b/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c
@@ -801,7 +801,6 @@ InitUSBKeyboard (
IN OUT USB_KB_DEV *UsbKeyboardDevice=0D
)=0D
{=0D
- UINT8 Protocol;=0D
EFI_STATUS Status;=0D
=0D
REPORT_STATUS_CODE_WITH_DEVICE_PATH (=0D
@@ -814,21 +813,28 @@ InitUSBKeyboard (
InitQueue (&UsbKeyboardDevice->EfiKeyQueue, sizeof (EFI_KEY_DATA));=0D
InitQueue (&UsbKeyboardDevice->EfiKeyQueueForNotify, sizeof (EFI_KEY_DAT=
A));=0D
=0D
- UsbGetProtocolRequest (=0D
- UsbKeyboardDevice->UsbIo,=0D
- UsbKeyboardDevice->InterfaceDescriptor.InterfaceNumber,=0D
- &Protocol=0D
- );=0D
//=0D
// Set boot protocol for the USB Keyboard.=0D
// This driver only supports boot protocol.=0D
//=0D
- if (Protocol !=3D BOOT_PROTOCOL) {=0D
- UsbSetProtocolRequest (=0D
- UsbKeyboardDevice->UsbIo,=0D
- UsbKeyboardDevice->InterfaceDescriptor.InterfaceNumber,=0D
- BOOT_PROTOCOL=0D
+ Status =3D UsbSetProtocolRequest (=0D
+ UsbKeyboardDevice->UsbIo,=0D
+ UsbKeyboardDevice->InterfaceDescriptor.InterfaceNumber,=0D
+ BOOT_PROTOCOL=0D
+ );=0D
+ if (EFI_ERROR (Status)) {=0D
+ //=0D
+ // If protocol could not be set here, it means=0D
+ // the keyboard interface has some errors and could=0D
+ // not be initialized=0D
+ //=0D
+ REPORT_STATUS_CODE_WITH_DEVICE_PATH (=0D
+ EFI_ERROR_CODE | EFI_ERROR_MINOR,=0D
+ (EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_INTERFACE_ERROR),=0D
+ UsbKeyboardDevice->DevicePath=0D
);=0D
+=0D
+ return EFI_DEVICE_ERROR;=0D
}=0D
=0D
UsbKeyboardDevice->CtrlOn =3D FALSE;=0D
--=20
2.26.2

Join devel@edk2.groups.io to automatically receive all group messages.