From 5210d963c9dde1d6bae95f0d338360d7eb92ce5a Mon Sep 17 00:00:00 2001 From: James Sewart Date: Thu, 21 Mar 2019 11:31:44 +0000 Subject: [PATCH 5/9] 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 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 88d589d56ded..516e4d8995c2 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 ffbbc7e39cee..a5007d035218 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -186,6 +186,7 @@ struct iommu_resv_region { * @of_xlate: add OF master IDs to iommu grouping * @is_attach_deferred: Check if domain attach should be deferred from iommu * driver init to device driver init (default no) + * @is_identity_map: vendor customized identity map adjudicator * @pgsize_bitmap: bitmap of all possible supported page sizes */ struct iommu_ops { @@ -230,6 +231,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