]> git.proxmox.com Git - mirror_edk2.git/blob - FatPkg/FatPei/FatLitePeim.h
FatPkg/FatPei: Fix build error
[mirror_edk2.git] / FatPkg / FatPei / FatLitePeim.h
1 /** @file
2 Data structures for FAT recovery PEIM
3
4 Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
5
6 This program and the accompanying materials are licensed and made available
7 under the terms and conditions of the BSD License which accompanies this
8 distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #ifndef _FAT_PEIM_H_
17 #define _FAT_PEIM_H_
18
19 #include <PiPei.h>
20
21 #include <Guid/RecoveryDevice.h>
22 #include <Ppi/BlockIo.h>
23 #include <Ppi/BlockIo2.h>
24 #include <Ppi/DeviceRecoveryModule.h>
25
26 #include <Library/DebugLib.h>
27 #include <Library/BaseLib.h>
28 #include <Library/PeimEntryPoint.h>
29 #include <Library/BaseMemoryLib.h>
30 #include <Library/PcdLib.h>
31 #include <Library/PeiServicesTablePointerLib.h>
32 #include <Library/PeiServicesLib.h>
33
34 #include "FatLiteApi.h"
35 #include "FatLiteFmt.h"
36
37 //
38 // Definitions
39 //
40 #define PEI_FAT_RECOVERY_CAPSULE_WITH_NT_EMULATOR L"fv0001.fv"
41 #define PEI_FAT_RECOVERY_CAPSULE_WITHOUT_NT_EMULATOR L"fvmain.fv"
42
43 #define PEI_FAT_CACHE_SIZE 4
44 #define PEI_FAT_MAX_BLOCK_SIZE 8192
45 #define FAT_MAX_FILE_NAME_LENGTH 128
46 #define PEI_FAT_MAX_BLOCK_DEVICE 64
47 #define PEI_FAT_MAX_BLOCK_IO_PPI 32
48 #define PEI_FAT_MAX_VOLUME 64
49
50 #define PEI_FAT_MEMMORY_PAGE_SIZE 0x1000
51
52 //
53 // Data Structures
54 //
55 //
56 // The block device
57 //
58 typedef struct {
59
60 UINT32 BlockSize;
61 UINT64 LastBlock;
62 UINT32 IoAlign;
63 BOOLEAN Logical;
64 BOOLEAN PartitionChecked;
65
66 //
67 // Following fields only valid for logical device
68 //
69 CHAR8 PartitionFlag[8];
70 UINT64 StartingPos;
71 UINTN ParentDevNo;
72
73 //
74 // Following fields only valid for physical device
75 //
76 EFI_PEI_BLOCK_DEVICE_TYPE DevType;
77 UINT8 InterfaceType;
78 //
79 // EFI_PEI_READ_BLOCKS ReadFunc;
80 //
81 EFI_PEI_RECOVERY_BLOCK_IO_PPI *BlockIo;
82 EFI_PEI_RECOVERY_BLOCK_IO2_PPI *BlockIo2;
83 UINT8 PhysicalDevNo;
84 } PEI_FAT_BLOCK_DEVICE;
85
86 //
87 // the Volume structure
88 //
89 typedef struct {
90
91 UINTN BlockDeviceNo;
92 UINTN VolumeNo;
93 UINT64 VolumeSize;
94 UINTN MaxCluster;
95 CHAR16 VolumeLabel[FAT_MAX_FILE_NAME_LENGTH];
96 PEI_FAT_TYPE FatType;
97 UINT64 FatPos;
98 UINT32 SectorSize;
99 UINT32 ClusterSize;
100 UINT64 FirstClusterPos;
101 UINT64 RootDirPos;
102 UINT32 RootEntries;
103 UINT32 RootDirCluster;
104
105 } PEI_FAT_VOLUME;
106
107 //
108 // File instance
109 //
110 typedef struct {
111
112 PEI_FAT_VOLUME *Volume;
113 CHAR16 FileName[FAT_MAX_FILE_NAME_LENGTH];
114
115 BOOLEAN IsFixedRootDir;
116
117 UINT32 StartingCluster;
118 UINT32 CurrentPos;
119 UINT32 StraightReadAmount;
120 UINT32 CurrentCluster;
121
122 UINT8 Attributes;
123 UINT32 FileSize;
124
125 } PEI_FAT_FILE;
126
127 //
128 // Cache Buffer
129 //
130 typedef struct {
131
132 BOOLEAN Valid;
133 UINTN BlockDeviceNo;
134 UINT64 Lba;
135 UINT32 Lru;
136 UINT64 Buffer[PEI_FAT_MAX_BLOCK_SIZE / 8];
137 UINTN Size;
138
139 } PEI_FAT_CACHE_BUFFER;
140
141 //
142 // Private Data.
143 // This structure abstracts the whole memory usage in FAT PEIM.
144 // The entry point routine will get a chunk of memory (by whatever
145 // means) whose size is sizeof(PEI_FAT_PRIVATE_DATA), which is clean
146 // in both 32 and 64 bit environment. The boundary of the memory chunk
147 // should be 64bit aligned.
148 //
149 #define PEI_FAT_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('p', 'f', 'a', 't')
150
151 typedef struct {
152
153 UINTN Signature;
154 EFI_PEI_DEVICE_RECOVERY_MODULE_PPI DeviceRecoveryPpi;
155 EFI_PEI_PPI_DESCRIPTOR PpiDescriptor;
156 EFI_PEI_NOTIFY_DESCRIPTOR NotifyDescriptor[2];
157
158 UINT8 UnicodeCaseMap[0x300];
159 CHAR8 *EngUpperMap;
160 CHAR8 *EngLowerMap;
161 CHAR8 *EngInfoMap;
162
163 UINT64 BlockData[PEI_FAT_MAX_BLOCK_SIZE / 8];
164 UINTN BlockDeviceCount;
165 PEI_FAT_BLOCK_DEVICE BlockDevice[PEI_FAT_MAX_BLOCK_DEVICE];
166 UINTN VolumeCount;
167 PEI_FAT_VOLUME Volume[PEI_FAT_MAX_VOLUME];
168 PEI_FAT_FILE File;
169 PEI_FAT_CACHE_BUFFER CacheBuffer[PEI_FAT_CACHE_SIZE];
170
171 } PEI_FAT_PRIVATE_DATA;
172
173 #define PEI_FAT_PRIVATE_DATA_FROM_THIS(a) \
174 CR (a, PEI_FAT_PRIVATE_DATA, DeviceRecoveryPpi, PEI_FAT_PRIVATE_DATA_SIGNATURE)
175
176 //
177 // Extract INT32 from char array
178 //
179 #define UNPACK_INT32(a) \
180 (INT32) ((((UINT8 *) a)[0] << 0) | (((UINT8 *) a)[1] << 8) | (((UINT8 *) a)[2] << 16) | (((UINT8 *) a)[3] << 24))
181
182 //
183 // Extract UINT32 from char array
184 //
185 #define UNPACK_UINT32(a) \
186 (UINT32) ((((UINT8 *) a)[0] << 0) | (((UINT8 *) a)[1] << 8) | (((UINT8 *) a)[2] << 16) | (((UINT8 *) a)[3] << 24))
187
188
189 //
190 // API functions
191 //
192
193 /**
194 Finds the recovery file on a FAT volume.
195 This function finds the the recovery file named FileName on a specified FAT volume and returns
196 its FileHandle pointer.
197
198 @param PrivateData Global memory map for accessing global
199 variables.
200 @param VolumeIndex The index of the volume.
201 @param FileName The recovery file name to find.
202 @param Handle The output file handle.
203
204 @retval EFI_DEVICE_ERROR Some error occured when operating the FAT
205 volume.
206 @retval EFI_NOT_FOUND The recovery file was not found.
207 @retval EFI_SUCCESS The recovery file was successfully found on the
208 FAT volume.
209
210 **/
211 EFI_STATUS
212 FindRecoveryFile (
213 IN PEI_FAT_PRIVATE_DATA *PrivateData,
214 IN UINTN VolumeIndex,
215 IN CHAR16 *FileName,
216 OUT PEI_FILE_HANDLE *Handle
217 );
218
219
220 /**
221 Returns the number of DXE capsules residing on the device.
222 This function, by whatever mechanism, searches for DXE capsules from the associated device and
223 returns the number and maximum size in bytes of the capsules discovered.Entry 1 is assumed to be
224 the highest load priority and entry N is assumed to be the lowest priority.
225
226 @param PeiServices General-purpose services that are available to
227 every PEIM.
228 @param This Indicates the
229 EFI_PEI_DEVICE_RECOVERY_MODULE_PPI instance.
230 @param NumberRecoveryCapsules Pointer to a caller-allocated UINTN.On output,
231 *NumberRecoveryCapsules contains the number of
232 recovery capsule images available for retrieval
233 from this PEIM instance.
234
235 @retval EFI_SUCCESS The function completed successfully.
236
237 **/
238 EFI_STATUS
239 EFIAPI
240 GetNumberRecoveryCapsules (
241 IN EFI_PEI_SERVICES **PeiServices,
242 IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
243 OUT UINTN *NumberRecoveryCapsules
244 );
245
246
247 /**
248 Returns the size and type of the requested recovery capsule.
249 This function returns the size and type of the capsule specified by CapsuleInstance.
250
251 @param PeiServices General-purpose services that are available to
252 every PEIM.
253 @param This Indicates the
254 EFI_PEI_DEVICE_RECOVERY_MODULE_PPI instance.
255 @param CapsuleInstance Specifies for which capsule instance to
256 retrieve the information.T his parameter must
257 be between one and the value returned by
258 GetNumberRecoveryCapsules() in
259 NumberRecoveryCapsules.
260 @param Size A pointer to a caller-allocated UINTN in which
261 the size of the requested recovery module is
262 returned.
263 @param CapsuleType A pointer to a caller-allocated EFI_GUID in
264 which the type of the requested recovery
265 capsule is returned.T he semantic meaning of
266 the value returned is defined by the
267 implementation.
268
269 @retval EFI_SUCCESS The capsule type and size were retrieved.
270 @retval EFI_INVALID_PARAMETER The input CapsuleInstance does not match any
271 discovered recovery capsule.
272
273 **/
274 EFI_STATUS
275 EFIAPI
276 GetRecoveryCapsuleInfo (
277 IN EFI_PEI_SERVICES **PeiServices,
278 IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
279 IN UINTN CapsuleInstance,
280 OUT UINTN *Size,
281 OUT EFI_GUID *CapsuleType
282 );
283
284
285 /**
286 Loads a DXE capsule from some media into memory.
287
288 This function, by whatever mechanism, retrieves a DXE capsule from some device
289 and loads it into memory. Note that the published interface is device neutral.
290
291 @param[in] PeiServices General-purpose services that are available
292 to every PEIM
293 @param[in] This Indicates the EFI_PEI_DEVICE_RECOVERY_MODULE_PPI
294 instance.
295 @param[in] CapsuleInstance Specifies which capsule instance to retrieve.
296 @param[out] Buffer Specifies a caller-allocated buffer in which
297 the requested recovery capsule will be returned.
298
299 @retval EFI_SUCCESS The capsule was loaded correctly.
300 @retval EFI_DEVICE_ERROR A device error occurred.
301 @retval EFI_NOT_FOUND A requested recovery DXE capsule cannot be found.
302
303 **/
304 EFI_STATUS
305 EFIAPI
306 LoadRecoveryCapsule (
307 IN EFI_PEI_SERVICES **PeiServices,
308 IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
309 IN UINTN CapsuleInstance,
310 OUT VOID *Buffer
311 );
312
313
314 /**
315 This version is different from the version in Unicode collation
316 protocol in that this version strips off trailing blanks.
317 Converts an 8.3 FAT file name using an OEM character set
318 to a Null-terminated Unicode string.
319 Here does not expand DBCS FAT chars.
320
321 @param FatSize The size of the string Fat in bytes.
322 @param Fat A pointer to a Null-terminated string that contains
323 an 8.3 file name using an OEM character set.
324 @param Str A pointer to a Null-terminated Unicode string. The
325 string must be allocated in advance to hold FatSize
326 Unicode characters
327
328 **/
329 VOID
330 EngFatToStr (
331 IN UINTN FatSize,
332 IN CHAR8 *Fat,
333 OUT CHAR16 *Str
334 );
335
336
337 /**
338 Performs a case-insensitive comparison of two Null-terminated Unicode strings.
339
340 @param PrivateData Global memory map for accessing global variables
341 @param Str1 First string to perform case insensitive comparison.
342 @param Str2 Second string to perform case insensitive comparison.
343
344 **/
345 BOOLEAN
346 EngStriColl (
347 IN PEI_FAT_PRIVATE_DATA *PrivateData,
348 IN CHAR16 *Str1,
349 IN CHAR16 *Str2
350 );
351
352
353 /**
354 Reads a block of data from the block device by calling
355 underlying Block I/O service.
356
357 @param PrivateData Global memory map for accessing global variables
358 @param BlockDeviceNo The index for the block device number.
359 @param Lba The logic block address to read data from.
360 @param BufferSize The size of data in byte to read.
361 @param Buffer The buffer of the
362
363 @retval EFI_DEVICE_ERROR The specified block device number exceeds the maximum
364 device number.
365 @retval EFI_DEVICE_ERROR The maximum address has exceeded the maximum address
366 of the block device.
367
368 **/
369 EFI_STATUS
370 FatReadBlock (
371 IN PEI_FAT_PRIVATE_DATA *PrivateData,
372 IN UINTN BlockDeviceNo,
373 IN EFI_PEI_LBA Lba,
374 IN UINTN BufferSize,
375 OUT VOID *Buffer
376 );
377
378
379 /**
380 Check if there is a valid FAT in the corresponding Block device
381 of the volume and if yes, fill in the relevant fields for the
382 volume structure. Note there should be a valid Block device number
383 already set.
384
385 @param PrivateData Global memory map for accessing global
386 variables.
387 @param Volume On input, the BlockDeviceNumber field of the
388 Volume should be a valid value. On successful
389 output, all fields except the VolumeNumber
390 field is initialized.
391
392 @retval EFI_SUCCESS A FAT is found and the volume structure is
393 initialized.
394 @retval EFI_NOT_FOUND There is no FAT on the corresponding device.
395 @retval EFI_DEVICE_ERROR There is something error while accessing device.
396
397 **/
398 EFI_STATUS
399 FatGetBpbInfo (
400 IN PEI_FAT_PRIVATE_DATA *PrivateData,
401 IN OUT PEI_FAT_VOLUME *Volume
402 );
403
404
405 /**
406 Gets the next cluster in the cluster chain.
407
408 @param PrivateData Global memory map for accessing global variables
409 @param Volume The volume
410 @param Cluster The cluster
411 @param NextCluster The cluster number of the next cluster
412
413 @retval EFI_SUCCESS The address is got
414 @retval EFI_INVALID_PARAMETER ClusterNo exceeds the MaxCluster of the volume.
415 @retval EFI_DEVICE_ERROR Read disk error
416
417 **/
418 EFI_STATUS
419 FatGetNextCluster (
420 IN PEI_FAT_PRIVATE_DATA *PrivateData,
421 IN PEI_FAT_VOLUME *Volume,
422 IN UINT32 Cluster,
423 OUT UINT32 *NextCluster
424 );
425
426
427 /**
428 Disk reading.
429
430 @param PrivateData the global memory map;
431 @param BlockDeviceNo the block device to read;
432 @param StartingAddress the starting address.
433 @param Size the amount of data to read.
434 @param Buffer the buffer holding the data
435
436 @retval EFI_SUCCESS The function completed successfully.
437 @retval EFI_DEVICE_ERROR Something error.
438
439 **/
440 EFI_STATUS
441 FatReadDisk (
442 IN PEI_FAT_PRIVATE_DATA *PrivateData,
443 IN UINTN BlockDeviceNo,
444 IN UINT64 StartingAddress,
445 IN UINTN Size,
446 OUT VOID *Buffer
447 );
448
449
450 /**
451 Set a file's CurrentPos and CurrentCluster, then compute StraightReadAmount.
452
453 @param PrivateData the global memory map
454 @param File the file
455 @param Pos the Position which is offset from the file's
456 CurrentPos
457
458 @retval EFI_SUCCESS Success.
459 @retval EFI_INVALID_PARAMETER Pos is beyond file's size.
460 @retval EFI_DEVICE_ERROR Something error while accessing media.
461
462 **/
463 EFI_STATUS
464 FatSetFilePos (
465 IN PEI_FAT_PRIVATE_DATA *PrivateData,
466 IN PEI_FAT_FILE *File,
467 IN UINT32 Pos
468 );
469
470
471 /**
472 Reads file data. Updates the file's CurrentPos.
473
474 @param PrivateData Global memory map for accessing global variables
475 @param File The file.
476 @param Size The amount of data to read.
477 @param Buffer The buffer storing the data.
478
479 @retval EFI_SUCCESS The data is read.
480 @retval EFI_INVALID_PARAMETER File is invalid.
481 @retval EFI_DEVICE_ERROR Something error while accessing media.
482
483 **/
484 EFI_STATUS
485 FatReadFile (
486 IN PEI_FAT_PRIVATE_DATA *PrivateData,
487 IN PEI_FAT_FILE *File,
488 IN UINTN Size,
489 OUT VOID *Buffer
490 );
491
492
493 /**
494 This function reads the next item in the parent directory and
495 initializes the output parameter SubFile (CurrentPos is initialized to 0).
496 The function updates the CurrentPos of the parent dir to after the item read.
497 If no more items were found, the function returns EFI_NOT_FOUND.
498
499 @param PrivateData Global memory map for accessing global variables
500 @param ParentDir The parent directory.
501 @param SubFile The File structure containing the sub file that
502 is caught.
503
504 @retval EFI_SUCCESS The next sub file is obtained.
505 @retval EFI_INVALID_PARAMETER The ParentDir is not a directory.
506 @retval EFI_NOT_FOUND No more sub file exists.
507 @retval EFI_DEVICE_ERROR Something error while accessing media.
508
509 **/
510 EFI_STATUS
511 FatReadNextDirectoryEntry (
512 IN PEI_FAT_PRIVATE_DATA *PrivateData,
513 IN PEI_FAT_FILE *ParentDir,
514 OUT PEI_FAT_FILE *SubFile
515 );
516
517
518 /**
519 This function finds partitions (logical devices) in physical block devices.
520
521 @param PrivateData Global memory map for accessing global variables.
522
523 **/
524 VOID
525 FatFindPartitions (
526 IN PEI_FAT_PRIVATE_DATA *PrivateData
527 );
528
529 #endif // _FAT_PEIM_H_