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