drmP.h revision 196466
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/drm/drmP.h 196466 2009-08-23 14:33:12Z rnoland $"); 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/module.h> 50#include <sys/systm.h> 51#include <sys/conf.h> 52#include <sys/stat.h> 53#if __FreeBSD_version >= 700000 54#include <sys/priv.h> 55#endif 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/sysctl.h> 62#include <sys/bus.h> 63#include <sys/signalvar.h> 64#include <sys/poll.h> 65#include <sys/tree.h> 66#include <vm/vm.h> 67#include <vm/pmap.h> 68#include <vm/vm_extern.h> 69#include <vm/vm_map.h> 70#include <vm/vm_param.h> 71#include <machine/param.h> 72#include <machine/pmap.h> 73#include <machine/bus.h> 74#include <machine/resource.h> 75#include <machine/specialreg.h> 76#include <machine/sysarch.h> 77#include <sys/endian.h> 78#include <sys/mman.h> 79#include <sys/rman.h> 80#include <sys/memrange.h> 81#if __FreeBSD_version >= 800004 82#include <dev/agp/agpvar.h> 83#else /* __FreeBSD_version >= 800004 */ 84#include <pci/agpvar.h> 85#endif /* __FreeBSD_version >= 800004 */ 86#include <sys/agpio.h> 87#include <sys/mutex.h> 88#include <dev/pci/pcivar.h> 89#include <dev/pci/pcireg.h> 90#include <sys/selinfo.h> 91#include <sys/bus.h> 92 93#include "dev/drm/drm.h" 94#include "dev/drm/drm_linux_list.h" 95#include "dev/drm/drm_atomic.h" 96#include "dev/drm/drm_internal.h" 97 98#include <opt_drm.h> 99#ifdef DRM_DEBUG 100#undef DRM_DEBUG 101#define DRM_DEBUG_DEFAULT_ON 1 102#endif /* DRM_DEBUG */ 103 104#if defined(DRM_LINUX) && DRM_LINUX && !defined(__amd64__) 105#include <sys/file.h> 106#include <sys/proc.h> 107#include <machine/../linux/linux.h> 108#include <machine/../linux/linux_proto.h> 109#else 110/* Either it was defined when it shouldn't be (FreeBSD amd64) or it isn't 111 * supported on this OS yet. 112 */ 113#undef DRM_LINUX 114#define DRM_LINUX 0 115#endif 116 117/* driver capabilities and requirements mask */ 118#define DRIVER_USE_AGP 0x1 119#define DRIVER_REQUIRE_AGP 0x2 120#define DRIVER_USE_MTRR 0x4 121#define DRIVER_PCI_DMA 0x8 122#define DRIVER_SG 0x10 123#define DRIVER_HAVE_DMA 0x20 124#define DRIVER_HAVE_IRQ 0x40 125#define DRIVER_DMA_QUEUE 0x100 126 127 128#define DRM_HASH_SIZE 16 /* Size of key hash table */ 129#define DRM_KERNEL_CONTEXT 0 /* Change drm_resctx if changed */ 130#define DRM_RESERVED_CONTEXTS 1 /* Change drm_resctx if changed */ 131 132MALLOC_DECLARE(DRM_MEM_DMA); 133MALLOC_DECLARE(DRM_MEM_SAREA); 134MALLOC_DECLARE(DRM_MEM_DRIVER); 135MALLOC_DECLARE(DRM_MEM_MAGIC); 136MALLOC_DECLARE(DRM_MEM_IOCTLS); 137MALLOC_DECLARE(DRM_MEM_MAPS); 138MALLOC_DECLARE(DRM_MEM_BUFS); 139MALLOC_DECLARE(DRM_MEM_SEGS); 140MALLOC_DECLARE(DRM_MEM_PAGES); 141MALLOC_DECLARE(DRM_MEM_FILES); 142MALLOC_DECLARE(DRM_MEM_QUEUES); 143MALLOC_DECLARE(DRM_MEM_CMDS); 144MALLOC_DECLARE(DRM_MEM_MAPPINGS); 145MALLOC_DECLARE(DRM_MEM_BUFLISTS); 146MALLOC_DECLARE(DRM_MEM_AGPLISTS); 147MALLOC_DECLARE(DRM_MEM_CTXBITMAP); 148MALLOC_DECLARE(DRM_MEM_SGLISTS); 149MALLOC_DECLARE(DRM_MEM_DRAWABLE); 150 151SYSCTL_DECL(_hw_drm); 152 153#define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8) 154 155 /* Internal types and structures */ 156#define DRM_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) 157#define DRM_MIN(a,b) ((a)<(b)?(a):(b)) 158#define DRM_MAX(a,b) ((a)>(b)?(a):(b)) 159 160#define DRM_IF_VERSION(maj, min) (maj << 16 | min) 161 162#define __OS_HAS_AGP 1 163 164#define DRM_DEV_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) 165#define DRM_DEV_UID 0 166#define DRM_DEV_GID 0 167 168#define wait_queue_head_t atomic_t 169#define DRM_WAKEUP(w) wakeup((void *)w) 170#define DRM_WAKEUP_INT(w) wakeup(w) 171#define DRM_INIT_WAITQUEUE(queue) do {(void)(queue);} while (0) 172 173#define DRM_CURPROC curthread 174#define DRM_STRUCTPROC struct thread 175#define DRM_SPINTYPE struct mtx 176#define DRM_SPININIT(l,name) mtx_init(l, name, NULL, MTX_DEF) 177#define DRM_SPINUNINIT(l) mtx_destroy(l) 178#define DRM_SPINLOCK(l) mtx_lock(l) 179#define DRM_SPINUNLOCK(u) mtx_unlock(u) 180#define DRM_SPINLOCK_IRQSAVE(l, irqflags) do { \ 181 mtx_lock(l); \ 182 (void)irqflags; \ 183} while (0) 184#define DRM_SPINUNLOCK_IRQRESTORE(u, irqflags) mtx_unlock(u) 185#define DRM_SPINLOCK_ASSERT(l) mtx_assert(l, MA_OWNED) 186#define DRM_CURRENTPID curthread->td_proc->p_pid 187#define DRM_LOCK() mtx_lock(&dev->dev_lock) 188#define DRM_UNLOCK() mtx_unlock(&dev->dev_lock) 189#define DRM_SYSCTL_HANDLER_ARGS (SYSCTL_HANDLER_ARGS) 190 191#define DRM_IRQ_ARGS void *arg 192typedef void irqreturn_t; 193#define IRQ_HANDLED /* nothing */ 194#define IRQ_NONE /* nothing */ 195 196enum { 197 DRM_IS_NOT_AGP, 198 DRM_IS_AGP, 199 DRM_MIGHT_BE_AGP 200}; 201#define DRM_AGP_MEM struct agp_memory_info 202 203#define drm_get_device_from_kdev(_kdev) (_kdev->si_drv1) 204 205#define PAGE_ALIGN(addr) round_page(addr) 206/* DRM_SUSER returns true if the user is superuser */ 207#if __FreeBSD_version >= 700000 208#define DRM_SUSER(p) (priv_check(p, PRIV_DRIVER) == 0) 209#else 210#define DRM_SUSER(p) (suser(p) == 0) 211#endif 212#define DRM_AGP_FIND_DEVICE() agp_find_device() 213#define DRM_MTRR_WC MDF_WRITECOMBINE 214#define jiffies ticks 215 216typedef unsigned long dma_addr_t; 217typedef u_int64_t u64; 218typedef u_int32_t u32; 219typedef u_int16_t u16; 220typedef u_int8_t u8; 221 222/* DRM_READMEMORYBARRIER() prevents reordering of reads. 223 * DRM_WRITEMEMORYBARRIER() prevents reordering of writes. 224 * DRM_MEMORYBARRIER() prevents reordering of reads and writes. 225 */ 226#if defined(__i386__) 227#define DRM_READMEMORYBARRIER() __asm __volatile( \ 228 "lock; addl $0,0(%%esp)" : : : "memory"); 229#define DRM_WRITEMEMORYBARRIER() __asm __volatile("" : : : "memory"); 230#define DRM_MEMORYBARRIER() __asm __volatile( \ 231 "lock; addl $0,0(%%esp)" : : : "memory"); 232#elif defined(__alpha__) 233#define DRM_READMEMORYBARRIER() alpha_mb(); 234#define DRM_WRITEMEMORYBARRIER() alpha_wmb(); 235#define DRM_MEMORYBARRIER() alpha_mb(); 236#elif defined(__amd64__) 237#define DRM_READMEMORYBARRIER() __asm __volatile( \ 238 "lock; addl $0,0(%%rsp)" : : : "memory"); 239#define DRM_WRITEMEMORYBARRIER() __asm __volatile("" : : : "memory"); 240#define DRM_MEMORYBARRIER() __asm __volatile( \ 241 "lock; addl $0,0(%%rsp)" : : : "memory"); 242#endif 243 244#define DRM_READ8(map, offset) \ 245 *(volatile u_int8_t *)(((vm_offset_t)(map)->handle) + \ 246 (vm_offset_t)(offset)) 247#define DRM_READ16(map, offset) \ 248 *(volatile u_int16_t *)(((vm_offset_t)(map)->handle) + \ 249 (vm_offset_t)(offset)) 250#define DRM_READ32(map, offset) \ 251 *(volatile u_int32_t *)(((vm_offset_t)(map)->handle) + \ 252 (vm_offset_t)(offset)) 253#define DRM_WRITE8(map, offset, val) \ 254 *(volatile u_int8_t *)(((vm_offset_t)(map)->handle) + \ 255 (vm_offset_t)(offset)) = val 256#define DRM_WRITE16(map, offset, val) \ 257 *(volatile u_int16_t *)(((vm_offset_t)(map)->handle) + \ 258 (vm_offset_t)(offset)) = val 259#define DRM_WRITE32(map, offset, val) \ 260 *(volatile u_int32_t *)(((vm_offset_t)(map)->handle) + \ 261 (vm_offset_t)(offset)) = val 262 263#define DRM_VERIFYAREA_READ( uaddr, size ) \ 264 (!useracc(__DECONST(caddr_t, uaddr), size, VM_PROT_READ)) 265 266#define DRM_COPY_TO_USER(user, kern, size) \ 267 copyout(kern, user, size) 268#define DRM_COPY_FROM_USER(kern, user, size) \ 269 copyin(user, kern, size) 270#define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) \ 271 copyin(arg2, arg1, arg3) 272#define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3) \ 273 copyout(arg2, arg1, arg3) 274#define DRM_GET_USER_UNCHECKED(val, uaddr) \ 275 ((val) = fuword32(uaddr), 0) 276 277#define cpu_to_le32(x) htole32(x) 278#define le32_to_cpu(x) le32toh(x) 279 280#define DRM_HZ hz 281#define DRM_UDELAY(udelay) DELAY(udelay) 282#define DRM_TIME_SLICE (hz/20) /* Time slice for GLXContexts */ 283 284#define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \ 285 (_map) = (_dev)->context_sareas[_ctx]; \ 286} while(0) 287 288#define LOCK_TEST_WITH_RETURN(dev, file_priv) \ 289do { \ 290 if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) || \ 291 dev->lock.file_priv != file_priv) { \ 292 DRM_ERROR("%s called without lock held\n", \ 293 __FUNCTION__); \ 294 return EINVAL; \ 295 } \ 296} while (0) 297 298/* Returns -errno to shared code */ 299#define DRM_WAIT_ON( ret, queue, timeout, condition ) \ 300for ( ret = 0 ; !ret && !(condition) ; ) { \ 301 DRM_UNLOCK(); \ 302 mtx_lock(&dev->irq_lock); \ 303 if (!(condition)) \ 304 ret = -mtx_sleep(&(queue), &dev->irq_lock, \ 305 PCATCH, "drmwtq", (timeout)); \ 306 mtx_unlock(&dev->irq_lock); \ 307 DRM_LOCK(); \ 308} 309 310#define DRM_ERROR(fmt, ...) \ 311 printf("error: [" DRM_NAME ":pid%d:%s] *ERROR* " fmt, \ 312 DRM_CURRENTPID, __func__ , ##__VA_ARGS__) 313 314#define DRM_INFO(fmt, ...) printf("info: [" DRM_NAME "] " fmt , ##__VA_ARGS__) 315 316#define DRM_DEBUG(fmt, ...) do { \ 317 if (drm_debug_flag) \ 318 printf("[" DRM_NAME ":pid%d:%s] " fmt, DRM_CURRENTPID, \ 319 __func__ , ##__VA_ARGS__); \ 320} while (0) 321 322typedef struct drm_pci_id_list 323{ 324 int vendor; 325 int device; 326 long driver_private; 327 char *name; 328} drm_pci_id_list_t; 329 330struct drm_msi_blacklist_entry 331{ 332 int vendor; 333 int device; 334}; 335 336#define DRM_AUTH 0x1 337#define DRM_MASTER 0x2 338#define DRM_ROOT_ONLY 0x4 339typedef struct drm_ioctl_desc { 340 unsigned long cmd; 341 int (*func)(struct drm_device *dev, void *data, 342 struct drm_file *file_priv); 343 int flags; 344} drm_ioctl_desc_t; 345/** 346 * Creates a driver or general drm_ioctl_desc array entry for the given 347 * ioctl, for use by drm_ioctl(). 348 */ 349#define DRM_IOCTL_DEF(ioctl, func, flags) \ 350 [DRM_IOCTL_NR(ioctl)] = {ioctl, func, flags} 351 352typedef struct drm_magic_entry { 353 drm_magic_t magic; 354 struct drm_file *priv; 355 struct drm_magic_entry *next; 356} drm_magic_entry_t; 357 358typedef struct drm_magic_head { 359 struct drm_magic_entry *head; 360 struct drm_magic_entry *tail; 361} drm_magic_head_t; 362 363typedef struct drm_buf { 364 int idx; /* Index into master buflist */ 365 int total; /* Buffer size */ 366 int order; /* log-base-2(total) */ 367 int used; /* Amount of buffer in use (for DMA) */ 368 unsigned long offset; /* Byte offset (used internally) */ 369 void *address; /* Address of buffer */ 370 unsigned long bus_address; /* Bus address of buffer */ 371 struct drm_buf *next; /* Kernel-only: used for free list */ 372 __volatile__ int pending; /* On hardware DMA queue */ 373 struct drm_file *file_priv; /* Unique identifier of holding process */ 374 int context; /* Kernel queue for this buffer */ 375 enum { 376 DRM_LIST_NONE = 0, 377 DRM_LIST_FREE = 1, 378 DRM_LIST_WAIT = 2, 379 DRM_LIST_PEND = 3, 380 DRM_LIST_PRIO = 4, 381 DRM_LIST_RECLAIM = 5 382 } list; /* Which list we're on */ 383 384 int dev_priv_size; /* Size of buffer private stoarge */ 385 void *dev_private; /* Per-buffer private storage */ 386} drm_buf_t; 387 388typedef struct drm_freelist { 389 int initialized; /* Freelist in use */ 390 atomic_t count; /* Number of free buffers */ 391 drm_buf_t *next; /* End pointer */ 392 393 int low_mark; /* Low water mark */ 394 int high_mark; /* High water mark */ 395} drm_freelist_t; 396 397typedef struct drm_dma_handle { 398 void *vaddr; 399 bus_addr_t busaddr; 400 bus_dma_tag_t tag; 401 bus_dmamap_t map; 402} drm_dma_handle_t; 403 404typedef struct drm_buf_entry { 405 int buf_size; 406 int buf_count; 407 drm_buf_t *buflist; 408 int seg_count; 409 drm_dma_handle_t **seglist; 410 int page_order; 411 412 drm_freelist_t freelist; 413} drm_buf_entry_t; 414 415typedef TAILQ_HEAD(drm_file_list, drm_file) drm_file_list_t; 416struct drm_file { 417 TAILQ_ENTRY(drm_file) link; 418 struct drm_device *dev; 419 int authenticated; 420 int master; 421 pid_t pid; 422 uid_t uid; 423 drm_magic_t magic; 424 unsigned long ioctl_count; 425 void *driver_priv; 426}; 427 428typedef struct drm_lock_data { 429 struct drm_hw_lock *hw_lock; /* Hardware lock */ 430 struct drm_file *file_priv; /* Unique identifier of holding process (NULL is kernel)*/ 431 int lock_queue; /* Queue of blocked processes */ 432 unsigned long lock_time; /* Time of last lock in jiffies */ 433} drm_lock_data_t; 434 435/* This structure, in the struct drm_device, is always initialized while the 436 * device 437 * is open. dev->dma_lock protects the incrementing of dev->buf_use, which 438 * when set marks that no further bufs may be allocated until device teardown 439 * occurs (when the last open of the device has closed). The high/low 440 * watermarks of bufs are only touched by the X Server, and thus not 441 * concurrently accessed, so no locking is needed. 442 */ 443typedef struct drm_device_dma { 444 drm_buf_entry_t bufs[DRM_MAX_ORDER+1]; 445 int buf_count; 446 drm_buf_t **buflist; /* Vector of pointers info bufs */ 447 int seg_count; 448 int page_count; 449 unsigned long *pagelist; 450 unsigned long byte_count; 451 enum { 452 _DRM_DMA_USE_AGP = 0x01, 453 _DRM_DMA_USE_SG = 0x02 454 } flags; 455} drm_device_dma_t; 456 457typedef struct drm_agp_mem { 458 void *handle; 459 unsigned long bound; /* address */ 460 int pages; 461 struct drm_agp_mem *prev; 462 struct drm_agp_mem *next; 463} drm_agp_mem_t; 464 465typedef struct drm_agp_head { 466 device_t agpdev; 467 struct agp_info info; 468 const char *chipset; 469 drm_agp_mem_t *memory; 470 unsigned long mode; 471 int enabled; 472 int acquired; 473 unsigned long base; 474 int mtrr; 475 int cant_use_aperture; 476 unsigned long page_mask; 477} drm_agp_head_t; 478 479typedef struct drm_sg_mem { 480 unsigned long handle; 481 void *virtual; 482 int pages; 483 dma_addr_t *busaddr; 484 struct drm_dma_handle *dmah; /* Handle to PCI memory */ 485} drm_sg_mem_t; 486 487typedef TAILQ_HEAD(drm_map_list, drm_local_map) drm_map_list_t; 488 489typedef struct drm_local_map { 490 unsigned long offset; /* Physical address (0 for SAREA)*/ 491 unsigned long size; /* Physical size (bytes) */ 492 enum drm_map_type type; /* Type of memory mapped */ 493 enum drm_map_flags flags; /* Flags */ 494 void *handle; /* User-space: "Handle" to pass to mmap */ 495 /* Kernel-space: kernel-virtual address */ 496 int mtrr; /* Boolean: MTRR used */ 497 /* Private data */ 498 int rid; /* PCI resource ID for bus_space */ 499 struct resource *bsr; 500 bus_space_tag_t bst; 501 bus_space_handle_t bsh; 502 drm_dma_handle_t *dmah; 503 TAILQ_ENTRY(drm_local_map) link; 504} drm_local_map_t; 505 506struct drm_vblank_info { 507 wait_queue_head_t queue; /* vblank wait queue */ 508 atomic_t count; /* number of VBLANK interrupts */ 509 /* (driver must alloc the right number of counters) */ 510 atomic_t refcount; /* number of users of vblank interrupts */ 511 u32 last; /* protected by dev->vbl_lock, used */ 512 /* for wraparound handling */ 513 int enabled; /* so we don't call enable more than */ 514 /* once per disable */ 515 int inmodeset; /* Display driver is setting mode */ 516}; 517 518/* location of GART table */ 519#define DRM_ATI_GART_MAIN 1 520#define DRM_ATI_GART_FB 2 521 522#define DRM_ATI_GART_PCI 1 523#define DRM_ATI_GART_PCIE 2 524#define DRM_ATI_GART_IGP 3 525 526struct drm_ati_pcigart_info { 527 int gart_table_location; 528 int gart_reg_if; 529 void *addr; 530 dma_addr_t bus_addr; 531 dma_addr_t table_mask; 532 dma_addr_t member_mask; 533 struct drm_dma_handle *table_handle; 534 drm_local_map_t mapping; 535 int table_size; 536 struct drm_dma_handle *dmah; /* handle for ATI PCIGART table */ 537}; 538 539#ifndef DMA_BIT_MASK 540#define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : (1ULL<<(n)) - 1) 541#endif 542 543#define upper_32_bits(n) ((u32)(((n) >> 16) >> 16)) 544 545struct drm_driver_info { 546 int (*load)(struct drm_device *, unsigned long flags); 547 int (*firstopen)(struct drm_device *); 548 int (*open)(struct drm_device *, struct drm_file *); 549 void (*preclose)(struct drm_device *, struct drm_file *file_priv); 550 void (*postclose)(struct drm_device *, struct drm_file *); 551 void (*lastclose)(struct drm_device *); 552 int (*unload)(struct drm_device *); 553 void (*reclaim_buffers_locked)(struct drm_device *, 554 struct drm_file *file_priv); 555 int (*dma_ioctl)(struct drm_device *dev, void *data, 556 struct drm_file *file_priv); 557 void (*dma_ready)(struct drm_device *); 558 int (*dma_quiescent)(struct drm_device *); 559 int (*dma_flush_block_and_flush)(struct drm_device *, int context, 560 enum drm_lock_flags flags); 561 int (*dma_flush_unblock)(struct drm_device *, int context, 562 enum drm_lock_flags flags); 563 int (*context_ctor)(struct drm_device *dev, int context); 564 int (*context_dtor)(struct drm_device *dev, int context); 565 int (*kernel_context_switch)(struct drm_device *dev, int old, 566 int new); 567 int (*kernel_context_switch_unlock)(struct drm_device *dev); 568 void (*irq_preinstall)(struct drm_device *dev); 569 int (*irq_postinstall)(struct drm_device *dev); 570 void (*irq_uninstall)(struct drm_device *dev); 571 void (*irq_handler)(DRM_IRQ_ARGS); 572 u32 (*get_vblank_counter)(struct drm_device *dev, int crtc); 573 int (*enable_vblank)(struct drm_device *dev, int crtc); 574 void (*disable_vblank)(struct drm_device *dev, int crtc); 575 576 drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */ 577 578 /** 579 * Called by \c drm_device_is_agp. Typically used to determine if a 580 * card is really attached to AGP or not. 581 * 582 * \param dev DRM device handle 583 * 584 * \returns 585 * One of three values is returned depending on whether or not the 586 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP 587 * (return of 1), or may or may not be AGP (return of 2). 588 */ 589 int (*device_is_agp) (struct drm_device * dev); 590 591 drm_ioctl_desc_t *ioctls; 592 int max_ioctl; 593 594 int buf_priv_size; 595 596 int major; 597 int minor; 598 int patchlevel; 599 const char *name; /* Simple driver name */ 600 const char *desc; /* Longer driver name */ 601 const char *date; /* Date of last major changes. */ 602 603 u32 driver_features; 604}; 605 606/* Length for the array of resource pointers for drm_get_resource_*. */ 607#define DRM_MAX_PCI_RESOURCE 6 608 609/** 610 * DRM device functions structure 611 */ 612struct drm_device { 613 struct drm_driver_info *driver; 614 drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */ 615 616 u_int16_t pci_device; /* PCI device id */ 617 u_int16_t pci_vendor; /* PCI vendor id */ 618 619 char *unique; /* Unique identifier: e.g., busid */ 620 int unique_len; /* Length of unique field */ 621 device_t device; /* Device instance from newbus */ 622 struct cdev *devnode; /* Device number for mknod */ 623 int if_version; /* Highest interface version set */ 624 625 int flags; /* Flags to open(2) */ 626 627 /* Locks */ 628 struct mtx vbl_lock; /* protects vblank operations */ 629 struct mtx dma_lock; /* protects dev->dma */ 630 struct mtx irq_lock; /* protects irq condition checks */ 631 struct mtx dev_lock; /* protects everything else */ 632 DRM_SPINTYPE drw_lock; 633 634 /* Usage Counters */ 635 int open_count; /* Outstanding files open */ 636 int buf_use; /* Buffers in use -- cannot alloc */ 637 638 /* Performance counters */ 639 unsigned long counters; 640 enum drm_stat_type types[15]; 641 atomic_t counts[15]; 642 643 /* Authentication */ 644 drm_file_list_t files; 645 drm_magic_head_t magiclist[DRM_HASH_SIZE]; 646 647 /* Linked list of mappable regions. Protected by dev_lock */ 648 drm_map_list_t maplist; 649 650 drm_local_map_t **context_sareas; 651 int max_context; 652 653 drm_lock_data_t lock; /* Information on hardware lock */ 654 655 /* DMA queues (contexts) */ 656 drm_device_dma_t *dma; /* Optional pointer for DMA support */ 657 658 /* Context support */ 659 int irq; /* Interrupt used by board */ 660 int irq_enabled; /* True if the irq handler is enabled */ 661 int msi_enabled; /* MSI enabled */ 662 int irqrid; /* Interrupt used by board */ 663 struct resource *irqr; /* Resource for interrupt used by board */ 664 void *irqh; /* Handle from bus_setup_intr */ 665 666 /* Storage of resource pointers for drm_get_resource_* */ 667 struct resource *pcir[DRM_MAX_PCI_RESOURCE]; 668 int pcirid[DRM_MAX_PCI_RESOURCE]; 669 670 int pci_domain; 671 int pci_bus; 672 int pci_slot; 673 int pci_func; 674 675 atomic_t context_flag; /* Context swapping flag */ 676 int last_context; /* Last current context */ 677 678 int vblank_disable_allowed; 679 struct callout vblank_disable_timer; 680 u32 max_vblank_count; /* size of vblank counter register */ 681 struct drm_vblank_info *vblank; /* per crtc vblank info */ 682 int num_crtcs; 683 684 struct sigio *buf_sigio; /* Processes waiting for SIGIO */ 685 686 /* Sysctl support */ 687 struct drm_sysctl_info *sysctl; 688 689 drm_agp_head_t *agp; 690 drm_sg_mem_t *sg; /* Scatter gather memory */ 691 atomic_t *ctx_bitmap; 692 void *dev_private; 693 unsigned int agp_buffer_token; 694 drm_local_map_t *agp_buffer_map; 695 696 struct unrhdr *drw_unrhdr; 697 /* RB tree of drawable infos */ 698 RB_HEAD(drawable_tree, bsd_drm_drawable_info) drw_head; 699}; 700 701static __inline__ int drm_core_check_feature(struct drm_device *dev, 702 int feature) 703{ 704 return ((dev->driver->driver_features & feature) ? 1 : 0); 705} 706 707#if __OS_HAS_AGP 708static inline int drm_core_has_AGP(struct drm_device *dev) 709{ 710 return drm_core_check_feature(dev, DRIVER_USE_AGP); 711} 712#else 713#define drm_core_has_AGP(dev) (0) 714#endif 715 716extern int drm_debug_flag; 717 718/* Device setup support (drm_drv.c) */ 719int drm_probe(device_t kdev, drm_pci_id_list_t *idlist); 720int drm_attach(device_t kdev, drm_pci_id_list_t *idlist); 721void drm_close(void *data); 722int drm_detach(device_t kdev); 723d_ioctl_t drm_ioctl; 724d_open_t drm_open; 725d_read_t drm_read; 726d_poll_t drm_poll; 727d_mmap_t drm_mmap; 728extern drm_local_map_t *drm_getsarea(struct drm_device *dev); 729 730/* File operations helpers (drm_fops.c) */ 731extern int drm_open_helper(struct cdev *kdev, int flags, int fmt, 732 DRM_STRUCTPROC *p, 733 struct drm_device *dev); 734 735/* Memory management support (drm_memory.c) */ 736void drm_mem_init(void); 737void drm_mem_uninit(void); 738void *drm_ioremap_wc(struct drm_device *dev, drm_local_map_t *map); 739void *drm_ioremap(struct drm_device *dev, drm_local_map_t *map); 740void drm_ioremapfree(drm_local_map_t *map); 741int drm_mtrr_add(unsigned long offset, size_t size, int flags); 742int drm_mtrr_del(int handle, unsigned long offset, size_t size, int flags); 743 744int drm_context_switch(struct drm_device *dev, int old, int new); 745int drm_context_switch_complete(struct drm_device *dev, int new); 746 747int drm_ctxbitmap_init(struct drm_device *dev); 748void drm_ctxbitmap_cleanup(struct drm_device *dev); 749void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle); 750int drm_ctxbitmap_next(struct drm_device *dev); 751 752/* Locking IOCTL support (drm_lock.c) */ 753int drm_lock_take(struct drm_lock_data *lock_data, 754 unsigned int context); 755int drm_lock_transfer(struct drm_lock_data *lock_data, 756 unsigned int context); 757int drm_lock_free(struct drm_lock_data *lock_data, 758 unsigned int context); 759 760/* Buffer management support (drm_bufs.c) */ 761unsigned long drm_get_resource_start(struct drm_device *dev, 762 unsigned int resource); 763unsigned long drm_get_resource_len(struct drm_device *dev, 764 unsigned int resource); 765void drm_rmmap(struct drm_device *dev, drm_local_map_t *map); 766int drm_order(unsigned long size); 767int drm_addmap(struct drm_device *dev, unsigned long offset, 768 unsigned long size, 769 enum drm_map_type type, enum drm_map_flags flags, 770 drm_local_map_t **map_ptr); 771int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc *request); 772int drm_addbufs_sg(struct drm_device *dev, struct drm_buf_desc *request); 773int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc *request); 774 775/* DMA support (drm_dma.c) */ 776int drm_dma_setup(struct drm_device *dev); 777void drm_dma_takedown(struct drm_device *dev); 778void drm_free_buffer(struct drm_device *dev, drm_buf_t *buf); 779void drm_reclaim_buffers(struct drm_device *dev, struct drm_file *file_priv); 780#define drm_core_reclaim_buffers drm_reclaim_buffers 781 782/* IRQ support (drm_irq.c) */ 783int drm_irq_install(struct drm_device *dev); 784int drm_irq_uninstall(struct drm_device *dev); 785irqreturn_t drm_irq_handler(DRM_IRQ_ARGS); 786void drm_driver_irq_preinstall(struct drm_device *dev); 787void drm_driver_irq_postinstall(struct drm_device *dev); 788void drm_driver_irq_uninstall(struct drm_device *dev); 789void drm_handle_vblank(struct drm_device *dev, int crtc); 790u32 drm_vblank_count(struct drm_device *dev, int crtc); 791int drm_vblank_get(struct drm_device *dev, int crtc); 792void drm_vblank_put(struct drm_device *dev, int crtc); 793void drm_vblank_cleanup(struct drm_device *dev); 794int drm_vblank_wait(struct drm_device *dev, unsigned int *vbl_seq); 795int drm_vblank_init(struct drm_device *dev, int num_crtcs); 796int drm_modeset_ctl(struct drm_device *dev, void *data, 797 struct drm_file *file_priv); 798 799/* AGP/PCI Express/GART support (drm_agpsupport.c) */ 800int drm_device_is_agp(struct drm_device *dev); 801int drm_device_is_pcie(struct drm_device *dev); 802drm_agp_head_t *drm_agp_init(void); 803int drm_agp_acquire(struct drm_device *dev); 804int drm_agp_release(struct drm_device *dev); 805int drm_agp_info(struct drm_device * dev, struct drm_agp_info *info); 806int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode); 807void *drm_agp_allocate_memory(size_t pages, u32 type); 808int drm_agp_free_memory(void *handle); 809int drm_agp_bind_memory(void *handle, off_t start); 810int drm_agp_unbind_memory(void *handle); 811int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request); 812int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request); 813int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request); 814int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request); 815 816/* Scatter Gather Support (drm_scatter.c) */ 817void drm_sg_cleanup(drm_sg_mem_t *entry); 818int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request); 819 820/* sysctl support (drm_sysctl.h) */ 821extern int drm_sysctl_init(struct drm_device *dev); 822extern int drm_sysctl_cleanup(struct drm_device *dev); 823 824/* ATI PCIGART support (ati_pcigart.c) */ 825int drm_ati_pcigart_init(struct drm_device *dev, 826 struct drm_ati_pcigart_info *gart_info); 827int drm_ati_pcigart_cleanup(struct drm_device *dev, 828 struct drm_ati_pcigart_info *gart_info); 829 830/* Locking IOCTL support (drm_drv.c) */ 831int drm_lock(struct drm_device *dev, void *data, 832 struct drm_file *file_priv); 833int drm_unlock(struct drm_device *dev, void *data, 834 struct drm_file *file_priv); 835int drm_version(struct drm_device *dev, void *data, 836 struct drm_file *file_priv); 837int drm_setversion(struct drm_device *dev, void *data, 838 struct drm_file *file_priv); 839 840/* Misc. IOCTL support (drm_ioctl.c) */ 841int drm_irq_by_busid(struct drm_device *dev, void *data, 842 struct drm_file *file_priv); 843int drm_getunique(struct drm_device *dev, void *data, 844 struct drm_file *file_priv); 845int drm_setunique(struct drm_device *dev, void *data, 846 struct drm_file *file_priv); 847int drm_getmap(struct drm_device *dev, void *data, 848 struct drm_file *file_priv); 849int drm_getclient(struct drm_device *dev, void *data, 850 struct drm_file *file_priv); 851int drm_getstats(struct drm_device *dev, void *data, 852 struct drm_file *file_priv); 853int drm_noop(struct drm_device *dev, void *data, 854 struct drm_file *file_priv); 855 856/* Context IOCTL support (drm_context.c) */ 857int drm_resctx(struct drm_device *dev, void *data, 858 struct drm_file *file_priv); 859int drm_addctx(struct drm_device *dev, void *data, 860 struct drm_file *file_priv); 861int drm_modctx(struct drm_device *dev, void *data, 862 struct drm_file *file_priv); 863int drm_getctx(struct drm_device *dev, void *data, 864 struct drm_file *file_priv); 865int drm_switchctx(struct drm_device *dev, void *data, 866 struct drm_file *file_priv); 867int drm_newctx(struct drm_device *dev, void *data, 868 struct drm_file *file_priv); 869int drm_rmctx(struct drm_device *dev, void *data, 870 struct drm_file *file_priv); 871int drm_setsareactx(struct drm_device *dev, void *data, 872 struct drm_file *file_priv); 873int drm_getsareactx(struct drm_device *dev, void *data, 874 struct drm_file *file_priv); 875 876/* Drawable IOCTL support (drm_drawable.c) */ 877int drm_adddraw(struct drm_device *dev, void *data, 878 struct drm_file *file_priv); 879int drm_rmdraw(struct drm_device *dev, void *data, 880 struct drm_file *file_priv); 881int drm_update_draw(struct drm_device *dev, void *data, 882 struct drm_file *file_priv); 883struct drm_drawable_info *drm_get_drawable_info(struct drm_device *dev, 884 int handle); 885 886/* Drawable support (drm_drawable.c) */ 887void drm_drawable_free_all(struct drm_device *dev); 888 889/* Authentication IOCTL support (drm_auth.c) */ 890int drm_getmagic(struct drm_device *dev, void *data, 891 struct drm_file *file_priv); 892int drm_authmagic(struct drm_device *dev, void *data, 893 struct drm_file *file_priv); 894 895/* Buffer management support (drm_bufs.c) */ 896int drm_addmap_ioctl(struct drm_device *dev, void *data, 897 struct drm_file *file_priv); 898int drm_rmmap_ioctl(struct drm_device *dev, void *data, 899 struct drm_file *file_priv); 900int drm_addbufs(struct drm_device *dev, void *data, 901 struct drm_file *file_priv); 902int drm_infobufs(struct drm_device *dev, void *data, 903 struct drm_file *file_priv); 904int drm_markbufs(struct drm_device *dev, void *data, 905 struct drm_file *file_priv); 906int drm_freebufs(struct drm_device *dev, void *data, 907 struct drm_file *file_priv); 908int drm_mapbufs(struct drm_device *dev, void *data, 909 struct drm_file *file_priv); 910 911/* DMA support (drm_dma.c) */ 912int drm_dma(struct drm_device *dev, void *data, struct drm_file *file_priv); 913 914/* IRQ support (drm_irq.c) */ 915int drm_control(struct drm_device *dev, void *data, 916 struct drm_file *file_priv); 917int drm_wait_vblank(struct drm_device *dev, void *data, 918 struct drm_file *file_priv); 919 920/* AGP/GART support (drm_agpsupport.c) */ 921int drm_agp_acquire_ioctl(struct drm_device *dev, void *data, 922 struct drm_file *file_priv); 923int drm_agp_release_ioctl(struct drm_device *dev, void *data, 924 struct drm_file *file_priv); 925int drm_agp_enable_ioctl(struct drm_device *dev, void *data, 926 struct drm_file *file_priv); 927int drm_agp_info_ioctl(struct drm_device *dev, void *data, 928 struct drm_file *file_priv); 929int drm_agp_alloc_ioctl(struct drm_device *dev, void *data, 930 struct drm_file *file_priv); 931int drm_agp_free_ioctl(struct drm_device *dev, void *data, 932 struct drm_file *file_priv); 933int drm_agp_unbind_ioctl(struct drm_device *dev, void *data, 934 struct drm_file *file_priv); 935int drm_agp_bind_ioctl(struct drm_device *dev, void *data, 936 struct drm_file *file_priv); 937 938/* Scatter Gather Support (drm_scatter.c) */ 939int drm_sg_alloc_ioctl(struct drm_device *dev, void *data, 940 struct drm_file *file_priv); 941int drm_sg_free(struct drm_device *dev, void *data, 942 struct drm_file *file_priv); 943 944/* consistent PCI memory functions (drm_pci.c) */ 945drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size, 946 size_t align, dma_addr_t maxaddr); 947void drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah); 948 949/* Inline replacements for drm_alloc and friends */ 950static __inline__ void * 951drm_alloc(size_t size, struct malloc_type *area) 952{ 953 return malloc(size, area, M_NOWAIT); 954} 955 956static __inline__ void * 957drm_calloc(size_t nmemb, size_t size, struct malloc_type *area) 958{ 959 return malloc(size * nmemb, area, M_NOWAIT | M_ZERO); 960} 961 962static __inline__ void * 963drm_realloc(void *oldpt, size_t oldsize, size_t size, 964 struct malloc_type *area) 965{ 966 return reallocf(oldpt, size, area, M_NOWAIT); 967} 968 969static __inline__ void 970drm_free(void *pt, size_t size, struct malloc_type *area) 971{ 972 free(pt, area); 973} 974 975/* Inline replacements for DRM_IOREMAP macros */ 976static __inline__ void 977drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev) 978{ 979 map->handle = drm_ioremap_wc(dev, map); 980} 981static __inline__ void 982drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev) 983{ 984 map->handle = drm_ioremap(dev, map); 985} 986static __inline__ void 987drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev) 988{ 989 if ( map->handle && map->size ) 990 drm_ioremapfree(map); 991} 992 993static __inline__ struct drm_local_map * 994drm_core_findmap(struct drm_device *dev, unsigned long offset) 995{ 996 drm_local_map_t *map; 997 998 DRM_SPINLOCK_ASSERT(&dev->dev_lock); 999 TAILQ_FOREACH(map, &dev->maplist, link) { 1000 if (map->offset == offset) 1001 return map; 1002 } 1003 return NULL; 1004} 1005 1006static __inline__ void drm_core_dropmap(struct drm_map *map) 1007{ 1008} 1009 1010#endif /* __KERNEL__ */ 1011#endif /* _DRM_P_H_ */ 1012