Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iommu/amd: Add function to get IOMMUv2 domain for pdev

The AMD IOMMUv2 driver needs to get the IOMMUv2 domain
associated with a particular device. This patch adds a
function to get this information.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>

+23
+18
drivers/iommu/amd_iommu.c
··· 2958 2958 if (!domain->pt_root) 2959 2959 goto out_free; 2960 2960 2961 + domain->iommu_domain = dom; 2962 + 2961 2963 dom->priv = domain; 2962 2964 2963 2965 return 0; ··· 3465 3463 return iommu_queue_command(iommu, &cmd); 3466 3464 } 3467 3465 EXPORT_SYMBOL(amd_iommu_complete_ppr); 3466 + 3467 + struct iommu_domain *amd_iommu_get_v2_domain(struct pci_dev *pdev) 3468 + { 3469 + struct protection_domain *domain; 3470 + 3471 + domain = get_domain(&pdev->dev); 3472 + if (IS_ERR(domain)) 3473 + return NULL; 3474 + 3475 + /* Only return IOMMUv2 domains */ 3476 + if (!(domain->flags & PD_IOMMUV2_MASK)) 3477 + return NULL; 3478 + 3479 + return domain->iommu_domain; 3480 + } 3481 + EXPORT_SYMBOL(amd_iommu_get_v2_domain);
+1
drivers/iommu/amd_iommu_proto.h
··· 46 46 extern int amd_iommu_domain_set_gcr3(struct iommu_domain *dom, int pasid, 47 47 unsigned long cr3); 48 48 extern int amd_iommu_domain_clear_gcr3(struct iommu_domain *dom, int pasid); 49 + extern struct iommu_domain *amd_iommu_get_v2_domain(struct pci_dev *pdev); 49 50 50 51 #define PPR_SUCCESS 0x0 51 52 #define PPR_INVALID 0x1
+4
drivers/iommu/amd_iommu_types.h
··· 360 360 #define PPR_FAULT_RSVD (1 << 7) 361 361 #define PPR_FAULT_GN (1 << 8) 362 362 363 + struct iommu_domain; 364 + 363 365 /* 364 366 * This structure contains generic data for IOMMU protection domains 365 367 * independent of their use. ··· 381 379 unsigned dev_cnt; /* devices assigned to this domain */ 382 380 unsigned dev_iommu[MAX_IOMMUS]; /* per-IOMMU reference count */ 383 381 void *priv; /* private data */ 382 + struct iommu_domain *iommu_domain; /* Pointer to generic 383 + domain structure */ 384 384 385 385 }; 386 386