]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/UefiBootManagerLib/BmDriverHealth.c
MdeModulePkg: Change OPTIONAL keyword usage style
[mirror_edk2.git] / MdeModulePkg / Library / UefiBootManagerLib / BmDriverHealth.c
index bffbedaf84469cb6edf55ca3c88b5f36bce52cae..2a850f2953548e0d111668310cdeb65f125a4559 100644 (file)
@@ -1,15 +1,10 @@
 /** @file\r
   Library functions which relates with driver health.\r
 \r
+Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>\r
 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\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
+(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -91,7 +86,7 @@ BmGetControllerName (
 \r
     Status = ComponentName->GetControllerName (\r
                               ComponentName,\r
-                              ControllerHandle, \r
+                              ControllerHandle,\r
                               ChildHandle,\r
                               BestLanguage,\r
                               &ControllerName\r
@@ -130,11 +125,11 @@ BmDisplayMessages (
 \r
   ControllerName = BmGetControllerName (\r
                      DriverHealthInfo->DriverHealthHandle,\r
-                     DriverHealthInfo->ControllerHandle, \r
+                     DriverHealthInfo->ControllerHandle,\r
                      DriverHealthInfo->ChildHandle\r
                      );\r
 \r
-  DEBUG ((EFI_D_INFO, "Controller: %s\n", ControllerName));\r
+  DEBUG ((DEBUG_INFO, "Controller: %s\n", ControllerName));\r
   Print (L"Controller: %s\n", ControllerName);\r
   for (Index = 0; DriverHealthInfo->MessageList[Index].HiiHandle != NULL; Index++) {\r
     String = HiiGetString (\r
@@ -144,7 +139,7 @@ BmDisplayMessages (
                );\r
     if (String != NULL) {\r
       Print (L"  %s\n", String);\r
-      DEBUG ((EFI_D_INFO, "  %s\n", String));\r
+      DEBUG ((DEBUG_INFO, "  %s\n", String));\r
       FreePool (String);\r
     }\r
   }\r
@@ -172,7 +167,7 @@ BmRepairNotify (
   IN UINTN        Limit\r
   )\r
 {\r
-  DEBUG ((EFI_D_INFO, "[BDS]RepairNotify: %d/%d\n", Value, Limit));\r
+  DEBUG ((DEBUG_INFO, "[BDS]RepairNotify: %d/%d\n", Value, Limit));\r
   Print (L"[BDS]RepairNotify: %d/%d\n", Value, Limit);\r
 \r
   return EFI_SUCCESS;\r
@@ -180,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
@@ -197,7 +192,7 @@ BmGetSingleControllerHealthStatus (
   IN OUT EFI_BOOT_MANAGER_DRIVER_HEALTH_INFO **DriverHealthInfo,\r
   IN OUT UINTN                               *Count,\r
   IN  EFI_HANDLE                             DriverHealthHandle,\r
-  IN  EFI_HANDLE                             ControllerHandle,  OPTIONAL\r
+  IN  EFI_HANDLE                             ControllerHandle   OPTIONAL,\r
   IN  EFI_HANDLE                             ChildHandle        OPTIONAL\r
   )\r
 {\r
@@ -217,7 +212,7 @@ BmGetSingleControllerHealthStatus (
                   (VOID **) &DriverHealth\r
                   );\r
   ASSERT_EFI_ERROR (Status);\r
-  \r
+\r
 \r
   if (ControllerHandle == NULL) {\r
     //\r
@@ -422,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
@@ -439,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
@@ -462,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
@@ -510,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
@@ -541,10 +545,6 @@ BmRepairAllControllers (
   EfiBootManagerFreeDriverHealthInfo (DriverHealthInfo, Count);\r
 \r
 \r
-  if (ReconnectRequired) {\r
-    BmRepairAllControllers ();\r
-  }\r
-\r
   DEBUG_CODE (\r
     CHAR16 *ControllerName;\r
 \r
@@ -556,7 +556,7 @@ BmRepairAllControllers (
                          DriverHealthInfo[Index].ChildHandle\r
                          );\r
       DEBUG ((\r
-        EFI_D_INFO,\r
+        DEBUG_INFO,\r
         "%02d: %s - %s\n",\r
         Index,\r
         ControllerName,\r
@@ -569,8 +569,17 @@ 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__, DEBUG_LINE_NUMBER, ReconnectRepairCount));\r
+    }\r
+  }\r
+\r
   if (RebootRequired) {\r
-    DEBUG ((EFI_D_INFO, "[BDS] One of the Driver Health instances requires rebooting.\n"));\r
+    DEBUG ((DEBUG_INFO, "[BDS] One of the Driver Health instances requires rebooting.\n"));\r
     gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);\r
   }\r
 }\r