2 * drivers/staging/android/ion/compat_ion.c
4 * Copyright (C) 2013 Google, Inc.
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
17 #include <linux/compat.h>
19 #include <linux/uaccess.h>
22 #include "compat_ion.h"
24 /* See drivers/staging/android/uapi/ion.h for the definition of these structs */
25 struct compat_ion_allocation_data {
28 compat_uint_t heap_id_mask;
33 struct compat_ion_handle_data {
37 #define COMPAT_ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \
38 struct compat_ion_allocation_data)
39 #define COMPAT_ION_IOC_FREE _IOWR(ION_IOC_MAGIC, 1, \
40 struct compat_ion_handle_data)
42 static int compat_get_ion_allocation_data(
43 struct compat_ion_allocation_data __user *data32,
44 struct ion_allocation_data __user *data)
51 err = get_user(s, &data32->len);
52 err |= put_user(s, &data->len);
53 err |= get_user(s, &data32->align);
54 err |= put_user(s, &data->align);
55 err |= get_user(u, &data32->heap_id_mask);
56 err |= put_user(u, &data->heap_id_mask);
57 err |= get_user(u, &data32->flags);
58 err |= put_user(u, &data->flags);
59 err |= get_user(i, &data32->handle);
60 err |= put_user(i, &data->handle);
65 static int compat_get_ion_handle_data(
66 struct compat_ion_handle_data __user *data32,
67 struct ion_handle_data __user *data)
72 err = get_user(i, &data32->handle);
73 err |= put_user(i, &data->handle);
78 static int compat_put_ion_allocation_data(
79 struct compat_ion_allocation_data __user *data32,
80 struct ion_allocation_data __user *data)
87 err = get_user(s, &data->len);
88 err |= put_user(s, &data32->len);
89 err |= get_user(s, &data->align);
90 err |= put_user(s, &data32->align);
91 err |= get_user(u, &data->heap_id_mask);
92 err |= put_user(u, &data32->heap_id_mask);
93 err |= get_user(u, &data->flags);
94 err |= put_user(u, &data32->flags);
95 err |= get_user(i, &data->handle);
96 err |= put_user(i, &data32->handle);
101 long compat_ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
105 if (!filp->f_op->unlocked_ioctl)
109 case COMPAT_ION_IOC_ALLOC:
111 struct compat_ion_allocation_data __user *data32;
112 struct ion_allocation_data __user *data;
115 data32 = compat_ptr(arg);
116 data = compat_alloc_user_space(sizeof(*data));
120 err = compat_get_ion_allocation_data(data32, data);
123 ret = filp->f_op->unlocked_ioctl(filp, ION_IOC_ALLOC,
124 (unsigned long)data);
125 err = compat_put_ion_allocation_data(data32, data);
126 return ret ? ret : err;
128 case COMPAT_ION_IOC_FREE:
130 struct compat_ion_handle_data __user *data32;
131 struct ion_handle_data __user *data;
134 data32 = compat_ptr(arg);
135 data = compat_alloc_user_space(sizeof(*data));
139 err = compat_get_ion_handle_data(data32, data);
143 return filp->f_op->unlocked_ioctl(filp, ION_IOC_FREE,
144 (unsigned long)data);
147 return filp->f_op->unlocked_ioctl(filp, cmd,
148 (unsigned long)compat_ptr(arg));