]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/DriverHealthManagerDxe/DriverHealthManagerDxe.c
MdeModulePkg: Clean up source files
[mirror_edk2.git] / MdeModulePkg / Universal / DriverHealthManagerDxe / DriverHealthManagerDxe.c
1 /** @file
2 This module produces two driver health manager forms.
3 One will be used by BDS core to configure the Configured Required
4 driver health instances, the other will be automatically included by
5 firmware setup (UI).
6
7 Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
8 (C) Copyright 2018 Hewlett Packard Enterprise Development LP<BR>
9 This program and the accompanying materials
10 are licensed and made available under the terms and conditions of the BSD License
11 which accompanies this distribution. The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php
13
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16
17 **/
18
19 #include "DriverHealthManagerDxe.h"
20 #include "DriverHealthManagerVfr.h"
21
22 EFI_HII_CONFIG_ACCESS_PROTOCOL mDriverHealthManagerConfigAccess = {
23 DriverHealthManagerFakeExtractConfig,
24 DriverHealthManagerFakeRouteConfig,
25 DriverHealthManagerCallback
26 };
27
28 EFI_GUID mDriverHealthManagerForm = DRIVER_HEALTH_MANAGER_FORMSET_GUID;
29
30 FORM_DEVICE_PATH mDriverHealthManagerFormDevicePath = {
31 {
32 {
33 HARDWARE_DEVICE_PATH,
34 HW_VENDOR_DP,
35 {
36 (UINT8) (sizeof (VENDOR_DEVICE_PATH)),
37 (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)
38 }
39 },
40 EFI_CALLER_ID_GUID
41 },
42 {
43 END_DEVICE_PATH_TYPE,
44 END_ENTIRE_DEVICE_PATH_SUBTYPE,
45 {
46 (UINT8) (END_DEVICE_PATH_LENGTH),
47 (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)
48 }
49 }
50 };
51
52 EFI_HII_HANDLE mDriverHealthManagerHiiHandle;
53 EFI_BOOT_MANAGER_DRIVER_HEALTH_INFO *mDriverHealthManagerHealthInfo = NULL;
54 UINTN mDriverHealthManagerHealthInfoCount = 0;
55 EFI_HII_DATABASE_PROTOCOL *mDriverHealthManagerDatabase;
56
57
58 extern UINT8 DriverHealthManagerVfrBin[];
59 extern UINT8 DriverHealthConfigureVfrBin[];
60
61 /**
62 This function allows a caller to extract the current configuration for one
63 or more named elements from the target driver.
64
65
66 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
67 @param Request A null-terminated Unicode string in <ConfigRequest> format.
68 @param Progress On return, points to a character in the Request string.
69 Points to the string's null terminator if request was successful.
70 Points to the most recent '&' before the first failing name/value
71 pair (or the beginning of the string if the failure is in the
72 first name/value pair) if the request was not successful.
73 @param Results A null-terminated Unicode string in <ConfigAltResp> format which
74 has all values filled in for the names in the Request string.
75 String to be allocated by the called function.
76
77 @retval EFI_SUCCESS The Results is filled with the requested values.
78 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
79 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
80 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
81
82 **/
83 EFI_STATUS
84 EFIAPI
85 DriverHealthManagerFakeExtractConfig (
86 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
87 IN CONST EFI_STRING Request,
88 OUT EFI_STRING *Progress,
89 OUT EFI_STRING *Results
90 )
91 {
92 if (Progress == NULL || Results == NULL) {
93 return EFI_INVALID_PARAMETER;
94 }
95 *Progress = Request;
96 return EFI_NOT_FOUND;
97 }
98
99 /**
100 This function processes the results of changes in configuration.
101
102
103 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
104 @param Configuration A null-terminated Unicode string in <ConfigResp> format.
105 @param Progress A pointer to a string filled in with the offset of the most
106 recent '&' before the first failing name/value pair (or the
107 beginning of the string if the failure is in the first
108 name/value pair) or the terminating NULL if all was successful.
109
110 @retval EFI_SUCCESS The Results is processed successfully.
111 @retval EFI_INVALID_PARAMETER Configuration is NULL.
112 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
113
114 **/
115 EFI_STATUS
116 EFIAPI
117 DriverHealthManagerFakeRouteConfig (
118 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
119 IN CONST EFI_STRING Configuration,
120 OUT EFI_STRING *Progress
121 )
122 {
123 if (Configuration == NULL || Progress == NULL) {
124 return EFI_INVALID_PARAMETER;
125 }
126
127 *Progress = Configuration;
128
129 return EFI_NOT_FOUND;
130 }
131
132 /**
133
134 Install the health manager forms.
135 One will be used by BDS core to configure the Configured Required
136 driver health instances, the other will be automatically included by
137 firmware setup (UI).
138
139 @param ImageHandle The image handle.
140 @param SystemTable The system table.
141
142 @retval EFI_SUCEESS The health manager forms are successfully installed.
143
144 **/
145 EFI_STATUS
146 EFIAPI
147 InitializeDriverHealthManager (
148 EFI_HANDLE ImageHandle,
149 EFI_SYSTEM_TABLE *SystemTable
150 )
151 {
152 EFI_STATUS Status;
153 EFI_HANDLE Handle;
154
155 Status = gBS->LocateProtocol (
156 &gEfiHiiDatabaseProtocolGuid,
157 NULL,
158 (VOID **) &mDriverHealthManagerDatabase
159 );
160 ASSERT_EFI_ERROR (Status);
161
162 Handle = NULL;
163 Status = gBS->InstallMultipleProtocolInterfaces (
164 &Handle,
165 &gEfiDevicePathProtocolGuid,
166 &mDriverHealthManagerFormDevicePath,
167 &gEfiHiiConfigAccessProtocolGuid,
168 &mDriverHealthManagerConfigAccess,
169 NULL
170 );
171 ASSERT_EFI_ERROR (Status);
172
173
174 //
175 // Publish Driver Health HII data.
176 //
177 mDriverHealthManagerHiiHandle = HiiAddPackages (
178 &gEfiCallerIdGuid,
179 Handle,
180 DriverHealthManagerVfrBin,
181 DriverHealthConfigureVfrBin,
182 STRING_ARRAY_NAME,
183 NULL
184 );
185 ASSERT (mDriverHealthManagerHiiHandle != NULL);
186
187 return EFI_SUCCESS;
188 }
189
190 /**
191
192 Select the best matching language according to front page policy for best user experience.
193
194 This function supports both ISO 639-2 and RFC 4646 language codes, but language
195 code types may not be mixed in a single call to this function.
196
197 @param SupportedLanguages A pointer to a Null-terminated ASCII string that
198 contains a set of language codes in the format
199 specified by Iso639Language.
200 @param Iso639Language If TRUE, then all language codes are assumed to be
201 in ISO 639-2 format. If FALSE, then all language
202 codes are assumed to be in RFC 4646 language format.
203
204 @retval NULL The best matching language could not be found in SupportedLanguages.
205 @retval NULL There are not enough resources available to return the best matching
206 language.
207 @retval Other A pointer to a Null-terminated ASCII string that is the best matching
208 language in SupportedLanguages.
209 **/
210 CHAR8 *
211 DriverHealthManagerSelectBestLanguage (
212 IN CHAR8 *SupportedLanguages,
213 IN BOOLEAN Iso639Language
214 )
215 {
216 CHAR8 *LanguageVariable;
217 CHAR8 *BestLanguage;
218
219 GetEfiGlobalVariable2 (Iso639Language ? L"Lang" : L"PlatformLang", (VOID**)&LanguageVariable, NULL);
220
221 BestLanguage = GetBestLanguage(
222 SupportedLanguages,
223 Iso639Language,
224 (LanguageVariable != NULL) ? LanguageVariable : "",
225 Iso639Language ? "eng" : "en-US",
226 NULL
227 );
228 if (LanguageVariable != NULL) {
229 FreePool (LanguageVariable);
230 }
231
232 return BestLanguage;
233 }
234
235
236
237 /**
238
239 This is an internal worker function to get the Component Name (2) protocol interface
240 and the language it supports.
241
242 @param ProtocolGuid A pointer to an EFI_GUID. It points to Component Name (2) protocol GUID.
243 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
244 @param ComponentName A pointer to the Component Name (2) protocol interface.
245 @param SupportedLanguage The best suitable language that matches the SupportedLangues interface for the
246 located Component Name (2) instance.
247
248 @retval EFI_SUCCESS The Component Name (2) protocol instance is successfully located and we find
249 the best matching language it support.
250 @retval EFI_UNSUPPORTED The input Language is not supported by the Component Name (2) protocol.
251 @retval Other Some error occurs when locating Component Name (2) protocol instance or finding
252 the supported language.
253
254 **/
255 EFI_STATUS
256 DriverHealthManagerGetComponentNameWorker (
257 IN EFI_GUID *ProtocolGuid,
258 IN EFI_HANDLE DriverBindingHandle,
259 OUT EFI_COMPONENT_NAME_PROTOCOL **ComponentName,
260 OUT CHAR8 **SupportedLanguage
261 )
262 {
263 EFI_STATUS Status;
264
265 //
266 // Locate Component Name (2) protocol on the driver binging handle.
267 //
268 Status = gBS->OpenProtocol (
269 DriverBindingHandle,
270 ProtocolGuid,
271 (VOID **) ComponentName,
272 NULL,
273 NULL,
274 EFI_OPEN_PROTOCOL_GET_PROTOCOL
275 );
276 if (EFI_ERROR (Status)) {
277 return Status;
278 }
279
280 //
281 // Apply shell policy to select the best language.
282 //
283 *SupportedLanguage = DriverHealthManagerSelectBestLanguage (
284 (*ComponentName)->SupportedLanguages,
285 (BOOLEAN) (ProtocolGuid == &gEfiComponentNameProtocolGuid)
286 );
287 if (*SupportedLanguage == NULL) {
288 Status = EFI_UNSUPPORTED;
289 }
290
291 return Status;
292 }
293
294 /**
295
296 This is an internal worker function to get driver name from Component Name (2) protocol interface.
297
298 @param ProtocolGuid A pointer to an EFI_GUID. It points to Component Name (2) protocol GUID.
299 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
300 @param DriverName A pointer to the Unicode string to return. This Unicode string is the name
301 of the driver specified by This.
302
303 @retval EFI_SUCCESS The driver name is successfully retrieved from Component Name (2) protocol
304 interface.
305 @retval Other The driver name cannot be retrieved from Component Name (2) protocol
306 interface.
307
308 **/
309 EFI_STATUS
310 DriverHealthManagerGetDriverNameWorker (
311 IN EFI_GUID *ProtocolGuid,
312 IN EFI_HANDLE DriverBindingHandle,
313 OUT CHAR16 **DriverName
314 )
315 {
316 EFI_STATUS Status;
317 CHAR8 *BestLanguage;
318 EFI_COMPONENT_NAME_PROTOCOL *ComponentName;
319
320 //
321 // Retrieve Component Name (2) protocol instance on the driver binding handle and
322 // find the best language this instance supports.
323 //
324 Status = DriverHealthManagerGetComponentNameWorker (
325 ProtocolGuid,
326 DriverBindingHandle,
327 &ComponentName,
328 &BestLanguage
329 );
330 if (EFI_ERROR (Status)) {
331 return Status;
332 }
333
334 //
335 // Get the driver name from Component Name (2) protocol instance on the driver binging handle.
336 //
337 Status = ComponentName->GetDriverName (
338 ComponentName,
339 BestLanguage,
340 DriverName
341 );
342 FreePool (BestLanguage);
343
344 return Status;
345 }
346
347 /**
348 This function gets driver name from Component Name 2 protocol interface and Component Name protocol interface
349 in turn. It first tries UEFI 2.0 Component Name 2 protocol interface and try to get the driver name.
350 If the attempt fails, it then gets the driver name from EFI 1.1 Component Name protocol for backward
351 compatibility support.
352
353 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
354
355 @return A pointer to the Unicode string to return. This Unicode string is the name of the controller
356 specified by ControllerHandle and ChildHandle.
357
358
359 **/
360 CHAR16 *
361 DriverHealthManagerGetDriverName (
362 IN EFI_HANDLE DriverBindingHandle
363 )
364 {
365 EFI_STATUS Status;
366 CHAR16 *DriverName;
367
368 //
369 // Get driver name from UEFI 2.0 Component Name 2 protocol interface.
370 //
371 Status = DriverHealthManagerGetDriverNameWorker (&gEfiComponentName2ProtocolGuid, DriverBindingHandle, &DriverName);
372 if (EFI_ERROR (Status)) {
373 //
374 // If it fails to get the driver name from Component Name protocol interface, we should fall back on
375 // EFI 1.1 Component Name protocol interface.
376 //
377 Status = DriverHealthManagerGetDriverNameWorker (&gEfiComponentNameProtocolGuid, DriverBindingHandle, &DriverName);
378 }
379
380 if (!EFI_ERROR (Status)) {
381 return AllocateCopyPool (StrSize (DriverName), DriverName);
382 } else {
383 return ConvertDevicePathToText (DevicePathFromHandle (DriverBindingHandle), FALSE, TRUE);
384 }
385 }
386
387
388
389 /**
390 This function gets controller name from Component Name 2 protocol interface and Component Name protocol interface
391 in turn. It first tries UEFI 2.0 Component Name 2 protocol interface and try to get the controller name.
392 If the attempt fails, it then gets the controller name from EFI 1.1 Component Name protocol for backward
393 compatibility support.
394
395 @param ProtocolGuid A pointer to an EFI_GUID. It points to Component Name (2) protocol GUID.
396 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
397 @param ControllerHandle The handle of a controller that the driver specified by This is managing.
398 This handle specifies the controller whose name is to be returned.
399 @param ChildHandle The handle of the child controller to retrieve the name of. This is an
400 optional parameter that may be NULL. It will be NULL for device drivers.
401 It will also be NULL for bus drivers that attempt to retrieve the name
402 of the bus controller. It will not be NULL for a bus driver that attempts
403 to retrieve the name of a child controller.
404 @param ControllerName A pointer to the Unicode string to return. This Unicode string
405 is the name of the controller specified by ControllerHandle and ChildHandle.
406
407 @retval EFI_SUCCESS The controller name is successfully retrieved from Component Name (2) protocol
408 interface.
409 @retval Other The controller name cannot be retrieved from Component Name (2) protocol.
410
411 **/
412 EFI_STATUS
413 DriverHealthManagerGetControllerNameWorker (
414 IN EFI_GUID *ProtocolGuid,
415 IN EFI_HANDLE DriverBindingHandle,
416 IN EFI_HANDLE ControllerHandle,
417 IN EFI_HANDLE ChildHandle,
418 OUT CHAR16 **ControllerName
419 )
420 {
421 EFI_STATUS Status;
422 CHAR8 *BestLanguage;
423 EFI_COMPONENT_NAME_PROTOCOL *ComponentName;
424
425 //
426 // Retrieve Component Name (2) protocol instance on the driver binding handle and
427 // find the best language this instance supports.
428 //
429 Status = DriverHealthManagerGetComponentNameWorker (
430 ProtocolGuid,
431 DriverBindingHandle,
432 &ComponentName,
433 &BestLanguage
434 );
435 if (EFI_ERROR (Status)) {
436 return Status;
437 }
438
439 //
440 // Get the controller name from Component Name (2) protocol instance on the driver binging handle.
441 //
442 Status = ComponentName->GetControllerName (
443 ComponentName,
444 ControllerHandle,
445 ChildHandle,
446 BestLanguage,
447 ControllerName
448 );
449 FreePool (BestLanguage);
450
451 return Status;
452 }
453
454 /**
455
456 This function gets controller name from Component Name 2 protocol interface and Component Name protocol interface
457 in turn. It first tries UEFI 2.0 Component Name 2 protocol interface and try to get the controller name.
458 If the attempt fails, it then gets the controller name from EFI 1.1 Component Name protocol for backward
459 compatibility support.
460
461 @param DriverBindingHandle The handle on which the Component Name (2) protocol instance is retrieved.
462 @param ControllerHandle The handle of a controller that the driver specified by DriverBindingHandle is managing.
463 This handle specifies the controller whose name is to be returned.
464 @param ChildHandle The handle of the child controller to retrieve the name of. This is an
465 optional parameter that may be NULL. It will be NULL for device drivers.
466 It will also be NULL for bus drivers that attempt to retrieve the name
467 of the bus controller. It will not be NULL for a bus driver that attempts
468 to retrieve the name of a child controller.
469
470 @return A pointer to the Unicode string to return. This Unicode string is the name of the controller
471 specified by ControllerHandle and ChildHandle.
472 **/
473 CHAR16 *
474 DriverHealthManagerGetControllerName (
475 IN EFI_HANDLE DriverBindingHandle,
476 IN EFI_HANDLE ControllerHandle,
477 IN EFI_HANDLE ChildHandle
478 )
479 {
480 EFI_STATUS Status;
481 CHAR16 *ControllerName;
482
483 //
484 // Get controller name from UEFI 2.0 Component Name 2 protocol interface.
485 //
486 Status = DriverHealthManagerGetControllerNameWorker (
487 &gEfiComponentName2ProtocolGuid,
488 DriverBindingHandle,
489 ControllerHandle,
490 ChildHandle,
491 &ControllerName
492 );
493 if (EFI_ERROR (Status)) {
494 //
495 // If it fails to get the controller name from Component Name protocol interface, we should fall back on
496 // EFI 1.1 Component Name protocol interface.
497 //
498 Status = DriverHealthManagerGetControllerNameWorker (
499 &gEfiComponentNameProtocolGuid,
500 DriverBindingHandle,
501 ControllerHandle,
502 ChildHandle,
503 &ControllerName
504 );
505 }
506
507 if (!EFI_ERROR (Status)) {
508 return AllocateCopyPool (StrSize (ControllerName), ControllerName);
509 } else {
510 return ConvertDevicePathToText (DevicePathFromHandle (ChildHandle != NULL ? ChildHandle : ControllerHandle), FALSE, TRUE);
511 }
512 }
513
514 /**
515 The repair notify function.
516 @param Value A value between 0 and Limit that identifies the current progress
517 of the repair operation.
518 @param Limit The maximum value of Value for the current repair operation.
519 If Limit is 0, then the completion progress is indeterminate.
520 For example, a driver that wants to specify progress in percent
521 would use a Limit value of 100.
522
523 @retval EFI_SUCCESS Successfully return from the notify function.
524 **/
525 EFI_STATUS
526 EFIAPI
527 DriverHealthManagerRepairNotify (
528 IN UINTN Value,
529 IN UINTN Limit
530 )
531 {
532 DEBUG ((EFI_D_INFO, "[DriverHealthManagement]RepairNotify: %d/%d\n", Value, Limit));
533 return EFI_SUCCESS;
534 }
535
536 /**
537 Look for the formset GUID which has the gEfiHiiDriverHealthFormsetGuid class GUID in the specified HII package list.
538
539 @param Handle Handle to the HII package list.
540 @param FormsetGuid Return the formset GUID.
541
542 @retval EFI_SUCCESS The formset is found successfully.
543 @retval EFI_NOT_FOUND The formset cannot be found.
544 **/
545 EFI_STATUS
546 DriverHealthManagerGetFormsetId (
547 IN EFI_HII_HANDLE Handle,
548 OUT EFI_GUID *FormsetGuid
549 )
550 {
551 EFI_STATUS Status;
552 EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList;
553 UINTN BufferSize;
554 UINT8 *Package;
555 UINT8 *OpCodeData;
556 UINT32 Offset;
557 UINT32 Offset2;
558 EFI_HII_PACKAGE_HEADER PackageHeader;
559 UINT8 Index;
560 UINT8 NumberOfClassGuid;
561 EFI_GUID *ClassGuid;
562
563 //
564 // Get HII PackageList
565 //
566 BufferSize = 0;
567 HiiPackageList = NULL;
568 Status = mDriverHealthManagerDatabase->ExportPackageLists (mDriverHealthManagerDatabase, Handle, &BufferSize, HiiPackageList);
569 if (Status == EFI_BUFFER_TOO_SMALL) {
570 HiiPackageList = AllocatePool (BufferSize);
571 ASSERT (HiiPackageList != NULL);
572
573 Status = mDriverHealthManagerDatabase->ExportPackageLists (mDriverHealthManagerDatabase, Handle, &BufferSize, HiiPackageList);
574 }
575 if (EFI_ERROR (Status)) {
576 return Status;
577 }
578 ASSERT (HiiPackageList != NULL);
579
580 //
581 // Get Form package from this HII package List
582 //
583 for (Offset = sizeof (EFI_HII_PACKAGE_LIST_HEADER); Offset < ReadUnaligned32 (&HiiPackageList->PackageLength); Offset += PackageHeader.Length) {
584 Package = ((UINT8 *) HiiPackageList) + Offset;
585 CopyMem (&PackageHeader, Package, sizeof (EFI_HII_PACKAGE_HEADER));
586
587 if (PackageHeader.Type == EFI_HII_PACKAGE_FORMS) {
588 //
589 // Search FormSet in this Form Package
590 //
591
592 for (Offset2 = sizeof (EFI_HII_PACKAGE_HEADER); Offset2 < PackageHeader.Length; Offset2 += ((EFI_IFR_OP_HEADER *) OpCodeData)->Length) {
593 OpCodeData = Package + Offset2;
594
595 if ((((EFI_IFR_OP_HEADER *) OpCodeData)->OpCode == EFI_IFR_FORM_SET_OP) &&
596 (((EFI_IFR_OP_HEADER *) OpCodeData)->Length > OFFSET_OF (EFI_IFR_FORM_SET, Flags))) {
597 //
598 // Try to compare against formset class GUID
599 //
600 NumberOfClassGuid = (UINT8) (((EFI_IFR_FORM_SET *) OpCodeData)->Flags & 0x3);
601 ClassGuid = (EFI_GUID *) (OpCodeData + sizeof (EFI_IFR_FORM_SET));
602 for (Index = 0; Index < NumberOfClassGuid; Index++) {
603 if (CompareGuid (&gEfiHiiDriverHealthFormsetGuid, &ClassGuid[Index])) {
604 CopyMem (FormsetGuid, &((EFI_IFR_FORM_SET *) OpCodeData)->Guid, sizeof (EFI_GUID));
605 FreePool (HiiPackageList);
606 return EFI_SUCCESS;
607 }
608 }
609 }
610 }
611 }
612 }
613
614 //
615 // Form package not found in this Package List
616 //
617 FreePool (HiiPackageList);
618 return EFI_NOT_FOUND;
619 }
620
621 /**
622 Processes a single controller using the EFI Driver Health Protocol associated with
623 that controller.
624
625 @param DriverHealth A pointer to the EFI_DRIVER_HEALTH_PROTOCOL instance.
626 @param ControllerHandle The class guid specifies which form set will be displayed.
627 @param ChildHandle The handle of the child controller to retrieve the health
628 status on. This is an optional parameter that may be NULL.
629 @param HealthStatus The health status of the controller.
630 @param MessageList An array of warning or error messages associated
631 with the controller specified by ControllerHandle and
632 ChildHandle. This is an optional parameter that may be NULL.
633 @param FormHiiHandle The HII handle for an HII form associated with the
634 controller specified by ControllerHandle and ChildHandle.
635 **/
636 VOID
637 DriverHealthManagerProcessSingleControllerHealth (
638 IN EFI_DRIVER_HEALTH_PROTOCOL *DriverHealth,
639 IN EFI_HANDLE ControllerHandle, OPTIONAL
640 IN EFI_HANDLE ChildHandle, OPTIONAL
641 IN EFI_DRIVER_HEALTH_STATUS HealthStatus,
642 IN EFI_DRIVER_HEALTH_HII_MESSAGE **MessageList, OPTIONAL
643 IN EFI_HII_HANDLE FormHiiHandle
644 )
645 {
646 EFI_STATUS Status;
647
648 ASSERT (HealthStatus != EfiDriverHealthStatusConfigurationRequired);
649 //
650 // If the module need to be repaired or reconfiguration, will process it until
651 // reach a terminal status. The status from EfiDriverHealthStatusRepairRequired after repair
652 // will be in (Health, Failed, Configuration Required).
653 //
654 switch (HealthStatus) {
655
656 case EfiDriverHealthStatusRepairRequired:
657 Status = DriverHealth->Repair (
658 DriverHealth,
659 ControllerHandle,
660 ChildHandle,
661 DriverHealthManagerRepairNotify
662 );
663 break;
664
665 case EfiDriverHealthStatusRebootRequired:
666 gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);
667 break;
668
669 case EfiDriverHealthStatusReconnectRequired:
670 Status = gBS->DisconnectController (ControllerHandle, NULL, NULL);
671 if (EFI_ERROR (Status)) {
672 //
673 // Disconnect failed. Need to promote reconnect to a reboot.
674 //
675 gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);
676 } else {
677 gBS->ConnectController (ControllerHandle, NULL, NULL, TRUE);
678 }
679 break;
680
681 default:
682 break;
683 }
684 }
685
686 /**
687 Update the form to include the driver health instances.
688
689 @param ConfigureOnly Only include the configure required driver health instances
690 when TRUE, include all the driver health instances otherwise.
691 **/
692 VOID
693 DriverHealthManagerUpdateForm (
694 BOOLEAN ConfigureOnly
695 )
696 {
697 EFI_STATUS Status;
698 EFI_IFR_GUID_LABEL *StartLabel;
699 EFI_IFR_GUID_LABEL *EndLabel;
700 VOID *StartOpCodeHandle;
701 VOID *EndOpCodeHandle;
702 UINTN Index;
703 EFI_STRING_ID Prompt;
704 EFI_STRING_ID Help;
705 CHAR16 String[512];
706 UINTN StringCount;
707 EFI_STRING TmpString;
708 EFI_STRING DriverName;
709 EFI_STRING ControllerName;
710 UINTN MessageIndex;
711 EFI_HANDLE DriverHandle;
712 EFI_STRING_ID DevicePath;
713 EFI_GUID FormsetGuid;
714
715 EfiBootManagerFreeDriverHealthInfo (mDriverHealthManagerHealthInfo, mDriverHealthManagerHealthInfoCount);
716 mDriverHealthManagerHealthInfo = EfiBootManagerGetDriverHealthInfo (&mDriverHealthManagerHealthInfoCount);
717
718 //
719 // Allocate space for creation of UpdateData Buffer
720 //
721 StartOpCodeHandle = HiiAllocateOpCodeHandle ();
722 ASSERT (StartOpCodeHandle != NULL);
723
724 EndOpCodeHandle = HiiAllocateOpCodeHandle ();
725 ASSERT (EndOpCodeHandle != NULL);
726
727 //
728 // Create Hii Extend Label OpCode as the start opcode
729 //
730 StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
731 StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
732 StartLabel->Number = LABEL_BEGIN;
733
734 //
735 // Create Hii Extend Label OpCode as the end opcode
736 //
737 EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
738 EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
739 EndLabel->Number = LABEL_END;
740
741 for (Index = 0; Index < mDriverHealthManagerHealthInfoCount; Index++) {
742 if (ConfigureOnly && mDriverHealthManagerHealthInfo[Index].HealthStatus != EfiDriverHealthStatusConfigurationRequired) {
743 continue;
744 }
745 DriverName = DriverHealthManagerGetDriverName (mDriverHealthManagerHealthInfo[Index].DriverHealthHandle);
746 ASSERT (DriverName != NULL);
747
748 if (mDriverHealthManagerHealthInfo[Index].ControllerHandle == NULL) {
749 //
750 // The ControllerHandle is set to NULL and the HealthStatus is set to EfiDriverHealthStatusHealthy
751 // if all the controllers managed by the driver are in healthy state.
752 //
753 ASSERT (mDriverHealthManagerHealthInfo[Index].HealthStatus == EfiDriverHealthStatusHealthy);
754 UnicodeSPrint (String, sizeof (String), L"%s", DriverName);
755 } else {
756 ControllerName = DriverHealthManagerGetControllerName (
757 mDriverHealthManagerHealthInfo[Index].DriverHealthHandle,
758 mDriverHealthManagerHealthInfo[Index].ControllerHandle,
759 mDriverHealthManagerHealthInfo[Index].ChildHandle
760 );
761 ASSERT (ControllerName != NULL);
762 UnicodeSPrint (String, sizeof (String), L"%s %s", DriverName, ControllerName);
763 FreePool (ControllerName);
764 }
765 FreePool (DriverName);
766
767 Prompt = HiiSetString (mDriverHealthManagerHiiHandle, 0, String, NULL);
768
769 switch(mDriverHealthManagerHealthInfo[Index].HealthStatus) {
770 case EfiDriverHealthStatusRepairRequired:
771 TmpString = HiiGetString (mDriverHealthManagerHiiHandle, STRING_TOKEN (STR_REPAIR_REQUIRED), NULL);
772 break;
773 case EfiDriverHealthStatusConfigurationRequired:
774 TmpString = HiiGetString (mDriverHealthManagerHiiHandle, STRING_TOKEN (STR_CONFIGURATION_REQUIRED), NULL);
775 break;
776 case EfiDriverHealthStatusFailed:
777 TmpString = HiiGetString (mDriverHealthManagerHiiHandle, STRING_TOKEN (STR_FAILED), NULL);
778 break;
779 case EfiDriverHealthStatusReconnectRequired:
780 TmpString = HiiGetString (mDriverHealthManagerHiiHandle, STRING_TOKEN (STR_RECONNECT_REQUIRED), NULL);
781 break;
782 case EfiDriverHealthStatusRebootRequired:
783 TmpString = HiiGetString (mDriverHealthManagerHiiHandle, STRING_TOKEN (STR_REBOOT_REQUIRED), NULL);
784 break;
785 default:
786 ASSERT (mDriverHealthManagerHealthInfo[Index].HealthStatus == EfiDriverHealthStatusHealthy);
787 TmpString = HiiGetString (mDriverHealthManagerHiiHandle, STRING_TOKEN (STR_HEALTHY), NULL);
788 break;
789 }
790 StringCount = UnicodeSPrint (String, sizeof (String), L"%s\n", TmpString);
791 FreePool (TmpString);
792
793 //
794 // Add the message of the Module itself provided as the help.
795 //
796 if (mDriverHealthManagerHealthInfo[Index].MessageList != NULL) {
797 for (MessageIndex = 0; mDriverHealthManagerHealthInfo[Index].MessageList[MessageIndex].HiiHandle != NULL; MessageIndex++) {
798 TmpString = HiiGetString (
799 mDriverHealthManagerHealthInfo[Index].MessageList[MessageIndex].HiiHandle,
800 mDriverHealthManagerHealthInfo[Index].MessageList[MessageIndex].StringId,
801 NULL
802 );
803 StringCount += UnicodeSPrint (String + StringCount, sizeof (String) - sizeof (String[0]) * StringCount, L"\n%s", TmpString);
804 FreePool (TmpString);
805 }
806 }
807 Help = HiiSetString (mDriverHealthManagerHiiHandle, 0, String, NULL);
808
809 switch (mDriverHealthManagerHealthInfo[Index].HealthStatus) {
810 case EfiDriverHealthStatusConfigurationRequired:
811 Status = mDriverHealthManagerDatabase->GetPackageListHandle (
812 mDriverHealthManagerDatabase,
813 mDriverHealthManagerHealthInfo[Index].HiiHandle,
814 &DriverHandle
815 );
816 ASSERT_EFI_ERROR (Status);
817 TmpString = ConvertDevicePathToText (DevicePathFromHandle (DriverHandle), FALSE, TRUE);
818 DevicePath = HiiSetString (mDriverHealthManagerHiiHandle, 0, TmpString, NULL);
819 FreePool (TmpString);
820
821 Status = DriverHealthManagerGetFormsetId (mDriverHealthManagerHealthInfo[Index].HiiHandle, &FormsetGuid);
822 ASSERT_EFI_ERROR (Status);
823
824 HiiCreateGotoExOpCode (
825 StartOpCodeHandle,
826 0,
827 Prompt,
828 Help,
829 0,
830 0,
831 0,
832 &FormsetGuid,
833 DevicePath
834 );
835 break;
836
837 case EfiDriverHealthStatusRepairRequired:
838 case EfiDriverHealthStatusReconnectRequired:
839 case EfiDriverHealthStatusRebootRequired:
840 HiiCreateActionOpCode (
841 StartOpCodeHandle,
842 (EFI_QUESTION_ID) (Index + QUESTION_ID_DRIVER_HEALTH_BASE),
843 Prompt,
844 Help,
845 EFI_IFR_FLAG_CALLBACK,
846 0
847 );
848 break;
849
850 default:
851 ASSERT (mDriverHealthManagerHealthInfo[Index].HealthStatus == EfiDriverHealthStatusHealthy ||
852 mDriverHealthManagerHealthInfo[Index].HealthStatus == EfiDriverHealthStatusFailed);
853 HiiCreateTextOpCode (
854 StartOpCodeHandle,
855 Prompt,
856 Help,
857 0
858 );
859 break;
860 }
861 }
862
863 Status = HiiUpdateForm (
864 mDriverHealthManagerHiiHandle,
865 ConfigureOnly ? PcdGetPtr (PcdDriverHealthConfigureForm) : &mDriverHealthManagerForm,
866 DRIVER_HEALTH_FORM_ID,
867 StartOpCodeHandle,
868 EndOpCodeHandle
869 );
870 ASSERT_EFI_ERROR (Status);
871
872 HiiFreeOpCodeHandle (StartOpCodeHandle);
873 HiiFreeOpCodeHandle (EndOpCodeHandle);
874 }
875
876 /**
877 Called when the form is closing to remove the dynamicly added string from the HII package list.
878 **/
879 VOID
880 DriverHealthManagerCleanDynamicString (
881 VOID
882 )
883 {
884 EFI_STATUS Status;
885 EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList;
886 UINTN BufferSize;
887 EFI_HII_PACKAGE_HEADER *PackageHeader;
888 UINT32 FixedStringSize;
889
890 FixedStringSize = *(UINT32 *) &STRING_ARRAY_NAME - sizeof (UINT32);
891 BufferSize = sizeof (EFI_HII_PACKAGE_LIST_HEADER) + FixedStringSize + sizeof (EFI_HII_PACKAGE_HEADER);
892 HiiPackageList = AllocatePool (BufferSize);
893 ASSERT (HiiPackageList != NULL);
894
895 HiiPackageList->PackageLength = (UINT32) BufferSize;
896 CopyMem (&HiiPackageList->PackageListGuid, &gEfiCallerIdGuid, sizeof (EFI_GUID));
897
898 PackageHeader = (EFI_HII_PACKAGE_HEADER *) (HiiPackageList + 1);
899 CopyMem (PackageHeader, STRING_ARRAY_NAME + sizeof (UINT32), FixedStringSize);
900
901 PackageHeader = (EFI_HII_PACKAGE_HEADER *) ((UINT8 *) PackageHeader + PackageHeader->Length);
902 PackageHeader->Type = EFI_HII_PACKAGE_END;
903 PackageHeader->Length = sizeof (EFI_HII_PACKAGE_HEADER);
904
905 Status = mDriverHealthManagerDatabase->UpdatePackageList (
906 mDriverHealthManagerDatabase,
907 mDriverHealthManagerHiiHandle,
908 HiiPackageList
909 );
910 ASSERT_EFI_ERROR (Status);
911
912 //
913 // Form package not found in this Package List
914 //
915 FreePool (HiiPackageList);
916 }
917
918 /**
919 This function is invoked if user selected a interactive opcode from Driver Health's
920 Formset.
921
922 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
923 @param Action Specifies the type of action taken by the browser.
924 @param QuestionId A unique value which is sent to the original exporting driver
925 so that it can identify the type of data to expect.
926 @param Type The type of value for the question.
927 @param Value A pointer to the data being sent to the original exporting driver.
928 @param ActionRequest On return, points to the action requested by the callback function.
929
930 @retval EFI_SUCCESS The callback successfully handled the action.
931 @retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.
932
933 **/
934 EFI_STATUS
935 EFIAPI
936 DriverHealthManagerCallback (
937 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
938 IN EFI_BROWSER_ACTION Action,
939 IN EFI_QUESTION_ID QuestionId,
940 IN UINT8 Type,
941 IN EFI_IFR_TYPE_VALUE *Value,
942 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
943 )
944 {
945 UINTN Index;
946
947 if (QuestionId == QUESTION_ID_REFRESH_MANAGER || QuestionId == QUESTION_ID_REFRESH_CONFIGURE) {
948 if (Action == EFI_BROWSER_ACTION_FORM_OPEN) {
949 DriverHealthManagerUpdateForm ((BOOLEAN) (QuestionId == QUESTION_ID_REFRESH_CONFIGURE));
950 } else if (Action == EFI_BROWSER_ACTION_FORM_CLOSE) {
951 DriverHealthManagerCleanDynamicString ();
952 }
953 return EFI_SUCCESS;
954 }
955
956 if (Action != EFI_BROWSER_ACTION_CHANGED) {
957 //
958 // Do nothing for other UEFI Action. Only do call back when data is changed.
959 //
960 return EFI_UNSUPPORTED;
961 }
962
963 if ((Value == NULL) || (ActionRequest == NULL)) {
964 return EFI_INVALID_PARAMETER;
965 }
966
967 DEBUG ((EFI_D_ERROR, "QuestionId = %x\n", QuestionId));
968
969 //
970 // We will have returned from processing a callback - user either hit ESC to exit, or selected
971 // a target to display.
972 // Process the diver health status states here.
973 //
974 Index = QuestionId - QUESTION_ID_DRIVER_HEALTH_BASE;
975 ASSERT (Index < mDriverHealthManagerHealthInfoCount);
976 //
977 // Process the driver's healthy status for the specify module
978 //
979 DriverHealthManagerProcessSingleControllerHealth (
980 mDriverHealthManagerHealthInfo[Index].DriverHealth,
981 mDriverHealthManagerHealthInfo[Index].ControllerHandle,
982 mDriverHealthManagerHealthInfo[Index].ChildHandle,
983 mDriverHealthManagerHealthInfo[Index].HealthStatus,
984 &(mDriverHealthManagerHealthInfo[Index].MessageList),
985 mDriverHealthManagerHealthInfo[Index].HiiHandle
986 );
987
988 DriverHealthManagerUpdateForm ((BOOLEAN) (QuestionId == QUESTION_ID_REFRESH_CONFIGURE));
989
990 return EFI_SUCCESS;
991 }
992
993