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
) {
298 // Find FormSet OpCode
300 ClassGuidNum
= ((EFI_IFR_FORM_SET
*) OpCodeData
)->Flags
;
301 ClassGuid
= (EFI_GUID
*) (VOID
*)(OpCodeData
+ sizeof (EFI_IFR_FORM_SET
));
302 while (ClassGuidNum
-- > 0) {
303 if (CompareGuid (SetupClassGuid
, ClassGuid
)) {
304 CopyMem (FormSetTitle
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->FormSetTitle
, sizeof (EFI_STRING_ID
));
305 CopyMem (FormSetHelp
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->Help
, sizeof (EFI_STRING_ID
));
306 FreePool (HiiPackageList
);
315 Offset2
+= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
;
320 // Go to next package
322 Offset
+= PackageHeader
.Length
;
325 FreePool (HiiPackageList
);
331 Call the browser and display the device manager to allow user
332 to configure the platform.
334 This function create the dynamic content for device manager. It includes
335 section header for all class of devices, one-of opcode to set VBIOS.
337 @retval EFI_SUCCESS Operation is successful.
338 @return Other values if failed to clean up the dynamic content from HII
351 EFI_STRING_ID TokenHelp
;
352 EFI_HII_HANDLE
*HiiHandles
;
353 EFI_HII_HANDLE HiiHandle
;
354 EFI_STRING_ID FormSetTitle
;
355 EFI_STRING_ID FormSetHelp
;
356 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
357 VOID
*StartOpCodeHandle
;
358 VOID
*EndOpCodeHandle
;
359 EFI_IFR_GUID_LABEL
*StartLabel
;
360 EFI_IFR_GUID_LABEL
*EndLabel
;
362 EFI_HANDLE
*DriverHealthHandles
;
365 Status
= EFI_SUCCESS
;
368 DriverHealthHandles
= NULL
;
371 // Connect all prior to entering the platform setup menu.
373 if (!gConnectAllHappened
) {
374 BdsLibConnectAllDriversToAllControllers ();
375 gConnectAllHappened
= TRUE
;
378 // Create Subtitle OpCodes
381 // Allocate space for creation of UpdateData Buffer
383 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
384 ASSERT (StartOpCodeHandle
!= NULL
);
386 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
387 ASSERT (EndOpCodeHandle
!= NULL
);
390 // Create Hii Extend Label OpCode as the start opcode
392 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
393 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
394 StartLabel
->Number
= LABEL_DEVICES_LIST
;
397 // Create Hii Extend Label OpCode as the end opcode
399 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
400 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
401 EndLabel
->Number
= LABEL_END
;
403 HiiCreateSubTitleOpCode (StartOpCodeHandle
, STRING_TOKEN (STR_DEVICES_LIST
), 0, 0, 1);
406 // Get all the Hii handles
408 HiiHandles
= HiiGetHiiHandles (NULL
);
409 ASSERT (HiiHandles
!= NULL
);
411 HiiHandle
= gDeviceManagerPrivate
.HiiHandle
;
414 // Search for formset of each class type
416 for (Index
= 0; HiiHandles
[Index
] != NULL
; Index
++) {
417 if (!ExtractDisplayedHiiFormFromHiiHandle (HiiHandles
[Index
], &gEfiHiiPlatformSetupFormsetGuid
, &FormSetTitle
, &FormSetHelp
)) {
421 String
= HiiGetString (HiiHandles
[Index
], FormSetTitle
, NULL
);
422 if (String
== NULL
) {
423 String
= HiiGetString (HiiHandle
, STR_MISSING_STRING
, NULL
);
424 ASSERT (String
!= NULL
);
426 Token
= HiiSetString (HiiHandle
, 0, String
, NULL
);
429 String
= HiiGetString (HiiHandles
[Index
], FormSetHelp
, NULL
);
430 if (String
== NULL
) {
431 String
= HiiGetString (HiiHandle
, STR_MISSING_STRING
, NULL
);
432 ASSERT (String
!= NULL
);
434 TokenHelp
= HiiSetString (HiiHandle
, 0, String
, NULL
);
437 HiiCreateActionOpCode (
439 (EFI_QUESTION_ID
) (Index
+ DEVICE_KEY_OFFSET
),
442 EFI_IFR_FLAG_CALLBACK
,
448 // Add End Opcode for Subtitle
450 HiiCreateEndOpCode (StartOpCodeHandle
);
452 Status
= gBS
->LocateHandleBuffer (
454 &gEfiDriverHealthProtocolGuid
,
460 // If there are no drivers installed driver health protocol
462 if (NumHandles
== 0) {
463 HiiSetString (HiiHandle
, STRING_TOKEN (STR_DM_DRIVER_HEALTH_TITLE
), GetStringById (STRING_TOKEN (STR_EMPTY_STRING
)), NULL
);
464 HiiSetString (HiiHandle
, STRING_TOKEN (STR_DRIVER_HEALTH_ALL_HEALTHY
), GetStringById (STRING_TOKEN (STR_EMPTY_STRING
)), NULL
);
467 // Check All Driver health status
469 if (!PlaformHealthStatusCheck ()) {
471 // At least one driver in the platform are not in healthy status
473 HiiSetString (HiiHandle
, STRING_TOKEN (STR_DRIVER_HEALTH_ALL_HEALTHY
), GetStringById (STRING_TOKEN (STR_DRIVER_NOT_HEALTH
)), NULL
);
476 // For the string of STR_DRIVER_HEALTH_ALL_HEALTHY previously has been updated and we need to update it while re-entry.
478 HiiSetString (HiiHandle
, STRING_TOKEN (STR_DRIVER_HEALTH_ALL_HEALTHY
), GetStringById (STRING_TOKEN (STR_DRIVER_HEALTH_ALL_HEALTHY
)), NULL
);
485 DEVICE_MANAGER_FORM_ID
,
490 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
491 Status
= gFormBrowser2
->SendForm (
500 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
501 EnableResetRequired ();
505 // We will have returned from processing a callback - user either hit ESC to exit, or selected
506 // a target to display
508 if ((gCallbackKey
!= 0) && (gCallbackKey
!= DEVICE_MANAGER_KEY_DRIVER_HEALTH
)) {
509 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
510 Status
= gFormBrowser2
->SendForm (
512 &HiiHandles
[gCallbackKey
- DEVICE_KEY_OFFSET
],
520 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
521 EnableResetRequired ();
525 // Force return to Device Manager
527 gCallbackKey
= FRONT_PAGE_KEY_DEVICE_MANAGER
;
531 // Driver Health item chose.
533 if (gCallbackKey
== DEVICE_MANAGER_KEY_DRIVER_HEALTH
) {
536 // Force return to Device Manager
538 gCallbackKey
= FRONT_PAGE_KEY_DEVICE_MANAGER
;
542 // Cleanup dynamic created strings in HII database by reinstall the packagelist
544 HiiRemovePackages (HiiHandle
);
546 gDeviceManagerPrivate
.HiiHandle
= HiiAddPackages (
548 gDeviceManagerPrivate
.DriverHandle
,
553 if (gDeviceManagerPrivate
.HiiHandle
== NULL
) {
554 Status
= EFI_OUT_OF_RESOURCES
;
556 Status
= EFI_SUCCESS
;
559 HiiFreeOpCodeHandle (StartOpCodeHandle
);
560 HiiFreeOpCodeHandle (EndOpCodeHandle
);
561 FreePool (HiiHandles
);
567 This function is invoked if user selected a interactive opcode from Driver Health's
568 Formset. The decision by user is saved to gCallbackKey for later processing.
570 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
571 @param Action Specifies the type of action taken by the browser.
572 @param QuestionId A unique value which is sent to the original exporting driver
573 so that it can identify the type of data to expect.
574 @param Type The type of value for the question.
575 @param Value A pointer to the data being sent to the original exporting driver.
576 @param ActionRequest On return, points to the action requested by the callback function.
578 @retval EFI_SUCCESS The callback successfully handled the action.
579 @retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.
584 DriverHealthCallback (
585 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
586 IN EFI_BROWSER_ACTION Action
,
587 IN EFI_QUESTION_ID QuestionId
,
589 IN EFI_IFR_TYPE_VALUE
*Value
,
590 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
593 if ((Value
== NULL
) || (ActionRequest
== NULL
)) {
594 return EFI_INVALID_PARAMETER
;
597 gCallbackKey
= QuestionId
;
600 // Request to exit SendForm(), so as to switch to selected form
602 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
608 Collect and display the platform's driver health relative information, allow user to do interactive
609 operation while the platform is unhealthy.
611 This function display a form which divided into two parts. The one list all modules which has installed
612 driver health protocol. The list usually contain driver name, controller name, and it's health info.
613 While the driver name can't be retrieved, will use device path as backup. The other part of the form provide
614 a choice to the user to repair all platform.
623 EFI_HII_HANDLE HiiHandle
;
624 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
625 EFI_IFR_GUID_LABEL
*StartLabel
;
626 EFI_IFR_GUID_LABEL
*StartLabelRepair
;
627 EFI_IFR_GUID_LABEL
*EndLabel
;
628 EFI_IFR_GUID_LABEL
*EndLabelRepair
;
629 VOID
*StartOpCodeHandle
;
630 VOID
*EndOpCodeHandle
;
631 VOID
*StartOpCodeHandleRepair
;
632 VOID
*EndOpCodeHandleRepair
;
635 EFI_STRING_ID TokenHelp
;
637 EFI_STRING TmpString
;
638 EFI_STRING DriverName
;
639 EFI_STRING ControllerName
;
640 LIST_ENTRY DriverHealthList
;
641 DRIVER_HEALTH_INFO
*DriverHealthInfo
;
643 EFI_DEVICE_PATH_PROTOCOL
*DriverDevicePath
;
646 HiiHandle
= gDeviceManagerPrivate
.DriverHealthHiiHandle
;
649 DriverHealthInfo
= NULL
;
650 DriverDevicePath
= NULL
;
651 InitializeListHead (&DriverHealthList
);
654 // Allocate space for creation of UpdateData Buffer
656 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
657 ASSERT (StartOpCodeHandle
!= NULL
);
659 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
660 ASSERT (EndOpCodeHandle
!= NULL
);
662 StartOpCodeHandleRepair
= HiiAllocateOpCodeHandle ();
663 ASSERT (StartOpCodeHandleRepair
!= NULL
);
665 EndOpCodeHandleRepair
= HiiAllocateOpCodeHandle ();
666 ASSERT (EndOpCodeHandleRepair
!= NULL
);
669 // Create Hii Extend Label OpCode as the start opcode
671 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
672 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
673 StartLabel
->Number
= LABEL_DRIVER_HEALTH
;
676 // Create Hii Extend Label OpCode as the start opcode
678 StartLabelRepair
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandleRepair
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
679 StartLabelRepair
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
680 StartLabelRepair
->Number
= LABEL_DRIVER_HEALTH_REAPIR_ALL
;
683 // Create Hii Extend Label OpCode as the end opcode
685 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
686 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
687 EndLabel
->Number
= LABEL_DRIVER_HEALTH_END
;
690 // Create Hii Extend Label OpCode as the end opcode
692 EndLabelRepair
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandleRepair
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
693 EndLabelRepair
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
694 EndLabelRepair
->Number
= LABEL_DRIVER_HEALTH_REAPIR_ALL_END
;
696 HiiCreateSubTitleOpCode (StartOpCodeHandle
, STRING_TOKEN (STR_DH_STATUS_LIST
), 0, 0, 1);
698 Status
= GetAllControllersHealthStatus (&DriverHealthList
);
699 ASSERT (Status
!= EFI_OUT_OF_RESOURCES
);
701 Link
= GetFirstNode (&DriverHealthList
);
703 while (!IsNull (&DriverHealthList
, Link
)) {
704 DriverHealthInfo
= DEVICE_MANAGER_HEALTH_INFO_FROM_LINK (Link
);
707 // Assume no line strings is longer than 512 bytes.
709 String
= (EFI_STRING
) AllocateZeroPool (0x200);
710 ASSERT (String
!= NULL
);
712 Status
= DriverHealthGetDriverName (DriverHealthInfo
->DriverHandle
, &DriverName
);
713 if (EFI_ERROR (Status
)) {
715 // Can not get the Driver name, so use the Device path
717 DriverDevicePath
= DevicePathFromHandle (DriverHealthInfo
->DriverHandle
);
718 DriverName
= DevicePathToStr (DriverDevicePath
);
721 // Add the Driver name & Controller name into FormSetTitle string
723 StrnCat (String
, DriverName
, StrLen (DriverName
));
726 Status
= DriverHealthGetControllerName (
727 DriverHealthInfo
->DriverHandle
,
728 DriverHealthInfo
->ControllerHandle
,
729 DriverHealthInfo
->ChildHandle
,
733 if (!EFI_ERROR (Status
)) {
735 // Can not get the Controller name, just let it empty.
737 StrnCat (String
, L
" ", StrLen (L
" "));
738 StrnCat (String
, ControllerName
, StrLen (ControllerName
));
742 // Add the message of the Module itself provided after the string item.
744 if ((DriverHealthInfo
->MessageList
!= NULL
) && (DriverHealthInfo
->MessageList
->StringId
!= 0)) {
745 StrnCat (String
, L
" ", StrLen (L
" "));
746 TmpString
= HiiGetString (
747 DriverHealthInfo
->MessageList
->HiiHandle
,
748 DriverHealthInfo
->MessageList
->StringId
,
752 // Assert if can not retrieve the message string
754 ASSERT (TmpString
!= NULL
);
755 StrnCat (String
, TmpString
, StrLen (TmpString
));
756 FreePool (TmpString
);
759 // Update the string will be displayed base on the driver's health status
761 switch(DriverHealthInfo
->HealthStatus
) {
762 case EfiDriverHealthStatusRepairRequired
:
763 Length
= StrLen (GetStringById (STRING_TOKEN (STR_REPAIR_REQUIRED
)));
764 StrnCat (String
, GetStringById (STRING_TOKEN (STR_REPAIR_REQUIRED
)), Length
);
766 case EfiDriverHealthStatusConfigurationRequired
:
767 Length
= StrLen (GetStringById (STRING_TOKEN (STR_CONFIGURATION_REQUIRED
)));
768 StrnCat (String
, GetStringById (STRING_TOKEN (STR_CONFIGURATION_REQUIRED
)), Length
);
770 case EfiDriverHealthStatusFailed
:
771 Length
= StrLen (GetStringById (STRING_TOKEN (STR_OPERATION_FAILED
)));
772 StrnCat (String
, GetStringById (STRING_TOKEN (STR_OPERATION_FAILED
)), Length
);
774 case EfiDriverHealthStatusReconnectRequired
:
775 Length
= StrLen (GetStringById (STRING_TOKEN (STR_RECONNECT_REQUIRED
)));
776 StrnCat (String
, GetStringById (STRING_TOKEN (STR_RECONNECT_REQUIRED
)), Length
);
778 case EfiDriverHealthStatusRebootRequired
:
779 Length
= StrLen (GetStringById (STRING_TOKEN (STR_REBOOT_REQUIRED
)));
780 StrnCat (String
, GetStringById (STRING_TOKEN (STR_REBOOT_REQUIRED
)), Length
);
783 Length
= StrLen (GetStringById (STRING_TOKEN (STR_DRIVER_HEALTH_HEALTHY
)));
784 StrnCat (String
, GetStringById (STRING_TOKEN (STR_DRIVER_HEALTH_HEALTHY
)), Length
);
789 Token
= HiiSetString (HiiHandle
, 0, String
, NULL
);
792 TokenHelp
= HiiSetString (HiiHandle
, 0, GetStringById( STRING_TOKEN (STR_DH_REPAIR_SINGLE_HELP
)), NULL
);
794 HiiCreateActionOpCode (
796 (EFI_QUESTION_ID
) (Index
+ DRIVER_HEALTH_KEY_OFFSET
),
799 EFI_IFR_FLAG_CALLBACK
,
803 Link
= GetNextNode (&DriverHealthList
, Link
);
807 // Add End Opcode for Subtitle
809 HiiCreateEndOpCode (StartOpCodeHandle
);
811 HiiCreateSubTitleOpCode (StartOpCodeHandleRepair
, STRING_TOKEN (STR_DRIVER_HEALTH_REPAIR_ALL
), 0, 0, 1);
812 TokenHelp
= HiiSetString (HiiHandle
, 0, GetStringById( STRING_TOKEN (STR_DH_REPAIR_ALL_HELP
)), NULL
);
814 if (PlaformHealthStatusCheck ()) {
816 // No action need to do for the platform
818 Token
= HiiSetString (HiiHandle
, 0, GetStringById( STRING_TOKEN (STR_DRIVER_HEALTH_ALL_HEALTHY
)), NULL
);
819 HiiCreateActionOpCode (
820 StartOpCodeHandleRepair
,
824 EFI_IFR_FLAG_READ_ONLY
,
829 // Create ActionOpCode only while the platform need to do health related operation.
831 Token
= HiiSetString (HiiHandle
, 0, GetStringById( STRING_TOKEN (STR_DH_REPAIR_ALL_TITLE
)), NULL
);
832 HiiCreateActionOpCode (
833 StartOpCodeHandleRepair
,
834 (EFI_QUESTION_ID
) DRIVER_HEALTH_REPAIR_ALL_KEY
,
837 EFI_IFR_FLAG_CALLBACK
,
842 HiiCreateEndOpCode (StartOpCodeHandleRepair
);
844 Status
= HiiUpdateForm (
847 DRIVER_HEALTH_FORM_ID
,
851 ASSERT (Status
!= EFI_NOT_FOUND
);
852 ASSERT (Status
!= EFI_BUFFER_TOO_SMALL
);
854 Status
= HiiUpdateForm (
857 DRIVER_HEALTH_FORM_ID
,
858 StartOpCodeHandleRepair
,
859 EndOpCodeHandleRepair
861 ASSERT (Status
!= EFI_NOT_FOUND
);
862 ASSERT (Status
!= EFI_BUFFER_TOO_SMALL
);
864 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
865 Status
= gFormBrowser2
->SendForm (
870 DRIVER_HEALTH_FORM_ID
,
874 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
875 EnableResetRequired ();
879 // We will have returned from processing a callback - user either hit ESC to exit, or selected
880 // a target to display.
881 // Process the diver health status states here.
883 if (gCallbackKey
>= DRIVER_HEALTH_KEY_OFFSET
&& gCallbackKey
!= DRIVER_HEALTH_REPAIR_ALL_KEY
) {
884 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
886 Link
= GetFirstNode (&DriverHealthList
);
889 while (!IsNull (&DriverHealthList
, Link
)) {
891 // Got the item relative node in the List
893 if (Index
== (gCallbackKey
- DRIVER_HEALTH_KEY_OFFSET
)) {
894 DriverHealthInfo
= DEVICE_MANAGER_HEALTH_INFO_FROM_LINK (Link
);
896 // Process the driver's healthy status for the specify module
898 ProcessSingleControllerHealth (
899 DriverHealthInfo
->DriverHealth
,
900 DriverHealthInfo
->ControllerHandle
,
901 DriverHealthInfo
->ChildHandle
,
902 DriverHealthInfo
->HealthStatus
,
903 &(DriverHealthInfo
->MessageList
),
904 DriverHealthInfo
->HiiHandle
909 Link
= GetNextNode (&DriverHealthList
, Link
);
912 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
913 EnableResetRequired ();
917 // Force return to the form of Driver Health in Device Manager
919 gCallbackKey
= DRIVER_HEALTH_RETURN_KEY
;
923 // Repair the whole platform
925 if (gCallbackKey
== DRIVER_HEALTH_REPAIR_ALL_KEY
) {
926 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
928 PlatformRepairAll (&DriverHealthList
);
930 gCallbackKey
= DRIVER_HEALTH_RETURN_KEY
;
934 // Cleanup dynamic created strings in HII database by reinstall the packagelist
937 HiiRemovePackages (HiiHandle
);
939 gDeviceManagerPrivate
.DriverHealthHiiHandle
= HiiAddPackages (
941 gDeviceManagerPrivate
.DriverHealthHandle
,
946 if (gDeviceManagerPrivate
.DriverHealthHiiHandle
== NULL
) {
947 Status
= EFI_OUT_OF_RESOURCES
;
949 Status
= EFI_SUCCESS
;
952 // Free driver health info list
954 while (!IsListEmpty (&DriverHealthList
)) {
956 Link
= GetFirstNode(&DriverHealthList
);
957 DriverHealthInfo
= DEVICE_MANAGER_HEALTH_INFO_FROM_LINK (Link
);
958 RemoveEntryList (Link
);
960 if (DriverHealthInfo
->MessageList
!= NULL
) {
961 FreePool(DriverHealthInfo
->MessageList
);
962 FreePool (DriverHealthInfo
);
966 HiiFreeOpCodeHandle (StartOpCodeHandle
);
967 HiiFreeOpCodeHandle (EndOpCodeHandle
);
968 HiiFreeOpCodeHandle (StartOpCodeHandleRepair
);
969 HiiFreeOpCodeHandle (EndOpCodeHandleRepair
);
971 if (gCallbackKey
== DRIVER_HEALTH_RETURN_KEY
) {
973 // Force return to Driver Health Form
975 gCallbackKey
= DEVICE_MANAGER_KEY_DRIVER_HEALTH
;
982 Check the Driver Health status of a single controller and try to process it if not healthy.
984 This function called by CheckAllControllersHealthStatus () function in order to process a specify
985 contoller's health state.
987 @param DriverHealthList A Pointer to the list contain all of the platform driver health information.
988 @param DriverHandle The handle of driver.
989 @param ControllerHandle The class guid specifies which form set will be displayed.
990 @param ChildHandle The handle of the child controller to retrieve the health
991 status on. This is an optional parameter that may be NULL.
992 @param DriverHealth A pointer to the EFI_DRIVER_HEALTH_PROTOCOL instance.
993 @param HealthStatus The health status of the controller.
995 @retval EFI_INVALID_PARAMETER HealthStatus or DriverHealth is NULL.
996 @retval HealthStatus The Health status of specify controller.
997 @retval EFI_OUT_OF_RESOURCES The list of Driver Health Protocol handles can not be retrieved.
998 @retval EFI_NOT_FOUND No controller in the platform install Driver Health Protocol.
999 @retval EFI_SUCCESS The Health related operation has been taken successfully.
1004 GetSingleControllerHealthStatus (
1005 IN OUT LIST_ENTRY
*DriverHealthList
,
1006 IN EFI_HANDLE DriverHandle
,
1007 IN EFI_HANDLE ControllerHandle
, OPTIONAL
1008 IN EFI_HANDLE ChildHandle
, OPTIONAL
1009 IN EFI_DRIVER_HEALTH_PROTOCOL
*DriverHealth
,
1010 IN EFI_DRIVER_HEALTH_STATUS
*HealthStatus
1014 EFI_DRIVER_HEALTH_HII_MESSAGE
*MessageList
;
1015 EFI_HII_HANDLE FormHiiHandle
;
1016 DRIVER_HEALTH_INFO
*DriverHealthInfo
;
1018 if (HealthStatus
== NULL
) {
1020 // If HealthStatus is NULL, then return EFI_INVALID_PARAMETER
1022 return EFI_INVALID_PARAMETER
;
1026 // Assume the HealthStatus is healthy
1028 *HealthStatus
= EfiDriverHealthStatusHealthy
;
1030 if (DriverHealth
== NULL
) {
1032 // If DriverHealth is NULL, then return EFI_INVALID_PARAMETER
1034 return EFI_INVALID_PARAMETER
;
1037 if (ControllerHandle
== NULL
) {
1039 // If ControllerHandle is NULL, the return the cumulative health status of the driver
1041 Status
= DriverHealth
->GetHealthStatus (DriverHealth
, NULL
, NULL
, HealthStatus
, NULL
, NULL
);
1042 if (*HealthStatus
== EfiDriverHealthStatusHealthy
) {
1044 // Add the driver health related information into the list
1046 DriverHealthInfo
= AllocateZeroPool (sizeof (DRIVER_HEALTH_INFO
));
1047 if (DriverHealthInfo
== NULL
) {
1048 return EFI_OUT_OF_RESOURCES
;
1051 DriverHealthInfo
->Signature
= DEVICE_MANAGER_DRIVER_HEALTH_INFO_SIGNATURE
;
1052 DriverHealthInfo
->DriverHandle
= DriverHandle
;
1053 DriverHealthInfo
->ControllerHandle
= NULL
;
1054 DriverHealthInfo
->ChildHandle
= NULL
;
1055 DriverHealthInfo
->HiiHandle
= NULL
;
1056 DriverHealthInfo
->DriverHealth
= DriverHealth
;
1057 DriverHealthInfo
->MessageList
= NULL
;
1058 DriverHealthInfo
->HealthStatus
= *HealthStatus
;
1060 InsertTailList (DriverHealthList
, &DriverHealthInfo
->Link
);
1066 FormHiiHandle
= NULL
;
1069 // Collect the health status with the optional HII message list
1071 Status
= DriverHealth
->GetHealthStatus (DriverHealth
, ControllerHandle
, ChildHandle
, HealthStatus
, &MessageList
, &FormHiiHandle
);
1073 if (EFI_ERROR (Status
)) {
1075 // If the health status could not be retrieved, then return immediately
1081 // Add the driver health related information into the list
1083 DriverHealthInfo
= AllocateZeroPool (sizeof (DRIVER_HEALTH_INFO
));
1084 if (DriverHealthInfo
== NULL
) {
1085 return EFI_OUT_OF_RESOURCES
;
1088 DriverHealthInfo
->Signature
= DEVICE_MANAGER_DRIVER_HEALTH_INFO_SIGNATURE
;
1089 DriverHealthInfo
->DriverHandle
= DriverHandle
;
1090 DriverHealthInfo
->ControllerHandle
= ControllerHandle
;
1091 DriverHealthInfo
->ChildHandle
= ChildHandle
;
1092 DriverHealthInfo
->HiiHandle
= FormHiiHandle
;
1093 DriverHealthInfo
->DriverHealth
= DriverHealth
;
1094 DriverHealthInfo
->MessageList
= MessageList
;
1095 DriverHealthInfo
->HealthStatus
= *HealthStatus
;
1097 InsertTailList (DriverHealthList
, &DriverHealthInfo
->Link
);
1103 Collects all the EFI Driver Health Protocols currently present in the EFI Handle Database,
1104 and queries each EFI Driver Health Protocol to determine if one or more of the controllers
1105 managed by each EFI Driver Health Protocol instance are not healthy.
1107 @param DriverHealthList A Pointer to the list contain all of the platform driver health
1110 @retval EFI_NOT_FOUND No controller in the platform install Driver Health Protocol.
1111 @retval EFI_SUCCESS All the controllers in the platform are healthy.
1112 @retval EFI_OUT_OF_RESOURCES The list of Driver Health Protocol handles can not be retrieved.
1116 GetAllControllersHealthStatus (
1117 IN OUT LIST_ENTRY
*DriverHealthList
1122 EFI_HANDLE
*DriverHealthHandles
;
1123 EFI_DRIVER_HEALTH_PROTOCOL
*DriverHealth
;
1124 EFI_DRIVER_HEALTH_STATUS HealthStatus
;
1125 UINTN DriverHealthIndex
;
1126 EFI_HANDLE
*Handles
;
1128 UINTN ControllerIndex
;
1132 // Initialize local variables
1135 DriverHealthHandles
= NULL
;
1139 HealthStatus
= EfiDriverHealthStatusHealthy
;
1141 Status
= gBS
->LocateHandleBuffer (
1143 &gEfiDriverHealthProtocolGuid
,
1146 &DriverHealthHandles
1149 if (Status
== EFI_NOT_FOUND
|| NumHandles
== 0) {
1151 // If there are no Driver Health Protocols handles, then return EFI_NOT_FOUND
1153 return EFI_NOT_FOUND
;
1156 if (EFI_ERROR (Status
) || DriverHealthHandles
== NULL
) {
1158 // If the list of Driver Health Protocol handles can not be retrieved, then
1159 // return EFI_OUT_OF_RESOURCES
1161 return EFI_OUT_OF_RESOURCES
;
1165 // Check the health status of all controllers in the platform
1166 // Start by looping through all the Driver Health Protocol handles in the handle database
1168 for (DriverHealthIndex
= 0; DriverHealthIndex
< NumHandles
; DriverHealthIndex
++) {
1170 // Skip NULL Driver Health Protocol handles
1172 if (DriverHealthHandles
[DriverHealthIndex
] == NULL
) {
1177 // Retrieve the Driver Health Protocol from DriverHandle
1179 Status
= gBS
->HandleProtocol (
1180 DriverHealthHandles
[DriverHealthIndex
],
1181 &gEfiDriverHealthProtocolGuid
,
1182 (VOID
**)&DriverHealth
1184 if (EFI_ERROR (Status
)) {
1186 // If the Driver Health Protocol can not be retrieved, then skip to the next
1187 // Driver Health Protocol handle
1193 // Check the health of all the controllers managed by a Driver Health Protocol handle
1195 Status
= GetSingleControllerHealthStatus (DriverHealthList
, DriverHealthHandles
[DriverHealthIndex
], NULL
, NULL
, DriverHealth
, &HealthStatus
);
1198 // If Status is an error code, then the health information could not be retrieved, so assume healthy
1199 // and skip to the next Driver Health Protocol handle
1201 if (EFI_ERROR (Status
)) {
1206 // If all the controllers managed by this Driver Health Protocol are healthy, then skip to the next
1207 // Driver Health Protocol handle
1209 if (HealthStatus
== EfiDriverHealthStatusHealthy
) {
1214 // See if the list of all handles in the handle database has been retrieved
1217 if (Handles
== NULL
) {
1219 // Retrieve the list of all handles from the handle database
1221 Status
= gBS
->LocateHandleBuffer (
1228 if (EFI_ERROR (Status
) || Handles
== NULL
) {
1230 // If all the handles in the handle database can not be retrieved, then
1231 // return EFI_OUT_OF_RESOURCES
1233 Status
= EFI_OUT_OF_RESOURCES
;
1238 // Loop through all the controller handles in the handle database
1240 for (ControllerIndex
= 0; ControllerIndex
< HandleCount
; ControllerIndex
++) {
1242 // Skip NULL controller handles
1244 if (Handles
[ControllerIndex
] == NULL
) {
1248 Status
= GetSingleControllerHealthStatus (DriverHealthList
, DriverHealthHandles
[DriverHealthIndex
], Handles
[ControllerIndex
], NULL
, DriverHealth
, &HealthStatus
);
1249 if (EFI_ERROR (Status
)) {
1251 // If Status is an error code, then the health information could not be retrieved, so assume healthy
1253 HealthStatus
= EfiDriverHealthStatusHealthy
;
1257 // If CheckHealthSingleController() returned an error on a terminal state, then do not check the health of child controllers
1259 if (EFI_ERROR (Status
)) {
1264 // Loop through all the child handles in the handle database
1266 for (ChildIndex
= 0; ChildIndex
< HandleCount
; ChildIndex
++) {
1268 // Skip NULL child handles
1270 if (Handles
[ChildIndex
] == NULL
) {
1274 Status
= GetSingleControllerHealthStatus (DriverHealthList
, DriverHealthHandles
[DriverHealthIndex
], Handles
[ControllerIndex
], Handles
[ChildIndex
], DriverHealth
, &HealthStatus
);
1275 if (EFI_ERROR (Status
)) {
1277 // If Status is an error code, then the health information could not be retrieved, so assume healthy
1279 HealthStatus
= EfiDriverHealthStatusHealthy
;
1283 // If CheckHealthSingleController() returned an error on a terminal state, then skip to the next child
1285 if (EFI_ERROR (Status
)) {
1292 Status
= EFI_SUCCESS
;
1295 if (Handles
!= NULL
) {
1296 gBS
->FreePool (Handles
);
1298 if (DriverHealthHandles
!= NULL
) {
1299 gBS
->FreePool (DriverHealthHandles
);
1307 Check the healthy status of the platform, this function will return immediately while found one driver
1308 in the platform are not healthy.
1310 @retval FALSE at least one driver in the platform are not healthy.
1311 @retval TRUE No controller install Driver Health Protocol,
1312 or all controllers in the platform are in healthy status.
1315 PlaformHealthStatusCheck (
1319 EFI_DRIVER_HEALTH_STATUS HealthStatus
;
1323 EFI_HANDLE
*DriverHealthHandles
;
1324 EFI_DRIVER_HEALTH_PROTOCOL
*DriverHealth
;
1328 // Initialize local variables
1330 DriverHealthHandles
= NULL
;
1331 DriverHealth
= NULL
;
1333 HealthStatus
= EfiDriverHealthStatusHealthy
;
1335 Status
= gBS
->LocateHandleBuffer (
1337 &gEfiDriverHealthProtocolGuid
,
1340 &DriverHealthHandles
1343 // There are no handles match the search for Driver Health Protocol has been installed.
1345 if (Status
== EFI_NOT_FOUND
) {
1349 // Assume all modules are healthy.
1354 // Found one or more Handles.
1356 if (!EFI_ERROR (Status
)) {
1357 for (Index
= 0; Index
< NoHandles
; Index
++) {
1358 Status
= gBS
->HandleProtocol (
1359 DriverHealthHandles
[Index
],
1360 &gEfiDriverHealthProtocolGuid
,
1361 (VOID
**) &DriverHealth
1363 if (!EFI_ERROR (Status
)) {
1364 Status
= DriverHealth
->GetHealthStatus (
1374 // Get the healthy status of the module
1376 if (!EFI_ERROR (Status
)) {
1377 if (HealthStatus
!= EfiDriverHealthStatusHealthy
) {
1379 // Return immediately one driver's status not in healthy.
1390 Processes a single controller using the EFI Driver Health Protocol associated with
1391 that controller. This algorithm continues to query the GetHealthStatus() service until
1392 one of the legal terminal states of the EFI Driver Health Protocol is reached. This may
1393 require the processing of HII Messages, HII Form, and invocation of repair operations.
1395 @param DriverHealth A pointer to the EFI_DRIVER_HEALTH_PROTOCOL instance.
1396 @param ControllerHandle The class guid specifies which form set will be displayed.
1397 @param ChildHandle The handle of the child controller to retrieve the health
1398 status on. This is an optional parameter that may be NULL.
1399 @param HealthStatus The health status of the controller.
1400 @param MessageList An array of warning or error messages associated
1401 with the controller specified by ControllerHandle and
1402 ChildHandle. This is an optional parameter that may be NULL.
1403 @param FormHiiHandle The HII handle for an HII form associated with the
1404 controller specified by ControllerHandle and ChildHandle.
1407 ProcessSingleControllerHealth (
1408 IN EFI_DRIVER_HEALTH_PROTOCOL
*DriverHealth
,
1409 IN EFI_HANDLE ControllerHandle
, OPTIONAL
1410 IN EFI_HANDLE ChildHandle
, OPTIONAL
1411 IN EFI_DRIVER_HEALTH_STATUS HealthStatus
,
1412 IN EFI_DRIVER_HEALTH_HII_MESSAGE
**MessageList
, OPTIONAL
1413 IN EFI_HII_HANDLE FormHiiHandle
1417 EFI_DRIVER_HEALTH_STATUS LocalHealthStatus
;
1419 LocalHealthStatus
= HealthStatus
;
1421 // If the module need to be repaired or reconfiguration, will process it until
1422 // reach a terminal status. The status from EfiDriverHealthStatusRepairRequired after repair
1423 // will be in (Health, Failed, Configuration Required).
1425 while( LocalHealthStatus
== EfiDriverHealthStatusConfigurationRequired
||
1426 LocalHealthStatus
== EfiDriverHealthStatusRepairRequired
) {
1428 if (LocalHealthStatus
== EfiDriverHealthStatusRepairRequired
) {
1429 Status
= DriverHealth
->Repair (
1433 (EFI_DRIVER_HEALTH_REPAIR_PROGRESS_NOTIFY
) RepairNotify
1437 // Via a form of the driver need to do configuration provided to process of status in
1438 // EfiDriverHealthStatusConfigurationRequired. The status after configuration should be in
1439 // (Healthy, Reboot Required, Failed, Reconnect Required, Repair Required).
1441 if (LocalHealthStatus
== EfiDriverHealthStatusConfigurationRequired
) {
1442 Status
= gFormBrowser2
->SendForm (
1446 &gEfiHiiDriverHealthFormsetGuid
,
1451 ASSERT( !EFI_ERROR (Status
));
1454 Status
= DriverHealth
->GetHealthStatus (
1462 ASSERT_EFI_ERROR (Status
);
1464 if (*MessageList
!= NULL
) {
1465 ProcessMessages (*MessageList
);
1470 // Health status in {Healthy, Failed} may also have Messages need to process
1472 if (LocalHealthStatus
== EfiDriverHealthStatusHealthy
|| LocalHealthStatus
== EfiDriverHealthStatusFailed
) {
1473 if (*MessageList
!= NULL
) {
1474 ProcessMessages (*MessageList
);
1478 // Check for RebootRequired or ReconnectRequired
1480 if (LocalHealthStatus
== EfiDriverHealthStatusRebootRequired
) {
1481 gRT
->ResetSystem (EfiResetWarm
, EFI_SUCCESS
, 0, NULL
);
1485 // Do reconnect if need.
1487 if (LocalHealthStatus
== EfiDriverHealthStatusReconnectRequired
) {
1488 Status
= gBS
->DisconnectController (ControllerHandle
, NULL
, NULL
);
1489 if (EFI_ERROR (Status
)) {
1491 // Disconnect failed. Need to promote reconnect to a reboot.
1493 gRT
->ResetSystem (EfiResetWarm
, EFI_SUCCESS
, 0, NULL
);
1495 gBS
->ConnectController (ControllerHandle
, NULL
, NULL
, TRUE
);
1501 Platform specific notification function for controller repair operations.
1503 If the driver for a controller support the Driver Health Protocol and the
1504 current state of the controller is EfiDriverHealthStatusRepairRequired then
1505 when the Repair() service of the Driver Health Protocol is called, this
1506 platform specific notification function can display the progress of the repair
1507 operation. Some platforms may choose to not display anything, other may choose
1508 to show the percentage complete on text consoles, and other may choose to render
1509 a progress bar on text and graphical consoles.
1511 This function displays the percentage of the repair operation that has been
1512 completed on text consoles. The percentage is Value / Limit * 100%.
1514 @param Value Value in the range 0..Limit the the repair has completed..
1515 @param Limit The maximum value of Value
1527 Print(L
"Repair Progress Undefined\n\r");
1529 Percent
= Value
* 100 / Limit
;
1530 Print(L
"Repair Progress = %3d%%\n\r", Percent
);
1535 Processes a set of messages returned by the GetHealthStatus ()
1536 service of the EFI Driver Health Protocol
1538 @param MessageList The MessageList point to messages need to processed.
1543 IN EFI_DRIVER_HEALTH_HII_MESSAGE
*MessageList
1547 EFI_STRING MessageString
;
1549 for (MessageIndex
= 0;
1550 MessageList
[MessageIndex
].HiiHandle
!= NULL
;
1553 MessageString
= HiiGetString (
1554 MessageList
[MessageIndex
].HiiHandle
,
1555 MessageList
[MessageIndex
].StringId
,
1558 if (MessageString
!= NULL
) {
1560 // User can customize the output. Just simply print out the MessageString like below.
1561 // Also can use the HiiHandle to display message on the front page.
1563 // Print(L"%s\n",MessageString);
1564 // gBS->Stall (100000);
1571 Repair the whole platform.
1573 This function is the main entry for user choose "Repair All" in the front page.
1574 It will try to do recovery job till all the driver health protocol installed modules
1575 reach a terminal state.
1577 @param DriverHealthList A Pointer to the list contain all of the platform driver health
1583 IN LIST_ENTRY
*DriverHealthList
1586 DRIVER_HEALTH_INFO
*DriverHealthInfo
;
1589 ASSERT (DriverHealthList
!= NULL
);
1591 Link
= GetFirstNode (DriverHealthList
);
1593 while (!IsNull (DriverHealthList
, Link
)) {
1594 DriverHealthInfo
= DEVICE_MANAGER_HEALTH_INFO_FROM_LINK (Link
);
1596 // Do driver health status operation by each link node
1598 ASSERT (DriverHealthInfo
!= NULL
);
1600 ProcessSingleControllerHealth (
1601 DriverHealthInfo
->DriverHealth
,
1602 DriverHealthInfo
->ControllerHandle
,
1603 DriverHealthInfo
->ChildHandle
,
1604 DriverHealthInfo
->HealthStatus
,
1605 &(DriverHealthInfo
->MessageList
),
1606 DriverHealthInfo
->HiiHandle
1609 Link
= GetNextNode (DriverHealthList
, Link
);
1615 Select the best matching language according to front page policy for best user experience.
1617 This function supports both ISO 639-2 and RFC 4646 language codes, but language
1618 code types may not be mixed in a single call to this function.
1620 @param SupportedLanguages A pointer to a Null-terminated ASCII string that
1621 contains a set of language codes in the format
1622 specified by Iso639Language.
1623 @param Iso639Language If TRUE, then all language codes are assumed to be
1624 in ISO 639-2 format. If FALSE, then all language
1625 codes are assumed to be in RFC 4646 language format.
1627 @retval NULL The best matching language could not be found in SupportedLanguages.
1628 @retval NULL There are not enough resources available to return the best matching
1630 @retval Other A pointer to a Null-terminated ASCII string that is the best matching
1631 language in SupportedLanguages.
1634 DriverHealthSelectBestLanguage (
1635 IN CHAR8
*SupportedLanguages
,
1636 IN BOOLEAN Iso639Language
1639 CHAR8
*LanguageVariable
;
1640 CHAR8
*BestLanguage
;
1642 LanguageVariable
= GetEfiGlobalVariable (Iso639Language
? L
"Lang" : L
"PlatformLang");
1644 BestLanguage
= GetBestLanguage(
1647 (LanguageVariable
!= NULL
) ? LanguageVariable
: "",
1648 Iso639Language
? "eng" : "en-US",
1651 if (LanguageVariable
!= NULL
) {
1652 FreePool (LanguageVariable
);
1655 return BestLanguage
;
1662 This is an internal worker function to get the Component Name (2) protocol interface
1663 and the language it supports.
1665 @param ProtocolGuid A pointer to an EFI_GUID. It points to Component Name (2) protocol GUID.
1666 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
1667 @param ComponentName A pointer to the Component Name (2) protocol interface.
1668 @param SupportedLanguage The best suitable language that matches the SupportedLangues interface for the
1669 located Component Name (2) instance.
1671 @retval EFI_SUCCESS The Component Name (2) protocol instance is successfully located and we find
1672 the best matching language it support.
1673 @retval EFI_UNSUPPORTED The input Language is not supported by the Component Name (2) protocol.
1674 @retval Other Some error occurs when locating Component Name (2) protocol instance or finding
1675 the supported language.
1679 GetComponentNameWorker (
1680 IN EFI_GUID
*ProtocolGuid
,
1681 IN EFI_HANDLE DriverBindingHandle
,
1682 OUT EFI_COMPONENT_NAME_PROTOCOL
**ComponentName
,
1683 OUT CHAR8
**SupportedLanguage
1689 // Locate Component Name (2) protocol on the driver binging handle.
1691 Status
= gBS
->OpenProtocol (
1692 DriverBindingHandle
,
1694 (VOID
**) ComponentName
,
1697 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1699 if (EFI_ERROR (Status
)) {
1704 // Apply shell policy to select the best language.
1706 *SupportedLanguage
= DriverHealthSelectBestLanguage (
1707 (*ComponentName
)->SupportedLanguages
,
1708 (BOOLEAN
) (ProtocolGuid
== &gEfiComponentNameProtocolGuid
)
1710 if (*SupportedLanguage
== NULL
) {
1711 Status
= EFI_UNSUPPORTED
;
1719 This is an internal worker function to get driver name from Component Name (2) protocol interface.
1722 @param ProtocolGuid A pointer to an EFI_GUID. It points to Component Name (2) protocol GUID.
1723 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
1724 @param DriverName A pointer to the Unicode string to return. This Unicode string is the name
1725 of the driver specified by This.
1727 @retval EFI_SUCCESS The driver name is successfully retrieved from Component Name (2) protocol
1729 @retval Other The driver name cannot be retrieved from Component Name (2) protocol
1734 GetDriverNameWorker (
1735 IN EFI_GUID
*ProtocolGuid
,
1736 IN EFI_HANDLE DriverBindingHandle
,
1737 OUT CHAR16
**DriverName
1741 CHAR8
*BestLanguage
;
1742 EFI_COMPONENT_NAME_PROTOCOL
*ComponentName
;
1745 // Retrieve Component Name (2) protocol instance on the driver binding handle and
1746 // find the best language this instance supports.
1748 Status
= GetComponentNameWorker (
1750 DriverBindingHandle
,
1754 if (EFI_ERROR (Status
)) {
1759 // Get the driver name from Component Name (2) protocol instance on the driver binging handle.
1761 Status
= ComponentName
->GetDriverName (
1766 FreePool (BestLanguage
);
1773 This function gets driver name from Component Name 2 protocol interface and Component Name protocol interface
1774 in turn. It first tries UEFI 2.0 Component Name 2 protocol interface and try to get the driver name.
1775 If the attempt fails, it then gets the driver name from EFI 1.1 Component Name protocol for backward
1776 compatibility support.
1778 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
1779 @param DriverName A pointer to the Unicode string to return. This Unicode string is the name
1780 of the driver specified by This.
1782 @retval EFI_SUCCESS The driver name is successfully retrieved from Component Name (2) protocol
1784 @retval Other The driver name cannot be retrieved from Component Name (2) protocol
1789 DriverHealthGetDriverName (
1790 IN EFI_HANDLE DriverBindingHandle
,
1791 OUT CHAR16
**DriverName
1797 // Get driver name from UEFI 2.0 Component Name 2 protocol interface.
1799 Status
= GetDriverNameWorker (&gEfiComponentName2ProtocolGuid
, DriverBindingHandle
, DriverName
);
1800 if (EFI_ERROR (Status
)) {
1802 // If it fails to get the driver name from Component Name protocol interface, we should fall back on
1803 // EFI 1.1 Component Name protocol interface.
1805 Status
= GetDriverNameWorker (&gEfiComponentNameProtocolGuid
, DriverBindingHandle
, DriverName
);
1814 This function gets controller name from Component Name 2 protocol interface and Component Name protocol interface
1815 in turn. It first tries UEFI 2.0 Component Name 2 protocol interface and try to get the controller name.
1816 If the attempt fails, it then gets the controller name from EFI 1.1 Component Name protocol for backward
1817 compatibility support.
1819 @param ProtocolGuid A pointer to an EFI_GUID. It points to Component Name (2) protocol GUID.
1820 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
1821 @param ControllerHandle The handle of a controller that the driver specified by This is managing.
1822 This handle specifies the controller whose name is to be returned.
1823 @param ChildHandle The handle of the child controller to retrieve the name of. This is an
1824 optional parameter that may be NULL. It will be NULL for device drivers.
1825 It will also be NULL for bus drivers that attempt to retrieve the name
1826 of the bus controller. It will not be NULL for a bus driver that attempts
1827 to retrieve the name of a child controller.
1828 @param ControllerName A pointer to the Unicode string to return. This Unicode string
1829 is the name of the controller specified by ControllerHandle and ChildHandle.
1831 @retval EFI_SUCCESS The controller name is successfully retrieved from Component Name (2) protocol
1833 @retval Other The controller name cannot be retrieved from Component Name (2) protocol.
1837 GetControllerNameWorker (
1838 IN EFI_GUID
*ProtocolGuid
,
1839 IN EFI_HANDLE DriverBindingHandle
,
1840 IN EFI_HANDLE ControllerHandle
,
1841 IN EFI_HANDLE ChildHandle
,
1842 OUT CHAR16
**ControllerName
1846 CHAR8
*BestLanguage
;
1847 EFI_COMPONENT_NAME_PROTOCOL
*ComponentName
;
1850 // Retrieve Component Name (2) protocol instance on the driver binding handle and
1851 // find the best language this instance supports.
1853 Status
= GetComponentNameWorker (
1855 DriverBindingHandle
,
1859 if (EFI_ERROR (Status
)) {
1864 // Get the controller name from Component Name (2) protocol instance on the driver binging handle.
1866 Status
= ComponentName
->GetControllerName (
1873 FreePool (BestLanguage
);
1880 This function gets controller name from Component Name 2 protocol interface and Component Name protocol interface
1881 in turn. It first tries UEFI 2.0 Component Name 2 protocol interface and try to get the controller name.
1882 If the attempt fails, it then gets the controller name from EFI 1.1 Component Name protocol for backward
1883 compatibility support.
1885 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
1886 @param ControllerHandle The handle of a controller that the driver specified by This is managing.
1887 This handle specifies the controller whose name is to be returned.
1888 @param ChildHandle The handle of the child controller to retrieve the name of. This is an
1889 optional parameter that may be NULL. It will be NULL for device drivers.
1890 It will also be NULL for bus drivers that attempt to retrieve the name
1891 of the bus controller. It will not be NULL for a bus driver that attempts
1892 to retrieve the name of a child controller.
1893 @param ControllerName A pointer to the Unicode string to return. This Unicode string
1894 is the name of the controller specified by ControllerHandle and ChildHandle.
1896 @retval EFI_SUCCESS The controller name is successfully retrieved from Component Name (2) protocol
1898 @retval Other The controller name cannot be retrieved from Component Name (2) protocol.
1902 DriverHealthGetControllerName (
1903 IN EFI_HANDLE DriverBindingHandle
,
1904 IN EFI_HANDLE ControllerHandle
,
1905 IN EFI_HANDLE ChildHandle
,
1906 OUT CHAR16
**ControllerName
1912 // Get controller name from UEFI 2.0 Component Name 2 protocol interface.
1914 Status
= GetControllerNameWorker (
1915 &gEfiComponentName2ProtocolGuid
,
1916 DriverBindingHandle
,
1921 if (EFI_ERROR (Status
)) {
1923 // If it fails to get the controller name from Component Name protocol interface, we should fall back on
1924 // EFI 1.1 Component Name protocol interface.
1926 Status
= GetControllerNameWorker (
1927 &gEfiComponentNameProtocolGuid
,
1928 DriverBindingHandle
,