staging: android: ion: support get physical address

Signed-off-by: Meiyou Chen <cmy@rock-chips.com>
Change-Id: I002b94215de5a34580c5b291932ddba0d4ac33bf
This commit is contained in:
Meiyou Chen
2021-04-15 15:40:39 +08:00
parent 59541c84bb
commit ecb02a3dca
4 changed files with 39 additions and 0 deletions

View File

@@ -13,6 +13,7 @@
union ion_ioctl_arg {
struct ion_allocation_data allocation;
struct ion_heap_query query;
struct ion_phys_data phys;
};
static int validate_ioctl_arg(unsigned int cmd, union ion_ioctl_arg *arg)
@@ -86,6 +87,9 @@ long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
case ION_IOC_HEAP_QUERY:
ret = ion_query_heaps(&data.query);
break;
case ION_IOC_GET_PHYS:
ret = ion_get_phys(&data.phys);
break;
default:
return -ENOTTY;
}

View File

@@ -746,6 +746,31 @@ out:
return ret;
}
int ion_get_phys(struct ion_phys_data *phys)
{
struct dma_buf *dmabuf;
struct ion_buffer *buffer;
if (IS_ERR_OR_NULL(phys))
return -EINVAL;
dmabuf = dma_buf_get(phys->fd);
if (IS_ERR_OR_NULL(dmabuf))
return -ENOENT;
phys->paddr = (__u64)-1;
buffer = dmabuf->priv;
if (!IS_ERR_OR_NULL(buffer) &&
(buffer->heap->type == ION_HEAP_TYPE_SYSTEM_CONTIG ||
buffer->heap->type == ION_HEAP_TYPE_DMA ||
buffer->heap->type == ION_HEAP_TYPE_CARVEOUT))
phys->paddr = sg_phys(buffer->sg_table->sgl);
dma_buf_put(dmabuf);
return 0;
}
static const struct file_operations ion_fops = {
.owner = THIS_MODULE,
.unlocked_ioctl = ion_ioctl,

View File

@@ -335,6 +335,7 @@ int ion_page_pool_shrink(struct ion_page_pool *pool, gfp_t gfp_mask,
long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
int ion_query_heaps(struct ion_heap_query *query);
int ion_get_phys(struct ion_phys_data *phys);
#ifdef CONFIG_ION_MODULE
int ion_add_cma_heaps(void);

View File

@@ -130,4 +130,13 @@ struct ion_heap_query {
#define ION_IOC_HEAP_QUERY _IOWR(ION_IOC_MAGIC, 8, \
struct ion_heap_query)
struct ion_phys_data {
__u32 fd;
__u32 padding;
__u64 paddr;
};
#define ION_IOC_GET_PHYS _IOWR(ION_IOC_MAGIC, 9, \
struct ion_phys_data)
#endif /* _UAPI_LINUX_ION_H */