]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/BootDiscoveryPolicyUiLib/BootDiscoveryPolicyUiLib.c
MdeModulePkg: Add BootDiscoveryPolicyUiLib.
[mirror_edk2.git] / MdeModulePkg / Library / BootDiscoveryPolicyUiLib / BootDiscoveryPolicyUiLib.c
1 /** @file
2 Boot Discovery Policy UI for Boot Maintenance menu.
3
4 Copyright (c) 2021, ARM Ltd. All rights reserved.<BR>
5 Copyright (c) 2021, Semihalf All rights reserved.<BR>
6
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8
9 **/
10
11 #include <Guid/BootDiscoveryPolicy.h>
12 #include <Library/UefiDriverEntryPoint.h>
13 #include <Library/UefiBootServicesTableLib.h>
14 #include <Library/UefiRuntimeServicesTableLib.h>
15 #include <Library/BaseLib.h>
16 #include <Library/DevicePathLib.h>
17 #include <Library/DebugLib.h>
18 #include <Library/HiiLib.h>
19 #include <Library/UefiLib.h>
20 #include <Library/BaseMemoryLib.h>
21 #include <Include/Library/PcdLib.h>
22
23 ///
24 /// HII specific Vendor Device Path definition.
25 ///
26 typedef struct {
27 VENDOR_DEVICE_PATH VendorDevicePath;
28 EFI_DEVICE_PATH_PROTOCOL End;
29 } HII_VENDOR_DEVICE_PATH;
30
31 extern UINT8 BootDiscoveryPolicyUiLibVfrBin[];
32
33 EFI_HII_HANDLE mBPHiiHandle = NULL;
34 EFI_HANDLE mBPDriverHandle = NULL;
35
36 STATIC HII_VENDOR_DEVICE_PATH mVendorDevicePath = {
37 {
38 {
39 HARDWARE_DEVICE_PATH,
40 HW_VENDOR_DP,
41 {
42 (UINT8)(sizeof (VENDOR_DEVICE_PATH)),
43 (UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8)
44 }
45 },
46 BOOT_DISCOVERY_POLICY_MGR_FORMSET_GUID
47 },
48 {
49 END_DEVICE_PATH_TYPE,
50 END_ENTIRE_DEVICE_PATH_SUBTYPE,
51 {
52 (UINT8)(END_DEVICE_PATH_LENGTH),
53 (UINT8)((END_DEVICE_PATH_LENGTH) >> 8)
54 }
55 }
56 };
57
58 /**
59
60 Initialize Boot Maintenance Menu library.
61
62 @param ImageHandle The image handle.
63 @param SystemTable The system table.
64
65 @retval EFI_SUCCESS Install Boot manager menu success.
66 @retval Other Return error status.gBPDisplayLibGuid
67
68 **/
69 EFI_STATUS
70 EFIAPI
71 BootDiscoveryPolicyUiLibConstructor (
72 IN EFI_HANDLE ImageHandle,
73 IN EFI_SYSTEM_TABLE *SystemTable
74 )
75 {
76 EFI_STATUS Status;
77 UINTN Size;
78 UINT32 BootDiscoveryPolicy;
79
80 Size = sizeof (UINT32);
81 Status = gRT->GetVariable (
82 BOOT_DISCOVERY_POLICY_VAR,
83 &gBootDiscoveryPolicyMgrFormsetGuid,
84 NULL,
85 &Size,
86 &BootDiscoveryPolicy
87 );
88 if (EFI_ERROR (Status)) {
89 Status = PcdSet32S (PcdBootDiscoveryPolicy, PcdGet32 (PcdBootDiscoveryPolicy));
90 ASSERT_EFI_ERROR (Status);
91 }
92
93 Status = gBS->InstallMultipleProtocolInterfaces (
94 &mBPDriverHandle,
95 &gEfiDevicePathProtocolGuid,
96 &mVendorDevicePath,
97 NULL
98 );
99 if (EFI_ERROR (Status)) {
100 return Status;
101 }
102
103 //
104 // Publish our HII data
105 //
106 mBPHiiHandle = HiiAddPackages (
107 &gBootDiscoveryPolicyMgrFormsetGuid,
108 mBPDriverHandle,
109 BootDiscoveryPolicyUiLibVfrBin,
110 BootDiscoveryPolicyUiLibStrings,
111 NULL
112 );
113 if (mBPHiiHandle == NULL) {
114 gBS->UninstallMultipleProtocolInterfaces (
115 mBPDriverHandle,
116 &gEfiDevicePathProtocolGuid,
117 &mVendorDevicePath,
118 NULL
119 );
120
121 return EFI_OUT_OF_RESOURCES;
122 }
123
124 return EFI_SUCCESS;
125 }
126
127 /**
128 Destructor of Boot Maintenance menu library.
129
130 @param ImageHandle The firmware allocated handle for the EFI image.
131 @param SystemTable A pointer to the EFI System Table.
132
133 @retval EFI_SUCCESS The destructor completed successfully.
134 @retval Other value The destructor did not complete successfully.
135
136 **/
137 EFI_STATUS
138 EFIAPI
139 BootDiscoveryPolicyUiLibDestructor (
140 IN EFI_HANDLE ImageHandle,
141 IN EFI_SYSTEM_TABLE *SystemTable
142 )
143 {
144
145 if (mBPDriverHandle != NULL) {
146 gBS->UninstallProtocolInterface (
147 mBPDriverHandle,
148 &gEfiDevicePathProtocolGuid,
149 &mVendorDevicePath
150 );
151 mBPDriverHandle = NULL;
152 }
153
154 if (mBPHiiHandle != NULL) {
155 HiiRemovePackages (mBPHiiHandle);
156 mBPHiiHandle = NULL;
157 }
158
159 return EFI_SUCCESS;
160 }