OSDN Git Service

msm: ADSPRPC: handle 32 bit support
authorTharun Kumar Merugu <mtharu@codeaurora.org>
Thu, 31 May 2018 06:11:03 +0000 (11:41 +0530)
committerTharun Kumar Merugu <mtharu@codeaurora.org>
Wed, 13 Jun 2018 06:47:01 +0000 (12:17 +0530)
Handle 32 bit support without any truncation.
Add IOCTL calls for map and unmap for 64 bit separately.

Change-Id: I077a0b4345a6c21a88d7a500aa5c9faf7193f620
Signed-off-by: Tharun Kumar Merugu <mtharu@codeaurora.org>
drivers/char/adsprpc.c
drivers/char/adsprpc_compat.c
drivers/char/adsprpc_shared.h

index 18d9829..c078760 100644 (file)
@@ -2774,6 +2774,28 @@ static long fastrpc_device_ioctl(struct file *file, unsigned int ioctl_num,
                if (err)
                        goto bail;
                break;
+       case FASTRPC_IOCTL_MMAP_64:
+               K_COPY_FROM_USER(err, 0, &p.mmap, param,
+                                               sizeof(p.mmap));
+               if (err)
+                       goto bail;
+               VERIFY(err, 0 == (err = fastrpc_internal_mmap(fl, &p.mmap)));
+               if (err)
+                       goto bail;
+               K_COPY_TO_USER(err, 0, param, &p.mmap, sizeof(p.mmap));
+               if (err)
+                       goto bail;
+               break;
+       case FASTRPC_IOCTL_MUNMAP_64:
+               K_COPY_FROM_USER(err, 0, &p.munmap, param,
+                                               sizeof(p.munmap));
+               if (err)
+                       goto bail;
+               VERIFY(err, 0 == (err = fastrpc_internal_munmap(fl,
+                                                       &p.munmap)));
+               if (err)
+                       goto bail;
+               break;
        case FASTRPC_IOCTL_SETMODE:
                switch ((uint32_t)ioctl_param) {
                case FASTRPC_MODE_PARALLEL:
index fc64503..e1e0617 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014-2017, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2014-2018, The Linux Foundation. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 and
                _IOWR('R', 9, struct compat_fastrpc_ioctl_perf)
 #define COMPAT_FASTRPC_IOCTL_INIT_ATTRS \
                _IOWR('R', 10, struct compat_fastrpc_ioctl_init_attrs)
+#define COMPAT_FASTRPC_IOCTL_MMAP_64 \
+               _IOWR('R', 14, struct compat_fastrpc_ioctl_mmap_64)
+#define COMPAT_FASTRPC_IOCTL_MUNMAP_64 \
+               _IOWR('R', 15, struct compat_fastrpc_ioctl_munmap_64)
+
 
 struct compat_remote_buf {
        compat_uptr_t pv;       /* buffer pointer */
@@ -72,11 +77,24 @@ struct compat_fastrpc_ioctl_mmap {
        compat_uptr_t vaddrout; /* dsps virtual address */
 };
 
+struct compat_fastrpc_ioctl_mmap_64 {
+       compat_int_t fd;        /* ion fd */
+       compat_uint_t flags;    /* flags for dsp to map with */
+       compat_u64 vaddrin;     /* optional virtual address */
+       compat_size_t size;     /* size */
+       compat_u64 vaddrout;    /* dsps virtual address */
+};
+
 struct compat_fastrpc_ioctl_munmap {
        compat_uptr_t vaddrout; /* address to unmap */
        compat_size_t size;     /* size */
 };
 
+struct compat_fastrpc_ioctl_munmap_64 {
+       compat_u64 vaddrout;    /* address to unmap */
+       compat_size_t size;     /* size */
+};
+
 struct compat_fastrpc_ioctl_init {
        compat_uint_t flags;    /* one of FASTRPC_INIT_* macros */
        compat_uptr_t file;     /* pointer to elf file */
@@ -209,6 +227,28 @@ static int compat_get_fastrpc_ioctl_mmap(
        return err;
 }
 
+static int compat_get_fastrpc_ioctl_mmap_64(
+                       struct compat_fastrpc_ioctl_mmap_64 __user *map32,
+                       struct fastrpc_ioctl_mmap __user *map)
+{
+       compat_uint_t u;
+       compat_int_t i;
+       compat_size_t s;
+       compat_u64 p;
+       int err;
+
+       err = get_user(i, &map32->fd);
+       err |= put_user(i, &map->fd);
+       err |= get_user(u, &map32->flags);
+       err |= put_user(u, &map->flags);
+       err |= get_user(p, &map32->vaddrin);
+       err |= put_user(p, &map->vaddrin);
+       err |= get_user(s, &map32->size);
+       err |= put_user(s, &map->size);
+
+       return err;
+}
+
 static int compat_put_fastrpc_ioctl_mmap(
                        struct compat_fastrpc_ioctl_mmap __user *map32,
                        struct fastrpc_ioctl_mmap __user *map)
@@ -222,6 +262,19 @@ static int compat_put_fastrpc_ioctl_mmap(
        return err;
 }
 
+static int compat_put_fastrpc_ioctl_mmap_64(
+                       struct compat_fastrpc_ioctl_mmap_64 __user *map32,
+                       struct fastrpc_ioctl_mmap __user *map)
+{
+       compat_u64 p;
+       int err;
+
+       err = get_user(p, &map->vaddrout);
+       err |= put_user(p, &map32->vaddrout);
+
+       return err;
+}
+
 static int compat_get_fastrpc_ioctl_munmap(
                        struct compat_fastrpc_ioctl_munmap __user *unmap32,
                        struct fastrpc_ioctl_munmap __user *unmap)
@@ -238,6 +291,22 @@ static int compat_get_fastrpc_ioctl_munmap(
        return err;
 }
 
+static int compat_get_fastrpc_ioctl_munmap_64(
+                       struct compat_fastrpc_ioctl_munmap_64 __user *unmap32,
+                       struct fastrpc_ioctl_munmap __user *unmap)
+{
+       compat_u64 p;
+       compat_size_t s;
+       int err;
+
+       err = get_user(p, &unmap32->vaddrout);
+       err |= put_user(p, &unmap->vaddrout);
+       err |= get_user(s, &unmap32->size);
+       err |= put_user(s, &unmap->size);
+
+       return err;
+}
+
 static int compat_get_fastrpc_ioctl_perf(
                        struct compat_fastrpc_ioctl_perf __user *perf32,
                        struct fastrpc_ioctl_perf __user *perf)
@@ -343,6 +412,27 @@ long compat_fastrpc_device_ioctl(struct file *filp, unsigned int cmd,
                VERIFY(err, 0 == compat_put_fastrpc_ioctl_mmap(map32, map));
                return err;
        }
+       case COMPAT_FASTRPC_IOCTL_MMAP_64:
+       {
+               struct compat_fastrpc_ioctl_mmap_64  __user *map32;
+               struct fastrpc_ioctl_mmap __user *map;
+               long ret;
+
+               map32 = compat_ptr(arg);
+               VERIFY(err, NULL != (map = compat_alloc_user_space(
+                                                       sizeof(*map))));
+               if (err)
+                       return -EFAULT;
+               VERIFY(err, 0 == compat_get_fastrpc_ioctl_mmap_64(map32, map));
+               if (err)
+                       return err;
+               ret = filp->f_op->unlocked_ioctl(filp, FASTRPC_IOCTL_MMAP_64,
+                                                       (unsigned long)map);
+               if (ret)
+                       return ret;
+               VERIFY(err, 0 == compat_put_fastrpc_ioctl_mmap_64(map32, map));
+               return err;
+       }
        case COMPAT_FASTRPC_IOCTL_MUNMAP:
        {
                struct compat_fastrpc_ioctl_munmap __user *unmap32;
@@ -360,6 +450,23 @@ long compat_fastrpc_device_ioctl(struct file *filp, unsigned int cmd,
                return filp->f_op->unlocked_ioctl(filp, FASTRPC_IOCTL_MUNMAP,
                                                        (unsigned long)unmap);
        }
+       case COMPAT_FASTRPC_IOCTL_MUNMAP_64:
+       {
+               struct compat_fastrpc_ioctl_munmap_64 __user *unmap32;
+               struct fastrpc_ioctl_munmap __user *unmap;
+
+               unmap32 = compat_ptr(arg);
+               VERIFY(err, NULL != (unmap = compat_alloc_user_space(
+                                                       sizeof(*unmap))));
+               if (err)
+                       return -EFAULT;
+               VERIFY(err, 0 == compat_get_fastrpc_ioctl_munmap_64(unmap32,
+                                                       unmap));
+               if (err)
+                       return err;
+               return filp->f_op->unlocked_ioctl(filp, FASTRPC_IOCTL_MUNMAP_64,
+                                                       (unsigned long)unmap);
+       }
        case COMPAT_FASTRPC_IOCTL_INIT:
                /* fall through */
        case COMPAT_FASTRPC_IOCTL_INIT_ATTRS:
index be8d1a5..a88c668 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012-2017, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 and
@@ -19,6 +19,8 @@
 #define FASTRPC_IOCTL_INVOKE   _IOWR('R', 1, struct fastrpc_ioctl_invoke)
 #define FASTRPC_IOCTL_MMAP     _IOWR('R', 2, struct fastrpc_ioctl_mmap)
 #define FASTRPC_IOCTL_MUNMAP   _IOWR('R', 3, struct fastrpc_ioctl_munmap)
+#define FASTRPC_IOCTL_MMAP_64  _IOWR('R', 14, struct fastrpc_ioctl_mmap_64)
+#define FASTRPC_IOCTL_MUNMAP_64        _IOWR('R', 15, struct fastrpc_ioctl_munmap_64)
 #define FASTRPC_IOCTL_INVOKE_FD        _IOWR('R', 4, struct fastrpc_ioctl_invoke_fd)
 #define FASTRPC_IOCTL_SETMODE  _IOWR('R', 5, uint32_t)
 #define FASTRPC_IOCTL_INIT     _IOWR('R', 6, struct fastrpc_ioctl_init)
@@ -171,6 +173,11 @@ struct fastrpc_ioctl_munmap {
        size_t size;            /* size */
 };
 
+struct fastrpc_ioctl_munmap_64 {
+       uint64_t vaddrout;      /* address to unmap */
+       size_t size;            /* size */
+};
+
 struct fastrpc_ioctl_mmap {
        int fd;                         /* ion fd */
        uint32_t flags;                 /* flags for dsp to map with */
@@ -179,6 +186,15 @@ struct fastrpc_ioctl_mmap {
        uintptr_t vaddrout;             /* dsps virtual address */
 };
 
+
+struct fastrpc_ioctl_mmap_64 {
+       int fd;                         /* ion fd */
+       uint32_t flags;                 /* flags for dsp to map with */
+       uint64_t vaddrin;               /* optional virtual address */
+       size_t size;                    /* size */
+       uint64_t vaddrout;              /* dsps virtual address */
+};
+
 struct fastrpc_ioctl_perf {                    /* kernel performance data */
        uintptr_t data;
        uint32_t numkeys;