Skip to contentSkip to conversation

various dma_mask fixups

PATCH New Christoph Hellwig 3 participants 7 messages Aug 29, 2018 – Aug 30, 2018

Subsystems (3)
lore
Share & tools
lore
#1 lore raw

PATCH 1/3 driver core: initialize a default DMA mask for platform device

We still treat devices without a DMA mask as defaulting to 32-bits for both mask, but a few releases ago we've started warning about such cases, as they require special cases to work around this sloppyness. Add a dma_mask field to struct platform_object so that we can initialize the dma_mask pointer in struct device and initialize both masks to 32-bits by default. Architectures can still override this in arch_setup_pdev_archdata if needed.

Note that the code looks a little odd with the various conditionals because we have to support platform_device structures that are statically allocated.

---
 drivers/base/platform.c         | 15 +++++++++++++--
 include/linux/platform_device.h |  1 +
 2 files changed, 14 insertions(+), 2 deletions(-)
drivers/base/platform.c +13 -2
index dff82a3c2caa..baf4b06cf2d9 100644
@@ -225,6 +225,17 @@ struct platform_object {
 	char name[];
 };
 
+static void setup_pdev_archdata(struct platform_device *pdev)
+{
+	if (!pdev->dev.coherent_dma_mask)
+		pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
+	if (!pdev->dma_mask)
+		pdev->dma_mask = DMA_BIT_MASK(32);
+	if (!pdev->dev.dma_mask)
+		pdev->dev.dma_mask = &pdev->dma_mask;
+	arch_setup_pdev_archdata(pdev);
+};
+
 /**
  * platform_device_put - destroy a platform device
  * @pdev: platform device to free
@@ -271,7 +282,7 @@ struct platform_device *platform_device_alloc(const char *name, int id)
 		pa->pdev.id = id;
 		device_initialize(&pa->pdev.dev);
 		pa->pdev.dev.release = platform_device_release;
-		arch_setup_pdev_archdata(&pa->pdev);
+		setup_pdev_archdata(&pa->pdev);
 	}
 
 	return pa ? &pa->pdev : NULL;
@@ -472,7 +483,7 @@ EXPORT_SYMBOL_GPL(platform_device_del);
 int platform_device_register(struct platform_device *pdev)
 {
 	device_initialize(&pdev->dev);
-	arch_setup_pdev_archdata(pdev);
+	setup_pdev_archdata(pdev);
 	return platform_device_add(pdev);
 }
 EXPORT_SYMBOL_GPL(platform_device_register);
include/linux/platform_device.h +1 -0
index 1a9f38f27f65..d9dc4883d5fb 100644
@@ -25,6 +25,7 @@ struct platform_device {
 	int		id;
 	bool		id_auto;
 	struct device	dev;
+	u64		dma_mask;
 	u32		num_resources;
 	struct resource	*resource;
 
Signature · 1 line
2.18.0
#2 lore raw

PATCH 2/3 sparc: set a default 32-bit dma mask for OF devices

In reply to Christoph Hellwig

This keeps the historic default behavior for devices without a DMA mask, but removes the warning about a lacking DMA mask for doing DMA without a mask.

---
 arch/sparc/kernel/of_device_32.c | 5 +++++
 arch/sparc/kernel/of_device_64.c | 4 ++++
 2 files changed, 9 insertions(+)
arch/sparc/kernel/of_device_32.c +5 -0
index 3641a294ed54..7f3dec7e1e78 100644
@@ -9,6 +9,7 @@
 #include <linux/irq.h>
 #include <linux/of_device.h>
 #include <linux/of_platform.h>
+#include <linux/dma-mapping.h>
 #include <asm/leon.h>
 #include <asm/leon_amba.h>
 
@@ -381,6 +382,10 @@ static struct platform_device * __init scan_one_device(struct device_node *dp,
 	else
 		dev_set_name(&op->dev, "%08x", dp->phandle);
 
+	op->dev.coherent_dma_mask = DMA_BIT_MASK(32);
+	op->dev.dma_mask = &op->dma_mask;
+	op->dma_mask = DMA_BIT_MASK(32);
+
 	if (of_device_register(op)) {
 		printk("%s: Could not register of device.\n",
 		       dp->full_name);
arch/sparc/kernel/of_device_64.c +4 -0
index 44e4d4435bed..d94c31822da1 100644
@@ -2,6 +2,7 @@
 #include <linux/string.h>
 #include <linux/kernel.h>
 #include <linux/of.h>
+#include <linux/dma-mapping.h>
 #include <linux/init.h>
 #include <linux/export.h>
 #include <linux/mod_devicetable.h>
@@ -675,6 +676,9 @@ static struct platform_device * __init scan_one_device(struct device_node *dp,
 		dev_set_name(&op->dev, "root");
 	else
 		dev_set_name(&op->dev, "%08x", dp->phandle);
+	op->dev.coherent_dma_mask = DMA_BIT_MASK(32);
+	op->dev.dma_mask = &op->dma_mask;
+	op->dma_mask = DMA_BIT_MASK(32);
 
 	if (of_device_register(op)) {
 		printk("%s: Could not register of device.\n",
Signature · 1 line
2.18.0
#3 lore raw

PATCH 3/3 of/platform: initialise AMBA default DMA masks

In reply to Christoph Hellwig

From: Linus Walleij <[email protected]>

commit a5516219b102 ("of/platform: Initialise default DMA masks") sets up the coherent_dma_mask of platform devices created from the device tree, but fails to do the same for AMBA (PrimeCell) devices.

This leads to a regression in kernel v4.19-rc1 triggering the WARN_ON_ONCE(dev && !dev->coherent_dma_mask) in dma_alloc_attrs().

This regresses the PL111 DRM driver in drivers/gpu/drm/pl111 that uses the AMBA PrimeCell to instantiate the frame buffer device, as it cannot allocate a chunk of coherent memory anymore due to the missing mask.

Fixes a5516219b102 ("of/platform: Initialise default DMA masks")
[hch: added a comment, and droped a conditional that can't be true]
---
 drivers/of/platform.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/of/platform.c +4 -0
index 7ba90c290a42..6c59673933e9 100644
@@ -241,6 +241,10 @@ static struct amba_device *of_amba_device_create(struct device_node *node,
 	if (!dev)
 		goto err_clear_flag;
 
+	/* AMBA devices only support a single DMA mask */
+	dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
+	dev->dev.dma_mask = &dev->dev.coherent_dma_mask;
+
 	/* setup generic device info */
 	dev->dev.of_node = of_node_get(node);
 	dev->dev.fwnode = &node->fwnode;
