Skip to contentSkip to conversation

iommu: M1 Pro/Max DART support

PATCH Applied Janne Grunau 5 participants 14 messages Sep 16, 2022 – Sep 26, 2022

Subsystems (4)
lore
Share & tools
lore

Janne Grunau

author maintainer
#0 lore raw

v5 cover iommu: M1 Pro/Max DART support

Hej,

this is the next attempt adding support for the DART found in Apple's M1 Pro/Max/Ultra. This adds a separate io-pgtable implementation for DART. As already mentioned in v2 the pte format is not fully compatible with io-pgtable-arm. Especially the 2nd least significant bit is used and is not available to tag tables/pages.
io-pgtable-dart.c is copied from io-pgtable-arm.c and support for unused features is removed. Support for 4k IO pages is left for A7 to A11 SoCs as there's work underway to run Linux on them.

The incompatibilities between both Apple DART pte seems manageable in their own io-pgtable implementation. A short list of the known differences:

- the physical addresses are shifted left by 4 bits and and have 2 more bits inside the PTE entries
- the read/write protection flags are at a different position
- the subpage protection feature is now mandatory. For Linux we can just configure it to always allow access to the entire page.
- BIT(1) tags "uncached" mappings (used for the display controller)

There is second type of DART (t8110) present on M1 Pro/Max SoCs which uses the same PTE format as t6000.

Changes in v5:
- collected Sven's ack
- minor fixes in "iommu/io-pgtable: Move Apple DART support to its own file"

Changes in v4:
- split dart and io-pgtable-dart build to allow building dart as module
- add missing "SELECT IOMMU_IO_PGTABLE"
- made map/unmap_pages/iova_to_phys inon-recursive
- replace pgd concatenation with multiple table handling
- simplified config and page size checks
- collected Robin's Ack

Changes in v3:
- move APPLE_DART to its own io-pgtable implementation, copied from io-pgtable-arm and simplified

Changes in v2:
- added Rob's Acked-by:
- add APPLE_DART2 io-pgtable format

Janne Grunau (1):
iommu/io-pgtable: Move Apple DART support to its own file

Sven Peter (4):
dt-bindings: iommu: dart: add t6000 compatible iommu/io-pgtable: Add DART subpage protection support iommu/io-pgtable-dart: Add DART PTE support for t6000
iommu: dart: Support t6000 variant

 .../devicetree/bindings/iommu/apple,dart.yaml |   4 +-
 MAINTAINERS                                   |   1 +
 drivers/iommu/Kconfig                         |  13 +-
 drivers/iommu/Makefile                        |   1 +
 drivers/iommu/apple-dart.c                    |  24 +-
 drivers/iommu/io-pgtable-arm.c                |  63 ---
 drivers/iommu/io-pgtable-dart.c               | 470 ++++++++++++++++++
 drivers/iommu/io-pgtable.c                    |   3 +
 include/linux/io-pgtable.h                    |   1 +
 9 files changed, 512 insertions(+), 68 deletions(-)
 create mode 100644 drivers/iommu/io-pgtable-dart.c
Signature · 1 line
2.35.1
author maintainer
#1 lore raw

PATCH v5 1/5 dt-bindings: iommu: dart: add t6000 compatible

From: Sven Peter <[email protected]>

The M1 Max/Pro SoCs come with a new DART variant that is incompatible with the previous one. Add a new compatible for those.

---

(no changes since v2)

Changes in v2:
- added Rob's Acked-by:

 Documentation/devicetree/bindings/iommu/apple,dart.yaml | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/iommu/apple,dart.yaml +3 -1
index 82ad669feef7..06af2bacbe97 100644
@@ -22,7 +22,9 @@ description: |+
 
 properties:
   compatible:
-    const: apple,t8103-dart
+    enum:
+      - apple,t8103-dart
+      - apple,t6000-dart
 
   reg:
     maxItems: 1
Signature · 1 line
2.35.1
#2 lore raw

