Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 1 | /** |
| 2 | * \file drm_ioc32.c |
| 3 | * |
| 4 | * 32-bit ioctl compatibility routines for the DRM. |
| 5 | * |
| 6 | * \author Paul Mackerras <paulus@samba.org> |
| 7 | * |
| 8 | * Copyright (C) Paul Mackerras 2005. |
| 9 | * All Rights Reserved. |
| 10 | * |
| 11 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 12 | * copy of this software and associated documentation files (the "Software"), |
| 13 | * to deal in the Software without restriction, including without limitation |
| 14 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 15 | * and/or sell copies of the Software, and to permit persons to whom the |
| 16 | * Software is furnished to do so, subject to the following conditions: |
| 17 | * |
| 18 | * The above copyright notice and this permission notice (including the next |
| 19 | * paragraph) shall be included in all copies or substantial portions of the |
| 20 | * Software. |
| 21 | * |
| 22 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 23 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 24 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 25 | * THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 26 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 27 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 28 | * IN THE SOFTWARE. |
| 29 | */ |
| 30 | #include <linux/compat.h> |
Christian Dietrich | cafe8d8 | 2011-06-04 15:36:43 +0000 | [diff] [blame] | 31 | #include <linux/ratelimit.h> |
Paul Gortmaker | 2d1a8a4 | 2011-08-30 18:16:33 -0400 | [diff] [blame] | 32 | #include <linux/export.h> |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 33 | |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 34 | #include <drm/drmP.h> |
| 35 | #include <drm/drm_core.h> |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 36 | |
| 37 | #define DRM_IOCTL_VERSION32 DRM_IOWR(0x00, drm_version32_t) |
| 38 | #define DRM_IOCTL_GET_UNIQUE32 DRM_IOWR(0x01, drm_unique32_t) |
| 39 | #define DRM_IOCTL_GET_MAP32 DRM_IOWR(0x04, drm_map32_t) |
| 40 | #define DRM_IOCTL_GET_CLIENT32 DRM_IOWR(0x05, drm_client32_t) |
| 41 | #define DRM_IOCTL_GET_STATS32 DRM_IOR( 0x06, drm_stats32_t) |
| 42 | |
| 43 | #define DRM_IOCTL_SET_UNIQUE32 DRM_IOW( 0x10, drm_unique32_t) |
| 44 | #define DRM_IOCTL_ADD_MAP32 DRM_IOWR(0x15, drm_map32_t) |
| 45 | #define DRM_IOCTL_ADD_BUFS32 DRM_IOWR(0x16, drm_buf_desc32_t) |
| 46 | #define DRM_IOCTL_MARK_BUFS32 DRM_IOW( 0x17, drm_buf_desc32_t) |
| 47 | #define DRM_IOCTL_INFO_BUFS32 DRM_IOWR(0x18, drm_buf_info32_t) |
| 48 | #define DRM_IOCTL_MAP_BUFS32 DRM_IOWR(0x19, drm_buf_map32_t) |
| 49 | #define DRM_IOCTL_FREE_BUFS32 DRM_IOW( 0x1a, drm_buf_free32_t) |
| 50 | |
| 51 | #define DRM_IOCTL_RM_MAP32 DRM_IOW( 0x1b, drm_map32_t) |
| 52 | |
| 53 | #define DRM_IOCTL_SET_SAREA_CTX32 DRM_IOW( 0x1c, drm_ctx_priv_map32_t) |
| 54 | #define DRM_IOCTL_GET_SAREA_CTX32 DRM_IOWR(0x1d, drm_ctx_priv_map32_t) |
| 55 | |
| 56 | #define DRM_IOCTL_RES_CTX32 DRM_IOWR(0x26, drm_ctx_res32_t) |
| 57 | #define DRM_IOCTL_DMA32 DRM_IOWR(0x29, drm_dma32_t) |
| 58 | |
| 59 | #define DRM_IOCTL_AGP_ENABLE32 DRM_IOW( 0x32, drm_agp_mode32_t) |
| 60 | #define DRM_IOCTL_AGP_INFO32 DRM_IOR( 0x33, drm_agp_info32_t) |
| 61 | #define DRM_IOCTL_AGP_ALLOC32 DRM_IOWR(0x34, drm_agp_buffer32_t) |
| 62 | #define DRM_IOCTL_AGP_FREE32 DRM_IOW( 0x35, drm_agp_buffer32_t) |
| 63 | #define DRM_IOCTL_AGP_BIND32 DRM_IOW( 0x36, drm_agp_binding32_t) |
| 64 | #define DRM_IOCTL_AGP_UNBIND32 DRM_IOW( 0x37, drm_agp_binding32_t) |
| 65 | |
| 66 | #define DRM_IOCTL_SG_ALLOC32 DRM_IOW( 0x38, drm_scatter_gather32_t) |
| 67 | #define DRM_IOCTL_SG_FREE32 DRM_IOW( 0x39, drm_scatter_gather32_t) |
| 68 | |
Eric Anholt | 4956887 | 2008-10-21 11:38:50 -0700 | [diff] [blame] | 69 | #define DRM_IOCTL_UPDATE_DRAW32 DRM_IOW( 0x3f, drm_update_draw32_t) |
| 70 | |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 71 | #define DRM_IOCTL_WAIT_VBLANK32 DRM_IOWR(0x3a, drm_wait_vblank32_t) |
| 72 | |
Tvrtko Ursulin | c631d5f | 2015-07-14 11:13:08 +0100 | [diff] [blame] | 73 | #define DRM_IOCTL_MODE_ADDFB232 DRM_IOWR(0xb8, drm_mode_fb_cmd232_t) |
| 74 | |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 75 | typedef struct drm_version_32 { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 76 | int version_major; /**< Major version */ |
| 77 | int version_minor; /**< Minor version */ |
| 78 | int version_patchlevel; /**< Patch level */ |
| 79 | u32 name_len; /**< Length of name buffer */ |
| 80 | u32 name; /**< Name of driver */ |
| 81 | u32 date_len; /**< Length of date buffer */ |
| 82 | u32 date; /**< User-space buffer to hold date */ |
| 83 | u32 desc_len; /**< Length of desc buffer */ |
| 84 | u32 desc; /**< User-space buffer to hold desc */ |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 85 | } drm_version32_t; |
| 86 | |
| 87 | static int compat_drm_version(struct file *file, unsigned int cmd, |
| 88 | unsigned long arg) |
| 89 | { |
| 90 | drm_version32_t v32; |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 91 | struct drm_version __user *version; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 92 | int err; |
| 93 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 94 | if (copy_from_user(&v32, (void __user *)arg, sizeof(v32))) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 95 | return -EFAULT; |
| 96 | |
| 97 | version = compat_alloc_user_space(sizeof(*version)); |
Jarkko Sakkinen | 1f96bee | 2015-07-03 14:17:29 +0300 | [diff] [blame] | 98 | if (!version) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 99 | return -EFAULT; |
| 100 | if (__put_user(v32.name_len, &version->name_len) |
| 101 | || __put_user((void __user *)(unsigned long)v32.name, |
| 102 | &version->name) |
| 103 | || __put_user(v32.date_len, &version->date_len) |
| 104 | || __put_user((void __user *)(unsigned long)v32.date, |
| 105 | &version->date) |
| 106 | || __put_user(v32.desc_len, &version->desc_len) |
| 107 | || __put_user((void __user *)(unsigned long)v32.desc, |
| 108 | &version->desc)) |
| 109 | return -EFAULT; |
| 110 | |
Arnd Bergmann | ed8b670 | 2009-12-16 22:17:09 +0000 | [diff] [blame] | 111 | err = drm_ioctl(file, |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 112 | DRM_IOCTL_VERSION, (unsigned long)version); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 113 | if (err) |
| 114 | return err; |
| 115 | |
| 116 | if (__get_user(v32.version_major, &version->version_major) |
| 117 | || __get_user(v32.version_minor, &version->version_minor) |
| 118 | || __get_user(v32.version_patchlevel, &version->version_patchlevel) |
| 119 | || __get_user(v32.name_len, &version->name_len) |
| 120 | || __get_user(v32.date_len, &version->date_len) |
| 121 | || __get_user(v32.desc_len, &version->desc_len)) |
| 122 | return -EFAULT; |
| 123 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 124 | if (copy_to_user((void __user *)arg, &v32, sizeof(v32))) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 125 | return -EFAULT; |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | typedef struct drm_unique32 { |
| 130 | u32 unique_len; /**< Length of unique */ |
| 131 | u32 unique; /**< Unique name for driver instantiation */ |
| 132 | } drm_unique32_t; |
| 133 | |
| 134 | static int compat_drm_getunique(struct file *file, unsigned int cmd, |
| 135 | unsigned long arg) |
| 136 | { |
| 137 | drm_unique32_t uq32; |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 138 | struct drm_unique __user *u; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 139 | int err; |
| 140 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 141 | if (copy_from_user(&uq32, (void __user *)arg, sizeof(uq32))) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 142 | return -EFAULT; |
| 143 | |
| 144 | u = compat_alloc_user_space(sizeof(*u)); |
Jarkko Sakkinen | 1f96bee | 2015-07-03 14:17:29 +0300 | [diff] [blame] | 145 | if (!u) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 146 | return -EFAULT; |
| 147 | if (__put_user(uq32.unique_len, &u->unique_len) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 148 | || __put_user((void __user *)(unsigned long)uq32.unique, |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 149 | &u->unique)) |
| 150 | return -EFAULT; |
| 151 | |
Arnd Bergmann | ed8b670 | 2009-12-16 22:17:09 +0000 | [diff] [blame] | 152 | err = drm_ioctl(file, DRM_IOCTL_GET_UNIQUE, (unsigned long)u); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 153 | if (err) |
| 154 | return err; |
| 155 | |
| 156 | if (__get_user(uq32.unique_len, &u->unique_len)) |
| 157 | return -EFAULT; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 158 | if (copy_to_user((void __user *)arg, &uq32, sizeof(uq32))) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 159 | return -EFAULT; |
| 160 | return 0; |
| 161 | } |
| 162 | |
| 163 | static int compat_drm_setunique(struct file *file, unsigned int cmd, |
| 164 | unsigned long arg) |
| 165 | { |
| 166 | drm_unique32_t uq32; |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 167 | struct drm_unique __user *u; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 168 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 169 | if (copy_from_user(&uq32, (void __user *)arg, sizeof(uq32))) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 170 | return -EFAULT; |
| 171 | |
| 172 | u = compat_alloc_user_space(sizeof(*u)); |
Jarkko Sakkinen | 1f96bee | 2015-07-03 14:17:29 +0300 | [diff] [blame] | 173 | if (!u) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 174 | return -EFAULT; |
| 175 | if (__put_user(uq32.unique_len, &u->unique_len) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 176 | || __put_user((void __user *)(unsigned long)uq32.unique, |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 177 | &u->unique)) |
| 178 | return -EFAULT; |
| 179 | |
Arnd Bergmann | ed8b670 | 2009-12-16 22:17:09 +0000 | [diff] [blame] | 180 | return drm_ioctl(file, DRM_IOCTL_SET_UNIQUE, (unsigned long)u); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | typedef struct drm_map32 { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 184 | u32 offset; /**< Requested physical address (0 for SAREA)*/ |
| 185 | u32 size; /**< Requested physical size (bytes) */ |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 186 | enum drm_map_type type; /**< Type of memory to map */ |
| 187 | enum drm_map_flags flags; /**< Flags */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 188 | u32 handle; /**< User-space: "Handle" to pass to mmap() */ |
| 189 | int mtrr; /**< MTRR slot used */ |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 190 | } drm_map32_t; |
| 191 | |
| 192 | static int compat_drm_getmap(struct file *file, unsigned int cmd, |
| 193 | unsigned long arg) |
| 194 | { |
| 195 | drm_map32_t __user *argp = (void __user *)arg; |
| 196 | drm_map32_t m32; |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 197 | struct drm_map __user *map; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 198 | int idx, err; |
| 199 | void *handle; |
| 200 | |
| 201 | if (get_user(idx, &argp->offset)) |
| 202 | return -EFAULT; |
| 203 | |
| 204 | map = compat_alloc_user_space(sizeof(*map)); |
Jarkko Sakkinen | 1f96bee | 2015-07-03 14:17:29 +0300 | [diff] [blame] | 205 | if (!map) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 206 | return -EFAULT; |
| 207 | if (__put_user(idx, &map->offset)) |
| 208 | return -EFAULT; |
| 209 | |
Arnd Bergmann | ed8b670 | 2009-12-16 22:17:09 +0000 | [diff] [blame] | 210 | err = drm_ioctl(file, DRM_IOCTL_GET_MAP, (unsigned long)map); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 211 | if (err) |
| 212 | return err; |
| 213 | |
| 214 | if (__get_user(m32.offset, &map->offset) |
| 215 | || __get_user(m32.size, &map->size) |
| 216 | || __get_user(m32.type, &map->type) |
| 217 | || __get_user(m32.flags, &map->flags) |
| 218 | || __get_user(handle, &map->handle) |
| 219 | || __get_user(m32.mtrr, &map->mtrr)) |
| 220 | return -EFAULT; |
| 221 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 222 | m32.handle = (unsigned long)handle; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 223 | if (copy_to_user(argp, &m32, sizeof(m32))) |
| 224 | return -EFAULT; |
| 225 | return 0; |
| 226 | |
| 227 | } |
| 228 | |
| 229 | static int compat_drm_addmap(struct file *file, unsigned int cmd, |
| 230 | unsigned long arg) |
| 231 | { |
| 232 | drm_map32_t __user *argp = (void __user *)arg; |
| 233 | drm_map32_t m32; |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 234 | struct drm_map __user *map; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 235 | int err; |
| 236 | void *handle; |
| 237 | |
| 238 | if (copy_from_user(&m32, argp, sizeof(m32))) |
| 239 | return -EFAULT; |
| 240 | |
| 241 | map = compat_alloc_user_space(sizeof(*map)); |
Jarkko Sakkinen | 1f96bee | 2015-07-03 14:17:29 +0300 | [diff] [blame] | 242 | if (!map) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 243 | return -EFAULT; |
| 244 | if (__put_user(m32.offset, &map->offset) |
| 245 | || __put_user(m32.size, &map->size) |
| 246 | || __put_user(m32.type, &map->type) |
| 247 | || __put_user(m32.flags, &map->flags)) |
| 248 | return -EFAULT; |
| 249 | |
Arnd Bergmann | ed8b670 | 2009-12-16 22:17:09 +0000 | [diff] [blame] | 250 | err = drm_ioctl(file, DRM_IOCTL_ADD_MAP, (unsigned long)map); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 251 | if (err) |
| 252 | return err; |
| 253 | |
| 254 | if (__get_user(m32.offset, &map->offset) |
| 255 | || __get_user(m32.mtrr, &map->mtrr) |
| 256 | || __get_user(handle, &map->handle)) |
| 257 | return -EFAULT; |
| 258 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 259 | m32.handle = (unsigned long)handle; |
Christian Dietrich | cafe8d8 | 2011-06-04 15:36:43 +0000 | [diff] [blame] | 260 | if (m32.handle != (unsigned long)handle) |
| 261 | printk_ratelimited(KERN_ERR "compat_drm_addmap truncated handle" |
| 262 | " %p for type %d offset %x\n", |
| 263 | handle, m32.type, m32.offset); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 264 | |
| 265 | if (copy_to_user(argp, &m32, sizeof(m32))) |
| 266 | return -EFAULT; |
| 267 | |
| 268 | return 0; |
| 269 | } |
| 270 | |
| 271 | static int compat_drm_rmmap(struct file *file, unsigned int cmd, |
| 272 | unsigned long arg) |
| 273 | { |
| 274 | drm_map32_t __user *argp = (void __user *)arg; |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 275 | struct drm_map __user *map; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 276 | u32 handle; |
| 277 | |
| 278 | if (get_user(handle, &argp->handle)) |
| 279 | return -EFAULT; |
| 280 | |
| 281 | map = compat_alloc_user_space(sizeof(*map)); |
Jarkko Sakkinen | 1f96bee | 2015-07-03 14:17:29 +0300 | [diff] [blame] | 282 | if (!map) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 283 | return -EFAULT; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 284 | if (__put_user((void *)(unsigned long)handle, &map->handle)) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 285 | return -EFAULT; |
| 286 | |
Arnd Bergmann | ed8b670 | 2009-12-16 22:17:09 +0000 | [diff] [blame] | 287 | return drm_ioctl(file, DRM_IOCTL_RM_MAP, (unsigned long)map); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | typedef struct drm_client32 { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 291 | int idx; /**< Which client desired? */ |
| 292 | int auth; /**< Is client authenticated? */ |
| 293 | u32 pid; /**< Process ID */ |
| 294 | u32 uid; /**< User ID */ |
| 295 | u32 magic; /**< Magic */ |
| 296 | u32 iocs; /**< Ioctl count */ |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 297 | } drm_client32_t; |
| 298 | |
| 299 | static int compat_drm_getclient(struct file *file, unsigned int cmd, |
| 300 | unsigned long arg) |
| 301 | { |
| 302 | drm_client32_t c32; |
| 303 | drm_client32_t __user *argp = (void __user *)arg; |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 304 | struct drm_client __user *client; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 305 | int idx, err; |
| 306 | |
| 307 | if (get_user(idx, &argp->idx)) |
| 308 | return -EFAULT; |
| 309 | |
| 310 | client = compat_alloc_user_space(sizeof(*client)); |
Jarkko Sakkinen | 1f96bee | 2015-07-03 14:17:29 +0300 | [diff] [blame] | 311 | if (!client) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 312 | return -EFAULT; |
| 313 | if (__put_user(idx, &client->idx)) |
| 314 | return -EFAULT; |
| 315 | |
Arnd Bergmann | ed8b670 | 2009-12-16 22:17:09 +0000 | [diff] [blame] | 316 | err = drm_ioctl(file, DRM_IOCTL_GET_CLIENT, (unsigned long)client); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 317 | if (err) |
| 318 | return err; |
| 319 | |
Julia Lawall | 08bc3d4 | 2012-01-30 12:05:55 +0100 | [diff] [blame] | 320 | if (__get_user(c32.idx, &client->idx) |
| 321 | || __get_user(c32.auth, &client->auth) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 322 | || __get_user(c32.pid, &client->pid) |
| 323 | || __get_user(c32.uid, &client->uid) |
| 324 | || __get_user(c32.magic, &client->magic) |
| 325 | || __get_user(c32.iocs, &client->iocs)) |
| 326 | return -EFAULT; |
| 327 | |
| 328 | if (copy_to_user(argp, &c32, sizeof(c32))) |
| 329 | return -EFAULT; |
| 330 | return 0; |
| 331 | } |
| 332 | |
| 333 | typedef struct drm_stats32 { |
| 334 | u32 count; |
| 335 | struct { |
| 336 | u32 value; |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 337 | enum drm_stat_type type; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 338 | } data[15]; |
| 339 | } drm_stats32_t; |
| 340 | |
| 341 | static int compat_drm_getstats(struct file *file, unsigned int cmd, |
| 342 | unsigned long arg) |
| 343 | { |
| 344 | drm_stats32_t s32; |
| 345 | drm_stats32_t __user *argp = (void __user *)arg; |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 346 | struct drm_stats __user *stats; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 347 | int i, err; |
| 348 | |
| 349 | stats = compat_alloc_user_space(sizeof(*stats)); |
Jarkko Sakkinen | 1f96bee | 2015-07-03 14:17:29 +0300 | [diff] [blame] | 350 | if (!stats) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 351 | return -EFAULT; |
| 352 | |
Arnd Bergmann | ed8b670 | 2009-12-16 22:17:09 +0000 | [diff] [blame] | 353 | err = drm_ioctl(file, DRM_IOCTL_GET_STATS, (unsigned long)stats); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 354 | if (err) |
| 355 | return err; |
| 356 | |
| 357 | if (__get_user(s32.count, &stats->count)) |
| 358 | return -EFAULT; |
| 359 | for (i = 0; i < 15; ++i) |
| 360 | if (__get_user(s32.data[i].value, &stats->data[i].value) |
| 361 | || __get_user(s32.data[i].type, &stats->data[i].type)) |
| 362 | return -EFAULT; |
| 363 | |
| 364 | if (copy_to_user(argp, &s32, sizeof(s32))) |
| 365 | return -EFAULT; |
| 366 | return 0; |
| 367 | } |
| 368 | |
| 369 | typedef struct drm_buf_desc32 { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 370 | int count; /**< Number of buffers of this size */ |
| 371 | int size; /**< Size in bytes */ |
| 372 | int low_mark; /**< Low water mark */ |
| 373 | int high_mark; /**< High water mark */ |
| 374 | int flags; |
| 375 | u32 agp_start; /**< Start address in the AGP aperture */ |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 376 | } drm_buf_desc32_t; |
| 377 | |
| 378 | static int compat_drm_addbufs(struct file *file, unsigned int cmd, |
| 379 | unsigned long arg) |
| 380 | { |
| 381 | drm_buf_desc32_t __user *argp = (void __user *)arg; |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 382 | struct drm_buf_desc __user *buf; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 383 | int err; |
| 384 | unsigned long agp_start; |
| 385 | |
| 386 | buf = compat_alloc_user_space(sizeof(*buf)); |
Jarkko Sakkinen | 1f96bee | 2015-07-03 14:17:29 +0300 | [diff] [blame] | 387 | if (!buf || !access_ok(VERIFY_WRITE, argp, sizeof(*argp))) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 388 | return -EFAULT; |
| 389 | |
| 390 | if (__copy_in_user(buf, argp, offsetof(drm_buf_desc32_t, agp_start)) |
| 391 | || __get_user(agp_start, &argp->agp_start) |
| 392 | || __put_user(agp_start, &buf->agp_start)) |
| 393 | return -EFAULT; |
| 394 | |
Arnd Bergmann | ed8b670 | 2009-12-16 22:17:09 +0000 | [diff] [blame] | 395 | err = drm_ioctl(file, DRM_IOCTL_ADD_BUFS, (unsigned long)buf); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 396 | if (err) |
| 397 | return err; |
| 398 | |
| 399 | if (__copy_in_user(argp, buf, offsetof(drm_buf_desc32_t, agp_start)) |
| 400 | || __get_user(agp_start, &buf->agp_start) |
| 401 | || __put_user(agp_start, &argp->agp_start)) |
| 402 | return -EFAULT; |
| 403 | |
| 404 | return 0; |
| 405 | } |
| 406 | |
| 407 | static int compat_drm_markbufs(struct file *file, unsigned int cmd, |
| 408 | unsigned long arg) |
| 409 | { |
| 410 | drm_buf_desc32_t b32; |
| 411 | drm_buf_desc32_t __user *argp = (void __user *)arg; |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 412 | struct drm_buf_desc __user *buf; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 413 | |
| 414 | if (copy_from_user(&b32, argp, sizeof(b32))) |
| 415 | return -EFAULT; |
| 416 | |
| 417 | buf = compat_alloc_user_space(sizeof(*buf)); |
Jarkko Sakkinen | 1f96bee | 2015-07-03 14:17:29 +0300 | [diff] [blame] | 418 | if (!buf) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 419 | return -EFAULT; |
| 420 | |
| 421 | if (__put_user(b32.size, &buf->size) |
| 422 | || __put_user(b32.low_mark, &buf->low_mark) |
| 423 | || __put_user(b32.high_mark, &buf->high_mark)) |
| 424 | return -EFAULT; |
| 425 | |
Arnd Bergmann | ed8b670 | 2009-12-16 22:17:09 +0000 | [diff] [blame] | 426 | return drm_ioctl(file, DRM_IOCTL_MARK_BUFS, (unsigned long)buf); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | typedef struct drm_buf_info32 { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 430 | int count; /**< Entries in list */ |
| 431 | u32 list; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 432 | } drm_buf_info32_t; |
| 433 | |
| 434 | static int compat_drm_infobufs(struct file *file, unsigned int cmd, |
| 435 | unsigned long arg) |
| 436 | { |
| 437 | drm_buf_info32_t req32; |
| 438 | drm_buf_info32_t __user *argp = (void __user *)arg; |
| 439 | drm_buf_desc32_t __user *to; |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 440 | struct drm_buf_info __user *request; |
| 441 | struct drm_buf_desc __user *list; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 442 | size_t nbytes; |
| 443 | int i, err; |
| 444 | int count, actual; |
| 445 | |
| 446 | if (copy_from_user(&req32, argp, sizeof(req32))) |
| 447 | return -EFAULT; |
| 448 | |
| 449 | count = req32.count; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 450 | to = (drm_buf_desc32_t __user *) (unsigned long)req32.list; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 451 | if (count < 0) |
| 452 | count = 0; |
| 453 | if (count > 0 |
| 454 | && !access_ok(VERIFY_WRITE, to, count * sizeof(drm_buf_desc32_t))) |
| 455 | return -EFAULT; |
| 456 | |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 457 | nbytes = sizeof(*request) + count * sizeof(struct drm_buf_desc); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 458 | request = compat_alloc_user_space(nbytes); |
Jarkko Sakkinen | 1f96bee | 2015-07-03 14:17:29 +0300 | [diff] [blame] | 459 | if (!request) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 460 | return -EFAULT; |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 461 | list = (struct drm_buf_desc *) (request + 1); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 462 | |
| 463 | if (__put_user(count, &request->count) |
| 464 | || __put_user(list, &request->list)) |
| 465 | return -EFAULT; |
| 466 | |
Arnd Bergmann | ed8b670 | 2009-12-16 22:17:09 +0000 | [diff] [blame] | 467 | err = drm_ioctl(file, DRM_IOCTL_INFO_BUFS, (unsigned long)request); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 468 | if (err) |
| 469 | return err; |
| 470 | |
| 471 | if (__get_user(actual, &request->count)) |
| 472 | return -EFAULT; |
| 473 | if (count >= actual) |
| 474 | for (i = 0; i < actual; ++i) |
| 475 | if (__copy_in_user(&to[i], &list[i], |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 476 | offsetof(struct drm_buf_desc, flags))) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 477 | return -EFAULT; |
| 478 | |
| 479 | if (__put_user(actual, &argp->count)) |
| 480 | return -EFAULT; |
| 481 | |
| 482 | return 0; |
| 483 | } |
| 484 | |
| 485 | typedef struct drm_buf_pub32 { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 486 | int idx; /**< Index into the master buffer list */ |
| 487 | int total; /**< Buffer size */ |
| 488 | int used; /**< Amount of buffer in use (for DMA) */ |
| 489 | u32 address; /**< Address of buffer */ |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 490 | } drm_buf_pub32_t; |
| 491 | |
| 492 | typedef struct drm_buf_map32 { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 493 | int count; /**< Length of the buffer list */ |
| 494 | u32 virtual; /**< Mmap'd area in user-virtual */ |
| 495 | u32 list; /**< Buffer information */ |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 496 | } drm_buf_map32_t; |
| 497 | |
| 498 | static int compat_drm_mapbufs(struct file *file, unsigned int cmd, |
| 499 | unsigned long arg) |
| 500 | { |
| 501 | drm_buf_map32_t __user *argp = (void __user *)arg; |
| 502 | drm_buf_map32_t req32; |
| 503 | drm_buf_pub32_t __user *list32; |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 504 | struct drm_buf_map __user *request; |
| 505 | struct drm_buf_pub __user *list; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 506 | int i, err; |
| 507 | int count, actual; |
| 508 | size_t nbytes; |
| 509 | void __user *addr; |
| 510 | |
| 511 | if (copy_from_user(&req32, argp, sizeof(req32))) |
| 512 | return -EFAULT; |
| 513 | count = req32.count; |
| 514 | list32 = (void __user *)(unsigned long)req32.list; |
| 515 | |
| 516 | if (count < 0) |
| 517 | return -EINVAL; |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 518 | nbytes = sizeof(*request) + count * sizeof(struct drm_buf_pub); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 519 | request = compat_alloc_user_space(nbytes); |
Jarkko Sakkinen | 1f96bee | 2015-07-03 14:17:29 +0300 | [diff] [blame] | 520 | if (!request) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 521 | return -EFAULT; |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 522 | list = (struct drm_buf_pub *) (request + 1); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 523 | |
| 524 | if (__put_user(count, &request->count) |
| 525 | || __put_user(list, &request->list)) |
| 526 | return -EFAULT; |
| 527 | |
Arnd Bergmann | ed8b670 | 2009-12-16 22:17:09 +0000 | [diff] [blame] | 528 | err = drm_ioctl(file, DRM_IOCTL_MAP_BUFS, (unsigned long)request); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 529 | if (err) |
| 530 | return err; |
| 531 | |
| 532 | if (__get_user(actual, &request->count)) |
| 533 | return -EFAULT; |
| 534 | if (count >= actual) |
| 535 | for (i = 0; i < actual; ++i) |
| 536 | if (__copy_in_user(&list32[i], &list[i], |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 537 | offsetof(struct drm_buf_pub, address)) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 538 | || __get_user(addr, &list[i].address) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 539 | || __put_user((unsigned long)addr, |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 540 | &list32[i].address)) |
| 541 | return -EFAULT; |
| 542 | |
| 543 | if (__put_user(actual, &argp->count) |
| 544 | || __get_user(addr, &request->virtual) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 545 | || __put_user((unsigned long)addr, &argp->virtual)) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 546 | return -EFAULT; |
| 547 | |
| 548 | return 0; |
| 549 | } |
| 550 | |
| 551 | typedef struct drm_buf_free32 { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 552 | int count; |
| 553 | u32 list; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 554 | } drm_buf_free32_t; |
| 555 | |
| 556 | static int compat_drm_freebufs(struct file *file, unsigned int cmd, |
| 557 | unsigned long arg) |
| 558 | { |
| 559 | drm_buf_free32_t req32; |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 560 | struct drm_buf_free __user *request; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 561 | drm_buf_free32_t __user *argp = (void __user *)arg; |
| 562 | |
| 563 | if (copy_from_user(&req32, argp, sizeof(req32))) |
| 564 | return -EFAULT; |
| 565 | |
| 566 | request = compat_alloc_user_space(sizeof(*request)); |
Jarkko Sakkinen | 1f96bee | 2015-07-03 14:17:29 +0300 | [diff] [blame] | 567 | if (!request) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 568 | return -EFAULT; |
| 569 | if (__put_user(req32.count, &request->count) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 570 | || __put_user((int __user *)(unsigned long)req32.list, |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 571 | &request->list)) |
| 572 | return -EFAULT; |
| 573 | |
Arnd Bergmann | ed8b670 | 2009-12-16 22:17:09 +0000 | [diff] [blame] | 574 | return drm_ioctl(file, DRM_IOCTL_FREE_BUFS, (unsigned long)request); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | typedef struct drm_ctx_priv_map32 { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 578 | unsigned int ctx_id; /**< Context requesting private mapping */ |
| 579 | u32 handle; /**< Handle of map */ |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 580 | } drm_ctx_priv_map32_t; |
| 581 | |
| 582 | static int compat_drm_setsareactx(struct file *file, unsigned int cmd, |
| 583 | unsigned long arg) |
| 584 | { |
| 585 | drm_ctx_priv_map32_t req32; |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 586 | struct drm_ctx_priv_map __user *request; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 587 | drm_ctx_priv_map32_t __user *argp = (void __user *)arg; |
| 588 | |
| 589 | if (copy_from_user(&req32, argp, sizeof(req32))) |
| 590 | return -EFAULT; |
| 591 | |
| 592 | request = compat_alloc_user_space(sizeof(*request)); |
Jarkko Sakkinen | 1f96bee | 2015-07-03 14:17:29 +0300 | [diff] [blame] | 593 | if (!request) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 594 | return -EFAULT; |
| 595 | if (__put_user(req32.ctx_id, &request->ctx_id) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 596 | || __put_user((void *)(unsigned long)req32.handle, |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 597 | &request->handle)) |
| 598 | return -EFAULT; |
| 599 | |
Arnd Bergmann | ed8b670 | 2009-12-16 22:17:09 +0000 | [diff] [blame] | 600 | return drm_ioctl(file, DRM_IOCTL_SET_SAREA_CTX, (unsigned long)request); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | static int compat_drm_getsareactx(struct file *file, unsigned int cmd, |
| 604 | unsigned long arg) |
| 605 | { |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 606 | struct drm_ctx_priv_map __user *request; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 607 | drm_ctx_priv_map32_t __user *argp = (void __user *)arg; |
| 608 | int err; |
| 609 | unsigned int ctx_id; |
| 610 | void *handle; |
| 611 | |
| 612 | if (!access_ok(VERIFY_WRITE, argp, sizeof(*argp)) |
| 613 | || __get_user(ctx_id, &argp->ctx_id)) |
| 614 | return -EFAULT; |
| 615 | |
| 616 | request = compat_alloc_user_space(sizeof(*request)); |
Jarkko Sakkinen | 1f96bee | 2015-07-03 14:17:29 +0300 | [diff] [blame] | 617 | if (!request) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 618 | return -EFAULT; |
| 619 | if (__put_user(ctx_id, &request->ctx_id)) |
| 620 | return -EFAULT; |
| 621 | |
Arnd Bergmann | ed8b670 | 2009-12-16 22:17:09 +0000 | [diff] [blame] | 622 | err = drm_ioctl(file, DRM_IOCTL_GET_SAREA_CTX, (unsigned long)request); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 623 | if (err) |
| 624 | return err; |
| 625 | |
| 626 | if (__get_user(handle, &request->handle) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 627 | || __put_user((unsigned long)handle, &argp->handle)) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 628 | return -EFAULT; |
| 629 | |
| 630 | return 0; |
| 631 | } |
| 632 | |
| 633 | typedef struct drm_ctx_res32 { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 634 | int count; |
| 635 | u32 contexts; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 636 | } drm_ctx_res32_t; |
| 637 | |
| 638 | static int compat_drm_resctx(struct file *file, unsigned int cmd, |
| 639 | unsigned long arg) |
| 640 | { |
| 641 | drm_ctx_res32_t __user *argp = (void __user *)arg; |
| 642 | drm_ctx_res32_t res32; |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 643 | struct drm_ctx_res __user *res; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 644 | int err; |
| 645 | |
| 646 | if (copy_from_user(&res32, argp, sizeof(res32))) |
| 647 | return -EFAULT; |
| 648 | |
| 649 | res = compat_alloc_user_space(sizeof(*res)); |
Jarkko Sakkinen | 1f96bee | 2015-07-03 14:17:29 +0300 | [diff] [blame] | 650 | if (!res) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 651 | return -EFAULT; |
| 652 | if (__put_user(res32.count, &res->count) |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 653 | || __put_user((struct drm_ctx __user *) (unsigned long)res32.contexts, |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 654 | &res->contexts)) |
| 655 | return -EFAULT; |
| 656 | |
Arnd Bergmann | ed8b670 | 2009-12-16 22:17:09 +0000 | [diff] [blame] | 657 | err = drm_ioctl(file, DRM_IOCTL_RES_CTX, (unsigned long)res); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 658 | if (err) |
| 659 | return err; |
| 660 | |
| 661 | if (__get_user(res32.count, &res->count) |
| 662 | || __put_user(res32.count, &argp->count)) |
| 663 | return -EFAULT; |
| 664 | |
| 665 | return 0; |
| 666 | } |
| 667 | |
| 668 | typedef struct drm_dma32 { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 669 | int context; /**< Context handle */ |
| 670 | int send_count; /**< Number of buffers to send */ |
| 671 | u32 send_indices; /**< List of handles to buffers */ |
| 672 | u32 send_sizes; /**< Lengths of data to send */ |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 673 | enum drm_dma_flags flags; /**< Flags */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 674 | int request_count; /**< Number of buffers requested */ |
| 675 | int request_size; /**< Desired size for buffers */ |
| 676 | u32 request_indices; /**< Buffer information */ |
| 677 | u32 request_sizes; |
| 678 | int granted_count; /**< Number of buffers granted */ |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 679 | } drm_dma32_t; |
| 680 | |
| 681 | static int compat_drm_dma(struct file *file, unsigned int cmd, |
| 682 | unsigned long arg) |
| 683 | { |
| 684 | drm_dma32_t d32; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 685 | drm_dma32_t __user *argp = (void __user *)arg; |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 686 | struct drm_dma __user *d; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 687 | int err; |
| 688 | |
| 689 | if (copy_from_user(&d32, argp, sizeof(d32))) |
| 690 | return -EFAULT; |
| 691 | |
| 692 | d = compat_alloc_user_space(sizeof(*d)); |
Jarkko Sakkinen | 1f96bee | 2015-07-03 14:17:29 +0300 | [diff] [blame] | 693 | if (!d) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 694 | return -EFAULT; |
| 695 | |
| 696 | if (__put_user(d32.context, &d->context) |
| 697 | || __put_user(d32.send_count, &d->send_count) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 698 | || __put_user((int __user *)(unsigned long)d32.send_indices, |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 699 | &d->send_indices) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 700 | || __put_user((int __user *)(unsigned long)d32.send_sizes, |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 701 | &d->send_sizes) |
| 702 | || __put_user(d32.flags, &d->flags) |
| 703 | || __put_user(d32.request_count, &d->request_count) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 704 | || __put_user((int __user *)(unsigned long)d32.request_indices, |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 705 | &d->request_indices) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 706 | || __put_user((int __user *)(unsigned long)d32.request_sizes, |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 707 | &d->request_sizes)) |
| 708 | return -EFAULT; |
| 709 | |
Arnd Bergmann | ed8b670 | 2009-12-16 22:17:09 +0000 | [diff] [blame] | 710 | err = drm_ioctl(file, DRM_IOCTL_DMA, (unsigned long)d); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 711 | if (err) |
| 712 | return err; |
| 713 | |
| 714 | if (__get_user(d32.request_size, &d->request_size) |
| 715 | || __get_user(d32.granted_count, &d->granted_count) |
| 716 | || __put_user(d32.request_size, &argp->request_size) |
| 717 | || __put_user(d32.granted_count, &argp->granted_count)) |
| 718 | return -EFAULT; |
| 719 | |
| 720 | return 0; |
| 721 | } |
| 722 | |
Daniel Vetter | a7fb8a2 | 2015-09-09 16:45:52 +0200 | [diff] [blame] | 723 | #if IS_ENABLED(CONFIG_AGP) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 724 | typedef struct drm_agp_mode32 { |
| 725 | u32 mode; /**< AGP mode */ |
| 726 | } drm_agp_mode32_t; |
| 727 | |
| 728 | static int compat_drm_agp_enable(struct file *file, unsigned int cmd, |
| 729 | unsigned long arg) |
| 730 | { |
| 731 | drm_agp_mode32_t __user *argp = (void __user *)arg; |
| 732 | drm_agp_mode32_t m32; |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 733 | struct drm_agp_mode __user *mode; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 734 | |
| 735 | if (get_user(m32.mode, &argp->mode)) |
| 736 | return -EFAULT; |
| 737 | |
| 738 | mode = compat_alloc_user_space(sizeof(*mode)); |
| 739 | if (put_user(m32.mode, &mode->mode)) |
| 740 | return -EFAULT; |
| 741 | |
Arnd Bergmann | ed8b670 | 2009-12-16 22:17:09 +0000 | [diff] [blame] | 742 | return drm_ioctl(file, DRM_IOCTL_AGP_ENABLE, (unsigned long)mode); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | typedef struct drm_agp_info32 { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 746 | int agp_version_major; |
| 747 | int agp_version_minor; |
| 748 | u32 mode; |
| 749 | u32 aperture_base; /* physical address */ |
| 750 | u32 aperture_size; /* bytes */ |
| 751 | u32 memory_allowed; /* bytes */ |
| 752 | u32 memory_used; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 753 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 754 | /* PCI information */ |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 755 | unsigned short id_vendor; |
| 756 | unsigned short id_device; |
| 757 | } drm_agp_info32_t; |
| 758 | |
| 759 | static int compat_drm_agp_info(struct file *file, unsigned int cmd, |
| 760 | unsigned long arg) |
| 761 | { |
| 762 | drm_agp_info32_t __user *argp = (void __user *)arg; |
| 763 | drm_agp_info32_t i32; |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 764 | struct drm_agp_info __user *info; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 765 | int err; |
| 766 | |
| 767 | info = compat_alloc_user_space(sizeof(*info)); |
Jarkko Sakkinen | 1f96bee | 2015-07-03 14:17:29 +0300 | [diff] [blame] | 768 | if (!info) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 769 | return -EFAULT; |
| 770 | |
Arnd Bergmann | ed8b670 | 2009-12-16 22:17:09 +0000 | [diff] [blame] | 771 | err = drm_ioctl(file, DRM_IOCTL_AGP_INFO, (unsigned long)info); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 772 | if (err) |
| 773 | return err; |
| 774 | |
| 775 | if (__get_user(i32.agp_version_major, &info->agp_version_major) |
| 776 | || __get_user(i32.agp_version_minor, &info->agp_version_minor) |
| 777 | || __get_user(i32.mode, &info->mode) |
| 778 | || __get_user(i32.aperture_base, &info->aperture_base) |
| 779 | || __get_user(i32.aperture_size, &info->aperture_size) |
| 780 | || __get_user(i32.memory_allowed, &info->memory_allowed) |
| 781 | || __get_user(i32.memory_used, &info->memory_used) |
| 782 | || __get_user(i32.id_vendor, &info->id_vendor) |
| 783 | || __get_user(i32.id_device, &info->id_device)) |
| 784 | return -EFAULT; |
| 785 | |
| 786 | if (copy_to_user(argp, &i32, sizeof(i32))) |
| 787 | return -EFAULT; |
| 788 | |
| 789 | return 0; |
| 790 | } |
| 791 | |
| 792 | typedef struct drm_agp_buffer32 { |
| 793 | u32 size; /**< In bytes -- will round to page boundary */ |
| 794 | u32 handle; /**< Used for binding / unbinding */ |
| 795 | u32 type; /**< Type of memory to allocate */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 796 | u32 physical; /**< Physical used by i810 */ |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 797 | } drm_agp_buffer32_t; |
| 798 | |
| 799 | static int compat_drm_agp_alloc(struct file *file, unsigned int cmd, |
| 800 | unsigned long arg) |
| 801 | { |
| 802 | drm_agp_buffer32_t __user *argp = (void __user *)arg; |
| 803 | drm_agp_buffer32_t req32; |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 804 | struct drm_agp_buffer __user *request; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 805 | int err; |
| 806 | |
| 807 | if (copy_from_user(&req32, argp, sizeof(req32))) |
| 808 | return -EFAULT; |
| 809 | |
| 810 | request = compat_alloc_user_space(sizeof(*request)); |
Jarkko Sakkinen | 1f96bee | 2015-07-03 14:17:29 +0300 | [diff] [blame] | 811 | if (!request |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 812 | || __put_user(req32.size, &request->size) |
| 813 | || __put_user(req32.type, &request->type)) |
| 814 | return -EFAULT; |
| 815 | |
Arnd Bergmann | ed8b670 | 2009-12-16 22:17:09 +0000 | [diff] [blame] | 816 | err = drm_ioctl(file, DRM_IOCTL_AGP_ALLOC, (unsigned long)request); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 817 | if (err) |
| 818 | return err; |
| 819 | |
| 820 | if (__get_user(req32.handle, &request->handle) |
| 821 | || __get_user(req32.physical, &request->physical) |
| 822 | || copy_to_user(argp, &req32, sizeof(req32))) { |
Arnd Bergmann | ed8b670 | 2009-12-16 22:17:09 +0000 | [diff] [blame] | 823 | drm_ioctl(file, DRM_IOCTL_AGP_FREE, (unsigned long)request); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 824 | return -EFAULT; |
| 825 | } |
| 826 | |
| 827 | return 0; |
| 828 | } |
| 829 | |
| 830 | static int compat_drm_agp_free(struct file *file, unsigned int cmd, |
| 831 | unsigned long arg) |
| 832 | { |
| 833 | drm_agp_buffer32_t __user *argp = (void __user *)arg; |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 834 | struct drm_agp_buffer __user *request; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 835 | u32 handle; |
| 836 | |
| 837 | request = compat_alloc_user_space(sizeof(*request)); |
Jarkko Sakkinen | 1f96bee | 2015-07-03 14:17:29 +0300 | [diff] [blame] | 838 | if (!request |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 839 | || get_user(handle, &argp->handle) |
| 840 | || __put_user(handle, &request->handle)) |
| 841 | return -EFAULT; |
| 842 | |
Arnd Bergmann | ed8b670 | 2009-12-16 22:17:09 +0000 | [diff] [blame] | 843 | return drm_ioctl(file, DRM_IOCTL_AGP_FREE, (unsigned long)request); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | typedef struct drm_agp_binding32 { |
| 847 | u32 handle; /**< From drm_agp_buffer */ |
| 848 | u32 offset; /**< In bytes -- will round to page boundary */ |
| 849 | } drm_agp_binding32_t; |
| 850 | |
| 851 | static int compat_drm_agp_bind(struct file *file, unsigned int cmd, |
| 852 | unsigned long arg) |
| 853 | { |
| 854 | drm_agp_binding32_t __user *argp = (void __user *)arg; |
| 855 | drm_agp_binding32_t req32; |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 856 | struct drm_agp_binding __user *request; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 857 | |
| 858 | if (copy_from_user(&req32, argp, sizeof(req32))) |
| 859 | return -EFAULT; |
| 860 | |
| 861 | request = compat_alloc_user_space(sizeof(*request)); |
Jarkko Sakkinen | 1f96bee | 2015-07-03 14:17:29 +0300 | [diff] [blame] | 862 | if (!request |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 863 | || __put_user(req32.handle, &request->handle) |
| 864 | || __put_user(req32.offset, &request->offset)) |
| 865 | return -EFAULT; |
| 866 | |
Arnd Bergmann | ed8b670 | 2009-12-16 22:17:09 +0000 | [diff] [blame] | 867 | return drm_ioctl(file, DRM_IOCTL_AGP_BIND, (unsigned long)request); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | static int compat_drm_agp_unbind(struct file *file, unsigned int cmd, |
| 871 | unsigned long arg) |
| 872 | { |
| 873 | drm_agp_binding32_t __user *argp = (void __user *)arg; |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 874 | struct drm_agp_binding __user *request; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 875 | u32 handle; |
| 876 | |
| 877 | request = compat_alloc_user_space(sizeof(*request)); |
Jarkko Sakkinen | 1f96bee | 2015-07-03 14:17:29 +0300 | [diff] [blame] | 878 | if (!request |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 879 | || get_user(handle, &argp->handle) |
| 880 | || __put_user(handle, &request->handle)) |
| 881 | return -EFAULT; |
| 882 | |
Arnd Bergmann | ed8b670 | 2009-12-16 22:17:09 +0000 | [diff] [blame] | 883 | return drm_ioctl(file, DRM_IOCTL_AGP_UNBIND, (unsigned long)request); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 884 | } |
Daniel Vetter | a7fb8a2 | 2015-09-09 16:45:52 +0200 | [diff] [blame] | 885 | #endif /* CONFIG_AGP */ |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 886 | |
| 887 | typedef struct drm_scatter_gather32 { |
| 888 | u32 size; /**< In bytes -- will round to page boundary */ |
| 889 | u32 handle; /**< Used for mapping / unmapping */ |
| 890 | } drm_scatter_gather32_t; |
| 891 | |
| 892 | static int compat_drm_sg_alloc(struct file *file, unsigned int cmd, |
| 893 | unsigned long arg) |
| 894 | { |
| 895 | drm_scatter_gather32_t __user *argp = (void __user *)arg; |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 896 | struct drm_scatter_gather __user *request; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 897 | int err; |
| 898 | unsigned long x; |
| 899 | |
| 900 | request = compat_alloc_user_space(sizeof(*request)); |
Jarkko Sakkinen | 1f96bee | 2015-07-03 14:17:29 +0300 | [diff] [blame] | 901 | if (!request || !access_ok(VERIFY_WRITE, argp, sizeof(*argp)) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 902 | || __get_user(x, &argp->size) |
| 903 | || __put_user(x, &request->size)) |
| 904 | return -EFAULT; |
| 905 | |
Arnd Bergmann | ed8b670 | 2009-12-16 22:17:09 +0000 | [diff] [blame] | 906 | err = drm_ioctl(file, DRM_IOCTL_SG_ALLOC, (unsigned long)request); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 907 | if (err) |
| 908 | return err; |
| 909 | |
| 910 | /* XXX not sure about the handle conversion here... */ |
| 911 | if (__get_user(x, &request->handle) |
| 912 | || __put_user(x >> PAGE_SHIFT, &argp->handle)) |
| 913 | return -EFAULT; |
| 914 | |
| 915 | return 0; |
| 916 | } |
| 917 | |
| 918 | static int compat_drm_sg_free(struct file *file, unsigned int cmd, |
| 919 | unsigned long arg) |
| 920 | { |
| 921 | drm_scatter_gather32_t __user *argp = (void __user *)arg; |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 922 | struct drm_scatter_gather __user *request; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 923 | unsigned long x; |
| 924 | |
| 925 | request = compat_alloc_user_space(sizeof(*request)); |
Jarkko Sakkinen | 1f96bee | 2015-07-03 14:17:29 +0300 | [diff] [blame] | 926 | if (!request || !access_ok(VERIFY_WRITE, argp, sizeof(*argp)) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 927 | || __get_user(x, &argp->handle) |
| 928 | || __put_user(x << PAGE_SHIFT, &request->handle)) |
| 929 | return -EFAULT; |
| 930 | |
Arnd Bergmann | ed8b670 | 2009-12-16 22:17:09 +0000 | [diff] [blame] | 931 | return drm_ioctl(file, DRM_IOCTL_SG_FREE, (unsigned long)request); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 932 | } |
| 933 | |
David Miller | 09e40d6 | 2009-02-18 01:35:21 -0800 | [diff] [blame] | 934 | #if defined(CONFIG_X86) || defined(CONFIG_IA64) |
Eric Anholt | 4956887 | 2008-10-21 11:38:50 -0700 | [diff] [blame] | 935 | typedef struct drm_update_draw32 { |
| 936 | drm_drawable_t handle; |
| 937 | unsigned int type; |
| 938 | unsigned int num; |
| 939 | /* 64-bit version has a 32-bit pad here */ |
| 940 | u64 data; /**< Pointer */ |
| 941 | } __attribute__((packed)) drm_update_draw32_t; |
| 942 | |
| 943 | static int compat_drm_update_draw(struct file *file, unsigned int cmd, |
| 944 | unsigned long arg) |
| 945 | { |
| 946 | drm_update_draw32_t update32; |
| 947 | struct drm_update_draw __user *request; |
| 948 | int err; |
| 949 | |
| 950 | if (copy_from_user(&update32, (void __user *)arg, sizeof(update32))) |
| 951 | return -EFAULT; |
| 952 | |
| 953 | request = compat_alloc_user_space(sizeof(*request)); |
Jarkko Sakkinen | 1f96bee | 2015-07-03 14:17:29 +0300 | [diff] [blame] | 954 | if (!request || |
Eric Anholt | 4956887 | 2008-10-21 11:38:50 -0700 | [diff] [blame] | 955 | __put_user(update32.handle, &request->handle) || |
| 956 | __put_user(update32.type, &request->type) || |
| 957 | __put_user(update32.num, &request->num) || |
| 958 | __put_user(update32.data, &request->data)) |
| 959 | return -EFAULT; |
| 960 | |
Arnd Bergmann | ed8b670 | 2009-12-16 22:17:09 +0000 | [diff] [blame] | 961 | err = drm_ioctl(file, DRM_IOCTL_UPDATE_DRAW, (unsigned long)request); |
Eric Anholt | 4956887 | 2008-10-21 11:38:50 -0700 | [diff] [blame] | 962 | return err; |
| 963 | } |
David Miller | 09e40d6 | 2009-02-18 01:35:21 -0800 | [diff] [blame] | 964 | #endif |
Eric Anholt | 4956887 | 2008-10-21 11:38:50 -0700 | [diff] [blame] | 965 | |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 966 | struct drm_wait_vblank_request32 { |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 967 | enum drm_vblank_seq_type type; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 968 | unsigned int sequence; |
| 969 | u32 signal; |
| 970 | }; |
| 971 | |
| 972 | struct drm_wait_vblank_reply32 { |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 973 | enum drm_vblank_seq_type type; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 974 | unsigned int sequence; |
| 975 | s32 tval_sec; |
| 976 | s32 tval_usec; |
| 977 | }; |
| 978 | |
| 979 | typedef union drm_wait_vblank32 { |
| 980 | struct drm_wait_vblank_request32 request; |
| 981 | struct drm_wait_vblank_reply32 reply; |
| 982 | } drm_wait_vblank32_t; |
| 983 | |
| 984 | static int compat_drm_wait_vblank(struct file *file, unsigned int cmd, |
| 985 | unsigned long arg) |
| 986 | { |
| 987 | drm_wait_vblank32_t __user *argp = (void __user *)arg; |
| 988 | drm_wait_vblank32_t req32; |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 989 | union drm_wait_vblank __user *request; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 990 | int err; |
| 991 | |
| 992 | if (copy_from_user(&req32, argp, sizeof(req32))) |
| 993 | return -EFAULT; |
| 994 | |
| 995 | request = compat_alloc_user_space(sizeof(*request)); |
Jarkko Sakkinen | 1f96bee | 2015-07-03 14:17:29 +0300 | [diff] [blame] | 996 | if (!request |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 997 | || __put_user(req32.request.type, &request->request.type) |
| 998 | || __put_user(req32.request.sequence, &request->request.sequence) |
| 999 | || __put_user(req32.request.signal, &request->request.signal)) |
| 1000 | return -EFAULT; |
| 1001 | |
Arnd Bergmann | ed8b670 | 2009-12-16 22:17:09 +0000 | [diff] [blame] | 1002 | err = drm_ioctl(file, DRM_IOCTL_WAIT_VBLANK, (unsigned long)request); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 1003 | if (err) |
| 1004 | return err; |
| 1005 | |
| 1006 | if (__get_user(req32.reply.type, &request->reply.type) |
| 1007 | || __get_user(req32.reply.sequence, &request->reply.sequence) |
| 1008 | || __get_user(req32.reply.tval_sec, &request->reply.tval_sec) |
| 1009 | || __get_user(req32.reply.tval_usec, &request->reply.tval_usec)) |
| 1010 | return -EFAULT; |
| 1011 | |
| 1012 | if (copy_to_user(argp, &req32, sizeof(req32))) |
| 1013 | return -EFAULT; |
| 1014 | |
| 1015 | return 0; |
| 1016 | } |
| 1017 | |
Tvrtko Ursulin | c631d5f | 2015-07-14 11:13:08 +0100 | [diff] [blame] | 1018 | typedef struct drm_mode_fb_cmd232 { |
| 1019 | u32 fb_id; |
| 1020 | u32 width; |
| 1021 | u32 height; |
| 1022 | u32 pixel_format; |
| 1023 | u32 flags; |
| 1024 | u32 handles[4]; |
| 1025 | u32 pitches[4]; |
| 1026 | u32 offsets[4]; |
| 1027 | u64 modifier[4]; |
| 1028 | } __attribute__((packed)) drm_mode_fb_cmd232_t; |
| 1029 | |
| 1030 | static int compat_drm_mode_addfb2(struct file *file, unsigned int cmd, |
| 1031 | unsigned long arg) |
| 1032 | { |
| 1033 | struct drm_mode_fb_cmd232 __user *argp = (void __user *)arg; |
| 1034 | struct drm_mode_fb_cmd232 req32; |
| 1035 | struct drm_mode_fb_cmd2 __user *req64; |
| 1036 | int i; |
| 1037 | int err; |
| 1038 | |
| 1039 | if (copy_from_user(&req32, argp, sizeof(req32))) |
| 1040 | return -EFAULT; |
| 1041 | |
| 1042 | req64 = compat_alloc_user_space(sizeof(*req64)); |
| 1043 | |
| 1044 | if (!access_ok(VERIFY_WRITE, req64, sizeof(*req64)) |
| 1045 | || __put_user(req32.width, &req64->width) |
| 1046 | || __put_user(req32.height, &req64->height) |
| 1047 | || __put_user(req32.pixel_format, &req64->pixel_format) |
| 1048 | || __put_user(req32.flags, &req64->flags)) |
| 1049 | return -EFAULT; |
| 1050 | |
| 1051 | for (i = 0; i < 4; i++) { |
| 1052 | if (__put_user(req32.handles[i], &req64->handles[i])) |
| 1053 | return -EFAULT; |
| 1054 | if (__put_user(req32.pitches[i], &req64->pitches[i])) |
| 1055 | return -EFAULT; |
| 1056 | if (__put_user(req32.offsets[i], &req64->offsets[i])) |
| 1057 | return -EFAULT; |
| 1058 | if (__put_user(req32.modifier[i], &req64->modifier[i])) |
| 1059 | return -EFAULT; |
| 1060 | } |
| 1061 | |
| 1062 | err = drm_ioctl(file, DRM_IOCTL_MODE_ADDFB2, (unsigned long)req64); |
| 1063 | if (err) |
| 1064 | return err; |
| 1065 | |
| 1066 | if (__get_user(req32.fb_id, &req64->fb_id)) |
| 1067 | return -EFAULT; |
| 1068 | |
| 1069 | if (copy_to_user(argp, &req32, sizeof(req32))) |
| 1070 | return -EFAULT; |
| 1071 | |
| 1072 | return 0; |
| 1073 | } |
| 1074 | |
Ville Syrjälä | 43fc884 | 2015-03-13 14:51:25 +0200 | [diff] [blame] | 1075 | static drm_ioctl_compat_t *drm_compat_ioctls[] = { |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 1076 | [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version, |
| 1077 | [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique, |
| 1078 | [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap, |
| 1079 | [DRM_IOCTL_NR(DRM_IOCTL_GET_CLIENT32)] = compat_drm_getclient, |
| 1080 | [DRM_IOCTL_NR(DRM_IOCTL_GET_STATS32)] = compat_drm_getstats, |
| 1081 | [DRM_IOCTL_NR(DRM_IOCTL_SET_UNIQUE32)] = compat_drm_setunique, |
| 1082 | [DRM_IOCTL_NR(DRM_IOCTL_ADD_MAP32)] = compat_drm_addmap, |
| 1083 | [DRM_IOCTL_NR(DRM_IOCTL_ADD_BUFS32)] = compat_drm_addbufs, |
| 1084 | [DRM_IOCTL_NR(DRM_IOCTL_MARK_BUFS32)] = compat_drm_markbufs, |
| 1085 | [DRM_IOCTL_NR(DRM_IOCTL_INFO_BUFS32)] = compat_drm_infobufs, |
| 1086 | [DRM_IOCTL_NR(DRM_IOCTL_MAP_BUFS32)] = compat_drm_mapbufs, |
| 1087 | [DRM_IOCTL_NR(DRM_IOCTL_FREE_BUFS32)] = compat_drm_freebufs, |
| 1088 | [DRM_IOCTL_NR(DRM_IOCTL_RM_MAP32)] = compat_drm_rmmap, |
| 1089 | [DRM_IOCTL_NR(DRM_IOCTL_SET_SAREA_CTX32)] = compat_drm_setsareactx, |
| 1090 | [DRM_IOCTL_NR(DRM_IOCTL_GET_SAREA_CTX32)] = compat_drm_getsareactx, |
| 1091 | [DRM_IOCTL_NR(DRM_IOCTL_RES_CTX32)] = compat_drm_resctx, |
| 1092 | [DRM_IOCTL_NR(DRM_IOCTL_DMA32)] = compat_drm_dma, |
Daniel Vetter | a7fb8a2 | 2015-09-09 16:45:52 +0200 | [diff] [blame] | 1093 | #if IS_ENABLED(CONFIG_AGP) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 1094 | [DRM_IOCTL_NR(DRM_IOCTL_AGP_ENABLE32)] = compat_drm_agp_enable, |
| 1095 | [DRM_IOCTL_NR(DRM_IOCTL_AGP_INFO32)] = compat_drm_agp_info, |
| 1096 | [DRM_IOCTL_NR(DRM_IOCTL_AGP_ALLOC32)] = compat_drm_agp_alloc, |
| 1097 | [DRM_IOCTL_NR(DRM_IOCTL_AGP_FREE32)] = compat_drm_agp_free, |
| 1098 | [DRM_IOCTL_NR(DRM_IOCTL_AGP_BIND32)] = compat_drm_agp_bind, |
| 1099 | [DRM_IOCTL_NR(DRM_IOCTL_AGP_UNBIND32)] = compat_drm_agp_unbind, |
| 1100 | #endif |
| 1101 | [DRM_IOCTL_NR(DRM_IOCTL_SG_ALLOC32)] = compat_drm_sg_alloc, |
| 1102 | [DRM_IOCTL_NR(DRM_IOCTL_SG_FREE32)] = compat_drm_sg_free, |
David Miller | 09e40d6 | 2009-02-18 01:35:21 -0800 | [diff] [blame] | 1103 | #if defined(CONFIG_X86) || defined(CONFIG_IA64) |
Eric Anholt | 4956887 | 2008-10-21 11:38:50 -0700 | [diff] [blame] | 1104 | [DRM_IOCTL_NR(DRM_IOCTL_UPDATE_DRAW32)] = compat_drm_update_draw, |
David Miller | 09e40d6 | 2009-02-18 01:35:21 -0800 | [diff] [blame] | 1105 | #endif |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 1106 | [DRM_IOCTL_NR(DRM_IOCTL_WAIT_VBLANK32)] = compat_drm_wait_vblank, |
Tvrtko Ursulin | c631d5f | 2015-07-14 11:13:08 +0100 | [diff] [blame] | 1107 | [DRM_IOCTL_NR(DRM_IOCTL_MODE_ADDFB232)] = compat_drm_mode_addfb2, |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 1108 | }; |
| 1109 | |
| 1110 | /** |
| 1111 | * Called whenever a 32-bit process running under a 64-bit kernel |
| 1112 | * performs an ioctl on /dev/drm. |
| 1113 | * |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 1114 | * \param file_priv DRM file private. |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 1115 | * \param cmd command. |
| 1116 | * \param arg user argument. |
| 1117 | * \return zero on success or negative number on failure. |
| 1118 | */ |
| 1119 | long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) |
| 1120 | { |
| 1121 | unsigned int nr = DRM_IOCTL_NR(cmd); |
| 1122 | drm_ioctl_compat_t *fn; |
| 1123 | int ret; |
| 1124 | |
Ian Romanick | 7ffa05e | 2007-11-22 17:02:08 +1000 | [diff] [blame] | 1125 | /* Assume that ioctls without an explicit compat routine will just |
| 1126 | * work. This may not always be a good assumption, but it's better |
| 1127 | * than always failing. |
| 1128 | */ |
Dave Airlie | 3d77461 | 2006-08-07 20:07:43 +1000 | [diff] [blame] | 1129 | if (nr >= ARRAY_SIZE(drm_compat_ioctls)) |
Arnd Bergmann | ed8b670 | 2009-12-16 22:17:09 +0000 | [diff] [blame] | 1130 | return drm_ioctl(filp, cmd, arg); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 1131 | |
| 1132 | fn = drm_compat_ioctls[nr]; |
| 1133 | |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 1134 | if (fn != NULL) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1135 | ret = (*fn) (filp, cmd, arg); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 1136 | else |
Arnd Bergmann | ed8b670 | 2009-12-16 22:17:09 +0000 | [diff] [blame] | 1137 | ret = drm_ioctl(filp, cmd, arg); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 1138 | |
| 1139 | return ret; |
| 1140 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1141 | |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 1142 | EXPORT_SYMBOL(drm_compat_ioctl); |