Expose an indicator to let userspace know from which dma_heap
to allocate for buffers of this device.

Signed-off-by: Christian König <christian.koe...@amd.com>
---
 drivers/media/usb/uvc/uvc_driver.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/media/usb/uvc/uvc_driver.c 
b/drivers/media/usb/uvc/uvc_driver.c
index e4bcb5011360..b247026b68c5 100644
--- a/drivers/media/usb/uvc/uvc_driver.c
+++ b/drivers/media/usb/uvc/uvc_driver.c
@@ -7,6 +7,7 @@
  */
 
 #include <linux/atomic.h>
+#include <linux/dma-heap.h>
 #include <linux/gpio/consumer.h>
 #include <linux/kernel.h>
 #include <linux/list.h>
@@ -1909,6 +1910,8 @@ static void uvc_unregister_video(struct uvc_device *dev)
 
        if (dev->vdev.dev)
                v4l2_device_unregister(&dev->vdev);
+       dma_heap_remove_device_link(&dev->udev->dev);
+
 #ifdef CONFIG_MEDIA_CONTROLLER
        if (media_devnode_is_registered(dev->mdev.devnode))
                media_device_unregister(&dev->mdev);
@@ -2181,6 +2184,14 @@ static int uvc_probe(struct usb_interface *intf,
                         dev->uvc_version >> 8, dev->uvc_version & 0xff);
        }
 
+       /*
+        * UVC exports DMA-buf buffers with dirty CPU caches. For compatibility
+        * with device which can't snoop the CPU cache it's best practice to
+        * allocate DMA-bufs from the system DMA-heap.
+        */
+       if (dma_heap_create_device_link(&dev->udev->dev, "system"))
+               goto error;
+
        /* Register the V4L2 device. */
        if (v4l2_device_register(&intf->dev, &dev->vdev) < 0)
                goto error;
-- 
2.34.1

Reply via email to