Re: [PATCH v5 1/5] dt-bindings: iommu: dart: add t6000 compatible

Quoted 24 lines · Janne Grunau

From: Sven Peter <[email protected]>

The M1 Max/Pro SoCs come with a new DART variant that is incompatible with the previous one. Add a new compatible for those.

---

(no changes since v2)

Changes in v2:
- added Rob's Acked-by:

 Documentation/devicetree/bindings/iommu/apple,dart.yaml | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/iommu/apple,dart.yaml +0 -0
index 82ad669feef7..06af2bacbe97 100644

Documentation/devicetree/bindings/iommu/apple,dart.yaml description: |+ · line 30

Quoted 10 lines
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

I'm taking this one via the Asahi-SoC tree, since it unblocks the t6000 DT series and it is already reviewed and ready to go. Thanks!

- Hector

author maintainer
#3 lore raw

PATCH v5 2/5 iommu/io-pgtable: Move Apple DART support to its own file

In reply to Janne Grunau

The pte format used by the DARTs found in the Apple M1 (t8103) is not fully compatible with io-pgtable-arm. The 24 MSB are used for subpage protection (mapping only parts of page) and conflict with the address mask. In addition bit 1 is not available for tagging entries but disables subpage protection. Subpage protection could be useful to support a CPU granule of 4k with the fixed IOMMU page size of 16k.

The DARTs found on Apple M1 Pro/Max/Ultra use another different pte format which is even less compatible. To support an output address size of 42 bit the address is shifted down by 4. Subpage protection is mandatory and bit 1 signifies uncached mappings used by the display controller.

It would be advantageous to share code for all known Apple DART variants to support common features. The page table allocator for DARTs is less complex since it uses a two levels of translation table without support for huge pages.

---

Changes in v5:
- collected Sven's ack
- use alloc_pages instead alloc_pages_node
- do not return '0' as NULL pointer, Reported-by: kernel test robot <[email protected]>

Changes in v4:
- split dart and io-pgtable-dart build to allow building dart as module
- add missing "SELECT IOMMU_IO_PGTABLE"
- made map/unmap_pages/iova_to_phys inon-recursive
- replace pgd concatenation with multiple table handling
- simplified config and page size checks
- collected Robin's Ack

Changes in v3:
- move APPLE_DART to its own io-pgtable implementation, copied from io-pgtable-arm and simplified

Changes in v2:
- add APPLE_DART2 io-pgtable format

 MAINTAINERS                     |   1 +
 drivers/iommu/Kconfig           |  13 +-
 drivers/iommu/Makefile          |   1 +
 drivers/iommu/io-pgtable-arm.c  |  63 -----
 drivers/iommu/io-pgtable-dart.c | 427 ++++++++++++++++++++++++++++++++
 drivers/iommu/io-pgtable.c      |   2 +
 6 files changed, 443 insertions(+), 64 deletions(-)
 create mode 100644 drivers/iommu/io-pgtable-dart.c
MAINTAINERS +1 -0
index 1fc9ead83d2a..028b7e31e589 100644
@@ -1848,6 +1848,7 @@ F:	drivers/clk/clk-apple-nco.c
 F:	drivers/i2c/busses/i2c-pasemi-core.c
 F:	drivers/i2c/busses/i2c-pasemi-platform.c
 F:	drivers/iommu/apple-dart.c
+F:	drivers/iommu/io-pgtable-dart.c
 F:	drivers/irqchip/irq-apple-aic.c
 F:	drivers/mailbox/apple-mailbox.c
 F:	drivers/nvme/host/apple.c
drivers/iommu/Kconfig +12 -1
index c79a0df090c0..026921c1df53 100644
@@ -67,6 +67,17 @@ config IOMMU_IO_PGTABLE_ARMV7S_SELFTEST
 
 	  If unsure, say N here.
 
