v4l: vsp1: Add API to map and unmap DRM buffers through the VSP
authorLaurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Tue, 16 May 2017 23:20:06 +0000 (02:20 +0300)
committerKieran Bingham <kieran.bingham+renesas@ideasonboard.com>
Fri, 9 Jun 2017 11:25:38 +0000 (12:25 +0100)
The display buffers must be mapped for DMA through the device that
performs memory access. Expose an API to map and unmap memory through
the VSP device to be used by the DU.

As all the buffers allocated by the DU driver are coherent, we can skip
cache handling when mapping and unmapping them. This will need to be
revisited when support for non-coherent buffers will be added to the DU
driver.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
[Kieran: Remove unused header]
Signed-off-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
Acked-by: Mauro Cavalho Chehab <mchehab@s-opensource.com>
drivers/media/platform/vsp1/vsp1_drm.c
include/media/vsp1.h

index 84d0418..9377aaf 100644 (file)
@@ -12,6 +12,7 @@
  */
 
 #include <linux/device.h>
+#include <linux/dma-mapping.h>
 #include <linux/slab.h>
 
 #include <media/media-entity.h>
@@ -540,6 +541,29 @@ void vsp1_du_atomic_flush(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(vsp1_du_atomic_flush);
 
+int vsp1_du_map_sg(struct device *dev, struct sg_table *sgt)
+{
+       struct vsp1_device *vsp1 = dev_get_drvdata(dev);
+
+       /*
+        * As all the buffers allocated by the DU driver are coherent, we can
+        * skip cache sync. This will need to be revisited when support for
+        * non-coherent buffers will be added to the DU driver.
+        */
+       return dma_map_sg_attrs(vsp1->bus_master, sgt->sgl, sgt->nents,
+                               DMA_TO_DEVICE, DMA_ATTR_SKIP_CPU_SYNC);
+}
+EXPORT_SYMBOL_GPL(vsp1_du_map_sg);
+
+void vsp1_du_unmap_sg(struct device *dev, struct sg_table *sgt)
+{
+       struct vsp1_device *vsp1 = dev_get_drvdata(dev);
+
+       dma_unmap_sg_attrs(vsp1->bus_master, sgt->sgl, sgt->nents,
+                          DMA_TO_DEVICE, DMA_ATTR_SKIP_CPU_SYNC);
+}
+EXPORT_SYMBOL_GPL(vsp1_du_unmap_sg);
+
 /* -----------------------------------------------------------------------------
  * Initialization
  */
index c135c47..c837383 100644 (file)
@@ -13,6 +13,7 @@
 #ifndef __MEDIA_VSP1_H__
 #define __MEDIA_VSP1_H__
 
+#include <linux/scatterlist.h>
 #include <linux/types.h>
 #include <linux/videodev2.h>
 
@@ -53,5 +54,7 @@ void vsp1_du_atomic_begin(struct device *dev);
 int vsp1_du_atomic_update(struct device *dev, unsigned int rpf,
                          const struct vsp1_du_atomic_config *cfg);
 void vsp1_du_atomic_flush(struct device *dev);
+int vsp1_du_map_sg(struct device *dev, struct sg_table *sgt);
+void vsp1_du_unmap_sg(struct device *dev, struct sg_table *sgt);
 
 #endif /* __MEDIA_VSP1_H__ */