]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/CpuIoPei/CpuIoPei.c
UefiCpuPkg: Apply uncrustify changes
[mirror_edk2.git] / UefiCpuPkg / CpuIoPei / CpuIoPei.c
index 3c5c8a74b3a684f451dcf9bf7aba230a4c8bd874..0d0fe3d4bc96a6d713bbc6e8aa1caedda484f0ba 100644 (file)
@@ -1,14 +1,10 @@
 /** @file\r
   Produces the CPU I/O PPI.\r
 \r
-Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials                          \r
-are licensed and made available under the terms and conditions of the BSD License         \r
-which accompanies this 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
+Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>\r
+\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -47,16 +43,16 @@ EFI_PEI_CPU_IO_PPI  gCpuIoPpi = {
 //\r
 // PPI Descriptor used to install the CPU I/O PPI\r
 //\r
-EFI_PEI_PPI_DESCRIPTOR gPpiList = {\r
+EFI_PEI_PPI_DESCRIPTOR  gPpiList = {\r
   (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
   &gEfiPeiCpuIoPpiInstalledGuid,\r
   NULL\r
 };\r
-  \r
+\r
 //\r
 // Lookup table for increment values based on transfer widths\r
 //\r
-UINT8 mInStride[] = {\r
+UINT8  mInStride[] = {\r
   1, // EfiPeiCpuIoWidthUint8\r
   2, // EfiPeiCpuIoWidthUint16\r
   4, // EfiPeiCpuIoWidthUint32\r
@@ -74,7 +70,7 @@ UINT8 mInStride[] = {
 //\r
 // Lookup table for increment values based on transfer widths\r
 //\r
-UINT8 mOutStride[] = {\r
+UINT8  mOutStride[] = {\r
   1, // EfiPeiCpuIoWidthUint8\r
   2, // EfiPeiCpuIoWidthUint16\r
   4, // EfiPeiCpuIoWidthUint32\r
@@ -101,9 +97,9 @@ UINT8 mOutStride[] = {
   @retval EFI_SUCCESS            The parameters for this request pass the checks.\r
   @retval EFI_INVALID_PARAMETER  Width is invalid for this EFI system.\r
   @retval EFI_INVALID_PARAMETER  Buffer is NULL.\r
-  @retval EFI_UNSUPPORTED        The address range specified by Address, Width, \r
+  @retval EFI_UNSUPPORTED        The address range specified by Address, Width,\r
                                  and Count is not valid for this EFI system.\r
-                                 \r
+\r
 **/\r
 EFI_STATUS\r
 CpuIoCheckParameter (\r
@@ -135,31 +131,31 @@ CpuIoCheckParameter (
   // For FIFO type, the target address won't increase during the access,\r
   // so treat Count as 1\r
   //\r
-  if (Width >= EfiPeiCpuIoWidthFifoUint8 && Width <= EfiPeiCpuIoWidthFifoUint64) {\r
+  if ((Width >= EfiPeiCpuIoWidthFifoUint8) && (Width <= EfiPeiCpuIoWidthFifoUint64)) {\r
     Count = 1;\r
   }\r
 \r
   //\r
   // Check to see if Width is in the valid range for I/O Port operations\r
   //\r
-  Width = (EFI_PEI_CPU_IO_PPI_WIDTH) (Width & 0x03);\r
+  Width = (EFI_PEI_CPU_IO_PPI_WIDTH)(Width & 0x03);\r
   if (!MmioOperation && (Width == EfiPeiCpuIoWidthUint64)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  \r
+\r
   //\r
-  // Check to see if any address associated with this transfer exceeds the maximum \r
+  // Check to see if any address associated with this transfer exceeds the maximum\r
   // allowed address.  The maximum address implied by the parameters passed in is\r
   // Address + Size * Count.  If the following condition is met, then the transfer\r
   // is not supported.\r
   //\r
   //    Address + Size * Count > (MmioOperation ? MAX_ADDRESS : MAX_IO_PORT_ADDRESS) + 1\r
   //\r
-  // Since MAX_ADDRESS can be the maximum integer value supported by the CPU and Count \r
+  // Since MAX_ADDRESS can be the maximum integer value supported by the CPU and Count\r
   // can also be the maximum integer value supported by the CPU, this range\r
   // check must be adjusted to avoid all overflow conditions.\r
-  //   \r
-  // The following form of the range check is equivalent but assumes that \r
+  //\r
+  // The following form of the range check is equivalent but assumes that\r
   // MAX_ADDRESS and MAX_IO_PORT_ADDRESS are of the form (2^n - 1).\r
   //\r
   Limit = (MmioOperation ? MAX_ADDRESS : MAX_IO_PORT_ADDRESS);\r
@@ -167,16 +163,17 @@ CpuIoCheckParameter (
     if (Address > Limit) {\r
       return EFI_UNSUPPORTED;\r
     }\r
-  } else {  \r
+  } else {\r
     MaxCount = RShiftU64 (Limit, Width);\r
     if (MaxCount < (Count - 1)) {\r
       return EFI_UNSUPPORTED;\r
     }\r
+\r
     if (Address > LShiftU64 (MaxCount - Count + 1, Width)) {\r
       return EFI_UNSUPPORTED;\r
     }\r
   }\r
-  \r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -194,7 +191,7 @@ CpuIoCheckParameter (
   @retval EFI_SUCCESS            The function completed successfully.\r
   @retval EFI_INVALID_PARAMETER  Width is invalid for this EFI system.\r
   @retval EFI_INVALID_PARAMETER  Buffer is NULL.\r
-  @retval EFI_UNSUPPORTED        The address range specified by Address, Width, \r
+  @retval EFI_UNSUPPORTED        The address range specified by Address, Width,\r
                                  and Count is not valid for this EFI system.\r
 \r
 **/\r
@@ -224,10 +221,10 @@ CpuMemoryServiceRead (
   //\r
   // Select loop based on the width of the transfer\r
   //\r
-  InStride = mInStride[Width];\r
-  OutStride = mOutStride[Width];\r
-  OperationWidth = (EFI_PEI_CPU_IO_PPI_WIDTH) (Width & 0x03);\r
-  Aligned = (BOOLEAN)(((UINTN)Buffer & (mInStride[OperationWidth] - 1)) == 0x00);\r
+  InStride       = mInStride[Width];\r
+  OutStride      = mOutStride[Width];\r
+  OperationWidth = (EFI_PEI_CPU_IO_PPI_WIDTH)(Width & 0x03);\r
+  Aligned        = (BOOLEAN)(((UINTN)Buffer & (mInStride[OperationWidth] - 1)) == 0x00);\r
   for (Uint8Buffer = Buffer; Count > 0; Address += InStride, Uint8Buffer += OutStride, Count--) {\r
     if (OperationWidth == EfiPeiCpuIoWidthUint8) {\r
       *Uint8Buffer = MmioRead8 ((UINTN)Address);\r
@@ -251,6 +248,7 @@ CpuMemoryServiceRead (
       }\r
     }\r
   }\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -268,7 +266,7 @@ CpuMemoryServiceRead (
   @retval EFI_SUCCESS            The function completed successfully.\r
   @retval EFI_INVALID_PARAMETER  Width is invalid for this EFI system.\r
   @retval EFI_INVALID_PARAMETER  Buffer is NULL.\r
-  @retval EFI_UNSUPPORTED        The address range specified by Address, Width, \r
+  @retval EFI_UNSUPPORTED        The address range specified by Address, Width,\r
                                  and Count is not valid for this EFI system.\r
 \r
 **/\r
@@ -298,10 +296,10 @@ CpuMemoryServiceWrite (
   //\r
   // Select loop based on the width of the transfer\r
   //\r
-  InStride = mInStride[Width];\r
-  OutStride = mOutStride[Width];\r
-  OperationWidth = (EFI_PEI_CPU_IO_PPI_WIDTH) (Width & 0x03);\r
-  Aligned = (BOOLEAN)(((UINTN)Buffer & (mInStride[OperationWidth] - 1)) == 0x00);\r
+  InStride       = mInStride[Width];\r
+  OutStride      = mOutStride[Width];\r
+  OperationWidth = (EFI_PEI_CPU_IO_PPI_WIDTH)(Width & 0x03);\r
+  Aligned        = (BOOLEAN)(((UINTN)Buffer & (mInStride[OperationWidth] - 1)) == 0x00);\r
   for (Uint8Buffer = Buffer; Count > 0; Address += InStride, Uint8Buffer += OutStride, Count--) {\r
     if (OperationWidth == EfiPeiCpuIoWidthUint8) {\r
       MmioWrite8 ((UINTN)Address, *Uint8Buffer);\r
@@ -325,6 +323,7 @@ CpuMemoryServiceWrite (
       }\r
     }\r
   }\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -342,7 +341,7 @@ CpuMemoryServiceWrite (
   @retval EFI_SUCCESS            The function completed successfully.\r
   @retval EFI_INVALID_PARAMETER  Width is invalid for this EFI system.\r
   @retval EFI_INVALID_PARAMETER  Buffer is NULL.\r
-  @retval EFI_UNSUPPORTED        The address range specified by Address, Width, \r
+  @retval EFI_UNSUPPORTED        The address range specified by Address, Width,\r
                                  and Count is not valid for this EFI system.\r
 \r
 **/\r
@@ -372,9 +371,34 @@ CpuIoServiceRead (
   //\r
   // Select loop based on the width of the transfer\r
   //\r
-  InStride = mInStride[Width];\r
-  OutStride = mOutStride[Width];\r
-  OperationWidth = (EFI_PEI_CPU_IO_PPI_WIDTH) (Width & 0x03);\r
+  InStride       = mInStride[Width];\r
+  OutStride      = mOutStride[Width];\r
+  OperationWidth = (EFI_PEI_CPU_IO_PPI_WIDTH)(Width & 0x03);\r
+\r
+  //\r
+  // Fifo operations supported for (mInStride[Width] == 0)\r
+  //\r
+  if (InStride == 0) {\r
+    switch (OperationWidth) {\r
+      case EfiPeiCpuIoWidthUint8:\r
+        IoReadFifo8 ((UINTN)Address, Count, Buffer);\r
+        return EFI_SUCCESS;\r
+      case EfiPeiCpuIoWidthUint16:\r
+        IoReadFifo16 ((UINTN)Address, Count, Buffer);\r
+        return EFI_SUCCESS;\r
+      case EfiPeiCpuIoWidthUint32:\r
+        IoReadFifo32 ((UINTN)Address, Count, Buffer);\r
+        return EFI_SUCCESS;\r
+      default:\r
+        //\r
+        // The CpuIoCheckParameter call above will ensure that this\r
+        // path is not taken.\r
+        //\r
+        ASSERT (FALSE);\r
+        break;\r
+    }\r
+  }\r
+\r
   Aligned = (BOOLEAN)(((UINTN)Buffer & (mInStride[OperationWidth] - 1)) == 0x00);\r
   for (Uint8Buffer = Buffer; Count > 0; Address += InStride, Uint8Buffer += OutStride, Count--) {\r
     if (OperationWidth == EfiPeiCpuIoWidthUint8) {\r
@@ -411,7 +435,7 @@ CpuIoServiceRead (
   @retval EFI_SUCCESS            The function completed successfully.\r
   @retval EFI_INVALID_PARAMETER  Width is invalid for this EFI system.\r
   @retval EFI_INVALID_PARAMETER  Buffer is NULL.\r
-  @retval EFI_UNSUPPORTED        The address range specified by Address, Width, \r
+  @retval EFI_UNSUPPORTED        The address range specified by Address, Width,\r
                                  and Count is not valid for this EFI system.\r
 \r
 **/\r
@@ -444,9 +468,34 @@ CpuIoServiceWrite (
   //\r
   // Select loop based on the width of the transfer\r
   //\r
-  InStride = mInStride[Width];\r
-  OutStride = mOutStride[Width];\r
-  OperationWidth = (EFI_PEI_CPU_IO_PPI_WIDTH) (Width & 0x03);\r
+  InStride       = mInStride[Width];\r
+  OutStride      = mOutStride[Width];\r
+  OperationWidth = (EFI_PEI_CPU_IO_PPI_WIDTH)(Width & 0x03);\r
+\r
+  //\r
+  // Fifo operations supported for (mInStride[Width] == 0)\r
+  //\r
+  if (InStride == 0) {\r
+    switch (OperationWidth) {\r
+      case EfiPeiCpuIoWidthUint8:\r
+        IoWriteFifo8 ((UINTN)Address, Count, Buffer);\r
+        return EFI_SUCCESS;\r
+      case EfiPeiCpuIoWidthUint16:\r
+        IoWriteFifo16 ((UINTN)Address, Count, Buffer);\r
+        return EFI_SUCCESS;\r
+      case EfiPeiCpuIoWidthUint32:\r
+        IoWriteFifo32 ((UINTN)Address, Count, Buffer);\r
+        return EFI_SUCCESS;\r
+      default:\r
+        //\r
+        // The CpuIoCheckParameter call above will ensure that this\r
+        // path is not taken.\r
+        //\r
+        ASSERT (FALSE);\r
+        break;\r
+    }\r
+  }\r
+\r
   Aligned = (BOOLEAN)(((UINTN)Buffer & (mInStride[OperationWidth] - 1)) == 0x00);\r
   for (Uint8Buffer = (UINT8 *)Buffer; Count > 0; Address += InStride, Uint8Buffer += OutStride, Count--) {\r
     if (OperationWidth == EfiPeiCpuIoWidthUint8) {\r
@@ -465,14 +514,14 @@ CpuIoServiceWrite (
       }\r
     }\r
   }\r
-  \r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
   8-bit I/O read operations.\r
 \r
-  @param[in] PeiServices  An indirect pointer to the PEI Services Table published \r
+  @param[in] PeiServices  An indirect pointer to the PEI Services Table published\r
                           by the PEI Foundation.\r
   @param[in] This         Pointer to local data for the interface.\r
   @param[in] Address      The physical address of the access.\r
@@ -493,7 +542,7 @@ CpuIoRead8 (
 /**\r
   16-bit I/O read operations.\r
 \r
-  @param[in] PeiServices  An indirect pointer to the PEI Services Table published \r
+  @param[in] PeiServices  An indirect pointer to the PEI Services Table published\r
                           by the PEI Foundation.\r
   @param[in] This         Pointer to local data for the interface.\r
   @param[in] Address      The physical address of the access.\r
@@ -515,7 +564,7 @@ CpuIoRead16 (
 /**\r
   32-bit I/O read operations.\r
 \r
-  @param[in] PeiServices  An indirect pointer to the PEI Services Table published \r
+  @param[in] PeiServices  An indirect pointer to the PEI Services Table published\r
                           by the PEI Foundation.\r
   @param[in] This         Pointer to local data for the interface.\r
   @param[in] Address      The physical address of the access.\r
@@ -526,9 +575,9 @@ CpuIoRead16 (
 UINT32\r
 EFIAPI\r
 CpuIoRead32 (\r
-  IN CONST EFI_PEI_SERVICES     **PeiServices,\r
-  IN CONST EFI_PEI_CPU_IO_PPI   *This,\r
-  IN UINT64                     Address\r
+  IN CONST EFI_PEI_SERVICES    **PeiServices,\r
+  IN CONST EFI_PEI_CPU_IO_PPI  *This,\r
+  IN UINT64                    Address\r
   )\r
 {\r
   return IoRead32 ((UINTN)Address);\r
@@ -537,7 +586,7 @@ CpuIoRead32 (
 /**\r
   64-bit I/O read operations.\r
 \r
-  @param[in] PeiServices  An indirect pointer to the PEI Services Table published \r
+  @param[in] PeiServices  An indirect pointer to the PEI Services Table published\r
                           by the PEI Foundation.\r
   @param[in] This         Pointer to local data for the interface.\r
   @param[in] Address      The physical address of the access.\r
@@ -559,7 +608,7 @@ CpuIoRead64 (
 /**\r
   8-bit I/O write operations.\r
 \r
-  @param[in] PeiServices  An indirect pointer to the PEI Services Table published \r
+  @param[in] PeiServices  An indirect pointer to the PEI Services Table published\r
                           by the PEI Foundation.\r
   @param[in] This         Pointer to local data for the interface.\r
   @param[in] Address      The physical address of the access.\r
@@ -581,7 +630,7 @@ CpuIoWrite8 (
 /**\r
   16-bit I/O write operations.\r
 \r
-  @param[in] PeiServices  An indirect pointer to the PEI Services Table published \r
+  @param[in] PeiServices  An indirect pointer to the PEI Services Table published\r
                           by the PEI Foundation.\r
   @param[in] This         Pointer to local data for the interface.\r
   @param[in] Address      The physical address of the access.\r
@@ -603,7 +652,7 @@ CpuIoWrite16 (
 /**\r
   32-bit I/O write operations.\r
 \r
-  @param[in] PeiServices  An indirect pointer to the PEI Services Table published \r
+  @param[in] PeiServices  An indirect pointer to the PEI Services Table published\r
                           by the PEI Foundation.\r
   @param[in] This         Pointer to local data for the interface.\r
   @param[in] Address      The physical address of the access.\r
@@ -625,7 +674,7 @@ CpuIoWrite32 (
 /**\r
   64-bit I/O write operations.\r
 \r
-  @param[in] PeiServices  An indirect pointer to the PEI Services Table published \r
+  @param[in] PeiServices  An indirect pointer to the PEI Services Table published\r
                           by the PEI Foundation.\r
   @param[in] This         Pointer to local data for the interface.\r
   @param[in] Address      The physical address of the access.\r
@@ -647,7 +696,7 @@ CpuIoWrite64 (
 /**\r
   8-bit memory read operations.\r
 \r
-  @param[in] PeiServices  An indirect pointer to the PEI Services Table published \r
+  @param[in] PeiServices  An indirect pointer to the PEI Services Table published\r
                           by the PEI Foundation.\r
   @param[in] This         Pointer to local data for the interface.\r
   @param[in] Address      The physical address of the access.\r
@@ -669,7 +718,7 @@ CpuMemRead8 (
 /**\r
   16-bit memory read operations.\r
 \r
-  @param[in] PeiServices  An indirect pointer to the PEI Services Table published \r
+  @param[in] PeiServices  An indirect pointer to the PEI Services Table published\r
                           by the PEI Foundation.\r
   @param[in] This         Pointer to local data for the interface.\r
   @param[in] Address      The physical address of the access.\r
@@ -691,7 +740,7 @@ CpuMemRead16 (
 /**\r
   32-bit memory read operations.\r
 \r
-  @param[in] PeiServices  An indirect pointer to the PEI Services Table published \r
+  @param[in] PeiServices  An indirect pointer to the PEI Services Table published\r
                           by the PEI Foundation.\r
   @param[in] This         Pointer to local data for the interface.\r
   @param[in] Address      The physical address of the access.\r
@@ -713,7 +762,7 @@ CpuMemRead32 (
 /**\r
   64-bit memory read operations.\r
 \r
-  @param[in] PeiServices  An indirect pointer to the PEI Services Table published \r
+  @param[in] PeiServices  An indirect pointer to the PEI Services Table published\r
                           by the PEI Foundation.\r
   @param[in] This         Pointer to local data for the interface.\r
   @param[in] Address      The physical address of the access.\r
@@ -735,7 +784,7 @@ CpuMemRead64 (
 /**\r
   8-bit memory write operations.\r
 \r
-  @param[in] PeiServices  An indirect pointer to the PEI Services Table published \r
+  @param[in] PeiServices  An indirect pointer to the PEI Services Table published\r
                           by the PEI Foundation.\r
   @param[in] This         Pointer to local data for the interface.\r
   @param[in] Address      The physical address of the access.\r
@@ -757,7 +806,7 @@ CpuMemWrite8 (
 /**\r
   16-bit memory write operations.\r
 \r
-  @param[in] PeiServices  An indirect pointer to the PEI Services Table published \r
+  @param[in] PeiServices  An indirect pointer to the PEI Services Table published\r
                           by the PEI Foundation.\r
   @param[in] This         Pointer to local data for the interface.\r
   @param[in] Address      The physical address of the access.\r
@@ -779,7 +828,7 @@ CpuMemWrite16 (
 /**\r
   32-bit memory write operations.\r
 \r
-  @param[in] PeiServices  An indirect pointer to the PEI Services Table published \r
+  @param[in] PeiServices  An indirect pointer to the PEI Services Table published\r
                           by the PEI Foundation.\r
   @param[in] This         Pointer to local data for the interface.\r
   @param[in] Address      The physical address of the access.\r
@@ -801,7 +850,7 @@ CpuMemWrite32 (
 /**\r
   64-bit memory write operations.\r
 \r
-  @param[in] PeiServices  An indirect pointer to the PEI Services Table published \r
+  @param[in] PeiServices  An indirect pointer to the PEI Services Table published\r
                           by the PEI Foundation.\r
   @param[in] This         Pointer to local data for the interface.\r
   @param[in] Address      The physical address of the access.\r
@@ -826,7 +875,7 @@ CpuMemWrite64 (
   This function is the Entry point of the CPU I/O PEIM which installs CpuIoPpi.\r
 \r
   @param[in]  FileHandle   Pointer to image file handle.\r
-  @param[in]  PeiServices  Pointer to PEI Services Table   \r
+  @param[in]  PeiServices  Pointer to PEI Services Table\r
 \r
   @retval EFI_SUCCESS  CPU I/O PPI successfully installed\r
 \r
@@ -844,21 +893,21 @@ CpuIoInitialize (
   // Register so it will be automatically shadowed to memory\r
   //\r
   Status = PeiServicesRegisterForShadow (FileHandle);\r
-  \r
+\r
   //\r
   // Make CpuIo pointer in PeiService table point to gCpuIoPpi\r
   //\r
   (*((EFI_PEI_SERVICES **)PeiServices))->CpuIo = &gCpuIoPpi;\r
-  \r
+\r
   if (Status == EFI_ALREADY_STARTED) {\r
     //\r
     // Shadow completed and running from memory\r
     //\r
-    DEBUG ((EFI_D_INFO, "CpuIO PPI has been loaded into memory.  Reinstalled PPI=0x%x\n", &gCpuIoPpi));\r
+    DEBUG ((DEBUG_INFO, "CpuIO PPI has been loaded into memory.  Reinstalled PPI=0x%x\n", &gCpuIoPpi));\r
   } else {\r
     Status = PeiServicesInstallPpi (&gPpiList);\r
     ASSERT_EFI_ERROR (Status);\r
   }\r
-  \r
+\r
   return EFI_SUCCESS;\r
 }\r