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