]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/EdkFvbServiceLib/Fvb.c
Patch to remove STATIC modifier. This is on longer recommended by EFI Framework codin...
[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 EFI_EVENT mSetVirtualMapChangedEvent = NULL;
31
32 //
33 // Lib will ASSERT if more FVB devices than this are added to the system.
34 //
35 FVB_ENTRY *mFvbEntry;
36 EFI_EVENT mFvbRegistration;
37 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 VOID
139 EFIAPI
140 FvbNotificationEvent (
141 IN EFI_EVENT Event,
142 IN VOID *Context
143 )
144 {
145 EFI_STATUS Status;
146 UINTN BufferSize;
147 EFI_HANDLE Handle;
148 UINTN Index;
149 UINTN UpdateIndex;
150
151 while (TRUE) {
152 BufferSize = sizeof (Handle);
153 Status = gBS->LocateHandle (
154 ByRegisterNotify,
155 &gEfiFirmwareVolumeBlockProtocolGuid,
156 mFvbRegistration,
157 &BufferSize,
158 &Handle
159 );
160 if (EFI_ERROR (Status)) {
161 //
162 // Exit Path of While Loop....
163 //
164 break;
165 }
166
167 UpdateIndex = MAX_FVB_COUNT;
168 for (Index = 0; Index < mFvbCount; Index++) {
169 if (mFvbEntry[Index].Handle == Handle) {
170 //
171 // If the handle is already in the table just update the protocol
172 //
173 UpdateIndex = Index;
174 break;
175 }
176 }
177
178 if (UpdateIndex == MAX_FVB_COUNT) {
179 //
180 // Use the next free slot for a new entry
181 //
182 UpdateIndex = mFvbCount++;
183 //
184 // Check the UpdateIndex whether exceed the maximum value.
185 //
186 ASSERT (UpdateIndex < MAX_FVB_COUNT);
187 mFvbEntry[UpdateIndex].Handle = Handle;
188 }
189 //
190 // The array does not have enough entries
191 //
192 ASSERT (UpdateIndex < MAX_FVB_COUNT);
193
194 //
195 // Get the interface pointer and if it's ours, skip it
196 //
197 Status = gBS->HandleProtocol (
198 Handle,
199 &gEfiFirmwareVolumeBlockProtocolGuid,
200 (VOID **) &mFvbEntry[UpdateIndex].Fvb
201 );
202 ASSERT_EFI_ERROR (Status);
203
204 Status = gBS->HandleProtocol (
205 Handle,
206 &gEfiFvbExtensionProtocolGuid,
207 (VOID **) &mFvbEntry[UpdateIndex].FvbExtension
208 );
209 if (Status != EFI_SUCCESS) {
210 mFvbEntry[UpdateIndex].FvbExtension = NULL;
211 }
212
213 //
214 // Check the FVB can be accessed in RUNTIME, The FVBs in FVB handle list comes
215 // from two way:
216 // 1) Dxe Core. (FVB information is transferred from FV HOB).
217 // 2) FVB driver.
218 // The FVB produced Dxe core is used for discoverying DXE driver and dispatch. These
219 // FVBs can only be accessed in boot time.
220 // FVB driver will discovery all FV in FLASH and these FVBs can be accessed in runtime.
221 // The FVB itself produced by FVB driver is allocated in runtime memory. So we can
222 // determine the what FVB can be accessed in RUNTIME by judging whether FVB itself is allocated
223 // in RUNTIME memory.
224 //
225 mFvbEntry[UpdateIndex].IsRuntimeAccess = IsRuntimeMemory (mFvbEntry[UpdateIndex].Fvb);
226 }
227 }
228
229 /**
230 Convert all pointers in mFvbEntry after ExitBootServices.
231
232 @param Event The Event that is being processed
233 @param Context Event Context
234
235 **/
236 VOID
237 EFIAPI
238 FvbVirtualAddressChangeNotifyEvent (
239 IN EFI_EVENT Event,
240 IN VOID *Context
241 )
242 {
243 UINTN Index;
244 if (mFvbEntry != NULL) {
245 for (Index = 0; Index < MAX_FVB_COUNT; Index++) {
246 if (!mFvbEntry[Index].IsRuntimeAccess) {
247 continue;
248 }
249
250 if (NULL != mFvbEntry[Index].Fvb) {
251 EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->GetBlockSize);
252 EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->GetPhysicalAddress);
253 EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->GetAttributes);
254 EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->SetAttributes);
255 EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->Read);
256 EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->Write);
257 EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->EraseBlocks);
258 EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb);
259 }
260
261 if (NULL != mFvbEntry[Index].FvbExtension) {
262 EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].FvbExtension->EraseFvbCustomBlock);
263 EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].FvbExtension);
264 }
265 }
266
267 EfiConvertPointer (0x0, (VOID **) &mFvbEntry);
268 }
269 }
270
271 /**
272 Library constructor function entry.
273
274 @param ImageHandle The handle of image who call this libary.
275 @param SystemTable The point of System Table.
276
277 @retval EFI_SUCESS Sucess construct this library.
278 @retval Others Fail to contruct this libary.
279 **/
280 EFI_STATUS
281 EFIAPI
282 FvbLibInitialize (
283 IN EFI_HANDLE ImageHandle,
284 IN EFI_SYSTEM_TABLE *SystemTable
285 )
286 {
287 UINTN Status;
288 mFvbCount = 0;
289
290 Status = gBS->AllocatePool (
291 EfiRuntimeServicesData,
292 (UINTN) sizeof (FVB_ENTRY) * MAX_FVB_COUNT,
293 (VOID *) &mFvbEntry
294 );
295
296 if (EFI_ERROR (Status)) {
297 return Status;
298 }
299
300 ZeroMem (mFvbEntry, sizeof (FVB_ENTRY) * MAX_FVB_COUNT);
301
302 EfiCreateProtocolNotifyEvent (
303 &gEfiFirmwareVolumeBlockProtocolGuid,
304 TPL_CALLBACK,
305 FvbNotificationEvent,
306 NULL,
307 &mFvbRegistration
308 );
309
310 //
311 // Register SetVirtualAddressMap () notify function
312 //
313 Status = gBS->CreateEvent (
314 EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,
315 TPL_NOTIFY,
316 FvbVirtualAddressChangeNotifyEvent,
317 NULL,
318 &mSetVirtualMapChangedEvent
319 );
320 ASSERT_EFI_ERROR (Status);
321
322 return EFI_SUCCESS;
323 }
324
325 //
326 // =============================================================================
327 // The following functions wrap Fvb protocol in the Runtime Lib functions.
328 // The Instance translates into Fvb instance. The Fvb order defined by HOBs and
329 // thus the sequence of FVB protocol addition define Instance.
330 //
331 // EfiFvbInitialize () must be called before any of the following functions
332 // must be called.
333 // =============================================================================
334 //
335
336 /**
337 Reads specified number of bytes into a buffer from the specified block.
338
339 The EfiFvbReadBlock() function reads the requested number of bytes from
340 the requested block in the specified firmware volume and stores them in
341 the provided buffer. Implementations should be mindful that the firmware
342 volume might be in the ReadDisabled state. If it is in this state, the
343 EfiFvbReadBlock() function must return the status code EFI_ACCESS_DENIED
344 without modifying the contents of the buffer.
345
346 The EfiFvbReadBlock() function must also prevent spanning block boundaries.
347 If a read is requested that would span a block boundary, the read must read
348 up to the boundary but not beyond. The output parameter NumBytes must be
349 set to correctly indicate the number of bytes actually read.
350 The caller must be aware that a read may be partially completed.
351
352 If NumBytes is NULL, then ASSERT().
353
354 If Buffer is NULL, then ASSERT().
355
356 @param[in] Instance The FV instance to be read from.
357 @param[in] Lba The logical block address to be read from
358 @param[in] Offset The offset relative to the block, at which to begin reading.
359 @param[in, out] NumBytes Pointer to a UINTN. On input, *NumBytes contains the total
360 size of the buffer. On output, it contains the actual number
361 of bytes read.
362 @param[out] Buffer Pointer to a caller allocated buffer that will be
363 used to hold the data read.
364
365 @retval EFI_SUCCESS The firmware volume was read successfully and contents are in Buffer.
366 @retval EFI_BAD_BUFFER_SIZE Read attempted across an LBA boundary. On output, NumBytes contains the total number of bytes returned in Buffer.
367 @retval EFI_ACCESS_DENIED The firmware volume is in the ReadDisabled state.
368 @retval EFI_DEVICE_ERROR The block device is not functioning correctly and could not be read.
369 @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.
370
371 **/
372 EFI_STATUS
373 EfiFvbReadBlock (
374 IN UINTN Instance,
375 IN EFI_LBA Lba,
376 IN UINTN Offset,
377 IN OUT UINTN *NumBytes,
378 OUT UINT8 *Buffer
379 )
380 {
381 ASSERT (NumBytes != NULL);
382 ASSERT (Buffer != NULL);
383
384 if (Instance >= mFvbCount) {
385 return EFI_INVALID_PARAMETER;
386 }
387
388 if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) {
389 return EFI_INVALID_PARAMETER;
390 }
391
392 return mFvbEntry[Instance].Fvb->Read (mFvbEntry[Instance].Fvb, Lba, Offset, NumBytes, Buffer);
393 }
394
395 /**
396 Writes specified number of bytes from the input buffer to the block
397
398 The EfiFvbWriteBlock() function writes the specified number of bytes
399 from the provided buffer to the specified block and offset in the
400 requested firmware volume.
401
402 If the firmware volume is sticky write, the caller must ensure that
403 all the bits of the specified range to write are in the EFI_FVB_ERASE_POLARITY
404 state before calling the EfiFvbWriteBlock() function, or else the
405 result will be unpredictable. This unpredictability arises because,
406 for a sticky-write firmware volume, a write may negate a bit in the
407 EFI_FVB_ERASE_POLARITY state but it cannot flip it back again. In
408 general, before calling the EfiFvbWriteBlock() function, the caller
409 should call the EfiFvbEraseBlock() function first to erase the specified
410 block to write. A block erase cycle will transition bits from the
411 (NOT)EFI_FVB_ERASE_POLARITY state back to the EFI_FVB_ERASE_POLARITY state.
412 Implementations should be mindful that the firmware volume might be
413 in the WriteDisabled state. If it is in this state, the EfiFvbWriteBlock()
414 function must return the status code EFI_ACCESS_DENIED without modifying
415 the contents of the firmware volume.
416
417 The EfiFvbWriteBlock() function must also prevent spanning block boundaries.
418 If a write is requested that spans a block boundary, the write must store
419 up to the boundary but not beyond. The output parameter NumBytes must be
420 set to correctly indicate the number of bytes actually written. The caller
421 must be aware that a write may be partially completed.
422 All writes, partial or otherwise, must be fully flushed to the hardware
423 before the EfiFvbWriteBlock() function returns.
424
425 If NumBytes is NULL, then ASSERT().
426
427 @param Instance The FV instance to be written to
428 @param Lba The starting logical block index to write to
429 @param Offset The offset relative to the block, at which to begin writting.
430 @param NumBytes Pointer to a UINTN. On input, *NumBytes contains
431 the total size of the buffer. On output, it contains
432 the actual number of bytes written.
433 @param Buffer Pointer to a caller allocated buffer that contains
434 the source for the write
435
436 @retval EFI_SUCCESS The firmware volume was written successfully.
437 @retval EFI_BAD_BUFFER_SIZE The write was attempted across an LBA boundary.
438 On output, NumBytes contains the total number of bytes actually written.
439 @retval EFI_ACCESS_DENIED The firmware volume is in the WriteDisabled state.
440 @retval EFI_DEVICE_ERROR The block device is malfunctioning and could not be written.
441 @retval EFI_INVALID_PARAMETER Invalid parameter, Instance is larger than the max FVB number.
442 Lba index is larger than the last block of the firmware volume.
443 Offset is larger than the block size.
444 **/
445 EFI_STATUS
446 EfiFvbWriteBlock (
447 IN UINTN Instance,
448 IN EFI_LBA Lba,
449 IN UINTN Offset,
450 IN OUT UINTN *NumBytes,
451 IN UINT8 *Buffer
452 )
453 {
454 ASSERT (NumBytes != NULL);
455
456 if (Instance >= mFvbCount) {
457 return EFI_INVALID_PARAMETER;
458 }
459
460 if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) {
461 return EFI_INVALID_PARAMETER;
462 }
463
464 return mFvbEntry[Instance].Fvb->Write (mFvbEntry[Instance].Fvb, Lba, Offset, NumBytes, Buffer);
465 }
466
467 /**
468 Erases and initializes a firmware volume block.
469
470 The EfiFvbEraseBlock() function erases one block specified by Lba.
471 Implementations should be mindful that the firmware volume might
472 be in the WriteDisabled state. If it is in this state, the EfiFvbEraseBlock()
473 function must return the status code EFI_ACCESS_DENIED without
474 modifying the contents of the firmware volume. If Instance is
475 larger than the max FVB number, or Lba index is larger than the
476 last block of the firmware volume, this function return the status
477 code EFI_INVALID_PARAMETER.
478
479 All calls to EfiFvbEraseBlock() must be fully flushed to the
480 hardware before this function returns.
481
482 @param[in] Instance The FV instance to be erased.
483 @param[in] Lba The logical block index to be erased from.
484
485 @retval EFI_SUCCESS The erase request was successfully completed.
486 @retval EFI_ACCESS_DENIED The firmware volume is in the WriteDisabled state.
487 @retval EFI_DEVICE_ERROR The block device is not functioning correctly and
488 could not be written. The firmware device may
489 have been partially erased.
490 @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max
491 FVB number. Lba index is larger than the last block
492 of the firmware volume.
493
494 **/
495 EFI_STATUS
496 EfiFvbEraseBlock (
497 IN UINTN Instance,
498 IN EFI_LBA Lba
499 )
500 {
501 if (Instance >= mFvbCount) {
502 return EFI_INVALID_PARAMETER;
503 }
504
505 if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) {
506 return EFI_INVALID_PARAMETER;
507 }
508
509 return mFvbEntry[Instance].Fvb->EraseBlocks (mFvbEntry[Instance].Fvb, Lba, 1, EFI_LBA_LIST_TERMINATOR);
510 }
511
512 /**
513 Retrieves the attributes and current settings of the specified block,
514 returns resulting attributes in output parameter.
515
516 The EfiFvbGetAttributes() function retrieves the attributes and current
517 settings of the block specified by Instance. If Instance is larger than
518 the max FVB number, this function returns the status code EFI_INVALID_PARAMETER.
519
520 If Attributes is NULL, then ASSERT().
521
522 @param[in] Instance The FV instance to be operated.
523 @param[out] Attributes Pointer to EFI_FVB_ATTRIBUTES_2 in which the
524 attributes and current settings are returned.
525
526 @retval EFI_EFI_SUCCESS The firmware volume attributes were returned.
527 @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max FVB number.
528 **/
529 EFI_STATUS
530 EfiFvbGetVolumeAttributes (
531 IN UINTN Instance,
532 OUT EFI_FVB_ATTRIBUTES_2 *Attributes
533 )
534 {
535 ASSERT (Attributes != NULL);
536
537 if (Instance >= mFvbCount) {
538 return EFI_INVALID_PARAMETER;
539 }
540
541 if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) {
542 return EFI_INVALID_PARAMETER;
543 }
544
545 return mFvbEntry[Instance].Fvb->GetAttributes (mFvbEntry[Instance].Fvb, Attributes);
546 }
547
548 /**
549 Modify the attributes and current settings of the specified block
550 according to the input parameter.
551
552 The EfiFvbSetAttributes() function sets configurable firmware volume
553 attributes and returns the new settings of the firmware volume specified
554 by Instance. If Instance is larger than the max FVB number, this function
555 returns the status code EFI_INVALID_PARAMETER.
556
557 If Attributes is NULL, then ASSERT().
558
559 @param[in] Instance The FV instance to be operated.
560 @param[in, out]Attributes On input, Attributes is a pointer to EFI_FVB_ATTRIBUTES_2
561 that contains the desired firmware volume settings.
562 On successful return, it contains the new settings of the firmware volume.
563
564 @retval EFI_EFI_SUCCESS The firmware volume attributes were modified successfully.
565 @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max FVB number.
566
567 **/
568 EFI_STATUS
569 EfiFvbSetVolumeAttributes (
570 IN UINTN Instance,
571 IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes
572 )
573 {
574 ASSERT (Attributes != NULL);
575
576 if (Instance >= mFvbCount) {
577 return EFI_INVALID_PARAMETER;
578 }
579
580 if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) {
581 return EFI_INVALID_PARAMETER;
582 }
583
584 return mFvbEntry[Instance].Fvb->SetAttributes (mFvbEntry[Instance].Fvb, Attributes);
585 }
586
587 /**
588 Retrieves the physical address of the specified memory mapped FV.
589
590 Retrieve the base address of a memory-mapped firmware volume specified by Instance.
591 If Instance is larger than the max FVB number, this function returns the status
592 code EFI_INVALID_PARAMETER.
593
594 If BaseAddress is NULL, then ASSERT().
595
596 @param[in] Instance The FV instance to be operated.
597 @param[out] BaseAddress Pointer to a caller allocated EFI_PHYSICAL_ADDRESS
598 that on successful return, contains the base address
599 of the firmware volume.
600
601 @retval EFI_EFI_SUCCESS The firmware volume base address is returned.
602 @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max FVB number.
603
604 **/
605 EFI_STATUS
606 EfiFvbGetPhysicalAddress (
607 IN UINTN Instance,
608 OUT EFI_PHYSICAL_ADDRESS *BaseAddress
609 )
610 {
611 ASSERT (BaseAddress != NULL);
612
613 if (Instance >= mFvbCount) {
614 return EFI_INVALID_PARAMETER;
615 }
616
617 if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) {
618 return EFI_INVALID_PARAMETER;
619 }
620
621 return mFvbEntry[Instance].Fvb->GetPhysicalAddress (mFvbEntry[Instance].Fvb, BaseAddress);
622 }
623
624 /**
625 Retrieve the block size of the specified fv.
626
627 The EfiFvbGetBlockSize() function retrieves the size of the requested block.
628 It also returns the number of additional blocks with the identical size.
629 If Instance is larger than the max FVB number, or Lba index is larger than
630 the last block of the firmware volume, this function return the status code
631 EFI_INVALID_PARAMETER.
632
633 If BlockSize is NULL, then ASSERT().
634
635 If NumOfBlocks is NULL, then ASSERT().
636
637 @param[in] Instance The FV instance to be operated.
638 @param[in] Lba Indicates which block to return the size for.
639 @param[out] BlockSize Pointer to a caller-allocated UINTN in which the
640 size of the block is returned.
641 @param[out] NumOfBlocks Pointer to a caller-allocated UINTN in which the
642 number of consecutive blocks, starting with Lba,
643 is returned. All blocks in this range have a size of BlockSize.
644
645 @retval EFI_EFI_SUCCESS The firmware volume base address is returned.
646 @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max FVB number.
647 Lba index is larger than the last block of the firmware volume.
648
649 **/
650 EFI_STATUS
651 EfiFvbGetBlockSize (
652 IN UINTN Instance,
653 IN EFI_LBA Lba,
654 OUT UINTN *BlockSize,
655 OUT UINTN *NumOfBlocks
656 )
657 {
658 ASSERT (BlockSize != NULL);
659 ASSERT (NumOfBlocks != NULL);
660
661 if (Instance >= mFvbCount) {
662 return EFI_INVALID_PARAMETER;
663 }
664
665 if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) {
666 return EFI_INVALID_PARAMETER;
667 }
668
669 return mFvbEntry[Instance].Fvb->GetBlockSize (mFvbEntry[Instance].Fvb, Lba, BlockSize, NumOfBlocks);
670 }
671
672 /**
673 Erases and initializes a specified range of a firmware volume.
674
675 The EfiFvbEraseCustomBlockRange() function erases the specified range in the firmware
676 volume index by Instance. If Instance is larger than the max FVB number, StartLba or
677 LastLba index is larger than the last block of the firmware volume, StartLba > LastLba
678 or StartLba equal to LastLba but OffsetStartLba > OffsetLastLba, this function return
679 the status code EFI_INVALID_PARAMETER.
680
681 @param[in] Instance The FV instance to be operated.
682 @param[in] StartLba The starting logical block index to be erased.
683 @param[in] OffsetStartLba Offset into the starting block at which to
684 begin erasing.
685 @param[in] LastLba The last logical block index to be erased.
686 @param[in] OffsetLastLba Offset into the last block at which to end erasing.
687
688 @retval EFI_EFI_SUCCESS Successfully erase custom block range
689 @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max FVB number.
690 @retval EFI_UNSUPPORTED Firmware volume block device has no this capability.
691
692 **/
693 EFI_STATUS
694 EfiFvbEraseCustomBlockRange (
695 IN UINTN Instance,
696 IN EFI_LBA StartLba,
697 IN UINTN OffsetStartLba,
698 IN EFI_LBA LastLba,
699 IN UINTN OffsetLastLba
700 )
701 {
702 if (Instance >= mFvbCount) {
703 return EFI_INVALID_PARAMETER;
704 }
705
706 if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) {
707 return EFI_INVALID_PARAMETER;
708 }
709
710 if (!(mFvbEntry[Instance].FvbExtension)) {
711 return EFI_UNSUPPORTED;
712 }
713
714 if (!(mFvbEntry[Instance].FvbExtension->EraseFvbCustomBlock)) {
715 return EFI_UNSUPPORTED;
716 }
717
718 return mFvbEntry[Instance].FvbExtension->EraseFvbCustomBlock (
719 mFvbEntry[Instance].FvbExtension,
720 StartLba,
721 OffsetStartLba,
722 LastLba,
723 OffsetLastLba
724 );
725 }