Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp3598473ybx; Sun, 3 Nov 2019 23:05:07 -0800 (PST) X-Google-Smtp-Source: APXvYqwZyVm6DUh9XM6ZjtflcATqCPU39SK4QeoZdjVucXZY1bXSQdP9WDfjLtUNmX79nQcXB+M8 X-Received: by 2002:a17:906:198c:: with SMTP id g12mr11377613ejd.247.1572851107502; Sun, 03 Nov 2019 23:05:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572851107; cv=none; d=google.com; s=arc-20160816; b=TbNm8eIP9wZY4seYez8Nw9YfA51NxPcAUgXXGOrT8fA1o6iX/RTTC8rMkYTkV606+N 8+AIUjvUJIMWkIh57n7TzEjhjHT239a38pxQHTAwAlsFty2DQ1m2xLGT32L5b4Z/d57E 1327Kybb3t2rSAbtfLMAWRHS7rLcxcIYS5QggYjROVj9F8FrN7En8+j4t50z1qUhn+Zl MWuiyi3yNzQBkAoa4lCtOisb8LCP4CLaFSPdRAWgq1yVnLHJQVzwgeynkaYysWZo8vg/ CbpBSePgnezYtuPaJTJqMgHOhRYcmC2nSkH4NJjQoTEiHFUGTv0SvJVQF2ozND/0LlJ2 Ycug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=i0AWUVyQ2vkfP6s6U7GU8ziLPzEfu5e0rSqjUNpMGqA=; b=0H0mEPFxJRqbyAYcWIJ2bjrKcn4agrCZOXgKQbfT+psMY0RVJkUN2jYWwVtueuYS8Q PYIcVQO/RQZd8rJEAPMKqVHg3HAojn60nWiZbbGdUu9TJxj5g3F21dQHfBoOBwkXcA0G kI/YIspW5247/rEieCPJnBJUw0xlvBjGPmIC5Oa72ozMQ5uYVlNpfkVwPQ98hNGhfMuT 131iEWE68MFXzxQ6uorNPxgX4wnwbpd3UDuNxa348omBX3btUmts7HZqBRuWlA8YOB6Z puGyamWRwVnMP7Fu2W7qgggDmDoauXlzaw3CwBfSyG6EA89kDQpQJGh0ISsvhrW7DUJy VB2A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id l12si7456831edk.60.2019.11.03.23.04.44; Sun, 03 Nov 2019 23:05:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1728069AbfKDHB4 (ORCPT + 99 others); Mon, 4 Nov 2019 02:01:56 -0500 Received: from mailgw01.mediatek.com ([210.61.82.183]:43487 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726441AbfKDHB4 (ORCPT ); Mon, 4 Nov 2019 02:01:56 -0500 X-UUID: 5e9b9f67176d4ae0970fb4b8db5d9574-20191104 X-UUID: 5e9b9f67176d4ae0970fb4b8db5d9574-20191104 Received: from mtkcas06.mediatek.inc [(172.21.101.30)] by mailgw01.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.10 Build 0809 with TLS) with ESMTP id 1417561631; Mon, 04 Nov 2019 15:01:49 +0800 Received: from mtkcas09.mediatek.inc (172.21.101.178) by mtkmbs07n1.mediatek.inc (172.21.101.16) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 4 Nov 2019 15:01:46 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas09.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Mon, 4 Nov 2019 15:01:45 +0800 From: Yong Wu To: Matthias Brugger , Joerg Roedel , Will Deacon CC: Evan Green , Robin Murphy , Tomasz Figa , , , , , , , , Nicolas Boichat , , , , Subject: [PATCH v5 3/7] iommu/mediatek: Use gather to achieve the tlb range flush Date: Mon, 4 Nov 2019 15:01:04 +0800 Message-ID: <1572850868-22315-4-git-send-email-yong.wu@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1572850868-22315-1-git-send-email-yong.wu@mediatek.com> References: <1572850868-22315-1-git-send-email-yong.wu@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use the iommu_gather mechanism to achieve the tlb range flush. Gather the iova range in the "tlb_add_page", then flush the merged iova range in iotlb_sync. Suggested-by: Tomasz Figa Signed-off-by: Yong Wu --- drivers/iommu/mtk_iommu.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index c2f6c78..81ac95f 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -245,11 +245,9 @@ static void mtk_iommu_tlb_flush_page_nosync(struct iommu_iotlb_gather *gather, void *cookie) { struct mtk_iommu_data *data = cookie; - unsigned long flags; + struct iommu_domain *domain = &data->m4u_dom->domain; - spin_lock_irqsave(&data->tlb_lock, flags); - mtk_iommu_tlb_add_flush_nosync(iova, granule, granule, true, cookie); - spin_unlock_irqrestore(&data->tlb_lock, flags); + iommu_iotlb_gather_add_page(domain, gather, iova, granule); } static const struct iommu_flush_ops mtk_iommu_flush_ops = { @@ -469,9 +467,15 @@ static void mtk_iommu_iotlb_sync(struct iommu_domain *domain, struct iommu_iotlb_gather *gather) { struct mtk_iommu_data *data = mtk_iommu_get_m4u_data(); + size_t length = gather->end - gather->start; unsigned long flags; + if (gather->start == ULONG_MAX) + return; + spin_lock_irqsave(&data->tlb_lock, flags); + mtk_iommu_tlb_add_flush_nosync(gather->start, length, gather->pgsize, + false, data); mtk_iommu_tlb_sync(data); spin_unlock_irqrestore(&data->tlb_lock, flags); } -- 1.9.1