]> git.proxmox.com Git - mirror_edk2.git/blobdiff - FatPkg/FatPei/FatLiteLib.c
IntelFsp2Pkg: Support 64bit FspResetType for X64 build.
[mirror_edk2.git] / FatPkg / FatPei / FatLiteLib.c
index 109789a54baa0e412e52913256dc8c92fb4c0d82..ef71fe907e557ed0c0d5877b7a944a78d1e70649 100644 (file)
@@ -1,71 +1,62 @@
 /** @file\r
   General purpose supporting routines for FAT recovery PEIM\r
 \r
-Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
 \r
-This program and the accompanying materials are licensed and made available\r
-under the terms and conditions of the BSD License which accompanies this\r
-distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 #include "FatLitePeim.h"\r
 \r
-\r
 #define CHAR_FAT_VALID  0x01\r
 \r
-\r
 /**\r
   Converts a union code character to upper case.\r
   This functions converts a unicode character to upper case.\r
   If the input Letter is not a lower-cased letter,\r
   the original value is returned.\r
 \r
-  @param  Letter            The input unicode character. \r
+  @param  Letter            The input unicode character.\r
 \r
   @return The upper cased letter.\r
 \r
 **/\r
 CHAR16\r
 ToUpper (\r
-  IN CHAR16                    Letter\r
+  IN CHAR16  Letter\r
   )\r
 {\r
-  if ('a' <= Letter && Letter <= 'z') {\r
-    Letter = (CHAR16) (Letter - 0x20);\r
+  if (('a' <= Letter) && (Letter <= 'z')) {\r
+    Letter = (CHAR16)(Letter - 0x20);\r
   }\r
 \r
   return Letter;\r
 }\r
 \r
-\r
 /**\r
   Reads a block of data from the block device by calling\r
   underlying Block I/O service.\r
 \r
-  @param  PrivateData       Global memory map for accessing global variables \r
-  @param  BlockDeviceNo     The index for the block device number. \r
-  @param  Lba               The logic block address to read data from. \r
-  @param  BufferSize        The size of data in byte to read. \r
-  @param  Buffer            The buffer of the \r
+  @param  PrivateData       Global memory map for accessing global variables\r
+  @param  BlockDeviceNo     The index for the block device number.\r
+  @param  Lba               The logic block address to read data from.\r
+  @param  BufferSize        The size of data in byte to read.\r
+  @param  Buffer            The buffer of the\r
 \r
-  @retval EFI_DEVICE_ERROR  The specified block device number exceeds the maximum \r
-                            device number. \r
-  @retval EFI_DEVICE_ERROR  The maximum address has exceeded the maximum address \r
+  @retval EFI_DEVICE_ERROR  The specified block device number exceeds the maximum\r
+                            device number.\r
+  @retval EFI_DEVICE_ERROR  The maximum address has exceeded the maximum address\r
                             of the block device.\r
 \r
 **/\r
 EFI_STATUS\r
 FatReadBlock (\r
-  IN  PEI_FAT_PRIVATE_DATA   *PrivateData,\r
-  IN  UINTN                  BlockDeviceNo,\r
-  IN  EFI_PEI_LBA            Lba,\r
-  IN  UINTN                  BufferSize,\r
-  OUT VOID                   *Buffer\r
+  IN  PEI_FAT_PRIVATE_DATA  *PrivateData,\r
+  IN  UINTN                 BlockDeviceNo,\r
+  IN  EFI_PEI_LBA           Lba,\r
+  IN  UINTN                 BufferSize,\r
+  OUT VOID                  *Buffer\r
   )\r
 {\r
   EFI_STATUS            Status;\r
@@ -75,8 +66,8 @@ FatReadBlock (
     return EFI_DEVICE_ERROR;\r
   }\r
 \r
-  Status    = EFI_SUCCESS;\r
-  BlockDev  = &(PrivateData->BlockDevice[BlockDeviceNo]);\r
+  Status   = EFI_SUCCESS;\r
+  BlockDev = &(PrivateData->BlockDevice[BlockDeviceNo]);\r
 \r
   if (BufferSize > MultU64x32 (BlockDev->LastBlock - Lba + 1, BlockDev->BlockSize)) {\r
     return EFI_DEVICE_ERROR;\r
@@ -89,47 +80,45 @@ FatReadBlock (
     //\r
     if (BlockDev->BlockIo2 != NULL) {\r
       Status = BlockDev->BlockIo2->ReadBlocks (\r
-                                    (EFI_PEI_SERVICES **) GetPeiServicesTablePointer (),\r
-                                    BlockDev->BlockIo2,\r
+                                     (EFI_PEI_SERVICES **)GetPeiServicesTablePointer (),\r
+                                     BlockDev->BlockIo2,\r
+                                     BlockDev->PhysicalDevNo,\r
+                                     Lba,\r
+                                     BufferSize,\r
+                                     Buffer\r
+                                     );\r
+    } else {\r
+      Status = BlockDev->BlockIo->ReadBlocks (\r
+                                    (EFI_PEI_SERVICES **)GetPeiServicesTablePointer (),\r
+                                    BlockDev->BlockIo,\r
                                     BlockDev->PhysicalDevNo,\r
                                     Lba,\r
                                     BufferSize,\r
                                     Buffer\r
                                     );\r
-    } else {\r
-      Status = BlockDev->BlockIo->ReadBlocks (\r
-                                  (EFI_PEI_SERVICES **) GetPeiServicesTablePointer (),\r
-                                  BlockDev->BlockIo,\r
-                                  BlockDev->PhysicalDevNo,\r
-                                  Lba,\r
-                                  BufferSize,\r
-                                  Buffer\r
-                                  );\r
     }\r
-\r
   } else {\r
     Status = FatReadDisk (\r
-              PrivateData,\r
-              BlockDev->ParentDevNo,\r
-              BlockDev->StartingPos + MultU64x32 (Lba, BlockDev->BlockSize),\r
-              BufferSize,\r
-              Buffer\r
-              );\r
+               PrivateData,\r
+               BlockDev->ParentDevNo,\r
+               BlockDev->StartingPos + MultU64x32 (Lba, BlockDev->BlockSize),\r
+               BufferSize,\r
+               Buffer\r
+               );\r
   }\r
 \r
   return Status;\r
 }\r
 \r
-\r
 /**\r
   Find a cache block designated to specific Block device and Lba.\r
   If not found, invalidate an oldest one and use it. (LRU cache)\r
 \r
-  @param  PrivateData       the global memory map. \r
-  @param  BlockDeviceNo     the Block device. \r
-  @param  Lba               the Logical Block Address \r
-  @param  CachePtr          Ptr to the starting address of the memory holding the \r
-                            data; \r
+  @param  PrivateData       the global memory map.\r
+  @param  BlockDeviceNo     the Block device.\r
+  @param  Lba               the Logical Block Address\r
+  @param  CachePtr          Ptr to the starting address of the memory holding the\r
+                            data;\r
 \r
   @retval EFI_SUCCESS       The function completed successfully.\r
   @retval EFI_DEVICE_ERROR  Something error while accessing media.\r
@@ -156,15 +145,16 @@ FatGetCacheBlock (
   //\r
   for (Index = 0; Index < PEI_FAT_CACHE_SIZE; Index++) {\r
     CacheBuffer = &(PrivateData->CacheBuffer[Index]);\r
-    if (CacheBuffer->Valid && CacheBuffer->BlockDeviceNo == BlockDeviceNo && CacheBuffer->Lba == Lba) {\r
+    if (CacheBuffer->Valid && (CacheBuffer->BlockDeviceNo == BlockDeviceNo) && (CacheBuffer->Lba == Lba)) {\r
       break;\r
     }\r
   }\r
 \r
   if (Index < PEI_FAT_CACHE_SIZE) {\r
-    *CachePtr = (CHAR8 *) CacheBuffer->Buffer;\r
+    *CachePtr = (CHAR8 *)CacheBuffer->Buffer;\r
     return EFI_SUCCESS;\r
   }\r
+\r
   //\r
   // We have to find an invalid cache buffer\r
   //\r
@@ -173,55 +163,55 @@ FatGetCacheBlock (
       break;\r
     }\r
   }\r
+\r
   //\r
   // Use the cache buffer\r
   //\r
   if (Index == PEI_FAT_CACHE_SIZE) {\r
     Index = (Seed++) % PEI_FAT_CACHE_SIZE;\r
   }\r
-  \r
+\r
   //\r
-  // Current device ID should be less than maximum device ID. \r
+  // Current device ID should be less than maximum device ID.\r
   //\r
   if (BlockDeviceNo >= PEI_FAT_MAX_BLOCK_DEVICE) {\r
     return EFI_DEVICE_ERROR;\r
   }\r
 \r
-  CacheBuffer                 = &(PrivateData->CacheBuffer[Index]);\r
+  CacheBuffer = &(PrivateData->CacheBuffer[Index]);\r
 \r
-  CacheBuffer->BlockDeviceNo  = BlockDeviceNo;\r
-  CacheBuffer->Lba            = Lba;\r
-  CacheBuffer->Size           = PrivateData->BlockDevice[BlockDeviceNo].BlockSize;\r
+  CacheBuffer->BlockDeviceNo = BlockDeviceNo;\r
+  CacheBuffer->Lba           = Lba;\r
+  CacheBuffer->Size          = PrivateData->BlockDevice[BlockDeviceNo].BlockSize;\r
 \r
   //\r
   // Read in the data\r
   //\r
   Status = FatReadBlock (\r
-            PrivateData,\r
-            BlockDeviceNo,\r
-            Lba,\r
-            CacheBuffer->Size,\r
-            CacheBuffer->Buffer\r
-            );\r
+             PrivateData,\r
+             BlockDeviceNo,\r
+             Lba,\r
+             CacheBuffer->Size,\r
+             CacheBuffer->Buffer\r
+             );\r
   if (EFI_ERROR (Status)) {\r
     return EFI_DEVICE_ERROR;\r
   }\r
 \r
-  CacheBuffer->Valid  = TRUE;\r
-  *CachePtr           = (CHAR8 *) CacheBuffer->Buffer;\r
+  CacheBuffer->Valid = TRUE;\r
+  *CachePtr          = (CHAR8 *)CacheBuffer->Buffer;\r
 \r
   return Status;\r
 }\r
 \r
-\r
 /**\r
   Disk reading.\r
 \r
-  @param  PrivateData       the global memory map; \r
-  @param  BlockDeviceNo     the block device to read; \r
-  @param  StartingAddress   the starting address. \r
-  @param  Size              the amount of data to read. \r
-  @param  Buffer            the buffer holding the data \r
+  @param  PrivateData       the global memory map;\r
+  @param  BlockDeviceNo     the block device to read;\r
+  @param  StartingAddress   the starting address.\r
+  @param  Size              the amount of data to read.\r
+  @param  Buffer            the buffer holding the data\r
 \r
   @retval EFI_SUCCESS       The function completed successfully.\r
   @retval EFI_DEVICE_ERROR  Something error.\r
@@ -252,8 +242,8 @@ FatReadDisk (
   //\r
   // Read underrun\r
   //\r
-  Lba     = DivU64x32Remainder (StartingAddress, BlockSize, &Offset);\r
-  Status  = FatGetCacheBlock (PrivateData, BlockDeviceNo, Lba, &CachePtr);\r
+  Lba    = DivU64x32Remainder (StartingAddress, BlockSize, &Offset);\r
+  Status = FatGetCacheBlock (PrivateData, BlockDeviceNo, Lba, &CachePtr);\r
   if (EFI_ERROR (Status)) {\r
     return EFI_DEVICE_ERROR;\r
   }\r
@@ -265,17 +255,17 @@ FatReadDisk (
     return EFI_SUCCESS;\r
   }\r
 \r
-  Size -= Amount;\r
-  BufferPtr += Amount;\r
+  Size            -= Amount;\r
+  BufferPtr       += Amount;\r
   StartingAddress += Amount;\r
-  Lba += 1;\r
+  Lba             += 1;\r
 \r
   //\r
   // Read aligned parts\r
   //\r
   OverRunLba = Lba + DivU64x32Remainder (Size, BlockSize, &Offset);\r
 \r
-  Size -= Offset;\r
+  Size  -= Offset;\r
   Status = FatReadBlock (PrivateData, BlockDeviceNo, Lba, Size, BufferPtr);\r
   if (EFI_ERROR (Status)) {\r
     return EFI_DEVICE_ERROR;\r
@@ -298,7 +288,6 @@ FatReadDisk (
   return Status;\r
 }\r
 \r
-\r
 /**\r
   This version is different from the version in Unicode collation\r
   protocol in that this version strips off trailing blanks.\r
@@ -306,19 +295,19 @@ FatReadDisk (
   to a Null-terminated Unicode string.\r
   Here does not expand DBCS FAT chars.\r
 \r
-  @param  FatSize           The size of the string Fat in bytes. \r
-  @param  Fat               A pointer to a Null-terminated string that contains \r
-                            an 8.3 file name using an OEM character set. \r
-  @param  Str               A pointer to a Null-terminated Unicode string. The \r
-                            string must be allocated in advance to hold FatSize \r
+  @param  FatSize           The size of the string Fat in bytes.\r
+  @param  Fat               A pointer to a Null-terminated string that contains\r
+                            an 8.3 file name using an OEM character set.\r
+  @param  Str               A pointer to a Null-terminated Unicode string. The\r
+                            string must be allocated in advance to hold FatSize\r
                             Unicode characters\r
 \r
 **/\r
 VOID\r
 EngFatToStr (\r
-  IN UINTN                            FatSize,\r
-  IN CHAR8                            *Fat,\r
-  OUT CHAR16                          *Str\r
+  IN UINTN    FatSize,\r
+  IN CHAR8    *Fat,\r
+  OUT CHAR16  *Str\r
   )\r
 {\r
   CHAR16  *String;\r
@@ -331,21 +320,21 @@ EngFatToStr (
     if (*Fat == ' ') {\r
       break;\r
     }\r
-    *String = *Fat;\r
-    String += 1;\r
-    Fat += 1;\r
+\r
+    *String  = *Fat;\r
+    String  += 1;\r
+    Fat     += 1;\r
     FatSize -= 1;\r
   }\r
 \r
   *String = 0;\r
 }\r
 \r
-\r
 /**\r
   Performs a case-insensitive comparison of two Null-terminated Unicode strings.\r
 \r
-  @param  PrivateData       Global memory map for accessing global variables \r
-  @param  Str1              First string to perform case insensitive comparison. \r
+  @param  PrivateData       Global memory map for accessing global variables\r
+  @param  Str1              First string to perform case insensitive comparison.\r
   @param  Str2              Second string to perform case insensitive comparison.\r
 \r
 **/\r
@@ -372,5 +361,5 @@ EngStriColl (
     UpperS2 = ToUpper (*Str2);\r
   }\r
 \r
-  return (BOOLEAN) ((*Str2 != 0) ? FALSE : TRUE);\r
+  return (BOOLEAN)((*Str2 != 0) ? FALSE : TRUE);\r
 }\r