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