]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/PciBus: do not improperly degrade resource
authorRuiyu Ni <ruiyu.ni@intel.com>
Fri, 1 Apr 2016 08:14:07 +0000 (16:14 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Mon, 23 May 2016 05:49:41 +0000 (13:49 +0800)
PciBus driver originally always degrade (64->32) the MMIO resource
for PCI BAR when the PCI device contains option ROM.
But the degrade causes the PCI device can only use resource below 4GB
which makes the resource allocation fails when the PCI device wants
very big MMIO.
The patch follows the PI spec (ECR 1529) to honor the granularity
setting for PCI BAR from IncompatiblePciDeviceSupport so that even
for PCI device which contains option ROM, the degrade doesn't happen
if IncompatiblePciDeviceSupport returns 64 as granularity.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Jeff Fan <jeff.fan@intel.com>
Tested-by: Laszlo Ersek <lersek@redhat.com>
MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h
MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c
MdeModulePkg/Bus/Pci/PciBusDxe/PciResourceSupport.c

index 2226b1b052522f7d41ffac2c628164f7489a90e7..b12d7ec5032fe5c0784095e63cf06b4f93f3e745 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Header files and data structures needed by PCI Bus module.\r
 \r
-Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2015, 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
@@ -102,6 +102,7 @@ struct _PCI_BAR {
   UINT64        Length;\r
   UINT64        Alignment;\r
   PCI_BAR_TYPE  BarType;\r
+  BOOLEAN       BarTypeFixed;\r
   UINT16        Offset;\r
 };\r
 \r
index 29d80c4a23bf6008d621fb3a9268f120c2b0a2c1..80f2885005df39e85cdc7d66bec4df43f6dc8eee 100644 (file)
@@ -1416,6 +1416,38 @@ UpdatePciInfo (
         //\r
         if (CheckBarType (PciIoDevice, (UINT8) BarIndex, PciBarTypeMem)) {\r
           SetFlag = TRUE;\r
+\r
+          //\r
+          // Ignored if granularity is 0.\r
+          // Ignored if PCI BAR is I/O or 32-bit memory.\r
+          // If PCI BAR is 64-bit memory and granularity is 32, then\r
+          // the PCI BAR resource is allocated below 4GB.\r
+          // If PCI BAR is 64-bit memory and granularity is 64, then\r
+          // the PCI BAR resource is allocated above 4GB.\r
+          //\r
+          if (PciIoDevice->PciBar[BarIndex].BarType == PciBarTypeMem64) {\r
+            switch (Ptr->AddrSpaceGranularity) {\r
+            case 32:\r
+              PciIoDevice->PciBar[BarIndex].BarType = PciBarTypeMem32;\r
+            case 64:\r
+              PciIoDevice->PciBar[BarIndex].BarTypeFixed = TRUE;\r
+              break;\r
+            default:\r
+              break;\r
+            }\r
+          }\r
+\r
+          if (PciIoDevice->PciBar[BarIndex].BarType == PciBarTypePMem64) {\r
+            switch (Ptr->AddrSpaceGranularity) {\r
+            case 32:\r
+              PciIoDevice->PciBar[BarIndex].BarType = PciBarTypePMem32;\r
+            case 64:\r
+              PciIoDevice->PciBar[BarIndex].BarTypeFixed = TRUE;\r
+              break;\r
+            default:\r
+              break;\r
+            }\r
+          }\r
         }\r
         break;\r
 \r
@@ -1760,6 +1792,7 @@ PciParseBar (
     return Offset + 4;\r
   }\r
 \r
+  PciIoDevice->PciBar[BarIndex].BarTypeFixed = FALSE;\r
   PciIoDevice->PciBar[BarIndex].Offset = (UINT8) Offset;\r
   if ((Value & 0x01) != 0) {\r
     //\r
index 560f8d8a756ab25eee39904903fd30c0c20db3f6..b0632d53b82b9ffba96cc3161b2430040b8d19cc 100644 (file)
@@ -1072,7 +1072,9 @@ DegradeResource (
           ResourceNode = RESOURCE_NODE_FROM_LINK (ChildNodeLink);\r
           NextChildNodeLink = ChildNodeLink->ForwardLink;\r
 \r
-          if (ResourceNode->PciDev == PciIoDevice) {\r
+          if ((ResourceNode->PciDev == PciIoDevice) &&\r
+              (ResourceNode->Virtual || !PciIoDevice->PciBar[ResourceNode->Bar].BarTypeFixed)\r
+              ) {\r
             RemoveEntryList (ChildNodeLink);\r
             InsertResourceNode (Mem32Node, ResourceNode);\r
           }\r
@@ -1086,7 +1088,9 @@ DegradeResource (
           ResourceNode = RESOURCE_NODE_FROM_LINK (ChildNodeLink);\r
           NextChildNodeLink = ChildNodeLink->ForwardLink;\r
 \r
-          if (ResourceNode->PciDev == PciIoDevice) {\r
+          if ((ResourceNode->PciDev == PciIoDevice) &&\r
+              (ResourceNode->Virtual || !PciIoDevice->PciBar[ResourceNode->Bar].BarTypeFixed)\r
+              ) {\r
             RemoveEntryList (ChildNodeLink);\r
             InsertResourceNode (PMem32Node, ResourceNode);\r
           }\r