Add a config option to make the "legacy" /dev/ion
interface optional.

Not yet clear if this will come out of staging or
not, but to help with the transition.

Cc: Laura Abbott <labb...@redhat.com>
Cc: Sumit Semwal <sumit.sem...@linaro.org>
Cc: Liam Mark <lm...@codeaurora.org>
Cc: Brian Starkey <brian.star...@arm.com>
Cc: Andrew F. Davis <a...@ti.com>
Cc: Alistair Strachan <astrac...@google.com>
Cc: dri-devel@lists.freedesktop.org
Signed-off-by: John Stultz <john.stu...@linaro.org>
---
 drivers/staging/android/ion/Kconfig     |  7 ++++++
 drivers/staging/android/ion/ion-ioctl.c |  2 ++
 drivers/staging/android/ion/ion.c       | 43 +++++++++++++++++++++------------
 drivers/staging/android/ion/ion.h       |  2 ++
 4 files changed, 39 insertions(+), 15 deletions(-)

diff --git a/drivers/staging/android/ion/Kconfig 
b/drivers/staging/android/ion/Kconfig
index 0fdda6f..7f5a0b2 100644
--- a/drivers/staging/android/ion/Kconfig
+++ b/drivers/staging/android/ion/Kconfig
@@ -42,3 +42,10 @@ config ION_CMA_HEAP
          Choose this option to enable CMA heaps with Ion. This heap is backed
          by the Contiguous Memory Allocator (CMA). If your system has these
          regions, you should say Y here.
+
+config ION_COMPAT_INTERFACE
+       bool "Legacy /dev/ion interface support"
+       depends on ION
+       help
+         Choose this option to enable the legacy /dev/ion interface which
+         provides compatibility with userspace designed for 4.12+ kernels
diff --git a/drivers/staging/android/ion/ion-ioctl.c 
b/drivers/staging/android/ion/ion-ioctl.c
index 6db5969..427980c 100644
--- a/drivers/staging/android/ion/ion-ioctl.c
+++ b/drivers/staging/android/ion/ion-ioctl.c
@@ -43,6 +43,7 @@ static unsigned int ion_ioctl_dir(unsigned int cmd)
        }
 }
 
+#ifdef CONFIG_ION_COMPAT_INTERFACE
 long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 {
        int ret = 0;
@@ -102,6 +103,7 @@ long ion_ioctl(struct file *filp, unsigned int cmd, 
unsigned long arg)
        }
        return ret;
 }
+#endif
 
 long ion_heap_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 {
diff --git a/drivers/staging/android/ion/ion.c 
b/drivers/staging/android/ion/ion.c
index 1f7c893..9a73526 100644
--- a/drivers/staging/android/ion/ion.c
+++ b/drivers/staging/android/ion/ion.c
@@ -500,14 +500,6 @@ static const struct file_operations ion_heap_fops = {
 #endif
 };
 
-static const struct file_operations ion_fops = {
-       .owner          = THIS_MODULE,
-       .unlocked_ioctl = ion_ioctl,
-#ifdef CONFIG_COMPAT
-       .compat_ioctl   = ion_ioctl,
-#endif
-};
-
 static int debug_shrink_set(void *data, u64 val)
 {
        struct ion_heap *heap = data;
@@ -619,15 +611,19 @@ void ion_device_add_heap(struct ion_heap *heap)
 }
 EXPORT_SYMBOL(ion_device_add_heap);
 
-static int ion_device_create(void)
+#ifdef CONFIG_ION_COMPAT_INTERFACE
+static const struct file_operations ion_fops = {
+       .owner          = THIS_MODULE,
+       .unlocked_ioctl = ion_ioctl,
+#ifdef CONFIG_COMPAT
+       .compat_ioctl   = ion_ioctl,
+#endif
+};
+
+static int ion_create_legacy_interface(struct ion_device *idev)
 {
-       struct ion_device *idev;
        int ret;
 
-       idev = kzalloc(sizeof(*idev), GFP_KERNEL);
-       if (!idev)
-               return -ENOMEM;
-
        idev->dev.minor = MISC_DYNAMIC_MINOR;
        idev->dev.name = "ion";
        idev->dev.fops = &ion_fops;
@@ -636,8 +632,25 @@ static int ion_device_create(void)
        if (ret) {
                pr_err("ion: failed to register misc device.\n");
                kfree(idev);
-               return ret;
        }
+       return ret;
+}
+#else
+#define ion_create_legacy_interface(x) 0
+#endif
+
+static int ion_device_create(void)
+{
+       struct ion_device *idev;
+       int ret;
+
+       idev = kzalloc(sizeof(*idev), GFP_KERNEL);
+       if (!idev)
+               return -ENOMEM;
+
+       ret = ion_create_legacy_interface(idev);
+       if (ret)
+               return ret;
 
        idev->debug_root = debugfs_create_dir("ion", NULL);
        idev->buffers = RB_ROOT;
diff --git a/drivers/staging/android/ion/ion.h 
b/drivers/staging/android/ion/ion.h
index 7ed4a6a..a82178b 100644
--- a/drivers/staging/android/ion/ion.h
+++ b/drivers/staging/android/ion/ion.h
@@ -333,7 +333,9 @@ void ion_page_pool_free(struct ion_page_pool *pool, struct 
page *page);
 int ion_page_pool_shrink(struct ion_page_pool *pool, gfp_t gfp_mask,
                         int nr_to_scan);
 
+#ifdef CONFIG_ION_COMPAT_INTERFACE
 long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
+#endif
 long ion_heap_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
 
 int ion_query_heaps(struct ion_heap_query *query);
-- 
2.7.4

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Reply via email to