diff options
author | Yong Wu <yong.wu@mediatek.com> | 2018-03-17 21:52:54 -0400 |
---|---|---|
committer | Joerg Roedel <jroedel@suse.de> | 2018-03-21 07:13:57 -0400 |
commit | 70ca608b2ec6dafa6bb1c2b0691852fc78f8f717 (patch) | |
tree | 9e1bc273b91fefbde05e482bd7a7539ba37430a4 | |
parent | f3e827d73ed454053d2ce6a4bf021b5adde3ac54 (diff) |
iommu/mediatek: Fix protect memory setting
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>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
-rw-r--r-- | drivers/iommu/mtk_iommu.c | 15 | ||||
-rw-r--r-- | 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 f227d73e7bf6..f2832a10fcea 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c | |||
@@ -60,7 +60,7 @@ | |||
60 | (((prot) & 0x3) << F_MMU_TF_PROTECT_SEL_SHIFT(data)) | 60 | (((prot) & 0x3) << F_MMU_TF_PROTECT_SEL_SHIFT(data)) |
61 | 61 | ||
62 | #define REG_MMU_IVRP_PADDR 0x114 | 62 | #define REG_MMU_IVRP_PADDR 0x114 |
63 | #define F_MMU_IVRP_PA_SET(pa, ext) (((pa) >> 1) | ((!!(ext)) << 31)) | 63 | |
64 | #define REG_MMU_VLD_PA_RNG 0x118 | 64 | #define REG_MMU_VLD_PA_RNG 0x118 |
65 | #define F_MMU_VLD_PA_RNG(EA, SA) (((EA) << 8) | (SA)) | 65 | #define F_MMU_VLD_PA_RNG(EA, SA) (((EA) << 8) | (SA)) |
66 | 66 | ||
@@ -539,8 +539,13 @@ static int mtk_iommu_hw_init(const struct mtk_iommu_data *data) | |||
539 | F_INT_PRETETCH_TRANSATION_FIFO_FAULT; | 539 | F_INT_PRETETCH_TRANSATION_FIFO_FAULT; |
540 | writel_relaxed(regval, data->base + REG_MMU_INT_MAIN_CONTROL); | 540 | writel_relaxed(regval, data->base + REG_MMU_INT_MAIN_CONTROL); |
541 | 541 | ||
542 | writel_relaxed(F_MMU_IVRP_PA_SET(data->protect_base, data->enable_4GB), | 542 | if (data->m4u_plat == M4U_MT8173) |
543 | data->base + REG_MMU_IVRP_PADDR); | 543 | regval = (data->protect_base >> 1) | (data->enable_4GB << 31); |
544 | else | ||
545 | regval = lower_32_bits(data->protect_base) | | ||
546 | upper_32_bits(data->protect_base); | ||
547 | writel_relaxed(regval, data->base + REG_MMU_IVRP_PADDR); | ||
548 | |||
544 | if (data->enable_4GB && data->m4u_plat != M4U_MT8173) { | 549 | if (data->enable_4GB && data->m4u_plat != M4U_MT8173) { |
545 | /* | 550 | /* |
546 | * If 4GB mode is enabled, the validate PA range is from | 551 | * 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) | |||
695 | reg->ctrl_reg = readl_relaxed(base + REG_MMU_CTRL_REG); | 700 | reg->ctrl_reg = readl_relaxed(base + REG_MMU_CTRL_REG); |
696 | reg->int_control0 = readl_relaxed(base + REG_MMU_INT_CONTROL0); | 701 | reg->int_control0 = readl_relaxed(base + REG_MMU_INT_CONTROL0); |
697 | reg->int_main_control = readl_relaxed(base + REG_MMU_INT_MAIN_CONTROL); | 702 | reg->int_main_control = readl_relaxed(base + REG_MMU_INT_MAIN_CONTROL); |
703 | reg->ivrp_paddr = readl_relaxed(base + REG_MMU_IVRP_PADDR); | ||
698 | clk_disable_unprepare(data->bclk); | 704 | clk_disable_unprepare(data->bclk); |
699 | return 0; | 705 | return 0; |
700 | } | 706 | } |
@@ -717,8 +723,7 @@ static int __maybe_unused mtk_iommu_resume(struct device *dev) | |||
717 | writel_relaxed(reg->ctrl_reg, base + REG_MMU_CTRL_REG); | 723 | writel_relaxed(reg->ctrl_reg, base + REG_MMU_CTRL_REG); |
718 | writel_relaxed(reg->int_control0, base + REG_MMU_INT_CONTROL0); | 724 | writel_relaxed(reg->int_control0, base + REG_MMU_INT_CONTROL0); |
719 | writel_relaxed(reg->int_main_control, base + REG_MMU_INT_MAIN_CONTROL); | 725 | writel_relaxed(reg->int_main_control, base + REG_MMU_INT_MAIN_CONTROL); |
720 | writel_relaxed(F_MMU_IVRP_PA_SET(data->protect_base, data->enable_4GB), | 726 | writel_relaxed(reg->ivrp_paddr, base + REG_MMU_IVRP_PADDR); |
721 | base + REG_MMU_IVRP_PADDR); | ||
722 | if (data->m4u_dom) | 727 | if (data->m4u_dom) |
723 | writel(data->m4u_dom->cfg.arm_v7s_cfg.ttbr[0], | 728 | writel(data->m4u_dom->cfg.arm_v7s_cfg.ttbr[0], |
724 | base + REG_MMU_PT_BASE_ADDR); | 729 | base + REG_MMU_PT_BASE_ADDR); |
diff --git a/drivers/iommu/mtk_iommu.h b/drivers/iommu/mtk_iommu.h index b4451a1c7c2f..778498b8633f 100644 --- a/drivers/iommu/mtk_iommu.h +++ b/drivers/iommu/mtk_iommu.h | |||
@@ -32,6 +32,7 @@ struct mtk_iommu_suspend_reg { | |||
32 | u32 ctrl_reg; | 32 | u32 ctrl_reg; |
33 | u32 int_control0; | 33 | u32 int_control0; |
34 | u32 int_main_control; | 34 | u32 int_main_control; |
35 | u32 ivrp_paddr; | ||
35 | }; | 36 | }; |
36 | 37 | ||
37 | enum mtk_iommu_plat { | 38 | enum mtk_iommu_plat { |