From: Yong Wu <yong.wu@mediatek.com>
To: Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>,
"Matthias Brugger" <matthias.bgg@gmail.com>
Cc: Robin Murphy <robin.murphy@arm.com>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Yong Wu <yong.wu@mediatek.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
<iommu@lists.linux.dev>, <linux-mediatek@lists.infradead.org>,
<linux-kernel@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>, <anan.sun@mediatek.com>,
<yf.wang@mediatek.com>, <mingyuan.ma@mediatek.com>,
"T . J . Mercier" <tjmercier@google.com>
Subject: [PATCH 2/4] iommu/mediatek: Add irq handle for secure bank
Date: Mon, 11 Sep 2023 09:17:49 +0800 [thread overview]
Message-ID: <20230911011751.29906-3-yong.wu@mediatek.com> (raw)
In-Reply-To: <20230911011751.29906-1-yong.wu@mediatek.com>
The secure bank registers are protected and can only be accessed in
the secure world, thus it won't be initialised in linux. In kernel, we only
need register the irq handle to report which iommu HW the secure
translation fault happen in.
We will enter the ATF to read the detail fault information. If ATF fail or
ATF isn't the debug load, we won't get the fault information, just print
a simple "secure bank fault" log.
Signed-off-by: Anan Sun <anan.sun@mediatek.com>
Signed-off-by: Yong Wu <yong.wu@mediatek.com>
---
drivers/iommu/mtk_iommu.c | 61 +++++++++++++++++++++++++++-----------
include/soc/mediatek/smi.h | 1 +
2 files changed, 45 insertions(+), 17 deletions(-)
diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c
index 4a2cffb28c61..e1faf2339b9a 100644
--- a/drivers/iommu/mtk_iommu.c
+++ b/drivers/iommu/mtk_iommu.c
@@ -465,22 +465,38 @@ static irqreturn_t mtk_iommu_isr(int irq, void *dev_id)
struct mtk_iommu_data *data = bank->parent_data;
struct mtk_iommu_domain *dom = bank->m4u_dom;
unsigned int fault_larb = MTK_INVALID_LARBID, fault_port = 0, sub_comm = 0;
- u32 int_state, regval, va34_32, pa34_32;
const struct mtk_iommu_plat_data *plat_data = data->plat_data;
+ u32 int_state = ~0, regval = 0, va34_32, pa34_32;
+ u64 fault_iova = ~0ULL, fault_pa = ~0ULL;
void __iomem *base = bank->base;
- u64 fault_iova, fault_pa;
+ struct arm_smccc_res res;
bool layer, write;
- /* Read error info from registers */
- int_state = readl_relaxed(base + REG_MMU_FAULT_ST1);
- if (int_state & F_REG_MMU0_FAULT_MASK) {
- regval = readl_relaxed(base + REG_MMU0_INT_ID);
- fault_iova = readl_relaxed(base + REG_MMU0_FAULT_VA);
- fault_pa = readl_relaxed(base + REG_MMU0_INVLD_PA);
+ if (bank->is_secure) {
+ /* Enter to secure world to Read fault status if it is secure bank. */
+ arm_smccc_smc(MTK_SIP_KERNEL_IOMMU_CONTROL,
+ IOMMU_ATF_CMD_GET_SECURE_IOMMU_STATUS,
+ bank->sec_bank_base, 0, 0, 0, 0, 0, &res);
+ if (res.a0 == 0) {
+ fault_iova = res.a1;
+ fault_pa = res.a2;
+ regval = res.a3;
+ } else {
+ dev_err_ratelimited(bank->parent_dev, "secure bank fault\n");
+ goto tlb_flush_all;
+ }
} else {
- regval = readl_relaxed(base + REG_MMU1_INT_ID);
- fault_iova = readl_relaxed(base + REG_MMU1_FAULT_VA);
- fault_pa = readl_relaxed(base + REG_MMU1_INVLD_PA);
+ /* Read error info from registers */
+ int_state = readl_relaxed(base + REG_MMU_FAULT_ST1);
+ if (int_state & F_REG_MMU0_FAULT_MASK) {
+ regval = readl_relaxed(base + REG_MMU0_INT_ID);
+ fault_iova = readl_relaxed(base + REG_MMU0_FAULT_VA);
+ fault_pa = readl_relaxed(base + REG_MMU0_INVLD_PA);
+ } else {
+ regval = readl_relaxed(base + REG_MMU1_INT_ID);
+ fault_iova = readl_relaxed(base + REG_MMU1_FAULT_VA);
+ fault_pa = readl_relaxed(base + REG_MMU1_INVLD_PA);
+ }
}
layer = fault_iova & F_MMU_FAULT_VA_LAYER_BIT;
write = fault_iova & F_MMU_FAULT_VA_WRITE_BIT;
@@ -515,16 +531,19 @@ static irqreturn_t mtk_iommu_isr(int irq, void *dev_id)
write ? IOMMU_FAULT_WRITE : IOMMU_FAULT_READ)) {
dev_err_ratelimited(
bank->parent_dev,
- "fault type=0x%x iova=0x%llx pa=0x%llx master=0x%x(larb=%d port=%d) layer=%d %s\n",
- int_state, fault_iova, fault_pa, regval, fault_larb, fault_port,
+ "bank(%u) fault type=0x%x iova=0x%llx pa=0x%llx master=0x%x(larb=%d port=%d) layer=%d %s\n",
+ bank->id, int_state, fault_iova, fault_pa, regval, fault_larb, fault_port,
layer, write ? "write" : "read");
}
/* Interrupt clear */
- regval = readl_relaxed(base + REG_MMU_INT_CONTROL0);
- regval |= F_INT_CLR_BIT;
- writel_relaxed(regval, base + REG_MMU_INT_CONTROL0);
+ if (!bank->is_secure) {
+ regval = readl_relaxed(base + REG_MMU_INT_CONTROL0);
+ regval |= F_INT_CLR_BIT;
+ writel_relaxed(regval, base + REG_MMU_INT_CONTROL0);
+ }
+tlb_flush_all:
mtk_iommu_tlb_flush_all(data);
return IRQ_HANDLED;
@@ -1333,6 +1352,14 @@ static int mtk_iommu_probe(struct platform_device *pdev)
bank->parent_dev = dev;
bank->parent_data = data;
spin_lock_init(&bank->tlb_lock);
+
+ /* Secure bank is initialised in secure world. Only need register irq here */
+ if (!bank->is_secure)
+ continue;
+ ret = devm_request_irq(bank->parent_dev, bank->irq, mtk_iommu_isr,
+ 0, dev_name(bank->parent_dev), (void *)bank);
+ if (ret)
+ return ret;
} while (++i < banks_num);
if (MTK_IOMMU_HAS_FLAG(data->plat_data, HAS_BCLK)) {
@@ -1426,7 +1453,7 @@ static void mtk_iommu_remove(struct platform_device *pdev)
pm_runtime_disable(&pdev->dev);
for (i = 0; i < data->plat_data->banks_num; i++) {
bank = &data->bank[i];
- if (!bank->m4u_dom)
+ if (!bank->m4u_dom && !data->bank[i].is_secure)
continue;
devm_free_irq(&pdev->dev, bank->irq, bank);
}
diff --git a/include/soc/mediatek/smi.h b/include/soc/mediatek/smi.h
index 000eb1cf68b7..294550240aa6 100644
--- a/include/soc/mediatek/smi.h
+++ b/include/soc/mediatek/smi.h
@@ -14,6 +14,7 @@
enum iommu_atf_cmd {
IOMMU_ATF_CMD_CONFIG_SMI_LARB, /* For mm master to en/disable iommu */
IOMMU_ATF_CMD_CONFIG_INFRA_IOMMU, /* For infra master to enable iommu */
+ IOMMU_ATF_CMD_GET_SECURE_IOMMU_STATUS, /* Get secure iommu translation fault status */
IOMMU_ATF_CMD_MAX,
};
--
2.25.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2023-09-11 1:19 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-11 1:17 iommu/mediatek: Add SVP support for mt8188 Yong Wu
2023-09-11 1:17 ` [PATCH 1/4] iommu/mediatek: Initialise the secure bank Yong Wu
2023-09-11 9:22 ` AngeloGioacchino Del Regno
2023-09-25 12:50 ` Yong Wu (吴勇)
2023-09-25 18:01 ` Alexandre Mergnat
2023-09-26 2:45 ` Yong Wu (吴勇)
2023-09-11 1:17 ` Yong Wu [this message]
2023-09-11 1:17 ` [PATCH 3/4] iommu/mediatek: Avoid access secure bank register in runtime_suspend Yong Wu
2023-09-11 1:17 ` [PATCH 4/4] iommu/mediatek: mt8188: Enable secure bank for MM IOMMU Yong Wu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230911011751.29906-3-yong.wu@mediatek.com \
--to=yong.wu@mediatek.com \
--cc=anan.sun@mediatek.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=iommu@lists.linux.dev \
--cc=joro@8bytes.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=matthias.bgg@gmail.com \
--cc=mingyuan.ma@mediatek.com \
--cc=robin.murphy@arm.com \
--cc=tjmercier@google.com \
--cc=will@kernel.org \
--cc=yf.wang@mediatek.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).