Received: by 2002:a05:6a10:8a4d:0:0:0:0 with SMTP id dn13csp527879pxb; Thu, 12 Aug 2021 23:56:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz1R4IY91IoxLjANjNrmS5kKxOsTpLqefAjPmeaZwniFFaTN+NvAcaYaj85bsEqA1myJ6LO X-Received: by 2002:a5d:9ac1:: with SMTP id x1mr914535ion.191.1628837795686; Thu, 12 Aug 2021 23:56:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628837795; cv=none; d=google.com; s=arc-20160816; b=FntekuMFpkFempGysY6NJHSe9ROQPJU5Ch61ldY1otqkAYuUFVLriGsJAm41GSiGU9 kmkDTeU7RcAdSt1/KKhAvliY+W5Ndabv5Dq5SIy5QKC1K2Wv/bmwHF1h+YmB2y2R0DlC UmkYU0Bc3QZAtPbOGAbeIZyG97bVqcj2fqYtDCzHuNYke5HBt/fncg5lWLnA7W5hc7wQ QEYbxTcsdCTPOAZ/QpLgJ4xUjWSZK3aVDooNf/erARCXkOhpeOZjN+fJp2c6GyoW5V5O or6HuqxWk6DRN4J8tt9Cjm8x0+Cek0oweE2qGb5VqQV/UBE+Pt5oS3Qh5bH2OoiLh6hj t62w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=neD9RzFe5MVvBR/uKmGs38u6p9enZAsw3ZtS0V/bV8o=; b=CWlXnSfY+pOZxHnmjaHQ8e1NQYhAVlHymIwnXeU4dHPWDHxWAHnkWFv2iHBXz0vfdY ad6UgMTN9HHkiN4L6N2mQnRnXvDF536YtSpbH7WH6nU/2qFzqByIM6BvR9jg5MF5n0Rd L6aMwu2Wv6cz73PtrjkvFG5UVD1+MvznWE4PetknLWJ4kxFVDPp7fxSqKoH7NU6hZiSV 36BoSZNUe69YeaGypPz706nVFRsbg4ivE7n8pNdrsjhInErQfHnpMDrbjew6Red5VRPp hjlCytmlTVCQSrixKEes0TgKKlvgXGawO/0vpRZygLkJogragbVoDhV6Ys+5TAldlX5j td1w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d5si694740iod.6.2021.08.12.23.56.24; Thu, 12 Aug 2021 23:56:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239088AbhHMGzZ (ORCPT + 99 others); Fri, 13 Aug 2021 02:55:25 -0400 Received: from mailgw01.mediatek.com ([60.244.123.138]:36600 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S238879AbhHMGzV (ORCPT ); Fri, 13 Aug 2021 02:55:21 -0400 X-UUID: 72f64193c7e24027af1f8e318f8a8fde-20210813 X-UUID: 72f64193c7e24027af1f8e318f8a8fde-20210813 Received: from mtkcas07.mediatek.inc [(172.21.101.84)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1478555678; Fri, 13 Aug 2021 14:54:52 +0800 Received: from mtkcas11.mediatek.inc (172.21.101.40) by mtkmbs07n2.mediatek.inc (172.21.101.141) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 13 Aug 2021 14:54:50 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas11.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Fri, 13 Aug 2021 14:54:49 +0800 From: Yong Wu To: Joerg Roedel , Rob Herring , Matthias Brugger , Will Deacon , Robin Murphy CC: Krzysztof Kozlowski , Evan Green , Tomasz Figa , Tomasz Figa , , , , , , , , , Nicolas Boichat , , Subject: [PATCH v2 09/29] iommu/mediatek: Add tlb_lock in tlb_flush_all Date: Fri, 13 Aug 2021 14:53:04 +0800 Message-ID: <20210813065324.29220-10-yong.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20210813065324.29220-1-yong.wu@mediatek.com> References: <20210813065324.29220-1-yong.wu@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The tlb_flush_all also touches the registers about tlb operations. Add spinlock in it to protect the tlb registers. If flush_all is called from tlb_flush_range, then no need this spinlock as tlb_flush_range already hold the tlb_lock. Signed-off-by: Yong Wu --- drivers/iommu/mtk_iommu.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index 1e18fff76e61..d64139ab59d0 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -205,15 +205,24 @@ static struct mtk_iommu_domain *to_mtk_domain(struct iommu_domain *dom) return container_of(dom, struct mtk_iommu_domain, domain); } -static void mtk_iommu_tlb_flush_all(struct mtk_iommu_data *data) +static void __mtk_iommu_tlb_flush_all(struct mtk_iommu_data *data) { - if (pm_runtime_get_if_in_use(data->dev) <= 0) - return; - writel_relaxed(F_INVLD_EN1 | F_INVLD_EN0, data->base + data->plat_data->inv_sel_reg); writel_relaxed(F_ALL_INVLD, data->base + REG_MMU_INVALIDATE); wmb(); /* Make sure the tlb flush all done */ +} + +static void mtk_iommu_tlb_flush_all(struct mtk_iommu_data *data) +{ + unsigned long flags; + + if (pm_runtime_get_if_in_use(data->dev) <= 0) + return; + + spin_lock_irqsave(&data->tlb_lock, flags); + __mtk_iommu_tlb_flush_all(data); + spin_unlock_irqrestore(&data->tlb_lock, flags); pm_runtime_put(data->dev); } @@ -251,7 +260,7 @@ static void mtk_iommu_tlb_flush_range_sync(unsigned long iova, size_t size, if (ret) { dev_warn(data->dev, "Partial TLB flush timed out, falling back to full flush\n"); - mtk_iommu_tlb_flush_all(data); + __mtk_iommu_tlb_flush_all(data); } /* Clear the CPE status */ writel_relaxed(0, data->base + REG_MMU_CPE_DONE); -- 2.18.0