fe596e6a36b16f17c7f57dbc7679cf2b168c82fc
[mirror_edk2.git] / EdkModulePkg / Library / EdkFvbServiceLib / Ipf / Fvb.c
1 /*++
2
3 Copyright (c) 2006, 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 EFI_STATUS
29 EFIAPI
30 FvbLibInitialize (
31 IN EFI_HANDLE ImageHandle,
32 IN EFI_SYSTEM_TABLE *SystemTable
33 )
34 /*++
35
36 Routine Description:
37 Initialize globals and register Fvb Protocol notification function.
38
39 Arguments:
40 None
41
42 Returns:
43 EFI_SUCCESS
44
45 --*/
46 {
47 return EFI_SUCCESS;
48 }
49 //
50 // The following functions wrap Fvb protocol in the Runtime Lib functions.
51 // The Instance translates into Fvb instance. The Fvb order defined by HOBs and
52 // thus the sequence of FVB protocol addition define Instance.
53 //
54 // EfiFvbInitialize () must be called before any of the following functions
55 // must be called.
56 //
57 EFI_STATUS
58 EfiFvbReadBlock (
59 IN UINTN Instance,
60 IN EFI_LBA Lba,
61 IN UINTN Offset,
62 IN OUT UINTN *NumBytes,
63 IN UINT8 *Buffer
64 )
65 /*++
66
67 Routine Description:
68 Reads specified number of bytes into a buffer from the specified block
69
70 Arguments:
71 Instance - The FV instance to be read from
72 Lba - The logical block address to be read from
73 Offset - Offset into the block at which to begin reading
74 NumBytes - Pointer that on input contains the total size of
75 the buffer. On output, it contains the total number
76 of bytes read
77 Buffer - Pointer to a caller allocated buffer that will be
78 used to hold the data read
79
80 Returns:
81 Status code
82
83 --*/
84 {
85 EFI_GUID Guid;
86
87 *((UINT64 *) &Guid) = EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID_LO;
88 *(((UINT64 *)&Guid) + 1) = EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID_HI;
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;
122
123 *((UINT64 *) &Guid) = EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID_LO;
124 *(((UINT64 *)&Guid) + 1) = EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID_HI;
125
126 return EfiCallEsalService (&Guid, Write, Instance, Lba, Offset, (UINT64) NumBytes, (UINT64) Buffer, 0, 0).Status;
127 }
128
129 EFI_STATUS
130 EfiFvbEraseBlock (
131 IN UINTN Instance,
132 IN UINTN Lba
133 )
134 /*++
135
136 Routine Description:
137 Erases and initializes a firmware volume block
138
139 Arguments:
140 Instance - The FV instance to be erased
141 Lba - The logical block index to be erased
142
143 Returns:
144 Status code
145
146 --*/
147 {
148 EFI_GUID Guid;
149
150 *((UINT64 *) &Guid) = EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID_LO;
151 *(((UINT64 *)&Guid) + 1) = EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID_HI;
152
153 return EfiCallEsalService (&Guid, EraseBlock, Instance, Lba, 0, 0, 0, 0, 0).Status;
154 }
155
156 EFI_STATUS
157 EfiFvbGetVolumeAttributes (
158 IN UINTN Instance,
159 OUT EFI_FVB_ATTRIBUTES *Attributes
160 )
161 /*++
162
163 Routine Description:
164 Retrieves attributes, insures positive polarity of attribute bits, returns
165 resulting attributes in output parameter
166
167 Arguments:
168 Instance - The FV instance whose attributes is going to be
169 returned
170 Attributes - Output buffer which contains attributes
171
172 Returns:
173 Status code
174
175 --*/
176 {
177 EFI_GUID Guid;
178
179 *((UINT64 *) &Guid) = EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID_LO;
180 *(((UINT64 *)&Guid) + 1) = EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID_HI;
181
182 return EfiCallEsalService (&Guid, SetVolumeAttributes, Instance, (UINT64) Attributes, 0, 0, 0, 0, 0).Status;
183 }
184
185 EFI_STATUS
186 EfiFvbSetVolumeAttributes (
187 IN UINTN Instance,
188 IN EFI_FVB_ATTRIBUTES Attributes
189 )
190 /*++
191
192 Routine Description:
193 Modifies the current settings of the firmware volume according to the
194 input parameter, and returns the new setting of the volume
195
196 Arguments:
197 Instance - The FV instance whose attributes is going to be
198 modified
199 Attributes - On input, it is a pointer to EFI_FVB_ATTRIBUTES
200 containing the desired firmware volume settings.
201 On successful return, it contains the new settings
202 of the firmware volume
203
204 Returns:
205 Status code
206
207 --*/
208 {
209 EFI_GUID Guid;
210
211 *((UINT64 *) &Guid) = EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID_LO;
212 *(((UINT64 *)&Guid) + 1) = EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID_HI;
213
214 return EfiCallEsalService (&Guid, SetVolumeAttributes, Instance, (UINT64) Attributes, 0, 0, 0, 0, 0).Status;
215 }
216
217 EFI_STATUS
218 EfiFvbGetPhysicalAddress (
219 IN UINTN Instance,
220 OUT EFI_PHYSICAL_ADDRESS *BaseAddress
221 )
222 /*++
223
224 Routine Description:
225 Retrieves the physical address of a memory mapped FV
226
227 Arguments:
228 Instance - The FV instance whose base address is going to be
229 returned
230 BaseAddress - Pointer to a caller allocated EFI_PHYSICAL_ADDRESS
231 that on successful return, contains the base address
232 of the firmware volume.
233
234 Returns:
235 Status code
236
237 --*/
238 {
239 EFI_GUID Guid;
240
241 *((UINT64 *) &Guid) = EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID_LO;
242 *(((UINT64 *)&Guid) + 1) = EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID_HI;
243
244 return EfiCallEsalService (&Guid, GetPhysicalAddress, Instance, (UINT64) BaseAddress, 0, 0, 0, 0, 0).Status;
245 }
246
247 EFI_STATUS
248 EfiFvbGetBlockSize (
249 IN UINTN Instance,
250 IN EFI_LBA Lba,
251 OUT UINTN *BlockSize,
252 OUT UINTN *NumOfBlocks
253 )
254 /*++
255
256 Routine Description:
257 Retrieve the size of a logical block
258
259 Arguments:
260 Instance - The FV instance whose block size is going to be
261 returned
262 Lba - Indicates which block to return the size for.
263 BlockSize - A pointer to a caller allocated UINTN in which
264 the size of the block is returned
265 NumOfBlocks - a pointer to a caller allocated UINTN in which the
266 number of consecutive blocks starting with Lba is
267 returned. All blocks in this range have a size of
268 BlockSize
269
270 Returns:
271 EFI_SUCCESS - The firmware volume was read successfully and
272 contents are in Buffer
273
274 --*/
275 {
276 EFI_GUID Guid;
277
278 *((UINT64 *) &Guid) = EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID_LO;
279 *(((UINT64 *)&Guid) + 1) = EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID_HI;
280
281 return EfiCallEsalService (
282 &Guid,
283 GetBlockSize,
284 Instance,
285 Lba,
286 (UINT64) BlockSize,
287 (UINT64) NumOfBlocks,
288 0,
289 0,
290 0
291 ).Status;
292 }
293
294 EFI_STATUS
295 EfiFvbEraseCustomBlockRange (
296 IN UINTN Instance,
297 IN EFI_LBA StartLba,
298 IN UINTN OffsetStartLba,
299 IN EFI_LBA LastLba,
300 IN UINTN OffsetLastLba
301 )
302 /*++
303
304 Routine Description:
305 Erases and initializes a specified range of a firmware volume
306
307 Arguments:
308 Instance - The FV instance to be erased
309 StartLba - The starting logical block index to be erased
310 OffsetStartLba - Offset into the starting block at which to
311 begin erasing
312 LastLba - The last logical block index to be erased
313 OffsetLastLba - Offset into the last block at which to end erasing
314
315 Returns:
316 Status code
317
318 --*/
319 {
320 EFI_GUID Guid;
321
322 *((UINT64 *) &Guid) = EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID_LO;
323 *(((UINT64 *)&Guid) + 1) = EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID_HI;
324
325 return EfiCallEsalService (
326 &Guid,
327 EraseCustomBlockRange,
328 Instance,
329 StartLba,
330 OffsetStartLba,
331 LastLba,
332 OffsetLastLba,
333 0,
334 0
335 ).Status;
336 }
337
338
339 /**
340 BugBug: Can't turn this off in the current MSA so we need a stub
341 **/
342 VOID
343 EFIAPI
344 FvbVirtualAddressChangeNotifyEvent (
345 IN EFI_EVENT Event,
346 IN VOID *Context
347 )
348 {
349 }