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_custom_data {
38 #define COMPAT_ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \
39 struct compat_ion_allocation_data)
40 #define COMPAT_ION_IOC_FREE _IOWR(ION_IOC_MAGIC, 1, struct ion_handle_data)
41 #define COMPAT_ION_IOC_CUSTOM _IOWR(ION_IOC_MAGIC, 6, \
42 struct compat_ion_custom_data)
44 static int compat_get_ion_allocation_data(
45 struct compat_ion_allocation_data __user *data32,
46 struct ion_allocation_data __user *data)
53 err = get_user(s, &data32->len);
54 err |= put_user(s, &data->len);
55 err |= get_user(s, &data32->align);
56 err |= put_user(s, &data->align);
57 err |= get_user(u, &data32->heap_id_mask);
58 err |= put_user(u, &data->heap_id_mask);
59 err |= get_user(u, &data32->flags);
60 err |= put_user(u, &data->flags);
61 err |= get_user(i, &data32->handle);
62 err |= put_user(i, &data->handle);
67 static int compat_put_ion_allocation_data(
68 struct compat_ion_allocation_data __user *data32,
69 struct ion_allocation_data __user *data)
76 err = get_user(s, &data->len);
77 err |= put_user(s, &data32->len);
78 err |= get_user(s, &data->align);
79 err |= put_user(s, &data32->align);
80 err |= get_user(u, &data->heap_id_mask);
81 err |= put_user(u, &data32->heap_id_mask);
82 err |= get_user(u, &data->flags);
83 err |= put_user(u, &data32->flags);
84 err |= get_user(i, &data->handle);
85 err |= put_user(i, &data32->handle);
90 static int compat_get_ion_custom_data(
91 struct compat_ion_custom_data __user *data32,
92 struct ion_custom_data __user *data)
98 err = get_user(cmd, &data32->cmd);
99 err |= put_user(cmd, &data->cmd);
100 err |= get_user(arg, &data32->arg);
101 err |= put_user(arg, &data->arg);
106 long compat_ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
110 if (!filp->f_op || !filp->f_op->unlocked_ioctl)
114 case COMPAT_ION_IOC_ALLOC:
116 struct compat_ion_allocation_data __user *data32;
117 struct ion_allocation_data __user *data;
120 data32 = compat_ptr(arg);
121 data = compat_alloc_user_space(sizeof(*data));
125 err = compat_get_ion_allocation_data(data32, data);
128 ret = filp->f_op->unlocked_ioctl(filp, ION_IOC_ALLOC,
129 (unsigned long)data);
130 err = compat_put_ion_allocation_data(data32, data);
131 return ret ? ret : err;
133 case COMPAT_ION_IOC_FREE:
135 struct compat_ion_allocation_data __user *data32;
136 struct ion_allocation_data __user *data;
139 data32 = compat_ptr(arg);
140 data = compat_alloc_user_space(sizeof(*data));
144 err = compat_get_ion_allocation_data(data32, data);
148 return filp->f_op->unlocked_ioctl(filp, ION_IOC_FREE,
149 (unsigned long)data);
151 case COMPAT_ION_IOC_CUSTOM: {
152 struct compat_ion_custom_data __user *data32;
153 struct ion_custom_data __user *data;
156 data32 = compat_ptr(arg);
157 data = compat_alloc_user_space(sizeof(*data));
161 err = compat_get_ion_custom_data(data32, data);
165 return filp->f_op->unlocked_ioctl(filp, ION_IOC_CUSTOM,
166 (unsigned long)data);
172 return filp->f_op->unlocked_ioctl(filp, cmd,
173 (unsigned long)compat_ptr(arg));