Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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.

Besides the case of USB, there are embedded DRM devices without DMA
capability. DMA is performed by a separate controller. DRM drivers should
set this accordingly.

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.

v2:
- acquire internal reference on dma_dev (Jani)
- add DMA-controller usecase to docs (Maxime)

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Jani Nikula <jani.nikula@intel.com>
Reviewed-by: Maxime Ripard <mripard@kernel.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20250307080836.42848-2-tzimmermann@suse.de

+63 -1
+21
drivers/gpu/drm/drm_drv.c
··· 500 500 } 501 501 EXPORT_SYMBOL(drm_dev_unplug); 502 502 503 + /** 504 + * drm_dev_set_dma_dev - set the DMA device for a DRM device 505 + * @dev: DRM device 506 + * @dma_dev: DMA device or NULL 507 + * 508 + * Sets the DMA device of the given DRM device. Only required if 509 + * the DMA device is different from the DRM device's parent. After 510 + * calling this function, the DRM device holds a reference on 511 + * @dma_dev. Pass NULL to clear the DMA device. 512 + */ 513 + void drm_dev_set_dma_dev(struct drm_device *dev, struct device *dma_dev) 514 + { 515 + dma_dev = get_device(dma_dev); 516 + 517 + put_device(dev->dma_dev); 518 + dev->dma_dev = dma_dev; 519 + } 520 + EXPORT_SYMBOL(drm_dev_set_dma_dev); 521 + 503 522 /* 504 523 * Available recovery methods for wedged device. To be sent along with device 505 524 * wedged uevent. ··· 673 654 { 674 655 drm_fs_inode_free(dev->anon_inode); 675 656 657 + put_device(dev->dma_dev); 658 + dev->dma_dev = NULL; 676 659 put_device(dev->dev); 677 660 /* Prevent use-after-free in drm_managed_release when debugging is 678 661 * enabled. Slightly awkward, but can't really be helped. */
+1 -1
drivers/gpu/drm/drm_prime.c
··· 997 997 struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev, 998 998 struct dma_buf *dma_buf) 999 999 { 1000 - return drm_gem_prime_import_dev(dev, dma_buf, dev->dev); 1000 + return drm_gem_prime_import_dev(dev, dma_buf, drm_dev_dma_dev(dev)); 1001 1001 } 1002 1002 EXPORT_SYMBOL(drm_gem_prime_import); 1003 1003
+41
include/drm/drm_device.h
··· 65 65 struct device *dev; 66 66 67 67 /** 68 + * @dma_dev: 69 + * 70 + * Device for DMA operations. Only required if the device @dev 71 + * cannot perform DMA by itself. Should be NULL otherwise. Call 72 + * drm_dev_dma_dev() to get the DMA device instead of using this 73 + * field directly. Call drm_dev_set_dma_dev() to set this field. 74 + * 75 + * DRM devices are sometimes bound to virtual devices that cannot 76 + * perform DMA by themselves. Drivers should set this field to the 77 + * respective DMA controller. 78 + * 79 + * Devices on USB and other peripheral busses also cannot perform 80 + * DMA by themselves. The @dma_dev field should point the bus 81 + * controller that does DMA on behalve of such a device. Required 82 + * for importing buffers via dma-buf. 83 + * 84 + * If set, the DRM core automatically releases the reference on the 85 + * device. 86 + */ 87 + struct device *dma_dev; 88 + 89 + /** 68 90 * @managed: 69 91 * 70 92 * Managed resources linked to the lifetime of this &drm_device as ··· 348 326 */ 349 327 struct dentry *debugfs_root; 350 328 }; 329 + 330 + void drm_dev_set_dma_dev(struct drm_device *dev, struct device *dma_dev); 331 + 332 + /** 333 + * drm_dev_dma_dev - returns the DMA device for a DRM device 334 + * @dev: DRM device 335 + * 336 + * Returns the DMA device of the given DRM device. By default, this 337 + * the DRM device's parent. See drm_dev_set_dma_dev(). 338 + * 339 + * Returns: 340 + * A DMA-capable device for the DRM device. 341 + */ 342 + static inline struct device *drm_dev_dma_dev(struct drm_device *dev) 343 + { 344 + if (dev->dma_dev) 345 + return dev->dma_dev; 346 + return dev->dev; 347 + } 351 348 352 349 #endif