<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <p>Hi Grzegorz,</p>
    <p>Thank you for this patch. I have a few minor suggestions,
      otherwise this patch looks good to me.</p>
    <p>I have tested this patch on FVP and Juno and both platforms work
      fine.</p>
    <p>Reviewed-by: Sami Mujawar <a class="moz-txt-link-rfc2396E" href="mailto:sami.mujawar@arm.com"><sami.mujawar@arm.com></a></p>
    <p>Regards,</p>
    <p>Sami Mujawar<br>
    </p>
    <br>
    <div class="moz-cite-prefix">On 18/08/2021 08:43 PM, Samer
      El-Haj-Mahmoud wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:PAXPR08MB6987ACD7293D0BDD0C9E34A290FF9@PAXPR08MB6987.eurprd08.prod.outlook.com">
      <pre wrap="">+ Sami for ArmPkg review

</pre>
      <blockquote type="cite">
        <pre wrap="">-----Original Message-----
From: Grzegorz Bernacki <a class="moz-txt-link-rfc2396E" href="mailto:gjb@semihalf.com"><gjb@semihalf.com></a>
Sent: Monday, August 16, 2021 6:09 AM
To: <a class="moz-txt-link-abbreviated" href="mailto:devel@edk2.groups.io">devel@edk2.groups.io</a>
Cc: <a class="moz-txt-link-abbreviated" href="mailto:leif@nuviainc.com">leif@nuviainc.com</a>; <a class="moz-txt-link-abbreviated" href="mailto:ardb+tianocore@kernel.org">ardb+tianocore@kernel.org</a>; Samer El-Haj-Mahmoud
<a class="moz-txt-link-rfc2396E" href="mailto:Samer.El-Haj-Mahmoud@arm.com"><Samer.El-Haj-Mahmoud@arm.com></a>; Sunny Wang
<a class="moz-txt-link-rfc2396E" href="mailto:Sunny.Wang@arm.com"><Sunny.Wang@arm.com></a>; <a class="moz-txt-link-abbreviated" href="mailto:mw@semihalf.com">mw@semihalf.com</a>; <a class="moz-txt-link-abbreviated" href="mailto:upstream@semihalf.com">upstream@semihalf.com</a>;
Grzegorz Bernacki <a class="moz-txt-link-rfc2396E" href="mailto:gjb@semihalf.com"><gjb@semihalf.com></a>
Subject: [edk2-platforms PATCH v2] ArmPkg: Enable boot discovery policy for
ARM package.

This commit adds code which check BootDiscoveryPolicy variable and
calls Boot Policy Manager Protocol to connect device specified by
the variable. To enable that mechanism for platform
EfiMdeModulePkgTokenSpaceGuid.PcdBootDiscoveryPolicy PCD must be
added to DSC file and BootDiscoveryPolicyUiLib should be added to
UiApp libraries.

Signed-off-by: Grzegorz Bernacki <a class="moz-txt-link-rfc2396E" href="mailto:gjb@semihalf.com"><gjb@semihalf.com></a>
---
 ArmPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf |  5
+
 ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c               | 96
+++++++++++++++++++-
 2 files changed, 100 insertions(+), 1 deletion(-)

diff --git
a/ArmPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
b/ArmPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
index 353d7a967b..86751b45f8 100644
--- a/ArmPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
+++
b/ArmPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
@@ -65,11 +65,15 @@

 [Pcd]
   gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut
+  gEfiMdeModulePkgTokenSpaceGuid.PcdBootDiscoveryPolicy

 [Guids]
+  gBootDiscoveryPolicyMgrFormsetGuid
   gEdkiiNonDiscoverableEhciDeviceGuid
   gEdkiiNonDiscoverableUhciDeviceGuid
   gEdkiiNonDiscoverableXhciDeviceGuid
+  gEfiBootManagerPolicyNetworkGuid
+  gEfiBootManagerPolicyConnectAllGuid
   gEfiFileInfoGuid
   gEfiFileSystemInfoGuid
   gEfiFileSystemVolumeLabelInfoIdGuid
