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