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 #include <sys/cdefs.h> 35 __FBSDID("$FreeBSD$"); 36 37 #ifndef _DRM_P_H_ 38 #define _DRM_P_H_ 39 40 #if defined(_KERNEL) || defined(__KERNEL__) 41 42 struct drm_device; 43 struct drm_file; 44 45 #include <sys/param.h> 46 #include <sys/queue.h> 47 #include <sys/malloc.h> 48 #include <sys/kernel.h> 49 #include <sys/ktr.h> 50 #include <sys/module.h> 51 #include <sys/systm.h> 52 #include <sys/conf.h> 53 #include <sys/sglist.h> 54 #include <sys/stat.h> 55 #include <sys/priv.h> 56 #include <sys/proc.h> 57 #include <sys/lock.h> 58 #include <sys/fcntl.h> 59 #include <sys/uio.h> 60 #include <sys/filio.h> 61 #include <sys/selinfo.h> 62 #include <sys/sysctl.h> 63 #include <sys/bus.h> 64 #include <sys/queue.h> 65 #include <sys/signalvar.h> 66 #include <sys/poll.h> 67 #include <sys/sbuf.h> 68 #include <sys/taskqueue.h> 69 #include <sys/tree.h> 70 #include <vm/vm.h> 71 #include <vm/pmap.h> 72 #include <vm/vm_extern.h> 73 #include <vm/vm_kern.h> 74 #include <vm/vm_map.h> 75 #include <vm/vm_object.h> 76 #include <vm/vm_page.h> 77 #include <vm/vm_pager.h> 78 #include <vm/vm_param.h> 79 #include <vm/vm_phys.h> 80 #include <machine/param.h> 81 #include <machine/pmap.h> 82 #include <machine/bus.h> 83 #include <machine/resource.h> 84 #if defined(__i386__) || defined(__amd64__) 85 #include <machine/specialreg.h> 86 #endif 87 #include <machine/sysarch.h> 88 #include <sys/endian.h> 89 #include <sys/mman.h> 90 #include <sys/rman.h> 91 #include <sys/memrange.h> 92 #include <dev/agp/agpvar.h> 93 #include <sys/agpio.h> 94 #include <sys/mutex.h> 95 #include <dev/pci/pcivar.h> 96 #include <dev/pci/pcireg.h> 97 #include <sys/selinfo.h> 98 #include <sys/bus.h> 99 100 #include <dev/drm2/drm.h> 101 #include <dev/drm2/drm_atomic.h> 102 #include <dev/drm2/drm_internal.h> 103 #include <dev/drm2/drm_linux_list.h> 104 #include <dev/drm2/drm_gem_names.h> 105 #include <dev/drm2/drm_mm.h> 106 #include <dev/drm2/drm_hashtab.h> 107 108 #include "opt_compat.h" 109 #include "opt_drm.h" 110 #ifdef DRM_DEBUG 111 #undef DRM_DEBUG 112 #define DRM_DEBUG_DEFAULT_ON 1 113 #endif /* DRM_DEBUG */ 114 115 #define DRM_DEBUGBITS_DEBUG 0x1 116 #define DRM_DEBUGBITS_KMS 0x2 117 #define DRM_DEBUGBITS_FAILED_IOCTL 0x4 118 119 #undef DRM_LINUX 120 #define DRM_LINUX 0 121 122 /* driver capabilities and requirements mask */ 123 #define DRIVER_USE_AGP 0x1 124 #define DRIVER_REQUIRE_AGP 0x2 125 #define DRIVER_USE_MTRR 0x4 126 #define DRIVER_PCI_DMA 0x8 127 #define DRIVER_SG 0x10 128 #define DRIVER_HAVE_DMA 0x20 129 #define DRIVER_HAVE_IRQ 0x40 130 #define DRIVER_IRQ_SHARED 0x80 131 #define DRIVER_IRQ_VBL 0x100 132 #define DRIVER_DMA_QUEUE 0x200 133 #define DRIVER_FB_DMA 0x400 134 #define DRIVER_IRQ_VBL2 0x800 135 #define DRIVER_GEM 0x1000 136 #define DRIVER_MODESET 0x2000 137 #define DRIVER_USE_PLATFORM_DEVICE 0x4000 138 #define DRIVER_LOCKLESS_IRQ 0x8000 139 140 141 #define DRM_HASH_SIZE 16 /* Size of key hash table */ 142 #define DRM_KERNEL_CONTEXT 0 /* Change drm_resctx if changed */ 143 #define DRM_RESERVED_CONTEXTS 1 /* Change drm_resctx if changed */ 144 145 #define DRM_GEM_MAPPING_MASK (3ULL << 62) 146 #define DRM_GEM_MAPPING_KEY (2ULL << 62) /* Non-canonical address form */ 147 #define DRM_GEM_MAX_IDX 0x3fffff 148 #define DRM_GEM_MAPPING_IDX(o) (((o) >> 40) & DRM_GEM_MAX_IDX) 149 #define DRM_GEM_MAPPING_OFF(i) (((uint64_t)(i)) << 40) 150 #define DRM_GEM_MAPPING_MAPOFF(o) \ 151 ((o) & ~(DRM_GEM_MAPPING_OFF(DRM_GEM_MAX_IDX) | DRM_GEM_MAPPING_KEY)) 152 153 MALLOC_DECLARE(DRM_MEM_DMA); 154 MALLOC_DECLARE(DRM_MEM_SAREA); 155 MALLOC_DECLARE(DRM_MEM_DRIVER); 156 MALLOC_DECLARE(DRM_MEM_MAGIC); 157 MALLOC_DECLARE(DRM_MEM_IOCTLS); 158 MALLOC_DECLARE(DRM_MEM_MAPS); 159 MALLOC_DECLARE(DRM_MEM_BUFS); 160 MALLOC_DECLARE(DRM_MEM_SEGS); 161 MALLOC_DECLARE(DRM_MEM_PAGES); 162 MALLOC_DECLARE(DRM_MEM_FILES); 163 MALLOC_DECLARE(DRM_MEM_QUEUES); 164 MALLOC_DECLARE(DRM_MEM_CMDS); 165 MALLOC_DECLARE(DRM_MEM_MAPPINGS); 166 MALLOC_DECLARE(DRM_MEM_BUFLISTS); 167 MALLOC_DECLARE(DRM_MEM_AGPLISTS); 168 MALLOC_DECLARE(DRM_MEM_CTXBITMAP); 169 MALLOC_DECLARE(DRM_MEM_SGLISTS); 170 MALLOC_DECLARE(DRM_MEM_DRAWABLE); 171 MALLOC_DECLARE(DRM_MEM_MM); 172 MALLOC_DECLARE(DRM_MEM_HASHTAB); 173 MALLOC_DECLARE(DRM_MEM_KMS); 174 175 SYSCTL_DECL(_hw_drm); 176 177 #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8) 178 179 /* Internal types and structures */ 180 #define DRM_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) 181 #define DRM_MIN(a,b) ((a)<(b)?(a):(b)) 182 #define DRM_MAX(a,b) ((a)>(b)?(a):(b)) 183 184 #define DRM_IF_VERSION(maj, min) (maj << 16 | min) 185 186 #define __OS_HAS_AGP 1 187 188 #define DRM_DEV_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) 189 #define DRM_DEV_UID 0 190 #define DRM_DEV_GID 0 191 192 #define wait_queue_head_t atomic_t 193 #define DRM_WAKEUP(w) wakeup((void *)w) 194 #define DRM_WAKEUP_INT(w) wakeup(w) 195 #define DRM_INIT_WAITQUEUE(queue) do {(void)(queue);} while (0) 196 197 #define DRM_CURPROC curthread 198 #define DRM_STRUCTPROC struct thread 199 #define DRM_SPINTYPE struct mtx 200 #define DRM_SPININIT(l,name) mtx_init(l, name, NULL, MTX_DEF) 201 #define DRM_SPINUNINIT(l) mtx_destroy(l) 202 #define DRM_SPINLOCK(l) mtx_lock(l) 203 #define DRM_SPINUNLOCK(u) mtx_unlock(u) 204 #define DRM_SPINLOCK_IRQSAVE(l, irqflags) do { \ 205 mtx_lock(l); \ 206 (void)irqflags; \ 207 } while (0) 208 #define DRM_SPINUNLOCK_IRQRESTORE(u, irqflags) mtx_unlock(u) 209 #define DRM_SPINLOCK_ASSERT(l) mtx_assert(l, MA_OWNED) 210 #define DRM_CURRENTPID curthread->td_proc->p_pid 211 #define DRM_LOCK(dev) sx_xlock(&(dev)->dev_struct_lock) 212 #define DRM_UNLOCK(dev) sx_xunlock(&(dev)->dev_struct_lock) 213 #define DRM_LOCK_SLEEP(dev, chan, flags, msg, timeout) \ 214 (sx_sleep((chan), &(dev)->dev_struct_lock, (flags), (msg), (timeout))) 215 #if defined(INVARIANTS) 216 #define DRM_LOCK_ASSERT(dev) sx_assert(&(dev)->dev_struct_lock, SA_XLOCKED) 217 #define DRM_UNLOCK_ASSERT(dev) sx_assert(&(dev)->dev_struct_lock, SA_UNLOCKED) 218 #else 219 #define DRM_LOCK_ASSERT(d) 220 #define DRM_UNLOCK_ASSERT(d) 221 #endif 222 223 #define DRM_SYSCTL_HANDLER_ARGS (SYSCTL_HANDLER_ARGS) 224 225 #define DRM_IRQ_ARGS void *arg 226 typedef void irqreturn_t; 227 #define IRQ_HANDLED /* nothing */ 228 #define IRQ_NONE /* nothing */ 229 230 #define unlikely(x) __builtin_expect(!!(x), 0) 231 #define container_of(ptr, type, member) ({ \ 232 __typeof( ((type *)0)->member ) *__mptr = (ptr); \ 233 (type *)( (char *)__mptr - offsetof(type,member) );}) 234 235 enum { 236 DRM_IS_NOT_AGP, 237 DRM_IS_AGP, 238 DRM_MIGHT_BE_AGP 239 }; 240 #define DRM_AGP_MEM struct agp_memory_info 241 242 #define drm_get_device_from_kdev(_kdev) (_kdev->si_drv1) 243 244 #define PAGE_ALIGN(addr) round_page(addr) 245 /* DRM_SUSER returns true if the user is superuser */ 246 #define DRM_SUSER(p) (priv_check(p, PRIV_DRIVER) == 0) 247 #define DRM_AGP_FIND_DEVICE() agp_find_device() 248 #define DRM_MTRR_WC MDF_WRITECOMBINE 249 #define jiffies ticks 250 #define jiffies_to_msecs(x) (((int64_t)(x)) * 1000 / hz) 251 #define msecs_to_jiffies(x) (((int64_t)(x)) * hz / 1000) 252 #define time_after(a,b) ((long)(b) - (long)(a) < 0) 253 #define time_after_eq(a,b) ((long)(b) - (long)(a) <= 0) 254 #define drm_msleep(x, msg) pause((msg), ((int64_t)(x)) * hz / 1000) 255 256 typedef vm_paddr_t dma_addr_t; 257 typedef uint64_t u64; 258 typedef uint32_t u32; 259 typedef uint16_t u16; 260 typedef uint8_t u8; 261 typedef int64_t s64; 262 typedef int32_t s32; 263 typedef int16_t s16; 264 typedef int8_t s8; 265 266 /* DRM_READMEMORYBARRIER() prevents reordering of reads. 267 * DRM_WRITEMEMORYBARRIER() prevents reordering of writes. 268 * DRM_MEMORYBARRIER() prevents reordering of reads and writes. 269 */ 270 #define DRM_READMEMORYBARRIER() rmb() 271 #define DRM_WRITEMEMORYBARRIER() wmb() 272 #define DRM_MEMORYBARRIER() mb() 273 274 #define DRM_READ8(map, offset) \ 275 *(volatile u_int8_t *)(((vm_offset_t)(map)->virtual) + \ 276 (vm_offset_t)(offset)) 277 #define DRM_READ16(map, offset) \ 278 le16toh(*(volatile u_int16_t *)(((vm_offset_t)(map)->virtual) + \ 279 (vm_offset_t)(offset))) 280 #define DRM_READ32(map, offset) \ 281 le32toh(*(volatile u_int32_t *)(((vm_offset_t)(map)->virtual) + \ 282 (vm_offset_t)(offset))) 283 #define DRM_READ64(map, offset) \ 284 le64toh(*(volatile u_int64_t *)(((vm_offset_t)(map)->virtual) + \ 285 (vm_offset_t)(offset))) 286 #define DRM_WRITE8(map, offset, val) \ 287 *(volatile u_int8_t *)(((vm_offset_t)(map)->virtual) + \ 288 (vm_offset_t)(offset)) = val 289 #define DRM_WRITE16(map, offset, val) \ 290 *(volatile u_int16_t *)(((vm_offset_t)(map)->virtual) + \ 291 (vm_offset_t)(offset)) = htole16(val) 292 #define DRM_WRITE32(map, offset, val) \ 293 *(volatile u_int32_t *)(((vm_offset_t)(map)->virtual) + \ 294 (vm_offset_t)(offset)) = htole32(val) 295 #define DRM_WRITE64(map, offset, val) \ 296 *(volatile u_int64_t *)(((vm_offset_t)(map)->virtual) + \ 297 (vm_offset_t)(offset)) = htole64(val) 298 299 #define DRM_VERIFYAREA_READ( uaddr, size ) \ 300 (!useracc(__DECONST(caddr_t, uaddr), size, VM_PROT_READ)) 301 302 #define DRM_COPY_TO_USER(user, kern, size) \ 303 copyout(kern, user, size) 304 #define DRM_COPY_FROM_USER(kern, user, size) \ 305 copyin(user, kern, size) 306 #define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) \ 307 copyin(arg2, arg1, arg3) 308 #define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3) \ 309 copyout(arg2, arg1, arg3) 310 #define DRM_GET_USER_UNCHECKED(val, uaddr) \ 311 ((val) = fuword32(uaddr), 0) 312 313 #define cpu_to_le32(x) htole32(x) 314 #define le32_to_cpu(x) le32toh(x) 315 316 #define DRM_HZ hz 317 #define DRM_UDELAY(udelay) DELAY(udelay) 318 #define DRM_TIME_SLICE (hz/20) /* Time slice for GLXContexts */ 319 320 #define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \ 321 (_map) = (_dev)->context_sareas[_ctx]; \ 322 } while(0) 323 324 #define LOCK_TEST_WITH_RETURN(dev, file_priv) \ 325 do { \ 326 if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) || \ 327 dev->lock.file_priv != file_priv) { \ 328 DRM_ERROR("%s called without lock held\n", \ 329 __FUNCTION__); \ 330 return EINVAL; \ 331 } \ 332 } while (0) 333 334 /* Returns -errno to shared code */ 335 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \ 336 for ( ret = 0 ; !ret && !(condition) ; ) { \ 337 DRM_UNLOCK(dev); \ 338 mtx_lock(&dev->irq_lock); \ 339 if (!(condition)) \ 340 ret = -mtx_sleep(&(queue), &dev->irq_lock, \ 341 PCATCH, "drmwtq", (timeout)); \ 342 mtx_unlock(&dev->irq_lock); \ 343 DRM_LOCK(dev); \ 344 } 345 346 #define DRM_ERROR(fmt, ...) \ 347 printf("error: [" DRM_NAME ":pid%d:%s] *ERROR* " fmt, \ 348 DRM_CURRENTPID, __func__ , ##__VA_ARGS__) 349 350 #define DRM_INFO(fmt, ...) printf("info: [" DRM_NAME "] " fmt , ##__VA_ARGS__) 351 352 #define DRM_DEBUG(fmt, ...) do { \ 353 if ((drm_debug_flag & DRM_DEBUGBITS_DEBUG) != 0) \ 354 printf("[" DRM_NAME ":pid%d:%s] " fmt, DRM_CURRENTPID, \ 355 __func__ , ##__VA_ARGS__); \ 356 } while (0) 357 358 #define DRM_DEBUG_KMS(fmt, ...) do { \ 359 if ((drm_debug_flag & DRM_DEBUGBITS_KMS) != 0) \ 360 printf("[" DRM_NAME ":KMS:pid%d:%s] " fmt, DRM_CURRENTPID,\ 361 __func__ , ##__VA_ARGS__); \ 362 } while (0) 363 364 #define DRM_DEBUG_DRIVER(fmt, ...) do { \ 365 if ((drm_debug_flag & DRM_DEBUGBITS_KMS) != 0) \ 366 printf("[" DRM_NAME ":KMS:pid%d:%s] " fmt, DRM_CURRENTPID,\ 367 __func__ , ##__VA_ARGS__); \ 368 } while (0) 369 370 typedef struct drm_pci_id_list 371 { 372 int vendor; 373 int device; 374 long driver_private; 375 char *name; 376 } drm_pci_id_list_t; 377 378 struct drm_msi_blacklist_entry 379 { 380 int vendor; 381 int device; 382 }; 383 384 #define DRM_AUTH 0x1 385 #define DRM_MASTER 0x2 386 #define DRM_ROOT_ONLY 0x4 387 #define DRM_CONTROL_ALLOW 0x8 388 #define DRM_UNLOCKED 0x10 389 390 typedef struct drm_ioctl_desc { 391 unsigned long cmd; 392 int (*func)(struct drm_device *dev, void *data, 393 struct drm_file *file_priv); 394 int flags; 395 } drm_ioctl_desc_t; 396 /** 397 * Creates a driver or general drm_ioctl_desc array entry for the given 398 * ioctl, for use by drm_ioctl(). 399 */ 400 #define DRM_IOCTL_DEF(ioctl, func, flags) \ 401 [DRM_IOCTL_NR(ioctl)] = {ioctl, func, flags} 402 403 typedef struct drm_magic_entry { 404 drm_magic_t magic; 405 struct drm_file *priv; 406 struct drm_magic_entry *next; 407 } drm_magic_entry_t; 408 409 typedef struct drm_magic_head { 410 struct drm_magic_entry *head; 411 struct drm_magic_entry *tail; 412 } drm_magic_head_t; 413 414 typedef struct drm_buf { 415 int idx; /* Index into master buflist */ 416 int total; /* Buffer size */ 417 int order; /* log-base-2(total) */ 418 int used; /* Amount of buffer in use (for DMA) */ 419 unsigned long offset; /* Byte offset (used internally) */ 420 void *address; /* Address of buffer */ 421 unsigned long bus_address; /* Bus address of buffer */ 422 struct drm_buf *next; /* Kernel-only: used for free list */ 423 __volatile__ int pending; /* On hardware DMA queue */ 424 struct drm_file *file_priv; /* Unique identifier of holding process */ 425 int context; /* Kernel queue for this buffer */ 426 enum { 427 DRM_LIST_NONE = 0, 428 DRM_LIST_FREE = 1, 429 DRM_LIST_WAIT = 2, 430 DRM_LIST_PEND = 3, 431 DRM_LIST_PRIO = 4, 432 DRM_LIST_RECLAIM = 5 433 } list; /* Which list we're on */ 434 435 int dev_priv_size; /* Size of buffer private stoarge */ 436 void *dev_private; /* Per-buffer private storage */ 437 } drm_buf_t; 438 439 typedef struct drm_freelist { 440 int initialized; /* Freelist in use */ 441 atomic_t count; /* Number of free buffers */ 442 drm_buf_t *next; /* End pointer */ 443 444 int low_mark; /* Low water mark */ 445 int high_mark; /* High water mark */ 446 } drm_freelist_t; 447 448 typedef struct drm_dma_handle { 449 void *vaddr; 450 bus_addr_t busaddr; 451 bus_dma_tag_t tag; 452 bus_dmamap_t map; 453 } drm_dma_handle_t; 454 455 typedef struct drm_buf_entry { 456 int buf_size; 457 int buf_count; 458 drm_buf_t *buflist; 459 int seg_count; 460 drm_dma_handle_t **seglist; 461 int page_order; 462 463 drm_freelist_t freelist; 464 } drm_buf_entry_t; 465 466 /* Event queued up for userspace to read */ 467 struct drm_pending_event { 468 struct drm_event *event; 469 struct list_head link; 470 struct drm_file *file_priv; 471 pid_t pid; /* pid of requester, no guarantee it's valid by the time 472 we deliver the event, for tracing only */ 473 void (*destroy)(struct drm_pending_event *event); 474 }; 475 476 typedef TAILQ_HEAD(drm_file_list, drm_file) drm_file_list_t; 477 struct drm_file { 478 TAILQ_ENTRY(drm_file) link; 479 struct drm_device *dev; 480 int authenticated; 481 int master; 482 pid_t pid; 483 uid_t uid; 484 drm_magic_t magic; 485 unsigned long ioctl_count; 486 487 void *driver_priv; 488 struct drm_gem_names object_names; 489 490 int is_master; 491 struct drm_master *masterp; 492 493 struct list_head fbs; 494 495 struct list_head event_list; 496 int event_space; 497 struct selinfo event_poll; 498 }; 499 500 typedef struct drm_lock_data { 501 struct drm_hw_lock *hw_lock; /* Hardware lock */ 502 struct drm_file *file_priv; /* Unique identifier of holding process (NULL is kernel)*/ 503 int lock_queue; /* Queue of blocked processes */ 504 unsigned long lock_time; /* Time of last lock in jiffies */ 505 } drm_lock_data_t; 506 507 /* This structure, in the struct drm_device, is always initialized while the 508 * device 509 * is open. dev->dma_lock protects the incrementing of dev->buf_use, which 510 * when set marks that no further bufs may be allocated until device teardown 511 * occurs (when the last open of the device has closed). The high/low 512 * watermarks of bufs are only touched by the X Server, and thus not 513 * concurrently accessed, so no locking is needed. 514 */ 515 typedef struct drm_device_dma { 516 drm_buf_entry_t bufs[DRM_MAX_ORDER+1]; 517 int buf_count; 518 drm_buf_t **buflist; /* Vector of pointers info bufs */ 519 int seg_count; 520 int page_count; 521 unsigned long *pagelist; 522 unsigned long byte_count; 523 enum { 524 _DRM_DMA_USE_AGP = 0x01, 525 _DRM_DMA_USE_SG = 0x02 526 } flags; 527 } drm_device_dma_t; 528 529 typedef struct drm_agp_mem { 530 void *handle; 531 unsigned long bound; /* address */ 532 int pages; 533 struct drm_agp_mem *prev; 534 struct drm_agp_mem *next; 535 } drm_agp_mem_t; 536 537 typedef struct drm_agp_head { 538 device_t agpdev; 539 struct agp_info info; 540 const char *chipset; 541 drm_agp_mem_t *memory; 542 unsigned long mode; 543 int enabled; 544 int acquired; 545 unsigned long base; 546 int mtrr; 547 int cant_use_aperture; 548 unsigned long page_mask; 549 } drm_agp_head_t; 550 551 typedef struct drm_sg_mem { 552 vm_offset_t vaddr; 553 vm_paddr_t *busaddr; 554 vm_pindex_t pages; 555 } drm_sg_mem_t; 556 557 #define DRM_MAP_HANDLE_BITS (sizeof(void *) == 4 ? 4 : 24) 558 #define DRM_MAP_HANDLE_SHIFT (sizeof(void *) * 8 - DRM_MAP_HANDLE_BITS) 559 typedef TAILQ_HEAD(drm_map_list, drm_local_map) drm_map_list_t; 560 561 typedef struct drm_local_map { 562 unsigned long offset; /* Physical address (0 for SAREA) */ 563 unsigned long size; /* Physical size (bytes) */ 564 enum drm_map_type type; /* Type of memory mapped */ 565 enum drm_map_flags flags; /* Flags */ 566 void *handle; /* User-space: "Handle" to pass to mmap */ 567 /* Kernel-space: kernel-virtual address */ 568 int mtrr; /* Boolean: MTRR used */ 569 /* Private data */ 570 int rid; /* PCI resource ID for bus_space */ 571 void *virtual; /* Kernel-space: kernel-virtual address */ 572 struct resource *bsr; 573 bus_space_tag_t bst; 574 bus_space_handle_t bsh; 575 drm_dma_handle_t *dmah; 576 TAILQ_ENTRY(drm_local_map) link; 577 } drm_local_map_t; 578 579 struct drm_vblank_info { 580 wait_queue_head_t queue; /* vblank wait queue */ 581 atomic_t count; /* number of VBLANK interrupts */ 582 /* (driver must alloc the right number of counters) */ 583 atomic_t refcount; /* number of users of vblank interrupts */ 584 u32 last; /* protected by dev->vbl_lock, used */ 585 /* for wraparound handling */ 586 int enabled; /* so we don't call enable more than */ 587 /* once per disable */ 588 int inmodeset; /* Display driver is setting mode */ 589 }; 590 591 /* Size of ringbuffer for vblank timestamps. Just double-buffer 592 * in initial implementation. 593 */ 594 #define DRM_VBLANKTIME_RBSIZE 2 595 596 /* Flags and return codes for get_vblank_timestamp() driver function. */ 597 #define DRM_CALLED_FROM_VBLIRQ 1 598 #define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0) 599 #define DRM_VBLANKTIME_INVBL (1 << 1) 600 601 /* get_scanout_position() return flags */ 602 #define DRM_SCANOUTPOS_VALID (1 << 0) 603 #define DRM_SCANOUTPOS_INVBL (1 << 1) 604 #define DRM_SCANOUTPOS_ACCURATE (1 << 2) 605 606 /* location of GART table */ 607 #define DRM_ATI_GART_MAIN 1 608 #define DRM_ATI_GART_FB 2 609 610 #define DRM_ATI_GART_PCI 1 611 #define DRM_ATI_GART_PCIE 2 612 #define DRM_ATI_GART_IGP 3 613 614 struct drm_ati_pcigart_info { 615 int gart_table_location; 616 int gart_reg_if; 617 void *addr; 618 dma_addr_t bus_addr; 619 dma_addr_t table_mask; 620 dma_addr_t member_mask; 621 struct drm_dma_handle *table_handle; 622 drm_local_map_t mapping; 623 int table_size; 624 struct drm_dma_handle *dmah; /* handle for ATI PCIGART table */ 625 }; 626 627 typedef vm_paddr_t resource_size_t; 628 629 /** 630 * GEM specific mm private for tracking GEM objects 631 */ 632 struct drm_gem_mm { 633 struct drm_open_hash offset_hash; /**< User token hash table for maps */ 634 struct unrhdr *idxunr; 635 }; 636 637 struct drm_gem_object { 638 /** Reference count of this object */ 639 u_int refcount; 640 641 /** Handle count of this object. Each handle also holds a reference */ 642 u_int handle_count; /* number of handles on this object */ 643 644 /** Related drm device */ 645 struct drm_device *dev; 646 647 /** File representing the shmem storage: filp in Linux parlance */ 648 vm_object_t vm_obj; 649 650 bool on_map; 651 struct drm_hash_item map_list; 652 653 /** 654 * Size of the object, in bytes. Immutable over the object's 655 * lifetime. 656 */ 657 size_t size; 658 659 /** 660 * Global name for this object, starts at 1. 0 means unnamed. 661 * Access is covered by the object_name_lock in the related drm_device 662 */ 663 int name; 664 665 /** 666 * Memory domains. These monitor which caches contain read/write data 667 * related to the object. When transitioning from one set of domains 668 * to another, the driver is called to ensure that caches are suitably 669 * flushed and invalidated 670 */ 671 uint32_t read_domains; 672 uint32_t write_domain; 673 674 /** 675 * While validating an exec operation, the 676 * new read/write domain values are computed here. 677 * They will be transferred to the above values 678 * at the point that any cache flushing occurs 679 */ 680 uint32_t pending_read_domains; 681 uint32_t pending_write_domain; 682 683 void *driver_private; 684 }; 685 686 #include "drm_crtc.h" 687 688 #ifndef DMA_BIT_MASK 689 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : (1ULL<<(n)) - 1) 690 #endif 691 692 #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16)) 693 694 struct drm_driver_info { 695 int (*load)(struct drm_device *, unsigned long flags); 696 int (*firstopen)(struct drm_device *); 697 int (*open)(struct drm_device *, struct drm_file *); 698 void (*preclose)(struct drm_device *, struct drm_file *file_priv); 699 void (*postclose)(struct drm_device *, struct drm_file *); 700 void (*lastclose)(struct drm_device *); 701 int (*unload)(struct drm_device *); 702 void (*reclaim_buffers_locked)(struct drm_device *, 703 struct drm_file *file_priv); 704 int (*dma_ioctl)(struct drm_device *dev, void *data, 705 struct drm_file *file_priv); 706 void (*dma_ready)(struct drm_device *); 707 int (*dma_quiescent)(struct drm_device *); 708 int (*dma_flush_block_and_flush)(struct drm_device *, int context, 709 enum drm_lock_flags flags); 710 int (*dma_flush_unblock)(struct drm_device *, int context, 711 enum drm_lock_flags flags); 712 int (*context_ctor)(struct drm_device *dev, int context); 713 int (*context_dtor)(struct drm_device *dev, int context); 714 int (*kernel_context_switch)(struct drm_device *dev, int old, 715 int new); 716 int (*kernel_context_switch_unlock)(struct drm_device *dev); 717 void (*irq_preinstall)(struct drm_device *dev); 718 int (*irq_postinstall)(struct drm_device *dev); 719 void (*irq_uninstall)(struct drm_device *dev); 720 void (*irq_handler)(DRM_IRQ_ARGS); 721 722 u32 (*get_vblank_counter)(struct drm_device *dev, int crtc); 723 int (*enable_vblank)(struct drm_device *dev, int crtc); 724 void (*disable_vblank)(struct drm_device *dev, int crtc); 725 int (*get_scanout_position)(struct drm_device *dev, int crtc, 726 int *vpos, int *hpos); 727 728 int (*get_vblank_timestamp)(struct drm_device *dev, int crtc, 729 int *max_error, struct timeval *vblank_time, 730 unsigned flags); 731 732 int (*gem_init_object)(struct drm_gem_object *obj); 733 void (*gem_free_object)(struct drm_gem_object *obj); 734 735 struct cdev_pager_ops *gem_pager_ops; 736 737 int (*dumb_create)(struct drm_file *file_priv, 738 struct drm_device *dev, struct drm_mode_create_dumb *args); 739 int (*dumb_map_offset)(struct drm_file *file_priv, 740 struct drm_device *dev, uint32_t handle, uint64_t *offset); 741 int (*dumb_destroy)(struct drm_file *file_priv, 742 struct drm_device *dev, uint32_t handle); 743 744 int (*sysctl_init)(struct drm_device *dev, 745 struct sysctl_ctx_list *ctx, struct sysctl_oid *top); 746 void (*sysctl_cleanup)(struct drm_device *dev); 747 748 drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */ 749 750 /** 751 * Called by \c drm_device_is_agp. Typically used to determine if a 752 * card is really attached to AGP or not. 753 * 754 * \param dev DRM device handle 755 * 756 * \returns 757 * One of three values is returned depending on whether or not the 758 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP 759 * (return of 1), or may or may not be AGP (return of 2). 760 */ 761 int (*device_is_agp) (struct drm_device * dev); 762 763 drm_ioctl_desc_t *ioctls; 764 #ifdef COMPAT_FREEBSD32 765 drm_ioctl_desc_t *compat_ioctls; 766 int *compat_ioctls_nr; 767 #endif 768 int max_ioctl; 769 770 int buf_priv_size; 771 772 int major; 773 int minor; 774 int patchlevel; 775 const char *name; /* Simple driver name */ 776 const char *desc; /* Longer driver name */ 777 const char *date; /* Date of last major changes. */ 778 779 u32 driver_features; 780 }; 781 782 /** 783 * DRM minor structure. This structure represents a drm minor number. 784 */ 785 struct drm_minor { 786 int index; /**< Minor device number */ 787 int type; /**< Control or render */ 788 device_t kdev; /**< OS device */ 789 struct drm_device *dev; 790 791 struct drm_master *master; /* currently active master for this node */ 792 struct list_head master_list; 793 struct drm_mode_group mode_group; 794 }; 795 796 /* mode specified on the command line */ 797 struct drm_cmdline_mode { 798 bool specified; 799 bool refresh_specified; 800 bool bpp_specified; 801 int xres, yres; 802 int bpp; 803 int refresh; 804 bool rb; 805 bool interlace; 806 bool cvt; 807 bool margins; 808 enum drm_connector_force force; 809 }; 810 811 struct drm_pending_vblank_event { 812 struct drm_pending_event base; 813 int pipe; 814 struct drm_event_vblank event; 815 }; 816 817 /* Length for the array of resource pointers for drm_get_resource_*. */ 818 #define DRM_MAX_PCI_RESOURCE 6 819 820 /** 821 * DRM device functions structure 822 */ 823 struct drm_device { 824 struct drm_driver_info *driver; 825 drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */ 826 827 u_int16_t pci_device; /* PCI device id */ 828 u_int16_t pci_vendor; /* PCI vendor id */ 829 830 char *unique; /* Unique identifier: e.g., busid */ 831 int unique_len; /* Length of unique field */ 832 device_t device; /* Device instance from newbus */ 833 struct cdev *devnode; /* Device number for mknod */ 834 int if_version; /* Highest interface version set */ 835 836 int flags; /* Flags to open(2) */ 837 838 /* Locks */ 839 struct mtx dma_lock; /* protects dev->dma */ 840 struct mtx irq_lock; /* protects irq condition checks */ 841 struct mtx dev_lock; /* protects everything else */ 842 struct sx dev_struct_lock; 843 DRM_SPINTYPE drw_lock; 844 845 /* Usage Counters */ 846 int open_count; /* Outstanding files open */ 847 int buf_use; /* Buffers in use -- cannot alloc */ 848 849 /* Performance counters */ 850 unsigned long counters; 851 enum drm_stat_type types[15]; 852 atomic_t counts[15]; 853 854 /* Authentication */ 855 drm_file_list_t files; 856 drm_magic_head_t magiclist[DRM_HASH_SIZE]; 857 858 /* Linked list of mappable regions. Protected by dev_lock */ 859 drm_map_list_t maplist; 860 struct unrhdr *map_unrhdr; 861 862 drm_local_map_t **context_sareas; 863 int max_context; 864 865 drm_lock_data_t lock; /* Information on hardware lock */ 866 867 /* DMA queues (contexts) */ 868 drm_device_dma_t *dma; /* Optional pointer for DMA support */ 869 870 /* Context support */ 871 int irq; /* Interrupt used by board */ 872 int irq_enabled; /* True if the irq handler is enabled */ 873 int msi_enabled; /* MSI enabled */ 874 int irqrid; /* Interrupt used by board */ 875 struct resource *irqr; /* Resource for interrupt used by board */ 876 void *irqh; /* Handle from bus_setup_intr */ 877 878 /* Storage of resource pointers for drm_get_resource_* */ 879 struct resource *pcir[DRM_MAX_PCI_RESOURCE]; 880 int pcirid[DRM_MAX_PCI_RESOURCE]; 881 882 int pci_domain; 883 int pci_bus; 884 int pci_slot; 885 int pci_func; 886 887 atomic_t context_flag; /* Context swapping flag */ 888 int last_context; /* Last current context */ 889 890 int num_crtcs; 891 892 struct sigio *buf_sigio; /* Processes waiting for SIGIO */ 893 894 /* Sysctl support */ 895 struct drm_sysctl_info *sysctl; 896 int sysctl_node_idx; 897 898 drm_agp_head_t *agp; 899 drm_sg_mem_t *sg; /* Scatter gather memory */ 900 atomic_t *ctx_bitmap; 901 void *dev_private; 902 unsigned int agp_buffer_token; 903 drm_local_map_t *agp_buffer_map; 904 905 struct drm_minor *control; /**< Control node for card */ 906 struct drm_minor *primary; /**< render type primary screen head */ 907 908 struct unrhdr *drw_unrhdr; 909 /* RB tree of drawable infos */ 910 RB_HEAD(drawable_tree, bsd_drm_drawable_info) drw_head; 911 912 int vblank_disable_allowed; 913 914 atomic_t *_vblank_count; /**< number of VBLANK interrupts (driver must alloc the right number of counters) */ 915 struct timeval *_vblank_time; /**< timestamp of current vblank_count (drivers must alloc right number of fields) */ 916 struct mtx vblank_time_lock; /**< Protects vblank count and time updates during vblank enable/disable */ 917 struct mtx vbl_lock; 918 atomic_t *vblank_refcount; /* number of users of vblank interruptsper crtc */ 919 u32 *last_vblank; /* protected by dev->vbl_lock, used */ 920 /* for wraparound handling */ 921 int *vblank_enabled; /* so we don't call enable more than 922 once per disable */ 923 int *vblank_inmodeset; /* Display driver is setting mode */ 924 u32 *last_vblank_wait; /* Last vblank seqno waited per CRTC */ 925 struct callout vblank_disable_callout; 926 927 u32 max_vblank_count; /**< size of vblank counter register */ 928 929 struct list_head vblank_event_list; 930 struct mtx event_lock; 931 932 struct drm_mode_config mode_config; /**< Current mode config */ 933 934 /* GEM part */ 935 struct sx object_name_lock; 936 struct drm_gem_names object_names; 937 void *mm_private; 938 939 void *sysctl_private; 940 char busid_str[128]; 941 int modesetting; 942 }; 943 944 static __inline__ int drm_core_check_feature(struct drm_device *dev, 945 int feature) 946 { 947 return ((dev->driver->driver_features & feature) ? 1 : 0); 948 } 949 950 #if __OS_HAS_AGP 951 static inline int drm_core_has_AGP(struct drm_device *dev) 952 { 953 return drm_core_check_feature(dev, DRIVER_USE_AGP); 954 } 955 #else 956 #define drm_core_has_AGP(dev) (0) 957 #endif 958 959 enum dmi_field { 960 DMI_NONE, 961 DMI_BIOS_VENDOR, 962 DMI_BIOS_VERSION, 963 DMI_BIOS_DATE, 964 DMI_SYS_VENDOR, 965 DMI_PRODUCT_NAME, 966 DMI_PRODUCT_VERSION, 967 DMI_PRODUCT_SERIAL, 968 DMI_PRODUCT_UUID, 969 DMI_BOARD_VENDOR, 970 DMI_BOARD_NAME, 971 DMI_BOARD_VERSION, 972 DMI_BOARD_SERIAL, 973 DMI_BOARD_ASSET_TAG, 974 DMI_CHASSIS_VENDOR, 975 DMI_CHASSIS_TYPE, 976 DMI_CHASSIS_VERSION, 977 DMI_CHASSIS_SERIAL, 978 DMI_CHASSIS_ASSET_TAG, 979 DMI_STRING_MAX, 980 }; 981 982 struct dmi_strmatch { 983 unsigned char slot; 984 char substr[79]; 985 }; 986 987 struct dmi_system_id { 988 int (*callback)(const struct dmi_system_id *); 989 const char *ident; 990 struct dmi_strmatch matches[4]; 991 }; 992 #define DMI_MATCH(a, b) {(a), (b)} 993 bool dmi_check_system(const struct dmi_system_id *); 994 995 extern int drm_debug_flag; 996 extern int drm_notyet_flag; 997 extern unsigned int drm_vblank_offdelay; 998 extern unsigned int drm_timestamp_precision; 999 1000 /* Device setup support (drm_drv.c) */ 1001 int drm_probe(device_t kdev, drm_pci_id_list_t *idlist); 1002 int drm_attach(device_t kdev, drm_pci_id_list_t *idlist); 1003 int drm_create_cdevs(device_t kdev); 1004 void drm_close(void *data); 1005 int drm_detach(device_t kdev); 1006 d_ioctl_t drm_ioctl; 1007 d_open_t drm_open; 1008 d_read_t drm_read; 1009 d_poll_t drm_poll; 1010 d_mmap_t drm_mmap; 1011 extern drm_local_map_t *drm_getsarea(struct drm_device *dev); 1012 1013 void drm_event_wakeup(struct drm_pending_event *e); 1014 1015 int drm_add_busid_modesetting(struct drm_device *dev, 1016 struct sysctl_ctx_list *ctx, struct sysctl_oid *top); 1017 1018 /* File operations helpers (drm_fops.c) */ 1019 extern int drm_open_helper(struct cdev *kdev, int flags, int fmt, 1020 DRM_STRUCTPROC *p, 1021 struct drm_device *dev); 1022 1023 /* Memory management support (drm_memory.c) */ 1024 void drm_mem_init(void); 1025 void drm_mem_uninit(void); 1026 void *drm_ioremap_wc(struct drm_device *dev, drm_local_map_t *map); 1027 void *drm_ioremap(struct drm_device *dev, drm_local_map_t *map); 1028 void drm_ioremapfree(drm_local_map_t *map); 1029 int drm_mtrr_add(unsigned long offset, size_t size, int flags); 1030 int drm_mtrr_del(int handle, unsigned long offset, size_t size, int flags); 1031 1032 int drm_context_switch(struct drm_device *dev, int old, int new); 1033 int drm_context_switch_complete(struct drm_device *dev, int new); 1034 1035 int drm_ctxbitmap_init(struct drm_device *dev); 1036 void drm_ctxbitmap_cleanup(struct drm_device *dev); 1037 void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle); 1038 int drm_ctxbitmap_next(struct drm_device *dev); 1039 1040 /* Locking IOCTL support (drm_lock.c) */ 1041 int drm_lock_take(struct drm_lock_data *lock_data, 1042 unsigned int context); 1043 int drm_lock_transfer(struct drm_lock_data *lock_data, 1044 unsigned int context); 1045 int drm_lock_free(struct drm_lock_data *lock_data, 1046 unsigned int context); 1047 1048 /* Buffer management support (drm_bufs.c) */ 1049 unsigned long drm_get_resource_start(struct drm_device *dev, 1050 unsigned int resource); 1051 unsigned long drm_get_resource_len(struct drm_device *dev, 1052 unsigned int resource); 1053 void drm_rmmap(struct drm_device *dev, drm_local_map_t *map); 1054 int drm_order(unsigned long size); 1055 int drm_addmap(struct drm_device *dev, unsigned long offset, 1056 unsigned long size, 1057 enum drm_map_type type, enum drm_map_flags flags, 1058 drm_local_map_t **map_ptr); 1059 int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc *request); 1060 int drm_addbufs_sg(struct drm_device *dev, struct drm_buf_desc *request); 1061 int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc *request); 1062 1063 /* DMA support (drm_dma.c) */ 1064 int drm_dma_setup(struct drm_device *dev); 1065 void drm_dma_takedown(struct drm_device *dev); 1066 void drm_free_buffer(struct drm_device *dev, drm_buf_t *buf); 1067 void drm_reclaim_buffers(struct drm_device *dev, struct drm_file *file_priv); 1068 #define drm_core_reclaim_buffers drm_reclaim_buffers 1069 1070 /* IRQ support (drm_irq.c) */ 1071 int drm_irq_install(struct drm_device *dev); 1072 int drm_irq_uninstall(struct drm_device *dev); 1073 irqreturn_t drm_irq_handler(DRM_IRQ_ARGS); 1074 void drm_driver_irq_preinstall(struct drm_device *dev); 1075 void drm_driver_irq_postinstall(struct drm_device *dev); 1076 void drm_driver_irq_uninstall(struct drm_device *dev); 1077 1078 void drm_vblank_pre_modeset(struct drm_device *dev, int crtc); 1079 void drm_vblank_post_modeset(struct drm_device *dev, int crtc); 1080 int drm_modeset_ctl(struct drm_device *dev, void *data, 1081 struct drm_file *file_priv); 1082 1083 extern int drm_vblank_init(struct drm_device *dev, int num_crtcs); 1084 extern int drm_wait_vblank(struct drm_device *dev, void *data, 1085 struct drm_file *filp); 1086 extern int drm_vblank_wait(struct drm_device *dev, unsigned int *vbl_seq); 1087 extern u32 drm_vblank_count(struct drm_device *dev, int crtc); 1088 extern u32 drm_vblank_count_and_time(struct drm_device *dev, int crtc, 1089 struct timeval *vblanktime); 1090 extern bool drm_handle_vblank(struct drm_device *dev, int crtc); 1091 void drm_handle_vblank_events(struct drm_device *dev, int crtc); 1092 extern int drm_vblank_get(struct drm_device *dev, int crtc); 1093 extern void drm_vblank_put(struct drm_device *dev, int crtc); 1094 extern void drm_vblank_off(struct drm_device *dev, int crtc); 1095 extern void drm_vblank_cleanup(struct drm_device *dev); 1096 extern u32 drm_get_last_vbltimestamp(struct drm_device *dev, int crtc, 1097 struct timeval *tvblank, unsigned flags); 1098 extern int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev, 1099 int crtc, int *max_error, 1100 struct timeval *vblank_time, 1101 unsigned flags, 1102 struct drm_crtc *refcrtc); 1103 extern void drm_calc_timestamping_constants(struct drm_crtc *crtc); 1104 1105 struct timeval ns_to_timeval(const int64_t nsec); 1106 int64_t timeval_to_ns(const struct timeval *tv); 1107 1108 /* AGP/PCI Express/GART support (drm_agpsupport.c) */ 1109 int drm_device_is_agp(struct drm_device *dev); 1110 int drm_device_is_pcie(struct drm_device *dev); 1111 drm_agp_head_t *drm_agp_init(void); 1112 int drm_agp_acquire(struct drm_device *dev); 1113 int drm_agp_release(struct drm_device *dev); 1114 int drm_agp_info(struct drm_device * dev, struct drm_agp_info *info); 1115 int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode); 1116 void *drm_agp_allocate_memory(size_t pages, u32 type); 1117 int drm_agp_free_memory(void *handle); 1118 int drm_agp_bind_memory(void *handle, off_t start); 1119 int drm_agp_unbind_memory(void *handle); 1120 int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request); 1121 int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request); 1122 int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request); 1123 int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request); 1124 1125 /* Scatter Gather Support (drm_scatter.c) */ 1126 void drm_sg_cleanup(drm_sg_mem_t *entry); 1127 int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request); 1128 1129 /* sysctl support (drm_sysctl.h) */ 1130 extern int drm_sysctl_init(struct drm_device *dev); 1131 extern int drm_sysctl_cleanup(struct drm_device *dev); 1132 1133 /* ATI PCIGART support (ati_pcigart.c) */ 1134 int drm_ati_pcigart_init(struct drm_device *dev, 1135 struct drm_ati_pcigart_info *gart_info); 1136 int drm_ati_pcigart_cleanup(struct drm_device *dev, 1137 struct drm_ati_pcigart_info *gart_info); 1138 1139 /* Cache management (drm_memory.c) */ 1140 void drm_clflush_pages(vm_page_t *pages, unsigned long num_pages); 1141 1142 /* Locking IOCTL support (drm_drv.c) */ 1143 int drm_lock(struct drm_device *dev, void *data, 1144 struct drm_file *file_priv); 1145 int drm_unlock(struct drm_device *dev, void *data, 1146 struct drm_file *file_priv); 1147 int drm_version(struct drm_device *dev, void *data, 1148 struct drm_file *file_priv); 1149 int drm_setversion(struct drm_device *dev, void *data, 1150 struct drm_file *file_priv); 1151 1152 /* Misc. IOCTL support (drm_ioctl.c) */ 1153 int drm_irq_by_busid(struct drm_device *dev, void *data, 1154 struct drm_file *file_priv); 1155 int drm_getunique(struct drm_device *dev, void *data, 1156 struct drm_file *file_priv); 1157 int drm_setunique(struct drm_device *dev, void *data, 1158 struct drm_file *file_priv); 1159 int drm_getmap(struct drm_device *dev, void *data, 1160 struct drm_file *file_priv); 1161 int drm_getclient(struct drm_device *dev, void *data, 1162 struct drm_file *file_priv); 1163 int drm_getstats(struct drm_device *dev, void *data, 1164 struct drm_file *file_priv); 1165 int drm_getcap(struct drm_device *dev, void *data, 1166 struct drm_file *file_priv); 1167 int drm_noop(struct drm_device *dev, void *data, 1168 struct drm_file *file_priv); 1169 1170 /* Context IOCTL support (drm_context.c) */ 1171 int drm_resctx(struct drm_device *dev, void *data, 1172 struct drm_file *file_priv); 1173 int drm_addctx(struct drm_device *dev, void *data, 1174 struct drm_file *file_priv); 1175 int drm_modctx(struct drm_device *dev, void *data, 1176 struct drm_file *file_priv); 1177 int drm_getctx(struct drm_device *dev, void *data, 1178 struct drm_file *file_priv); 1179 int drm_switchctx(struct drm_device *dev, void *data, 1180 struct drm_file *file_priv); 1181 int drm_newctx(struct drm_device *dev, void *data, 1182 struct drm_file *file_priv); 1183 int drm_rmctx(struct drm_device *dev, void *data, 1184 struct drm_file *file_priv); 1185 int drm_setsareactx(struct drm_device *dev, void *data, 1186 struct drm_file *file_priv); 1187 int drm_getsareactx(struct drm_device *dev, void *data, 1188 struct drm_file *file_priv); 1189 1190 /* Drawable IOCTL support (drm_drawable.c) */ 1191 int drm_adddraw(struct drm_device *dev, void *data, 1192 struct drm_file *file_priv); 1193 int drm_rmdraw(struct drm_device *dev, void *data, 1194 struct drm_file *file_priv); 1195 int drm_update_draw(struct drm_device *dev, void *data, 1196 struct drm_file *file_priv); 1197 struct drm_drawable_info *drm_get_drawable_info(struct drm_device *dev, 1198 int handle); 1199 1200 /* Drawable support (drm_drawable.c) */ 1201 void drm_drawable_free_all(struct drm_device *dev); 1202 1203 /* Authentication IOCTL support (drm_auth.c) */ 1204 int drm_getmagic(struct drm_device *dev, void *data, 1205 struct drm_file *file_priv); 1206 int drm_authmagic(struct drm_device *dev, void *data, 1207 struct drm_file *file_priv); 1208 1209 /* Buffer management support (drm_bufs.c) */ 1210 int drm_addmap_ioctl(struct drm_device *dev, void *data, 1211 struct drm_file *file_priv); 1212 int drm_rmmap_ioctl(struct drm_device *dev, void *data, 1213 struct drm_file *file_priv); 1214 int drm_addbufs(struct drm_device *dev, void *data, 1215 struct drm_file *file_priv); 1216 int drm_infobufs(struct drm_device *dev, void *data, 1217 struct drm_file *file_priv); 1218 int drm_markbufs(struct drm_device *dev, void *data, 1219 struct drm_file *file_priv); 1220 int drm_freebufs(struct drm_device *dev, void *data, 1221 struct drm_file *file_priv); 1222 int drm_mapbufs(struct drm_device *dev, void *data, 1223 struct drm_file *file_priv); 1224 1225 /* DMA support (drm_dma.c) */ 1226 int drm_dma(struct drm_device *dev, void *data, struct drm_file *file_priv); 1227 1228 /* IRQ support (drm_irq.c) */ 1229 int drm_control(struct drm_device *dev, void *data, 1230 struct drm_file *file_priv); 1231 1232 /* AGP/GART support (drm_agpsupport.c) */ 1233 int drm_agp_acquire_ioctl(struct drm_device *dev, void *data, 1234 struct drm_file *file_priv); 1235 int drm_agp_release_ioctl(struct drm_device *dev, void *data, 1236 struct drm_file *file_priv); 1237 int drm_agp_enable_ioctl(struct drm_device *dev, void *data, 1238 struct drm_file *file_priv); 1239 int drm_agp_info_ioctl(struct drm_device *dev, void *data, 1240 struct drm_file *file_priv); 1241 int drm_agp_alloc_ioctl(struct drm_device *dev, void *data, 1242 struct drm_file *file_priv); 1243 int drm_agp_free_ioctl(struct drm_device *dev, void *data, 1244 struct drm_file *file_priv); 1245 int drm_agp_unbind_ioctl(struct drm_device *dev, void *data, 1246 struct drm_file *file_priv); 1247 int drm_agp_bind_ioctl(struct drm_device *dev, void *data, 1248 struct drm_file *file_priv); 1249 1250 /* Stub support (drm_stub.h) */ 1251 extern int drm_setmaster_ioctl(struct drm_device *dev, void *data, 1252 struct drm_file *file_priv); 1253 extern int drm_dropmaster_ioctl(struct drm_device *dev, void *data, 1254 struct drm_file *file_priv); 1255 1256 /* Scatter Gather Support (drm_scatter.c) */ 1257 int drm_sg_alloc_ioctl(struct drm_device *dev, void *data, 1258 struct drm_file *file_priv); 1259 int drm_sg_free(struct drm_device *dev, void *data, 1260 struct drm_file *file_priv); 1261 1262 /* consistent PCI memory functions (drm_pci.c) */ 1263 drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size, 1264 size_t align, dma_addr_t maxaddr); 1265 void drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah); 1266 1267 /* Graphics Execution Manager library functions (drm_gem.c) */ 1268 int drm_gem_init(struct drm_device *dev); 1269 void drm_gem_destroy(struct drm_device *dev); 1270 1271 int drm_gem_close_ioctl(struct drm_device *dev, void *data, 1272 struct drm_file *file_priv); 1273 int drm_gem_flink_ioctl(struct drm_device *dev, void *data, 1274 struct drm_file *file_priv); 1275 int drm_gem_open_ioctl(struct drm_device *dev, void *data, 1276 struct drm_file *file_priv); 1277 int drm_gem_handle_create(struct drm_file *file_priv, 1278 struct drm_gem_object *obj, 1279 u32 *handlep); 1280 int drm_gem_handle_delete(struct drm_file *file_priv, uint32_t handle); 1281 void drm_gem_object_handle_reference(struct drm_gem_object *obj); 1282 void drm_gem_object_handle_unreference(struct drm_gem_object *obj); 1283 void drm_gem_object_handle_unreference_unlocked(struct drm_gem_object *obj); 1284 void drm_gem_object_handle_free(struct drm_gem_object *obj); 1285 void drm_gem_object_reference(struct drm_gem_object *obj); 1286 void drm_gem_object_unreference(struct drm_gem_object *obj); 1287 void drm_gem_object_unreference_unlocked(struct drm_gem_object *obj); 1288 void drm_gem_object_release(struct drm_gem_object *obj); 1289 void drm_gem_object_free(struct drm_gem_object *obj); 1290 int drm_gem_object_init(struct drm_device *dev, struct drm_gem_object *obj, 1291 size_t size); 1292 int drm_gem_private_object_init(struct drm_device *dev, 1293 struct drm_gem_object *obj, size_t size); 1294 struct drm_gem_object *drm_gem_object_alloc(struct drm_device *dev, 1295 size_t size); 1296 struct drm_gem_object *drm_gem_object_lookup(struct drm_device *dev, 1297 struct drm_file *file_priv, uint32_t handle); 1298 1299 void drm_gem_open(struct drm_device *dev, struct drm_file *file_priv); 1300 void drm_gem_release(struct drm_device *dev, struct drm_file *file_priv); 1301 1302 int drm_gem_create_mmap_offset(struct drm_gem_object *obj); 1303 void drm_gem_free_mmap_offset(struct drm_gem_object *obj); 1304 int drm_gem_mmap_single(struct cdev *kdev, vm_ooffset_t *offset, vm_size_t size, 1305 struct vm_object **obj_res, int nprot); 1306 void drm_gem_pager_dtr(void *obj); 1307 1308 void drm_device_lock_mtx(struct drm_device *dev); 1309 void drm_device_unlock_mtx(struct drm_device *dev); 1310 int drm_device_sleep_mtx(struct drm_device *dev, void *chan, int flags, 1311 const char *msg, int timeout); 1312 void drm_device_assert_mtx_locked(struct drm_device *dev); 1313 void drm_device_assert_mtx_unlocked(struct drm_device *dev); 1314 1315 void drm_device_lock_struct(struct drm_device *dev); 1316 void drm_device_unlock_struct(struct drm_device *dev); 1317 int drm_device_sleep_struct(struct drm_device *dev, void *chan, int flags, 1318 const char *msg, int timeout); 1319 void drm_device_assert_struct_locked(struct drm_device *dev); 1320 void drm_device_assert_struct_unlocked(struct drm_device *dev); 1321 1322 void drm_compat_locking_init(struct drm_device *dev); 1323 void drm_sleep_locking_init(struct drm_device *dev); 1324 1325 /* drm_modes.c */ 1326 bool drm_mode_parse_command_line_for_connector(const char *mode_option, 1327 struct drm_connector *connector, struct drm_cmdline_mode *mode); 1328 struct drm_display_mode *drm_mode_create_from_cmdline_mode( 1329 struct drm_device *dev, struct drm_cmdline_mode *cmd); 1330 1331 /* drm_edid.c */ 1332 u8 *drm_find_cea_extension(struct edid *edid); 1333 1334 /* Inline replacements for drm_alloc and friends */ 1335 static __inline__ void * 1336 drm_alloc(size_t size, struct malloc_type *area) 1337 { 1338 return malloc(size, area, M_NOWAIT); 1339 } 1340 1341 static __inline__ void * 1342 drm_calloc(size_t nmemb, size_t size, struct malloc_type *area) 1343 { 1344 return malloc(size * nmemb, area, M_NOWAIT | M_ZERO); 1345 } 1346 1347 static __inline__ void * 1348 drm_realloc(void *oldpt, size_t oldsize, size_t size, 1349 struct malloc_type *area) 1350 { 1351 return reallocf(oldpt, size, area, M_NOWAIT); 1352 } 1353 1354 static __inline__ void 1355 drm_free(void *pt, size_t size, struct malloc_type *area) 1356 { 1357 free(pt, area); 1358 } 1359 1360 /* Inline replacements for DRM_IOREMAP macros */ 1361 static __inline__ void 1362 drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev) 1363 { 1364 map->virtual = drm_ioremap_wc(dev, map); 1365 } 1366 static __inline__ void 1367 drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev) 1368 { 1369 map->virtual = drm_ioremap(dev, map); 1370 } 1371 static __inline__ void 1372 drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev) 1373 { 1374 if ( map->virtual && map->size ) 1375 drm_ioremapfree(map); 1376 } 1377 1378 static __inline__ struct drm_local_map * 1379 drm_core_findmap(struct drm_device *dev, unsigned long offset) 1380 { 1381 drm_local_map_t *map; 1382 1383 DRM_LOCK_ASSERT(dev); 1384 TAILQ_FOREACH(map, &dev->maplist, link) { 1385 if (offset == (unsigned long)map->handle) 1386 return map; 1387 } 1388 return NULL; 1389 } 1390 1391 static __inline__ void drm_core_dropmap(struct drm_map *map) 1392 { 1393 } 1394 1395 #define KIB_NOTYET() \ 1396 do { \ 1397 if (drm_debug_flag && drm_notyet_flag) \ 1398 printf("NOTYET: %s at %s:%d\n", __func__, __FILE__, __LINE__); \ 1399 } while (0) 1400 1401 #define KTR_DRM KTR_DEV 1402 #define KTR_DRM_REG KTR_SPARE3 1403 1404 #endif /* __KERNEL__ */ 1405 #endif /* _DRM_P_H_ */ 1406