@@ -79,6 +83,7 @@

 [Protocols]
   gEdkiiNonDiscoverableDeviceProtocolGuid
+  gEfiBootManagerPolicyProtocolGuid
   gEfiDevicePathProtocolGuid
   gEfiGraphicsOutputProtocolGuid
   gEfiLoadedImageProtocolGuid
diff --git a/ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c
b/ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c
index 5ceb23d822..ef5c323743 100644
--- a/ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c
+++ b/ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c
@@ -2,9 +2,10 @@
   Implementation for PlatformBootManagerLib library class interfaces.

   Copyright (C) 2015-2016, Red Hat, Inc.
-  Copyright (c) 2014 - 2019, ARM Ltd. All rights reserved.<BR>
+  Copyright (c) 2014 - 2021, ARM Ltd. All rights reserved.<BR>
   Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
   Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
+  Copyright (c) 2021, Semihalf All rights reserved.<BR>

   SPDX-License-Identifier: BSD-2-Clause-Patent

@@ -19,6 +20,7 @@
 #include <Library/UefiBootManagerLib.h>
 #include <Library/UefiLib.h>
 #include <Library/UefiRuntimeServicesTableLib.h>
+#include <Protocol/BootManagerPolicy.h>
 #include <Protocol/DevicePath.h>
 #include <Protocol/EsrtManagement.h>
 #include <Protocol/GraphicsOutput.h>
@@ -27,6 +29,7 @@
 #include <Protocol/PciIo.h>
 #include <Protocol/PciRootBridgeIo.h>
 #include <Protocol/PlatformBootManager.h>
+#include <Guid/BootDiscoveryPolicy.h>
 #include <Guid/EventGroup.h>
 #include <Guid/NonDiscoverableDevice.h>
 #include <Guid/TtyTerm.h>
@@ -703,6 +706,91 @@ HandleCapsules (

 #define VERSION_STRING_PREFIX    L"Tianocore/EDK2 firmware version "

+/**
+  This functions checks the value of BootDiscoverPolicy variable and
+  connect devices of class specified by that variable. Then it refreshes
+  Boot order for newly discovered boot device.
+
+  @retval  EFI_SUCCESS  Devices connected successfully or connection
+                        not required.
+  @retval  others       Return values from GetVariable(), LocateProtocol()
+                        and ConnectDeviceClass().
+**/
+STATIC
+EFI_STATUS
+BootDiscoveryPolicyHandler (
+  VOID
+  )
+{
+  EFI_STATUS                       Status;
+  UINT32                           DiscoveryPolicy;
+  UINTN                            Size;
+  EFI_BOOT_MANAGER_POLICY_PROTOCOL *BMPolicy;
+  EFI_GUID                         *Class;
+
+  Size = sizeof (DiscoveryPolicy);
+  Status = gRT->GetVariable (
+                  BOOT_DISCOVERY_POLICY_VAR,
+                  &gBootDiscoveryPolicyMgrFormsetGuid,
+                  NULL,
+                  &Size,
+                  &DiscoveryPolicy
+                  );
+  if (Status == EFI_NOT_FOUND) {
+    Status = PcdSet32S (PcdBootDiscoveryPolicy, PcdGet32
(PcdBootDiscoveryPolicy));
+    if (Status == EFI_NOT_FOUND) {
+      return EFI_SUCCESS;
+    } else if (EFI_ERROR (Status)) {
+      return Status;
+    }
+    DiscoveryPolicy = PcdGet32 (PcdBootDiscoveryPolicy);</pre>
      </blockquote>
    </blockquote>
    [SAMI] Can 'DiscoveryPolicy' be initialised a few lines above and
    used in the call to PcdSet32S ()?
    <blockquote type="cite" cite="mid:PAXPR08MB6987ACD7293D0BDD0C9E34A290FF9@PAXPR08MB6987.eurprd08.prod.outlook.com">
      <blockquote type="cite">
        <pre wrap="">
+  } else if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  if (DiscoveryPolicy == BDP_CONNECT_MINIMAL) {
+    return EFI_SUCCESS;
+  }
+
+  switch (DiscoveryPolicy) {
+    case BDP_CONNECT_NET:
+      Class = &gEfiBootManagerPolicyNetworkGuid;
+      break;
+    case BDP_CONNECT_ALL:
+      Class = &gEfiBootManagerPolicyConnectAllGuid;
+      break;
+    default:
+      DEBUG ((
+        DEBUG_INFO,
+        "%a - Unexpected DiscoveryPolicy (0x%x). Run Minimal Discovery
Policy\n",
+        __FUNCTION__,
+        DiscoveryPolicy
+        ));
+      return EFI_SUCCESS;
+  }
+
+  Status = gBS->LocateProtocol (
+                  &gEfiBootManagerPolicyProtocolGuid,
+                  NULL,
+                  (VOID **)&BMPolicy
+                  );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_INFO, "%a - Failed to locate
gEfiBootManagerPolicyProtocolGuid."
+      "Driver connect will be skipped.\n", __FUNCTION__));
+    return Status;
+  }
+
+  Status = BMPolicy->ConnectDeviceClass (BMPolicy, Class);
+  if (EFI_ERROR (Status)){
+    DEBUG ((DEBUG_ERROR, "%a - ConnectDeviceClass returns - %r\n",
__FUNCTION__, Status));
+    return Status;
+  }
+
+  EfiBootManagerRefreshAllBootOption();</pre>
      </blockquote>
    </blockquote>
    [SAMI] Please add a space after the function name and the opening
    parenthesis<span style="font-size:11.0pt;line-height:107%;
