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