]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/PciBus: Fix bug that PCI BUS claims too much resource
authorRuiyu Ni <ruiyu.ni@intel.com>
Fri, 20 Oct 2017 09:55:01 +0000 (17:55 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Mon, 23 Oct 2017 07:50:55 +0000 (15:50 +0800)
The bug was caused by 728d74973c9262b6c7b7ef4be213223d55affec3
"MdeModulePkg/PciBus: Count multiple hotplug resource paddings".

The patch firstly updated the Bridge->Alignment to the maximum
alignment of all devices under the bridge, then aligned the
Bridge->Length to Bridge->Alignment.
It caused too much resources were claimed.

The new patch firstly aligns Bridge->Length to Bridge->Alignment,
then updates the Bridge->Alignment to the maximum alignment of all
devices under the bridge.
Because the step to update the Bridge->Alignment is to make sure
the resource allocated to the bus under the Bridge meets all
devices alignment. But the Bridge->Length doesn't have to align
to the maximum alignment.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
MdeModulePkg/Bus/Pci/PciBusDxe/PciResourceSupport.c

index 8dbe9a00380f253873f245d2bcb98269d5e5f314..2f713fcee95eb0479e37b87ee8411aebe10ac5c7 100644 (file)
@@ -389,18 +389,7 @@ CalculateResourceAperture (
   }\r
 \r
   //\r
-  // Adjust the bridge's alignment to the MAX (first) alignment of all children.\r
-  //\r
-  CurrentLink = Bridge->ChildList.ForwardLink;\r
-  if (CurrentLink != &Bridge->ChildList) {\r
-    Node = RESOURCE_NODE_FROM_LINK (CurrentLink);\r
-    if (Node->Alignment > Bridge->Alignment) {\r
-      Bridge->Alignment = Node->Alignment;\r
-    }\r
-  }\r
-\r
-  //\r
-  // At last, adjust the aperture with the bridge's alignment\r
+  // Adjust the aperture with the bridge's alignment\r
   //\r
   Aperture[PciResUsageTypical] = ALIGN_VALUE (Aperture[PciResUsageTypical], Bridge->Alignment + 1);\r
   Aperture[PciResUsagePadding] = ALIGN_VALUE (Aperture[PciResUsagePadding], Bridge->Alignment + 1);\r
@@ -410,6 +399,17 @@ CalculateResourceAperture (
   // Use the larger one between the padding resource and actual occupied resource.\r
   //\r
   Bridge->Length = MAX (Aperture[PciResUsageTypical], Aperture[PciResUsagePadding]);\r
+\r
+  //\r
+  // Adjust the bridge's alignment to the MAX (first) alignment of all children.\r
+  //\r
+  CurrentLink = Bridge->ChildList.ForwardLink;\r
+  if (CurrentLink != &Bridge->ChildList) {\r
+    Node = RESOURCE_NODE_FROM_LINK (CurrentLink);\r
+    if (Node->Alignment > Bridge->Alignment) {\r
+      Bridge->Alignment = Node->Alignment;\r
+    }\r
+  }\r
 }\r
 \r
 /**\r