Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2251631imm; Mon, 28 May 2018 04:48:31 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqH6Xiwd2u1MoJGCXO6wuCA8BqSS+bmRyQImunZIFFPnBcsILqBKpbXlq2hPiF6SWtsQZEw X-Received: by 2002:a65:49cb:: with SMTP id t11-v6mr9911917pgs.218.1527508111896; Mon, 28 May 2018 04:48:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527508111; cv=none; d=google.com; s=arc-20160816; b=cmR9fiZYluzs0O9paRUmrnN2asHEosoMtHzIbxoLizuY0YWk4Mi5h9xPh+ctnAOZv3 OMVL5IV6f5/18ilug44pzBy3MfXrQ7RLe2MqPS6RRUboq3FXu+lvbfNaJz13kk7Dm2Vv FEOhBL9nb7itsNOPCqhQqrw+4tyoTxUNnZYIzKhpZTCDKKEVaD4AMwzom/T/mk2qKhGo 7SEMCICWMzp0lJEH+S8G4WAasyN+0j+VVHYdCQhP/w/3Mbq3KC87cUZnRtGYzbnmL5mf +eMfYvajG55ucCh88tcEQj8xyKnzkql73AiDgMaSc81zMYzrium915WMq2rpTfy80mRb k1Ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=RUguEI11HjH5SyVKG+fa7qxa6//kH1PCB7a2ypdJZV4=; b=kZkMRQCazTRUx12A8PbKPJyMySw0Z70qbSZ8o0hy9pKwGm6wCHM991+t2gjcXTwV1d lOKac/3fGKhFXPLmgOsuIINNFsN1j8D5Dzk9IxKyJy/sfvv8pcxTiankpKFfYQyQBrEh 7b6LrXST22WHoIwxJtVpzSs0ElKfjvKYytfRGKxDYYoiHxB2ef2Auc9MjfnxFya1KCOP XcNn45/Abl0a9SD4jNJgJiZ739Lk3YN7AI6kyFCVN6TQ8ErKXcxp9ZKfL3DNvpPPu74S +TZq9OI8pEowUb558ugMytq3xRJrdgLs1Ym3PHwWi5efXqGap9BHkZkRCn4YU+iWeuZ6 dreQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=b9ScjRRW; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d14-v6si2965450pln.206.2018.05.28.04.48.17; Mon, 28 May 2018 04:48:31 -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; dkim=pass header.i=@kernel.org header.s=default header.b=b9ScjRRW; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1423926AbeE1LKi (ORCPT + 99 others); Mon, 28 May 2018 07:10:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:58518 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1423896AbeE1LKb (ORCPT ); Mon, 28 May 2018 07:10:31 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 12BE820845; Mon, 28 May 2018 11:10:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527505830; bh=Xsb4GNM181jpYwlNwwqaGSj+iEhynIL5H4HDA0LNJ68=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b9ScjRRWMzuGA6VXWB+QD8aqz4mWYp53GxAjGneEM6sGBAXauZx8E8a6lzcmg0wdt L83sa79hFjW/0O7UHeK1WuwTSyFSApx0UWbcwVFrS+33HX9382RMCl329X1s943Bmx QBbpE5WgkDFbIBpYJVDM6YL0A/+aLKsiwmNU6ZFI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Honghui Zhang , Yong Wu , Joerg Roedel , Sasha Levin Subject: [PATCH 4.16 142/272] iommu/mediatek: Fix protect memory setting Date: Mon, 28 May 2018 12:02:55 +0200 Message-Id: <20180528100252.943994546@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100240.256525891@linuxfoundation.org> References: <20180528100240.256525891@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yong Wu [ Upstream commit 70ca608b2ec6dafa6bb1c2b0691852fc78f8f717 ] In MediaTek's IOMMU design, When a iommu translation fault occurs (HW can NOT translate the destination address to a valid physical address), the IOMMU HW output the dirty data into a special memory to avoid corrupting the main memory, this is called "protect memory". the register(0x114) for protect memory is a little different between mt8173 and mt2712. In the mt8173, bit[30:6] in the register represents [31:7] of the physical address. In the 4GB mode, the register bit[31] should be 1. While in the mt2712, the bits don't shift. bit[31:7] in the register represents [31:7] in the physical address, and bit[1:0] in the register represents bit[33:32] of the physical address if it has. Fixes: e6dec9230862 ("iommu/mediatek: Add mt2712 IOMMU support") Reported-by: Honghui Zhang Signed-off-by: Yong Wu Signed-off-by: Joerg Roedel Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/iommu/mtk_iommu.c | 15 ++++++++++----- drivers/iommu/mtk_iommu.h | 1 + 2 files changed, 11 insertions(+), 5 deletions(-) --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -60,7 +60,7 @@ (((prot) & 0x3) << F_MMU_TF_PROTECT_SEL_SHIFT(data)) #define REG_MMU_IVRP_PADDR 0x114 -#define F_MMU_IVRP_PA_SET(pa, ext) (((pa) >> 1) | ((!!(ext)) << 31)) + #define REG_MMU_VLD_PA_RNG 0x118 #define F_MMU_VLD_PA_RNG(EA, SA) (((EA) << 8) | (SA)) @@ -539,8 +539,13 @@ static int mtk_iommu_hw_init(const struc F_INT_PRETETCH_TRANSATION_FIFO_FAULT; writel_relaxed(regval, data->base + REG_MMU_INT_MAIN_CONTROL); - writel_relaxed(F_MMU_IVRP_PA_SET(data->protect_base, data->enable_4GB), - data->base + REG_MMU_IVRP_PADDR); + if (data->m4u_plat == M4U_MT8173) + regval = (data->protect_base >> 1) | (data->enable_4GB << 31); + else + regval = lower_32_bits(data->protect_base) | + upper_32_bits(data->protect_base); + writel_relaxed(regval, data->base + REG_MMU_IVRP_PADDR); + if (data->enable_4GB && data->m4u_plat != M4U_MT8173) { /* * If 4GB mode is enabled, the validate PA range is from @@ -695,6 +700,7 @@ static int __maybe_unused mtk_iommu_susp reg->ctrl_reg = readl_relaxed(base + REG_MMU_CTRL_REG); reg->int_control0 = readl_relaxed(base + REG_MMU_INT_CONTROL0); reg->int_main_control = readl_relaxed(base + REG_MMU_INT_MAIN_CONTROL); + reg->ivrp_paddr = readl_relaxed(base + REG_MMU_IVRP_PADDR); clk_disable_unprepare(data->bclk); return 0; } @@ -717,8 +723,7 @@ static int __maybe_unused mtk_iommu_resu writel_relaxed(reg->ctrl_reg, base + REG_MMU_CTRL_REG); writel_relaxed(reg->int_control0, base + REG_MMU_INT_CONTROL0); writel_relaxed(reg->int_main_control, base + REG_MMU_INT_MAIN_CONTROL); - writel_relaxed(F_MMU_IVRP_PA_SET(data->protect_base, data->enable_4GB), - base + REG_MMU_IVRP_PADDR); + writel_relaxed(reg->ivrp_paddr, base + REG_MMU_IVRP_PADDR); if (data->m4u_dom) writel(data->m4u_dom->cfg.arm_v7s_cfg.ttbr[0], base + REG_MMU_PT_BASE_ADDR); --- a/drivers/iommu/mtk_iommu.h +++ b/drivers/iommu/mtk_iommu.h @@ -32,6 +32,7 @@ struct mtk_iommu_suspend_reg { u32 ctrl_reg; u32 int_control0; u32 int_main_control; + u32 ivrp_paddr; }; enum mtk_iommu_plat {