]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/ArmRealViewEbPkg/FvbDxe/FvbDxe.c
Add ArmPlatformPkg from ARM Ltd. patch.
[mirror_edk2.git] / ArmPlatformPkg / ArmRealViewEbPkg / FvbDxe / FvbDxe.c
1 /*++
2 RealView EB FVB DXE Driver
3
4 Copyright (c) 2010, Apple Inc. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13
14 --*/
15
16 #include <PiDxe.h>
17
18 #include <Library/BaseLib.h>
19 #include <Library/DebugLib.h>
20 #include <Library/BaseMemoryLib.h>
21 #include <Library/UefiBootServicesTableLib.h>
22 #include <Library/UefiLib.h>
23 #include <Library/PcdLib.h>
24
25 #include <Protocol/FirmwareVolumeBlock.h>
26
27
28
29 /**
30 The GetAttributes() function retrieves the attributes and
31 current settings of the block.
32
33 @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.
34
35 @param Attributes Pointer to EFI_FVB_ATTRIBUTES_2 in which the
36 attributes and current settings are
37 returned. Type EFI_FVB_ATTRIBUTES_2 is defined
38 in EFI_FIRMWARE_VOLUME_HEADER.
39
40 @retval EFI_SUCCESS The firmware volume attributes were
41 returned.
42
43 **/
44
45 EFI_STATUS
46 EFIAPI
47 FvbGetAttributes (
48 IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
49 OUT EFI_FVB_ATTRIBUTES_2 *Attributes
50 )
51 {
52 return EFI_UNSUPPORTED;
53 }
54
55
56 /**
57 The SetAttributes() function sets configurable firmware volume
58 attributes and returns the new settings of the firmware volume.
59
60
61 @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.
62
63 @param Attributes On input, Attributes is a pointer to
64 EFI_FVB_ATTRIBUTES_2 that contains the
65 desired firmware volume settings. On
66 successful return, it contains the new
67 settings of the firmware volume. Type
68 EFI_FVB_ATTRIBUTES_2 is defined in
69 EFI_FIRMWARE_VOLUME_HEADER.
70
71 @retval EFI_SUCCESS The firmware volume attributes were returned.
72
73 @retval EFI_INVALID_PARAMETER The attributes requested are in
74 conflict with the capabilities
75 as declared in the firmware
76 volume header.
77
78 **/
79 EFI_STATUS
80 EFIAPI
81 FvbSetAttributes (
82 IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
83 IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes
84 )
85 {
86 return EFI_UNSUPPORTED;
87 }
88
89
90 /**
91 The GetPhysicalAddress() function retrieves the base address of
92 a memory-mapped firmware volume. This function should be called
93 only for memory-mapped firmware volumes.
94
95 @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.
96
97 @param Address Pointer to a caller-allocated
98 EFI_PHYSICAL_ADDRESS that, on successful
99 return from GetPhysicalAddress(), contains the
100 base address of the firmware volume.
101
102 @retval EFI_SUCCESS The firmware volume base address was returned.
103
104 @retval EFI_NOT_SUPPORTED The firmware volume is not memory mapped.
105
106 **/
107 EFI_STATUS
108 EFIAPI
109 FvbGetPhysicalAddress (
110 IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
111 OUT EFI_PHYSICAL_ADDRESS *Address
112 )
113 {
114 return EFI_UNSUPPORTED;
115 }
116
117
118 /**
119 The GetBlockSize() function retrieves the size of the requested
120 block. It also returns the number of additional blocks with
121 the identical size. The GetBlockSize() function is used to
122 retrieve the block map (see EFI_FIRMWARE_VOLUME_HEADER).
123
124
125 @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.
126
127 @param Lba Indicates the block for which to return the size.
128
129 @param BlockSize Pointer to a caller-allocated UINTN in which
130 the size of the block is returned.
131
132 @param NumberOfBlocks Pointer to a caller-allocated UINTN in
133 which the number of consecutive blocks,
134 starting with Lba, is returned. All
135 blocks in this range have a size of
136 BlockSize.
137
138
139 @retval EFI_SUCCESS The firmware volume base address was returned.
140
141 @retval EFI_INVALID_PARAMETER The requested LBA is out of range.
142
143 **/
144 EFI_STATUS
145 EFIAPI
146 FvbGetBlockSize (
147 IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
148 IN EFI_LBA Lba,
149 OUT UINTN *BlockSize,
150 OUT UINTN *NumberOfBlocks
151 )
152 {
153 return EFI_UNSUPPORTED;
154 }
155
156
157
158 /**
159 Reads the specified number of bytes into a buffer from the specified block.
160
161 The Read() function reads the requested number of bytes from the
162 requested block and stores them in the provided buffer.
163 Implementations should be mindful that the firmware volume
164 might be in the ReadDisabled state. If it is in this state,
165 the Read() function must return the status code
166 EFI_ACCESS_DENIED without modifying the contents of the
167 buffer. The Read() function must also prevent spanning block
168 boundaries. If a read is requested that would span a block
169 boundary, the read must read up to the boundary but not
170 beyond. The output parameter NumBytes must be set to correctly
171 indicate the number of bytes actually read. The caller must be
172 aware that a read may be partially completed.
173
174 @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.
175
176 @param Lba The starting logical block index
177 from which to read.
178
179 @param Offset Offset into the block at which to begin reading.
180
181 @param NumBytes Pointer to a UINTN. At entry, *NumBytes
182 contains the total size of the buffer. At
183 exit, *NumBytes contains the total number of
184 bytes read.
185
186 @param Buffer Pointer to a caller-allocated buffer that will
187 be used to hold the data that is read.
188
189 @retval EFI_SUCCESS The firmware volume was read successfully,
190 and contents are in Buffer.
191
192 @retval EFI_BAD_BUFFER_SIZE Read attempted across an LBA
193 boundary. On output, NumBytes
194 contains the total number of bytes
195 returned in Buffer.
196
197 @retval EFI_ACCESS_DENIED The firmware volume is in the
198 ReadDisabled state.
199
200 @retval EFI_DEVICE_ERROR The block device is not
201 functioning correctly and could
202 not be read.
203
204 **/
205 EFI_STATUS
206 EFIAPI
207 FvbRead (
208 IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
209 IN EFI_LBA Lba,
210 IN UINTN Offset,
211 IN OUT UINTN *NumBytes,
212 IN OUT UINT8 *Buffer
213 )
214 {
215 return EFI_UNSUPPORTED;
216 }
217
218
219 /**
220 Writes the specified number of bytes from the input buffer to the block.
221
222 The Write() function writes the specified number of bytes from
223 the provided buffer to the specified block and offset. If the
224 firmware volume is sticky write, the caller must ensure that
225 all the bits of the specified range to write are in the
226 EFI_FVB_ERASE_POLARITY state before calling the Write()
227 function, or else the result will be unpredictable. This
228 unpredictability arises because, for a sticky-write firmware
229 volume, a write may negate a bit in the EFI_FVB_ERASE_POLARITY
230 state but cannot flip it back again. Before calling the
231 Write() function, it is recommended for the caller to first call
232 the EraseBlocks() function to erase the specified block to
233 write. A block erase cycle will transition bits from the
234 (NOT)EFI_FVB_ERASE_POLARITY state back to the
235 EFI_FVB_ERASE_POLARITY state. Implementations should be
236 mindful that the firmware volume might be in the WriteDisabled
237 state. If it is in this state, the Write() function must
238 return the status code EFI_ACCESS_DENIED without modifying the
239 contents of the firmware volume. The Write() function must
240 also prevent spanning block boundaries. If a write is
241 requested that spans a block boundary, the write must store up
242 to the boundary but not beyond. The output parameter NumBytes
243 must be set to correctly indicate the number of bytes actually
244 written. The caller must be aware that a write may be
245 partially completed. All writes, partial or otherwise, must be
246 fully flushed to the hardware before the Write() service
247 returns.
248
249 @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.
250
251 @param Lba The starting logical block index to write to.
252
253 @param Offset Offset into the block at which to begin writing.
254
255 @param NumBytes The pointer to a UINTN. At entry, *NumBytes
256 contains the total size of the buffer. At
257 exit, *NumBytes contains the total number of
258 bytes actually written.
259
260 @param Buffer The pointer to a caller-allocated buffer that
261 contains the source for the write.
262
263 @retval EFI_SUCCESS The firmware volume was written successfully.
264
265 @retval EFI_BAD_BUFFER_SIZE The write was attempted across an
266 LBA boundary. On output, NumBytes
267 contains the total number of bytes
268 actually written.
269
270 @retval EFI_ACCESS_DENIED The firmware volume is in the
271 WriteDisabled state.
272
273 @retval EFI_DEVICE_ERROR The block device is malfunctioning
274 and could not be written.
275
276
277 **/
278 EFI_STATUS
279 EFIAPI
280 FvbWrite (
281 IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
282 IN EFI_LBA Lba,
283 IN UINTN Offset,
284 IN OUT UINTN *NumBytes,
285 IN UINT8 *Buffer
286 )
287 {
288 return EFI_UNSUPPORTED;
289 }
290
291
292 /**
293 Erases and initializes a firmware volume block.
294
295 The EraseBlocks() function erases one or more blocks as denoted
296 by the variable argument list. The entire parameter list of
297 blocks must be verified before erasing any blocks. If a block is
298 requested that does not exist within the associated firmware
299 volume (it has a larger index than the last block of the
300 firmware volume), the EraseBlocks() function must return the
301 status code EFI_INVALID_PARAMETER without modifying the contents
302 of the firmware volume. Implementations should be mindful that
303 the firmware volume might be in the WriteDisabled state. If it
304 is in this state, the EraseBlocks() function must return the
305 status code EFI_ACCESS_DENIED without modifying the contents of
306 the firmware volume. All calls to EraseBlocks() must be fully
307 flushed to the hardware before the EraseBlocks() service
308 returns.
309
310 @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL
311 instance.
312
313 @param ... The variable argument list is a list of tuples.
314 Each tuple describes a range of LBAs to erase
315 and consists of the following:
316 - An EFI_LBA that indicates the starting LBA
317 - A UINTN that indicates the number of blocks to
318 erase.
319
320 The list is terminated with an
321 EFI_LBA_LIST_TERMINATOR. For example, the
322 following indicates that two ranges of blocks
323 (5-7 and 10-11) are to be erased: EraseBlocks
324 (This, 5, 3, 10, 2, EFI_LBA_LIST_TERMINATOR);
325
326 @retval EFI_SUCCESS The erase request successfully
327 completed.
328
329 @retval EFI_ACCESS_DENIED The firmware volume is in the
330 WriteDisabled state.
331 @retval EFI_DEVICE_ERROR The block device is not functioning
332 correctly and could not be written.
333 The firmware device may have been
334 partially erased.
335 @retval EFI_INVALID_PARAMETER One or more of the LBAs listed
336 in the variable argument list do
337 not exist in the firmware volume.
338
339 **/
340 EFI_STATUS
341 EFIAPI
342 FvbEraseBlocks (
343 IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
344 ...
345 )
346 {
347 return EFI_UNSUPPORTED;
348 }
349
350
351 //
352 // Making this global saves a few bytes in image size
353 //
354 EFI_HANDLE gFvbHandle = NULL;
355
356
357 ///
358 /// The Firmware Volume Block Protocol is the low-level interface
359 /// to a firmware volume. File-level access to a firmware volume
360 /// should not be done using the Firmware Volume Block Protocol.
361 /// Normal access to a firmware volume must use the Firmware
362 /// Volume Protocol. Typically, only the file system driver that
363 /// produces the Firmware Volume Protocol will bind to the
364 /// Firmware Volume Block Protocol.
365 ///
366 EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL gFvbProtocol = {
367 FvbGetAttributes,
368 FvbSetAttributes,
369 FvbGetPhysicalAddress,
370 FvbGetBlockSize,
371 FvbRead,
372 FvbWrite,
373 FvbEraseBlocks,
374 ///
375 /// The handle of the parent firmware volume.
376 ///
377 NULL
378 };
379
380 // NvStorageVariableBase = (EFI_PHYSICAL_ADDRESS) FixedPcdGet32 (PcdFlashNvStorageVariableBase);
381
382
383 /**
384 Initialize the state information for the CPU Architectural Protocol
385
386 @param ImageHandle of the loaded driver
387 @param SystemTable Pointer to the System Table
388
389 @retval EFI_SUCCESS Protocol registered
390 @retval EFI_OUT_OF_RESOURCES Cannot allocate protocol data structure
391 @retval EFI_DEVICE_ERROR Hardware problems
392
393 **/
394 EFI_STATUS
395 EFIAPI
396 FvbDxeInitialize (
397 IN EFI_HANDLE ImageHandle,
398 IN EFI_SYSTEM_TABLE *SystemTable
399 )
400 {
401 EFI_STATUS Status;
402
403
404 Status = gBS->InstallMultipleProtocolInterfaces (
405 &gFvbHandle,
406 &gEfiFirmwareVolumeBlockProtocolGuid, &gFvbProtocol,
407 NULL
408 );
409 ASSERT_EFI_ERROR (Status);
410
411 // SetVertAddressEvent ()
412
413 // GCD Map NAND as RT
414
415 return Status;
416 }
417