]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/UefiBootManagerLib/BmDriverHealth.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Library / UefiBootManagerLib / BmDriverHealth.c
index b3f57f56fab2ce310503ff84f91266372f674657..52e35e45185d21c7c90424585b521cf21e5a7af8 100644 (file)
@@ -1,14 +1,10 @@
 /** @file\r
   Library functions which relates with driver health.\r
 \r
-Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution.  The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>\r
+(C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
+(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -90,7 +86,7 @@ BmGetControllerName (
 \r
     Status = ComponentName->GetControllerName (\r
                               ComponentName,\r
-                              ControllerHandle, \r
+                              ControllerHandle,\r
                               ChildHandle,\r
                               BestLanguage,\r
                               &ControllerName\r
@@ -129,7 +125,7 @@ BmDisplayMessages (
 \r
   ControllerName = BmGetControllerName (\r
                      DriverHealthInfo->DriverHealthHandle,\r
-                     DriverHealthInfo->ControllerHandle, \r
+                     DriverHealthInfo->ControllerHandle,\r
                      DriverHealthInfo->ChildHandle\r
                      );\r
 \r
@@ -179,7 +175,7 @@ BmRepairNotify (
 \r
 /**\r
   Collect the Driver Health status of a single controller.\r
-  \r
+\r
   @param DriverHealthInfo        A pointer to the array containing all of the platform driver health information.\r
   @param Count                   Return the updated array count.\r
   @param DriverHealthHandle      The handle on which the Driver Health protocol instance is retrieved.\r
@@ -216,7 +212,7 @@ BmGetSingleControllerHealthStatus (
                   (VOID **) &DriverHealth\r
                   );\r
   ASSERT_EFI_ERROR (Status);\r
-  \r
+\r
 \r
   if (ControllerHandle == NULL) {\r
     //\r
@@ -295,7 +291,6 @@ EfiBootManagerGetDriverHealthInfo (
   EFI_STATUS                 Status;\r
   UINTN                      NumHandles;\r
   EFI_HANDLE                 *DriverHealthHandles;\r
-  EFI_DRIVER_HEALTH_STATUS   HealthStatus;\r
   UINTN                      DriverHealthIndex;\r
   EFI_HANDLE                 *Handles;\r
   UINTN                      HandleCount;\r
@@ -313,8 +308,6 @@ EfiBootManagerGetDriverHealthInfo (
   NumHandles              = 0;\r
   HandleCount             = 0;\r
 \r
-  HealthStatus = EfiDriverHealthStatusHealthy;\r
-\r
   Status = gBS->LocateHandleBuffer (\r
                   ByProtocol,\r
                   &gEfiDriverHealthProtocolGuid,\r
@@ -424,10 +417,13 @@ EfiBootManagerFreeDriverHealthInfo (
 \r
 /**\r
   Repair all the controllers according to the Driver Health status queried.\r
+\r
+  @param ReconnectRepairCount     To record the number of recursive call of\r
+                                  this function itself.\r
 **/\r
 VOID\r
 BmRepairAllControllers (\r
-  VOID\r
+  UINTN       ReconnectRepairCount\r
   )\r
 {\r
   EFI_STATUS                          Status;\r
@@ -441,17 +437,22 @@ BmRepairAllControllers (
   BOOLEAN                             RebootRequired;\r
   EFI_HII_HANDLE                      *HiiHandles;\r
   EFI_FORM_BROWSER2_PROTOCOL          *FormBrowser2;\r
+  UINT32                              MaxRepairCount;\r
+  UINT32                              RepairCount;\r
 \r
   //\r
   // Configure PcdDriverHealthConfigureForm to ZeroGuid to disable driver health check.\r
   //\r
-  if (CompareGuid (PcdGetPtr (PcdDriverHealthConfigureForm), &gZeroGuid)) {\r
+  if (IsZeroGuid (PcdGetPtr (PcdDriverHealthConfigureForm))) {\r
     return;\r
   }\r
 \r
   Status = gBS->LocateProtocol (&gEfiFormBrowser2ProtocolGuid, NULL, (VOID **) &FormBrowser2);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
+  MaxRepairCount = PcdGet32 (PcdMaxRepairCount);\r
+  RepairCount = 0;\r
+\r
   do {\r
     RepairRequired        = FALSE;\r
     ConfigurationRequired = FALSE;\r
@@ -464,7 +465,7 @@ BmRepairAllControllers (
       if (DriverHealthInfo[Index].HealthStatus == EfiDriverHealthStatusConfigurationRequired) {\r
         ConfigurationRequired = TRUE;\r
       }\r
-      \r
+\r
       if (DriverHealthInfo[Index].HealthStatus == EfiDriverHealthStatusRepairRequired) {\r
         RepairRequired        = TRUE;\r
 \r
@@ -512,9 +513,10 @@ BmRepairAllControllers (
         FreePool (HiiHandles);\r
       }\r
     }\r
-  \r
+\r
     EfiBootManagerFreeDriverHealthInfo (DriverHealthInfo, Count);\r
-  } while (RepairRequired || ConfigurationRequired);\r
+    RepairCount++;\r
+  } while ((RepairRequired || ConfigurationRequired) && ((MaxRepairCount == 0) || (RepairCount < MaxRepairCount)));\r
 \r
   RebootRequired    = FALSE;\r
   ReconnectRequired = FALSE;\r
@@ -543,10 +545,6 @@ BmRepairAllControllers (
   EfiBootManagerFreeDriverHealthInfo (DriverHealthInfo, Count);\r
 \r
 \r
-  if (ReconnectRequired) {\r
-    BmRepairAllControllers ();\r
-  }\r
-\r
   DEBUG_CODE (\r
     CHAR16 *ControllerName;\r
 \r
@@ -571,6 +569,15 @@ BmRepairAllControllers (
     EfiBootManagerFreeDriverHealthInfo (DriverHealthInfo, Count);\r
     );\r
 \r
+  if (ReconnectRequired) {\r
+    if (ReconnectRepairCount < MAX_RECONNECT_REPAIR) {\r
+      BmRepairAllControllers (ReconnectRepairCount + 1);\r
+    } else {\r
+      DEBUG ((DEBUG_ERROR, "[%a:%d] Repair failed after %d retries.\n",\r
+        __FUNCTION__, __LINE__, ReconnectRepairCount));\r
+    }\r
+  }\r
+\r
   if (RebootRequired) {\r
     DEBUG ((EFI_D_INFO, "[BDS] One of the Driver Health instances requires rebooting.\n"));\r
     gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);\r