iommu: M1 Pro/Max DART support
Subsystems (4)
cover iommu: M1 Pro/Max DART support
Hi,
This is a fairly brief series to add support for the DARTs present in the M1 Pro/Max. They have two differences that make them incompatible with those in the M1:
- the physical addresses are shifted left by 4 bits and and have 2 more bits inside the PTE entries
- the subpage protection feature is now mandatory. For Linux we can just configure it to always allow access to the entire page.
Note that this needs a fix to the core pagetable code. Hector already sent a first version separately to the mailing list since the problem is (at least in theory) also present on other SoCs using the LPAE format with a large physical address space [1].
Sven
[1] https://lore.kernel.org/linux-iommu/[email protected]/T/#t
Sven Peter (4):
dt-bindings: iommu: dart: add t6000 compatible iommu/io-pgtable: Add DART subpage protection support iommu/io-pgtable: Add DART PTE support for t6000
iommu: dart: Support t6000 variant
.../devicetree/bindings/iommu/apple,dart.yaml | 4 +- drivers/iommu/apple-dart.c | 19 ++++++++- drivers/iommu/io-pgtable-arm.c | 40 ++++++++++++++++++- include/linux/io-pgtable.h | 2 + 4 files changed, 61 insertions(+), 4 deletions(-)
Signature · 6 lines
2.25.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH 1/4 dt-bindings: iommu: dart: add t6000 compatible
The M1 Max/Pro SoCs come with a new DART variant that is incompatible with the previous one. Add a new compatible for those.
--- Documentation/devicetree/bindings/iommu/apple,dart.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/iommu/apple,dart.yaml +3 -1
@@ -22,7 +22,9 @@ description: |+ properties: compatible: - const: apple,t8103-dart + enum: + - apple,t8103-dart + - apple,t6000-dart reg: maxItems: 1
Signature · 6 lines
2.25.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [PATCH 1/4] dt-bindings: iommu: dart: add t6000 compatible
Quoted 8 lines · Sven Peter
The M1 Max/Pro SoCs come with a new DART variant that is incompatible with the previous one. Add a new compatible for those.
Signed-off-by Sven Peter <[email protected]>--- Documentation/devicetree/bindings/iommu/apple,dart.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH 2/4 iommu/io-pgtable: Add DART subpage protection support
In reply to Sven PeterDART allows to only expose a subpage to the device. While this is an optional feature on the M1 DARTs the new ones present on the Pro/Max models require this field in every PTE.
--- drivers/iommu/io-pgtable-arm.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/iommu/io-pgtable-arm.c +10 -0
@@ -10,6 +10,7 @@#define pr_fmt (fmt) "arm-lpae io-pgtable: " fmt#include <linux/atomic.h> +#include <linux/bitfield.h> #include <linux/bitops.h> #include <linux/io-pgtable.h> #include <linux/kernel.h>
@@ -133,6 +134,9 @@#define APPLE_DART_PTE_PROT_NO_WRITE (1<<7)#define APPLE_DART_PTE_PROT_NO_READ (1<<8) +#define APPLE_DART_PTE_SUBPAGE_START GENMASK_ULL(63, 52) +#define APPLE_DART_PTE_SUBPAGE_END GENMASK_ULL(51, 40) +/* IOPTE accessors */ #define iopte_deref (pte,d) __va(iopte_to_paddr(pte, d))
@@ -273,6 +277,12 @@ static void __arm_lpae_init_pte(struct arm_lpae_io_pgtable *data,else pte |=ARM_LPAE_PTE_TYPE_BLOCK ; +if (data->iop.fmt ==APPLE_DART ) { +/* subpage protection: always allow access to the entire page */ + pte |=FIELD_PREP (APPLE_DART_PTE_SUBPAGE_START ,0 ); + pte |=FIELD_PREP (APPLE_DART_PTE_SUBPAGE_END ,0xfff ); + } +for (i =0 ; i < num_entries; i++) ptep[i] = pte |paddr_to_iopte (paddr + i * sz, data);
Signature · 6 lines
2.25.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH 3/4 iommu/io-pgtable: Add DART PTE support for t6000
In reply to Sven PeterThe DARTs present in the M1 Pro/Max SoC support a 42bit physical address space by shifting the paddr and extending its mask inside the PTE.
--- drivers/iommu/io-pgtable-arm.c | 30 +++++++++++++++++++++++++++++- include/linux/io-pgtable.h | 2 ++ 2 files changed, 31 insertions(+), 1 deletion(-)
drivers/iommu/io-pgtable-arm.c +29 -1
@@ -137,6 +137,11 @@#define APPLE_DART_PTE_SUBPAGE_START GENMASK_ULL(63, 52)#define APPLE_DART_PTE_SUBPAGE_END GENMASK_ULL(51, 40) +#define APPLE_DART_PADDR_MASK_PS_36BIT GENMASK_ULL(35, 12) +#define APPLE_DART_PADDR_SHIFT_PS_36BIT (0) +#define APPLE_DART_PADDR_MASK_PS_42BIT GENMASK_ULL(37, 10) +#define APPLE_DART_PADDR_SHIFT_PS_42BIT (4) +/* IOPTE accessors */ #define iopte_deref (pte,d) __va(iopte_to_paddr(pte, d))
@@ -171,6 +176,13 @@ static arm_lpae_iopte paddr_to_iopte(phys_addr_t paddr, {arm_lpae_iopte pte = paddr; +if (data->iop.fmt ==APPLE_DART ) { + pte = paddr >> data->iop.cfg.apple_dart_cfg.paddr_shift; + pte &= data->iop.cfg.apple_dart_cfg.paddr_mask; + +return pte; + } +/* Of the bits which overlap, either 51:48 or 15:12 are always RES0 */ return (pte | (pte >> (48 -12 ))) &ARM_LPAE_PTE_ADDR_MASK ; }
@@ -180,6 +192,12 @@ static phys_addr_t iopte_to_paddr(arm_lpae_iopte pte, {u64 paddr = pte &ARM_LPAE_PTE_ADDR_MASK ; +if (data->iop.fmt ==APPLE_DART ) { + paddr = pte & data->iop.cfg.apple_dart_cfg.paddr_mask; + paddr <<= data->iop.cfg.apple_dart_cfg.paddr_shift; +return paddr; + } +if (ARM_LPAE_GRANULE (data) <SZ_64K )return paddr;
@@ -1122,8 +1140,18 @@ apple_dart_alloc_pgtable(struct io_pgtable_cfg *cfg, void *cookie)struct arm_lpae_io_pgtable *data;int i; -if (cfg->oas >36 ) +switch (cfg->oas) { +case 36 : + cfg->apple_dart_cfg.paddr_shift =APPLE_DART_PADDR_SHIFT_PS_36BIT ; + cfg->apple_dart_cfg.paddr_mask =APPLE_DART_PADDR_MASK_PS_36BIT ; +break ; +case 42 : + cfg->apple_dart_cfg.paddr_shift =APPLE_DART_PADDR_SHIFT_PS_42BIT ; + cfg->apple_dart_cfg.paddr_mask =APPLE_DART_PADDR_MASK_PS_42BIT ; +break ; +default :return NULL ; + } data =arm_lpae_alloc_pgtable (cfg);if (!data)
include/linux/io-pgtable.h +2 -0
@@ -136,6 +136,8 @@ struct io_pgtable_cfg {struct {u64 ttbr[4 ];u32 n_ttbrs; +u32 paddr_shift; +u64 paddr_mask; } apple_dart_cfg; }; };
Signature · 6 lines
2.25.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH 4/4 iommu: dart: Support t6000 variant
In reply to Sven PeterThe M1 Pro/Max SoCs come with a new variant of DART which supports a larger physical address space with a slightly different PTE format. Pass through the correct paddr address space size to the io-pgtable code which will take care of the rest.
--- drivers/iommu/apple-dart.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
drivers/iommu/apple-dart.c +17 -2
@@ -81,10 +81,15 @@#define DART_TTBR_VALID BIT(31)#define DART_TTBR_SHIFT 12 +struct apple_dart_hw { +u32 oas; +}; +/* * Private structure associated with each DART device. * * @dev: device struct +* @hw: SoC-specific hardware data * @regs: mapped MMIO region * @irq: interrupt number, can be shared with other DARTs * @clks: clocks associated with this DART
@@ -98,6 +103,7 @@*/ struct apple_dart {struct device *dev; +const struct apple_dart_hw *hw;void __iomem *regs;
@@ -421,7 +427,7 @@ static int apple_dart_finalize_domain(struct iommu_domain *domain, pgtbl_cfg = (struct io_pgtable_cfg ){ .pgsize_bitmap = dart->pgsize, .ias =32 , - .oas =36 , + .oas = dart->hw->oas, .coherent_walk =1 , .iommu_dev = dart->dev, };
@@ -855,6 +861,7 @@ static int apple_dart_probe(struct platform_device *pdev)return -ENOMEM ; dart->dev = dev; + dart->hw =of_device_get_match_data (dev);spin_lock_init (&dart->lock); res =platform_get_resource (pdev,IORESOURCE_MEM ,0 );
@@ -944,8 +951,16 @@ static int apple_dart_remove(struct platform_device *pdev)return 0 ; } +static const struct apple_dart_hw apple_dart_hw_t8103 = { + .oas =36 , +}; +static const struct apple_dart_hw apple_dart_hw_t6000 = { + .oas =42 , +}; +static const struct of_device_id apple_dart_of_match[] = { - { .compatible ="apple,t8103-dart" , .data =NULL }, + { .compatible ="apple,t8103-dart" , .data = &apple_dart_hw_t8103 }, + { .compatible ="apple,t6000-dart" , .data = &apple_dart_hw_t6000 }, {}, };MODULE_DEVICE_TABLE (of, apple_dart_of_match);
Signature · 6 lines
2.25.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Hej,
Quoted 25 lines · Sven Peter
This is a fairly brief series to add support for the DARTs present in the M1 Pro/Max. They have two differences that make them incompatible with those in the M1:
- the physical addresses are shifted left by 4 bits and and have 2 more bits inside the PTE entries
- the subpage protection feature is now mandatory. For Linux we can just configure it to always allow access to the entire page.Note that this needs a fix to the core pagetable code. Hector already sent a first version separately to the mailing list since the problem is (at least in theory) also present on other SoCs using the LPAE format with a large physical address space [1].
Sven
[1] https://lore.kernel.org/linux-iommu/[email protected]/T/#t
Sven Peter (4):
dt-bindings: iommu: dart: add t6000 compatible iommu/io-pgtable: Add DART subpage protection support iommu/io-pgtable: Add DART PTE support for t6000
iommu: dart: Support t6000 variant
Quoted 5 lines
.../devicetree/bindings/iommu/apple,dart.yaml | 4 +- drivers/iommu/apple-dart.c | 19 ++++++++- drivers/iommu/io-pgtable-arm.c | 40 ++++++++++++++++++- include/linux/io-pgtable.h | 2 + 4 files changed, 61 insertions(+), 4 deletions(-)
Whole series tested on M1 Max. Feel free to add
best
Janne
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Joerg Roedel
maintainerHi Sven,
Quoted 5 lines · Sven Peter
Sven Peter (4):
dt-bindings: iommu: dart: add t6000 compatible iommu/io-pgtable: Add DART subpage protection support iommu/io-pgtable: Add DART PTE support for t6000
iommu: dart: Support t6000 variant
Looks good to me, will apply it when Robin had a chance to look at the io-pgtable changes.
Thanks,
Joerg