2 This module produces Boot Manager Policy protocol.
4 Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include <Protocol/BootManagerPolicy.h>
11 #include <Protocol/ManagedNetwork.h>
12 #include <Library/BaseMemoryLib.h>
13 #include <Library/MemoryAllocationLib.h>
14 #include <Library/UefiLib.h>
15 #include <Library/DevicePathLib.h>
16 #include <Library/DebugLib.h>
17 #include <Library/UefiBootServicesTableLib.h>
18 #include <Library/UefiRuntimeServicesTableLib.h>
19 #include <Library/UefiBootManagerLib.h>
21 CHAR16 mNetworkDeviceList
[] = L
"_NDL";
24 Connect all the system drivers to controllers and create the network device list in NV storage.
26 @retval EFI_SUCCESS Network devices are connected.
27 @retval EFI_DEVICE_ERROR No network device is connected.
31 ConnectAllAndCreateNetworkDeviceList (
38 EFI_DEVICE_PATH_PROTOCOL
*SingleDevice
;
39 EFI_DEVICE_PATH_PROTOCOL
*Devices
;
40 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
42 EfiBootManagerConnectAll ();
44 Status
= gBS
->LocateHandleBuffer (ByProtocol
, &gEfiManagedNetworkServiceBindingProtocolGuid
, NULL
, &HandleCount
, &Handles
);
45 if (EFI_ERROR (Status
)) {
51 while (HandleCount
-- != 0) {
52 Status
= gBS
->HandleProtocol (Handles
[HandleCount
], &gEfiDevicePathProtocolGuid
, (VOID
**)&SingleDevice
);
53 if (EFI_ERROR (Status
) || (SingleDevice
== NULL
)) {
57 TempDevicePath
= Devices
;
58 Devices
= AppendDevicePathInstance (Devices
, SingleDevice
);
59 if (TempDevicePath
!= NULL
) {
60 FreePool (TempDevicePath
);
64 if (Devices
!= NULL
) {
65 Status
= gRT
->SetVariable (
68 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
69 GetDevicePathSize (Devices
),
73 // Fails to save the network device list to NV storage is not a fatal error.
74 // Only impact is performance.
79 return (Devices
== NULL
) ? EFI_DEVICE_ERROR
: EFI_SUCCESS
;
83 Connect the network devices.
85 @retval EFI_SUCCESS At least one network device was connected.
86 @retval EFI_DEVICE_ERROR Network devices were not connected due to an error.
95 EFI_DEVICE_PATH_PROTOCOL
*Devices
;
96 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
97 EFI_DEVICE_PATH_PROTOCOL
*SingleDevice
;
100 OneConnected
= FALSE
;
101 GetVariable2 (mNetworkDeviceList
, &gEfiCallerIdGuid
, (VOID
**)&Devices
, NULL
);
102 TempDevicePath
= Devices
;
103 while (TempDevicePath
!= NULL
) {
104 SingleDevice
= GetNextDevicePathInstance (&TempDevicePath
, &Size
);
105 Status
= EfiBootManagerConnectDevicePath (SingleDevice
, NULL
);
106 if (!EFI_ERROR (Status
)) {
110 FreePool (SingleDevice
);
113 if (Devices
!= NULL
) {
121 // Cached network devices list doesn't exist or is NOT valid.
123 return ConnectAllAndCreateNetworkDeviceList ();
128 Connect a device path following the platforms EFI Boot Manager policy.
130 The ConnectDevicePath() function allows the caller to connect a DevicePath using the
131 same policy as the EFI Boot Manger.
133 @param[in] This A pointer to the EFI_BOOT_MANAGER_POLICY_PROTOCOL instance.
134 @param[in] DevicePath Points to the start of the EFI device path to connect.
135 If DevicePath is NULL then all the controllers in the
136 system will be connected using the platforms EFI Boot
138 @param[in] Recursive If TRUE, then ConnectController() is called recursively
139 until the entire tree of controllers below the
140 controller specified by DevicePath have been created.
141 If FALSE, then the tree of controllers is only expanded
142 one level. If DevicePath is NULL then Recursive is ignored.
144 @retval EFI_SUCCESS The DevicePath was connected.
145 @retval EFI_NOT_FOUND The DevicePath was not found.
146 @retval EFI_NOT_FOUND No driver was connected to DevicePath.
147 @retval EFI_SECURITY_VIOLATION The user has no permission to start UEFI device
148 drivers on the DevicePath.
149 @retval EFI_UNSUPPORTED The current TPL is not TPL_APPLICATION.
153 BootManagerPolicyConnectDevicePath (
154 IN EFI_BOOT_MANAGER_POLICY_PROTOCOL
*This
,
155 IN EFI_DEVICE_PATH
*DevicePath
,
160 EFI_HANDLE Controller
;
162 if (EfiGetCurrentTpl () != TPL_APPLICATION
) {
163 return EFI_UNSUPPORTED
;
166 if (DevicePath
== NULL
) {
167 EfiBootManagerConnectAll ();
172 Status
= EfiBootManagerConnectDevicePath (DevicePath
, NULL
);
174 Status
= gBS
->LocateDevicePath (&gEfiDevicePathProtocolGuid
, &DevicePath
, &Controller
);
175 if (!EFI_ERROR (Status
)) {
176 Status
= gBS
->ConnectController (Controller
, NULL
, DevicePath
, FALSE
);
184 Connect a class of devices using the platform Boot Manager policy.
186 The ConnectDeviceClass() function allows the caller to request that the Boot
187 Manager connect a class of devices.
189 If Class is EFI_BOOT_MANAGER_POLICY_CONSOLE_GUID then the Boot Manager will
190 use platform policy to connect consoles. Some platforms may restrict the
191 number of consoles connected as they attempt to fast boot, and calling
192 ConnectDeviceClass() with a Class value of EFI_BOOT_MANAGER_POLICY_CONSOLE_GUID
193 must connect the set of consoles that follow the Boot Manager platform policy,
194 and the EFI_SIMPLE_TEXT_INPUT_PROTOCOL, EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL, and
195 the EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL are produced on the connected handles.
196 The Boot Manager may restrict which consoles get connect due to platform policy,
197 for example a security policy may require that a given console is not connected.
199 If Class is EFI_BOOT_MANAGER_POLICY_NETWORK_GUID then the Boot Manager will
200 connect the protocols the platforms supports for UEFI general purpose network
201 applications on one or more handles. If more than one network controller is
202 available a platform will connect, one, many, or all of the networks based
203 on platform policy. Connecting UEFI networking protocols, like EFI_DHCP4_PROTOCOL,
204 does not establish connections on the network. The UEFI general purpose network
205 application that called ConnectDeviceClass() may need to use the published
206 protocols to establish the network connection. The Boot Manager can optionally
207 have a policy to establish a network connection.
209 If Class is EFI_BOOT_MANAGER_POLICY_CONNECT_ALL_GUID then the Boot Manager
210 will connect all UEFI drivers using the UEFI Boot Service
211 EFI_BOOT_SERVICES.ConnectController(). If the Boot Manager has policy
212 associated with connect all UEFI drivers this policy will be used.
214 A platform can also define platform specific Class values as a properly generated
215 EFI_GUID would never conflict with this specification.
217 @param[in] This A pointer to the EFI_BOOT_MANAGER_POLICY_PROTOCOL instance.
218 @param[in] Class A pointer to an EFI_GUID that represents a class of devices
219 that will be connected using the Boot Mangers platform policy.
221 @retval EFI_SUCCESS At least one devices of the Class was connected.
222 @retval EFI_DEVICE_ERROR Devices were not connected due to an error.
223 @retval EFI_NOT_FOUND The Class is not supported by the platform.
224 @retval EFI_UNSUPPORTED The current TPL is not TPL_APPLICATION.
228 BootManagerPolicyConnectDeviceClass (
229 IN EFI_BOOT_MANAGER_POLICY_PROTOCOL
*This
,
233 if (EfiGetCurrentTpl () != TPL_APPLICATION
) {
234 return EFI_UNSUPPORTED
;
237 if (CompareGuid (Class
, &gEfiBootManagerPolicyConnectAllGuid
)) {
238 ConnectAllAndCreateNetworkDeviceList ();
242 if (CompareGuid (Class
, &gEfiBootManagerPolicyConsoleGuid
)) {
243 return EfiBootManagerConnectAllDefaultConsoles ();
246 if (CompareGuid (Class
, &gEfiBootManagerPolicyNetworkGuid
)) {
247 return ConnectNetwork ();
250 return EFI_NOT_FOUND
;
253 EFI_BOOT_MANAGER_POLICY_PROTOCOL mBootManagerPolicy
= {
254 EFI_BOOT_MANAGER_POLICY_PROTOCOL_REVISION
,
255 BootManagerPolicyConnectDevicePath
,
256 BootManagerPolicyConnectDeviceClass
260 Install Boot Manager Policy Protocol.
262 @param ImageHandle The image handle.
263 @param SystemTable The system table.
265 @retval EFI_SUCEESS The Boot Manager Policy protocol is successfully installed.
266 @retval Other Return status from gBS->InstallMultipleProtocolInterfaces().
271 BootManagerPolicyInitialize (
272 IN EFI_HANDLE ImageHandle
,
273 IN EFI_SYSTEM_TABLE
*SystemTable
278 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL
, &gEfiBootManagerPolicyProtocolGuid
);
281 return gBS
->InstallMultipleProtocolInterfaces (
283 &gEfiBootManagerPolicyProtocolGuid
,