Skip to content

Commit 0892c49

Browse files
Sam Protsenkojoergroedel
authored andcommitted
iommu/exynos: Add SysMMU v7 register set
SysMMU v7 might have different register layouts (VM capable or non-VM capable). Virtual Machine registers (if present) implement multiple translation domains. If VM registers are not present, the driver shouldn't try to access those. Check which layout is implemented in current SysMMU module (by reading the capability registers) and prepare the corresponding variant structure for further usage. Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org> Acked-by: Marek Szyprowski <m.szyprowski@samsung.com> Link: https://lore.kernel.org/r/20220714165550.8884-6-semen.protsenko@linaro.org Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent 2125afb commit 0892c49

1 file changed

Lines changed: 47 additions & 3 deletions

File tree

drivers/iommu/exynos-iommu.c

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ static u32 lv2ent_offset(sysmmu_iova_t iova)
135135
#define CFG_SYSSEL (1 << 22) /* System MMU 3.2 only */
136136
#define CFG_FLPDCACHE (1 << 20) /* System MMU 3.2+ only */
137137

138+
#define CAPA0_CAPA1_EXIST BIT(11)
139+
#define CAPA1_VCR_ENABLED BIT(14)
140+
138141
/* common registers */
139142
#define REG_MMU_CTRL 0x000
140143
#define REG_MMU_CFG 0x004
@@ -157,6 +160,10 @@ static u32 lv2ent_offset(sysmmu_iova_t iova)
157160
#define REG_V5_FAULT_AR_VA 0x070
158161
#define REG_V5_FAULT_AW_VA 0x080
159162

163+
/* v7.x registers */
164+
#define REG_V7_CAPA0 0x870
165+
#define REG_V7_CAPA1 0x874
166+
160167
#define has_sysmmu(dev) (dev_iommu_priv_get(dev) != NULL)
161168

162169
static struct device *dma_dev;
@@ -276,6 +283,9 @@ struct sysmmu_drvdata {
276283

277284
struct iommu_device iommu; /* IOMMU core handle */
278285
const struct sysmmu_variant *variant; /* version specific data */
286+
287+
/* v7 fields */
288+
bool has_vcr; /* virtual machine control register */
279289
};
280290

281291
#define SYSMMU_REG(data, reg) ((data)->sfrbase + (data)->variant->reg)
@@ -289,7 +299,7 @@ static const struct sysmmu_variant sysmmu_v1_variant = {
289299
.int_clear = 0x1c,
290300
};
291301

292-
/* SysMMU v5 */
302+
/* SysMMU v5 and v7 (non-VM capable) */
293303
static const struct sysmmu_variant sysmmu_v5_variant = {
294304
.pt_base = 0x0c,
295305
.flush_all = 0x10,
@@ -301,6 +311,18 @@ static const struct sysmmu_variant sysmmu_v5_variant = {
301311
.int_clear = 0x64,
302312
};
303313

314+
/* SysMMU v7: VM capable register set */
315+
static const struct sysmmu_variant sysmmu_v7_vm_variant = {
316+
.pt_base = 0x800c,
317+
.flush_all = 0x8010,
318+
.flush_entry = 0x8014,
319+
.flush_range = 0x8018,
320+
.flush_start = 0x8020,
321+
.flush_end = 0x8024,
322+
.int_status = 0x60,
323+
.int_clear = 0x64,
324+
};
325+
304326
static struct exynos_iommu_domain *to_exynos_domain(struct iommu_domain *dom)
305327
{
306328
return container_of(dom, struct exynos_iommu_domain, domain);
@@ -380,6 +402,20 @@ static void __sysmmu_disable_clocks(struct sysmmu_drvdata *data)
380402
clk_disable_unprepare(data->clk_master);
381403
}
382404

405+
static bool __sysmmu_has_capa1(struct sysmmu_drvdata *data)
406+
{
407+
u32 capa0 = readl(data->sfrbase + REG_V7_CAPA0);
408+
409+
return capa0 & CAPA0_CAPA1_EXIST;
410+
}
411+
412+
static void __sysmmu_get_vcr(struct sysmmu_drvdata *data)
413+
{
414+
u32 capa1 = readl(data->sfrbase + REG_V7_CAPA1);
415+
416+
data->has_vcr = capa1 & CAPA1_VCR_ENABLED;
417+
}
418+
383419
static void __sysmmu_get_version(struct sysmmu_drvdata *data)
384420
{
385421
u32 ver;
@@ -397,10 +433,18 @@ static void __sysmmu_get_version(struct sysmmu_drvdata *data)
397433
dev_dbg(data->sysmmu, "hardware version: %d.%d\n",
398434
MMU_MAJ_VER(data->version), MMU_MIN_VER(data->version));
399435

400-
if (MMU_MAJ_VER(data->version) < 5)
436+
if (MMU_MAJ_VER(data->version) < 5) {
401437
data->variant = &sysmmu_v1_variant;
402-
else
438+
} else if (MMU_MAJ_VER(data->version) < 7) {
403439
data->variant = &sysmmu_v5_variant;
440+
} else {
441+
if (__sysmmu_has_capa1(data))
442+
__sysmmu_get_vcr(data);
443+
if (data->has_vcr)
444+
data->variant = &sysmmu_v7_vm_variant;
445+
else
446+
data->variant = &sysmmu_v5_variant;
447+
}
404448

405449
__sysmmu_disable_clocks(data);
406450
}

0 commit comments

Comments
 (0)