]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/RuntimeDxe/EfiRuntimeLib/Ipf/Fvb.c
Add in the 1st version of ECP.
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / RuntimeDxe / EfiRuntimeLib / Ipf / Fvb.c
1 /*++
2
3 Copyright (c) 2004, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 Fvb.c
15
16 Abstract:
17
18 Light weight lib to support Tiano Firmware Volume Block
19 protocol abstraction at runtime.
20
21 All these functions convert EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID
22 class function to the Runtime Lib function. There is a 1 to 1 mapping.
23
24 If you are using any of these lib functions.you must first call FvbInitialize ().
25
26 --*/
27
28 #include "Tiano.h"
29 #include "EfiRuntimeLib.h"
30 #include EFI_PROTOCOL_DEFINITION (ExtendedSalGuid)
31 #include "SalApi.h"
32
33 EFI_STATUS
34 EfiFvbInitialize (
35 VOID
36 )
37 /*++
38
39 Routine Description:
40 Initialize globals and register Fvb Protocol notification function.
41
42 Arguments:
43 None
44
45 Returns:
46 EFI_SUCCESS
47
48 --*/
49 {
50 return EFI_SUCCESS;
51 }
52 //
53 // The following functions wrap Fvb protocol in the Runtime Lib functions.
54 // The Instance translates into Fvb instance. The Fvb order defined by HOBs and
55 // thus the sequence of FVB protocol addition define Instance.
56 //
57 // EfiFvbInitialize () must be called before any of the following functions
58 // must be called.
59 //
60 EFI_STATUS
61 EfiFvbReadBlock (
62 IN UINTN Instance,
63 IN EFI_LBA Lba,
64 IN UINTN Offset,
65 IN OUT UINTN *NumBytes,
66 IN UINT8 *Buffer
67 )
68 /*++
69
70 Routine Description:
71 Reads specified number of bytes into a buffer from the specified block
72
73 Arguments:
74 Instance - The FV instance to be read from
75 Lba - The logical block address to be read from
76 Offset - Offset into the block at which to begin reading
77 NumBytes - Pointer that on input contains the total size of
78 the buffer. On output, it contains the total number
79 of bytes read
80 Buffer - Pointer to a caller allocated buffer that will be
81 used to hold the data read
82
83 Returns:
84 Status code
85
86 --*/
87 {
88 EFI_GUID Guid = EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID;
89
90 return EfiCallEsalService (&Guid, Read, Instance, Lba, Offset, (UINT64) NumBytes, (UINT64) Buffer, 0, 0).Status;
91 }
92
93 EFI_STATUS
94 EfiFvbWriteBlock (
95 IN UINTN Instance,
96 IN EFI_LBA Lba,
97 IN UINTN Offset,
98 IN OUT UINTN *NumBytes,
99 IN UINT8 *Buffer
100 )
101 /*++
102
103 Routine Description:
104 Writes specified number of bytes from the input buffer to the block
105
106 Arguments:
107 Instance - The FV instance to be written to
108 Lba - The starting logical block index to write to
109 Offset - Offset into the block at which to begin writing
110 NumBytes - Pointer that on input contains the total size of
111 the buffer. On output, it contains the total number
112 of bytes actually written
113 Buffer - Pointer to a caller allocated buffer that contains
114 the source for the write
115
116 Returns:
117 Status code
118
119 --*/
120 {
121 EFI_GUID Guid = EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID;
122
123 return EfiCallEsalService (&Guid, Write, Instance, Lba, Offset, (UINT64) NumBytes, (UINT64) Buffer, 0, 0).Status;
124 }
125
126 EFI_STATUS
127 EfiFvbEraseBlock (
128 IN UINTN Instance,
129 IN UINTN Lba
130 )
131 /*++
132
133 Routine Description:
134 Erases and initializes a firmware volume block
135
136 Arguments:
137 Instance - The FV instance to be erased
138 Lba - The logical block index to be erased
139
140 Returns:
141 Status code
142
143 --*/
144 {
145 EFI_GUID Guid = EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID;
146
147 return EfiCallEsalService (&Guid, EraseBlock, Instance, Lba, 0, 0, 0, 0, 0).Status;
148 }
149
150 EFI_STATUS
151 EfiFvbGetVolumeAttributes (
152 IN UINTN Instance,
153 OUT EFI_FVB_ATTRIBUTES *Attributes
154 )
155 /*++
156
157 Routine Description:
158 Retrieves attributes, insures positive polarity of attribute bits, returns
159 resulting attributes in output parameter
160
161 Arguments:
162 Instance - The FV instance whose attributes is going to be
163 returned
164 Attributes - Output buffer which contains attributes
165
166 Returns:
167 Status code
168
169 --*/
170 {
171 EFI_GUID Guid = EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID;
172
173 return EfiCallEsalService (&Guid, SetVolumeAttributes, Instance, (UINT64) Attributes, 0, 0, 0, 0, 0).Status;
174 }
175
176 EFI_STATUS
177 EfiFvbSetVolumeAttributes (
178 IN UINTN Instance,
179 IN EFI_FVB_ATTRIBUTES Attributes
180 )
181 /*++
182
183 Routine Description:
184 Modifies the current settings of the firmware volume according to the
185 input parameter, and returns the new setting of the volume
186
187 Arguments:
188 Instance - The FV instance whose attributes is going to be
189 modified
190 Attributes - On input, it is a pointer to EFI_FVB_ATTRIBUTES
191 containing the desired firmware volume settings.
192 On successful return, it contains the new settings
193 of the firmware volume
194
195 Returns:
196 Status code
197
198 --*/
199 {
200 EFI_GUID Guid = EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID;
201
202 return EfiCallEsalService (&Guid, SetVolumeAttributes, Instance, (UINT64) Attributes, 0, 0, 0, 0, 0).Status;
203 }
204
205 EFI_STATUS
206 EfiFvbGetPhysicalAddress (
207 IN UINTN Instance,
208 OUT EFI_PHYSICAL_ADDRESS *BaseAddress
209 )
210 /*++
211
212 Routine Description:
213 Retrieves the physical address of a memory mapped FV
214
215 Arguments:
216 Instance - The FV instance whose base address is going to be
217 returned
218 BaseAddress - Pointer to a caller allocated EFI_PHYSICAL_ADDRESS
219 that on successful return, contains the base address
220 of the firmware volume.
221
222 Returns:
223 Status code
224
225 --*/
226 {
227 EFI_GUID Guid = EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID;
228
229 return EfiCallEsalService (&Guid, GetPhysicalAddress, Instance, (UINT64) BaseAddress, 0, 0, 0, 0, 0).Status;
230 }
231
232 EFI_STATUS
233 EfiFvbGetBlockSize (
234 IN UINTN Instance,
235 IN EFI_LBA Lba,
236 OUT UINTN *BlockSize,
237 OUT UINTN *NumOfBlocks
238 )
239 /*++
240
241 Routine Description:
242 Retrieve the size of a logical block
243
244 Arguments:
245 Instance - The FV instance whose block size is going to be
246 returned
247 Lba - Indicates which block to return the size for.
248 BlockSize - A pointer to a caller allocated UINTN in which
249 the size of the block is returned
250 NumOfBlocks - a pointer to a caller allocated UINTN in which the
251 number of consecutive blocks starting with Lba is
252 returned. All blocks in this range have a size of
253 BlockSize
254
255 Returns:
256 EFI_SUCCESS - The firmware volume was read successfully and
257 contents are in Buffer
258
259 --*/
260 {
261 EFI_GUID Guid = EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID;
262
263 return EfiCallEsalService (
264 &Guid,
265 GetBlockSize,
266 Instance,
267 Lba,
268 (UINT64) BlockSize,
269 (UINT64) NumOfBlocks,
270 0,
271 0,
272 0
273 ).Status;
274 }
275
276 EFI_STATUS
277 EfiFvbEraseCustomBlockRange (
278 IN UINTN Instance,
279 IN EFI_LBA StartLba,
280 IN UINTN OffsetStartLba,
281 IN EFI_LBA LastLba,
282 IN UINTN OffsetLastLba
283 )
284 /*++
285
286 Routine Description:
287 Erases and initializes a specified range of a firmware volume
288
289 Arguments:
290 Instance - The FV instance to be erased
291 StartLba - The starting logical block index to be erased
292 OffsetStartLba - Offset into the starting block at which to
293 begin erasing
294 LastLba - The last logical block index to be erased
295 OffsetLastLba - Offset into the last block at which to end erasing
296
297 Returns:
298 Status code
299
300 --*/
301 {
302 EFI_GUID Guid = EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID;
303
304 return EfiCallEsalService (
305 &Guid,
306 EraseCustomBlockRange,
307 Instance,
308 StartLba,
309 OffsetStartLba,
310 LastLba,
311 OffsetLastLba,
312 0,
313 0
314 ).Status;
315 }
316 EFI_STATUS
317 EfiFvbShutdown (
318 VOID
319 )
320 /*++
321
322 Routine Description:
323 Release resources allocated in EfiFvbInitialize.
324
325 Arguments:
326 None
327
328 Returns:
329 EFI_SUCCESS
330
331 --*/
332 {
333 return EFI_SUCCESS;
334 }