aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/iommu/amd_iommu.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 6edbd0edcae7..3a00b5ce73ab 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -274,6 +274,18 @@ static void swap_pci_ref(struct pci_dev **from, struct pci_dev *to)
274 *from = to; 274 *from = to;
275} 275}
276 276
277static struct pci_bus *find_hosted_bus(struct pci_bus *bus)
278{
279 while (!bus->self) {
280 if (!pci_is_root_bus(bus))
281 bus = bus->parent;
282 else
283 return ERR_PTR(-ENODEV);
284 }
285
286 return bus;
287}
288
277#define REQ_ACS_FLAGS (PCI_ACS_SV | PCI_ACS_RR | PCI_ACS_CR | PCI_ACS_UF) 289#define REQ_ACS_FLAGS (PCI_ACS_SV | PCI_ACS_RR | PCI_ACS_CR | PCI_ACS_UF)
278 290
279static struct pci_dev *get_isolation_root(struct pci_dev *pdev) 291static struct pci_dev *get_isolation_root(struct pci_dev *pdev)
@@ -300,14 +312,9 @@ static struct pci_dev *get_isolation_root(struct pci_dev *pdev)
300 * Finding the next device may require skipping virtual buses. 312 * Finding the next device may require skipping virtual buses.
301 */ 313 */
302 while (!pci_is_root_bus(dma_pdev->bus)) { 314 while (!pci_is_root_bus(dma_pdev->bus)) {
303 struct pci_bus *bus = dma_pdev->bus; 315 struct pci_bus *bus = find_hosted_bus(dma_pdev->bus);
304 316 if (IS_ERR(bus))
305 while (!bus->self) { 317 break;
306 if (!pci_is_root_bus(bus))
307 bus = bus->parent;
308 else
309 goto root_bus;
310 }
311 318
312 if (pci_acs_path_enabled(bus->self, NULL, REQ_ACS_FLAGS)) 319 if (pci_acs_path_enabled(bus->self, NULL, REQ_ACS_FLAGS))
313 break; 320 break;
@@ -315,7 +322,6 @@ static struct pci_dev *get_isolation_root(struct pci_dev *pdev)
315 swap_pci_ref(&dma_pdev, pci_dev_get(bus->self)); 322 swap_pci_ref(&dma_pdev, pci_dev_get(bus->self));
316 } 323 }
317 324
318root_bus:
319 return dma_pdev; 325 return dma_pdev;
320} 326}
321 327