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