]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c
MdeModulePkg/PciBus: return CPU address for GetBarAttributes
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / PciBusDxe / PciIo.c
index 659f480d712234871485664f6de596412aa0887d..62179eb44bbdbf9d4f57d34dc11f68f13444a182 100644 (file)
@@ -1081,7 +1081,7 @@ PciIoUnmap (
 \r
 /**\r
   Allocates pages that are suitable for an EfiPciIoOperationBusMasterCommonBuffer\r
-  mapping.\r
+  or EfiPciOperationBusMasterCommonBuffer64 mapping.\r
 \r
   @param  This                  A pointer to the EFI_PCI_IO_PROTOCOL instance.\r
   @param  Type                  This parameter is not used and must be ignored.\r
@@ -1094,7 +1094,7 @@ PciIoUnmap (
 \r
   @retval EFI_SUCCESS           The requested memory pages were allocated.\r
   @retval EFI_UNSUPPORTED       Attributes is unsupported. The only legal attribute bits are\r
-                                MEMORY_WRITE_COMBINE and MEMORY_CACHED.\r
+                                MEMORY_WRITE_COMBINE, MEMORY_CACHED and DUAL_ADDRESS_CYCLE.\r
   @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
   @retval EFI_OUT_OF_RESOURCES  The memory pages could not be allocated.\r
 \r
@@ -1348,8 +1348,7 @@ ModifyRootBridgeAttributes (
   //\r
   Attributes &= ~(UINT64)(EFI_PCI_IO_ATTRIBUTE_EMBEDDED_DEVICE |\r
                           EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM |\r
-                          EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE |\r
-                          EFI_PCI_IO_ATTRIBUTE_BUS_MASTER);\r
+                          EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE);\r
 \r
   //\r
   // Record the new attribute of the Root Bridge\r
@@ -1727,11 +1726,12 @@ PciIoAttributes (
   }\r
   //\r
   // The upstream bridge should be also set to revelant attribute\r
-  // expect for IO and Mem\r
+  // expect for IO, Mem and BusMaster\r
   //\r
   UpStreamAttributes = Attributes &\r
                        (~(EFI_PCI_IO_ATTRIBUTE_IO     |\r
-                          EFI_PCI_IO_ATTRIBUTE_MEMORY\r
+                          EFI_PCI_IO_ATTRIBUTE_MEMORY |\r
+                          EFI_PCI_IO_ATTRIBUTE_BUS_MASTER\r
                           )\r
                         );\r
   UpStreamBridge = PciIoDevice->Parent;\r
@@ -1812,10 +1812,14 @@ GetMmioAddressTranslationOffset (
     return (UINT64) -1;\r
   }\r
 \r
+  // According to UEFI 2.7, EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL::Configuration()\r
+  // returns host address instead of device address, while AddrTranslationOffset\r
+  // is not zero, and device address = host address + AddrTranslationOffset, so\r
+  // we convert host address to device address for range compare.\r
   while (Configuration->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR) {\r
     if ((Configuration->ResType == ACPI_ADDRESS_SPACE_TYPE_MEM) &&\r
-        (Configuration->AddrRangeMin <= AddrRangeMin) &&\r
-        (Configuration->AddrRangeMin + Configuration->AddrLen >= AddrRangeMin + AddrLen)\r
+        (Configuration->AddrRangeMin + Configuration->AddrTranslationOffset <= AddrRangeMin) &&\r
+        (Configuration->AddrRangeMin + Configuration->AddrLen + Configuration->AddrTranslationOffset >= AddrRangeMin + AddrLen)\r
         ) {\r
       return Configuration->AddrTranslationOffset;\r
     }\r
@@ -1968,6 +1972,10 @@ PciIoGetBarAttributes (
         return EFI_UNSUPPORTED;\r
       }\r
     }\r
+\r
+    // According to UEFI spec 2.7, we need return host address for\r
+    // PciIo->GetBarAttributes, and host address = device address - translation.\r
+    Descriptor->AddrRangeMin -= Descriptor->AddrTranslationOffset;\r
   }\r
 \r
   return EFI_SUCCESS;\r