From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from smarthost01b.ixn.mail.zen.net.uk (smarthost01b.ixn.mail.zen.net.uk [212.23.1.21])
 by mx.groups.io with SMTP id smtpd.web09.459.1646434364906100243
 for <devel@edk2.groups.io>;
 Fri, 04 Mar 2022 14:52:45 -0800
Authentication-Results: mx.groups.io;
 dkim=missing; spf=permerror, err=parse error for token &{10 18 sdn.klaviyomail.com}: permanent DNS error (domain: starlabs.systems, ip: 212.23.1.21, mailfrom: sean@starlabs.systems)
Received: from [217.155.46.38] (helo=sean-StarBook.lan)
	by smarthost01b.ixn.mail.zen.net.uk with esmtp (Exim 4.90_1)
	(envelope-from <sean@starlabs.systems>)
	id 1nQGmv-0000Vl-G5; Fri, 04 Mar 2022 22:52:41 +0000
From: "Sean Rhodes" <sean@starlabs.systems>
To: devel@edk2.groups.io
Cc: Matt DeVillier <matt.devillier@gmail.com>,
	Zhichao Gao <zhichao.gao@intel.com>,
	Ray Ni <ray.ni@intel.com>,
	Sean Rhodes <sean@starlabs.systems>
Subject: [PATCH 1/2] MdeModulePkg/UefiBootManagerLib: Add Pcd to prioritize internal devices
Date: Fri,  4 Mar 2022 22:52:39 +0000
Message-Id: <8d861caf929257f2c4b060ee2818da48e4bd6548.1646434359.git.sean@starlabs.systems>
X-Mailer: git-send-email 2.32.0
MIME-Version: 1.0
X-Originating-smarthost01b-IP: [217.155.46.38]
Feedback-ID: 217.155.46.38
Content-Transfer-Encoding: quoted-printable

From: Matt DeVillier <matt.devillier@gmail.com>

Add Pcd to allow configuring internal devices to be prioritized over
internally-attached USB devices, such as card readers, over SATA, NVMe
and eMMC drives.

Cc: Zhichao Gao <zhichao.gao@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Signed-off-by: Matt DeVillier <matt.devillier@gmail.com>
Signed-off-by: Sean Rhodes <sean@starlabs.systems>
---
 MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c       | 10 ++++++++--
 .../Library/UefiBootManagerLib/UefiBootManagerLib.inf  |  1 +
 MdeModulePkg/MdeModulePkg.dec                          |  3 +++
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c b/MdeModulePk=
g/Library/UefiBootManagerLib/BmBoot.c
index 962892d38f..28c3cff471 100644
--- a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
+++ b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
@@ -2214,8 +2214,14 @@ BmEnumerateBootOptions (
       //=0D
       // Skip the fixed block io then the removable block io=0D
       //=0D
-      if (BlkIo->Media->RemovableMedia =3D=3D ((Removable =3D=3D 0) ? FALS=
E : TRUE)) {=0D
-        continue;=0D
+      if (FixedPcdGetBool (PcdPrioritizeInternal)) {=0D
+        if (BlkIo->Media->RemovableMedia =3D=3D (Removable =3D=3D 0)) {=0D
+          continue;=0D
+        }=0D
+      } else {=0D
+        if (BlkIo->Media->RemovableMedia =3D=3D ((Removable =3D=3D 0) ? FA=
LSE : TRUE)) {=0D
+          continue;=0D
+        }=0D
       }=0D
 =0D
       Description =3D BmGetBootDescription (Handles[Index]);=0D
diff --git a/MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf=
 b/MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf
index fe05d5f1cc..207420e334 100644
--- a/MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf
+++ b/MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf
@@ -119,3 +119,4 @@
   gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile                   =
  ## CONSUMES=0D
   gEfiMdeModulePkgTokenSpaceGuid.PcdDriverHealthConfigureForm             =
  ## SOMETIMES_CONSUMES=0D
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxRepairCount                        =
  ## CONSUMES=0D
+  gEfiMdeModulePkgTokenSpaceGuid.PcdPrioritizeInternal=0D
diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec
index 463e889e9a..ded82d1cff 100644
--- a/MdeModulePkg/MdeModulePkg.dec
+++ b/MdeModulePkg/MdeModulePkg.dec
@@ -1077,6 +1077,9 @@
   # @Prompt Enable UEFI Stack Guard.=0D
   gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard|FALSE|BOOLEAN|0x30001055=
=0D
 =0D
+  # Prioritize Internal Devices=0D
+  gEfiMdeModulePkgTokenSpaceGuid.PcdPrioritizeInternal|FALSE|BOOLEAN|0x000=
00031=0D
+=0D
 [PcdsFixedAtBuild, PcdsPatchableInModule]=0D
   ## Dynamic type PCD can be registered callback function for Pcd setting =
action.=0D
   #  PcdMaxPeiPcdCallBackNumberPerPcdEntry indicates the maximum number of=
 callback function=0D
--=20
2.32.0