1 /** 2 * \file drmP.h 3 * Private header for Direct Rendering Manager 4 * 5 * \author Rickard E. (Rik) Faith <faith@valinux.com> 6 * \author Gareth Hughes <gareth@valinux.com> 7 */ 8 9 /* 10 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. 11 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 12 * Copyright (c) 2009-2010, Code Aurora Forum. 13 * All rights reserved. 14 * 15 * Permission is hereby granted, free of charge, to any person obtaining a 16 * copy of this software and associated documentation files (the "Software"), 17 * to deal in the Software without restriction, including without limitation 18 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 19 * and/or sell copies of the Software, and to permit persons to whom the 20 * Software is furnished to do so, subject to the following conditions: 21 * 22 * The above copyright notice and this permission notice (including the next 23 * paragraph) shall be included in all copies or substantial portions of the 24 * Software. 25 * 26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 29 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 30 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 31 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 32 * OTHER DEALINGS IN THE SOFTWARE. 33 */ 34 35 #ifndef _DRM_P_H_ 36 #define _DRM_P_H_ 37 38 #if defined(_KERNEL) || defined(__KERNEL__) 39 40 #include <sys/param.h> 41 #include <sys/queue.h> 42 #include <sys/malloc.h> 43 #include <sys/kernel.h> 44 #include <sys/ktr.h> 45 #include <sys/module.h> 46 #include <sys/systm.h> 47 #include <sys/device.h> 48 #include <sys/sglist.h> 49 #include <sys/stat.h> 50 #include <sys/priv.h> 51 #include <sys/proc.h> 52 #include <sys/lock.h> 53 #include <sys/spinlock.h> 54 #include <sys/spinlock2.h> 55 #include <sys/fcntl.h> 56 #include <sys/uio.h> 57 #include <sys/filio.h> 58 #include <sys/sysctl.h> 59 #include <sys/bus.h> 60 #include <sys/queue.h> 61 #include <sys/signalvar.h> 62 #include <sys/poll.h> 63 #include <sys/sbuf.h> 64 #include <sys/taskqueue.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_kern.h> 70 #include <vm/vm_map.h> 71 #include <vm/vm_object.h> 72 #include <vm/vm_page2.h> 73 #include <vm/vm_pager.h> 74 #include <vm/vm_param.h> 75 #include <machine/param.h> 76 #include <machine/pmap.h> 77 #if defined(__i386__) || defined(__amd64__) 78 #include <machine/specialreg.h> 79 #endif 80 #include <machine/sysarch.h> 81 #include <sys/endian.h> 82 #include <sys/mman.h> 83 #include <sys/rman.h> 84 #include <sys/memrange.h> 85 #include <dev/agp/agpvar.h> 86 #include <sys/agpio.h> 87 #include <sys/mutex.h> 88 89 MALLOC_DECLARE(M_DRM); 90 91 #include <uapi_drm/drm.h> 92 #include <uapi_drm/drm_sarea.h> 93 94 #include <linux/atomic.h> 95 #include <linux/bug.h> 96 #include <linux/err.h> 97 #include <linux/idr.h> 98 #include <linux/pci.h> 99 #include <linux/jiffies.h> 100 #include <linux/kernel.h> 101 #include <linux/kref.h> 102 #include <linux/list.h> 103 #include <linux/mm.h> 104 #include <linux/moduleparam.h> 105 #include <linux/mutex.h> 106 #include <linux/slab.h> 107 #include <linux/scatterlist.h> 108 #include <linux/timer.h> 109 #include <asm/io.h> 110 #include <linux/types.h> 111 #include <linux/wait.h> 112 #include <linux/workqueue.h> 113 114 #include <asm/uaccess.h> 115 116 #include <drm/drm_vma_manager.h> 117 118 struct drm_file; 119 struct drm_device; 120 121 #include <drm/drm_os_linux.h> 122 #include <drm/drm_hashtab.h> 123 #include <drm/drm_mm.h> 124 125 #define DRM_UT_CORE 0x01 126 #define DRM_UT_DRIVER 0x02 127 #define DRM_UT_KMS 0x04 128 #define DRM_UT_PRIME 0x08 129 130 #include "opt_drm.h" 131 #ifdef DRM_DEBUG 132 #undef DRM_DEBUG 133 #define DRM_DEBUG_DEFAULT_ON 1 134 #endif /* DRM_DEBUG */ 135 136 #define DRM_DEBUGBITS_DEBUG 0x1 137 #define DRM_DEBUGBITS_KMS 0x2 138 #define DRM_DEBUGBITS_FAILED_IOCTL 0x4 139 140 #undef DRM_LINUX 141 #define DRM_LINUX 0 142 143 /***********************************************************************/ 144 /** \name DRM template customization defaults */ 145 /*@{*/ 146 147 /* driver capabilities and requirements mask */ 148 #define DRIVER_USE_AGP 0x1 149 #define DRIVER_REQUIRE_AGP 0x2 150 #define DRIVER_PCI_DMA 0x8 151 #define DRIVER_SG 0x10 152 #define DRIVER_HAVE_DMA 0x20 153 #define DRIVER_HAVE_IRQ 0x40 154 #define DRIVER_IRQ_SHARED 0x80 155 #define DRIVER_IRQ_VBL 0x100 156 #define DRIVER_DMA_QUEUE 0x200 157 #define DRIVER_FB_DMA 0x400 158 #define DRIVER_IRQ_VBL2 0x800 159 #define DRIVER_GEM 0x1000 160 #define DRIVER_MODESET 0x2000 161 #define DRIVER_PRIME 0x4000 162 163 /***********************************************************************/ 164 /** \name Begin the DRM... */ 165 /*@{*/ 166 167 #define DRM_MAGIC_HASH_ORDER 4 /**< Size of key hash table. Must be power of 2. */ 168 #define DRM_KERNEL_CONTEXT 0 /* Change drm_resctx if changed */ 169 #define DRM_RESERVED_CONTEXTS 1 /* Change drm_resctx if changed */ 170 171 #define DRM_GEM_MAPPING_MASK (3ULL << 62) 172 #define DRM_GEM_MAPPING_KEY (2ULL << 62) /* Non-canonical address form */ 173 #define DRM_GEM_MAX_IDX 0x3fffff 174 #define DRM_GEM_MAPPING_IDX(o) (((o) >> 40) & DRM_GEM_MAX_IDX) 175 #define DRM_GEM_MAPPING_OFF(i) (((uint64_t)(i)) << 40) 176 #define DRM_GEM_MAPPING_MAPOFF(o) \ 177 ((o) & ~(DRM_GEM_MAPPING_OFF(DRM_GEM_MAX_IDX) | DRM_GEM_MAPPING_KEY)) 178 179 SYSCTL_DECL(_hw_drm); 180 181 #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8) 182 183 /***********************************************************************/ 184 /** \name Internal types and structures */ 185 /*@{*/ 186 187 #define DRM_ARRAY_SIZE(x) NELEM(x) 188 #define DRM_MIN(a,b) ((a)<(b)?(a):(b)) 189 #define DRM_MAX(a,b) ((a)>(b)?(a):(b)) 190 191 #define DRM_IF_VERSION(maj, min) (maj << 16 | min) 192 193 #define __OS_HAS_AGP 1 194 195 #define DRM_DEV_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) 196 #define DRM_DEV_UID 0 197 #define DRM_DEV_GID 0 198 199 #define DRM_WAKEUP(w) wakeup((void *)w) 200 #define DRM_WAKEUP_INT(w) wakeup(w) 201 #define DRM_INIT_WAITQUEUE(queue) do {(void)(queue);} while (0) 202 203 #define DRM_CURPROC curthread 204 #define DRM_STRUCTPROC struct thread 205 #define DRM_CURRENTPID (curproc != NULL ? curproc->p_pid : -1) 206 #define DRM_LOCK(dev) lockmgr(&(dev)->struct_mutex, LK_EXCLUSIVE) 207 #define DRM_UNLOCK(dev) lockmgr(&(dev)->struct_mutex, LK_RELEASE) 208 #define DRM_LOCK_SLEEP(dev, chan, flags, msg, timeout) \ 209 (lksleep((chan), &(dev)->struct_mutex, (flags), (msg), (timeout))) 210 #if defined(INVARIANTS) 211 #define DRM_LOCK_ASSERT(dev) KKASSERT(lockstatus(&(dev)->struct_mutex, curthread) != 0); 212 #define DRM_UNLOCK_ASSERT(dev) KKASSERT(lockstatus(&(dev)->struct_mutex, curthread) == 0); 213 #else 214 #define DRM_LOCK_ASSERT(d) 215 #define DRM_UNLOCK_ASSERT(d) 216 #endif 217 218 #define DRM_SYSCTL_HANDLER_ARGS (SYSCTL_HANDLER_ARGS) 219 220 #define DRM_IRQ_ARGS void *arg 221 typedef void irqreturn_t; 222 #define IRQ_HANDLED /* nothing */ 223 #define IRQ_NONE /* nothing */ 224 225 enum { 226 DRM_IS_NOT_AGP, 227 DRM_IS_AGP, 228 DRM_MIGHT_BE_AGP 229 }; 230 #define DRM_AGP_MEM struct agp_memory_info 231 232 #define drm_get_device_from_kdev(_kdev) (_kdev->si_drv1) 233 234 /* DRM_SUSER returns true if the user is superuser */ 235 #define DRM_SUSER(p) (priv_check(p, PRIV_DRIVER) == 0) 236 #define DRM_AGP_FIND_DEVICE() agp_find_device() 237 #define DRM_MTRR_WC MDF_WRITECOMBINE 238 239 /* DRM_READMEMORYBARRIER() prevents reordering of reads. 240 * DRM_WRITEMEMORYBARRIER() prevents reordering of writes. 241 * DRM_MEMORYBARRIER() prevents reordering of reads and writes. 242 */ 243 #define DRM_READMEMORYBARRIER() cpu_lfence() 244 #define DRM_WRITEMEMORYBARRIER() cpu_sfence() 245 #define DRM_MEMORYBARRIER() cpu_mfence() 246 247 #define DRM_VERIFYAREA_READ( uaddr, size ) \ 248 (!useracc(__DECONST(caddr_t, uaddr), size, VM_PROT_READ)) 249 250 #define DRM_COPY_TO_USER(user, kern, size) \ 251 copyout(kern, user, size) 252 #define DRM_COPY_FROM_USER(kern, user, size) \ 253 copyin(user, kern, size) 254 #define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) \ 255 copyin(arg2, arg1, arg3) 256 #define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3) \ 257 copyout(arg2, arg1, arg3) 258 #define DRM_GET_USER_UNCHECKED(val, uaddr) \ 259 ((val) = fuword32(uaddr), 0) 260 261 #define drm_can_sleep() (DRM_HZ & 1) 262 263 #define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \ 264 (_map) = (_dev)->context_sareas[_ctx]; \ 265 } while(0) 266 267 #define LOCK_TEST_WITH_RETURN(dev, file_priv) \ 268 do { \ 269 if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) || \ 270 dev->lock.file_priv != file_priv) { \ 271 DRM_ERROR("%s called without lock held\n", \ 272 __FUNCTION__); \ 273 return EINVAL; \ 274 } \ 275 } while (0) 276 277 /* Returns -errno to shared code */ 278 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \ 279 for ( ret = 0 ; !ret && !(condition) ; ) { \ 280 DRM_UNLOCK(dev); \ 281 lwkt_serialize_enter(&dev->irq_lock); \ 282 if (!(condition)) { \ 283 tsleep_interlock(&(queue), PCATCH); \ 284 lwkt_serialize_exit(&dev->irq_lock); \ 285 ret = -tsleep(&(queue), PCATCH | PINTERLOCKED, \ 286 "drmwtq", (timeout)); \ 287 } else { \ 288 lwkt_serialize_exit(&dev->irq_lock); \ 289 } \ 290 DRM_LOCK(dev); \ 291 } 292 293 __inline static void 294 vm_page_unhold_pages(vm_page_t *ma, int count) 295 { 296 int i; 297 298 for (i = 0; i < count; i++) 299 vm_page_unhold(ma[i]); 300 } 301 302 int vm_phys_fictitious_reg_range(vm_paddr_t start, vm_paddr_t end, 303 vm_memattr_t memattr); 304 void vm_phys_fictitious_unreg_range(vm_paddr_t start, vm_paddr_t end); 305 vm_page_t vm_phys_fictitious_to_vm_page(vm_paddr_t pa); 306 307 /***********************************************************************/ 308 /** \name Macros to make printk easier */ 309 /*@{*/ 310 311 /** 312 * Error output. 313 * 314 * \param fmt printf() like format string. 315 * \param arg arguments 316 */ 317 #define DRM_ERROR(fmt, ...) \ 318 kprintf("error: [" DRM_NAME ":pid%d:%s] *ERROR* " fmt, \ 319 DRM_CURRENTPID, __func__ , ##__VA_ARGS__) 320 321 #define DRM_INFO(fmt, ...) kprintf("info: [" DRM_NAME "] " fmt , ##__VA_ARGS__) 322 323 #define DRM_INFO_ONCE(fmt, ...) \ 324 printk_once(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__) 325 326 #define DRM_DEBUG(fmt, ...) do { \ 327 if ((drm_debug & DRM_DEBUGBITS_DEBUG) != 0) \ 328 kprintf("[" DRM_NAME ":pid%d:%s] " fmt, DRM_CURRENTPID, \ 329 __func__ , ##__VA_ARGS__); \ 330 } while (0) 331 332 #define DRM_DEBUG_KMS(fmt, ...) do { \ 333 if ((drm_debug & DRM_DEBUGBITS_KMS) != 0) \ 334 kprintf("[" DRM_NAME ":KMS:pid%d:%s] " fmt, DRM_CURRENTPID,\ 335 __func__ , ##__VA_ARGS__); \ 336 } while (0) 337 338 #define DRM_DEBUG_DRIVER(fmt, ...) do { \ 339 if ((drm_debug & DRM_DEBUGBITS_KMS) != 0) \ 340 kprintf("[" DRM_NAME ":KMS:pid%d:%s] " fmt, DRM_CURRENTPID,\ 341 __func__ , ##__VA_ARGS__); \ 342 } while (0) 343 344 #define DRM_LOG_KMS(fmt, ...) do { \ 345 kprintf("[" DRM_NAME ":KMS:pid%d:%s] " fmt, DRM_CURRENTPID, \ 346 __func__ , ##__VA_ARGS__); \ 347 } while (0) 348 349 #define dev_dbg(dev, fmt, ...) do { \ 350 if ((drm_debug& DRM_DEBUGBITS_KMS) != 0) { \ 351 device_printf((dev), "debug: " fmt, ## __VA_ARGS__); \ 352 } \ 353 } while (0) 354 355 typedef struct drm_pci_id_list 356 { 357 int vendor; 358 int device; 359 long driver_private; 360 char *name; 361 } drm_pci_id_list_t; 362 363 struct drm_msi_blacklist_entry 364 { 365 int vendor; 366 int device; 367 }; 368 369 /** 370 * Ioctl function type. 371 * 372 * \param inode device inode. 373 * \param file_priv DRM file private pointer. 374 * \param cmd command. 375 * \param arg argument. 376 */ 377 typedef int drm_ioctl_t(struct drm_device *dev, void *data, 378 struct drm_file *file_priv); 379 380 typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd, 381 unsigned long arg); 382 383 #define DRM_IOCTL_NR(n) ((n) & 0xff) 384 385 #define DRM_AUTH 0x1 386 #define DRM_MASTER 0x2 387 #define DRM_ROOT_ONLY 0x4 388 #define DRM_CONTROL_ALLOW 0x8 389 #define DRM_UNLOCKED 0x10 390 391 struct drm_ioctl_desc { 392 unsigned long cmd; 393 int (*func)(struct drm_device *dev, void *data, 394 struct drm_file *file_priv); 395 int flags; 396 unsigned int cmd_drv; 397 }; 398 399 /** 400 * Creates a driver or general drm_ioctl_desc array entry for the given 401 * ioctl, for use by drm_ioctl(). 402 */ 403 #define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags) \ 404 [DRM_IOCTL_NR(DRM_##ioctl)] = {.cmd = DRM_##ioctl, .func = _func, .flags = _flags, .cmd_drv = DRM_IOCTL_##ioctl} 405 406 typedef struct drm_magic_entry { 407 struct list_head head; 408 struct drm_hash_item hash_item; 409 struct drm_file *priv; 410 struct drm_magic_entry *next; 411 } drm_magic_entry_t; 412 413 typedef struct drm_magic_head { 414 struct drm_magic_entry *head; 415 struct drm_magic_entry *tail; 416 } drm_magic_head_t; 417 418 typedef struct drm_buf { 419 int idx; /**< Index into master buflist */ 420 int total; /**< Buffer size */ 421 int order; /**< log-base-2(total) */ 422 int used; /**< Amount of buffer in use (for DMA) */ 423 unsigned long offset; /**< Byte offset (used internally) */ 424 void *address; /**< Address of buffer */ 425 unsigned long bus_address; /**< Bus address of buffer */ 426 struct drm_buf *next; /**< Kernel-only: used for free list */ 427 __volatile__ int waiting; /**< On kernel DMA queue */ 428 __volatile__ int pending; /**< On hardware DMA queue */ 429 struct drm_file *file_priv; /**< Private of holding file descr */ 430 int context; /**< Kernel queue for this buffer */ 431 int while_locked; /**< Dispatch this buffer while locked */ 432 enum { 433 DRM_LIST_NONE = 0, 434 DRM_LIST_FREE = 1, 435 DRM_LIST_WAIT = 2, 436 DRM_LIST_PEND = 3, 437 DRM_LIST_PRIO = 4, 438 DRM_LIST_RECLAIM = 5 439 } list; /**< Which list we're on */ 440 441 int dev_priv_size; /**< Size of buffer private storage */ 442 void *dev_private; /**< Per-buffer private storage */ 443 } drm_buf_t; 444 445 struct drm_freelist { 446 int initialized; /* Freelist in use */ 447 atomic_t count; /* Number of free buffers */ 448 drm_buf_t *next; /* End pointer */ 449 450 wait_queue_head_t waiting; /**< Processes waiting on free bufs */ 451 int low_mark; /* Low water mark */ 452 int high_mark; /* High water mark */ 453 }; 454 455 typedef struct drm_dma_handle { 456 void *vaddr; 457 size_t size; 458 bus_addr_t busaddr; 459 bus_dma_tag_t tag; 460 bus_dmamap_t map; 461 } drm_dma_handle_t; 462 463 typedef struct drm_buf_entry { 464 int buf_size; 465 int buf_count; 466 drm_buf_t *buflist; 467 int seg_count; 468 drm_dma_handle_t **seglist; 469 int page_order; 470 471 struct drm_freelist freelist; 472 } drm_buf_entry_t; 473 474 /* Event queued up for userspace to read */ 475 struct drm_pending_event { 476 struct drm_event *event; 477 struct list_head link; 478 struct drm_file *file_priv; 479 pid_t pid; /* pid of requester, no guarantee it's valid by the time 480 we deliver the event, for tracing only */ 481 void (*destroy)(struct drm_pending_event *event); 482 }; 483 484 /* initial implementaton using a linked list - todo hashtab */ 485 struct drm_prime_file_private { 486 struct list_head head; 487 #ifdef DUMBBELL_WIP 488 struct mutex lock; 489 #endif /* DUMBBELL_WIP */ 490 }; 491 492 /** File private data */ 493 struct drm_file { 494 int authenticated; 495 struct drm_device *dev; 496 int master; 497 pid_t pid; 498 uid_t uid; 499 drm_magic_t magic; 500 unsigned long ioctl_count; 501 struct list_head lhead; 502 struct kqinfo dkq; 503 504 /** Mapping of mm object handles to object pointers. */ 505 struct idr object_idr; 506 /** Lock for synchronization of access to object_idr. */ 507 struct lock table_lock; 508 509 void *driver_priv; 510 511 int is_master; 512 struct drm_master *masterp; 513 514 /* true when the client has asked us to expose stereo 3D mode flags */ 515 bool stereo_allowed; 516 517 /** 518 * fbs - List of framebuffers associated with this file. 519 * 520 * Protected by fbs_lock. Note that the fbs list holds a reference on 521 * the fb object to prevent it from untimely disappearing. 522 */ 523 struct list_head fbs; 524 struct lock fbs_lock; 525 526 wait_queue_head_t event_wait; 527 struct list_head event_list; 528 int event_space; 529 530 struct drm_prime_file_private prime; 531 }; 532 533 /** 534 * Lock data. 535 */ 536 struct drm_lock_data { 537 struct drm_hw_lock *hw_lock; /**< Hardware lock */ 538 /** Private of lock holder's file (NULL=kernel) */ 539 struct drm_file *file_priv; 540 wait_queue_head_t lock_queue; /**< Queue of blocked processes */ 541 unsigned long lock_time; /**< Time of last lock in jiffies */ 542 }; 543 544 /* This structure, in the struct drm_device, is always initialized while the 545 * device 546 * is open. dev->dma_lock protects the incrementing of dev->buf_use, which 547 * when set marks that no further bufs may be allocated until device teardown 548 * occurs (when the last open of the device has closed). The high/low 549 * watermarks of bufs are only touched by the X Server, and thus not 550 * concurrently accessed, so no locking is needed. 551 */ 552 typedef struct drm_device_dma { 553 554 struct drm_buf_entry bufs[DRM_MAX_ORDER + 1]; /**< buffers, grouped by their size order */ 555 int buf_count; /**< total number of buffers */ 556 struct drm_buf **buflist; /**< Vector of pointers into drm_device_dma::bufs */ 557 int seg_count; 558 int page_count; /**< number of pages */ 559 unsigned long *pagelist; /**< page list */ 560 unsigned long byte_count; 561 enum { 562 _DRM_DMA_USE_AGP = 0x01, 563 _DRM_DMA_USE_SG = 0x02, 564 _DRM_DMA_USE_FB = 0x04, 565 _DRM_DMA_USE_PCI_RO = 0x08 566 } flags; 567 568 } drm_device_dma_t; 569 570 typedef struct drm_agp_mem { 571 void *handle; 572 unsigned long bound; /* address */ 573 int pages; 574 struct drm_agp_mem *prev; 575 struct drm_agp_mem *next; 576 } drm_agp_mem_t; 577 578 typedef struct drm_agp_head { 579 device_t agpdev; 580 struct agp_info agp_info; 581 const char *chipset; 582 drm_agp_mem_t *memory; 583 unsigned long mode; 584 int enabled; 585 int acquired; 586 unsigned long base; 587 int agp_mtrr; 588 int cant_use_aperture; 589 unsigned long page_mask; 590 } drm_agp_head_t; 591 592 typedef struct drm_sg_mem { 593 vm_offset_t vaddr; 594 vm_paddr_t *busaddr; 595 vm_pindex_t pages; 596 } drm_sg_mem_t; 597 598 /** 599 * Kernel side of a mapping 600 */ 601 struct drm_local_map { 602 resource_size_t offset; /**< Requested physical address (0 for SAREA)*/ 603 unsigned long size; /**< Requested physical size (bytes) */ 604 enum drm_map_type type; /**< Type of memory to map */ 605 enum drm_map_flags flags; /**< Flags */ 606 void *handle; /**< User-space: "Handle" to pass to mmap() */ 607 /**< Kernel-space: kernel-virtual address */ 608 int mtrr; /**< MTRR slot used */ 609 }; 610 611 typedef struct drm_local_map drm_local_map_t; 612 613 /** 614 * Mappings list 615 */ 616 struct drm_map_list { 617 struct list_head head; /**< list head */ 618 struct drm_hash_item hash; 619 struct drm_local_map *map; /**< mapping */ 620 uint64_t user_token; 621 struct drm_master *master; 622 struct drm_mm_node *file_offset_node; /**< fake offset */ 623 }; 624 625 /** 626 * Context handle list 627 */ 628 struct drm_ctx_list { 629 struct list_head head; /**< list head */ 630 drm_context_t handle; /**< context handle */ 631 struct drm_file *tag; /**< associated fd private data */ 632 }; 633 634 struct drm_vblank_info { 635 wait_queue_head_t queue; /* vblank wait queue */ 636 atomic_t count; /* number of VBLANK interrupts */ 637 /* (driver must alloc the right number of counters) */ 638 atomic_t refcount; /* number of users of vblank interrupts */ 639 u32 last; /* protected by dev->vbl_lock, used */ 640 /* for wraparound handling */ 641 int enabled; /* so we don't call enable more than */ 642 /* once per disable */ 643 int inmodeset; /* Display driver is setting mode */ 644 }; 645 646 /* location of GART table */ 647 #define DRM_ATI_GART_MAIN 1 648 #define DRM_ATI_GART_FB 2 649 650 #define DRM_ATI_GART_PCI 1 651 #define DRM_ATI_GART_PCIE 2 652 #define DRM_ATI_GART_IGP 3 653 654 struct drm_ati_pcigart_info { 655 int gart_table_location; 656 int gart_reg_if; 657 void *addr; 658 dma_addr_t bus_addr; 659 dma_addr_t table_mask; 660 dma_addr_t member_mask; 661 struct drm_dma_handle *table_handle; 662 drm_local_map_t mapping; 663 int table_size; 664 struct drm_dma_handle *dmah; /* handle for ATI PCIGART table */ 665 }; 666 667 /** 668 * GEM specific mm private for tracking GEM objects 669 */ 670 struct drm_gem_mm { 671 struct drm_vma_offset_manager vma_manager; 672 struct drm_mm offset_manager; /**< Offset mgmt for buffer objects */ 673 struct drm_open_hash offset_hash; /**< User token hash table for maps */ 674 struct unrhdr *idxunr; 675 }; 676 677 struct drm_gem_object { 678 /** Reference count of this object */ 679 struct kref refcount; 680 681 /** Handle count of this object. Each handle also holds a reference */ 682 atomic_t handle_count; /* number of handles on this object */ 683 684 /** Related drm device */ 685 struct drm_device *dev; 686 687 /** File representing the shmem storage: filp in Linux parlance */ 688 vm_object_t vm_obj; 689 690 /* Mapping info for this object */ 691 struct drm_vma_offset_node vma_node; 692 bool on_map; 693 struct drm_hash_item map_list; 694 695 /** 696 * Size of the object, in bytes. Immutable over the object's 697 * lifetime. 698 */ 699 size_t size; 700 701 /** 702 * Global name for this object, starts at 1. 0 means unnamed. 703 * Access is covered by the object_name_lock in the related drm_device 704 */ 705 int name; 706 707 /** 708 * Memory domains. These monitor which caches contain read/write data 709 * related to the object. When transitioning from one set of domains 710 * to another, the driver is called to ensure that caches are suitably 711 * flushed and invalidated 712 */ 713 uint32_t read_domains; 714 uint32_t write_domain; 715 716 /** 717 * While validating an exec operation, the 718 * new read/write domain values are computed here. 719 * They will be transferred to the above values 720 * at the point that any cache flushing occurs 721 */ 722 uint32_t pending_read_domains; 723 uint32_t pending_write_domain; 724 725 #ifdef DUMBBELL_WIP 726 /* dma buf exported from this GEM object */ 727 struct dma_buf *export_dma_buf; 728 729 /* dma buf attachment backing this object */ 730 struct dma_buf_attachment *import_attach; 731 #endif /* DUMBBELL_WIP */ 732 }; 733 734 #include "drm_crtc.h" 735 736 /* per-master structure */ 737 struct drm_master { 738 739 struct kref refcount; /* refcount for this master */ 740 741 struct list_head head; /**< each minor contains a list of masters */ 742 struct drm_minor *minor; /**< link back to minor we are a master for */ 743 744 char *unique; /**< Unique identifier: e.g., busid */ 745 int unique_len; /**< Length of unique field */ 746 int unique_size; /**< amount allocated */ 747 748 int blocked; /**< Blocked due to VC switch? */ 749 750 /** \name Authentication */ 751 /*@{ */ 752 struct drm_open_hash magiclist; 753 struct list_head magicfree; 754 /*@} */ 755 756 struct drm_lock_data lock; /**< Information on hardware lock */ 757 758 void *driver_priv; /**< Private structure for driver to use */ 759 }; 760 761 /* Size of ringbuffer for vblank timestamps. Just double-buffer 762 * in initial implementation. 763 */ 764 #define DRM_VBLANKTIME_RBSIZE 2 765 766 /* Flags and return codes for get_vblank_timestamp() driver function. */ 767 #define DRM_CALLED_FROM_VBLIRQ 1 768 #define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0) 769 #define DRM_VBLANKTIME_INVBL (1 << 1) 770 771 /* get_scanout_position() return flags */ 772 #define DRM_SCANOUTPOS_VALID (1 << 0) 773 #define DRM_SCANOUTPOS_INVBL (1 << 1) 774 #define DRM_SCANOUTPOS_ACCURATE (1 << 2) 775 776 #ifndef DMA_BIT_MASK 777 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : (1ULL<<(n)) - 1) 778 #endif 779 780 #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16)) 781 782 struct drm_driver { 783 int (*load)(struct drm_device *, unsigned long flags); 784 int (*use_msi)(struct drm_device *, unsigned long flags); 785 int (*firstopen)(struct drm_device *); 786 int (*open)(struct drm_device *, struct drm_file *); 787 void (*preclose)(struct drm_device *, struct drm_file *file_priv); 788 void (*postclose)(struct drm_device *, struct drm_file *); 789 void (*lastclose)(struct drm_device *); 790 int (*unload)(struct drm_device *); 791 void (*reclaim_buffers_locked)(struct drm_device *, 792 struct drm_file *file_priv); 793 int (*dma_ioctl)(struct drm_device *dev, void *data, 794 struct drm_file *file_priv); 795 void (*dma_ready)(struct drm_device *); 796 int (*dma_quiescent)(struct drm_device *); 797 int (*dma_flush_block_and_flush)(struct drm_device *, int context, 798 enum drm_lock_flags flags); 799 int (*dma_flush_unblock)(struct drm_device *, int context, 800 enum drm_lock_flags flags); 801 int (*context_ctor)(struct drm_device *dev, int context); 802 int (*context_dtor)(struct drm_device *dev, int context); 803 int (*kernel_context_switch)(struct drm_device *dev, int old, 804 int new); 805 int (*kernel_context_switch_unlock)(struct drm_device *dev); 806 void (*irq_preinstall)(struct drm_device *dev); 807 int (*irq_postinstall)(struct drm_device *dev); 808 void (*irq_uninstall)(struct drm_device *dev); 809 void (*irq_handler)(DRM_IRQ_ARGS); 810 811 u32 (*get_vblank_counter)(struct drm_device *dev, int crtc); 812 int (*enable_vblank)(struct drm_device *dev, int crtc); 813 void (*disable_vblank)(struct drm_device *dev, int crtc); 814 int (*get_scanout_position)(struct drm_device *dev, int crtc, 815 int *vpos, int *hpos); 816 817 int (*get_vblank_timestamp)(struct drm_device *dev, int crtc, 818 int *max_error, struct timeval *vblank_time, 819 unsigned flags); 820 821 void (*gem_free_object)(struct drm_gem_object *obj); 822 int (*gem_open_object)(struct drm_gem_object *, struct drm_file *); 823 void (*gem_close_object)(struct drm_gem_object *, struct drm_file *); 824 825 struct cdev_pager_ops *gem_pager_ops; 826 827 int (*dumb_create)(struct drm_file *file_priv, 828 struct drm_device *dev, struct drm_mode_create_dumb *args); 829 int (*dumb_map_offset)(struct drm_file *file_priv, 830 struct drm_device *dev, uint32_t handle, uint64_t *offset); 831 int (*dumb_destroy)(struct drm_file *file_priv, 832 struct drm_device *dev, uint32_t handle); 833 834 int (*sysctl_init)(struct drm_device *dev, 835 struct sysctl_ctx_list *ctx, struct sysctl_oid *top); 836 void (*sysctl_cleanup)(struct drm_device *dev); 837 838 drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */ 839 840 /** 841 * Called by \c drm_device_is_agp. Typically used to determine if a 842 * card is really attached to AGP or not. 843 * 844 * \param dev DRM device handle 845 * 846 * \returns 847 * One of three values is returned depending on whether or not the 848 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP 849 * (return of 1), or may or may not be AGP (return of 2). 850 */ 851 int (*device_is_agp) (struct drm_device * dev); 852 853 int buf_priv_size; 854 855 int major; 856 int minor; 857 int patchlevel; 858 const char *name; /* Simple driver name */ 859 const char *desc; /* Longer driver name */ 860 const char *date; /* Date of last major changes. */ 861 862 u32 driver_features; 863 int dev_priv_size; 864 struct drm_ioctl_desc *ioctls; 865 int num_ioctls; 866 }; 867 868 /** 869 * DRM minor structure. This structure represents a drm minor number. 870 */ 871 struct drm_minor { 872 int index; /**< Minor device number */ 873 int type; /**< Control or render */ 874 device_t kdev; /**< OS device */ 875 struct drm_device *dev; 876 877 struct drm_master *master; /* currently active master for this node */ 878 struct list_head master_list; 879 struct drm_mode_group mode_group; 880 }; 881 882 /* mode specified on the command line */ 883 struct drm_cmdline_mode { 884 bool specified; 885 bool refresh_specified; 886 bool bpp_specified; 887 int xres, yres; 888 int bpp; 889 int refresh; 890 bool rb; 891 bool interlace; 892 bool cvt; 893 bool margins; 894 enum drm_connector_force force; 895 }; 896 897 898 struct drm_pending_vblank_event { 899 struct drm_pending_event base; 900 int pipe; 901 struct drm_event_vblank event; 902 }; 903 904 struct drm_sysctl_info { 905 struct sysctl_ctx_list ctx; 906 char name[2]; 907 }; 908 909 /* Length for the array of resource pointers for drm_get_resource_*. */ 910 #define DRM_MAX_PCI_RESOURCE 6 911 912 /** 913 * DRM device structure. This structure represent a complete card that 914 * may contain multiple heads. 915 */ 916 struct drm_device { 917 drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */ 918 919 uint16_t pci_subdevice; /* PCI subsystem device id */ 920 uint16_t pci_subvendor; /* PCI subsystem vendor id */ 921 922 char *unique; /* Unique identifier: e.g., busid */ 923 int unique_len; /* Length of unique field */ 924 struct cdev *devnode; /* Device number for mknod */ 925 int if_version; /* Highest interface version set */ 926 927 int flags; /* Flags to open(2) */ 928 929 /* Locks */ 930 struct spinlock dma_lock; /* protects dev->dma */ 931 struct lwkt_serialize irq_lock; /* protects irq condition checks */ 932 struct lock dev_lock; /* protects everything else */ 933 934 /** \name Locks */ 935 /*@{ */ 936 struct lock struct_mutex; /**< For others */ 937 /*@} */ 938 939 /** \name Usage Counters */ 940 /*@{ */ 941 int open_count; /* Outstanding files open */ 942 int buf_use; /* Buffers in use -- cannot alloc */ 943 /*@} */ 944 945 946 /** \name Performance counters */ 947 /*@{ */ 948 unsigned long counters; 949 enum drm_stat_type types[15]; 950 atomic_t counts[15]; 951 /*@} */ 952 953 /* Authentication */ 954 struct drm_open_hash magiclist; /**< magic hash table */ 955 struct list_head magicfree; 956 957 struct list_head filelist; 958 959 /** \name Memory management */ 960 /*@{ */ 961 struct list_head maplist; /**< Linked list of regions */ 962 int map_count; /**< Number of mappable regions */ 963 struct drm_open_hash map_hash; /**< User token hash table for maps */ 964 965 /** \name Context handle management */ 966 /*@{ */ 967 struct list_head ctxlist; /**< Linked list of context handles */ 968 int ctx_count; /**< Number of context handles */ 969 struct lock ctxlist_mutex; /**< For ctxlist */ 970 971 struct idr ctx_idr; 972 973 /*@} */ 974 975 struct drm_lock_data lock; /* Information on hardware lock */ 976 977 /* DMA queues (contexts) */ 978 drm_device_dma_t *dma; /* Optional pointer for DMA support */ 979 980 int irq; /* Interrupt used by board */ 981 int msi_enabled; /* MSI enabled */ 982 int irqrid; /* Interrupt used by board */ 983 struct resource *irqr; /* Resource for interrupt used by board */ 984 void *irqh; /* Handle from bus_setup_intr */ 985 986 /* Storage of resource pointers for drm_get_resource_* */ 987 struct resource *pcir[DRM_MAX_PCI_RESOURCE]; 988 int pcirid[DRM_MAX_PCI_RESOURCE]; 989 990 int pci_domain; 991 int pci_bus; 992 int pci_slot; 993 int pci_func; 994 995 /** \name Context support */ 996 /*@{ */ 997 int irq_enabled; /**< True if irq handler is enabled */ 998 __volatile__ long context_flag; /**< Context swapping flag */ 999 __volatile__ long interrupt_flag; /**< Interruption handler flag */ 1000 __volatile__ long dma_flag; /**< DMA dispatch flag */ 1001 wait_queue_head_t context_wait; /**< Processes waiting on ctx switch */ 1002 int last_checked; /**< Last context checked for DMA */ 1003 int last_context; /**< Last current context */ 1004 unsigned long last_switch; /**< jiffies at last context switch */ 1005 /*@} */ 1006 1007 int num_crtcs; 1008 1009 struct sigio *buf_sigio; /* Processes waiting for SIGIO */ 1010 1011 /* Sysctl support */ 1012 struct drm_sysctl_info *sysctl; 1013 int sysctl_node_idx; 1014 1015 1016 drm_sg_mem_t *sg; /* Scatter gather memory */ 1017 unsigned long *ctx_bitmap; 1018 void *dev_private; 1019 1020 void *drm_ttm_bdev; 1021 1022 /* 1023 * At load time, disabling the vblank interrupt won't be allowed since 1024 * old clients may not call the modeset ioctl and therefore misbehave. 1025 * Once the modeset ioctl *has* been called though, we can safely 1026 * disable them when unused. 1027 */ 1028 int vblank_disable_allowed; 1029 1030 wait_queue_head_t *vbl_queue; /**< VBLANK wait queue */ 1031 atomic_t *_vblank_count; /**< number of VBLANK interrupts (driver must alloc the right number of counters) */ 1032 struct timeval *_vblank_time; /**< timestamp of current vblank_count (drivers must alloc right number of fields) */ 1033 struct lock vblank_time_lock; /**< Protects vblank count and time updates during vblank enable/disable */ 1034 struct lock vbl_lock; 1035 atomic_t *vblank_refcount; /* number of users of vblank interruptsper crtc */ 1036 u32 *last_vblank; /* protected by dev->vbl_lock, used */ 1037 /* for wraparound handling */ 1038 int *vblank_enabled; /* so we don't call enable more than 1039 once per disable */ 1040 int *vblank_inmodeset; /* Display driver is setting mode */ 1041 u32 *last_vblank_wait; /* Last vblank seqno waited per CRTC */ 1042 struct timer_list vblank_disable_timer; 1043 1044 u32 max_vblank_count; /**< size of vblank counter register */ 1045 1046 /** 1047 * List of events 1048 */ 1049 struct list_head vblank_event_list; 1050 struct lock event_lock; 1051 1052 /*@} */ 1053 1054 struct drm_agp_head *agp; /**< AGP data */ 1055 1056 struct device *dev; /**< Device structure */ 1057 struct pci_dev *pdev; /**< PCI device structure */ 1058 int pci_vendor; /**< PCI vendor id */ 1059 int pci_device; /**< PCI device id */ 1060 1061 struct drm_driver *driver; 1062 struct drm_local_map *agp_buffer_map; 1063 unsigned int agp_buffer_token; 1064 struct drm_minor *control; /**< Control node for card */ 1065 struct drm_minor *primary; /**< render type primary screen head */ 1066 1067 struct drm_mode_config mode_config; /**< Current mode config */ 1068 1069 /** \name GEM information */ 1070 /*@{ */ 1071 struct lock object_name_lock; 1072 struct idr object_name_idr; 1073 /*@} */ 1074 void *mm_private; 1075 1076 void *sysctl_private; 1077 char busid_str[128]; 1078 int modesetting; 1079 1080 int switch_power_state; 1081 }; 1082 1083 #define DRM_SWITCH_POWER_ON 0 1084 #define DRM_SWITCH_POWER_OFF 1 1085 #define DRM_SWITCH_POWER_CHANGING 2 1086 1087 static __inline__ int drm_core_check_feature(struct drm_device *dev, 1088 int feature) 1089 { 1090 return ((dev->driver->driver_features & feature) ? 1 : 0); 1091 } 1092 1093 #if __OS_HAS_AGP 1094 static inline int drm_core_has_AGP(struct drm_device *dev) 1095 { 1096 return drm_core_check_feature(dev, DRIVER_USE_AGP); 1097 } 1098 #else 1099 #define drm_core_has_AGP(dev) (0) 1100 #endif 1101 1102 enum dmi_field { 1103 DMI_NONE, 1104 DMI_BIOS_VENDOR, 1105 DMI_BIOS_VERSION, 1106 DMI_BIOS_DATE, 1107 DMI_SYS_VENDOR, 1108 DMI_PRODUCT_NAME, 1109 DMI_PRODUCT_VERSION, 1110 DMI_PRODUCT_SERIAL, 1111 DMI_PRODUCT_UUID, 1112 DMI_BOARD_VENDOR, 1113 DMI_BOARD_NAME, 1114 DMI_BOARD_VERSION, 1115 DMI_BOARD_SERIAL, 1116 DMI_BOARD_ASSET_TAG, 1117 DMI_CHASSIS_VENDOR, 1118 DMI_CHASSIS_TYPE, 1119 DMI_CHASSIS_VERSION, 1120 DMI_CHASSIS_SERIAL, 1121 DMI_CHASSIS_ASSET_TAG, 1122 DMI_STRING_MAX, 1123 }; 1124 1125 struct dmi_strmatch { 1126 unsigned char slot; 1127 char substr[79]; 1128 }; 1129 1130 struct dmi_system_id { 1131 int (*callback)(const struct dmi_system_id *); 1132 const char *ident; 1133 struct dmi_strmatch matches[4]; 1134 }; 1135 #define DMI_MATCH(a, b) {(a), (b)} 1136 bool dmi_check_system(const struct dmi_system_id *); 1137 1138 extern int drm_notyet_flag; 1139 extern int drm_debug; 1140 1141 extern unsigned int drm_vblank_offdelay; 1142 extern unsigned int drm_timestamp_precision; 1143 extern unsigned int drm_timestamp_monotonic; 1144 1145 /* Device setup support (drm_drv.c) */ 1146 int drm_probe(device_t kdev, drm_pci_id_list_t *idlist); 1147 int drm_attach(device_t kdev, drm_pci_id_list_t *idlist); 1148 int drm_create_cdevs(device_t kdev); 1149 1150 d_ioctl_t drm_ioctl; 1151 extern int drm_lastclose(struct drm_device *dev); 1152 1153 /* Device support (drm_fops.h) */ 1154 d_open_t drm_open; 1155 d_close_t drm_close; 1156 d_read_t drm_read; 1157 d_kqfilter_t drm_kqfilter; 1158 int drm_release(device_t kdev); 1159 1160 d_mmap_t drm_mmap; 1161 d_mmap_single_t drm_mmap_single; 1162 extern drm_local_map_t *drm_getsarea(struct drm_device *dev); 1163 1164 void drm_cdevpriv_dtor(void *cd); 1165 1166 void drm_event_wakeup(struct drm_pending_event *e); 1167 1168 int drm_add_busid_modesetting(struct drm_device *dev, 1169 struct sysctl_ctx_list *ctx, struct sysctl_oid *top); 1170 1171 /* File operations helpers (drm_fops.c) */ 1172 extern int drm_open_helper(struct cdev *kdev, int flags, int fmt, 1173 DRM_STRUCTPROC *p, 1174 struct drm_device *dev, 1175 struct file *fp); 1176 extern struct drm_file *drm_find_file_by_proc(struct drm_device *dev, 1177 DRM_STRUCTPROC *p); 1178 1179 #ifdef DUMBBELL_WIP 1180 extern int drm_gem_prime_handle_to_fd(struct drm_device *dev, 1181 struct drm_file *file_priv, uint32_t handle, uint32_t flags, 1182 int *prime_fd); 1183 extern int drm_gem_prime_fd_to_handle(struct drm_device *dev, 1184 struct drm_file *file_priv, int prime_fd, uint32_t *handle); 1185 1186 extern int drm_prime_handle_to_fd_ioctl(struct drm_device *dev, void *data, 1187 struct drm_file *file_priv); 1188 extern int drm_prime_fd_to_handle_ioctl(struct drm_device *dev, void *data, 1189 struct drm_file *file_priv); 1190 1191 extern int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, vm_page_t *pages, 1192 dma_addr_t *addrs, int max_pages); 1193 #endif /* DUMBBELL_WIP */ 1194 extern struct sg_table *drm_prime_pages_to_sg(vm_page_t *pages, int nr_pages); 1195 extern void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg); 1196 1197 int drm_gem_dumb_destroy(struct drm_file *file, 1198 struct drm_device *dev, 1199 uint32_t handle); 1200 1201 #ifdef DUMBBELL_WIP 1202 void drm_prime_init_file_private(struct drm_prime_file_private *prime_fpriv); 1203 void drm_prime_destroy_file_private(struct drm_prime_file_private *prime_fpriv); 1204 int drm_prime_add_imported_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf, uint32_t handle); 1205 int drm_prime_lookup_imported_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf, uint32_t *handle); 1206 void drm_prime_remove_imported_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf); 1207 1208 int drm_prime_add_dma_buf(struct drm_device *dev, struct drm_gem_object *obj); 1209 int drm_prime_lookup_obj(struct drm_device *dev, struct dma_buf *buf, 1210 struct drm_gem_object **obj); 1211 #endif /* DUMBBELL_WIP */ 1212 1213 /* Memory management support (drm_memory.h) */ 1214 #include <drm/drm_memory.h> 1215 void drm_mem_init(void); 1216 void drm_mem_uninit(void); 1217 void *drm_ioremap_wc(struct drm_device *dev, drm_local_map_t *map); 1218 void *drm_ioremap(struct drm_device *dev, drm_local_map_t *map); 1219 void drm_ioremapfree(drm_local_map_t *map); 1220 int drm_mtrr_add(unsigned long offset, size_t size, int flags); 1221 int drm_mtrr_del(int handle, unsigned long offset, size_t size, int flags); 1222 1223 int drm_ctxbitmap_init(struct drm_device *dev); 1224 void drm_ctxbitmap_cleanup(struct drm_device *dev); 1225 void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle); 1226 1227 /* Locking IOCTL support (drm_lock.c) */ 1228 int drm_lock_take(struct drm_lock_data *lock_data, 1229 unsigned int context); 1230 int drm_lock_transfer(struct drm_lock_data *lock_data, 1231 unsigned int context); 1232 int drm_lock_free(struct drm_lock_data *lock_data, 1233 unsigned int context); 1234 1235 /* 1236 * These are exported to drivers so that they can implement fencing using 1237 * DMA quiscent + idle. DMA quiescent usually requires the hardware lock. 1238 */ 1239 1240 unsigned long drm_get_resource_start(struct drm_device *dev, 1241 unsigned int resource); 1242 unsigned long drm_get_resource_len(struct drm_device *dev, 1243 unsigned int resource); 1244 void drm_rmmap(struct drm_device *dev, drm_local_map_t *map); 1245 int drm_order(unsigned long size); 1246 int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc *request); 1247 int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc *request); 1248 extern int drm_addmap(struct drm_device *dev, resource_size_t offset, 1249 unsigned int size, enum drm_map_type type, 1250 enum drm_map_flags flags, struct drm_local_map **map_ptr); 1251 1252 /* DMA support (drm_dma.c) */ 1253 int drm_dma_setup(struct drm_device *dev); 1254 void drm_dma_takedown(struct drm_device *dev); 1255 void drm_free_buffer(struct drm_device *dev, drm_buf_t *buf); 1256 void drm_reclaim_buffers(struct drm_device *dev, struct drm_file *file_priv); 1257 #define drm_core_reclaim_buffers drm_reclaim_buffers 1258 1259 /* IRQ support (drm_irq.h) */ 1260 int drm_irq_install(struct drm_device *dev); 1261 int drm_irq_uninstall(struct drm_device *dev); 1262 void drm_driver_irq_preinstall(struct drm_device *dev); 1263 void drm_driver_irq_postinstall(struct drm_device *dev); 1264 void drm_driver_irq_uninstall(struct drm_device *dev); 1265 1266 void drm_vblank_pre_modeset(struct drm_device *dev, int crtc); 1267 void drm_vblank_post_modeset(struct drm_device *dev, int crtc); 1268 int drm_modeset_ctl(struct drm_device *dev, void *data, 1269 struct drm_file *file_priv); 1270 1271 extern int drm_vblank_init(struct drm_device *dev, int num_crtcs); 1272 extern int drm_wait_vblank(struct drm_device *dev, void *data, 1273 struct drm_file *filp); 1274 extern int drm_vblank_wait(struct drm_device *dev, unsigned int *vbl_seq); 1275 extern u32 drm_vblank_count(struct drm_device *dev, int crtc); 1276 extern u32 drm_vblank_count_and_time(struct drm_device *dev, int crtc, 1277 struct timeval *vblanktime); 1278 extern void drm_send_vblank_event(struct drm_device *dev, int crtc, 1279 struct drm_pending_vblank_event *e); 1280 extern bool drm_handle_vblank(struct drm_device *dev, int crtc); 1281 void drm_handle_vblank_events(struct drm_device *dev, int crtc); 1282 extern int drm_vblank_get(struct drm_device *dev, int crtc); 1283 extern void drm_vblank_put(struct drm_device *dev, int crtc); 1284 extern void drm_vblank_off(struct drm_device *dev, int crtc); 1285 extern void drm_vblank_cleanup(struct drm_device *dev); 1286 extern u32 drm_get_last_vbltimestamp(struct drm_device *dev, int crtc, 1287 struct timeval *tvblank, unsigned flags); 1288 extern int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev, 1289 int crtc, int *max_error, 1290 struct timeval *vblank_time, 1291 unsigned flags, 1292 struct drm_crtc *refcrtc); 1293 extern void drm_calc_timestamping_constants(struct drm_crtc *crtc, 1294 const struct drm_display_mode *mode); 1295 1296 /* AGP/PCI Express/GART support (drm_agpsupport.c) */ 1297 int drm_device_is_agp(struct drm_device *dev); 1298 int drm_device_is_pcie(struct drm_device *dev); 1299 drm_agp_head_t *drm_agp_init(void); 1300 int drm_agp_acquire(struct drm_device *dev); 1301 int drm_agp_release(struct drm_device *dev); 1302 int drm_agp_info(struct drm_device * dev, struct drm_agp_info *info); 1303 int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode); 1304 void *drm_agp_allocate_memory(size_t pages, u32 type); 1305 int drm_agp_free_memory(void *handle); 1306 int drm_agp_bind_memory(void *handle, off_t start); 1307 int drm_agp_unbind_memory(void *handle); 1308 int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request); 1309 int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request); 1310 int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request); 1311 int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request); 1312 1313 /* Scatter Gather Support (drm_scatter.c) */ 1314 void drm_sg_cleanup(drm_sg_mem_t *entry); 1315 int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request); 1316 1317 /* sysctl support (drm_sysctl.h) */ 1318 extern int drm_sysctl_init(struct drm_device *dev); 1319 extern int drm_sysctl_cleanup(struct drm_device *dev); 1320 1321 /* ATI PCIGART support (ati_pcigart.c) */ 1322 int drm_ati_pcigart_init(struct drm_device *dev, 1323 struct drm_ati_pcigart_info *gart_info); 1324 int drm_ati_pcigart_cleanup(struct drm_device *dev, 1325 struct drm_ati_pcigart_info *gart_info); 1326 1327 /* Cache management (drm_memory.c) */ 1328 void drm_clflush_pages(vm_page_t *pages, unsigned long num_pages); 1329 1330 /* Locking IOCTL support (drm_drv.c) */ 1331 int drm_lock(struct drm_device *dev, void *data, 1332 struct drm_file *file_priv); 1333 int drm_unlock(struct drm_device *dev, void *data, 1334 struct drm_file *file_priv); 1335 int drm_version(struct drm_device *dev, void *data, 1336 struct drm_file *file_priv); 1337 int drm_setversion(struct drm_device *dev, void *data, 1338 struct drm_file *file_priv); 1339 1340 /* Misc. IOCTL support (drm_ioctl.c) */ 1341 int drm_irq_by_busid(struct drm_device *dev, void *data, 1342 struct drm_file *file_priv); 1343 int drm_getunique(struct drm_device *dev, void *data, 1344 struct drm_file *file_priv); 1345 int drm_setunique(struct drm_device *dev, void *data, 1346 struct drm_file *file_priv); 1347 int drm_getmap(struct drm_device *dev, void *data, 1348 struct drm_file *file_priv); 1349 int drm_getclient(struct drm_device *dev, void *data, 1350 struct drm_file *file_priv); 1351 int drm_getstats(struct drm_device *dev, void *data, 1352 struct drm_file *file_priv); 1353 int drm_getcap(struct drm_device *dev, void *data, 1354 struct drm_file *file_priv); 1355 extern int drm_setclientcap(struct drm_device *dev, void *data, 1356 struct drm_file *file_priv); 1357 int drm_noop(struct drm_device *dev, void *data, 1358 struct drm_file *file_priv); 1359 1360 /* Context IOCTL support (drm_context.c) */ 1361 int drm_resctx(struct drm_device *dev, void *data, 1362 struct drm_file *file_priv); 1363 int drm_addctx(struct drm_device *dev, void *data, 1364 struct drm_file *file_priv); 1365 int drm_modctx(struct drm_device *dev, void *data, 1366 struct drm_file *file_priv); 1367 int drm_getctx(struct drm_device *dev, void *data, 1368 struct drm_file *file_priv); 1369 int drm_switchctx(struct drm_device *dev, void *data, 1370 struct drm_file *file_priv); 1371 int drm_newctx(struct drm_device *dev, void *data, 1372 struct drm_file *file_priv); 1373 int drm_rmctx(struct drm_device *dev, void *data, 1374 struct drm_file *file_priv); 1375 int drm_setsareactx(struct drm_device *dev, void *data, 1376 struct drm_file *file_priv); 1377 int drm_getsareactx(struct drm_device *dev, void *data, 1378 struct drm_file *file_priv); 1379 1380 /* Authentication IOCTL support (drm_auth.c) */ 1381 int drm_getmagic(struct drm_device *dev, void *data, 1382 struct drm_file *file_priv); 1383 int drm_authmagic(struct drm_device *dev, void *data, 1384 struct drm_file *file_priv); 1385 1386 /* Cache management (drm_cache.c) */ 1387 void drm_clflush_virt_range(char *addr, unsigned long length); 1388 1389 /* Buffer management support (drm_bufs.c) */ 1390 int drm_addmap_ioctl(struct drm_device *dev, void *data, 1391 struct drm_file *file_priv); 1392 int drm_rmmap_ioctl(struct drm_device *dev, void *data, 1393 struct drm_file *file_priv); 1394 int drm_addbufs(struct drm_device *dev, void *data, 1395 struct drm_file *file_priv); 1396 int drm_infobufs(struct drm_device *dev, void *data, 1397 struct drm_file *file_priv); 1398 int drm_markbufs(struct drm_device *dev, void *data, 1399 struct drm_file *file_priv); 1400 int drm_freebufs(struct drm_device *dev, void *data, 1401 struct drm_file *file_priv); 1402 int drm_mapbufs(struct drm_device *dev, void *data, 1403 struct drm_file *file_priv); 1404 1405 /* DMA support (drm_dma.c) */ 1406 int drm_dma(struct drm_device *dev, void *data, struct drm_file *file_priv); 1407 1408 /* IRQ support (drm_irq.c) */ 1409 int drm_control(struct drm_device *dev, void *data, 1410 struct drm_file *file_priv); 1411 1412 /* AGP/GART support (drm_agpsupport.c) */ 1413 int drm_agp_acquire_ioctl(struct drm_device *dev, void *data, 1414 struct drm_file *file_priv); 1415 int drm_agp_release_ioctl(struct drm_device *dev, void *data, 1416 struct drm_file *file_priv); 1417 int drm_agp_enable_ioctl(struct drm_device *dev, void *data, 1418 struct drm_file *file_priv); 1419 int drm_agp_info_ioctl(struct drm_device *dev, void *data, 1420 struct drm_file *file_priv); 1421 int drm_agp_alloc_ioctl(struct drm_device *dev, void *data, 1422 struct drm_file *file_priv); 1423 int drm_agp_free_ioctl(struct drm_device *dev, void *data, 1424 struct drm_file *file_priv); 1425 int drm_agp_unbind_ioctl(struct drm_device *dev, void *data, 1426 struct drm_file *file_priv); 1427 int drm_agp_bind_ioctl(struct drm_device *dev, void *data, 1428 struct drm_file *file_priv); 1429 1430 /* Stub support (drm_stub.h) */ 1431 extern int drm_setmaster_ioctl(struct drm_device *dev, void *data, 1432 struct drm_file *file_priv); 1433 extern int drm_dropmaster_ioctl(struct drm_device *dev, void *data, 1434 struct drm_file *file_priv); 1435 1436 /* Scatter Gather Support (drm_scatter.c) */ 1437 int drm_sg_alloc_ioctl(struct drm_device *dev, void *data, 1438 struct drm_file *file_priv); 1439 int drm_sg_free(struct drm_device *dev, void *data, 1440 struct drm_file *file_priv); 1441 1442 /* consistent PCI memory functions (drm_pci.c) */ 1443 extern drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size, 1444 size_t align); 1445 void drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah); 1446 1447 /* sysfs support (drm_sysfs.c) */ 1448 struct drm_sysfs_class; 1449 extern struct class *drm_sysfs_create(struct module *owner, char *name); 1450 extern void drm_sysfs_destroy(void); 1451 extern int drm_sysfs_device_add(struct drm_minor *minor); 1452 extern void drm_sysfs_hotplug_event(struct drm_device *dev); 1453 extern void drm_sysfs_device_remove(struct drm_minor *minor); 1454 extern int drm_sysfs_connector_add(struct drm_connector *connector); 1455 extern void drm_sysfs_connector_remove(struct drm_connector *connector); 1456 1457 /* Graphics Execution Manager library functions (drm_gem.c) */ 1458 int drm_gem_init(struct drm_device *dev); 1459 void drm_gem_destroy(struct drm_device *dev); 1460 void drm_gem_object_release(struct drm_gem_object *obj); 1461 void drm_gem_object_free(struct kref *kref); 1462 int drm_gem_object_init(struct drm_device *dev, 1463 struct drm_gem_object *obj, size_t size); 1464 void drm_gem_private_object_init(struct drm_device *dev, 1465 struct drm_gem_object *obj, size_t size); 1466 1467 int i915_gem_pager_ctor(void *handle, vm_ooffset_t size, vm_prot_t prot, 1468 vm_ooffset_t foff, struct ucred *cred, u_short *color); 1469 void i915_gem_pager_dtor(void * handle); 1470 1471 #include <drm/drm_global.h> 1472 1473 static inline void 1474 drm_gem_object_reference(struct drm_gem_object *obj) 1475 { 1476 kref_get(&obj->refcount); 1477 } 1478 1479 static inline void 1480 drm_gem_object_unreference(struct drm_gem_object *obj) 1481 { 1482 if (obj != NULL) 1483 kref_put(&obj->refcount, drm_gem_object_free); 1484 } 1485 1486 static inline void 1487 drm_gem_object_unreference_unlocked(struct drm_gem_object *obj) 1488 { 1489 if (obj != NULL) { 1490 struct drm_device *dev = obj->dev; 1491 DRM_LOCK(dev); 1492 kref_put(&obj->refcount, drm_gem_object_free); 1493 DRM_UNLOCK(dev); 1494 } 1495 } 1496 1497 int drm_gem_handle_create(struct drm_file *file_priv, 1498 struct drm_gem_object *obj, 1499 u32 *handlep); 1500 int drm_gem_handle_delete(struct drm_file *filp, u32 handle); 1501 1502 static inline void 1503 drm_gem_object_handle_reference(struct drm_gem_object *obj) 1504 { 1505 drm_gem_object_reference(obj); 1506 atomic_inc(&obj->handle_count); 1507 } 1508 1509 struct drm_gem_object *drm_gem_object_lookup(struct drm_device *dev, 1510 struct drm_file *filp, 1511 u32 handle); 1512 int drm_gem_close_ioctl(struct drm_device *dev, void *data, 1513 struct drm_file *file_priv); 1514 int drm_gem_flink_ioctl(struct drm_device *dev, void *data, 1515 struct drm_file *file_priv); 1516 int drm_gem_open_ioctl(struct drm_device *dev, void *data, 1517 struct drm_file *file_priv); 1518 void drm_gem_open(struct drm_device *dev, struct drm_file *file_priv); 1519 void drm_gem_release(struct drm_device *dev, struct drm_file *file_priv); 1520 1521 void drm_gem_free_mmap_offset(struct drm_gem_object *obj); 1522 int drm_gem_create_mmap_offset(struct drm_gem_object *obj); 1523 int drm_gem_create_mmap_offset_size(struct drm_gem_object *obj, size_t size); 1524 1525 int drm_gem_mmap_single(struct drm_device *dev, vm_ooffset_t *offset, 1526 vm_size_t size, struct vm_object **obj_res, int nprot); 1527 void drm_gem_pager_dtr(void *obj); 1528 1529 struct ttm_bo_device; 1530 int ttm_bo_mmap_single(struct ttm_bo_device *bdev, vm_ooffset_t *offset, 1531 vm_size_t size, struct vm_object **obj_res, int nprot); 1532 struct ttm_buffer_object; 1533 void ttm_bo_release_mmap(struct ttm_buffer_object *bo); 1534 1535 void drm_device_lock_mtx(struct drm_device *dev); 1536 void drm_device_unlock_mtx(struct drm_device *dev); 1537 int drm_device_sleep_mtx(struct drm_device *dev, void *chan, int flags, 1538 const char *msg, int timeout); 1539 void drm_device_assert_mtx_locked(struct drm_device *dev); 1540 void drm_device_assert_mtx_unlocked(struct drm_device *dev); 1541 1542 void drm_device_lock_struct(struct drm_device *dev); 1543 void drm_device_unlock_struct(struct drm_device *dev); 1544 int drm_device_sleep_struct(struct drm_device *dev, void *chan, int flags, 1545 const char *msg, int timeout); 1546 void drm_device_assert_struct_locked(struct drm_device *dev); 1547 void drm_device_assert_struct_unlocked(struct drm_device *dev); 1548 1549 void drm_compat_locking_init(struct drm_device *dev); 1550 void drm_sleep_locking_init(struct drm_device *dev); 1551 1552 /* drm_modes.c */ 1553 bool drm_mode_parse_command_line_for_connector(const char *mode_option, 1554 struct drm_connector *connector, struct drm_cmdline_mode *mode); 1555 struct drm_display_mode *drm_mode_create_from_cmdline_mode( 1556 struct drm_device *dev, struct drm_cmdline_mode *cmd); 1557 1558 /* Inline replacements for drm_alloc and friends */ 1559 static __inline__ void * 1560 drm_alloc(size_t size, struct malloc_type *area) 1561 { 1562 return kmalloc(size, area, M_WAITOK | M_NULLOK); 1563 } 1564 1565 static __inline__ void * 1566 drm_calloc(size_t nmemb, size_t size, struct malloc_type *area) 1567 { 1568 return kmalloc(size * nmemb, area, M_WAITOK | M_NULLOK | M_ZERO); 1569 } 1570 1571 static __inline__ void 1572 drm_free(void *pt, struct malloc_type *area) 1573 { 1574 kfree(pt); 1575 } 1576 1577 static __inline__ void 1578 drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev) 1579 { 1580 map->handle = drm_ioremap_wc(dev, map); 1581 } 1582 static __inline__ void 1583 drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev) 1584 { 1585 map->handle = drm_ioremap(dev, map); 1586 } 1587 static __inline__ void 1588 drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev) 1589 { 1590 if ( map->handle && map->size ) 1591 drm_ioremapfree(map); 1592 } 1593 1594 static __inline__ struct drm_local_map * 1595 drm_core_findmap(struct drm_device *dev, unsigned long offset) 1596 { 1597 struct drm_map_list *_entry; 1598 1599 list_for_each_entry(_entry, &dev->maplist, head) { 1600 if (offset == (unsigned long)_entry->map->handle) 1601 return _entry->map; 1602 } 1603 return NULL; 1604 } 1605 1606 static __inline__ void drm_core_dropmap(struct drm_map *map) 1607 { 1608 } 1609 1610 #include <drm/drm_mem_util.h> 1611 1612 /* FreeBSD compatibility macros */ 1613 #define VM_OBJECT_WLOCK(object) VM_OBJECT_LOCK(object) 1614 #define VM_OBJECT_WUNLOCK(object) VM_OBJECT_UNLOCK(object) 1615 1616 #define DRM_PCIE_SPEED_25 1 1617 #define DRM_PCIE_SPEED_50 2 1618 #define DRM_PCIE_SPEED_80 4 1619 1620 extern int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *speed_mask); 1621 1622 #define drm_can_sleep() (DRM_HZ & 1) 1623 1624 #endif /* __KERNEL__ */ 1625 #endif /* _DRM_P_H_ */ 1626