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