Skip to contentSkip to conversation

dmaengine: apple-admac: Add support for M3 generation

PATCH Superseded Sasha Finkelstein 4 participants 8 messages Jul 29 – Aug 11

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover dmaengine: apple-admac: Add support for M3 generation

The ADMACs present in M3 series devices (t8122 and t603x SoCs) need additional register writes in order to function correctly. Add a new compatible chain for those, and change the driver to do the write.

To simplify the merge strategy, the device tree entries will be sent in a future patch series.

---
Changes in v2:
- Typo fix
- Link to v1: https://patch.msgid.link/[email protected]

---
Sasha Finkelstein (2):
dt-bindings: dma: apple,admac: Add M3 generation ADMACs
dmaengine: apple-admac: Add M3 generation ADMACs

 Documentation/devicetree/bindings/dma/apple,admac.yaml | 10 ++++++++--
 drivers/dma/apple-admac.c                              | 32 ++++++++++++++++++++++++++++++--
 2 files changed, 38 insertions(+), 4 deletions(-)

---
base-commit: 0ce37745d4bfbc493f718169c3974898ffec8ee7
change-id: 20260725-t603x-admac-a1b07a2ccb54

Best regards,

Signature · 1 line
Sasha Finkelstein <[email protected]>
#1 lore raw

PATCH v2 1/2 dt-bindings: dma: apple,admac: Add M3 generation ADMACs

The admacs seen in M3-generation SoCs (t603x, t8122) need additional configuration writes and so are getting a new compatible chain.

---
 Documentation/devicetree/bindings/dma/apple,admac.yaml | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/dma/apple,admac.yaml +8 -2
index 6a200cbd7d02..5b4fd8348f99 100644
@@ -10,7 +10,7 @@ description: |
   Apple's Audio DMA Controller (ADMAC) is used to fetch and store audio samples
   on SoCs from the "Apple Silicon" family.
 
-  The controller has been seen with up to 24 channels. Even-numbered channels
+  The controller has been seen with up to 32 channels. Even-numbered channels
   are TX-only, odd-numbered are RX-only. Individual channels are coupled to
   fixed device endpoints.
 
@@ -33,6 +33,12 @@ properties:
               - apple,t8103-admac
               - apple,t8112-admac
           - const: apple,admac
+      - items:
+          - enum:
+              - apple,t6030-admac
+              - apple,t6031-admac
+          - const: apple,t8122-admac
+      - const: apple,t8122-admac
 
   reg:
     maxItems: 1
@@ -43,7 +49,7 @@ properties:
       Clients specify a single cell with channel number.
 
   dma-channels:
-    maximum: 24
+    maximum: 32
 
   interrupts:
     minItems: 4
Signature · 1 line
2.55.0
maintainer Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] dt-bindings: dma: apple,admac: Add M3 generation ADMACs

Quoted 37 lines · Sasha Finkelstein

The admacs seen in M3-generation SoCs (t603x, t8122) need additional configuration writes and so are getting a new compatible chain.

---
 Documentation/devicetree/bindings/dma/apple,admac.yaml | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/dma/apple,admac.yaml +7 -1
index 6a200cbd7d02..5b4fd8348f99 100644
@@ -10,7 +10,7 @@ description: |
   Apple's Audio DMA Controller (ADMAC) is used to fetch and store audio samples
   on SoCs from the "Apple Silicon" family.
 
-  The controller has been seen with up to 24 channels. Even-numbered channels
+  The controller has been seen with up to 32 channels. Even-numbered channels
   are TX-only, odd-numbered are RX-only. Individual channels are coupled to
   fixed device endpoints.
 
@@ -33,6 +33,12 @@ properties:
               - apple,t8103-admac
               - apple,t8112-admac
           - const: apple,admac
+      - items:
+          - enum:
+              - apple,t6030-admac
+              - apple,t6031-admac
+          - const: apple,t8122-admac
+      - const: apple,t8122-admac
 
   reg:
     maxItems: 1

Documentation/devicetree/bindings/dma/apple,admac.yaml properties: · line 55

Quoted 8 lines
Documentation/devicetree/bindings/dma/apple,admac.yaml +1 -1
@@ -43,7 +49,7 @@ properties:
       Clients specify a single cell with channel number.
 
   dma-channels:
-    maximum: 24
+    maximum: 32
 
   interrupts:
     minItems: 4

Janne

#3 lore raw

PATCH v2 2/2 dmaengine: apple-admac: Add M3 generation ADMACs

In reply to Sasha Finkelstein

