1 /* drmP.h -- Private header for Direct Rendering Manager -*- linux-c -*- 2 * Created: Mon Jan 4 10:05:05 1999 by faith@precisioninsight.com 3 */ 4 /*- 5 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. 6 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 7 * All rights reserved. 8 * 9 * Permission is hereby granted, free of charge, to any person obtaining a 10 * copy of this software and associated documentation files (the "Software"), 11 * to deal in the Software without restriction, including without limitation 12 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 * and/or sell copies of the Software, and to permit persons to whom the 14 * Software is furnished to do so, subject to the following conditions: 15 * 16 * The above copyright notice and this permission notice (including the next 17 * paragraph) shall be included in all copies or substantial portions of the 18 * Software. 19 * 20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 23 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 24 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 * OTHER DEALINGS IN THE SOFTWARE. 27 * 28 * Authors: 29 * Rickard E. (Rik) Faith <faith@valinux.com> 30 * Gareth Hughes <gareth@valinux.com> 31 * 32 */ 33 34 #ifndef _DRM_P_H_ 35 #define _DRM_P_H_ 36 37 #if defined(_KERNEL) || defined(__KERNEL__) 38 39 struct drm_device; 40 struct drm_file; 41 42 #if defined(__NetBSD__) && defined(_KERNEL_OPT) 43 #include "opt_drm.h" 44 #endif 45 46 #include <sys/param.h> 47 #include <sys/queue.h> 48 #include <sys/malloc.h> 49 #include <sys/kernel.h> 50 #include <sys/module.h> 51 #include <sys/systm.h> 52 #include <sys/conf.h> 53 #include <sys/stat.h> 54 #if __FreeBSD_version >= 700000 55 #include <sys/priv.h> 56 #endif 57 #include <sys/proc.h> 58 #include <sys/lock.h> 59 #include <sys/fcntl.h> 60 #include <sys/uio.h> 61 #include <sys/filio.h> 62 #include <sys/sysctl.h> 63 #include <sys/bus.h> 64 #include <sys/signalvar.h> 65 #include <sys/poll.h> 66 #include <sys/tree.h> 67 #ifdef __FreeBSD__ 68 #include <vm/vm.h> 69 #include <vm/pmap.h> 70 #include <vm/vm_extern.h> 71 #include <vm/vm_map.h> 72 #include <vm/vm_param.h> 73 #include <machine/resource.h> 74 #include <machine/param.h> 75 #endif 76 #include <machine/pmap.h> 77 #include <sys/bus.h> 78 #if defined(__i386__) || defined(__x86_64__) 79 #include <machine/specialreg.h> 80 #include <machine/sysarch.h> 81 #endif 82 #include <sys/endian.h> 83 #include <sys/mman.h> 84 #if defined( __FreeBSD__) 85 #include <sys/rman.h> 86 #include <sys/memrange.h> 87 #if __FreeBSD_version >= 800004 88 #include <dev/agp/agpvar.h> 89 #else /* __FreeBSD_version >= 800004 */ 90 #include <pci/agpvar.h> 91 #endif /* __FreeBSD_version >= 800004 */ 92 #include <sys/agpio.h> 93 #include <sys/mutex.h> 94 #include <dev/pci/pcivar.h> 95 #include <dev/pci/pcireg.h> 96 #include <sys/selinfo.h> 97 #include <sys/bus.h> 98 #elif defined(__NetBSD__) 99 #if defined(__i386__) || defined(__x86_64__) 100 #include <machine/mtrr.h> 101 #endif 102 #include <sys/vnode.h> 103 #include <sys/select.h> 104 #include <sys/device.h> 105 #include <sys/resourcevar.h> 106 #include <sys/agpio.h> 107 #include <sys/ttycom.h> 108 #include <sys/mman.h> 109 #include <sys/kauth.h> 110 #include <sys/types.h> 111 #include <sys/file.h> 112 #include <sys/atomic.h> 113 #include <sys/workqueue.h> 114 #include <uvm/uvm.h> 115 #include <dev/pci/pcireg.h> 116 #include <dev/pci/pcivar.h> 117 #include <dev/pci/agpvar.h> 118 #endif 119 120 #include "drm.h" 121 #include "drm_linux_list.h" 122 #include "drm_atomic.h" 123 #include "drm_internal.h" 124 125 #ifdef __FreeBSD__ 126 #include <opt_drm.h> 127 #endif 128 129 #ifdef DRM_DEBUG 130 #undef DRM_DEBUG 131 #define DRM_DEBUG_DEFAULT_ON 1 132 #endif /* DRM_DEBUG */ 133 134 #ifdef __FreeBSD__ 135 #define DRM_KASSERT(x,y) KASSERT(x,y) 136 #else 137 #define DRM_KASSERT(x,y) KASSERT(x) 138 #define device_get_softc(x) device_private(x) 139 #define callout_deactivate(x) callout_stop(x) 140 #define callout_drain(x) callout_stop(x) 141 #endif 142 143 #if defined(DRM_LINUX) && DRM_LINUX && !defined(__amd64__) 144 #include <sys/file.h> 145 #include <sys/proc.h> 146 #include <machine/../linux/linux.h> 147 #include <machine/../linux/linux_proto.h> 148 #else 149 /* Either it was defined when it shouldn't be (FreeBSD amd64) or it isn't 150 * supported on this OS yet. 151 */ 152 #undef DRM_LINUX 153 #define DRM_LINUX 0 154 #endif 155 156 /* driver capabilities and requirements mask */ 157 #define DRIVER_USE_AGP 0x1 158 #define DRIVER_REQUIRE_AGP 0x2 159 #define DRIVER_USE_MTRR 0x4 160 #define DRIVER_PCI_DMA 0x8 161 #define DRIVER_SG 0x10 162 #define DRIVER_HAVE_DMA 0x20 163 #define DRIVER_HAVE_IRQ 0x40 164 #define DRIVER_DMA_QUEUE 0x100 165 166 167 #define DRM_HASH_SIZE 16 /* Size of key hash table */ 168 #define DRM_KERNEL_CONTEXT 0 /* Change drm_resctx if changed */ 169 #define DRM_RESERVED_CONTEXTS 1 /* Change drm_resctx if changed */ 170 171 MALLOC_DECLARE(DRM_MEM_DMA); 172 MALLOC_DECLARE(DRM_MEM_SAREA); 173 MALLOC_DECLARE(DRM_MEM_DRIVER); 174 MALLOC_DECLARE(DRM_MEM_MAGIC); 175 MALLOC_DECLARE(DRM_MEM_IOCTLS); 176 MALLOC_DECLARE(DRM_MEM_MAPS); 177 MALLOC_DECLARE(DRM_MEM_BUFS); 178 MALLOC_DECLARE(DRM_MEM_SEGS); 179 MALLOC_DECLARE(DRM_MEM_PAGES); 180 MALLOC_DECLARE(DRM_MEM_FILES); 181 MALLOC_DECLARE(DRM_MEM_QUEUES); 182 MALLOC_DECLARE(DRM_MEM_CMDS); 183 MALLOC_DECLARE(DRM_MEM_MAPPINGS); 184 MALLOC_DECLARE(DRM_MEM_BUFLISTS); 185 MALLOC_DECLARE(DRM_MEM_AGPLISTS); 186 MALLOC_DECLARE(DRM_MEM_CTXBITMAP); 187 MALLOC_DECLARE(DRM_MEM_SGLISTS); 188 MALLOC_DECLARE(DRM_MEM_DRAWABLE); 189 MALLOC_DECLARE(DRM_MEM_MM); 190 191 #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8) 192 193 /* Internal types and structures */ 194 #define DRM_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) 195 #define DRM_MIN(a,b) ((a)<(b)?(a):(b)) 196 #define DRM_MAX(a,b) ((a)>(b)?(a):(b)) 197 198 #define DRM_IF_VERSION(maj, min) (maj << 16 | min) 199 200 #define __OS_HAS_AGP 1 201 202 #define DRM_DEV_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) 203 #define DRM_DEV_UID 0 204 #define DRM_DEV_GID 0 205 206 #define wait_queue_head_t atomic_t 207 #define DRM_WAKEUP(w) wakeup((void *)w) 208 #define DRM_WAKEUP_INT(w) wakeup(w) 209 #define DRM_INIT_WAITQUEUE(queue) do {(void)(queue);} while (0) 210 211 #if defined(__FreeBSD__) 212 #define DRM_CDEV struct cdev * 213 #define DRM_CURPROC curthread 214 #define DRM_STRUCTPROC struct thread 215 #define DRM_STRUCTCDEVPROC struct thread 216 #define DRM_CDEVPROC_REAL(p) (p) 217 #define DRM_IOCTL_DATA caddr_t 218 #define DRM_SPINTYPE struct mtx 219 #define DRM_SPININIT(l,name) mtx_init(l, name, NULL, MTX_DEF) 220 #define DRM_SPINUNINIT(l) mtx_destroy(l) 221 #define DRM_SPINLOCK(l) mtx_lock(l) 222 #define DRM_SPINUNLOCK(u) mtx_unlock(u) 223 #define DRM_SPINLOCK_IRQSAVE(l, irqflags) do { \ 224 mtx_lock(l); \ 225 (void)irqflags; \ 226 } while (0) 227 #define DRM_SPINUNLOCK_IRQRESTORE(u, irqflags) mtx_unlock(u) 228 #define DRM_SPINLOCK_ASSERT(l) mtx_assert(l, MA_OWNED) 229 #define DRM_CURRENTPID curthread->td_proc->p_pid 230 #define DRM_LOCK() mtx_lock(&dev->dev_lock) 231 #define DRM_UNLOCK() mtx_unlock(&dev->dev_lock) 232 #define DRM_SYSCTL_HANDLER_ARGS (SYSCTL_HANDLER_ARGS) 233 #elif defined(__NetBSD__) 234 #define DRM_CDEV dev_t 235 #define DRM_CURPROC curproc 236 #define DRM_STRUCTPROC struct proc 237 #define DRM_STRUCTCDEVPROC struct lwp 238 #define DRM_CDEVPROC_REAL(l) (l)->l_proc 239 #define DRM_IOCTL_DATA void * 240 #define DRM_SPINTYPE kmutex_t 241 #define DRM_SPININIT(l,name) mutex_init(l, MUTEX_DEFAULT, /*IPL_NONE*/ IPL_VM) 242 #define DRM_SPINUNINIT(l) mutex_destroy(l) 243 #define DRM_SPINLOCK(l) mutex_enter(l) 244 #define DRM_SPINUNLOCK(u) mutex_exit(u) 245 #define DRM_SPINLOCK_IRQSAVE(l, irqflags) do { \ 246 mutex_enter(l); \ 247 (void)irqflags; \ 248 } while (0) 249 #define DRM_SPINUNLOCK_IRQRESTORE(u, irqflags) mutex_exit(u) 250 #define DRM_SPINLOCK_ASSERT(l) mutex_owned(l) 251 #define DRM_CURRENTPID curproc->p_pid 252 #define DRM_LOCK() DRM_SPINLOCK(&dev->dev_lock) 253 #define DRM_UNLOCK() DRM_SPINUNLOCK(&dev->dev_lock) 254 #define DRM_SYSCTL_HANDLER_ARGS (SYSCTLFN_ARGS) 255 #define vslock(addr, len) uvm_vslock(curproc->p_vmspace, addr, len, VM_PROT_READ | VM_PROT_WRITE) 256 #define vsunlock(addr, len) uvm_vsunlock(curproc->p_vmspace, addr, len) 257 #endif 258 259 #define DRM_IRQ_ARGS void *arg 260 #if defined(__FreeBSD__) 261 typedef void irqreturn_t; 262 #define IRQ_HANDLED /* nothing */ 263 #define IRQ_NONE /* nothing */ 264 #elif defined(__NetBSD__) 265 typedef int irqreturn_t; 266 #define IRQ_HANDLED 1 267 #define IRQ_NONE 0 268 #endif 269 270 enum { 271 DRM_IS_NOT_AGP, 272 DRM_IS_AGP, 273 DRM_MIGHT_BE_AGP 274 }; 275 #define DRM_AGP_MEM struct agp_memory_info 276 277 #if defined(__FreeBSD__) 278 #define drm_get_device_from_kdev(_kdev) (_kdev->si_drv1) 279 #elif defined(__NetBSD__) 280 #define drm_get_device_from_kdev(_kdev) ((minor(_kdev) < DRM_MAXUNITS) ? \ 281 drm_units[minor(_kdev)] : NULL) 282 #endif 283 284 #if defined(__FreeBSD__) 285 #define PAGE_ALIGN(addr) round_page(addr) 286 /* DRM_SUSER returns true if the user is superuser */ 287 #if __FreeBSD_version >= 700000 288 #define DRM_SUSER(p) (priv_check(p, PRIV_DRIVER) == 0) 289 #else 290 #define DRM_SUSER(p) (suser(p) == 0) 291 #endif 292 #define DRM_AGP_FIND_DEVICE() agp_find_device() 293 #define DRM_MTRR_WC MDF_WRITECOMBINE 294 #define jiffies ticks 295 296 #elif defined(__NetBSD__) 297 298 #define PAGE_ALIGN(addr) round_page(addr) 299 #define DRM_SUSER(p) (kauth_cred_getsvuid((p)->p_cred) == 0) 300 #define DRM_AGP_FIND_DEVICE() agp_find_device(0) 301 #ifdef MTRR_TYPE_WC 302 #define DRM_MTRR_WC MTRR_TYPE_WC 303 #else 304 #define DRM_MTRR_WC 0 305 #endif 306 #define jiffies hardclock_ticks 307 308 #define DRM_MAXUNITS 128 309 extern struct drm_device *drm_units[]; 310 311 #endif 312 313 /* Capabilities taken from src/sys/dev/pci/pcireg.h. */ 314 #ifndef PCIY_AGP 315 #define PCIY_AGP 0x02 316 #endif 317 318 #ifndef PCIY_EXPRESS 319 #define PCIY_EXPRESS 0x10 320 #endif 321 322 typedef unsigned long dma_addr_t; 323 #if defined(__FreeBSD__) 324 typedef u_int64_t u64; 325 typedef u_int32_t u32; 326 typedef u_int16_t u16; 327 typedef u_int8_t u8; 328 #else 329 typedef uint64_t u64; 330 typedef uint32_t u32; 331 typedef uint16_t u16; 332 typedef uint8_t u8; 333 #endif 334 335 /* DRM_READMEMORYBARRIER() prevents reordering of reads. 336 * DRM_WRITEMEMORYBARRIER() prevents reordering of writes. 337 * DRM_MEMORYBARRIER() prevents reordering of reads and writes. 338 */ 339 #if defined(__NetBSD__) 340 #define DRM_READMEMORYBARRIER() membar_consumer() 341 #define DRM_WRITEMEMORYBARRIER() membar_producer() 342 #define DRM_MEMORYBARRIER() membar_sync() 343 #elif defined(__i386__) 344 #define DRM_READMEMORYBARRIER() __asm __volatile( \ 345 "lock; addl $0,0(%%esp)" : : : "memory"); 346 #define DRM_WRITEMEMORYBARRIER() __asm __volatile("" : : : "memory"); 347 #define DRM_MEMORYBARRIER() __asm __volatile( \ 348 "lock; addl $0,0(%%esp)" : : : "memory"); 349 #elif defined(__alpha__) 350 #define DRM_READMEMORYBARRIER() alpha_mb(); 351 #define DRM_WRITEMEMORYBARRIER() alpha_wmb(); 352 #define DRM_MEMORYBARRIER() alpha_mb(); 353 #elif defined(__amd64__) 354 #define DRM_READMEMORYBARRIER() __asm __volatile( \ 355 "lock; addl $0,0(%%rsp)" : : : "memory"); 356 #define DRM_WRITEMEMORYBARRIER() __asm __volatile("" : : : "memory"); 357 #define DRM_MEMORYBARRIER() __asm __volatile( \ 358 "lock; addl $0,0(%%rsp)" : : : "memory"); 359 #endif 360 361 #define DRM_COPY_TO_USER(user, kern, size) \ 362 copyout(kern, user, size) 363 #define DRM_COPY_FROM_USER(kern, user, size) \ 364 copyin(user, kern, size) 365 #define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) \ 366 copyin(arg2, arg1, arg3) 367 #define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3) \ 368 copyout(arg2, arg1, arg3) 369 #if defined(__FreeBSD__) 370 #define DRM_GET_USER_UNCHECKED(val, uaddr) \ 371 ((val) = fuword32(uaddr), 0) 372 #else 373 #define DRM_GET_USER_UNCHECKED(val, uaddr) \ 374 ((val) = fuword(uaddr), 0) 375 #endif 376 377 #define cpu_to_le32(x) htole32(x) 378 #define le32_to_cpu(x) le32toh(x) 379 380 #define DRM_HZ hz 381 #define DRM_UDELAY(udelay) DELAY(udelay) 382 #define DRM_TIME_SLICE (hz/20) /* Time slice for GLXContexts */ 383 384 #define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \ 385 (_map) = (_dev)->context_sareas[_ctx]; \ 386 } while(0) 387 388 #define LOCK_TEST_WITH_RETURN(dev, file_priv) \ 389 do { \ 390 if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) || \ 391 dev->lock.file_priv != file_priv) { \ 392 DRM_ERROR("%s called without lock held\n", \ 393 __FUNCTION__); \ 394 return EINVAL; \ 395 } \ 396 } while (0) 397 398 /* Returns -errno to shared code */ 399 #if defined(__FreeBSD__) 400 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \ 401 for ( ret = 0 ; !ret && !(condition) ; ) { \ 402 DRM_UNLOCK(); \ 403 mtx_lock(&dev->irq_lock); \ 404 if (!(condition)) \ 405 ret = -mtx_sleep(&(queue), &dev->irq_lock, \ 406 PCATCH, "drmwtq", (timeout)); \ 407 mtx_unlock(&dev->irq_lock); \ 408 DRM_LOCK(); \ 409 } 410 #elif defined(__NetBSD__) 411 /* Returns -errno to shared code */ 412 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \ 413 for ( ret = 0 ; !ret && !(condition) ; ) { \ 414 DRM_UNLOCK(); \ 415 mutex_enter(&dev->irq_lock); \ 416 if (!(condition)) \ 417 ret = -mtsleep(&(queue), PCATCH, \ 418 "drmwtq", (timeout), &dev->irq_lock); \ 419 mutex_exit(&dev->irq_lock); \ 420 DRM_LOCK(); \ 421 } 422 #endif 423 424 #define DRM_ERROR(fmt, ...) \ 425 printf("error: [" DRM_NAME ":pid%d:%s] *ERROR* " fmt, \ 426 DRM_CURRENTPID, __func__ , ##__VA_ARGS__) 427 428 #define DRM_INFO(fmt, ...) printf("info: [" DRM_NAME "] " fmt , ##__VA_ARGS__) 429 430 #define DRM_DEBUG(fmt, ...) do { \ 431 if (drm_debug_flag) \ 432 printf("[" DRM_NAME ":pid%d:%s] " fmt, DRM_CURRENTPID, \ 433 __func__ , ##__VA_ARGS__); \ 434 } while (0) 435 436 typedef struct drm_pci_id_list 437 { 438 int vendor; 439 int device; 440 long driver_private; 441 #if defined(__NetBSD__) 442 const char *name; 443 #else 444 char *name; 445 #endif 446 } drm_pci_id_list_t; 447 448 struct drm_msi_blacklist_entry 449 { 450 int vendor; 451 int device; 452 }; 453 454 #define DRM_AUTH 0x1 455 #define DRM_MASTER 0x2 456 #define DRM_ROOT_ONLY 0x4 457 typedef struct drm_ioctl_desc { 458 unsigned long cmd; 459 int (*func)(struct drm_device *dev, void *data, 460 struct drm_file *file_priv); 461 int flags; 462 } drm_ioctl_desc_t; 463 /** 464 * Creates a driver or general drm_ioctl_desc array entry for the given 465 * ioctl, for use by drm_ioctl(). 466 */ 467 #define DRM_IOCTL_DEF(ioctl, func, flags) \ 468 [DRM_IOCTL_NR(ioctl)] = {ioctl, func, flags} 469 470 typedef struct drm_magic_entry { 471 drm_magic_t magic; 472 struct drm_file *priv; 473 struct drm_magic_entry *next; 474 } drm_magic_entry_t; 475 476 typedef struct drm_magic_head { 477 struct drm_magic_entry *head; 478 struct drm_magic_entry *tail; 479 } drm_magic_head_t; 480 481 typedef struct drm_buf { 482 int idx; /* Index into master buflist */ 483 int total; /* Buffer size */ 484 int order; /* log-base-2(total) */ 485 int used; /* Amount of buffer in use (for DMA) */ 486 unsigned long offset; /* Byte offset (used internally) */ 487 void *address; /* Address of buffer */ 488 unsigned long bus_address; /* Bus address of buffer */ 489 struct drm_buf *next; /* Kernel-only: used for free list */ 490 __volatile__ int pending; /* On hardware DMA queue */ 491 struct drm_file *file_priv; /* Unique identifier of holding process */ 492 int context; /* Kernel queue for this buffer */ 493 enum { 494 DRM_LIST_NONE = 0, 495 DRM_LIST_FREE = 1, 496 DRM_LIST_WAIT = 2, 497 DRM_LIST_PEND = 3, 498 DRM_LIST_PRIO = 4, 499 DRM_LIST_RECLAIM = 5 500 } list; /* Which list we're on */ 501 502 int dev_priv_size; /* Size of buffer private stoarge */ 503 void *dev_private; /* Per-buffer private storage */ 504 } drm_buf_t; 505 506 typedef struct drm_freelist { 507 int initialized; /* Freelist in use */ 508 atomic_t count; /* Number of free buffers */ 509 drm_buf_t *next; /* End pointer */ 510 511 int low_mark; /* Low water mark */ 512 int high_mark; /* High water mark */ 513 } drm_freelist_t; 514 515 typedef struct drm_dma_handle { 516 void *vaddr; 517 bus_addr_t busaddr; 518 bus_dma_tag_t tag; 519 bus_dmamap_t map; 520 #if defined(__NetBSD__) 521 size_t size; 522 size_t nsegs; 523 bus_dma_segment_t segs[1]; 524 #endif 525 } drm_dma_handle_t; 526 527 typedef struct drm_buf_entry { 528 int buf_size; 529 int buf_count; 530 drm_buf_t *buflist; 531 int seg_count; 532 drm_dma_handle_t **seglist; 533 int page_order; 534 535 drm_freelist_t freelist; 536 } drm_buf_entry_t; 537 538 typedef TAILQ_HEAD(drm_file_list, drm_file) drm_file_list_t; 539 struct drm_file { 540 TAILQ_ENTRY(drm_file) link; 541 struct drm_device *dev; 542 int authenticated; 543 int master; 544 int minor; 545 pid_t pid; 546 uid_t uid; 547 drm_magic_t magic; 548 unsigned long ioctl_count; 549 void *driver_priv; 550 }; 551 552 typedef struct drm_lock_data { 553 struct drm_hw_lock *hw_lock; /* Hardware lock */ 554 struct drm_file *file_priv; /* Unique identifier of holding process (NULL is kernel)*/ 555 int lock_queue; /* Queue of blocked processes */ 556 unsigned long lock_time; /* Time of last lock in jiffies */ 557 } drm_lock_data_t; 558 559 /* This structure, in the struct drm_device, is always initialized while the 560 * device 561 * is open. dev->dma_lock protects the incrementing of dev->buf_use, which 562 * when set marks that no further bufs may be allocated until device teardown 563 * occurs (when the last open of the device has closed). The high/low 564 * watermarks of bufs are only touched by the X Server, and thus not 565 * concurrently accessed, so no locking is needed. 566 */ 567 typedef struct drm_device_dma { 568 drm_buf_entry_t bufs[DRM_MAX_ORDER+1]; 569 int buf_count; 570 drm_buf_t **buflist; /* Vector of pointers info bufs */ 571 int seg_count; 572 int page_count; 573 unsigned long *pagelist; 574 unsigned long byte_count; 575 enum { 576 _DRM_DMA_USE_AGP = 0x01, 577 _DRM_DMA_USE_SG = 0x02 578 } flags; 579 } drm_device_dma_t; 580 581 typedef struct drm_agp_mem { 582 void *handle; 583 unsigned long bound; /* address */ 584 int pages; 585 struct drm_agp_mem *prev; 586 struct drm_agp_mem *next; 587 } drm_agp_mem_t; 588 589 typedef struct drm_agp_head { 590 device_t agpdev; 591 struct agp_info info; 592 const char *chipset; 593 drm_agp_mem_t *memory; 594 unsigned long mode; 595 int enabled; 596 int acquired; 597 unsigned long base; 598 int mtrr; 599 int cant_use_aperture; 600 unsigned long page_mask; 601 } drm_agp_head_t; 602 603 typedef struct drm_sg_mem { 604 unsigned long handle; 605 void *virtual; 606 int pages; 607 dma_addr_t *busaddr; 608 struct drm_dma_handle *sg_dmah; /* Handle for sg_pages */ 609 struct drm_dma_handle *dmah; /* Handle to PCI memory */ 610 /* for ATI PCIGART table */ 611 } drm_sg_mem_t; 612 613 typedef TAILQ_HEAD(drm_map_list, drm_local_map) drm_map_list_t; 614 615 #if defined(__NetBSD__) 616 typedef struct { 617 int mapped; 618 int maptype; 619 bus_addr_t base; 620 bus_size_t size; 621 bus_space_handle_t bsh; 622 int flags; 623 void * vaddr; 624 } pci_map_data_t; 625 626 /* XXX */ 627 #define readl(va) (*(volatile u_int32_t *) (va)) 628 #endif 629 630 typedef struct drm_local_map { 631 unsigned long offset; /* Physical address (0 for SAREA)*/ 632 unsigned long size; /* Physical size (bytes) */ 633 enum drm_map_type type; /* Type of memory mapped */ 634 enum drm_map_flags flags; /* Flags */ 635 void *handle; /* User-space: "Handle" to pass to mmap */ 636 /* Kernel-space: kernel-virtual address */ 637 int mtrr; /* Boolean: MTRR used */ 638 /* Private data */ 639 int rid; /* PCI resource ID for bus_space */ 640 #if defined(__FreeBSD__) 641 struct resource *bsr; 642 #endif 643 bus_space_tag_t bst; 644 bus_space_handle_t bsh; 645 drm_dma_handle_t *dmah; 646 #if defined(__NetBSD__) 647 pci_map_data_t *fullmap; 648 bus_size_t mapsize; 649 #endif 650 TAILQ_ENTRY(drm_local_map) link; 651 } drm_local_map_t; 652 653 TAILQ_HEAD(drm_vbl_sig_list, drm_vbl_sig); 654 typedef struct drm_vbl_sig { 655 TAILQ_ENTRY(drm_vbl_sig) link; 656 unsigned int sequence; 657 int signo; 658 int pid; 659 } drm_vbl_sig_t; 660 661 struct drm_vblank_info { 662 wait_queue_head_t queue; /* vblank wait queue */ 663 atomic_t count; /* number of VBLANK interrupts */ 664 /* (driver must alloc the right number of counters) */ 665 struct drm_vbl_sig_list sigs; /* signal list to send on VBLANK */ 666 atomic_t refcount; /* number of users of vblank interrupts */ 667 u32 last; /* protected by dev->vbl_lock, used */ 668 /* for wraparound handling */ 669 int enabled; /* so we don't call enable more than */ 670 /* once per disable */ 671 int inmodeset; /* Display driver is setting mode */ 672 }; 673 674 /* location of GART table */ 675 #define DRM_ATI_GART_MAIN 1 676 #define DRM_ATI_GART_FB 2 677 678 #define DRM_ATI_GART_PCI 1 679 #define DRM_ATI_GART_PCIE 2 680 #define DRM_ATI_GART_IGP 3 681 682 struct drm_ati_pcigart_info { 683 int gart_table_location; 684 int gart_reg_if; 685 void *addr; 686 dma_addr_t bus_addr; 687 dma_addr_t table_mask; 688 dma_addr_t member_mask; 689 struct drm_dma_handle *table_handle; 690 drm_local_map_t mapping; 691 int table_size; 692 }; 693 694 #ifndef DMA_BIT_MASK 695 #define DMA_BIT_MASK(n) ((dma_addr_t)(((n) == 64) ? ~0ULL : (1ULL<<(n)) - 1)) 696 #endif 697 698 #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16)) 699 700 struct drm_driver_info { 701 int (*load)(struct drm_device *, unsigned long flags); 702 int (*firstopen)(struct drm_device *); 703 int (*open)(struct drm_device *, struct drm_file *); 704 void (*preclose)(struct drm_device *, struct drm_file *file_priv); 705 void (*postclose)(struct drm_device *, struct drm_file *); 706 void (*lastclose)(struct drm_device *); 707 int (*unload)(struct drm_device *); 708 void (*reclaim_buffers_locked)(struct drm_device *, 709 struct drm_file *file_priv); 710 int (*dma_ioctl)(struct drm_device *dev, void *data, 711 struct drm_file *file_priv); 712 void (*dma_ready)(struct drm_device *); 713 int (*dma_quiescent)(struct drm_device *); 714 int (*dma_flush_block_and_flush)(struct drm_device *, int context, 715 enum drm_lock_flags flags); 716 int (*dma_flush_unblock)(struct drm_device *, int context, 717 enum drm_lock_flags flags); 718 int (*context_ctor)(struct drm_device *dev, int context); 719 int (*context_dtor)(struct drm_device *dev, int context); 720 int (*kernel_context_switch)(struct drm_device *dev, int old, 721 int new); 722 int (*kernel_context_switch_unlock)(struct drm_device *dev); 723 void (*irq_preinstall)(struct drm_device *dev); 724 int (*irq_postinstall)(struct drm_device *dev); 725 void (*irq_uninstall)(struct drm_device *dev); 726 irqreturn_t (*irq_handler)(DRM_IRQ_ARGS); 727 u32 (*get_vblank_counter)(struct drm_device *dev, unsigned int crtc); 728 int (*enable_vblank)(struct drm_device *dev, unsigned int crtc); 729 void (*disable_vblank)(struct drm_device *dev, unsigned int crtc); 730 731 drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */ 732 733 /** 734 * Called by \c drm_device_is_agp. Typically used to determine if a 735 * card is really attached to AGP or not. 736 * 737 * \param dev DRM device handle 738 * 739 * \returns 740 * One of three values is returned depending on whether or not the 741 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP 742 * (return of 1), or may or may not be AGP (return of 2). 743 */ 744 int (*device_is_agp) (struct drm_device * dev); 745 746 drm_ioctl_desc_t *ioctls; 747 int max_ioctl; 748 749 int buf_priv_size; 750 751 int major; 752 int minor; 753 int patchlevel; 754 const char *name; /* Simple driver name */ 755 const char *desc; /* Longer driver name */ 756 const char *date; /* Date of last major changes. */ 757 758 u32 driver_features; 759 }; 760 761 /* Length for the array of resource pointers for drm_get_resource_*. */ 762 #define DRM_MAX_PCI_RESOURCE 6 763 764 /** 765 * DRM device functions structure 766 */ 767 struct drm_device { 768 struct drm_driver_info *driver; 769 drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */ 770 771 u_int16_t pci_device; /* PCI device id */ 772 u_int16_t pci_vendor; /* PCI vendor id */ 773 774 char *unique; /* Unique identifier: e.g., busid */ 775 int unique_len; /* Length of unique field */ 776 device_t device; /* Device instance from newbus */ 777 #if defined(__FreeBSD__) 778 struct cdev *devnode; /* Device number for mknod */ 779 #endif 780 int if_version; /* Highest interface version set */ 781 782 int flags; /* Flags to open(2) */ 783 784 /* Locks */ 785 DRM_SPINTYPE vbl_lock; /* protects vblank operations */ 786 DRM_SPINTYPE dma_lock; /* protects dev->dma */ 787 DRM_SPINTYPE irq_lock; /* protects irq condition checks */ 788 DRM_SPINTYPE dev_lock; /* protects everything else */ 789 DRM_SPINTYPE drw_lock; 790 791 /* Usage Counters */ 792 int open_count; /* Outstanding files open */ 793 int buf_use; /* Buffers in use -- cannot alloc */ 794 795 /* Performance counters */ 796 unsigned long counters; 797 enum drm_stat_type types[15]; 798 atomic_t counts[15]; 799 800 /* Authentication */ 801 drm_file_list_t files; 802 drm_magic_head_t magiclist[DRM_HASH_SIZE]; 803 804 /* Linked list of mappable regions. Protected by dev_lock */ 805 drm_map_list_t maplist; 806 807 drm_local_map_t **context_sareas; 808 int max_context; 809 810 drm_lock_data_t lock; /* Information on hardware lock */ 811 812 /* DMA queues (contexts) */ 813 drm_device_dma_t *dma; /* Optional pointer for DMA support */ 814 815 /* Context support */ 816 int irq; /* Interrupt used by board */ 817 int irq_enabled; /* True if the irq handler is enabled */ 818 int msi_enabled; /* MSI enabled */ 819 #if defined(__FreeBSD__) 820 int irqrid; /* Interrupt used by board */ 821 struct resource *irqr; /* Resource for interrupt used by board */ 822 823 /* Storage of resource pointers for drm_get_resource_* */ 824 struct resource *pcir[DRM_MAX_PCI_RESOURCE]; 825 int pcirid[DRM_MAX_PCI_RESOURCE]; 826 #elif defined(__NetBSD__) 827 struct pci_attach_args pa; 828 pci_map_data_t pci_map_data[DRM_MAX_PCI_RESOURCE]; 829 pci_map_data_t agp_map_data[DRM_MAX_PCI_RESOURCE]; 830 dev_t kdev; 831 #endif 832 void *irqh; /* Handle from bus_setup_intr */ 833 834 int pci_domain; 835 int pci_bus; 836 int pci_slot; 837 int pci_func; 838 839 atomic_t context_flag; /* Context swapping flag */ 840 int last_context; /* Last current context */ 841 842 int vblank_disable_allowed; 843 atomic_t vbl_signal_pending; /* number of signals pending on all crtcs */ 844 struct callout vblank_disable_timer; 845 u32 max_vblank_count; /* size of vblank counter register */ 846 struct drm_vblank_info *vblank; /* per crtc vblank info */ 847 int num_crtcs; 848 849 #if defined(__FreeBSD__) 850 struct sigio *buf_sigio; /* Processes waiting for SIGIO */ 851 #elif defined(__NetBSD__) 852 pid_t buf_pgid; 853 #endif 854 855 /* Sysctl support */ 856 struct drm_sysctl_info *sysctl; 857 858 drm_agp_head_t *agp; 859 drm_sg_mem_t *sg; /* Scatter gather memory */ 860 atomic_t *ctx_bitmap; 861 void *dev_private; 862 unsigned int agp_buffer_token; 863 drm_local_map_t *agp_buffer_map; 864 865 #if defined(__FreeBSD__) 866 struct unrhdr *drw_unrhdr; 867 #elif defined(__NetBSD__) 868 int drw_no; 869 #endif 870 /* RB tree of drawable infos */ 871 RB_HEAD(drawable_tree, bsd_drm_drawable_info) drw_head; 872 }; 873 874 static __inline__ int drm_core_check_feature(struct drm_device *dev, 875 int feature) 876 { 877 return ((dev->driver->driver_features & feature) ? 1 : 0); 878 } 879 880 #if __OS_HAS_AGP 881 static inline int drm_core_has_AGP(struct drm_device *dev) 882 { 883 return drm_core_check_feature(dev, DRIVER_USE_AGP); 884 } 885 #else 886 #define drm_core_has_AGP(dev) (0) 887 #endif 888 889 #if defined(__FreeBSD__) 890 891 #define DRM_READ8(map, offset) \ 892 *(volatile u_int8_t *)(((vm_offset_t)(map)->handle) + \ 893 (vm_offset_t)(offset)) 894 #define DRM_READ16(map, offset) \ 895 *(volatile u_int16_t *)(((vm_offset_t)(map)->handle) + \ 896 (vm_offset_t)(offset)) 897 #define DRM_READ32(map, offset) \ 898 *(volatile u_int32_t *)(((vm_offset_t)(map)->handle) + \ 899 (vm_offset_t)(offset)) 900 #define DRM_WRITE8(map, offset, val) \ 901 *(volatile u_int8_t *)(((vm_offset_t)(map)->handle) + \ 902 (vm_offset_t)(offset)) = val 903 #define DRM_WRITE16(map, offset, val) \ 904 *(volatile u_int16_t *)(((vm_offset_t)(map)->handle) + \ 905 (vm_offset_t)(offset)) = val 906 #define DRM_WRITE32(map, offset, val) \ 907 *(volatile u_int32_t *)(((vm_offset_t)(map)->handle) + \ 908 (vm_offset_t)(offset)) = val 909 910 #define DRM_VERIFYAREA_READ( uaddr, size ) \ 911 (!useracc(__DECONST(caddr_t, uaddr), size, VM_PROT_READ)) 912 913 #elif defined(__NetBSD__) 914 915 typedef vaddr_t vm_offset_t; 916 917 #define DRM_IS_BUS_SPACE(map) ((map)->type == _DRM_REGISTERS || \ 918 (map)->type == _DRM_CONSISTENT) 919 920 static __inline__ u_int8_t 921 DRM_READ8(drm_local_map_t *map, bus_size_t offset) 922 { 923 if (DRM_IS_BUS_SPACE(map)) 924 return bus_space_read_1(map->bst, map->bsh, offset); 925 else 926 return *(volatile u_int8_t *)((vaddr_t)map->handle + offset); 927 } 928 929 static __inline__ u_int16_t 930 DRM_READ16(drm_local_map_t *map, bus_size_t offset) 931 { 932 if (DRM_IS_BUS_SPACE(map)) 933 return bus_space_read_2(map->bst, map->bsh, offset); 934 else 935 return *(volatile u_int16_t *)((vaddr_t)map->handle + offset); 936 } 937 938 static __inline__ u_int32_t 939 DRM_READ32(drm_local_map_t *map, bus_size_t offset) 940 { 941 if (DRM_IS_BUS_SPACE(map)) 942 return bus_space_read_4(map->bst, map->bsh, offset); 943 else 944 return *(volatile u_int32_t *)((vaddr_t)map->handle + offset); 945 } 946 947 static __inline__ void 948 DRM_WRITE8(drm_local_map_t *map, bus_size_t offset, u_int8_t val) 949 { 950 if (DRM_IS_BUS_SPACE(map)) 951 bus_space_write_1(map->bst, map->bsh, offset, val); 952 else 953 *(volatile u_int8_t *)((vaddr_t)map->handle + offset) = val; 954 } 955 956 static __inline__ void 957 DRM_WRITE16(drm_local_map_t *map, bus_size_t offset, u_int16_t val) 958 { 959 if (DRM_IS_BUS_SPACE(map)) 960 bus_space_write_2(map->bst, map->bsh, offset, val); 961 else 962 *(volatile u_int16_t *)((vaddr_t)map->handle + offset) = val; 963 } 964 965 static __inline__ void 966 DRM_WRITE32(drm_local_map_t *map, bus_size_t offset, u_int32_t val) 967 { 968 if (DRM_IS_BUS_SPACE(map)) 969 bus_space_write_4(map->bst, map->bsh, offset, val); 970 else 971 *(volatile u_int32_t *)((vaddr_t)map->handle + offset) = val; 972 } 973 974 #define DRM_VERIFYAREA_READ( uaddr, size ) \ 975 (!uvm_map_checkprot(&(curproc->p_vmspace->vm_map), \ 976 (vaddr_t)uaddr, (vaddr_t)uaddr+size, UVM_PROT_READ)) 977 978 #endif 979 980 extern int drm_debug_flag; 981 982 /* Device setup support (drm_drv.c) */ 983 #if defined(__FreeBSD__) 984 int drm_probe(device_t kdev, drm_pci_id_list_t *idlist); 985 int drm_attach(device_t kdev, drm_pci_id_list_t *idlist); 986 void drm_close(void *data); 987 int drm_detach(device_t kdev); 988 d_ioctl_t drm_ioctl; 989 d_open_t drm_open; 990 d_read_t drm_read; 991 d_poll_t drm_poll; 992 d_mmap_t drm_mmap; 993 #elif defined(__NetBSD__) 994 int drm_probe(struct pci_attach_args *pa, drm_pci_id_list_t *idlist); 995 void drm_attach(device_t kdev, struct pci_attach_args *pa, drm_pci_id_list_t *idlist); 996 int drm_detach(device_t self, int flags); 997 dev_type_ioctl(drm_ioctl); 998 dev_type_open(drm_open); 999 dev_type_close(drm_close); 1000 dev_type_read(drm_read); 1001 dev_type_poll(drm_poll); 1002 dev_type_mmap(drm_mmap); 1003 #endif 1004 extern drm_local_map_t *drm_getsarea(struct drm_device *dev); 1005 1006 int drm_close_pid(struct drm_device *dev, struct drm_file *priv, pid_t pid); 1007 1008 /* File operations helpers (drm_fops.c) */ 1009 #if defined(__FreeBSD__) 1010 extern int drm_open_helper(struct cdev *kdev, int flags, int fmt, 1011 DRM_STRUCTPROC *p, 1012 struct drm_device *dev); 1013 #elif defined(__NetBSD__) 1014 extern struct drm_file *drm_find_file_by_proc(struct drm_device *dev, 1015 struct proc *p); 1016 extern int drm_open_helper(dev_t kdev, int flags, int fmt, 1017 struct proc *p, struct drm_device *dev); 1018 #endif 1019 1020 /* Memory management support (drm_memory.c) */ 1021 void drm_mem_init(void); 1022 void drm_mem_uninit(void); 1023 void *drm_ioremap_wc(struct drm_device *dev, drm_local_map_t *map); 1024 void *drm_ioremap(struct drm_device *dev, drm_local_map_t *map); 1025 void drm_ioremapfree(drm_local_map_t *map); 1026 int drm_mtrr_add(unsigned long offset, size_t size, int flags); 1027 int drm_mtrr_del(int handle, unsigned long offset, size_t size, int flags); 1028 1029 int drm_context_switch(struct drm_device *dev, int old, int new); 1030 int drm_context_switch_complete(struct drm_device *dev, int new); 1031 1032 int drm_ctxbitmap_init(struct drm_device *dev); 1033 void drm_ctxbitmap_cleanup(struct drm_device *dev); 1034 void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle); 1035 int drm_ctxbitmap_next(struct drm_device *dev); 1036 1037 /* Locking IOCTL support (drm_lock.c) */ 1038 int drm_lock_take(struct drm_lock_data *lock_data, 1039 unsigned int context); 1040 int drm_lock_transfer(struct drm_lock_data *lock_data, 1041 unsigned int context); 1042 int drm_lock_free(struct drm_lock_data *lock_data, 1043 unsigned int context); 1044 1045 /* Buffer management support (drm_bufs.c) */ 1046 unsigned long drm_get_resource_start(struct drm_device *dev, 1047 unsigned int resource); 1048 unsigned long drm_get_resource_len(struct drm_device *dev, 1049 unsigned int resource); 1050 void drm_rmmap(struct drm_device *dev, drm_local_map_t *map); 1051 int drm_order(unsigned long size); 1052 int drm_addmap(struct drm_device *dev, unsigned long offset, 1053 unsigned long size, 1054 enum drm_map_type type, enum drm_map_flags flags, 1055 drm_local_map_t **map_ptr); 1056 int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc *request); 1057 int drm_addbufs_sg(struct drm_device *dev, struct drm_buf_desc *request); 1058 int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc *request); 1059 1060 /* DMA support (drm_dma.c) */ 1061 int drm_dma_setup(struct drm_device *dev); 1062 void drm_dma_takedown(struct drm_device *dev); 1063 void drm_free_buffer(struct drm_device *dev, drm_buf_t *buf); 1064 void drm_reclaim_buffers(struct drm_device *dev, struct drm_file *file_priv); 1065 #define drm_core_reclaim_buffers drm_reclaim_buffers 1066 1067 /* IRQ support (drm_irq.c) */ 1068 int drm_irq_install(struct drm_device *dev); 1069 int drm_irq_uninstall(struct drm_device *dev); 1070 irqreturn_t drm_irq_handler(DRM_IRQ_ARGS); 1071 void drm_driver_irq_preinstall(struct drm_device *dev); 1072 void drm_driver_irq_postinstall(struct drm_device *dev); 1073 void drm_driver_irq_uninstall(struct drm_device *dev); 1074 void drm_handle_vblank(struct drm_device *dev, unsigned int crtc); 1075 u32 drm_vblank_count(struct drm_device *dev, unsigned int crtc); 1076 int drm_vblank_get(struct drm_device *dev, unsigned int crtc); 1077 void drm_vblank_put(struct drm_device *dev, unsigned int crtc); 1078 void drm_vblank_cleanup(struct drm_device *dev); 1079 int drm_vblank_wait(struct drm_device *dev, unsigned int *vbl_seq); 1080 int drm_vblank_init(struct drm_device *dev, int num_crtcs); 1081 void drm_vbl_send_signals(struct drm_device *dev, unsigned int crtc); 1082 int drm_modeset_ctl(struct drm_device *dev, void *data, 1083 struct drm_file *file_priv); 1084 1085 /* AGP/PCI Express/GART support (drm_agpsupport.c) */ 1086 int drm_device_is_agp(struct drm_device *dev); 1087 int drm_device_is_pcie(struct drm_device *dev); 1088 drm_agp_head_t *drm_agp_init(struct drm_device *dev); 1089 int drm_agp_acquire(struct drm_device *dev); 1090 int drm_agp_release(struct drm_device *dev); 1091 int drm_agp_info(struct drm_device * dev, struct drm_agp_info *info); 1092 int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode); 1093 void *drm_agp_allocate_memory(size_t pages, u32 type); 1094 int drm_agp_free_memory(void *handle); 1095 int drm_agp_bind_memory(void *handle, off_t start); 1096 int drm_agp_unbind_memory(void *handle); 1097 int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request); 1098 int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request); 1099 int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request); 1100 int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request); 1101 1102 /* Scatter Gather Support (drm_scatter.c) */ 1103 void drm_sg_cleanup(drm_sg_mem_t *entry); 1104 int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request); 1105 1106 /* sysctl support (drm_sysctl.h) */ 1107 extern int drm_sysctl_init(struct drm_device *dev); 1108 extern int drm_sysctl_cleanup(struct drm_device *dev); 1109 1110 /* ATI PCIGART support (ati_pcigart.c) */ 1111 int drm_ati_pcigart_init(struct drm_device *dev, 1112 struct drm_ati_pcigart_info *gart_info); 1113 int drm_ati_pcigart_cleanup(struct drm_device *dev, 1114 struct drm_ati_pcigart_info *gart_info); 1115 1116 /* Locking IOCTL support (drm_drv.c) */ 1117 int drm_lock(struct drm_device *dev, void *data, 1118 struct drm_file *file_priv); 1119 int drm_unlock(struct drm_device *dev, void *data, 1120 struct drm_file *file_priv); 1121 int drm_version(struct drm_device *dev, void *data, 1122 struct drm_file *file_priv); 1123 int drm_setversion(struct drm_device *dev, void *data, 1124 struct drm_file *file_priv); 1125 1126 /* Misc. IOCTL support (drm_ioctl.c) */ 1127 int drm_irq_by_busid(struct drm_device *dev, void *data, 1128 struct drm_file *file_priv); 1129 int drm_getunique(struct drm_device *dev, void *data, 1130 struct drm_file *file_priv); 1131 int drm_setunique(struct drm_device *dev, void *data, 1132 struct drm_file *file_priv); 1133 int drm_getmap(struct drm_device *dev, void *data, 1134 struct drm_file *file_priv); 1135 int drm_getclient(struct drm_device *dev, void *data, 1136 struct drm_file *file_priv); 1137 int drm_getstats(struct drm_device *dev, void *data, 1138 struct drm_file *file_priv); 1139 int drm_noop(struct drm_device *dev, void *data, 1140 struct drm_file *file_priv); 1141 1142 /* Context IOCTL support (drm_context.c) */ 1143 int drm_resctx(struct drm_device *dev, void *data, 1144 struct drm_file *file_priv); 1145 int drm_addctx(struct drm_device *dev, void *data, 1146 struct drm_file *file_priv); 1147 int drm_modctx(struct drm_device *dev, void *data, 1148 struct drm_file *file_priv); 1149 int drm_getctx(struct drm_device *dev, void *data, 1150 struct drm_file *file_priv); 1151 int drm_switchctx(struct drm_device *dev, void *data, 1152 struct drm_file *file_priv); 1153 int drm_newctx(struct drm_device *dev, void *data, 1154 struct drm_file *file_priv); 1155 int drm_rmctx(struct drm_device *dev, void *data, 1156 struct drm_file *file_priv); 1157 int drm_setsareactx(struct drm_device *dev, void *data, 1158 struct drm_file *file_priv); 1159 int drm_getsareactx(struct drm_device *dev, void *data, 1160 struct drm_file *file_priv); 1161 1162 /* Drawable IOCTL support (drm_drawable.c) */ 1163 int drm_adddraw(struct drm_device *dev, void *data, 1164 struct drm_file *file_priv); 1165 int drm_rmdraw(struct drm_device *dev, void *data, 1166 struct drm_file *file_priv); 1167 int drm_update_draw(struct drm_device *dev, void *data, 1168 struct drm_file *file_priv); 1169 struct drm_drawable_info *drm_get_drawable_info(struct drm_device *dev, 1170 int handle); 1171 1172 /* Drawable support (drm_drawable.c) */ 1173 void drm_drawable_free_all(struct drm_device *dev); 1174 1175 /* Authentication IOCTL support (drm_auth.c) */ 1176 int drm_getmagic(struct drm_device *dev, void *data, 1177 struct drm_file *file_priv); 1178 int drm_authmagic(struct drm_device *dev, void *data, 1179 struct drm_file *file_priv); 1180 1181 /* Buffer management support (drm_bufs.c) */ 1182 int drm_addmap_ioctl(struct drm_device *dev, void *data, 1183 struct drm_file *file_priv); 1184 int drm_rmmap_ioctl(struct drm_device *dev, void *data, 1185 struct drm_file *file_priv); 1186 int drm_addbufs(struct drm_device *dev, void *data, 1187 struct drm_file *file_priv); 1188 int drm_infobufs(struct drm_device *dev, void *data, 1189 struct drm_file *file_priv); 1190 int drm_markbufs(struct drm_device *dev, void *data, 1191 struct drm_file *file_priv); 1192 int drm_freebufs(struct drm_device *dev, void *data, 1193 struct drm_file *file_priv); 1194 int drm_mapbufs(struct drm_device *dev, void *data, 1195 struct drm_file *file_priv); 1196 1197 /* DMA support (drm_dma.c) */ 1198 int drm_dma(struct drm_device *dev, void *data, struct drm_file *file_priv); 1199 1200 /* IRQ support (drm_irq.c) */ 1201 int drm_control(struct drm_device *dev, void *data, 1202 struct drm_file *file_priv); 1203 int drm_wait_vblank(struct drm_device *dev, void *data, 1204 struct drm_file *file_priv); 1205 1206 /* AGP/GART support (drm_agpsupport.c) */ 1207 int drm_agp_acquire_ioctl(struct drm_device *dev, void *data, 1208 struct drm_file *file_priv); 1209 int drm_agp_release_ioctl(struct drm_device *dev, void *data, 1210 struct drm_file *file_priv); 1211 int drm_agp_enable_ioctl(struct drm_device *dev, void *data, 1212 struct drm_file *file_priv); 1213 int drm_agp_info_ioctl(struct drm_device *dev, void *data, 1214 struct drm_file *file_priv); 1215 int drm_agp_alloc_ioctl(struct drm_device *dev, void *data, 1216 struct drm_file *file_priv); 1217 int drm_agp_free_ioctl(struct drm_device *dev, void *data, 1218 struct drm_file *file_priv); 1219 int drm_agp_unbind_ioctl(struct drm_device *dev, void *data, 1220 struct drm_file *file_priv); 1221 int drm_agp_bind_ioctl(struct drm_device *dev, void *data, 1222 struct drm_file *file_priv); 1223 1224 /* Scatter Gather Support (drm_scatter.c) */ 1225 int drm_sg_alloc_ioctl(struct drm_device *dev, void *data, 1226 struct drm_file *file_priv); 1227 int drm_sg_free(struct drm_device *dev, void *data, 1228 struct drm_file *file_priv); 1229 1230 /* consistent PCI memory functions (drm_pci.c) */ 1231 drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size, 1232 size_t align, dma_addr_t maxaddr); 1233 void drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah); 1234 1235 /* Inline replacements for drm_alloc and friends */ 1236 static __inline__ void * 1237 drm_alloc(size_t size, struct malloc_type *area) 1238 { 1239 return malloc(size, area, M_NOWAIT); 1240 } 1241 1242 static __inline__ void * 1243 drm_calloc(size_t nmemb, size_t size, struct malloc_type *area) 1244 { 1245 return malloc(size * nmemb, area, M_NOWAIT | M_ZERO); 1246 } 1247 1248 static __inline__ void * 1249 drm_realloc(void *oldpt, size_t oldsize, size_t size, 1250 struct malloc_type *area) 1251 { 1252 #if defined(__FreeBSD__) 1253 return reallocf(oldpt, size, area, M_NOWAIT); 1254 #elif defined(__NetBSD__) 1255 void *pt; 1256 1257 pt = malloc(size, area, M_NOWAIT); 1258 if (pt == NULL) 1259 return NULL; 1260 if (oldpt && oldsize) { 1261 memcpy(pt, oldpt, oldsize); 1262 free(oldpt, area); 1263 } 1264 return pt; 1265 #endif 1266 } 1267 1268 static __inline__ void 1269 drm_free(void *pt, size_t size, struct malloc_type *area) 1270 { 1271 free(pt, area); 1272 } 1273 1274 /* Inline replacements for DRM_IOREMAP macros */ 1275 static __inline__ void 1276 drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev) 1277 { 1278 map->handle = drm_ioremap_wc(dev, map); 1279 } 1280 static __inline__ void 1281 drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev) 1282 { 1283 map->handle = drm_ioremap(dev, map); 1284 } 1285 static __inline__ void 1286 drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev) 1287 { 1288 if ( map->handle && map->size ) 1289 drm_ioremapfree(map); 1290 } 1291 1292 static __inline__ struct drm_local_map * 1293 drm_core_findmap(struct drm_device *dev, unsigned long offset) 1294 { 1295 drm_local_map_t *map; 1296 1297 DRM_SPINLOCK_ASSERT(&dev->dev_lock); 1298 TAILQ_FOREACH(map, &dev->maplist, link) { 1299 if (map->offset == offset) 1300 return map; 1301 } 1302 return NULL; 1303 } 1304 1305 static __inline__ void drm_core_dropmap(struct drm_map *map) 1306 { 1307 } 1308 1309 #endif /* __KERNEL__ */ 1310 #endif /* _DRM_P_H_ */ 1311