From 381653de660ece07a46d6c518692d16e7b02fffc Mon Sep 17 00:00:00 2001 From: CMY Date: Thu, 20 Feb 2014 11:21:40 +0800 Subject: [PATCH] rk: ion: add custom ioctl: ION_IOC_GET_PHYS --- drivers/staging/android/ion/ion.c | 2 +- .../android/ion/rockchip/rockchip_ion.c | 39 ++++++++++++++++++- include/linux/rockchip_ion.h | 24 +++++++----- 3 files changed, 54 insertions(+), 11 deletions(-) diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index 48774e3974aa..468146dc87fb 100755 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -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; diff --git a/drivers/staging/android/ion/rockchip/rockchip_ion.c b/drivers/staging/android/ion/rockchip/rockchip_ion.c index 78bdcba76406..903562e67194 100755 --- a/drivers/staging/android/ion/rockchip/rockchip_ion.c +++ b/drivers/staging/android/ion/rockchip/rockchip_ion.c @@ -18,6 +18,7 @@ #include #include #include +#include #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; } diff --git a/include/linux/rockchip_ion.h b/include/linux/rockchip_ion.h index 8b589e9d6e84..def0f390ecbd 100644 --- a/include/linux/rockchip_ion.h +++ b/include/linux/rockchip_ion.h @@ -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 -- 2.34.1