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