Signature · 1 line
2.18.0
#5 lore raw
In reply to Christoph Hellwig
Quoted 1 line · Christoph Hellwig

Fix warnings and regressions from requiring a dma mask.

With this series applied, I see the following in my sh4 boot tests.

sb 1-1: new full-speed USB device number 2 using sm501-usb sm501-usb sm501-usb: OHCI Unrecoverable Error, disabled sm501-usb sm501-usb: HC died; cleaning up

This is a persistent problem. Reverting upstream commit 2f606da7823 ("mfd: sm501: Set coherent_dma_mask when creating subdevices") does not make a difference.

The problem is gone if I do not apply 'driver core: initialize a default DMA mask for platform device'.

On the plus side, the sparc warnings are gone.

Guenter

#6 lore raw
Quoted 5 lines · Guenter Roeck
Quoted 1 line · Christoph Hellwig

Fix warnings and regressions from requiring a dma mask.

With this series applied, I see the following in my sh4 boot tests.

Quoted 8 lines

sb 1-1: new full-speed USB device number 2 using sm501-usb sm501-usb sm501-usb: OHCI Unrecoverable Error, disabled sm501-usb sm501-usb: HC died; cleaning up

This is a persistent problem. Reverting upstream commit 2f606da7823 ("mfd: sm501: Set coherent_dma_mask when creating subdevices") does not make a difference.

This failure is now seen in -next.

Guenter