2 The platform device manager reference implementation
4 Copyright (c) 2004 - 2010, 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
37 EFI_GUID mDeviceManagerGuid
= DEVICE_MANAGER_FORMSET_GUID
;
38 EFI_GUID mDriverHealthGuid
= DRIVER_HEALTH_FORMSET_GUID
;
41 // Which Mac Address string is select
42 // it will decide what menu need to show in the NETWORK_DEVICE_FORM_ID form.
44 EFI_STRING mSelectedMacAddrString
;
47 // Which form Id need to be show.
49 EFI_FORM_ID mNextShowFormId
= DEVICE_MANAGER_FORM_ID
;
52 // The Mac Address show in the NETWORK_DEVICE_LIST_FORM_ID
54 MAC_ADDRESS_NODE_LIST mMacDeviceList
;
56 DEVICE_MANAGER_MENU_ITEM mDeviceManagerMenuItemTable
[] = {
57 { STRING_TOKEN (STR_DISK_DEVICE
), EFI_DISK_DEVICE_CLASS
},
58 { STRING_TOKEN (STR_VIDEO_DEVICE
), EFI_VIDEO_DEVICE_CLASS
},
59 { STRING_TOKEN (STR_NETWORK_DEVICE
), EFI_NETWORK_DEVICE_CLASS
},
60 { STRING_TOKEN (STR_INPUT_DEVICE
), EFI_INPUT_DEVICE_CLASS
},
61 { STRING_TOKEN (STR_ON_BOARD_DEVICE
), EFI_ON_BOARD_DEVICE_CLASS
},
62 { STRING_TOKEN (STR_OTHER_DEVICE
), EFI_OTHER_DEVICE_CLASS
}
65 HII_VENDOR_DEVICE_PATH mDeviceManagerHiiVendorDevicePath
= {
71 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
72 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
76 // {102579A0-3686-466e-ACD8-80C087044F4A}
78 { 0x102579a0, 0x3686, 0x466e, { 0xac, 0xd8, 0x80, 0xc0, 0x87, 0x4, 0x4f, 0x4a } }
82 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
84 (UINT8
) (END_DEVICE_PATH_LENGTH
),
85 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
90 HII_VENDOR_DEVICE_PATH mDriverHealthHiiVendorDevicePath
= {
96 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
97 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
101 // {D8F76651-1675-4986-BED4-3824B2F1F4C8}
103 { 0xd8f76651, 0x1675, 0x4986, { 0xbe, 0xd4, 0x38, 0x24, 0xb2, 0xf1, 0xf4, 0xc8 } }
106 END_DEVICE_PATH_TYPE
,
107 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
109 (UINT8
) (END_DEVICE_PATH_LENGTH
),
110 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
116 This function is invoked if user selected a interactive opcode from Device Manager's
117 Formset. The decision by user is saved to gCallbackKey for later processing. If
118 user set VBIOS, the new value is saved to EFI variable.
120 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
121 @param Action Specifies the type of action taken by the browser.
122 @param QuestionId A unique value which is sent to the original exporting driver
123 so that it can identify the type of data to expect.
124 @param Type The type of value for the question.
125 @param Value A pointer to the data being sent to the original exporting driver.
126 @param ActionRequest On return, points to the action requested by the callback function.
128 @retval EFI_SUCCESS The callback successfully handled the action.
129 @retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.
134 DeviceManagerCallback (
135 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
136 IN EFI_BROWSER_ACTION Action
,
137 IN EFI_QUESTION_ID QuestionId
,
139 IN EFI_IFR_TYPE_VALUE
*Value
,
140 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
145 if ((Action
== EFI_BROWSER_ACTION_FORM_OPEN
) || (Action
== EFI_BROWSER_ACTION_FORM_CLOSE
)) {
147 // Do nothing for UEFI OPEN/CLOSE Action
152 if ((Value
== NULL
) || (ActionRequest
== NULL
)) {
153 return EFI_INVALID_PARAMETER
;
156 gCallbackKey
= QuestionId
;
158 if ((QuestionId
< MAX_KEY_SECTION_LEN
+ NETWORK_DEVICE_LIST_KEY_OFFSET
) && (QuestionId
>= NETWORK_DEVICE_LIST_KEY_OFFSET
)) {
160 // If user select the mac address, need to record mac address string to support next form show.
162 for (CurIndex
= 0; CurIndex
< mMacDeviceList
.CurListLen
; CurIndex
++) {
163 if (mMacDeviceList
.NodeList
[CurIndex
].QuestionId
== QuestionId
) {
164 mSelectedMacAddrString
= HiiGetString (gDeviceManagerPrivate
.HiiHandle
, mMacDeviceList
.NodeList
[CurIndex
].PromptId
, NULL
);
170 // Request to exit SendForm(), so as to switch to selected form
172 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
179 This function registers HII packages to HII database.
181 @retval EFI_SUCCESS HII packages for the Device Manager were registered successfully.
182 @retval EFI_OUT_OF_RESOURCES HII packages for the Device Manager failed to be registered.
186 InitializeDeviceManager (
193 // Install Device Path Protocol and Config Access protocol to driver handle
195 Status
= gBS
->InstallMultipleProtocolInterfaces (
196 &gDeviceManagerPrivate
.DriverHandle
,
197 &gEfiDevicePathProtocolGuid
,
198 &mDeviceManagerHiiVendorDevicePath
,
199 &gEfiHiiConfigAccessProtocolGuid
,
200 &gDeviceManagerPrivate
.ConfigAccess
,
203 ASSERT_EFI_ERROR (Status
);
205 Status
= gBS
->InstallMultipleProtocolInterfaces (
206 &gDeviceManagerPrivate
.DriverHealthHandle
,
207 &gEfiDevicePathProtocolGuid
,
208 &mDriverHealthHiiVendorDevicePath
,
209 &gEfiHiiConfigAccessProtocolGuid
,
210 &gDeviceManagerPrivate
.DriverHealthConfigAccess
,
213 ASSERT_EFI_ERROR (Status
);
215 mMacDeviceList
.CurListLen
= 0;
216 mMacDeviceList
.MaxListLen
= 0;
222 Extract the displayed formset for given HII handle and class guid.
224 @param Handle The HII handle.
225 @param SetupClassGuid The class guid specifies which form set will be displayed.
226 @param FormSetTitle Formset title string.
227 @param FormSetHelp Formset help string.
229 @retval TRUE The formset for given HII handle will be displayed.
230 @return FALSE The formset for given HII handle will not be displayed.
234 ExtractDisplayedHiiFormFromHiiHandle (
235 IN EFI_HII_HANDLE Handle
,
236 IN EFI_GUID
*SetupClassGuid
,
237 OUT EFI_STRING_ID
*FormSetTitle
,
238 OUT EFI_STRING_ID
*FormSetHelp
243 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
248 UINT32 PackageListLength
;
249 EFI_HII_PACKAGE_HEADER PackageHeader
;
253 ASSERT (Handle
!= NULL
);
254 ASSERT (SetupClassGuid
!= NULL
);
255 ASSERT (FormSetTitle
!= NULL
);
256 ASSERT (FormSetHelp
!= NULL
);
264 // Get HII PackageList
267 HiiPackageList
= NULL
;
268 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
270 // Handle is a invalid handle. Check if Handle is corrupted.
272 ASSERT (Status
!= EFI_NOT_FOUND
);
274 // The return status should always be EFI_BUFFER_TOO_SMALL as input buffer's size is 0.
276 ASSERT (Status
== EFI_BUFFER_TOO_SMALL
);
278 HiiPackageList
= AllocatePool (BufferSize
);
279 ASSERT (HiiPackageList
!= NULL
);
281 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
282 if (EFI_ERROR (Status
)) {
287 // Get Form package from this HII package List
289 Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
291 PackageListLength
= ReadUnaligned32 (&HiiPackageList
->PackageLength
);
293 while (Offset
< PackageListLength
) {
294 Package
= ((UINT8
*) HiiPackageList
) + Offset
;
295 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
297 if (PackageHeader
.Type
== EFI_HII_PACKAGE_FORMS
) {
299 // Search FormSet Opcode in this Form Package
301 Offset2
= sizeof (EFI_HII_PACKAGE_HEADER
);
302 while (Offset2
< PackageHeader
.Length
) {
303 OpCodeData
= Package
+ Offset2
;
305 if (((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
== EFI_IFR_FORM_SET_OP
) {
306 if (((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
> OFFSET_OF (EFI_IFR_FORM_SET
, Flags
)) {
308 // Find FormSet OpCode
310 ClassGuidNum
= (UINT8
) (((EFI_IFR_FORM_SET
*) OpCodeData
)->Flags
& 0x3);
311 ClassGuid
= (EFI_GUID
*) (VOID
*)(OpCodeData
+ sizeof (EFI_IFR_FORM_SET
));
312 while (ClassGuidNum
-- > 0) {
313 if (CompareGuid (SetupClassGuid
, ClassGuid
)) {
314 CopyMem (FormSetTitle
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->FormSetTitle
, sizeof (EFI_STRING_ID
));
315 CopyMem (FormSetHelp
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->Help
, sizeof (EFI_STRING_ID
));
316 FreePool (HiiPackageList
);
322 CopyMem (FormSetTitle
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->FormSetTitle
, sizeof (EFI_STRING_ID
));
323 CopyMem (FormSetHelp
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->Help
, sizeof (EFI_STRING_ID
));
324 FreePool (HiiPackageList
);
332 Offset2
+= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
;
337 // Go to next package
339 Offset
+= PackageHeader
.Length
;
342 FreePool (HiiPackageList
);
348 Get the mac address string from the device path.
349 if the device path has the vlan, get the vanid also.
351 @param MacAddressNode Device path begin with mac address
352 @param PBuffer Output string buffer contain mac address.
357 IN MAC_ADDR_DEVICE_PATH
*MacAddressNode
,
364 EFI_DEVICE_PATH_PROTOCOL
*Node
;
371 ASSERT(MacAddressNode
!= NULL
);
373 HwAddressSize
= sizeof (EFI_MAC_ADDRESS
);
374 if (MacAddressNode
->IfType
== 0x01 || MacAddressNode
->IfType
== 0x00) {
379 // The output format is MAC:XX:XX:XX:...\XXXX
380 // The size is the Number size + ":" size + Vlan size(\XXXX) + End
382 BufferLen
= (4 + 2 * HwAddressSize
+ (HwAddressSize
- 1) + 5 + 1) * sizeof (CHAR16
);
383 String
= AllocateZeroPool (BufferLen
);
384 if (String
== NULL
) {
389 StrCpy(String
, L
"MAC:");
393 // Convert the MAC address into a unicode string.
395 HwAddress
= &MacAddressNode
->MacAddress
.Addr
[0];
396 for (Index
= 0; Index
< HwAddressSize
; Index
++) {
397 String
+= UnicodeValueToString (String
, PREFIX_ZERO
| RADIX_HEX
, *(HwAddress
++), 2);
398 if (Index
< HwAddressSize
- 1) {
404 // If VLAN is configured, it will need extra 5 characters like "\0005".
405 // Plus one unicode character for the null-terminator.
407 Node
= (EFI_DEVICE_PATH_PROTOCOL
*)MacAddressNode
;
408 while (!IsDevicePathEnd (Node
)) {
409 if (Node
->Type
== MESSAGING_DEVICE_PATH
&& Node
->SubType
== MSG_VLAN_DP
) {
410 VlanId
= ((VLAN_DEVICE_PATH
*) Node
)->VlanId
;
412 Node
= NextDevicePathNode (Node
);
417 String
+= UnicodeValueToString (String
, PREFIX_ZERO
| RADIX_HEX
, VlanId
, 4);
421 // Null terminate the Unicode string
429 Save question id and prompt id to the mac device list.
430 If the same mac address has saved yet, no need to add more.
432 @param MacAddrString Mac address string.
434 @retval EFI_SUCCESS Add the item is successful.
435 @return Other values if failed to Add the item.
438 AddIdToMacDeviceList (
439 IN EFI_STRING MacAddrString
442 MENU_INFO_ITEM
*TempDeviceList
;
444 EFI_STRING StoredString
;
445 EFI_STRING_ID PromptId
;
446 EFI_HII_HANDLE HiiHandle
;
448 HiiHandle
= gDeviceManagerPrivate
.HiiHandle
;
449 TempDeviceList
= NULL
;
451 for (Index
= 0; Index
< mMacDeviceList
.CurListLen
; Index
++) {
452 StoredString
= HiiGetString (HiiHandle
, mMacDeviceList
.NodeList
[Index
].PromptId
, NULL
);
453 if (StoredString
== NULL
) {
458 // Already has save the same mac address to the list.
460 if (StrCmp (MacAddrString
, StoredString
) == 0) {
465 PromptId
= HiiSetString(HiiHandle
, 0, MacAddrString
, NULL
);
467 // If not in the list, save it.
469 if (mMacDeviceList
.MaxListLen
> mMacDeviceList
.CurListLen
+ 1) {
470 mMacDeviceList
.NodeList
[mMacDeviceList
.CurListLen
].PromptId
= PromptId
;
471 mMacDeviceList
.NodeList
[mMacDeviceList
.CurListLen
].QuestionId
= (EFI_QUESTION_ID
) (mMacDeviceList
.CurListLen
+ NETWORK_DEVICE_LIST_KEY_OFFSET
);
473 mMacDeviceList
.MaxListLen
+= MAX_MAC_ADDRESS_NODE_LIST_LEN
;
474 if (mMacDeviceList
.CurListLen
!= 0) {
475 TempDeviceList
= (MENU_INFO_ITEM
*)AllocateCopyPool (sizeof (MENU_INFO_ITEM
) * mMacDeviceList
.MaxListLen
, (VOID
*)mMacDeviceList
.NodeList
);
477 TempDeviceList
= (MENU_INFO_ITEM
*)AllocatePool (sizeof (MENU_INFO_ITEM
) * mMacDeviceList
.MaxListLen
);
480 if (TempDeviceList
== NULL
) {
483 TempDeviceList
[mMacDeviceList
.CurListLen
].PromptId
= PromptId
;
484 TempDeviceList
[mMacDeviceList
.CurListLen
].QuestionId
= (EFI_QUESTION_ID
) (mMacDeviceList
.CurListLen
+ NETWORK_DEVICE_LIST_KEY_OFFSET
);
486 if (mMacDeviceList
.CurListLen
> 0) {
487 FreePool(mMacDeviceList
.NodeList
);
490 mMacDeviceList
.NodeList
= TempDeviceList
;
492 mMacDeviceList
.CurListLen
++;
498 Check the devcie path, try to find whether it has mac address path.
500 In this function, first need to check whether this path has mac address path.
501 second, when the mac address device path has find, also need to deicide whether
502 need to add this mac address relate info to the menu.
504 @param *Node Input device which need to be check.
505 @param *NeedAddItem Whether need to add the menu in the network device list.
507 @retval TRUE Has mac address device path.
508 @retval FALSE NOT Has mac address device path.
512 IsMacAddressDevicePath (
514 OUT BOOLEAN
*NeedAddItem
517 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
521 ASSERT (Node
!= NULL
);
522 *NeedAddItem
= FALSE
;
526 DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) Node
;
529 // find the partition device path node
531 while (!IsDevicePathEnd (DevicePath
)) {
532 if ((DevicePathType (DevicePath
) == MESSAGING_DEVICE_PATH
) &&
533 (DevicePathSubType (DevicePath
) == MSG_MAC_ADDR_DP
)) {
536 if (DEVICE_MANAGER_FORM_ID
== mNextShowFormId
) {
541 if (!GetMacAddressString((MAC_ADDR_DEVICE_PATH
*)DevicePath
, &Buffer
)) {
545 if (NETWORK_DEVICE_FORM_ID
== mNextShowFormId
) {
546 if (StrCmp (Buffer
, mSelectedMacAddrString
) == 0) {
552 if (NETWORK_DEVICE_LIST_FORM_ID
== mNextShowFormId
) {
554 // Same handle may has two network child handle, so the questionid
555 // has the offset of SAME_HANDLE_KEY_OFFSET.
557 if (AddIdToMacDeviceList (Buffer
)) {
563 DevicePath
= NextDevicePathNode (DevicePath
);
566 if (Buffer
!= NULL
) {
574 Check to see if the device path is for the network device.
576 @param Handle The HII handle which include the mac address device path.
577 @param ItemCount The new add Mac address item count.
579 @retval TRUE Need to add new item in the menu.
580 @return FALSE Do not need to add the menu about the network.
584 IsNeedAddNetworkMenu (
585 IN EFI_HII_HANDLE Handle
,
592 EFI_HII_HANDLE HiiDeviceManagerHandle
;
593 EFI_HANDLE DriverHandle
;
594 EFI_HANDLE ControllerHandle
;
595 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
596 EFI_DEVICE_PATH_PROTOCOL
*TmpDevicePath
;
597 EFI_DEVICE_PATH_PROTOCOL
*ChildDevicePath
;
598 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY
*OpenInfoBuffer
;
601 HiiDeviceManagerHandle
= gDeviceManagerPrivate
.HiiHandle
;
603 OpenInfoBuffer
= NULL
;
604 if ((Handle
== NULL
) || (ItemCount
== NULL
)) {
609 Status
= gHiiDatabase
->GetPackageListHandle (gHiiDatabase
, Handle
, &DriverHandle
);
610 if (EFI_ERROR (Status
)) {
614 // Get the device path by the got Driver handle .
616 Status
= gBS
->HandleProtocol (DriverHandle
, &gEfiDevicePathProtocolGuid
, (VOID
**) &DevicePath
);
617 if (EFI_ERROR (Status
)) {
620 TmpDevicePath
= DevicePath
;
623 // Check whether this device path include mac address device path.
624 // If this path has mac address path, get the value whether need
625 // add this info to the menu and return.
626 // Else check more about the child handle devcie path.
628 if (IsMacAddressDevicePath(TmpDevicePath
, &IsNeedAdd
)) {
629 if ((NETWORK_DEVICE_LIST_FORM_ID
== mNextShowFormId
) && IsNeedAdd
) {
636 // Search whether this path is the controller path, not he child handle path.
637 // And the child handle has the network devcie connected.
639 TmpDevicePath
= DevicePath
;
640 Status
= gBS
->LocateDevicePath(&gEfiDevicePathProtocolGuid
, &TmpDevicePath
, &ControllerHandle
);
641 if (EFI_ERROR (Status
)) {
645 if (!IsDevicePathEnd (TmpDevicePath
)) {
650 // Retrieve the list of agents that are consuming the specific protocol
651 // on ControllerHandle.
652 // The buffer point by OpenInfoBuffer need be free at this function.
654 Status
= gBS
->OpenProtocolInformation (
656 &gEfiPciIoProtocolGuid
,
660 if (EFI_ERROR (Status
)) {
665 // Inspect if ChildHandle is one of the agents.
667 Status
= EFI_UNSUPPORTED
;
668 for (Index
= 0; Index
< EntryCount
; Index
++) {
670 // Query all the children created by the controller handle's driver
672 if ((OpenInfoBuffer
[Index
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) != 0) {
673 Status
= gBS
->OpenProtocol (
674 OpenInfoBuffer
[Index
].ControllerHandle
,
675 &gEfiDevicePathProtocolGuid
,
676 (VOID
**) &ChildDevicePath
,
679 EFI_OPEN_PROTOCOL_GET_PROTOCOL
681 if (EFI_ERROR (Status
)) {
686 // Check whether this device path include mac address device path.
688 if (!IsMacAddressDevicePath(ChildDevicePath
, &IsNeedAdd
)) {
690 // If this path not has mac address path, check the other.
695 // If need to update the NETWORK_DEVICE_LIST_FORM, try to get more.
697 if ((NETWORK_DEVICE_LIST_FORM_ID
== mNextShowFormId
)) {
704 // If need to update other form, return whether need to add to the menu.
713 if (OpenInfoBuffer
!= NULL
) {
714 FreePool (OpenInfoBuffer
);
720 Call the browser and display the device manager to allow user
721 to configure the platform.
723 This function create the dynamic content for device manager. It includes
724 section header for all class of devices, one-of opcode to set VBIOS.
726 @retval EFI_SUCCESS Operation is successful.
727 @return Other values if failed to clean up the dynamic content from HII
740 EFI_STRING_ID TokenHelp
;
741 EFI_HII_HANDLE
*HiiHandles
;
742 EFI_HII_HANDLE HiiHandle
;
743 EFI_STRING_ID FormSetTitle
;
744 EFI_STRING_ID FormSetHelp
;
745 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
746 VOID
*StartOpCodeHandle
;
747 VOID
*EndOpCodeHandle
;
748 EFI_IFR_GUID_LABEL
*StartLabel
;
749 EFI_IFR_GUID_LABEL
*EndLabel
;
751 EFI_HANDLE
*DriverHealthHandles
;
752 BOOLEAN AddNetworkMenu
;
755 EFI_STRING NewStringTitle
;
758 Status
= EFI_SUCCESS
;
761 DriverHealthHandles
= NULL
;
762 AddNetworkMenu
= FALSE
;
766 // Connect all prior to entering the platform setup menu.
768 if (!gConnectAllHappened
) {
769 BdsLibConnectAllDriversToAllControllers ();
770 gConnectAllHappened
= TRUE
;
773 HiiHandle
= gDeviceManagerPrivate
.HiiHandle
;
774 if (HiiHandle
== NULL
) {
776 // Publish our HII data.
778 HiiHandle
= HiiAddPackages (
780 gDeviceManagerPrivate
.DriverHandle
,
785 if (HiiHandle
== NULL
) {
786 return EFI_OUT_OF_RESOURCES
;
789 gDeviceManagerPrivate
.HiiHandle
= HiiHandle
;
793 // If need show the Network device list form, clear the old save list first.
795 if ((mNextShowFormId
== NETWORK_DEVICE_LIST_FORM_ID
) && (mMacDeviceList
.CurListLen
> 0)) {
796 mMacDeviceList
.CurListLen
= 0;
800 // Update the network device form titile.
802 if (mNextShowFormId
== NETWORK_DEVICE_FORM_ID
) {
803 String
= HiiGetString (HiiHandle
, STRING_TOKEN (STR_FORM_NETWORK_DEVICE_TITLE
), NULL
);
804 NewStringLen
= StrLen(mSelectedMacAddrString
) * 2;
805 NewStringLen
+= (StrLen(String
) + 2) * 2;
806 NewStringTitle
= AllocatePool (NewStringLen
);
807 UnicodeSPrint (NewStringTitle
, NewStringLen
, L
"%s %s", String
, mSelectedMacAddrString
);
808 HiiSetString (HiiHandle
, STRING_TOKEN (STR_FORM_NETWORK_DEVICE_TITLE
), NewStringTitle
, NULL
);
810 FreePool (NewStringTitle
);
814 // Allocate space for creation of UpdateData Buffer
816 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
817 ASSERT (StartOpCodeHandle
!= NULL
);
819 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
820 ASSERT (EndOpCodeHandle
!= NULL
);
823 // Create Hii Extend Label OpCode as the start opcode
825 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
826 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
828 // According to the next show Form id(mNextShowFormId) to decide which form need to update.
830 StartLabel
->Number
= (UINT16
) (LABEL_FORM_ID_OFFSET
+ mNextShowFormId
);
833 // Create Hii Extend Label OpCode as the end opcode
835 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
836 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
837 EndLabel
->Number
= LABEL_END
;
840 // Get all the Hii handles
842 HiiHandles
= HiiGetHiiHandles (NULL
);
843 ASSERT (HiiHandles
!= NULL
);
846 // Search for formset of each class type
848 for (Index
= 0; HiiHandles
[Index
] != NULL
; Index
++) {
850 // The QuestionId in the form which will call the driver form has this asssumption.
851 // QuestionId = Handle Index + NETWORK_DEVICE_LIST_KEY_OFFSET;
852 // Different QuestionId at least has the section of NETWORK_DEVICE_LIST_KEY_OFFSET.
854 ASSERT(Index
< MAX_KEY_SECTION_LEN
);
856 if (!ExtractDisplayedHiiFormFromHiiHandle (HiiHandles
[Index
], &gEfiHiiPlatformSetupFormsetGuid
, &FormSetTitle
, &FormSetHelp
)) {
860 String
= HiiGetString (HiiHandles
[Index
], FormSetTitle
, NULL
);
861 if (String
== NULL
) {
862 String
= HiiGetString (HiiHandle
, STR_MISSING_STRING
, NULL
);
863 ASSERT (String
!= NULL
);
865 Token
= HiiSetString (HiiHandle
, 0, String
, NULL
);
868 String
= HiiGetString (HiiHandles
[Index
], FormSetHelp
, NULL
);
869 if (String
== NULL
) {
870 String
= HiiGetString (HiiHandle
, STR_MISSING_STRING
, NULL
);
871 ASSERT (String
!= NULL
);
873 TokenHelp
= HiiSetString (HiiHandle
, 0, String
, NULL
);
877 // Network device process
879 if (IsNeedAddNetworkMenu (HiiHandles
[Index
], &AddItemCount
)) {
880 if (mNextShowFormId
== DEVICE_MANAGER_FORM_ID
) {
882 // Only show one menu item "Network Config" in the device manger form.
884 if (!AddNetworkMenu
) {
885 AddNetworkMenu
= TRUE
;
886 HiiCreateGotoOpCode (
888 DEVICE_MANAGER_FORM_ID
,
889 STRING_TOKEN (STR_FORM_NETWORK_DEVICE_LIST_TITLE
),
890 STRING_TOKEN (STR_FORM_NETWORK_DEVICE_LIST_HELP
),
891 EFI_IFR_FLAG_CALLBACK
,
892 (EFI_QUESTION_ID
) QUESTION_NETWORK_DEVICE_ID
895 } else if (mNextShowFormId
== NETWORK_DEVICE_LIST_FORM_ID
) {
897 // In network device list form, same mac address device only show one menu.
899 while (AddItemCount
> 0) {
900 HiiCreateGotoOpCode (
902 NETWORK_DEVICE_LIST_FORM_ID
,
903 mMacDeviceList
.NodeList
[mMacDeviceList
.CurListLen
- AddItemCount
].PromptId
,
904 STRING_TOKEN (STR_NETWORK_DEVICE_HELP
),
905 EFI_IFR_FLAG_CALLBACK
,
906 mMacDeviceList
.NodeList
[mMacDeviceList
.CurListLen
- AddItemCount
].QuestionId
910 } else if (mNextShowFormId
== NETWORK_DEVICE_FORM_ID
) {
912 // In network device form, only the selected mac address device need to be show.
914 HiiCreateGotoOpCode (
916 NETWORK_DEVICE_FORM_ID
,
919 EFI_IFR_FLAG_CALLBACK
,
920 (EFI_QUESTION_ID
) (Index
+ DEVICE_KEY_OFFSET
)
926 // Not network device process, only need to show at device manger form.
928 if (mNextShowFormId
== DEVICE_MANAGER_FORM_ID
) {
929 HiiCreateGotoOpCode (
931 DEVICE_MANAGER_FORM_ID
,
934 EFI_IFR_FLAG_CALLBACK
,
935 (EFI_QUESTION_ID
) (Index
+ DEVICE_KEY_OFFSET
)
941 Status
= gBS
->LocateHandleBuffer (
943 &gEfiDriverHealthProtocolGuid
,
950 // If there are no drivers installed driver health protocol, do not create driver health entry in UI
952 if (NumHandles
!= 0) {
954 // If driver health protocol is installed, create Driver Health subtitle and entry
956 HiiCreateSubTitleOpCode (StartOpCodeHandle
, STRING_TOKEN (STR_DM_DRIVER_HEALTH_TITLE
), 0, 0, 0);
957 HiiCreateGotoOpCode (
959 DRIVER_HEALTH_FORM_ID
,
960 STRING_TOKEN(STR_DRIVER_HEALTH_ALL_HEALTHY
), // Prompt text
961 STRING_TOKEN(STR_DRIVER_HEALTH_STATUS_HELP
), // Help text
962 EFI_IFR_FLAG_CALLBACK
,
963 DEVICE_MANAGER_KEY_DRIVER_HEALTH
// Question ID
967 // Check All Driver health status
969 if (!PlaformHealthStatusCheck ()) {
971 // At least one driver in the platform are not in healthy status
973 HiiSetString (HiiHandle
, STRING_TOKEN (STR_DRIVER_HEALTH_ALL_HEALTHY
), GetStringById (STRING_TOKEN (STR_DRIVER_NOT_HEALTH
)), NULL
);
976 // For the string of STR_DRIVER_HEALTH_ALL_HEALTHY previously has been updated and we need to update it while re-entry.
978 HiiSetString (HiiHandle
, STRING_TOKEN (STR_DRIVER_HEALTH_ALL_HEALTHY
), GetStringById (STRING_TOKEN (STR_DRIVER_HEALTH_ALL_HEALTHY
)), NULL
);
990 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
991 Status
= gFormBrowser2
->SendForm (
1000 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
1001 EnableResetRequired ();
1005 // We will have returned from processing a callback, selected
1006 // a target to display
1008 if ((gCallbackKey
>= DEVICE_KEY_OFFSET
)) {
1009 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
1010 Status
= gFormBrowser2
->SendForm (
1012 &HiiHandles
[gCallbackKey
- DEVICE_KEY_OFFSET
],
1020 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
1021 EnableResetRequired ();
1025 // Force return to Device Manager
1027 gCallbackKey
= FRONT_PAGE_KEY_DEVICE_MANAGER
;
1032 // Driver Health item chose.
1034 if (gCallbackKey
== DEVICE_MANAGER_KEY_DRIVER_HEALTH
) {
1035 CallDriverHealth ();
1037 // Force return to Device Manager
1039 gCallbackKey
= FRONT_PAGE_KEY_DEVICE_MANAGER
;
1044 // Enter from device manager and into the network device list.
1046 if (gCallbackKey
== QUESTION_NETWORK_DEVICE_ID
) {
1047 mNextShowFormId
= NETWORK_DEVICE_LIST_FORM_ID
;
1048 gCallbackKey
= FRONT_PAGE_KEY_DEVICE_MANAGER
;
1053 // In this case, go from the network device list to the specify device.
1055 if ((gCallbackKey
< MAX_KEY_SECTION_LEN
+ NETWORK_DEVICE_LIST_KEY_OFFSET
) && (gCallbackKey
>= NETWORK_DEVICE_LIST_KEY_OFFSET
)) {
1056 mNextShowFormId
= NETWORK_DEVICE_FORM_ID
;
1057 gCallbackKey
= FRONT_PAGE_KEY_DEVICE_MANAGER
;
1062 // Select the ESC, the gCallbackKey == 0.
1064 if(mNextShowFormId
- 1 < DEVICE_MANAGER_FORM_ID
) {
1065 mNextShowFormId
= DEVICE_MANAGER_FORM_ID
;
1067 mNextShowFormId
= (UINT16
) (mNextShowFormId
- 1);
1068 gCallbackKey
= FRONT_PAGE_KEY_DEVICE_MANAGER
;
1073 // Remove our packagelist from HII database.
1075 HiiRemovePackages (HiiHandle
);
1076 gDeviceManagerPrivate
.HiiHandle
= NULL
;
1078 HiiFreeOpCodeHandle (StartOpCodeHandle
);
1079 HiiFreeOpCodeHandle (EndOpCodeHandle
);
1080 FreePool (HiiHandles
);
1086 This function is invoked if user selected a interactive opcode from Driver Health's
1087 Formset. The decision by user is saved to gCallbackKey for later processing.
1089 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1090 @param Action Specifies the type of action taken by the browser.
1091 @param QuestionId A unique value which is sent to the original exporting driver
1092 so that it can identify the type of data to expect.
1093 @param Type The type of value for the question.
1094 @param Value A pointer to the data being sent to the original exporting driver.
1095 @param ActionRequest On return, points to the action requested by the callback function.
1097 @retval EFI_SUCCESS The callback successfully handled the action.
1098 @retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.
1103 DriverHealthCallback (
1104 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1105 IN EFI_BROWSER_ACTION Action
,
1106 IN EFI_QUESTION_ID QuestionId
,
1108 IN EFI_IFR_TYPE_VALUE
*Value
,
1109 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
1112 if ((Action
== EFI_BROWSER_ACTION_FORM_OPEN
) || (Action
== EFI_BROWSER_ACTION_FORM_CLOSE
)) {
1114 // Do nothing for UEFI OPEN/CLOSE Action
1119 if ((Value
== NULL
) || (ActionRequest
== NULL
)) {
1120 return EFI_INVALID_PARAMETER
;
1123 gCallbackKey
= QuestionId
;
1126 // Request to exit SendForm(), so as to switch to selected form
1128 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
1134 Collect and display the platform's driver health relative information, allow user to do interactive
1135 operation while the platform is unhealthy.
1137 This function display a form which divided into two parts. The one list all modules which has installed
1138 driver health protocol. The list usually contain driver name, controller name, and it's health info.
1139 While the driver name can't be retrieved, will use device path as backup. The other part of the form provide
1140 a choice to the user to repair all platform.
1149 EFI_HII_HANDLE HiiHandle
;
1150 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
1151 EFI_IFR_GUID_LABEL
*StartLabel
;
1152 EFI_IFR_GUID_LABEL
*StartLabelRepair
;
1153 EFI_IFR_GUID_LABEL
*EndLabel
;
1154 EFI_IFR_GUID_LABEL
*EndLabelRepair
;
1155 VOID
*StartOpCodeHandle
;
1156 VOID
*EndOpCodeHandle
;
1157 VOID
*StartOpCodeHandleRepair
;
1158 VOID
*EndOpCodeHandleRepair
;
1160 EFI_STRING_ID Token
;
1161 EFI_STRING_ID TokenHelp
;
1163 EFI_STRING TmpString
;
1164 EFI_STRING DriverName
;
1165 EFI_STRING ControllerName
;
1166 LIST_ENTRY DriverHealthList
;
1167 DRIVER_HEALTH_INFO
*DriverHealthInfo
;
1169 EFI_DEVICE_PATH_PROTOCOL
*DriverDevicePath
;
1174 DriverHealthInfo
= NULL
;
1175 DriverDevicePath
= NULL
;
1176 InitializeListHead (&DriverHealthList
);
1178 HiiHandle
= gDeviceManagerPrivate
.DriverHealthHiiHandle
;
1179 if (HiiHandle
== NULL
) {
1181 // Publish Driver Health HII data.
1183 HiiHandle
= HiiAddPackages (
1184 &mDeviceManagerGuid
,
1185 gDeviceManagerPrivate
.DriverHealthHandle
,
1190 if (HiiHandle
== NULL
) {
1194 gDeviceManagerPrivate
.DriverHealthHiiHandle
= HiiHandle
;
1198 // Allocate space for creation of UpdateData Buffer
1200 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
1201 ASSERT (StartOpCodeHandle
!= NULL
);
1203 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
1204 ASSERT (EndOpCodeHandle
!= NULL
);
1206 StartOpCodeHandleRepair
= HiiAllocateOpCodeHandle ();
1207 ASSERT (StartOpCodeHandleRepair
!= NULL
);
1209 EndOpCodeHandleRepair
= HiiAllocateOpCodeHandle ();
1210 ASSERT (EndOpCodeHandleRepair
!= NULL
);
1213 // Create Hii Extend Label OpCode as the start opcode
1215 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
1216 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
1217 StartLabel
->Number
= LABEL_DRIVER_HEALTH
;
1220 // Create Hii Extend Label OpCode as the start opcode
1222 StartLabelRepair
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandleRepair
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
1223 StartLabelRepair
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
1224 StartLabelRepair
->Number
= LABEL_DRIVER_HEALTH_REAPIR_ALL
;
1227 // Create Hii Extend Label OpCode as the end opcode
1229 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
1230 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
1231 EndLabel
->Number
= LABEL_DRIVER_HEALTH_END
;
1234 // Create Hii Extend Label OpCode as the end opcode
1236 EndLabelRepair
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandleRepair
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
1237 EndLabelRepair
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
1238 EndLabelRepair
->Number
= LABEL_DRIVER_HEALTH_REAPIR_ALL_END
;
1240 HiiCreateSubTitleOpCode (StartOpCodeHandle
, STRING_TOKEN (STR_DH_STATUS_LIST
), 0, 0, 1);
1242 Status
= GetAllControllersHealthStatus (&DriverHealthList
);
1243 ASSERT (Status
!= EFI_OUT_OF_RESOURCES
);
1245 Link
= GetFirstNode (&DriverHealthList
);
1247 while (!IsNull (&DriverHealthList
, Link
)) {
1248 DriverHealthInfo
= DEVICE_MANAGER_HEALTH_INFO_FROM_LINK (Link
);
1251 // Assume no line strings is longer than 512 bytes.
1253 String
= (EFI_STRING
) AllocateZeroPool (0x200);
1254 ASSERT (String
!= NULL
);
1256 Status
= DriverHealthGetDriverName (DriverHealthInfo
->DriverHandle
, &DriverName
);
1257 if (EFI_ERROR (Status
)) {
1259 // Can not get the Driver name, so use the Device path
1261 DriverDevicePath
= DevicePathFromHandle (DriverHealthInfo
->DriverHandle
);
1262 DriverName
= DevicePathToStr (DriverDevicePath
);
1265 // Add the Driver name & Controller name into FormSetTitle string
1267 StrnCat (String
, DriverName
, StrLen (DriverName
));
1270 Status
= DriverHealthGetControllerName (
1271 DriverHealthInfo
->DriverHandle
,
1272 DriverHealthInfo
->ControllerHandle
,
1273 DriverHealthInfo
->ChildHandle
,
1277 if (!EFI_ERROR (Status
)) {
1279 // Can not get the Controller name, just let it empty.
1281 StrnCat (String
, L
" ", StrLen (L
" "));
1282 StrnCat (String
, ControllerName
, StrLen (ControllerName
));
1286 // Add the message of the Module itself provided after the string item.
1288 if ((DriverHealthInfo
->MessageList
!= NULL
) && (DriverHealthInfo
->MessageList
->StringId
!= 0)) {
1289 StrnCat (String
, L
" ", StrLen (L
" "));
1290 TmpString
= HiiGetString (
1291 DriverHealthInfo
->MessageList
->HiiHandle
,
1292 DriverHealthInfo
->MessageList
->StringId
,
1296 // Assert if can not retrieve the message string
1298 ASSERT (TmpString
!= NULL
);
1299 StrnCat (String
, TmpString
, StrLen (TmpString
));
1300 FreePool (TmpString
);
1303 // Update the string will be displayed base on the driver's health status
1305 switch(DriverHealthInfo
->HealthStatus
) {
1306 case EfiDriverHealthStatusRepairRequired
:
1307 Length
= StrLen (GetStringById (STRING_TOKEN (STR_REPAIR_REQUIRED
)));
1308 StrnCat (String
, GetStringById (STRING_TOKEN (STR_REPAIR_REQUIRED
)), Length
);
1310 case EfiDriverHealthStatusConfigurationRequired
:
1311 Length
= StrLen (GetStringById (STRING_TOKEN (STR_CONFIGURATION_REQUIRED
)));
1312 StrnCat (String
, GetStringById (STRING_TOKEN (STR_CONFIGURATION_REQUIRED
)), Length
);
1314 case EfiDriverHealthStatusFailed
:
1315 Length
= StrLen (GetStringById (STRING_TOKEN (STR_OPERATION_FAILED
)));
1316 StrnCat (String
, GetStringById (STRING_TOKEN (STR_OPERATION_FAILED
)), Length
);
1318 case EfiDriverHealthStatusReconnectRequired
:
1319 Length
= StrLen (GetStringById (STRING_TOKEN (STR_RECONNECT_REQUIRED
)));
1320 StrnCat (String
, GetStringById (STRING_TOKEN (STR_RECONNECT_REQUIRED
)), Length
);
1322 case EfiDriverHealthStatusRebootRequired
:
1323 Length
= StrLen (GetStringById (STRING_TOKEN (STR_REBOOT_REQUIRED
)));
1324 StrnCat (String
, GetStringById (STRING_TOKEN (STR_REBOOT_REQUIRED
)), Length
);
1327 Length
= StrLen (GetStringById (STRING_TOKEN (STR_DRIVER_HEALTH_HEALTHY
)));
1328 StrnCat (String
, GetStringById (STRING_TOKEN (STR_DRIVER_HEALTH_HEALTHY
)), Length
);
1333 Token
= HiiSetString (HiiHandle
, 0, String
, NULL
);
1336 TokenHelp
= HiiSetString (HiiHandle
, 0, GetStringById( STRING_TOKEN (STR_DH_REPAIR_SINGLE_HELP
)), NULL
);
1338 HiiCreateActionOpCode (
1340 (EFI_QUESTION_ID
) (Index
+ DRIVER_HEALTH_KEY_OFFSET
),
1343 EFI_IFR_FLAG_CALLBACK
,
1347 Link
= GetNextNode (&DriverHealthList
, Link
);
1351 // Add End Opcode for Subtitle
1353 HiiCreateEndOpCode (StartOpCodeHandle
);
1355 HiiCreateSubTitleOpCode (StartOpCodeHandleRepair
, STRING_TOKEN (STR_DRIVER_HEALTH_REPAIR_ALL
), 0, 0, 1);
1356 TokenHelp
= HiiSetString (HiiHandle
, 0, GetStringById( STRING_TOKEN (STR_DH_REPAIR_ALL_HELP
)), NULL
);
1358 if (PlaformHealthStatusCheck ()) {
1360 // No action need to do for the platform
1362 Token
= HiiSetString (HiiHandle
, 0, GetStringById( STRING_TOKEN (STR_DRIVER_HEALTH_ALL_HEALTHY
)), NULL
);
1363 HiiCreateActionOpCode (
1364 StartOpCodeHandleRepair
,
1368 EFI_IFR_FLAG_READ_ONLY
,
1373 // Create ActionOpCode only while the platform need to do health related operation.
1375 Token
= HiiSetString (HiiHandle
, 0, GetStringById( STRING_TOKEN (STR_DH_REPAIR_ALL_TITLE
)), NULL
);
1376 HiiCreateActionOpCode (
1377 StartOpCodeHandleRepair
,
1378 (EFI_QUESTION_ID
) DRIVER_HEALTH_REPAIR_ALL_KEY
,
1381 EFI_IFR_FLAG_CALLBACK
,
1386 HiiCreateEndOpCode (StartOpCodeHandleRepair
);
1388 Status
= HiiUpdateForm (
1391 DRIVER_HEALTH_FORM_ID
,
1395 ASSERT (Status
!= EFI_NOT_FOUND
);
1396 ASSERT (Status
!= EFI_BUFFER_TOO_SMALL
);
1398 Status
= HiiUpdateForm (
1401 DRIVER_HEALTH_FORM_ID
,
1402 StartOpCodeHandleRepair
,
1403 EndOpCodeHandleRepair
1405 ASSERT (Status
!= EFI_NOT_FOUND
);
1406 ASSERT (Status
!= EFI_BUFFER_TOO_SMALL
);
1408 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
1409 Status
= gFormBrowser2
->SendForm (
1414 DRIVER_HEALTH_FORM_ID
,
1418 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
1419 EnableResetRequired ();
1423 // We will have returned from processing a callback - user either hit ESC to exit, or selected
1424 // a target to display.
1425 // Process the diver health status states here.
1427 if (gCallbackKey
>= DRIVER_HEALTH_KEY_OFFSET
&& gCallbackKey
!= DRIVER_HEALTH_REPAIR_ALL_KEY
) {
1428 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
1430 Link
= GetFirstNode (&DriverHealthList
);
1433 while (!IsNull (&DriverHealthList
, Link
)) {
1435 // Got the item relative node in the List
1437 if (Index
== (gCallbackKey
- DRIVER_HEALTH_KEY_OFFSET
)) {
1438 DriverHealthInfo
= DEVICE_MANAGER_HEALTH_INFO_FROM_LINK (Link
);
1440 // Process the driver's healthy status for the specify module
1442 ProcessSingleControllerHealth (
1443 DriverHealthInfo
->DriverHealth
,
1444 DriverHealthInfo
->ControllerHandle
,
1445 DriverHealthInfo
->ChildHandle
,
1446 DriverHealthInfo
->HealthStatus
,
1447 &(DriverHealthInfo
->MessageList
),
1448 DriverHealthInfo
->HiiHandle
1453 Link
= GetNextNode (&DriverHealthList
, Link
);
1456 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
1457 EnableResetRequired ();
1461 // Force return to the form of Driver Health in Device Manager
1463 gCallbackKey
= DRIVER_HEALTH_RETURN_KEY
;
1467 // Repair the whole platform
1469 if (gCallbackKey
== DRIVER_HEALTH_REPAIR_ALL_KEY
) {
1470 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
1472 PlatformRepairAll (&DriverHealthList
);
1474 gCallbackKey
= DRIVER_HEALTH_RETURN_KEY
;
1478 // Remove driver health packagelist from HII database.
1480 HiiRemovePackages (HiiHandle
);
1481 gDeviceManagerPrivate
.DriverHealthHiiHandle
= NULL
;
1484 // Free driver health info list
1486 while (!IsListEmpty (&DriverHealthList
)) {
1488 Link
= GetFirstNode(&DriverHealthList
);
1489 DriverHealthInfo
= DEVICE_MANAGER_HEALTH_INFO_FROM_LINK (Link
);
1490 RemoveEntryList (Link
);
1492 if (DriverHealthInfo
->MessageList
!= NULL
) {
1493 FreePool(DriverHealthInfo
->MessageList
);
1494 FreePool (DriverHealthInfo
);
1498 HiiFreeOpCodeHandle (StartOpCodeHandle
);
1499 HiiFreeOpCodeHandle (EndOpCodeHandle
);
1500 HiiFreeOpCodeHandle (StartOpCodeHandleRepair
);
1501 HiiFreeOpCodeHandle (EndOpCodeHandleRepair
);
1503 if (gCallbackKey
== DRIVER_HEALTH_RETURN_KEY
) {
1505 // Force return to Driver Health Form
1507 gCallbackKey
= DEVICE_MANAGER_KEY_DRIVER_HEALTH
;
1508 CallDriverHealth ();
1514 Check the Driver Health status of a single controller and try to process it if not healthy.
1516 This function called by CheckAllControllersHealthStatus () function in order to process a specify
1517 contoller's health state.
1519 @param DriverHealthList A Pointer to the list contain all of the platform driver health information.
1520 @param DriverHandle The handle of driver.
1521 @param ControllerHandle The class guid specifies which form set will be displayed.
1522 @param ChildHandle The handle of the child controller to retrieve the health
1523 status on. This is an optional parameter that may be NULL.
1524 @param DriverHealth A pointer to the EFI_DRIVER_HEALTH_PROTOCOL instance.
1525 @param HealthStatus The health status of the controller.
1527 @retval EFI_INVALID_PARAMETER HealthStatus or DriverHealth is NULL.
1528 @retval HealthStatus The Health status of specify controller.
1529 @retval EFI_OUT_OF_RESOURCES The list of Driver Health Protocol handles can not be retrieved.
1530 @retval EFI_NOT_FOUND No controller in the platform install Driver Health Protocol.
1531 @retval EFI_SUCCESS The Health related operation has been taken successfully.
1536 GetSingleControllerHealthStatus (
1537 IN OUT LIST_ENTRY
*DriverHealthList
,
1538 IN EFI_HANDLE DriverHandle
,
1539 IN EFI_HANDLE ControllerHandle
, OPTIONAL
1540 IN EFI_HANDLE ChildHandle
, OPTIONAL
1541 IN EFI_DRIVER_HEALTH_PROTOCOL
*DriverHealth
,
1542 IN EFI_DRIVER_HEALTH_STATUS
*HealthStatus
1546 EFI_DRIVER_HEALTH_HII_MESSAGE
*MessageList
;
1547 EFI_HII_HANDLE FormHiiHandle
;
1548 DRIVER_HEALTH_INFO
*DriverHealthInfo
;
1550 if (HealthStatus
== NULL
) {
1552 // If HealthStatus is NULL, then return EFI_INVALID_PARAMETER
1554 return EFI_INVALID_PARAMETER
;
1558 // Assume the HealthStatus is healthy
1560 *HealthStatus
= EfiDriverHealthStatusHealthy
;
1562 if (DriverHealth
== NULL
) {
1564 // If DriverHealth is NULL, then return EFI_INVALID_PARAMETER
1566 return EFI_INVALID_PARAMETER
;
1569 if (ControllerHandle
== NULL
) {
1571 // If ControllerHandle is NULL, the return the cumulative health status of the driver
1573 Status
= DriverHealth
->GetHealthStatus (DriverHealth
, NULL
, NULL
, HealthStatus
, NULL
, NULL
);
1574 if (*HealthStatus
== EfiDriverHealthStatusHealthy
) {
1576 // Add the driver health related information into the list
1578 DriverHealthInfo
= AllocateZeroPool (sizeof (DRIVER_HEALTH_INFO
));
1579 if (DriverHealthInfo
== NULL
) {
1580 return EFI_OUT_OF_RESOURCES
;
1583 DriverHealthInfo
->Signature
= DEVICE_MANAGER_DRIVER_HEALTH_INFO_SIGNATURE
;
1584 DriverHealthInfo
->DriverHandle
= DriverHandle
;
1585 DriverHealthInfo
->ControllerHandle
= NULL
;
1586 DriverHealthInfo
->ChildHandle
= NULL
;
1587 DriverHealthInfo
->HiiHandle
= NULL
;
1588 DriverHealthInfo
->DriverHealth
= DriverHealth
;
1589 DriverHealthInfo
->MessageList
= NULL
;
1590 DriverHealthInfo
->HealthStatus
= *HealthStatus
;
1592 InsertTailList (DriverHealthList
, &DriverHealthInfo
->Link
);
1598 FormHiiHandle
= NULL
;
1601 // Collect the health status with the optional HII message list
1603 Status
= DriverHealth
->GetHealthStatus (DriverHealth
, ControllerHandle
, ChildHandle
, HealthStatus
, &MessageList
, &FormHiiHandle
);
1605 if (EFI_ERROR (Status
)) {
1607 // If the health status could not be retrieved, then return immediately
1613 // Add the driver health related information into the list
1615 DriverHealthInfo
= AllocateZeroPool (sizeof (DRIVER_HEALTH_INFO
));
1616 if (DriverHealthInfo
== NULL
) {
1617 return EFI_OUT_OF_RESOURCES
;
1620 DriverHealthInfo
->Signature
= DEVICE_MANAGER_DRIVER_HEALTH_INFO_SIGNATURE
;
1621 DriverHealthInfo
->DriverHandle
= DriverHandle
;
1622 DriverHealthInfo
->ControllerHandle
= ControllerHandle
;
1623 DriverHealthInfo
->ChildHandle
= ChildHandle
;
1624 DriverHealthInfo
->HiiHandle
= FormHiiHandle
;
1625 DriverHealthInfo
->DriverHealth
= DriverHealth
;
1626 DriverHealthInfo
->MessageList
= MessageList
;
1627 DriverHealthInfo
->HealthStatus
= *HealthStatus
;
1629 InsertTailList (DriverHealthList
, &DriverHealthInfo
->Link
);
1635 Collects all the EFI Driver Health Protocols currently present in the EFI Handle Database,
1636 and queries each EFI Driver Health Protocol to determine if one or more of the controllers
1637 managed by each EFI Driver Health Protocol instance are not healthy.
1639 @param DriverHealthList A Pointer to the list contain all of the platform driver health
1642 @retval EFI_NOT_FOUND No controller in the platform install Driver Health Protocol.
1643 @retval EFI_SUCCESS All the controllers in the platform are healthy.
1644 @retval EFI_OUT_OF_RESOURCES The list of Driver Health Protocol handles can not be retrieved.
1648 GetAllControllersHealthStatus (
1649 IN OUT LIST_ENTRY
*DriverHealthList
1654 EFI_HANDLE
*DriverHealthHandles
;
1655 EFI_DRIVER_HEALTH_PROTOCOL
*DriverHealth
;
1656 EFI_DRIVER_HEALTH_STATUS HealthStatus
;
1657 UINTN DriverHealthIndex
;
1658 EFI_HANDLE
*Handles
;
1660 UINTN ControllerIndex
;
1664 // Initialize local variables
1667 DriverHealthHandles
= NULL
;
1671 HealthStatus
= EfiDriverHealthStatusHealthy
;
1673 Status
= gBS
->LocateHandleBuffer (
1675 &gEfiDriverHealthProtocolGuid
,
1678 &DriverHealthHandles
1681 if (Status
== EFI_NOT_FOUND
|| NumHandles
== 0) {
1683 // If there are no Driver Health Protocols handles, then return EFI_NOT_FOUND
1685 return EFI_NOT_FOUND
;
1688 if (EFI_ERROR (Status
) || DriverHealthHandles
== NULL
) {
1690 // If the list of Driver Health Protocol handles can not be retrieved, then
1691 // return EFI_OUT_OF_RESOURCES
1693 return EFI_OUT_OF_RESOURCES
;
1697 // Check the health status of all controllers in the platform
1698 // Start by looping through all the Driver Health Protocol handles in the handle database
1700 for (DriverHealthIndex
= 0; DriverHealthIndex
< NumHandles
; DriverHealthIndex
++) {
1702 // Skip NULL Driver Health Protocol handles
1704 if (DriverHealthHandles
[DriverHealthIndex
] == NULL
) {
1709 // Retrieve the Driver Health Protocol from DriverHandle
1711 Status
= gBS
->HandleProtocol (
1712 DriverHealthHandles
[DriverHealthIndex
],
1713 &gEfiDriverHealthProtocolGuid
,
1714 (VOID
**)&DriverHealth
1716 if (EFI_ERROR (Status
)) {
1718 // If the Driver Health Protocol can not be retrieved, then skip to the next
1719 // Driver Health Protocol handle
1725 // Check the health of all the controllers managed by a Driver Health Protocol handle
1727 Status
= GetSingleControllerHealthStatus (DriverHealthList
, DriverHealthHandles
[DriverHealthIndex
], NULL
, NULL
, DriverHealth
, &HealthStatus
);
1730 // If Status is an error code, then the health information could not be retrieved, so assume healthy
1731 // and skip to the next Driver Health Protocol handle
1733 if (EFI_ERROR (Status
)) {
1738 // If all the controllers managed by this Driver Health Protocol are healthy, then skip to the next
1739 // Driver Health Protocol handle
1741 if (HealthStatus
== EfiDriverHealthStatusHealthy
) {
1746 // See if the list of all handles in the handle database has been retrieved
1749 if (Handles
== NULL
) {
1751 // Retrieve the list of all handles from the handle database
1753 Status
= gBS
->LocateHandleBuffer (
1760 if (EFI_ERROR (Status
) || Handles
== NULL
) {
1762 // If all the handles in the handle database can not be retrieved, then
1763 // return EFI_OUT_OF_RESOURCES
1765 Status
= EFI_OUT_OF_RESOURCES
;
1770 // Loop through all the controller handles in the handle database
1772 for (ControllerIndex
= 0; ControllerIndex
< HandleCount
; ControllerIndex
++) {
1774 // Skip NULL controller handles
1776 if (Handles
[ControllerIndex
] == NULL
) {
1780 Status
= GetSingleControllerHealthStatus (DriverHealthList
, DriverHealthHandles
[DriverHealthIndex
], Handles
[ControllerIndex
], NULL
, DriverHealth
, &HealthStatus
);
1781 if (EFI_ERROR (Status
)) {
1783 // If Status is an error code, then the health information could not be retrieved, so assume healthy
1785 HealthStatus
= EfiDriverHealthStatusHealthy
;
1789 // If CheckHealthSingleController() returned an error on a terminal state, then do not check the health of child controllers
1791 if (EFI_ERROR (Status
)) {
1796 // Loop through all the child handles in the handle database
1798 for (ChildIndex
= 0; ChildIndex
< HandleCount
; ChildIndex
++) {
1800 // Skip NULL child handles
1802 if (Handles
[ChildIndex
] == NULL
) {
1806 Status
= GetSingleControllerHealthStatus (DriverHealthList
, DriverHealthHandles
[DriverHealthIndex
], Handles
[ControllerIndex
], Handles
[ChildIndex
], DriverHealth
, &HealthStatus
);
1807 if (EFI_ERROR (Status
)) {
1809 // If Status is an error code, then the health information could not be retrieved, so assume healthy
1811 HealthStatus
= EfiDriverHealthStatusHealthy
;
1815 // If CheckHealthSingleController() returned an error on a terminal state, then skip to the next child
1817 if (EFI_ERROR (Status
)) {
1824 Status
= EFI_SUCCESS
;
1827 if (Handles
!= NULL
) {
1828 gBS
->FreePool (Handles
);
1830 if (DriverHealthHandles
!= NULL
) {
1831 gBS
->FreePool (DriverHealthHandles
);
1839 Check the healthy status of the platform, this function will return immediately while found one driver
1840 in the platform are not healthy.
1842 @retval FALSE at least one driver in the platform are not healthy.
1843 @retval TRUE No controller install Driver Health Protocol,
1844 or all controllers in the platform are in healthy status.
1847 PlaformHealthStatusCheck (
1851 EFI_DRIVER_HEALTH_STATUS HealthStatus
;
1855 EFI_HANDLE
*DriverHealthHandles
;
1856 EFI_DRIVER_HEALTH_PROTOCOL
*DriverHealth
;
1860 // Initialize local variables
1862 DriverHealthHandles
= NULL
;
1863 DriverHealth
= NULL
;
1865 HealthStatus
= EfiDriverHealthStatusHealthy
;
1867 Status
= gBS
->LocateHandleBuffer (
1869 &gEfiDriverHealthProtocolGuid
,
1872 &DriverHealthHandles
1875 // There are no handles match the search for Driver Health Protocol has been installed.
1877 if (Status
== EFI_NOT_FOUND
) {
1881 // Assume all modules are healthy.
1886 // Found one or more Handles.
1888 if (!EFI_ERROR (Status
)) {
1889 for (Index
= 0; Index
< NoHandles
; Index
++) {
1890 Status
= gBS
->HandleProtocol (
1891 DriverHealthHandles
[Index
],
1892 &gEfiDriverHealthProtocolGuid
,
1893 (VOID
**) &DriverHealth
1895 if (!EFI_ERROR (Status
)) {
1896 Status
= DriverHealth
->GetHealthStatus (
1906 // Get the healthy status of the module
1908 if (!EFI_ERROR (Status
)) {
1909 if (HealthStatus
!= EfiDriverHealthStatusHealthy
) {
1911 // Return immediately one driver's status not in healthy.
1922 Processes a single controller using the EFI Driver Health Protocol associated with
1923 that controller. This algorithm continues to query the GetHealthStatus() service until
1924 one of the legal terminal states of the EFI Driver Health Protocol is reached. This may
1925 require the processing of HII Messages, HII Form, and invocation of repair operations.
1927 @param DriverHealth A pointer to the EFI_DRIVER_HEALTH_PROTOCOL instance.
1928 @param ControllerHandle The class guid specifies which form set will be displayed.
1929 @param ChildHandle The handle of the child controller to retrieve the health
1930 status on. This is an optional parameter that may be NULL.
1931 @param HealthStatus The health status of the controller.
1932 @param MessageList An array of warning or error messages associated
1933 with the controller specified by ControllerHandle and
1934 ChildHandle. This is an optional parameter that may be NULL.
1935 @param FormHiiHandle The HII handle for an HII form associated with the
1936 controller specified by ControllerHandle and ChildHandle.
1939 ProcessSingleControllerHealth (
1940 IN EFI_DRIVER_HEALTH_PROTOCOL
*DriverHealth
,
1941 IN EFI_HANDLE ControllerHandle
, OPTIONAL
1942 IN EFI_HANDLE ChildHandle
, OPTIONAL
1943 IN EFI_DRIVER_HEALTH_STATUS HealthStatus
,
1944 IN EFI_DRIVER_HEALTH_HII_MESSAGE
**MessageList
, OPTIONAL
1945 IN EFI_HII_HANDLE FormHiiHandle
1949 EFI_DRIVER_HEALTH_STATUS LocalHealthStatus
;
1951 LocalHealthStatus
= HealthStatus
;
1953 // If the module need to be repaired or reconfiguration, will process it until
1954 // reach a terminal status. The status from EfiDriverHealthStatusRepairRequired after repair
1955 // will be in (Health, Failed, Configuration Required).
1957 while( LocalHealthStatus
== EfiDriverHealthStatusConfigurationRequired
||
1958 LocalHealthStatus
== EfiDriverHealthStatusRepairRequired
) {
1960 if (LocalHealthStatus
== EfiDriverHealthStatusRepairRequired
) {
1961 Status
= DriverHealth
->Repair (
1965 (EFI_DRIVER_HEALTH_REPAIR_PROGRESS_NOTIFY
) RepairNotify
1969 // Via a form of the driver need to do configuration provided to process of status in
1970 // EfiDriverHealthStatusConfigurationRequired. The status after configuration should be in
1971 // (Healthy, Reboot Required, Failed, Reconnect Required, Repair Required).
1973 if (LocalHealthStatus
== EfiDriverHealthStatusConfigurationRequired
) {
1974 Status
= gFormBrowser2
->SendForm (
1978 &gEfiHiiDriverHealthFormsetGuid
,
1983 ASSERT( !EFI_ERROR (Status
));
1986 Status
= DriverHealth
->GetHealthStatus (
1994 ASSERT_EFI_ERROR (Status
);
1996 if (*MessageList
!= NULL
) {
1997 ProcessMessages (*MessageList
);
2002 // Health status in {Healthy, Failed} may also have Messages need to process
2004 if (LocalHealthStatus
== EfiDriverHealthStatusHealthy
|| LocalHealthStatus
== EfiDriverHealthStatusFailed
) {
2005 if (*MessageList
!= NULL
) {
2006 ProcessMessages (*MessageList
);
2010 // Check for RebootRequired or ReconnectRequired
2012 if (LocalHealthStatus
== EfiDriverHealthStatusRebootRequired
) {
2013 gRT
->ResetSystem (EfiResetWarm
, EFI_SUCCESS
, 0, NULL
);
2017 // Do reconnect if need.
2019 if (LocalHealthStatus
== EfiDriverHealthStatusReconnectRequired
) {
2020 Status
= gBS
->DisconnectController (ControllerHandle
, NULL
, NULL
);
2021 if (EFI_ERROR (Status
)) {
2023 // Disconnect failed. Need to promote reconnect to a reboot.
2025 gRT
->ResetSystem (EfiResetWarm
, EFI_SUCCESS
, 0, NULL
);
2027 gBS
->ConnectController (ControllerHandle
, NULL
, NULL
, TRUE
);
2033 Platform specific notification function for controller repair operations.
2035 If the driver for a controller support the Driver Health Protocol and the
2036 current state of the controller is EfiDriverHealthStatusRepairRequired then
2037 when the Repair() service of the Driver Health Protocol is called, this
2038 platform specific notification function can display the progress of the repair
2039 operation. Some platforms may choose to not display anything, other may choose
2040 to show the percentage complete on text consoles, and other may choose to render
2041 a progress bar on text and graphical consoles.
2043 This function displays the percentage of the repair operation that has been
2044 completed on text consoles. The percentage is Value / Limit * 100%.
2046 @param Value Value in the range 0..Limit the the repair has completed..
2047 @param Limit The maximum value of Value
2059 Print(L
"Repair Progress Undefined\n\r");
2061 Percent
= Value
* 100 / Limit
;
2062 Print(L
"Repair Progress = %3d%%\n\r", Percent
);
2067 Processes a set of messages returned by the GetHealthStatus ()
2068 service of the EFI Driver Health Protocol
2070 @param MessageList The MessageList point to messages need to processed.
2075 IN EFI_DRIVER_HEALTH_HII_MESSAGE
*MessageList
2079 EFI_STRING MessageString
;
2081 for (MessageIndex
= 0;
2082 MessageList
[MessageIndex
].HiiHandle
!= NULL
;
2085 MessageString
= HiiGetString (
2086 MessageList
[MessageIndex
].HiiHandle
,
2087 MessageList
[MessageIndex
].StringId
,
2090 if (MessageString
!= NULL
) {
2092 // User can customize the output. Just simply print out the MessageString like below.
2093 // Also can use the HiiHandle to display message on the front page.
2095 // Print(L"%s\n",MessageString);
2096 // gBS->Stall (100000);
2103 Repair the whole platform.
2105 This function is the main entry for user choose "Repair All" in the front page.
2106 It will try to do recovery job till all the driver health protocol installed modules
2107 reach a terminal state.
2109 @param DriverHealthList A Pointer to the list contain all of the platform driver health
2115 IN LIST_ENTRY
*DriverHealthList
2118 DRIVER_HEALTH_INFO
*DriverHealthInfo
;
2121 ASSERT (DriverHealthList
!= NULL
);
2123 Link
= GetFirstNode (DriverHealthList
);
2125 while (!IsNull (DriverHealthList
, Link
)) {
2126 DriverHealthInfo
= DEVICE_MANAGER_HEALTH_INFO_FROM_LINK (Link
);
2128 // Do driver health status operation by each link node
2130 ASSERT (DriverHealthInfo
!= NULL
);
2132 ProcessSingleControllerHealth (
2133 DriverHealthInfo
->DriverHealth
,
2134 DriverHealthInfo
->ControllerHandle
,
2135 DriverHealthInfo
->ChildHandle
,
2136 DriverHealthInfo
->HealthStatus
,
2137 &(DriverHealthInfo
->MessageList
),
2138 DriverHealthInfo
->HiiHandle
2141 Link
= GetNextNode (DriverHealthList
, Link
);
2147 Select the best matching language according to front page policy for best user experience.
2149 This function supports both ISO 639-2 and RFC 4646 language codes, but language
2150 code types may not be mixed in a single call to this function.
2152 @param SupportedLanguages A pointer to a Null-terminated ASCII string that
2153 contains a set of language codes in the format
2154 specified by Iso639Language.
2155 @param Iso639Language If TRUE, then all language codes are assumed to be
2156 in ISO 639-2 format. If FALSE, then all language
2157 codes are assumed to be in RFC 4646 language format.
2159 @retval NULL The best matching language could not be found in SupportedLanguages.
2160 @retval NULL There are not enough resources available to return the best matching
2162 @retval Other A pointer to a Null-terminated ASCII string that is the best matching
2163 language in SupportedLanguages.
2166 DriverHealthSelectBestLanguage (
2167 IN CHAR8
*SupportedLanguages
,
2168 IN BOOLEAN Iso639Language
2171 CHAR8
*LanguageVariable
;
2172 CHAR8
*BestLanguage
;
2174 LanguageVariable
= GetEfiGlobalVariable (Iso639Language
? L
"Lang" : L
"PlatformLang");
2176 BestLanguage
= GetBestLanguage(
2179 (LanguageVariable
!= NULL
) ? LanguageVariable
: "",
2180 Iso639Language
? "eng" : "en-US",
2183 if (LanguageVariable
!= NULL
) {
2184 FreePool (LanguageVariable
);
2187 return BestLanguage
;
2194 This is an internal worker function to get the Component Name (2) protocol interface
2195 and the language it supports.
2197 @param ProtocolGuid A pointer to an EFI_GUID. It points to Component Name (2) protocol GUID.
2198 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
2199 @param ComponentName A pointer to the Component Name (2) protocol interface.
2200 @param SupportedLanguage The best suitable language that matches the SupportedLangues interface for the
2201 located Component Name (2) instance.
2203 @retval EFI_SUCCESS The Component Name (2) protocol instance is successfully located and we find
2204 the best matching language it support.
2205 @retval EFI_UNSUPPORTED The input Language is not supported by the Component Name (2) protocol.
2206 @retval Other Some error occurs when locating Component Name (2) protocol instance or finding
2207 the supported language.
2211 GetComponentNameWorker (
2212 IN EFI_GUID
*ProtocolGuid
,
2213 IN EFI_HANDLE DriverBindingHandle
,
2214 OUT EFI_COMPONENT_NAME_PROTOCOL
**ComponentName
,
2215 OUT CHAR8
**SupportedLanguage
2221 // Locate Component Name (2) protocol on the driver binging handle.
2223 Status
= gBS
->OpenProtocol (
2224 DriverBindingHandle
,
2226 (VOID
**) ComponentName
,
2229 EFI_OPEN_PROTOCOL_GET_PROTOCOL
2231 if (EFI_ERROR (Status
)) {
2236 // Apply shell policy to select the best language.
2238 *SupportedLanguage
= DriverHealthSelectBestLanguage (
2239 (*ComponentName
)->SupportedLanguages
,
2240 (BOOLEAN
) (ProtocolGuid
== &gEfiComponentNameProtocolGuid
)
2242 if (*SupportedLanguage
== NULL
) {
2243 Status
= EFI_UNSUPPORTED
;
2251 This is an internal worker function to get driver name from Component Name (2) protocol interface.
2254 @param ProtocolGuid A pointer to an EFI_GUID. It points to Component Name (2) protocol GUID.
2255 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
2256 @param DriverName A pointer to the Unicode string to return. This Unicode string is the name
2257 of the driver specified by This.
2259 @retval EFI_SUCCESS The driver name is successfully retrieved from Component Name (2) protocol
2261 @retval Other The driver name cannot be retrieved from Component Name (2) protocol
2266 GetDriverNameWorker (
2267 IN EFI_GUID
*ProtocolGuid
,
2268 IN EFI_HANDLE DriverBindingHandle
,
2269 OUT CHAR16
**DriverName
2273 CHAR8
*BestLanguage
;
2274 EFI_COMPONENT_NAME_PROTOCOL
*ComponentName
;
2277 // Retrieve Component Name (2) protocol instance on the driver binding handle and
2278 // find the best language this instance supports.
2280 Status
= GetComponentNameWorker (
2282 DriverBindingHandle
,
2286 if (EFI_ERROR (Status
)) {
2291 // Get the driver name from Component Name (2) protocol instance on the driver binging handle.
2293 Status
= ComponentName
->GetDriverName (
2298 FreePool (BestLanguage
);
2305 This function gets driver name from Component Name 2 protocol interface and Component Name protocol interface
2306 in turn. It first tries UEFI 2.0 Component Name 2 protocol interface and try to get the driver name.
2307 If the attempt fails, it then gets the driver name from EFI 1.1 Component Name protocol for backward
2308 compatibility support.
2310 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
2311 @param DriverName A pointer to the Unicode string to return. This Unicode string is the name
2312 of the driver specified by This.
2314 @retval EFI_SUCCESS The driver name is successfully retrieved from Component Name (2) protocol
2316 @retval Other The driver name cannot be retrieved from Component Name (2) protocol
2321 DriverHealthGetDriverName (
2322 IN EFI_HANDLE DriverBindingHandle
,
2323 OUT CHAR16
**DriverName
2329 // Get driver name from UEFI 2.0 Component Name 2 protocol interface.
2331 Status
= GetDriverNameWorker (&gEfiComponentName2ProtocolGuid
, DriverBindingHandle
, DriverName
);
2332 if (EFI_ERROR (Status
)) {
2334 // If it fails to get the driver name from Component Name protocol interface, we should fall back on
2335 // EFI 1.1 Component Name protocol interface.
2337 Status
= GetDriverNameWorker (&gEfiComponentNameProtocolGuid
, DriverBindingHandle
, DriverName
);
2346 This function gets controller name from Component Name 2 protocol interface and Component Name protocol interface
2347 in turn. It first tries UEFI 2.0 Component Name 2 protocol interface and try to get the controller name.
2348 If the attempt fails, it then gets the controller name from EFI 1.1 Component Name protocol for backward
2349 compatibility support.
2351 @param ProtocolGuid A pointer to an EFI_GUID. It points to Component Name (2) protocol GUID.
2352 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
2353 @param ControllerHandle The handle of a controller that the driver specified by This is managing.
2354 This handle specifies the controller whose name is to be returned.
2355 @param ChildHandle The handle of the child controller to retrieve the name of. This is an
2356 optional parameter that may be NULL. It will be NULL for device drivers.
2357 It will also be NULL for bus drivers that attempt to retrieve the name
2358 of the bus controller. It will not be NULL for a bus driver that attempts
2359 to retrieve the name of a child controller.
2360 @param ControllerName A pointer to the Unicode string to return. This Unicode string
2361 is the name of the controller specified by ControllerHandle and ChildHandle.
2363 @retval EFI_SUCCESS The controller name is successfully retrieved from Component Name (2) protocol
2365 @retval Other The controller name cannot be retrieved from Component Name (2) protocol.
2369 GetControllerNameWorker (
2370 IN EFI_GUID
*ProtocolGuid
,
2371 IN EFI_HANDLE DriverBindingHandle
,
2372 IN EFI_HANDLE ControllerHandle
,
2373 IN EFI_HANDLE ChildHandle
,
2374 OUT CHAR16
**ControllerName
2378 CHAR8
*BestLanguage
;
2379 EFI_COMPONENT_NAME_PROTOCOL
*ComponentName
;
2382 // Retrieve Component Name (2) protocol instance on the driver binding handle and
2383 // find the best language this instance supports.
2385 Status
= GetComponentNameWorker (
2387 DriverBindingHandle
,
2391 if (EFI_ERROR (Status
)) {
2396 // Get the controller name from Component Name (2) protocol instance on the driver binging handle.
2398 Status
= ComponentName
->GetControllerName (
2405 FreePool (BestLanguage
);
2412 This function gets controller name from Component Name 2 protocol interface and Component Name protocol interface
2413 in turn. It first tries UEFI 2.0 Component Name 2 protocol interface and try to get the controller name.
2414 If the attempt fails, it then gets the controller name from EFI 1.1 Component Name protocol for backward
2415 compatibility support.
2417 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
2418 @param ControllerHandle The handle of a controller that the driver specified by This is managing.
2419 This handle specifies the controller whose name is to be returned.
2420 @param ChildHandle The handle of the child controller to retrieve the name of. This is an
2421 optional parameter that may be NULL. It will be NULL for device drivers.
2422 It will also be NULL for bus drivers that attempt to retrieve the name
2423 of the bus controller. It will not be NULL for a bus driver that attempts
2424 to retrieve the name of a child controller.
2425 @param ControllerName A pointer to the Unicode string to return. This Unicode string
2426 is the name of the controller specified by ControllerHandle and ChildHandle.
2428 @retval EFI_SUCCESS The controller name is successfully retrieved from Component Name (2) protocol
2430 @retval Other The controller name cannot be retrieved from Component Name (2) protocol.
2434 DriverHealthGetControllerName (
2435 IN EFI_HANDLE DriverBindingHandle
,
2436 IN EFI_HANDLE ControllerHandle
,
2437 IN EFI_HANDLE ChildHandle
,
2438 OUT CHAR16
**ControllerName
2444 // Get controller name from UEFI 2.0 Component Name 2 protocol interface.
2446 Status
= GetControllerNameWorker (
2447 &gEfiComponentName2ProtocolGuid
,
2448 DriverBindingHandle
,
2453 if (EFI_ERROR (Status
)) {
2455 // If it fails to get the controller name from Component Name protocol interface, we should fall back on
2456 // EFI 1.1 Component Name protocol interface.
2458 Status
= GetControllerNameWorker (
2459 &gEfiComponentNameProtocolGuid
,
2460 DriverBindingHandle
,