rk: ion: add custom ioctl: ION_IOC_GET_PHYS
authorCMY <cmy@rock-chips.com>
Thu, 20 Feb 2014 03:21:40 +0000 (11:21 +0800)
committerCMY <cmy@rock-chips.com>
Thu, 20 Feb 2014 03:21:40 +0000 (11:21 +0800)
drivers/staging/android/ion/ion.c
drivers/staging/android/ion/rockchip/rockchip_ion.c
include/linux/rockchip_ion.h

index 48774e3974aa02f13a4656541660f8f182549888..468146dc87fb70917e074fa80ae2615620ea01cd 100755 (executable)
@@ -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;
index 78bdcba7640667f0268f9fb9749539396f0dfe6c..903562e67194572c5c72f68ffe7d7ed2e293fc0c 100755 (executable)
@@ -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;
 }
 
index 8b589e9d6e8452441321c020786080185d5a7339..def0f390ecbd9586622198970ad4e145fa9af26a 100644 (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