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