]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c
MdeModuelPkg/PciBus: Return AddrTranslationOffset in GetBarAttributes
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / PciBusDxe / PciIo.c
index 334a6ac3095b8e2a5239ff14fad2ac9b5a520b8e..f72598d3ae680fa05ea400ae2922ed56d287ea89 100644 (file)
@@ -1743,6 +1743,53 @@ PciIoAttributes (
   return Status;\r
 }\r
 \r
+/**\r
+  Retrieve the AddrTranslationOffset from RootBridgeIo for the\r
+  specified range.\r
+\r
+  @param RootBridgeIo    Root Bridge IO instance.\r
+  @param AddrRangeMin    The base address of the MMIO.\r
+  @param AddrLen         The length of the MMIO.\r
+\r
+  @retval The AddrTranslationOffset from RootBridgeIo for the \r
+          specified range, or (UINT64) -1 if the range is not\r
+          found in RootBridgeIo.\r
+**/\r
+UINT64\r
+GetMmioAddressTranslationOffset (\r
+  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL   *RootBridgeIo,\r
+  UINT64                            AddrRangeMin,\r
+  UINT64                            AddrLen\r
+  )\r
+{\r
+  EFI_STATUS                        Status;\r
+  EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Configuration;\r
+\r
+  Status = RootBridgeIo->Configuration (\r
+                           RootBridgeIo,\r
+                           (VOID **) &Configuration\r
+                           );\r
+  if (EFI_ERROR (Status)) {\r
+    return (UINT64) -1;\r
+  }\r
+\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
+        ) {\r
+      return Configuration->AddrTranslationOffset;\r
+    }\r
+    Configuration++;\r
+  }\r
+\r
+  //\r
+  // The resource occupied by BAR should be in the range reported by RootBridge.\r
+  //\r
+  ASSERT (FALSE);\r
+  return (UINT64) -1;\r
+}\r
+\r
 /**\r
   Gets the attributes that this PCI controller supports setting on a BAR using\r
   SetBarAttributes(), and retrieves the list of resource descriptors for a BAR.\r
@@ -1867,6 +1914,21 @@ PciIoGetBarAttributes (
     End           = (EFI_ACPI_END_TAG_DESCRIPTOR *) (Descriptor + 1);\r
     End->Desc     = ACPI_END_TAG_DESCRIPTOR;\r
     End->Checksum = 0;\r
+\r
+    //\r
+    // Get the Address Translation Offset\r
+    //\r
+    if (Descriptor->ResType == ACPI_ADDRESS_SPACE_TYPE_MEM) {\r
+      Descriptor->AddrTranslationOffset = GetMmioAddressTranslationOffset (\r
+                                            PciIoDevice->PciRootBridgeIo,\r
+                                            Descriptor->AddrRangeMin,\r
+                                            Descriptor->AddrLen\r
+                                            );\r
+      if (Descriptor->AddrTranslationOffset == (UINT64) -1) {\r
+        FreePool (Descriptor);\r
+        return EFI_UNSUPPORTED;\r
+      }\r
+    }\r
   }\r
 \r
   return EFI_SUCCESS;\r