Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp501957pxb; Thu, 23 Sep 2021 05:03:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwYUIOKUK97iEH/ITOBrEe2LNBgCyRkNW36TPDork/5ksY9JfJL2Lz0vtJ7rw+pk55AgFqL X-Received: by 2002:a2e:140f:: with SMTP id u15mr2784821ljd.25.1632398624338; Thu, 23 Sep 2021 05:03:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632398624; cv=none; d=google.com; s=arc-20160816; b=A8pXkBI9x00GcTs/YT6oU6o7GqbVn7TlRUrQ4KxrMF1py7yOb25WPe3vPXoNWoXKLl DZt8PRSpUd8daVpew6ovxbEoTRlqDON5s3Up/oSP2Chy+j00Pc9wrjj40giJegRD+8Yn JL0PEFUpkJnAoA2v+9sJm4398v6YX1b8cAaWhqrHJ8yrrMqob85MoSuw3P+mzuwYn176 YAj39W9Aa745hzyiz3wi7X/qvkPVSGn7dxnEM+I0NgDDLKc9CMbCc2b3ciLOMfTy8kui D8tAQZCq3t13yR2UukPlxqrsPwB7DYKp4bEzsaH/R7pOsOJzTuMOOUXwuyhNZmwru7r5 t7eA== 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=K3HCTbrx2MMcBM8nCqFgRJmp77voD/omH5dotHeIWCw=; b=LZt+2WYN+V56FpF7c3UqrOFSaeiXl1BdWSv9Tryoq1aHOrws6fIeEQcObExHV832Gc 8o+DU5FG5LgxIZdjlS+Kd4ZPsKfVFNCwcPte8FKI8XDVfcgAG/na7kBsoQR2jKOU01Z1 wS2T9unov/O3jM+8KjqmsaLx3RQuPaAWYCUy9kKA38jSp/XmGhmYKun0glGViPM+ocS8 fgVG9Iw2F8Csr4eEGozzwKr9GhmQospVDArSwtfVnDzIEAspAdELk1qh+Bsfu1IuO1ie kbHoL3PpQ0sej1/1KpeY+SZytsFQxsJ9Ed8se6ozVymFTLaNXFnZcTKoNnHqfdVqCfrD wSBA== 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 u18si5206272edb.154.2021.09.23.05.03.14; Thu, 23 Sep 2021 05:03:44 -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 S240789AbhIWMC2 (ORCPT + 99 others); Thu, 23 Sep 2021 08:02:28 -0400 Received: from mailgw01.mediatek.com ([60.244.123.138]:51106 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S240819AbhIWMCN (ORCPT ); Thu, 23 Sep 2021 08:02:13 -0400 X-UUID: f599a0feb942408a8c8fbf2aa597c56a-20210923 X-UUID: f599a0feb942408a8c8fbf2aa597c56a-20210923 Received: from mtkcas11.mediatek.inc [(172.21.101.40)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 242078960; Thu, 23 Sep 2021 20:00:39 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs07n2.mediatek.inc (172.21.101.141) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 23 Sep 2021 20:00:37 +0800 Received: from localhost.localdomain (10.17.3.154) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 23 Sep 2021 20:00:36 +0800 From: Yong Wu To: Joerg Roedel , Rob Herring , Matthias Brugger , Will Deacon , Robin Murphy CC: Krzysztof Kozlowski , Tomasz Figa , , , , , , , Hsin-Yi Wang , , , , , Subject: [PATCH v3 10/33] iommu/mediatek: Add tlb_lock in tlb_flush_all Date: Thu, 23 Sep 2021 19:58:17 +0800 Message-ID: <20210923115840.17813-11-yong.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20210923115840.17813-1-yong.wu@mediatek.com> References: <20210923115840.17813-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. since the tlb_range already hold the spinlock, move it a bit outside the spinlock to print log. Signed-off-by: Yong Wu --- drivers/iommu/mtk_iommu.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index 0b4c30baa864..ab484d20b441 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -204,15 +204,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_do_flush_all(struct mtk_iommu_data *data) { - if (pm_runtime_get_if_in_use(data->dev) <= 0) - return; + unsigned long flags; + spin_lock_irqsave(&data->tlb_lock, flags); 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 */ + spin_unlock_irqrestore(&data->tlb_lock, flags); +} + +static void mtk_iommu_tlb_flush_all(struct mtk_iommu_data *data) +{ + if (pm_runtime_get_if_in_use(data->dev) <= 0) + return; + + mtk_iommu_tlb_do_flush_all(data); pm_runtime_put(data->dev); } @@ -247,14 +256,16 @@ static void mtk_iommu_tlb_flush_range_sync(unsigned long iova, size_t size, /* tlb sync */ ret = readl_poll_timeout_atomic(data->base + REG_MMU_CPE_DONE, tmp, tmp != 0, 10, 1000); + + /* Clear the CPE status */ + writel_relaxed(0, data->base + REG_MMU_CPE_DONE); + spin_unlock_irqrestore(&data->tlb_lock, flags); + 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_do_flush_all(data); } - /* Clear the CPE status */ - writel_relaxed(0, data->base + REG_MMU_CPE_DONE); - spin_unlock_irqrestore(&data->tlb_lock, flags); if (has_pm) pm_runtime_put(data->dev); -- 2.18.0