The admacs present on t8122 and t603x SoCs need additional writes in order to operate correctly. The exact purpose of this register is unknown

---
 drivers/dma/apple-admac.c | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)
drivers/dma/apple-admac.c +30 -2
index 14a5ee14a481..72ff677c8ce5 100644
@@ -39,10 +39,14 @@
 
 #define FLAG_DESC_NOTIFY	BIT(16)
 
+#define T8122_UNK_28_VAL	0x200000
+
 #define REG_TX_START		0x0000
 #define REG_TX_STOP		0x0004
 #define REG_RX_START		0x0008
 #define REG_RX_STOP		0x000c
+#define REG_UNK_28		0x0028
+#define REG_UNK_2C		0x002c
 #define REG_IMPRINT		0x0090
 #define REG_TX_SRAM_SIZE	0x0094
 #define REG_RX_SRAM_SIZE	0x0098
@@ -127,6 +131,7 @@ struct admac_data {
 	struct mutex cache_alloc_lock;
 	struct admac_sram txcache, rxcache;
 
+	bool set_unk28;
 	int irq;
 	int irq_index;
 	int nchannels;
@@ -147,6 +152,10 @@ struct admac_tx {
 	struct list_head node;
 };
 
+struct admac_hw {
+	bool set_unk28;
+};
+
 static int admac_alloc_sram_carveout(struct admac_data *ad,
 				     enum dma_transfer_direction dir,
 				     u32 *out)
@@ -747,6 +756,11 @@ static int admac_device_config(struct dma_chan *chan,
 	u32 bus_width = readl_relaxed(ad->base + REG_BUS_WIDTH(adchan->no)) &
 		~(BUS_WIDTH_WORD_SIZE | BUS_WIDTH_FRAME_SIZE);
 
+	if (ad->set_unk28) {
+		writel_relaxed(T8122_UNK_28_VAL, ad->base + REG_UNK_28);
+		writel_relaxed(T8122_UNK_28_VAL, ad->base + REG_UNK_2C);
+	}
+
 	switch (is_tx ? config->dst_addr_width : config->src_addr_width) {
 	case DMA_SLAVE_BUSWIDTH_1_BYTE:
 		wordsize = 1;
@@ -805,6 +819,7 @@ static int admac_probe(struct platform_device *pdev)
 	struct device_node *np = pdev->dev.of_node;
 	struct admac_data *ad;
 	struct dma_device *dma;
+	const struct admac_hw *hw;
 	int nchannels;
 	int err, irq, i;
 
@@ -813,6 +828,9 @@ static int admac_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev, "missing or invalid dma-channels property\n");
 		return -EINVAL;
 	}
+	hw = of_device_get_match_data(&pdev->dev);
+	if (!hw)
+		return -EINVAL;
 
 	ad = devm_kzalloc(&pdev->dev, struct_size(ad, channels, nchannels), GFP_KERNEL);
 	if (!ad)
@@ -821,6 +839,7 @@ static int admac_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, ad);
 	ad->dev = &pdev->dev;
 	ad->nchannels = nchannels;
