LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] iommu/mediatek: Fix protect memory setting
@ 2018-03-18  1:52 Yong Wu
  2018-03-20 18:57 ` Joerg Roedel
  0 siblings, 1 reply; 5+ messages in thread
From: Yong Wu @ 2018-03-18  1:52 UTC (permalink / raw)
  To: Joerg Roedel, Matthias Brugger
  Cc: Robin Murphy, Will Deacon, Tomasz Figa, linux-mediatek,
	srv_heupstream, linux-kernel, linux-arm-kernel, iommu, arnd,
	honghui.zhang, youlin.pei, Yong Wu

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 <honghui.zhang@mediatek.com>
Signed-off-by: Yong Wu <yong.wu@mediatek.com>
---
After adding the setting above, the macro will be complex, like:
 #define F_MMU_IVRP_PA_SET(data)		({	\
	const struct mtk_iommu_data *_data =  data;	\
	phys_addr_t _pa = data->protect_base;		\
	((_data->m4u_plat == M4U_MT8173) ?		\
	((_pa >> 1) | (_data->enable_4GB << 31)) :	\
	(lower_32_bits(_pa) | (_pa >> 32)));		\
	})
And this macro is called twice(hw_init and resume).

To avoid adding this complex macro or a new function, I put
it in the code and backup its value in the suspend registers.
---
 drivers/iommu/mtk_iommu.c | 15 ++++++++++-----
 drivers/iommu/mtk_iommu.h |  1 +
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c
index f227d73..f2832a1 100644
--- 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 struct mtk_iommu_data *data)
 		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_suspend(struct device *dev)
 	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_resume(struct device *dev)
 	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);
diff --git a/drivers/iommu/mtk_iommu.h b/drivers/iommu/mtk_iommu.h
index b4451a1..778498b 100644
--- 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 {
-- 
1.8.1.1.dirty

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] iommu/mediatek: Fix protect memory setting
  2018-03-18  1:52 [PATCH] iommu/mediatek: Fix protect memory setting Yong Wu
@ 2018-03-20 18:57 ` Joerg Roedel
  2018-03-21  5:18   ` Yong Wu
  0 siblings, 1 reply; 5+ messages in thread
From: Joerg Roedel @ 2018-03-20 18:57 UTC (permalink / raw)
  To: Yong Wu
  Cc: Matthias Brugger, Robin Murphy, Will Deacon, Tomasz Figa,
	linux-mediatek, srv_heupstream, linux-kernel, linux-arm-kernel,
	iommu, arnd, honghui.zhang, youlin.pei

On Sun, Mar 18, 2018 at 09:52:54AM +0800, Yong Wu wrote:
> To avoid adding this complex macro or a new function, I put
> it in the code and backup its value in the suspend registers.

Missing Signed-off-by.

> ---
>  drivers/iommu/mtk_iommu.c | 15 ++++++++++-----
>  drivers/iommu/mtk_iommu.h |  1 +
>  2 files changed, 11 insertions(+), 5 deletions(-)


Joerg

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] iommu/mediatek: Fix protect memory setting
  2018-03-20 18:57 ` Joerg Roedel
@ 2018-03-21  5:18   ` Yong Wu
  2018-03-21 11:14     ` Joerg Roedel
  0 siblings, 1 reply; 5+ messages in thread
From: Yong Wu @ 2018-03-21  5:18 UTC (permalink / raw)
  To: Joerg Roedel
  Cc: Matthias Brugger, Robin Murphy, Will Deacon, Tomasz Figa,
	linux-mediatek, srv_heupstream, linux-kernel, linux-arm-kernel,
	iommu, arnd, honghui.zhang, youlin.pei

Hi Joerg,

On Tue, 2018-03-20 at 13:57 -0500, Joerg Roedel wrote:
> On Sun, Mar 18, 2018 at 09:52:54AM +0800, Yong Wu wrote:
> > To avoid adding this complex macro or a new function, I put
> > it in the code and backup its value in the suspend registers.
> 
> Missing Signed-off-by.

