TianoCore EDK2 master
Loading...
Searching...
No Matches
MemoryAttributeManagerDxe.c
Go to the documentation of this file.
1
9#include <Uefi.h>
10#include <Library/DebugLib.h>
12#include <Library/HiiLib.h>
15
17
18extern UINT8 MemoryAttributeManagerDxeHiiBin[];
19extern UINT8 MemoryAttributeManagerDxeStrings[];
20
21typedef struct {
22 VENDOR_DEVICE_PATH VendorDevicePath;
25
26STATIC HII_VENDOR_DEVICE_PATH mVendorDevicePath = {
27 {
28 {
31 {
32 (UINT8)(sizeof (VENDOR_DEVICE_PATH)),
33 (UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8)
34 }
35 },
36 MEMORY_ATTRIBUTE_MANAGER_FORMSET_GUID
37 },
38 {
39 END_DEVICE_PATH_TYPE,
40 END_ENTIRE_DEVICE_PATH_SUBTYPE,
41 {
42 (UINT8)(END_DEVICE_PATH_LENGTH),
43 (UINT8)((END_DEVICE_PATH_LENGTH) >> 8)
44 }
45 }
46};
47
56EFIAPI
58 VOID
59 )
60{
61 EFI_STATUS Status;
62 EFI_HII_HANDLE HiiHandle;
63 EFI_HANDLE DriverHandle;
64
65 DriverHandle = NULL;
66 Status = gBS->InstallMultipleProtocolInterfaces (
67 &DriverHandle,
68 &gEfiDevicePathProtocolGuid,
69 &mVendorDevicePath,
70 NULL
71 );
72 if (EFI_ERROR (Status)) {
73 return Status;
74 }
75
76 HiiHandle = HiiAddPackages (
77 &gMemoryAttributeManagerFormSetGuid,
78 DriverHandle,
79 MemoryAttributeManagerDxeStrings,
80 MemoryAttributeManagerDxeHiiBin,
81 NULL
82 );
83
84 if (HiiHandle == NULL) {
85 gBS->UninstallMultipleProtocolInterfaces (
86 DriverHandle,
87 &gEfiDevicePathProtocolGuid,
88 &mVendorDevicePath,
89 NULL
90 );
91 return EFI_OUT_OF_RESOURCES;
92 }
93
94 return EFI_SUCCESS;
95}
96
101STATIC
102VOID
104 VOID
105 )
106{
107 EFI_STATUS Status;
108 EFI_HANDLE Handle;
109 UINTN Size;
110 VOID *MemoryAttributeProtocol;
111
112 Size = sizeof (Handle);
113 Status = gBS->LocateHandle (
115 &gEfiMemoryAttributeProtocolGuid,
116 NULL,
117 &Size,
118 &Handle
119 );
120 if (EFI_ERROR (Status)) {
121 ASSERT (Status == EFI_NOT_FOUND);
122 return;
123 }
124
125 Status = gBS->HandleProtocol (
126 Handle,
127 &gEfiMemoryAttributeProtocolGuid,
128 &MemoryAttributeProtocol
129 );
130 ASSERT_EFI_ERROR (Status);
131 if (EFI_ERROR (Status)) {
132 return;
133 }
134
135 Status = gBS->UninstallProtocolInterface (
136 Handle,
137 &gEfiMemoryAttributeProtocolGuid,
138 MemoryAttributeProtocol
139 );
140 ASSERT_EFI_ERROR (Status);
141 if (EFI_ERROR (Status)) {
142 return;
143 }
144
145 DEBUG ((
146 DEBUG_INFO,
147 "EFI Memory Attribute Protocol disabled due to user/platform preference!\n"
148 ));
149}
150
161EFIAPI
163 IN EFI_HANDLE ImageHandle,
164 IN EFI_SYSTEM_TABLE *SystemTable
165 )
166{
167 EFI_STATUS Status;
168 UINTN Size;
170
171 Config.Enabled = PROTOCOL_ENABLED_DEFAULT;
172
174 Status = gRT->GetVariable (
175 MEMORY_ATTRIBUTE_MANAGER_DATA_VAR_NAME,
176 &gMemoryAttributeManagerFormSetGuid,
177 NULL,
178 &Size,
179 &Config
180 );
181 if (EFI_ERROR (Status)) {
182 Status = gRT->SetVariable (
183 MEMORY_ATTRIBUTE_MANAGER_DATA_VAR_NAME,
184 &gMemoryAttributeManagerFormSetGuid,
185 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
186 Size,
187 &Config
188 );
189 ASSERT_EFI_ERROR (Status);
190 }
191
192 if (!Config.Enabled) {
194 }
195
196 return InstallHiiPages ();
197}
UINT64 UINTN
#define HARDWARE_DEVICE_PATH
Definition: DevicePath.h:68
#define HW_VENDOR_DP
Definition: DevicePath.h:133
EFI_HII_HANDLE EFIAPI HiiAddPackages(IN CONST EFI_GUID *PackageListGuid, IN EFI_HANDLE DeviceHandle OPTIONAL,...)
Definition: HiiLib.c:141
EFI_RUNTIME_SERVICES * gRT
#define NULL
Definition: Base.h:319
#define STATIC
Definition: Base.h:264
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
STATIC VOID UninstallEfiMemoryAttributeProtocol(VOID)
STATIC EFI_STATUS EFIAPI InstallHiiPages(VOID)
EFI_STATUS EFIAPI MemoryAttributeManagerInitialize(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
VOID * EFI_HII_HANDLE
#define EFI_VARIABLE_NON_VOLATILE
@ ByProtocol
Definition: UefiSpec.h:1518