+config IOMMU_IO_PGTABLE_DART
+	bool "Apple DART Formats"
+	select IOMMU_IO_PGTABLE
+	depends on ARM64 || (COMPILE_TEST && !GENERIC_ATOMIC64)
+	help
+	  Enable support for the Apple DART pagetable formats. These include
+	  the t8020 and t6000/t8110 DART formats used in Apple M1/M2 family
+	  SoCs.
+
+	  If unsure, say N here.
+
 endmenu
 
 config IOMMU_DEBUGFS
@@ -294,7 +305,7 @@ config APPLE_DART
 	tristate "Apple DART IOMMU Support"
 	depends on ARCH_APPLE || (COMPILE_TEST && !GENERIC_ATOMIC64)
 	select IOMMU_API
-	select IOMMU_IO_PGTABLE_LPAE
+	select IOMMU_IO_PGTABLE_DART
 	default ARCH_APPLE
 	help
 	  Support for Apple DART (Device Address Resolution Table) IOMMUs
drivers/iommu/Makefile +1 -0
index 44475a9b3eea..cc9f381013c3 100644
@@ -8,6 +8,7 @@ obj-$(CONFIG_IOMMU_DMA) += dma-iommu.o
 obj-$(CONFIG_IOMMU_IO_PGTABLE) += io-pgtable.o
 obj-$(CONFIG_IOMMU_IO_PGTABLE_ARMV7S) += io-pgtable-arm-v7s.o
 obj-$(CONFIG_IOMMU_IO_PGTABLE_LPAE) += io-pgtable-arm.o
+obj-$(CONFIG_IOMMU_IO_PGTABLE_DART) += io-pgtable-dart.o
 obj-$(CONFIG_IOASID) += ioasid.o
 obj-$(CONFIG_IOMMU_IOVA) += iova.o
 obj-$(CONFIG_OF_IOMMU)	+= of_iommu.o
drivers/iommu/io-pgtable-arm.c +0 -63

87 lines not on this page · raw message

drivers/iommu/io-pgtable-dart.c new file +427 -0

427 lines not on this page · raw message

