]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.c
Update the copyright notice format
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / BdsDxe / DeviceMngr / DeviceManager.c
1 /** @file
2 The platform device manager reference implementation
3
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
9
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.
12
13 **/
14
15 #include "DeviceManager.h"
16
17 DEVICE_MANAGER_CALLBACK_DATA gDeviceManagerPrivate = {
18 DEVICE_MANAGER_CALLBACK_DATA_SIGNATURE,
19 NULL,
20 NULL,
21 NULL,
22 NULL,
23 {
24 FakeExtractConfig,
25 FakeRouteConfig,
26 DeviceManagerCallback
27 },
28 {
29 FakeExtractConfig,
30 FakeRouteConfig,
31 DriverHealthCallback
32 }
33 };
34
35 EFI_GUID mDeviceManagerGuid = DEVICE_MANAGER_FORMSET_GUID;
36 EFI_GUID mDriverHealthGuid = DRIVER_HEALTH_FORMSET_GUID;
37
38 DEVICE_MANAGER_MENU_ITEM mDeviceManagerMenuItemTable[] = {
39 { STRING_TOKEN (STR_DISK_DEVICE), EFI_DISK_DEVICE_CLASS },
40 { STRING_TOKEN (STR_VIDEO_DEVICE), EFI_VIDEO_DEVICE_CLASS },
41 { STRING_TOKEN (STR_NETWORK_DEVICE), EFI_NETWORK_DEVICE_CLASS },
42 { STRING_TOKEN (STR_INPUT_DEVICE), EFI_INPUT_DEVICE_CLASS },
43 { STRING_TOKEN (STR_ON_BOARD_DEVICE), EFI_ON_BOARD_DEVICE_CLASS },
44 { STRING_TOKEN (STR_OTHER_DEVICE), EFI_OTHER_DEVICE_CLASS }
45 };
46
47 HII_VENDOR_DEVICE_PATH mDeviceManagerHiiVendorDevicePath = {
48 {
49 {
50 HARDWARE_DEVICE_PATH,
51 HW_VENDOR_DP,
52 {
53 (UINT8) (sizeof (VENDOR_DEVICE_PATH)),
54 (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)
55 }
56 },
57 //
58 // {102579A0-3686-466e-ACD8-80C087044F4A}
59 //
60 { 0x102579a0, 0x3686, 0x466e, { 0xac, 0xd8, 0x80, 0xc0, 0x87, 0x4, 0x4f, 0x4a } }
61 },
62 {
63 END_DEVICE_PATH_TYPE,
64 END_ENTIRE_DEVICE_PATH_SUBTYPE,
65 {
66 (UINT8) (END_DEVICE_PATH_LENGTH),
67 (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)
68 }
69 }
70 };
71
72 HII_VENDOR_DEVICE_PATH mDriverHealthHiiVendorDevicePath = {
73 {
74 {
75 HARDWARE_DEVICE_PATH,
76 HW_VENDOR_DP,
77 {
78 (UINT8) (sizeof (VENDOR_DEVICE_PATH)),
79 (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)
80 }
81 },
82 //
83 // {D8F76651-1675-4986-BED4-3824B2F1F4C8}
84 //
85 { 0xd8f76651, 0x1675, 0x4986, { 0xbe, 0xd4, 0x38, 0x24, 0xb2, 0xf1, 0xf4, 0xc8 } }
86 },
87 {
88 END_DEVICE_PATH_TYPE,
89 END_ENTIRE_DEVICE_PATH_SUBTYPE,
90 {
91 (UINT8) (END_DEVICE_PATH_LENGTH),
92 (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)
93 }
94 }
95 };
96
97 /**
98 This function is invoked if user selected a interactive opcode from Device Manager's
99 Formset. The decision by user is saved to gCallbackKey for later processing. If
100 user set VBIOS, the new value is saved to EFI variable.
101
102 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
103 @param Action Specifies the type of action taken by the browser.
104 @param QuestionId A unique value which is sent to the original exporting driver
105 so that it can identify the type of data to expect.
106 @param Type The type of value for the question.
107 @param Value A pointer to the data being sent to the original exporting driver.
108 @param ActionRequest On return, points to the action requested by the callback function.
109
110 @retval EFI_SUCCESS The callback successfully handled the action.
111 @retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.
112
113 **/
114 EFI_STATUS
115 EFIAPI
116 DeviceManagerCallback (
117 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
118 IN EFI_BROWSER_ACTION Action,
119 IN EFI_QUESTION_ID QuestionId,
120 IN UINT8 Type,
121 IN EFI_IFR_TYPE_VALUE *Value,
122 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
123 )
124 {
125 if ((Value == NULL) || (ActionRequest == NULL)) {
126 return EFI_INVALID_PARAMETER;
127 }
128
129 gCallbackKey = QuestionId;
130
131 //
132 // Request to exit SendForm(), so as to switch to selected form
133 //
134 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;
135
136 return EFI_SUCCESS;
137 }
138
139 /**
140
141 This function registers HII packages to HII database.
142
143 @retval EFI_SUCCESS HII packages for the Device Manager were registered successfully.
144 @retval EFI_OUT_OF_RESOURCES HII packages for the Device Manager failed to be registered.
145
146 **/
147 EFI_STATUS
148 InitializeDeviceManager (
149 VOID
150 )
151 {
152 EFI_STATUS Status;
153
154 //
155 // Install Device Path Protocol and Config Access protocol to driver handle
156 //
157 Status = gBS->InstallMultipleProtocolInterfaces (
158 &gDeviceManagerPrivate.DriverHandle,
159 &gEfiDevicePathProtocolGuid,
160 &mDeviceManagerHiiVendorDevicePath,
161 &gEfiHiiConfigAccessProtocolGuid,
162 &gDeviceManagerPrivate.ConfigAccess,
163 NULL
164 );
165 ASSERT_EFI_ERROR (Status);
166
167 Status = gBS->InstallMultipleProtocolInterfaces (
168 &gDeviceManagerPrivate.DriverHealthHandle,
169 &gEfiDevicePathProtocolGuid,
170 &mDriverHealthHiiVendorDevicePath,
171 &gEfiHiiConfigAccessProtocolGuid,
172 &gDeviceManagerPrivate.DriverHealthConfigAccess,
173 NULL
174 );
175 ASSERT_EFI_ERROR (Status);
176
177 //
178 // Publish our HII data
179 //
180 gDeviceManagerPrivate.HiiHandle = HiiAddPackages (
181 &mDeviceManagerGuid,
182 gDeviceManagerPrivate.DriverHandle,
183 DeviceManagerVfrBin,
184 BdsDxeStrings,
185 NULL
186 );
187 if (gDeviceManagerPrivate.HiiHandle == NULL) {
188 return EFI_OUT_OF_RESOURCES;
189 } else {
190 Status = EFI_SUCCESS;
191 }
192
193 //
194 // Publish Driver Health HII data
195 //
196 gDeviceManagerPrivate.DriverHealthHiiHandle = HiiAddPackages (
197 &mDeviceManagerGuid,
198 gDeviceManagerPrivate.DriverHealthHandle,
199 DriverHealthVfrBin,
200 BdsDxeStrings,
201 NULL
202 );
203 if (gDeviceManagerPrivate.DriverHealthHiiHandle == NULL) {
204 Status = EFI_OUT_OF_RESOURCES;
205 } else {
206 Status = EFI_SUCCESS;
207 }
208
209 return Status;
210 }
211
212 /**
213 Extract the displayed formset for given HII handle and class guid.
214
215 @param Handle The HII handle.
216 @param SetupClassGuid The class guid specifies which form set will be displayed.
217 @param FormSetTitle Formset title string.
218 @param FormSetHelp Formset help string.
219
220 @retval TRUE The formset for given HII handle will be displayed.
221 @return FALSE The formset for given HII handle will not be displayed.
222
223 **/
224 BOOLEAN
225 ExtractDisplayedHiiFormFromHiiHandle (
226 IN EFI_HII_HANDLE Handle,
227 IN EFI_GUID *SetupClassGuid,
228 OUT EFI_STRING_ID *FormSetTitle,
229 OUT EFI_STRING_ID *FormSetHelp
230 )
231 {
232 EFI_STATUS Status;
233 UINTN BufferSize;
234 EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList;
235 UINT8 *Package;
236 UINT8 *OpCodeData;
237 UINT32 Offset;
238 UINT32 Offset2;
239 UINT32 PackageListLength;
240 EFI_HII_PACKAGE_HEADER PackageHeader;
241 EFI_GUID *ClassGuid;
242 UINT8 ClassGuidNum;
243
244 ASSERT (Handle != NULL);
245 ASSERT (SetupClassGuid != NULL);
246 ASSERT (FormSetTitle != NULL);
247 ASSERT (FormSetHelp != NULL);
248
249 *FormSetTitle = 0;
250 *FormSetHelp = 0;
251 ClassGuidNum = 0;
252 ClassGuid = NULL;
253
254 //
255 // Get HII PackageList
256 //
257 BufferSize = 0;
258 HiiPackageList = NULL;
259 Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, Handle, &BufferSize, HiiPackageList);
260 //
261 // Handle is a invalid handle. Check if Handle is corrupted.
262 //
263 ASSERT (Status != EFI_NOT_FOUND);
264 //
265 // The return status should always be EFI_BUFFER_TOO_SMALL as input buffer's size is 0.
266 //
267 ASSERT (Status == EFI_BUFFER_TOO_SMALL);
268
269 HiiPackageList = AllocatePool (BufferSize);
270 ASSERT (HiiPackageList != NULL);
271
272 Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, Handle, &BufferSize, HiiPackageList);
273 if (EFI_ERROR (Status)) {
274 return FALSE;
275 }
276
277 //
278 // Get Form package from this HII package List
279 //
280 Offset = sizeof (EFI_HII_PACKAGE_LIST_HEADER);
281 Offset2 = 0;
282 PackageListLength = ReadUnaligned32 (&HiiPackageList->PackageLength);
283
284 while (Offset < PackageListLength) {
285 Package = ((UINT8 *) HiiPackageList) + Offset;
286 CopyMem (&PackageHeader, Package, sizeof (EFI_HII_PACKAGE_HEADER));
287
288 if (PackageHeader.Type == EFI_HII_PACKAGE_FORMS) {
289 //
290 // Search FormSet Opcode in this Form Package
291 //
292 Offset2 = sizeof (EFI_HII_PACKAGE_HEADER);
293 while (Offset2 < PackageHeader.Length) {
294 OpCodeData = Package + Offset2;
295
296 if (((EFI_IFR_OP_HEADER *) OpCodeData)->OpCode == EFI_IFR_FORM_SET_OP) {
297 if (((EFI_IFR_OP_HEADER *) OpCodeData)->Length > OFFSET_OF (EFI_IFR_FORM_SET, Flags)) {
298 //
299 // Find FormSet OpCode
300 //
301 ClassGuidNum = (UINT8) (((EFI_IFR_FORM_SET *) OpCodeData)->Flags & 0x3);
302 ClassGuid = (EFI_GUID *) (VOID *)(OpCodeData + sizeof (EFI_IFR_FORM_SET));
303 while (ClassGuidNum-- > 0) {
304 if (CompareGuid (SetupClassGuid, ClassGuid)) {
305 CopyMem (FormSetTitle, &((EFI_IFR_FORM_SET *) OpCodeData)->FormSetTitle, sizeof (EFI_STRING_ID));
306 CopyMem (FormSetHelp, &((EFI_IFR_FORM_SET *) OpCodeData)->Help, sizeof (EFI_STRING_ID));
307 FreePool (HiiPackageList);
308 return TRUE;
309 }
310 ClassGuid ++;
311 }
312 } else {
313 CopyMem (FormSetTitle, &((EFI_IFR_FORM_SET *) OpCodeData)->FormSetTitle, sizeof (EFI_STRING_ID));
314 CopyMem (FormSetHelp, &((EFI_IFR_FORM_SET *) OpCodeData)->Help, sizeof (EFI_STRING_ID));
315 FreePool (HiiPackageList);
316 return TRUE;
317 }
318 }
319
320 //
321 // Go to next opcode
322 //
323 Offset2 += ((EFI_IFR_OP_HEADER *) OpCodeData)->Length;
324 }
325 }
326
327 //
328 // Go to next package
329 //
330 Offset += PackageHeader.Length;
331 }
332
333 FreePool (HiiPackageList);
334
335 return FALSE;
336 }
337
338 /**
339 Call the browser and display the device manager to allow user
340 to configure the platform.
341
342 This function create the dynamic content for device manager. It includes
343 section header for all class of devices, one-of opcode to set VBIOS.
344
345 @retval EFI_SUCCESS Operation is successful.
346 @return Other values if failed to clean up the dynamic content from HII
347 database.
348
349 **/
350 EFI_STATUS
351 CallDeviceManager (
352 VOID
353 )
354 {
355 EFI_STATUS Status;
356 UINTN Index;
357 EFI_STRING String;
358 EFI_STRING_ID Token;
359 EFI_STRING_ID TokenHelp;
360 EFI_HII_HANDLE *HiiHandles;
361 EFI_HII_HANDLE HiiHandle;
362 EFI_STRING_ID FormSetTitle;
363 EFI_STRING_ID FormSetHelp;
364 EFI_BROWSER_ACTION_REQUEST ActionRequest;
365 VOID *StartOpCodeHandle;
366 VOID *EndOpCodeHandle;
367 EFI_IFR_GUID_LABEL *StartLabel;
368 EFI_IFR_GUID_LABEL *EndLabel;
369 UINTN NumHandles;
370 EFI_HANDLE *DriverHealthHandles;
371
372 HiiHandles = NULL;
373 Status = EFI_SUCCESS;
374 gCallbackKey = 0;
375 NumHandles = 0;
376 DriverHealthHandles = NULL;
377
378 //
379 // Connect all prior to entering the platform setup menu.
380 //
381 if (!gConnectAllHappened) {
382 BdsLibConnectAllDriversToAllControllers ();
383 gConnectAllHappened = TRUE;
384 }
385 //
386 // Create Subtitle OpCodes
387 //
388 //
389 // Allocate space for creation of UpdateData Buffer
390 //
391 StartOpCodeHandle = HiiAllocateOpCodeHandle ();
392 ASSERT (StartOpCodeHandle != NULL);
393
394 EndOpCodeHandle = HiiAllocateOpCodeHandle ();
395 ASSERT (EndOpCodeHandle != NULL);
396
397 //
398 // Create Hii Extend Label OpCode as the start opcode
399 //
400 StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
401 StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
402 StartLabel->Number = LABEL_DEVICES_LIST;
403
404 //
405 // Create Hii Extend Label OpCode as the end opcode
406 //
407 EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
408 EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
409 EndLabel->Number = LABEL_END;
410
411 HiiCreateSubTitleOpCode (StartOpCodeHandle, STRING_TOKEN (STR_DEVICES_LIST), 0, 0, 1);
412
413 //
414 // Get all the Hii handles
415 //
416 HiiHandles = HiiGetHiiHandles (NULL);
417 ASSERT (HiiHandles != NULL);
418
419 HiiHandle = gDeviceManagerPrivate.HiiHandle;
420
421 //
422 // Search for formset of each class type
423 //
424 for (Index = 0; HiiHandles[Index] != NULL; Index++) {
425 if (!ExtractDisplayedHiiFormFromHiiHandle (HiiHandles[Index], &gEfiHiiPlatformSetupFormsetGuid, &FormSetTitle, &FormSetHelp)) {
426 continue;
427 }
428
429 String = HiiGetString (HiiHandles[Index], FormSetTitle, NULL);
430 if (String == NULL) {
431 String = HiiGetString (HiiHandle, STR_MISSING_STRING, NULL);
432 ASSERT (String != NULL);
433 }
434 Token = HiiSetString (HiiHandle, 0, String, NULL);
435 FreePool (String);
436
437 String = HiiGetString (HiiHandles[Index], FormSetHelp, NULL);
438 if (String == NULL) {
439 String = HiiGetString (HiiHandle, STR_MISSING_STRING, NULL);
440 ASSERT (String != NULL);
441 }
442 TokenHelp = HiiSetString (HiiHandle, 0, String, NULL);
443 FreePool (String);
444
445 HiiCreateActionOpCode (
446 StartOpCodeHandle,
447 (EFI_QUESTION_ID) (Index + DEVICE_KEY_OFFSET),
448 Token,
449 TokenHelp,
450 EFI_IFR_FLAG_CALLBACK,
451 0
452 );
453 }
454
455 //
456 // Add End Opcode for Subtitle
457 //
458 HiiCreateEndOpCode (StartOpCodeHandle);
459
460 Status = gBS->LocateHandleBuffer (
461 ByProtocol,
462 &gEfiDriverHealthProtocolGuid,
463 NULL,
464 &NumHandles,
465 &DriverHealthHandles
466 );
467
468 //
469 // If there are no drivers installed driver health protocol, do not create driver health entry in UI
470 //
471 if (NumHandles != 0) {
472 //
473 // If driver health protocol is installed, create Driver Health subtitle and entry
474 //
475 HiiCreateSubTitleOpCode (StartOpCodeHandle, STRING_TOKEN (STR_DM_DRIVER_HEALTH_TITLE), 0, 0, 0);
476 HiiCreateActionOpCode (
477 StartOpCodeHandle, // Container for dynamic created opcodes
478 DEVICE_MANAGER_KEY_DRIVER_HEALTH, // Question ID
479 STRING_TOKEN(STR_DRIVER_HEALTH_ALL_HEALTHY), // Prompt text
480 STRING_TOKEN(STR_DRIVER_HEALTH_STATUS_HELP), // Help text
481 EFI_IFR_FLAG_CALLBACK, // Question flag
482 0 // Action String ID
483 );
484
485 //
486 // Check All Driver health status
487 //
488 if (!PlaformHealthStatusCheck ()) {
489 //
490 // At least one driver in the platform are not in healthy status
491 //
492 HiiSetString (HiiHandle, STRING_TOKEN (STR_DRIVER_HEALTH_ALL_HEALTHY), GetStringById (STRING_TOKEN (STR_DRIVER_NOT_HEALTH)), NULL);
493 } else {
494 //
495 // For the string of STR_DRIVER_HEALTH_ALL_HEALTHY previously has been updated and we need to update it while re-entry.
496 //
497 HiiSetString (HiiHandle, STRING_TOKEN (STR_DRIVER_HEALTH_ALL_HEALTHY), GetStringById (STRING_TOKEN (STR_DRIVER_HEALTH_ALL_HEALTHY)), NULL);
498 }
499 }
500
501 HiiUpdateForm (
502 HiiHandle,
503 &mDeviceManagerGuid,
504 DEVICE_MANAGER_FORM_ID,
505 StartOpCodeHandle,
506 EndOpCodeHandle
507 );
508
509 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
510 Status = gFormBrowser2->SendForm (
511 gFormBrowser2,
512 &HiiHandle,
513 1,
514 &mDeviceManagerGuid,
515 0,
516 NULL,
517 &ActionRequest
518 );
519 if (ActionRequest == EFI_BROWSER_ACTION_REQUEST_RESET) {
520 EnableResetRequired ();
521 }
522
523 //
524 // We will have returned from processing a callback - user either hit ESC to exit, or selected
525 // a target to display
526 //
527 if ((gCallbackKey != 0) && (gCallbackKey != DEVICE_MANAGER_KEY_DRIVER_HEALTH)) {
528 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
529 Status = gFormBrowser2->SendForm (
530 gFormBrowser2,
531 &HiiHandles[gCallbackKey - DEVICE_KEY_OFFSET],
532 1,
533 NULL,
534 0,
535 NULL,
536 &ActionRequest
537 );
538
539 if (ActionRequest == EFI_BROWSER_ACTION_REQUEST_RESET) {
540 EnableResetRequired ();
541 }
542
543 //
544 // Force return to Device Manager
545 //
546 gCallbackKey = FRONT_PAGE_KEY_DEVICE_MANAGER;
547 }
548
549 //
550 // Driver Health item chose.
551 //
552 if (gCallbackKey == DEVICE_MANAGER_KEY_DRIVER_HEALTH) {
553 CallDriverHealth ();
554 //
555 // Force return to Device Manager
556 //
557 gCallbackKey = FRONT_PAGE_KEY_DEVICE_MANAGER;
558 }
559
560 //
561 // Cleanup dynamic created strings in HII database by reinstall the packagelist
562 //
563 HiiRemovePackages (HiiHandle);
564
565 gDeviceManagerPrivate.HiiHandle = HiiAddPackages (
566 &mDeviceManagerGuid,
567 gDeviceManagerPrivate.DriverHandle,
568 DeviceManagerVfrBin,
569 BdsDxeStrings,
570 NULL
571 );
572 if (gDeviceManagerPrivate.HiiHandle == NULL) {
573 Status = EFI_OUT_OF_RESOURCES;
574 } else {
575 Status = EFI_SUCCESS;
576 }
577
578 HiiFreeOpCodeHandle (StartOpCodeHandle);
579 HiiFreeOpCodeHandle (EndOpCodeHandle);
580 FreePool (HiiHandles);
581
582 return Status;
583 }
584
585 /**
586 This function is invoked if user selected a interactive opcode from Driver Health's
587 Formset. The decision by user is saved to gCallbackKey for later processing.
588
589 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
590 @param Action Specifies the type of action taken by the browser.
591 @param QuestionId A unique value which is sent to the original exporting driver
592 so that it can identify the type of data to expect.
593 @param Type The type of value for the question.
594 @param Value A pointer to the data being sent to the original exporting driver.
595 @param ActionRequest On return, points to the action requested by the callback function.
596
597 @retval EFI_SUCCESS The callback successfully handled the action.
598 @retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.
599
600 **/
601 EFI_STATUS
602 EFIAPI
603 DriverHealthCallback (
604 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
605 IN EFI_BROWSER_ACTION Action,
606 IN EFI_QUESTION_ID QuestionId,
607 IN UINT8 Type,
608 IN EFI_IFR_TYPE_VALUE *Value,
609 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
610 )
611 {
612 if ((Value == NULL) || (ActionRequest == NULL)) {
613 return EFI_INVALID_PARAMETER;
614 }
615
616 gCallbackKey = QuestionId;
617
618 //
619 // Request to exit SendForm(), so as to switch to selected form
620 //
621 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;
622
623 return EFI_SUCCESS;
624 }
625
626 /**
627 Collect and display the platform's driver health relative information, allow user to do interactive
628 operation while the platform is unhealthy.
629
630 This function display a form which divided into two parts. The one list all modules which has installed
631 driver health protocol. The list usually contain driver name, controller name, and it's health info.
632 While the driver name can't be retrieved, will use device path as backup. The other part of the form provide
633 a choice to the user to repair all platform.
634
635 **/
636 VOID
637 CallDriverHealth (
638 VOID
639 )
640 {
641 EFI_STATUS Status;
642 EFI_HII_HANDLE HiiHandle;
643 EFI_BROWSER_ACTION_REQUEST ActionRequest;
644 EFI_IFR_GUID_LABEL *StartLabel;
645 EFI_IFR_GUID_LABEL *StartLabelRepair;
646 EFI_IFR_GUID_LABEL *EndLabel;
647 EFI_IFR_GUID_LABEL *EndLabelRepair;
648 VOID *StartOpCodeHandle;
649 VOID *EndOpCodeHandle;
650 VOID *StartOpCodeHandleRepair;
651 VOID *EndOpCodeHandleRepair;
652 UINTN Index;
653 EFI_STRING_ID Token;
654 EFI_STRING_ID TokenHelp;
655 EFI_STRING String;
656 EFI_STRING TmpString;
657 EFI_STRING DriverName;
658 EFI_STRING ControllerName;
659 LIST_ENTRY DriverHealthList;
660 DRIVER_HEALTH_INFO *DriverHealthInfo;
661 LIST_ENTRY *Link;
662 EFI_DEVICE_PATH_PROTOCOL *DriverDevicePath;
663 UINTN Length;
664
665 HiiHandle = gDeviceManagerPrivate.DriverHealthHiiHandle;
666 Index = 0;
667 Length = 0;
668 DriverHealthInfo = NULL;
669 DriverDevicePath = NULL;
670 InitializeListHead (&DriverHealthList);
671
672 //
673 // Allocate space for creation of UpdateData Buffer
674 //
675 StartOpCodeHandle = HiiAllocateOpCodeHandle ();
676 ASSERT (StartOpCodeHandle != NULL);
677
678 EndOpCodeHandle = HiiAllocateOpCodeHandle ();
679 ASSERT (EndOpCodeHandle != NULL);
680
681 StartOpCodeHandleRepair = HiiAllocateOpCodeHandle ();
682 ASSERT (StartOpCodeHandleRepair != NULL);
683
684 EndOpCodeHandleRepair = HiiAllocateOpCodeHandle ();
685 ASSERT (EndOpCodeHandleRepair != NULL);
686
687 //
688 // Create Hii Extend Label OpCode as the start opcode
689 //
690 StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
691 StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
692 StartLabel->Number = LABEL_DRIVER_HEALTH;
693
694 //
695 // Create Hii Extend Label OpCode as the start opcode
696 //
697 StartLabelRepair = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandleRepair, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
698 StartLabelRepair->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
699 StartLabelRepair->Number = LABEL_DRIVER_HEALTH_REAPIR_ALL;
700
701 //
702 // Create Hii Extend Label OpCode as the end opcode
703 //
704 EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
705 EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
706 EndLabel->Number = LABEL_DRIVER_HEALTH_END;
707
708 //
709 // Create Hii Extend Label OpCode as the end opcode
710 //
711 EndLabelRepair = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandleRepair, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
712 EndLabelRepair->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
713 EndLabelRepair->Number = LABEL_DRIVER_HEALTH_REAPIR_ALL_END;
714
715 HiiCreateSubTitleOpCode (StartOpCodeHandle, STRING_TOKEN (STR_DH_STATUS_LIST), 0, 0, 1);
716
717 Status = GetAllControllersHealthStatus (&DriverHealthList);
718 ASSERT (Status != EFI_OUT_OF_RESOURCES);
719
720 Link = GetFirstNode (&DriverHealthList);
721
722 while (!IsNull (&DriverHealthList, Link)) {
723 DriverHealthInfo = DEVICE_MANAGER_HEALTH_INFO_FROM_LINK (Link);
724
725 //
726 // Assume no line strings is longer than 512 bytes.
727 //
728 String = (EFI_STRING) AllocateZeroPool (0x200);
729 ASSERT (String != NULL);
730
731 Status = DriverHealthGetDriverName (DriverHealthInfo->DriverHandle, &DriverName);
732 if (EFI_ERROR (Status)) {
733 //
734 // Can not get the Driver name, so use the Device path
735 //
736 DriverDevicePath = DevicePathFromHandle (DriverHealthInfo->DriverHandle);
737 DriverName = DevicePathToStr (DriverDevicePath);
738 }
739 //
740 // Add the Driver name & Controller name into FormSetTitle string
741 //
742 StrnCat (String, DriverName, StrLen (DriverName));
743
744
745 Status = DriverHealthGetControllerName (
746 DriverHealthInfo->DriverHandle,
747 DriverHealthInfo->ControllerHandle,
748 DriverHealthInfo->ChildHandle,
749 &ControllerName
750 );
751
752 if (!EFI_ERROR (Status)) {
753 //
754 // Can not get the Controller name, just let it empty.
755 //
756 StrnCat (String, L" ", StrLen (L" "));
757 StrnCat (String, ControllerName, StrLen (ControllerName));
758 }
759
760 //
761 // Add the message of the Module itself provided after the string item.
762 //
763 if ((DriverHealthInfo->MessageList != NULL) && (DriverHealthInfo->MessageList->StringId != 0)) {
764 StrnCat (String, L" ", StrLen (L" "));
765 TmpString = HiiGetString (
766 DriverHealthInfo->MessageList->HiiHandle,
767 DriverHealthInfo->MessageList->StringId,
768 NULL
769 );
770 //
771 // Assert if can not retrieve the message string
772 //
773 ASSERT (TmpString != NULL);
774 StrnCat (String, TmpString, StrLen (TmpString));
775 FreePool (TmpString);
776 } else {
777 //
778 // Update the string will be displayed base on the driver's health status
779 //
780 switch(DriverHealthInfo->HealthStatus) {
781 case EfiDriverHealthStatusRepairRequired:
782 Length = StrLen (GetStringById (STRING_TOKEN (STR_REPAIR_REQUIRED)));
783 StrnCat (String, GetStringById (STRING_TOKEN (STR_REPAIR_REQUIRED)), Length);
784 break;
785 case EfiDriverHealthStatusConfigurationRequired:
786 Length = StrLen (GetStringById (STRING_TOKEN (STR_CONFIGURATION_REQUIRED)));
787 StrnCat (String, GetStringById (STRING_TOKEN (STR_CONFIGURATION_REQUIRED)), Length);
788 break;
789 case EfiDriverHealthStatusFailed:
790 Length = StrLen (GetStringById (STRING_TOKEN (STR_OPERATION_FAILED)));
791 StrnCat (String, GetStringById (STRING_TOKEN (STR_OPERATION_FAILED)), Length);
792 break;
793 case EfiDriverHealthStatusReconnectRequired:
794 Length = StrLen (GetStringById (STRING_TOKEN (STR_RECONNECT_REQUIRED)));
795 StrnCat (String, GetStringById (STRING_TOKEN (STR_RECONNECT_REQUIRED)), Length);
796 break;
797 case EfiDriverHealthStatusRebootRequired:
798 Length = StrLen (GetStringById (STRING_TOKEN (STR_REBOOT_REQUIRED)));
799 StrnCat (String, GetStringById (STRING_TOKEN (STR_REBOOT_REQUIRED)), Length);
800 break;
801 default:
802 Length = StrLen (GetStringById (STRING_TOKEN (STR_DRIVER_HEALTH_HEALTHY)));
803 StrnCat (String, GetStringById (STRING_TOKEN (STR_DRIVER_HEALTH_HEALTHY)), Length);
804 break;
805 }
806 }
807
808 Token = HiiSetString (HiiHandle, 0, String, NULL);
809 FreePool (String);
810
811 TokenHelp = HiiSetString (HiiHandle, 0, GetStringById( STRING_TOKEN (STR_DH_REPAIR_SINGLE_HELP)), NULL);
812
813 HiiCreateActionOpCode (
814 StartOpCodeHandle,
815 (EFI_QUESTION_ID) (Index + DRIVER_HEALTH_KEY_OFFSET),
816 Token,
817 TokenHelp,
818 EFI_IFR_FLAG_CALLBACK,
819 0
820 );
821 Index++;
822 Link = GetNextNode (&DriverHealthList, Link);
823 }
824
825 //
826 // Add End Opcode for Subtitle
827 //
828 HiiCreateEndOpCode (StartOpCodeHandle);
829
830 HiiCreateSubTitleOpCode (StartOpCodeHandleRepair, STRING_TOKEN (STR_DRIVER_HEALTH_REPAIR_ALL), 0, 0, 1);
831 TokenHelp = HiiSetString (HiiHandle, 0, GetStringById( STRING_TOKEN (STR_DH_REPAIR_ALL_HELP)), NULL);
832
833 if (PlaformHealthStatusCheck ()) {
834 //
835 // No action need to do for the platform
836 //
837 Token = HiiSetString (HiiHandle, 0, GetStringById( STRING_TOKEN (STR_DRIVER_HEALTH_ALL_HEALTHY)), NULL);
838 HiiCreateActionOpCode (
839 StartOpCodeHandleRepair,
840 0,
841 Token,
842 TokenHelp,
843 EFI_IFR_FLAG_READ_ONLY,
844 0
845 );
846 } else {
847 //
848 // Create ActionOpCode only while the platform need to do health related operation.
849 //
850 Token = HiiSetString (HiiHandle, 0, GetStringById( STRING_TOKEN (STR_DH_REPAIR_ALL_TITLE)), NULL);
851 HiiCreateActionOpCode (
852 StartOpCodeHandleRepair,
853 (EFI_QUESTION_ID) DRIVER_HEALTH_REPAIR_ALL_KEY,
854 Token,
855 TokenHelp,
856 EFI_IFR_FLAG_CALLBACK,
857 0
858 );
859 }
860
861 HiiCreateEndOpCode (StartOpCodeHandleRepair);
862
863 Status = HiiUpdateForm (
864 HiiHandle,
865 &mDriverHealthGuid,
866 DRIVER_HEALTH_FORM_ID,
867 StartOpCodeHandle,
868 EndOpCodeHandle
869 );
870 ASSERT (Status != EFI_NOT_FOUND);
871 ASSERT (Status != EFI_BUFFER_TOO_SMALL);
872
873 Status = HiiUpdateForm (
874 HiiHandle,
875 &mDriverHealthGuid,
876 DRIVER_HEALTH_FORM_ID,
877 StartOpCodeHandleRepair,
878 EndOpCodeHandleRepair
879 );
880 ASSERT (Status != EFI_NOT_FOUND);
881 ASSERT (Status != EFI_BUFFER_TOO_SMALL);
882
883 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
884 Status = gFormBrowser2->SendForm (
885 gFormBrowser2,
886 &HiiHandle,
887 1,
888 &mDriverHealthGuid,
889 DRIVER_HEALTH_FORM_ID,
890 NULL,
891 &ActionRequest
892 );
893 if (ActionRequest == EFI_BROWSER_ACTION_REQUEST_RESET) {
894 EnableResetRequired ();
895 }
896
897 //
898 // We will have returned from processing a callback - user either hit ESC to exit, or selected
899 // a target to display.
900 // Process the diver health status states here.
901 //
902 if (gCallbackKey >= DRIVER_HEALTH_KEY_OFFSET && gCallbackKey != DRIVER_HEALTH_REPAIR_ALL_KEY) {
903 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
904
905 Link = GetFirstNode (&DriverHealthList);
906 Index = 0;
907
908 while (!IsNull (&DriverHealthList, Link)) {
909 //
910 // Got the item relative node in the List
911 //
912 if (Index == (gCallbackKey - DRIVER_HEALTH_KEY_OFFSET)) {
913 DriverHealthInfo = DEVICE_MANAGER_HEALTH_INFO_FROM_LINK (Link);
914 //
915 // Process the driver's healthy status for the specify module
916 //
917 ProcessSingleControllerHealth (
918 DriverHealthInfo->DriverHealth,
919 DriverHealthInfo->ControllerHandle,
920 DriverHealthInfo->ChildHandle,
921 DriverHealthInfo->HealthStatus,
922 &(DriverHealthInfo->MessageList),
923 DriverHealthInfo->HiiHandle
924 );
925 break;
926 }
927 Index++;
928 Link = GetNextNode (&DriverHealthList, Link);
929 }
930
931 if (ActionRequest == EFI_BROWSER_ACTION_REQUEST_RESET) {
932 EnableResetRequired ();
933 }
934
935 //
936 // Force return to the form of Driver Health in Device Manager
937 //
938 gCallbackKey = DRIVER_HEALTH_RETURN_KEY;
939 }
940
941 //
942 // Repair the whole platform
943 //
944 if (gCallbackKey == DRIVER_HEALTH_REPAIR_ALL_KEY) {
945 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
946
947 PlatformRepairAll (&DriverHealthList);
948
949 gCallbackKey = DRIVER_HEALTH_RETURN_KEY;
950 }
951
952 //
953 // Cleanup dynamic created strings in HII database by reinstall the packagelist
954 //
955
956 HiiRemovePackages (HiiHandle);
957
958 gDeviceManagerPrivate.DriverHealthHiiHandle = HiiAddPackages (
959 &mDriverHealthGuid,
960 gDeviceManagerPrivate.DriverHealthHandle,
961 DriverHealthVfrBin,
962 BdsDxeStrings,
963 NULL
964 );
965 if (gDeviceManagerPrivate.DriverHealthHiiHandle == NULL) {
966 Status = EFI_OUT_OF_RESOURCES;
967 } else {
968 Status = EFI_SUCCESS;
969 }
970 //
971 // Free driver health info list
972 //
973 while (!IsListEmpty (&DriverHealthList)) {
974
975 Link = GetFirstNode(&DriverHealthList);
976 DriverHealthInfo = DEVICE_MANAGER_HEALTH_INFO_FROM_LINK (Link);
977 RemoveEntryList (Link);
978
979 if (DriverHealthInfo->MessageList != NULL) {
980 FreePool(DriverHealthInfo->MessageList);
981 FreePool (DriverHealthInfo);
982 }
983 }
984
985 HiiFreeOpCodeHandle (StartOpCodeHandle);
986 HiiFreeOpCodeHandle (EndOpCodeHandle);
987 HiiFreeOpCodeHandle (StartOpCodeHandleRepair);
988 HiiFreeOpCodeHandle (EndOpCodeHandleRepair);
989
990 if (gCallbackKey == DRIVER_HEALTH_RETURN_KEY) {
991 //
992 // Force return to Driver Health Form
993 //
994 gCallbackKey = DEVICE_MANAGER_KEY_DRIVER_HEALTH;
995 CallDriverHealth ();
996 }
997 }
998
999
1000 /**
1001 Check the Driver Health status of a single controller and try to process it if not healthy.
1002
1003 This function called by CheckAllControllersHealthStatus () function in order to process a specify
1004 contoller's health state.
1005
1006 @param DriverHealthList A Pointer to the list contain all of the platform driver health information.
1007 @param DriverHandle The handle of driver.
1008 @param ControllerHandle The class guid specifies which form set will be displayed.
1009 @param ChildHandle The handle of the child controller to retrieve the health
1010 status on. This is an optional parameter that may be NULL.
1011 @param DriverHealth A pointer to the EFI_DRIVER_HEALTH_PROTOCOL instance.
1012 @param HealthStatus The health status of the controller.
1013
1014 @retval EFI_INVALID_PARAMETER HealthStatus or DriverHealth is NULL.
1015 @retval HealthStatus The Health status of specify controller.
1016 @retval EFI_OUT_OF_RESOURCES The list of Driver Health Protocol handles can not be retrieved.
1017 @retval EFI_NOT_FOUND No controller in the platform install Driver Health Protocol.
1018 @retval EFI_SUCCESS The Health related operation has been taken successfully.
1019
1020 **/
1021 EFI_STATUS
1022 EFIAPI
1023 GetSingleControllerHealthStatus (
1024 IN OUT LIST_ENTRY *DriverHealthList,
1025 IN EFI_HANDLE DriverHandle,
1026 IN EFI_HANDLE ControllerHandle, OPTIONAL
1027 IN EFI_HANDLE ChildHandle, OPTIONAL
1028 IN EFI_DRIVER_HEALTH_PROTOCOL *DriverHealth,
1029 IN EFI_DRIVER_HEALTH_STATUS *HealthStatus
1030 )
1031 {
1032 EFI_STATUS Status;
1033 EFI_DRIVER_HEALTH_HII_MESSAGE *MessageList;
1034 EFI_HII_HANDLE FormHiiHandle;
1035 DRIVER_HEALTH_INFO *DriverHealthInfo;
1036
1037 if (HealthStatus == NULL) {
1038 //
1039 // If HealthStatus is NULL, then return EFI_INVALID_PARAMETER
1040 //
1041 return EFI_INVALID_PARAMETER;
1042 }
1043
1044 //
1045 // Assume the HealthStatus is healthy
1046 //
1047 *HealthStatus = EfiDriverHealthStatusHealthy;
1048
1049 if (DriverHealth == NULL) {
1050 //
1051 // If DriverHealth is NULL, then return EFI_INVALID_PARAMETER
1052 //
1053 return EFI_INVALID_PARAMETER;
1054 }
1055
1056 if (ControllerHandle == NULL) {
1057 //
1058 // If ControllerHandle is NULL, the return the cumulative health status of the driver
1059 //
1060 Status = DriverHealth->GetHealthStatus (DriverHealth, NULL, NULL, HealthStatus, NULL, NULL);
1061 if (*HealthStatus == EfiDriverHealthStatusHealthy) {
1062 //
1063 // Add the driver health related information into the list
1064 //
1065 DriverHealthInfo = AllocateZeroPool (sizeof (DRIVER_HEALTH_INFO));
1066 if (DriverHealthInfo == NULL) {
1067 return EFI_OUT_OF_RESOURCES;
1068 }
1069
1070 DriverHealthInfo->Signature = DEVICE_MANAGER_DRIVER_HEALTH_INFO_SIGNATURE;
1071 DriverHealthInfo->DriverHandle = DriverHandle;
1072 DriverHealthInfo->ControllerHandle = NULL;
1073 DriverHealthInfo->ChildHandle = NULL;
1074 DriverHealthInfo->HiiHandle = NULL;
1075 DriverHealthInfo->DriverHealth = DriverHealth;
1076 DriverHealthInfo->MessageList = NULL;
1077 DriverHealthInfo->HealthStatus = *HealthStatus;
1078
1079 InsertTailList (DriverHealthList, &DriverHealthInfo->Link);
1080 }
1081 return Status;
1082 }
1083
1084 MessageList = NULL;
1085 FormHiiHandle = NULL;
1086
1087 //
1088 // Collect the health status with the optional HII message list
1089 //
1090 Status = DriverHealth->GetHealthStatus (DriverHealth, ControllerHandle, ChildHandle, HealthStatus, &MessageList, &FormHiiHandle);
1091
1092 if (EFI_ERROR (Status)) {
1093 //
1094 // If the health status could not be retrieved, then return immediately
1095 //
1096 return Status;
1097 }
1098
1099 //
1100 // Add the driver health related information into the list
1101 //
1102 DriverHealthInfo = AllocateZeroPool (sizeof (DRIVER_HEALTH_INFO));
1103 if (DriverHealthInfo == NULL) {
1104 return EFI_OUT_OF_RESOURCES;
1105 }
1106
1107 DriverHealthInfo->Signature = DEVICE_MANAGER_DRIVER_HEALTH_INFO_SIGNATURE;
1108 DriverHealthInfo->DriverHandle = DriverHandle;
1109 DriverHealthInfo->ControllerHandle = ControllerHandle;
1110 DriverHealthInfo->ChildHandle = ChildHandle;
1111 DriverHealthInfo->HiiHandle = FormHiiHandle;
1112 DriverHealthInfo->DriverHealth = DriverHealth;
1113 DriverHealthInfo->MessageList = MessageList;
1114 DriverHealthInfo->HealthStatus = *HealthStatus;
1115
1116 InsertTailList (DriverHealthList, &DriverHealthInfo->Link);
1117
1118 return EFI_SUCCESS;
1119 }
1120
1121 /**
1122 Collects all the EFI Driver Health Protocols currently present in the EFI Handle Database,
1123 and queries each EFI Driver Health Protocol to determine if one or more of the controllers
1124 managed by each EFI Driver Health Protocol instance are not healthy.
1125
1126 @param DriverHealthList A Pointer to the list contain all of the platform driver health
1127 information.
1128
1129 @retval EFI_NOT_FOUND No controller in the platform install Driver Health Protocol.
1130 @retval EFI_SUCCESS All the controllers in the platform are healthy.
1131 @retval EFI_OUT_OF_RESOURCES The list of Driver Health Protocol handles can not be retrieved.
1132
1133 **/
1134 EFI_STATUS
1135 GetAllControllersHealthStatus (
1136 IN OUT LIST_ENTRY *DriverHealthList
1137 )
1138 {
1139 EFI_STATUS Status;
1140 UINTN NumHandles;
1141 EFI_HANDLE *DriverHealthHandles;
1142 EFI_DRIVER_HEALTH_PROTOCOL *DriverHealth;
1143 EFI_DRIVER_HEALTH_STATUS HealthStatus;
1144 UINTN DriverHealthIndex;
1145 EFI_HANDLE *Handles;
1146 UINTN HandleCount;
1147 UINTN ControllerIndex;
1148 UINTN ChildIndex;
1149
1150 //
1151 // Initialize local variables
1152 //
1153 Handles = NULL;
1154 DriverHealthHandles = NULL;
1155 NumHandles = 0;
1156 HandleCount = 0;
1157
1158 HealthStatus = EfiDriverHealthStatusHealthy;
1159
1160 Status = gBS->LocateHandleBuffer (
1161 ByProtocol,
1162 &gEfiDriverHealthProtocolGuid,
1163 NULL,
1164 &NumHandles,
1165 &DriverHealthHandles
1166 );
1167
1168 if (Status == EFI_NOT_FOUND || NumHandles == 0) {
1169 //
1170 // If there are no Driver Health Protocols handles, then return EFI_NOT_FOUND
1171 //
1172 return EFI_NOT_FOUND;
1173 }
1174
1175 if (EFI_ERROR (Status) || DriverHealthHandles == NULL) {
1176 //
1177 // If the list of Driver Health Protocol handles can not be retrieved, then
1178 // return EFI_OUT_OF_RESOURCES
1179 //
1180 return EFI_OUT_OF_RESOURCES;
1181 }
1182
1183 //
1184 // Check the health status of all controllers in the platform
1185 // Start by looping through all the Driver Health Protocol handles in the handle database
1186 //
1187 for (DriverHealthIndex = 0; DriverHealthIndex < NumHandles; DriverHealthIndex++) {
1188 //
1189 // Skip NULL Driver Health Protocol handles
1190 //
1191 if (DriverHealthHandles[DriverHealthIndex] == NULL) {
1192 continue;
1193 }
1194
1195 //
1196 // Retrieve the Driver Health Protocol from DriverHandle
1197 //
1198 Status = gBS->HandleProtocol (
1199 DriverHealthHandles[DriverHealthIndex],
1200 &gEfiDriverHealthProtocolGuid,
1201 (VOID **)&DriverHealth
1202 );
1203 if (EFI_ERROR (Status)) {
1204 //
1205 // If the Driver Health Protocol can not be retrieved, then skip to the next
1206 // Driver Health Protocol handle
1207 //
1208 continue;
1209 }
1210
1211 //
1212 // Check the health of all the controllers managed by a Driver Health Protocol handle
1213 //
1214 Status = GetSingleControllerHealthStatus (DriverHealthList, DriverHealthHandles[DriverHealthIndex], NULL, NULL, DriverHealth, &HealthStatus);
1215
1216 //
1217 // If Status is an error code, then the health information could not be retrieved, so assume healthy
1218 // and skip to the next Driver Health Protocol handle
1219 //
1220 if (EFI_ERROR (Status)) {
1221 continue;
1222 }
1223
1224 //
1225 // If all the controllers managed by this Driver Health Protocol are healthy, then skip to the next
1226 // Driver Health Protocol handle
1227 //
1228 if (HealthStatus == EfiDriverHealthStatusHealthy) {
1229 continue;
1230 }
1231
1232 //
1233 // See if the list of all handles in the handle database has been retrieved
1234 //
1235 //
1236 if (Handles == NULL) {
1237 //
1238 // Retrieve the list of all handles from the handle database
1239 //
1240 Status = gBS->LocateHandleBuffer (
1241 AllHandles,
1242 NULL,
1243 NULL,
1244 &HandleCount,
1245 &Handles
1246 );
1247 if (EFI_ERROR (Status) || Handles == NULL) {
1248 //
1249 // If all the handles in the handle database can not be retrieved, then
1250 // return EFI_OUT_OF_RESOURCES
1251 //
1252 Status = EFI_OUT_OF_RESOURCES;
1253 goto Done;
1254 }
1255 }
1256 //
1257 // Loop through all the controller handles in the handle database
1258 //
1259 for (ControllerIndex = 0; ControllerIndex < HandleCount; ControllerIndex++) {
1260 //
1261 // Skip NULL controller handles
1262 //
1263 if (Handles[ControllerIndex] == NULL) {
1264 continue;
1265 }
1266
1267 Status = GetSingleControllerHealthStatus (DriverHealthList, DriverHealthHandles[DriverHealthIndex], Handles[ControllerIndex], NULL, DriverHealth, &HealthStatus);
1268 if (EFI_ERROR (Status)) {
1269 //
1270 // If Status is an error code, then the health information could not be retrieved, so assume healthy
1271 //
1272 HealthStatus = EfiDriverHealthStatusHealthy;
1273 }
1274
1275 //
1276 // If CheckHealthSingleController() returned an error on a terminal state, then do not check the health of child controllers
1277 //
1278 if (EFI_ERROR (Status)) {
1279 continue;
1280 }
1281
1282 //
1283 // Loop through all the child handles in the handle database
1284 //
1285 for (ChildIndex = 0; ChildIndex < HandleCount; ChildIndex++) {
1286 //
1287 // Skip NULL child handles
1288 //
1289 if (Handles[ChildIndex] == NULL) {
1290 continue;
1291 }
1292
1293 Status = GetSingleControllerHealthStatus (DriverHealthList, DriverHealthHandles[DriverHealthIndex], Handles[ControllerIndex], Handles[ChildIndex], DriverHealth, &HealthStatus);
1294 if (EFI_ERROR (Status)) {
1295 //
1296 // If Status is an error code, then the health information could not be retrieved, so assume healthy
1297 //
1298 HealthStatus = EfiDriverHealthStatusHealthy;
1299 }
1300
1301 //
1302 // If CheckHealthSingleController() returned an error on a terminal state, then skip to the next child
1303 //
1304 if (EFI_ERROR (Status)) {
1305 continue;
1306 }
1307 }
1308 }
1309 }
1310
1311 Status = EFI_SUCCESS;
1312
1313 Done:
1314 if (Handles != NULL) {
1315 gBS->FreePool (Handles);
1316 }
1317 if (DriverHealthHandles != NULL) {
1318 gBS->FreePool (DriverHealthHandles);
1319 }
1320
1321 return Status;
1322 }
1323
1324
1325 /**
1326 Check the healthy status of the platform, this function will return immediately while found one driver
1327 in the platform are not healthy.
1328
1329 @retval FALSE at least one driver in the platform are not healthy.
1330 @retval TRUE No controller install Driver Health Protocol,
1331 or all controllers in the platform are in healthy status.
1332 **/
1333 BOOLEAN
1334 PlaformHealthStatusCheck (
1335 VOID
1336 )
1337 {
1338 EFI_DRIVER_HEALTH_STATUS HealthStatus;
1339 EFI_STATUS Status;
1340 UINTN Index;
1341 UINTN NoHandles;
1342 EFI_HANDLE *DriverHealthHandles;
1343 EFI_DRIVER_HEALTH_PROTOCOL *DriverHealth;
1344 BOOLEAN AllHealthy;
1345
1346 //
1347 // Initialize local variables
1348 //
1349 DriverHealthHandles = NULL;
1350 DriverHealth = NULL;
1351
1352 HealthStatus = EfiDriverHealthStatusHealthy;
1353
1354 Status = gBS->LocateHandleBuffer (
1355 ByProtocol,
1356 &gEfiDriverHealthProtocolGuid,
1357 NULL,
1358 &NoHandles,
1359 &DriverHealthHandles
1360 );
1361 //
1362 // There are no handles match the search for Driver Health Protocol has been installed.
1363 //
1364 if (Status == EFI_NOT_FOUND) {
1365 return TRUE;
1366 }
1367 //
1368 // Assume all modules are healthy.
1369 //
1370 AllHealthy = TRUE;
1371
1372 //
1373 // Found one or more Handles.
1374 //
1375 if (!EFI_ERROR (Status)) {
1376 for (Index = 0; Index < NoHandles; Index++) {
1377 Status = gBS->HandleProtocol (
1378 DriverHealthHandles[Index],
1379 &gEfiDriverHealthProtocolGuid,
1380 (VOID **) &DriverHealth
1381 );
1382 if (!EFI_ERROR (Status)) {
1383 Status = DriverHealth->GetHealthStatus (
1384 DriverHealth,
1385 NULL,
1386 NULL,
1387 &HealthStatus,
1388 NULL,
1389 NULL
1390 );
1391 }
1392 //
1393 // Get the healthy status of the module
1394 //
1395 if (!EFI_ERROR (Status)) {
1396 if (HealthStatus != EfiDriverHealthStatusHealthy) {
1397 //
1398 // Return immediately one driver's status not in healthy.
1399 //
1400 return FALSE;
1401 }
1402 }
1403 }
1404 }
1405 return AllHealthy;
1406 }
1407
1408 /**
1409 Processes a single controller using the EFI Driver Health Protocol associated with
1410 that controller. This algorithm continues to query the GetHealthStatus() service until
1411 one of the legal terminal states of the EFI Driver Health Protocol is reached. This may
1412 require the processing of HII Messages, HII Form, and invocation of repair operations.
1413
1414 @param DriverHealth A pointer to the EFI_DRIVER_HEALTH_PROTOCOL instance.
1415 @param ControllerHandle The class guid specifies which form set will be displayed.
1416 @param ChildHandle The handle of the child controller to retrieve the health
1417 status on. This is an optional parameter that may be NULL.
1418 @param HealthStatus The health status of the controller.
1419 @param MessageList An array of warning or error messages associated
1420 with the controller specified by ControllerHandle and
1421 ChildHandle. This is an optional parameter that may be NULL.
1422 @param FormHiiHandle The HII handle for an HII form associated with the
1423 controller specified by ControllerHandle and ChildHandle.
1424 **/
1425 VOID
1426 ProcessSingleControllerHealth (
1427 IN EFI_DRIVER_HEALTH_PROTOCOL *DriverHealth,
1428 IN EFI_HANDLE ControllerHandle, OPTIONAL
1429 IN EFI_HANDLE ChildHandle, OPTIONAL
1430 IN EFI_DRIVER_HEALTH_STATUS HealthStatus,
1431 IN EFI_DRIVER_HEALTH_HII_MESSAGE **MessageList, OPTIONAL
1432 IN EFI_HII_HANDLE FormHiiHandle
1433 )
1434 {
1435 EFI_STATUS Status;
1436 EFI_DRIVER_HEALTH_STATUS LocalHealthStatus;
1437
1438 LocalHealthStatus = HealthStatus;
1439 //
1440 // If the module need to be repaired or reconfiguration, will process it until
1441 // reach a terminal status. The status from EfiDriverHealthStatusRepairRequired after repair
1442 // will be in (Health, Failed, Configuration Required).
1443 //
1444 while( LocalHealthStatus == EfiDriverHealthStatusConfigurationRequired ||
1445 LocalHealthStatus == EfiDriverHealthStatusRepairRequired) {
1446
1447 if (LocalHealthStatus == EfiDriverHealthStatusRepairRequired) {
1448 Status = DriverHealth->Repair (
1449 DriverHealth,
1450 ControllerHandle,
1451 ChildHandle,
1452 (EFI_DRIVER_HEALTH_REPAIR_PROGRESS_NOTIFY) RepairNotify
1453 );
1454 }
1455 //
1456 // Via a form of the driver need to do configuration provided to process of status in
1457 // EfiDriverHealthStatusConfigurationRequired. The status after configuration should be in
1458 // (Healthy, Reboot Required, Failed, Reconnect Required, Repair Required).
1459 //
1460 if (LocalHealthStatus == EfiDriverHealthStatusConfigurationRequired) {
1461 Status = gFormBrowser2->SendForm (
1462 gFormBrowser2,
1463 &FormHiiHandle,
1464 1,
1465 &gEfiHiiDriverHealthFormsetGuid,
1466 0,
1467 NULL,
1468 NULL
1469 );
1470 ASSERT( !EFI_ERROR (Status));
1471 }
1472
1473 Status = DriverHealth->GetHealthStatus (
1474 DriverHealth,
1475 ControllerHandle,
1476 ChildHandle,
1477 &LocalHealthStatus,
1478 NULL,
1479 &FormHiiHandle
1480 );
1481 ASSERT_EFI_ERROR (Status);
1482
1483 if (*MessageList != NULL) {
1484 ProcessMessages (*MessageList);
1485 }
1486 }
1487
1488 //
1489 // Health status in {Healthy, Failed} may also have Messages need to process
1490 //
1491 if (LocalHealthStatus == EfiDriverHealthStatusHealthy || LocalHealthStatus == EfiDriverHealthStatusFailed) {
1492 if (*MessageList != NULL) {
1493 ProcessMessages (*MessageList);
1494 }
1495 }
1496 //
1497 // Check for RebootRequired or ReconnectRequired
1498 //
1499 if (LocalHealthStatus == EfiDriverHealthStatusRebootRequired) {
1500 gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);
1501 }
1502
1503 //
1504 // Do reconnect if need.
1505 //
1506 if (LocalHealthStatus == EfiDriverHealthStatusReconnectRequired) {
1507 Status = gBS->DisconnectController (ControllerHandle, NULL, NULL);
1508 if (EFI_ERROR (Status)) {
1509 //
1510 // Disconnect failed. Need to promote reconnect to a reboot.
1511 //
1512 gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);
1513 }
1514 gBS->ConnectController (ControllerHandle, NULL, NULL, TRUE);
1515 }
1516 }
1517
1518
1519 /**
1520 Platform specific notification function for controller repair operations.
1521
1522 If the driver for a controller support the Driver Health Protocol and the
1523 current state of the controller is EfiDriverHealthStatusRepairRequired then
1524 when the Repair() service of the Driver Health Protocol is called, this
1525 platform specific notification function can display the progress of the repair
1526 operation. Some platforms may choose to not display anything, other may choose
1527 to show the percentage complete on text consoles, and other may choose to render
1528 a progress bar on text and graphical consoles.
1529
1530 This function displays the percentage of the repair operation that has been
1531 completed on text consoles. The percentage is Value / Limit * 100%.
1532
1533 @param Value Value in the range 0..Limit the the repair has completed..
1534 @param Limit The maximum value of Value
1535
1536 **/
1537 VOID
1538 RepairNotify (
1539 IN UINTN Value,
1540 IN UINTN Limit
1541 )
1542 {
1543 UINTN Percent;
1544
1545 if (Limit == 0) {
1546 Print(L"Repair Progress Undefined\n\r");
1547 } else {
1548 Percent = Value * 100 / Limit;
1549 Print(L"Repair Progress = %3d%%\n\r", Percent);
1550 }
1551 }
1552
1553 /**
1554 Processes a set of messages returned by the GetHealthStatus ()
1555 service of the EFI Driver Health Protocol
1556
1557 @param MessageList The MessageList point to messages need to processed.
1558
1559 **/
1560 VOID
1561 ProcessMessages (
1562 IN EFI_DRIVER_HEALTH_HII_MESSAGE *MessageList
1563 )
1564 {
1565 UINTN MessageIndex;
1566 EFI_STRING MessageString;
1567
1568 for (MessageIndex = 0;
1569 MessageList[MessageIndex].HiiHandle != NULL;
1570 MessageIndex++) {
1571
1572 MessageString = HiiGetString (
1573 MessageList[MessageIndex].HiiHandle,
1574 MessageList[MessageIndex].StringId,
1575 NULL
1576 );
1577 if (MessageString != NULL) {
1578 //
1579 // User can customize the output. Just simply print out the MessageString like below.
1580 // Also can use the HiiHandle to display message on the front page.
1581 //
1582 // Print(L"%s\n",MessageString);
1583 // gBS->Stall (100000);
1584 }
1585 }
1586
1587 }
1588
1589 /**
1590 Repair the whole platform.
1591
1592 This function is the main entry for user choose "Repair All" in the front page.
1593 It will try to do recovery job till all the driver health protocol installed modules
1594 reach a terminal state.
1595
1596 @param DriverHealthList A Pointer to the list contain all of the platform driver health
1597 information.
1598
1599 **/
1600 VOID
1601 PlatformRepairAll (
1602 IN LIST_ENTRY *DriverHealthList
1603 )
1604 {
1605 DRIVER_HEALTH_INFO *DriverHealthInfo;
1606 LIST_ENTRY *Link;
1607
1608 ASSERT (DriverHealthList != NULL);
1609
1610 Link = GetFirstNode (DriverHealthList);
1611
1612 while (!IsNull (DriverHealthList, Link)) {
1613 DriverHealthInfo = DEVICE_MANAGER_HEALTH_INFO_FROM_LINK (Link);
1614 //
1615 // Do driver health status operation by each link node
1616 //
1617 ASSERT (DriverHealthInfo != NULL);
1618
1619 ProcessSingleControllerHealth (
1620 DriverHealthInfo->DriverHealth,
1621 DriverHealthInfo->ControllerHandle,
1622 DriverHealthInfo->ChildHandle,
1623 DriverHealthInfo->HealthStatus,
1624 &(DriverHealthInfo->MessageList),
1625 DriverHealthInfo->HiiHandle
1626 );
1627
1628 Link = GetNextNode (DriverHealthList, Link);
1629 }
1630 }
1631
1632 /**
1633
1634 Select the best matching language according to front page policy for best user experience.
1635
1636 This function supports both ISO 639-2 and RFC 4646 language codes, but language
1637 code types may not be mixed in a single call to this function.
1638
1639 @param SupportedLanguages A pointer to a Null-terminated ASCII string that
1640 contains a set of language codes in the format
1641 specified by Iso639Language.
1642 @param Iso639Language If TRUE, then all language codes are assumed to be
1643 in ISO 639-2 format. If FALSE, then all language
1644 codes are assumed to be in RFC 4646 language format.
1645
1646 @retval NULL The best matching language could not be found in SupportedLanguages.
1647 @retval NULL There are not enough resources available to return the best matching
1648 language.
1649 @retval Other A pointer to a Null-terminated ASCII string that is the best matching
1650 language in SupportedLanguages.
1651 **/
1652 CHAR8 *
1653 DriverHealthSelectBestLanguage (
1654 IN CHAR8 *SupportedLanguages,
1655 IN BOOLEAN Iso639Language
1656 )
1657 {
1658 CHAR8 *LanguageVariable;
1659 CHAR8 *BestLanguage;
1660
1661 LanguageVariable = GetEfiGlobalVariable (Iso639Language ? L"Lang" : L"PlatformLang");
1662
1663 BestLanguage = GetBestLanguage(
1664 SupportedLanguages,
1665 Iso639Language,
1666 (LanguageVariable != NULL) ? LanguageVariable : "",
1667 Iso639Language ? "eng" : "en-US",
1668 NULL
1669 );
1670 if (LanguageVariable != NULL) {
1671 FreePool (LanguageVariable);
1672 }
1673
1674 return BestLanguage;
1675 }
1676
1677
1678
1679 /**
1680
1681 This is an internal worker function to get the Component Name (2) protocol interface
1682 and the language it supports.
1683
1684 @param ProtocolGuid A pointer to an EFI_GUID. It points to Component Name (2) protocol GUID.
1685 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
1686 @param ComponentName A pointer to the Component Name (2) protocol interface.
1687 @param SupportedLanguage The best suitable language that matches the SupportedLangues interface for the
1688 located Component Name (2) instance.
1689
1690 @retval EFI_SUCCESS The Component Name (2) protocol instance is successfully located and we find
1691 the best matching language it support.
1692 @retval EFI_UNSUPPORTED The input Language is not supported by the Component Name (2) protocol.
1693 @retval Other Some error occurs when locating Component Name (2) protocol instance or finding
1694 the supported language.
1695
1696 **/
1697 EFI_STATUS
1698 GetComponentNameWorker (
1699 IN EFI_GUID *ProtocolGuid,
1700 IN EFI_HANDLE DriverBindingHandle,
1701 OUT EFI_COMPONENT_NAME_PROTOCOL **ComponentName,
1702 OUT CHAR8 **SupportedLanguage
1703 )
1704 {
1705 EFI_STATUS Status;
1706
1707 //
1708 // Locate Component Name (2) protocol on the driver binging handle.
1709 //
1710 Status = gBS->OpenProtocol (
1711 DriverBindingHandle,
1712 ProtocolGuid,
1713 (VOID **) ComponentName,
1714 NULL,
1715 NULL,
1716 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1717 );
1718 if (EFI_ERROR (Status)) {
1719 return Status;
1720 }
1721
1722 //
1723 // Apply shell policy to select the best language.
1724 //
1725 *SupportedLanguage = DriverHealthSelectBestLanguage (
1726 (*ComponentName)->SupportedLanguages,
1727 (BOOLEAN) (ProtocolGuid == &gEfiComponentNameProtocolGuid)
1728 );
1729 if (*SupportedLanguage == NULL) {
1730 Status = EFI_UNSUPPORTED;
1731 }
1732
1733 return Status;
1734 }
1735
1736 /**
1737
1738 This is an internal worker function to get driver name from Component Name (2) protocol interface.
1739
1740
1741 @param ProtocolGuid A pointer to an EFI_GUID. It points to Component Name (2) protocol GUID.
1742 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
1743 @param DriverName A pointer to the Unicode string to return. This Unicode string is the name
1744 of the driver specified by This.
1745
1746 @retval EFI_SUCCESS The driver name is successfully retrieved from Component Name (2) protocol
1747 interface.
1748 @retval Other The driver name cannot be retrieved from Component Name (2) protocol
1749 interface.
1750
1751 **/
1752 EFI_STATUS
1753 GetDriverNameWorker (
1754 IN EFI_GUID *ProtocolGuid,
1755 IN EFI_HANDLE DriverBindingHandle,
1756 OUT CHAR16 **DriverName
1757 )
1758 {
1759 EFI_STATUS Status;
1760 CHAR8 *BestLanguage;
1761 EFI_COMPONENT_NAME_PROTOCOL *ComponentName;
1762
1763 //
1764 // Retrieve Component Name (2) protocol instance on the driver binding handle and
1765 // find the best language this instance supports.
1766 //
1767 Status = GetComponentNameWorker (
1768 ProtocolGuid,
1769 DriverBindingHandle,
1770 &ComponentName,
1771 &BestLanguage
1772 );
1773 if (EFI_ERROR (Status)) {
1774 return Status;
1775 }
1776
1777 //
1778 // Get the driver name from Component Name (2) protocol instance on the driver binging handle.
1779 //
1780 Status = ComponentName->GetDriverName (
1781 ComponentName,
1782 BestLanguage,
1783 DriverName
1784 );
1785 FreePool (BestLanguage);
1786
1787 return Status;
1788 }
1789
1790 /**
1791
1792 This function gets driver name from Component Name 2 protocol interface and Component Name protocol interface
1793 in turn. It first tries UEFI 2.0 Component Name 2 protocol interface and try to get the driver name.
1794 If the attempt fails, it then gets the driver name from EFI 1.1 Component Name protocol for backward
1795 compatibility support.
1796
1797 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
1798 @param DriverName A pointer to the Unicode string to return. This Unicode string is the name
1799 of the driver specified by This.
1800
1801 @retval EFI_SUCCESS The driver name is successfully retrieved from Component Name (2) protocol
1802 interface.
1803 @retval Other The driver name cannot be retrieved from Component Name (2) protocol
1804 interface.
1805
1806 **/
1807 EFI_STATUS
1808 DriverHealthGetDriverName (
1809 IN EFI_HANDLE DriverBindingHandle,
1810 OUT CHAR16 **DriverName
1811 )
1812 {
1813 EFI_STATUS Status;
1814
1815 //
1816 // Get driver name from UEFI 2.0 Component Name 2 protocol interface.
1817 //
1818 Status = GetDriverNameWorker (&gEfiComponentName2ProtocolGuid, DriverBindingHandle, DriverName);
1819 if (EFI_ERROR (Status)) {
1820 //
1821 // If it fails to get the driver name from Component Name protocol interface, we should fall back on
1822 // EFI 1.1 Component Name protocol interface.
1823 //
1824 Status = GetDriverNameWorker (&gEfiComponentNameProtocolGuid, DriverBindingHandle, DriverName);
1825 }
1826
1827 return Status;
1828 }
1829
1830
1831
1832 /**
1833 This function gets controller name from Component Name 2 protocol interface and Component Name protocol interface
1834 in turn. It first tries UEFI 2.0 Component Name 2 protocol interface and try to get the controller name.
1835 If the attempt fails, it then gets the controller name from EFI 1.1 Component Name protocol for backward
1836 compatibility support.
1837
1838 @param ProtocolGuid A pointer to an EFI_GUID. It points to Component Name (2) protocol GUID.
1839 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
1840 @param ControllerHandle The handle of a controller that the driver specified by This is managing.
1841 This handle specifies the controller whose name is to be returned.
1842 @param ChildHandle The handle of the child controller to retrieve the name of. This is an
1843 optional parameter that may be NULL. It will be NULL for device drivers.
1844 It will also be NULL for bus drivers that attempt to retrieve the name
1845 of the bus controller. It will not be NULL for a bus driver that attempts
1846 to retrieve the name of a child controller.
1847 @param ControllerName A pointer to the Unicode string to return. This Unicode string
1848 is the name of the controller specified by ControllerHandle and ChildHandle.
1849
1850 @retval EFI_SUCCESS The controller name is successfully retrieved from Component Name (2) protocol
1851 interface.
1852 @retval Other The controller name cannot be retrieved from Component Name (2) protocol.
1853
1854 **/
1855 EFI_STATUS
1856 GetControllerNameWorker (
1857 IN EFI_GUID *ProtocolGuid,
1858 IN EFI_HANDLE DriverBindingHandle,
1859 IN EFI_HANDLE ControllerHandle,
1860 IN EFI_HANDLE ChildHandle,
1861 OUT CHAR16 **ControllerName
1862 )
1863 {
1864 EFI_STATUS Status;
1865 CHAR8 *BestLanguage;
1866 EFI_COMPONENT_NAME_PROTOCOL *ComponentName;
1867
1868 //
1869 // Retrieve Component Name (2) protocol instance on the driver binding handle and
1870 // find the best language this instance supports.
1871 //
1872 Status = GetComponentNameWorker (
1873 ProtocolGuid,
1874 DriverBindingHandle,
1875 &ComponentName,
1876 &BestLanguage
1877 );
1878 if (EFI_ERROR (Status)) {
1879 return Status;
1880 }
1881
1882 //
1883 // Get the controller name from Component Name (2) protocol instance on the driver binging handle.
1884 //
1885 Status = ComponentName->GetControllerName (
1886 ComponentName,
1887 ControllerHandle,
1888 ChildHandle,
1889 BestLanguage,
1890 ControllerName
1891 );
1892 FreePool (BestLanguage);
1893
1894 return Status;
1895 }
1896
1897 /**
1898
1899 This function gets controller name from Component Name 2 protocol interface and Component Name protocol interface
1900 in turn. It first tries UEFI 2.0 Component Name 2 protocol interface and try to get the controller name.
1901 If the attempt fails, it then gets the controller name from EFI 1.1 Component Name protocol for backward
1902 compatibility support.
1903
1904 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
1905 @param ControllerHandle The handle of a controller that the driver specified by This is managing.
1906 This handle specifies the controller whose name is to be returned.
1907 @param ChildHandle The handle of the child controller to retrieve the name of. This is an
1908 optional parameter that may be NULL. It will be NULL for device drivers.
1909 It will also be NULL for bus drivers that attempt to retrieve the name
1910 of the bus controller. It will not be NULL for a bus driver that attempts
1911 to retrieve the name of a child controller.
1912 @param ControllerName A pointer to the Unicode string to return. This Unicode string
1913 is the name of the controller specified by ControllerHandle and ChildHandle.
1914
1915 @retval EFI_SUCCESS The controller name is successfully retrieved from Component Name (2) protocol
1916 interface.
1917 @retval Other The controller name cannot be retrieved from Component Name (2) protocol.
1918
1919 **/
1920 EFI_STATUS
1921 DriverHealthGetControllerName (
1922 IN EFI_HANDLE DriverBindingHandle,
1923 IN EFI_HANDLE ControllerHandle,
1924 IN EFI_HANDLE ChildHandle,
1925 OUT CHAR16 **ControllerName
1926 )
1927 {
1928 EFI_STATUS Status;
1929
1930 //
1931 // Get controller name from UEFI 2.0 Component Name 2 protocol interface.
1932 //
1933 Status = GetControllerNameWorker (
1934 &gEfiComponentName2ProtocolGuid,
1935 DriverBindingHandle,
1936 ControllerHandle,
1937 ChildHandle,
1938 ControllerName
1939 );
1940 if (EFI_ERROR (Status)) {
1941 //
1942 // If it fails to get the controller name from Component Name protocol interface, we should fall back on
1943 // EFI 1.1 Component Name protocol interface.
1944 //
1945 Status = GetControllerNameWorker (
1946 &gEfiComponentNameProtocolGuid,
1947 DriverBindingHandle,
1948 ControllerHandle,
1949 ChildHandle,
1950 ControllerName
1951 );
1952 }
1953
1954 return Status;
1955 }