>From d1625f1e8461cef23bc8697ec51382c47b92fa5a Mon Sep 17 00:00:00 2001 From: Lu Baolu Date: Thu, 7 Mar 2019 10:50:27 +0800 Subject: [PATCH 06/12] iommu: Add ops entry for vendor specific default domain type This adds an iommu ops entry for iommu vendor driver to specify the type of the default domain for each device. This is needed for the vendor driver, which already has its own logic to determine the use of identity domain for a long time, when it switches to apply default domain. Signed-off-by: Lu Baolu --- drivers/iommu/iommu.c | 12 +++++++++--- include/linux/iommu.h | 4 ++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 374327018a11..4101f38a7844 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1102,12 +1102,18 @@ struct iommu_group *iommu_group_get_for_dev(struct device *dev) */ if (!group->default_domain) { struct iommu_domain *dom; + int domain_type = iommu_def_domain_type; - dom = __iommu_domain_alloc(dev->bus, iommu_def_domain_type); - if (!dom && iommu_def_domain_type != IOMMU_DOMAIN_DMA) { + if (ops->is_identity_map) + domain_type = ops->is_identity_map(dev) ? + IOMMU_DOMAIN_IDENTITY : + IOMMU_DOMAIN_DMA; + + dom = __iommu_domain_alloc(dev->bus, domain_type); + if (!dom && domain_type != IOMMU_DOMAIN_DMA) { dev_warn(dev, "failed to allocate default IOMMU domain of type %u; falling back to IOMMU_DOMAIN_DMA", - iommu_def_domain_type); + domain_type); dom = __iommu_domain_alloc(dev->bus, IOMMU_DOMAIN_DMA); } diff --git a/include/linux/iommu.h b/include/linux/iommu.h index e90da6b6f3d1..8e298fd631d0 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -184,6 +184,7 @@ struct iommu_resv_region { * @domain_window_disable: Disable a particular window for a domain * @of_xlate: add OF master IDs to iommu grouping * @pgsize_bitmap: bitmap of all possible supported page sizes + * @is_identity_map: vendor customized identity map adjudicator */ struct iommu_ops { bool (*capable)(enum iommu_cap); @@ -226,6 +227,9 @@ struct iommu_ops { int (*of_xlate)(struct device *dev, struct of_phandle_args *args); bool (*is_attach_deferred)(struct iommu_domain *domain, struct device *dev); + /* Vendor customized identity map adjudicator */ + bool (*is_identity_map)(struct device *dev); + unsigned long pgsize_bitmap; }; -- 2.17.1