2 Console Platform DXE Driver, install Console Device Guids and update Console
5 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "ConPlatform.h"
13 EFI_DRIVER_BINDING_PROTOCOL gConPlatformTextInDriverBinding
= {
14 ConPlatformTextInDriverBindingSupported
,
15 ConPlatformTextInDriverBindingStart
,
16 ConPlatformTextInDriverBindingStop
,
22 EFI_DRIVER_BINDING_PROTOCOL gConPlatformTextOutDriverBinding
= {
23 ConPlatformTextOutDriverBindingSupported
,
24 ConPlatformTextOutDriverBindingStart
,
25 ConPlatformTextOutDriverBindingStop
,
32 Entrypoint of this module.
34 This function is the entrypoint of this module. It installs Driver Binding
35 Protocols together with Component Name Protocols.
37 @param ImageHandle The firmware allocated handle for the EFI image.
38 @param SystemTable A pointer to the EFI System Table.
40 @retval EFI_SUCCESS The entry point is executed successfully.
45 InitializeConPlatform(
46 IN EFI_HANDLE ImageHandle
,
47 IN EFI_SYSTEM_TABLE
*SystemTable
52 Status
= EfiLibInstallDriverBindingComponentName2 (
55 &gConPlatformTextInDriverBinding
,
57 &gConPlatformComponentName
,
58 &gConPlatformComponentName2
60 ASSERT_EFI_ERROR (Status
);
62 Status
= EfiLibInstallDriverBindingComponentName2 (
65 &gConPlatformTextOutDriverBinding
,
67 &gConPlatformComponentName
,
68 &gConPlatformComponentName2
70 ASSERT_EFI_ERROR (Status
);
77 Test to see if EFI_SIMPLE_TEXT_INPUT_PROTOCOL is supported on ControllerHandle.
79 @param This Protocol instance pointer.
80 @param ControllerHandle Handle of device to test.
81 @param RemainingDevicePath Optional parameter use to pick a specific child
84 @retval EFI_SUCCESS This driver supports this device.
85 @retval other This driver does not support this device.
90 ConPlatformTextInDriverBindingSupported (
91 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
92 IN EFI_HANDLE ControllerHandle
,
93 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
96 return ConPlatformDriverBindingSupported (
99 &gEfiSimpleTextInProtocolGuid
105 Test to see if EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL is supported on ControllerHandle.
107 @param This Protocol instance pointer.
108 @param ControllerHandle Handle of device to test.
109 @param RemainingDevicePath Optional parameter use to pick a specific child
112 @retval EFI_SUCCESS This driver supports this device.
113 @retval other This driver does not support this device.
118 ConPlatformTextOutDriverBindingSupported (
119 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
120 IN EFI_HANDLE ControllerHandle
,
121 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
124 return ConPlatformDriverBindingSupported (
127 &gEfiSimpleTextOutProtocolGuid
133 Test to see if the specified protocol is supported on ControllerHandle.
135 @param This Protocol instance pointer.
136 @param ControllerHandle Handle of device to test.
137 @param ProtocolGuid The specfic protocol.
139 @retval EFI_SUCCESS This driver supports this device.
140 @retval other This driver does not support this device.
144 ConPlatformDriverBindingSupported (
145 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
146 IN EFI_HANDLE ControllerHandle
,
147 IN EFI_GUID
*ProtocolGuid
154 // Test to see if this is a physical device by checking if
155 // it has a Device Path Protocol.
157 Status
= gBS
->OpenProtocol (
159 &gEfiDevicePathProtocolGuid
,
161 This
->DriverBindingHandle
,
163 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
165 if (EFI_ERROR (Status
)) {
169 // Test to see if this device supports the specified Protocol.
171 Status
= gBS
->OpenProtocol (
174 (VOID
**) &Interface
,
175 This
->DriverBindingHandle
,
177 EFI_OPEN_PROTOCOL_BY_DRIVER
179 if (EFI_ERROR (Status
)) {
186 This
->DriverBindingHandle
,
194 Start this driver on the device for console input.
196 Start this driver on ControllerHandle by opening Simple Text Input Protocol,
197 reading Device Path, and installing Console In Devcice GUID on ControllerHandle.
199 Append its device path into the console environment variables ConInDev.
201 @param This Protocol instance pointer.
202 @param ControllerHandle Handle of device to bind driver to
203 @param RemainingDevicePath Optional parameter use to pick a specific child
206 @retval EFI_SUCCESS This driver is added to ControllerHandle
207 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
208 @retval other This driver does not support this device.
213 ConPlatformTextInDriverBindingStart (
214 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
215 IN EFI_HANDLE ControllerHandle
,
216 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
220 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
221 EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*TextIn
;
222 BOOLEAN IsInConInVariable
;
225 // Get the Device Path Protocol so the environment variables can be updated
227 Status
= gBS
->OpenProtocol (
229 &gEfiDevicePathProtocolGuid
,
230 (VOID
**) &DevicePath
,
231 This
->DriverBindingHandle
,
233 EFI_OPEN_PROTOCOL_GET_PROTOCOL
235 if (EFI_ERROR (Status
)) {
239 // Open the Simple Text Input Protocol BY_DRIVER
241 Status
= gBS
->OpenProtocol (
243 &gEfiSimpleTextInProtocolGuid
,
245 This
->DriverBindingHandle
,
247 EFI_OPEN_PROTOCOL_BY_DRIVER
249 if (EFI_ERROR (Status
)) {
253 // Check if the device path is in ConIn Variable
255 IsInConInVariable
= FALSE
;
256 Status
= ConPlatformUpdateDeviceVariable (
261 if (!EFI_ERROR (Status
)) {
262 IsInConInVariable
= TRUE
;
266 // Append the device path to the ConInDev environment variable
268 ConPlatformUpdateDeviceVariable (
275 // If the device path is an instance in the ConIn environment variable,
276 // then install EfiConsoleInDeviceGuid onto ControllerHandle
278 if (IsInConInVariable
) {
279 gBS
->InstallMultipleProtocolInterfaces (
281 &gEfiConsoleInDeviceGuid
,
288 &gEfiSimpleTextInProtocolGuid
,
289 This
->DriverBindingHandle
,
298 Start this driver on the device for console output and standard error output.
300 Start this driver on ControllerHandle by opening Simple Text Output Protocol,
301 reading Device Path, and installing Console Out Devcic GUID, Standard Error
302 Device GUID on ControllerHandle.
304 Append its device path into the console environment variables ConOutDev, ErrOutDev.
306 @param This Protocol instance pointer.
307 @param ControllerHandle Handle of device to bind driver to
308 @param RemainingDevicePath Optional parameter use to pick a specific child
311 @retval EFI_SUCCESS This driver is added to ControllerHandle
312 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
313 @retval other This driver does not support this device
318 ConPlatformTextOutDriverBindingStart (
319 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
320 IN EFI_HANDLE ControllerHandle
,
321 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
325 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
326 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*TextOut
;
328 BOOLEAN IsInConOutVariable
;
329 BOOLEAN IsInErrOutVariable
;
334 // Get the Device Path Protocol so the environment variables can be updated
336 Status
= gBS
->OpenProtocol (
338 &gEfiDevicePathProtocolGuid
,
339 (VOID
**) &DevicePath
,
340 This
->DriverBindingHandle
,
342 EFI_OPEN_PROTOCOL_GET_PROTOCOL
344 if (EFI_ERROR (Status
)) {
348 // Open the Simple Text Output Protocol BY_DRIVER
350 Status
= gBS
->OpenProtocol (
352 &gEfiSimpleTextOutProtocolGuid
,
354 This
->DriverBindingHandle
,
356 EFI_OPEN_PROTOCOL_BY_DRIVER
358 if (EFI_ERROR (Status
)) {
362 // Check if the device path is in ConOut & ErrOut Variable
364 IsInConOutVariable
= FALSE
;
365 Status
= ConPlatformUpdateDeviceVariable (
370 if (!EFI_ERROR (Status
)) {
371 IsInConOutVariable
= TRUE
;
374 IsInErrOutVariable
= FALSE
;
375 Status
= ConPlatformUpdateDeviceVariable (
380 if (!EFI_ERROR (Status
)) {
381 IsInErrOutVariable
= TRUE
;
385 // Append the device path to the ConOutDev and ErrOutDev environment variable.
386 // For GOP device path, append the sibling device path as well.
388 if (!ConPlatformUpdateGopCandidate (DevicePath
)) {
389 ConPlatformUpdateDeviceVariable (
395 // Then append the device path to the ErrOutDev environment variable
397 ConPlatformUpdateDeviceVariable (
405 // If the device path is an instance in the ConOut environment variable,
406 // then install EfiConsoleOutDeviceGuid onto ControllerHandle
408 if (IsInConOutVariable
) {
410 Status
= gBS
->InstallMultipleProtocolInterfaces (
412 &gEfiConsoleOutDeviceGuid
,
418 // If the device path is an instance in the ErrOut environment variable,
419 // then install EfiStandardErrorDeviceGuid onto ControllerHandle
421 if (IsInErrOutVariable
) {
423 gBS
->InstallMultipleProtocolInterfaces (
425 &gEfiStandardErrorDeviceGuid
,
434 &gEfiSimpleTextOutProtocolGuid
,
435 This
->DriverBindingHandle
,
444 Stop this driver on ControllerHandle by removing Console In Devcice GUID
445 and closing the Simple Text Input protocol on ControllerHandle.
447 @param This Protocol instance pointer.
448 @param ControllerHandle Handle of device to stop driver on
449 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
450 children is zero stop the entire bus driver.
451 @param ChildHandleBuffer List of Child Handles to Stop.
453 @retval EFI_SUCCESS This driver is removed ControllerHandle
454 @retval other This driver was not removed from this device
459 ConPlatformTextInDriverBindingStop (
460 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
461 IN EFI_HANDLE ControllerHandle
,
462 IN UINTN NumberOfChildren
,
463 IN EFI_HANDLE
*ChildHandleBuffer
467 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
470 // Get the Device Path Protocol firstly
472 Status
= gBS
->OpenProtocol (
474 &gEfiDevicePathProtocolGuid
,
475 (VOID
**) &DevicePath
,
476 This
->DriverBindingHandle
,
478 EFI_OPEN_PROTOCOL_GET_PROTOCOL
481 // If there is device path on ControllerHandle
483 if (!EFI_ERROR (Status
)) {
485 // Remove DevicePath from ConInDev if exists.
487 ConPlatformUpdateDeviceVariable (
495 // Uninstall the Console Device GUIDs from Controller Handle
497 ConPlatformUnInstallProtocol (
500 &gEfiConsoleInDeviceGuid
504 // Close the Simple Text Input Protocol
508 &gEfiSimpleTextInProtocolGuid
,
509 This
->DriverBindingHandle
,
518 Stop this driver on ControllerHandle by removing Console Out Devcice GUID
519 and closing the Simple Text Output protocol on ControllerHandle.
521 @param This Protocol instance pointer.
522 @param ControllerHandle Handle of device to stop driver on
523 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
524 children is zero stop the entire bus driver.
525 @param ChildHandleBuffer List of Child Handles to Stop.
527 @retval EFI_SUCCESS This driver is removed ControllerHandle
528 @retval other This driver was not removed from this device
533 ConPlatformTextOutDriverBindingStop (
534 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
535 IN EFI_HANDLE ControllerHandle
,
536 IN UINTN NumberOfChildren
,
537 IN EFI_HANDLE
*ChildHandleBuffer
541 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
544 // Get the Device Path Protocol firstly
546 Status
= gBS
->OpenProtocol (
548 &gEfiDevicePathProtocolGuid
,
549 (VOID
**) &DevicePath
,
550 This
->DriverBindingHandle
,
552 EFI_OPEN_PROTOCOL_GET_PROTOCOL
554 if (!EFI_ERROR (Status
)) {
556 // Remove DevicePath from ConOutDev and ErrOutDev if exists.
558 ConPlatformUpdateDeviceVariable (
563 ConPlatformUpdateDeviceVariable (
571 // Uninstall the Console Device GUIDs from Controller Handle
573 ConPlatformUnInstallProtocol (
576 &gEfiConsoleOutDeviceGuid
579 ConPlatformUnInstallProtocol (
582 &gEfiStandardErrorDeviceGuid
586 // Close the Simple Text Output Protocol
590 &gEfiSimpleTextOutProtocolGuid
,
591 This
->DriverBindingHandle
,
600 Uninstall the specified protocol.
602 @param This Protocol instance pointer.
603 @param Handle Handle of device to uninstall protocol on.
604 @param ProtocolGuid The specified protocol need to be uninstalled.
608 ConPlatformUnInstallProtocol (
609 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
610 IN EFI_HANDLE Handle
,
611 IN EFI_GUID
*ProtocolGuid
616 Status
= gBS
->OpenProtocol (
620 This
->DriverBindingHandle
,
622 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
625 if (!EFI_ERROR (Status
)) {
626 gBS
->UninstallMultipleProtocolInterfaces (
638 Get the necessary size of buffer and read the variable.
640 First get the necessary size of buffer. Then read the
641 EFI variable (Name) and return a dynamically allocated
642 buffer. On failure return NULL.
644 @param Name String part of EFI variable name
646 @return Dynamically allocated memory that contains a copy of the EFI variable.
647 Caller is repsoncible freeing the buffer. Return NULL means Variable
652 ConPlatformGetVariable (
664 // Test to see if the variable exists. If it doesn't, return NULL.
666 Status
= gRT
->GetVariable (
668 &gEfiGlobalVariableGuid
,
674 if (Status
== EFI_BUFFER_TOO_SMALL
) {
676 // Allocate the buffer to return
678 Buffer
= AllocatePool (BufferSize
);
679 if (Buffer
== NULL
) {
683 // Read variable into the allocated buffer.
685 Status
= gRT
->GetVariable (
687 &gEfiGlobalVariableGuid
,
692 if (EFI_ERROR (Status
)) {
695 // To make sure Buffer is NULL if any error occurs.
705 Function returns TRUE when the two input device paths point to the two
706 GOP child handles that have the same parent.
708 @param Left A pointer to a device path data structure.
709 @param Right A pointer to a device path data structure.
711 @retval TRUE Left and Right share the same parent.
712 @retval FALSE Left and Right don't share the same parent or either of them is not
717 IN EFI_DEVICE_PATH_PROTOCOL
*Left
,
718 IN EFI_DEVICE_PATH_PROTOCOL
*Right
721 EFI_DEVICE_PATH_PROTOCOL
*NodeLeft
;
722 EFI_DEVICE_PATH_PROTOCOL
*NodeRight
;
724 for (NodeLeft
= Left
; !IsDevicePathEndType (NodeLeft
); NodeLeft
= NextDevicePathNode (NodeLeft
)) {
725 if ((DevicePathType (NodeLeft
) == ACPI_DEVICE_PATH
&& DevicePathSubType (NodeLeft
) == ACPI_ADR_DP
) ||
726 (DevicePathType (NodeLeft
) == HARDWARE_DEVICE_PATH
&& DevicePathSubType (NodeLeft
) == HW_CONTROLLER_DP
&&
727 DevicePathType (NextDevicePathNode (NodeLeft
)) == ACPI_DEVICE_PATH
&& DevicePathSubType (NextDevicePathNode (NodeLeft
)) == ACPI_ADR_DP
)) {
732 if (IsDevicePathEndType (NodeLeft
)) {
736 for (NodeRight
= Right
; !IsDevicePathEndType (NodeRight
); NodeRight
= NextDevicePathNode (NodeRight
)) {
737 if ((DevicePathType (NodeRight
) == ACPI_DEVICE_PATH
&& DevicePathSubType (NodeRight
) == ACPI_ADR_DP
) ||
738 (DevicePathType (NodeRight
) == HARDWARE_DEVICE_PATH
&& DevicePathSubType (NodeRight
) == HW_CONTROLLER_DP
&&
739 DevicePathType (NextDevicePathNode (NodeRight
)) == ACPI_DEVICE_PATH
&& DevicePathSubType (NextDevicePathNode (NodeRight
)) == ACPI_ADR_DP
)) {
744 if (IsDevicePathEndType (NodeRight
)) {
748 if (((UINTN
) NodeLeft
- (UINTN
) Left
) != ((UINTN
) NodeRight
- (UINTN
) Right
)) {
752 return (BOOLEAN
) (CompareMem (Left
, Right
, (UINTN
) NodeLeft
- (UINTN
) Left
) == 0);
756 Check whether a USB device match the specified USB Class device path. This
757 function follows "Load Option Processing" behavior in UEFI specification.
759 @param UsbIo USB I/O protocol associated with the USB device.
760 @param UsbClass The USB Class device path to match.
762 @retval TRUE The USB device match the USB Class device path.
763 @retval FALSE The USB device does not match the USB Class device path.
768 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
769 IN USB_CLASS_DEVICE_PATH
*UsbClass
773 EFI_USB_DEVICE_DESCRIPTOR DevDesc
;
774 EFI_USB_INTERFACE_DESCRIPTOR IfDesc
;
776 UINT8 DeviceSubClass
;
777 UINT8 DeviceProtocol
;
779 if ((DevicePathType (UsbClass
) != MESSAGING_DEVICE_PATH
) ||
780 (DevicePathSubType (UsbClass
) != MSG_USB_CLASS_DP
)){
785 // Check Vendor Id and Product Id.
787 Status
= UsbIo
->UsbGetDeviceDescriptor (UsbIo
, &DevDesc
);
788 if (EFI_ERROR (Status
)) {
792 if ((UsbClass
->VendorId
!= 0xffff) &&
793 (UsbClass
->VendorId
!= DevDesc
.IdVendor
)) {
797 if ((UsbClass
->ProductId
!= 0xffff) &&
798 (UsbClass
->ProductId
!= DevDesc
.IdProduct
)) {
802 DeviceClass
= DevDesc
.DeviceClass
;
803 DeviceSubClass
= DevDesc
.DeviceSubClass
;
804 DeviceProtocol
= DevDesc
.DeviceProtocol
;
805 if (DeviceClass
== 0) {
807 // If Class in Device Descriptor is set to 0, use the Class, SubClass and
808 // Protocol in Interface Descriptor instead.
810 Status
= UsbIo
->UsbGetInterfaceDescriptor (UsbIo
, &IfDesc
);
811 if (EFI_ERROR (Status
)) {
815 DeviceClass
= IfDesc
.InterfaceClass
;
816 DeviceSubClass
= IfDesc
.InterfaceSubClass
;
817 DeviceProtocol
= IfDesc
.InterfaceProtocol
;
821 // Check Class, SubClass and Protocol.
823 if ((UsbClass
->DeviceClass
!= 0xff) &&
824 (UsbClass
->DeviceClass
!= DeviceClass
)) {
828 if ((UsbClass
->DeviceSubClass
!= 0xff) &&
829 (UsbClass
->DeviceSubClass
!= DeviceSubClass
)) {
833 if ((UsbClass
->DeviceProtocol
!= 0xff) &&
834 (UsbClass
->DeviceProtocol
!= DeviceProtocol
)) {
842 Check whether a USB device match the specified USB WWID device path. This
843 function follows "Load Option Processing" behavior in UEFI specification.
845 @param UsbIo USB I/O protocol associated with the USB device.
846 @param UsbWwid The USB WWID device path to match.
848 @retval TRUE The USB device match the USB WWID device path.
849 @retval FALSE The USB device does not match the USB WWID device path.
854 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
855 IN USB_WWID_DEVICE_PATH
*UsbWwid
859 EFI_USB_DEVICE_DESCRIPTOR DevDesc
;
860 EFI_USB_INTERFACE_DESCRIPTOR IfDesc
;
866 CHAR16
*SerialNumberStr
;
869 if ((DevicePathType (UsbWwid
) != MESSAGING_DEVICE_PATH
) ||
870 (DevicePathSubType (UsbWwid
) != MSG_USB_WWID_DP
)) {
875 // Check Vendor Id and Product Id.
877 Status
= UsbIo
->UsbGetDeviceDescriptor (UsbIo
, &DevDesc
);
878 if (EFI_ERROR (Status
)) {
881 if ((DevDesc
.IdVendor
!= UsbWwid
->VendorId
) ||
882 (DevDesc
.IdProduct
!= UsbWwid
->ProductId
)) {
887 // Check Interface Number.
889 Status
= UsbIo
->UsbGetInterfaceDescriptor (UsbIo
, &IfDesc
);
890 if (EFI_ERROR (Status
)) {
893 if (IfDesc
.InterfaceNumber
!= UsbWwid
->InterfaceNumber
) {
898 // Check Serial Number.
900 if (DevDesc
.StrSerialNumber
== 0) {
905 // Get all supported languages.
909 Status
= UsbIo
->UsbGetSupportedLanguages (UsbIo
, &LangIdTable
, &TableSize
);
910 if (EFI_ERROR (Status
) || (TableSize
== 0) || (LangIdTable
== NULL
)) {
915 // Serial number in USB WWID device path is the last 64-or-less UTF-16 characters.
917 CompareStr
= (CHAR16
*) (UINTN
) (UsbWwid
+ 1);
918 CompareLen
= (DevicePathNodeLength (UsbWwid
) - sizeof (USB_WWID_DEVICE_PATH
)) / sizeof (CHAR16
);
919 if (CompareStr
[CompareLen
- 1] == L
'\0') {
924 // Compare serial number in each supported language.
926 for (Index
= 0; Index
< TableSize
/ sizeof (UINT16
); Index
++) {
927 SerialNumberStr
= NULL
;
928 Status
= UsbIo
->UsbGetStringDescriptor (
931 DevDesc
.StrSerialNumber
,
934 if (EFI_ERROR (Status
) || (SerialNumberStr
== NULL
)) {
938 Length
= StrLen (SerialNumberStr
);
939 if ((Length
>= CompareLen
) &&
940 (CompareMem (SerialNumberStr
+ Length
- CompareLen
, CompareStr
, CompareLen
* sizeof (CHAR16
)) == 0)) {
941 FreePool (SerialNumberStr
);
945 FreePool (SerialNumberStr
);
952 Compare whether a full console device path matches a USB shortform device path.
954 @param[in] FullPath Full console device path.
955 @param[in] ShortformPath Short-form device path. Short-form device node may in the beginning or in the middle.
957 @retval TRUE The full console device path matches the short-form device path.
958 @retval FALSE The full console device path doesn't match the short-form device path.
961 MatchUsbShortformDevicePath (
962 IN EFI_DEVICE_PATH_PROTOCOL
*FullPath
,
963 IN EFI_DEVICE_PATH_PROTOCOL
*ShortformPath
967 EFI_DEVICE_PATH_PROTOCOL
*ShortformNode
;
968 UINTN ParentDevicePathSize
;
969 EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
;
970 EFI_USB_IO_PROTOCOL
*UsbIo
;
973 for ( ShortformNode
= ShortformPath
974 ; !IsDevicePathEnd (ShortformNode
)
975 ; ShortformNode
= NextDevicePathNode (ShortformNode
)
977 if ((DevicePathType (ShortformNode
) == MESSAGING_DEVICE_PATH
) &&
978 ((DevicePathSubType (ShortformNode
) == MSG_USB_CLASS_DP
) ||
979 (DevicePathSubType (ShortformNode
) == MSG_USB_WWID_DP
))
986 // Skip further compare when it's not a shortform device path.
988 if (IsDevicePathEnd (ShortformNode
)) {
993 // Compare the parent device path when the ShortformPath doesn't start with short-form node.
995 ParentDevicePathSize
= (UINTN
) ShortformNode
- (UINTN
) ShortformPath
;
996 RemainingDevicePath
= FullPath
;
997 Status
= gBS
->LocateDevicePath (&gEfiUsbIoProtocolGuid
, &RemainingDevicePath
, &Handle
);
998 if (EFI_ERROR (Status
)) {
1001 if (ParentDevicePathSize
!= 0) {
1002 if ((ParentDevicePathSize
> (UINTN
) RemainingDevicePath
- (UINTN
) FullPath
) ||
1003 (CompareMem (FullPath
, ShortformPath
, ParentDevicePathSize
) != 0)) {
1009 // Compar the USB layer.
1011 Status
= gBS
->HandleProtocol(
1013 &gEfiUsbIoProtocolGuid
,
1016 ASSERT_EFI_ERROR (Status
);
1018 return MatchUsbClass (UsbIo
, (USB_CLASS_DEVICE_PATH
*)ShortformNode
) ||
1019 MatchUsbWwid (UsbIo
, (USB_WWID_DEVICE_PATH
*)ShortformNode
);
1023 Function compares a device path data structure to that of all the nodes of a
1024 second device path instance.
1026 @param Multi A pointer to a multi-instance device path data structure.
1027 @param Single A pointer to a single-instance device path data structure.
1028 @param NewDevicePath If Delete is TRUE, this parameter must not be null, and it
1029 points to the remaining device path data structure.
1030 (remaining device path = Multi - Single.)
1031 @param Delete If TRUE, means removing Single from Multi.
1032 If FALSE, the routine just check whether Single matches
1033 with any instance in Multi.
1035 @retval EFI_SUCCESS If the Single is contained within Multi.
1036 @retval EFI_NOT_FOUND If the Single is not contained within Multi.
1037 @retval EFI_INVALID_PARAMETER Multi is NULL.
1038 @retval EFI_INVALID_PARAMETER Single is NULL.
1039 @retval EFI_INVALID_PARAMETER NewDevicePath is NULL when Delete is TRUE.
1043 ConPlatformMatchDevicePaths (
1044 IN EFI_DEVICE_PATH_PROTOCOL
*Multi
,
1045 IN EFI_DEVICE_PATH_PROTOCOL
*Single
,
1046 OUT EFI_DEVICE_PATH_PROTOCOL
**NewDevicePath OPTIONAL
,
1050 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
1051 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath1
;
1052 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath2
;
1053 EFI_DEVICE_PATH_PROTOCOL
*DevicePathInst
;
1057 // The passed in DevicePath should not be NULL
1059 if ((Multi
== NULL
) || (Single
== NULL
)) {
1060 return EFI_INVALID_PARAMETER
;
1064 // If performing Delete operation, the NewDevicePath must not be NULL.
1067 if (NewDevicePath
== NULL
) {
1068 return EFI_INVALID_PARAMETER
;
1072 TempDevicePath1
= NULL
;
1075 DevicePathInst
= GetNextDevicePathInstance (&DevicePath
, &Size
);
1078 // Search for the match of 'Single' in 'Multi'
1080 while (DevicePathInst
!= NULL
) {
1081 if ((CompareMem (Single
, DevicePathInst
, Size
) == 0) ||
1082 IsGopSibling (Single
, DevicePathInst
) || MatchUsbShortformDevicePath (Single
, DevicePathInst
)) {
1085 // If Delete is FALSE, return EFI_SUCCESS if Single is found in Multi.
1087 FreePool (DevicePathInst
);
1093 // If the node of Multi does not match Single, then added it back to the result.
1094 // That is, the node matching Single will be dropped and deleted from result.
1096 TempDevicePath2
= AppendDevicePathInstance (
1100 if (TempDevicePath1
!= NULL
) {
1101 FreePool (TempDevicePath1
);
1103 TempDevicePath1
= TempDevicePath2
;
1107 FreePool (DevicePathInst
);
1108 DevicePathInst
= GetNextDevicePathInstance (&DevicePath
, &Size
);
1113 // Return the new device path data structure with specified node deleted.
1115 *NewDevicePath
= TempDevicePath1
;
1119 return EFI_NOT_FOUND
;
1123 Update console environment variables.
1125 @param VariableName Console environment variables, ConOutDev, ConInDev
1126 ErrOutDev, ConIn ,ConOut or ErrOut.
1127 @param DevicePath Console devcie's device path.
1128 @param Operation Variable operations, including APPEND, CHECK and DELETE.
1130 @retval EFI_SUCCESS Variable operates successfully.
1131 @retval EFI_OUT_OF_RESOURCES If variable cannot be appended.
1132 @retval other Variable updating failed.
1136 ConPlatformUpdateDeviceVariable (
1137 IN CHAR16
*VariableName
,
1138 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
1139 IN CONPLATFORM_VAR_OPERATION Operation
1143 EFI_DEVICE_PATH_PROTOCOL
*VariableDevicePath
;
1144 EFI_DEVICE_PATH_PROTOCOL
*NewVariableDevicePath
;
1146 VariableDevicePath
= NULL
;
1147 NewVariableDevicePath
= NULL
;
1150 // Get Variable according to variable name.
1151 // The memory for Variable is allocated within ConPlatformGetVarible(),
1152 // it is the caller's responsibility to free the memory before return.
1154 VariableDevicePath
= ConPlatformGetVariable (VariableName
);
1156 if (Operation
!= Delete
) {
1158 // Match specified DevicePath in Console Variable.
1160 Status
= ConPlatformMatchDevicePaths (
1167 if ((Operation
== Check
) || (!EFI_ERROR (Status
))) {
1169 // Branch here includes 2 cases:
1170 // 1. Operation is CHECK, simply return Status.
1171 // 2. Operation is APPEND, and device path already exists in variable, also return.
1173 if (VariableDevicePath
!= NULL
) {
1174 FreePool (VariableDevicePath
);
1180 // We reach here to append a device path that does not exist in variable.
1182 Status
= EFI_SUCCESS
;
1183 NewVariableDevicePath
= AppendDevicePathInstance (
1187 if (NewVariableDevicePath
== NULL
) {
1188 Status
= EFI_OUT_OF_RESOURCES
;
1193 // We reach here to remove DevicePath from the environment variable that
1194 // is a multi-instance device path.
1196 Status
= ConPlatformMatchDevicePaths (
1199 &NewVariableDevicePath
,
1204 if (VariableDevicePath
!= NULL
) {
1205 FreePool (VariableDevicePath
);
1208 if (EFI_ERROR (Status
)) {
1212 if (NewVariableDevicePath
!= NULL
) {
1214 // Update Console Environment Variable.
1216 Status
= gRT
->SetVariable (
1218 &gEfiGlobalVariableGuid
,
1219 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
1220 GetDevicePathSize (NewVariableDevicePath
),
1221 NewVariableDevicePath
1224 FreePool (NewVariableDevicePath
);
1231 Update ConOutDev and ErrOutDev variables to add the device path of
1232 GOP controller itself and the sibling controllers.
1234 @param DevicePath Pointer to device's device path.
1236 @retval TRUE The devcie is a GOP device.
1237 @retval FALSE The devcie is not a GOP device.
1241 ConPlatformUpdateGopCandidate (
1242 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
1246 EFI_HANDLE PciHandle
;
1247 EFI_HANDLE GopHandle
;
1248 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
1251 // Check whether it's a GOP device.
1253 TempDevicePath
= DevicePath
;
1254 Status
= gBS
->LocateDevicePath (&gEfiGraphicsOutputProtocolGuid
, &TempDevicePath
, &GopHandle
);
1255 if (EFI_ERROR (Status
)) {
1259 // Get the parent PciIo handle in order to find all the children
1261 Status
= gBS
->LocateDevicePath (&gEfiPciIoProtocolGuid
, &DevicePath
, &PciHandle
);
1262 if (EFI_ERROR (Status
)) {
1265 TempDevicePath
= EfiBootManagerGetGopDevicePath (PciHandle
);
1266 if (TempDevicePath
!= NULL
) {
1267 ConPlatformUpdateDeviceVariable (L
"ConOutDev", TempDevicePath
, Append
);
1268 ConPlatformUpdateDeviceVariable (L
"ErrOutDev", TempDevicePath
, Append
);