added EFIAPI for those constructor functions
[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 = EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID;
86
87 return EfiCallEsalService (&Guid, Read, Instance, Lba, Offset, (UINT64) NumBytes, (UINT64) Buffer, 0, 0).Status;
88 }
89
90 EFI_STATUS
91 EfiFvbWriteBlock (
92 IN UINTN Instance,
93 IN EFI_LBA Lba,
94 IN UINTN Offset,
95 IN OUT UINTN *NumBytes,
96 IN UINT8 *Buffer
97 )
98 /*++
99
100 Routine Description:
101 Writes specified number of bytes from the input buffer to the block
102
103 Arguments:
104 Instance - The FV instance to be written to
105 Lba - The starting logical block index to write to
106 Offset - Offset into the block at which to begin writing
107 NumBytes - Pointer that on input contains the total size of
108 the buffer. On output, it contains the total number
109 of bytes actually written
110 Buffer - Pointer to a caller allocated buffer that contains
111 the source for the write
112
113 Returns:
114 Status code
115
116 --*/
117 {
118 EFI_GUID Guid = EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID;
119
120 return EfiCallEsalService (&Guid, Write, Instance, Lba, Offset, (UINT64) NumBytes, (UINT64) Buffer, 0, 0).Status;
121 }
122
123 EFI_STATUS
124 EfiFvbEraseBlock (
125 IN UINTN Instance,
126 IN UINTN Lba
127 )
128 /*++
129
130 Routine Description:
131 Erases and initializes a firmware volume block
132
133 Arguments:
134 Instance - The FV instance to be erased
135 Lba - The logical block index to be erased
136
137 Returns:
138 Status code
139
140 --*/
141 {
142 EFI_GUID Guid = EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID;
143
144 return EfiCallEsalService (&Guid, EraseBlock, Instance, Lba, 0, 0, 0, 0, 0).Status;
145 }
146
147 EFI_STATUS
148 EfiFvbGetVolumeAttributes (
149 IN UINTN Instance,
150 OUT EFI_FVB_ATTRIBUTES *Attributes
151 )
152 /*++
153
154 Routine Description:
155 Retrieves attributes, insures positive polarity of attribute bits, returns
156 resulting attributes in output parameter
157
158 Arguments:
159 Instance - The FV instance whose attributes is going to be
160 returned
161 Attributes - Output buffer which contains attributes
162
163 Returns:
164 Status code
165
166 --*/
167 {
168 EFI_GUID Guid = EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID;
169
170 return EfiCallEsalService (&Guid, SetVolumeAttributes, Instance, (UINT64) Attributes, 0, 0, 0, 0, 0).Status;
171 }
172
173 EFI_STATUS
174 EfiFvbSetVolumeAttributes (
175 IN UINTN Instance,
176 IN EFI_FVB_ATTRIBUTES Attributes
177 )
178 /*++
179
180 Routine Description:
181 Modifies the current settings of the firmware volume according to the
182 input parameter, and returns the new setting of the volume
183
184 Arguments:
185 Instance - The FV instance whose attributes is going to be
186 modified
187 Attributes - On input, it is a pointer to EFI_FVB_ATTRIBUTES
188 containing the desired firmware volume settings.
189 On successful return, it contains the new settings
190 of the firmware volume
191
192 Returns:
193 Status code
194
195 --*/
196 {
197 EFI_GUID Guid = EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID;
198
199 return EfiCallEsalService (&Guid, SetVolumeAttributes, Instance, (UINT64) Attributes, 0, 0, 0, 0, 0).Status;
200 }
201
202 EFI_STATUS
203 EfiFvbGetPhysicalAddress (
204 IN UINTN Instance,
205 OUT EFI_PHYSICAL_ADDRESS *BaseAddress
206 )
207 /*++
208
209 Routine Description:
210 Retrieves the physical address of a memory mapped FV
211
212 Arguments:
213 Instance - The FV instance whose base address is going to be
214 returned
215 BaseAddress - Pointer to a caller allocated EFI_PHYSICAL_ADDRESS
216 that on successful return, contains the base address
217 of the firmware volume.
218
219 Returns:
220 Status code
221
222 --*/
223 {
224 EFI_GUID Guid = EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID;
225
226 return EfiCallEsalService (&Guid, GetPhysicalAddress, Instance, (UINT64) BaseAddress, 0, 0, 0, 0, 0).Status;
227 }
228
229 EFI_STATUS
230 EfiFvbGetBlockSize (
231 IN UINTN Instance,
232 IN EFI_LBA Lba,
233 OUT UINTN *BlockSize,
234 OUT UINTN *NumOfBlocks
235 )
236 /*++
237
238 Routine Description:
239 Retrieve the size of a logical block
240
241 Arguments:
242 Instance - The FV instance whose block size is going to be
243 returned
244 Lba - Indicates which block to return the size for.
245 BlockSize - A pointer to a caller allocated UINTN in which
246 the size of the block is returned
247 NumOfBlocks - a pointer to a caller allocated UINTN in which the
248 number of consecutive blocks starting with Lba is
249 returned. All blocks in this range have a size of
250 BlockSize
251
252 Returns:
253 EFI_SUCCESS - The firmware volume was read successfully and
254 contents are in Buffer
255
256 --*/
257 {
258 EFI_GUID Guid = EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID;
259
260 return EfiCallEsalService (
261 &Guid,
262 GetBlockSize,
263 Instance,
264 Lba,
265 (UINT64) BlockSize,
266 (UINT64) NumOfBlocks,
267 0,
268 0,
269 0
270 ).Status;
271 }
272
273 EFI_STATUS
274 EfiFvbEraseCustomBlockRange (
275 IN UINTN Instance,
276 IN EFI_LBA StartLba,
277 IN UINTN OffsetStartLba,
278 IN EFI_LBA LastLba,
279 IN UINTN OffsetLastLba
280 )
281 /*++
282
283 Routine Description:
284 Erases and initializes a specified range of a firmware volume
285
286 Arguments:
287 Instance - The FV instance to be erased
288 StartLba - The starting logical block index to be erased
289 OffsetStartLba - Offset into the starting block at which to
290 begin erasing
291 LastLba - The last logical block index to be erased
292 OffsetLastLba - Offset into the last block at which to end erasing
293
294 Returns:
295 Status code
296
297 --*/
298 {
299 EFI_GUID Guid = EFI_EXTENDED_SAL_FV_BLOCK_SERVICES_PROTOCOL_GUID;
300
301 return EfiCallEsalService (
302 &Guid,
303 EraseCustomBlockRange,
304 Instance,
305 StartLba,
306 OffsetStartLba,
307 LastLba,
308 OffsetLastLba,
309 0,
310 0
311 ).Status;
312 }
313
314
315 /**
316 BugBug: Can't turn this off in the current MSA so we need a stub
317 **/
318 VOID
319 EFIAPI
320 FvbVirtualAddressChangeNotifyEvent (
321 IN EFI_EVENT Event,
322 IN VOID *Context
323 )
324 {
325 }