2 The platform device manager reference implementation
4 Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
5 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 #define MAX_MAC_ADDRESS_NODE_LIST_LEN 10
38 // Which Mac Address string is select
39 // it will decide what menu need to show in the NETWORK_DEVICE_FORM_ID form.
41 EFI_STRING mSelectedMacAddrString
;
44 // Which form Id need to be show.
46 EFI_FORM_ID mNextShowFormId
= DEVICE_MANAGER_FORM_ID
;
49 // The Mac Address show in the NETWORK_DEVICE_LIST_FORM_ID
51 MAC_ADDRESS_NODE_LIST mMacDeviceList
;
53 DEVICE_MANAGER_MENU_ITEM mDeviceManagerMenuItemTable
[] = {
54 { STRING_TOKEN (STR_DISK_DEVICE
), EFI_DISK_DEVICE_CLASS
},
55 { STRING_TOKEN (STR_VIDEO_DEVICE
), EFI_VIDEO_DEVICE_CLASS
},
56 { STRING_TOKEN (STR_NETWORK_DEVICE
), EFI_NETWORK_DEVICE_CLASS
},
57 { STRING_TOKEN (STR_INPUT_DEVICE
), EFI_INPUT_DEVICE_CLASS
},
58 { STRING_TOKEN (STR_ON_BOARD_DEVICE
), EFI_ON_BOARD_DEVICE_CLASS
},
59 { STRING_TOKEN (STR_OTHER_DEVICE
), EFI_OTHER_DEVICE_CLASS
}
62 HII_VENDOR_DEVICE_PATH mDeviceManagerHiiVendorDevicePath
= {
68 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
69 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
72 DEVICE_MANAGER_FORMSET_GUID
76 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
78 (UINT8
) (END_DEVICE_PATH_LENGTH
),
79 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
84 HII_VENDOR_DEVICE_PATH mDriverHealthHiiVendorDevicePath
= {
90 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
91 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
94 DRIVER_HEALTH_FORMSET_GUID
98 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
100 (UINT8
) (END_DEVICE_PATH_LENGTH
),
101 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
107 This function is invoked if user selected a interactive opcode from Device Manager's
108 Formset. The decision by user is saved to gCallbackKey for later processing. If
109 user set VBIOS, the new value is saved to EFI variable.
111 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
112 @param Action Specifies the type of action taken by the browser.
113 @param QuestionId A unique value which is sent to the original exporting driver
114 so that it can identify the type of data to expect.
115 @param Type The type of value for the question.
116 @param Value A pointer to the data being sent to the original exporting driver.
117 @param ActionRequest On return, points to the action requested by the callback function.
119 @retval EFI_SUCCESS The callback successfully handled the action.
120 @retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.
125 DeviceManagerCallback (
126 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
127 IN EFI_BROWSER_ACTION Action
,
128 IN EFI_QUESTION_ID QuestionId
,
130 IN EFI_IFR_TYPE_VALUE
*Value
,
131 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
136 if (Action
!= EFI_BROWSER_ACTION_CHANGING
) {
138 // All other action return unsupported.
140 return EFI_UNSUPPORTED
;
144 return EFI_INVALID_PARAMETER
;
147 gCallbackKey
= QuestionId
;
148 if ((QuestionId
< MAX_KEY_SECTION_LEN
+ NETWORK_DEVICE_LIST_KEY_OFFSET
) && (QuestionId
>= NETWORK_DEVICE_LIST_KEY_OFFSET
)) {
150 // If user select the mac address, need to record mac address string to support next form show.
152 for (CurIndex
= 0; CurIndex
< mMacDeviceList
.CurListLen
; CurIndex
++) {
153 if (mMacDeviceList
.NodeList
[CurIndex
].QuestionId
== QuestionId
) {
154 mSelectedMacAddrString
= HiiGetString (gDeviceManagerPrivate
.HiiHandle
, mMacDeviceList
.NodeList
[CurIndex
].PromptId
, NULL
);
164 This function registers HII packages to HII database.
166 @retval EFI_SUCCESS HII packages for the Device Manager were registered successfully.
167 @retval EFI_OUT_OF_RESOURCES HII packages for the Device Manager failed to be registered.
171 InitializeDeviceManager (
178 // Install Device Path Protocol and Config Access protocol to driver handle
180 Status
= gBS
->InstallMultipleProtocolInterfaces (
181 &gDeviceManagerPrivate
.DriverHandle
,
182 &gEfiDevicePathProtocolGuid
,
183 &mDeviceManagerHiiVendorDevicePath
,
184 &gEfiHiiConfigAccessProtocolGuid
,
185 &gDeviceManagerPrivate
.ConfigAccess
,
188 ASSERT_EFI_ERROR (Status
);
190 Status
= gBS
->InstallMultipleProtocolInterfaces (
191 &gDeviceManagerPrivate
.DriverHealthHandle
,
192 &gEfiDevicePathProtocolGuid
,
193 &mDriverHealthHiiVendorDevicePath
,
194 &gEfiHiiConfigAccessProtocolGuid
,
195 &gDeviceManagerPrivate
.DriverHealthConfigAccess
,
198 ASSERT_EFI_ERROR (Status
);
200 mMacDeviceList
.CurListLen
= 0;
201 mMacDeviceList
.MaxListLen
= 0;
207 Extract the displayed formset for given HII handle and class guid.
209 @param Handle The HII handle.
210 @param SetupClassGuid The class guid specifies which form set will be displayed.
211 @param SkipCount Skip some formsets which has processed before.
212 @param FormSetTitle Formset title string.
213 @param FormSetHelp Formset help string.
214 @param FormSetGuid Return the formset guid for this formset.
216 @retval TRUE The formset for given HII handle will be displayed.
217 @return FALSE The formset for given HII handle will not be displayed.
221 ExtractDisplayedHiiFormFromHiiHandle (
222 IN EFI_HII_HANDLE Handle
,
223 IN EFI_GUID
*SetupClassGuid
,
225 OUT EFI_STRING_ID
*FormSetTitle
,
226 OUT EFI_STRING_ID
*FormSetHelp
,
227 OUT EFI_GUID
**FormSetGuid
232 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
237 UINT32 PackageListLength
;
238 EFI_HII_PACKAGE_HEADER PackageHeader
;
242 ASSERT (Handle
!= NULL
);
243 ASSERT (SetupClassGuid
!= NULL
);
244 ASSERT (FormSetTitle
!= NULL
);
245 ASSERT (FormSetHelp
!= NULL
);
253 // Get HII PackageList
256 HiiPackageList
= NULL
;
257 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
259 // Handle is a invalid handle. Check if Handle is corrupted.
261 ASSERT (Status
!= EFI_NOT_FOUND
);
263 // The return status should always be EFI_BUFFER_TOO_SMALL as input buffer's size is 0.
265 ASSERT (Status
== EFI_BUFFER_TOO_SMALL
);
267 HiiPackageList
= AllocatePool (BufferSize
);
268 ASSERT (HiiPackageList
!= NULL
);
270 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
271 if (EFI_ERROR (Status
)) {
276 // Get Form package from this HII package List
278 Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
280 PackageListLength
= ReadUnaligned32 (&HiiPackageList
->PackageLength
);
282 while (Offset
< PackageListLength
) {
283 Package
= ((UINT8
*) HiiPackageList
) + Offset
;
284 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
286 if (PackageHeader
.Type
== EFI_HII_PACKAGE_FORMS
) {
288 // Search FormSet Opcode in this Form Package
290 Offset2
= sizeof (EFI_HII_PACKAGE_HEADER
);
291 while (Offset2
< PackageHeader
.Length
) {
292 OpCodeData
= Package
+ Offset2
;
293 Offset2
+= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
;
295 if (((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
== EFI_IFR_FORM_SET_OP
) {
296 if (SkipCount
!= 0) {
301 if (((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
> OFFSET_OF (EFI_IFR_FORM_SET
, Flags
)) {
303 // Find FormSet OpCode
305 ClassGuidNum
= (UINT8
) (((EFI_IFR_FORM_SET
*) OpCodeData
)->Flags
& 0x3);
306 ClassGuid
= (EFI_GUID
*) (VOID
*)(OpCodeData
+ sizeof (EFI_IFR_FORM_SET
));
307 while (ClassGuidNum
-- > 0) {
308 if (CompareGuid (SetupClassGuid
, ClassGuid
)) {
309 CopyMem (FormSetTitle
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->FormSetTitle
, sizeof (EFI_STRING_ID
));
310 CopyMem (FormSetHelp
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->Help
, sizeof (EFI_STRING_ID
));
311 *FormSetGuid
= AllocateCopyPool (sizeof (EFI_GUID
), &((EFI_IFR_FORM_SET
*) OpCodeData
)->Guid
);
312 ASSERT (*FormSetGuid
!= NULL
);
313 FreePool (HiiPackageList
);
319 CopyMem (FormSetTitle
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->FormSetTitle
, sizeof (EFI_STRING_ID
));
320 CopyMem (FormSetHelp
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->Help
, sizeof (EFI_STRING_ID
));
321 *FormSetGuid
= AllocateCopyPool (sizeof (EFI_GUID
), &((EFI_IFR_FORM_SET
*) OpCodeData
)->Guid
);
322 ASSERT (*FormSetGuid
!= NULL
);
323 FreePool (HiiPackageList
);
331 // Go to next package
333 Offset
+= PackageHeader
.Length
;
336 FreePool (HiiPackageList
);
342 Get the mac address string from the device path.
343 if the device path has the vlan, get the vanid also.
345 @param MacAddressNode Device path begin with mac address
346 @param PBuffer Output string buffer contain mac address.
351 IN MAC_ADDR_DEVICE_PATH
*MacAddressNode
,
358 EFI_DEVICE_PATH_PROTOCOL
*Node
;
365 ASSERT(MacAddressNode
!= NULL
);
367 HwAddressSize
= sizeof (EFI_MAC_ADDRESS
);
368 if (MacAddressNode
->IfType
== 0x01 || MacAddressNode
->IfType
== 0x00) {
373 // The output format is MAC:XX:XX:XX:...\XXXX
374 // The size is the Number size + ":" size + Vlan size(\XXXX) + End
376 BufferLen
= (4 + 2 * HwAddressSize
+ (HwAddressSize
- 1) + 5 + 1) * sizeof (CHAR16
);
377 String
= AllocateZeroPool (BufferLen
);
378 if (String
== NULL
) {
383 StrCpy(String
, L
"MAC:");
387 // Convert the MAC address into a unicode string.
389 HwAddress
= &MacAddressNode
->MacAddress
.Addr
[0];
390 for (Index
= 0; Index
< HwAddressSize
; Index
++) {
391 String
+= UnicodeValueToString (String
, PREFIX_ZERO
| RADIX_HEX
, *(HwAddress
++), 2);
392 if (Index
< HwAddressSize
- 1) {
398 // If VLAN is configured, it will need extra 5 characters like "\0005".
399 // Plus one unicode character for the null-terminator.
401 Node
= (EFI_DEVICE_PATH_PROTOCOL
*)MacAddressNode
;
402 while (!IsDevicePathEnd (Node
)) {
403 if (Node
->Type
== MESSAGING_DEVICE_PATH
&& Node
->SubType
== MSG_VLAN_DP
) {
404 VlanId
= ((VLAN_DEVICE_PATH
*) Node
)->VlanId
;
406 Node
= NextDevicePathNode (Node
);
411 String
+= UnicodeValueToString (String
, PREFIX_ZERO
| RADIX_HEX
, VlanId
, 4);
415 // Null terminate the Unicode string
423 Save question id and prompt id to the mac device list.
424 If the same mac address has saved yet, no need to add more.
426 @param MacAddrString Mac address string.
428 @retval EFI_SUCCESS Add the item is successful.
429 @return Other values if failed to Add the item.
432 AddIdToMacDeviceList (
433 IN EFI_STRING MacAddrString
436 MENU_INFO_ITEM
*TempDeviceList
;
438 EFI_STRING StoredString
;
439 EFI_STRING_ID PromptId
;
440 EFI_HII_HANDLE HiiHandle
;
442 HiiHandle
= gDeviceManagerPrivate
.HiiHandle
;
443 TempDeviceList
= NULL
;
445 for (Index
= 0; Index
< mMacDeviceList
.CurListLen
; Index
++) {
446 StoredString
= HiiGetString (HiiHandle
, mMacDeviceList
.NodeList
[Index
].PromptId
, NULL
);
447 if (StoredString
== NULL
) {
452 // Already has save the same mac address to the list.
454 if (StrCmp (MacAddrString
, StoredString
) == 0) {
459 PromptId
= HiiSetString(HiiHandle
, 0, MacAddrString
, NULL
);
461 // If not in the list, save it.
463 if (mMacDeviceList
.MaxListLen
> mMacDeviceList
.CurListLen
+ 1) {
464 mMacDeviceList
.NodeList
[mMacDeviceList
.CurListLen
].PromptId
= PromptId
;
465 mMacDeviceList
.NodeList
[mMacDeviceList
.CurListLen
].QuestionId
= (EFI_QUESTION_ID
) (mMacDeviceList
.CurListLen
+ NETWORK_DEVICE_LIST_KEY_OFFSET
);
467 mMacDeviceList
.MaxListLen
+= MAX_MAC_ADDRESS_NODE_LIST_LEN
;
468 if (mMacDeviceList
.CurListLen
!= 0) {
469 TempDeviceList
= (MENU_INFO_ITEM
*)AllocateCopyPool (sizeof (MENU_INFO_ITEM
) * mMacDeviceList
.MaxListLen
, (VOID
*)mMacDeviceList
.NodeList
);
471 TempDeviceList
= (MENU_INFO_ITEM
*)AllocatePool (sizeof (MENU_INFO_ITEM
) * mMacDeviceList
.MaxListLen
);
474 if (TempDeviceList
== NULL
) {
477 TempDeviceList
[mMacDeviceList
.CurListLen
].PromptId
= PromptId
;
478 TempDeviceList
[mMacDeviceList
.CurListLen
].QuestionId
= (EFI_QUESTION_ID
) (mMacDeviceList
.CurListLen
+ NETWORK_DEVICE_LIST_KEY_OFFSET
);
480 if (mMacDeviceList
.CurListLen
> 0) {
481 FreePool(mMacDeviceList
.NodeList
);
484 mMacDeviceList
.NodeList
= TempDeviceList
;
486 mMacDeviceList
.CurListLen
++;
492 Check the devcie path, try to find whether it has mac address path.
494 In this function, first need to check whether this path has mac address path.
495 second, when the mac address device path has find, also need to deicide whether
496 need to add this mac address relate info to the menu.
498 @param *Node Input device which need to be check.
499 @param *NeedAddItem Whether need to add the menu in the network device list.
501 @retval TRUE Has mac address device path.
502 @retval FALSE NOT Has mac address device path.
506 IsMacAddressDevicePath (
508 OUT BOOLEAN
*NeedAddItem
511 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
515 ASSERT (Node
!= NULL
);
516 *NeedAddItem
= FALSE
;
520 DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) Node
;
523 // find the partition device path node
525 while (!IsDevicePathEnd (DevicePath
)) {
526 if ((DevicePathType (DevicePath
) == MESSAGING_DEVICE_PATH
) &&
527 (DevicePathSubType (DevicePath
) == MSG_MAC_ADDR_DP
)) {
530 if (DEVICE_MANAGER_FORM_ID
== mNextShowFormId
) {
535 if (!GetMacAddressString((MAC_ADDR_DEVICE_PATH
*)DevicePath
, &Buffer
)) {
539 if (NETWORK_DEVICE_FORM_ID
== mNextShowFormId
) {
540 if (StrCmp (Buffer
, mSelectedMacAddrString
) == 0) {
546 if (NETWORK_DEVICE_LIST_FORM_ID
== mNextShowFormId
) {
548 // Same handle may has two network child handle, so the questionid
549 // has the offset of SAME_HANDLE_KEY_OFFSET.
551 if (AddIdToMacDeviceList (Buffer
)) {
557 DevicePath
= NextDevicePathNode (DevicePath
);
560 if (Buffer
!= NULL
) {
568 Check to see if the device path is for the network device.
570 @param Handle The HII handle which include the mac address device path.
571 @param ItemCount The new add Mac address item count.
573 @retval TRUE Need to add new item in the menu.
574 @return FALSE Do not need to add the menu about the network.
578 IsNeedAddNetworkMenu (
579 IN EFI_HII_HANDLE Handle
,
586 EFI_HANDLE DriverHandle
;
587 EFI_HANDLE ControllerHandle
;
588 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
589 EFI_DEVICE_PATH_PROTOCOL
*TmpDevicePath
;
590 EFI_DEVICE_PATH_PROTOCOL
*ChildDevicePath
;
591 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY
*OpenInfoBuffer
;
595 OpenInfoBuffer
= NULL
;
596 if ((Handle
== NULL
) || (ItemCount
== NULL
)) {
601 Status
= gHiiDatabase
->GetPackageListHandle (gHiiDatabase
, Handle
, &DriverHandle
);
602 if (EFI_ERROR (Status
)) {
606 // Get the device path by the got Driver handle .
608 Status
= gBS
->HandleProtocol (DriverHandle
, &gEfiDevicePathProtocolGuid
, (VOID
**) &DevicePath
);
609 if (EFI_ERROR (Status
)) {
612 TmpDevicePath
= DevicePath
;
615 // Check whether this device path include mac address device path.
616 // If this path has mac address path, get the value whether need
617 // add this info to the menu and return.
618 // Else check more about the child handle devcie path.
620 if (IsMacAddressDevicePath(TmpDevicePath
, &IsNeedAdd
)) {
621 if ((NETWORK_DEVICE_LIST_FORM_ID
== mNextShowFormId
) && IsNeedAdd
) {
628 // Search whether this path is the controller path, not he child handle path.
629 // And the child handle has the network devcie connected.
631 TmpDevicePath
= DevicePath
;
632 Status
= gBS
->LocateDevicePath(&gEfiDevicePathProtocolGuid
, &TmpDevicePath
, &ControllerHandle
);
633 if (EFI_ERROR (Status
)) {
637 if (!IsDevicePathEnd (TmpDevicePath
)) {
642 // Retrieve the list of agents that are consuming the specific protocol
643 // on ControllerHandle.
644 // The buffer point by OpenInfoBuffer need be free at this function.
646 Status
= gBS
->OpenProtocolInformation (
648 &gEfiPciIoProtocolGuid
,
652 if (EFI_ERROR (Status
)) {
657 // Inspect if ChildHandle is one of the agents.
659 Status
= EFI_UNSUPPORTED
;
660 for (Index
= 0; Index
< EntryCount
; Index
++) {
662 // Query all the children created by the controller handle's driver
664 if ((OpenInfoBuffer
[Index
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) != 0) {
665 Status
= gBS
->OpenProtocol (
666 OpenInfoBuffer
[Index
].ControllerHandle
,
667 &gEfiDevicePathProtocolGuid
,
668 (VOID
**) &ChildDevicePath
,
671 EFI_OPEN_PROTOCOL_GET_PROTOCOL
673 if (EFI_ERROR (Status
)) {
678 // Check whether this device path include mac address device path.
680 if (!IsMacAddressDevicePath(ChildDevicePath
, &IsNeedAdd
)) {
682 // If this path not has mac address path, check the other.
687 // If need to update the NETWORK_DEVICE_LIST_FORM, try to get more.
689 if ((NETWORK_DEVICE_LIST_FORM_ID
== mNextShowFormId
)) {
696 // If need to update other form, return whether need to add to the menu.
705 if (OpenInfoBuffer
!= NULL
) {
706 FreePool (OpenInfoBuffer
);
712 Get HiiHandle total number.
714 @param HiiHandles The input HiiHandle array.
716 @retval the Hiihandle count.
721 IN EFI_HII_HANDLE
*HiiHandles
726 for (Index
= 0; HiiHandles
[Index
] != NULL
; Index
++) {
733 Insert the new HiiHandle + FormsetGuid at the NewPair[InsertOffset].
735 @param HiiHandles The input HiiHandle array.
736 @param GuidLists The input form set guid lists.
737 @param ArrayCount The input array count, new array will be arraycount + 1 size.
738 @param Offset The current used HiiHandle's Offset.
739 @param FormSetGuid The new found formset guid.
744 IN OUT EFI_HII_HANDLE
**HiiHandles
,
745 IN OUT EFI_GUID
***GuidLists
,
748 IN EFI_GUID
*FormSetGuid
751 EFI_HII_HANDLE
*NewHiiHandles
;
752 EFI_GUID
**NewGuidLists
;
755 // +2 means include the new HiiHandle and the last empty NULL pointer.
757 NewHiiHandles
= AllocateZeroPool ((ArrayCount
+ 2) * sizeof (EFI_HII_HANDLE
));
758 ASSERT (NewHiiHandles
!= NULL
);
760 CopyMem (NewHiiHandles
, *HiiHandles
, Offset
* sizeof (EFI_HII_HANDLE
));
761 NewHiiHandles
[Offset
] = NewHiiHandles
[Offset
- 1];
762 CopyMem (NewHiiHandles
+ Offset
+ 1, *HiiHandles
+ Offset
, (ArrayCount
- Offset
) * sizeof (EFI_HII_HANDLE
));
764 NewGuidLists
= AllocateZeroPool ((ArrayCount
+ 2) * sizeof (EFI_GUID
*));
765 ASSERT (NewGuidLists
!= NULL
);
767 CopyMem (NewGuidLists
, *GuidLists
, Offset
* sizeof (EFI_GUID
*));
768 NewGuidLists
[Offset
] = FormSetGuid
;
770 FreePool (*HiiHandles
);
771 *HiiHandles
= NewHiiHandles
;
772 FreePool (*GuidLists
);
773 *GuidLists
= NewGuidLists
;
777 Call the browser and display the device manager to allow user
778 to configure the platform.
780 This function create the dynamic content for device manager. It includes
781 section header for all class of devices, one-of opcode to set VBIOS.
783 @retval EFI_SUCCESS Operation is successful.
784 @return Other values if failed to clean up the dynamic content from HII
797 EFI_STRING_ID TokenHelp
;
798 EFI_HII_HANDLE
*HiiHandles
;
799 EFI_HII_HANDLE HiiHandle
;
800 EFI_STRING_ID FormSetTitle
;
801 EFI_STRING_ID FormSetHelp
;
802 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
803 VOID
*StartOpCodeHandle
;
804 VOID
*EndOpCodeHandle
;
805 EFI_IFR_GUID_LABEL
*StartLabel
;
806 EFI_IFR_GUID_LABEL
*EndLabel
;
808 EFI_HANDLE
*DriverHealthHandles
;
809 BOOLEAN AddNetworkMenu
;
812 EFI_STRING NewStringTitle
;
813 EFI_GUID
**GuidLists
;
816 EFI_GUID
*FormSetGuid
;
820 Status
= EFI_SUCCESS
;
823 DriverHealthHandles
= NULL
;
824 AddNetworkMenu
= FALSE
;
830 // Connect all prior to entering the platform setup menu.
832 if (!gConnectAllHappened
) {
833 BdsLibConnectAllDriversToAllControllers ();
834 gConnectAllHappened
= TRUE
;
837 HiiHandle
= gDeviceManagerPrivate
.HiiHandle
;
838 if (HiiHandle
== NULL
) {
840 // Publish our HII data.
842 HiiHandle
= HiiAddPackages (
843 &gDeviceManagerFormSetGuid
,
844 gDeviceManagerPrivate
.DriverHandle
,
849 if (HiiHandle
== NULL
) {
850 return EFI_OUT_OF_RESOURCES
;
853 gDeviceManagerPrivate
.HiiHandle
= HiiHandle
;
857 // If need show the Network device list form, clear the old save list first.
859 if ((mNextShowFormId
== NETWORK_DEVICE_LIST_FORM_ID
) && (mMacDeviceList
.CurListLen
> 0)) {
860 mMacDeviceList
.CurListLen
= 0;
864 // Update the network device form titile.
866 if (mNextShowFormId
== NETWORK_DEVICE_FORM_ID
) {
867 String
= HiiGetString (HiiHandle
, STRING_TOKEN (STR_FORM_NETWORK_DEVICE_TITLE
), NULL
);
868 NewStringLen
= StrLen(mSelectedMacAddrString
) * 2;
869 NewStringLen
+= (StrLen(String
) + 2) * 2;
870 NewStringTitle
= AllocatePool (NewStringLen
);
871 UnicodeSPrint (NewStringTitle
, NewStringLen
, L
"%s %s", String
, mSelectedMacAddrString
);
872 HiiSetString (HiiHandle
, STRING_TOKEN (STR_FORM_NETWORK_DEVICE_TITLE
), NewStringTitle
, NULL
);
874 FreePool (NewStringTitle
);
878 // Allocate space for creation of UpdateData Buffer
880 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
881 ASSERT (StartOpCodeHandle
!= NULL
);
883 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
884 ASSERT (EndOpCodeHandle
!= NULL
);
887 // Create Hii Extend Label OpCode as the start opcode
889 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
890 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
892 // According to the next show Form id(mNextShowFormId) to decide which form need to update.
894 StartLabel
->Number
= (UINT16
) (LABEL_FORM_ID_OFFSET
+ mNextShowFormId
);
897 // Create Hii Extend Label OpCode as the end opcode
899 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
900 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
901 EndLabel
->Number
= LABEL_END
;
904 // Get all the Hii handles
906 HiiHandles
= HiiGetHiiHandles (NULL
);
907 ASSERT (HiiHandles
!= NULL
);
909 HandleNum
= GetHiiHandleCount (HiiHandles
);
910 GuidLists
= AllocateZeroPool ((HandleNum
+ 1) * sizeof (EFI_GUID
*));
911 ASSERT (GuidLists
!= NULL
);
914 // Search for formset of each class type
916 for (Index
= 0; HiiHandles
[Index
] != NULL
; Index
++) {
918 // The QuestionId in the form which will call the driver form has this asssumption.
919 // QuestionId = Handle Index + NETWORK_DEVICE_LIST_KEY_OFFSET;
920 // Different QuestionId at least has the section of NETWORK_DEVICE_LIST_KEY_OFFSET.
922 ASSERT(Index
< MAX_KEY_SECTION_LEN
);
924 if (!ExtractDisplayedHiiFormFromHiiHandle (HiiHandles
[Index
], &gEfiHiiPlatformSetupFormsetGuid
, SkipCount
, &FormSetTitle
, &FormSetHelp
, &FormSetGuid
)) {
930 // One HiiHandle has more than one formset can be shown,
931 // Insert a new pair of HiiHandle + Guid to the HiiHandles and GuidLists list.
934 AdjustArrayData (&HiiHandles
, &GuidLists
, HandleNum
, Index
+ 1, FormSetGuid
);
939 String
= HiiGetString (HiiHandles
[Index
], FormSetTitle
, NULL
);
940 if (String
== NULL
) {
941 String
= HiiGetString (HiiHandle
, STR_MISSING_STRING
, NULL
);
942 ASSERT (String
!= NULL
);
944 Token
= HiiSetString (HiiHandle
, 0, String
, NULL
);
947 String
= HiiGetString (HiiHandles
[Index
], FormSetHelp
, NULL
);
948 if (String
== NULL
) {
949 String
= HiiGetString (HiiHandle
, STR_MISSING_STRING
, NULL
);
950 ASSERT (String
!= NULL
);
952 TokenHelp
= HiiSetString (HiiHandle
, 0, String
, NULL
);
956 // Network device process
958 if (IsNeedAddNetworkMenu (HiiHandles
[Index
], &AddItemCount
)) {
959 if (mNextShowFormId
== DEVICE_MANAGER_FORM_ID
) {
961 // Only show one menu item "Network Config" in the device manger form.
963 if (!AddNetworkMenu
) {
964 AddNetworkMenu
= TRUE
;
965 HiiCreateGotoOpCode (
968 STRING_TOKEN (STR_FORM_NETWORK_DEVICE_LIST_TITLE
),
969 STRING_TOKEN (STR_FORM_NETWORK_DEVICE_LIST_HELP
),
970 EFI_IFR_FLAG_CALLBACK
,
971 (EFI_QUESTION_ID
) QUESTION_NETWORK_DEVICE_ID
974 } else if (mNextShowFormId
== NETWORK_DEVICE_LIST_FORM_ID
) {
976 // In network device list form, same mac address device only show one menu.
978 while (AddItemCount
> 0) {
979 HiiCreateGotoOpCode (
982 mMacDeviceList
.NodeList
[mMacDeviceList
.CurListLen
- AddItemCount
].PromptId
,
983 STRING_TOKEN (STR_NETWORK_DEVICE_HELP
),
984 EFI_IFR_FLAG_CALLBACK
,
985 mMacDeviceList
.NodeList
[mMacDeviceList
.CurListLen
- AddItemCount
].QuestionId
989 } else if (mNextShowFormId
== NETWORK_DEVICE_FORM_ID
) {
991 // In network device form, only the selected mac address device need to be show.
993 HiiCreateGotoOpCode (
998 EFI_IFR_FLAG_CALLBACK
,
999 (EFI_QUESTION_ID
) (Index
+ DEVICE_KEY_OFFSET
)
1005 // Not network device process, only need to show at device manger form.
1007 if (mNextShowFormId
== DEVICE_MANAGER_FORM_ID
) {
1008 HiiCreateGotoOpCode (
1013 EFI_IFR_FLAG_CALLBACK
,
1014 (EFI_QUESTION_ID
) (Index
+ DEVICE_KEY_OFFSET
)
1020 // Try to find more formset in this HiiHandle.
1026 Status
= gBS
->LocateHandleBuffer (
1028 &gEfiDriverHealthProtocolGuid
,
1031 &DriverHealthHandles
1035 // If there are no drivers installed driver health protocol, do not create driver health entry in UI
1037 if (NumHandles
!= 0) {
1039 // If driver health protocol is installed, create Driver Health subtitle and entry
1041 HiiCreateSubTitleOpCode (StartOpCodeHandle
, STRING_TOKEN (STR_DM_DRIVER_HEALTH_TITLE
), 0, 0, 0);
1042 HiiCreateGotoOpCode (
1044 DRIVER_HEALTH_FORM_ID
,
1045 STRING_TOKEN(STR_DRIVER_HEALTH_ALL_HEALTHY
), // Prompt text
1046 STRING_TOKEN(STR_DRIVER_HEALTH_STATUS_HELP
), // Help text
1047 EFI_IFR_FLAG_CALLBACK
,
1048 DEVICE_MANAGER_KEY_DRIVER_HEALTH
// Question ID
1052 // Check All Driver health status
1054 if (!PlaformHealthStatusCheck ()) {
1056 // At least one driver in the platform are not in healthy status
1058 HiiSetString (HiiHandle
, STRING_TOKEN (STR_DRIVER_HEALTH_ALL_HEALTHY
), GetStringById (STRING_TOKEN (STR_DRIVER_NOT_HEALTH
)), NULL
);
1061 // For the string of STR_DRIVER_HEALTH_ALL_HEALTHY previously has been updated and we need to update it while re-entry.
1063 HiiSetString (HiiHandle
, STRING_TOKEN (STR_DRIVER_HEALTH_ALL_HEALTHY
), GetStringById (STRING_TOKEN (STR_DRIVER_HEALTH_ALL_HEALTHY
)), NULL
);
1069 &gDeviceManagerFormSetGuid
,
1075 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
1076 Status
= gFormBrowser2
->SendForm (
1080 &gDeviceManagerFormSetGuid
,
1085 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
1086 EnableResetRequired ();
1090 // We will have returned from processing a callback, selected
1091 // a target to display
1093 if ((gCallbackKey
>= DEVICE_KEY_OFFSET
)) {
1094 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
1095 Status
= gFormBrowser2
->SendForm (
1097 &HiiHandles
[gCallbackKey
- DEVICE_KEY_OFFSET
],
1099 GuidLists
[gCallbackKey
- DEVICE_KEY_OFFSET
],
1105 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
1106 EnableResetRequired ();
1110 // Force return to Device Manager
1112 gCallbackKey
= FRONT_PAGE_KEY_DEVICE_MANAGER
;
1117 // Driver Health item chose.
1119 if (gCallbackKey
== DEVICE_MANAGER_KEY_DRIVER_HEALTH
) {
1120 CallDriverHealth ();
1122 // Force return to Device Manager
1124 gCallbackKey
= FRONT_PAGE_KEY_DEVICE_MANAGER
;
1129 // Enter from device manager and into the network device list.
1131 if (gCallbackKey
== QUESTION_NETWORK_DEVICE_ID
) {
1132 mNextShowFormId
= NETWORK_DEVICE_LIST_FORM_ID
;
1133 gCallbackKey
= FRONT_PAGE_KEY_DEVICE_MANAGER
;
1138 // In this case, go from the network device list to the specify device.
1140 if ((gCallbackKey
< MAX_KEY_SECTION_LEN
+ NETWORK_DEVICE_LIST_KEY_OFFSET
) && (gCallbackKey
>= NETWORK_DEVICE_LIST_KEY_OFFSET
)) {
1141 mNextShowFormId
= NETWORK_DEVICE_FORM_ID
;
1142 gCallbackKey
= FRONT_PAGE_KEY_DEVICE_MANAGER
;
1147 // Select the ESC, the gCallbackKey == 0.
1149 if(mNextShowFormId
- 1 < DEVICE_MANAGER_FORM_ID
) {
1150 mNextShowFormId
= DEVICE_MANAGER_FORM_ID
;
1152 mNextShowFormId
= (UINT16
) (mNextShowFormId
- 1);
1153 gCallbackKey
= FRONT_PAGE_KEY_DEVICE_MANAGER
;
1158 // Remove our packagelist from HII database.
1160 HiiRemovePackages (HiiHandle
);
1161 gDeviceManagerPrivate
.HiiHandle
= NULL
;
1163 HiiFreeOpCodeHandle (StartOpCodeHandle
);
1164 HiiFreeOpCodeHandle (EndOpCodeHandle
);
1165 FreePool (HiiHandles
);
1167 for (Index
= 0; Index
< HandleNum
; Index
++) {
1168 if (GuidLists
[Index
] != NULL
) {
1169 FreePool (GuidLists
[Index
]);
1172 FreePool (GuidLists
);
1178 This function is invoked if user selected a interactive opcode from Driver Health's
1179 Formset. The decision by user is saved to gCallbackKey for later processing.
1181 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1182 @param Action Specifies the type of action taken by the browser.
1183 @param QuestionId A unique value which is sent to the original exporting driver
1184 so that it can identify the type of data to expect.
1185 @param Type The type of value for the question.
1186 @param Value A pointer to the data being sent to the original exporting driver.
1187 @param ActionRequest On return, points to the action requested by the callback function.
1189 @retval EFI_SUCCESS The callback successfully handled the action.
1190 @retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.
1195 DriverHealthCallback (
1196 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1197 IN EFI_BROWSER_ACTION Action
,
1198 IN EFI_QUESTION_ID QuestionId
,
1200 IN EFI_IFR_TYPE_VALUE
*Value
,
1201 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
1204 if (Action
== EFI_BROWSER_ACTION_CHANGED
) {
1205 if ((Value
== NULL
) || (ActionRequest
== NULL
)) {
1206 return EFI_INVALID_PARAMETER
;
1209 gCallbackKey
= QuestionId
;
1212 // Request to exit SendForm(), so as to switch to selected form
1214 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
1220 // All other action return unsupported.
1222 return EFI_UNSUPPORTED
;
1226 Collect and display the platform's driver health relative information, allow user to do interactive
1227 operation while the platform is unhealthy.
1229 This function display a form which divided into two parts. The one list all modules which has installed
1230 driver health protocol. The list usually contain driver name, controller name, and it's health info.
1231 While the driver name can't be retrieved, will use device path as backup. The other part of the form provide
1232 a choice to the user to repair all platform.
1241 EFI_HII_HANDLE HiiHandle
;
1242 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
1243 EFI_IFR_GUID_LABEL
*StartLabel
;
1244 EFI_IFR_GUID_LABEL
*StartLabelRepair
;
1245 EFI_IFR_GUID_LABEL
*EndLabel
;
1246 EFI_IFR_GUID_LABEL
*EndLabelRepair
;
1247 VOID
*StartOpCodeHandle
;
1248 VOID
*EndOpCodeHandle
;
1249 VOID
*StartOpCodeHandleRepair
;
1250 VOID
*EndOpCodeHandleRepair
;
1252 EFI_STRING_ID Token
;
1253 EFI_STRING_ID TokenHelp
;
1255 EFI_STRING TmpString
;
1256 EFI_STRING DriverName
;
1257 EFI_STRING ControllerName
;
1258 LIST_ENTRY DriverHealthList
;
1259 DRIVER_HEALTH_INFO
*DriverHealthInfo
;
1261 EFI_DEVICE_PATH_PROTOCOL
*DriverDevicePath
;
1262 BOOLEAN RebootRequired
;
1266 DriverHealthInfo
= NULL
;
1267 DriverDevicePath
= NULL
;
1268 InitializeListHead (&DriverHealthList
);
1270 HiiHandle
= gDeviceManagerPrivate
.DriverHealthHiiHandle
;
1271 if (HiiHandle
== NULL
) {
1273 // Publish Driver Health HII data.
1275 HiiHandle
= HiiAddPackages (
1276 &gDeviceManagerFormSetGuid
,
1277 gDeviceManagerPrivate
.DriverHealthHandle
,
1282 if (HiiHandle
== NULL
) {
1286 gDeviceManagerPrivate
.DriverHealthHiiHandle
= HiiHandle
;
1290 // Allocate space for creation of UpdateData Buffer
1292 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
1293 ASSERT (StartOpCodeHandle
!= NULL
);
1295 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
1296 ASSERT (EndOpCodeHandle
!= NULL
);
1298 StartOpCodeHandleRepair
= HiiAllocateOpCodeHandle ();
1299 ASSERT (StartOpCodeHandleRepair
!= NULL
);
1301 EndOpCodeHandleRepair
= HiiAllocateOpCodeHandle ();
1302 ASSERT (EndOpCodeHandleRepair
!= NULL
);
1305 // Create Hii Extend Label OpCode as the start opcode
1307 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
1308 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
1309 StartLabel
->Number
= LABEL_DRIVER_HEALTH
;
1312 // Create Hii Extend Label OpCode as the start opcode
1314 StartLabelRepair
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandleRepair
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
1315 StartLabelRepair
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
1316 StartLabelRepair
->Number
= LABEL_DRIVER_HEALTH_REAPIR_ALL
;
1319 // Create Hii Extend Label OpCode as the end opcode
1321 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
1322 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
1323 EndLabel
->Number
= LABEL_DRIVER_HEALTH_END
;
1326 // Create Hii Extend Label OpCode as the end opcode
1328 EndLabelRepair
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandleRepair
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
1329 EndLabelRepair
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
1330 EndLabelRepair
->Number
= LABEL_DRIVER_HEALTH_REAPIR_ALL_END
;
1332 HiiCreateSubTitleOpCode (StartOpCodeHandle
, STRING_TOKEN (STR_DH_STATUS_LIST
), 0, 0, 1);
1334 Status
= GetAllControllersHealthStatus (&DriverHealthList
);
1335 ASSERT (Status
!= EFI_OUT_OF_RESOURCES
);
1337 Link
= GetFirstNode (&DriverHealthList
);
1339 while (!IsNull (&DriverHealthList
, Link
)) {
1340 DriverHealthInfo
= DEVICE_MANAGER_HEALTH_INFO_FROM_LINK (Link
);
1343 // Assume no line strings is longer than 512 bytes.
1346 String
= (EFI_STRING
) AllocateZeroPool (StringSize
);
1347 ASSERT (String
!= NULL
);
1349 Status
= DriverHealthGetDriverName (DriverHealthInfo
->DriverHandle
, &DriverName
);
1350 if (EFI_ERROR (Status
)) {
1352 // Can not get the Driver name, so use the Device path
1354 DriverDevicePath
= DevicePathFromHandle (DriverHealthInfo
->DriverHandle
);
1355 DriverName
= DevicePathToStr (DriverDevicePath
);
1358 // Add the Driver name & Controller name into FormSetTitle string
1360 StrnCat (String
, DriverName
, StrLen (DriverName
));
1363 Status
= DriverHealthGetControllerName (
1364 DriverHealthInfo
->DriverHandle
,
1365 DriverHealthInfo
->ControllerHandle
,
1366 DriverHealthInfo
->ChildHandle
,
1370 if (!EFI_ERROR (Status
)) {
1372 // Can not get the Controller name, just let it empty.
1374 StrnCat (String
, L
" ", StrLen (L
" "));
1375 StrnCat (String
, ControllerName
, StrLen (ControllerName
));
1379 // Add the message of the Module itself provided after the string item.
1381 if ((DriverHealthInfo
->MessageList
!= NULL
) && (DriverHealthInfo
->MessageList
->StringId
!= 0)) {
1382 StrnCat (String
, L
" ", StrLen (L
" "));
1383 TmpString
= HiiGetString (
1384 DriverHealthInfo
->MessageList
->HiiHandle
,
1385 DriverHealthInfo
->MessageList
->StringId
,
1390 // Update the string will be displayed base on the driver's health status
1392 switch(DriverHealthInfo
->HealthStatus
) {
1393 case EfiDriverHealthStatusRepairRequired
:
1394 TmpString
= GetStringById (STRING_TOKEN (STR_REPAIR_REQUIRED
));
1396 case EfiDriverHealthStatusConfigurationRequired
:
1397 TmpString
= GetStringById (STRING_TOKEN (STR_CONFIGURATION_REQUIRED
));
1399 case EfiDriverHealthStatusFailed
:
1400 TmpString
= GetStringById (STRING_TOKEN (STR_OPERATION_FAILED
));
1402 case EfiDriverHealthStatusReconnectRequired
:
1403 TmpString
= GetStringById (STRING_TOKEN (STR_RECONNECT_REQUIRED
));
1405 case EfiDriverHealthStatusRebootRequired
:
1406 TmpString
= GetStringById (STRING_TOKEN (STR_REBOOT_REQUIRED
));
1409 TmpString
= GetStringById (STRING_TOKEN (STR_DRIVER_HEALTH_HEALTHY
));
1414 ASSERT (TmpString
!= NULL
);
1415 StrnCat (String
, TmpString
, StringSize
/ sizeof (CHAR16
) - StrLen (String
) - 1);
1416 FreePool (TmpString
);
1418 Token
= HiiSetString (HiiHandle
, 0, String
, NULL
);
1421 TokenHelp
= HiiSetString (HiiHandle
, 0, GetStringById( STRING_TOKEN (STR_DH_REPAIR_SINGLE_HELP
)), NULL
);
1423 HiiCreateActionOpCode (
1425 (EFI_QUESTION_ID
) (Index
+ DRIVER_HEALTH_KEY_OFFSET
),
1428 EFI_IFR_FLAG_CALLBACK
,
1432 Link
= GetNextNode (&DriverHealthList
, Link
);
1436 // Add End Opcode for Subtitle
1438 HiiCreateEndOpCode (StartOpCodeHandle
);
1440 HiiCreateSubTitleOpCode (StartOpCodeHandleRepair
, STRING_TOKEN (STR_DRIVER_HEALTH_REPAIR_ALL
), 0, 0, 1);
1441 TokenHelp
= HiiSetString (HiiHandle
, 0, GetStringById( STRING_TOKEN (STR_DH_REPAIR_ALL_HELP
)), NULL
);
1443 if (PlaformHealthStatusCheck ()) {
1445 // No action need to do for the platform
1447 Token
= HiiSetString (HiiHandle
, 0, GetStringById( STRING_TOKEN (STR_DRIVER_HEALTH_ALL_HEALTHY
)), NULL
);
1448 HiiCreateActionOpCode (
1449 StartOpCodeHandleRepair
,
1453 EFI_IFR_FLAG_READ_ONLY
,
1458 // Create ActionOpCode only while the platform need to do health related operation.
1460 Token
= HiiSetString (HiiHandle
, 0, GetStringById( STRING_TOKEN (STR_DH_REPAIR_ALL_TITLE
)), NULL
);
1461 HiiCreateActionOpCode (
1462 StartOpCodeHandleRepair
,
1463 (EFI_QUESTION_ID
) DRIVER_HEALTH_REPAIR_ALL_KEY
,
1466 EFI_IFR_FLAG_CALLBACK
,
1471 HiiCreateEndOpCode (StartOpCodeHandleRepair
);
1473 Status
= HiiUpdateForm (
1475 &gDriverHealthFormSetGuid
,
1476 DRIVER_HEALTH_FORM_ID
,
1480 ASSERT (Status
!= EFI_NOT_FOUND
);
1481 ASSERT (Status
!= EFI_BUFFER_TOO_SMALL
);
1483 Status
= HiiUpdateForm (
1485 &gDriverHealthFormSetGuid
,
1486 DRIVER_HEALTH_FORM_ID
,
1487 StartOpCodeHandleRepair
,
1488 EndOpCodeHandleRepair
1490 ASSERT (Status
!= EFI_NOT_FOUND
);
1491 ASSERT (Status
!= EFI_BUFFER_TOO_SMALL
);
1493 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
1494 Status
= gFormBrowser2
->SendForm (
1498 &gDriverHealthFormSetGuid
,
1499 DRIVER_HEALTH_FORM_ID
,
1503 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
1504 EnableResetRequired ();
1508 // We will have returned from processing a callback - user either hit ESC to exit, or selected
1509 // a target to display.
1510 // Process the diver health status states here.
1512 if (gCallbackKey
>= DRIVER_HEALTH_KEY_OFFSET
&& gCallbackKey
!= DRIVER_HEALTH_REPAIR_ALL_KEY
) {
1513 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
1515 Link
= GetFirstNode (&DriverHealthList
);
1518 while (!IsNull (&DriverHealthList
, Link
)) {
1520 // Got the item relative node in the List
1522 if (Index
== (gCallbackKey
- DRIVER_HEALTH_KEY_OFFSET
)) {
1523 DriverHealthInfo
= DEVICE_MANAGER_HEALTH_INFO_FROM_LINK (Link
);
1525 // Process the driver's healthy status for the specify module
1527 RebootRequired
= FALSE
;
1528 ProcessSingleControllerHealth (
1529 DriverHealthInfo
->DriverHealth
,
1530 DriverHealthInfo
->ControllerHandle
,
1531 DriverHealthInfo
->ChildHandle
,
1532 DriverHealthInfo
->HealthStatus
,
1533 &(DriverHealthInfo
->MessageList
),
1534 DriverHealthInfo
->HiiHandle
,
1537 if (RebootRequired
) {
1538 gRT
->ResetSystem (EfiResetWarm
, EFI_SUCCESS
, 0, NULL
);
1543 Link
= GetNextNode (&DriverHealthList
, Link
);
1546 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
1547 EnableResetRequired ();
1551 // Force return to the form of Driver Health in Device Manager
1553 gCallbackKey
= DRIVER_HEALTH_RETURN_KEY
;
1557 // Repair the whole platform
1559 if (gCallbackKey
== DRIVER_HEALTH_REPAIR_ALL_KEY
) {
1560 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
1562 PlatformRepairAll (&DriverHealthList
);
1564 gCallbackKey
= DRIVER_HEALTH_RETURN_KEY
;
1568 // Remove driver health packagelist from HII database.
1570 HiiRemovePackages (HiiHandle
);
1571 gDeviceManagerPrivate
.DriverHealthHiiHandle
= NULL
;
1574 // Free driver health info list
1576 while (!IsListEmpty (&DriverHealthList
)) {
1578 Link
= GetFirstNode(&DriverHealthList
);
1579 DriverHealthInfo
= DEVICE_MANAGER_HEALTH_INFO_FROM_LINK (Link
);
1580 RemoveEntryList (Link
);
1582 if (DriverHealthInfo
->MessageList
!= NULL
) {
1583 FreePool(DriverHealthInfo
->MessageList
);
1584 FreePool (DriverHealthInfo
);
1588 HiiFreeOpCodeHandle (StartOpCodeHandle
);
1589 HiiFreeOpCodeHandle (EndOpCodeHandle
);
1590 HiiFreeOpCodeHandle (StartOpCodeHandleRepair
);
1591 HiiFreeOpCodeHandle (EndOpCodeHandleRepair
);
1593 if (gCallbackKey
== DRIVER_HEALTH_RETURN_KEY
) {
1595 // Force return to Driver Health Form
1597 gCallbackKey
= DEVICE_MANAGER_KEY_DRIVER_HEALTH
;
1598 CallDriverHealth ();
1604 Check the Driver Health status of a single controller and try to process it if not healthy.
1606 This function called by CheckAllControllersHealthStatus () function in order to process a specify
1607 contoller's health state.
1609 @param DriverHealthList A Pointer to the list contain all of the platform driver health information.
1610 @param DriverHandle The handle of driver.
1611 @param ControllerHandle The class guid specifies which form set will be displayed.
1612 @param ChildHandle The handle of the child controller to retrieve the health
1613 status on. This is an optional parameter that may be NULL.
1614 @param DriverHealth A pointer to the EFI_DRIVER_HEALTH_PROTOCOL instance.
1615 @param HealthStatus The health status of the controller.
1617 @retval EFI_INVALID_PARAMETER HealthStatus or DriverHealth is NULL.
1618 @retval HealthStatus The Health status of specify controller.
1619 @retval EFI_OUT_OF_RESOURCES The list of Driver Health Protocol handles can not be retrieved.
1620 @retval EFI_NOT_FOUND No controller in the platform install Driver Health Protocol.
1621 @retval EFI_SUCCESS The Health related operation has been taken successfully.
1626 GetSingleControllerHealthStatus (
1627 IN OUT LIST_ENTRY
*DriverHealthList
,
1628 IN EFI_HANDLE DriverHandle
,
1629 IN EFI_HANDLE ControllerHandle
, OPTIONAL
1630 IN EFI_HANDLE ChildHandle
, OPTIONAL
1631 IN EFI_DRIVER_HEALTH_PROTOCOL
*DriverHealth
,
1632 IN EFI_DRIVER_HEALTH_STATUS
*HealthStatus
1636 EFI_DRIVER_HEALTH_HII_MESSAGE
*MessageList
;
1637 EFI_HII_HANDLE FormHiiHandle
;
1638 DRIVER_HEALTH_INFO
*DriverHealthInfo
;
1640 if (HealthStatus
== NULL
) {
1642 // If HealthStatus is NULL, then return EFI_INVALID_PARAMETER
1644 return EFI_INVALID_PARAMETER
;
1648 // Assume the HealthStatus is healthy
1650 *HealthStatus
= EfiDriverHealthStatusHealthy
;
1652 if (DriverHealth
== NULL
) {
1654 // If DriverHealth is NULL, then return EFI_INVALID_PARAMETER
1656 return EFI_INVALID_PARAMETER
;
1659 if (ControllerHandle
== NULL
) {
1661 // If ControllerHandle is NULL, the return the cumulative health status of the driver
1663 Status
= DriverHealth
->GetHealthStatus (DriverHealth
, NULL
, NULL
, HealthStatus
, NULL
, NULL
);
1664 if (*HealthStatus
== EfiDriverHealthStatusHealthy
) {
1666 // Add the driver health related information into the list
1668 DriverHealthInfo
= AllocateZeroPool (sizeof (DRIVER_HEALTH_INFO
));
1669 if (DriverHealthInfo
== NULL
) {
1670 return EFI_OUT_OF_RESOURCES
;
1673 DriverHealthInfo
->Signature
= DEVICE_MANAGER_DRIVER_HEALTH_INFO_SIGNATURE
;
1674 DriverHealthInfo
->DriverHandle
= DriverHandle
;
1675 DriverHealthInfo
->ControllerHandle
= NULL
;
1676 DriverHealthInfo
->ChildHandle
= NULL
;
1677 DriverHealthInfo
->HiiHandle
= NULL
;
1678 DriverHealthInfo
->DriverHealth
= DriverHealth
;
1679 DriverHealthInfo
->MessageList
= NULL
;
1680 DriverHealthInfo
->HealthStatus
= *HealthStatus
;
1682 InsertTailList (DriverHealthList
, &DriverHealthInfo
->Link
);
1688 FormHiiHandle
= NULL
;
1691 // Collect the health status with the optional HII message list
1693 Status
= DriverHealth
->GetHealthStatus (DriverHealth
, ControllerHandle
, ChildHandle
, HealthStatus
, &MessageList
, &FormHiiHandle
);
1695 if (EFI_ERROR (Status
)) {
1697 // If the health status could not be retrieved, then return immediately
1703 // Add the driver health related information into the list
1705 DriverHealthInfo
= AllocateZeroPool (sizeof (DRIVER_HEALTH_INFO
));
1706 if (DriverHealthInfo
== NULL
) {
1707 return EFI_OUT_OF_RESOURCES
;
1710 DriverHealthInfo
->Signature
= DEVICE_MANAGER_DRIVER_HEALTH_INFO_SIGNATURE
;
1711 DriverHealthInfo
->DriverHandle
= DriverHandle
;
1712 DriverHealthInfo
->ControllerHandle
= ControllerHandle
;
1713 DriverHealthInfo
->ChildHandle
= ChildHandle
;
1714 DriverHealthInfo
->HiiHandle
= FormHiiHandle
;
1715 DriverHealthInfo
->DriverHealth
= DriverHealth
;
1716 DriverHealthInfo
->MessageList
= MessageList
;
1717 DriverHealthInfo
->HealthStatus
= *HealthStatus
;
1719 InsertTailList (DriverHealthList
, &DriverHealthInfo
->Link
);
1725 Collects all the EFI Driver Health Protocols currently present in the EFI Handle Database,
1726 and queries each EFI Driver Health Protocol to determine if one or more of the controllers
1727 managed by each EFI Driver Health Protocol instance are not healthy.
1729 @param DriverHealthList A Pointer to the list contain all of the platform driver health
1732 @retval EFI_NOT_FOUND No controller in the platform install Driver Health Protocol.
1733 @retval EFI_SUCCESS All the controllers in the platform are healthy.
1734 @retval EFI_OUT_OF_RESOURCES The list of Driver Health Protocol handles can not be retrieved.
1738 GetAllControllersHealthStatus (
1739 IN OUT LIST_ENTRY
*DriverHealthList
1744 EFI_HANDLE
*DriverHealthHandles
;
1745 EFI_DRIVER_HEALTH_PROTOCOL
*DriverHealth
;
1746 EFI_DRIVER_HEALTH_STATUS HealthStatus
;
1747 UINTN DriverHealthIndex
;
1748 EFI_HANDLE
*Handles
;
1750 UINTN ControllerIndex
;
1754 // Initialize local variables
1757 DriverHealthHandles
= NULL
;
1761 HealthStatus
= EfiDriverHealthStatusHealthy
;
1763 Status
= gBS
->LocateHandleBuffer (
1765 &gEfiDriverHealthProtocolGuid
,
1768 &DriverHealthHandles
1771 if (Status
== EFI_NOT_FOUND
|| NumHandles
== 0) {
1773 // If there are no Driver Health Protocols handles, then return EFI_NOT_FOUND
1775 return EFI_NOT_FOUND
;
1778 if (EFI_ERROR (Status
) || DriverHealthHandles
== NULL
) {
1780 // If the list of Driver Health Protocol handles can not be retrieved, then
1781 // return EFI_OUT_OF_RESOURCES
1783 return EFI_OUT_OF_RESOURCES
;
1787 // Check the health status of all controllers in the platform
1788 // Start by looping through all the Driver Health Protocol handles in the handle database
1790 for (DriverHealthIndex
= 0; DriverHealthIndex
< NumHandles
; DriverHealthIndex
++) {
1792 // Skip NULL Driver Health Protocol handles
1794 if (DriverHealthHandles
[DriverHealthIndex
] == NULL
) {
1799 // Retrieve the Driver Health Protocol from DriverHandle
1801 Status
= gBS
->HandleProtocol (
1802 DriverHealthHandles
[DriverHealthIndex
],
1803 &gEfiDriverHealthProtocolGuid
,
1804 (VOID
**)&DriverHealth
1806 if (EFI_ERROR (Status
)) {
1808 // If the Driver Health Protocol can not be retrieved, then skip to the next
1809 // Driver Health Protocol handle
1815 // Check the health of all the controllers managed by a Driver Health Protocol handle
1817 Status
= GetSingleControllerHealthStatus (DriverHealthList
, DriverHealthHandles
[DriverHealthIndex
], NULL
, NULL
, DriverHealth
, &HealthStatus
);
1820 // If Status is an error code, then the health information could not be retrieved, so assume healthy
1821 // and skip to the next Driver Health Protocol handle
1823 if (EFI_ERROR (Status
)) {
1828 // If all the controllers managed by this Driver Health Protocol are healthy, then skip to the next
1829 // Driver Health Protocol handle
1831 if (HealthStatus
== EfiDriverHealthStatusHealthy
) {
1836 // See if the list of all handles in the handle database has been retrieved
1839 if (Handles
== NULL
) {
1841 // Retrieve the list of all handles from the handle database
1843 Status
= gBS
->LocateHandleBuffer (
1850 if (EFI_ERROR (Status
) || Handles
== NULL
) {
1852 // If all the handles in the handle database can not be retrieved, then
1853 // return EFI_OUT_OF_RESOURCES
1855 Status
= EFI_OUT_OF_RESOURCES
;
1860 // Loop through all the controller handles in the handle database
1862 for (ControllerIndex
= 0; ControllerIndex
< HandleCount
; ControllerIndex
++) {
1864 // Skip NULL controller handles
1866 if (Handles
[ControllerIndex
] == NULL
) {
1870 Status
= GetSingleControllerHealthStatus (DriverHealthList
, DriverHealthHandles
[DriverHealthIndex
], Handles
[ControllerIndex
], NULL
, DriverHealth
, &HealthStatus
);
1871 if (EFI_ERROR (Status
)) {
1873 // If Status is an error code, then the health information could not be retrieved, so assume healthy
1875 HealthStatus
= EfiDriverHealthStatusHealthy
;
1879 // If CheckHealthSingleController() returned an error on a terminal state, then do not check the health of child controllers
1881 if (EFI_ERROR (Status
)) {
1886 // Loop through all the child handles in the handle database
1888 for (ChildIndex
= 0; ChildIndex
< HandleCount
; ChildIndex
++) {
1890 // Skip NULL child handles
1892 if (Handles
[ChildIndex
] == NULL
) {
1896 Status
= GetSingleControllerHealthStatus (DriverHealthList
, DriverHealthHandles
[DriverHealthIndex
], Handles
[ControllerIndex
], Handles
[ChildIndex
], DriverHealth
, &HealthStatus
);
1897 if (EFI_ERROR (Status
)) {
1899 // If Status is an error code, then the health information could not be retrieved, so assume healthy
1901 HealthStatus
= EfiDriverHealthStatusHealthy
;
1905 // If CheckHealthSingleController() returned an error on a terminal state, then skip to the next child
1907 if (EFI_ERROR (Status
)) {
1914 Status
= EFI_SUCCESS
;
1917 if (Handles
!= NULL
) {
1918 gBS
->FreePool (Handles
);
1920 if (DriverHealthHandles
!= NULL
) {
1921 gBS
->FreePool (DriverHealthHandles
);
1929 Check the healthy status of the platform, this function will return immediately while found one driver
1930 in the platform are not healthy.
1932 @retval FALSE at least one driver in the platform are not healthy.
1933 @retval TRUE No controller install Driver Health Protocol,
1934 or all controllers in the platform are in healthy status.
1937 PlaformHealthStatusCheck (
1941 EFI_DRIVER_HEALTH_STATUS HealthStatus
;
1945 EFI_HANDLE
*DriverHealthHandles
;
1946 EFI_DRIVER_HEALTH_PROTOCOL
*DriverHealth
;
1950 // Initialize local variables
1952 DriverHealthHandles
= NULL
;
1953 DriverHealth
= NULL
;
1955 HealthStatus
= EfiDriverHealthStatusHealthy
;
1957 Status
= gBS
->LocateHandleBuffer (
1959 &gEfiDriverHealthProtocolGuid
,
1962 &DriverHealthHandles
1965 // There are no handles match the search for Driver Health Protocol has been installed.
1967 if (Status
== EFI_NOT_FOUND
) {
1971 // Assume all modules are healthy.
1976 // Found one or more Handles.
1978 if (!EFI_ERROR (Status
)) {
1979 for (Index
= 0; Index
< NoHandles
; Index
++) {
1980 Status
= gBS
->HandleProtocol (
1981 DriverHealthHandles
[Index
],
1982 &gEfiDriverHealthProtocolGuid
,
1983 (VOID
**) &DriverHealth
1985 if (!EFI_ERROR (Status
)) {
1986 Status
= DriverHealth
->GetHealthStatus (
1996 // Get the healthy status of the module
1998 if (!EFI_ERROR (Status
)) {
1999 if (HealthStatus
!= EfiDriverHealthStatusHealthy
) {
2001 // Return immediately one driver's status not in healthy.
2012 Processes a single controller using the EFI Driver Health Protocol associated with
2013 that controller. This algorithm continues to query the GetHealthStatus() service until
2014 one of the legal terminal states of the EFI Driver Health Protocol is reached. This may
2015 require the processing of HII Messages, HII Form, and invocation of repair operations.
2017 @param DriverHealth A pointer to the EFI_DRIVER_HEALTH_PROTOCOL instance.
2018 @param ControllerHandle The class guid specifies which form set will be displayed.
2019 @param ChildHandle The handle of the child controller to retrieve the health
2020 status on. This is an optional parameter that may be NULL.
2021 @param HealthStatus The health status of the controller.
2022 @param MessageList An array of warning or error messages associated
2023 with the controller specified by ControllerHandle and
2024 ChildHandle. This is an optional parameter that may be NULL.
2025 @param FormHiiHandle The HII handle for an HII form associated with the
2026 controller specified by ControllerHandle and ChildHandle.
2027 @param RebootRequired Indicate whether a reboot is required to repair the controller.
2030 ProcessSingleControllerHealth (
2031 IN EFI_DRIVER_HEALTH_PROTOCOL
*DriverHealth
,
2032 IN EFI_HANDLE ControllerHandle
, OPTIONAL
2033 IN EFI_HANDLE ChildHandle
, OPTIONAL
2034 IN EFI_DRIVER_HEALTH_STATUS HealthStatus
,
2035 IN EFI_DRIVER_HEALTH_HII_MESSAGE
**MessageList
, OPTIONAL
2036 IN EFI_HII_HANDLE FormHiiHandle
,
2037 IN OUT BOOLEAN
*RebootRequired
2041 EFI_DRIVER_HEALTH_STATUS LocalHealthStatus
;
2043 LocalHealthStatus
= HealthStatus
;
2045 // If the module need to be repaired or reconfiguration, will process it until
2046 // reach a terminal status. The status from EfiDriverHealthStatusRepairRequired after repair
2047 // will be in (Health, Failed, Configuration Required).
2049 while(LocalHealthStatus
== EfiDriverHealthStatusConfigurationRequired
||
2050 LocalHealthStatus
== EfiDriverHealthStatusRepairRequired
) {
2052 if (LocalHealthStatus
== EfiDriverHealthStatusRepairRequired
) {
2053 Status
= DriverHealth
->Repair (
2061 // Via a form of the driver need to do configuration provided to process of status in
2062 // EfiDriverHealthStatusConfigurationRequired. The status after configuration should be in
2063 // (Healthy, Reboot Required, Failed, Reconnect Required, Repair Required).
2065 if (LocalHealthStatus
== EfiDriverHealthStatusConfigurationRequired
) {
2066 if (FormHiiHandle
!= NULL
) {
2067 Status
= gFormBrowser2
->SendForm (
2071 &gEfiHiiDriverHealthFormsetGuid
,
2076 ASSERT( !EFI_ERROR (Status
));
2079 // Exit the loop in case no FormHiiHandle is supplied to prevent dead-loop
2085 Status
= DriverHealth
->GetHealthStatus (
2093 ASSERT_EFI_ERROR (Status
);
2095 if (*MessageList
!= NULL
) {
2096 ProcessMessages (*MessageList
);
2101 // Health status in {Healthy, Failed} may also have Messages need to process
2103 if (LocalHealthStatus
== EfiDriverHealthStatusHealthy
|| LocalHealthStatus
== EfiDriverHealthStatusFailed
) {
2104 if (*MessageList
!= NULL
) {
2105 ProcessMessages (*MessageList
);
2109 // Check for RebootRequired or ReconnectRequired
2111 if (LocalHealthStatus
== EfiDriverHealthStatusRebootRequired
) {
2112 *RebootRequired
= TRUE
;
2116 // Do reconnect if need.
2118 if (LocalHealthStatus
== EfiDriverHealthStatusReconnectRequired
) {
2119 Status
= gBS
->DisconnectController (ControllerHandle
, NULL
, NULL
);
2120 if (EFI_ERROR (Status
)) {
2122 // Disconnect failed. Need to promote reconnect to a reboot.
2124 *RebootRequired
= TRUE
;
2126 gBS
->ConnectController (ControllerHandle
, NULL
, NULL
, TRUE
);
2133 Reports the progress of a repair operation.
2135 @param[in] Value A value between 0 and Limit that identifies the current
2136 progress of the repair operation.
2138 @param[in] Limit The maximum value of Value for the current repair operation.
2139 For example, a driver that wants to specify progress in
2140 percent would use a Limit value of 100.
2142 @retval EFI_SUCCESS The progress of a repair operation is reported successfully.
2155 Print(L
"Repair Progress Undefined\n\r");
2157 Percent
= Value
* 100 / Limit
;
2158 Print(L
"Repair Progress = %3d%%\n\r", Percent
);
2164 Processes a set of messages returned by the GetHealthStatus ()
2165 service of the EFI Driver Health Protocol
2167 @param MessageList The MessageList point to messages need to processed.
2172 IN EFI_DRIVER_HEALTH_HII_MESSAGE
*MessageList
2176 EFI_STRING MessageString
;
2178 for (MessageIndex
= 0;
2179 MessageList
[MessageIndex
].HiiHandle
!= NULL
;
2182 MessageString
= HiiGetString (
2183 MessageList
[MessageIndex
].HiiHandle
,
2184 MessageList
[MessageIndex
].StringId
,
2187 if (MessageString
!= NULL
) {
2189 // User can customize the output. Just simply print out the MessageString like below.
2190 // Also can use the HiiHandle to display message on the front page.
2192 // Print(L"%s\n",MessageString);
2193 // gBS->Stall (100000);
2200 Repair the whole platform.
2202 This function is the main entry for user choose "Repair All" in the front page.
2203 It will try to do recovery job till all the driver health protocol installed modules
2204 reach a terminal state.
2206 @param DriverHealthList A Pointer to the list contain all of the platform driver health
2212 IN LIST_ENTRY
*DriverHealthList
2215 DRIVER_HEALTH_INFO
*DriverHealthInfo
;
2217 BOOLEAN RebootRequired
;
2219 ASSERT (DriverHealthList
!= NULL
);
2221 RebootRequired
= FALSE
;
2223 for ( Link
= GetFirstNode (DriverHealthList
)
2224 ; !IsNull (DriverHealthList
, Link
)
2225 ; Link
= GetNextNode (DriverHealthList
, Link
)
2227 DriverHealthInfo
= DEVICE_MANAGER_HEALTH_INFO_FROM_LINK (Link
);
2229 // Do driver health status operation by each link node
2231 ASSERT (DriverHealthInfo
!= NULL
);
2233 ProcessSingleControllerHealth (
2234 DriverHealthInfo
->DriverHealth
,
2235 DriverHealthInfo
->ControllerHandle
,
2236 DriverHealthInfo
->ChildHandle
,
2237 DriverHealthInfo
->HealthStatus
,
2238 &(DriverHealthInfo
->MessageList
),
2239 DriverHealthInfo
->HiiHandle
,
2244 if (RebootRequired
) {
2245 gRT
->ResetSystem (EfiResetWarm
, EFI_SUCCESS
, 0, NULL
);
2251 Select the best matching language according to front page policy for best user experience.
2253 This function supports both ISO 639-2 and RFC 4646 language codes, but language
2254 code types may not be mixed in a single call to this function.
2256 @param SupportedLanguages A pointer to a Null-terminated ASCII string that
2257 contains a set of language codes in the format
2258 specified by Iso639Language.
2259 @param Iso639Language If TRUE, then all language codes are assumed to be
2260 in ISO 639-2 format. If FALSE, then all language
2261 codes are assumed to be in RFC 4646 language format.
2263 @retval NULL The best matching language could not be found in SupportedLanguages.
2264 @retval NULL There are not enough resources available to return the best matching
2266 @retval Other A pointer to a Null-terminated ASCII string that is the best matching
2267 language in SupportedLanguages.
2270 DriverHealthSelectBestLanguage (
2271 IN CHAR8
*SupportedLanguages
,
2272 IN BOOLEAN Iso639Language
2275 CHAR8
*LanguageVariable
;
2276 CHAR8
*BestLanguage
;
2278 GetEfiGlobalVariable2 (Iso639Language
? L
"Lang" : L
"PlatformLang", (VOID
**)&LanguageVariable
, NULL
);
2280 BestLanguage
= GetBestLanguage(
2283 (LanguageVariable
!= NULL
) ? LanguageVariable
: "",
2284 Iso639Language
? "eng" : "en-US",
2287 if (LanguageVariable
!= NULL
) {
2288 FreePool (LanguageVariable
);
2291 return BestLanguage
;
2298 This is an internal worker function to get the Component Name (2) protocol interface
2299 and the language it supports.
2301 @param ProtocolGuid A pointer to an EFI_GUID. It points to Component Name (2) protocol GUID.
2302 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
2303 @param ComponentName A pointer to the Component Name (2) protocol interface.
2304 @param SupportedLanguage The best suitable language that matches the SupportedLangues interface for the
2305 located Component Name (2) instance.
2307 @retval EFI_SUCCESS The Component Name (2) protocol instance is successfully located and we find
2308 the best matching language it support.
2309 @retval EFI_UNSUPPORTED The input Language is not supported by the Component Name (2) protocol.
2310 @retval Other Some error occurs when locating Component Name (2) protocol instance or finding
2311 the supported language.
2315 GetComponentNameWorker (
2316 IN EFI_GUID
*ProtocolGuid
,
2317 IN EFI_HANDLE DriverBindingHandle
,
2318 OUT EFI_COMPONENT_NAME_PROTOCOL
**ComponentName
,
2319 OUT CHAR8
**SupportedLanguage
2325 // Locate Component Name (2) protocol on the driver binging handle.
2327 Status
= gBS
->OpenProtocol (
2328 DriverBindingHandle
,
2330 (VOID
**) ComponentName
,
2333 EFI_OPEN_PROTOCOL_GET_PROTOCOL
2335 if (EFI_ERROR (Status
)) {
2340 // Apply shell policy to select the best language.
2342 *SupportedLanguage
= DriverHealthSelectBestLanguage (
2343 (*ComponentName
)->SupportedLanguages
,
2344 (BOOLEAN
) (ProtocolGuid
== &gEfiComponentNameProtocolGuid
)
2346 if (*SupportedLanguage
== NULL
) {
2347 Status
= EFI_UNSUPPORTED
;
2355 This is an internal worker function to get driver name from Component Name (2) protocol interface.
2358 @param ProtocolGuid A pointer to an EFI_GUID. It points to Component Name (2) protocol GUID.
2359 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
2360 @param DriverName A pointer to the Unicode string to return. This Unicode string is the name
2361 of the driver specified by This.
2363 @retval EFI_SUCCESS The driver name is successfully retrieved from Component Name (2) protocol
2365 @retval Other The driver name cannot be retrieved from Component Name (2) protocol
2370 GetDriverNameWorker (
2371 IN EFI_GUID
*ProtocolGuid
,
2372 IN EFI_HANDLE DriverBindingHandle
,
2373 OUT CHAR16
**DriverName
2377 CHAR8
*BestLanguage
;
2378 EFI_COMPONENT_NAME_PROTOCOL
*ComponentName
;
2381 // Retrieve Component Name (2) protocol instance on the driver binding handle and
2382 // find the best language this instance supports.
2384 Status
= GetComponentNameWorker (
2386 DriverBindingHandle
,
2390 if (EFI_ERROR (Status
)) {
2395 // Get the driver name from Component Name (2) protocol instance on the driver binging handle.
2397 Status
= ComponentName
->GetDriverName (
2402 FreePool (BestLanguage
);
2409 This function gets driver name from Component Name 2 protocol interface and Component Name protocol interface
2410 in turn. It first tries UEFI 2.0 Component Name 2 protocol interface and try to get the driver name.
2411 If the attempt fails, it then gets the driver name from EFI 1.1 Component Name protocol for backward
2412 compatibility support.
2414 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
2415 @param DriverName A pointer to the Unicode string to return. This Unicode string is the name
2416 of the driver specified by This.
2418 @retval EFI_SUCCESS The driver name is successfully retrieved from Component Name (2) protocol
2420 @retval Other The driver name cannot be retrieved from Component Name (2) protocol
2425 DriverHealthGetDriverName (
2426 IN EFI_HANDLE DriverBindingHandle
,
2427 OUT CHAR16
**DriverName
2433 // Get driver name from UEFI 2.0 Component Name 2 protocol interface.
2435 Status
= GetDriverNameWorker (&gEfiComponentName2ProtocolGuid
, DriverBindingHandle
, DriverName
);
2436 if (EFI_ERROR (Status
)) {
2438 // If it fails to get the driver name from Component Name protocol interface, we should fall back on
2439 // EFI 1.1 Component Name protocol interface.
2441 Status
= GetDriverNameWorker (&gEfiComponentNameProtocolGuid
, DriverBindingHandle
, DriverName
);
2450 This function gets controller name from Component Name 2 protocol interface and Component Name protocol interface
2451 in turn. It first tries UEFI 2.0 Component Name 2 protocol interface and try to get the controller name.
2452 If the attempt fails, it then gets the controller name from EFI 1.1 Component Name protocol for backward
2453 compatibility support.
2455 @param ProtocolGuid A pointer to an EFI_GUID. It points to Component Name (2) protocol GUID.
2456 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
2457 @param ControllerHandle The handle of a controller that the driver specified by This is managing.
2458 This handle specifies the controller whose name is to be returned.
2459 @param ChildHandle The handle of the child controller to retrieve the name of. This is an
2460 optional parameter that may be NULL. It will be NULL for device drivers.
2461 It will also be NULL for bus drivers that attempt to retrieve the name
2462 of the bus controller. It will not be NULL for a bus driver that attempts
2463 to retrieve the name of a child controller.
2464 @param ControllerName A pointer to the Unicode string to return. This Unicode string
2465 is the name of the controller specified by ControllerHandle and ChildHandle.
2467 @retval EFI_SUCCESS The controller name is successfully retrieved from Component Name (2) protocol
2469 @retval Other The controller name cannot be retrieved from Component Name (2) protocol.
2473 GetControllerNameWorker (
2474 IN EFI_GUID
*ProtocolGuid
,
2475 IN EFI_HANDLE DriverBindingHandle
,
2476 IN EFI_HANDLE ControllerHandle
,
2477 IN EFI_HANDLE ChildHandle
,
2478 OUT CHAR16
**ControllerName
2482 CHAR8
*BestLanguage
;
2483 EFI_COMPONENT_NAME_PROTOCOL
*ComponentName
;
2486 // Retrieve Component Name (2) protocol instance on the driver binding handle and
2487 // find the best language this instance supports.
2489 Status
= GetComponentNameWorker (
2491 DriverBindingHandle
,
2495 if (EFI_ERROR (Status
)) {
2500 // Get the controller name from Component Name (2) protocol instance on the driver binging handle.
2502 Status
= ComponentName
->GetControllerName (
2509 FreePool (BestLanguage
);
2516 This function gets controller name from Component Name 2 protocol interface and Component Name protocol interface
2517 in turn. It first tries UEFI 2.0 Component Name 2 protocol interface and try to get the controller name.
2518 If the attempt fails, it then gets the controller name from EFI 1.1 Component Name protocol for backward
2519 compatibility support.
2521 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
2522 @param ControllerHandle The handle of a controller that the driver specified by This is managing.
2523 This handle specifies the controller whose name is to be returned.
2524 @param ChildHandle The handle of the child controller to retrieve the name of. This is an
2525 optional parameter that may be NULL. It will be NULL for device drivers.
2526 It will also be NULL for bus drivers that attempt to retrieve the name
2527 of the bus controller. It will not be NULL for a bus driver that attempts
2528 to retrieve the name of a child controller.
2529 @param ControllerName A pointer to the Unicode string to return. This Unicode string
2530 is the name of the controller specified by ControllerHandle and ChildHandle.
2532 @retval EFI_SUCCESS The controller name is successfully retrieved from Component Name (2) protocol
2534 @retval Other The controller name cannot be retrieved from Component Name (2) protocol.
2538 DriverHealthGetControllerName (
2539 IN EFI_HANDLE DriverBindingHandle
,
2540 IN EFI_HANDLE ControllerHandle
,
2541 IN EFI_HANDLE ChildHandle
,
2542 OUT CHAR16
**ControllerName
2548 // Get controller name from UEFI 2.0 Component Name 2 protocol interface.
2550 Status
= GetControllerNameWorker (
2551 &gEfiComponentName2ProtocolGuid
,
2552 DriverBindingHandle
,
2557 if (EFI_ERROR (Status
)) {
2559 // If it fails to get the controller name from Component Name protocol interface, we should fall back on
2560 // EFI 1.1 Component Name protocol interface.
2562 Status
= GetControllerNameWorker (
2563 &gEfiComponentNameProtocolGuid
,
2564 DriverBindingHandle
,