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