From: Jianqun Xu Date: Wed, 28 Dec 2016 03:27:37 +0000 (+0800) Subject: staging: ion: add api to set/get platform device X-Git-Tag: firefly_0821_release~374 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=466ee1ee7b7290ffeee1638e491696b3f40edd56;p=firefly-linux-kernel-4.4.55.git staging: ion: add api to set/get platform device Change-Id: Ic251497b173608e1f98bf68fbf2b54b75f89c143 Signed-off-by: Jianqun Xu --- diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index 5952c2b3cf50..18c2c7c3deb8 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -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, diff --git a/drivers/staging/android/ion/ion.h b/drivers/staging/android/ion/ion.h index bd35c9c259d4..13f48f6bd2d3 100644 --- a/drivers/staging/android/ion/ion.h +++ b/drivers/staging/android/ion/ion.h @@ -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 diff --git a/drivers/staging/android/ion/rockchip/rockchip_ion.c b/drivers/staging/android/ion/rockchip/rockchip_ion.c index e61c89f1c9c5..0cb02f5bd4eb 100644 --- a/drivers/staging/android/ion/rockchip/rockchip_ion.c +++ b/drivers/staging/android/ion/rockchip/rockchip_ion.c @@ -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 */