Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1434289ybl; Fri, 23 Aug 2019 20:21:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqxG3W6gt74NZSw7OEUNzVtGVh2R/EF60vcLX43Pe5VyF53qv+1leD3UvRqQ7Wf83IT0ubr3 X-Received: by 2002:a17:90a:d146:: with SMTP id t6mr8557408pjw.76.1566616898008; Fri, 23 Aug 2019 20:21:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566616897; cv=none; d=google.com; s=arc-20160816; b=O0R4TE26sr2SOUgZXVgPRgWa8UgXXa5soaEB08u63N5kqmInOxDqFRroigoIIPkkD8 D3YDtfb6DqdbDPRV6SoYj8KMQJUezo+KcaaS2Grrp5UTXuMJQPR0v5q6RWM+7tPRqh7J RfZ49CpwxFQLn5SkzKOTan/a1YCwRLq6r2IRs9/RQlMFK13Z7J7Ej9N4Zq8bBb6iRwMG rTNe4cm1GTnjOfYg0D+u1MKNiOgPZPdvn7RIEFcBOY6PSjr6r0rDNBUiiw14Id2R/6Kq gUKK13vrWCklk3NVh0B4935PVwYQKn5RtUhBuNGVEAybdyjBA8Qk3Gsahv5gqA4c3jaR t8aQ== 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=rNQxWVia7Ut5w8dYsuiBzshQh1bnewIeVM9Z9CJ1/PA=; b=y9arm1no93jfuy0YKyjCqDecS2mIAx6E39Srspq2+1YFf7q7uEOvCQw287U7PG6TZt 5ariEV4F3CPnfLXfkBi4XFIPT8W+PZ5dsu2eRqkFdgf2mKS0kXSrPskF5362hAztZHjc MjQxkpu71AhNjLzB3WVulrn4ZIcoWBkIhlu9qj+VftOEzp5iYa9RK1BTZiqWLCTQZjON TTHtasBX1glNZMFfyfrgGzhRDfqpFVplix37PgylkhPJXobZo6sOp3FulHZHDFH05NWz pTgDJoTWSRNVFM1vATNY+oARCrPQ3luU+Q74jlVi6ODwF43hFF1I0p1KpYJC8sY99VHj oLiA== 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 k72si3361596pge.95.2019.08.23.20.21.22; Fri, 23 Aug 2019 20:21:37 -0700 (PDT) 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 S1726979AbfHXDUf (ORCPT + 99 others); Fri, 23 Aug 2019 23:20:35 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:55305 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726385AbfHXDUf (ORCPT ); Fri, 23 Aug 2019 23:20:35 -0400 X-UUID: ad9e56ca1daa4d6fbced1c481d6266fd-20190824 X-UUID: ad9e56ca1daa4d6fbced1c481d6266fd-20190824 Received: from mtkcas07.mediatek.inc [(172.21.101.84)] by mailgw02.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.10 Build 0707 with TLS) with ESMTP id 612082373; Sat, 24 Aug 2019 11:03:39 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs07n1.mediatek.inc (172.21.101.16) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Sat, 24 Aug 2019 11:03:31 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Sat, 24 Aug 2019 11:03:30 +0800 From: Yong Wu To: Joerg Roedel , Matthias Brugger , Robin Murphy , Will Deacon CC: Rob Herring , Evan Green , Tomasz Figa , , , , , , , , , Nicolas Boichat , , Matthias Kaehlcke , , , Subject: [PATCH v11 05/23] iommu/mediatek: Fix iova_to_phys PA start for 4GB mode Date: Sat, 24 Aug 2019 11:01:50 +0800 Message-ID: <1566615728-26388-6-git-send-email-yong.wu@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1566615728-26388-1-git-send-email-yong.wu@mediatek.com> References: <1566615728-26388-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 In M4U 4GB mode, the physical address is remapped as below: CPU Physical address: ==================== 0 1G 2G 3G 4G 5G |---A---|---B---|---C---|---D---|---E---| +--I/O--+------------Memory-------------+ IOMMU output physical address: ============================= 4G 5G 6G 7G 8G |---E---|---B---|---C---|---D---| +------------Memory-------------+ The Region 'A'(I/O) can not be mapped by M4U; For Region 'B'/'C'/'D', the bit32 of the CPU physical address always is needed to set, and for Region 'E', the CPU physical address keep as is. something looks like this: CPU PA -> M4U OUTPUT PA 0x4000_0000 0x1_4000_0000 (Add bit32) 0x8000_0000 0x1_8000_0000 ... 0xc000_0000 0x1_c000_0000 ... 0x1_0000_0000 0x1_0000_0000 (No change) Additionally, the iommu consumers always use the CPU phyiscal address. The PA in the iova_to_phys that is got from v7s always is u32, But from the CPU point of view, PA only need add BIT(32) when PA < 0x4000_0000. Fixes: 30e2fccf9512 ("iommu/mediatek: Enlarge the validate PA range for 4GB mode") Signed-off-by: Yong Wu --- drivers/iommu/mtk_iommu.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index c6e6dc3..9ba2706 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -107,6 +107,30 @@ struct mtk_iommu_domain { static const struct iommu_ops mtk_iommu_ops; +/* + * In M4U 4GB mode, the physical address is remapped as below: + * + * CPU Physical address: + * ==================== + * + * 0 1G 2G 3G 4G 5G + * |---A---|---B---|---C---|---D---|---E---| + * +--I/O--+------------Memory-------------+ + * + * IOMMU output physical address: + * ============================= + * + * 4G 5G 6G 7G 8G + * |---E---|---B---|---C---|---D---| + * +------------Memory-------------+ + * + * The Region 'A'(I/O) can NOT be mapped by M4U; For Region 'B'/'C'/'D', the + * bit32 of the CPU physical address always is needed to set, and for Region + * 'E', the CPU physical address keep as is. + * Additionally, The iommu consumers always use the CPU phyiscal address. + */ +#define MTK_IOMMU_4GB_MODE_REMAP_BASE 0x40000000 + static LIST_HEAD(m4ulist); /* List all the M4U HWs */ #define for_each_m4u(data) list_for_each_entry(data, &m4ulist, list) @@ -401,7 +425,7 @@ static phys_addr_t mtk_iommu_iova_to_phys(struct iommu_domain *domain, pa = dom->iop->iova_to_phys(dom->iop, iova); spin_unlock_irqrestore(&dom->pgtlock, flags); - if (data->enable_4GB) + if (data->enable_4GB && pa < MTK_IOMMU_4GB_MODE_REMAP_BASE) pa |= BIT_ULL(32); return pa; -- 1.9.1