* [PATCH] MdeModulePkg/ConPlatform: Support short-form USB device path
@ 2018-04-25 5:44 Ruiyu Ni
2018-04-25 14:16 ` Laszlo Ersek
2018-04-26 7:04 ` Zeng, Star
0 siblings, 2 replies; 7+ messages in thread
From: Ruiyu Ni @ 2018-04-25 5:44 UTC (permalink / raw)
To: edk2-devel; +Cc: Hao A Wu, Michael D Kinney, Star Zeng
Today's implementation does an exact device path match to check
whether the device path of a console is in ConIn/ConOut/ErrOut.
But that doesn't work for the USB keyboard.
Because when a platform have multiple USB port, ConIn needs to
carry all device paths corresponding to each port.
Even worse, today's BDS core logic removes the device path from
ConIn/ConOut/ErrOut when the connection to that device path fails.
So if user switches the USB keyboard from one port to another across
boot, the USB keyboard doesn't work in the second boot.
ConPlatform driver solved this problem by adding the
IsHotPlugDevice() function. So that for USB keyboard, ConPlatform
doesn't care whether its device path is in ConIn or not.
But the rule is too loose, and now causes platform BDS cannot control
whether to enable USB keyboard as an active console.
The patch changes ConPlatform to support USB short-form device path
when checking whether the device path of a console is in
ConIn/ConOut/ErrOut.
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
---
.../Universal/Console/ConPlatformDxe/ConPlatform.c | 526 ++++++++++++++-------
.../Universal/Console/ConPlatformDxe/ConPlatform.h | 20 +-
2 files changed, 353 insertions(+), 193 deletions(-)
diff --git a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c
index 6b53e8ac74..a509d0e3a5 100644
--- a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c
+++ b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c
@@ -2,7 +2,7 @@
Console Platform DXE Driver, install Console Device Guids and update Console
Environment Variables.
-Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -270,58 +270,33 @@ ConPlatformTextInDriverBindingStart (
}
//
- // Check the device path, if it is a hot plug device,
- // do not put the device path into ConInDev, and install
- // gEfiConsoleInDeviceGuid to the device handle directly.
- // The policy is, make hot plug device plug in and play immediately.
+ // If it is not a hot-plug device, append the device path to the
+ // ConInDev environment variable
//
- if (IsHotPlugDevice (DevicePath)) {
+ ConPlatformUpdateDeviceVariable (
+ L"ConInDev",
+ DevicePath,
+ Append
+ );
+
+ //
+ // If the device path is an instance in the ConIn environment variable,
+ // then install EfiConsoleInDeviceGuid onto ControllerHandle
+ //
+ if (IsInConInVariable) {
gBS->InstallMultipleProtocolInterfaces (
&ControllerHandle,
&gEfiConsoleInDeviceGuid,
NULL,
NULL
);
- //
- // Append the device path to ConInDev only if it is in ConIn variable.
- //
- if (IsInConInVariable) {
- ConPlatformUpdateDeviceVariable (
- L"ConInDev",
- DevicePath,
- Append
- );
- }
} else {
- //
- // If it is not a hot-plug device, append the device path to the
- // ConInDev environment variable
- //
- ConPlatformUpdateDeviceVariable (
- L"ConInDev",
- DevicePath,
- Append
- );
-
- //
- // If the device path is an instance in the ConIn environment variable,
- // then install EfiConsoleInDeviceGuid onto ControllerHandle
- //
- if (IsInConInVariable) {
- gBS->InstallMultipleProtocolInterfaces (
- &ControllerHandle,
- &gEfiConsoleInDeviceGuid,
- NULL,
- NULL
- );
- } else {
- gBS->CloseProtocol (
- ControllerHandle,
- &gEfiSimpleTextInProtocolGuid,
- This->DriverBindingHandle,
- ControllerHandle
- );
- }
+ gBS->CloseProtocol (
+ ControllerHandle,
+ &gEfiSimpleTextInProtocolGuid,
+ This->DriverBindingHandle,
+ ControllerHandle
+ );
}
return EFI_SUCCESS;
@@ -416,95 +391,60 @@ ConPlatformTextOutDriverBindingStart (
}
//
- // Check the device path, if it is a hot plug device,
- // do not put the device path into ConOutDev and ErrOutDev,
- // and install gEfiConsoleOutDeviceGuid to the device handle directly.
- // The policy is, make hot plug device plug in and play immediately.
+ // If it is not a hot-plug device, append the device path to
+ // the ConOutDev and ErrOutDev environment variable.
+ // For GOP device path, append the sibling device path as well.
+ //
+ if (!ConPlatformUpdateGopCandidate (DevicePath)) {
+ ConPlatformUpdateDeviceVariable (
+ L"ConOutDev",
+ DevicePath,
+ Append
+ );
+ //
+ // Then append the device path to the ErrOutDev environment variable
+ //
+ ConPlatformUpdateDeviceVariable (
+ L"ErrOutDev",
+ DevicePath,
+ Append
+ );
+ }
+
+ //
+ // If the device path is an instance in the ConOut environment variable,
+ // then install EfiConsoleOutDeviceGuid onto ControllerHandle
+ //
+ if (IsInConOutVariable) {
+ NeedClose = FALSE;
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ &ControllerHandle,
+ &gEfiConsoleOutDeviceGuid,
+ NULL,
+ NULL
+ );
+ }
+ //
+ // If the device path is an instance in the ErrOut environment variable,
+ // then install EfiStandardErrorDeviceGuid onto ControllerHandle
//
- if (IsHotPlugDevice (DevicePath)) {
+ if (IsInErrOutVariable) {
+ NeedClose = FALSE;
gBS->InstallMultipleProtocolInterfaces (
&ControllerHandle,
- &gEfiConsoleOutDeviceGuid,
+ &gEfiStandardErrorDeviceGuid,
NULL,
NULL
);
- //
- // Append the device path to ConOutDev only if it is in ConOut variable.
- //
- if (IsInConOutVariable) {
- ConPlatformUpdateDeviceVariable (
- L"ConOutDev",
- DevicePath,
- Append
- );
- }
- //
- // Append the device path to ErrOutDev only if it is in ErrOut variable.
- //
- if (IsInErrOutVariable) {
- ConPlatformUpdateDeviceVariable (
- L"ErrOutDev",
- DevicePath,
- Append
- );
- }
- } else {
- //
- // If it is not a hot-plug device, append the device path to
- // the ConOutDev and ErrOutDev environment variable.
- // For GOP device path, append the sibling device path as well.
- //
- if (!ConPlatformUpdateGopCandidate (DevicePath)) {
- ConPlatformUpdateDeviceVariable (
- L"ConOutDev",
- DevicePath,
- Append
- );
- //
- // Then append the device path to the ErrOutDev environment variable
- //
- ConPlatformUpdateDeviceVariable (
- L"ErrOutDev",
- DevicePath,
- Append
- );
- }
-
- //
- // If the device path is an instance in the ConOut environment variable,
- // then install EfiConsoleOutDeviceGuid onto ControllerHandle
- //
- if (IsInConOutVariable) {
- NeedClose = FALSE;
- Status = gBS->InstallMultipleProtocolInterfaces (
- &ControllerHandle,
- &gEfiConsoleOutDeviceGuid,
- NULL,
- NULL
- );
- }
- //
- // If the device path is an instance in the ErrOut environment variable,
- // then install EfiStandardErrorDeviceGuid onto ControllerHandle
- //
- if (IsInErrOutVariable) {
- NeedClose = FALSE;
- gBS->InstallMultipleProtocolInterfaces (
- &ControllerHandle,
- &gEfiStandardErrorDeviceGuid,
- NULL,
- NULL
- );
- }
+ }
- if (NeedClose) {
- gBS->CloseProtocol (
- ControllerHandle,
- &gEfiSimpleTextOutProtocolGuid,
- This->DriverBindingHandle,
- ControllerHandle
- );
- }
+ if (NeedClose) {
+ gBS->CloseProtocol (
+ ControllerHandle,
+ &gEfiSimpleTextOutProtocolGuid,
+ This->DriverBindingHandle,
+ ControllerHandle
+ );
}
return EFI_SUCCESS;
@@ -822,6 +762,288 @@ IsGopSibling (
return (BOOLEAN) (CompareMem (Left, Right, (UINTN) NodeLeft - (UINTN) Left) == 0);
}
+/**
+ Check whether a USB device match the specified USB Class device path. This
+ function follows "Load Option Processing" behavior in UEFI specification.
+
+ @param UsbIo USB I/O protocol associated with the USB device.
+ @param UsbClass The USB Class device path to match.
+
+ @retval TRUE The USB device match the USB Class device path.
+ @retval FALSE The USB device does not match the USB Class device path.
+
+**/
+BOOLEAN
+MatchUsbClass (
+ IN EFI_USB_IO_PROTOCOL *UsbIo,
+ IN USB_CLASS_DEVICE_PATH *UsbClass
+ )
+{
+ EFI_STATUS Status;
+ EFI_USB_DEVICE_DESCRIPTOR DevDesc;
+ EFI_USB_INTERFACE_DESCRIPTOR IfDesc;
+ UINT8 DeviceClass;
+ UINT8 DeviceSubClass;
+ UINT8 DeviceProtocol;
+
+ if ((DevicePathType (UsbClass) != MESSAGING_DEVICE_PATH) ||
+ (DevicePathSubType (UsbClass) != MSG_USB_CLASS_DP)){
+ return FALSE;
+ }
+
+ //
+ // Check Vendor Id and Product Id.
+ //
+ Status = UsbIo->UsbGetDeviceDescriptor (UsbIo, &DevDesc);
+ if (EFI_ERROR (Status)) {
+ return FALSE;
+ }
+
+ if ((UsbClass->VendorId != 0xffff) &&
+ (UsbClass->VendorId != DevDesc.IdVendor)) {
+ return FALSE;
+ }
+
+ if ((UsbClass->ProductId != 0xffff) &&
+ (UsbClass->ProductId != DevDesc.IdProduct)) {
+ return FALSE;
+ }
+
+ DeviceClass = DevDesc.DeviceClass;
+ DeviceSubClass = DevDesc.DeviceSubClass;
+ DeviceProtocol = DevDesc.DeviceProtocol;
+ if (DeviceClass == 0) {
+ //
+ // If Class in Device Descriptor is set to 0, use the Class, SubClass and
+ // Protocol in Interface Descriptor instead.
+ //
+ Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &IfDesc);
+ if (EFI_ERROR (Status)) {
+ return FALSE;
+ }
+
+ DeviceClass = IfDesc.InterfaceClass;
+ DeviceSubClass = IfDesc.InterfaceSubClass;
+ DeviceProtocol = IfDesc.InterfaceProtocol;
+ }
+
+ //
+ // Check Class, SubClass and Protocol.
+ //
+ if ((UsbClass->DeviceClass != 0xff) &&
+ (UsbClass->DeviceClass != DeviceClass)) {
+ return FALSE;
+ }
+
+ if ((UsbClass->DeviceSubClass != 0xff) &&
+ (UsbClass->DeviceSubClass != DeviceSubClass)) {
+ return FALSE;
+ }
+
+ if ((UsbClass->DeviceProtocol != 0xff) &&
+ (UsbClass->DeviceProtocol != DeviceProtocol)) {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/**
+ Check whether a USB device match the specified USB WWID device path. This
+ function follows "Load Option Processing" behavior in UEFI specification.
+
+ @param UsbIo USB I/O protocol associated with the USB device.
+ @param UsbWwid The USB WWID device path to match.
+
+ @retval TRUE The USB device match the USB WWID device path.
+ @retval FALSE The USB device does not match the USB WWID device path.
+
+**/
+BOOLEAN
+MatchUsbWwid (
+ IN EFI_USB_IO_PROTOCOL *UsbIo,
+ IN USB_WWID_DEVICE_PATH *UsbWwid
+ )
+{
+ EFI_STATUS Status;
+ EFI_USB_DEVICE_DESCRIPTOR DevDesc;
+ EFI_USB_INTERFACE_DESCRIPTOR IfDesc;
+ UINT16 *LangIdTable;
+ UINT16 TableSize;
+ UINT16 Index;
+ CHAR16 *CompareStr;
+ UINTN CompareLen;
+ CHAR16 *SerialNumberStr;
+ UINTN Length;
+
+ if ((DevicePathType (UsbWwid) != MESSAGING_DEVICE_PATH) ||
+ (DevicePathSubType (UsbWwid) != MSG_USB_WWID_DP)) {
+ return FALSE;
+ }
+
+ //
+ // Check Vendor Id and Product Id.
+ //
+ Status = UsbIo->UsbGetDeviceDescriptor (UsbIo, &DevDesc);
+ if (EFI_ERROR (Status)) {
+ return FALSE;
+ }
+ if ((DevDesc.IdVendor != UsbWwid->VendorId) ||
+ (DevDesc.IdProduct != UsbWwid->ProductId)) {
+ return FALSE;
+ }
+
+ //
+ // Check Interface Number.
+ //
+ Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &IfDesc);
+ if (EFI_ERROR (Status)) {
+ return FALSE;
+ }
+ if (IfDesc.InterfaceNumber != UsbWwid->InterfaceNumber) {
+ return FALSE;
+ }
+
+ //
+ // Check Serial Number.
+ //
+ if (DevDesc.StrSerialNumber == 0) {
+ return FALSE;
+ }
+
+ //
+ // Get all supported languages.
+ //
+ TableSize = 0;
+ LangIdTable = NULL;
+ Status = UsbIo->UsbGetSupportedLanguages (UsbIo, &LangIdTable, &TableSize);
+ if (EFI_ERROR (Status) || (TableSize == 0) || (LangIdTable == NULL)) {
+ return FALSE;
+ }
+
+ //
+ // Serial number in USB WWID device path is the last 64-or-less UTF-16 characters.
+ //
+ CompareStr = (CHAR16 *) (UINTN) (UsbWwid + 1);
+ CompareLen = (DevicePathNodeLength (UsbWwid) - sizeof (USB_WWID_DEVICE_PATH)) / sizeof (CHAR16);
+ if (CompareStr[CompareLen - 1] == L'\0') {
+ CompareLen--;
+ }
+
+ //
+ // Compare serial number in each supported language.
+ //
+ for (Index = 0; Index < TableSize / sizeof (UINT16); Index++) {
+ SerialNumberStr = NULL;
+ Status = UsbIo->UsbGetStringDescriptor (
+ UsbIo,
+ LangIdTable[Index],
+ DevDesc.StrSerialNumber,
+ &SerialNumberStr
+ );
+ if (EFI_ERROR (Status) || (SerialNumberStr == NULL)) {
+ continue;
+ }
+
+ Length = StrLen (SerialNumberStr);
+ if ((Length >= CompareLen) &&
+ (CompareMem (SerialNumberStr + Length - CompareLen, CompareStr, CompareLen * sizeof (CHAR16)) == 0)) {
+ FreePool (SerialNumberStr);
+ return TRUE;
+ }
+
+ FreePool (SerialNumberStr);
+ }
+
+ return FALSE;
+}
+
+/**
+ Compare whether a full console device path matches a USB shortform device path.
+
+ @param[in] FullPath Full console device path.
+ @param[in] ShortformPath Short-form device path. Short-form device node may in the beginning or in the middle.
+
+ @retval TRUE The full console device path matches the short-form device path.
+ @retval FALSE The full console device path doesn't match the short-form device path.
+**/
+BOOLEAN
+MatchUsbShortformDevicePath (
+ IN EFI_DEVICE_PATH_PROTOCOL *FullPath,
+ IN EFI_DEVICE_PATH_PROTOCOL *ShortformPath
+ )
+{
+ EFI_STATUS Status;
+ EFI_DEVICE_PATH_PROTOCOL *ShortformNode;
+ EFI_DEVICE_PATH_PROTOCOL *ShortformRemainingDevicePath;
+ UINTN ParentDevicePathSize;
+ EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath;
+ EFI_USB_IO_PROTOCOL *UsbIo;
+ EFI_HANDLE Handle;
+
+ for ( ShortformNode = ShortformPath
+ ; !IsDevicePathEnd (ShortformNode)
+ ; ShortformNode = NextDevicePathNode (ShortformNode)
+ ) {
+ if ((DevicePathType (ShortformNode) == MESSAGING_DEVICE_PATH) &&
+ ((DevicePathSubType (ShortformNode) == MSG_USB_CLASS_DP) ||
+ (DevicePathSubType (ShortformNode) == MSG_USB_WWID_DP))
+ ) {
+ break;
+ }
+ }
+
+ //
+ // Skip further compare when it's not a shortform device path.
+ //
+ if (IsDevicePathEnd (ShortformNode)) {
+ return FALSE;
+ }
+
+ //
+ // Match the parent device path below USB layer when the ShortformPath doesn't start with short-form node.
+ //
+ ParentDevicePathSize = (UINTN) ShortformNode - (UINTN) ShortformPath;
+ ShortformRemainingDevicePath = NextDevicePathNode (ShortformNode);
+
+ RemainingDevicePath = FullPath;
+ Status = gBS->LocateDevicePath (&gEfiUsbIoProtocolGuid, &RemainingDevicePath, &Handle);
+ if (EFI_ERROR (Status)) {
+ return FALSE;
+ }
+
+ if (ParentDevicePathSize != 0) {
+ //
+ // Skip comparing the parent device path when ShortformPath begins with short-form node.
+ //
+ if ((ParentDevicePathSize != (UINTN) RemainingDevicePath - (UINTN) FullPath) ||
+ (CompareMem (FullPath, ShortformPath, ParentDevicePathSize) != 0)) {
+ return FALSE;
+ }
+ }
+
+ //
+ // Match the remaining device path above USB layer.
+ // For USB keyboard, the remaining device path above USB layer is END node.
+ //
+ if (CompareMem (RemainingDevicePath, ShortformRemainingDevicePath, GetDevicePathSize (RemainingDevicePath)) != 0) {
+ return FALSE;
+ }
+
+ //
+ // Match the USB layer.
+ //
+ Status = gBS->HandleProtocol(
+ Handle,
+ &gEfiUsbIoProtocolGuid,
+ (VOID **) &UsbIo
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ return MatchUsbClass (UsbIo, (USB_CLASS_DEVICE_PATH *)ShortformNode) ||
+ MatchUsbWwid (UsbIo, (USB_WWID_DEVICE_PATH *)ShortformNode);
+}
+
/**
Function compares a device path data structure to that of all the nodes of a
second device path instance.
@@ -881,7 +1103,8 @@ ConPlatformMatchDevicePaths (
// Search for the match of 'Single' in 'Multi'
//
while (DevicePathInst != NULL) {
- if ((CompareMem (Single, DevicePathInst, Size) == 0) || IsGopSibling (Single, DevicePathInst)) {
+ if ((CompareMem (Single, DevicePathInst, Size) == 0) ||
+ IsGopSibling (Single, DevicePathInst) || MatchUsbShortformDevicePath (Single, DevicePathInst)) {
if (!Delete) {
//
// If Delete is FALSE, return EFI_SUCCESS if Single is found in Multi.
@@ -1029,53 +1252,6 @@ ConPlatformUpdateDeviceVariable (
return Status;
}
-/**
- Check if the device supports hot-plug through its device path.
-
- This function could be updated to check more types of Hot Plug devices.
- Currently, it checks USB and PCCard device.
-
- @param DevicePath Pointer to device's device path.
-
- @retval TRUE The devcie is a hot-plug device
- @retval FALSE The devcie is not a hot-plug device.
-
-**/
-BOOLEAN
-IsHotPlugDevice (
- IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
- )
-{
- EFI_DEVICE_PATH_PROTOCOL *CheckDevicePath;
-
- CheckDevicePath = DevicePath;
- while (!IsDevicePathEnd (CheckDevicePath)) {
- //
- // Check device whether is hot plug device or not throught Device Path
- //
- if ((DevicePathType (CheckDevicePath) == MESSAGING_DEVICE_PATH) &&
- (DevicePathSubType (CheckDevicePath) == MSG_USB_DP ||
- DevicePathSubType (CheckDevicePath) == MSG_USB_CLASS_DP ||
- DevicePathSubType (CheckDevicePath) == MSG_USB_WWID_DP)) {
- //
- // If Device is USB device
- //
- return TRUE;
- }
- if ((DevicePathType (CheckDevicePath) == HARDWARE_DEVICE_PATH) &&
- (DevicePathSubType (CheckDevicePath) == HW_PCCARD_DP)) {
- //
- // If Device is PCCard
- //
- return TRUE;
- }
-
- CheckDevicePath = NextDevicePathNode (CheckDevicePath);
- }
-
- return FALSE;
-}
-
/**
Update ConOutDev and ErrOutDev variables to add the device path of
GOP controller itself and the sibling controllers.
diff --git a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.h b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.h
index 6d853c1360..28f882afeb 100644
--- a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.h
+++ b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.h
@@ -1,7 +1,7 @@
/** @file
Header file for Console Platfrom DXE Driver.
-Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -21,6 +21,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Protocol/DevicePath.h>
#include <Protocol/SimpleTextIn.h>
#include <Protocol/PciIo.h>
+#include <Protocol/UsbIo.h>
#include <Protocol/GraphicsOutput.h>
#include <Guid/GlobalVariable.h>
@@ -294,23 +295,6 @@ ConPlatformUpdateDeviceVariable (
IN CONPLATFORM_VAR_OPERATION Operation
);
-/**
- Check if the device supports hot-plug through its device path.
-
- This function could be updated to check more types of Hot Plug devices.
- Currently, it checks USB and PCCard device.
-
- @param DevicePath Pointer to device's device path.
-
- @retval TRUE The devcie is a hot-plug device
- @retval FALSE The devcie is not a hot-plug device.
-
-**/
-BOOLEAN
-IsHotPlugDevice (
- IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
- );
-
//
// EFI Component Name Functions
//
--
2.16.1.windows.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] MdeModulePkg/ConPlatform: Support short-form USB device path
2018-04-25 5:44 [PATCH] MdeModulePkg/ConPlatform: Support short-form USB device path Ruiyu Ni
@ 2018-04-25 14:16 ` Laszlo Ersek
2018-04-26 6:52 ` Ni, Ruiyu
2018-04-26 7:04 ` Zeng, Star
1 sibling, 1 reply; 7+ messages in thread
From: Laszlo Ersek @ 2018-04-25 14:16 UTC (permalink / raw)
To: Ruiyu Ni; +Cc: edk2-devel, Hao A Wu, Michael D Kinney, Star Zeng
Hello Ray,
On 04/25/18 07:44, Ruiyu Ni wrote:
> Today's implementation does an exact device path match to check
> whether the device path of a console is in ConIn/ConOut/ErrOut.
> But that doesn't work for the USB keyboard.
> Because when a platform have multiple USB port, ConIn needs to
> carry all device paths corresponding to each port.
> Even worse, today's BDS core logic removes the device path from
> ConIn/ConOut/ErrOut when the connection to that device path fails.
> So if user switches the USB keyboard from one port to another across
> boot, the USB keyboard doesn't work in the second boot.
>
> ConPlatform driver solved this problem by adding the
> IsHotPlugDevice() function. So that for USB keyboard, ConPlatform
> doesn't care whether its device path is in ConIn or not.
> But the rule is too loose, and now causes platform BDS cannot control
> whether to enable USB keyboard as an active console.
>
> The patch changes ConPlatform to support USB short-form device path
> when checking whether the device path of a console is in
> ConIn/ConOut/ErrOut.
>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
> Cc: Hao A Wu <hao.a.wu@intel.com>
> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> Cc: Star Zeng <star.zeng@intel.com>
> ---
> .../Universal/Console/ConPlatformDxe/ConPlatform.c | 526 ++++++++++++++-------
> .../Universal/Console/ConPlatformDxe/ConPlatform.h | 20 +-
> 2 files changed, 353 insertions(+), 193 deletions(-)
just a quick question: in OvmfPkg and ArmVirtPkg (more precisely:
ArmVirtQemu*), we add a "wild card" USB keyboard to ConIn:
> STATIC PLATFORM_USB_KEYBOARD mUsbKeyboard = {
> //
> // USB_CLASS_DEVICE_PATH Keyboard
> //
> {
> {
> MESSAGING_DEVICE_PATH, MSG_USB_CLASS_DP,
> DP_NODE_LEN (USB_CLASS_DEVICE_PATH)
> },
> 0xFFFF, // VendorId: any
> 0xFFFF, // ProductId: any
> 3, // DeviceClass: HID
> 1, // DeviceSubClass: boot
> 1 // DeviceProtocol: keyboard
> },
>
> //
> // EFI_DEVICE_PATH_PROTOCOL End
> //
> {
> END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE,
> DP_NODE_LEN (EFI_DEVICE_PATH_PROTOCOL)
> }
> };
>
> [...]
>
> //
> // Add the hardcoded short-form USB keyboard device path to ConIn.
> //
> EfiBootManagerUpdateConsoleVariable (ConIn,
> (EFI_DEVICE_PATH_PROTOCOL *)&mUsbKeyboard, NULL);
The idea is to connect any USB keyboard(s) that the virtual machine
might have.
This patch for ConPlatformDxe will keep that working, right?
Thanks!
Laszlo
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] MdeModulePkg/ConPlatform: Support short-form USB device path
2018-04-25 14:16 ` Laszlo Ersek
@ 2018-04-26 6:52 ` Ni, Ruiyu
0 siblings, 0 replies; 7+ messages in thread
From: Ni, Ruiyu @ 2018-04-26 6:52 UTC (permalink / raw)
To: Laszlo Ersek
Cc: Wu, Hao A, Kinney, Michael D, edk2-devel@lists.01.org, Zeng, Star
> -----Original Message-----
> From: edk2-devel <edk2-devel-bounces@lists.01.org> On Behalf Of Laszlo
> Ersek
> Sent: Wednesday, April 25, 2018 10:16 PM
> To: Ni, Ruiyu <ruiyu.ni@intel.com>
> Cc: Wu, Hao A <hao.a.wu@intel.com>; Kinney, Michael D
> <michael.d.kinney@intel.com>; edk2-devel@lists.01.org; Zeng, Star
> <star.zeng@intel.com>
> Subject: Re: [edk2] [PATCH] MdeModulePkg/ConPlatform: Support short-
> form USB device path
>
> Hello Ray,
>
> On 04/25/18 07:44, Ruiyu Ni wrote:
> > Today's implementation does an exact device path match to check
> > whether the device path of a console is in ConIn/ConOut/ErrOut.
> > But that doesn't work for the USB keyboard.
> > Because when a platform have multiple USB port, ConIn needs to carry
> > all device paths corresponding to each port.
> > Even worse, today's BDS core logic removes the device path from
> > ConIn/ConOut/ErrOut when the connection to that device path fails.
> > So if user switches the USB keyboard from one port to another across
> > boot, the USB keyboard doesn't work in the second boot.
> >
> > ConPlatform driver solved this problem by adding the
> > IsHotPlugDevice() function. So that for USB keyboard, ConPlatform
> > doesn't care whether its device path is in ConIn or not.
> > But the rule is too loose, and now causes platform BDS cannot control
> > whether to enable USB keyboard as an active console.
> >
> > The patch changes ConPlatform to support USB short-form device path
> > when checking whether the device path of a console is in
> > ConIn/ConOut/ErrOut.
> >
> > Contributed-under: TianoCore Contribution Agreement 1.1
> > Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
> > Cc: Hao A Wu <hao.a.wu@intel.com>
> > Cc: Michael D Kinney <michael.d.kinney@intel.com>
> > Cc: Star Zeng <star.zeng@intel.com>
> > ---
> > .../Universal/Console/ConPlatformDxe/ConPlatform.c | 526
> > ++++++++++++++-------
> > .../Universal/Console/ConPlatformDxe/ConPlatform.h | 20 +-
> > 2 files changed, 353 insertions(+), 193 deletions(-)
>
> just a quick question: in OvmfPkg and ArmVirtPkg (more precisely:
> ArmVirtQemu*), we add a "wild card" USB keyboard to ConIn:
>
> > STATIC PLATFORM_USB_KEYBOARD mUsbKeyboard = {
> > //
> > // USB_CLASS_DEVICE_PATH Keyboard
> > //
> > {
> > {
> > MESSAGING_DEVICE_PATH, MSG_USB_CLASS_DP,
> > DP_NODE_LEN (USB_CLASS_DEVICE_PATH)
> > },
> > 0xFFFF, // VendorId: any
> > 0xFFFF, // ProductId: any
> > 3, // DeviceClass: HID
> > 1, // DeviceSubClass: boot
> > 1 // DeviceProtocol: keyboard
> > },
> >
> > //
> > // EFI_DEVICE_PATH_PROTOCOL End
> > //
> > {
> > END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE,
> > DP_NODE_LEN (EFI_DEVICE_PATH_PROTOCOL)
> > }
> > };
> >
> > [...]
> >
> > //
> > // Add the hardcoded short-form USB keyboard device path to ConIn.
> > //
> > EfiBootManagerUpdateConsoleVariable (ConIn,
> > (EFI_DEVICE_PATH_PROTOCOL *)&mUsbKeyboard, NULL);
>
> The idea is to connect any USB keyboard(s) that the virtual machine might
> have.
>
> This patch for ConPlatformDxe will keep that working, right?
Right!
>
> Thanks!
> Laszlo
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] MdeModulePkg/ConPlatform: Support short-form USB device path
2018-04-25 5:44 [PATCH] MdeModulePkg/ConPlatform: Support short-form USB device path Ruiyu Ni
2018-04-25 14:16 ` Laszlo Ersek
@ 2018-04-26 7:04 ` Zeng, Star
2018-05-02 7:50 ` Ni, Ruiyu
1 sibling, 1 reply; 7+ messages in thread
From: Zeng, Star @ 2018-04-26 7:04 UTC (permalink / raw)
To: Ni, Ruiyu, edk2-devel@lists.01.org
Cc: Wu, Hao A, Kinney, Michael D, Zeng, Star
Ray,
Some minor comments below.
1. How MSG_USB_DP and HW_PCCARD_DP be handled? We see they are checked in original IsHotPlugDevice()?
2. gEfiUsbIoProtocolGuid needs be stated in ConPlatformDxe.inf?
3. The comment " If it is not a hot-plug device, append the device path to " in ConPlatformTextInDriverBindingStart()/ConPlatformTextOutDriverBindingStart() needs be updated accordingly since IsHotPlugDevice() will be removed?
Thanks,
Star
-----Original Message-----
From: Ni, Ruiyu
Sent: Wednesday, April 25, 2018 1:44 PM
To: edk2-devel@lists.01.org
Cc: Wu, Hao A <hao.a.wu@intel.com>; Kinney, Michael D <michael.d.kinney@intel.com>; Zeng, Star <star.zeng@intel.com>
Subject: [PATCH] MdeModulePkg/ConPlatform: Support short-form USB device path
Today's implementation does an exact device path match to check
whether the device path of a console is in ConIn/ConOut/ErrOut.
But that doesn't work for the USB keyboard.
Because when a platform have multiple USB port, ConIn needs to
carry all device paths corresponding to each port.
Even worse, today's BDS core logic removes the device path from
ConIn/ConOut/ErrOut when the connection to that device path fails.
So if user switches the USB keyboard from one port to another across
boot, the USB keyboard doesn't work in the second boot.
ConPlatform driver solved this problem by adding the
IsHotPlugDevice() function. So that for USB keyboard, ConPlatform
doesn't care whether its device path is in ConIn or not.
But the rule is too loose, and now causes platform BDS cannot control
whether to enable USB keyboard as an active console.
The patch changes ConPlatform to support USB short-form device path
when checking whether the device path of a console is in
ConIn/ConOut/ErrOut.
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
---
.../Universal/Console/ConPlatformDxe/ConPlatform.c | 526 ++++++++++++++-------
.../Universal/Console/ConPlatformDxe/ConPlatform.h | 20 +-
2 files changed, 353 insertions(+), 193 deletions(-)
diff --git a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c
index 6b53e8ac74..a509d0e3a5 100644
--- a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c
+++ b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c
@@ -2,7 +2,7 @@
Console Platform DXE Driver, install Console Device Guids and update Console
Environment Variables.
-Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -270,58 +270,33 @@ ConPlatformTextInDriverBindingStart (
}
//
- // Check the device path, if it is a hot plug device,
- // do not put the device path into ConInDev, and install
- // gEfiConsoleInDeviceGuid to the device handle directly.
- // The policy is, make hot plug device plug in and play immediately.
+ // If it is not a hot-plug device, append the device path to the
+ // ConInDev environment variable
//
- if (IsHotPlugDevice (DevicePath)) {
+ ConPlatformUpdateDeviceVariable (
+ L"ConInDev",
+ DevicePath,
+ Append
+ );
+
+ //
+ // If the device path is an instance in the ConIn environment variable,
+ // then install EfiConsoleInDeviceGuid onto ControllerHandle
+ //
+ if (IsInConInVariable) {
gBS->InstallMultipleProtocolInterfaces (
&ControllerHandle,
&gEfiConsoleInDeviceGuid,
NULL,
NULL
);
- //
- // Append the device path to ConInDev only if it is in ConIn variable.
- //
- if (IsInConInVariable) {
- ConPlatformUpdateDeviceVariable (
- L"ConInDev",
- DevicePath,
- Append
- );
- }
} else {
- //
- // If it is not a hot-plug device, append the device path to the
- // ConInDev environment variable
- //
- ConPlatformUpdateDeviceVariable (
- L"ConInDev",
- DevicePath,
- Append
- );
-
- //
- // If the device path is an instance in the ConIn environment variable,
- // then install EfiConsoleInDeviceGuid onto ControllerHandle
- //
- if (IsInConInVariable) {
- gBS->InstallMultipleProtocolInterfaces (
- &ControllerHandle,
- &gEfiConsoleInDeviceGuid,
- NULL,
- NULL
- );
- } else {
- gBS->CloseProtocol (
- ControllerHandle,
- &gEfiSimpleTextInProtocolGuid,
- This->DriverBindingHandle,
- ControllerHandle
- );
- }
+ gBS->CloseProtocol (
+ ControllerHandle,
+ &gEfiSimpleTextInProtocolGuid,
+ This->DriverBindingHandle,
+ ControllerHandle
+ );
}
return EFI_SUCCESS;
@@ -416,95 +391,60 @@ ConPlatformTextOutDriverBindingStart (
}
//
- // Check the device path, if it is a hot plug device,
- // do not put the device path into ConOutDev and ErrOutDev,
- // and install gEfiConsoleOutDeviceGuid to the device handle directly.
- // The policy is, make hot plug device plug in and play immediately.
+ // If it is not a hot-plug device, append the device path to
+ // the ConOutDev and ErrOutDev environment variable.
+ // For GOP device path, append the sibling device path as well.
+ //
+ if (!ConPlatformUpdateGopCandidate (DevicePath)) {
+ ConPlatformUpdateDeviceVariable (
+ L"ConOutDev",
+ DevicePath,
+ Append
+ );
+ //
+ // Then append the device path to the ErrOutDev environment variable
+ //
+ ConPlatformUpdateDeviceVariable (
+ L"ErrOutDev",
+ DevicePath,
+ Append
+ );
+ }
+
+ //
+ // If the device path is an instance in the ConOut environment variable,
+ // then install EfiConsoleOutDeviceGuid onto ControllerHandle
+ //
+ if (IsInConOutVariable) {
+ NeedClose = FALSE;
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ &ControllerHandle,
+ &gEfiConsoleOutDeviceGuid,
+ NULL,
+ NULL
+ );
+ }
+ //
+ // If the device path is an instance in the ErrOut environment variable,
+ // then install EfiStandardErrorDeviceGuid onto ControllerHandle
//
- if (IsHotPlugDevice (DevicePath)) {
+ if (IsInErrOutVariable) {
+ NeedClose = FALSE;
gBS->InstallMultipleProtocolInterfaces (
&ControllerHandle,
- &gEfiConsoleOutDeviceGuid,
+ &gEfiStandardErrorDeviceGuid,
NULL,
NULL
);
- //
- // Append the device path to ConOutDev only if it is in ConOut variable.
- //
- if (IsInConOutVariable) {
- ConPlatformUpdateDeviceVariable (
- L"ConOutDev",
- DevicePath,
- Append
- );
- }
- //
- // Append the device path to ErrOutDev only if it is in ErrOut variable.
- //
- if (IsInErrOutVariable) {
- ConPlatformUpdateDeviceVariable (
- L"ErrOutDev",
- DevicePath,
- Append
- );
- }
- } else {
- //
- // If it is not a hot-plug device, append the device path to
- // the ConOutDev and ErrOutDev environment variable.
- // For GOP device path, append the sibling device path as well.
- //
- if (!ConPlatformUpdateGopCandidate (DevicePath)) {
- ConPlatformUpdateDeviceVariable (
- L"ConOutDev",
- DevicePath,
- Append
- );
- //
- // Then append the device path to the ErrOutDev environment variable
- //
- ConPlatformUpdateDeviceVariable (
- L"ErrOutDev",
- DevicePath,
- Append
- );
- }
-
- //
- // If the device path is an instance in the ConOut environment variable,
- // then install EfiConsoleOutDeviceGuid onto ControllerHandle
- //
- if (IsInConOutVariable) {
- NeedClose = FALSE;
- Status = gBS->InstallMultipleProtocolInterfaces (
- &ControllerHandle,
- &gEfiConsoleOutDeviceGuid,
- NULL,
- NULL
- );
- }
- //
- // If the device path is an instance in the ErrOut environment variable,
- // then install EfiStandardErrorDeviceGuid onto ControllerHandle
- //
- if (IsInErrOutVariable) {
- NeedClose = FALSE;
- gBS->InstallMultipleProtocolInterfaces (
- &ControllerHandle,
- &gEfiStandardErrorDeviceGuid,
- NULL,
- NULL
- );
- }
+ }
- if (NeedClose) {
- gBS->CloseProtocol (
- ControllerHandle,
- &gEfiSimpleTextOutProtocolGuid,
- This->DriverBindingHandle,
- ControllerHandle
- );
- }
+ if (NeedClose) {
+ gBS->CloseProtocol (
+ ControllerHandle,
+ &gEfiSimpleTextOutProtocolGuid,
+ This->DriverBindingHandle,
+ ControllerHandle
+ );
}
return EFI_SUCCESS;
@@ -822,6 +762,288 @@ IsGopSibling (
return (BOOLEAN) (CompareMem (Left, Right, (UINTN) NodeLeft - (UINTN) Left) == 0);
}
+/**
+ Check whether a USB device match the specified USB Class device path. This
+ function follows "Load Option Processing" behavior in UEFI specification.
+
+ @param UsbIo USB I/O protocol associated with the USB device.
+ @param UsbClass The USB Class device path to match.
+
+ @retval TRUE The USB device match the USB Class device path.
+ @retval FALSE The USB device does not match the USB Class device path.
+
+**/
+BOOLEAN
+MatchUsbClass (
+ IN EFI_USB_IO_PROTOCOL *UsbIo,
+ IN USB_CLASS_DEVICE_PATH *UsbClass
+ )
+{
+ EFI_STATUS Status;
+ EFI_USB_DEVICE_DESCRIPTOR DevDesc;
+ EFI_USB_INTERFACE_DESCRIPTOR IfDesc;
+ UINT8 DeviceClass;
+ UINT8 DeviceSubClass;
+ UINT8 DeviceProtocol;
+
+ if ((DevicePathType (UsbClass) != MESSAGING_DEVICE_PATH) ||
+ (DevicePathSubType (UsbClass) != MSG_USB_CLASS_DP)){
+ return FALSE;
+ }
+
+ //
+ // Check Vendor Id and Product Id.
+ //
+ Status = UsbIo->UsbGetDeviceDescriptor (UsbIo, &DevDesc);
+ if (EFI_ERROR (Status)) {
+ return FALSE;
+ }
+
+ if ((UsbClass->VendorId != 0xffff) &&
+ (UsbClass->VendorId != DevDesc.IdVendor)) {
+ return FALSE;
+ }
+
+ if ((UsbClass->ProductId != 0xffff) &&
+ (UsbClass->ProductId != DevDesc.IdProduct)) {
+ return FALSE;
+ }
+
+ DeviceClass = DevDesc.DeviceClass;
+ DeviceSubClass = DevDesc.DeviceSubClass;
+ DeviceProtocol = DevDesc.DeviceProtocol;
+ if (DeviceClass == 0) {
+ //
+ // If Class in Device Descriptor is set to 0, use the Class, SubClass and
+ // Protocol in Interface Descriptor instead.
+ //
+ Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &IfDesc);
+ if (EFI_ERROR (Status)) {
+ return FALSE;
+ }
+
+ DeviceClass = IfDesc.InterfaceClass;
+ DeviceSubClass = IfDesc.InterfaceSubClass;
+ DeviceProtocol = IfDesc.InterfaceProtocol;
+ }
+
+ //
+ // Check Class, SubClass and Protocol.
+ //
+ if ((UsbClass->DeviceClass != 0xff) &&
+ (UsbClass->DeviceClass != DeviceClass)) {
+ return FALSE;
+ }
+
+ if ((UsbClass->DeviceSubClass != 0xff) &&
+ (UsbClass->DeviceSubClass != DeviceSubClass)) {
+ return FALSE;
+ }
+
+ if ((UsbClass->DeviceProtocol != 0xff) &&
+ (UsbClass->DeviceProtocol != DeviceProtocol)) {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/**
+ Check whether a USB device match the specified USB WWID device path. This
+ function follows "Load Option Processing" behavior in UEFI specification.
+
+ @param UsbIo USB I/O protocol associated with the USB device.
+ @param UsbWwid The USB WWID device path to match.
+
+ @retval TRUE The USB device match the USB WWID device path.
+ @retval FALSE The USB device does not match the USB WWID device path.
+
+**/
+BOOLEAN
+MatchUsbWwid (
+ IN EFI_USB_IO_PROTOCOL *UsbIo,
+ IN USB_WWID_DEVICE_PATH *UsbWwid
+ )
+{
+ EFI_STATUS Status;
+ EFI_USB_DEVICE_DESCRIPTOR DevDesc;
+ EFI_USB_INTERFACE_DESCRIPTOR IfDesc;
+ UINT16 *LangIdTable;
+ UINT16 TableSize;
+ UINT16 Index;
+ CHAR16 *CompareStr;
+ UINTN CompareLen;
+ CHAR16 *SerialNumberStr;
+ UINTN Length;
+
+ if ((DevicePathType (UsbWwid) != MESSAGING_DEVICE_PATH) ||
+ (DevicePathSubType (UsbWwid) != MSG_USB_WWID_DP)) {
+ return FALSE;
+ }
+
+ //
+ // Check Vendor Id and Product Id.
+ //
+ Status = UsbIo->UsbGetDeviceDescriptor (UsbIo, &DevDesc);
+ if (EFI_ERROR (Status)) {
+ return FALSE;
+ }
+ if ((DevDesc.IdVendor != UsbWwid->VendorId) ||
+ (DevDesc.IdProduct != UsbWwid->ProductId)) {
+ return FALSE;
+ }
+
+ //
+ // Check Interface Number.
+ //
+ Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &IfDesc);
+ if (EFI_ERROR (Status)) {
+ return FALSE;
+ }
+ if (IfDesc.InterfaceNumber != UsbWwid->InterfaceNumber) {
+ return FALSE;
+ }
+
+ //
+ // Check Serial Number.
+ //
+ if (DevDesc.StrSerialNumber == 0) {
+ return FALSE;
+ }
+
+ //
+ // Get all supported languages.
+ //
+ TableSize = 0;
+ LangIdTable = NULL;
+ Status = UsbIo->UsbGetSupportedLanguages (UsbIo, &LangIdTable, &TableSize);
+ if (EFI_ERROR (Status) || (TableSize == 0) || (LangIdTable == NULL)) {
+ return FALSE;
+ }
+
+ //
+ // Serial number in USB WWID device path is the last 64-or-less UTF-16 characters.
+ //
+ CompareStr = (CHAR16 *) (UINTN) (UsbWwid + 1);
+ CompareLen = (DevicePathNodeLength (UsbWwid) - sizeof (USB_WWID_DEVICE_PATH)) / sizeof (CHAR16);
+ if (CompareStr[CompareLen - 1] == L'\0') {
+ CompareLen--;
+ }
+
+ //
+ // Compare serial number in each supported language.
+ //
+ for (Index = 0; Index < TableSize / sizeof (UINT16); Index++) {
+ SerialNumberStr = NULL;
+ Status = UsbIo->UsbGetStringDescriptor (
+ UsbIo,
+ LangIdTable[Index],
+ DevDesc.StrSerialNumber,
+ &SerialNumberStr
+ );
+ if (EFI_ERROR (Status) || (SerialNumberStr == NULL)) {
+ continue;
+ }
+
+ Length = StrLen (SerialNumberStr);
+ if ((Length >= CompareLen) &&
+ (CompareMem (SerialNumberStr + Length - CompareLen, CompareStr, CompareLen * sizeof (CHAR16)) == 0)) {
+ FreePool (SerialNumberStr);
+ return TRUE;
+ }
+
+ FreePool (SerialNumberStr);
+ }
+
+ return FALSE;
+}
+
+/**
+ Compare whether a full console device path matches a USB shortform device path.
+
+ @param[in] FullPath Full console device path.
+ @param[in] ShortformPath Short-form device path. Short-form device node may in the beginning or in the middle.
+
+ @retval TRUE The full console device path matches the short-form device path.
+ @retval FALSE The full console device path doesn't match the short-form device path.
+**/
+BOOLEAN
+MatchUsbShortformDevicePath (
+ IN EFI_DEVICE_PATH_PROTOCOL *FullPath,
+ IN EFI_DEVICE_PATH_PROTOCOL *ShortformPath
+ )
+{
+ EFI_STATUS Status;
+ EFI_DEVICE_PATH_PROTOCOL *ShortformNode;
+ EFI_DEVICE_PATH_PROTOCOL *ShortformRemainingDevicePath;
+ UINTN ParentDevicePathSize;
+ EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath;
+ EFI_USB_IO_PROTOCOL *UsbIo;
+ EFI_HANDLE Handle;
+
+ for ( ShortformNode = ShortformPath
+ ; !IsDevicePathEnd (ShortformNode)
+ ; ShortformNode = NextDevicePathNode (ShortformNode)
+ ) {
+ if ((DevicePathType (ShortformNode) == MESSAGING_DEVICE_PATH) &&
+ ((DevicePathSubType (ShortformNode) == MSG_USB_CLASS_DP) ||
+ (DevicePathSubType (ShortformNode) == MSG_USB_WWID_DP))
+ ) {
+ break;
+ }
+ }
+
+ //
+ // Skip further compare when it's not a shortform device path.
+ //
+ if (IsDevicePathEnd (ShortformNode)) {
+ return FALSE;
+ }
+
+ //
+ // Match the parent device path below USB layer when the ShortformPath doesn't start with short-form node.
+ //
+ ParentDevicePathSize = (UINTN) ShortformNode - (UINTN) ShortformPath;
+ ShortformRemainingDevicePath = NextDevicePathNode (ShortformNode);
+
+ RemainingDevicePath = FullPath;
+ Status = gBS->LocateDevicePath (&gEfiUsbIoProtocolGuid, &RemainingDevicePath, &Handle);
+ if (EFI_ERROR (Status)) {
+ return FALSE;
+ }
+
+ if (ParentDevicePathSize != 0) {
+ //
+ // Skip comparing the parent device path when ShortformPath begins with short-form node.
+ //
+ if ((ParentDevicePathSize != (UINTN) RemainingDevicePath - (UINTN) FullPath) ||
+ (CompareMem (FullPath, ShortformPath, ParentDevicePathSize) != 0)) {
+ return FALSE;
+ }
+ }
+
+ //
+ // Match the remaining device path above USB layer.
+ // For USB keyboard, the remaining device path above USB layer is END node.
+ //
+ if (CompareMem (RemainingDevicePath, ShortformRemainingDevicePath, GetDevicePathSize (RemainingDevicePath)) != 0) {
+ return FALSE;
+ }
+
+ //
+ // Match the USB layer.
+ //
+ Status = gBS->HandleProtocol(
+ Handle,
+ &gEfiUsbIoProtocolGuid,
+ (VOID **) &UsbIo
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ return MatchUsbClass (UsbIo, (USB_CLASS_DEVICE_PATH *)ShortformNode) ||
+ MatchUsbWwid (UsbIo, (USB_WWID_DEVICE_PATH *)ShortformNode);
+}
+
/**
Function compares a device path data structure to that of all the nodes of a
second device path instance.
@@ -881,7 +1103,8 @@ ConPlatformMatchDevicePaths (
// Search for the match of 'Single' in 'Multi'
//
while (DevicePathInst != NULL) {
- if ((CompareMem (Single, DevicePathInst, Size) == 0) || IsGopSibling (Single, DevicePathInst)) {
+ if ((CompareMem (Single, DevicePathInst, Size) == 0) ||
+ IsGopSibling (Single, DevicePathInst) || MatchUsbShortformDevicePath (Single, DevicePathInst)) {
if (!Delete) {
//
// If Delete is FALSE, return EFI_SUCCESS if Single is found in Multi.
@@ -1029,53 +1252,6 @@ ConPlatformUpdateDeviceVariable (
return Status;
}
-/**
- Check if the device supports hot-plug through its device path.
-
- This function could be updated to check more types of Hot Plug devices.
- Currently, it checks USB and PCCard device.
-
- @param DevicePath Pointer to device's device path.
-
- @retval TRUE The devcie is a hot-plug device
- @retval FALSE The devcie is not a hot-plug device.
-
-**/
-BOOLEAN
-IsHotPlugDevice (
- IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
- )
-{
- EFI_DEVICE_PATH_PROTOCOL *CheckDevicePath;
-
- CheckDevicePath = DevicePath;
- while (!IsDevicePathEnd (CheckDevicePath)) {
- //
- // Check device whether is hot plug device or not throught Device Path
- //
- if ((DevicePathType (CheckDevicePath) == MESSAGING_DEVICE_PATH) &&
- (DevicePathSubType (CheckDevicePath) == MSG_USB_DP ||
- DevicePathSubType (CheckDevicePath) == MSG_USB_CLASS_DP ||
- DevicePathSubType (CheckDevicePath) == MSG_USB_WWID_DP)) {
- //
- // If Device is USB device
- //
- return TRUE;
- }
- if ((DevicePathType (CheckDevicePath) == HARDWARE_DEVICE_PATH) &&
- (DevicePathSubType (CheckDevicePath) == HW_PCCARD_DP)) {
- //
- // If Device is PCCard
- //
- return TRUE;
- }
-
- CheckDevicePath = NextDevicePathNode (CheckDevicePath);
- }
-
- return FALSE;
-}
-
/**
Update ConOutDev and ErrOutDev variables to add the device path of
GOP controller itself and the sibling controllers.
diff --git a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.h b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.h
index 6d853c1360..28f882afeb 100644
--- a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.h
+++ b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.h
@@ -1,7 +1,7 @@
/** @file
Header file for Console Platfrom DXE Driver.
-Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -21,6 +21,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Protocol/DevicePath.h>
#include <Protocol/SimpleTextIn.h>
#include <Protocol/PciIo.h>
+#include <Protocol/UsbIo.h>
#include <Protocol/GraphicsOutput.h>
#include <Guid/GlobalVariable.h>
@@ -294,23 +295,6 @@ ConPlatformUpdateDeviceVariable (
IN CONPLATFORM_VAR_OPERATION Operation
);
-/**
- Check if the device supports hot-plug through its device path.
-
- This function could be updated to check more types of Hot Plug devices.
- Currently, it checks USB and PCCard device.
-
- @param DevicePath Pointer to device's device path.
-
- @retval TRUE The devcie is a hot-plug device
- @retval FALSE The devcie is not a hot-plug device.
-
-**/
-BOOLEAN
-IsHotPlugDevice (
- IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
- );
-
//
// EFI Component Name Functions
//
--
2.16.1.windows.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] MdeModulePkg/ConPlatform: Support short-form USB device path
2018-04-26 7:04 ` Zeng, Star
@ 2018-05-02 7:50 ` Ni, Ruiyu
0 siblings, 0 replies; 7+ messages in thread
From: Ni, Ruiyu @ 2018-05-02 7:50 UTC (permalink / raw)
To: Zeng, Star, edk2-devel@lists.01.org; +Cc: Wu, Hao A, Kinney, Michael D
Thanks/Ray
> -----Original Message-----
> From: Zeng, Star
> Sent: Thursday, April 26, 2018 3:05 PM
> To: Ni, Ruiyu <ruiyu.ni@intel.com>; edk2-devel@lists.01.org
> Cc: Wu, Hao A <hao.a.wu@intel.com>; Kinney, Michael D
> <michael.d.kinney@intel.com>; Zeng, Star <star.zeng@intel.com>
> Subject: RE: [PATCH] MdeModulePkg/ConPlatform: Support short-form USB
> device path
>
> Ray,
>
> Some minor comments below.
>
> 1. How MSG_USB_DP and HW_PCCARD_DP be handled? We see they are
> checked in original IsHotPlugDevice()?
Original implementation to always accept USB/PCCARD device as active console is wrong.
So these code is just removed.
>
> 2. gEfiUsbIoProtocolGuid needs be stated in ConPlatformDxe.inf?
Thanks. I will fix it.
>
> 3. The comment " If it is not a hot-plug device, append the device path to " in
> ConPlatformTextInDriverBindingStart()/ConPlatformTextOutDriverBindingSt
> art() needs be updated accordingly since IsHotPlugDevice() will be removed?
Thanks. I will fix it in v2 patch.
>
>
> Thanks,
> Star
> -----Original Message-----
> From: Ni, Ruiyu
> Sent: Wednesday, April 25, 2018 1:44 PM
> To: edk2-devel@lists.01.org
> Cc: Wu, Hao A <hao.a.wu@intel.com>; Kinney, Michael D
> <michael.d.kinney@intel.com>; Zeng, Star <star.zeng@intel.com>
> Subject: [PATCH] MdeModulePkg/ConPlatform: Support short-form USB
> device path
>
> Today's implementation does an exact device path match to check
> whether the device path of a console is in ConIn/ConOut/ErrOut.
> But that doesn't work for the USB keyboard.
> Because when a platform have multiple USB port, ConIn needs to
> carry all device paths corresponding to each port.
> Even worse, today's BDS core logic removes the device path from
> ConIn/ConOut/ErrOut when the connection to that device path fails.
> So if user switches the USB keyboard from one port to another across
> boot, the USB keyboard doesn't work in the second boot.
>
> ConPlatform driver solved this problem by adding the
> IsHotPlugDevice() function. So that for USB keyboard, ConPlatform
> doesn't care whether its device path is in ConIn or not.
> But the rule is too loose, and now causes platform BDS cannot control
> whether to enable USB keyboard as an active console.
>
> The patch changes ConPlatform to support USB short-form device path
> when checking whether the device path of a console is in
> ConIn/ConOut/ErrOut.
>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
> Cc: Hao A Wu <hao.a.wu@intel.com>
> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> Cc: Star Zeng <star.zeng@intel.com>
> ---
> .../Universal/Console/ConPlatformDxe/ConPlatform.c | 526
> ++++++++++++++-------
> .../Universal/Console/ConPlatformDxe/ConPlatform.h | 20 +-
> 2 files changed, 353 insertions(+), 193 deletions(-)
>
> diff --git
> a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c
> b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c
> index 6b53e8ac74..a509d0e3a5 100644
> --- a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c
> +++ b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c
> @@ -2,7 +2,7 @@
> Console Platform DXE Driver, install Console Device Guids and update
> Console
> Environment Variables.
>
> -Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
> This program and the accompanying materials
> are licensed and made available under the terms and conditions of the BSD
> License
> which accompanies this distribution. The full text of the license may be
> found at
> @@ -270,58 +270,33 @@ ConPlatformTextInDriverBindingStart (
> }
>
> //
> - // Check the device path, if it is a hot plug device,
> - // do not put the device path into ConInDev, and install
> - // gEfiConsoleInDeviceGuid to the device handle directly.
> - // The policy is, make hot plug device plug in and play immediately.
> + // If it is not a hot-plug device, append the device path to the
> + // ConInDev environment variable
> //
> - if (IsHotPlugDevice (DevicePath)) {
> + ConPlatformUpdateDeviceVariable (
> + L"ConInDev",
> + DevicePath,
> + Append
> + );
> +
> + //
> + // If the device path is an instance in the ConIn environment variable,
> + // then install EfiConsoleInDeviceGuid onto ControllerHandle
> + //
> + if (IsInConInVariable) {
> gBS->InstallMultipleProtocolInterfaces (
> &ControllerHandle,
> &gEfiConsoleInDeviceGuid,
> NULL,
> NULL
> );
> - //
> - // Append the device path to ConInDev only if it is in ConIn variable.
> - //
> - if (IsInConInVariable) {
> - ConPlatformUpdateDeviceVariable (
> - L"ConInDev",
> - DevicePath,
> - Append
> - );
> - }
> } else {
> - //
> - // If it is not a hot-plug device, append the device path to the
> - // ConInDev environment variable
> - //
> - ConPlatformUpdateDeviceVariable (
> - L"ConInDev",
> - DevicePath,
> - Append
> - );
> -
> - //
> - // If the device path is an instance in the ConIn environment variable,
> - // then install EfiConsoleInDeviceGuid onto ControllerHandle
> - //
> - if (IsInConInVariable) {
> - gBS->InstallMultipleProtocolInterfaces (
> - &ControllerHandle,
> - &gEfiConsoleInDeviceGuid,
> - NULL,
> - NULL
> - );
> - } else {
> - gBS->CloseProtocol (
> - ControllerHandle,
> - &gEfiSimpleTextInProtocolGuid,
> - This->DriverBindingHandle,
> - ControllerHandle
> - );
> - }
> + gBS->CloseProtocol (
> + ControllerHandle,
> + &gEfiSimpleTextInProtocolGuid,
> + This->DriverBindingHandle,
> + ControllerHandle
> + );
> }
>
> return EFI_SUCCESS;
> @@ -416,95 +391,60 @@ ConPlatformTextOutDriverBindingStart (
> }
>
> //
> - // Check the device path, if it is a hot plug device,
> - // do not put the device path into ConOutDev and ErrOutDev,
> - // and install gEfiConsoleOutDeviceGuid to the device handle directly.
> - // The policy is, make hot plug device plug in and play immediately.
> + // If it is not a hot-plug device, append the device path to
> + // the ConOutDev and ErrOutDev environment variable.
> + // For GOP device path, append the sibling device path as well.
> + //
> + if (!ConPlatformUpdateGopCandidate (DevicePath)) {
> + ConPlatformUpdateDeviceVariable (
> + L"ConOutDev",
> + DevicePath,
> + Append
> + );
> + //
> + // Then append the device path to the ErrOutDev environment variable
> + //
> + ConPlatformUpdateDeviceVariable (
> + L"ErrOutDev",
> + DevicePath,
> + Append
> + );
> + }
> +
> + //
> + // If the device path is an instance in the ConOut environment variable,
> + // then install EfiConsoleOutDeviceGuid onto ControllerHandle
> + //
> + if (IsInConOutVariable) {
> + NeedClose = FALSE;
> + Status = gBS->InstallMultipleProtocolInterfaces (
> + &ControllerHandle,
> + &gEfiConsoleOutDeviceGuid,
> + NULL,
> + NULL
> + );
> + }
> + //
> + // If the device path is an instance in the ErrOut environment variable,
> + // then install EfiStandardErrorDeviceGuid onto ControllerHandle
> //
> - if (IsHotPlugDevice (DevicePath)) {
> + if (IsInErrOutVariable) {
> + NeedClose = FALSE;
> gBS->InstallMultipleProtocolInterfaces (
> &ControllerHandle,
> - &gEfiConsoleOutDeviceGuid,
> + &gEfiStandardErrorDeviceGuid,
> NULL,
> NULL
> );
> - //
> - // Append the device path to ConOutDev only if it is in ConOut variable.
> - //
> - if (IsInConOutVariable) {
> - ConPlatformUpdateDeviceVariable (
> - L"ConOutDev",
> - DevicePath,
> - Append
> - );
> - }
> - //
> - // Append the device path to ErrOutDev only if it is in ErrOut variable.
> - //
> - if (IsInErrOutVariable) {
> - ConPlatformUpdateDeviceVariable (
> - L"ErrOutDev",
> - DevicePath,
> - Append
> - );
> - }
> - } else {
> - //
> - // If it is not a hot-plug device, append the device path to
> - // the ConOutDev and ErrOutDev environment variable.
> - // For GOP device path, append the sibling device path as well.
> - //
> - if (!ConPlatformUpdateGopCandidate (DevicePath)) {
> - ConPlatformUpdateDeviceVariable (
> - L"ConOutDev",
> - DevicePath,
> - Append
> - );
> - //
> - // Then append the device path to the ErrOutDev environment variable
> - //
> - ConPlatformUpdateDeviceVariable (
> - L"ErrOutDev",
> - DevicePath,
> - Append
> - );
> - }
> -
> - //
> - // If the device path is an instance in the ConOut environment variable,
> - // then install EfiConsoleOutDeviceGuid onto ControllerHandle
> - //
> - if (IsInConOutVariable) {
> - NeedClose = FALSE;
> - Status = gBS->InstallMultipleProtocolInterfaces (
> - &ControllerHandle,
> - &gEfiConsoleOutDeviceGuid,
> - NULL,
> - NULL
> - );
> - }
> - //
> - // If the device path is an instance in the ErrOut environment variable,
> - // then install EfiStandardErrorDeviceGuid onto ControllerHandle
> - //
> - if (IsInErrOutVariable) {
> - NeedClose = FALSE;
> - gBS->InstallMultipleProtocolInterfaces (
> - &ControllerHandle,
> - &gEfiStandardErrorDeviceGuid,
> - NULL,
> - NULL
> - );
> - }
> + }
>
> - if (NeedClose) {
> - gBS->CloseProtocol (
> - ControllerHandle,
> - &gEfiSimpleTextOutProtocolGuid,
> - This->DriverBindingHandle,
> - ControllerHandle
> - );
> - }
> + if (NeedClose) {
> + gBS->CloseProtocol (
> + ControllerHandle,
> + &gEfiSimpleTextOutProtocolGuid,
> + This->DriverBindingHandle,
> + ControllerHandle
> + );
> }
>
> return EFI_SUCCESS;
> @@ -822,6 +762,288 @@ IsGopSibling (
> return (BOOLEAN) (CompareMem (Left, Right, (UINTN) NodeLeft - (UINTN)
> Left) == 0);
> }
>
> +/**
> + Check whether a USB device match the specified USB Class device path.
> This
> + function follows "Load Option Processing" behavior in UEFI specification.
> +
> + @param UsbIo USB I/O protocol associated with the USB device.
> + @param UsbClass The USB Class device path to match.
> +
> + @retval TRUE The USB device match the USB Class device path.
> + @retval FALSE The USB device does not match the USB Class device path.
> +
> +**/
> +BOOLEAN
> +MatchUsbClass (
> + IN EFI_USB_IO_PROTOCOL *UsbIo,
> + IN USB_CLASS_DEVICE_PATH *UsbClass
> + )
> +{
> + EFI_STATUS Status;
> + EFI_USB_DEVICE_DESCRIPTOR DevDesc;
> + EFI_USB_INTERFACE_DESCRIPTOR IfDesc;
> + UINT8 DeviceClass;
> + UINT8 DeviceSubClass;
> + UINT8 DeviceProtocol;
> +
> + if ((DevicePathType (UsbClass) != MESSAGING_DEVICE_PATH) ||
> + (DevicePathSubType (UsbClass) != MSG_USB_CLASS_DP)){
> + return FALSE;
> + }
> +
> + //
> + // Check Vendor Id and Product Id.
> + //
> + Status = UsbIo->UsbGetDeviceDescriptor (UsbIo, &DevDesc);
> + if (EFI_ERROR (Status)) {
> + return FALSE;
> + }
> +
> + if ((UsbClass->VendorId != 0xffff) &&
> + (UsbClass->VendorId != DevDesc.IdVendor)) {
> + return FALSE;
> + }
> +
> + if ((UsbClass->ProductId != 0xffff) &&
> + (UsbClass->ProductId != DevDesc.IdProduct)) {
> + return FALSE;
> + }
> +
> + DeviceClass = DevDesc.DeviceClass;
> + DeviceSubClass = DevDesc.DeviceSubClass;
> + DeviceProtocol = DevDesc.DeviceProtocol;
> + if (DeviceClass == 0) {
> + //
> + // If Class in Device Descriptor is set to 0, use the Class, SubClass and
> + // Protocol in Interface Descriptor instead.
> + //
> + Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &IfDesc);
> + if (EFI_ERROR (Status)) {
> + return FALSE;
> + }
> +
> + DeviceClass = IfDesc.InterfaceClass;
> + DeviceSubClass = IfDesc.InterfaceSubClass;
> + DeviceProtocol = IfDesc.InterfaceProtocol;
> + }
> +
> + //
> + // Check Class, SubClass and Protocol.
> + //
> + if ((UsbClass->DeviceClass != 0xff) &&
> + (UsbClass->DeviceClass != DeviceClass)) {
> + return FALSE;
> + }
> +
> + if ((UsbClass->DeviceSubClass != 0xff) &&
> + (UsbClass->DeviceSubClass != DeviceSubClass)) {
> + return FALSE;
> + }
> +
> + if ((UsbClass->DeviceProtocol != 0xff) &&
> + (UsbClass->DeviceProtocol != DeviceProtocol)) {
> + return FALSE;
> + }
> +
> + return TRUE;
> +}
> +
> +/**
> + Check whether a USB device match the specified USB WWID device path.
> This
> + function follows "Load Option Processing" behavior in UEFI specification.
> +
> + @param UsbIo USB I/O protocol associated with the USB device.
> + @param UsbWwid The USB WWID device path to match.
> +
> + @retval TRUE The USB device match the USB WWID device path.
> + @retval FALSE The USB device does not match the USB WWID device
> path.
> +
> +**/
> +BOOLEAN
> +MatchUsbWwid (
> + IN EFI_USB_IO_PROTOCOL *UsbIo,
> + IN USB_WWID_DEVICE_PATH *UsbWwid
> + )
> +{
> + EFI_STATUS Status;
> + EFI_USB_DEVICE_DESCRIPTOR DevDesc;
> + EFI_USB_INTERFACE_DESCRIPTOR IfDesc;
> + UINT16 *LangIdTable;
> + UINT16 TableSize;
> + UINT16 Index;
> + CHAR16 *CompareStr;
> + UINTN CompareLen;
> + CHAR16 *SerialNumberStr;
> + UINTN Length;
> +
> + if ((DevicePathType (UsbWwid) != MESSAGING_DEVICE_PATH) ||
> + (DevicePathSubType (UsbWwid) != MSG_USB_WWID_DP)) {
> + return FALSE;
> + }
> +
> + //
> + // Check Vendor Id and Product Id.
> + //
> + Status = UsbIo->UsbGetDeviceDescriptor (UsbIo, &DevDesc);
> + if (EFI_ERROR (Status)) {
> + return FALSE;
> + }
> + if ((DevDesc.IdVendor != UsbWwid->VendorId) ||
> + (DevDesc.IdProduct != UsbWwid->ProductId)) {
> + return FALSE;
> + }
> +
> + //
> + // Check Interface Number.
> + //
> + Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &IfDesc);
> + if (EFI_ERROR (Status)) {
> + return FALSE;
> + }
> + if (IfDesc.InterfaceNumber != UsbWwid->InterfaceNumber) {
> + return FALSE;
> + }
> +
> + //
> + // Check Serial Number.
> + //
> + if (DevDesc.StrSerialNumber == 0) {
> + return FALSE;
> + }
> +
> + //
> + // Get all supported languages.
> + //
> + TableSize = 0;
> + LangIdTable = NULL;
> + Status = UsbIo->UsbGetSupportedLanguages (UsbIo, &LangIdTable,
> &TableSize);
> + if (EFI_ERROR (Status) || (TableSize == 0) || (LangIdTable == NULL)) {
> + return FALSE;
> + }
> +
> + //
> + // Serial number in USB WWID device path is the last 64-or-less UTF-16
> characters.
> + //
> + CompareStr = (CHAR16 *) (UINTN) (UsbWwid + 1);
> + CompareLen = (DevicePathNodeLength (UsbWwid) - sizeof
> (USB_WWID_DEVICE_PATH)) / sizeof (CHAR16);
> + if (CompareStr[CompareLen - 1] == L'\0') {
> + CompareLen--;
> + }
> +
> + //
> + // Compare serial number in each supported language.
> + //
> + for (Index = 0; Index < TableSize / sizeof (UINT16); Index++) {
> + SerialNumberStr = NULL;
> + Status = UsbIo->UsbGetStringDescriptor (
> + UsbIo,
> + LangIdTable[Index],
> + DevDesc.StrSerialNumber,
> + &SerialNumberStr
> + );
> + if (EFI_ERROR (Status) || (SerialNumberStr == NULL)) {
> + continue;
> + }
> +
> + Length = StrLen (SerialNumberStr);
> + if ((Length >= CompareLen) &&
> + (CompareMem (SerialNumberStr + Length - CompareLen, CompareStr,
> CompareLen * sizeof (CHAR16)) == 0)) {
> + FreePool (SerialNumberStr);
> + return TRUE;
> + }
> +
> + FreePool (SerialNumberStr);
> + }
> +
> + return FALSE;
> +}
> +
> +/**
> + Compare whether a full console device path matches a USB shortform
> device path.
> +
> + @param[in] FullPath Full console device path.
> + @param[in] ShortformPath Short-form device path. Short-form device
> node may in the beginning or in the middle.
> +
> + @retval TRUE The full console device path matches the short-form device
> path.
> + @retval FALSE The full console device path doesn't match the short-form
> device path.
> +**/
> +BOOLEAN
> +MatchUsbShortformDevicePath (
> + IN EFI_DEVICE_PATH_PROTOCOL *FullPath,
> + IN EFI_DEVICE_PATH_PROTOCOL *ShortformPath
> + )
> +{
> + EFI_STATUS Status;
> + EFI_DEVICE_PATH_PROTOCOL *ShortformNode;
> + EFI_DEVICE_PATH_PROTOCOL *ShortformRemainingDevicePath;
> + UINTN ParentDevicePathSize;
> + EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath;
> + EFI_USB_IO_PROTOCOL *UsbIo;
> + EFI_HANDLE Handle;
> +
> + for ( ShortformNode = ShortformPath
> + ; !IsDevicePathEnd (ShortformNode)
> + ; ShortformNode = NextDevicePathNode (ShortformNode)
> + ) {
> + if ((DevicePathType (ShortformNode) == MESSAGING_DEVICE_PATH) &&
> + ((DevicePathSubType (ShortformNode) == MSG_USB_CLASS_DP) ||
> + (DevicePathSubType (ShortformNode) == MSG_USB_WWID_DP))
> + ) {
> + break;
> + }
> + }
> +
> + //
> + // Skip further compare when it's not a shortform device path.
> + //
> + if (IsDevicePathEnd (ShortformNode)) {
> + return FALSE;
> + }
> +
> + //
> + // Match the parent device path below USB layer when the ShortformPath
> doesn't start with short-form node.
> + //
> + ParentDevicePathSize = (UINTN) ShortformNode - (UINTN)
> ShortformPath;
> + ShortformRemainingDevicePath = NextDevicePathNode (ShortformNode);
> +
> + RemainingDevicePath = FullPath;
> + Status = gBS->LocateDevicePath (&gEfiUsbIoProtocolGuid,
> &RemainingDevicePath, &Handle);
> + if (EFI_ERROR (Status)) {
> + return FALSE;
> + }
> +
> + if (ParentDevicePathSize != 0) {
> + //
> + // Skip comparing the parent device path when ShortformPath begins
> with short-form node.
> + //
> + if ((ParentDevicePathSize != (UINTN) RemainingDevicePath - (UINTN)
> FullPath) ||
> + (CompareMem (FullPath, ShortformPath, ParentDevicePathSize) != 0))
> {
> + return FALSE;
> + }
> + }
> +
> + //
> + // Match the remaining device path above USB layer.
> + // For USB keyboard, the remaining device path above USB layer is END
> node.
> + //
> + if (CompareMem (RemainingDevicePath, ShortformRemainingDevicePath,
> GetDevicePathSize (RemainingDevicePath)) != 0) {
> + return FALSE;
> + }
> +
> + //
> + // Match the USB layer.
> + //
> + Status = gBS->HandleProtocol(
> + Handle,
> + &gEfiUsbIoProtocolGuid,
> + (VOID **) &UsbIo
> + );
> + ASSERT_EFI_ERROR (Status);
> +
> + return MatchUsbClass (UsbIo, (USB_CLASS_DEVICE_PATH
> *)ShortformNode) ||
> + MatchUsbWwid (UsbIo, (USB_WWID_DEVICE_PATH
> *)ShortformNode);
> +}
> +
> /**
> Function compares a device path data structure to that of all the nodes of a
> second device path instance.
> @@ -881,7 +1103,8 @@ ConPlatformMatchDevicePaths (
> // Search for the match of 'Single' in 'Multi'
> //
> while (DevicePathInst != NULL) {
> - if ((CompareMem (Single, DevicePathInst, Size) == 0) || IsGopSibling
> (Single, DevicePathInst)) {
> + if ((CompareMem (Single, DevicePathInst, Size) == 0) ||
> + IsGopSibling (Single, DevicePathInst) || MatchUsbShortformDevicePath
> (Single, DevicePathInst)) {
> if (!Delete) {
> //
> // If Delete is FALSE, return EFI_SUCCESS if Single is found in Multi.
> @@ -1029,53 +1252,6 @@ ConPlatformUpdateDeviceVariable (
> return Status;
> }
>
> -/**
> - Check if the device supports hot-plug through its device path.
> -
> - This function could be updated to check more types of Hot Plug devices.
> - Currently, it checks USB and PCCard device.
> -
> - @param DevicePath Pointer to device's device path.
> -
> - @retval TRUE The devcie is a hot-plug device
> - @retval FALSE The devcie is not a hot-plug device.
> -
> -**/
> -BOOLEAN
> -IsHotPlugDevice (
> - IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
> - )
> -{
> - EFI_DEVICE_PATH_PROTOCOL *CheckDevicePath;
> -
> - CheckDevicePath = DevicePath;
> - while (!IsDevicePathEnd (CheckDevicePath)) {
> - //
> - // Check device whether is hot plug device or not throught Device Path
> - //
> - if ((DevicePathType (CheckDevicePath) == MESSAGING_DEVICE_PATH)
> &&
> - (DevicePathSubType (CheckDevicePath) == MSG_USB_DP ||
> - DevicePathSubType (CheckDevicePath) == MSG_USB_CLASS_DP ||
> - DevicePathSubType (CheckDevicePath) == MSG_USB_WWID_DP)) {
> - //
> - // If Device is USB device
> - //
> - return TRUE;
> - }
> - if ((DevicePathType (CheckDevicePath) == HARDWARE_DEVICE_PATH)
> &&
> - (DevicePathSubType (CheckDevicePath) == HW_PCCARD_DP)) {
> - //
> - // If Device is PCCard
> - //
> - return TRUE;
> - }
> -
> - CheckDevicePath = NextDevicePathNode (CheckDevicePath);
> - }
> -
> - return FALSE;
> -}
> -
> /**
> Update ConOutDev and ErrOutDev variables to add the device path of
> GOP controller itself and the sibling controllers.
> diff --git
> a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.h
> b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.h
> index 6d853c1360..28f882afeb 100644
> --- a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.h
> +++ b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.h
> @@ -1,7 +1,7 @@
> /** @file
> Header file for Console Platfrom DXE Driver.
>
> -Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
> This program and the accompanying materials
> are licensed and made available under the terms and conditions of the BSD
> License
> which accompanies this distribution. The full text of the license may be
> found at
> @@ -21,6 +21,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY
> KIND, EITHER EXPRESS OR IMPLIED.
> #include <Protocol/DevicePath.h>
> #include <Protocol/SimpleTextIn.h>
> #include <Protocol/PciIo.h>
> +#include <Protocol/UsbIo.h>
> #include <Protocol/GraphicsOutput.h>
>
> #include <Guid/GlobalVariable.h>
> @@ -294,23 +295,6 @@ ConPlatformUpdateDeviceVariable (
> IN CONPLATFORM_VAR_OPERATION Operation
> );
>
> -/**
> - Check if the device supports hot-plug through its device path.
> -
> - This function could be updated to check more types of Hot Plug devices.
> - Currently, it checks USB and PCCard device.
> -
> - @param DevicePath Pointer to device's device path.
> -
> - @retval TRUE The devcie is a hot-plug device
> - @retval FALSE The devcie is not a hot-plug device.
> -
> -**/
> -BOOLEAN
> -IsHotPlugDevice (
> - IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
> - );
> -
> //
> // EFI Component Name Functions
> //
> --
> 2.16.1.windows.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] MdeModulePkg/ConPlatform: Support short-form USB device path
@ 2018-09-10 10:05 Ruiyu Ni
2018-09-12 1:47 ` Zeng, Star
0 siblings, 1 reply; 7+ messages in thread
From: Ruiyu Ni @ 2018-09-10 10:05 UTC (permalink / raw)
To: edk2-devel; +Cc: Hao A Wu, Michael D Kinney, Star Zeng
Today's implementation does an exact device path match to check
whether the device path of a console is in ConIn/ConOut/ErrOut.
But that doesn't work for the USB keyboard.
Because when a platform have multiple USB port, ConIn needs to
carry all device paths corresponding to each port.
Even worse, today's BDS core logic removes the device path from
ConIn/ConOut/ErrOut when the connection to that device path fails.
So if user switches the USB keyboard from one port to another across
boot, the USB keyboard doesn't work in the second boot.
ConPlatform driver solved this problem by adding the
IsHotPlugDevice() function. So that for USB keyboard, ConPlatform
doesn't care whether its device path is in ConIn or not.
But the rule is too loose, and now causes platform BDS cannot control
whether to enable USB keyboard as an active console.
The patch changes ConPlatform to support USB short-form device path
when checking whether the device path of a console is in
ConIn/ConOut/ErrOut.
The logic to always accept USB/PCCARD device as active console is
removed.
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
---
.../Universal/Console/ConPlatformDxe/ConPlatform.c | 513 ++++++++++++++-------
.../Universal/Console/ConPlatformDxe/ConPlatform.h | 24 +-
.../Console/ConPlatformDxe/ConPlatformDxe.inf | 1 +
3 files changed, 339 insertions(+), 199 deletions(-)
diff --git a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c
index 5fa7facfca..27df8a4b56 100644
--- a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c
+++ b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c
@@ -202,8 +202,7 @@ ConPlatformDriverBindingSupported (
Start this driver on ControllerHandle by opening Simple Text Input Protocol,
reading Device Path, and installing Console In Devcice GUID on ControllerHandle.
- If this devcie is not one hot-plug devce, append its device path into the
- console environment variables ConInDev.
+ Append its device path into the console environment variables ConInDev.
@param This Protocol instance pointer.
@param ControllerHandle Handle of device to bind driver to
@@ -270,58 +269,32 @@ ConPlatformTextInDriverBindingStart (
}
//
- // Check the device path, if it is a hot plug device,
- // do not put the device path into ConInDev, and install
- // gEfiConsoleInDeviceGuid to the device handle directly.
- // The policy is, make hot plug device plug in and play immediately.
+ // Append the device path to the ConInDev environment variable
//
- if (IsHotPlugDevice (DevicePath)) {
+ ConPlatformUpdateDeviceVariable (
+ L"ConInDev",
+ DevicePath,
+ Append
+ );
+
+ //
+ // If the device path is an instance in the ConIn environment variable,
+ // then install EfiConsoleInDeviceGuid onto ControllerHandle
+ //
+ if (IsInConInVariable) {
gBS->InstallMultipleProtocolInterfaces (
&ControllerHandle,
&gEfiConsoleInDeviceGuid,
NULL,
NULL
);
- //
- // Append the device path to ConInDev only if it is in ConIn variable.
- //
- if (IsInConInVariable) {
- ConPlatformUpdateDeviceVariable (
- L"ConInDev",
- DevicePath,
- Append
- );
- }
} else {
- //
- // If it is not a hot-plug device, append the device path to the
- // ConInDev environment variable
- //
- ConPlatformUpdateDeviceVariable (
- L"ConInDev",
- DevicePath,
- Append
- );
-
- //
- // If the device path is an instance in the ConIn environment variable,
- // then install EfiConsoleInDeviceGuid onto ControllerHandle
- //
- if (IsInConInVariable) {
- gBS->InstallMultipleProtocolInterfaces (
- &ControllerHandle,
- &gEfiConsoleInDeviceGuid,
- NULL,
- NULL
- );
- } else {
- gBS->CloseProtocol (
- ControllerHandle,
- &gEfiSimpleTextInProtocolGuid,
- This->DriverBindingHandle,
- ControllerHandle
- );
- }
+ gBS->CloseProtocol (
+ ControllerHandle,
+ &gEfiSimpleTextInProtocolGuid,
+ This->DriverBindingHandle,
+ ControllerHandle
+ );
}
return EFI_SUCCESS;
@@ -334,8 +307,7 @@ ConPlatformTextInDriverBindingStart (
reading Device Path, and installing Console Out Devcic GUID, Standard Error
Device GUID on ControllerHandle.
- If this devcie is not one hot-plug devce, append its device path into the
- console environment variables ConOutDev, ErrOutDev.
+ Append its device path into the console environment variables ConOutDev, ErrOutDev.
@param This Protocol instance pointer.
@param ControllerHandle Handle of device to bind driver to
@@ -416,95 +388,59 @@ ConPlatformTextOutDriverBindingStart (
}
//
- // Check the device path, if it is a hot plug device,
- // do not put the device path into ConOutDev and ErrOutDev,
- // and install gEfiConsoleOutDeviceGuid to the device handle directly.
- // The policy is, make hot plug device plug in and play immediately.
+ // Append the device path to the ConOutDev and ErrOutDev environment variable.
+ // For GOP device path, append the sibling device path as well.
//
- if (IsHotPlugDevice (DevicePath)) {
+ if (!ConPlatformUpdateGopCandidate (DevicePath)) {
+ ConPlatformUpdateDeviceVariable (
+ L"ConOutDev",
+ DevicePath,
+ Append
+ );
+ //
+ // Then append the device path to the ErrOutDev environment variable
+ //
+ ConPlatformUpdateDeviceVariable (
+ L"ErrOutDev",
+ DevicePath,
+ Append
+ );
+ }
+
+ //
+ // If the device path is an instance in the ConOut environment variable,
+ // then install EfiConsoleOutDeviceGuid onto ControllerHandle
+ //
+ if (IsInConOutVariable) {
+ NeedClose = FALSE;
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ &ControllerHandle,
+ &gEfiConsoleOutDeviceGuid,
+ NULL,
+ NULL
+ );
+ }
+ //
+ // If the device path is an instance in the ErrOut environment variable,
+ // then install EfiStandardErrorDeviceGuid onto ControllerHandle
+ //
+ if (IsInErrOutVariable) {
+ NeedClose = FALSE;
gBS->InstallMultipleProtocolInterfaces (
&ControllerHandle,
- &gEfiConsoleOutDeviceGuid,
+ &gEfiStandardErrorDeviceGuid,
NULL,
NULL
);
- //
- // Append the device path to ConOutDev only if it is in ConOut variable.
- //
- if (IsInConOutVariable) {
- ConPlatformUpdateDeviceVariable (
- L"ConOutDev",
- DevicePath,
- Append
- );
- }
- //
- // Append the device path to ErrOutDev only if it is in ErrOut variable.
- //
- if (IsInErrOutVariable) {
- ConPlatformUpdateDeviceVariable (
- L"ErrOutDev",
- DevicePath,
- Append
- );
- }
- } else {
- //
- // If it is not a hot-plug device, append the device path to
- // the ConOutDev and ErrOutDev environment variable.
- // For GOP device path, append the sibling device path as well.
- //
- if (!ConPlatformUpdateGopCandidate (DevicePath)) {
- ConPlatformUpdateDeviceVariable (
- L"ConOutDev",
- DevicePath,
- Append
- );
- //
- // Then append the device path to the ErrOutDev environment variable
- //
- ConPlatformUpdateDeviceVariable (
- L"ErrOutDev",
- DevicePath,
- Append
- );
- }
-
- //
- // If the device path is an instance in the ConOut environment variable,
- // then install EfiConsoleOutDeviceGuid onto ControllerHandle
- //
- if (IsInConOutVariable) {
- NeedClose = FALSE;
- Status = gBS->InstallMultipleProtocolInterfaces (
- &ControllerHandle,
- &gEfiConsoleOutDeviceGuid,
- NULL,
- NULL
- );
- }
- //
- // If the device path is an instance in the ErrOut environment variable,
- // then install EfiStandardErrorDeviceGuid onto ControllerHandle
- //
- if (IsInErrOutVariable) {
- NeedClose = FALSE;
- gBS->InstallMultipleProtocolInterfaces (
- &ControllerHandle,
- &gEfiStandardErrorDeviceGuid,
- NULL,
- NULL
- );
- }
+ }
- if (NeedClose) {
- gBS->CloseProtocol (
- ControllerHandle,
- &gEfiSimpleTextOutProtocolGuid,
- This->DriverBindingHandle,
- ControllerHandle
- );
- }
+ if (NeedClose) {
+ gBS->CloseProtocol (
+ ControllerHandle,
+ &gEfiSimpleTextOutProtocolGuid,
+ This->DriverBindingHandle,
+ ControllerHandle
+ );
}
return EFI_SUCCESS;
@@ -822,6 +758,273 @@ IsGopSibling (
return (BOOLEAN) (CompareMem (Left, Right, (UINTN) NodeLeft - (UINTN) Left) == 0);
}
+/**
+ Check whether a USB device match the specified USB Class device path. This
+ function follows "Load Option Processing" behavior in UEFI specification.
+
+ @param UsbIo USB I/O protocol associated with the USB device.
+ @param UsbClass The USB Class device path to match.
+
+ @retval TRUE The USB device match the USB Class device path.
+ @retval FALSE The USB device does not match the USB Class device path.
+
+**/
+BOOLEAN
+MatchUsbClass (
+ IN EFI_USB_IO_PROTOCOL *UsbIo,
+ IN USB_CLASS_DEVICE_PATH *UsbClass
+ )
+{
+ EFI_STATUS Status;
+ EFI_USB_DEVICE_DESCRIPTOR DevDesc;
+ EFI_USB_INTERFACE_DESCRIPTOR IfDesc;
+ UINT8 DeviceClass;
+ UINT8 DeviceSubClass;
+ UINT8 DeviceProtocol;
+
+ if ((DevicePathType (UsbClass) != MESSAGING_DEVICE_PATH) ||
+ (DevicePathSubType (UsbClass) != MSG_USB_CLASS_DP)){
+ return FALSE;
+ }
+
+ //
+ // Check Vendor Id and Product Id.
+ //
+ Status = UsbIo->UsbGetDeviceDescriptor (UsbIo, &DevDesc);
+ if (EFI_ERROR (Status)) {
+ return FALSE;
+ }
+
+ if ((UsbClass->VendorId != 0xffff) &&
+ (UsbClass->VendorId != DevDesc.IdVendor)) {
+ return FALSE;
+ }
+
+ if ((UsbClass->ProductId != 0xffff) &&
+ (UsbClass->ProductId != DevDesc.IdProduct)) {
+ return FALSE;
+ }
+
+ DeviceClass = DevDesc.DeviceClass;
+ DeviceSubClass = DevDesc.DeviceSubClass;
+ DeviceProtocol = DevDesc.DeviceProtocol;
+ if (DeviceClass == 0) {
+ //
+ // If Class in Device Descriptor is set to 0, use the Class, SubClass and
+ // Protocol in Interface Descriptor instead.
+ //
+ Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &IfDesc);
+ if (EFI_ERROR (Status)) {
+ return FALSE;
+ }
+
+ DeviceClass = IfDesc.InterfaceClass;
+ DeviceSubClass = IfDesc.InterfaceSubClass;
+ DeviceProtocol = IfDesc.InterfaceProtocol;
+ }
+
+ //
+ // Check Class, SubClass and Protocol.
+ //
+ if ((UsbClass->DeviceClass != 0xff) &&
+ (UsbClass->DeviceClass != DeviceClass)) {
+ return FALSE;
+ }
+
+ if ((UsbClass->DeviceSubClass != 0xff) &&
+ (UsbClass->DeviceSubClass != DeviceSubClass)) {
+ return FALSE;
+ }
+
+ if ((UsbClass->DeviceProtocol != 0xff) &&
+ (UsbClass->DeviceProtocol != DeviceProtocol)) {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/**
+ Check whether a USB device match the specified USB WWID device path. This
+ function follows "Load Option Processing" behavior in UEFI specification.
+
+ @param UsbIo USB I/O protocol associated with the USB device.
+ @param UsbWwid The USB WWID device path to match.
+
+ @retval TRUE The USB device match the USB WWID device path.
+ @retval FALSE The USB device does not match the USB WWID device path.
+
+**/
+BOOLEAN
+MatchUsbWwid (
+ IN EFI_USB_IO_PROTOCOL *UsbIo,
+ IN USB_WWID_DEVICE_PATH *UsbWwid
+ )
+{
+ EFI_STATUS Status;
+ EFI_USB_DEVICE_DESCRIPTOR DevDesc;
+ EFI_USB_INTERFACE_DESCRIPTOR IfDesc;
+ UINT16 *LangIdTable;
+ UINT16 TableSize;
+ UINT16 Index;
+ CHAR16 *CompareStr;
+ UINTN CompareLen;
+ CHAR16 *SerialNumberStr;
+ UINTN Length;
+
+ if ((DevicePathType (UsbWwid) != MESSAGING_DEVICE_PATH) ||
+ (DevicePathSubType (UsbWwid) != MSG_USB_WWID_DP)) {
+ return FALSE;
+ }
+
+ //
+ // Check Vendor Id and Product Id.
+ //
+ Status = UsbIo->UsbGetDeviceDescriptor (UsbIo, &DevDesc);
+ if (EFI_ERROR (Status)) {
+ return FALSE;
+ }
+ if ((DevDesc.IdVendor != UsbWwid->VendorId) ||
+ (DevDesc.IdProduct != UsbWwid->ProductId)) {
+ return FALSE;
+ }
+
+ //
+ // Check Interface Number.
+ //
+ Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &IfDesc);
+ if (EFI_ERROR (Status)) {
+ return FALSE;
+ }
+ if (IfDesc.InterfaceNumber != UsbWwid->InterfaceNumber) {
+ return FALSE;
+ }
+
+ //
+ // Check Serial Number.
+ //
+ if (DevDesc.StrSerialNumber == 0) {
+ return FALSE;
+ }
+
+ //
+ // Get all supported languages.
+ //
+ TableSize = 0;
+ LangIdTable = NULL;
+ Status = UsbIo->UsbGetSupportedLanguages (UsbIo, &LangIdTable, &TableSize);
+ if (EFI_ERROR (Status) || (TableSize == 0) || (LangIdTable == NULL)) {
+ return FALSE;
+ }
+
+ //
+ // Serial number in USB WWID device path is the last 64-or-less UTF-16 characters.
+ //
+ CompareStr = (CHAR16 *) (UINTN) (UsbWwid + 1);
+ CompareLen = (DevicePathNodeLength (UsbWwid) - sizeof (USB_WWID_DEVICE_PATH)) / sizeof (CHAR16);
+ if (CompareStr[CompareLen - 1] == L'\0') {
+ CompareLen--;
+ }
+
+ //
+ // Compare serial number in each supported language.
+ //
+ for (Index = 0; Index < TableSize / sizeof (UINT16); Index++) {
+ SerialNumberStr = NULL;
+ Status = UsbIo->UsbGetStringDescriptor (
+ UsbIo,
+ LangIdTable[Index],
+ DevDesc.StrSerialNumber,
+ &SerialNumberStr
+ );
+ if (EFI_ERROR (Status) || (SerialNumberStr == NULL)) {
+ continue;
+ }
+
+ Length = StrLen (SerialNumberStr);
+ if ((Length >= CompareLen) &&
+ (CompareMem (SerialNumberStr + Length - CompareLen, CompareStr, CompareLen * sizeof (CHAR16)) == 0)) {
+ FreePool (SerialNumberStr);
+ return TRUE;
+ }
+
+ FreePool (SerialNumberStr);
+ }
+
+ return FALSE;
+}
+
+/**
+ Compare whether a full console device path matches a USB shortform device path.
+
+ @param[in] FullPath Full console device path.
+ @param[in] ShortformPath Short-form device path. Short-form device node may in the beginning or in the middle.
+
+ @retval TRUE The full console device path matches the short-form device path.
+ @retval FALSE The full console device path doesn't match the short-form device path.
+**/
+BOOLEAN
+MatchUsbShortformDevicePath (
+ IN EFI_DEVICE_PATH_PROTOCOL *FullPath,
+ IN EFI_DEVICE_PATH_PROTOCOL *ShortformPath
+ )
+{
+ EFI_STATUS Status;
+ EFI_DEVICE_PATH_PROTOCOL *ShortformNode;
+ UINTN ParentDevicePathSize;
+ EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath;
+ EFI_USB_IO_PROTOCOL *UsbIo;
+ EFI_HANDLE Handle;
+
+ for ( ShortformNode = ShortformPath
+ ; !IsDevicePathEnd (ShortformNode)
+ ; ShortformNode = NextDevicePathNode (ShortformNode)
+ ) {
+ if ((DevicePathType (ShortformNode) == MESSAGING_DEVICE_PATH) &&
+ ((DevicePathSubType (ShortformNode) == MSG_USB_CLASS_DP) ||
+ (DevicePathSubType (ShortformNode) == MSG_USB_WWID_DP))
+ ) {
+ break;
+ }
+ }
+
+ //
+ // Skip further compare when it's not a shortform device path.
+ //
+ if (IsDevicePathEnd (ShortformNode)) {
+ return FALSE;
+ }
+
+ //
+ // Compare the parent device path when the ShortformPath doesn't start with short-form node.
+ //
+ ParentDevicePathSize = (UINTN) ShortformNode - (UINTN) ShortformPath;
+ RemainingDevicePath = FullPath;
+ Status = gBS->LocateDevicePath (&gEfiUsbIoProtocolGuid, &RemainingDevicePath, &Handle);
+ if (EFI_ERROR (Status)) {
+ return FALSE;
+ }
+ if (ParentDevicePathSize != 0) {
+ if ((ParentDevicePathSize > (UINTN) RemainingDevicePath - (UINTN) FullPath) ||
+ (CompareMem (FullPath, ShortformPath, ParentDevicePathSize) != 0)) {
+ return FALSE;
+ }
+ }
+
+ //
+ // Compar the USB layer.
+ //
+ Status = gBS->HandleProtocol(
+ Handle,
+ &gEfiUsbIoProtocolGuid,
+ (VOID **) &UsbIo
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ return MatchUsbClass (UsbIo, (USB_CLASS_DEVICE_PATH *)ShortformNode) ||
+ MatchUsbWwid (UsbIo, (USB_WWID_DEVICE_PATH *)ShortformNode);
+}
+
/**
Function compares a device path data structure to that of all the nodes of a
second device path instance.
@@ -881,7 +1084,8 @@ ConPlatformMatchDevicePaths (
// Search for the match of 'Single' in 'Multi'
//
while (DevicePathInst != NULL) {
- if ((CompareMem (Single, DevicePathInst, Size) == 0) || IsGopSibling (Single, DevicePathInst)) {
+ if ((CompareMem (Single, DevicePathInst, Size) == 0) ||
+ IsGopSibling (Single, DevicePathInst) || MatchUsbShortformDevicePath (Single, DevicePathInst)) {
if (!Delete) {
//
// If Delete is FALSE, return EFI_SUCCESS if Single is found in Multi.
@@ -1029,53 +1233,6 @@ ConPlatformUpdateDeviceVariable (
return Status;
}
-/**
- Check if the device supports hot-plug through its device path.
-
- This function could be updated to check more types of Hot Plug devices.
- Currently, it checks USB and PCCard device.
-
- @param DevicePath Pointer to device's device path.
-
- @retval TRUE The devcie is a hot-plug device
- @retval FALSE The devcie is not a hot-plug device.
-
-**/
-BOOLEAN
-IsHotPlugDevice (
- IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
- )
-{
- EFI_DEVICE_PATH_PROTOCOL *CheckDevicePath;
-
- CheckDevicePath = DevicePath;
- while (!IsDevicePathEnd (CheckDevicePath)) {
- //
- // Check device whether is hot plug device or not throught Device Path
- //
- if ((DevicePathType (CheckDevicePath) == MESSAGING_DEVICE_PATH) &&
- (DevicePathSubType (CheckDevicePath) == MSG_USB_DP ||
- DevicePathSubType (CheckDevicePath) == MSG_USB_CLASS_DP ||
- DevicePathSubType (CheckDevicePath) == MSG_USB_WWID_DP)) {
- //
- // If Device is USB device
- //
- return TRUE;
- }
- if ((DevicePathType (CheckDevicePath) == HARDWARE_DEVICE_PATH) &&
- (DevicePathSubType (CheckDevicePath) == HW_PCCARD_DP)) {
- //
- // If Device is PCCard
- //
- return TRUE;
- }
-
- CheckDevicePath = NextDevicePathNode (CheckDevicePath);
- }
-
- return FALSE;
-}
-
/**
Update ConOutDev and ErrOutDev variables to add the device path of
GOP controller itself and the sibling controllers.
diff --git a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.h b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.h
index 1d5f11e94c..b5465f09f1 100644
--- a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.h
+++ b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.h
@@ -21,6 +21,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Protocol/DevicePath.h>
#include <Protocol/SimpleTextIn.h>
#include <Protocol/PciIo.h>
+#include <Protocol/UsbIo.h>
#include <Protocol/GraphicsOutput.h>
#include <Guid/GlobalVariable.h>
@@ -119,8 +120,7 @@ ConPlatformTextOutDriverBindingSupported (
Start this driver on ControllerHandle by opening Simple Text Input Protocol,
reading Device Path, and installing Console In Devcice GUID on ControllerHandle.
- If this devcie is not one hot-plug devce, append its device path into the
- console environment variables ConInDev.
+ Append its device path into the console environment variables ConInDev.
@param This Protocol instance pointer.
@param ControllerHandle Handle of device to bind driver to
@@ -147,8 +147,7 @@ ConPlatformTextInDriverBindingStart (
reading Device Path, and installing Console Out Devcic GUID, Standard Error
Device GUID on ControllerHandle.
- If this devcie is not one hot-plug devce, append its device path into the
- console environment variables ConOutDev, StdErrDev.
+ Append its device path into the console environment variables ConOutDev, ErrOutDev.
@param This Protocol instance pointer.
@param ControllerHandle Handle of device to bind driver to
@@ -294,23 +293,6 @@ ConPlatformUpdateDeviceVariable (
IN CONPLATFORM_VAR_OPERATION Operation
);
-/**
- Check if the device supports hot-plug through its device path.
-
- This function could be updated to check more types of Hot Plug devices.
- Currently, it checks USB and PCCard device.
-
- @param DevicePath Pointer to device's device path.
-
- @retval TRUE The devcie is a hot-plug device
- @retval FALSE The devcie is not a hot-plug device.
-
-**/
-BOOLEAN
-IsHotPlugDevice (
- IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
- );
-
//
// EFI Component Name Functions
//
diff --git a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf
index 176fd2fa0b..19b3f5c443 100644
--- a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf
+++ b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf
@@ -94,6 +94,7 @@ [Protocols]
gEfiSimpleTextOutProtocolGuid ## TO_START
gEfiPciIoProtocolGuid ## SOMETIMES_CONSUMES
gEfiGraphicsOutputProtocolGuid ## SOMETIMES_CONSUMES
+ gEfiUsbIoProtocolGuid ## SOMETIMES_CONSUMES
[UserExtensions.TianoCore."ExtraFiles"]
ConPlatformDxeExtra.uni
--
2.16.1.windows.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] MdeModulePkg/ConPlatform: Support short-form USB device path
2018-09-10 10:05 Ruiyu Ni
@ 2018-09-12 1:47 ` Zeng, Star
0 siblings, 0 replies; 7+ messages in thread
From: Zeng, Star @ 2018-09-12 1:47 UTC (permalink / raw)
To: Ni, Ruiyu, edk2-devel@lists.01.org
Cc: Wu, Hao A, Kinney, Michael D, Zeng, Star
Reviewed-by: Star Zeng <star.zeng@intel.com>
-----Original Message-----
From: Ni, Ruiyu
Sent: Monday, September 10, 2018 6:05 PM
To: edk2-devel@lists.01.org
Cc: Wu, Hao A <hao.a.wu@intel.com>; Kinney, Michael D <michael.d.kinney@intel.com>; Zeng, Star <star.zeng@intel.com>
Subject: [PATCH] MdeModulePkg/ConPlatform: Support short-form USB device path
Today's implementation does an exact device path match to check whether the device path of a console is in ConIn/ConOut/ErrOut.
But that doesn't work for the USB keyboard.
Because when a platform have multiple USB port, ConIn needs to carry all device paths corresponding to each port.
Even worse, today's BDS core logic removes the device path from ConIn/ConOut/ErrOut when the connection to that device path fails.
So if user switches the USB keyboard from one port to another across boot, the USB keyboard doesn't work in the second boot.
ConPlatform driver solved this problem by adding the
IsHotPlugDevice() function. So that for USB keyboard, ConPlatform doesn't care whether its device path is in ConIn or not.
But the rule is too loose, and now causes platform BDS cannot control whether to enable USB keyboard as an active console.
The patch changes ConPlatform to support USB short-form device path when checking whether the device path of a console is in ConIn/ConOut/ErrOut.
The logic to always accept USB/PCCARD device as active console is removed.
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
---
.../Universal/Console/ConPlatformDxe/ConPlatform.c | 513 ++++++++++++++------- .../Universal/Console/ConPlatformDxe/ConPlatform.h | 24 +-
.../Console/ConPlatformDxe/ConPlatformDxe.inf | 1 +
3 files changed, 339 insertions(+), 199 deletions(-)
diff --git a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c
index 5fa7facfca..27df8a4b56 100644
--- a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c
+++ b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c
@@ -202,8 +202,7 @@ ConPlatformDriverBindingSupported (
Start this driver on ControllerHandle by opening Simple Text Input Protocol,
reading Device Path, and installing Console In Devcice GUID on ControllerHandle.
- If this devcie is not one hot-plug devce, append its device path into the
- console environment variables ConInDev.
+ Append its device path into the console environment variables ConInDev.
@param This Protocol instance pointer.
@param ControllerHandle Handle of device to bind driver to
@@ -270,58 +269,32 @@ ConPlatformTextInDriverBindingStart (
}
//
- // Check the device path, if it is a hot plug device,
- // do not put the device path into ConInDev, and install
- // gEfiConsoleInDeviceGuid to the device handle directly.
- // The policy is, make hot plug device plug in and play immediately.
+ // Append the device path to the ConInDev environment variable
//
- if (IsHotPlugDevice (DevicePath)) {
+ ConPlatformUpdateDeviceVariable (
+ L"ConInDev",
+ DevicePath,
+ Append
+ );
+
+ //
+ // If the device path is an instance in the ConIn environment
+ variable, // then install EfiConsoleInDeviceGuid onto
+ ControllerHandle // if (IsInConInVariable) {
gBS->InstallMultipleProtocolInterfaces (
&ControllerHandle,
&gEfiConsoleInDeviceGuid,
NULL,
NULL
);
- //
- // Append the device path to ConInDev only if it is in ConIn variable.
- //
- if (IsInConInVariable) {
- ConPlatformUpdateDeviceVariable (
- L"ConInDev",
- DevicePath,
- Append
- );
- }
} else {
- //
- // If it is not a hot-plug device, append the device path to the
- // ConInDev environment variable
- //
- ConPlatformUpdateDeviceVariable (
- L"ConInDev",
- DevicePath,
- Append
- );
-
- //
- // If the device path is an instance in the ConIn environment variable,
- // then install EfiConsoleInDeviceGuid onto ControllerHandle
- //
- if (IsInConInVariable) {
- gBS->InstallMultipleProtocolInterfaces (
- &ControllerHandle,
- &gEfiConsoleInDeviceGuid,
- NULL,
- NULL
- );
- } else {
- gBS->CloseProtocol (
- ControllerHandle,
- &gEfiSimpleTextInProtocolGuid,
- This->DriverBindingHandle,
- ControllerHandle
- );
- }
+ gBS->CloseProtocol (
+ ControllerHandle,
+ &gEfiSimpleTextInProtocolGuid,
+ This->DriverBindingHandle,
+ ControllerHandle
+ );
}
return EFI_SUCCESS;
@@ -334,8 +307,7 @@ ConPlatformTextInDriverBindingStart (
reading Device Path, and installing Console Out Devcic GUID, Standard Error
Device GUID on ControllerHandle.
- If this devcie is not one hot-plug devce, append its device path into the
- console environment variables ConOutDev, ErrOutDev.
+ Append its device path into the console environment variables ConOutDev, ErrOutDev.
@param This Protocol instance pointer.
@param ControllerHandle Handle of device to bind driver to
@@ -416,95 +388,59 @@ ConPlatformTextOutDriverBindingStart (
}
//
- // Check the device path, if it is a hot plug device,
- // do not put the device path into ConOutDev and ErrOutDev,
- // and install gEfiConsoleOutDeviceGuid to the device handle directly.
- // The policy is, make hot plug device plug in and play immediately.
+ // Append the device path to the ConOutDev and ErrOutDev environment variable.
+ // For GOP device path, append the sibling device path as well.
//
- if (IsHotPlugDevice (DevicePath)) {
+ if (!ConPlatformUpdateGopCandidate (DevicePath)) {
+ ConPlatformUpdateDeviceVariable (
+ L"ConOutDev",
+ DevicePath,
+ Append
+ );
+ //
+ // Then append the device path to the ErrOutDev environment variable
+ //
+ ConPlatformUpdateDeviceVariable (
+ L"ErrOutDev",
+ DevicePath,
+ Append
+ );
+ }
+
+ //
+ // If the device path is an instance in the ConOut environment
+ variable, // then install EfiConsoleOutDeviceGuid onto
+ ControllerHandle // if (IsInConOutVariable) {
+ NeedClose = FALSE;
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ &ControllerHandle,
+ &gEfiConsoleOutDeviceGuid,
+ NULL,
+ NULL
+ );
+ }
+ //
+ // If the device path is an instance in the ErrOut environment
+ variable, // then install EfiStandardErrorDeviceGuid onto
+ ControllerHandle // if (IsInErrOutVariable) {
+ NeedClose = FALSE;
gBS->InstallMultipleProtocolInterfaces (
&ControllerHandle,
- &gEfiConsoleOutDeviceGuid,
+ &gEfiStandardErrorDeviceGuid,
NULL,
NULL
);
- //
- // Append the device path to ConOutDev only if it is in ConOut variable.
- //
- if (IsInConOutVariable) {
- ConPlatformUpdateDeviceVariable (
- L"ConOutDev",
- DevicePath,
- Append
- );
- }
- //
- // Append the device path to ErrOutDev only if it is in ErrOut variable.
- //
- if (IsInErrOutVariable) {
- ConPlatformUpdateDeviceVariable (
- L"ErrOutDev",
- DevicePath,
- Append
- );
- }
- } else {
- //
- // If it is not a hot-plug device, append the device path to
- // the ConOutDev and ErrOutDev environment variable.
- // For GOP device path, append the sibling device path as well.
- //
- if (!ConPlatformUpdateGopCandidate (DevicePath)) {
- ConPlatformUpdateDeviceVariable (
- L"ConOutDev",
- DevicePath,
- Append
- );
- //
- // Then append the device path to the ErrOutDev environment variable
- //
- ConPlatformUpdateDeviceVariable (
- L"ErrOutDev",
- DevicePath,
- Append
- );
- }
-
- //
- // If the device path is an instance in the ConOut environment variable,
- // then install EfiConsoleOutDeviceGuid onto ControllerHandle
- //
- if (IsInConOutVariable) {
- NeedClose = FALSE;
- Status = gBS->InstallMultipleProtocolInterfaces (
- &ControllerHandle,
- &gEfiConsoleOutDeviceGuid,
- NULL,
- NULL
- );
- }
- //
- // If the device path is an instance in the ErrOut environment variable,
- // then install EfiStandardErrorDeviceGuid onto ControllerHandle
- //
- if (IsInErrOutVariable) {
- NeedClose = FALSE;
- gBS->InstallMultipleProtocolInterfaces (
- &ControllerHandle,
- &gEfiStandardErrorDeviceGuid,
- NULL,
- NULL
- );
- }
+ }
- if (NeedClose) {
- gBS->CloseProtocol (
- ControllerHandle,
- &gEfiSimpleTextOutProtocolGuid,
- This->DriverBindingHandle,
- ControllerHandle
- );
- }
+ if (NeedClose) {
+ gBS->CloseProtocol (
+ ControllerHandle,
+ &gEfiSimpleTextOutProtocolGuid,
+ This->DriverBindingHandle,
+ ControllerHandle
+ );
}
return EFI_SUCCESS;
@@ -822,6 +758,273 @@ IsGopSibling (
return (BOOLEAN) (CompareMem (Left, Right, (UINTN) NodeLeft - (UINTN) Left) == 0); }
+/**
+ Check whether a USB device match the specified USB Class device path.
+This
+ function follows "Load Option Processing" behavior in UEFI specification.
+
+ @param UsbIo USB I/O protocol associated with the USB device.
+ @param UsbClass The USB Class device path to match.
+
+ @retval TRUE The USB device match the USB Class device path.
+ @retval FALSE The USB device does not match the USB Class device path.
+
+**/
+BOOLEAN
+MatchUsbClass (
+ IN EFI_USB_IO_PROTOCOL *UsbIo,
+ IN USB_CLASS_DEVICE_PATH *UsbClass
+ )
+{
+ EFI_STATUS Status;
+ EFI_USB_DEVICE_DESCRIPTOR DevDesc;
+ EFI_USB_INTERFACE_DESCRIPTOR IfDesc;
+ UINT8 DeviceClass;
+ UINT8 DeviceSubClass;
+ UINT8 DeviceProtocol;
+
+ if ((DevicePathType (UsbClass) != MESSAGING_DEVICE_PATH) ||
+ (DevicePathSubType (UsbClass) != MSG_USB_CLASS_DP)){
+ return FALSE;
+ }
+
+ //
+ // Check Vendor Id and Product Id.
+ //
+ Status = UsbIo->UsbGetDeviceDescriptor (UsbIo, &DevDesc); if
+ (EFI_ERROR (Status)) {
+ return FALSE;
+ }
+
+ if ((UsbClass->VendorId != 0xffff) &&
+ (UsbClass->VendorId != DevDesc.IdVendor)) {
+ return FALSE;
+ }
+
+ if ((UsbClass->ProductId != 0xffff) &&
+ (UsbClass->ProductId != DevDesc.IdProduct)) {
+ return FALSE;
+ }
+
+ DeviceClass = DevDesc.DeviceClass;
+ DeviceSubClass = DevDesc.DeviceSubClass; DeviceProtocol =
+ DevDesc.DeviceProtocol; if (DeviceClass == 0) {
+ //
+ // If Class in Device Descriptor is set to 0, use the Class, SubClass and
+ // Protocol in Interface Descriptor instead.
+ //
+ Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &IfDesc);
+ if (EFI_ERROR (Status)) {
+ return FALSE;
+ }
+
+ DeviceClass = IfDesc.InterfaceClass;
+ DeviceSubClass = IfDesc.InterfaceSubClass;
+ DeviceProtocol = IfDesc.InterfaceProtocol; }
+
+ //
+ // Check Class, SubClass and Protocol.
+ //
+ if ((UsbClass->DeviceClass != 0xff) &&
+ (UsbClass->DeviceClass != DeviceClass)) {
+ return FALSE;
+ }
+
+ if ((UsbClass->DeviceSubClass != 0xff) &&
+ (UsbClass->DeviceSubClass != DeviceSubClass)) {
+ return FALSE;
+ }
+
+ if ((UsbClass->DeviceProtocol != 0xff) &&
+ (UsbClass->DeviceProtocol != DeviceProtocol)) {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/**
+ Check whether a USB device match the specified USB WWID device path.
+This
+ function follows "Load Option Processing" behavior in UEFI specification.
+
+ @param UsbIo USB I/O protocol associated with the USB device.
+ @param UsbWwid The USB WWID device path to match.
+
+ @retval TRUE The USB device match the USB WWID device path.
+ @retval FALSE The USB device does not match the USB WWID device path.
+
+**/
+BOOLEAN
+MatchUsbWwid (
+ IN EFI_USB_IO_PROTOCOL *UsbIo,
+ IN USB_WWID_DEVICE_PATH *UsbWwid
+ )
+{
+ EFI_STATUS Status;
+ EFI_USB_DEVICE_DESCRIPTOR DevDesc;
+ EFI_USB_INTERFACE_DESCRIPTOR IfDesc;
+ UINT16 *LangIdTable;
+ UINT16 TableSize;
+ UINT16 Index;
+ CHAR16 *CompareStr;
+ UINTN CompareLen;
+ CHAR16 *SerialNumberStr;
+ UINTN Length;
+
+ if ((DevicePathType (UsbWwid) != MESSAGING_DEVICE_PATH) ||
+ (DevicePathSubType (UsbWwid) != MSG_USB_WWID_DP)) {
+ return FALSE;
+ }
+
+ //
+ // Check Vendor Id and Product Id.
+ //
+ Status = UsbIo->UsbGetDeviceDescriptor (UsbIo, &DevDesc); if
+ (EFI_ERROR (Status)) {
+ return FALSE;
+ }
+ if ((DevDesc.IdVendor != UsbWwid->VendorId) ||
+ (DevDesc.IdProduct != UsbWwid->ProductId)) {
+ return FALSE;
+ }
+
+ //
+ // Check Interface Number.
+ //
+ Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &IfDesc); if
+ (EFI_ERROR (Status)) {
+ return FALSE;
+ }
+ if (IfDesc.InterfaceNumber != UsbWwid->InterfaceNumber) {
+ return FALSE;
+ }
+
+ //
+ // Check Serial Number.
+ //
+ if (DevDesc.StrSerialNumber == 0) {
+ return FALSE;
+ }
+
+ //
+ // Get all supported languages.
+ //
+ TableSize = 0;
+ LangIdTable = NULL;
+ Status = UsbIo->UsbGetSupportedLanguages (UsbIo, &LangIdTable,
+ &TableSize); if (EFI_ERROR (Status) || (TableSize == 0) || (LangIdTable == NULL)) {
+ return FALSE;
+ }
+
+ //
+ // Serial number in USB WWID device path is the last 64-or-less UTF-16 characters.
+ //
+ CompareStr = (CHAR16 *) (UINTN) (UsbWwid + 1); CompareLen =
+ (DevicePathNodeLength (UsbWwid) - sizeof (USB_WWID_DEVICE_PATH)) /
+ sizeof (CHAR16); if (CompareStr[CompareLen - 1] == L'\0') {
+ CompareLen--;
+ }
+
+ //
+ // Compare serial number in each supported language.
+ //
+ for (Index = 0; Index < TableSize / sizeof (UINT16); Index++) {
+ SerialNumberStr = NULL;
+ Status = UsbIo->UsbGetStringDescriptor (
+ UsbIo,
+ LangIdTable[Index],
+ DevDesc.StrSerialNumber,
+ &SerialNumberStr
+ );
+ if (EFI_ERROR (Status) || (SerialNumberStr == NULL)) {
+ continue;
+ }
+
+ Length = StrLen (SerialNumberStr);
+ if ((Length >= CompareLen) &&
+ (CompareMem (SerialNumberStr + Length - CompareLen, CompareStr, CompareLen * sizeof (CHAR16)) == 0)) {
+ FreePool (SerialNumberStr);
+ return TRUE;
+ }
+
+ FreePool (SerialNumberStr);
+ }
+
+ return FALSE;
+}
+
+/**
+ Compare whether a full console device path matches a USB shortform device path.
+
+ @param[in] FullPath Full console device path.
+ @param[in] ShortformPath Short-form device path. Short-form device node may in the beginning or in the middle.
+
+ @retval TRUE The full console device path matches the short-form device path.
+ @retval FALSE The full console device path doesn't match the short-form device path.
+**/
+BOOLEAN
+MatchUsbShortformDevicePath (
+ IN EFI_DEVICE_PATH_PROTOCOL *FullPath,
+ IN EFI_DEVICE_PATH_PROTOCOL *ShortformPath
+ )
+{
+ EFI_STATUS Status;
+ EFI_DEVICE_PATH_PROTOCOL *ShortformNode;
+ UINTN ParentDevicePathSize;
+ EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath;
+ EFI_USB_IO_PROTOCOL *UsbIo;
+ EFI_HANDLE Handle;
+
+ for ( ShortformNode = ShortformPath
+ ; !IsDevicePathEnd (ShortformNode)
+ ; ShortformNode = NextDevicePathNode (ShortformNode)
+ ) {
+ if ((DevicePathType (ShortformNode) == MESSAGING_DEVICE_PATH) &&
+ ((DevicePathSubType (ShortformNode) == MSG_USB_CLASS_DP) ||
+ (DevicePathSubType (ShortformNode) == MSG_USB_WWID_DP))
+ ) {
+ break;
+ }
+ }
+
+ //
+ // Skip further compare when it's not a shortform device path.
+ //
+ if (IsDevicePathEnd (ShortformNode)) {
+ return FALSE;
+ }
+
+ //
+ // Compare the parent device path when the ShortformPath doesn't start with short-form node.
+ //
+ ParentDevicePathSize = (UINTN) ShortformNode - (UINTN) ShortformPath;
+ RemainingDevicePath = FullPath;
+ Status = gBS->LocateDevicePath (&gEfiUsbIoProtocolGuid, &RemainingDevicePath, &Handle);
+ if (EFI_ERROR (Status)) {
+ return FALSE;
+ }
+ if (ParentDevicePathSize != 0) {
+ if ((ParentDevicePathSize > (UINTN) RemainingDevicePath - (UINTN) FullPath) ||
+ (CompareMem (FullPath, ShortformPath, ParentDevicePathSize) != 0)) {
+ return FALSE;
+ }
+ }
+
+ //
+ // Compar the USB layer.
+ //
+ Status = gBS->HandleProtocol(
+ Handle,
+ &gEfiUsbIoProtocolGuid,
+ (VOID **) &UsbIo
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ return MatchUsbClass (UsbIo, (USB_CLASS_DEVICE_PATH *)ShortformNode) ||
+ MatchUsbWwid (UsbIo, (USB_WWID_DEVICE_PATH *)ShortformNode); }
+
/**
Function compares a device path data structure to that of all the nodes of a
second device path instance.
@@ -881,7 +1084,8 @@ ConPlatformMatchDevicePaths (
// Search for the match of 'Single' in 'Multi'
//
while (DevicePathInst != NULL) {
- if ((CompareMem (Single, DevicePathInst, Size) == 0) || IsGopSibling (Single, DevicePathInst)) {
+ if ((CompareMem (Single, DevicePathInst, Size) == 0) ||
+ IsGopSibling (Single, DevicePathInst) ||
+ MatchUsbShortformDevicePath (Single, DevicePathInst)) {
if (!Delete) {
//
// If Delete is FALSE, return EFI_SUCCESS if Single is found in Multi.
@@ -1029,53 +1233,6 @@ ConPlatformUpdateDeviceVariable (
return Status;
}
-/**
- Check if the device supports hot-plug through its device path.
-
- This function could be updated to check more types of Hot Plug devices.
- Currently, it checks USB and PCCard device.
-
- @param DevicePath Pointer to device's device path.
-
- @retval TRUE The devcie is a hot-plug device
- @retval FALSE The devcie is not a hot-plug device.
-
-**/
-BOOLEAN
-IsHotPlugDevice (
- IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
- )
-{
- EFI_DEVICE_PATH_PROTOCOL *CheckDevicePath;
-
- CheckDevicePath = DevicePath;
- while (!IsDevicePathEnd (CheckDevicePath)) {
- //
- // Check device whether is hot plug device or not throught Device Path
- //
- if ((DevicePathType (CheckDevicePath) == MESSAGING_DEVICE_PATH) &&
- (DevicePathSubType (CheckDevicePath) == MSG_USB_DP ||
- DevicePathSubType (CheckDevicePath) == MSG_USB_CLASS_DP ||
- DevicePathSubType (CheckDevicePath) == MSG_USB_WWID_DP)) {
- //
- // If Device is USB device
- //
- return TRUE;
- }
- if ((DevicePathType (CheckDevicePath) == HARDWARE_DEVICE_PATH) &&
- (DevicePathSubType (CheckDevicePath) == HW_PCCARD_DP)) {
- //
- // If Device is PCCard
- //
- return TRUE;
- }
-
- CheckDevicePath = NextDevicePathNode (CheckDevicePath);
- }
-
- return FALSE;
-}
-
/**
Update ConOutDev and ErrOutDev variables to add the device path of
GOP controller itself and the sibling controllers.
diff --git a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.h b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.h
index 1d5f11e94c..b5465f09f1 100644
--- a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.h
+++ b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.h
@@ -21,6 +21,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Protocol/DevicePath.h>
#include <Protocol/SimpleTextIn.h>
#include <Protocol/PciIo.h>
+#include <Protocol/UsbIo.h>
#include <Protocol/GraphicsOutput.h>
#include <Guid/GlobalVariable.h>
@@ -119,8 +120,7 @@ ConPlatformTextOutDriverBindingSupported (
Start this driver on ControllerHandle by opening Simple Text Input Protocol,
reading Device Path, and installing Console In Devcice GUID on ControllerHandle.
- If this devcie is not one hot-plug devce, append its device path into the
- console environment variables ConInDev.
+ Append its device path into the console environment variables ConInDev.
@param This Protocol instance pointer.
@param ControllerHandle Handle of device to bind driver to
@@ -147,8 +147,7 @@ ConPlatformTextInDriverBindingStart (
reading Device Path, and installing Console Out Devcic GUID, Standard Error
Device GUID on ControllerHandle.
- If this devcie is not one hot-plug devce, append its device path into the
- console environment variables ConOutDev, StdErrDev.
+ Append its device path into the console environment variables ConOutDev, ErrOutDev.
@param This Protocol instance pointer.
@param ControllerHandle Handle of device to bind driver to
@@ -294,23 +293,6 @@ ConPlatformUpdateDeviceVariable (
IN CONPLATFORM_VAR_OPERATION Operation
);
-/**
- Check if the device supports hot-plug through its device path.
-
- This function could be updated to check more types of Hot Plug devices.
- Currently, it checks USB and PCCard device.
-
- @param DevicePath Pointer to device's device path.
-
- @retval TRUE The devcie is a hot-plug device
- @retval FALSE The devcie is not a hot-plug device.
-
-**/
-BOOLEAN
-IsHotPlugDevice (
- IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
- );
-
//
// EFI Component Name Functions
//
diff --git a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf
index 176fd2fa0b..19b3f5c443 100644
--- a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf
+++ b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf
@@ -94,6 +94,7 @@ [Protocols]
gEfiSimpleTextOutProtocolGuid ## TO_START
gEfiPciIoProtocolGuid ## SOMETIMES_CONSUMES
gEfiGraphicsOutputProtocolGuid ## SOMETIMES_CONSUMES
+ gEfiUsbIoProtocolGuid ## SOMETIMES_CONSUMES
[UserExtensions.TianoCore."ExtraFiles"]
ConPlatformDxeExtra.uni
--
2.16.1.windows.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2018-09-12 1:47 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-25 5:44 [PATCH] MdeModulePkg/ConPlatform: Support short-form USB device path Ruiyu Ni
2018-04-25 14:16 ` Laszlo Ersek
2018-04-26 6:52 ` Ni, Ruiyu
2018-04-26 7:04 ` Zeng, Star
2018-05-02 7:50 ` Ni, Ruiyu
-- strict thread matches above, loose matches on Subject: below --
2018-09-10 10:05 Ruiyu Ni
2018-09-12 1:47 ` Zeng, Star
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox