TianoCore EDK2 master
Loading...
Searching...
No Matches
FaultTolerantWriteDxe.c
Go to the documentation of this file.
1
49#include "FaultTolerantWrite.h"
50VOID *mFvbRegistration = NULL;
51
66 IN EFI_HANDLE FvBlockHandle,
68 )
69{
70 //
71 // To get the FVB protocol interface on the handle
72 //
73 return gBS->HandleProtocol (
74 FvBlockHandle,
75 &gEfiFirmwareVolumeBlockProtocolGuid,
76 (VOID **)FvBlock
77 );
78}
79
92 OUT VOID **SarProtocol
93 )
94{
95 EFI_STATUS Status;
96
97 //
98 // Locate Swap Address Range protocol
99 //
100 Status = gBS->LocateProtocol (
101 &gEfiSwapAddressRangeProtocolGuid,
102 NULL,
103 SarProtocol
104 );
105 return Status;
106}
107
125 OUT UINTN *NumberHandles,
126 OUT EFI_HANDLE **Buffer
127 )
128{
129 EFI_STATUS Status;
130
131 //
132 // Locate all handles of Fvb protocol
133 //
134 Status = gBS->LocateHandleBuffer (
136 &gEfiFirmwareVolumeBlockProtocolGuid,
137 NULL,
138 NumberHandles,
139 Buffer
140 );
141 return Status;
142}
143
151VOID
152EFIAPI
154 IN EFI_EVENT Event,
155 IN VOID *Context
156 )
157{
158 EFI_STATUS Status;
160 EFI_FTW_DEVICE *FtwDevice;
161
162 //
163 // Just return to avoid installing FaultTolerantWriteProtocol again
164 // if Fault Tolerant Write protocol has been installed.
165 //
166 Status = gBS->LocateProtocol (
167 &gEfiFaultTolerantWriteProtocolGuid,
168 NULL,
169 (VOID **)&FtwProtocol
170 );
171 if (!EFI_ERROR (Status)) {
172 return;
173 }
174
175 //
176 // Found proper FVB protocol and initialize FtwDevice for protocol installation
177 //
178 FtwDevice = (EFI_FTW_DEVICE *)Context;
179 Status = InitFtwProtocol (FtwDevice);
180 if (EFI_ERROR (Status)) {
181 return;
182 }
183
184 //
185 // Install protocol interface
186 //
187 Status = gBS->InstallProtocolInterface (
188 &FtwDevice->Handle,
189 &gEfiFaultTolerantWriteProtocolGuid,
191 &FtwDevice->FtwInstance
192 );
193 ASSERT_EFI_ERROR (Status);
194
195 Status = gBS->CloseEvent (Event);
196 ASSERT_EFI_ERROR (Status);
197
198 return;
199}
200
213EFIAPI
215 IN EFI_HANDLE ImageHandle,
216 IN EFI_SYSTEM_TABLE *SystemTable
217 )
218{
219 EFI_STATUS Status;
220 EFI_FTW_DEVICE *FtwDevice;
221
222 FtwDevice = NULL;
223
224 //
225 // Allocate private data structure for FTW protocol and do some initialization
226 //
227 Status = InitFtwDevice (&FtwDevice);
228 if (EFI_ERROR (Status)) {
229 return Status;
230 }
231
232 //
233 // Register FvbNotificationEvent () notify function.
234 //
236 &gEfiFirmwareVolumeBlockProtocolGuid,
237 TPL_CALLBACK,
239 (VOID *)FtwDevice,
240 &mFvbRegistration
241 );
242
243 return EFI_SUCCESS;
244}
245
261UINT32
263 IN VOID *Buffer,
264 IN UINTN Length
265 )
266{
267 EFI_STATUS Status;
268 UINT32 ReturnValue;
269
270 Status = gBS->CalculateCrc32 (Buffer, Length, &ReturnValue);
271 ASSERT_EFI_ERROR (Status);
272
273 return ReturnValue;
274}
UINT64 UINTN
EFI_STATUS FtwGetSarProtocol(OUT VOID **SarProtocol)
EFI_STATUS EFIAPI FaultTolerantWriteInitialize(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
VOID EFIAPI FvbNotificationEvent(IN EFI_EVENT Event, IN VOID *Context)
UINT32 FtwCalculateCrc32(IN VOID *Buffer, IN UINTN Length)
EFI_STATUS GetFvbCountAndBuffer(OUT UINTN *NumberHandles, OUT EFI_HANDLE **Buffer)
EFI_STATUS FtwGetFvbByHandle(IN EFI_HANDLE FvBlockHandle, OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvBlock)
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_EVENT
Definition: UefiBaseType.h:37
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
EFI_EVENT EFIAPI EfiCreateProtocolNotifyEvent(IN EFI_GUID *ProtocolGuid, IN EFI_TPL NotifyTpl, IN EFI_EVENT_NOTIFY NotifyFunction, IN VOID *NotifyContext OPTIONAL, OUT VOID **Registration)
Definition: UefiLib.c:134
@ EFI_NATIVE_INTERFACE
Definition: UefiSpec.h:1193
@ ByProtocol
Definition: UefiSpec.h:1518
EFI_STATUS InitFtwDevice(OUT EFI_FTW_DEVICE **FtwData)
Definition: FtwMisc.c:992
EFI_STATUS InitFtwProtocol(IN OUT EFI_FTW_DEVICE *FtwDevice)
Definition: FtwMisc.c:1236