diff options
author | Ruiyu Ni <ruiyu.ni@intel.com> | 2015-10-23 08:29:38 +0000 |
---|---|---|
committer | niruiyu <niruiyu@Edk2> | 2015-10-23 08:29:38 +0000 |
commit | fbe618a45ef9358c8d2c32ce4bff5e8f4898b969 (patch) | |
tree | 6916727bdb501ef5081548d0726646c5f955b8f9 /MdeModulePkg/Bus/Pci/PciBusDxe/PciResourceSupport.c | |
parent | d4bf294e0ed2a6cdc1e128df512df1d5e56cfc4d (diff) | |
download | edk2-platforms-fbe618a45ef9358c8d2c32ce4bff5e8f4898b969.tar.xz |
MdeModulePkg: Fix a PciBusDxe hot plug bug
For a hot plug bridge with device attached, PciBusDxe driver reserves
the resources which equal to the total amount of padding resource
returned from HotPlug->GetResourcePadding() and the actual occupied
resource by the attached device. The behavior is incorrect.
Correct behavior is to reserve the bigger one between the padding
resource and the actual occupied resource.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Feng Tian <feng.tian@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18658 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdeModulePkg/Bus/Pci/PciBusDxe/PciResourceSupport.c')
-rw-r--r-- | MdeModulePkg/Bus/Pci/PciBusDxe/PciResourceSupport.c | 58 |
1 files changed, 38 insertions, 20 deletions
diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciResourceSupport.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciResourceSupport.c index d8d988cbfc..b106abe0fa 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciResourceSupport.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciResourceSupport.c @@ -196,6 +196,7 @@ CalculateApertureIo16 ( PCI_RESOURCE_NODE *Node;
UINT64 Offset;
EFI_PCI_PLATFORM_POLICY PciPolicy;
+ UINT64 PaddingAperture;
if (!mPolicyDetermined) {
//
@@ -228,21 +229,27 @@ CalculateApertureIo16 ( mPolicyDetermined = TRUE;
}
- Aperture = 0;
+ Aperture = 0;
+ PaddingAperture = 0;
if (Bridge == NULL) {
return ;
}
- CurrentLink = Bridge->ChildList.ForwardLink;
-
//
// Assume the bridge is aligned
//
- while (CurrentLink != &Bridge->ChildList) {
+ for ( CurrentLink = GetFirstNode (&Bridge->ChildList)
+ ; !IsNull (&Bridge->ChildList, CurrentLink)
+ ; CurrentLink = GetNextNode (&Bridge->ChildList, CurrentLink)
+ ) {
Node = RESOURCE_NODE_FROM_LINK (CurrentLink);
-
+ if (Node->ResourceUsage == PciResUsagePadding) {
+ ASSERT (PaddingAperture == 0);
+ PaddingAperture = Node->Length;
+ continue;
+ }
//
// Consider the aperture alignment
//
@@ -293,13 +300,10 @@ CalculateApertureIo16 ( // Increment aperture by the length of node
//
Aperture += Node->Length;
-
- CurrentLink = CurrentLink->ForwardLink;
}
//
- // At last, adjust the aperture with the bridge's
- // alignment
+ // Adjust the aperture with the bridge's alignment
//
Offset = Aperture & (Bridge->Alignment);
@@ -319,6 +323,12 @@ CalculateApertureIo16 ( Bridge->Alignment = Node->Alignment;
}
}
+
+ //
+ // Hotplug controller needs padding resources.
+ // Use the larger one between the padding resource and actual occupied resource.
+ //
+ Bridge->Length = MAX (Bridge->Length, PaddingAperture);
}
/**
@@ -336,10 +346,11 @@ CalculateResourceAperture ( UINT64 Aperture;
LIST_ENTRY *CurrentLink;
PCI_RESOURCE_NODE *Node;
-
+ UINT64 PaddingAperture;
UINT64 Offset;
- Aperture = 0;
+ Aperture = 0;
+ PaddingAperture = 0;
if (Bridge == NULL) {
return ;
@@ -351,14 +362,20 @@ CalculateResourceAperture ( return ;
}
- CurrentLink = Bridge->ChildList.ForwardLink;
-
//
// Assume the bridge is aligned
//
- while (CurrentLink != &Bridge->ChildList) {
+ for ( CurrentLink = GetFirstNode (&Bridge->ChildList)
+ ; !IsNull (&Bridge->ChildList, CurrentLink)
+ ; CurrentLink = GetNextNode (&Bridge->ChildList, CurrentLink)
+ ) {
Node = RESOURCE_NODE_FROM_LINK (CurrentLink);
+ if (Node->ResourceUsage == PciResUsagePadding) {
+ ASSERT (PaddingAperture == 0);
+ PaddingAperture = Node->Length;
+ continue;
+ }
//
// Apply padding resource if available
@@ -381,11 +398,6 @@ CalculateResourceAperture ( // Increment aperture by the length of node
//
Aperture += Node->Length;
-
- //
- // Consider the aperture alignment
- //
- CurrentLink = CurrentLink->ForwardLink;
}
//
@@ -407,7 +419,7 @@ CalculateResourceAperture ( }
//
- // At last, adjust the bridge's alignment to the first child's alignment
+ // Adjust the bridge's alignment to the first child's alignment
// if the bridge has at least one child
//
CurrentLink = Bridge->ChildList.ForwardLink;
@@ -417,6 +429,12 @@ CalculateResourceAperture ( Bridge->Alignment = Node->Alignment;
}
}
+
+ //
+ // Hotplug controller needs padding resources.
+ // Use the larger one between the padding resource and actual occupied resource.
+ //
+ Bridge->Length = MAX (Bridge->Length, PaddingAperture);
}
/**
|