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"
12 EFI_DRIVER_BINDING_PROTOCOL gConPlatformTextInDriverBinding
= {
13 ConPlatformTextInDriverBindingSupported
,
14 ConPlatformTextInDriverBindingStart
,
15 ConPlatformTextInDriverBindingStop
,
21 EFI_DRIVER_BINDING_PROTOCOL gConPlatformTextOutDriverBinding
= {
22 ConPlatformTextOutDriverBindingSupported
,
23 ConPlatformTextOutDriverBindingStart
,
24 ConPlatformTextOutDriverBindingStop
,
31 Entrypoint of this module.
33 This function is the entrypoint of this module. It installs Driver Binding
34 Protocols together with Component Name Protocols.
36 @param ImageHandle The firmware allocated handle for the EFI image.
37 @param SystemTable A pointer to the EFI System Table.
39 @retval EFI_SUCCESS The entry point is executed successfully.
44 InitializeConPlatform (
45 IN EFI_HANDLE ImageHandle
,
46 IN EFI_SYSTEM_TABLE
*SystemTable
51 Status
= EfiLibInstallDriverBindingComponentName2 (
54 &gConPlatformTextInDriverBinding
,
56 &gConPlatformComponentName
,
57 &gConPlatformComponentName2
59 ASSERT_EFI_ERROR (Status
);
61 Status
= EfiLibInstallDriverBindingComponentName2 (
64 &gConPlatformTextOutDriverBinding
,
66 &gConPlatformComponentName
,
67 &gConPlatformComponentName2
69 ASSERT_EFI_ERROR (Status
);
75 Test to see if EFI_SIMPLE_TEXT_INPUT_PROTOCOL is supported on ControllerHandle.
77 @param This Protocol instance pointer.
78 @param ControllerHandle Handle of device to test.
79 @param RemainingDevicePath Optional parameter use to pick a specific child
82 @retval EFI_SUCCESS This driver supports this device.
83 @retval other This driver does not support this device.
88 ConPlatformTextInDriverBindingSupported (
89 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
90 IN EFI_HANDLE ControllerHandle
,
91 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
94 return ConPlatformDriverBindingSupported (
97 &gEfiSimpleTextInProtocolGuid
102 Test to see if EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL is supported on ControllerHandle.
104 @param This Protocol instance pointer.
105 @param ControllerHandle Handle of device to test.
106 @param RemainingDevicePath Optional parameter use to pick a specific child
109 @retval EFI_SUCCESS This driver supports this device.
110 @retval other This driver does not support this device.
115 ConPlatformTextOutDriverBindingSupported (
116 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
117 IN EFI_HANDLE ControllerHandle
,
118 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
121 return ConPlatformDriverBindingSupported (
124 &gEfiSimpleTextOutProtocolGuid
129 Test to see if the specified protocol is supported on ControllerHandle.
131 @param This Protocol instance pointer.
132 @param ControllerHandle Handle of device to test.
133 @param ProtocolGuid The specfic protocol.
135 @retval EFI_SUCCESS This driver supports this device.
136 @retval other This driver does not support this device.
140 ConPlatformDriverBindingSupported (
141 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
142 IN EFI_HANDLE ControllerHandle
,
143 IN EFI_GUID
*ProtocolGuid
150 // Test to see if this is a physical device by checking if
151 // it has a Device Path Protocol.
153 Status
= gBS
->OpenProtocol (
155 &gEfiDevicePathProtocolGuid
,
157 This
->DriverBindingHandle
,
159 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
161 if (EFI_ERROR (Status
)) {
166 // Test to see if this device supports the specified Protocol.
168 Status
= gBS
->OpenProtocol (
172 This
->DriverBindingHandle
,
174 EFI_OPEN_PROTOCOL_BY_DRIVER
176 if (EFI_ERROR (Status
)) {
183 This
->DriverBindingHandle
,
191 Start this driver on the device for console input.
193 Start this driver on ControllerHandle by opening Simple Text Input Protocol,
194 reading Device Path, and installing Console In Devcice GUID on ControllerHandle.
196 Append its device path into the console environment variables ConInDev.
198 @param This Protocol instance pointer.
199 @param ControllerHandle Handle of device to bind driver to
200 @param RemainingDevicePath Optional parameter use to pick a specific child
203 @retval EFI_SUCCESS This driver is added to ControllerHandle
204 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
205 @retval other This driver does not support this device.
210 ConPlatformTextInDriverBindingStart (
211 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
212 IN EFI_HANDLE ControllerHandle
,
213 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
217 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
218 EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*TextIn
;
219 BOOLEAN IsInConInVariable
;
222 // Get the Device Path Protocol so the environment variables can be updated
224 Status
= gBS
->OpenProtocol (
226 &gEfiDevicePathProtocolGuid
,
227 (VOID
**)&DevicePath
,
228 This
->DriverBindingHandle
,
230 EFI_OPEN_PROTOCOL_GET_PROTOCOL
232 if (EFI_ERROR (Status
)) {
237 // Open the Simple Text Input Protocol BY_DRIVER
239 Status
= gBS
->OpenProtocol (
241 &gEfiSimpleTextInProtocolGuid
,
243 This
->DriverBindingHandle
,
245 EFI_OPEN_PROTOCOL_BY_DRIVER
247 if (EFI_ERROR (Status
)) {
252 // Check if the device path is in ConIn Variable
254 IsInConInVariable
= FALSE
;
255 Status
= ConPlatformUpdateDeviceVariable (
260 if (!EFI_ERROR (Status
)) {
261 IsInConInVariable
= TRUE
;
265 // Append the device path to the ConInDev environment variable
267 ConPlatformUpdateDeviceVariable (
274 // If the device path is an instance in the ConIn environment variable,
275 // then install EfiConsoleInDeviceGuid onto ControllerHandle
277 if (IsInConInVariable
) {
278 gBS
->InstallMultipleProtocolInterfaces (
280 &gEfiConsoleInDeviceGuid
,
287 &gEfiSimpleTextInProtocolGuid
,
288 This
->DriverBindingHandle
,
297 Start this driver on the device for console output and standard error output.
299 Start this driver on ControllerHandle by opening Simple Text Output Protocol,
300 reading Device Path, and installing Console Out Devcic GUID, Standard Error
301 Device GUID on ControllerHandle.
303 Append its device path into the console environment variables ConOutDev, ErrOutDev.
305 @param This Protocol instance pointer.
306 @param ControllerHandle Handle of device to bind driver to
307 @param RemainingDevicePath Optional parameter use to pick a specific child
310 @retval EFI_SUCCESS This driver is added to ControllerHandle
311 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
312 @retval other This driver does not support this device
317 ConPlatformTextOutDriverBindingStart (
318 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
319 IN EFI_HANDLE ControllerHandle
,
320 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
324 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
325 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*TextOut
;
327 BOOLEAN IsInConOutVariable
;
328 BOOLEAN IsInErrOutVariable
;
333 // Get the Device Path Protocol so the environment variables can be updated
335 Status
= gBS
->OpenProtocol (
337 &gEfiDevicePathProtocolGuid
,
338 (VOID
**)&DevicePath
,
339 This
->DriverBindingHandle
,
341 EFI_OPEN_PROTOCOL_GET_PROTOCOL
343 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
)) {
363 // Check if the device path is in ConOut & ErrOut Variable
365 IsInConOutVariable
= FALSE
;
366 Status
= ConPlatformUpdateDeviceVariable (
371 if (!EFI_ERROR (Status
)) {
372 IsInConOutVariable
= TRUE
;
375 IsInErrOutVariable
= FALSE
;
376 Status
= ConPlatformUpdateDeviceVariable (
381 if (!EFI_ERROR (Status
)) {
382 IsInErrOutVariable
= TRUE
;
386 // Append the device path to the ConOutDev and ErrOutDev environment variable.
387 // For GOP device path, append the sibling device path as well.
389 if (!ConPlatformUpdateGopCandidate (DevicePath
)) {
390 ConPlatformUpdateDeviceVariable (
396 // Then append the device path to the ErrOutDev environment variable
398 ConPlatformUpdateDeviceVariable (
406 // If the device path is an instance in the ConOut environment variable,
407 // then install EfiConsoleOutDeviceGuid onto ControllerHandle
409 if (IsInConOutVariable
) {
411 Status
= gBS
->InstallMultipleProtocolInterfaces (
413 &gEfiConsoleOutDeviceGuid
,
420 // If the device path is an instance in the ErrOut environment variable,
421 // then install EfiStandardErrorDeviceGuid onto ControllerHandle
423 if (IsInErrOutVariable
) {
425 gBS
->InstallMultipleProtocolInterfaces (
427 &gEfiStandardErrorDeviceGuid
,
436 &gEfiSimpleTextOutProtocolGuid
,
437 This
->DriverBindingHandle
,
446 Stop this driver on ControllerHandle by removing Console In Devcice GUID
447 and closing the Simple Text Input protocol on ControllerHandle.
449 @param This Protocol instance pointer.
450 @param ControllerHandle Handle of device to stop driver on
451 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
452 children is zero stop the entire bus driver.
453 @param ChildHandleBuffer List of Child Handles to Stop.
455 @retval EFI_SUCCESS This driver is removed ControllerHandle
456 @retval other This driver was not removed from this device
461 ConPlatformTextInDriverBindingStop (
462 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
463 IN EFI_HANDLE ControllerHandle
,
464 IN UINTN NumberOfChildren
,
465 IN EFI_HANDLE
*ChildHandleBuffer
469 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
472 // Get the Device Path Protocol firstly
474 Status
= gBS
->OpenProtocol (
476 &gEfiDevicePathProtocolGuid
,
477 (VOID
**)&DevicePath
,
478 This
->DriverBindingHandle
,
480 EFI_OPEN_PROTOCOL_GET_PROTOCOL
483 // If there is device path on ControllerHandle
485 if (!EFI_ERROR (Status
)) {
487 // Remove DevicePath from ConInDev if exists.
489 ConPlatformUpdateDeviceVariable (
497 // Uninstall the Console Device GUIDs from Controller Handle
499 ConPlatformUnInstallProtocol (
502 &gEfiConsoleInDeviceGuid
506 // Close the Simple Text Input Protocol
510 &gEfiSimpleTextInProtocolGuid
,
511 This
->DriverBindingHandle
,
519 Stop this driver on ControllerHandle by removing Console Out Devcice GUID
520 and closing the Simple Text Output protocol on ControllerHandle.
522 @param This Protocol instance pointer.
523 @param ControllerHandle Handle of device to stop driver on
524 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
525 children is zero stop the entire bus driver.
526 @param ChildHandleBuffer List of Child Handles to Stop.
528 @retval EFI_SUCCESS This driver is removed ControllerHandle
529 @retval other This driver was not removed from this device
534 ConPlatformTextOutDriverBindingStop (
535 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
536 IN EFI_HANDLE ControllerHandle
,
537 IN UINTN NumberOfChildren
,
538 IN EFI_HANDLE
*ChildHandleBuffer
542 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
545 // Get the Device Path Protocol firstly
547 Status
= gBS
->OpenProtocol (
549 &gEfiDevicePathProtocolGuid
,
550 (VOID
**)&DevicePath
,
551 This
->DriverBindingHandle
,
553 EFI_OPEN_PROTOCOL_GET_PROTOCOL
555 if (!EFI_ERROR (Status
)) {
557 // Remove DevicePath from ConOutDev and ErrOutDev if exists.
559 ConPlatformUpdateDeviceVariable (
564 ConPlatformUpdateDeviceVariable (
572 // Uninstall the Console Device GUIDs from Controller Handle
574 ConPlatformUnInstallProtocol (
577 &gEfiConsoleOutDeviceGuid
580 ConPlatformUnInstallProtocol (
583 &gEfiStandardErrorDeviceGuid
587 // Close the Simple Text Output Protocol
591 &gEfiSimpleTextOutProtocolGuid
,
592 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
) {
684 // Read variable into the allocated buffer.
686 Status
= gRT
->GetVariable (
688 &gEfiGlobalVariableGuid
,
693 if (EFI_ERROR (Status
)) {
696 // To make sure Buffer is NULL if any error occurs.
706 Function returns TRUE when the two input device paths point to the two
707 GOP child handles that have the same parent.
709 @param Left A pointer to a device path data structure.
710 @param Right A pointer to a device path data structure.
712 @retval TRUE Left and Right share the same parent.
713 @retval FALSE Left and Right don't share the same parent or either of them is not
718 IN EFI_DEVICE_PATH_PROTOCOL
*Left
,
719 IN EFI_DEVICE_PATH_PROTOCOL
*Right
722 EFI_DEVICE_PATH_PROTOCOL
*NodeLeft
;
723 EFI_DEVICE_PATH_PROTOCOL
*NodeRight
;
725 for (NodeLeft
= Left
; !IsDevicePathEndType (NodeLeft
); NodeLeft
= NextDevicePathNode (NodeLeft
)) {
726 if (((DevicePathType (NodeLeft
) == ACPI_DEVICE_PATH
) && (DevicePathSubType (NodeLeft
) == ACPI_ADR_DP
)) ||
727 ((DevicePathType (NodeLeft
) == HARDWARE_DEVICE_PATH
) && (DevicePathSubType (NodeLeft
) == HW_CONTROLLER_DP
) &&
728 (DevicePathType (NextDevicePathNode (NodeLeft
)) == ACPI_DEVICE_PATH
) && (DevicePathSubType (NextDevicePathNode (NodeLeft
)) == ACPI_ADR_DP
)))
734 if (IsDevicePathEndType (NodeLeft
)) {
738 for (NodeRight
= Right
; !IsDevicePathEndType (NodeRight
); NodeRight
= NextDevicePathNode (NodeRight
)) {
739 if (((DevicePathType (NodeRight
) == ACPI_DEVICE_PATH
) && (DevicePathSubType (NodeRight
) == ACPI_ADR_DP
)) ||
740 ((DevicePathType (NodeRight
) == HARDWARE_DEVICE_PATH
) && (DevicePathSubType (NodeRight
) == HW_CONTROLLER_DP
) &&
741 (DevicePathType (NextDevicePathNode (NodeRight
)) == ACPI_DEVICE_PATH
) && (DevicePathSubType (NextDevicePathNode (NodeRight
)) == ACPI_ADR_DP
)))
747 if (IsDevicePathEndType (NodeRight
)) {
751 if (((UINTN
)NodeLeft
- (UINTN
)Left
) != ((UINTN
)NodeRight
- (UINTN
)Right
)) {
755 return (BOOLEAN
)(CompareMem (Left
, Right
, (UINTN
)NodeLeft
- (UINTN
)Left
) == 0);
759 Check whether a USB device match the specified USB Class device path. This
760 function follows "Load Option Processing" behavior in UEFI specification.
762 @param UsbIo USB I/O protocol associated with the USB device.
763 @param UsbClass The USB Class device path to match.
765 @retval TRUE The USB device match the USB Class device path.
766 @retval FALSE The USB device does not match the USB Class device path.
771 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
772 IN USB_CLASS_DEVICE_PATH
*UsbClass
776 EFI_USB_DEVICE_DESCRIPTOR DevDesc
;
777 EFI_USB_INTERFACE_DESCRIPTOR IfDesc
;
779 UINT8 DeviceSubClass
;
780 UINT8 DeviceProtocol
;
782 if ((DevicePathType (UsbClass
) != MESSAGING_DEVICE_PATH
) ||
783 (DevicePathSubType (UsbClass
) != MSG_USB_CLASS_DP
))
789 // Check Vendor Id and Product Id.
791 Status
= UsbIo
->UsbGetDeviceDescriptor (UsbIo
, &DevDesc
);
792 if (EFI_ERROR (Status
)) {
796 if ((UsbClass
->VendorId
!= 0xffff) &&
797 (UsbClass
->VendorId
!= DevDesc
.IdVendor
))
802 if ((UsbClass
->ProductId
!= 0xffff) &&
803 (UsbClass
->ProductId
!= DevDesc
.IdProduct
))
808 DeviceClass
= DevDesc
.DeviceClass
;
809 DeviceSubClass
= DevDesc
.DeviceSubClass
;
810 DeviceProtocol
= DevDesc
.DeviceProtocol
;
811 if (DeviceClass
== 0) {
813 // If Class in Device Descriptor is set to 0, use the Class, SubClass and
814 // Protocol in Interface Descriptor instead.
816 Status
= UsbIo
->UsbGetInterfaceDescriptor (UsbIo
, &IfDesc
);
817 if (EFI_ERROR (Status
)) {
821 DeviceClass
= IfDesc
.InterfaceClass
;
822 DeviceSubClass
= IfDesc
.InterfaceSubClass
;
823 DeviceProtocol
= IfDesc
.InterfaceProtocol
;
827 // Check Class, SubClass and Protocol.
829 if ((UsbClass
->DeviceClass
!= 0xff) &&
830 (UsbClass
->DeviceClass
!= DeviceClass
))
835 if ((UsbClass
->DeviceSubClass
!= 0xff) &&
836 (UsbClass
->DeviceSubClass
!= DeviceSubClass
))
841 if ((UsbClass
->DeviceProtocol
!= 0xff) &&
842 (UsbClass
->DeviceProtocol
!= DeviceProtocol
))
851 Check whether a USB device match the specified USB WWID device path. This
852 function follows "Load Option Processing" behavior in UEFI specification.
854 @param UsbIo USB I/O protocol associated with the USB device.
855 @param UsbWwid The USB WWID device path to match.
857 @retval TRUE The USB device match the USB WWID device path.
858 @retval FALSE The USB device does not match the USB WWID device path.
863 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
864 IN USB_WWID_DEVICE_PATH
*UsbWwid
868 EFI_USB_DEVICE_DESCRIPTOR DevDesc
;
869 EFI_USB_INTERFACE_DESCRIPTOR IfDesc
;
875 CHAR16
*SerialNumberStr
;
878 if ((DevicePathType (UsbWwid
) != MESSAGING_DEVICE_PATH
) ||
879 (DevicePathSubType (UsbWwid
) != MSG_USB_WWID_DP
))
885 // Check Vendor Id and Product Id.
887 Status
= UsbIo
->UsbGetDeviceDescriptor (UsbIo
, &DevDesc
);
888 if (EFI_ERROR (Status
)) {
892 if ((DevDesc
.IdVendor
!= UsbWwid
->VendorId
) ||
893 (DevDesc
.IdProduct
!= UsbWwid
->ProductId
))
899 // Check Interface Number.
901 Status
= UsbIo
->UsbGetInterfaceDescriptor (UsbIo
, &IfDesc
);
902 if (EFI_ERROR (Status
)) {
906 if (IfDesc
.InterfaceNumber
!= UsbWwid
->InterfaceNumber
) {
911 // Check Serial Number.
913 if (DevDesc
.StrSerialNumber
== 0) {
918 // Get all supported languages.
922 Status
= UsbIo
->UsbGetSupportedLanguages (UsbIo
, &LangIdTable
, &TableSize
);
923 if (EFI_ERROR (Status
) || (TableSize
== 0) || (LangIdTable
== NULL
)) {
928 // Serial number in USB WWID device path is the last 64-or-less UTF-16 characters.
930 CompareStr
= (CHAR16
*)(UINTN
)(UsbWwid
+ 1);
931 CompareLen
= (DevicePathNodeLength (UsbWwid
) - sizeof (USB_WWID_DEVICE_PATH
)) / sizeof (CHAR16
);
932 if (CompareStr
[CompareLen
- 1] == L
'\0') {
937 // Compare serial number in each supported language.
939 for (Index
= 0; Index
< TableSize
/ sizeof (UINT16
); Index
++) {
940 SerialNumberStr
= NULL
;
941 Status
= UsbIo
->UsbGetStringDescriptor (
944 DevDesc
.StrSerialNumber
,
947 if (EFI_ERROR (Status
) || (SerialNumberStr
== NULL
)) {
951 Length
= StrLen (SerialNumberStr
);
952 if ((Length
>= CompareLen
) &&
953 (CompareMem (SerialNumberStr
+ Length
- CompareLen
, CompareStr
, CompareLen
* sizeof (CHAR16
)) == 0))
955 FreePool (SerialNumberStr
);
959 FreePool (SerialNumberStr
);
966 Compare whether a full console device path matches a USB shortform device path.
968 @param[in] FullPath Full console device path.
969 @param[in] ShortformPath Short-form device path. Short-form device node may in the beginning or in the middle.
971 @retval TRUE The full console device path matches the short-form device path.
972 @retval FALSE The full console device path doesn't match the short-form device path.
975 MatchUsbShortformDevicePath (
976 IN EFI_DEVICE_PATH_PROTOCOL
*FullPath
,
977 IN EFI_DEVICE_PATH_PROTOCOL
*ShortformPath
981 EFI_DEVICE_PATH_PROTOCOL
*ShortformNode
;
982 UINTN ParentDevicePathSize
;
983 EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
;
984 EFI_USB_IO_PROTOCOL
*UsbIo
;
987 for ( ShortformNode
= ShortformPath
988 ; !IsDevicePathEnd (ShortformNode
)
989 ; ShortformNode
= NextDevicePathNode (ShortformNode
)
992 if ((DevicePathType (ShortformNode
) == MESSAGING_DEVICE_PATH
) &&
993 ((DevicePathSubType (ShortformNode
) == MSG_USB_CLASS_DP
) ||
994 (DevicePathSubType (ShortformNode
) == MSG_USB_WWID_DP
))
1002 // Skip further compare when it's not a shortform device path.
1004 if (IsDevicePathEnd (ShortformNode
)) {
1009 // Compare the parent device path when the ShortformPath doesn't start with short-form node.
1011 ParentDevicePathSize
= (UINTN
)ShortformNode
- (UINTN
)ShortformPath
;
1012 RemainingDevicePath
= FullPath
;
1013 Status
= gBS
->LocateDevicePath (&gEfiUsbIoProtocolGuid
, &RemainingDevicePath
, &Handle
);
1014 if (EFI_ERROR (Status
)) {
1018 if (ParentDevicePathSize
!= 0) {
1019 if ((ParentDevicePathSize
> (UINTN
)RemainingDevicePath
- (UINTN
)FullPath
) ||
1020 (CompareMem (FullPath
, ShortformPath
, ParentDevicePathSize
) != 0))
1027 // Compar the USB layer.
1029 Status
= gBS
->HandleProtocol (
1031 &gEfiUsbIoProtocolGuid
,
1034 ASSERT_EFI_ERROR (Status
);
1036 return MatchUsbClass (UsbIo
, (USB_CLASS_DEVICE_PATH
*)ShortformNode
) ||
1037 MatchUsbWwid (UsbIo
, (USB_WWID_DEVICE_PATH
*)ShortformNode
);
1041 Function compares a device path data structure to that of all the nodes of a
1042 second device path instance.
1044 @param Multi A pointer to a multi-instance device path data structure.
1045 @param Single A pointer to a single-instance device path data structure.
1046 @param NewDevicePath If Delete is TRUE, this parameter must not be null, and it
1047 points to the remaining device path data structure.
1048 (remaining device path = Multi - Single.)
1049 @param Delete If TRUE, means removing Single from Multi.
1050 If FALSE, the routine just check whether Single matches
1051 with any instance in Multi.
1053 @retval EFI_SUCCESS If the Single is contained within Multi.
1054 @retval EFI_NOT_FOUND If the Single is not contained within Multi.
1055 @retval EFI_INVALID_PARAMETER Multi is NULL.
1056 @retval EFI_INVALID_PARAMETER Single is NULL.
1057 @retval EFI_INVALID_PARAMETER NewDevicePath is NULL when Delete is TRUE.
1061 ConPlatformMatchDevicePaths (
1062 IN EFI_DEVICE_PATH_PROTOCOL
*Multi
,
1063 IN EFI_DEVICE_PATH_PROTOCOL
*Single
,
1064 OUT EFI_DEVICE_PATH_PROTOCOL
**NewDevicePath OPTIONAL
,
1068 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
1069 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath1
;
1070 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath2
;
1071 EFI_DEVICE_PATH_PROTOCOL
*DevicePathInst
;
1075 // The passed in DevicePath should not be NULL
1077 if ((Multi
== NULL
) || (Single
== NULL
)) {
1078 return EFI_INVALID_PARAMETER
;
1082 // If performing Delete operation, the NewDevicePath must not be NULL.
1085 if (NewDevicePath
== NULL
) {
1086 return EFI_INVALID_PARAMETER
;
1090 TempDevicePath1
= NULL
;
1093 DevicePathInst
= GetNextDevicePathInstance (&DevicePath
, &Size
);
1096 // Search for the match of 'Single' in 'Multi'
1098 while (DevicePathInst
!= NULL
) {
1099 if ((CompareMem (Single
, DevicePathInst
, Size
) == 0) ||
1100 IsGopSibling (Single
, DevicePathInst
) || MatchUsbShortformDevicePath (Single
, DevicePathInst
))
1104 // If Delete is FALSE, return EFI_SUCCESS if Single is found in Multi.
1106 FreePool (DevicePathInst
);
1112 // If the node of Multi does not match Single, then added it back to the result.
1113 // That is, the node matching Single will be dropped and deleted from result.
1115 TempDevicePath2
= AppendDevicePathInstance (
1119 if (TempDevicePath1
!= NULL
) {
1120 FreePool (TempDevicePath1
);
1123 TempDevicePath1
= TempDevicePath2
;
1127 FreePool (DevicePathInst
);
1128 DevicePathInst
= GetNextDevicePathInstance (&DevicePath
, &Size
);
1133 // Return the new device path data structure with specified node deleted.
1135 *NewDevicePath
= TempDevicePath1
;
1139 return EFI_NOT_FOUND
;
1143 Update console environment variables.
1145 @param VariableName Console environment variables, ConOutDev, ConInDev
1146 ErrOutDev, ConIn ,ConOut or ErrOut.
1147 @param DevicePath Console devcie's device path.
1148 @param Operation Variable operations, including APPEND, CHECK and DELETE.
1150 @retval EFI_SUCCESS Variable operates successfully.
1151 @retval EFI_OUT_OF_RESOURCES If variable cannot be appended.
1152 @retval other Variable updating failed.
1156 ConPlatformUpdateDeviceVariable (
1157 IN CHAR16
*VariableName
,
1158 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
1159 IN CONPLATFORM_VAR_OPERATION Operation
1163 EFI_DEVICE_PATH_PROTOCOL
*VariableDevicePath
;
1164 EFI_DEVICE_PATH_PROTOCOL
*NewVariableDevicePath
;
1166 VariableDevicePath
= NULL
;
1167 NewVariableDevicePath
= NULL
;
1170 // Get Variable according to variable name.
1171 // The memory for Variable is allocated within ConPlatformGetVarible(),
1172 // it is the caller's responsibility to free the memory before return.
1174 VariableDevicePath
= ConPlatformGetVariable (VariableName
);
1176 if (Operation
!= Delete
) {
1178 // Match specified DevicePath in Console Variable.
1180 Status
= ConPlatformMatchDevicePaths (
1187 if ((Operation
== Check
) || (!EFI_ERROR (Status
))) {
1189 // Branch here includes 2 cases:
1190 // 1. Operation is CHECK, simply return Status.
1191 // 2. Operation is APPEND, and device path already exists in variable, also return.
1193 if (VariableDevicePath
!= NULL
) {
1194 FreePool (VariableDevicePath
);
1201 // We reach here to append a device path that does not exist in variable.
1203 Status
= EFI_SUCCESS
;
1204 NewVariableDevicePath
= AppendDevicePathInstance (
1208 if (NewVariableDevicePath
== NULL
) {
1209 Status
= EFI_OUT_OF_RESOURCES
;
1213 // We reach here to remove DevicePath from the environment variable that
1214 // is a multi-instance device path.
1216 Status
= ConPlatformMatchDevicePaths (
1219 &NewVariableDevicePath
,
1224 if (VariableDevicePath
!= NULL
) {
1225 FreePool (VariableDevicePath
);
1228 if (EFI_ERROR (Status
)) {
1232 if (NewVariableDevicePath
!= NULL
) {
1234 // Update Console Environment Variable.
1236 Status
= gRT
->SetVariable (
1238 &gEfiGlobalVariableGuid
,
1239 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
1240 GetDevicePathSize (NewVariableDevicePath
),
1241 NewVariableDevicePath
1244 FreePool (NewVariableDevicePath
);
1251 Update ConOutDev and ErrOutDev variables to add the device path of
1252 GOP controller itself and the sibling controllers.
1254 @param DevicePath Pointer to device's device path.
1256 @retval TRUE The devcie is a GOP device.
1257 @retval FALSE The devcie is not a GOP device.
1261 ConPlatformUpdateGopCandidate (
1262 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
1266 EFI_HANDLE PciHandle
;
1267 EFI_HANDLE GopHandle
;
1268 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
1271 // Check whether it's a GOP device.
1273 TempDevicePath
= DevicePath
;
1274 Status
= gBS
->LocateDevicePath (&gEfiGraphicsOutputProtocolGuid
, &TempDevicePath
, &GopHandle
);
1275 if (EFI_ERROR (Status
)) {
1280 // Get the parent PciIo handle in order to find all the children
1282 Status
= gBS
->LocateDevicePath (&gEfiPciIoProtocolGuid
, &DevicePath
, &PciHandle
);
1283 if (EFI_ERROR (Status
)) {
1287 TempDevicePath
= EfiBootManagerGetGopDevicePath (PciHandle
);
1288 if (TempDevicePath
!= NULL
) {
1289 ConPlatformUpdateDeviceVariable (L
"ConOutDev", TempDevicePath
, Append
);
1290 ConPlatformUpdateDeviceVariable (L
"ErrOutDev", TempDevicePath
, Append
);