drivers/iommu/io-pgtable.c +2 -0
index f4bfcef98297..16205ea9272c 100644
@@ -20,6 +20,8 @@ io_pgtable_init_table[IO_PGTABLE_NUM_FMTS] = {
 	[ARM_64_LPAE_S1] = &io_pgtable_arm_64_lpae_s1_init_fns,
 	[ARM_64_LPAE_S2] = &io_pgtable_arm_64_lpae_s2_init_fns,
 	[ARM_MALI_LPAE] = &io_pgtable_arm_mali_lpae_init_fns,
+#endif
+#ifdef CONFIG_IOMMU_IO_PGTABLE_DART
 	[APPLE_DART] = &io_pgtable_apple_dart_init_fns,
 #endif
 #ifdef CONFIG_IOMMU_IO_PGTABLE_ARMV7S
Signature · 1 line
2.35.1
#4 lore raw

Re: [PATCH v5 2/5] iommu/io-pgtable: Move Apple DART support to its own file

Quoted 23 lines · Janne Grunau

The pte format used by the DARTs found in the Apple M1 (t8103) is not fully compatible with io-pgtable-arm. The 24 MSB are used for subpage protection (mapping only parts of page) and conflict with the address mask. In addition bit 1 is not available for tagging entries but disables subpage protection. Subpage protection could be useful to support a CPU granule of 4k with the fixed IOMMU page size of 16k.

The DARTs found on Apple M1 Pro/Max/Ultra use another different pte format which is even less compatible. To support an output address size of 42 bit the address is shifted down by 4. Subpage protection is mandatory and bit 1 signifies uncached mappings used by the display controller.

It would be advantageous to share code for all known Apple DART variants to support common features. The page table allocator for DARTs is less complex since it uses a two levels of translation table without support for huge pages.

---

[...]

Quoted 4 lines
drivers/iommu/io-pgtable-dart.c new file +4 -0
+static void *__dart_alloc_pages(size_t size, gfp_t gfp,
+				    struct io_pgtable_cfg *cfg)
+{
+	struct device *dev = cfg->iommu_dev;

drivers/iommu/io-pgtable-dart.c line 93

Quoted 10 lines
drivers/iommu/io-pgtable-dart.c new file +10 -0
+	int order = get_order(size);
+	struct page *p;
+
+	VM_BUG_ON((gfp & __GFP_HIGHMEM));
+	p = alloc_pages(gfp | __GFP_ZERO, order);
+	if (!p)
+		return NULL;
+
+	return page_address(p);
+}

This throws a warning:

drivers/iommu/io-pgtable-dart.c: In function ‘__dart_alloc_pages’:
drivers/iommu/io-pgtable-dart.c:112:24: warning: unused variable ‘dev’ [-Wunused-variable]
112 | struct device *dev = cfg->iommu_dev;
| ^~~

The fix is trivial, of course.

- Hector

author maintainer
#5 lore raw

PATCH v5 3/5 iommu/io-pgtable: Add DART subpage protection support

In reply to Janne Grunau

From: Sven Peter <[email protected]>

DART 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.

---

(no changes since v3)

Changes in v3:
- apply change to io-pgtable-dart.c

 drivers/iommu/io-pgtable-dart.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/iommu/io-pgtable-dart.c +8 -0
index 312d40528748..665a52e5c9b0 100644
@@ -14,6 +14,7 @@
 #define pr_fmt(fmt)	"dart io-pgtable: " fmt
 
 #include <linux/atomic.h>
+#include <linux/bitfield.h>
 #include <linux/bitops.h>
 #include <linux/io-pgtable.h>
 #include <linux/kernel.h>
@@ -40,6 +41,9 @@
 #define DART_PTES_PER_TABLE(d)					\
 	(DART_GRANULE(d) >> ilog2(sizeof(dart_iopte)))
 
+#define APPLE_DART_PTE_SUBPAGE_START   GENMASK_ULL(63, 52)
+#define APPLE_DART_PTE_SUBPAGE_END     GENMASK_ULL(51, 40)
+
 #define APPLE_DART1_PADDR_MASK	GENMASK_ULL(35, 12)
 
 /* Apple DART1 protection bits */
@@ -108,6 +112,10 @@ static int dart_init_pte(struct dart_io_pgtable *data,
 			return -EEXIST;
 		}
 
+	/* 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);
+
 	pte |= APPLE_DART1_PTE_PROT_SP_DIS;
 	pte |= APPLE_DART_PTE_VALID;
 
Signature · 1 line
2.35.1
maintainer Reviewed-by on v5 3/5
#6 lore raw

Re: [PATCH v5 3/5] iommu/io-pgtable: Add DART subpage protection support

Quoted 12 lines · Janne Grunau

From: Sven Peter <[email protected]>

DART 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.

---

Quoted 7 lines

(no changes since v3)

Changes in v3:
- apply change to io-pgtable-dart.c

 drivers/iommu/io-pgtable-dart.c | 8 ++++++++
 1 file changed, 8 insertions(+)
author maintainer
#7 lore raw

PATCH v5 4/5 iommu/io-pgtable-dart: Add DART PTE support for t6000

In reply to Janne Grunau

From: Sven Peter <[email protected]>

The DARTs present in the M1 Pro/Max/Ultra SoC use a diffent PTE format. They support a 42bit physical address space by shifting the paddr and extending its mask inside the PTE.
They also come with mandatory sub-page protection now which we just configure to always allow access to the entire page. This feature is already present but optional on the previous DARTs which allows to unconditionally configure it.

---

(no changes since v3)

Changes in v3:
- apply change to io-pgtable-dart.c
- handle pte <> paddr conversion based on the pte format instead of the output address size

Changes in v2:
- add APPLE_DART2 PTE format

 drivers/iommu/io-pgtable-dart.c | 49 ++++++++++++++++++++++++++++-----
 drivers/iommu/io-pgtable.c      |  1 +
 include/linux/io-pgtable.h      |  1 +
 3 files changed, 44 insertions(+), 7 deletions(-)
drivers/iommu/io-pgtable-dart.c +42 -7
index 665a52e5c9b0..cc66593318e6 100644
@@ -45,12 +45,19 @@
 #define APPLE_DART_PTE_SUBPAGE_END     GENMASK_ULL(51, 40)
 
 #define APPLE_DART1_PADDR_MASK	GENMASK_ULL(35, 12)
+#define APPLE_DART2_PADDR_MASK	GENMASK_ULL(37, 10)
+#define APPLE_DART2_PADDR_SHIFT	(4)
 
 /* Apple DART1 protection bits */
 #define APPLE_DART1_PTE_PROT_NO_READ	BIT(8)
 #define APPLE_DART1_PTE_PROT_NO_WRITE	BIT(7)
 #define APPLE_DART1_PTE_PROT_SP_DIS	BIT(1)
 
+/* Apple DART2 protection bits */
+#define APPLE_DART2_PTE_PROT_NO_READ	BIT(3)
+#define APPLE_DART2_PTE_PROT_NO_WRITE	BIT(2)
+#define APPLE_DART2_PTE_PROT_NO_CACHE	BIT(1)
+
 /* marks PTE as valid */
 #define APPLE_DART_PTE_VALID		BIT(0)
 
@@ -72,13 +79,31 @@ typedef u64 dart_iopte;
 static dart_iopte paddr_to_iopte(phys_addr_t paddr,
 				     struct dart_io_pgtable *data)
 {
-	return paddr & APPLE_DART1_PADDR_MASK;
+	dart_iopte pte;
+
+	if (data->iop.fmt == APPLE_DART)
+		return paddr & APPLE_DART1_PADDR_MASK;
+
+	/* format is APPLE_DART2 */
+	pte = paddr >> APPLE_DART2_PADDR_SHIFT;
+	pte &= APPLE_DART2_PADDR_MASK;
+
+	return pte;
 }
 
 static phys_addr_t iopte_to_paddr(dart_iopte pte,
 				  struct dart_io_pgtable *data)
 {
-	return pte & APPLE_DART1_PADDR_MASK;
+	u64 paddr;
+
+	if (data->iop.fmt == APPLE_DART)
+		return pte & APPLE_DART1_PADDR_MASK;
+
+	/* format is APPLE_DART2 */
+	paddr = pte & APPLE_DART2_PADDR_MASK;
+	paddr <<= APPLE_DART2_PADDR_SHIFT;
+
+	return paddr;
 }
 
 static void *__dart_alloc_pages(size_t size, gfp_t gfp,
@@ -191,10 +216,20 @@ static dart_iopte dart_prot_to_pte(struct dart_io_pgtable *data,
 {
 	dart_iopte pte = 0;
 
-	if (!(prot & IOMMU_WRITE))
-		pte |= APPLE_DART1_PTE_PROT_NO_WRITE;
-	if (!(prot & IOMMU_READ))
-		pte |= APPLE_DART1_PTE_PROT_NO_READ;
+	if (data->iop.fmt == APPLE_DART) {
+		if (!(prot & IOMMU_WRITE))
+			pte |= APPLE_DART1_PTE_PROT_NO_WRITE;
+		if (!(prot & IOMMU_READ))
+			pte |= APPLE_DART1_PTE_PROT_NO_READ;
+	}
+	if (data->iop.fmt == APPLE_DART2) {
+		if (!(prot & IOMMU_WRITE))
+			pte |= APPLE_DART2_PTE_PROT_NO_WRITE;
+		if (!(prot & IOMMU_READ))
+			pte |= APPLE_DART2_PTE_PROT_NO_READ;
+		if (!(prot & IOMMU_CACHE))
+			pte |= APPLE_DART2_PTE_PROT_NO_CACHE;
+	}
 
 	return pte;
 }
@@ -369,7 +404,7 @@ apple_dart_alloc_pgtable(struct io_pgtable_cfg *cfg, void *cookie)
 	if (!cfg->coherent_walk)
 		return NULL;
 
-	if (cfg->oas > DART1_MAX_ADDR_BITS)
+	if (cfg->oas != 36 && cfg->oas != 42)
 		return NULL;
 
 	if (cfg->ias > cfg->oas)
drivers/iommu/io-pgtable.c +1 -0
index 16205ea9272c..49f46e1eabf7 100644
@@ -23,6 +23,7 @@ io_pgtable_init_table[IO_PGTABLE_NUM_FMTS] = {
 #endif
 #ifdef CONFIG_IOMMU_IO_PGTABLE_DART
 	[APPLE_DART] = &io_pgtable_apple_dart_init_fns,
+	[APPLE_DART2] = &io_pgtable_apple_dart_init_fns,
 #endif
 #ifdef CONFIG_IOMMU_IO_PGTABLE_ARMV7S
 	[ARM_V7S] = &io_pgtable_arm_v7s_init_fns,
include/linux/io-pgtable.h +1 -0
index 86af6f0a00a2..76b98511cbc8 100644
@@ -17,6 +17,7 @@ enum io_pgtable_fmt {
 	ARM_MALI_LPAE,
 	AMD_IOMMU_V1,
 	APPLE_DART,
+	APPLE_DART2,
 	IO_PGTABLE_NUM_FMTS,
 };
 
Signature · 1 line
2.35.1
maintainer Reviewed-by on v5 4/5
#8 lore raw

Re: [PATCH v5 4/5] iommu/io-pgtable-dart: Add DART PTE support for t6000

Quoted 24 lines · Janne Grunau

From: Sven Peter <[email protected]>

The DARTs present in the M1 Pro/Max/Ultra SoC use a diffent PTE format. They support a 42bit physical address space by shifting the paddr and extending its mask inside the PTE.
They also come with mandatory sub-page protection now which we just configure to always allow access to the entire page. This feature is already present but optional on the previous DARTs which allows to unconditionally configure it.

---

(no changes since v3)

Changes in v3:
- apply change to io-pgtable-dart.c
- handle pte <> paddr conversion based on the pte format instead of the output address size

Quoted 7 lines

Changes in v2:
- add APPLE_DART2 PTE format

 drivers/iommu/io-pgtable-dart.c | 49 ++++++++++++++++++++++++++++-----
 drivers/iommu/io-pgtable.c      |  1 +
 include/linux/io-pgtable.h      |  1 +
 3 files changed, 44 insertions(+), 7 deletions(-)
author maintainer
#9 lore raw

PATCH v5 5/5 iommu: dart: Support t6000 variant

In reply to Janne Grunau

From: Sven Peter <[email protected]>

The M1 Pro/Max/Ultra SoCs come with a new variant of DART which supports a larger physical address space with a different PTE format. Pass through the correct paddr address space size and the PTE format to the io-pgtable code which will take care of the rest.

---

(no changes since v3)

Changes in v3:
- apply change to io-pgtable-dart.c

Changes in v2:
- use APPLE_DART2 PTE format for dart-t6000

 drivers/iommu/apple-dart.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)
drivers/iommu/apple-dart.c +21 -3
index 8af0242a90d9..e5793c0d08b4 100644
@@ -81,10 +81,16 @@
 #define DART_TTBR_VALID BIT(31)
 #define DART_TTBR_SHIFT 12
 
+struct apple_dart_hw {
+	u32 oas;
+	enum io_pgtable_fmt fmt;
+};
+
 /*
  * 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 +104,7 @@
  */
 struct apple_dart {
 	struct device *dev;
+	const struct apple_dart_hw *hw;
 
 	void __iomem *regs;
 
@@ -421,13 +428,13 @@ 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,
 	};
 
 	dart_domain->pgtbl_ops =
-		alloc_io_pgtable_ops(APPLE_DART, &pgtbl_cfg, domain);
+		alloc_io_pgtable_ops(dart->hw->fmt, &pgtbl_cfg, domain);
 	if (!dart_domain->pgtbl_ops) {
 		ret = -ENOMEM;
 		goto done;
@@ -858,6 +865,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);
 
 	dart->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
@@ -946,8 +954,18 @@ static int apple_dart_remove(struct platform_device *pdev)
 	return 0;
 }
 
+static const struct apple_dart_hw apple_dart_hw_t8103 = {
+	.oas = 36,
+	.fmt = APPLE_DART,
+};
+static const struct apple_dart_hw apple_dart_hw_t6000 = {
+	.oas = 42,
+	.fmt = APPLE_DART2,
+};
+
 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 · 1 line
2.35.1
maintainer Reviewed-by on v5 5/5
#10 lore raw

Re: [PATCH v5 5/5] iommu: dart: Support t6000 variant

Quoted 16 lines · Janne Grunau

From: Sven Peter <[email protected]>

The M1 Pro/Max/Ultra SoCs come with a new variant of DART which supports a larger physical address space with a different PTE format. Pass through the correct paddr address space size and the PTE format to the io-pgtable code which will take care of the rest.

---

(no changes since v3)

Quoted 8 lines

Changes in v3:
- apply change to io-pgtable-dart.c

Changes in v2:
- use APPLE_DART2 PTE format for dart-t6000

 drivers/iommu/apple-dart.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)
reviewer
#11 lore raw
In reply to Janne Grunau
Quoted 22 lines · Janne Grunau

Hej,

this is the next attempt adding support for the DART found in Apple's M1 Pro/Max/Ultra. This adds a separate io-pgtable implementation for DART. As already mentioned in v2 the pte format is not fully compatible with io-pgtable-arm. Especially the 2nd least significant bit is used and is not available to tag tables/pages.
io-pgtable-dart.c is copied from io-pgtable-arm.c and support for unused features is removed. Support for 4k IO pages is left for A7 to A11 SoCs as there's work underway to run Linux on them.

The incompatibilities between both Apple DART pte seems manageable in their own io-pgtable implementation. A short list of the known differences:

- the physical addresses are shifted left by 4 bits and and have 2 more bits inside the PTE entries
- the read/write protection flags are at a different position
- the subpage protection feature is now mandatory. For Linux we can just configure it to always allow access to the entire page.
- BIT(1) tags "uncached" mappings (used for the display controller)

Quoted 2 lines

There is second type of DART (t8110) present on M1 Pro/Max SoCs which uses the same PTE format as t6000.

FWIW I think there's minimal risk in queueing this up as a late addition for 6.1, lest it get forgotten again. I've not been following it since I've been busy with other things and I largely trust that DART patches are well-tested, but from a quick skim it all earns a solid "yeah, why not" from me :)

Cheers,
Robin.

Quoted 42 lines

Changes in v5:
- collected Sven's ack
- minor fixes in "iommu/io-pgtable: Move Apple DART support to its own file"

Changes in v4:
- split dart and io-pgtable-dart build to allow building dart as module
- add missing "SELECT IOMMU_IO_PGTABLE"
- made map/unmap_pages/iova_to_phys inon-recursive
- replace pgd concatenation with multiple table handling
- simplified config and page size checks
- collected Robin's Ack

Changes in v3:
- move APPLE_DART to its own io-pgtable implementation, copied from io-pgtable-arm and simplified

Changes in v2:
- added Rob's Acked-by:
- add APPLE_DART2 io-pgtable format

Janne Grunau (1):
iommu/io-pgtable: Move Apple DART support to its own file

Sven Peter (4):
dt-bindings: iommu: dart: add t6000 compatible iommu/io-pgtable: Add DART subpage protection support iommu/io-pgtable-dart: Add DART PTE support for t6000
iommu: dart: Support t6000 variant

  .../devicetree/bindings/iommu/apple,dart.yaml |   4 +-
  MAINTAINERS                                   |   1 +
  drivers/iommu/Kconfig                         |  13 +-
  drivers/iommu/Makefile                        |   1 +
  drivers/iommu/apple-dart.c                    |  24 +-
  drivers/iommu/io-pgtable-arm.c                |  63 ---
  drivers/iommu/io-pgtable-dart.c               | 470 ++++++++++++++++++
  drivers/iommu/io-pgtable.c                    |   3 +
  include/linux/io-pgtable.h                    |   1 +
  9 files changed, 512 insertions(+), 68 deletions(-)

create mode 100644 drivers/iommu/io-pgtable-dart.c

Acked-by on the v5 series
#12 lore raw
In reply to Janne Grunau
Quoted 55 lines · Janne Grunau

Hej,

this is the next attempt adding support for the DART found in Apple's M1 Pro/Max/Ultra. This adds a separate io-pgtable implementation for DART. As already mentioned in v2 the pte format is not fully compatible with io-pgtable-arm. Especially the 2nd least significant bit is used and is not available to tag tables/pages.
io-pgtable-dart.c is copied from io-pgtable-arm.c and support for unused features is removed. Support for 4k IO pages is left for A7 to A11 SoCs as there's work underway to run Linux on them.

The incompatibilities between both Apple DART pte seems manageable in their own io-pgtable implementation. A short list of the known differences:

- the physical addresses are shifted left by 4 bits and and have 2 more bits inside the PTE entries
- the read/write protection flags are at a different position
- the subpage protection feature is now mandatory. For Linux we can just configure it to always allow access to the entire page.
- BIT(1) tags "uncached" mappings (used for the display controller)

There is second type of DART (t8110) present on M1 Pro/Max SoCs which uses the same PTE format as t6000.

Changes in v5:
- collected Sven's ack
- minor fixes in "iommu/io-pgtable: Move Apple DART support to its own file"

Changes in v4:
- split dart and io-pgtable-dart build to allow building dart as module
- add missing "SELECT IOMMU_IO_PGTABLE"
- made map/unmap_pages/iova_to_phys inon-recursive
- replace pgd concatenation with multiple table handling
- simplified config and page size checks
- collected Robin's Ack

Changes in v3:
- move APPLE_DART to its own io-pgtable implementation, copied from io-pgtable-arm and simplified

Changes in v2:
- added Rob's Acked-by:
- add APPLE_DART2 io-pgtable format

Janne Grunau (1):
iommu/io-pgtable: Move Apple DART support to its own file

Sven Peter (4):
dt-bindings: iommu: dart: add t6000 compatible iommu/io-pgtable: Add DART subpage protection support iommu/io-pgtable-dart: Add DART PTE support for t6000
iommu: dart: Support t6000 variant

Quoted 12 lines
 .../devicetree/bindings/iommu/apple,dart.yaml |   4 +-
 MAINTAINERS                                   |   1 +
 drivers/iommu/Kconfig                         |  13 +-
 drivers/iommu/Makefile                        |   1 +
 drivers/iommu/apple-dart.c                    |  24 +-
 drivers/iommu/io-pgtable-arm.c                |  63 ---
 drivers/iommu/io-pgtable-dart.c               | 470 ++++++++++++++++++
 drivers/iommu/io-pgtable.c                    |   3 +
 include/linux/io-pgtable.h                    |   1 +
 9 files changed, 512 insertions(+), 68 deletions(-)
 create mode 100644 drivers/iommu/io-pgtable-dart.c

For the whole series, modulo the trivial warning I mentioned:

Let's get this merged please, it's been blocking t6000 support for a long time now :)

- Hector

maintainer Applied
#13 lore raw
In reply to Janne Grunau
Quoted 8 lines · Janne Grunau

Janne Grunau (1):
iommu/io-pgtable: Move Apple DART support to its own file

Sven Peter (4):
dt-bindings: iommu: dart: add t6000 compatible iommu/io-pgtable: Add DART subpage protection support iommu/io-pgtable-dart: Add DART PTE support for t6000
iommu: dart: Support t6000 variant

Applied patches 2-5 for v6.1, thanks everyone.