2 The platform device manager reference implementation
4 Copyright (c) 2004 - 2010, Intel Corporation. <BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "DeviceManager.h"
17 DEVICE_MANAGER_CALLBACK_DATA gDeviceManagerPrivate
= {
18 DEVICE_MANAGER_CALLBACK_DATA_SIGNATURE
,
35 EFI_GUID mDeviceManagerGuid
= DEVICE_MANAGER_FORMSET_GUID
;
36 EFI_GUID mDriverHealthGuid
= DRIVER_HEALTH_FORMSET_GUID
;
38 DEVICE_MANAGER_MENU_ITEM mDeviceManagerMenuItemTable
[] = {
39 { STRING_TOKEN (STR_DISK_DEVICE
), EFI_DISK_DEVICE_CLASS
},
40 { STRING_TOKEN (STR_VIDEO_DEVICE
), EFI_VIDEO_DEVICE_CLASS
},
41 { STRING_TOKEN (STR_NETWORK_DEVICE
), EFI_NETWORK_DEVICE_CLASS
},
42 { STRING_TOKEN (STR_INPUT_DEVICE
), EFI_INPUT_DEVICE_CLASS
},
43 { STRING_TOKEN (STR_ON_BOARD_DEVICE
), EFI_ON_BOARD_DEVICE_CLASS
},
44 { STRING_TOKEN (STR_OTHER_DEVICE
), EFI_OTHER_DEVICE_CLASS
}
47 HII_VENDOR_DEVICE_PATH mDeviceManagerHiiVendorDevicePath
= {
53 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
54 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
58 // {102579A0-3686-466e-ACD8-80C087044F4A}
60 { 0x102579a0, 0x3686, 0x466e, { 0xac, 0xd8, 0x80, 0xc0, 0x87, 0x4, 0x4f, 0x4a } }
64 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
66 (UINT8
) (END_DEVICE_PATH_LENGTH
),
67 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
72 HII_VENDOR_DEVICE_PATH mDriverHealthHiiVendorDevicePath
= {
78 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
79 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
83 // {D8F76651-1675-4986-BED4-3824B2F1F4C8}
85 { 0xd8f76651, 0x1675, 0x4986, { 0xbe, 0xd4, 0x38, 0x24, 0xb2, 0xf1, 0xf4, 0xc8 } }
89 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
91 (UINT8
) (END_DEVICE_PATH_LENGTH
),
92 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
98 This function is invoked if user selected a interactive opcode from Device Manager's
99 Formset. The decision by user is saved to gCallbackKey for later processing. If
100 user set VBIOS, the new value is saved to EFI variable.
102 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
103 @param Action Specifies the type of action taken by the browser.
104 @param QuestionId A unique value which is sent to the original exporting driver
105 so that it can identify the type of data to expect.
106 @param Type The type of value for the question.
107 @param Value A pointer to the data being sent to the original exporting driver.
108 @param ActionRequest On return, points to the action requested by the callback function.
110 @retval EFI_SUCCESS The callback successfully handled the action.
111 @retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.
116 DeviceManagerCallback (
117 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
118 IN EFI_BROWSER_ACTION Action
,
119 IN EFI_QUESTION_ID QuestionId
,
121 IN EFI_IFR_TYPE_VALUE
*Value
,
122 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
125 if ((Value
== NULL
) || (ActionRequest
== NULL
)) {
126 return EFI_INVALID_PARAMETER
;
129 gCallbackKey
= QuestionId
;
132 // Request to exit SendForm(), so as to switch to selected form
134 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
141 This function registers HII packages to HII database.
143 @retval EFI_SUCCESS HII packages for the Device Manager were registered successfully.
144 @retval EFI_OUT_OF_RESOURCES HII packages for the Device Manager failed to be registered.
148 InitializeDeviceManager (
155 // Install Device Path Protocol and Config Access protocol to driver handle
157 Status
= gBS
->InstallMultipleProtocolInterfaces (
158 &gDeviceManagerPrivate
.DriverHandle
,
159 &gEfiDevicePathProtocolGuid
,
160 &mDeviceManagerHiiVendorDevicePath
,
161 &gEfiHiiConfigAccessProtocolGuid
,
162 &gDeviceManagerPrivate
.ConfigAccess
,
165 ASSERT_EFI_ERROR (Status
);
167 Status
= gBS
->InstallMultipleProtocolInterfaces (
168 &gDeviceManagerPrivate
.DriverHealthHandle
,
169 &gEfiDevicePathProtocolGuid
,
170 &mDriverHealthHiiVendorDevicePath
,
171 &gEfiHiiConfigAccessProtocolGuid
,
172 &gDeviceManagerPrivate
.DriverHealthConfigAccess
,
175 ASSERT_EFI_ERROR (Status
);
178 // Publish our HII data
180 gDeviceManagerPrivate
.HiiHandle
= HiiAddPackages (
182 gDeviceManagerPrivate
.DriverHandle
,
187 if (gDeviceManagerPrivate
.HiiHandle
== NULL
) {
188 return EFI_OUT_OF_RESOURCES
;
190 Status
= EFI_SUCCESS
;
194 // Publish Driver Health HII data
196 gDeviceManagerPrivate
.DriverHealthHiiHandle
= HiiAddPackages (
198 gDeviceManagerPrivate
.DriverHealthHandle
,
203 if (gDeviceManagerPrivate
.DriverHealthHiiHandle
== NULL
) {
204 Status
= EFI_OUT_OF_RESOURCES
;
206 Status
= EFI_SUCCESS
;
213 Extract the displayed formset for given HII handle and class guid.
215 @param Handle The HII handle.
216 @param SetupClassGuid The class guid specifies which form set will be displayed.
217 @param FormSetTitle Formset title string.
218 @param FormSetHelp Formset help string.
220 @retval TRUE The formset for given HII handle will be displayed.
221 @return FALSE The formset for given HII handle will not be displayed.
225 ExtractDisplayedHiiFormFromHiiHandle (
226 IN EFI_HII_HANDLE Handle
,
227 IN EFI_GUID
*SetupClassGuid
,
228 OUT EFI_STRING_ID
*FormSetTitle
,
229 OUT EFI_STRING_ID
*FormSetHelp
234 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
239 UINT32 PackageListLength
;
240 EFI_HII_PACKAGE_HEADER PackageHeader
;
244 ASSERT (Handle
!= NULL
);
245 ASSERT (SetupClassGuid
!= NULL
);
246 ASSERT (FormSetTitle
!= NULL
);
247 ASSERT (FormSetHelp
!= NULL
);
255 // Get HII PackageList
258 HiiPackageList
= NULL
;
259 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
261 // Handle is a invalid handle. Check if Handle is corrupted.
263 ASSERT (Status
!= EFI_NOT_FOUND
);
265 // The return status should always be EFI_BUFFER_TOO_SMALL as input buffer's size is 0.
267 ASSERT (Status
== EFI_BUFFER_TOO_SMALL
);
269 HiiPackageList
= AllocatePool (BufferSize
);
270 ASSERT (HiiPackageList
!= NULL
);
272 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
273 if (EFI_ERROR (Status
)) {
278 // Get Form package from this HII package List
280 Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
282 PackageListLength
= ReadUnaligned32 (&HiiPackageList
->PackageLength
);
284 while (Offset
< PackageListLength
) {
285 Package
= ((UINT8
*) HiiPackageList
) + Offset
;
286 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
288 if (PackageHeader
.Type
== EFI_HII_PACKAGE_FORMS
) {
290 // Search FormSet Opcode in this Form Package
292 Offset2
= sizeof (EFI_HII_PACKAGE_HEADER
);
293 while (Offset2
< PackageHeader
.Length
) {
294 OpCodeData
= Package
+ Offset2
;
296 if (((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
== EFI_IFR_FORM_SET_OP
) {
297 if (((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
> OFFSET_OF (EFI_IFR_FORM_SET
, Flags
)) {
299 // Find FormSet OpCode
301 ClassGuidNum
= (UINT8
) (((EFI_IFR_FORM_SET
*) OpCodeData
)->Flags
& 0x3);
302 ClassGuid
= (EFI_GUID
*) (VOID
*)(OpCodeData
+ sizeof (EFI_IFR_FORM_SET
));
303 while (ClassGuidNum
-- > 0) {
304 if (CompareGuid (SetupClassGuid
, ClassGuid
)) {
305 CopyMem (FormSetTitle
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->FormSetTitle
, sizeof (EFI_STRING_ID
));
306 CopyMem (FormSetHelp
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->Help
, sizeof (EFI_STRING_ID
));
307 FreePool (HiiPackageList
);
313 CopyMem (FormSetTitle
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->FormSetTitle
, sizeof (EFI_STRING_ID
));
314 CopyMem (FormSetHelp
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->Help
, sizeof (EFI_STRING_ID
));
315 FreePool (HiiPackageList
);
323 Offset2
+= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
;
328 // Go to next package
330 Offset
+= PackageHeader
.Length
;
333 FreePool (HiiPackageList
);
339 Call the browser and display the device manager to allow user
340 to configure the platform.
342 This function create the dynamic content for device manager. It includes
343 section header for all class of devices, one-of opcode to set VBIOS.
345 @retval EFI_SUCCESS Operation is successful.
346 @return Other values if failed to clean up the dynamic content from HII
359 EFI_STRING_ID TokenHelp
;
360 EFI_HII_HANDLE
*HiiHandles
;
361 EFI_HII_HANDLE HiiHandle
;
362 EFI_STRING_ID FormSetTitle
;
363 EFI_STRING_ID FormSetHelp
;
364 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
365 VOID
*StartOpCodeHandle
;
366 VOID
*EndOpCodeHandle
;
367 EFI_IFR_GUID_LABEL
*StartLabel
;
368 EFI_IFR_GUID_LABEL
*EndLabel
;
370 EFI_HANDLE
*DriverHealthHandles
;
373 Status
= EFI_SUCCESS
;
376 DriverHealthHandles
= NULL
;
379 // Connect all prior to entering the platform setup menu.
381 if (!gConnectAllHappened
) {
382 BdsLibConnectAllDriversToAllControllers ();
383 gConnectAllHappened
= TRUE
;
386 // Create Subtitle OpCodes
389 // Allocate space for creation of UpdateData Buffer
391 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
392 ASSERT (StartOpCodeHandle
!= NULL
);
394 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
395 ASSERT (EndOpCodeHandle
!= NULL
);
398 // Create Hii Extend Label OpCode as the start opcode
400 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
401 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
402 StartLabel
->Number
= LABEL_DEVICES_LIST
;
405 // Create Hii Extend Label OpCode as the end opcode
407 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
408 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
409 EndLabel
->Number
= LABEL_END
;
411 HiiCreateSubTitleOpCode (StartOpCodeHandle
, STRING_TOKEN (STR_DEVICES_LIST
), 0, 0, 1);
414 // Get all the Hii handles
416 HiiHandles
= HiiGetHiiHandles (NULL
);
417 ASSERT (HiiHandles
!= NULL
);
419 HiiHandle
= gDeviceManagerPrivate
.HiiHandle
;
422 // Search for formset of each class type
424 for (Index
= 0; HiiHandles
[Index
] != NULL
; Index
++) {
425 if (!ExtractDisplayedHiiFormFromHiiHandle (HiiHandles
[Index
], &gEfiHiiPlatformSetupFormsetGuid
, &FormSetTitle
, &FormSetHelp
)) {
429 String
= HiiGetString (HiiHandles
[Index
], FormSetTitle
, NULL
);
430 if (String
== NULL
) {
431 String
= HiiGetString (HiiHandle
, STR_MISSING_STRING
, NULL
);
432 ASSERT (String
!= NULL
);
434 Token
= HiiSetString (HiiHandle
, 0, String
, NULL
);
437 String
= HiiGetString (HiiHandles
[Index
], FormSetHelp
, NULL
);
438 if (String
== NULL
) {
439 String
= HiiGetString (HiiHandle
, STR_MISSING_STRING
, NULL
);
440 ASSERT (String
!= NULL
);
442 TokenHelp
= HiiSetString (HiiHandle
, 0, String
, NULL
);
445 HiiCreateActionOpCode (
447 (EFI_QUESTION_ID
) (Index
+ DEVICE_KEY_OFFSET
),
450 EFI_IFR_FLAG_CALLBACK
,
456 // Add End Opcode for Subtitle
458 HiiCreateEndOpCode (StartOpCodeHandle
);
460 Status
= gBS
->LocateHandleBuffer (
462 &gEfiDriverHealthProtocolGuid
,
469 // If there are no drivers installed driver health protocol, do not create driver health entry in UI
471 if (NumHandles
!= 0) {
473 // If driver health protocol is installed, create Driver Health subtitle and entry
475 HiiCreateSubTitleOpCode (StartOpCodeHandle
, STRING_TOKEN (STR_DM_DRIVER_HEALTH_TITLE
), 0, 0, 0);
476 HiiCreateActionOpCode (
477 StartOpCodeHandle
, // Container for dynamic created opcodes
478 DEVICE_MANAGER_KEY_DRIVER_HEALTH
, // Question ID
479 STRING_TOKEN(STR_DRIVER_HEALTH_ALL_HEALTHY
), // Prompt text
480 STRING_TOKEN(STR_DRIVER_HEALTH_STATUS_HELP
), // Help text
481 EFI_IFR_FLAG_CALLBACK
, // Question flag
482 0 // Action String ID
486 // Check All Driver health status
488 if (!PlaformHealthStatusCheck ()) {
490 // At least one driver in the platform are not in healthy status
492 HiiSetString (HiiHandle
, STRING_TOKEN (STR_DRIVER_HEALTH_ALL_HEALTHY
), GetStringById (STRING_TOKEN (STR_DRIVER_NOT_HEALTH
)), NULL
);
495 // For the string of STR_DRIVER_HEALTH_ALL_HEALTHY previously has been updated and we need to update it while re-entry.
497 HiiSetString (HiiHandle
, STRING_TOKEN (STR_DRIVER_HEALTH_ALL_HEALTHY
), GetStringById (STRING_TOKEN (STR_DRIVER_HEALTH_ALL_HEALTHY
)), NULL
);
504 DEVICE_MANAGER_FORM_ID
,
509 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
510 Status
= gFormBrowser2
->SendForm (
519 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
520 EnableResetRequired ();
524 // We will have returned from processing a callback - user either hit ESC to exit, or selected
525 // a target to display
527 if ((gCallbackKey
!= 0) && (gCallbackKey
!= DEVICE_MANAGER_KEY_DRIVER_HEALTH
)) {
528 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
529 Status
= gFormBrowser2
->SendForm (
531 &HiiHandles
[gCallbackKey
- DEVICE_KEY_OFFSET
],
539 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
540 EnableResetRequired ();
544 // Force return to Device Manager
546 gCallbackKey
= FRONT_PAGE_KEY_DEVICE_MANAGER
;
550 // Driver Health item chose.
552 if (gCallbackKey
== DEVICE_MANAGER_KEY_DRIVER_HEALTH
) {
555 // Force return to Device Manager
557 gCallbackKey
= FRONT_PAGE_KEY_DEVICE_MANAGER
;
561 // Cleanup dynamic created strings in HII database by reinstall the packagelist
563 HiiRemovePackages (HiiHandle
);
565 gDeviceManagerPrivate
.HiiHandle
= HiiAddPackages (
567 gDeviceManagerPrivate
.DriverHandle
,
572 if (gDeviceManagerPrivate
.HiiHandle
== NULL
) {
573 Status
= EFI_OUT_OF_RESOURCES
;
575 Status
= EFI_SUCCESS
;
578 HiiFreeOpCodeHandle (StartOpCodeHandle
);
579 HiiFreeOpCodeHandle (EndOpCodeHandle
);
580 FreePool (HiiHandles
);
586 This function is invoked if user selected a interactive opcode from Driver Health's
587 Formset. The decision by user is saved to gCallbackKey for later processing.
589 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
590 @param Action Specifies the type of action taken by the browser.
591 @param QuestionId A unique value which is sent to the original exporting driver
592 so that it can identify the type of data to expect.
593 @param Type The type of value for the question.
594 @param Value A pointer to the data being sent to the original exporting driver.
595 @param ActionRequest On return, points to the action requested by the callback function.
597 @retval EFI_SUCCESS The callback successfully handled the action.
598 @retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.
603 DriverHealthCallback (
604 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
605 IN EFI_BROWSER_ACTION Action
,
606 IN EFI_QUESTION_ID QuestionId
,
608 IN EFI_IFR_TYPE_VALUE
*Value
,
609 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
612 if ((Value
== NULL
) || (ActionRequest
== NULL
)) {
613 return EFI_INVALID_PARAMETER
;
616 gCallbackKey
= QuestionId
;
619 // Request to exit SendForm(), so as to switch to selected form
621 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
627 Collect and display the platform's driver health relative information, allow user to do interactive
628 operation while the platform is unhealthy.
630 This function display a form which divided into two parts. The one list all modules which has installed
631 driver health protocol. The list usually contain driver name, controller name, and it's health info.
632 While the driver name can't be retrieved, will use device path as backup. The other part of the form provide
633 a choice to the user to repair all platform.
642 EFI_HII_HANDLE HiiHandle
;
643 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
644 EFI_IFR_GUID_LABEL
*StartLabel
;
645 EFI_IFR_GUID_LABEL
*StartLabelRepair
;
646 EFI_IFR_GUID_LABEL
*EndLabel
;
647 EFI_IFR_GUID_LABEL
*EndLabelRepair
;
648 VOID
*StartOpCodeHandle
;
649 VOID
*EndOpCodeHandle
;
650 VOID
*StartOpCodeHandleRepair
;
651 VOID
*EndOpCodeHandleRepair
;
654 EFI_STRING_ID TokenHelp
;
656 EFI_STRING TmpString
;
657 EFI_STRING DriverName
;
658 EFI_STRING ControllerName
;
659 LIST_ENTRY DriverHealthList
;
660 DRIVER_HEALTH_INFO
*DriverHealthInfo
;
662 EFI_DEVICE_PATH_PROTOCOL
*DriverDevicePath
;
665 HiiHandle
= gDeviceManagerPrivate
.DriverHealthHiiHandle
;
668 DriverHealthInfo
= NULL
;
669 DriverDevicePath
= NULL
;
670 InitializeListHead (&DriverHealthList
);
673 // Allocate space for creation of UpdateData Buffer
675 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
676 ASSERT (StartOpCodeHandle
!= NULL
);
678 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
679 ASSERT (EndOpCodeHandle
!= NULL
);
681 StartOpCodeHandleRepair
= HiiAllocateOpCodeHandle ();
682 ASSERT (StartOpCodeHandleRepair
!= NULL
);
684 EndOpCodeHandleRepair
= HiiAllocateOpCodeHandle ();
685 ASSERT (EndOpCodeHandleRepair
!= NULL
);
688 // Create Hii Extend Label OpCode as the start opcode
690 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
691 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
692 StartLabel
->Number
= LABEL_DRIVER_HEALTH
;
695 // Create Hii Extend Label OpCode as the start opcode
697 StartLabelRepair
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandleRepair
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
698 StartLabelRepair
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
699 StartLabelRepair
->Number
= LABEL_DRIVER_HEALTH_REAPIR_ALL
;
702 // Create Hii Extend Label OpCode as the end opcode
704 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
705 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
706 EndLabel
->Number
= LABEL_DRIVER_HEALTH_END
;
709 // Create Hii Extend Label OpCode as the end opcode
711 EndLabelRepair
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandleRepair
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
712 EndLabelRepair
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
713 EndLabelRepair
->Number
= LABEL_DRIVER_HEALTH_REAPIR_ALL_END
;
715 HiiCreateSubTitleOpCode (StartOpCodeHandle
, STRING_TOKEN (STR_DH_STATUS_LIST
), 0, 0, 1);
717 Status
= GetAllControllersHealthStatus (&DriverHealthList
);
718 ASSERT (Status
!= EFI_OUT_OF_RESOURCES
);
720 Link
= GetFirstNode (&DriverHealthList
);
722 while (!IsNull (&DriverHealthList
, Link
)) {
723 DriverHealthInfo
= DEVICE_MANAGER_HEALTH_INFO_FROM_LINK (Link
);
726 // Assume no line strings is longer than 512 bytes.
728 String
= (EFI_STRING
) AllocateZeroPool (0x200);
729 ASSERT (String
!= NULL
);
731 Status
= DriverHealthGetDriverName (DriverHealthInfo
->DriverHandle
, &DriverName
);
732 if (EFI_ERROR (Status
)) {
734 // Can not get the Driver name, so use the Device path
736 DriverDevicePath
= DevicePathFromHandle (DriverHealthInfo
->DriverHandle
);
737 DriverName
= DevicePathToStr (DriverDevicePath
);
740 // Add the Driver name & Controller name into FormSetTitle string
742 StrnCat (String
, DriverName
, StrLen (DriverName
));
745 Status
= DriverHealthGetControllerName (
746 DriverHealthInfo
->DriverHandle
,
747 DriverHealthInfo
->ControllerHandle
,
748 DriverHealthInfo
->ChildHandle
,
752 if (!EFI_ERROR (Status
)) {
754 // Can not get the Controller name, just let it empty.
756 StrnCat (String
, L
" ", StrLen (L
" "));
757 StrnCat (String
, ControllerName
, StrLen (ControllerName
));
761 // Add the message of the Module itself provided after the string item.
763 if ((DriverHealthInfo
->MessageList
!= NULL
) && (DriverHealthInfo
->MessageList
->StringId
!= 0)) {
764 StrnCat (String
, L
" ", StrLen (L
" "));
765 TmpString
= HiiGetString (
766 DriverHealthInfo
->MessageList
->HiiHandle
,
767 DriverHealthInfo
->MessageList
->StringId
,
771 // Assert if can not retrieve the message string
773 ASSERT (TmpString
!= NULL
);
774 StrnCat (String
, TmpString
, StrLen (TmpString
));
775 FreePool (TmpString
);
778 // Update the string will be displayed base on the driver's health status
780 switch(DriverHealthInfo
->HealthStatus
) {
781 case EfiDriverHealthStatusRepairRequired
:
782 Length
= StrLen (GetStringById (STRING_TOKEN (STR_REPAIR_REQUIRED
)));
783 StrnCat (String
, GetStringById (STRING_TOKEN (STR_REPAIR_REQUIRED
)), Length
);
785 case EfiDriverHealthStatusConfigurationRequired
:
786 Length
= StrLen (GetStringById (STRING_TOKEN (STR_CONFIGURATION_REQUIRED
)));
787 StrnCat (String
, GetStringById (STRING_TOKEN (STR_CONFIGURATION_REQUIRED
)), Length
);
789 case EfiDriverHealthStatusFailed
:
790 Length
= StrLen (GetStringById (STRING_TOKEN (STR_OPERATION_FAILED
)));
791 StrnCat (String
, GetStringById (STRING_TOKEN (STR_OPERATION_FAILED
)), Length
);
793 case EfiDriverHealthStatusReconnectRequired
:
794 Length
= StrLen (GetStringById (STRING_TOKEN (STR_RECONNECT_REQUIRED
)));
795 StrnCat (String
, GetStringById (STRING_TOKEN (STR_RECONNECT_REQUIRED
)), Length
);
797 case EfiDriverHealthStatusRebootRequired
:
798 Length
= StrLen (GetStringById (STRING_TOKEN (STR_REBOOT_REQUIRED
)));
799 StrnCat (String
, GetStringById (STRING_TOKEN (STR_REBOOT_REQUIRED
)), Length
);
802 Length
= StrLen (GetStringById (STRING_TOKEN (STR_DRIVER_HEALTH_HEALTHY
)));
803 StrnCat (String
, GetStringById (STRING_TOKEN (STR_DRIVER_HEALTH_HEALTHY
)), Length
);
808 Token
= HiiSetString (HiiHandle
, 0, String
, NULL
);
811 TokenHelp
= HiiSetString (HiiHandle
, 0, GetStringById( STRING_TOKEN (STR_DH_REPAIR_SINGLE_HELP
)), NULL
);
813 HiiCreateActionOpCode (
815 (EFI_QUESTION_ID
) (Index
+ DRIVER_HEALTH_KEY_OFFSET
),
818 EFI_IFR_FLAG_CALLBACK
,
822 Link
= GetNextNode (&DriverHealthList
, Link
);
826 // Add End Opcode for Subtitle
828 HiiCreateEndOpCode (StartOpCodeHandle
);
830 HiiCreateSubTitleOpCode (StartOpCodeHandleRepair
, STRING_TOKEN (STR_DRIVER_HEALTH_REPAIR_ALL
), 0, 0, 1);
831 TokenHelp
= HiiSetString (HiiHandle
, 0, GetStringById( STRING_TOKEN (STR_DH_REPAIR_ALL_HELP
)), NULL
);
833 if (PlaformHealthStatusCheck ()) {
835 // No action need to do for the platform
837 Token
= HiiSetString (HiiHandle
, 0, GetStringById( STRING_TOKEN (STR_DRIVER_HEALTH_ALL_HEALTHY
)), NULL
);
838 HiiCreateActionOpCode (
839 StartOpCodeHandleRepair
,
843 EFI_IFR_FLAG_READ_ONLY
,
848 // Create ActionOpCode only while the platform need to do health related operation.
850 Token
= HiiSetString (HiiHandle
, 0, GetStringById( STRING_TOKEN (STR_DH_REPAIR_ALL_TITLE
)), NULL
);
851 HiiCreateActionOpCode (
852 StartOpCodeHandleRepair
,
853 (EFI_QUESTION_ID
) DRIVER_HEALTH_REPAIR_ALL_KEY
,
856 EFI_IFR_FLAG_CALLBACK
,
861 HiiCreateEndOpCode (StartOpCodeHandleRepair
);
863 Status
= HiiUpdateForm (
866 DRIVER_HEALTH_FORM_ID
,
870 ASSERT (Status
!= EFI_NOT_FOUND
);
871 ASSERT (Status
!= EFI_BUFFER_TOO_SMALL
);
873 Status
= HiiUpdateForm (
876 DRIVER_HEALTH_FORM_ID
,
877 StartOpCodeHandleRepair
,
878 EndOpCodeHandleRepair
880 ASSERT (Status
!= EFI_NOT_FOUND
);
881 ASSERT (Status
!= EFI_BUFFER_TOO_SMALL
);
883 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
884 Status
= gFormBrowser2
->SendForm (
889 DRIVER_HEALTH_FORM_ID
,
893 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
894 EnableResetRequired ();
898 // We will have returned from processing a callback - user either hit ESC to exit, or selected
899 // a target to display.
900 // Process the diver health status states here.
902 if (gCallbackKey
>= DRIVER_HEALTH_KEY_OFFSET
&& gCallbackKey
!= DRIVER_HEALTH_REPAIR_ALL_KEY
) {
903 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
905 Link
= GetFirstNode (&DriverHealthList
);
908 while (!IsNull (&DriverHealthList
, Link
)) {
910 // Got the item relative node in the List
912 if (Index
== (gCallbackKey
- DRIVER_HEALTH_KEY_OFFSET
)) {
913 DriverHealthInfo
= DEVICE_MANAGER_HEALTH_INFO_FROM_LINK (Link
);
915 // Process the driver's healthy status for the specify module
917 ProcessSingleControllerHealth (
918 DriverHealthInfo
->DriverHealth
,
919 DriverHealthInfo
->ControllerHandle
,
920 DriverHealthInfo
->ChildHandle
,
921 DriverHealthInfo
->HealthStatus
,
922 &(DriverHealthInfo
->MessageList
),
923 DriverHealthInfo
->HiiHandle
928 Link
= GetNextNode (&DriverHealthList
, Link
);
931 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
932 EnableResetRequired ();
936 // Force return to the form of Driver Health in Device Manager
938 gCallbackKey
= DRIVER_HEALTH_RETURN_KEY
;
942 // Repair the whole platform
944 if (gCallbackKey
== DRIVER_HEALTH_REPAIR_ALL_KEY
) {
945 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
947 PlatformRepairAll (&DriverHealthList
);
949 gCallbackKey
= DRIVER_HEALTH_RETURN_KEY
;
953 // Cleanup dynamic created strings in HII database by reinstall the packagelist
956 HiiRemovePackages (HiiHandle
);
958 gDeviceManagerPrivate
.DriverHealthHiiHandle
= HiiAddPackages (
960 gDeviceManagerPrivate
.DriverHealthHandle
,
965 if (gDeviceManagerPrivate
.DriverHealthHiiHandle
== NULL
) {
966 Status
= EFI_OUT_OF_RESOURCES
;
968 Status
= EFI_SUCCESS
;
971 // Free driver health info list
973 while (!IsListEmpty (&DriverHealthList
)) {
975 Link
= GetFirstNode(&DriverHealthList
);
976 DriverHealthInfo
= DEVICE_MANAGER_HEALTH_INFO_FROM_LINK (Link
);
977 RemoveEntryList (Link
);
979 if (DriverHealthInfo
->MessageList
!= NULL
) {
980 FreePool(DriverHealthInfo
->MessageList
);
981 FreePool (DriverHealthInfo
);
985 HiiFreeOpCodeHandle (StartOpCodeHandle
);
986 HiiFreeOpCodeHandle (EndOpCodeHandle
);
987 HiiFreeOpCodeHandle (StartOpCodeHandleRepair
);
988 HiiFreeOpCodeHandle (EndOpCodeHandleRepair
);
990 if (gCallbackKey
== DRIVER_HEALTH_RETURN_KEY
) {
992 // Force return to Driver Health Form
994 gCallbackKey
= DEVICE_MANAGER_KEY_DRIVER_HEALTH
;
1001 Check the Driver Health status of a single controller and try to process it if not healthy.
1003 This function called by CheckAllControllersHealthStatus () function in order to process a specify
1004 contoller's health state.
1006 @param DriverHealthList A Pointer to the list contain all of the platform driver health information.
1007 @param DriverHandle The handle of driver.
1008 @param ControllerHandle The class guid specifies which form set will be displayed.
1009 @param ChildHandle The handle of the child controller to retrieve the health
1010 status on. This is an optional parameter that may be NULL.
1011 @param DriverHealth A pointer to the EFI_DRIVER_HEALTH_PROTOCOL instance.
1012 @param HealthStatus The health status of the controller.
1014 @retval EFI_INVALID_PARAMETER HealthStatus or DriverHealth is NULL.
1015 @retval HealthStatus The Health status of specify controller.
1016 @retval EFI_OUT_OF_RESOURCES The list of Driver Health Protocol handles can not be retrieved.
1017 @retval EFI_NOT_FOUND No controller in the platform install Driver Health Protocol.
1018 @retval EFI_SUCCESS The Health related operation has been taken successfully.
1023 GetSingleControllerHealthStatus (
1024 IN OUT LIST_ENTRY
*DriverHealthList
,
1025 IN EFI_HANDLE DriverHandle
,
1026 IN EFI_HANDLE ControllerHandle
, OPTIONAL
1027 IN EFI_HANDLE ChildHandle
, OPTIONAL
1028 IN EFI_DRIVER_HEALTH_PROTOCOL
*DriverHealth
,
1029 IN EFI_DRIVER_HEALTH_STATUS
*HealthStatus
1033 EFI_DRIVER_HEALTH_HII_MESSAGE
*MessageList
;
1034 EFI_HII_HANDLE FormHiiHandle
;
1035 DRIVER_HEALTH_INFO
*DriverHealthInfo
;
1037 if (HealthStatus
== NULL
) {
1039 // If HealthStatus is NULL, then return EFI_INVALID_PARAMETER
1041 return EFI_INVALID_PARAMETER
;
1045 // Assume the HealthStatus is healthy
1047 *HealthStatus
= EfiDriverHealthStatusHealthy
;
1049 if (DriverHealth
== NULL
) {
1051 // If DriverHealth is NULL, then return EFI_INVALID_PARAMETER
1053 return EFI_INVALID_PARAMETER
;
1056 if (ControllerHandle
== NULL
) {
1058 // If ControllerHandle is NULL, the return the cumulative health status of the driver
1060 Status
= DriverHealth
->GetHealthStatus (DriverHealth
, NULL
, NULL
, HealthStatus
, NULL
, NULL
);
1061 if (*HealthStatus
== EfiDriverHealthStatusHealthy
) {
1063 // Add the driver health related information into the list
1065 DriverHealthInfo
= AllocateZeroPool (sizeof (DRIVER_HEALTH_INFO
));
1066 if (DriverHealthInfo
== NULL
) {
1067 return EFI_OUT_OF_RESOURCES
;
1070 DriverHealthInfo
->Signature
= DEVICE_MANAGER_DRIVER_HEALTH_INFO_SIGNATURE
;
1071 DriverHealthInfo
->DriverHandle
= DriverHandle
;
1072 DriverHealthInfo
->ControllerHandle
= NULL
;
1073 DriverHealthInfo
->ChildHandle
= NULL
;
1074 DriverHealthInfo
->HiiHandle
= NULL
;
1075 DriverHealthInfo
->DriverHealth
= DriverHealth
;
1076 DriverHealthInfo
->MessageList
= NULL
;
1077 DriverHealthInfo
->HealthStatus
= *HealthStatus
;
1079 InsertTailList (DriverHealthList
, &DriverHealthInfo
->Link
);
1085 FormHiiHandle
= NULL
;
1088 // Collect the health status with the optional HII message list
1090 Status
= DriverHealth
->GetHealthStatus (DriverHealth
, ControllerHandle
, ChildHandle
, HealthStatus
, &MessageList
, &FormHiiHandle
);
1092 if (EFI_ERROR (Status
)) {
1094 // If the health status could not be retrieved, then return immediately
1100 // Add the driver health related information into the list
1102 DriverHealthInfo
= AllocateZeroPool (sizeof (DRIVER_HEALTH_INFO
));
1103 if (DriverHealthInfo
== NULL
) {
1104 return EFI_OUT_OF_RESOURCES
;
1107 DriverHealthInfo
->Signature
= DEVICE_MANAGER_DRIVER_HEALTH_INFO_SIGNATURE
;
1108 DriverHealthInfo
->DriverHandle
= DriverHandle
;
1109 DriverHealthInfo
->ControllerHandle
= ControllerHandle
;
1110 DriverHealthInfo
->ChildHandle
= ChildHandle
;
1111 DriverHealthInfo
->HiiHandle
= FormHiiHandle
;
1112 DriverHealthInfo
->DriverHealth
= DriverHealth
;
1113 DriverHealthInfo
->MessageList
= MessageList
;
1114 DriverHealthInfo
->HealthStatus
= *HealthStatus
;
1116 InsertTailList (DriverHealthList
, &DriverHealthInfo
->Link
);
1122 Collects all the EFI Driver Health Protocols currently present in the EFI Handle Database,
1123 and queries each EFI Driver Health Protocol to determine if one or more of the controllers
1124 managed by each EFI Driver Health Protocol instance are not healthy.
1126 @param DriverHealthList A Pointer to the list contain all of the platform driver health
1129 @retval EFI_NOT_FOUND No controller in the platform install Driver Health Protocol.
1130 @retval EFI_SUCCESS All the controllers in the platform are healthy.
1131 @retval EFI_OUT_OF_RESOURCES The list of Driver Health Protocol handles can not be retrieved.
1135 GetAllControllersHealthStatus (
1136 IN OUT LIST_ENTRY
*DriverHealthList
1141 EFI_HANDLE
*DriverHealthHandles
;
1142 EFI_DRIVER_HEALTH_PROTOCOL
*DriverHealth
;
1143 EFI_DRIVER_HEALTH_STATUS HealthStatus
;
1144 UINTN DriverHealthIndex
;
1145 EFI_HANDLE
*Handles
;
1147 UINTN ControllerIndex
;
1151 // Initialize local variables
1154 DriverHealthHandles
= NULL
;
1158 HealthStatus
= EfiDriverHealthStatusHealthy
;
1160 Status
= gBS
->LocateHandleBuffer (
1162 &gEfiDriverHealthProtocolGuid
,
1165 &DriverHealthHandles
1168 if (Status
== EFI_NOT_FOUND
|| NumHandles
== 0) {
1170 // If there are no Driver Health Protocols handles, then return EFI_NOT_FOUND
1172 return EFI_NOT_FOUND
;
1175 if (EFI_ERROR (Status
) || DriverHealthHandles
== NULL
) {
1177 // If the list of Driver Health Protocol handles can not be retrieved, then
1178 // return EFI_OUT_OF_RESOURCES
1180 return EFI_OUT_OF_RESOURCES
;
1184 // Check the health status of all controllers in the platform
1185 // Start by looping through all the Driver Health Protocol handles in the handle database
1187 for (DriverHealthIndex
= 0; DriverHealthIndex
< NumHandles
; DriverHealthIndex
++) {
1189 // Skip NULL Driver Health Protocol handles
1191 if (DriverHealthHandles
[DriverHealthIndex
] == NULL
) {
1196 // Retrieve the Driver Health Protocol from DriverHandle
1198 Status
= gBS
->HandleProtocol (
1199 DriverHealthHandles
[DriverHealthIndex
],
1200 &gEfiDriverHealthProtocolGuid
,
1201 (VOID
**)&DriverHealth
1203 if (EFI_ERROR (Status
)) {
1205 // If the Driver Health Protocol can not be retrieved, then skip to the next
1206 // Driver Health Protocol handle
1212 // Check the health of all the controllers managed by a Driver Health Protocol handle
1214 Status
= GetSingleControllerHealthStatus (DriverHealthList
, DriverHealthHandles
[DriverHealthIndex
], NULL
, NULL
, DriverHealth
, &HealthStatus
);
1217 // If Status is an error code, then the health information could not be retrieved, so assume healthy
1218 // and skip to the next Driver Health Protocol handle
1220 if (EFI_ERROR (Status
)) {
1225 // If all the controllers managed by this Driver Health Protocol are healthy, then skip to the next
1226 // Driver Health Protocol handle
1228 if (HealthStatus
== EfiDriverHealthStatusHealthy
) {
1233 // See if the list of all handles in the handle database has been retrieved
1236 if (Handles
== NULL
) {
1238 // Retrieve the list of all handles from the handle database
1240 Status
= gBS
->LocateHandleBuffer (
1247 if (EFI_ERROR (Status
) || Handles
== NULL
) {
1249 // If all the handles in the handle database can not be retrieved, then
1250 // return EFI_OUT_OF_RESOURCES
1252 Status
= EFI_OUT_OF_RESOURCES
;
1257 // Loop through all the controller handles in the handle database
1259 for (ControllerIndex
= 0; ControllerIndex
< HandleCount
; ControllerIndex
++) {
1261 // Skip NULL controller handles
1263 if (Handles
[ControllerIndex
] == NULL
) {
1267 Status
= GetSingleControllerHealthStatus (DriverHealthList
, DriverHealthHandles
[DriverHealthIndex
], Handles
[ControllerIndex
], NULL
, DriverHealth
, &HealthStatus
);
1268 if (EFI_ERROR (Status
)) {
1270 // If Status is an error code, then the health information could not be retrieved, so assume healthy
1272 HealthStatus
= EfiDriverHealthStatusHealthy
;
1276 // If CheckHealthSingleController() returned an error on a terminal state, then do not check the health of child controllers
1278 if (EFI_ERROR (Status
)) {
1283 // Loop through all the child handles in the handle database
1285 for (ChildIndex
= 0; ChildIndex
< HandleCount
; ChildIndex
++) {
1287 // Skip NULL child handles
1289 if (Handles
[ChildIndex
] == NULL
) {
1293 Status
= GetSingleControllerHealthStatus (DriverHealthList
, DriverHealthHandles
[DriverHealthIndex
], Handles
[ControllerIndex
], Handles
[ChildIndex
], DriverHealth
, &HealthStatus
);
1294 if (EFI_ERROR (Status
)) {
1296 // If Status is an error code, then the health information could not be retrieved, so assume healthy
1298 HealthStatus
= EfiDriverHealthStatusHealthy
;
1302 // If CheckHealthSingleController() returned an error on a terminal state, then skip to the next child
1304 if (EFI_ERROR (Status
)) {
1311 Status
= EFI_SUCCESS
;
1314 if (Handles
!= NULL
) {
1315 gBS
->FreePool (Handles
);
1317 if (DriverHealthHandles
!= NULL
) {
1318 gBS
->FreePool (DriverHealthHandles
);
1326 Check the healthy status of the platform, this function will return immediately while found one driver
1327 in the platform are not healthy.
1329 @retval FALSE at least one driver in the platform are not healthy.
1330 @retval TRUE No controller install Driver Health Protocol,
1331 or all controllers in the platform are in healthy status.
1334 PlaformHealthStatusCheck (
1338 EFI_DRIVER_HEALTH_STATUS HealthStatus
;
1342 EFI_HANDLE
*DriverHealthHandles
;
1343 EFI_DRIVER_HEALTH_PROTOCOL
*DriverHealth
;
1347 // Initialize local variables
1349 DriverHealthHandles
= NULL
;
1350 DriverHealth
= NULL
;
1352 HealthStatus
= EfiDriverHealthStatusHealthy
;
1354 Status
= gBS
->LocateHandleBuffer (
1356 &gEfiDriverHealthProtocolGuid
,
1359 &DriverHealthHandles
1362 // There are no handles match the search for Driver Health Protocol has been installed.
1364 if (Status
== EFI_NOT_FOUND
) {
1368 // Assume all modules are healthy.
1373 // Found one or more Handles.
1375 if (!EFI_ERROR (Status
)) {
1376 for (Index
= 0; Index
< NoHandles
; Index
++) {
1377 Status
= gBS
->HandleProtocol (
1378 DriverHealthHandles
[Index
],
1379 &gEfiDriverHealthProtocolGuid
,
1380 (VOID
**) &DriverHealth
1382 if (!EFI_ERROR (Status
)) {
1383 Status
= DriverHealth
->GetHealthStatus (
1393 // Get the healthy status of the module
1395 if (!EFI_ERROR (Status
)) {
1396 if (HealthStatus
!= EfiDriverHealthStatusHealthy
) {
1398 // Return immediately one driver's status not in healthy.
1409 Processes a single controller using the EFI Driver Health Protocol associated with
1410 that controller. This algorithm continues to query the GetHealthStatus() service until
1411 one of the legal terminal states of the EFI Driver Health Protocol is reached. This may
1412 require the processing of HII Messages, HII Form, and invocation of repair operations.
1414 @param DriverHealth A pointer to the EFI_DRIVER_HEALTH_PROTOCOL instance.
1415 @param ControllerHandle The class guid specifies which form set will be displayed.
1416 @param ChildHandle The handle of the child controller to retrieve the health
1417 status on. This is an optional parameter that may be NULL.
1418 @param HealthStatus The health status of the controller.
1419 @param MessageList An array of warning or error messages associated
1420 with the controller specified by ControllerHandle and
1421 ChildHandle. This is an optional parameter that may be NULL.
1422 @param FormHiiHandle The HII handle for an HII form associated with the
1423 controller specified by ControllerHandle and ChildHandle.
1426 ProcessSingleControllerHealth (
1427 IN EFI_DRIVER_HEALTH_PROTOCOL
*DriverHealth
,
1428 IN EFI_HANDLE ControllerHandle
, OPTIONAL
1429 IN EFI_HANDLE ChildHandle
, OPTIONAL
1430 IN EFI_DRIVER_HEALTH_STATUS HealthStatus
,
1431 IN EFI_DRIVER_HEALTH_HII_MESSAGE
**MessageList
, OPTIONAL
1432 IN EFI_HII_HANDLE FormHiiHandle
1436 EFI_DRIVER_HEALTH_STATUS LocalHealthStatus
;
1438 LocalHealthStatus
= HealthStatus
;
1440 // If the module need to be repaired or reconfiguration, will process it until
1441 // reach a terminal status. The status from EfiDriverHealthStatusRepairRequired after repair
1442 // will be in (Health, Failed, Configuration Required).
1444 while( LocalHealthStatus
== EfiDriverHealthStatusConfigurationRequired
||
1445 LocalHealthStatus
== EfiDriverHealthStatusRepairRequired
) {
1447 if (LocalHealthStatus
== EfiDriverHealthStatusRepairRequired
) {
1448 Status
= DriverHealth
->Repair (
1452 (EFI_DRIVER_HEALTH_REPAIR_PROGRESS_NOTIFY
) RepairNotify
1456 // Via a form of the driver need to do configuration provided to process of status in
1457 // EfiDriverHealthStatusConfigurationRequired. The status after configuration should be in
1458 // (Healthy, Reboot Required, Failed, Reconnect Required, Repair Required).
1460 if (LocalHealthStatus
== EfiDriverHealthStatusConfigurationRequired
) {
1461 Status
= gFormBrowser2
->SendForm (
1465 &gEfiHiiDriverHealthFormsetGuid
,
1470 ASSERT( !EFI_ERROR (Status
));
1473 Status
= DriverHealth
->GetHealthStatus (
1481 ASSERT_EFI_ERROR (Status
);
1483 if (*MessageList
!= NULL
) {
1484 ProcessMessages (*MessageList
);
1489 // Health status in {Healthy, Failed} may also have Messages need to process
1491 if (LocalHealthStatus
== EfiDriverHealthStatusHealthy
|| LocalHealthStatus
== EfiDriverHealthStatusFailed
) {
1492 if (*MessageList
!= NULL
) {
1493 ProcessMessages (*MessageList
);
1497 // Check for RebootRequired or ReconnectRequired
1499 if (LocalHealthStatus
== EfiDriverHealthStatusRebootRequired
) {
1500 gRT
->ResetSystem (EfiResetWarm
, EFI_SUCCESS
, 0, NULL
);
1504 // Do reconnect if need.
1506 if (LocalHealthStatus
== EfiDriverHealthStatusReconnectRequired
) {
1507 Status
= gBS
->DisconnectController (ControllerHandle
, NULL
, NULL
);
1508 if (EFI_ERROR (Status
)) {
1510 // Disconnect failed. Need to promote reconnect to a reboot.
1512 gRT
->ResetSystem (EfiResetWarm
, EFI_SUCCESS
, 0, NULL
);
1514 gBS
->ConnectController (ControllerHandle
, NULL
, NULL
, TRUE
);
1520 Platform specific notification function for controller repair operations.
1522 If the driver for a controller support the Driver Health Protocol and the
1523 current state of the controller is EfiDriverHealthStatusRepairRequired then
1524 when the Repair() service of the Driver Health Protocol is called, this
1525 platform specific notification function can display the progress of the repair
1526 operation. Some platforms may choose to not display anything, other may choose
1527 to show the percentage complete on text consoles, and other may choose to render
1528 a progress bar on text and graphical consoles.
1530 This function displays the percentage of the repair operation that has been
1531 completed on text consoles. The percentage is Value / Limit * 100%.
1533 @param Value Value in the range 0..Limit the the repair has completed..
1534 @param Limit The maximum value of Value
1546 Print(L
"Repair Progress Undefined\n\r");
1548 Percent
= Value
* 100 / Limit
;
1549 Print(L
"Repair Progress = %3d%%\n\r", Percent
);
1554 Processes a set of messages returned by the GetHealthStatus ()
1555 service of the EFI Driver Health Protocol
1557 @param MessageList The MessageList point to messages need to processed.
1562 IN EFI_DRIVER_HEALTH_HII_MESSAGE
*MessageList
1566 EFI_STRING MessageString
;
1568 for (MessageIndex
= 0;
1569 MessageList
[MessageIndex
].HiiHandle
!= NULL
;
1572 MessageString
= HiiGetString (
1573 MessageList
[MessageIndex
].HiiHandle
,
1574 MessageList
[MessageIndex
].StringId
,
1577 if (MessageString
!= NULL
) {
1579 // User can customize the output. Just simply print out the MessageString like below.
1580 // Also can use the HiiHandle to display message on the front page.
1582 // Print(L"%s\n",MessageString);
1583 // gBS->Stall (100000);
1590 Repair the whole platform.
1592 This function is the main entry for user choose "Repair All" in the front page.
1593 It will try to do recovery job till all the driver health protocol installed modules
1594 reach a terminal state.
1596 @param DriverHealthList A Pointer to the list contain all of the platform driver health
1602 IN LIST_ENTRY
*DriverHealthList
1605 DRIVER_HEALTH_INFO
*DriverHealthInfo
;
1608 ASSERT (DriverHealthList
!= NULL
);
1610 Link
= GetFirstNode (DriverHealthList
);
1612 while (!IsNull (DriverHealthList
, Link
)) {
1613 DriverHealthInfo
= DEVICE_MANAGER_HEALTH_INFO_FROM_LINK (Link
);
1615 // Do driver health status operation by each link node
1617 ASSERT (DriverHealthInfo
!= NULL
);
1619 ProcessSingleControllerHealth (
1620 DriverHealthInfo
->DriverHealth
,
1621 DriverHealthInfo
->ControllerHandle
,
1622 DriverHealthInfo
->ChildHandle
,
1623 DriverHealthInfo
->HealthStatus
,
1624 &(DriverHealthInfo
->MessageList
),
1625 DriverHealthInfo
->HiiHandle
1628 Link
= GetNextNode (DriverHealthList
, Link
);
1634 Select the best matching language according to front page policy for best user experience.
1636 This function supports both ISO 639-2 and RFC 4646 language codes, but language
1637 code types may not be mixed in a single call to this function.
1639 @param SupportedLanguages A pointer to a Null-terminated ASCII string that
1640 contains a set of language codes in the format
1641 specified by Iso639Language.
1642 @param Iso639Language If TRUE, then all language codes are assumed to be
1643 in ISO 639-2 format. If FALSE, then all language
1644 codes are assumed to be in RFC 4646 language format.
1646 @retval NULL The best matching language could not be found in SupportedLanguages.
1647 @retval NULL There are not enough resources available to return the best matching
1649 @retval Other A pointer to a Null-terminated ASCII string that is the best matching
1650 language in SupportedLanguages.
1653 DriverHealthSelectBestLanguage (
1654 IN CHAR8
*SupportedLanguages
,
1655 IN BOOLEAN Iso639Language
1658 CHAR8
*LanguageVariable
;
1659 CHAR8
*BestLanguage
;
1661 LanguageVariable
= GetEfiGlobalVariable (Iso639Language
? L
"Lang" : L
"PlatformLang");
1663 BestLanguage
= GetBestLanguage(
1666 (LanguageVariable
!= NULL
) ? LanguageVariable
: "",
1667 Iso639Language
? "eng" : "en-US",
1670 if (LanguageVariable
!= NULL
) {
1671 FreePool (LanguageVariable
);
1674 return BestLanguage
;
1681 This is an internal worker function to get the Component Name (2) protocol interface
1682 and the language it supports.
1684 @param ProtocolGuid A pointer to an EFI_GUID. It points to Component Name (2) protocol GUID.
1685 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
1686 @param ComponentName A pointer to the Component Name (2) protocol interface.
1687 @param SupportedLanguage The best suitable language that matches the SupportedLangues interface for the
1688 located Component Name (2) instance.
1690 @retval EFI_SUCCESS The Component Name (2) protocol instance is successfully located and we find
1691 the best matching language it support.
1692 @retval EFI_UNSUPPORTED The input Language is not supported by the Component Name (2) protocol.
1693 @retval Other Some error occurs when locating Component Name (2) protocol instance or finding
1694 the supported language.
1698 GetComponentNameWorker (
1699 IN EFI_GUID
*ProtocolGuid
,
1700 IN EFI_HANDLE DriverBindingHandle
,
1701 OUT EFI_COMPONENT_NAME_PROTOCOL
**ComponentName
,
1702 OUT CHAR8
**SupportedLanguage
1708 // Locate Component Name (2) protocol on the driver binging handle.
1710 Status
= gBS
->OpenProtocol (
1711 DriverBindingHandle
,
1713 (VOID
**) ComponentName
,
1716 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1718 if (EFI_ERROR (Status
)) {
1723 // Apply shell policy to select the best language.
1725 *SupportedLanguage
= DriverHealthSelectBestLanguage (
1726 (*ComponentName
)->SupportedLanguages
,
1727 (BOOLEAN
) (ProtocolGuid
== &gEfiComponentNameProtocolGuid
)
1729 if (*SupportedLanguage
== NULL
) {
1730 Status
= EFI_UNSUPPORTED
;
1738 This is an internal worker function to get driver name from Component Name (2) protocol interface.
1741 @param ProtocolGuid A pointer to an EFI_GUID. It points to Component Name (2) protocol GUID.
1742 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
1743 @param DriverName A pointer to the Unicode string to return. This Unicode string is the name
1744 of the driver specified by This.
1746 @retval EFI_SUCCESS The driver name is successfully retrieved from Component Name (2) protocol
1748 @retval Other The driver name cannot be retrieved from Component Name (2) protocol
1753 GetDriverNameWorker (
1754 IN EFI_GUID
*ProtocolGuid
,
1755 IN EFI_HANDLE DriverBindingHandle
,
1756 OUT CHAR16
**DriverName
1760 CHAR8
*BestLanguage
;
1761 EFI_COMPONENT_NAME_PROTOCOL
*ComponentName
;
1764 // Retrieve Component Name (2) protocol instance on the driver binding handle and
1765 // find the best language this instance supports.
1767 Status
= GetComponentNameWorker (
1769 DriverBindingHandle
,
1773 if (EFI_ERROR (Status
)) {
1778 // Get the driver name from Component Name (2) protocol instance on the driver binging handle.
1780 Status
= ComponentName
->GetDriverName (
1785 FreePool (BestLanguage
);
1792 This function gets driver name from Component Name 2 protocol interface and Component Name protocol interface
1793 in turn. It first tries UEFI 2.0 Component Name 2 protocol interface and try to get the driver name.
1794 If the attempt fails, it then gets the driver name from EFI 1.1 Component Name protocol for backward
1795 compatibility support.
1797 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
1798 @param DriverName A pointer to the Unicode string to return. This Unicode string is the name
1799 of the driver specified by This.
1801 @retval EFI_SUCCESS The driver name is successfully retrieved from Component Name (2) protocol
1803 @retval Other The driver name cannot be retrieved from Component Name (2) protocol
1808 DriverHealthGetDriverName (
1809 IN EFI_HANDLE DriverBindingHandle
,
1810 OUT CHAR16
**DriverName
1816 // Get driver name from UEFI 2.0 Component Name 2 protocol interface.
1818 Status
= GetDriverNameWorker (&gEfiComponentName2ProtocolGuid
, DriverBindingHandle
, DriverName
);
1819 if (EFI_ERROR (Status
)) {
1821 // If it fails to get the driver name from Component Name protocol interface, we should fall back on
1822 // EFI 1.1 Component Name protocol interface.
1824 Status
= GetDriverNameWorker (&gEfiComponentNameProtocolGuid
, DriverBindingHandle
, DriverName
);
1833 This function gets controller name from Component Name 2 protocol interface and Component Name protocol interface
1834 in turn. It first tries UEFI 2.0 Component Name 2 protocol interface and try to get the controller name.
1835 If the attempt fails, it then gets the controller name from EFI 1.1 Component Name protocol for backward
1836 compatibility support.
1838 @param ProtocolGuid A pointer to an EFI_GUID. It points to Component Name (2) protocol GUID.
1839 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
1840 @param ControllerHandle The handle of a controller that the driver specified by This is managing.
1841 This handle specifies the controller whose name is to be returned.
1842 @param ChildHandle The handle of the child controller to retrieve the name of. This is an
1843 optional parameter that may be NULL. It will be NULL for device drivers.
1844 It will also be NULL for bus drivers that attempt to retrieve the name
1845 of the bus controller. It will not be NULL for a bus driver that attempts
1846 to retrieve the name of a child controller.
1847 @param ControllerName A pointer to the Unicode string to return. This Unicode string
1848 is the name of the controller specified by ControllerHandle and ChildHandle.
1850 @retval EFI_SUCCESS The controller name is successfully retrieved from Component Name (2) protocol
1852 @retval Other The controller name cannot be retrieved from Component Name (2) protocol.
1856 GetControllerNameWorker (
1857 IN EFI_GUID
*ProtocolGuid
,
1858 IN EFI_HANDLE DriverBindingHandle
,
1859 IN EFI_HANDLE ControllerHandle
,
1860 IN EFI_HANDLE ChildHandle
,
1861 OUT CHAR16
**ControllerName
1865 CHAR8
*BestLanguage
;
1866 EFI_COMPONENT_NAME_PROTOCOL
*ComponentName
;
1869 // Retrieve Component Name (2) protocol instance on the driver binding handle and
1870 // find the best language this instance supports.
1872 Status
= GetComponentNameWorker (
1874 DriverBindingHandle
,
1878 if (EFI_ERROR (Status
)) {
1883 // Get the controller name from Component Name (2) protocol instance on the driver binging handle.
1885 Status
= ComponentName
->GetControllerName (
1892 FreePool (BestLanguage
);
1899 This function gets controller name from Component Name 2 protocol interface and Component Name protocol interface
1900 in turn. It first tries UEFI 2.0 Component Name 2 protocol interface and try to get the controller name.
1901 If the attempt fails, it then gets the controller name from EFI 1.1 Component Name protocol for backward
1902 compatibility support.
1904 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
1905 @param ControllerHandle The handle of a controller that the driver specified by This is managing.
1906 This handle specifies the controller whose name is to be returned.
1907 @param ChildHandle The handle of the child controller to retrieve the name of. This is an
1908 optional parameter that may be NULL. It will be NULL for device drivers.
1909 It will also be NULL for bus drivers that attempt to retrieve the name
1910 of the bus controller. It will not be NULL for a bus driver that attempts
1911 to retrieve the name of a child controller.
1912 @param ControllerName A pointer to the Unicode string to return. This Unicode string
1913 is the name of the controller specified by ControllerHandle and ChildHandle.
1915 @retval EFI_SUCCESS The controller name is successfully retrieved from Component Name (2) protocol
1917 @retval Other The controller name cannot be retrieved from Component Name (2) protocol.
1921 DriverHealthGetControllerName (
1922 IN EFI_HANDLE DriverBindingHandle
,
1923 IN EFI_HANDLE ControllerHandle
,
1924 IN EFI_HANDLE ChildHandle
,
1925 OUT CHAR16
**ControllerName
1931 // Get controller name from UEFI 2.0 Component Name 2 protocol interface.
1933 Status
= GetControllerNameWorker (
1934 &gEfiComponentName2ProtocolGuid
,
1935 DriverBindingHandle
,
1940 if (EFI_ERROR (Status
)) {
1942 // If it fails to get the controller name from Component Name protocol interface, we should fall back on
1943 // EFI 1.1 Component Name protocol interface.
1945 Status
= GetControllerNameWorker (
1946 &gEfiComponentNameProtocolGuid
,
1947 DriverBindingHandle
,