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 This program and the accompanying materials
10 are licensed and made available under the terms and conditions of the BSD License
11 which accompanies this distribution. The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 #include "DriverHealthManagerDxe.h"
20 #include "DriverHealthManagerVfr.h"
22 EFI_HII_CONFIG_ACCESS_PROTOCOL mDriverHealthManagerConfigAccess
= {
23 DriverHealthManagerFakeExtractConfig
,
24 DriverHealthManagerFakeRouteConfig
,
25 DriverHealthManagerCallback
28 EFI_GUID mDriverHealthManagerForm
= DRIVER_HEALTH_MANAGER_FORMSET_GUID
;
30 FORM_DEVICE_PATH mDriverHealthManagerFormDevicePath
= {
36 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
37 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
44 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
46 (UINT8
) (END_DEVICE_PATH_LENGTH
),
47 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
52 EFI_HII_HANDLE mDriverHealthManagerHiiHandle
;
53 EFI_BOOT_MANAGER_DRIVER_HEALTH_INFO
*mDriverHealthManagerHealthInfo
= NULL
;
54 UINTN mDriverHealthManagerHealthInfoCount
= 0;
55 EFI_HII_DATABASE_PROTOCOL
*mDriverHealthManagerDatabase
;
58 extern UINT8 DriverHealthManagerVfrBin
[];
59 extern UINT8 DriverHealthConfigureVfrBin
[];
62 This function allows a caller to extract the current configuration for one
63 or more named elements from the target driver.
66 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
67 @param Request A null-terminated Unicode string in <ConfigRequest> format.
68 @param Progress On return, points to a character in the Request string.
69 Points to the string's null terminator if request was successful.
70 Points to the most recent '&' before the first failing name/value
71 pair (or the beginning of the string if the failure is in the
72 first name/value pair) if the request was not successful.
73 @param Results A null-terminated Unicode string in <ConfigAltResp> format which
74 has all values filled in for the names in the Request string.
75 String to be allocated by the called function.
77 @retval EFI_SUCCESS The Results is filled with the requested values.
78 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
79 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
80 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
85 DriverHealthManagerFakeExtractConfig (
86 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
87 IN CONST EFI_STRING Request
,
88 OUT EFI_STRING
*Progress
,
89 OUT EFI_STRING
*Results
92 if (Progress
== NULL
|| Results
== NULL
) {
93 return EFI_INVALID_PARAMETER
;
100 This function processes the results of changes in configuration.
103 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
104 @param Configuration A null-terminated Unicode string in <ConfigResp> format.
105 @param Progress A pointer to a string filled in with the offset of the most
106 recent '&' before the first failing name/value pair (or the
107 beginning of the string if the failure is in the first
108 name/value pair) or the terminating NULL if all was successful.
110 @retval EFI_SUCCESS The Results is processed successfully.
111 @retval EFI_INVALID_PARAMETER Configuration is NULL.
112 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
117 DriverHealthManagerFakeRouteConfig (
118 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
119 IN CONST EFI_STRING Configuration
,
120 OUT EFI_STRING
*Progress
123 if (Configuration
== NULL
|| Progress
== NULL
) {
124 return EFI_INVALID_PARAMETER
;
127 *Progress
= Configuration
;
129 return EFI_NOT_FOUND
;
134 Install the health manager forms.
135 One will be used by BDS core to configure the Configured Required
136 driver health instances, the other will be automatically included by
139 @param ImageHandle The image handle.
140 @param SystemTable The system table.
142 @retval EFI_SUCEESS The health manager forms are successfully installed.
147 InitializeDriverHealthManager (
148 EFI_HANDLE ImageHandle
,
149 EFI_SYSTEM_TABLE
*SystemTable
155 Status
= gBS
->LocateProtocol (
156 &gEfiHiiDatabaseProtocolGuid
,
158 (VOID
**) &mDriverHealthManagerDatabase
160 ASSERT_EFI_ERROR (Status
);
163 Status
= gBS
->InstallMultipleProtocolInterfaces (
165 &gEfiDevicePathProtocolGuid
,
166 &mDriverHealthManagerFormDevicePath
,
167 &gEfiHiiConfigAccessProtocolGuid
,
168 &mDriverHealthManagerConfigAccess
,
171 ASSERT_EFI_ERROR (Status
);
175 // Publish Driver Health HII data.
177 mDriverHealthManagerHiiHandle
= HiiAddPackages (
180 DriverHealthManagerVfrBin
,
181 DriverHealthConfigureVfrBin
,
185 ASSERT (mDriverHealthManagerHiiHandle
!= NULL
);
192 Select the best matching language according to front page policy for best user experience.
194 This function supports both ISO 639-2 and RFC 4646 language codes, but language
195 code types may not be mixed in a single call to this function.
197 @param SupportedLanguages A pointer to a Null-terminated ASCII string that
198 contains a set of language codes in the format
199 specified by Iso639Language.
200 @param Iso639Language If TRUE, then all language codes are assumed to be
201 in ISO 639-2 format. If FALSE, then all language
202 codes are assumed to be in RFC 4646 language format.
204 @retval NULL The best matching language could not be found in SupportedLanguages.
205 @retval NULL There are not enough resources available to return the best matching
207 @retval Other A pointer to a Null-terminated ASCII string that is the best matching
208 language in SupportedLanguages.
211 DriverHealthManagerSelectBestLanguage (
212 IN CHAR8
*SupportedLanguages
,
213 IN BOOLEAN Iso639Language
216 CHAR8
*LanguageVariable
;
219 GetEfiGlobalVariable2 (Iso639Language
? L
"Lang" : L
"PlatformLang", (VOID
**)&LanguageVariable
, NULL
);
221 BestLanguage
= GetBestLanguage(
224 (LanguageVariable
!= NULL
) ? LanguageVariable
: "",
225 Iso639Language
? "eng" : "en-US",
228 if (LanguageVariable
!= NULL
) {
229 FreePool (LanguageVariable
);
239 This is an internal worker function to get the Component Name (2) protocol interface
240 and the language it supports.
242 @param ProtocolGuid A pointer to an EFI_GUID. It points to Component Name (2) protocol GUID.
243 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
244 @param ComponentName A pointer to the Component Name (2) protocol interface.
245 @param SupportedLanguage The best suitable language that matches the SupportedLangues interface for the
246 located Component Name (2) instance.
248 @retval EFI_SUCCESS The Component Name (2) protocol instance is successfully located and we find
249 the best matching language it support.
250 @retval EFI_UNSUPPORTED The input Language is not supported by the Component Name (2) protocol.
251 @retval Other Some error occurs when locating Component Name (2) protocol instance or finding
252 the supported language.
256 DriverHealthManagerGetComponentNameWorker (
257 IN EFI_GUID
*ProtocolGuid
,
258 IN EFI_HANDLE DriverBindingHandle
,
259 OUT EFI_COMPONENT_NAME_PROTOCOL
**ComponentName
,
260 OUT CHAR8
**SupportedLanguage
266 // Locate Component Name (2) protocol on the driver binging handle.
268 Status
= gBS
->OpenProtocol (
271 (VOID
**) ComponentName
,
274 EFI_OPEN_PROTOCOL_GET_PROTOCOL
276 if (EFI_ERROR (Status
)) {
281 // Apply shell policy to select the best language.
283 *SupportedLanguage
= DriverHealthManagerSelectBestLanguage (
284 (*ComponentName
)->SupportedLanguages
,
285 (BOOLEAN
) (ProtocolGuid
== &gEfiComponentNameProtocolGuid
)
287 if (*SupportedLanguage
== NULL
) {
288 Status
= EFI_UNSUPPORTED
;
296 This is an internal worker function to get driver name from Component Name (2) protocol interface.
298 @param ProtocolGuid A pointer to an EFI_GUID. It points to Component Name (2) protocol GUID.
299 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
300 @param DriverName A pointer to the Unicode string to return. This Unicode string is the name
301 of the driver specified by This.
303 @retval EFI_SUCCESS The driver name is successfully retrieved from Component Name (2) protocol
305 @retval Other The driver name cannot be retrieved from Component Name (2) protocol
310 DriverHealthManagerGetDriverNameWorker (
311 IN EFI_GUID
*ProtocolGuid
,
312 IN EFI_HANDLE DriverBindingHandle
,
313 OUT CHAR16
**DriverName
318 EFI_COMPONENT_NAME_PROTOCOL
*ComponentName
;
321 // Retrieve Component Name (2) protocol instance on the driver binding handle and
322 // find the best language this instance supports.
324 Status
= DriverHealthManagerGetComponentNameWorker (
330 if (EFI_ERROR (Status
)) {
335 // Get the driver name from Component Name (2) protocol instance on the driver binging handle.
337 Status
= ComponentName
->GetDriverName (
342 FreePool (BestLanguage
);
348 This function gets driver name from Component Name 2 protocol interface and Component Name protocol interface
349 in turn. It first tries UEFI 2.0 Component Name 2 protocol interface and try to get the driver name.
350 If the attempt fails, it then gets the driver name from EFI 1.1 Component Name protocol for backward
351 compatibility support.
353 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
355 @return A pointer to the Unicode string to return. This Unicode string is the name of the controller
356 specified by ControllerHandle and ChildHandle.
361 DriverHealthManagerGetDriverName (
362 IN EFI_HANDLE DriverBindingHandle
369 // Get driver name from UEFI 2.0 Component Name 2 protocol interface.
371 Status
= DriverHealthManagerGetDriverNameWorker (&gEfiComponentName2ProtocolGuid
, DriverBindingHandle
, &DriverName
);
372 if (EFI_ERROR (Status
)) {
374 // If it fails to get the driver name from Component Name protocol interface, we should fall back on
375 // EFI 1.1 Component Name protocol interface.
377 Status
= DriverHealthManagerGetDriverNameWorker (&gEfiComponentNameProtocolGuid
, DriverBindingHandle
, &DriverName
);
380 if (!EFI_ERROR (Status
)) {
381 return AllocateCopyPool (StrSize (DriverName
), DriverName
);
383 return ConvertDevicePathToText (DevicePathFromHandle (DriverBindingHandle
), FALSE
, TRUE
);
390 This function gets controller name from Component Name 2 protocol interface and Component Name protocol interface
391 in turn. It first tries UEFI 2.0 Component Name 2 protocol interface and try to get the controller name.
392 If the attempt fails, it then gets the controller name from EFI 1.1 Component Name protocol for backward
393 compatibility support.
395 @param ProtocolGuid A pointer to an EFI_GUID. It points to Component Name (2) protocol GUID.
396 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
397 @param ControllerHandle The handle of a controller that the driver specified by This is managing.
398 This handle specifies the controller whose name is to be returned.
399 @param ChildHandle The handle of the child controller to retrieve the name of. This is an
400 optional parameter that may be NULL. It will be NULL for device drivers.
401 It will also be NULL for bus drivers that attempt to retrieve the name
402 of the bus controller. It will not be NULL for a bus driver that attempts
403 to retrieve the name of a child controller.
404 @param ControllerName A pointer to the Unicode string to return. This Unicode string
405 is the name of the controller specified by ControllerHandle and ChildHandle.
407 @retval EFI_SUCCESS The controller name is successfully retrieved from Component Name (2) protocol
409 @retval Other The controller name cannot be retrieved from Component Name (2) protocol.
413 DriverHealthManagerGetControllerNameWorker (
414 IN EFI_GUID
*ProtocolGuid
,
415 IN EFI_HANDLE DriverBindingHandle
,
416 IN EFI_HANDLE ControllerHandle
,
417 IN EFI_HANDLE ChildHandle
,
418 OUT CHAR16
**ControllerName
423 EFI_COMPONENT_NAME_PROTOCOL
*ComponentName
;
426 // Retrieve Component Name (2) protocol instance on the driver binding handle and
427 // find the best language this instance supports.
429 Status
= DriverHealthManagerGetComponentNameWorker (
435 if (EFI_ERROR (Status
)) {
440 // Get the controller name from Component Name (2) protocol instance on the driver binging handle.
442 Status
= ComponentName
->GetControllerName (
449 FreePool (BestLanguage
);
456 This function gets controller name from Component Name 2 protocol interface and Component Name protocol interface
457 in turn. It first tries UEFI 2.0 Component Name 2 protocol interface and try to get the controller name.
458 If the attempt fails, it then gets the controller name from EFI 1.1 Component Name protocol for backward
459 compatibility support.
461 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
462 @param ControllerHandle The handle of a controller that the driver specified by DriverBindingHandle is managing.
463 This handle specifies the controller whose name is to be returned.
464 @param ChildHandle The handle of the child controller to retrieve the name of. This is an
465 optional parameter that may be NULL. It will be NULL for device drivers.
466 It will also be NULL for bus drivers that attempt to retrieve the name
467 of the bus controller. It will not be NULL for a bus driver that attempts
468 to retrieve the name of a child controller.
470 @return A pointer to the Unicode string to return. This Unicode string is the name of the controller
471 specified by ControllerHandle and ChildHandle.
474 DriverHealthManagerGetControllerName (
475 IN EFI_HANDLE DriverBindingHandle
,
476 IN EFI_HANDLE ControllerHandle
,
477 IN EFI_HANDLE ChildHandle
481 CHAR16
*ControllerName
;
484 // Get controller name from UEFI 2.0 Component Name 2 protocol interface.
486 Status
= DriverHealthManagerGetControllerNameWorker (
487 &gEfiComponentName2ProtocolGuid
,
493 if (EFI_ERROR (Status
)) {
495 // If it fails to get the controller name from Component Name protocol interface, we should fall back on
496 // EFI 1.1 Component Name protocol interface.
498 Status
= DriverHealthManagerGetControllerNameWorker (
499 &gEfiComponentNameProtocolGuid
,
507 if (!EFI_ERROR (Status
)) {
508 return AllocateCopyPool (StrSize (ControllerName
), ControllerName
);
510 return ConvertDevicePathToText (DevicePathFromHandle (ChildHandle
!= NULL
? ChildHandle
: ControllerHandle
), FALSE
, TRUE
);
515 The repair notify function.
516 @param Value A value between 0 and Limit that identifies the current progress
517 of the repair operation.
518 @param Limit The maximum value of Value for the current repair operation.
519 If Limit is 0, then the completion progress is indeterminate.
520 For example, a driver that wants to specify progress in percent
521 would use a Limit value of 100.
523 @retval EFI_SUCCESS Successfully return from the notify function.
527 DriverHealthManagerRepairNotify (
532 DEBUG ((EFI_D_INFO
, "[DriverHealthManagement]RepairNotify: %d/%d\n", Value
, Limit
));
537 Look for the formset GUID which has the gEfiHiiDriverHealthFormsetGuid class GUID in the specified HII package list.
539 @param Handle Handle to the HII package list.
540 @param FormsetGuid Return the formset GUID.
542 @retval EFI_SUCCESS The formset is found successfully.
543 @retval EFI_NOT_FOUND The formset cannot be found.
546 DriverHealthManagerGetFormsetId (
547 IN EFI_HII_HANDLE Handle
,
548 OUT EFI_GUID
*FormsetGuid
552 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
558 EFI_HII_PACKAGE_HEADER PackageHeader
;
560 UINT8 NumberOfClassGuid
;
564 // Get HII PackageList
567 HiiPackageList
= NULL
;
568 Status
= mDriverHealthManagerDatabase
->ExportPackageLists (mDriverHealthManagerDatabase
, Handle
, &BufferSize
, HiiPackageList
);
569 if (Status
== EFI_BUFFER_TOO_SMALL
) {
570 HiiPackageList
= AllocatePool (BufferSize
);
571 ASSERT (HiiPackageList
!= NULL
);
573 Status
= mDriverHealthManagerDatabase
->ExportPackageLists (mDriverHealthManagerDatabase
, Handle
, &BufferSize
, HiiPackageList
);
575 if (EFI_ERROR (Status
)) {
578 ASSERT (HiiPackageList
!= NULL
);
581 // Get Form package from this HII package List
583 for (Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
); Offset
< ReadUnaligned32 (&HiiPackageList
->PackageLength
); Offset
+= PackageHeader
.Length
) {
584 Package
= ((UINT8
*) HiiPackageList
) + Offset
;
585 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
587 if (PackageHeader
.Type
== EFI_HII_PACKAGE_FORMS
) {
589 // Search FormSet in this Form Package
592 for (Offset2
= sizeof (EFI_HII_PACKAGE_HEADER
); Offset2
< PackageHeader
.Length
; Offset2
+= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
) {
593 OpCodeData
= Package
+ Offset2
;
595 if ((((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
== EFI_IFR_FORM_SET_OP
) &&
596 (((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
> OFFSET_OF (EFI_IFR_FORM_SET
, Flags
))) {
598 // Try to compare against formset class GUID
600 NumberOfClassGuid
= (UINT8
) (((EFI_IFR_FORM_SET
*) OpCodeData
)->Flags
& 0x3);
601 ClassGuid
= (EFI_GUID
*) (OpCodeData
+ sizeof (EFI_IFR_FORM_SET
));
602 for (Index
= 0; Index
< NumberOfClassGuid
; Index
++) {
603 if (CompareGuid (&gEfiHiiDriverHealthFormsetGuid
, &ClassGuid
[Index
])) {
604 CopyMem (FormsetGuid
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->Guid
, sizeof (EFI_GUID
));
605 FreePool (HiiPackageList
);
615 // Form package not found in this Package List
617 FreePool (HiiPackageList
);
618 return EFI_NOT_FOUND
;
622 Processes a single controller using the EFI Driver Health Protocol associated with
625 @param DriverHealth A pointer to the EFI_DRIVER_HEALTH_PROTOCOL instance.
626 @param ControllerHandle The class guid specifies which form set will be displayed.
627 @param ChildHandle The handle of the child controller to retrieve the health
628 status on. This is an optional parameter that may be NULL.
629 @param HealthStatus The health status of the controller.
630 @param MessageList An array of warning or error messages associated
631 with the controller specified by ControllerHandle and
632 ChildHandle. This is an optional parameter that may be NULL.
633 @param FormHiiHandle The HII handle for an HII form associated with the
634 controller specified by ControllerHandle and ChildHandle.
637 DriverHealthManagerProcessSingleControllerHealth (
638 IN EFI_DRIVER_HEALTH_PROTOCOL
*DriverHealth
,
639 IN EFI_HANDLE ControllerHandle
, OPTIONAL
640 IN EFI_HANDLE ChildHandle
, OPTIONAL
641 IN EFI_DRIVER_HEALTH_STATUS HealthStatus
,
642 IN EFI_DRIVER_HEALTH_HII_MESSAGE
**MessageList
, OPTIONAL
643 IN EFI_HII_HANDLE FormHiiHandle
648 ASSERT (HealthStatus
!= EfiDriverHealthStatusConfigurationRequired
);
650 // If the module need to be repaired or reconfiguration, will process it until
651 // reach a terminal status. The status from EfiDriverHealthStatusRepairRequired after repair
652 // will be in (Health, Failed, Configuration Required).
654 switch (HealthStatus
) {
656 case EfiDriverHealthStatusRepairRequired
:
657 Status
= DriverHealth
->Repair (
661 DriverHealthManagerRepairNotify
665 case EfiDriverHealthStatusRebootRequired
:
666 gRT
->ResetSystem (EfiResetWarm
, EFI_SUCCESS
, 0, NULL
);
669 case EfiDriverHealthStatusReconnectRequired
:
670 Status
= gBS
->DisconnectController (ControllerHandle
, NULL
, NULL
);
671 if (EFI_ERROR (Status
)) {
673 // Disconnect failed. Need to promote reconnect to a reboot.
675 gRT
->ResetSystem (EfiResetWarm
, EFI_SUCCESS
, 0, NULL
);
677 gBS
->ConnectController (ControllerHandle
, NULL
, NULL
, TRUE
);
687 Update the form to include the driver health instances.
689 @param ConfigureOnly Only include the configure required driver health instances
690 when TRUE, include all the driver health instances otherwise.
693 DriverHealthManagerUpdateForm (
694 BOOLEAN ConfigureOnly
698 EFI_IFR_GUID_LABEL
*StartLabel
;
699 EFI_IFR_GUID_LABEL
*EndLabel
;
700 VOID
*StartOpCodeHandle
;
701 VOID
*EndOpCodeHandle
;
703 EFI_STRING_ID Prompt
;
707 EFI_STRING TmpString
;
708 EFI_STRING DriverName
;
709 EFI_STRING ControllerName
;
711 EFI_HANDLE DriverHandle
;
712 EFI_STRING_ID DevicePath
;
713 EFI_GUID FormsetGuid
;
715 EfiBootManagerFreeDriverHealthInfo (mDriverHealthManagerHealthInfo
, mDriverHealthManagerHealthInfoCount
);
716 mDriverHealthManagerHealthInfo
= EfiBootManagerGetDriverHealthInfo (&mDriverHealthManagerHealthInfoCount
);
719 // Allocate space for creation of UpdateData Buffer
721 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
722 ASSERT (StartOpCodeHandle
!= NULL
);
724 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
725 ASSERT (EndOpCodeHandle
!= NULL
);
728 // Create Hii Extend Label OpCode as the start opcode
730 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
731 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
732 StartLabel
->Number
= LABEL_BEGIN
;
735 // Create Hii Extend Label OpCode as the end opcode
737 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
738 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
739 EndLabel
->Number
= LABEL_END
;
741 for (Index
= 0; Index
< mDriverHealthManagerHealthInfoCount
; Index
++) {
742 if (ConfigureOnly
&& mDriverHealthManagerHealthInfo
[Index
].HealthStatus
!= EfiDriverHealthStatusConfigurationRequired
) {
745 DriverName
= DriverHealthManagerGetDriverName (mDriverHealthManagerHealthInfo
[Index
].DriverHealthHandle
);
746 ASSERT (DriverName
!= NULL
);
748 if (mDriverHealthManagerHealthInfo
[Index
].ControllerHandle
== NULL
) {
750 // The ControllerHandle is set to NULL and the HealthStatus is set to EfiDriverHealthStatusHealthy
751 // if all the controllers managed by the driver are in healthy state.
753 ASSERT (mDriverHealthManagerHealthInfo
[Index
].HealthStatus
== EfiDriverHealthStatusHealthy
);
754 UnicodeSPrint (String
, sizeof (String
), L
"%s", DriverName
);
756 ControllerName
= DriverHealthManagerGetControllerName (
757 mDriverHealthManagerHealthInfo
[Index
].DriverHealthHandle
,
758 mDriverHealthManagerHealthInfo
[Index
].ControllerHandle
,
759 mDriverHealthManagerHealthInfo
[Index
].ChildHandle
761 ASSERT (ControllerName
!= NULL
);
762 UnicodeSPrint (String
, sizeof (String
), L
"%s %s", DriverName
, ControllerName
);
763 FreePool (ControllerName
);
765 FreePool (DriverName
);
767 Prompt
= HiiSetString (mDriverHealthManagerHiiHandle
, 0, String
, NULL
);
769 switch(mDriverHealthManagerHealthInfo
[Index
].HealthStatus
) {
770 case EfiDriverHealthStatusRepairRequired
:
771 TmpString
= HiiGetString (mDriverHealthManagerHiiHandle
, STRING_TOKEN (STR_REPAIR_REQUIRED
), NULL
);
773 case EfiDriverHealthStatusConfigurationRequired
:
774 TmpString
= HiiGetString (mDriverHealthManagerHiiHandle
, STRING_TOKEN (STR_CONFIGURATION_REQUIRED
), NULL
);
776 case EfiDriverHealthStatusFailed
:
777 TmpString
= HiiGetString (mDriverHealthManagerHiiHandle
, STRING_TOKEN (STR_FAILED
), NULL
);
779 case EfiDriverHealthStatusReconnectRequired
:
780 TmpString
= HiiGetString (mDriverHealthManagerHiiHandle
, STRING_TOKEN (STR_RECONNECT_REQUIRED
), NULL
);
782 case EfiDriverHealthStatusRebootRequired
:
783 TmpString
= HiiGetString (mDriverHealthManagerHiiHandle
, STRING_TOKEN (STR_REBOOT_REQUIRED
), NULL
);
786 ASSERT (mDriverHealthManagerHealthInfo
[Index
].HealthStatus
== EfiDriverHealthStatusHealthy
);
787 TmpString
= HiiGetString (mDriverHealthManagerHiiHandle
, STRING_TOKEN (STR_HEALTHY
), NULL
);
790 StringCount
= UnicodeSPrint (String
, sizeof (String
), L
"%s\n", TmpString
);
791 FreePool (TmpString
);
794 // Add the message of the Module itself provided as the help.
796 if (mDriverHealthManagerHealthInfo
[Index
].MessageList
!= NULL
) {
797 for (MessageIndex
= 0; mDriverHealthManagerHealthInfo
[Index
].MessageList
[MessageIndex
].HiiHandle
!= NULL
; MessageIndex
++) {
798 TmpString
= HiiGetString (
799 mDriverHealthManagerHealthInfo
[Index
].MessageList
[MessageIndex
].HiiHandle
,
800 mDriverHealthManagerHealthInfo
[Index
].MessageList
[MessageIndex
].StringId
,
803 StringCount
+= UnicodeSPrint (String
+ StringCount
, sizeof (String
) - sizeof (String
[0]) * StringCount
, L
"\n%s", TmpString
);
804 FreePool (TmpString
);
807 Help
= HiiSetString (mDriverHealthManagerHiiHandle
, 0, String
, NULL
);
809 switch (mDriverHealthManagerHealthInfo
[Index
].HealthStatus
) {
810 case EfiDriverHealthStatusConfigurationRequired
:
811 Status
= mDriverHealthManagerDatabase
->GetPackageListHandle (
812 mDriverHealthManagerDatabase
,
813 mDriverHealthManagerHealthInfo
[Index
].HiiHandle
,
816 ASSERT_EFI_ERROR (Status
);
817 TmpString
= ConvertDevicePathToText (DevicePathFromHandle (DriverHandle
), FALSE
, TRUE
);
818 DevicePath
= HiiSetString (mDriverHealthManagerHiiHandle
, 0, TmpString
, NULL
);
819 FreePool (TmpString
);
821 Status
= DriverHealthManagerGetFormsetId (mDriverHealthManagerHealthInfo
[Index
].HiiHandle
, &FormsetGuid
);
822 ASSERT_EFI_ERROR (Status
);
824 HiiCreateGotoExOpCode (
837 case EfiDriverHealthStatusRepairRequired
:
838 case EfiDriverHealthStatusReconnectRequired
:
839 case EfiDriverHealthStatusRebootRequired
:
840 HiiCreateActionOpCode (
842 (EFI_QUESTION_ID
) (Index
+ QUESTION_ID_DRIVER_HEALTH_BASE
),
845 EFI_IFR_FLAG_CALLBACK
,
851 ASSERT (mDriverHealthManagerHealthInfo
[Index
].HealthStatus
== EfiDriverHealthStatusHealthy
||
852 mDriverHealthManagerHealthInfo
[Index
].HealthStatus
== EfiDriverHealthStatusFailed
);
853 HiiCreateTextOpCode (
863 Status
= HiiUpdateForm (
864 mDriverHealthManagerHiiHandle
,
865 ConfigureOnly
? PcdGetPtr (PcdDriverHealthConfigureForm
) : &mDriverHealthManagerForm
,
866 DRIVER_HEALTH_FORM_ID
,
870 ASSERT_EFI_ERROR (Status
);
872 HiiFreeOpCodeHandle (StartOpCodeHandle
);
873 HiiFreeOpCodeHandle (EndOpCodeHandle
);
877 Called when the form is closing to remove the dynamicly added string from the HII package list.
880 DriverHealthManagerCleanDynamicString (
885 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
887 EFI_HII_PACKAGE_HEADER
*PackageHeader
;
888 UINT32 FixedStringSize
;
890 FixedStringSize
= *(UINT32
*) &STRING_ARRAY_NAME
- sizeof (UINT32
);
891 BufferSize
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
) + FixedStringSize
+ sizeof (EFI_HII_PACKAGE_HEADER
);
892 HiiPackageList
= AllocatePool (BufferSize
);
893 ASSERT (HiiPackageList
!= NULL
);
895 HiiPackageList
->PackageLength
= (UINT32
) BufferSize
;
896 CopyMem (&HiiPackageList
->PackageListGuid
, &gEfiCallerIdGuid
, sizeof (EFI_GUID
));
898 PackageHeader
= (EFI_HII_PACKAGE_HEADER
*) (HiiPackageList
+ 1);
899 CopyMem (PackageHeader
, STRING_ARRAY_NAME
+ sizeof (UINT32
), FixedStringSize
);
901 PackageHeader
= (EFI_HII_PACKAGE_HEADER
*) ((UINT8
*) PackageHeader
+ PackageHeader
->Length
);
902 PackageHeader
->Type
= EFI_HII_PACKAGE_END
;
903 PackageHeader
->Length
= sizeof (EFI_HII_PACKAGE_HEADER
);
905 Status
= mDriverHealthManagerDatabase
->UpdatePackageList (
906 mDriverHealthManagerDatabase
,
907 mDriverHealthManagerHiiHandle
,
910 ASSERT_EFI_ERROR (Status
);
913 // Form package not found in this Package List
915 FreePool (HiiPackageList
);
919 This function is invoked if user selected a interactive opcode from Driver Health's
922 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
923 @param Action Specifies the type of action taken by the browser.
924 @param QuestionId A unique value which is sent to the original exporting driver
925 so that it can identify the type of data to expect.
926 @param Type The type of value for the question.
927 @param Value A pointer to the data being sent to the original exporting driver.
928 @param ActionRequest On return, points to the action requested by the callback function.
930 @retval EFI_SUCCESS The callback successfully handled the action.
931 @retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.
936 DriverHealthManagerCallback (
937 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
938 IN EFI_BROWSER_ACTION Action
,
939 IN EFI_QUESTION_ID QuestionId
,
941 IN EFI_IFR_TYPE_VALUE
*Value
,
942 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
947 if (QuestionId
== QUESTION_ID_REFRESH_MANAGER
|| QuestionId
== QUESTION_ID_REFRESH_CONFIGURE
) {
948 if (Action
== EFI_BROWSER_ACTION_FORM_OPEN
) {
949 DriverHealthManagerUpdateForm ((BOOLEAN
) (QuestionId
== QUESTION_ID_REFRESH_CONFIGURE
));
950 } else if (Action
== EFI_BROWSER_ACTION_FORM_CLOSE
) {
951 DriverHealthManagerCleanDynamicString ();
956 if (Action
!= EFI_BROWSER_ACTION_CHANGED
) {
958 // Do nothing for other UEFI Action. Only do call back when data is changed.
960 return EFI_UNSUPPORTED
;
963 if ((Value
== NULL
) || (ActionRequest
== NULL
)) {
964 return EFI_INVALID_PARAMETER
;
967 DEBUG ((EFI_D_ERROR
, "QuestionId = %x\n", QuestionId
));
970 // We will have returned from processing a callback - user either hit ESC to exit, or selected
971 // a target to display.
972 // Process the diver health status states here.
974 Index
= QuestionId
- QUESTION_ID_DRIVER_HEALTH_BASE
;
975 ASSERT (Index
< mDriverHealthManagerHealthInfoCount
);
977 // Process the driver's healthy status for the specify module
979 DriverHealthManagerProcessSingleControllerHealth (
980 mDriverHealthManagerHealthInfo
[Index
].DriverHealth
,
981 mDriverHealthManagerHealthInfo
[Index
].ControllerHandle
,
982 mDriverHealthManagerHealthInfo
[Index
].ChildHandle
,
983 mDriverHealthManagerHealthInfo
[Index
].HealthStatus
,
984 &(mDriverHealthManagerHealthInfo
[Index
].MessageList
),
985 mDriverHealthManagerHealthInfo
[Index
].HiiHandle
988 DriverHealthManagerUpdateForm ((BOOLEAN
) (QuestionId
== QUESTION_ID_REFRESH_CONFIGURE
));