2 This module produces two driver health manager forms.
3 One will be used by BDS core to configure the Configured Required
4 driver health instances, the other will be automatically included by
7 Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
8 (C) Copyright 2018 Hewlett Packard Enterprise Development LP<BR>
9 SPDX-License-Identifier: BSD-2-Clause-Patent
13 #include "DriverHealthManagerDxe.h"
14 #include "DriverHealthManagerVfr.h"
16 EFI_HII_CONFIG_ACCESS_PROTOCOL mDriverHealthManagerConfigAccess
= {
17 DriverHealthManagerFakeExtractConfig
,
18 DriverHealthManagerFakeRouteConfig
,
19 DriverHealthManagerCallback
22 EFI_GUID mDriverHealthManagerForm
= DRIVER_HEALTH_MANAGER_FORMSET_GUID
;
24 FORM_DEVICE_PATH mDriverHealthManagerFormDevicePath
= {
30 (UINT8
)(sizeof (VENDOR_DEVICE_PATH
)),
31 (UINT8
)((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
38 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
40 (UINT8
)(END_DEVICE_PATH_LENGTH
),
41 (UINT8
)((END_DEVICE_PATH_LENGTH
) >> 8)
46 EFI_HII_HANDLE mDriverHealthManagerHiiHandle
;
47 EFI_BOOT_MANAGER_DRIVER_HEALTH_INFO
*mDriverHealthManagerHealthInfo
= NULL
;
48 UINTN mDriverHealthManagerHealthInfoCount
= 0;
49 EFI_HII_DATABASE_PROTOCOL
*mDriverHealthManagerDatabase
;
51 extern UINT8 DriverHealthManagerVfrBin
[];
52 extern UINT8 DriverHealthConfigureVfrBin
[];
55 This function allows a caller to extract the current configuration for one
56 or more named elements from the target driver.
59 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
60 @param Request A null-terminated Unicode string in <ConfigRequest> format.
61 @param Progress On return, points to a character in the Request string.
62 Points to the string's null terminator if request was successful.
63 Points to the most recent '&' before the first failing name/value
64 pair (or the beginning of the string if the failure is in the
65 first name/value pair) if the request was not successful.
66 @param Results A null-terminated Unicode string in <ConfigAltResp> format which
67 has all values filled in for the names in the Request string.
68 String to be allocated by the called function.
70 @retval EFI_SUCCESS The Results is filled with the requested values.
71 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
72 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
73 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
78 DriverHealthManagerFakeExtractConfig (
79 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
80 IN CONST EFI_STRING Request
,
81 OUT EFI_STRING
*Progress
,
82 OUT EFI_STRING
*Results
85 if ((Progress
== NULL
) || (Results
== NULL
)) {
86 return EFI_INVALID_PARAMETER
;
94 This function processes the results of changes in configuration.
97 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
98 @param Configuration A null-terminated Unicode string in <ConfigResp> format.
99 @param Progress A pointer to a string filled in with the offset of the most
100 recent '&' before the first failing name/value pair (or the
101 beginning of the string if the failure is in the first
102 name/value pair) or the terminating NULL if all was successful.
104 @retval EFI_SUCCESS The Results is processed successfully.
105 @retval EFI_INVALID_PARAMETER Configuration is NULL.
106 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
111 DriverHealthManagerFakeRouteConfig (
112 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
113 IN CONST EFI_STRING Configuration
,
114 OUT EFI_STRING
*Progress
117 if ((Configuration
== NULL
) || (Progress
== NULL
)) {
118 return EFI_INVALID_PARAMETER
;
121 *Progress
= Configuration
;
123 return EFI_NOT_FOUND
;
128 Install the health manager forms.
129 One will be used by BDS core to configure the Configured Required
130 driver health instances, the other will be automatically included by
133 @param ImageHandle The image handle.
134 @param SystemTable The system table.
136 @retval EFI_SUCEESS The health manager forms are successfully installed.
141 InitializeDriverHealthManager (
142 EFI_HANDLE ImageHandle
,
143 EFI_SYSTEM_TABLE
*SystemTable
149 Status
= gBS
->LocateProtocol (
150 &gEfiHiiDatabaseProtocolGuid
,
152 (VOID
**)&mDriverHealthManagerDatabase
154 ASSERT_EFI_ERROR (Status
);
157 Status
= gBS
->InstallMultipleProtocolInterfaces (
159 &gEfiDevicePathProtocolGuid
,
160 &mDriverHealthManagerFormDevicePath
,
161 &gEfiHiiConfigAccessProtocolGuid
,
162 &mDriverHealthManagerConfigAccess
,
165 ASSERT_EFI_ERROR (Status
);
168 // Publish Driver Health HII data.
170 mDriverHealthManagerHiiHandle
= HiiAddPackages (
173 DriverHealthManagerVfrBin
,
174 DriverHealthConfigureVfrBin
,
178 ASSERT (mDriverHealthManagerHiiHandle
!= NULL
);
185 Select the best matching language according to front page policy for best user experience.
187 This function supports both ISO 639-2 and RFC 4646 language codes, but language
188 code types may not be mixed in a single call to this function.
190 @param SupportedLanguages A pointer to a Null-terminated ASCII string that
191 contains a set of language codes in the format
192 specified by Iso639Language.
193 @param Iso639Language If TRUE, then all language codes are assumed to be
194 in ISO 639-2 format. If FALSE, then all language
195 codes are assumed to be in RFC 4646 language format.
197 @retval NULL The best matching language could not be found in SupportedLanguages.
198 @retval NULL There are not enough resources available to return the best matching
200 @retval Other A pointer to a Null-terminated ASCII string that is the best matching
201 language in SupportedLanguages.
204 DriverHealthManagerSelectBestLanguage (
205 IN CHAR8
*SupportedLanguages
,
206 IN BOOLEAN Iso639Language
209 CHAR8
*LanguageVariable
;
212 GetEfiGlobalVariable2 (Iso639Language
? L
"Lang" : L
"PlatformLang", (VOID
**)&LanguageVariable
, NULL
);
214 BestLanguage
= GetBestLanguage (
217 (LanguageVariable
!= NULL
) ? LanguageVariable
: "",
218 Iso639Language
? "eng" : "en-US",
221 if (LanguageVariable
!= NULL
) {
222 FreePool (LanguageVariable
);
230 This is an internal worker function to get the Component Name (2) protocol interface
231 and the language it supports.
233 @param ProtocolGuid A pointer to an EFI_GUID. It points to Component Name (2) protocol GUID.
234 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
235 @param ComponentName A pointer to the Component Name (2) protocol interface.
236 @param SupportedLanguage The best suitable language that matches the SupportedLangues interface for the
237 located Component Name (2) instance.
239 @retval EFI_SUCCESS The Component Name (2) protocol instance is successfully located and we find
240 the best matching language it support.
241 @retval EFI_UNSUPPORTED The input Language is not supported by the Component Name (2) protocol.
242 @retval Other Some error occurs when locating Component Name (2) protocol instance or finding
243 the supported language.
247 DriverHealthManagerGetComponentNameWorker (
248 IN EFI_GUID
*ProtocolGuid
,
249 IN EFI_HANDLE DriverBindingHandle
,
250 OUT EFI_COMPONENT_NAME_PROTOCOL
**ComponentName
,
251 OUT CHAR8
**SupportedLanguage
257 // Locate Component Name (2) protocol on the driver binging handle.
259 Status
= gBS
->OpenProtocol (
262 (VOID
**)ComponentName
,
265 EFI_OPEN_PROTOCOL_GET_PROTOCOL
267 if (EFI_ERROR (Status
)) {
272 // Apply shell policy to select the best language.
274 *SupportedLanguage
= DriverHealthManagerSelectBestLanguage (
275 (*ComponentName
)->SupportedLanguages
,
276 (BOOLEAN
)(ProtocolGuid
== &gEfiComponentNameProtocolGuid
)
278 if (*SupportedLanguage
== NULL
) {
279 Status
= EFI_UNSUPPORTED
;
287 This is an internal worker function to get driver name from Component Name (2) protocol interface.
289 @param ProtocolGuid A pointer to an EFI_GUID. It points to Component Name (2) protocol GUID.
290 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
291 @param DriverName A pointer to the Unicode string to return. This Unicode string is the name
292 of the driver specified by This.
294 @retval EFI_SUCCESS The driver name is successfully retrieved from Component Name (2) protocol
296 @retval Other The driver name cannot be retrieved from Component Name (2) protocol
301 DriverHealthManagerGetDriverNameWorker (
302 IN EFI_GUID
*ProtocolGuid
,
303 IN EFI_HANDLE DriverBindingHandle
,
304 OUT CHAR16
**DriverName
309 EFI_COMPONENT_NAME_PROTOCOL
*ComponentName
;
312 // Retrieve Component Name (2) protocol instance on the driver binding handle and
313 // find the best language this instance supports.
315 Status
= DriverHealthManagerGetComponentNameWorker (
321 if (EFI_ERROR (Status
)) {
326 // Get the driver name from Component Name (2) protocol instance on the driver binging handle.
328 Status
= ComponentName
->GetDriverName (
333 FreePool (BestLanguage
);
339 This function gets driver name from Component Name 2 protocol interface and Component Name protocol interface
340 in turn. It first tries UEFI 2.0 Component Name 2 protocol interface and try to get the driver name.
341 If the attempt fails, it then gets the driver name from EFI 1.1 Component Name protocol for backward
342 compatibility support.
344 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
346 @return A pointer to the Unicode string to return. This Unicode string is the name of the controller
347 specified by ControllerHandle and ChildHandle.
352 DriverHealthManagerGetDriverName (
353 IN EFI_HANDLE DriverBindingHandle
360 // Get driver name from UEFI 2.0 Component Name 2 protocol interface.
362 Status
= DriverHealthManagerGetDriverNameWorker (&gEfiComponentName2ProtocolGuid
, DriverBindingHandle
, &DriverName
);
363 if (EFI_ERROR (Status
)) {
365 // If it fails to get the driver name from Component Name protocol interface, we should fall back on
366 // EFI 1.1 Component Name protocol interface.
368 Status
= DriverHealthManagerGetDriverNameWorker (&gEfiComponentNameProtocolGuid
, DriverBindingHandle
, &DriverName
);
371 if (!EFI_ERROR (Status
)) {
372 return AllocateCopyPool (StrSize (DriverName
), DriverName
);
374 return ConvertDevicePathToText (DevicePathFromHandle (DriverBindingHandle
), FALSE
, TRUE
);
379 This function gets controller name from Component Name 2 protocol interface and Component Name protocol interface
380 in turn. It first tries UEFI 2.0 Component Name 2 protocol interface and try to get the controller name.
381 If the attempt fails, it then gets the controller name from EFI 1.1 Component Name protocol for backward
382 compatibility support.
384 @param ProtocolGuid A pointer to an EFI_GUID. It points to Component Name (2) protocol GUID.
385 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
386 @param ControllerHandle The handle of a controller that the driver specified by This is managing.
387 This handle specifies the controller whose name is to be returned.
388 @param ChildHandle The handle of the child controller to retrieve the name of. This is an
389 optional parameter that may be NULL. It will be NULL for device drivers.
390 It will also be NULL for bus drivers that attempt to retrieve the name
391 of the bus controller. It will not be NULL for a bus driver that attempts
392 to retrieve the name of a child controller.
393 @param ControllerName A pointer to the Unicode string to return. This Unicode string
394 is the name of the controller specified by ControllerHandle and ChildHandle.
396 @retval EFI_SUCCESS The controller name is successfully retrieved from Component Name (2) protocol
398 @retval Other The controller name cannot be retrieved from Component Name (2) protocol.
402 DriverHealthManagerGetControllerNameWorker (
403 IN EFI_GUID
*ProtocolGuid
,
404 IN EFI_HANDLE DriverBindingHandle
,
405 IN EFI_HANDLE ControllerHandle
,
406 IN EFI_HANDLE ChildHandle
,
407 OUT CHAR16
**ControllerName
412 EFI_COMPONENT_NAME_PROTOCOL
*ComponentName
;
415 // Retrieve Component Name (2) protocol instance on the driver binding handle and
416 // find the best language this instance supports.
418 Status
= DriverHealthManagerGetComponentNameWorker (
424 if (EFI_ERROR (Status
)) {
429 // Get the controller name from Component Name (2) protocol instance on the driver binging handle.
431 Status
= ComponentName
->GetControllerName (
438 FreePool (BestLanguage
);
445 This function gets controller name from Component Name 2 protocol interface and Component Name protocol interface
446 in turn. It first tries UEFI 2.0 Component Name 2 protocol interface and try to get the controller name.
447 If the attempt fails, it then gets the controller name from EFI 1.1 Component Name protocol for backward
448 compatibility support.
450 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
451 @param ControllerHandle The handle of a controller that the driver specified by DriverBindingHandle is managing.
452 This handle specifies the controller whose name is to be returned.
453 @param ChildHandle The handle of the child controller to retrieve the name of. This is an
454 optional parameter that may be NULL. It will be NULL for device drivers.
455 It will also be NULL for bus drivers that attempt to retrieve the name
456 of the bus controller. It will not be NULL for a bus driver that attempts
457 to retrieve the name of a child controller.
459 @return A pointer to the Unicode string to return. This Unicode string is the name of the controller
460 specified by ControllerHandle and ChildHandle.
463 DriverHealthManagerGetControllerName (
464 IN EFI_HANDLE DriverBindingHandle
,
465 IN EFI_HANDLE ControllerHandle
,
466 IN EFI_HANDLE ChildHandle
470 CHAR16
*ControllerName
;
473 // Get controller name from UEFI 2.0 Component Name 2 protocol interface.
475 Status
= DriverHealthManagerGetControllerNameWorker (
476 &gEfiComponentName2ProtocolGuid
,
482 if (EFI_ERROR (Status
)) {
484 // If it fails to get the controller name from Component Name protocol interface, we should fall back on
485 // EFI 1.1 Component Name protocol interface.
487 Status
= DriverHealthManagerGetControllerNameWorker (
488 &gEfiComponentNameProtocolGuid
,
496 if (!EFI_ERROR (Status
)) {
497 return AllocateCopyPool (StrSize (ControllerName
), ControllerName
);
499 return ConvertDevicePathToText (DevicePathFromHandle (ChildHandle
!= NULL
? ChildHandle
: ControllerHandle
), FALSE
, TRUE
);
504 The repair notify function.
505 @param Value A value between 0 and Limit that identifies the current progress
506 of the repair operation.
507 @param Limit The maximum value of Value for the current repair operation.
508 If Limit is 0, then the completion progress is indeterminate.
509 For example, a driver that wants to specify progress in percent
510 would use a Limit value of 100.
512 @retval EFI_SUCCESS Successfully return from the notify function.
516 DriverHealthManagerRepairNotify (
521 DEBUG ((DEBUG_INFO
, "[DriverHealthManagement]RepairNotify: %d/%d\n", Value
, Limit
));
526 Look for the formset GUID which has the gEfiHiiDriverHealthFormsetGuid class GUID in the specified HII package list.
528 @param Handle Handle to the HII package list.
529 @param FormsetGuid Return the formset GUID.
531 @retval EFI_SUCCESS The formset is found successfully.
532 @retval EFI_NOT_FOUND The formset cannot be found.
535 DriverHealthManagerGetFormsetId (
536 IN EFI_HII_HANDLE Handle
,
537 OUT EFI_GUID
*FormsetGuid
541 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
547 EFI_HII_PACKAGE_HEADER PackageHeader
;
549 UINT8 NumberOfClassGuid
;
553 // Get HII PackageList
556 HiiPackageList
= NULL
;
557 Status
= mDriverHealthManagerDatabase
->ExportPackageLists (mDriverHealthManagerDatabase
, Handle
, &BufferSize
, HiiPackageList
);
558 if (Status
== EFI_BUFFER_TOO_SMALL
) {
559 HiiPackageList
= AllocatePool (BufferSize
);
560 ASSERT (HiiPackageList
!= NULL
);
562 Status
= mDriverHealthManagerDatabase
->ExportPackageLists (mDriverHealthManagerDatabase
, Handle
, &BufferSize
, HiiPackageList
);
565 if (EFI_ERROR (Status
)) {
569 ASSERT (HiiPackageList
!= NULL
);
572 // Get Form package from this HII package List
574 for (Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
); Offset
< ReadUnaligned32 (&HiiPackageList
->PackageLength
); Offset
+= PackageHeader
.Length
) {
575 Package
= ((UINT8
*)HiiPackageList
) + Offset
;
576 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
578 if (PackageHeader
.Type
== EFI_HII_PACKAGE_FORMS
) {
580 // Search FormSet in this Form Package
583 for (Offset2
= sizeof (EFI_HII_PACKAGE_HEADER
); Offset2
< PackageHeader
.Length
; Offset2
+= ((EFI_IFR_OP_HEADER
*)OpCodeData
)->Length
) {
584 OpCodeData
= Package
+ Offset2
;
586 if ((((EFI_IFR_OP_HEADER
*)OpCodeData
)->OpCode
== EFI_IFR_FORM_SET_OP
) &&
587 (((EFI_IFR_OP_HEADER
*)OpCodeData
)->Length
> OFFSET_OF (EFI_IFR_FORM_SET
, Flags
)))
590 // Try to compare against formset class GUID
592 NumberOfClassGuid
= (UINT8
)(((EFI_IFR_FORM_SET
*)OpCodeData
)->Flags
& 0x3);
593 ClassGuid
= (EFI_GUID
*)(OpCodeData
+ sizeof (EFI_IFR_FORM_SET
));
594 for (Index
= 0; Index
< NumberOfClassGuid
; Index
++) {
595 if (CompareGuid (&gEfiHiiDriverHealthFormsetGuid
, &ClassGuid
[Index
])) {
596 CopyMem (FormsetGuid
, &((EFI_IFR_FORM_SET
*)OpCodeData
)->Guid
, sizeof (EFI_GUID
));
597 FreePool (HiiPackageList
);
607 // Form package not found in this Package List
609 FreePool (HiiPackageList
);
610 return EFI_NOT_FOUND
;
614 Processes a single controller using the EFI Driver Health Protocol associated with
617 @param DriverHealth A pointer to the EFI_DRIVER_HEALTH_PROTOCOL instance.
618 @param ControllerHandle The class guid specifies which form set will be displayed.
619 @param ChildHandle The handle of the child controller to retrieve the health
620 status on. This is an optional parameter that may be NULL.
621 @param HealthStatus The health status of the controller.
622 @param MessageList An array of warning or error messages associated
623 with the controller specified by ControllerHandle and
624 ChildHandle. This is an optional parameter that may be NULL.
625 @param FormHiiHandle The HII handle for an HII form associated with the
626 controller specified by ControllerHandle and ChildHandle.
629 DriverHealthManagerProcessSingleControllerHealth (
630 IN EFI_DRIVER_HEALTH_PROTOCOL
*DriverHealth
,
631 IN EFI_HANDLE ControllerHandle OPTIONAL
,
632 IN EFI_HANDLE ChildHandle OPTIONAL
,
633 IN EFI_DRIVER_HEALTH_STATUS HealthStatus
,
634 IN EFI_DRIVER_HEALTH_HII_MESSAGE
**MessageList OPTIONAL
,
635 IN EFI_HII_HANDLE FormHiiHandle
640 ASSERT (HealthStatus
!= EfiDriverHealthStatusConfigurationRequired
);
642 // If the module need to be repaired or reconfiguration, will process it until
643 // reach a terminal status. The status from EfiDriverHealthStatusRepairRequired after repair
644 // will be in (Health, Failed, Configuration Required).
646 switch (HealthStatus
) {
647 case EfiDriverHealthStatusRepairRequired
:
648 Status
= DriverHealth
->Repair (
652 DriverHealthManagerRepairNotify
656 case EfiDriverHealthStatusRebootRequired
:
657 gRT
->ResetSystem (EfiResetWarm
, EFI_SUCCESS
, 0, NULL
);
660 case EfiDriverHealthStatusReconnectRequired
:
661 Status
= gBS
->DisconnectController (ControllerHandle
, NULL
, NULL
);
662 if (EFI_ERROR (Status
)) {
664 // Disconnect failed. Need to promote reconnect to a reboot.
666 gRT
->ResetSystem (EfiResetWarm
, EFI_SUCCESS
, 0, NULL
);
668 gBS
->ConnectController (ControllerHandle
, NULL
, NULL
, TRUE
);
679 Update the form to include the driver health instances.
681 @param ConfigureOnly Only include the configure required driver health instances
682 when TRUE, include all the driver health instances otherwise.
685 DriverHealthManagerUpdateForm (
686 BOOLEAN ConfigureOnly
690 EFI_IFR_GUID_LABEL
*StartLabel
;
691 EFI_IFR_GUID_LABEL
*EndLabel
;
692 VOID
*StartOpCodeHandle
;
693 VOID
*EndOpCodeHandle
;
695 EFI_STRING_ID Prompt
;
699 EFI_STRING TmpString
;
700 EFI_STRING DriverName
;
701 EFI_STRING ControllerName
;
703 EFI_HANDLE DriverHandle
;
704 EFI_STRING_ID DevicePath
;
705 EFI_GUID FormsetGuid
;
707 EfiBootManagerFreeDriverHealthInfo (mDriverHealthManagerHealthInfo
, mDriverHealthManagerHealthInfoCount
);
708 mDriverHealthManagerHealthInfo
= EfiBootManagerGetDriverHealthInfo (&mDriverHealthManagerHealthInfoCount
);
711 // Allocate space for creation of UpdateData Buffer
713 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
714 ASSERT (StartOpCodeHandle
!= NULL
);
716 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
717 ASSERT (EndOpCodeHandle
!= NULL
);
720 // Create Hii Extend Label OpCode as the start opcode
722 StartLabel
= (EFI_IFR_GUID_LABEL
*)HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
723 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
724 StartLabel
->Number
= LABEL_BEGIN
;
727 // Create Hii Extend Label OpCode as the end opcode
729 EndLabel
= (EFI_IFR_GUID_LABEL
*)HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
730 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
731 EndLabel
->Number
= LABEL_END
;
733 for (Index
= 0; Index
< mDriverHealthManagerHealthInfoCount
; Index
++) {
734 if (ConfigureOnly
&& (mDriverHealthManagerHealthInfo
[Index
].HealthStatus
!= EfiDriverHealthStatusConfigurationRequired
)) {
738 DriverName
= DriverHealthManagerGetDriverName (mDriverHealthManagerHealthInfo
[Index
].DriverHealthHandle
);
739 ASSERT (DriverName
!= NULL
);
741 if (mDriverHealthManagerHealthInfo
[Index
].ControllerHandle
== NULL
) {
743 // The ControllerHandle is set to NULL and the HealthStatus is set to EfiDriverHealthStatusHealthy
744 // if all the controllers managed by the driver are in healthy state.
746 ASSERT (mDriverHealthManagerHealthInfo
[Index
].HealthStatus
== EfiDriverHealthStatusHealthy
);
747 UnicodeSPrint (String
, sizeof (String
), L
"%s", DriverName
);
749 ControllerName
= DriverHealthManagerGetControllerName (
750 mDriverHealthManagerHealthInfo
[Index
].DriverHealthHandle
,
751 mDriverHealthManagerHealthInfo
[Index
].ControllerHandle
,
752 mDriverHealthManagerHealthInfo
[Index
].ChildHandle
754 ASSERT (ControllerName
!= NULL
);
755 UnicodeSPrint (String
, sizeof (String
), L
"%s %s", DriverName
, ControllerName
);
756 FreePool (ControllerName
);
759 FreePool (DriverName
);
761 Prompt
= HiiSetString (mDriverHealthManagerHiiHandle
, 0, String
, NULL
);
763 switch (mDriverHealthManagerHealthInfo
[Index
].HealthStatus
) {
764 case EfiDriverHealthStatusRepairRequired
:
765 TmpString
= HiiGetString (mDriverHealthManagerHiiHandle
, STRING_TOKEN (STR_REPAIR_REQUIRED
), NULL
);
767 case EfiDriverHealthStatusConfigurationRequired
:
768 TmpString
= HiiGetString (mDriverHealthManagerHiiHandle
, STRING_TOKEN (STR_CONFIGURATION_REQUIRED
), NULL
);
770 case EfiDriverHealthStatusFailed
:
771 TmpString
= HiiGetString (mDriverHealthManagerHiiHandle
, STRING_TOKEN (STR_FAILED
), NULL
);
773 case EfiDriverHealthStatusReconnectRequired
:
774 TmpString
= HiiGetString (mDriverHealthManagerHiiHandle
, STRING_TOKEN (STR_RECONNECT_REQUIRED
), NULL
);
776 case EfiDriverHealthStatusRebootRequired
:
777 TmpString
= HiiGetString (mDriverHealthManagerHiiHandle
, STRING_TOKEN (STR_REBOOT_REQUIRED
), NULL
);
780 ASSERT (mDriverHealthManagerHealthInfo
[Index
].HealthStatus
== EfiDriverHealthStatusHealthy
);
781 TmpString
= HiiGetString (mDriverHealthManagerHiiHandle
, STRING_TOKEN (STR_HEALTHY
), NULL
);
785 StringCount
= UnicodeSPrint (String
, sizeof (String
), L
"%s\n", TmpString
);
786 FreePool (TmpString
);
789 // Add the message of the Module itself provided as the help.
791 if (mDriverHealthManagerHealthInfo
[Index
].MessageList
!= NULL
) {
792 for (MessageIndex
= 0; mDriverHealthManagerHealthInfo
[Index
].MessageList
[MessageIndex
].HiiHandle
!= NULL
; MessageIndex
++) {
793 TmpString
= HiiGetString (
794 mDriverHealthManagerHealthInfo
[Index
].MessageList
[MessageIndex
].HiiHandle
,
795 mDriverHealthManagerHealthInfo
[Index
].MessageList
[MessageIndex
].StringId
,
798 StringCount
+= UnicodeSPrint (String
+ StringCount
, sizeof (String
) - sizeof (String
[0]) * StringCount
, L
"\n%s", TmpString
);
799 FreePool (TmpString
);
803 Help
= HiiSetString (mDriverHealthManagerHiiHandle
, 0, String
, NULL
);
805 switch (mDriverHealthManagerHealthInfo
[Index
].HealthStatus
) {
806 case EfiDriverHealthStatusConfigurationRequired
:
807 Status
= mDriverHealthManagerDatabase
->GetPackageListHandle (
808 mDriverHealthManagerDatabase
,
809 mDriverHealthManagerHealthInfo
[Index
].HiiHandle
,
812 ASSERT_EFI_ERROR (Status
);
813 TmpString
= ConvertDevicePathToText (DevicePathFromHandle (DriverHandle
), FALSE
, TRUE
);
814 DevicePath
= HiiSetString (mDriverHealthManagerHiiHandle
, 0, TmpString
, NULL
);
815 FreePool (TmpString
);
817 Status
= DriverHealthManagerGetFormsetId (mDriverHealthManagerHealthInfo
[Index
].HiiHandle
, &FormsetGuid
);
818 ASSERT_EFI_ERROR (Status
);
820 HiiCreateGotoExOpCode (
833 case EfiDriverHealthStatusRepairRequired
:
834 case EfiDriverHealthStatusReconnectRequired
:
835 case EfiDriverHealthStatusRebootRequired
:
836 HiiCreateActionOpCode (
838 (EFI_QUESTION_ID
)(Index
+ QUESTION_ID_DRIVER_HEALTH_BASE
),
841 EFI_IFR_FLAG_CALLBACK
,
848 mDriverHealthManagerHealthInfo
[Index
].HealthStatus
== EfiDriverHealthStatusHealthy
||
849 mDriverHealthManagerHealthInfo
[Index
].HealthStatus
== EfiDriverHealthStatusFailed
851 HiiCreateTextOpCode (
861 Status
= HiiUpdateForm (
862 mDriverHealthManagerHiiHandle
,
863 ConfigureOnly
? PcdGetPtr (PcdDriverHealthConfigureForm
) : &mDriverHealthManagerForm
,
864 DRIVER_HEALTH_FORM_ID
,
868 ASSERT_EFI_ERROR (Status
);
870 HiiFreeOpCodeHandle (StartOpCodeHandle
);
871 HiiFreeOpCodeHandle (EndOpCodeHandle
);
875 Called when the form is closing to remove the dynamicly added string from the HII package list.
878 DriverHealthManagerCleanDynamicString (
883 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
885 EFI_HII_PACKAGE_HEADER
*PackageHeader
;
886 UINT32 FixedStringSize
;
888 FixedStringSize
= *(UINT32
*)&STRING_ARRAY_NAME
- sizeof (UINT32
);
889 BufferSize
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
) + FixedStringSize
+ sizeof (EFI_HII_PACKAGE_HEADER
);
890 HiiPackageList
= AllocatePool (BufferSize
);
891 ASSERT (HiiPackageList
!= NULL
);
893 HiiPackageList
->PackageLength
= (UINT32
)BufferSize
;
894 CopyMem (&HiiPackageList
->PackageListGuid
, &gEfiCallerIdGuid
, sizeof (EFI_GUID
));
896 PackageHeader
= (EFI_HII_PACKAGE_HEADER
*)(HiiPackageList
+ 1);
897 CopyMem (PackageHeader
, STRING_ARRAY_NAME
+ sizeof (UINT32
), FixedStringSize
);
899 PackageHeader
= (EFI_HII_PACKAGE_HEADER
*)((UINT8
*)PackageHeader
+ PackageHeader
->Length
);
900 PackageHeader
->Type
= EFI_HII_PACKAGE_END
;
901 PackageHeader
->Length
= sizeof (EFI_HII_PACKAGE_HEADER
);
903 Status
= mDriverHealthManagerDatabase
->UpdatePackageList (
904 mDriverHealthManagerDatabase
,
905 mDriverHealthManagerHiiHandle
,
908 ASSERT_EFI_ERROR (Status
);
911 // Form package not found in this Package List
913 FreePool (HiiPackageList
);
917 This function is invoked if user selected a interactive opcode from Driver Health's
920 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
921 @param Action Specifies the type of action taken by the browser.
922 @param QuestionId A unique value which is sent to the original exporting driver
923 so that it can identify the type of data to expect.
924 @param Type The type of value for the question.
925 @param Value A pointer to the data being sent to the original exporting driver.
926 @param ActionRequest On return, points to the action requested by the callback function.
928 @retval EFI_SUCCESS The callback successfully handled the action.
929 @retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.
934 DriverHealthManagerCallback (
935 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
936 IN EFI_BROWSER_ACTION Action
,
937 IN EFI_QUESTION_ID QuestionId
,
939 IN EFI_IFR_TYPE_VALUE
*Value
,
940 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
945 if ((QuestionId
== QUESTION_ID_REFRESH_MANAGER
) || (QuestionId
== QUESTION_ID_REFRESH_CONFIGURE
)) {
946 if (Action
== EFI_BROWSER_ACTION_FORM_OPEN
) {
947 DriverHealthManagerUpdateForm ((BOOLEAN
)(QuestionId
== QUESTION_ID_REFRESH_CONFIGURE
));
948 } else if (Action
== EFI_BROWSER_ACTION_FORM_CLOSE
) {
949 DriverHealthManagerCleanDynamicString ();
955 if (Action
!= EFI_BROWSER_ACTION_CHANGED
) {
957 // Do nothing for other UEFI Action. Only do call back when data is changed.
959 return EFI_UNSUPPORTED
;
962 if ((Value
== NULL
) || (ActionRequest
== NULL
)) {
963 return EFI_INVALID_PARAMETER
;
966 DEBUG ((DEBUG_ERROR
, "QuestionId = %x\n", QuestionId
));
969 // We will have returned from processing a callback - user either hit ESC to exit, or selected
970 // a target to display.
971 // Process the diver health status states here.
973 Index
= QuestionId
- QUESTION_ID_DRIVER_HEALTH_BASE
;
974 ASSERT (Index
< mDriverHealthManagerHealthInfoCount
);
976 // Process the driver's healthy status for the specify module
978 DriverHealthManagerProcessSingleControllerHealth (
979 mDriverHealthManagerHealthInfo
[Index
].DriverHealth
,
980 mDriverHealthManagerHealthInfo
[Index
].ControllerHandle
,
981 mDriverHealthManagerHealthInfo
[Index
].ChildHandle
,
982 mDriverHealthManagerHealthInfo
[Index
].HealthStatus
,
983 &(mDriverHealthManagerHealthInfo
[Index
].MessageList
),
984 mDriverHealthManagerHealthInfo
[Index
].HiiHandle
987 DriverHealthManagerUpdateForm ((BOOLEAN
)(QuestionId
== QUESTION_ID_REFRESH_CONFIGURE
));