Skip to content

Commit e24453e

Browse files
YongWu-HFjoergroedel
authored andcommitted
iommu/mediatek: Initialise bank HW for each a bank
The mt8195 IOMMU HW max support 5 banks, and regarding the banks' registers, it looks like: ---------------------------------------- |bank0 | bank1 | bank2 | bank3 | bank4| ---------------------------------------- |global | |control| null |regs | ----------------------------------------- |bank |bank |bank |bank |bank | |regs |regs |regs |regs |regs | | | | | | | ----------------------------------------- Each bank has some special bank registers and it share bank0's global control registers. this patch initialise the bank hw with the bankid. In the hw_init, we always initialise bank0's control register since we don't know if the bank0 is initialised. Additionally, About each bank's register base, always delta 0x1000. like bank[x + 1] = bank[x] + 0x1000. Signed-off-by: Yong Wu <[email protected]> Reviewed-by: AngeloGioacchino Del Regno <[email protected]> Reviewed-by: Matthias Brugger <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 99ca022 commit e24453e

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

drivers/iommu/mtk_iommu.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ static void mtk_iommu_unbind(struct device *dev)
259259

260260
static const struct iommu_ops mtk_iommu_ops;
261261

262-
static int mtk_iommu_hw_init(const struct mtk_iommu_data *data);
262+
static int mtk_iommu_hw_init(const struct mtk_iommu_data *data, unsigned int bankid);
263263

264264
#define MTK_IOMMU_TLB_ADDR(iova) ({ \
265265
dma_addr_t _addr = iova; \
@@ -642,12 +642,14 @@ static int mtk_iommu_attach_device(struct iommu_domain *domain,
642642

643643
mutex_lock(&data->mutex);
644644
bank = &data->bank[bankid];
645-
if (!bank->m4u_dom) { /* Initialize the M4U HW */
645+
if (!bank->m4u_dom) { /* Initialize the M4U HW for each a BANK */
646646
ret = pm_runtime_resume_and_get(m4udev);
647-
if (ret < 0)
647+
if (ret < 0) {
648+
dev_err(m4udev, "pm get fail(%d) in attach.\n", ret);
648649
goto err_unlock;
650+
}
649651

650-
ret = mtk_iommu_hw_init(data);
652+
ret = mtk_iommu_hw_init(data, bankid);
651653
if (ret) {
652654
pm_runtime_put(m4udev);
653655
goto err_unlock;
@@ -897,11 +899,16 @@ static const struct iommu_ops mtk_iommu_ops = {
897899
}
898900
};
899901

900-
static int mtk_iommu_hw_init(const struct mtk_iommu_data *data)
902+
static int mtk_iommu_hw_init(const struct mtk_iommu_data *data, unsigned int bankid)
901903
{
904+
const struct mtk_iommu_bank_data *bankx = &data->bank[bankid];
902905
const struct mtk_iommu_bank_data *bank0 = &data->bank[0];
903906
u32 regval;
904907

908+
/*
909+
* Global control settings are in bank0. May re-init these global registers
910+
* since no sure if there is bank0 consumers.
911+
*/
905912
if (data->plat_data->m4u_plat == M4U_MT8173) {
906913
regval = F_MMU_PREFETCH_RT_REPLACE_MOD |
907914
F_MMU_TF_PROT_TO_PROGRAM_ADDR_MT8173;
@@ -944,13 +951,14 @@ static int mtk_iommu_hw_init(const struct mtk_iommu_data *data)
944951
}
945952
writel_relaxed(regval, bank0->base + REG_MMU_MISC_CTRL);
946953

954+
/* Independent settings for each bank */
947955
regval = F_L2_MULIT_HIT_EN |
948956
F_TABLE_WALK_FAULT_INT_EN |
949957
F_PREETCH_FIFO_OVERFLOW_INT_EN |
950958
F_MISS_FIFO_OVERFLOW_INT_EN |
951959
F_PREFETCH_FIFO_ERR_INT_EN |
952960
F_MISS_FIFO_ERR_INT_EN;
953-
writel_relaxed(regval, bank0->base + REG_MMU_INT_CONTROL0);
961+
writel_relaxed(regval, bankx->base + REG_MMU_INT_CONTROL0);
954962

955963
regval = F_INT_TRANSLATION_FAULT |
956964
F_INT_MAIN_MULTI_HIT_FAULT |
@@ -959,19 +967,19 @@ static int mtk_iommu_hw_init(const struct mtk_iommu_data *data)
959967
F_INT_TLB_MISS_FAULT |
960968
F_INT_MISS_TRANSACTION_FIFO_FAULT |
961969
F_INT_PRETETCH_TRANSATION_FIFO_FAULT;
962-
writel_relaxed(regval, bank0->base + REG_MMU_INT_MAIN_CONTROL);
970+
writel_relaxed(regval, bankx->base + REG_MMU_INT_MAIN_CONTROL);
963971

964972
if (MTK_IOMMU_HAS_FLAG(data->plat_data, HAS_LEGACY_IVRP_PADDR))
965973
regval = (data->protect_base >> 1) | (data->enable_4GB << 31);
966974
else
967975
regval = lower_32_bits(data->protect_base) |
968976
upper_32_bits(data->protect_base);
969-
writel_relaxed(regval, bank0->base + REG_MMU_IVRP_PADDR);
977+
writel_relaxed(regval, bankx->base + REG_MMU_IVRP_PADDR);
970978

971-
if (devm_request_irq(bank0->parent_dev, bank0->irq, mtk_iommu_isr, 0,
972-
dev_name(bank0->parent_dev), (void *)bank0)) {
973-
writel_relaxed(0, bank0->base + REG_MMU_PT_BASE_ADDR);
974-
dev_err(bank0->parent_dev, "Failed @ IRQ-%d Request\n", bank0->irq);
979+
if (devm_request_irq(bankx->parent_dev, bankx->irq, mtk_iommu_isr, 0,
980+
dev_name(bankx->parent_dev), (void *)bankx)) {
981+
writel_relaxed(0, bankx->base + REG_MMU_PT_BASE_ADDR);
982+
dev_err(bankx->parent_dev, "Failed @ IRQ-%d Request\n", bankx->irq);
975983
return -ENODEV;
976984
}
977985

0 commit comments

Comments
 (0)