TianoCore EDK2 master
Loading...
Searching...
No Matches
BootManagerPolicyDxe.c
Go to the documentation of this file.
1
9#include <Uefi.h>
14#include <Library/UefiLib.h>
16#include <Library/DebugLib.h>
20
21CHAR16 mNetworkDeviceList[] = L"_NDL";
22
32 VOID
33 )
34{
35 EFI_STATUS Status;
36 EFI_HANDLE *Handles;
37 UINTN HandleCount;
38 EFI_DEVICE_PATH_PROTOCOL *SingleDevice;
40 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
41
43
44 Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiManagedNetworkServiceBindingProtocolGuid, NULL, &HandleCount, &Handles);
45 if (EFI_ERROR (Status)) {
46 Handles = NULL;
47 HandleCount = 0;
48 }
49
50 Devices = NULL;
51 while (HandleCount-- != 0) {
52 Status = gBS->HandleProtocol (Handles[HandleCount], &gEfiDevicePathProtocolGuid, (VOID **)&SingleDevice);
53 if (EFI_ERROR (Status) || (SingleDevice == NULL)) {
54 continue;
55 }
56
57 TempDevicePath = Devices;
58 Devices = AppendDevicePathInstance (Devices, SingleDevice);
59 if (TempDevicePath != NULL) {
60 FreePool (TempDevicePath);
61 }
62 }
63
64 if (Devices != NULL) {
65 Status = gRT->SetVariable (
66 mNetworkDeviceList,
67 &gEfiCallerIdGuid,
68 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
69 GetDevicePathSize (Devices),
70 Devices
71 );
72 //
73 // Fails to save the network device list to NV storage is not a fatal error.
74 // Only impact is performance.
75 //
76 FreePool (Devices);
77 }
78
79 return (Devices == NULL) ? EFI_DEVICE_ERROR : EFI_SUCCESS;
80}
81
90 VOID
91 )
92{
93 EFI_STATUS Status;
94 BOOLEAN OneConnected;
96 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
97 EFI_DEVICE_PATH_PROTOCOL *SingleDevice;
98 UINTN Size;
99
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)) {
107 OneConnected = TRUE;
108 }
109
110 FreePool (SingleDevice);
111 }
112
113 if (Devices != NULL) {
114 FreePool (Devices);
115 }
116
117 if (OneConnected) {
118 return EFI_SUCCESS;
119 } else {
120 //
121 // Cached network devices list doesn't exist or is NOT valid.
122 //
124 }
125}
126
152EFIAPI
155 IN EFI_DEVICE_PATH *DevicePath,
156 IN BOOLEAN Recursive
157 )
158{
159 EFI_STATUS Status;
160 EFI_HANDLE Controller;
161
162 if (EfiGetCurrentTpl () != TPL_APPLICATION) {
163 return EFI_UNSUPPORTED;
164 }
165
166 if (DevicePath == NULL) {
168 return EFI_SUCCESS;
169 }
170
171 if (Recursive) {
172 Status = EfiBootManagerConnectDevicePath (DevicePath, NULL);
173 } else {
174 Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &DevicePath, &Controller);
175 if (!EFI_ERROR (Status)) {
176 Status = gBS->ConnectController (Controller, NULL, DevicePath, FALSE);
177 }
178 }
179
180 return Status;
181}
182
227EFIAPI
230 IN EFI_GUID *Class
231 )
232{
233 if (EfiGetCurrentTpl () != TPL_APPLICATION) {
234 return EFI_UNSUPPORTED;
235 }
236
237 if (CompareGuid (Class, &gEfiBootManagerPolicyConnectAllGuid)) {
239 return EFI_SUCCESS;
240 }
241
242 if (CompareGuid (Class, &gEfiBootManagerPolicyConsoleGuid)) {
244 }
245
246 if (CompareGuid (Class, &gEfiBootManagerPolicyNetworkGuid)) {
247 return ConnectNetwork ();
248 }
249
250 return EFI_NOT_FOUND;
251}
252
253EFI_BOOT_MANAGER_POLICY_PROTOCOL mBootManagerPolicy = {
254 EFI_BOOT_MANAGER_POLICY_PROTOCOL_REVISION,
257};
258
270EFIAPI
272 IN EFI_HANDLE ImageHandle,
273 IN EFI_SYSTEM_TABLE *SystemTable
274 )
275{
276 EFI_HANDLE Handle;
277
278 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiBootManagerPolicyProtocolGuid);
279
280 Handle = NULL;
281 return gBS->InstallMultipleProtocolInterfaces (
282 &Handle,
283 &gEfiBootManagerPolicyProtocolGuid,
284 &mBootManagerPolicy,
285 NULL
286 );
287}
UINT64 UINTN
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
Definition: MemLibGuid.c:73
EFI_STATUS ConnectNetwork(VOID)
EFI_STATUS EFIAPI BootManagerPolicyConnectDeviceClass(IN EFI_BOOT_MANAGER_POLICY_PROTOCOL *This, IN EFI_GUID *Class)
EFI_STATUS ConnectAllAndCreateNetworkDeviceList(VOID)
EFI_STATUS EFIAPI BootManagerPolicyInitialize(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS EFIAPI BootManagerPolicyConnectDevicePath(IN EFI_BOOT_MANAGER_POLICY_PROTOCOL *This, IN EFI_DEVICE_PATH *DevicePath, IN BOOLEAN Recursive)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI AppendDevicePathInstance(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL, IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI GetNextDevicePathInstance(IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath, OUT UINTN *Size)
UINTN EFIAPI GetDevicePathSize(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_RUNTIME_SERVICES * gRT
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid)
Definition: DebugLib.h:535
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_STATUS EFIAPI EfiBootManagerConnectAllDefaultConsoles(VOID)
Definition: BmConsole.c:712
EFI_STATUS EFIAPI EfiBootManagerConnectDevicePath(IN EFI_DEVICE_PATH_PROTOCOL *DevicePathToConnect, OUT EFI_HANDLE *MatchingHandle OPTIONAL)
Definition: BmConnect.c:108
VOID EFIAPI EfiBootManagerConnectAll(VOID)
Definition: BmConnect.c:67
EFI_BOOT_SERVICES * gBS
EFI_TPL EFIAPI EfiGetCurrentTpl(VOID)
Definition: UefiLib.c:375
EFI_STATUS EFIAPI GetVariable2(IN CONST CHAR16 *Name, IN CONST EFI_GUID *Guid, OUT VOID **Value, OUT UINTN *Size OPTIONAL)
Definition: UefiLib.c:1317
#define EFI_VARIABLE_NON_VOLATILE
@ ByProtocol
Definition: UefiSpec.h:1518
Definition: Base.h:213