diff options
author | ivan.liu <xiaowen.liu@nxp.com> | 2018-05-07 11:24:26 +0800 |
---|---|---|
committer | Dong Aisheng <aisheng.dong@nxp.com> | 2019-11-25 15:43:48 +0800 |
commit | 1186c5eb2c8d77380e789d7dadb3bb8b8349196e (patch) | |
tree | 7984a9aa062b3e181da20c6490629b0e8a44adaa /drivers/dma-buf/dma-buf.c | |
parent | 31b97fe1709a4c4a149ac8d88fb617e866e3f7e1 (diff) |
MA-11994 Add get phys address ioctl to dma-buf.
Add structure dma_buf_phys to store physical address.
Add DMA_BUF_IOCTL_PHYS to export physical address.
Change-Id: Ib2f24b33462d603f2cbeef975689aaf82447d088
Signed-off-by: ivan.liu <xiaowen.liu@nxp.com>
[ Aisheng: update ioctl NR to 2 due to the original 1 is used in upstream ]
[ Aisheng: update ioctl NR to 10 according to GPU team's request ]
Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
Diffstat (limited to 'drivers/dma-buf/dma-buf.c')
-rw-r--r-- | drivers/dma-buf/dma-buf.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index 433d91d710e4..3ef286fa17fc 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -25,6 +25,7 @@ #include <linux/mm.h> #include <linux/mount.h> #include <linux/pseudo_fs.h> +#include <linux/device.h> #include <uapi/linux/dma-buf.h> #include <uapi/linux/magic.h> @@ -359,6 +360,36 @@ static long dma_buf_ioctl(struct file *file, dmabuf = file->private_data; switch (cmd) { + case DMA_BUF_IOCTL_PHYS: { + struct dma_buf_attachment *attachment = NULL; + struct sg_table *sgt = NULL; + unsigned long phys = 0; + struct device dev; + + if (!dmabuf || IS_ERR(dmabuf)) { + return -EFAULT; + } + memset(&dev, 0, sizeof(dev)); + device_initialize(&dev); + dev.coherent_dma_mask = DMA_BIT_MASK(64); + dev.dma_mask = &dev.coherent_dma_mask; + arch_setup_dma_ops(&dev, 0, 0, NULL, false); + attachment = dma_buf_attach(dmabuf, &dev); + if (!attachment || IS_ERR(attachment)) { + return -EFAULT; + } + + sgt = dma_buf_map_attachment(attachment, DMA_BIDIRECTIONAL); + if (sgt && !IS_ERR(sgt)) { + phys = sg_dma_address(sgt->sgl); + dma_buf_unmap_attachment(attachment, sgt, + DMA_BIDIRECTIONAL); + } + dma_buf_detach(dmabuf, attachment); + if (copy_to_user((void __user *) arg, &phys, sizeof(phys))) + return -EFAULT; + return 0; + } case DMA_BUF_IOCTL_SYNC: if (copy_from_user(&sync, (void __user *) arg, sizeof(sync))) return -EFAULT; |