]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/EdkFvbServiceLib/Fvb.c
Add INF extension Information
[mirror_edk2.git] / MdeModulePkg / Library / EdkFvbServiceLib / Fvb.c
CommitLineData
677472aa 1/**@file\r
677472aa 2 Firmware Volume Block Protocol Runtime Interface Abstraction\r
3 And FVB Extension protocol Runtime Interface Abstraction\r
4\r
5 mFvbEntry is an array of Handle Fvb pairs. The Fvb Lib Instance matches the\r
6 index in the mFvbEntry array. This should be the same sequence as the FVB's\r
7 were described in the HOB. We have to remember the handle so we can tell if\r
48557c65 8 the protocol has been reinstalled and it needs updating.\r
677472aa 9\r
677472aa 10\r
11Copyright (c) 2006 - 2008, Intel Corporation\r
12All rights reserved. This program and the accompanying materials\r
13are licensed and made available under the terms and conditions of the BSD License\r
14which accompanies this distribution. The full text of the license may be found at\r
15http://opensource.org/licenses/bsd-license.php\r
16\r
17THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
18WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
19\r
20**/\r
21\r
22\r
23#include "Fvb.h"\r
24\r
bac86c0d 25\r
677472aa 26//\r
27// Event for Set Virtual Map Changed Event\r
28//\r
30ae98da 29EFI_EVENT mSetVirtualMapChangedEvent = NULL;\r
677472aa 30\r
31//\r
32// Lib will ASSERT if more FVB devices than this are added to the system.\r
33//\r
bac86c0d 34FVB_ENTRY *mFvbEntry = NULL;\r
35EFI_EVENT mFvbRegistration = NULL;\r
36UINTN mFvbCount = 0;\r
677472aa 37\r
38/**\r
39 Check whether an address is runtime memory or not.\r
40\r
41 @param Address The Address being checked.\r
42\r
43 @retval TRUE The address is runtime memory.\r
44 @retval FALSE The address is not runtime memory.\r
45**/\r
46BOOLEAN\r
47IsRuntimeMemory (\r
48 IN VOID *Address\r
49 )\r
50{\r
51 EFI_STATUS Status;\r
52 UINT8 TmpMemoryMap[1];\r
53 UINTN MapKey;\r
54 UINTN DescriptorSize;\r
55 UINT32 DescriptorVersion;\r
56 UINTN MemoryMapSize;\r
57 EFI_MEMORY_DESCRIPTOR *MemoryMap;\r
58 EFI_MEMORY_DESCRIPTOR *MemoryMapPtr;\r
59 BOOLEAN IsRuntime;\r
60 UINTN Index;\r
61\r
62 IsRuntime = FALSE;\r
63\r
64 //\r
65 // Get System MemoryMapSize\r
66 //\r
67 MemoryMapSize = 1;\r
68 Status = gBS->GetMemoryMap (\r
69 &MemoryMapSize,\r
70 (EFI_MEMORY_DESCRIPTOR *)TmpMemoryMap,\r
71 &MapKey,\r
72 &DescriptorSize,\r
73 &DescriptorVersion\r
74 );\r
75 ASSERT (Status == EFI_BUFFER_TOO_SMALL);\r
76 //\r
77 // Enlarge space here, because we will allocate pool now.\r
78 //\r
79 MemoryMapSize += EFI_PAGE_SIZE;\r
bac86c0d 80 MemoryMap = AllocatePool (MemoryMapSize);\r
81 ASSERT (MemoryMap != NULL);\r
677472aa 82\r
83 //\r
84 // Get System MemoryMap\r
85 //\r
86 Status = gBS->GetMemoryMap (\r
87 &MemoryMapSize,\r
88 MemoryMap,\r
89 &MapKey,\r
90 &DescriptorSize,\r
91 &DescriptorVersion\r
92 );\r
93 ASSERT_EFI_ERROR (Status);\r
94\r
95 MemoryMapPtr = MemoryMap;\r
96 //\r
97 // Search the request Address\r
98 //\r
99 for (Index = 0; Index < (MemoryMapSize / DescriptorSize); Index++) {\r
100 if (((EFI_PHYSICAL_ADDRESS)(UINTN)Address >= MemoryMap->PhysicalStart) &&\r
101 ((EFI_PHYSICAL_ADDRESS)(UINTN)Address < MemoryMap->PhysicalStart\r
102 + LShiftU64 (MemoryMap->NumberOfPages, EFI_PAGE_SHIFT))) {\r
103 //\r
104 // Found it\r
105 //\r
bac86c0d 106 if ((MemoryMap->Attribute & EFI_MEMORY_RUNTIME) != 0) {\r
677472aa 107 IsRuntime = TRUE;\r
108 }\r
109 break;\r
110 }\r
111 //\r
112 // Get next item\r
113 //\r
bac86c0d 114 MemoryMap = (EFI_MEMORY_DESCRIPTOR *)((UINTN) MemoryMap + DescriptorSize);\r
677472aa 115 }\r
116\r
117 //\r
118 // Done\r
119 //\r
bac86c0d 120 FreePool (MemoryMapPtr);\r
677472aa 121\r
122 return IsRuntime;\r
123}\r
124\r
bac86c0d 125\r
677472aa 126/**\r
127 Update mFvbEntry. Add new entry, or update existing entry if Fvb protocol is\r
128 reinstalled.\r
129\r
130 @param Event The Event that is being processed\r
131 @param Context Event Context\r
132\r
133**/\r
677472aa 134VOID\r
135EFIAPI\r
136FvbNotificationEvent (\r
137 IN EFI_EVENT Event,\r
138 IN VOID *Context\r
139 )\r
140{\r
141 EFI_STATUS Status;\r
142 UINTN BufferSize;\r
143 EFI_HANDLE Handle;\r
144 UINTN Index;\r
145 UINTN UpdateIndex;\r
146\r
147 while (TRUE) {\r
148 BufferSize = sizeof (Handle);\r
149 Status = gBS->LocateHandle (\r
150 ByRegisterNotify,\r
151 &gEfiFirmwareVolumeBlockProtocolGuid,\r
152 mFvbRegistration,\r
153 &BufferSize,\r
154 &Handle\r
155 );\r
156 if (EFI_ERROR (Status)) {\r
157 //\r
158 // Exit Path of While Loop....\r
159 //\r
160 break;\r
161 }\r
162\r
163 UpdateIndex = MAX_FVB_COUNT;\r
164 for (Index = 0; Index < mFvbCount; Index++) {\r
165 if (mFvbEntry[Index].Handle == Handle) {\r
166 //\r
167 // If the handle is already in the table just update the protocol\r
168 //\r
169 UpdateIndex = Index;\r
170 break;\r
171 }\r
172 }\r
173\r
174 if (UpdateIndex == MAX_FVB_COUNT) {\r
175 //\r
176 // Use the next free slot for a new entry\r
177 //\r
178 UpdateIndex = mFvbCount++;\r
179 //\r
180 // Check the UpdateIndex whether exceed the maximum value.\r
181 //\r
182 ASSERT (UpdateIndex < MAX_FVB_COUNT);\r
183 mFvbEntry[UpdateIndex].Handle = Handle;\r
184 }\r
185 //\r
186 // The array does not have enough entries\r
187 //\r
188 ASSERT (UpdateIndex < MAX_FVB_COUNT);\r
189\r
190 //\r
191 // Get the interface pointer and if it's ours, skip it\r
192 //\r
193 Status = gBS->HandleProtocol (\r
194 Handle,\r
195 &gEfiFirmwareVolumeBlockProtocolGuid,\r
196 (VOID **) &mFvbEntry[UpdateIndex].Fvb\r
197 );\r
198 ASSERT_EFI_ERROR (Status);\r
199\r
200 Status = gBS->HandleProtocol (\r
201 Handle,\r
202 &gEfiFvbExtensionProtocolGuid,\r
203 (VOID **) &mFvbEntry[UpdateIndex].FvbExtension\r
204 );\r
205 if (Status != EFI_SUCCESS) {\r
206 mFvbEntry[UpdateIndex].FvbExtension = NULL;\r
207 }\r
208\r
209 //\r
bac86c0d 210 // Check the FVB can be accessed in RUNTIME, The FVBs in FVB handle list come from two ways:\r
211 // 1) Dxe Core. (FVB information is transferred from FV HOB). 2) FVB driver. The FVB produced\r
212 // Dxe core is used to discovery DXE driver and dispatch. These FVBs can only be accessed in\r
213 // boot time. FVB driver will discovery all FV in FLASH and these FVBs can be accessed in\r
214 // runtime. The FVB itself produced by FVB driver is allocated in runtime memory. So we can\r
677472aa 215 // determine the what FVB can be accessed in RUNTIME by judging whether FVB itself is allocated\r
216 // in RUNTIME memory.\r
217 //\r
218 mFvbEntry[UpdateIndex].IsRuntimeAccess = IsRuntimeMemory (mFvbEntry[UpdateIndex].Fvb);\r
219 }\r
220}\r
221\r
222/**\r
223 Convert all pointers in mFvbEntry after ExitBootServices.\r
224\r
225 @param Event The Event that is being processed\r
226 @param Context Event Context\r
227\r
228**/\r
229VOID\r
230EFIAPI\r
231FvbVirtualAddressChangeNotifyEvent (\r
232 IN EFI_EVENT Event,\r
233 IN VOID *Context\r
234 )\r
235{\r
236 UINTN Index;\r
bac86c0d 237\r
677472aa 238 if (mFvbEntry != NULL) {\r
239 for (Index = 0; Index < MAX_FVB_COUNT; Index++) {\r
240 if (!mFvbEntry[Index].IsRuntimeAccess) {\r
241 continue;\r
242 }\r
243\r
bac86c0d 244 if (mFvbEntry[Index].Fvb != NULL) {\r
677472aa 245 EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->GetBlockSize);\r
246 EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->GetPhysicalAddress);\r
247 EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->GetAttributes);\r
248 EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->SetAttributes);\r
249 EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->Read);\r
250 EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->Write);\r
251 EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->EraseBlocks);\r
252 EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb);\r
253 }\r
254\r
bac86c0d 255 if (mFvbEntry[Index].FvbExtension != NULL) {\r
677472aa 256 EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].FvbExtension->EraseFvbCustomBlock);\r
257 EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].FvbExtension);\r
258 }\r
259 }\r
260\r
261 EfiConvertPointer (0x0, (VOID **) &mFvbEntry);\r
262 }\r
263}\r
264\r
bac86c0d 265\r
677472aa 266/**\r
267 Library constructor function entry.\r
268\r
48557c65 269 @param ImageHandle The handle of image who call this library.\r
677472aa 270 @param SystemTable The point of System Table.\r
271\r
48557c65 272 @retval EFI_SUCESS Success construct this library.\r
273 @retval Others Fail to construct this library.\r
677472aa 274**/\r
275EFI_STATUS\r
276EFIAPI\r
277FvbLibInitialize (\r
278 IN EFI_HANDLE ImageHandle,\r
279 IN EFI_SYSTEM_TABLE *SystemTable\r
280 )\r
281{\r
bac86c0d 282 EFI_STATUS Status;\r
283 \r
284 mFvbEntry = AllocateRuntimeZeroPool (sizeof (FVB_ENTRY) * MAX_FVB_COUNT);\r
285 ASSERT (mFvbEntry != NULL);\r
677472aa 286\r
bac86c0d 287 //\r
288 // Register FvbNotificationEvent () notify function.\r
289 // \r
677472aa 290 EfiCreateProtocolNotifyEvent (\r
291 &gEfiFirmwareVolumeBlockProtocolGuid,\r
292 TPL_CALLBACK,\r
293 FvbNotificationEvent,\r
294 NULL,\r
295 &mFvbRegistration\r
296 );\r
297\r
298 //\r
299 // Register SetVirtualAddressMap () notify function\r
300 //\r
301 Status = gBS->CreateEvent (\r
302 EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,\r
303 TPL_NOTIFY,\r
304 FvbVirtualAddressChangeNotifyEvent,\r
305 NULL,\r
306 &mSetVirtualMapChangedEvent\r
307 );\r
308 ASSERT_EFI_ERROR (Status);\r
309\r
bac86c0d 310 return Status;\r
677472aa 311}\r
312\r
313//\r
314// =============================================================================\r
315// The following functions wrap Fvb protocol in the Runtime Lib functions.\r
316// The Instance translates into Fvb instance. The Fvb order defined by HOBs and\r
317// thus the sequence of FVB protocol addition define Instance.\r
318//\r
677472aa 319\r
320/**\r
321 Reads specified number of bytes into a buffer from the specified block.\r
322\r
323 The EfiFvbReadBlock() function reads the requested number of bytes from\r
324 the requested block in the specified firmware volume and stores them in\r
325 the provided buffer. Implementations should be mindful that the firmware\r
326 volume might be in the ReadDisabled state. If it is in this state, the \r
327 EfiFvbReadBlock() function must return the status code EFI_ACCESS_DENIED\r
328 without modifying the contents of the buffer.\r
329 \r
330 The EfiFvbReadBlock() function must also prevent spanning block boundaries.\r
331 If a read is requested that would span a block boundary, the read must read\r
332 up to the boundary but not beyond. The output parameter NumBytes must be\r
333 set to correctly indicate the number of bytes actually read. \r
334 The caller must be aware that a read may be partially completed.\r
335\r
336 If NumBytes is NULL, then ASSERT().\r
337\r
338 If Buffer is NULL, then ASSERT().\r
339\r
340 @param[in] Instance The FV instance to be read from.\r
341 @param[in] Lba The logical block address to be read from\r
342 @param[in] Offset The offset relative to the block, at which to begin reading.\r
343 @param[in, out] NumBytes Pointer to a UINTN. On input, *NumBytes contains the total\r
344 size of the buffer. On output, it contains the actual number\r
345 of bytes read.\r
346 @param[out] Buffer Pointer to a caller allocated buffer that will be\r
347 used to hold the data read.\r
348\r
bac86c0d 349 @retval EFI_SUCCESS The firmware volume was read successfully and contents are in Buffer.\r
350 @retval EFI_BAD_BUFFER_SIZE Read attempted across an LBA boundary. On output, NumBytes contains\r
351 the total number of bytes returned in Buffer.\r
677472aa 352 @retval EFI_ACCESS_DENIED The firmware volume is in the ReadDisabled state.\r
353 @retval EFI_DEVICE_ERROR The block device is not functioning correctly and could not be read.\r
bac86c0d 354 @retval EFI_INVALID_PARAMETER Invalid parameter, Instance is larger than the max FVB number. Lba index\r
355 is larger than the last block of the firmware volume. Offset is larger\r
356 than the block size.\r
677472aa 357\r
358**/\r
359EFI_STATUS\r
bac86c0d 360EFIAPI\r
677472aa 361EfiFvbReadBlock (\r
362 IN UINTN Instance,\r
363 IN EFI_LBA Lba,\r
364 IN UINTN Offset,\r
365 IN OUT UINTN *NumBytes,\r
366 OUT UINT8 *Buffer\r
367 )\r
368{\r
369 ASSERT (NumBytes != NULL);\r
370 ASSERT (Buffer != NULL);\r
371 \r
372 if (Instance >= mFvbCount) {\r
373 return EFI_INVALID_PARAMETER;\r
374 }\r
375\r
376 if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) {\r
377 return EFI_INVALID_PARAMETER;\r
378 }\r
379\r
380 return mFvbEntry[Instance].Fvb->Read (mFvbEntry[Instance].Fvb, Lba, Offset, NumBytes, Buffer);\r
381}\r
382\r
383/**\r
384 Writes specified number of bytes from the input buffer to the block\r
385\r
386 The EfiFvbWriteBlock() function writes the specified number of bytes\r
387 from the provided buffer to the specified block and offset in the \r
388 requested firmware volume. \r
389\r
390 If the firmware volume is sticky write, the caller must ensure that\r
391 all the bits of the specified range to write are in the EFI_FVB_ERASE_POLARITY\r
392 state before calling the EfiFvbWriteBlock() function, or else the \r
393 result will be unpredictable. This unpredictability arises because,\r
394 for a sticky-write firmware volume, a write may negate a bit in the \r
395 EFI_FVB_ERASE_POLARITY state but it cannot flip it back again. In \r
396 general, before calling the EfiFvbWriteBlock() function, the caller\r
397 should call the EfiFvbEraseBlock() function first to erase the specified\r
398 block to write. A block erase cycle will transition bits from the\r
399 (NOT)EFI_FVB_ERASE_POLARITY state back to the EFI_FVB_ERASE_POLARITY state.\r
400 Implementations should be mindful that the firmware volume might be \r
401 in the WriteDisabled state. If it is in this state, the EfiFvbWriteBlock()\r
402 function must return the status code EFI_ACCESS_DENIED without modifying\r
403 the contents of the firmware volume.\r
404 \r
405 The EfiFvbWriteBlock() function must also prevent spanning block boundaries.\r
406 If a write is requested that spans a block boundary, the write must store\r
407 up to the boundary but not beyond. The output parameter NumBytes must be \r
408 set to correctly indicate the number of bytes actually written. The caller\r
409 must be aware that a write may be partially completed.\r
410 All writes, partial or otherwise, must be fully flushed to the hardware \r
411 before the EfiFvbWriteBlock() function returns. \r
412 \r
413 If NumBytes is NULL, then ASSERT().\r
414\r
48557c65 415 @param Instance The FV instance to be written to.\r
416 @param Lba The starting logical block index to write.\r
417 @param Offset The offset relative to the block to write.\r
677472aa 418 @param NumBytes Pointer to a UINTN. On input, *NumBytes contains\r
419 the total size of the buffer. On output, it contains\r
420 the actual number of bytes written.\r
421 @param Buffer Pointer to a caller allocated buffer that contains\r
422 the source for the write\r
423\r
424 @retval EFI_SUCCESS The firmware volume was written successfully.\r
425 @retval EFI_BAD_BUFFER_SIZE The write was attempted across an LBA boundary. \r
426 On output, NumBytes contains the total number of bytes actually written.\r
bac86c0d 427 @retval EFI_ACCESS_DENIED The firmware volume is in the WriteDisabled state.\r
677472aa 428 @retval EFI_DEVICE_ERROR The block device is malfunctioning and could not be written.\r
429 @retval EFI_INVALID_PARAMETER Invalid parameter, Instance is larger than the max FVB number. \r
430 Lba index is larger than the last block of the firmware volume.\r
431 Offset is larger than the block size.\r
432**/\r
433EFI_STATUS\r
bac86c0d 434EFIAPI\r
677472aa 435EfiFvbWriteBlock (\r
436 IN UINTN Instance,\r
437 IN EFI_LBA Lba,\r
438 IN UINTN Offset,\r
439 IN OUT UINTN *NumBytes,\r
440 IN UINT8 *Buffer\r
441 )\r
442{\r
443 ASSERT (NumBytes != NULL);\r
444 \r
445 if (Instance >= mFvbCount) {\r
446 return EFI_INVALID_PARAMETER;\r
447 }\r
448\r
449 if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) {\r
450 return EFI_INVALID_PARAMETER;\r
451 }\r
452\r
453 return mFvbEntry[Instance].Fvb->Write (mFvbEntry[Instance].Fvb, Lba, Offset, NumBytes, Buffer);\r
454}\r
455\r
bac86c0d 456\r
677472aa 457/**\r
458 Erases and initializes a firmware volume block.\r
459\r
460 The EfiFvbEraseBlock() function erases one block specified by Lba.\r
461 Implementations should be mindful that the firmware volume might \r
462 be in the WriteDisabled state. If it is in this state, the EfiFvbEraseBlock()\r
463 function must return the status code EFI_ACCESS_DENIED without \r
464 modifying the contents of the firmware volume. If Instance is \r
465 larger than the max FVB number, or Lba index is larger than the\r
466 last block of the firmware volume, this function return the status\r
467 code EFI_INVALID_PARAMETER.\r
468 \r
469 All calls to EfiFvbEraseBlock() must be fully flushed to the \r
470 hardware before this function returns. \r
471\r
472 @param[in] Instance The FV instance to be erased.\r
473 @param[in] Lba The logical block index to be erased from.\r
474 \r
475 @retval EFI_SUCCESS The erase request was successfully completed.\r
476 @retval EFI_ACCESS_DENIED The firmware volume is in the WriteDisabled state.\r
477 @retval EFI_DEVICE_ERROR The block device is not functioning correctly and\r
478 could not be written. The firmware device may \r
479 have been partially erased.\r
480 @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max\r
481 FVB number. Lba index is larger than the last block\r
482 of the firmware volume. \r
483\r
484**/\r
485EFI_STATUS\r
bac86c0d 486EFIAPI\r
677472aa 487EfiFvbEraseBlock (\r
488 IN UINTN Instance,\r
489 IN EFI_LBA Lba\r
490 )\r
491{\r
492 if (Instance >= mFvbCount) {\r
493 return EFI_INVALID_PARAMETER;\r
494 }\r
495\r
496 if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) {\r
497 return EFI_INVALID_PARAMETER;\r
498 }\r
499\r
500 return mFvbEntry[Instance].Fvb->EraseBlocks (mFvbEntry[Instance].Fvb, Lba, 1, EFI_LBA_LIST_TERMINATOR);\r
501}\r
502\r
bac86c0d 503\r
677472aa 504/**\r
505 Retrieves the attributes and current settings of the specified block, \r
506 returns resulting attributes in output parameter.\r
507\r
508 The EfiFvbGetAttributes() function retrieves the attributes and current\r
509 settings of the block specified by Instance. If Instance is larger than\r
510 the max FVB number, this function returns the status code EFI_INVALID_PARAMETER.\r
511\r
512 If Attributes is NULL, then ASSERT().\r
513\r
514 @param[in] Instance The FV instance to be operated.\r
515 @param[out] Attributes Pointer to EFI_FVB_ATTRIBUTES_2 in which the\r
516 attributes and current settings are returned.\r
517\r
518 @retval EFI_EFI_SUCCESS The firmware volume attributes were returned.\r
519 @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max FVB number. \r
520**/\r
521EFI_STATUS\r
bac86c0d 522EFIAPI\r
677472aa 523EfiFvbGetVolumeAttributes (\r
524 IN UINTN Instance,\r
525 OUT EFI_FVB_ATTRIBUTES_2 *Attributes\r
526 )\r
527{\r
528 ASSERT (Attributes != NULL);\r
529 \r
530 if (Instance >= mFvbCount) {\r
531 return EFI_INVALID_PARAMETER;\r
532 }\r
533\r
534 if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) {\r
535 return EFI_INVALID_PARAMETER;\r
536 }\r
537\r
538 return mFvbEntry[Instance].Fvb->GetAttributes (mFvbEntry[Instance].Fvb, Attributes);\r
539}\r
540\r
bac86c0d 541\r
677472aa 542/**\r
543 Modify the attributes and current settings of the specified block\r
544 according to the input parameter.\r
545\r
546 The EfiFvbSetAttributes() function sets configurable firmware volume\r
547 attributes and returns the new settings of the firmware volume specified\r
548 by Instance. If Instance is larger than the max FVB number, this function\r
549 returns the status code EFI_INVALID_PARAMETER.\r
550\r
551 If Attributes is NULL, then ASSERT().\r
552\r
553 @param[in] Instance The FV instance to be operated.\r
554 @param[in, out]Attributes On input, Attributes is a pointer to EFI_FVB_ATTRIBUTES_2\r
555 that contains the desired firmware volume settings. \r
556 On successful return, it contains the new settings of the firmware volume.\r
557\r
558 @retval EFI_EFI_SUCCESS The firmware volume attributes were modified successfully.\r
559 @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max FVB number.\r
560\r
561**/\r
562EFI_STATUS\r
bac86c0d 563EFIAPI\r
677472aa 564EfiFvbSetVolumeAttributes (\r
565 IN UINTN Instance,\r
566 IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes\r
567 )\r
568{\r
569 ASSERT (Attributes != NULL);\r
570 \r
571 if (Instance >= mFvbCount) {\r
572 return EFI_INVALID_PARAMETER;\r
573 }\r
574\r
575 if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) {\r
576 return EFI_INVALID_PARAMETER;\r
577 }\r
578\r
579 return mFvbEntry[Instance].Fvb->SetAttributes (mFvbEntry[Instance].Fvb, Attributes);\r
580}\r
581\r
bac86c0d 582\r
677472aa 583/**\r
584 Retrieves the physical address of the specified memory mapped FV.\r
585\r
586 Retrieve the base address of a memory-mapped firmware volume specified by Instance.\r
587 If Instance is larger than the max FVB number, this function returns the status \r
588 code EFI_INVALID_PARAMETER.\r
589 \r
590 If BaseAddress is NULL, then ASSERT().\r
591\r
592 @param[in] Instance The FV instance to be operated.\r
593 @param[out] BaseAddress Pointer to a caller allocated EFI_PHYSICAL_ADDRESS \r
594 that on successful return, contains the base address\r
595 of the firmware volume. \r
596\r
597 @retval EFI_EFI_SUCCESS The firmware volume base address is returned.\r
598 @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max FVB number. \r
599\r
600**/\r
601EFI_STATUS\r
bac86c0d 602EFIAPI\r
677472aa 603EfiFvbGetPhysicalAddress (\r
604 IN UINTN Instance,\r
605 OUT EFI_PHYSICAL_ADDRESS *BaseAddress\r
606 )\r
607{\r
608 ASSERT (BaseAddress != NULL);\r
609 \r
610 if (Instance >= mFvbCount) {\r
611 return EFI_INVALID_PARAMETER;\r
612 }\r
613\r
614 if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) {\r
615 return EFI_INVALID_PARAMETER;\r
616 }\r
617\r
618 return mFvbEntry[Instance].Fvb->GetPhysicalAddress (mFvbEntry[Instance].Fvb, BaseAddress);\r
619}\r
620\r
bac86c0d 621\r
677472aa 622/**\r
623 Retrieve the block size of the specified fv.\r
624 \r
625 The EfiFvbGetBlockSize() function retrieves the size of the requested block. \r
626 It also returns the number of additional blocks with the identical size. \r
627 If Instance is larger than the max FVB number, or Lba index is larger than\r
628 the last block of the firmware volume, this function return the status code\r
629 EFI_INVALID_PARAMETER.\r
630\r
bac86c0d 631 If BlockSize is NULL, then ASSERT().\r
677472aa 632 \r
633 If NumOfBlocks is NULL, then ASSERT().\r
634\r
635 @param[in] Instance The FV instance to be operated.\r
636 @param[in] Lba Indicates which block to return the size for.\r
637 @param[out] BlockSize Pointer to a caller-allocated UINTN in which the\r
638 size of the block is returned.\r
639 @param[out] NumOfBlocks Pointer to a caller-allocated UINTN in which the \r
640 number of consecutive blocks, starting with Lba, \r
641 is returned. All blocks in this range have a size of BlockSize.\r
642\r
643 @retval EFI_EFI_SUCCESS The firmware volume base address is returned.\r
644 @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max FVB number.\r
645 Lba index is larger than the last block of the firmware volume.\r
646\r
647**/\r
648EFI_STATUS\r
bac86c0d 649EFIAPI\r
677472aa 650EfiFvbGetBlockSize (\r
651 IN UINTN Instance,\r
652 IN EFI_LBA Lba,\r
653 OUT UINTN *BlockSize,\r
654 OUT UINTN *NumOfBlocks\r
655 )\r
656{\r
657 ASSERT (BlockSize != NULL);\r
658 ASSERT (NumOfBlocks != NULL);\r
659 \r
660 if (Instance >= mFvbCount) {\r
661 return EFI_INVALID_PARAMETER;\r
662 }\r
663\r
664 if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) {\r
665 return EFI_INVALID_PARAMETER;\r
666 }\r
667\r
668 return mFvbEntry[Instance].Fvb->GetBlockSize (mFvbEntry[Instance].Fvb, Lba, BlockSize, NumOfBlocks);\r
669}\r
670\r
bac86c0d 671\r
677472aa 672/**\r
673 Erases and initializes a specified range of a firmware volume.\r
674\r
675 The EfiFvbEraseCustomBlockRange() function erases the specified range in the firmware\r
676 volume index by Instance. If Instance is larger than the max FVB number, StartLba or \r
677 LastLba index is larger than the last block of the firmware volume, StartLba > LastLba\r
678 or StartLba equal to LastLba but OffsetStartLba > OffsetLastLba, this function return \r
679 the status code EFI_INVALID_PARAMETER.\r
680\r
681 @param[in] Instance The FV instance to be operated.\r
682 @param[in] StartLba The starting logical block index to be erased.\r
683 @param[in] OffsetStartLba Offset into the starting block at which to \r
684 begin erasing. \r
685 @param[in] LastLba The last logical block index to be erased.\r
686 @param[in] OffsetLastLba Offset into the last block at which to end erasing. \r
687\r
688 @retval EFI_EFI_SUCCESS Successfully erase custom block range\r
689 @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max FVB number. \r
690 @retval EFI_UNSUPPORTED Firmware volume block device has no this capability.\r
691\r
692**/\r
693EFI_STATUS\r
bac86c0d 694EFIAPI\r
677472aa 695EfiFvbEraseCustomBlockRange (\r
696 IN UINTN Instance,\r
697 IN EFI_LBA StartLba,\r
698 IN UINTN OffsetStartLba,\r
699 IN EFI_LBA LastLba,\r
700 IN UINTN OffsetLastLba\r
701 )\r
702{\r
703 if (Instance >= mFvbCount) {\r
704 return EFI_INVALID_PARAMETER;\r
705 }\r
706\r
707 if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) {\r
708 return EFI_INVALID_PARAMETER;\r
709 }\r
710\r
711 if (!(mFvbEntry[Instance].FvbExtension)) {\r
712 return EFI_UNSUPPORTED;\r
713 }\r
714\r
715 if (!(mFvbEntry[Instance].FvbExtension->EraseFvbCustomBlock)) {\r
716 return EFI_UNSUPPORTED;\r
717 }\r
718\r
719 return mFvbEntry[Instance].FvbExtension->EraseFvbCustomBlock (\r
720 mFvbEntry[Instance].FvbExtension,\r
721 StartLba,\r
722 OffsetStartLba,\r
723 LastLba,\r
724 OffsetLastLba\r
725 );\r
726}\r