+	ad->set_unk28 = hw->set_unk28;
 	mutex_init(&ad->cache_alloc_lock);
 
 	/*
@@ -935,9 +954,18 @@ static void admac_remove(struct platform_device *pdev)
 	reset_control_rearm(ad->rstc);
 }
 
+static const struct admac_hw admac_t8103_hw = {
+	.set_unk28 = false,
+};
+
+static const struct admac_hw admac_t8122_hw = {
+	.set_unk28 = true,
+};
+
 static const struct of_device_id admac_of_match[] = {
-	{ .compatible = "apple,t8103-admac", },
-	{ .compatible = "apple,admac", },
+	{ .compatible = "apple,t8122-admac", .data = &admac_t8122_hw },
+	{ .compatible = "apple,t8103-admac", .data = &admac_t8103_hw },
+	{ .compatible = "apple,admac", .data = &admac_t8103_hw },
 	{ }
 };
 MODULE_DEVICE_TABLE(of, admac_of_match);
Signature · 1 line
2.55.0
#4 lore raw

Re: [PATCH v2 2/2] dmaengine: apple-admac: Add M3 generation ADMACs

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] The driver schedules a tasklet for DMA channel completion but fails to kill it upon driver unbind, leading to a Use-After-Free.
- [High] Missing memory barrier between CPU writes to the DMA buffer and triggering the hardware via MMIO.
--

--- Patch [2]: [PATCH v2 2/2] dmaengine: apple-admac: Add M3 generation ADMACs --- commit 3e4665bdfbbc14988e79c929d83bff445def0885
Author: Sasha Finkelstein <[email protected]>

dmaengine: apple-admac: Add M3 generation ADMACs

The admacs present on t8122 and t603x SoCs need additional writes in order to operate correctly. The exact purpose of this register is unknown

Quoted 4 lines
drivers/dma/apple-admac.c +0 -0
index 14a5ee14a4815..72ff677c8ce54 100644

[ ... ]

drivers/dma/apple-admac.c static void admac_remove(struct platform_device *pdev) · line 955

Quoted 3 lines
drivers/dma/apple-admac.c +0 -0
@@ -935,9 +954,18 @@ static void admac_remove(struct platform_device *pdev)
 	reset_control_rearm(ad->rstc);
 }

[Severity: High]
This isn't a bug introduced by this patch, but I noticed the driver schedules a tasklet for DMA channel completion but fails to kill it upon driver unbind.

Does this leave the code open to a use-after-free? If an interrupt fires just before free_irq() and schedules the tasklet, the tasklet may run after admac_remove() returns and the devm_kzalloc managed memory (struct admac_data) is freed.

Could we add a call to tasklet_kill() during the teardown sequence?

[Severity: High]
This is another pre-existing issue not touched by this patch, but I noticed missing memory barriers when the hardware is started via MMIO.

Looking at admac_start_chan() and admac_cyclic_write_one_desc():

drivers/dma/apple-admac.c:admac_start_chan() {
    ...
	switch (admac_chan_direction(adchan->no)) {
	case DMA_MEM_TO_DEV:
		writel_relaxed(startbit, ad->base + REG_TX_START);
		break;
    ...
}
drivers/dma/apple-admac.c:admac_cyclic_write_one_desc() {
    ...
	writel_relaxed(lower_32_bits(addr), ad->base + REG_DESC_WRITE(channo));
	writel_relaxed(upper_32_bits(addr), ad->base + REG_DESC_WRITE(channo));
    ...
}

Could CPU writes to the DMA buffer be delayed and become visible to the DMA controller only after it starts fetching data?

Since writel_relaxed() does not include a memory barrier on ARM64 architectures and spin_lock only provides ACQUIRE semantics, prior memory stores to the DMA buffer might be reordered after the MMIO write. Does this require a memory barrier to prevent transmitting stale data?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
maintainer
#5 lore raw

Re: [PATCH v2 2/2] dmaengine: apple-admac: Add M3 generation ADMACs

In reply to Sasha Finkelstein
Quoted 14 lines · Sasha Finkelstein

The admacs present on t8122 and t603x SoCs need additional writes in order to operate correctly. The exact purpose of this register is unknown

---
 drivers/dma/apple-admac.c | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)
drivers/dma/apple-admac.c +0 -0
index 14a5ee14a481..72ff677c8ce5 100644

drivers/dma/apple-admac.c line 42

Quoted 4 lines
drivers/dma/apple-admac.c +1 -0
@@ -39,10 +39,14 @@
 
 #define FLAG_DESC_NOTIFY	BIT(16)
 
+#define T8122_UNK_28_VAL	0x200000

maybe BIT(21)

Quoted 29 lines
drivers/dma/apple-admac.c +7 -0
 #define REG_TX_START		0x0000
 #define REG_TX_STOP		0x0004
 #define REG_RX_START		0x0008
 #define REG_RX_STOP		0x000c
+#define REG_UNK_28		0x0028
+#define REG_UNK_2C		0x002c
 #define REG_IMPRINT		0x0090
 #define REG_TX_SRAM_SIZE	0x0094
 #define REG_RX_SRAM_SIZE	0x0098
@@ -127,6 +131,7 @@ struct admac_data {
 	struct mutex cache_alloc_lock;
 	struct admac_sram txcache, rxcache;
 
+	bool set_unk28;
 	int irq;
 	int irq_index;
 	int nchannels;
@@ -147,6 +152,10 @@ struct admac_tx {
 	struct list_head node;
 };
 
+struct admac_hw {
+	bool set_unk28;
+};
+
 static int admac_alloc_sram_carveout(struct admac_data *ad,
 				     enum dma_transfer_direction dir,
 				     u32 *out)

drivers/dma/apple-admac.c static int admac_device_config(struct dma_chan *chan, · line 762

Quoted 7 lines
drivers/dma/apple-admac.c +4 -0
@@ -747,6 +756,11 @@ static int admac_device_config(struct dma_chan *chan,
 	u32 bus_width = readl_relaxed(ad->base + REG_BUS_WIDTH(adchan->no)) &
 		~(BUS_WIDTH_WORD_SIZE | BUS_WIDTH_FRAME_SIZE);
 
+	if (ad->set_unk28) {
+		writel_relaxed(T8122_UNK_28_VAL, ad->base + REG_UNK_28);
+		writel_relaxed(T8122_UNK_28_VAL, ad->base + REG_UNK_2C);
+	}

can this be done in probe? This writes the same value for every channel without obvious way how the bit in those two registers can reset? If it needs to be done here a comment explaining why would be useful.

If it can be done in probe we could avoid putting set_unk28 into struct admac_data.

Janne

#6 lore raw

Re: [PATCH v2 2/2] dmaengine: apple-admac: Add M3 generation ADMACs

Quoted 17 lines · Janne Grunau
Quoted 15 lines · Sasha Finkelstein

The admacs present on t8122 and t603x SoCs need additional writes in order to operate correctly. The exact purpose of this register is unknown

---
drivers/dma/apple-admac.c | 32 ++++++++++++++++++++++++++++++--

1 file changed, 30 insertions(+), 2 deletions(-)
drivers/dma/apple-admac.c +0 -0
index 14a5ee14a481..72ff677c8ce5 100644
@@ -39,10 +39,14 @@
 
Quoted 5 lines

drivers/dma/apple-admac.c line 42

Quoted 3 lines
drivers/dma/apple-admac.c +1 -0
 #define FLAG_DESC_NOTIFY BIT(16)
 
+#define T8122_UNK_28_VAL 0x200000

maybe BIT(21)

Probably not, this is not in any way related to channel 21. I suspect but can't confirm that this is rather an address.

Quoted 33 lines
Quoted 33 lines
drivers/dma/apple-admac.c +7 -0
 #define REG_TX_START 0x0000
 #define REG_TX_STOP 0x0004
 #define REG_RX_START 0x0008
 #define REG_RX_STOP 0x000c
+#define REG_UNK_28 0x0028
+#define REG_UNK_2C 0x002c
 #define REG_IMPRINT 0x0090
 #define REG_TX_SRAM_SIZE 0x0094
 #define REG_RX_SRAM_SIZE 0x0098
@@ -127,6 +131,7 @@ struct admac_data {
 struct mutex cache_alloc_lock;
 struct admac_sram txcache, rxcache;
 
+ bool set_unk28;
 int irq;
 int irq_index;
 int nchannels;
@@ -147,6 +152,10 @@ struct admac_tx {
 struct list_head node;
 };
 
+struct admac_hw {
+ bool set_unk28;
+};
+
 static int admac_alloc_sram_carveout(struct admac_data *ad,
     enum dma_transfer_direction dir,
     u32 *out)
@@ -747,6 +756,11 @@ static int admac_device_config(struct dma_chan *chan,

u32 bus_width = readl_relaxed(ad->base + REG_BUS_WIDTH(adchan->no)) & ~(BUS_WIDTH_WORD_SIZE | BUS_WIDTH_FRAME_SIZE);

Quoted 8 lines
Quoted 4 lines

+ if (ad->set_unk28) {
+ writel_relaxed(T8122_UNK_28_VAL, ad->base + REG_UNK_28);
+ writel_relaxed(T8122_UNK_28_VAL, ad->base + REG_UNK_2C);
+ }

can this be done in probe? This writes the same value for every channel without obvious way how the bit in those two registers can reset? If it needs to be done here a comment explaining why would be useful.

Those are getting reset. The AOP-attached ADMAC has it's power controlled by the AOP firmware, so I can't even touch any registers in probe, as the hw is off at that point and will SError at us. device_config is the earliest point when the ADMAC is powered on. There is an explanation of this setup in the commit history for this file. (8d55e8a16f019211163f1180fd9f9fbe05901900)

maintainer
#7 lore raw

Re: [PATCH v2 2/2] dmaengine: apple-admac: Add M3 generation ADMACs

In reply to Sasha Finkelstein
Quoted 86 lines · Sasha Finkelstein

The admacs present on t8122 and t603x SoCs need additional writes in order to operate correctly. The exact purpose of this register is unknown

---
 drivers/dma/apple-admac.c | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)
drivers/dma/apple-admac.c +19 -0
index 14a5ee14a481..72ff677c8ce5 100644
@@ -39,10 +39,14 @@
 
 #define FLAG_DESC_NOTIFY	BIT(16)
 
+#define T8122_UNK_28_VAL	0x200000
+
 #define REG_TX_START		0x0000
 #define REG_TX_STOP		0x0004
 #define REG_RX_START		0x0008
 #define REG_RX_STOP		0x000c
+#define REG_UNK_28		0x0028
+#define REG_UNK_2C		0x002c
 #define REG_IMPRINT		0x0090
 #define REG_TX_SRAM_SIZE	0x0094
 #define REG_RX_SRAM_SIZE	0x0098
@@ -127,6 +131,7 @@ struct admac_data {
 	struct mutex cache_alloc_lock;
 	struct admac_sram txcache, rxcache;
 
+	bool set_unk28;
 	int irq;
 	int irq_index;
 	int nchannels;
@@ -147,6 +152,10 @@ struct admac_tx {
 	struct list_head node;
 };
 
+struct admac_hw {
+	bool set_unk28;
+};
+
 static int admac_alloc_sram_carveout(struct admac_data *ad,
 				     enum dma_transfer_direction dir,
 				     u32 *out)
@@ -747,6 +756,11 @@ static int admac_device_config(struct dma_chan *chan,
 	u32 bus_width = readl_relaxed(ad->base + REG_BUS_WIDTH(adchan->no)) &
 		~(BUS_WIDTH_WORD_SIZE | BUS_WIDTH_FRAME_SIZE);
 
+	if (ad->set_unk28) {
+		writel_relaxed(T8122_UNK_28_VAL, ad->base + REG_UNK_28);
+		writel_relaxed(T8122_UNK_28_VAL, ad->base + REG_UNK_2C);
+	}
+
 	switch (is_tx ? config->dst_addr_width : config->src_addr_width) {
 	case DMA_SLAVE_BUSWIDTH_1_BYTE:
 		wordsize = 1;
@@ -805,6 +819,7 @@ static int admac_probe(struct platform_device *pdev)
 	struct device_node *np = pdev->dev.of_node;
 	struct admac_data *ad;
 	struct dma_device *dma;
+	const struct admac_hw *hw;
 	int nchannels;
 	int err, irq, i;
 
@@ -813,6 +828,9 @@ static int admac_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev, "missing or invalid dma-channels property\n");
 		return -EINVAL;
 	}
+	hw = of_device_get_match_data(&pdev->dev);
+	if (!hw)
+		return -EINVAL;
 
 	ad = devm_kzalloc(&pdev->dev, struct_size(ad, channels, nchannels), GFP_KERNEL);
 	if (!ad)
@@ -821,6 +839,7 @@ static int admac_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, ad);
 	ad->dev = &pdev->dev;
 	ad->nchannels = nchannels;
+	ad->set_unk28 = hw->set_unk28;
 	mutex_init(&ad->cache_alloc_lock);
 
 	/*

drivers/dma/apple-admac.c static void admac_remove(struct platform_device *pdev) · line 959

Quoted 6 lines
drivers/dma/apple-admac.c +3 -0
@@ -935,9 +954,18 @@ static void admac_remove(struct platform_device *pdev)
 	reset_control_rearm(ad->rstc);
 }
 
+static const struct admac_hw admac_t8103_hw = {
+	.set_unk28 = false,
+};

This is dummy, why not this be default

drivers/dma/apple-admac.c static void admac_remove(struct platform_device *pdev) · line 962

Quoted 3 lines
drivers/dma/apple-admac.c +3 -0
+
+static const struct admac_hw admac_t8122_hw = {
+	.set_unk28 = true,

and we set this

drivers/dma/apple-admac.c static void admac_remove(struct platform_device *pdev) · line 968

Quoted 8 lines
drivers/dma/apple-admac.c +5 -2
+};
+
 static const struct of_device_id admac_of_match[] = {
-	{ .compatible = "apple,t8103-admac", },
-	{ .compatible = "apple,admac", },
+	{ .compatible = "apple,t8122-admac", .data = &admac_t8122_hw },
+	{ .compatible = "apple,t8103-admac", .data = &admac_t8103_hw },
+	{ .compatible = "apple,admac", .data = &admac_t8103_hw },

so only change would be adding this for admac_t8122_hw. If driver data is not defined (older and whereever not used), we dont set these..

Quoted 6 lines
drivers/dma/apple-admac.c +0 -0
 	{ }
 };
 MODULE_DEVICE_TABLE(of, admac_of_match);
Signature · 2 lines
-- 
2.55.0
Signature · 1 line
~Vinod