font-family:"Calibri",sans-serif;mso-ascii-theme-font:minor-latin;mso-fareast-font-family:
DengXian;mso-fareast-theme-font:minor-fareast;mso-hansi-theme-font:minor-latin;
      mso-bidi-font-family:"Times New
      Roman";mso-bidi-theme-font:minor-bidi;
mso-ansi-language:EN-GB;mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA"></span>.
    <blockquote type="cite" cite="mid:PAXPR08MB6987ACD7293D0BDD0C9E34A290FF9@PAXPR08MB6987.eurprd08.prod.outlook.com">
      <blockquote type="cite">
        <pre wrap="">
+
+  return EFI_SUCCESS;
+}
+
 /**
   Do the platform specific action after the console is ready
   Possible things that can be done in PlatformBootManagerAfterConsole:
@@ -753,6 +841,12 @@ PlatformBootManagerAfterConsole (
     }
   }

+  //
+  // Connect device specified by BootDiscoverPolicy variable and
+  // refresh Boot order for newly discovered boot devices
+  //
+  BootDiscoveryPolicyHandler ();
+
   //
   // On ARM, there is currently no reason to use the phased capsule
   // update approach where some capsules are dispatched before EndOfDxe
--
2.25.1
</pre>
      </blockquote>
      <pre wrap="">
</pre>
    </blockquote>
    <br>
  </body>
</html>


 <div width="1" style="color:white;clear:both">_._,_._,_</div> <hr>   Groups.io Links:<p>   You receive all messages sent to this group.    <p> <a target="_blank" href="https://edk2.groups.io/g/devel/message/79642">View/Reply Online (#79642)</a> |    |  <a target="_blank" href="https://groups.io/mt/84919870/1813853">Mute This Topic</a>  | <a href="https://edk2.groups.io/g/devel/post">New Topic</a><br>    <a href="https://edk2.groups.io/g/devel/editsub/1813853">Your Subscription</a> | <a href="mailto:devel+owner@edk2.groups.io">Contact Group Owner</a> |  <a href="https://edk2.groups.io/g/devel/unsub">Unsubscribe</a>  [edk2-devel-archive@redhat.com]<br> <div width="1" style="color:white;clear:both">_._,_._,_</div>