Skip to contentSkip to conversation

drm: Provide a dedicated DMA device for PRIME import

PATCH Superseded Thomas Zimmermann 3 participants 9 messages Feb 28, 2025 – Mar 3, 2025

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Thomas Zimmermann

author maintainer
#0 lore raw

cover drm: Provide a dedicated DMA device for PRIME import

Importing dma-bufs via PRIME requires a DMA-capable hardware device. This is not the case for USB, where DMA is controller entirely by the USB controller instead of the USB devices.

Drivers for USB-based hardware maintainer their own workaround for this problem. The original ideas to resolve this was to provide different PRIME helpers for such devices, but the dma-buf code assumes DMA functionality as well. So that ideas is not realistic.

Let's instead turn the current workaround into a feature. It will also be useful in other code.

Patch 1 add a dma_device field to struct drm_device and makes the PRIME code use it. Patches 2 to 4 replace related driver code.

There are other possible users of the new field. The exynos and mediatek drivers already maintain a dedicated DMA device for non-PRIME code. They could likely use dma_dev as well. GEM-DMA helpers currently allocate DMA memory with the regular parent device. They should support the dma_dev settings as well.

Tested with udl.

Thomas Zimmermann (4):
drm/prime: Support dedicated DMA device for dma-buf imports drm/gm12u320: Set struct drm_device.dma_dev drm/gud: Set struct drm_device.dma_dev
drm/udl: Set struct drm_device.dma_dev

 drivers/gpu/drm/drm_drv.c          |  2 ++
 drivers/gpu/drm/drm_prime.c        |  2 +-
 drivers/gpu/drm/gud/gud_drv.c      | 26 +++----------------
 drivers/gpu/drm/gud/gud_internal.h |  1 -
 drivers/gpu/drm/tiny/gm12u320.c    | 41 ++++++------------------------
 drivers/gpu/drm/udl/udl_drv.c      | 17 -------------
 drivers/gpu/drm/udl/udl_drv.h      |  1 -
 drivers/gpu/drm/udl/udl_main.c     |  9 ++-----
 include/drm/drm_device.h           | 37 +++++++++++++++++++++++++++
 9 files changed, 53 insertions(+), 83 deletions(-)
Signature · 1 line
2.48.1
author maintainer
#1 lore raw

PATCH 1/4 drm/prime: Support dedicated DMA device for dma-buf imports

Importing dma-bufs via PRIME requires a DMA-capable device. Devices on peripheral busses, such as USB, often cannot perform DMA by themselves. Without DMA-capable device PRIME import fails. DRM drivers for USB devices already use a separate DMA device for dma-buf imports. Make the mechanism generally available.

Add the field dma_dev to struct drm_device to refer to the device's DMA device. For USB this should be the USB controller. Use dma_dev in the PRIME import helpers, if set.

---
 drivers/gpu/drm/drm_drv.c   |  2 ++
 drivers/gpu/drm/drm_prime.c |  2 +-
 include/drm/drm_device.h    | 37 +++++++++++++++++++++++++++++++++++++
 3 files changed, 40 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_drv.c +2 -0
index 17fc5dc708f4..f8c3c9f77d22 100644
@@ -654,6 +654,8 @@ static void drm_dev_init_release(struct drm_device *dev, void *res)
 {
 	drm_fs_inode_free(dev->anon_inode);
 
+	put_device(dev->dma_dev);
+	dev->dma_dev = NULL;
 	put_device(dev->dev);
 	/* Prevent use-after-free in drm_managed_release when debugging is
 	 * enabled. Slightly awkward, but can't really be helped. */
drivers/gpu/drm/drm_prime.c +1 -1
index 32a8781cfd67..258858f2f8dd 100644
@@ -1004,7 +1004,7 @@ EXPORT_SYMBOL(drm_gem_prime_import_dev);
 struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,
 					    struct dma_buf *dma_buf)
 {
-	return drm_gem_prime_import_dev(dev, dma_buf, dev->dev);
+	return drm_gem_prime_import_dev(dev, dma_buf, drm_dev_dma_dev(dev));
 }
 EXPORT_SYMBOL(drm_gem_prime_import);
 
