iommu/ipmmu-vmsa: IPMMU IOVA prototyping on r8a7796 ES1.0
Subsystems (2)
cover iommu/ipmmu-vmsa: IPMMU IOVA prototyping on r8a7796 ES1.0
iommu/ipmmu-vmsa: IPMMU IOVA prototyping on r8a7796 ES1.0
[PATCH/RFC 01/04] iommu: Hack to dump page table configuration on boot [PATCH/RFC 02/04] iommu/ipmmu-vmsa: VA64 mode with 32-bit IOVA [PATCH/RFC 03/04] iommu/ipmmu-vmsa: VA64 mode with 31-bit IOVA [PATCH/RFC 04/04] iommu/ipmmu-vmsa: VA64 mode with 30-bit IOVA
This series contains a collection of prototype patches to play with various IOVA space sizes on the r8a7796 IPMMU. Use one of patches 2-4 to test the desired mode and use patch 1 to dump the page table configuration on boot to see the size of the pgd and other things.
The actual goal with this activity is to play with the page table concatenation feature that is needed for 40-bit IOVA support. The Renesas IPMMU hardware according to the friendly documentation supports stage 1 translation with concatenation as opposed to other implementations that only use concatenation for stage 2 translation.
My early investigation of the IPMMMU on r8a7996 ES1.0 only allowed me to successfully scale down the IOVA from 32 to lower values. The patches in this series has allowed me to test "Initial lookup level" settings but without concatenation.
In the not so distant future my plan is to continue this activity on more recent hardware such as the r8a77965 SoC (R-Car M3-N).
--- drivers/iommu/io-pgtable-arm.c | 12 ++++ drivers/iommu/io-pgtable.c | 4 + drivers/iommu/ipmmu-vmsa.c | 116 +++++++++++++++++++++++++++------------- 3 files changed, 95 insertions(+), 37 deletions(-)
PATCH 1/4 iommu: Hack to dump page table configuration on boot
From: Magnus Damm <[email protected]>
Adjust code to output page table configuration on boot. Not for upstream merge.
---
drivers/iommu/io-pgtable-arm.c | 12 ++++++++++++ drivers/iommu/io-pgtable.c | 4 ++++ 2 files changed, 16 insertions(+)
drivers/iommu/io-pgtable-arm.c +12 -0
@@ -970,6 +970,18 @@ struct io_pgtable_init_fns io_pgtable_ar .free = arm_lpae_free_pgtable, }; +void arm_lpae_dump (struct io_pgtable_ops *ops) +{ +struct arm_lpae_io_pgtable *data =io_pgtable_ops_to_data (ops); +struct io_pgtable_cfg *cfg = &data->iop.cfg; + +pr_err ("cfg: pgsize_bitmap 0x%lx, ias %u-bit\n" , + cfg->pgsize_bitmap, cfg->ias); +pr_err ("data: %d levels, 0x%zx pgd_size, %lu pg_shift, %lu bits_per_level, pgd @ %p\n" , + data->levels, data->pgd_size, data->pg_shift, + data->bits_per_level, data->pgd); +} +#ifdef CONFIG_IOMMU_IO_PGTABLE_LPAE_SELFTEST static struct io_pgtable_cfg *cfg_cookie;
drivers/iommu/io-pgtable.c +4 -0
@@ -37,6 +37,8 @@ io_pgtable_init_table[IO_PGTABLE_NUM_FMT#endif }; +void arm_lpae_dump (struct io_pgtable_ops *ops); +struct io_pgtable_ops *alloc_io_pgtable_ops (enum io_pgtable_fmt fmt,struct io_pgtable_cfg *cfg,void *cookie)
@@ -59,6 +61,8 @@ struct io_pgtable_ops *alloc_io_pgtable_ iop->cookie = cookie; iop->cfg = *cfg; +arm_lpae_dump (&iop->ops); +return &iop->ops; }
PATCH 2/4 iommu/ipmmu-vmsa: VA64 mode with 32-bit IOVA
In reply to Magnus DammFrom: Magnus Damm <[email protected]>
Hack up the IPMMU driver to enable VM64 mode with 32-bit IOVA.
For this configuration the IPMMU hardware is configured with IMTTBCR.SL=1 and TSZ0 bits set to 0x20. This will enable a 32-bit IOVA space and use "Initial lookup level 1" (in Table D4-13 of armv8_arm.pdf) also known as "Start at first level" in IPMMU documentation.
Not for upstream merge. Tested on ULCB with r8a7796 ES1.0.
Earlier version posted as:
[PATCH/RFC] iommu/ipmmu-vmsa: Initial R-Car Gen3 VA64 mode support
The SL bit position has since then been updated to match more recent IPMMU hardware documentation.
---
drivers/iommu/ipmmu-vmsa.c | 36 +++++++++++++++++++++++++----------- 1 files changed, 25 insertions(+), 11 deletions(-)
drivers/iommu/ipmmu-vmsa.c +25 -11
@@ -42,6 +42,7 @@ struct ipmmu_features {unsigned int number_of_contexts;bool setup_imbuscr;bool twobit_imttbcr_sl0; +bool imctr_va64; };struct ipmmu_vmsa_device {
@@ -97,6 +98,7 @@ static struct ipmmu_vmsa_iommu_priv *to_#define IM_CTX_SIZE 0x40#define IMCTR 0x0000 +#define IMCTR_VA64 (1 << 29)#define IMCTR_TRE (1 << 17)#define IMCTR_AFE (1 << 16)#define IMCTR_RTSEL_MASK (3 << 4)
@@ -442,8 +444,9 @@ static int ipmmu_domain_init_context(str domain->context_id = ret; - domain->iop =alloc_io_pgtable_ops (ARM_32_LPAE_S1 , &domain->cfg, - domain); + domain->iop =alloc_io_pgtable_ops (domain->mmu->features->imctr_va64 ? +ARM_64_LPAE_S1 :ARM_32_LPAE_S1 , + &domain->cfg, domain);if (!domain->iop) {ipmmu_domain_free_context (domain->mmu->root, domain->context_id);
@@ -456,14 +459,22 @@ static int ipmmu_domain_init_context(stripmmu_ctx_write_root (domain,IMTTUBR0 , ttbr >>32 );/* -* TTBCR -* We use long descriptors with inner-shareable WBWA tables and allocate -* the whole 32-bit VA space to TTBR0. -*/ -if (domain->mmu->features->twobit_imttbcr_sl0) - tmp =IMTTBCR_SL0_TWOBIT_LVL_1 ; -else - tmp =IMTTBCR_SL0_LVL_1 ; +* For IMCTR_VA64 and ARM_64_LPAE_S1 we need lowest bits of TTBCR +*/ +if (domain->mmu->features->imctr_va64) { + tmp = (1 <<6 ) |0x20 ; + }else { +/* +* TTBCR +* We use long descriptors with inner-shareable WBWA tables +* and allocate the whole 32-bit VA space to TTBR0. +*/ + +if (domain->mmu->features->twobit_imttbcr_sl0) + tmp =IMTTBCR_SL0_TWOBIT_LVL_1 ; +else + tmp =IMTTBCR_SL0_LVL_1 ; + } ipmmu_ctx_write_root(domain, IMTTBCR, IMTTBCR_EAE | IMTTBCR_SH0_INNER_SHAREABLE | IMTTBCR_ORGN0_WB_WA |
@@ -493,7 +504,8 @@ static int ipmmu_domain_init_context(str* required when modifying the context registers. */ ipmmu_ctx_write_all (domain,IMCTR , -IMCTR_INTEN |IMCTR_FLUSH |IMCTR_MMUEN ); + (domain->mmu->features->imctr_va64 ?IMCTR_VA64 :0 ) + |IMCTR_INTEN |IMCTR_FLUSH |IMCTR_MMUEN );return 0 ; }
@@ -1018,6 +1030,7 @@ static const struct ipmmu_features ipmmu .number_of_contexts = 1, /* software only tested with one context */ .setup_imbuscr = true, .twobit_imttbcr_sl0 = false, + .imctr_va64 = false, };static const struct ipmmu_features ipmmu_features_rcar_gen3 = {
@@ -1026,6 +1039,7 @@ static const struct ipmmu_features ipmmu .number_of_contexts = 8, .setup_imbuscr = false, .twobit_imttbcr_sl0 = true, + .imctr_va64 = true, };static const struct of_device_id ipmmu_of_ids[] = {
PATCH 3/4 iommu/ipmmu-vmsa: VA64 mode with 31-bit IOVA
In reply to Magnus DammFrom: Magnus Damm <[email protected]>
Hack up the IPMMU driver to enable VM64 mode with 31-bit IOVA.
For this configuration the IPMMU hardware is configured with IMTTBCR.SL=1 and TSZ0 bits set to 0x21. This will enable a 31-bit IOVA space and use "Initial lookup level 1" (in Table D4-13 of armv8_arm.pdf) also known as "Start at first level" in IPMMU documentation.
Not for upstream merge. Tested on ULCB with r8a7796 ES1.0.
---
drivers/iommu/ipmmu-vmsa.c | 40 +++++++++++++++++++++++++++------------- 1 files changed, 27 insertions(+), 13 deletions(-)
drivers/iommu/ipmmu-vmsa.c +27 -13
@@ -42,6 +42,7 @@ struct ipmmu_features {unsigned int number_of_contexts;bool setup_imbuscr;bool twobit_imttbcr_sl0; +bool imctr_va64; };struct ipmmu_vmsa_device {
@@ -97,6 +98,7 @@ static struct ipmmu_vmsa_iommu_priv *to_#define IM_CTX_SIZE 0x40#define IMCTR 0x0000 +#define IMCTR_VA64 (1 << 29)#define IMCTR_TRE (1 << 17)#define IMCTR_AFE (1 << 16)#define IMCTR_RTSEL_MASK (3 << 4)
@@ -422,10 +424,10 @@ static int ipmmu_domain_init_context(str*/ domain->cfg.quirks =IO_PGTABLE_QUIRK_ARM_NS ; domain->cfg.pgsize_bitmap =SZ_1G |SZ_2M |SZ_4K ; - domain->cfg.ias =32 ; + domain->cfg.ias =31 ; domain->cfg.oas =40 ; domain->cfg.tlb = &ipmmu_gather_ops; - domain->io_domain.geometry.aperture_end =DMA_BIT_MASK (32 ); + domain->io_domain.geometry.aperture_end =DMA_BIT_MASK (31 ); domain->io_domain.geometry.force_aperture = true;/* * TODO: Add support for coherent walk through CCI with DVM and remove
@@ -442,8 +444,9 @@ static int ipmmu_domain_init_context(str domain->context_id = ret; - domain->iop =alloc_io_pgtable_ops (ARM_32_LPAE_S1 , &domain->cfg, - domain); + domain->iop =alloc_io_pgtable_ops (domain->mmu->features->imctr_va64 ? +ARM_64_LPAE_S1 :ARM_32_LPAE_S1 , + &domain->cfg, domain);if (!domain->iop) {ipmmu_domain_free_context (domain->mmu->root, domain->context_id);
@@ -456,14 +459,22 @@ static int ipmmu_domain_init_context(stripmmu_ctx_write_root (domain,IMTTUBR0 , ttbr >>32 );/* -* TTBCR -* We use long descriptors with inner-shareable WBWA tables and allocate -* the whole 32-bit VA space to TTBR0. -*/ -if (domain->mmu->features->twobit_imttbcr_sl0) - tmp =IMTTBCR_SL0_TWOBIT_LVL_1 ; -else - tmp =IMTTBCR_SL0_LVL_1 ; +* For IMCTR_VA64 and ARM_64_LPAE_S1 we need lowest bits of TTBCR +*/ +if (domain->mmu->features->imctr_va64) { + tmp = (1 <<6 ) |0x21 ; + }else { +/* +* TTBCR +* We use long descriptors with inner-shareable WBWA tables +* and allocate the whole 32-bit VA space to TTBR0. +*/ + +if (domain->mmu->features->twobit_imttbcr_sl0) + tmp =IMTTBCR_SL0_TWOBIT_LVL_1 ; +else + tmp =IMTTBCR_SL0_LVL_1 ; + } ipmmu_ctx_write_root(domain, IMTTBCR, IMTTBCR_EAE | IMTTBCR_SH0_INNER_SHAREABLE | IMTTBCR_ORGN0_WB_WA |
@@ -493,7 +504,8 @@ static int ipmmu_domain_init_context(str* required when modifying the context registers. */ ipmmu_ctx_write_all (domain,IMCTR , -IMCTR_INTEN |IMCTR_FLUSH |IMCTR_MMUEN ); + (domain->mmu->features->imctr_va64 ?IMCTR_VA64 :0 ) + |IMCTR_INTEN |IMCTR_FLUSH |IMCTR_MMUEN );return 0 ; }
@@ -1018,6 +1030,7 @@ static const struct ipmmu_features ipmmu .number_of_contexts = 1, /* software only tested with one context */ .setup_imbuscr = true, .twobit_imttbcr_sl0 = false, + .imctr_va64 = false, };static const struct ipmmu_features ipmmu_features_rcar_gen3 = {
@@ -1026,6 +1039,7 @@ static const struct ipmmu_features ipmmu .number_of_contexts = 8, .setup_imbuscr = false, .twobit_imttbcr_sl0 = true, + .imctr_va64 = true, };static const struct of_device_id ipmmu_of_ids[] = {
PATCH 4/4 iommu/ipmmu-vmsa: VA64 mode with 30-bit IOVA
In reply to Magnus DammFrom: Magnus Damm <[email protected]>
Hack up the IPMMU driver to enable VM64 mode with 30-bit IOVA.
For this configuration the IPMMU hardware is configured with IMTTBCR.SL=0 and TSZ0 bits set to 0x22. This will enable a 30-bit IOVA space and use "Initial lookup level 2" (in Table D4-13 of armv8_arm.pdf) also known as "Start at second level" in IPMMU documentation.
Not for upstream merge. Tested on ULCB with r8a7796 ES1.0.
---
drivers/iommu/ipmmu-vmsa.c | 40 +++++++++++++++++++++++++++------------- 1 files changed, 27 insertions(+), 13 deletions(-)
drivers/iommu/ipmmu-vmsa.c +27 -13
@@ -42,6 +42,7 @@ struct ipmmu_features {unsigned int number_of_contexts;bool setup_imbuscr;bool twobit_imttbcr_sl0; +bool imctr_va64; };struct ipmmu_vmsa_device {
@@ -97,6 +98,7 @@ static struct ipmmu_vmsa_iommu_priv *to_#define IM_CTX_SIZE 0x40#define IMCTR 0x0000 +#define IMCTR_VA64 (1 << 29)#define IMCTR_TRE (1 << 17)#define IMCTR_AFE (1 << 16)#define IMCTR_RTSEL_MASK (3 << 4)
@@ -422,10 +424,10 @@ static int ipmmu_domain_init_context(str*/ domain->cfg.quirks =IO_PGTABLE_QUIRK_ARM_NS ; domain->cfg.pgsize_bitmap =SZ_1G |SZ_2M |SZ_4K ; - domain->cfg.ias =32 ; + domain->cfg.ias =30 ; domain->cfg.oas =40 ; domain->cfg.tlb = &ipmmu_gather_ops; - domain->io_domain.geometry.aperture_end =DMA_BIT_MASK (32 ); + domain->io_domain.geometry.aperture_end =DMA_BIT_MASK (30 ); domain->io_domain.geometry.force_aperture = true;/* * TODO: Add support for coherent walk through CCI with DVM and remove
@@ -442,8 +444,9 @@ static int ipmmu_domain_init_context(str domain->context_id = ret; - domain->iop =alloc_io_pgtable_ops (ARM_32_LPAE_S1 , &domain->cfg, - domain); + domain->iop =alloc_io_pgtable_ops (domain->mmu->features->imctr_va64 ? +ARM_64_LPAE_S1 :ARM_32_LPAE_S1 , + &domain->cfg, domain);if (!domain->iop) {ipmmu_domain_free_context (domain->mmu->root, domain->context_id);
@@ -456,14 +459,22 @@ static int ipmmu_domain_init_context(stripmmu_ctx_write_root (domain,IMTTUBR0 , ttbr >>32 );/* -* TTBCR -* We use long descriptors with inner-shareable WBWA tables and allocate -* the whole 32-bit VA space to TTBR0. -*/ -if (domain->mmu->features->twobit_imttbcr_sl0) - tmp =IMTTBCR_SL0_TWOBIT_LVL_1 ; -else - tmp =IMTTBCR_SL0_LVL_1 ; +* For IMCTR_VA64 and ARM_64_LPAE_S1 we need lowest bits of TTBCR +*/ +if (domain->mmu->features->imctr_va64) { + tmp = (0 <<6 ) |0x22 ; + }else { +/* +* TTBCR +* We use long descriptors with inner-shareable WBWA tables +* and allocate the whole 32-bit VA space to TTBR0. +*/ + +if (domain->mmu->features->twobit_imttbcr_sl0) + tmp =IMTTBCR_SL0_TWOBIT_LVL_1 ; +else + tmp =IMTTBCR_SL0_LVL_1 ; + } ipmmu_ctx_write_root(domain, IMTTBCR, IMTTBCR_EAE | IMTTBCR_SH0_INNER_SHAREABLE | IMTTBCR_ORGN0_WB_WA |
@@ -493,7 +504,8 @@ static int ipmmu_domain_init_context(str* required when modifying the context registers. */ ipmmu_ctx_write_all (domain,IMCTR , -IMCTR_INTEN |IMCTR_FLUSH |IMCTR_MMUEN ); + (domain->mmu->features->imctr_va64 ?IMCTR_VA64 :0 ) + |IMCTR_INTEN |IMCTR_FLUSH |IMCTR_MMUEN );return 0 ; }
@@ -1018,6 +1030,7 @@ static const struct ipmmu_features ipmmu .number_of_contexts = 1, /* software only tested with one context */ .setup_imbuscr = true, .twobit_imttbcr_sl0 = false, + .imctr_va64 = false, };static const struct ipmmu_features ipmmu_features_rcar_gen3 = {
@@ -1026,6 +1039,7 @@ static const struct ipmmu_features ipmmu .number_of_contexts = 8, .setup_imbuscr = false, .twobit_imttbcr_sl0 = true, + .imctr_va64 = true, };static const struct of_device_id ipmmu_of_ids[] = {