Signed-off-by and Reported-by have been added above.

====
Reported-by: Honghui Zhang <honghui.zhang@mediatek.com>
Signed-off-by: Yong Wu <yong.wu@mediatek.com>
====

> 
> > ---
> >  drivers/iommu/mtk_iommu.c | 15 ++++++++++-----
> >  drivers/iommu/mtk_iommu.h |  1 +
> >  2 files changed, 11 insertions(+), 5 deletions(-)
> 
> 
> Joerg

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] iommu/mediatek: Fix protect memory setting
  2018-03-21  5:18   ` Yong Wu
@ 2018-03-21 11:14     ` Joerg Roedel
  2018-03-22  1:13       ` Yong Wu
  0 siblings, 1 reply; 5+ messages in thread
From: Joerg Roedel @ 2018-03-21 11:14 UTC (permalink / raw)
  To: Yong Wu
  Cc: Matthias Brugger, Robin Murphy, Will Deacon, Tomasz Figa,
	linux-mediatek, srv_heupstream, linux-kernel, linux-arm-kernel,
	iommu, arnd, honghui.zhang, youlin.pei

On Wed, Mar 21, 2018 at 01:18:24PM +0800, Yong Wu wrote:
> On Tue, 2018-03-20 at 13:57 -0500, Joerg Roedel wrote:
> > On Sun, Mar 18, 2018 at 09:52:54AM +0800, Yong Wu wrote:
> > > To avoid adding this complex macro or a new function, I put
> > > it in the code and backup its value in the suspend registers.
> > 
> > Missing Signed-off-by.
> 
> Signed-off-by and Reported-by have been added above.
> 
> ====
> Reported-by: Honghui Zhang <honghui.zhang@mediatek.com>
> Signed-off-by: Yong Wu <yong.wu@mediatek.com>
> ====

Right, sorry. I was in a hurry and missed it. Patch is now applied.


Thanks,

	Joerg

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] iommu/mediatek: Fix protect memory setting
  2018-03-21 11:14     ` Joerg Roedel
@ 2018-03-22  1:13       ` Yong Wu
  0 siblings, 0 replies; 5+ messages in thread
From: Yong Wu @ 2018-03-22  1:13 UTC (permalink / raw)
  To: Joerg Roedel
  Cc: Matthias Brugger, Robin Murphy, Will Deacon, Tomasz Figa,
	linux-mediatek, srv_heupstream, linux-kernel, linux-arm-kernel,
	iommu, arnd, honghui.zhang, youlin.pei

On Wed, 2018-03-21 at 06:14 -0500, Joerg Roedel wrote:
> On Wed, Mar 21, 2018 at 01:18:24PM +0800, Yong Wu wrote:
> > On Tue, 2018-03-20 at 13:57 -0500, Joerg Roedel wrote:
> > > On Sun, Mar 18, 2018 at 09:52:54AM +0800, Yong Wu wrote:
> > > > To avoid adding this complex macro or a new function, I put
> > > > it in the code and backup its value in the suspend registers.
> > > 
> > > Missing Signed-off-by.
> > 
> > Signed-off-by and Reported-by have been added above.
> > 
> > ====
> > Reported-by: Honghui Zhang <honghui.zhang@mediatek.com>
> > Signed-off-by: Yong Wu <yong.wu@mediatek.com>
> > ====
> 
> Right, sorry. I was in a hurry and missed it. Patch is now applied.

Thanks Joerg.

> 
> 
> Thanks,
> 
> 	Joerg

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-03-22  1:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-18  1:52 [PATCH] iommu/mediatek: Fix protect memory setting Yong Wu
2018-03-20 18:57 ` Joerg Roedel
2018-03-21  5:18   ` Yong Wu
2018-03-21 11:14     ` Joerg Roedel
2018-03-22  1:13       ` Yong Wu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).