staging: ion: add api to set/get platform device
authorJianqun Xu <jay.xu@rock-chips.com>
Wed, 28 Dec 2016 03:27:37 +0000 (11:27 +0800)
committerJianqun Xu <jay.xu@rock-chips.com>
Fri, 10 Mar 2017 01:22:28 +0000 (09:22 +0800)
Change-Id: Ic251497b173608e1f98bf68fbf2b54b75f89c143
Signed-off-by: Jianqun Xu <jay.xu@rock-chips.com>
drivers/staging/android/ion/ion.c
drivers/staging/android/ion/ion.h
drivers/staging/android/ion/rockchip/rockchip_ion.c

index 5952c2b3cf5078f8ea0febcaa51d7fce995df083..18c2c7c3deb8c07e17ed3ab8b764c2f175a9f062 100644 (file)
@@ -44,6 +44,7 @@
 /**
  * struct ion_device - the metadata of the ion device node
  * @dev:               the actual misc device
+ * @pdev:              the device from platform
  * @buffers:           an rb tree of all the existing buffers
  * @buffer_lock:       lock protecting the tree of buffers
  * @lock:              rwsem protecting the tree of heaps and clients
@@ -52,6 +53,7 @@
  */
 struct ion_device {
        struct miscdevice dev;
+       struct device *pdev;
        struct rb_root buffers;
        struct mutex buffer_lock;
        struct rw_semaphore lock;
@@ -1499,6 +1501,8 @@ static int ion_sync_for_device(struct ion_client *client, int fd)
 {
        struct dma_buf *dmabuf;
        struct ion_buffer *buffer;
+       struct ion_device *idev = client->dev;
+       struct device *dev = ion_device_get_platform(idev);
 
        dmabuf = dma_buf_get(fd);
        if (IS_ERR(dmabuf))
@@ -1513,7 +1517,7 @@ static int ion_sync_for_device(struct ion_client *client, int fd)
        }
        buffer = dmabuf->priv;
 
-       dma_sync_sg_for_device(NULL, buffer->sg_table->sgl,
+       dma_sync_sg_for_device(dev, buffer->sg_table->sgl,
                               buffer->sg_table->nents, DMA_BIDIRECTIONAL);
        dma_buf_put(dmabuf);
        return 0;
@@ -1859,6 +1863,20 @@ void ion_device_add_heap(struct ion_device *dev, struct ion_heap *heap)
 }
 EXPORT_SYMBOL(ion_device_add_heap);
 
+struct device *ion_device_get_platform(struct ion_device *idev)
+{
+       if (!idev)
+               return NULL;
+
+       return idev->pdev;
+}
+
+void ion_device_set_platform(struct ion_device *idev, struct device *dev)
+{
+       if (dev && !idev->pdev)
+               idev->pdev = dev;
+}
+
 struct ion_device *ion_device_create(long (*custom_ioctl)
                                     (struct ion_client *client,
                                      unsigned int cmd,
index bd35c9c259d41437160b415e2a43bc9596a2b85b..13f48f6bd2d313347b1afdf2f2f53080c6683bf5 100644 (file)
@@ -72,6 +72,11 @@ struct ion_platform_data {
        struct ion_platform_heap *heaps;
 };
 
+struct device *ion_device_get_platform(struct ion_device *idev);
+
+void ion_device_set_platform(struct ion_device *idev,
+                            struct device *dev);
+
 /**
  * ion_reserve() - reserve memory for ion heaps if applicable
  * @data:      platform data specifying starting physical address and
index e61c89f1c9c56788eb0859023cc9aaac0b0af8d8..0cb02f5bd4eb667aba5c8d12b347f2d8db7084a3 100644 (file)
@@ -255,6 +255,7 @@ static int rk_ion_probe(struct platform_device *pdev)
                return PTR_ERR(idev);
        }
 
+       ion_device_set_platform(idev, &pdev->dev);
        rockchip_ion_dev = idev;
 
        /* create the heaps as specified in the board file */