From c8410c0f810bc668ae7bc48ba8a2f756eca09d10 Mon Sep 17 00:00:00 2001 From: Simon Xue Date: Fri, 28 Jun 2019 10:54:26 +0800 Subject: [PATCH] iommu/rockchip: disable iommu by attaching NULL Iommu framework introduce default_domain for automatic attach which we were not interesting before, now rockchip iommu driver following this way that make things different: iommu_detach_device function is not able to disable iommu anymore. It just do following things either: 1. Just return Like Vcodec/ISP who does not allocate new domain 2. Attach default_domain Like vop who allocate new domain by vop driver We have no way to temporary disable iommu,to fix this issue, master driver need to attach a NULL domain,also master driver need more step: 1. iommu_attach_device(NULL, dev) -> disable iommu 2. iommu_detach_device(NULL, dev) -> attach default_domain Above two steps must comes in pairs. Following order called by driver is not permitted: 1. iommu_attach_device(domain, dev) 2. iommu_attach_device(NULL, dev) 3. iommu_detach_device(NULL, dev) 4. iommu_detach_device(domain, dev) Correct is: 1. iommu_attach_device(domain, dev) 2. iommu_detach_device(domain, dev) 3. iommu_attach_device(NULL, dev) 4. iommu_detach_device(NULL, dev) Change-Id: I12b1e27e5119fb1abd05ccce57c9e941f03e9498 Signed-off-by: Simon Xue --- drivers/iommu/rockchip-iommu.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c index 8fb0fcb16740..854ed28839c1 100644 --- a/drivers/iommu/rockchip-iommu.c +++ b/drivers/iommu/rockchip-iommu.c @@ -982,6 +982,10 @@ static int rk_iommu_attach_device(struct iommu_domain *domain, iommu->domain = domain; + /* Attach NULL for disable iommu */ + if (!domain) + return 0; + spin_lock_irqsave(&rk_domain->iommus_lock, flags); list_add_tail(&iommu->node, &rk_domain->iommus); spin_unlock_irqrestore(&rk_domain->iommus_lock, flags);