diff mbox series

[3/5] PCI: vmd: Add offset translation helper

Message ID 20201120225144.15138-4-jonathan.derrick@intel.com
State New
Headers show
Series Legacy direct-assign mode | expand

Commit Message

Jon Derrick Nov. 20, 2020, 10:51 p.m. UTC
Adds a helper for translating physical addresses to bridge window
offsets. No functional changes.

Signed-off-by: Jon Derrick <jonathan.derrick@intel.com>
---
 drivers/pci/controller/vmd.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/drivers/pci/controller/vmd.c b/drivers/pci/controller/vmd.c
index c7b5614..b0504ee 100644
--- a/drivers/pci/controller/vmd.c
+++ b/drivers/pci/controller/vmd.c
@@ -483,6 +483,16 @@  static int vmd_find_free_domain(void)
 	return domain + 1;
 }
 
+static void vmd_phys_to_offset(struct vmd_dev *vmd, u64 phys1, u64 phys2,
+				 resource_size_t *offset1,
+				 resource_size_t *offset2)
+{
+	*offset1 = vmd->dev->resource[VMD_MEMBAR1].start -
+			(phys1 & PCI_BASE_ADDRESS_MEM_MASK);
+	*offset2 = vmd->dev->resource[VMD_MEMBAR2].start -
+			(phys2 & PCI_BASE_ADDRESS_MEM_MASK);
+}
+
 static int vmd_get_phys_offsets(struct vmd_dev *vmd, bool native_hint,
 				resource_size_t *offset1,
 				resource_size_t *offset2)
@@ -507,8 +517,8 @@  static int vmd_get_phys_offsets(struct vmd_dev *vmd, bool native_hint,
 			phys1 = readq(membar2 + MB2_SHADOW_OFFSET);
 			phys2 = readq(membar2 + MB2_SHADOW_OFFSET + 8);
 			pci_iounmap(dev, membar2);
-		} else
-			return 0;
+			vmd_phys_to_offset(vmd, phys1, phys2, offset1, offset2);
+		}
 	} else {
 		/* Hypervisor-Emulated Vendor-Specific Capability */
 		int pos = pci_find_capability(dev, PCI_CAP_ID_VNDR);
@@ -525,15 +535,10 @@  static int vmd_get_phys_offsets(struct vmd_dev *vmd, bool native_hint,
 			pci_read_config_dword(dev, pos + 16, &reg);
 			pci_read_config_dword(dev, pos + 20, &regu);
 			phys2 = (u64) regu << 32 | reg;
-		} else
-			return 0;
+			vmd_phys_to_offset(vmd, phys1, phys2, offset1, offset2);
+		}
 	}
 
-	*offset1 = dev->resource[VMD_MEMBAR1].start -
-			(phys1 & PCI_BASE_ADDRESS_MEM_MASK);
-	*offset2 = dev->resource[VMD_MEMBAR2].start -
-			(phys2 & PCI_BASE_ADDRESS_MEM_MASK);
-
 	return 0;
 }