]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c
MdeModulePkg/PciBus: Correct typos
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / PciBusDxe / PciEnumeratorSupport.c
index 80f2885005df39e85cdc7d66bec4df43f6dc8eee..9b59e85bcd7a13e0bd41e0d9010df83b272e61ae 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   PCI emumeration support functions implementation for PCI Bus module.\r
 \r
-Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r
 (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
@@ -17,6 +17,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 extern CHAR16  *mBarTypeStr[];\r
 \r
+#define OLD_ALIGN   0xFFFFFFFFFFFFFFFFULL\r
+#define EVEN_ALIGN  0xFFFFFFFFFFFFFFFEULL\r
+#define SQUAD_ALIGN 0xFFFFFFFFFFFFFFFDULL\r
+#define DQUAD_ALIGN 0xFFFFFFFFFFFFFFFCULL\r
+\r
 /**\r
   This routine is used to check whether the pci device is present.\r
 \r
@@ -83,7 +88,7 @@ PciDevicePresent (
   root bridge will then be created.\r
 \r
   @param Bridge         Parent bridge instance.\r
-  @param StartBusNumber Bus number of begining.\r
+  @param StartBusNumber Bus number of beginning.\r
 \r
   @retval EFI_SUCCESS   PCI device is found.\r
   @retval other         Some error occurred when reading PCI bridge information.\r
@@ -203,7 +208,7 @@ PciPciDeviceInfoCollector (
 }\r
 \r
 /**\r
-  Seach required device and create PCI device instance.\r
+  Search required device and create PCI device instance.\r
 \r
   @param Bridge     Parent bridge instance.\r
   @param Pci        Input PCI device information block.\r
@@ -365,14 +370,14 @@ DumpPpbPaddingResource (
 \r
       if (Descriptor->AddrSpaceGranularity == 32) {\r
         //\r
-        // prefechable\r
+        // prefetchable\r
         //\r
         if (Descriptor->SpecificFlag == EFI_ACPI_MEMORY_RESOURCE_SPECIFIC_FLAG_CACHEABLE_PREFETCHABLE) {\r
           Type = PciBarTypePMem32;\r
         }\r
 \r
         //\r
-        // Non-prefechable\r
+        // Non-prefetchable\r
         //\r
         if (Descriptor->SpecificFlag == 0) {\r
           Type = PciBarTypeMem32;\r
@@ -381,14 +386,14 @@ DumpPpbPaddingResource (
 \r
       if (Descriptor->AddrSpaceGranularity == 64) {\r
         //\r
-        // prefechable\r
+        // prefetchable\r
         //\r
         if (Descriptor->SpecificFlag == EFI_ACPI_MEMORY_RESOURCE_SPECIFIC_FLAG_CACHEABLE_PREFETCHABLE) {\r
           Type = PciBarTypePMem64;\r
         }\r
 \r
         //\r
-        // Non-prefechable\r
+        // Non-prefetchable\r
         //\r
         if (Descriptor->SpecificFlag == 0) {\r
           Type = PciBarTypeMem64;\r
@@ -563,7 +568,7 @@ GatherPpbInfo (
     PCI_DISABLE_COMMAND_REGISTER (PciIoDevice, EFI_PCI_COMMAND_BITS_OWNED);\r
 \r
     //\r
-    // Initalize the bridge control register\r
+    // Initialize the bridge control register\r
     //\r
     PCI_DISABLE_BRIDGE_CONTROL_REGISTER (PciIoDevice, EFI_PCI_BRIDGE_CONTROL_BITS_OWNED);\r
 \r
@@ -599,14 +604,14 @@ GatherPpbInfo (
 \r
   //\r
   // if PcdPciBridgeIoAlignmentProbe is TRUE, PCI bus driver probes\r
-  // PCI bridge supporting non-stardard I/O window alignment less than 4K.\r
+  // PCI bridge supporting non-standard I/O window alignment less than 4K.\r
   //\r
 \r
   PciIoDevice->BridgeIoAlignment = 0xFFF;\r
   if (FeaturePcdGet (PcdPciBridgeIoAlignmentProbe)) {\r
     //\r
     // Check any bits of bit 3-1 of I/O Base Register are writable.\r
-    // if so, it is assumed non-stardard I/O window alignment is supported by this bridge.\r
+    // if so, it is assumed non-standard I/O window alignment is supported by this bridge.\r
     // Per spec, bit 3-1 of I/O Base Register are reserved bits, so its content can't be assumed.\r
     //\r
     Value = (UINT8)(Temp ^ (BIT3 | BIT2 | BIT1));\r
@@ -717,7 +722,7 @@ GatherP2CInfo (
     PCI_DISABLE_COMMAND_REGISTER (PciIoDevice, EFI_PCI_COMMAND_BITS_OWNED);\r
 \r
     //\r
-    // Initalize the bridge control register\r
+    // Initialize the bridge control register\r
     //\r
     PCI_DISABLE_BRIDGE_CONTROL_REGISTER (PciIoDevice, EFI_PCCARD_BRIDGE_CONTROL_BITS_OWNED);\r
   }\r
@@ -741,7 +746,7 @@ GatherP2CInfo (
 }\r
 \r
 /**\r
-  Create device path for pci deivce.\r
+  Create device path for pci device.\r
 \r
   @param ParentDevicePath  Parent bridge's path.\r
   @param PciIoDevice       Pci device instance.\r
@@ -917,7 +922,7 @@ BarExisted (
   @param PciIoDevice      Pci device instance.\r
   @param Command          Input command register value, and\r
                           returned supported register value.\r
-  @param BridgeControl    Inout bridge control value for PPB or P2C, and\r
+  @param BridgeControl    Input bridge control value for PPB or P2C, and\r
                           returned supported bridge control value.\r
   @param OldCommand       Returned and stored old command register offset.\r
   @param OldBridgeControl Returned and stored old Bridge control value for PPB or P2C.\r
@@ -1200,7 +1205,7 @@ DetermineDeviceAttribute (
   EFI_STATUS      Status;\r
 \r
   //\r
-  // For Root Bridge, just copy it by RootBridgeIo proctocol\r
+  // For Root Bridge, just copy it by RootBridgeIo protocol\r
   // so as to keep consistent with the actual attribute\r
   //\r
   if (PciIoDevice->Parent == NULL) {\r
@@ -1249,9 +1254,11 @@ DetermineDeviceAttribute (
     PciSetDeviceAttribute (PciIoDevice, OldCommand, OldBridgeControl, EFI_SET_ATTRIBUTES);\r
 \r
     //\r
-    // Enable other supported attributes but not defined in PCI_IO_PROTOCOL\r
-    //\r
-    PCI_ENABLE_COMMAND_REGISTER (PciIoDevice, EFI_PCI_COMMAND_MEMORY_WRITE_AND_INVALIDATE);\r
+    // Enable other PCI supported attributes but not defined in PCI_IO_PROTOCOL\r
+    // For PCI Express devices, Memory Write and Invalidate is hardwired to 0b so only enable it for PCI devices.\r
+    if (!PciIoDevice->IsPciExp) {\r
+      PCI_ENABLE_COMMAND_REGISTER (PciIoDevice, EFI_PCI_COMMAND_MEMORY_WRITE_AND_INVALIDATE);\r
+    }\r
   }\r
 \r
   FastB2BSupport = TRUE;\r
@@ -1275,7 +1282,7 @@ DetermineDeviceAttribute (
       return Status;\r
     }\r
     //\r
-    // Detect Fast Bact to Bact support for the device under the bridge\r
+    // Detect Fast Back to Back support for the device under the bridge\r
     //\r
     Status = GetFastBackToBackSupport (Temp, PCI_PRIMARY_STATUS_OFFSET);\r
     if (FastB2BSupport && EFI_ERROR (Status)) {\r
@@ -1336,7 +1343,6 @@ UpdatePciInfo (
 {\r
   EFI_STATUS                        Status;\r
   UINTN                             BarIndex;\r
-  UINTN                             BarEndIndex;\r
   BOOLEAN                           SetFlag;\r
   VOID                              *Configuration;\r
   EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Ptr;\r
@@ -1390,23 +1396,19 @@ UpdatePciInfo (
       break;\r
     }\r
 \r
-    BarIndex    = (UINTN) Ptr->AddrTranslationOffset;\r
-    BarEndIndex = BarIndex;\r
-\r
-    //\r
-    // Update all the bars in the device\r
-    //\r
-    if (BarIndex == PCI_BAR_ALL) {\r
-      BarIndex    = 0;\r
-      BarEndIndex = PCI_MAX_BAR - 1;\r
-    }\r
-\r
-    if (BarIndex > PCI_MAX_BAR) {\r
-      Ptr++;\r
-      continue;\r
-    }\r
+    for (BarIndex = 0; BarIndex < PCI_MAX_BAR; BarIndex++) {\r
+      if ((Ptr->AddrTranslationOffset != MAX_UINT64) &&\r
+          (Ptr->AddrTranslationOffset != MAX_UINT8) &&\r
+          (Ptr->AddrTranslationOffset != BarIndex)\r
+          ) {\r
+        //\r
+        // Skip updating when AddrTranslationOffset is not MAX_UINT64 or MAX_UINT8 (wide match).\r
+        // Skip updating when current BarIndex doesn't equal to AddrTranslationOffset.\r
+        // Comparing against MAX_UINT8 is to keep backward compatibility.\r
+        //\r
+        continue;\r
+      }\r
 \r
-    for (; BarIndex <= BarEndIndex; BarIndex++) {\r
       SetFlag = FALSE;\r
       switch (Ptr->ResType) {\r
       case ACPI_ADDRESS_SPACE_TYPE_MEM:\r
@@ -1472,7 +1474,7 @@ UpdatePciInfo (
         //\r
         // Update the new length for the device\r
         //\r
-        if (Ptr->AddrLen != PCI_BAR_NOCHANGE) {\r
+        if (Ptr->AddrLen != 0) {\r
           PciIoDevice->PciBar[BarIndex].Length = Ptr->AddrLen;\r
         }\r
       }\r
@@ -1488,6 +1490,8 @@ UpdatePciInfo (
 \r
 /**\r
   This routine will update the alignment with the new alignment.\r
+  Compare with OLD_ALIGN/EVEN_ALIGN/SQUAD_ALIGN/DQUAD_ALIGN is to keep\r
+  backward compatibility.\r
 \r
   @param Alignment    Input Old alignment. Output updated alignment.\r
   @param NewAlignment New alignment.\r
@@ -1506,15 +1510,15 @@ SetNewAlign (
   // The new alignment is the same as the original,\r
   // so skip it\r
   //\r
-  if (NewAlignment == PCI_BAR_OLD_ALIGN) {\r
+  if ((NewAlignment == 0) || (NewAlignment == OLD_ALIGN)) {\r
     return ;\r
   }\r
   //\r
   // Check the validity of the parameter\r
   //\r
-   if (NewAlignment != PCI_BAR_EVEN_ALIGN  &&\r
-       NewAlignment != PCI_BAR_SQUAD_ALIGN &&\r
-       NewAlignment != PCI_BAR_DQUAD_ALIGN ) {\r
+   if (NewAlignment != EVEN_ALIGN  &&\r
+       NewAlignment != SQUAD_ALIGN &&\r
+       NewAlignment != DQUAD_ALIGN ) {\r
     *Alignment = NewAlignment;\r
     return ;\r
   }\r
@@ -1533,15 +1537,15 @@ SetNewAlign (
   //\r
   // Adjust the alignment to even, quad or double quad boundary\r
   //\r
-  if (NewAlignment == PCI_BAR_EVEN_ALIGN) {\r
+  if (NewAlignment == EVEN_ALIGN) {\r
     if ((OldAlignment & 0x01) != 0) {\r
       OldAlignment = OldAlignment + 2 - (OldAlignment & 0x01);\r
     }\r
-  } else if (NewAlignment == PCI_BAR_SQUAD_ALIGN) {\r
+  } else if (NewAlignment == SQUAD_ALIGN) {\r
     if ((OldAlignment & 0x03) != 0) {\r
       OldAlignment = OldAlignment + 4 - (OldAlignment & 0x03);\r
     }\r
-  } else if (NewAlignment == PCI_BAR_DQUAD_ALIGN) {\r
+  } else if (NewAlignment == DQUAD_ALIGN) {\r
     if ((OldAlignment & 0x07) != 0) {\r
       OldAlignment = OldAlignment + 8 - (OldAlignment & 0x07);\r
     }\r
@@ -1691,7 +1695,7 @@ PciIovParseVfBar (
       }\r
 \r
       //\r
-      // Fix the length to support some spefic 64 bit BAR\r
+      // Fix the length to support some special 64 bit BAR\r
       //\r
       Value |= ((UINT32) -1 << HighBitSet32 (Value));\r
 \r
@@ -1732,7 +1736,7 @@ PciIovParseVfBar (
       break;\r
     }\r
   }\r
-  \r
+\r
   //\r
   // Check the length again so as to keep compatible with some special bars\r
   //\r
@@ -1741,7 +1745,7 @@ PciIovParseVfBar (
     PciIoDevice->VfPciBar[BarIndex].BaseAddress = 0;\r
     PciIoDevice->VfPciBar[BarIndex].Alignment   = 0;\r
   }\r
-  \r
+\r
   //\r
   // Increment number of bar\r
   //\r
@@ -1818,7 +1822,7 @@ PciParseBar (
 \r
     }\r
     //\r
-    // Workaround. Some platforms inplement IO bar with 0 length\r
+    // Workaround. Some platforms implement IO bar with 0 length\r
     // Need to treat it as no-bar\r
     //\r
     if (PciIoDevice->PciBar[BarIndex].Length == 0) {\r
@@ -1902,7 +1906,7 @@ PciParseBar (
       }\r
 \r
       //\r
-      // Fix the length to support some spefic 64 bit BAR\r
+      // Fix the length to support some special 64 bit BAR\r
       //\r
       if (Value == 0) {\r
         DEBUG ((EFI_D_INFO, "[PciBus]BAR probing for upper 32bit of MEM64 BAR returns 0, change to 0xFFFFFFFF.\n"));\r
@@ -1983,7 +1987,7 @@ InitializePciDevice (
   //\r
   // Put all the resource apertures\r
   // Resource base is set to all ones so as to indicate its resource\r
-  // has not been alloacted\r
+  // has not been allocated\r
   //\r
   for (Offset = 0x10; Offset <= 0x24; Offset += sizeof (UINT32)) {\r
     PciIo->Pci.Write (PciIo, EfiPciIoWidthUint32, Offset, 1, &gAllOne);\r
@@ -2073,10 +2077,10 @@ InitializeP2C (
 }\r
 \r
 /**\r
-  Create and initiliaze general PCI I/O device instance for\r
+  Create and initialize general PCI I/O device instance for\r
   PCI device/bridge device/hotplug bridge device.\r
 \r
-  @param PciRootBridgeIo   Pointer to instance of EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.\r
+  @param Bridge            Parent bridge instance.\r
   @param Pci               Input Pci information block.\r
   @param Bus               Device Bus NO.\r
   @param Device            Device device NO.\r
@@ -2181,7 +2185,7 @@ CreatePciIoDevice (
       //\r
       ParentPciIo = &Bridge->PciIo;\r
       ParentPciIo->Pci.Read (\r
-                          ParentPciIo, \r
+                          ParentPciIo,\r
                           EfiPciIoWidthUint32,\r
                           Bridge->PciExpressCapabilityOffset + EFI_PCIE_CAPABILITY_DEVICE_CAPABILITIES_2_OFFSET,\r
                           1,\r
@@ -2439,7 +2443,7 @@ PciEnumeratorLight (
     }\r
 \r
     //\r
-    // Record the root bridgeio protocol\r
+    // Record the root bridge-io protocol\r
     //\r
     RootBridgeDev->PciRootBridgeIo = PciRootBridgeIo;\r
 \r
@@ -2472,7 +2476,7 @@ PciEnumeratorLight (
     } else {\r
 \r
       //\r
-      // If unsuccessly, destroy the entire node\r
+      // If unsuccessfully, destroy the entire node\r
       //\r
       DestroyRootBridge (RootBridgeDev);\r
     }\r