From e8409200d6a52f4a03111acd407f94c6680e85ea Mon Sep 17 00:00:00 2001 From: Simon Xue Date: Tue, 6 Apr 2021 16:27:16 +0800 Subject: [PATCH] iommu/rockchip: add deferred attach for vop When jumping from uboot to kernel, vop may page fault, this due to vop working parallel to kernel probe dts node by cpu. Defer vop iommu attach function when iommu_ops->add_device called, and hand the attach function to vop driver is a solution. Change-Id: I84822ac7a3d0884f96df774a2363c22cbf0f074a Signed-off-by: Simon Xue --- drivers/iommu/rockchip-iommu.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c index b42c6181c296..2fc8a302b4a3 100644 --- a/drivers/iommu/rockchip-iommu.c +++ b/drivers/iommu/rockchip-iommu.c @@ -114,6 +114,7 @@ struct rk_iommu { struct rk_iommudata { struct device_link *link; /* runtime PM link from IOMMU to master */ struct rk_iommu *iommu; + bool defer_attach; }; static struct device *dma_dev; @@ -1099,6 +1100,8 @@ static struct iommu_device *rk_iommu_probe_device(struct device *dev) data->link = device_link_add(dev, iommu->dev, DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME); + data->defer_attach = false; + return &iommu->iommu; } @@ -1118,6 +1121,14 @@ static struct iommu_group *rk_iommu_device_group(struct device *dev) return iommu_group_ref_get(iommu->group); } +static bool rk_iommu_is_attach_deferred(struct iommu_domain *domain, + struct device *dev) +{ + struct rk_iommudata *data = dev_iommu_priv_get(dev); + + return data->defer_attach; +} + static int rk_iommu_of_xlate(struct device *dev, struct of_phandle_args *args) { @@ -1131,6 +1142,10 @@ static int rk_iommu_of_xlate(struct device *dev, iommu_dev = of_find_device_by_node(args->np); data->iommu = platform_get_drvdata(iommu_dev); + + if (strstr(dev_name(dev), "vop")) + data->defer_attach = true; + dev_iommu_priv_set(dev, data); platform_device_put(iommu_dev); @@ -1148,6 +1163,7 @@ static const struct iommu_ops rk_iommu_ops = { .probe_device = rk_iommu_probe_device, .release_device = rk_iommu_release_device, .iova_to_phys = rk_iommu_iova_to_phys, + .is_attach_deferred = rk_iommu_is_attach_deferred, .device_group = rk_iommu_device_group, .pgsize_bitmap = RK_IOMMU_PGSIZE_BITMAP, .of_xlate = rk_iommu_of_xlate,