include/drm/drm_device.h +37 -0
index 6ea54a578cda..a24cac4b2077 100644
@@ -64,6 +64,23 @@ struct drm_device {
 	/** @dev: Device structure of bus-device */
 	struct device *dev;
 
+	/**
+	 * @dma_dev:
+	 *
+	 * Device for DMA operations. Only required if the device @dev
+	 * cannot perform DMA by itself. Should be NULL otherwise.
+	 *
+	 * Devices on USB and other peripheral busses cannot perform DMA
+	 * by themselves. The @dma_dev field should point the bus controller
+	 * that does DMA on behalve of such a device. Required for importing
+	 * buffers via dma-buf.
+	 *
+	 * If set, the DRM driver has to acquire a reference on the DMA
+	 * device, which will be owned and released automatically by the
+	 * DRM core.
+	 */
+	struct device *dma_dev;
+
 	/**
 	 * @managed:
 	 *
@@ -327,4 +344,24 @@ struct drm_device {
 	struct dentry *debugfs_root;
 };
 
+/**
+ * drm_dev_dma_dev - returns the DMA device for a DRM device
+ * @dev: DRM device
+ *
+ * Returns the DMA device of the given DRM device. This is usually
+ * the same as the DRM device's parent. Devices on some peripheral
+ * busses, such as USB, are incapable of performing DMA by themselves.
+ * Drivers should set struct &drm_device.dma_dev to the bus controller
+ * to make DMA work. Required for PRIME buffer import.
+ *
+ * Returns:
+ * A DMA-capable device for the DRM device.
+ */
+static inline struct device *drm_dev_dma_dev(struct drm_device *dev)
+{
+	if (dev->dma_dev)
+		return dev->dma_dev;
+	return dev->dev;
+}
+
 #endif
Signature · 1 line
2.48.1
#2 lore raw

Re: [PATCH 1/4] drm/prime: Support dedicated DMA device for dma-buf imports

Quoted 22 lines · Thomas Zimmermann

Importing dma-bufs via PRIME requires a DMA-capable device. Devices on peripheral busses, such as USB, often cannot perform DMA by themselves. Without DMA-capable device PRIME import fails. DRM drivers for USB devices already use a separate DMA device for dma-buf imports. Make the mechanism generally available.

Add the field dma_dev to struct drm_device to refer to the device's DMA device. For USB this should be the USB controller. Use dma_dev in the PRIME import helpers, if set.

---
 drivers/gpu/drm/drm_drv.c   |  2 ++
 drivers/gpu/drm/drm_prime.c |  2 +-
 include/drm/drm_device.h    | 37 +++++++++++++++++++++++++++++++++++++
 3 files changed, 40 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_drv.c +0 -0
index 17fc5dc708f4..f8c3c9f77d22 100644

drivers/gpu/drm/drm_drv.c static void drm_dev_init_release(struct drm_device *dev, void *res) · line 658

Quoted 5 lines
drivers/gpu/drm/drm_drv.c +2 -0
@@ -654,6 +654,8 @@ static void drm_dev_init_release(struct drm_device *dev, void *res)
 {
 	drm_fs_inode_free(dev->anon_inode);
 
+	put_device(dev->dma_dev);
+	dev->dma_dev = NULL;

The asymmetry in who gets and puts the ->dma_dev bugs me.

You could avoid that by providing a helper for setting ->dma_dev, and having that get the device:

int drm_dev_set_dma_device(struct drm_device *drm, struct device *dma_device)

{
	dev->dma_dev = get_device(dma_device);

	return dev->dma_dev ? 0 : -ENODEV.
}

Taking drm/gm12u320 from patch 2 as an example, it would become:

	dma_device = usb_intf_get_dma_device(to_usb_interface(dev->dev))
	if (drm_dev_set_dma_device(drm, dma_device))
		drm_warn(dev, "buffer sharing not supported"); /* not an error */
	put_device(dma_device);

Sligthly more verbose, but has a get/put pair in the driver, and a get/put pair in the core, instead of the asymmetry.

I'm not insisting, but something to consider.

BR,
Jani.

Quoted 69 lines
drivers/gpu/drm/drm_drv.c +0 -0
 	put_device(dev->dev);
 	/* Prevent use-after-free in drm_managed_release when debugging is
 	 * enabled. Slightly awkward, but can't really be helped. */
drivers/gpu/drm/drm_prime.c +1 -1
index 32a8781cfd67..258858f2f8dd 100644
@@ -1004,7 +1004,7 @@ EXPORT_SYMBOL(drm_gem_prime_import_dev);
 struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,
 					    struct dma_buf *dma_buf)
 {
-	return drm_gem_prime_import_dev(dev, dma_buf, dev->dev);
+	return drm_gem_prime_import_dev(dev, dma_buf, drm_dev_dma_dev(dev));
 }
 EXPORT_SYMBOL(drm_gem_prime_import);
 
include/drm/drm_device.h +37 -0
index 6ea54a578cda..a24cac4b2077 100644
@@ -64,6 +64,23 @@ struct drm_device {
 	/** @dev: Device structure of bus-device */
 	struct device *dev;
 
+	/**
+	 * @dma_dev:
+	 *
+	 * Device for DMA operations. Only required if the device @dev
+	 * cannot perform DMA by itself. Should be NULL otherwise.
+	 *
+	 * Devices on USB and other peripheral busses cannot perform DMA
+	 * by themselves. The @dma_dev field should point the bus controller
+	 * that does DMA on behalve of such a device. Required for importing
+	 * buffers via dma-buf.
+	 *
+	 * If set, the DRM driver has to acquire a reference on the DMA
+	 * device, which will be owned and released automatically by the
+	 * DRM core.
+	 */
+	struct device *dma_dev;
+
 	/**
 	 * @managed:
 	 *
@@ -327,4 +344,24 @@ struct drm_device {
 	struct dentry *debugfs_root;
 };
 
+/**
+ * drm_dev_dma_dev - returns the DMA device for a DRM device
+ * @dev: DRM device
+ *
+ * Returns the DMA device of the given DRM device. This is usually
+ * the same as the DRM device's parent. Devices on some peripheral
+ * busses, such as USB, are incapable of performing DMA by themselves.
+ * Drivers should set struct &drm_device.dma_dev to the bus controller
+ * to make DMA work. Required for PRIME buffer import.
+ *
+ * Returns:
+ * A DMA-capable device for the DRM device.
+ */
+static inline struct device *drm_dev_dma_dev(struct drm_device *dev)
+{
+	if (dev->dma_dev)
+		return dev->dma_dev;
+	return dev->dev;
+}
+
 #endif
Signature · 1 line
Jani Nikula, Intel
author maintainer
#3 lore raw

Re: [PATCH 1/4] drm/prime: Support dedicated DMA device for dma-buf imports

Hi

Am 28.02.25 um 12:21 schrieb Jani Nikula:

Quoted 47 lines · Thomas Zimmermann
Quoted 22 lines

Importing dma-bufs via PRIME requires a DMA-capable device. Devices on peripheral busses, such as USB, often cannot perform DMA by themselves. Without DMA-capable device PRIME import fails. DRM drivers for USB devices already use a separate DMA device for dma-buf imports. Make the mechanism generally available.

Add the field dma_dev to struct drm_device to refer to the device's DMA device. For USB this should be the USB controller. Use dma_dev in the PRIME import helpers, if set.

---
  drivers/gpu/drm/drm_drv.c   |  2 ++
  drivers/gpu/drm/drm_prime.c |  2 +-
  include/drm/drm_device.h    | 37 +++++++++++++++++++++++++++++++++++++
  3 files changed, 40 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_drv.c +0 -0
index 17fc5dc708f4..f8c3c9f77d22 100644

drivers/gpu/drm/drm_drv.c static void drm_dev_init_release(struct drm_device *dev, void *res) · line 658

Quoted 5 lines
drivers/gpu/drm/drm_drv.c +2 -0
@@ -654,6 +654,8 @@ static void drm_dev_init_release(struct drm_device *dev, void *res)
  {
  	drm_fs_inode_free(dev->anon_inode);
 
+	put_device(dev->dma_dev);
+	dev->dma_dev = NULL;

The asymmetry in who gets and puts the ->dma_dev bugs me.

You could avoid that by providing a helper for setting ->dma_dev, and having that get the device:

int drm_dev_set_dma_device(struct drm_device *drm, struct device *dma_device)

{
	dev->dma_dev = get_device(dma_device);

	return dev->dma_dev ? 0 : -ENODEV.
}

Taking drm/gm12u320 from patch 2 as an example, it would become:

	dma_device = usb_intf_get_dma_device(to_usb_interface(dev->dev))
	if (drm_dev_set_dma_device(drm, dma_device))
		drm_warn(dev, "buffer sharing not supported"); /* not an error */
	put_device(dma_device);
Quoted 4 lines

Sligthly more verbose, but has a get/put pair in the driver, and a get/put pair in the core, instead of the asymmetry.

I'm not insisting, but something to consider.

We're doing a get_device() on the regular parent kept in dev. So yeah, keeping a ref on the dma_dev would make sense.

Best regards
Thomas

Quoted 75 lines

BR,
Jani.

Quoted 69 lines
drivers/gpu/drm/drm_drv.c +0 -0
  	put_device(dev->dev);
  	/* Prevent use-after-free in drm_managed_release when debugging is
  	 * enabled. Slightly awkward, but can't really be helped. */
drivers/gpu/drm/drm_prime.c +1 -1
index 32a8781cfd67..258858f2f8dd 100644
@@ -1004,7 +1004,7 @@ EXPORT_SYMBOL(drm_gem_prime_import_dev);
  struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,
  					    struct dma_buf *dma_buf)
  {
-	return drm_gem_prime_import_dev(dev, dma_buf, dev->dev);
+	return drm_gem_prime_import_dev(dev, dma_buf, drm_dev_dma_dev(dev));
  }
  EXPORT_SYMBOL(drm_gem_prime_import);
 
include/drm/drm_device.h +37 -0
index 6ea54a578cda..a24cac4b2077 100644
@@ -64,6 +64,23 @@ struct drm_device {
  	/** @dev: Device structure of bus-device */
  	struct device *dev;
 
+	/**
+	 * @dma_dev:
+	 *
+	 * Device for DMA operations. Only required if the device @dev
+	 * cannot perform DMA by itself. Should be NULL otherwise.
+	 *
+	 * Devices on USB and other peripheral busses cannot perform DMA
+	 * by themselves. The @dma_dev field should point the bus controller
+	 * that does DMA on behalve of such a device. Required for importing
+	 * buffers via dma-buf.
+	 *
+	 * If set, the DRM driver has to acquire a reference on the DMA
+	 * device, which will be owned and released automatically by the
+	 * DRM core.
+	 */
+	struct device *dma_dev;
+
  	/**
  	 * @managed:
  	 *
@@ -327,4 +344,24 @@ struct drm_device {
  	struct dentry *debugfs_root;
  };
 
+/**
+ * drm_dev_dma_dev - returns the DMA device for a DRM device
+ * @dev: DRM device
+ *
+ * Returns the DMA device of the given DRM device. This is usually
+ * the same as the DRM device's parent. Devices on some peripheral
+ * busses, such as USB, are incapable of performing DMA by themselves.
+ * Drivers should set struct &drm_device.dma_dev to the bus controller
+ * to make DMA work. Required for PRIME buffer import.
+ *
+ * Returns:
+ * A DMA-capable device for the DRM device.
+ */
+static inline struct device *drm_dev_dma_dev(struct drm_device *dev)
+{
+	if (dev->dma_dev)
+		return dev->dma_dev;
+	return dev->dev;
+}
+
  #endif
Signature · 7 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
maintainer
#4 lore raw

Re: [PATCH 1/4] drm/prime: Support dedicated DMA device for dma-buf imports

In reply to Thomas Zimmermann

Hi Thomas,

Quoted 58 lines · Thomas Zimmermann

Importing dma-bufs via PRIME requires a DMA-capable device. Devices on peripheral busses, such as USB, often cannot perform DMA by themselves. Without DMA-capable device PRIME import fails. DRM drivers for USB devices already use a separate DMA device for dma-buf imports. Make the mechanism generally available.

Add the field dma_dev to struct drm_device to refer to the device's DMA device. For USB this should be the USB controller. Use dma_dev in the PRIME import helpers, if set.

---
 drivers/gpu/drm/drm_drv.c   |  2 ++
 drivers/gpu/drm/drm_prime.c |  2 +-
 include/drm/drm_device.h    | 37 +++++++++++++++++++++++++++++++++++++
 3 files changed, 40 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_drv.c +2 -0
index 17fc5dc708f4..f8c3c9f77d22 100644
@@ -654,6 +654,8 @@ static void drm_dev_init_release(struct drm_device *dev, void *res)
 {
 	drm_fs_inode_free(dev->anon_inode);
 
+	put_device(dev->dma_dev);
+	dev->dma_dev = NULL;
 	put_device(dev->dev);
 	/* Prevent use-after-free in drm_managed_release when debugging is
 	 * enabled. Slightly awkward, but can't really be helped. */
drivers/gpu/drm/drm_prime.c +1 -1
index 32a8781cfd67..258858f2f8dd 100644
@@ -1004,7 +1004,7 @@ EXPORT_SYMBOL(drm_gem_prime_import_dev);
 struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,
 					    struct dma_buf *dma_buf)
 {
-	return drm_gem_prime_import_dev(dev, dma_buf, dev->dev);
+	return drm_gem_prime_import_dev(dev, dma_buf, drm_dev_dma_dev(dev));
 }
 EXPORT_SYMBOL(drm_gem_prime_import);
 
include/drm/drm_device.h +7 -0
index 6ea54a578cda..a24cac4b2077 100644
@@ -64,6 +64,23 @@ struct drm_device {
 	/** @dev: Device structure of bus-device */
 	struct device *dev;
 
+	/**
+	 * @dma_dev:
+	 *
+	 * Device for DMA operations. Only required if the device @dev
+	 * cannot perform DMA by itself. Should be NULL otherwise.
+	 *
+	 * Devices on USB and other peripheral busses cannot perform DMA

include/drm/drm_device.h struct drm_device { · line 83

Quoted 10 lines
include/drm/drm_device.h +10 -0
+	 * by themselves. The @dma_dev field should point the bus controller
+	 * that does DMA on behalve of such a device. Required for importing
+	 * buffers via dma-buf.
+	 *
+	 * If set, the DRM driver has to acquire a reference on the DMA
+	 * device, which will be owned and released automatically by the
+	 * DRM core.
+	 */
+	struct device *dma_dev;
+

It looks good to me in general, but this is also useful with ARM platform is general. On those, the DRM device is bound to a virtual device (and thus can't do DMA), but the HW accesses will be done by one or more HW controllers that are part of the overall DRM driver.

Thus, we typically have to make hacks to copy to the virtual device DMA setup from the actual device doing the DMA accesses.

See for example
https://elixir.bootlin.com/linux/v6.13.5/source/drivers/gpu/drm/vc4/vc4_drv.c#L313
https://elixir.bootlin.com/linux/v6.13.5/source/drivers/gpu/drm/sun4i/sun4i_backend.c#L797

It's probably worth documenting.

Maxime

author maintainer
#5 lore raw

Re: [PATCH 1/4] drm/prime: Support dedicated DMA device for dma-buf imports

Hi

Am 03.03.25 um 10:57 schrieb Maxime Ripard:

Quoted 76 lines

Hi Thomas,

Quoted 58 lines · Thomas Zimmermann

Importing dma-bufs via PRIME requires a DMA-capable device. Devices on peripheral busses, such as USB, often cannot perform DMA by themselves. Without DMA-capable device PRIME import fails. DRM drivers for USB devices already use a separate DMA device for dma-buf imports. Make the mechanism generally available.

Add the field dma_dev to struct drm_device to refer to the device's DMA device. For USB this should be the USB controller. Use dma_dev in the PRIME import helpers, if set.

---
  drivers/gpu/drm/drm_drv.c   |  2 ++
  drivers/gpu/drm/drm_prime.c |  2 +-
  include/drm/drm_device.h    | 37 +++++++++++++++++++++++++++++++++++++
  3 files changed, 40 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_drv.c +2 -0
index 17fc5dc708f4..f8c3c9f77d22 100644
@@ -654,6 +654,8 @@ static void drm_dev_init_release(struct drm_device *dev, void *res)
  {
  	drm_fs_inode_free(dev->anon_inode);
 
+	put_device(dev->dma_dev);
+	dev->dma_dev = NULL;
  	put_device(dev->dev);
  	/* Prevent use-after-free in drm_managed_release when debugging is
  	 * enabled. Slightly awkward, but can't really be helped. */
drivers/gpu/drm/drm_prime.c +1 -1
index 32a8781cfd67..258858f2f8dd 100644
@@ -1004,7 +1004,7 @@ EXPORT_SYMBOL(drm_gem_prime_import_dev);
  struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,
  					    struct dma_buf *dma_buf)
  {
-	return drm_gem_prime_import_dev(dev, dma_buf, dev->dev);
+	return drm_gem_prime_import_dev(dev, dma_buf, drm_dev_dma_dev(dev));
  }
  EXPORT_SYMBOL(drm_gem_prime_import);
 
include/drm/drm_device.h +7 -0
index 6ea54a578cda..a24cac4b2077 100644
@@ -64,6 +64,23 @@ struct drm_device {
  	/** @dev: Device structure of bus-device */
  	struct device *dev;
 
+	/**
+	 * @dma_dev:
+	 *
+	 * Device for DMA operations. Only required if the device @dev
+	 * cannot perform DMA by itself. Should be NULL otherwise.
+	 *
+	 * Devices on USB and other peripheral busses cannot perform DMA

include/drm/drm_device.h struct drm_device { · line 83

Quoted 10 lines
include/drm/drm_device.h +10 -0
+	 * by themselves. The @dma_dev field should point the bus controller
+	 * that does DMA on behalve of such a device. Required for importing
+	 * buffers via dma-buf.
+	 *
+	 * If set, the DRM driver has to acquire a reference on the DMA
+	 * device, which will be owned and released automatically by the
+	 * DRM core.
+	 */
+	struct device *dma_dev;
+

It looks good to me in general, but this is also useful with ARM platform is general. On those, the DRM device is bound to a virtual device (and thus can't do DMA), but the HW accesses will be done by one or more HW controllers that are part of the overall DRM driver.

Quoted 8 lines

Thus, we typically have to make hacks to copy to the virtual device DMA setup from the actual device doing the DMA accesses.

See for example
https://elixir.bootlin.com/linux/v6.13.5/source/drivers/gpu/drm/vc4/vc4_drv.c#L313
https://elixir.bootlin.com/linux/v6.13.5/source/drivers/gpu/drm/sun4i/sun4i_backend.c#L797

It's probably worth documenting.

Sure, I can do that.

In the series' cover letter, I mention that the GEM-DMA code could use the dma_dev. It seems that these drivers would benefit from such a change.

Best regards
Thomas

Quoted 2 lines

Maxime

Signature · 7 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
author maintainer
#6 lore raw

PATCH 2/4 drm/gm12u320: Set struct drm_device.dma_dev

In reply to Thomas Zimmermann

Set the dma_dev field provided by the DRM device. Required for PRIME dma-buf import. Remove the driver's implementation.

---
 drivers/gpu/drm/tiny/gm12u320.c | 41 +++++++--------------------------
 1 file changed, 8 insertions(+), 33 deletions(-)
drivers/gpu/drm/tiny/gm12u320.c +8 -33
index 41e9bfb2e2ff..caee35ecaaef 100644
@@ -86,7 +86,6 @@ MODULE_PARM_DESC(eco_mode, "Turn on Eco mode (less bright, more silent)");
 
 struct gm12u320_device {
 	struct drm_device	         dev;
-	struct device                   *dmadev;
 	struct drm_simple_display_pipe   pipe;
 	struct drm_connector	         conn;
 	unsigned char                   *cmd_buf;
@@ -602,22 +601,6 @@ static const uint64_t gm12u320_pipe_modifiers[] = {
 	DRM_FORMAT_MOD_INVALID
 };
 
-/*
- * FIXME: Dma-buf sharing requires DMA support by the importing device.
- *        This function is a workaround to make USB devices work as well.
- *        See todo.rst for how to fix the issue in the dma-buf framework.
- */
-static struct drm_gem_object *gm12u320_gem_prime_import(struct drm_device *dev,
-							struct dma_buf *dma_buf)
-{
-	struct gm12u320_device *gm12u320 = to_gm12u320(dev);
-
-	if (!gm12u320->dmadev)
-		return ERR_PTR(-ENODEV);
-
-	return drm_gem_prime_import_dev(dev, dma_buf, gm12u320->dmadev);
-}
-
 DEFINE_DRM_GEM_FOPS(gm12u320_fops);
 
 static const struct drm_driver gm12u320_drm_driver = {
@@ -630,7 +613,6 @@ static const struct drm_driver gm12u320_drm_driver = {
 
 	.fops		 = &gm12u320_fops,
 	DRM_GEM_SHMEM_DRIVER_OPS,
-	.gem_prime_import = gm12u320_gem_prime_import,
 	DRM_FBDEV_SHMEM_DRIVER_OPS,
 };
 
@@ -660,8 +642,8 @@ static int gm12u320_usb_probe(struct usb_interface *interface,
 		return PTR_ERR(gm12u320);
 	dev = &gm12u320->dev;
 
-	gm12u320->dmadev = usb_intf_get_dma_device(to_usb_interface(dev->dev));
-	if (!gm12u320->dmadev)
+	dev->dma_dev = usb_intf_get_dma_device(to_usb_interface(dev->dev));
+	if (!dev->dma_dev)
 		drm_warn(dev, "buffer sharing not supported"); /* not an error */
 
 	INIT_DELAYED_WORK(&gm12u320->fb_update.work, gm12u320_fb_update_work);
@@ -669,7 +651,7 @@ static int gm12u320_usb_probe(struct usb_interface *interface,
 
 	ret = drmm_mode_config_init(dev);
 	if (ret)
-		goto err_put_device;
+		return ret;
 
 	dev->mode_config.min_width = GM12U320_USER_WIDTH;
 	dev->mode_config.max_width = GM12U320_USER_WIDTH;
@@ -679,15 +661,15 @@ static int gm12u320_usb_probe(struct usb_interface *interface,
 
 	ret = gm12u320_usb_alloc(gm12u320);
 	if (ret)
-		goto err_put_device;
+		return ret;
 
 	ret = gm12u320_set_ecomode(gm12u320);
 	if (ret)
-		goto err_put_device;
+		return ret;
 
 	ret = gm12u320_conn_init(gm12u320);
 	if (ret)
-		goto err_put_device;
+		return ret;
 
 	ret = drm_simple_display_pipe_init(&gm12u320->dev,
 					   &gm12u320->pipe,
@@ -697,31 +679,24 @@ static int gm12u320_usb_probe(struct usb_interface *interface,
 					   gm12u320_pipe_modifiers,
 					   &gm12u320->conn);
 	if (ret)
-		goto err_put_device;
+		return ret;
 
 	drm_mode_config_reset(dev);
 
 	usb_set_intfdata(interface, dev);
 	ret = drm_dev_register(dev, 0);
 	if (ret)
-		goto err_put_device;
+		return ret;
 
 	drm_client_setup(dev, NULL);
 
 	return 0;
-
-err_put_device:
-	put_device(gm12u320->dmadev);
-	return ret;
 }
 
 static void gm12u320_usb_disconnect(struct usb_interface *interface)
 {
 	struct drm_device *dev = usb_get_intfdata(interface);
-	struct gm12u320_device *gm12u320 = to_gm12u320(dev);
 
-	put_device(gm12u320->dmadev);
-	gm12u320->dmadev = NULL;
 	drm_dev_unplug(dev);
 	drm_atomic_helper_shutdown(dev);
 }
Signature · 1 line
2.48.1
author maintainer
#7 lore raw

PATCH 3/4 drm/gud: Set struct drm_device.dma_dev

In reply to Thomas Zimmermann

Set the dma_dev field provided by the DRM device. Required for PRIME dma-buf import. Remove the driver's implementation.

---
 drivers/gpu/drm/gud/gud_drv.c      | 26 +++-----------------------
 drivers/gpu/drm/gud/gud_internal.h |  1 -
 2 files changed, 3 insertions(+), 24 deletions(-)
drivers/gpu/drm/gud/gud_drv.c +3 -23
index cb405771d6e2..bf7d8cb17333 100644
@@ -309,21 +309,6 @@ static int gud_get_properties(struct gud_device *gdrm)
 	return ret;
 }
 
-/*
- * FIXME: Dma-buf sharing requires DMA support by the importing device.
- *        This function is a workaround to make USB devices work as well.
- *        See todo.rst for how to fix the issue in the dma-buf framework.
- */
-static struct drm_gem_object *gud_gem_prime_import(struct drm_device *drm, struct dma_buf *dma_buf)
-{
-	struct gud_device *gdrm = to_gud_device(drm);
-
-	if (!gdrm->dmadev)
-		return ERR_PTR(-ENODEV);
-
-	return drm_gem_prime_import_dev(drm, dma_buf, gdrm->dmadev);
-}
-
 static int gud_stats_debugfs(struct seq_file *m, void *data)
 {
 	struct drm_debugfs_entry *entry = m->private;
@@ -376,7 +361,6 @@ static const struct drm_driver gud_drm_driver = {
 	.driver_features	= DRIVER_MODESET | DRIVER_GEM | DRIVER_ATOMIC,
 	.fops			= &gud_fops,
 	DRM_GEM_SHMEM_DRIVER_OPS,
-	.gem_prime_import	= gud_gem_prime_import,
 	DRM_FBDEV_SHMEM_DRIVER_OPS,
 
 	.name			= "gud",
@@ -609,17 +593,15 @@ static int gud_probe(struct usb_interface *intf, const struct usb_device_id *id)
 
 	usb_set_intfdata(intf, gdrm);
 
-	gdrm->dmadev = usb_intf_get_dma_device(intf);
-	if (!gdrm->dmadev)
+	drm->dma_dev = usb_intf_get_dma_device(intf);
+	if (!drm->dma_dev)
 		dev_warn(dev, "buffer sharing not supported");
 
 	drm_debugfs_add_file(drm, "stats", gud_stats_debugfs, NULL);
 
 	ret = drm_dev_register(drm, 0);
-	if (ret) {
-		put_device(gdrm->dmadev);
+	if (ret)
 		return ret;
-	}
 
 	drm_kms_helper_poll_init(drm);
 
@@ -638,8 +620,6 @@ static void gud_disconnect(struct usb_interface *interface)
 	drm_kms_helper_poll_fini(drm);
 	drm_dev_unplug(drm);
 	drm_atomic_helper_shutdown(drm);
-	put_device(gdrm->dmadev);
-	gdrm->dmadev = NULL;
 }
 
 static int gud_suspend(struct usb_interface *intf, pm_message_t message)
drivers/gpu/drm/gud/gud_internal.h +0 -1
index 0d148a6f27aa..d6fb25388722 100644
@@ -16,7 +16,6 @@
 struct gud_device {
 	struct drm_device drm;
 	struct drm_simple_display_pipe pipe;
-	struct device *dmadev;
 	struct work_struct work;
 	u32 flags;
 	const struct drm_format_info *xrgb8888_emulation_format;
Signature · 1 line
2.48.1
author maintainer
#8 lore raw

PATCH 4/4 drm/udl: Set struct drm_device.dma_dev

In reply to Thomas Zimmermann

Set the dma_dev field provided by the DRM device. Required for PRIME dma-buf import. Remove the driver's implementation.

---
 drivers/gpu/drm/udl/udl_drv.c  | 17 -----------------
 drivers/gpu/drm/udl/udl_drv.h  |  1 -
 drivers/gpu/drm/udl/udl_main.c |  9 ++-------
 3 files changed, 2 insertions(+), 25 deletions(-)
drivers/gpu/drm/udl/udl_drv.c +0 -17
index 05b3a152cc33..3b56ca2f6eb8 100644
@@ -49,22 +49,6 @@ static int udl_usb_reset_resume(struct usb_interface *interface)
 	return drm_mode_config_helper_resume(dev);
 }
 
-/*
- * FIXME: Dma-buf sharing requires DMA support by the importing device.
- *        This function is a workaround to make USB devices work as well.
- *        See todo.rst for how to fix the issue in the dma-buf framework.
- */
-static struct drm_gem_object *udl_driver_gem_prime_import(struct drm_device *dev,
-							  struct dma_buf *dma_buf)
-{
-	struct udl_device *udl = to_udl(dev);
-
-	if (!udl->dmadev)
-		return ERR_PTR(-ENODEV);
-
-	return drm_gem_prime_import_dev(dev, dma_buf, udl->dmadev);
-}
-
 DEFINE_DRM_GEM_FOPS(udl_driver_fops);
 
 static const struct drm_driver driver = {
@@ -73,7 +57,6 @@ static const struct drm_driver driver = {
 	/* GEM hooks */
 	.fops = &udl_driver_fops,
 	DRM_GEM_SHMEM_DRIVER_OPS,
-	.gem_prime_import = udl_driver_gem_prime_import,
 	DRM_FBDEV_SHMEM_DRIVER_OPS,
 
 	.name = DRIVER_NAME,
drivers/gpu/drm/udl/udl_drv.h +0 -1
index be00dc1d87a1..e67e7e2e6f1f 100644
@@ -51,7 +51,6 @@ struct urb_list {
 struct udl_device {
 	struct drm_device drm;
 	struct device *dev;
-	struct device *dmadev;
 
 	struct drm_plane primary_plane;
 	struct drm_crtc crtc;
drivers/gpu/drm/udl/udl_main.c +2 -7
index 3ebe2ce55dfd..45b745241de6 100644
@@ -311,8 +311,8 @@ int udl_init(struct udl_device *udl)
 
 	DRM_DEBUG("\n");
 
-	udl->dmadev = usb_intf_get_dma_device(to_usb_interface(dev->dev));
-	if (!udl->dmadev)
+	dev->dma_dev = usb_intf_get_dma_device(to_usb_interface(dev->dev));
+	if (!dev->dma_dev)
 		drm_warn(dev, "buffer sharing not supported"); /* not an error */
 
 	mutex_init(&udl->gem_lock);
@@ -343,18 +343,13 @@ int udl_init(struct udl_device *udl)
 err:
 	if (udl->urbs.count)
 		udl_free_urb_list(dev);
-	put_device(udl->dmadev);
 	DRM_ERROR("%d\n", ret);
 	return ret;
 }
 
 int udl_drop_usb(struct drm_device *dev)
 {
-	struct udl_device *udl = to_udl(dev);
-
 	udl_free_urb_list(dev);
-	put_device(udl->dmadev);
-	udl->dmadev = NULL;
 
 	return 0;
 }
Signature · 1 line
2.48.1