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