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