rk: ion: add custom ioctl: ION_IOC_GET_PHYS

This commit is contained in:
CMY
2014-02-20 11:21:40 +08:00
parent fbd2562669
commit 381653de66
3 changed files with 54 additions and 11 deletions

View File

@@ -417,7 +417,7 @@ static struct ion_handle *ion_handle_lookup(struct ion_client *client,
return ERR_PTR(-EINVAL);
}
static struct ion_handle *ion_handle_get_by_id(struct ion_client *client,
struct ion_handle *ion_handle_get_by_id(struct ion_client *client,
int id)
{
struct ion_handle *handle;

View File

@@ -18,6 +18,7 @@
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <linux/rockchip_ion.h>
#include <linux/uaccess.h>
#include "../ion_priv.h"
#ifdef CONFIG_OF
@@ -36,6 +37,9 @@ struct ion_heap_desc {
const char *name;
};
extern struct ion_handle *ion_handle_get_by_id(struct ion_client *client,
int id);
static struct ion_heap_desc ion_heap_meta[] = {
{
.id = ION_SYSTEM_HEAP_ID,
@@ -101,7 +105,7 @@ static int rockchip_ion_get_heap_size(struct device_node *node,
static struct ion_platform_data *rockchip_ion_parse_dt(
struct device *dev)
{
struct device_node *dt_node = dev->of_node;
struct device_node *dt_node = dev->of_node;
struct ion_platform_data *pdata = 0;
struct device_node *node;
uint32_t val = 0;
@@ -164,6 +168,39 @@ EXPORT_SYMBOL(rockchip_ion_client_create);
static long rockchip_custom_ioctl (struct ion_client *client, unsigned int cmd,
unsigned long arg)
{
pr_info("[%s %d] cmd=%X\n", __func__, __LINE__, cmd);
switch (cmd) {
case ION_IOC_CLEAN_CACHES:
case ION_IOC_INV_CACHES:
case ION_IOC_CLEAN_INV_CACHES:
break;
case ION_IOC_GET_PHYS:
{
struct ion_phys_data data;
struct ion_handle *handle;
int ret;
if (copy_from_user(&data, (void __user *)arg,
sizeof(struct ion_phys_data)))
return -EFAULT;
handle = ion_handle_get_by_id(client, data.handle);
if (IS_ERR(handle))
return PTR_ERR(handle);
ret = ion_phys(client, handle, &data.phys, (size_t *)&data.size);
pr_info("ret=%d, phys=0x%X\n", ret, data.phys);
if(ret < 0)
return ret;
if (copy_to_user((void __user *)arg, &data, sizeof(struct ion_phys_data)))
return -EFAULT;
break;
}
default:
return -ENOTTY;
}
return 0;
}

View File

@@ -31,10 +31,10 @@ enum ion_heap_ids {
#define ION_HEAP(bit) (1 << (bit))
#define ION_VIDEO_HEAP_NAME "video"
#define ION_AUDIO_HEAP_NAME "audio"
#define ION_VIDEO_HEAP_NAME "video"
#define ION_AUDIO_HEAP_NAME "audio"
#define ION_CAMERA_HEAP_NAME "camera_preview"
#define ION_IOMMU_HEAP_NAME "iommu"
#define ION_IOMMU_HEAP_NAME "iommu"
#define ION_VMALLOC_HEAP_NAME "vmalloc"
#define ION_SET_CACHED(__cache) (__cache | ION_FLAG_CACHED)
@@ -62,28 +62,34 @@ struct ion_flush_data {
unsigned int length;
};
struct ion_phys_data {
ion_user_handle_t handle;
unsigned long phys;
unsigned long size;
};
#define ION_IOC_ROCKCHIP_MAGIC 'R'
/**
* DOC: ION_IOC_CLEAN_CACHES - clean the caches
*
* Clean the caches of the handle specified.
*/
#define ION_IOC_CLEAN_CACHES _IOWR(ION_IOC_ROCKCHIP_MAGIC, 0, \
struct ion_flush_data)
/**
* DOC: ION_IOC_INV_CACHES - invalidate the caches
*
* Invalidate the caches of the handle specified.
*/
#define ION_IOC_INV_CACHES _IOWR(ION_IOC_ROCKCHIP_MAGIC, 1, \
struct ion_flush_data)
/**
* DOC: ION_IOC_CLEAN_INV_CACHES - clean and invalidate the caches
*
* Clean and invalidate the caches of the handle specified.
*/
#define ION_IOC_CLEAN_INV_CACHES _IOWR(ION_IOC_ROCKCHIP_MAGIC, 2, \
struct ion_flush_data)
/**
* Get phys addr of the handle specified.
*/
#define ION_IOC_GET_PHYS _IOWR(ION_IOC_ROCKCHIP_MAGIC, 3, \
struct ion_phys_data)
#endif