1 /*- 2 * Copyright (C) Paul Mackerras 2005. 3 * All Rights Reserved. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice (including the next 13 * paragraph) shall be included in all copies or substantial portions of the 14 * Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22 * IN THE SOFTWARE. 23 */ 24 25 #include <sys/cdefs.h> 26 __FBSDID("$FreeBSD$"); 27 28 #ifdef COMPAT_FREEBSD32 29 30 #include <dev/drm2/drmP.h> 31 #include <dev/drm2/drm.h> 32 33 #define DRM_IOCTL_VERSION32 DRM_IOWR(0x00, drm_version32_t) 34 #define DRM_IOCTL_GET_UNIQUE32 DRM_IOWR(0x01, drm_unique32_t) 35 #define DRM_IOCTL_GET_MAP32 DRM_IOWR(0x04, drm_map32_t) 36 #define DRM_IOCTL_GET_CLIENT32 DRM_IOWR(0x05, drm_client32_t) 37 #define DRM_IOCTL_GET_STATS32 DRM_IOR( 0x06, drm_stats32_t) 38 39 #define DRM_IOCTL_SET_UNIQUE32 DRM_IOW( 0x10, drm_unique32_t) 40 #define DRM_IOCTL_ADD_MAP32 DRM_IOWR(0x15, drm_map32_t) 41 #define DRM_IOCTL_ADD_BUFS32 DRM_IOWR(0x16, drm_buf_desc32_t) 42 #define DRM_IOCTL_MARK_BUFS32 DRM_IOW( 0x17, drm_buf_desc32_t) 43 #define DRM_IOCTL_INFO_BUFS32 DRM_IOWR(0x18, drm_buf_info32_t) 44 #define DRM_IOCTL_MAP_BUFS32 DRM_IOWR(0x19, drm_buf_map32_t) 45 #define DRM_IOCTL_FREE_BUFS32 DRM_IOW( 0x1a, drm_buf_free32_t) 46 47 #define DRM_IOCTL_RM_MAP32 DRM_IOW( 0x1b, drm_map32_t) 48 49 #define DRM_IOCTL_SET_SAREA_CTX32 DRM_IOW( 0x1c, drm_ctx_priv_map32_t) 50 #define DRM_IOCTL_GET_SAREA_CTX32 DRM_IOWR(0x1d, drm_ctx_priv_map32_t) 51 52 #define DRM_IOCTL_RES_CTX32 DRM_IOWR(0x26, drm_ctx_res32_t) 53 #define DRM_IOCTL_DMA32 DRM_IOWR(0x29, drm_dma32_t) 54 55 #define DRM_IOCTL_AGP_ENABLE32 DRM_IOW( 0x32, drm_agp_mode32_t) 56 #define DRM_IOCTL_AGP_INFO32 DRM_IOR( 0x33, drm_agp_info32_t) 57 #define DRM_IOCTL_AGP_ALLOC32 DRM_IOWR(0x34, drm_agp_buffer32_t) 58 #define DRM_IOCTL_AGP_FREE32 DRM_IOW( 0x35, drm_agp_buffer32_t) 59 #define DRM_IOCTL_AGP_BIND32 DRM_IOW( 0x36, drm_agp_binding32_t) 60 #define DRM_IOCTL_AGP_UNBIND32 DRM_IOW( 0x37, drm_agp_binding32_t) 61 62 #define DRM_IOCTL_SG_ALLOC32 DRM_IOW( 0x38, drm_scatter_gather32_t) 63 #define DRM_IOCTL_SG_FREE32 DRM_IOW( 0x39, drm_scatter_gather32_t) 64 65 #define DRM_IOCTL_UPDATE_DRAW32 DRM_IOW( 0x3f, drm_update_draw32_t) 66 67 #define DRM_IOCTL_WAIT_VBLANK32 DRM_IOWR(0x3a, drm_wait_vblank32_t) 68 69 typedef struct drm_version_32 { 70 int version_major; /**< Major version */ 71 int version_minor; /**< Minor version */ 72 int version_patchlevel; /**< Patch level */ 73 u32 name_len; /**< Length of name buffer */ 74 u32 name; /**< Name of driver */ 75 u32 date_len; /**< Length of date buffer */ 76 u32 date; /**< User-space buffer to hold date */ 77 u32 desc_len; /**< Length of desc buffer */ 78 u32 desc; /**< User-space buffer to hold desc */ 79 } drm_version32_t; 80 81 static int compat_drm_version(struct drm_device *dev, void *data, 82 struct drm_file *file_priv) 83 { 84 drm_version32_t *v32 = data; 85 struct drm_version version; 86 int err; 87 88 version.name_len = v32->name_len; 89 version.name = (void *)(unsigned long)v32->name; 90 version.date_len = v32->date_len; 91 version.date = (void *)(unsigned long)v32->date; 92 version.desc_len = v32->desc_len; 93 version.desc = (void *)(unsigned long)v32->desc; 94 95 err = drm_version(dev, (void *)&version, file_priv); 96 if (err) 97 return err; 98 99 v32->version_major = version.version_major; 100 v32->version_minor = version.version_minor; 101 v32->version_patchlevel = version.version_patchlevel; 102 v32->name_len = version.name_len; 103 v32->date_len = version.date_len; 104 v32->desc_len = version.desc_len; 105 106 return 0; 107 } 108 109 typedef struct drm_unique32 { 110 u32 unique_len; /**< Length of unique */ 111 u32 unique; /**< Unique name for driver instantiation */ 112 } drm_unique32_t; 113 114 static int compat_drm_getunique(struct drm_device *dev, void *data, 115 struct drm_file *file_priv) 116 { 117 drm_unique32_t *uq32 = data; 118 struct drm_unique u; 119 int err; 120 121 u.unique_len = uq32->unique_len; 122 u.unique = (void *)(unsigned long)uq32->unique; 123 124 err = drm_getunique(dev, (void *)&u, file_priv); 125 if (err) 126 return err; 127 128 uq32->unique_len = u.unique_len; 129 130 return 0; 131 } 132 133 static int compat_drm_setunique(struct drm_device *dev, void *data, 134 struct drm_file *file_priv) 135 { 136 drm_unique32_t *uq32 = data; 137 struct drm_unique u; 138 139 u.unique_len = uq32->unique_len; 140 u.unique = (void *)(unsigned long)uq32->unique; 141 142 return drm_setunique(dev, (void *)&u, file_priv); 143 } 144 145 typedef struct drm_map32 { 146 u32 offset; /**< Requested physical address (0 for SAREA)*/ 147 u32 size; /**< Requested physical size (bytes) */ 148 enum drm_map_type type; /**< Type of memory to map */ 149 enum drm_map_flags flags; /**< Flags */ 150 u32 handle; /**< User-space: "Handle" to pass to mmap() */ 151 int mtrr; /**< MTRR slot used */ 152 } drm_map32_t; 153 154 static int compat_drm_getmap(struct drm_device *dev, void *data, 155 struct drm_file *file_priv) 156 { 157 drm_map32_t *m32 = data; 158 struct drm_map map; 159 int err; 160 void *handle; 161 162 map.offset = (unsigned long)m32->offset; 163 164 err = drm_getmap(dev, (void *)&map, file_priv); 165 if (err) 166 return err; 167 168 m32->offset = map.offset; 169 m32->size = map.size; 170 m32->type = map.type; 171 m32->flags = map.flags; 172 handle = map.handle; 173 m32->mtrr = map.mtrr; 174 175 m32->handle = (unsigned long)handle; 176 177 return 0; 178 179 } 180 181 static int compat_drm_addmap(struct drm_device *dev, void *data, 182 struct drm_file *file_priv) 183 { 184 drm_map32_t *m32 = data; 185 struct drm_map map; 186 int err; 187 void *handle; 188 189 map.offset = (unsigned long)m32->offset; 190 map.size = (unsigned long)m32->size; 191 map.type = m32->type; 192 map.flags = m32->flags; 193 194 err = drm_addmap_ioctl(dev, (void *)&map, file_priv); 195 if (err) 196 return err; 197 198 m32->offset = map.offset; 199 m32->mtrr = map.mtrr; 200 handle = map.handle; 201 202 m32->handle = (unsigned long)handle; 203 if (m32->handle != (unsigned long)handle) 204 DRM_DEBUG("compat_drm_addmap truncated handle" 205 " %p for type %d offset %x\n", 206 handle, m32->type, m32->offset); 207 208 return 0; 209 } 210 211 static int compat_drm_rmmap(struct drm_device *dev, void *data, 212 struct drm_file *file_priv) 213 { 214 drm_map32_t *m32 = data; 215 struct drm_map map; 216 217 map.handle = (void *)(unsigned long)m32->handle; 218 219 return drm_rmmap_ioctl(dev, (void *)&map, file_priv); 220 } 221 222 typedef struct drm_client32 { 223 int idx; /**< Which client desired? */ 224 int auth; /**< Is client authenticated? */ 225 u32 pid; /**< Process ID */ 226 u32 uid; /**< User ID */ 227 u32 magic; /**< Magic */ 228 u32 iocs; /**< Ioctl count */ 229 } drm_client32_t; 230 231 static int compat_drm_getclient(struct drm_device *dev, void *data, 232 struct drm_file *file_priv) 233 { 234 drm_client32_t *c32 = data; 235 struct drm_client client; 236 int err; 237 238 client.idx = c32->idx; 239 240 err = drm_getclient(dev, (void *)&client, file_priv); 241 if (err) 242 return err; 243 244 c32->idx = client.idx; 245 c32->auth = client.auth; 246 c32->pid = client.pid; 247 c32->uid = client.uid; 248 c32->magic = client.magic; 249 c32->iocs = client.iocs; 250 251 return 0; 252 } 253 254 typedef struct drm_stats32 { 255 u32 count; 256 struct { 257 u32 value; 258 enum drm_stat_type type; 259 } data[15]; 260 } drm_stats32_t; 261 262 static int compat_drm_getstats(struct drm_device *dev, void *data, 263 struct drm_file *file_priv) 264 { 265 drm_stats32_t *s32 = data; 266 struct drm_stats stats; 267 int i, err; 268 269 err = drm_getstats(dev, (void *)&stats, file_priv); 270 if (err) 271 return err; 272 273 s32->count = stats.count; 274 for (i = 0; i < stats.count; i++) { 275 s32->data[i].value = stats.data[i].value; 276 s32->data[i].type = stats.data[i].type; 277 } 278 279 return 0; 280 } 281 282 typedef struct drm_buf_desc32 { 283 int count; /**< Number of buffers of this size */ 284 int size; /**< Size in bytes */ 285 int low_mark; /**< Low water mark */ 286 int high_mark; /**< High water mark */ 287 int flags; 288 u32 agp_start; /**< Start address in the AGP aperture */ 289 } drm_buf_desc32_t; 290 291 static int compat_drm_addbufs(struct drm_device *dev, void *data, 292 struct drm_file *file_priv) 293 { 294 drm_buf_desc32_t *b32 = data; 295 struct drm_buf_desc buf; 296 int err; 297 298 buf.count = b32->count; 299 buf.size = b32->size; 300 buf.low_mark = b32->low_mark; 301 buf.high_mark = b32->high_mark; 302 buf.flags = b32->flags; 303 buf.agp_start = (unsigned long)b32->agp_start; 304 305 err = drm_addbufs(dev, (void *)&buf, file_priv); 306 if (err) 307 return err; 308 309 b32->count = buf.count; 310 b32->size = buf.size; 311 b32->low_mark = buf.low_mark; 312 b32->high_mark = buf.high_mark; 313 b32->flags = buf.flags; 314 b32->agp_start = buf.agp_start; 315 316 return 0; 317 } 318 319 static int compat_drm_markbufs(struct drm_device *dev, void *data, 320 struct drm_file *file_priv) 321 { 322 drm_buf_desc32_t *b32 = data; 323 struct drm_buf_desc buf; 324 325 buf.size = b32->size; 326 buf.low_mark = b32->low_mark; 327 buf.high_mark = b32->high_mark; 328 329 return drm_markbufs(dev, (void *)&buf, file_priv); 330 } 331 332 typedef struct drm_buf_info32 { 333 int count; /**< Entries in list */ 334 u32 list; 335 } drm_buf_info32_t; 336 337 static int compat_drm_infobufs(struct drm_device *dev, void *data, 338 struct drm_file *file_priv) 339 { 340 drm_buf_info32_t *req32 = data; 341 drm_buf_desc32_t *to; 342 struct drm_buf_info *request; 343 struct drm_buf_desc *list; 344 size_t nbytes; 345 int i, err; 346 int count, actual; 347 348 count = req32->count; 349 to = (drm_buf_desc32_t *)(unsigned long)req32->list; 350 if (count < 0) 351 count = 0; 352 353 nbytes = sizeof(*request) + count * sizeof(struct drm_buf_desc); 354 request = malloc(nbytes, DRM_MEM_BUFLISTS, M_ZERO | M_NOWAIT); 355 if (!request) 356 return -ENOMEM; 357 list = (struct drm_buf_desc *) (request + 1); 358 359 request->count = count; 360 request->list = list; 361 362 err = drm_infobufs(dev, (void *)request, file_priv); 363 if (err) 364 return err; 365 366 actual = request->count; 367 if (count >= actual) 368 for (i = 0; i < actual; ++i) { 369 to[i].count = list[i].count; 370 to[i].size = list[i].size; 371 to[i].low_mark = list[i].low_mark; 372 to[i].high_mark = list[i].high_mark; 373 to[i].flags = list[i].flags; 374 } 375 376 req32->count = actual; 377 378 return 0; 379 } 380 381 typedef struct drm_buf_pub32 { 382 int idx; /**< Index into the master buffer list */ 383 int total; /**< Buffer size */ 384 int used; /**< Amount of buffer in use (for DMA) */ 385 u32 address; /**< Address of buffer */ 386 } drm_buf_pub32_t; 387 388 typedef struct drm_buf_map32 { 389 int count; /**< Length of the buffer list */ 390 u32 virtual; /**< Mmap'd area in user-virtual */ 391 u32 list; /**< Buffer information */ 392 } drm_buf_map32_t; 393 394 static int compat_drm_mapbufs(struct drm_device *dev, void *data, 395 struct drm_file *file_priv) 396 { 397 drm_buf_map32_t *req32 = data; 398 drm_buf_pub32_t *list32; 399 struct drm_buf_map *request; 400 struct drm_buf_pub *list; 401 int i, err; 402 int count, actual; 403 size_t nbytes; 404 405 count = req32->count; 406 list32 = (void *)(unsigned long)req32->list; 407 408 if (count < 0) 409 return -EINVAL; 410 nbytes = sizeof(*request) + count * sizeof(struct drm_buf_pub); 411 request = malloc(nbytes, DRM_MEM_BUFLISTS, M_ZERO | M_NOWAIT); 412 if (!request) 413 return -ENOMEM; 414 list = (struct drm_buf_pub *) (request + 1); 415 416 request->count = count; 417 request->list = list; 418 419 err = drm_mapbufs(dev, (void *)request, file_priv); 420 if (err) 421 return err; 422 423 actual = request->count; 424 if (count >= actual) 425 for (i = 0; i < actual; ++i) { 426 list32[i].idx = list[i].idx; 427 list32[i].total = list[i].total; 428 list32[i].used = list[i].used; 429 list32[i].address = (unsigned long)list[i].address; 430 } 431 432 req32->count = actual; 433 req32->virtual = (unsigned long)request->virtual; 434 435 return 0; 436 } 437 438 typedef struct drm_buf_free32 { 439 int count; 440 u32 list; 441 } drm_buf_free32_t; 442 443 static int compat_drm_freebufs(struct drm_device *dev, void *data, 444 struct drm_file *file_priv) 445 { 446 drm_buf_free32_t *req32 = data; 447 struct drm_buf_free request; 448 449 request.count = req32->count; 450 request.list = (int *)(unsigned long)req32->list; 451 452 return drm_freebufs(dev, (void *)&request, file_priv); 453 } 454 455 typedef struct drm_ctx_priv_map32 { 456 unsigned int ctx_id; /**< Context requesting private mapping */ 457 u32 handle; /**< Handle of map */ 458 } drm_ctx_priv_map32_t; 459 460 static int compat_drm_setsareactx(struct drm_device *dev, void *data, 461 struct drm_file *file_priv) 462 { 463 drm_ctx_priv_map32_t *req32 = data; 464 struct drm_ctx_priv_map request; 465 466 request.ctx_id = req32->ctx_id; 467 request.handle = (void *)(unsigned long)req32->handle; 468 469 return drm_setsareactx(dev, (void *)&request, file_priv); 470 } 471 472 static int compat_drm_getsareactx(struct drm_device *dev, void *data, 473 struct drm_file *file_priv) 474 { 475 drm_ctx_priv_map32_t *req32 = data; 476 struct drm_ctx_priv_map request; 477 int err; 478 479 request.ctx_id = req32->ctx_id; 480 481 err = drm_getsareactx(dev, (void *)&request, file_priv); 482 if (err) 483 return err; 484 485 req32->handle = (unsigned long)request.handle; 486 487 return 0; 488 } 489 490 typedef struct drm_ctx_res32 { 491 int count; 492 u32 contexts; 493 } drm_ctx_res32_t; 494 495 static int compat_drm_resctx(struct drm_device *dev, void *data, 496 struct drm_file *file_priv) 497 { 498 drm_ctx_res32_t *res32 = data; 499 struct drm_ctx_res res; 500 int err; 501 502 res.count = res32->count; 503 res.contexts = (struct drm_ctx __user *)(unsigned long)res32->contexts; 504 505 err = drm_resctx(dev, (void *)&res, file_priv); 506 if (err) 507 return err; 508 509 res32->count = res.count; 510 511 return 0; 512 } 513 514 typedef struct drm_dma32 { 515 int context; /**< Context handle */ 516 int send_count; /**< Number of buffers to send */ 517 u32 send_indices; /**< List of handles to buffers */ 518 u32 send_sizes; /**< Lengths of data to send */ 519 enum drm_dma_flags flags; /**< Flags */ 520 int request_count; /**< Number of buffers requested */ 521 int request_size; /**< Desired size for buffers */ 522 u32 request_indices; /**< Buffer information */ 523 u32 request_sizes; 524 int granted_count; /**< Number of buffers granted */ 525 } drm_dma32_t; 526 527 static int compat_drm_dma(struct drm_device *dev, void *data, 528 struct drm_file *file_priv) 529 { 530 drm_dma32_t *d32 = data; 531 struct drm_dma d; 532 int err; 533 534 if (!dev->driver->dma_ioctl) { 535 DRM_DEBUG("DMA ioctl on driver with no dma handler\n"); 536 return -EINVAL; 537 } 538 539 d.context = d32->context; 540 d.send_count = d32->send_count; 541 d.send_indices = (int *)(unsigned long)d32->send_indices; 542 d.send_sizes = (int *)(unsigned long)d32->send_sizes; 543 d.flags = d32->flags; 544 d.request_count = d32->request_count; 545 d.request_indices = (int *)(unsigned long)d32->request_indices; 546 d.request_sizes = (int *)(unsigned long)d32->request_sizes; 547 548 err = dev->driver->dma_ioctl(dev, (void *)&d, file_priv); 549 if (err) 550 return err; 551 552 d32->request_size = d.request_size; 553 d32->granted_count = d.granted_count; 554 555 return 0; 556 } 557 558 #if __OS_HAS_AGP 559 typedef struct drm_agp_mode32 { 560 u32 mode; /**< AGP mode */ 561 } drm_agp_mode32_t; 562 563 static int compat_drm_agp_enable(struct drm_device *dev, void *data, 564 struct drm_file *file_priv) 565 { 566 drm_agp_mode32_t *m32 = data; 567 struct drm_agp_mode mode; 568 569 mode.mode = m32->mode; 570 571 return drm_agp_enable_ioctl(dev, (void *)&mode, file_priv); 572 } 573 574 typedef struct drm_agp_info32 { 575 int agp_version_major; 576 int agp_version_minor; 577 u32 mode; 578 u32 aperture_base; /* physical address */ 579 u32 aperture_size; /* bytes */ 580 u32 memory_allowed; /* bytes */ 581 u32 memory_used; 582 583 /* PCI information */ 584 unsigned short id_vendor; 585 unsigned short id_device; 586 } drm_agp_info32_t; 587 588 static int compat_drm_agp_info(struct drm_device *dev, void *data, 589 struct drm_file *file_priv) 590 { 591 drm_agp_info32_t *i32 = data; 592 struct drm_agp_info info; 593 int err; 594 595 err = drm_agp_info_ioctl(dev, (void *)&info, file_priv); 596 if (err) 597 return err; 598 599 i32->agp_version_major = info.agp_version_major; 600 i32->agp_version_minor = info.agp_version_minor; 601 i32->mode = info.mode; 602 i32->aperture_base = info.aperture_base; 603 i32->aperture_size = info.aperture_size; 604 i32->memory_allowed = info.memory_allowed; 605 i32->memory_used = info.memory_used; 606 i32->id_vendor = info.id_vendor; 607 i32->id_device = info.id_device; 608 609 return 0; 610 } 611 612 typedef struct drm_agp_buffer32 { 613 u32 size; /**< In bytes -- will round to page boundary */ 614 u32 handle; /**< Used for binding / unbinding */ 615 u32 type; /**< Type of memory to allocate */ 616 u32 physical; /**< Physical used by i810 */ 617 } drm_agp_buffer32_t; 618 619 static int compat_drm_agp_alloc(struct drm_device *dev, void *data, 620 struct drm_file *file_priv) 621 { 622 drm_agp_buffer32_t *req32 = data; 623 struct drm_agp_buffer request; 624 int err; 625 626 request.size = req32->size; 627 request.type = req32->type; 628 629 err = drm_agp_alloc_ioctl(dev, (void *)&request, file_priv); 630 if (err) 631 return err; 632 633 req32->handle = request.handle; 634 req32->physical = request.physical; 635 636 return 0; 637 } 638 639 static int compat_drm_agp_free(struct drm_device *dev, void *data, 640 struct drm_file *file_priv) 641 { 642 drm_agp_buffer32_t *req32 = data; 643 struct drm_agp_buffer request; 644 645 request.handle = req32->handle; 646 647 return drm_agp_free_ioctl(dev, (void *)&request, file_priv); 648 } 649 650 typedef struct drm_agp_binding32 { 651 u32 handle; /**< From drm_agp_buffer */ 652 u32 offset; /**< In bytes -- will round to page boundary */ 653 } drm_agp_binding32_t; 654 655 static int compat_drm_agp_bind(struct drm_device *dev, void *data, 656 struct drm_file *file_priv) 657 { 658 drm_agp_binding32_t *req32 = data; 659 struct drm_agp_binding request; 660 661 request.handle = req32->handle; 662 request.offset = req32->offset; 663 664 return drm_agp_bind_ioctl(dev, (void *)&request, file_priv); 665 } 666 667 static int compat_drm_agp_unbind(struct drm_device *dev, void *data, 668 struct drm_file *file_priv) 669 { 670 drm_agp_binding32_t *req32 = data; 671 struct drm_agp_binding request; 672 673 request.handle = req32->handle; 674 675 return drm_agp_unbind_ioctl(dev, (void *)&request, file_priv); 676 } 677 #endif /* __OS_HAS_AGP */ 678 679 typedef struct drm_scatter_gather32 { 680 u32 size; /**< In bytes -- will round to page boundary */ 681 u32 handle; /**< Used for mapping / unmapping */ 682 } drm_scatter_gather32_t; 683 684 static int compat_drm_sg_alloc(struct drm_device *dev, void *data, 685 struct drm_file *file_priv) 686 { 687 drm_scatter_gather32_t *req32 = data; 688 struct drm_scatter_gather request; 689 int err; 690 691 request.size = (unsigned long)req32->size; 692 693 err = drm_sg_alloc_ioctl(dev, (void *)&request, file_priv); 694 if (err) 695 return err; 696 697 /* XXX not sure about the handle conversion here... */ 698 req32->handle = (unsigned long)request.handle >> PAGE_SHIFT; 699 700 return 0; 701 } 702 703 static int compat_drm_sg_free(struct drm_device *dev, void *data, 704 struct drm_file *file_priv) 705 { 706 drm_scatter_gather32_t *req32 = data; 707 struct drm_scatter_gather request; 708 709 request.handle = (unsigned long)req32->handle << PAGE_SHIFT; 710 711 return drm_sg_free(dev, (void *)&request, file_priv); 712 } 713 714 #if defined(CONFIG_X86) || defined(CONFIG_IA64) 715 typedef struct drm_update_draw32 { 716 drm_drawable_t handle; 717 unsigned int type; 718 unsigned int num; 719 /* 64-bit version has a 32-bit pad here */ 720 u64 data; /**< Pointer */ 721 } __attribute__((packed)) drm_update_draw32_t; 722 #endif 723 724 struct drm_wait_vblank_request32 { 725 enum drm_vblank_seq_type type; 726 unsigned int sequence; 727 u32 signal; 728 }; 729 730 struct drm_wait_vblank_reply32 { 731 enum drm_vblank_seq_type type; 732 unsigned int sequence; 733 s32 tval_sec; 734 s32 tval_usec; 735 }; 736 737 typedef union drm_wait_vblank32 { 738 struct drm_wait_vblank_request32 request; 739 struct drm_wait_vblank_reply32 reply; 740 } drm_wait_vblank32_t; 741 742 static int compat_drm_wait_vblank(struct drm_device *dev, void *data, 743 struct drm_file *file_priv) 744 { 745 drm_wait_vblank32_t *req32 = data; 746 union drm_wait_vblank request; 747 int err; 748 749 request.request.type = req32->request.type; 750 request.request.sequence = req32->request.sequence; 751 request.request.signal = req32->request.signal; 752 753 err = drm_wait_vblank(dev, (void *)&request, file_priv); 754 if (err) 755 return err; 756 757 req32->reply.type = request.reply.type; 758 req32->reply.sequence = request.reply.sequence; 759 req32->reply.tval_sec = request.reply.tval_sec; 760 req32->reply.tval_usec = request.reply.tval_usec; 761 762 return 0; 763 } 764 765 struct drm_ioctl_desc drm_compat_ioctls[256] = { 766 DRM_IOCTL_DEF(DRM_IOCTL_VERSION32, compat_drm_version, DRM_UNLOCKED), 767 DRM_IOCTL_DEF(DRM_IOCTL_GET_UNIQUE32, compat_drm_getunique, 0), 768 DRM_IOCTL_DEF(DRM_IOCTL_GET_MAP32, compat_drm_getmap, DRM_UNLOCKED), 769 DRM_IOCTL_DEF(DRM_IOCTL_GET_CLIENT32, compat_drm_getclient, DRM_UNLOCKED), 770 DRM_IOCTL_DEF(DRM_IOCTL_GET_STATS32, compat_drm_getstats, DRM_UNLOCKED), 771 DRM_IOCTL_DEF(DRM_IOCTL_SET_UNIQUE32, compat_drm_setunique, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), 772 DRM_IOCTL_DEF(DRM_IOCTL_ADD_MAP32, compat_drm_addmap, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), 773 DRM_IOCTL_DEF(DRM_IOCTL_ADD_BUFS32, compat_drm_addbufs, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), 774 DRM_IOCTL_DEF(DRM_IOCTL_MARK_BUFS32, compat_drm_markbufs, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), 775 DRM_IOCTL_DEF(DRM_IOCTL_INFO_BUFS32, compat_drm_infobufs, DRM_AUTH), 776 DRM_IOCTL_DEF(DRM_IOCTL_MAP_BUFS32, compat_drm_mapbufs, DRM_AUTH), 777 DRM_IOCTL_DEF(DRM_IOCTL_FREE_BUFS32, compat_drm_freebufs, DRM_AUTH), 778 DRM_IOCTL_DEF(DRM_IOCTL_RM_MAP32, compat_drm_rmmap, DRM_AUTH), 779 DRM_IOCTL_DEF(DRM_IOCTL_SET_SAREA_CTX32, compat_drm_setsareactx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), 780 DRM_IOCTL_DEF(DRM_IOCTL_GET_SAREA_CTX32, compat_drm_getsareactx, DRM_AUTH), 781 DRM_IOCTL_DEF(DRM_IOCTL_RES_CTX32, compat_drm_resctx, DRM_AUTH), 782 DRM_IOCTL_DEF(DRM_IOCTL_DMA32, compat_drm_dma, DRM_AUTH), 783 #if __OS_HAS_AGP 784 DRM_IOCTL_DEF(DRM_IOCTL_AGP_ENABLE32, compat_drm_agp_enable, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), 785 DRM_IOCTL_DEF(DRM_IOCTL_AGP_INFO32, compat_drm_agp_info, DRM_AUTH), 786 DRM_IOCTL_DEF(DRM_IOCTL_AGP_ALLOC32, compat_drm_agp_alloc, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), 787 DRM_IOCTL_DEF(DRM_IOCTL_AGP_FREE32, compat_drm_agp_free, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), 788 DRM_IOCTL_DEF(DRM_IOCTL_AGP_BIND32, compat_drm_agp_bind, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), 789 DRM_IOCTL_DEF(DRM_IOCTL_AGP_UNBIND32, compat_drm_agp_unbind, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), 790 #endif 791 DRM_IOCTL_DEF(DRM_IOCTL_SG_ALLOC32, compat_drm_sg_alloc, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), 792 DRM_IOCTL_DEF(DRM_IOCTL_SG_FREE32, compat_drm_sg_free, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), 793 #if defined(CONFIG_X86) || defined(CONFIG_IA64) 794 DRM_IOCTL_DEF(DRM_IOCTL_UPDATE_DRAW32, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), 795 #endif 796 DRM_IOCTL_DEF(DRM_IOCTL_WAIT_VBLANK32, compat_drm_wait_vblank, DRM_UNLOCKED), 797 }; 798 799 #endif 800