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