]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Pci/PciBusDxe/PciResourceSupport.c
MdeModulePkg/PciBusDxe: make OPROM BAR degradation configurable
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / PciBusDxe / PciResourceSupport.c
index d8d988cbfc270b223503d34aad5ef50bcb589bef..e93134613b488aad1b8c4fa5069500760769d562 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   PCI resouces support functions implemntation for PCI Bus module.\r
 \r
-Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2016, 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
@@ -196,6 +196,7 @@ CalculateApertureIo16 (
   PCI_RESOURCE_NODE       *Node;\r
   UINT64                  Offset;\r
   EFI_PCI_PLATFORM_POLICY PciPolicy;\r
+  UINT64                  PaddingAperture;\r
 \r
   if (!mPolicyDetermined) {\r
     //\r
@@ -228,21 +229,27 @@ CalculateApertureIo16 (
     mPolicyDetermined = TRUE;\r
   }\r
 \r
-  Aperture = 0;\r
+  Aperture        = 0;\r
+  PaddingAperture = 0;\r
 \r
   if (Bridge == NULL) {\r
     return ;\r
   }\r
 \r
-  CurrentLink = Bridge->ChildList.ForwardLink;\r
-\r
   //\r
   // Assume the bridge is aligned\r
   //\r
-  while (CurrentLink != &Bridge->ChildList) {\r
+  for ( CurrentLink = GetFirstNode (&Bridge->ChildList)\r
+      ; !IsNull (&Bridge->ChildList, CurrentLink)\r
+      ; CurrentLink = GetNextNode (&Bridge->ChildList, CurrentLink)\r
+      ) {\r
 \r
     Node = RESOURCE_NODE_FROM_LINK (CurrentLink);\r
-\r
+    if (Node->ResourceUsage == PciResUsagePadding) {\r
+      ASSERT (PaddingAperture == 0);\r
+      PaddingAperture = Node->Length;\r
+      continue;\r
+    }\r
     //\r
     // Consider the aperture alignment\r
     //\r
@@ -293,13 +300,10 @@ CalculateApertureIo16 (
     // Increment aperture by the length of node\r
     //\r
     Aperture += Node->Length;\r
-\r
-    CurrentLink = CurrentLink->ForwardLink;\r
   }\r
 \r
   //\r
-  // At last, adjust the aperture with the bridge's\r
-  // alignment\r
+  // Adjust the aperture with the bridge's alignment\r
   //\r
   Offset = Aperture & (Bridge->Alignment);\r
 \r
@@ -319,6 +323,12 @@ CalculateApertureIo16 (
       Bridge->Alignment = Node->Alignment;\r
     }\r
   }\r
+\r
+  //\r
+  // Hotplug controller needs padding resources.\r
+  // Use the larger one between the padding resource and actual occupied resource.\r
+  //\r
+  Bridge->Length = MAX (Bridge->Length, PaddingAperture);\r
 }\r
 \r
 /**\r
@@ -336,10 +346,11 @@ CalculateResourceAperture (
   UINT64            Aperture;\r
   LIST_ENTRY        *CurrentLink;\r
   PCI_RESOURCE_NODE *Node;\r
-\r
+  UINT64            PaddingAperture;\r
   UINT64            Offset;\r
 \r
-  Aperture = 0;\r
+  Aperture        = 0;\r
+  PaddingAperture = 0;\r
 \r
   if (Bridge == NULL) {\r
     return ;\r
@@ -351,14 +362,20 @@ CalculateResourceAperture (
     return ;\r
   }\r
 \r
-  CurrentLink = Bridge->ChildList.ForwardLink;\r
-\r
   //\r
   // Assume the bridge is aligned\r
   //\r
-  while (CurrentLink != &Bridge->ChildList) {\r
+  for ( CurrentLink = GetFirstNode (&Bridge->ChildList)\r
+      ; !IsNull (&Bridge->ChildList, CurrentLink)\r
+      ; CurrentLink = GetNextNode (&Bridge->ChildList, CurrentLink)\r
+      ) {\r
 \r
     Node = RESOURCE_NODE_FROM_LINK (CurrentLink);\r
+    if (Node->ResourceUsage == PciResUsagePadding) {\r
+      ASSERT (PaddingAperture == 0);\r
+      PaddingAperture = Node->Length;\r
+      continue;\r
+    }\r
 \r
     //\r
     // Apply padding resource if available\r
@@ -381,11 +398,6 @@ CalculateResourceAperture (
     // Increment aperture by the length of node\r
     //\r
     Aperture += Node->Length;\r
-\r
-    //\r
-    // Consider the aperture alignment\r
-    //\r
-    CurrentLink = CurrentLink->ForwardLink;\r
   }\r
 \r
   //\r
@@ -407,7 +419,7 @@ CalculateResourceAperture (
   }\r
 \r
   //\r
-  // At last, adjust the bridge's alignment to the first child's alignment\r
+  // Adjust the bridge's alignment to the first child's alignment\r
   // if the bridge has at least one child\r
   //\r
   CurrentLink = Bridge->ChildList.ForwardLink;\r
@@ -417,6 +429,12 @@ CalculateResourceAperture (
       Bridge->Alignment = Node->Alignment;\r
     }\r
   }\r
+\r
+  //\r
+  // Hotplug controller needs padding resources.\r
+  // Use the larger one between the padding resource and actual occupied resource.\r
+  //\r
+  Bridge->Length = MAX (Bridge->Length, PaddingAperture);\r
 }\r
 \r
 /**\r
@@ -1034,50 +1052,56 @@ DegradeResource (
   IN PCI_RESOURCE_NODE *PMem64Node\r
   )\r
 {\r
-  PCI_IO_DEVICE        *Temp;\r
+  PCI_IO_DEVICE        *PciIoDevice;\r
   LIST_ENTRY           *ChildDeviceLink;\r
   LIST_ENTRY           *ChildNodeLink;\r
   LIST_ENTRY           *NextChildNodeLink;\r
-  PCI_RESOURCE_NODE    *TempNode;\r
+  PCI_RESOURCE_NODE    *ResourceNode;\r
 \r
-  //\r
-  // If any child device has both option ROM and 64-bit BAR, degrade its PMEM64/MEM64\r
-  // requests in case that if a legacy option ROM image can not access 64-bit resources.\r
-  //\r
-  ChildDeviceLink = Bridge->ChildList.ForwardLink;\r
-  while (ChildDeviceLink != NULL && ChildDeviceLink != &Bridge->ChildList) {\r
-    Temp = PCI_IO_DEVICE_FROM_LINK (ChildDeviceLink);\r
-    if (Temp->RomSize != 0) {\r
-      if (!IsListEmpty (&Mem64Node->ChildList)) {      \r
-        ChildNodeLink = Mem64Node->ChildList.ForwardLink;\r
-        while (ChildNodeLink != &Mem64Node->ChildList) {\r
-          TempNode = RESOURCE_NODE_FROM_LINK (ChildNodeLink);\r
-          NextChildNodeLink = ChildNodeLink->ForwardLink;\r
-\r
-          if (TempNode->PciDev == Temp) {\r
-            RemoveEntryList (ChildNodeLink);\r
-            InsertResourceNode (Mem32Node, TempNode);\r
+  if (FeaturePcdGet (PcdPciDegradeResourceForOptionRom)) {\r
+    //\r
+    // If any child device has both option ROM and 64-bit BAR, degrade its PMEM64/MEM64\r
+    // requests in case that if a legacy option ROM image can not access 64-bit resources.\r
+    //\r
+    ChildDeviceLink = Bridge->ChildList.ForwardLink;\r
+    while (ChildDeviceLink != NULL && ChildDeviceLink != &Bridge->ChildList) {\r
+      PciIoDevice = PCI_IO_DEVICE_FROM_LINK (ChildDeviceLink);\r
+      if (PciIoDevice->RomSize != 0) {\r
+        if (!IsListEmpty (&Mem64Node->ChildList)) {\r
+          ChildNodeLink = Mem64Node->ChildList.ForwardLink;\r
+          while (ChildNodeLink != &Mem64Node->ChildList) {\r
+            ResourceNode = RESOURCE_NODE_FROM_LINK (ChildNodeLink);\r
+            NextChildNodeLink = ChildNodeLink->ForwardLink;\r
+\r
+            if ((ResourceNode->PciDev == PciIoDevice) &&\r
+                (ResourceNode->Virtual || !PciIoDevice->PciBar[ResourceNode->Bar].BarTypeFixed)\r
+                ) {\r
+              RemoveEntryList (ChildNodeLink);\r
+              InsertResourceNode (Mem32Node, ResourceNode);\r
+            }\r
+            ChildNodeLink = NextChildNodeLink;\r
           }\r
-          ChildNodeLink = NextChildNodeLink;\r
-        }        \r
-      }\r
-\r
-      if (!IsListEmpty (&PMem64Node->ChildList)) {      \r
-        ChildNodeLink = PMem64Node->ChildList.ForwardLink;\r
-        while (ChildNodeLink != &PMem64Node->ChildList) {\r
-          TempNode = RESOURCE_NODE_FROM_LINK (ChildNodeLink);\r
-          NextChildNodeLink = ChildNodeLink->ForwardLink;\r
+        }\r
 \r
-          if (TempNode->PciDev == Temp) {\r
-            RemoveEntryList (ChildNodeLink);\r
-            InsertResourceNode (PMem32Node, TempNode);\r
+        if (!IsListEmpty (&PMem64Node->ChildList)) {\r
+          ChildNodeLink = PMem64Node->ChildList.ForwardLink;\r
+          while (ChildNodeLink != &PMem64Node->ChildList) {\r
+            ResourceNode = RESOURCE_NODE_FROM_LINK (ChildNodeLink);\r
+            NextChildNodeLink = ChildNodeLink->ForwardLink;\r
+\r
+            if ((ResourceNode->PciDev == PciIoDevice) &&\r
+                (ResourceNode->Virtual || !PciIoDevice->PciBar[ResourceNode->Bar].BarTypeFixed)\r
+                ) {\r
+              RemoveEntryList (ChildNodeLink);\r
+              InsertResourceNode (PMem32Node, ResourceNode);\r
+            }\r
+            ChildNodeLink = NextChildNodeLink;\r
           }\r
-          ChildNodeLink = NextChildNodeLink;\r
-        }        \r
-      }\r
+        }\r
 \r
+      }\r
+      ChildDeviceLink = ChildDeviceLink->ForwardLink;\r
     }\r
-    ChildDeviceLink = ChildDeviceLink->ForwardLink;\r
   }\r
 \r
   //\r