Skip to content

Commit 8d2c749

Browse files
YongWu-HFwilldeacon
authored andcommitted
iommu/mediatek: Support master use iova over 32bit
After extending v7s, our pagetable already support iova reach 16GB(34bit). the master got the iova via dma_alloc_attrs may reach 34bits, but its HW register still is 32bit. then how to set the bit32/bit33 iova? this depend on a SMI larb setting(bank_sel). we separate whole 16GB iova to four banks: bank: 0: 0~4G; 1: 4~8G; 2: 8-12G; 3: 12-16G; The bank number is (iova >> 32). We will preassign which bank the larbs belong to. currently we don't have a interface for master to adjust its bank number. Each a bank is a iova_region which is a independent iommu-domain. the iova range for each iommu-domain can't cross 4G. Signed-off-by: Yong Wu <[email protected]> Acked-by: Krzysztof Kozlowski <[email protected]> #for memory part Reviewed-by: Tomasz Figa <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent ab1d528 commit 8d2c749

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

drivers/iommu/mtk_iommu.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -345,21 +345,27 @@ static int mtk_iommu_get_domain_id(struct device *dev,
345345
return -EINVAL;
346346
}
347347

348-
static void mtk_iommu_config(struct mtk_iommu_data *data,
349-
struct device *dev, bool enable)
348+
static void mtk_iommu_config(struct mtk_iommu_data *data, struct device *dev,
349+
bool enable, unsigned int domid)
350350
{
351351
struct mtk_smi_larb_iommu *larb_mmu;
352352
unsigned int larbid, portid;
353353
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
354+
const struct mtk_iommu_iova_region *region;
354355
int i;
355356

356357
for (i = 0; i < fwspec->num_ids; ++i) {
357358
larbid = MTK_M4U_TO_LARB(fwspec->ids[i]);
358359
portid = MTK_M4U_TO_PORT(fwspec->ids[i]);
360+
359361
larb_mmu = &data->larb_imu[larbid];
360362

361-
dev_dbg(dev, "%s iommu port: %d\n",
362-
enable ? "enable" : "disable", portid);
363+
region = data->plat_data->iova_region + domid;
364+
larb_mmu->bank[portid] = upper_32_bits(region->iova_base);
365+
366+
dev_dbg(dev, "%s iommu for larb(%s) port %d dom %d bank %d.\n",
367+
enable ? "enable" : "disable", dev_name(larb_mmu->dev),
368+
portid, domid, larb_mmu->bank[portid]);
363369

364370
if (enable)
365371
larb_mmu->mmu |= MTK_SMI_MMU_EN(portid);
@@ -477,7 +483,7 @@ static int mtk_iommu_attach_device(struct iommu_domain *domain,
477483
pm_runtime_put(m4udev);
478484
}
479485

480-
mtk_iommu_config(data, dev, true);
486+
mtk_iommu_config(data, dev, true, domid);
481487
return 0;
482488
}
483489

@@ -489,7 +495,7 @@ static void mtk_iommu_detach_device(struct iommu_domain *domain,
489495
if (!data)
490496
return;
491497

492-
mtk_iommu_config(data, dev, false);
498+
mtk_iommu_config(data, dev, false, 0);
493499
}
494500

495501
static int mtk_iommu_map(struct iommu_domain *domain, unsigned long iova,

drivers/memory/mtk-smi.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
/* mt2712 */
4545
#define SMI_LARB_NONSEC_CON(id) (0x380 + ((id) * 4))
4646
#define F_MMU_EN BIT(0)
47+
#define BANK_SEL(id) ({ \
48+
u32 _id = (id) & 0x3; \
49+
(_id << 8 | _id << 10 | _id << 12 | _id << 14); \
50+
})
4751

4852
/* SMI COMMON */
4953
#define SMI_BUS_SEL 0x220
@@ -88,6 +92,7 @@ struct mtk_smi_larb { /* larb: local arbiter */
8892
const struct mtk_smi_larb_gen *larb_gen;
8993
int larbid;
9094
u32 *mmu;
95+
unsigned char *bank;
9196
};
9297

9398
static int mtk_smi_clk_enable(const struct mtk_smi *smi)
@@ -154,6 +159,7 @@ mtk_smi_larb_bind(struct device *dev, struct device *master, void *data)
154159
if (dev == larb_mmu[i].dev) {
155160
larb->larbid = i;
156161
larb->mmu = &larb_mmu[i].mmu;
162+
larb->bank = larb_mmu[i].bank;
157163
return 0;
158164
}
159165
}
@@ -172,6 +178,7 @@ static void mtk_smi_larb_config_port_gen2_general(struct device *dev)
172178
for_each_set_bit(i, (unsigned long *)larb->mmu, 32) {
173179
reg = readl_relaxed(larb->base + SMI_LARB_NONSEC_CON(i));
174180
reg |= F_MMU_EN;
181+
reg |= BANK_SEL(larb->bank[i]);
175182
writel(reg, larb->base + SMI_LARB_NONSEC_CON(i));
176183
}
177184
}

include/soc/mediatek/smi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
struct mtk_smi_larb_iommu {
1717
struct device *dev;
1818
unsigned int mmu;
19+
unsigned char bank[32];
1920
};
2021

2122
/*

0 commit comments

Comments
 (0)