]> git.proxmox.com Git - mirror_edk2.git/blobdiff - DuetPkg/PciBusNoEnumerationDxe/PciIo.c
BaseTools: Update BPDG to support L'' and '' format as VPD Pcd Value
[mirror_edk2.git] / DuetPkg / PciBusNoEnumerationDxe / PciIo.c
index e5485dcedc46edd1998946e6b7cf8abe11aa2eb6..9f473737435e539a2edd7cbae63928bed514ed86 100644 (file)
@@ -1,7 +1,7 @@
 /*++\r
 \r
-Copyright (c) 2005 - 2007, Intel Corporation                                                         \r
-All rights reserved. This program and the accompanying materials                          \r
+Copyright (c) 2005 - 2014, 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
@@ -21,7 +21,7 @@ Revision History
 \r
 --*/\r
 \r
-#include "Pcibus.h"\r
+#include "PciBus.h"\r
 \r
 //\r
 // PCI I/O Support Function Prototypes\r
@@ -267,7 +267,7 @@ PciIoSetBarAttributes(
 //\r
 // Pci Io Protocol Interface\r
 //\r
-static EFI_PCI_IO_PROTOCOL  PciIoInterface = {\r
+EFI_PCI_IO_PROTOCOL  PciIoInterface = {\r
   PciIoPollMem,\r
   PciIoPollIo,\r
   {\r
@@ -343,7 +343,7 @@ Returns:
 \r
 --*/\r
 {\r
-  if (Width < 0 || Width >= EfiPciIoWidthMaximum) {\r
+  if ((UINT32)Width >= EfiPciIoWidthMaximum) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -366,11 +366,11 @@ Returns:
   // If Width is EfiPciIoWidthFifoUintX then convert to EfiPciIoWidthUintX\r
   // If Width is EfiPciIoWidthFillUintX then convert to EfiPciIoWidthUintX\r
   //\r
-  if (Width >= EfiPciWidthFifoUint8 && Width <= EfiPciWidthFifoUint64) {\r
+  if (Width >= EfiPciIoWidthFifoUint8 && Width <= EfiPciIoWidthFifoUint64) {\r
     Count = 1;\r
   }\r
 \r
-  Width &= 0x03;\r
+  Width = (EFI_PCI_IO_PROTOCOL_WIDTH) (Width & 0x03);\r
 \r
   if ((*Offset + Count * ((UINTN)1 << Width)) - 1 >= PciIoDevice->PciBar[BarIndex].Length) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -404,7 +404,7 @@ Returns:
 {\r
   UINT64  ExtendOffset;\r
 \r
-  if (Width < 0 || Width >= EfiPciIoWidthMaximum) {\r
+  if ((UINT32)Width >= EfiPciIoWidthMaximum) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -412,7 +412,7 @@ Returns:
   // If Width is EfiPciIoWidthFifoUintX then convert to EfiPciIoWidthUintX\r
   // If Width is EfiPciIoWidthFillUintX then convert to EfiPciIoWidthUintX\r
   //\r
-  Width &= 0x03;\r
+  Width = (EFI_PCI_IO_PROTOCOL_WIDTH) (Width & 0x03);\r
 \r
   if (PciIoDevice->IsPciExp) {\r
     if ((*Offset + Count * ((UINTN)1 << Width)) - 1 >= PCI_EXP_MAX_CONFIG_OFFSET) {\r
@@ -465,7 +465,7 @@ Returns:
 \r
   PciIoDevice = PCI_IO_DEVICE_FROM_PCI_IO_THIS (This);\r
 \r
-  if (Width < 0 || Width >= EfiPciIoWidthMaximum) {\r
+  if ((UINT32)Width >= EfiPciIoWidthMaximum) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -521,7 +521,7 @@ Returns:
 \r
   PciIoDevice = PCI_IO_DEVICE_FROM_PCI_IO_THIS (This);\r
 \r
-  if (Width < 0 || Width > EfiPciIoWidthUint64) {\r
+  if ((UINT32)Width > EfiPciIoWidthUint64) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -571,12 +571,12 @@ Returns:
   PCI_IO_DEVICE *PciIoDevice;\r
 \r
   if (Buffer == NULL){\r
-         return EFI_INVALID_PARAMETER;\r
+    return EFI_INVALID_PARAMETER;\r
   }\r
 \r
   PciIoDevice = PCI_IO_DEVICE_FROM_PCI_IO_THIS (This);\r
 \r
-  if (Width < 0 || Width >= EfiPciIoWidthMaximum) {\r
+  if ((UINT32)Width >= EfiPciIoWidthMaximum) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -624,12 +624,12 @@ Returns:
   PCI_IO_DEVICE *PciIoDevice;\r
 \r
   if (Buffer == NULL){\r
-         return EFI_INVALID_PARAMETER;\r
+    return EFI_INVALID_PARAMETER;\r
   }\r
   \r
   PciIoDevice = PCI_IO_DEVICE_FROM_PCI_IO_THIS (This);\r
 \r
-  if (Width < 0 || Width >= EfiPciIoWidthMaximum) {\r
+  if ((UINT32)Width >= EfiPciIoWidthMaximum) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -677,12 +677,12 @@ Returns:
   PCI_IO_DEVICE *PciIoDevice;\r
 \r
   if (Buffer == NULL){\r
-         return EFI_INVALID_PARAMETER;\r
+    return EFI_INVALID_PARAMETER;\r
   }\r
 \r
   PciIoDevice = PCI_IO_DEVICE_FROM_PCI_IO_THIS (This);\r
 \r
-  if (Width < 0 || Width >= EfiPciIoWidthMaximum) {\r
+  if ((UINT32)Width >= EfiPciIoWidthMaximum) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -730,12 +730,12 @@ Returns:
   PCI_IO_DEVICE *PciIoDevice;\r
 \r
   if (Buffer == NULL){\r
-         return EFI_INVALID_PARAMETER;\r
+    return EFI_INVALID_PARAMETER;\r
   }\r
 \r
   PciIoDevice = PCI_IO_DEVICE_FROM_PCI_IO_THIS (This);\r
 \r
-  if (Width < 0 || Width >= EfiPciIoWidthMaximum) {\r
+  if ((UINT32)Width >= EfiPciIoWidthMaximum) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -877,7 +877,7 @@ Returns:
 \r
   PciIoDevice = PCI_IO_DEVICE_FROM_PCI_IO_THIS (This);\r
 \r
-  if (Width < 0 || Width >= EfiPciIoWidthMaximum) {\r
+  if ((UINT32)Width >= EfiPciIoWidthMaximum) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -942,7 +942,7 @@ Returns:
 \r
   PciIoDevice = PCI_IO_DEVICE_FROM_PCI_IO_THIS (This);\r
 \r
-  if (Operation < 0 || Operation >= EfiPciIoOperationMaximum) {\r
+  if ((UINT32)Operation >= EfiPciIoOperationMaximum) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -951,7 +951,7 @@ Returns:
   }\r
 \r
   if (PciIoDevice->Attributes & EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE) {\r
-    Operation = Operation + EfiPciOperationBusMasterRead64;\r
+    Operation = (EFI_PCI_IO_PROTOCOL_OPERATION) (Operation + EfiPciOperationBusMasterRead64);\r
   }\r
 \r
   Status = PciIoDevice->PciRootBridgeIo->Map (\r
@@ -1074,7 +1074,7 @@ Returns:
   PCI_IO_DEVICE *PciIoDevice;\r
   \r
   if( HostAddress == NULL ){\r
-        return EFI_INVALID_PARAMETER;\r
+     return EFI_INVALID_PARAMETER;\r
   } \r
 \r
   PciIoDevice = PCI_IO_DEVICE_FROM_PCI_IO_THIS (This);\r
@@ -1282,21 +1282,21 @@ Returns:
     return EFI_SUCCESS;\r
 \r
   case EfiPciIoAttributeOperationEnable:\r
-         if(Attributes & ~(PciIoDevice->Supports)) {\r
-                 return EFI_UNSUPPORTED;\r
-         }\r
-         NewAttributes = PciIoDevice->Attributes | Attributes;\r
+    if(Attributes & ~(PciIoDevice->Supports)) {\r
+      return EFI_UNSUPPORTED;\r
+    }\r
+    NewAttributes = PciIoDevice->Attributes | Attributes;\r
     break;\r
   case EfiPciIoAttributeOperationDisable:\r
-         if(Attributes & ~(PciIoDevice->Supports)) {\r
-                 return EFI_UNSUPPORTED;\r
-         }\r
+    if(Attributes & ~(PciIoDevice->Supports)) {\r
+      return EFI_UNSUPPORTED;\r
+    }\r
     NewAttributes = PciIoDevice->Attributes & (~Attributes);\r
     break;\r
   case EfiPciIoAttributeOperationSet:\r
-         if(Attributes & ~(PciIoDevice->Supports)) {\r
-                 return EFI_UNSUPPORTED;\r
-         }\r
+    if(Attributes & ~(PciIoDevice->Supports)) {\r
+      return EFI_UNSUPPORTED;\r
+    }\r
     NewAttributes = Attributes;\r
     break;\r
   default:\r
@@ -1600,14 +1600,10 @@ Returns:
 \r
 --*/\r
 {\r
-\r
   UINT8                             *Configuration;\r
-  UINT8                             NumConfig;\r
   PCI_IO_DEVICE                     *PciIoDevice;\r
-  EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Ptr;\r
-  EFI_ACPI_END_TAG_DESCRIPTOR       *PtrEnd;\r
-\r
-  NumConfig   = 0;\r
+  EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *AddressSpace;\r
+  EFI_ACPI_END_TAG_DESCRIPTOR       *End;\r
 \r
   PciIoDevice = PCI_IO_DEVICE_FROM_PCI_IO_THIS (This);\r
 \r
@@ -1615,7 +1611,7 @@ Returns:
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  if (BarIndex >= PCI_MAX_BAR) {\r
+  if ((BarIndex >= PCI_MAX_BAR) || (PciIoDevice->PciBar[BarIndex].BarType == PciBarTypeUnknown)) {\r
     return EFI_UNSUPPORTED;\r
   }\r
 \r
@@ -1628,104 +1624,93 @@ Returns:
   }\r
 \r
   if (Resources != NULL) {\r
-\r
-    if (PciIoDevice->PciBar[BarIndex].BarType != PciBarTypeUnknown) {\r
-      NumConfig = 1;\r
-    }\r
-\r
-    Configuration = AllocatePool (sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) * NumConfig + sizeof (EFI_ACPI_END_TAG_DESCRIPTOR));\r
+    Configuration = AllocateZeroPool (sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) + sizeof (EFI_ACPI_END_TAG_DESCRIPTOR));\r
     if (Configuration == NULL) {\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
 \r
-    ZeroMem (\r
-      Configuration,\r
-      sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) * NumConfig + sizeof (EFI_ACPI_END_TAG_DESCRIPTOR)\r
-      );\r
+    AddressSpace = (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *) Configuration;\r
 \r
-    Ptr = (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *) Configuration;\r
+    AddressSpace->Desc         = ACPI_ADDRESS_SPACE_DESCRIPTOR;\r
+    AddressSpace->Len          = (UINT16) (sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) - 3);\r
 \r
-    if (NumConfig == 1) {\r
-      Ptr->Desc         = ACPI_ADDRESS_SPACE_DESCRIPTOR;\r
-      Ptr->Len          = sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) - 3;\r
+    AddressSpace->AddrRangeMin = PciIoDevice->PciBar[BarIndex].BaseAddress;\r
+    AddressSpace->AddrLen      = PciIoDevice->PciBar[BarIndex].Length;\r
+    AddressSpace->AddrRangeMax = PciIoDevice->PciBar[BarIndex].Alignment;\r
 \r
-      Ptr->AddrRangeMin = PciIoDevice->PciBar[BarIndex].BaseAddress;\r
-      Ptr->AddrLen      = PciIoDevice->PciBar[BarIndex].Length;\r
-      Ptr->AddrRangeMax = PciIoDevice->PciBar[BarIndex].Alignment;\r
-\r
-      switch (PciIoDevice->PciBar[BarIndex].BarType) {\r
-      case PciBarTypeIo16:\r
-      case PciBarTypeIo32:\r
-        //\r
-        // Io\r
-        //\r
-        Ptr->ResType = ACPI_ADDRESS_SPACE_TYPE_IO;\r
-        break;\r
+    switch (PciIoDevice->PciBar[BarIndex].BarType) {\r
+    case PciBarTypeIo16:\r
+    case PciBarTypeIo32:\r
+      //\r
+      // Io\r
+      //\r
+      AddressSpace->ResType = ACPI_ADDRESS_SPACE_TYPE_IO;\r
+      break;\r
 \r
-      case PciBarTypeMem32:\r
-        //\r
-        // Mem\r
-        //\r
-        Ptr->ResType = ACPI_ADDRESS_SPACE_TYPE_MEM;\r
-        //\r
-        // 32 bit\r
-        //\r
-        Ptr->AddrSpaceGranularity = 32;\r
-        break;\r
+    case PciBarTypeMem32:\r
+      //\r
+      // Mem\r
+      //\r
+      AddressSpace->ResType = ACPI_ADDRESS_SPACE_TYPE_MEM;\r
+      //\r
+      // 32 bit\r
+      //\r
+      AddressSpace->AddrSpaceGranularity = 32;\r
+      break;\r
 \r
-      case PciBarTypePMem32:\r
-        //\r
-        // Mem\r
-        //\r
-        Ptr->ResType = ACPI_ADDRESS_SPACE_TYPE_MEM;\r
-        //\r
-        // prefechable\r
-        //\r
-        Ptr->SpecificFlag = 0x6;\r
-        //\r
-        // 32 bit\r
-        //\r
-        Ptr->AddrSpaceGranularity = 32;\r
-        break;\r
+    case PciBarTypePMem32:\r
+      //\r
+      // Mem\r
+      //\r
+      AddressSpace->ResType = ACPI_ADDRESS_SPACE_TYPE_MEM;\r
+      //\r
+      // prefechable\r
+      //\r
+      AddressSpace->SpecificFlag = 0x6;\r
+      //\r
+      // 32 bit\r
+      //\r
+      AddressSpace->AddrSpaceGranularity = 32;\r
+      break;\r
 \r
-      case PciBarTypeMem64:\r
-        //\r
-        // Mem\r
-        //\r
-        Ptr->ResType = ACPI_ADDRESS_SPACE_TYPE_MEM;\r
-        //\r
-        // 64 bit\r
-        //\r
-        Ptr->AddrSpaceGranularity = 64;\r
-        break;\r
+    case PciBarTypeMem64:\r
+      //\r
+      // Mem\r
+      //\r
+      AddressSpace->ResType = ACPI_ADDRESS_SPACE_TYPE_MEM;\r
+      //\r
+      // 64 bit\r
+      //\r
+      AddressSpace->AddrSpaceGranularity = 64;\r
+      break;\r
 \r
-      case PciBarTypePMem64:\r
-        //\r
-        // Mem\r
-        //\r
-        Ptr->ResType = ACPI_ADDRESS_SPACE_TYPE_MEM;\r
-        //\r
-        // prefechable\r
-        //\r
-        Ptr->SpecificFlag = 0x6;\r
-        //\r
-        // 64 bit\r
-        //\r
-        Ptr->AddrSpaceGranularity = 64;\r
-        break;\r
-      }\r
+    case PciBarTypePMem64:\r
+      //\r
+      // Mem\r
+      //\r
+      AddressSpace->ResType = ACPI_ADDRESS_SPACE_TYPE_MEM;\r
+      //\r
+      // prefechable\r
+      //\r
+      AddressSpace->SpecificFlag = 0x6;\r
+      //\r
+      // 64 bit\r
+      //\r
+      AddressSpace->AddrSpaceGranularity = 64;\r
+      break;\r
 \r
-      Ptr = (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *) ((UINT8 *) Ptr + sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR));\r
+    default:\r
+      break;\r
     }\r
-    \r
+\r
     //\r
     // put the checksum\r
     //\r
-    PtrEnd            = (EFI_ACPI_END_TAG_DESCRIPTOR *) ((UINT8 *) Ptr);\r
-    PtrEnd->Desc      = ACPI_END_TAG_DESCRIPTOR;\r
-    PtrEnd->Checksum  = 0;\r
+    End           = (EFI_ACPI_END_TAG_DESCRIPTOR *) (AddressSpace + 1);\r
+    End->Desc     = ACPI_END_TAG_DESCRIPTOR;\r
+    End->Checksum = 0;\r
 \r
-    *Resources        = Configuration;\r
+    *Resources    = Configuration;\r
   }\r
 \r
   return EFI_SUCCESS;\r
@@ -1863,5 +1848,5 @@ Returns:
     return TRUE;\r
   }\r
 \r
-  return (PciDeviceExisted (PciDevice1->Parent, PciDevice2)|| PciDeviceExisted (PciDevice2->Parent, PciDevice1));\r
+  return (BOOLEAN) ((PciDeviceExisted (PciDevice1->Parent, PciDevice2)|| PciDeviceExisted (PciDevice2->Parent, PciDevice1)));\r
 }\r