1 /* 2 * drmP.h -- Private header for Direct Rendering Manager -*- linux-c -*- 3 * Created: Mon Jan 4 10:05:05 1999 by faith@precisioninsight.com 4 */ 5 /* 6 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. 7 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 8 * All rights reserved. 9 * 10 * Permission is hereby granted, free of charge, to any person obtaining a 11 * copy of this software and associated documentation files (the "Software"), 12 * to deal in the Software without restriction, including without limitation 13 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 14 * and/or sell copies of the Software, and to permit persons to whom the 15 * Software is furnished to do so, subject to the following conditions: 16 * 17 * The above copyright notice and this permission notice (including the next 18 * paragraph) shall be included in all copies or substantial portions of the 19 * Software. 20 * 21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 24 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 25 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 26 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 * OTHER DEALINGS IN THE SOFTWARE. 28 * 29 * Authors: 30 * Rickard E. (Rik) Faith <faith@valinux.com> 31 * Gareth Hughes <gareth@valinux.com> 32 * 33 */ 34 35 /* 36 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 37 * Use is subject to license terms. 38 */ 39 40 #ifndef _DRMP_H 41 #define _DRMP_H 42 43 #pragma ident "%Z%%M% %I% %E% SMI" 44 45 #include <sys/types.h> 46 #include <sys/conf.h> 47 #include <sys/modctl.h> 48 #include <sys/stat.h> 49 #include <sys/file.h> 50 #include <sys/cmn_err.h> 51 #include <sys/varargs.h> 52 #include <sys/pci.h> 53 #include <sys/ddi.h> 54 #include <sys/sunddi.h> 55 #include <sys/sunldi.h> 56 #include <sys/pmem.h> 57 #include <sys/agpgart.h> 58 #include <sys/time.h> 59 #include "drm_atomic.h" 60 #include "drm.h" 61 #include "queue.h" 62 #include "drm_linux_list.h" 63 64 #ifndef __inline__ 65 #define __inline__ inline 66 #endif 67 68 #if !defined(__FUNCTION__) 69 #if defined(C99) 70 #define __FUNCTION__ __func__ 71 #else 72 #define __FUNCTION__ " " 73 #endif 74 #endif 75 76 /* DRM space units */ 77 #define DRM_PAGE_SHIFT PAGESHIFT 78 #define DRM_PAGE_SIZE (1 << DRM_PAGE_SHIFT) 79 #define DRM_PAGE_OFFSET (DRM_PAGE_SIZE - 1) 80 #define DRM_PAGE_MASK ~(DRM_PAGE_SIZE - 1) 81 #define DRM_MB2PAGES(x) ((x) << 8) 82 #define DRM_PAGES2BYTES(x) ((x) << DRM_PAGE_SHIFT) 83 #define DRM_BYTES2PAGES(x) ((x) >> DRM_PAGE_SHIFT) 84 #define DRM_PAGES2KB(x) ((x) << 2) 85 #define DRM_ALIGNED(offset) (((offset) & DRM_PAGE_OFFSET) == 0) 86 87 #define PAGE_SHIFT DRM_PAGE_SHIFT 88 #define PAGE_SIZE DRM_PAGE_SIZE 89 90 #define DRM_MAX_INSTANCES 8 91 #define DRM_DEVNODE "drm" 92 #define DRM_UNOPENED 0 93 #define DRM_OPENED 1 94 95 #define DRM_HASH_SIZE 16 /* Size of key hash table */ 96 #define DRM_KERNEL_CONTEXT 0 /* Change drm_resctx if changed */ 97 #define DRM_RESERVED_CONTEXTS 1 /* Change drm_resctx if changed */ 98 99 #define DRM_MEM_DMA 0 100 #define DRM_MEM_SAREA 1 101 #define DRM_MEM_DRIVER 2 102 #define DRM_MEM_MAGIC 3 103 #define DRM_MEM_IOCTLS 4 104 #define DRM_MEM_MAPS 5 105 #define DRM_MEM_BUFS 6 106 #define DRM_MEM_SEGS 7 107 #define DRM_MEM_PAGES 8 108 #define DRM_MEM_FILES 9 109 #define DRM_MEM_QUEUES 10 110 #define DRM_MEM_CMDS 11 111 #define DRM_MEM_MAPPINGS 12 112 #define DRM_MEM_BUFLISTS 13 113 #define DRM_MEM_DRMLISTS 14 114 #define DRM_MEM_TOTALDRM 15 115 #define DRM_MEM_BOUNDDRM 16 116 #define DRM_MEM_CTXBITMAP 17 117 #define DRM_MEM_STUB 18 118 #define DRM_MEM_SGLISTS 19 119 #define DRM_MEM_AGPLISTS 20 120 #define DRM_MEM_CTXLIST 21 121 #define DRM_MEM_MM 22 122 #define DRM_MEM_HASHTAB 23 123 #define DRM_MEM_OBJECTS 24 124 125 #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8) 126 #define DRM_MAP_HASH_OFFSET 0x10000000 127 #define DRM_MAP_HASH_ORDER 12 128 #define DRM_OBJECT_HASH_ORDER 12 129 #define DRM_FILE_PAGE_OFFSET_START ((0xFFFFFFFFUL >> PAGE_SHIFT) + 1) 130 #define DRM_FILE_PAGE_OFFSET_SIZE ((0xFFFFFFFFUL >> PAGE_SHIFT) * 16) 131 #define DRM_MM_INIT_MAX_PAGES 256 132 133 134 /* Internal types and structures */ 135 #define DRM_ARRAY_SIZE(x) (sizeof (x) / sizeof (x[0])) 136 #define DRM_MIN(a, b) ((a) < (b) ? (a) : (b)) 137 #define DRM_MAX(a, b) ((a) > (b) ? (a) : (b)) 138 139 #define DRM_IF_VERSION(maj, min) (maj << 16 | min) 140 141 #define __OS_HAS_AGP 1 142 143 #define DRM_DEV_MOD (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) 144 #define DRM_DEV_UID 0 145 #define DRM_DEV_GID 0 146 147 #define DRM_CURRENTPID ddi_get_pid() 148 #define DRM_SPINLOCK(l) mutex_enter(l) 149 #define DRM_SPINUNLOCK(u) mutex_exit(u) 150 #define DRM_SPINLOCK_ASSERT(l) 151 #define DRM_LOCK() mutex_enter(&dev->dev_lock) 152 #define DRM_UNLOCK() mutex_exit(&dev->dev_lock) 153 #define DRM_LOCK_OWNED() ASSERT(mutex_owned(&dev->dev_lock)) 154 #define spin_lock_irqsave(l, flag) mutex_enter(l) 155 #define spin_unlock_irqrestore(u, flag) mutex_exit(u) 156 #define spin_lock(l) mutex_enter(l) 157 #define spin_unlock(u) mutex_exit(u) 158 159 #define DRM_UDELAY(sec) delay(drv_usectohz(sec *1000)) 160 #define DRM_MEMORYBARRIER() 161 162 typedef struct drm_file drm_file_t; 163 typedef struct drm_device drm_device_t; 164 typedef struct drm_driver_info drm_driver_t; 165 166 #define DRM_DEVICE drm_device_t *dev = dev1 167 #define DRM_IOCTL_ARGS \ 168 drm_device_t *dev1, intptr_t data, drm_file_t *fpriv, int mode 169 170 #define DRM_COPYFROM_WITH_RETURN(dest, src, size) \ 171 if (ddi_copyin(src, dest, size, 0)) \ 172 return (EFAULT) 173 174 #define DRM_COPYTO_WITH_RETURN(dest, src, size) \ 175 if (ddi_copyout((src), (dest), (size), 0)) \ 176 return (EFAULT) 177 178 #define DRM_COPY_FROM_USER(dest, src, size) \ 179 ddi_copyin((src), (dest), (size), 0) /* flag for src */ 180 181 #define DRM_COPY_TO_USER(dest, src, size) \ 182 ddi_copyout((src), (dest), (size), 0) /* flags for dest */ 183 184 #define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) \ 185 ddi_copyin((arg2), (arg1), (arg3), 0) 186 187 #define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3) \ 188 ddi_copyout((arg2), arg1, arg3, 0) 189 190 #define DRM_READ8(map, offset) \ 191 *(uint8_t *)((uintptr_t)((map)->dev_addr) + (offset)) 192 #define DRM_READ16(map, offset) \ 193 *(uint16_t *)((uintptr_t)((map)->dev_addr) + (offset)) 194 #define DRM_READ32(map, offset) \ 195 *(uint32_t *)((uintptr_t)((map)->dev_addr) + (offset)) 196 #define DRM_WRITE8(map, offset, val) \ 197 *(uint8_t *)((uintptr_t)((map)->dev_addr) + (offset)) = (val) 198 #define DRM_WRITE16(map, offset, val) \ 199 *(uint16_t *)((uintptr_t)((map)->dev_addr) + (offset)) = (val) 200 #define DRM_WRITE32(map, offset, val) \ 201 *(uint32_t *)((uintptr_t)((map)->dev_addr) + (offset)) = (val) 202 203 typedef struct drm_wait_queue { 204 kcondvar_t cv; 205 kmutex_t lock; 206 }wait_queue_head_t; 207 208 #define DRM_INIT_WAITQUEUE(q, pri) \ 209 { \ 210 mutex_init(&(q)->lock, NULL, MUTEX_DRIVER, pri); \ 211 cv_init(&(q)->cv, NULL, CV_DRIVER, NULL); \ 212 } 213 214 #define DRM_FINI_WAITQUEUE(q) \ 215 { \ 216 mutex_destroy(&(q)->lock); \ 217 cv_destroy(&(q)->cv); \ 218 } 219 220 #define DRM_WAKEUP(q) \ 221 { \ 222 mutex_enter(&(q)->lock); \ 223 cv_broadcast(&(q)->cv); \ 224 mutex_exit(&(q)->lock); \ 225 } 226 227 #define jiffies ddi_get_lbolt() 228 #define DRM_WAIT_ON(ret, q, timeout, condition) \ 229 mutex_enter(&(q)->lock); \ 230 while (!(condition)) { \ 231 ret = cv_timedwait_sig(&(q)->cv, &(q)->lock, jiffies + timeout); \ 232 if (ret == -1) { \ 233 ret = EBUSY; \ 234 break; \ 235 } else if (ret == 0) { \ 236 ret = EINTR; \ 237 break; \ 238 } else { \ 239 ret = 0; \ 240 } \ 241 } \ 242 mutex_exit(&(q)->lock); 243 244 #define DRM_GETSAREA() \ 245 { \ 246 drm_local_map_t *map; \ 247 DRM_SPINLOCK_ASSERT(&dev->dev_lock); \ 248 TAILQ_FOREACH(map, &dev->maplist, link) { \ 249 if (map->type == _DRM_SHM && \ 250 map->flags & _DRM_CONTAINS_LOCK) { \ 251 dev_priv->sarea = map; \ 252 break; \ 253 } \ 254 } \ 255 } 256 257 #define LOCK_TEST_WITH_RETURN(dev, fpriv) \ 258 if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) || \ 259 dev->lock.filp != fpriv) { \ 260 DRM_ERROR("called without lock held"); \ 261 return (EINVAL); \ 262 } 263 264 #define DRM_IRQ_ARGS caddr_t arg 265 #define IRQ_HANDLED DDI_INTR_CLAIMED 266 #define IRQ_NONE DDI_INTR_UNCLAIMED 267 268 enum { 269 DRM_IS_NOT_AGP, 270 DRM_IS_AGP, 271 DRM_MIGHT_BE_AGP 272 }; 273 274 /* Capabilities taken from src/sys/dev/pci/pcireg.h. */ 275 #ifndef PCIY_AGP 276 #define PCIY_AGP 0x02 277 #endif 278 279 #ifndef PCIY_EXPRESS 280 #define PCIY_EXPRESS 0x10 281 #endif 282 283 #define PAGE_ALIGN(addr) (((addr) + DRM_PAGE_SIZE - 1) & DRM_PAGE_MASK) 284 #define DRM_SUSER(p) (crgetgid(p) == 0 || crgetuid(p) == 0) 285 286 /* 287 * wait for 400 milliseconds 288 */ 289 #define DRM_HZ drv_usectohz(400000) 290 291 typedef unsigned long dma_addr_t; 292 typedef uint64_t u64; 293 typedef uint32_t u32; 294 typedef uint16_t u16; 295 typedef uint8_t u8; 296 typedef uint_t irqreturn_t; 297 298 #define DRM_SUPPORT 1 299 #define DRM_UNSUPPORT 0 300 301 #define __OS_HAS_AGP 1 302 303 #define __offsetof(type, field) ((size_t)(&((type *)0)->field)) 304 #define offsetof(type, field) __offsetof(type, field) 305 306 typedef struct drm_pci_id_list 307 { 308 int vendor; 309 int device; 310 long driver_private; 311 char *name; 312 } drm_pci_id_list_t; 313 314 #define DRM_AUTH 0x1 315 #define DRM_MASTER 0x2 316 #define DRM_ROOT_ONLY 0x4 317 typedef int drm_ioctl_t(DRM_IOCTL_ARGS); 318 typedef struct drm_ioctl_desc { 319 int (*func)(DRM_IOCTL_ARGS); 320 int auth_needed; 321 int root_only; 322 char *desc; 323 int flags; 324 } drm_ioctl_desc_t; 325 326 typedef struct drm_magic_entry { 327 drm_magic_t magic; 328 struct drm_file *priv; 329 struct drm_magic_entry *next; 330 } drm_magic_entry_t; 331 332 typedef struct drm_magic_head { 333 struct drm_magic_entry *head; 334 struct drm_magic_entry *tail; 335 } drm_magic_head_t; 336 337 typedef struct drm_buf { 338 int idx; /* Index into master buflist */ 339 int total; /* Buffer size */ 340 int order; /* log-base-2(total) */ 341 int used; /* Amount of buffer in use (for DMA) */ 342 unsigned long offset; /* Byte offset (used internally) */ 343 void *address; /* Address of buffer */ 344 unsigned long bus_address; /* Bus address of buffer */ 345 struct drm_buf *next; /* Kernel-only: used for free list */ 346 volatile int pending; /* On hardware DMA queue */ 347 drm_file_t *filp; 348 /* Uniq. identifier of holding process */ 349 int context; /* Kernel queue for this buffer */ 350 enum { 351 DRM_LIST_NONE = 0, 352 DRM_LIST_FREE = 1, 353 DRM_LIST_WAIT = 2, 354 DRM_LIST_PEND = 3, 355 DRM_LIST_PRIO = 4, 356 DRM_LIST_RECLAIM = 5 357 } list; /* Which list we're on */ 358 359 int dev_priv_size; /* Size of buffer private stoarge */ 360 void *dev_private; /* Per-buffer private storage */ 361 } drm_buf_t; 362 363 typedef struct drm_freelist { 364 int initialized; /* Freelist in use */ 365 uint32_t count; /* Number of free buffers */ 366 drm_buf_t *next; /* End pointer */ 367 368 int low_mark; /* Low water mark */ 369 int high_mark; /* High water mark */ 370 } drm_freelist_t; 371 372 typedef struct drm_buf_entry { 373 int buf_size; 374 int buf_count; 375 drm_buf_t *buflist; 376 int seg_count; 377 int page_order; 378 379 uint32_t *seglist; 380 unsigned long *seglist_bus; 381 382 drm_freelist_t freelist; 383 } drm_buf_entry_t; 384 385 typedef TAILQ_HEAD(drm_file_list, drm_file) drm_file_list_t; 386 struct drm_file { 387 TAILQ_ENTRY(drm_file) link; 388 int authenticated; 389 int master; 390 int minor; 391 pid_t pid; 392 uid_t uid; 393 int refs; 394 drm_magic_t magic; 395 unsigned long ioctl_count; 396 void *driver_priv; 397 }; 398 399 typedef struct drm_lock_data { 400 drm_hw_lock_t *hw_lock; /* Hardware lock */ 401 drm_file_t *filp; 402 /* Uniq. identifier of holding process */ 403 kcondvar_t lock_cv; /* lock queue - SOLARIS Specific */ 404 kmutex_t lock_mutex; /* lock - SOLARIS Specific */ 405 unsigned long lock_time; /* Time of last lock in jiffies */ 406 } drm_lock_data_t; 407 408 /* 409 * This structure, in drm_device_t, is always initialized while the device 410 * is open. dev->dma_lock protects the incrementing of dev->buf_use, which 411 * when set marks that no further bufs may be allocated until device teardown 412 * occurs (when the last open of the device has closed). The high/low 413 * watermarks of bufs are only touched by the X Server, and thus not 414 * concurrently accessed, so no locking is needed. 415 */ 416 typedef struct drm_device_dma { 417 drm_buf_entry_t bufs[DRM_MAX_ORDER+1]; 418 int buf_count; 419 drm_buf_t **buflist; /* Vector of pointers info bufs */ 420 int seg_count; 421 int page_count; 422 unsigned long *pagelist; 423 unsigned long byte_count; 424 enum { 425 _DRM_DMA_USE_AGP = 0x01, 426 _DRM_DMA_USE_SG = 0x02 427 } flags; 428 } drm_device_dma_t; 429 430 typedef struct drm_agp_mem { 431 void *handle; 432 unsigned long bound; /* address */ 433 int pages; 434 caddr_t phys_addr; 435 struct drm_agp_mem *prev; 436 struct drm_agp_mem *next; 437 } drm_agp_mem_t; 438 439 typedef struct drm_agp_head { 440 agp_info_t agp_info; 441 const char *chipset; 442 drm_agp_mem_t *memory; 443 unsigned long mode; 444 int enabled; 445 int acquired; 446 unsigned long base; 447 int mtrr; 448 int cant_use_aperture; 449 unsigned long page_mask; 450 ldi_ident_t agpgart_li; 451 ldi_handle_t agpgart_lh; 452 } drm_agp_head_t; 453 454 455 typedef struct drm_dma_handle { 456 ddi_dma_handle_t dma_hdl; 457 ddi_acc_handle_t acc_hdl; 458 ddi_dma_cookie_t cookie; 459 uint_t cookie_num; 460 uintptr_t vaddr; /* virtual addr */ 461 uintptr_t paddr; /* physical addr */ 462 size_t req_sz; /* required size of memory */ 463 size_t real_sz; /* real size of memory */ 464 } drm_dma_handle_t; 465 466 typedef struct drm_sg_mem { 467 unsigned long handle; 468 void *virtual; 469 int pages; 470 dma_addr_t *busaddr; 471 ddi_umem_cookie_t *umem_cookie; 472 drm_dma_handle_t *dmah_sg; 473 drm_dma_handle_t *dmah_gart; /* Handle to PCI memory */ 474 } drm_sg_mem_t; 475 476 typedef TAILQ_HEAD(drm_map_list, drm_local_map) drm_map_list_t; 477 478 /* BEGIN CSTYLED */ 479 typedef struct drm_local_map { 480 unsigned long offset; /* Physical address (0 for SAREA) */ 481 unsigned long size; /* Physical size (bytes) */ 482 drm_map_type_t type; /* Type of memory mapped */ 483 drm_map_flags_t flags; /* Flags */ 484 void *handle; /* User-space: "Handle" to pass to mmap */ 485 /* Kernel-space: kernel-virtual address */ 486 int mtrr; /* Boolean: MTRR used */ 487 /* Private data */ 488 int rid; /* PCI resource ID for bus_space */ 489 int kernel_owned; /* Boolean: 1= initmapped, 0= addmapped */ 490 caddr_t dev_addr; /* base device address */ 491 ddi_acc_handle_t dev_handle; /* The data access handle */ 492 ddi_umem_cookie_t drm_umem_cookie; /* For SAREA alloc and free */ 493 TAILQ_ENTRY(drm_local_map) link; 494 } drm_local_map_t; 495 /* END CSTYLED */ 496 497 typedef TAILQ_HEAD(drm_vbl_sig_list, drm_vbl_sig) drm_vbl_sig_list_t; 498 typedef struct drm_vbl_sig { 499 TAILQ_ENTRY(drm_vbl_sig) link; 500 unsigned int sequence; 501 int signo; 502 int pid; 503 } drm_vbl_sig_t; 504 505 506 /* used for clone device */ 507 typedef TAILQ_HEAD(drm_cminor_list, drm_cminor) drm_cminor_list_t; 508 typedef struct drm_cminor { 509 TAILQ_ENTRY(drm_cminor) link; 510 drm_file_t *fpriv; 511 int minor; 512 } drm_cminor_t; 513 514 /* location of GART table */ 515 #define DRM_ATI_GART_MAIN 1 516 #define DRM_ATI_GART_FB 2 517 518 typedef struct ati_pcigart_info { 519 int gart_table_location; 520 int is_pcie; 521 void *addr; 522 dma_addr_t bus_addr; 523 drm_local_map_t mapping; 524 } drm_ati_pcigart_info; 525 526 527 528 /* DRM device structure */ 529 struct drm_device; 530 struct drm_driver_info { 531 int (*load)(struct drm_device *, unsigned long); 532 int (*firstopen)(struct drm_device *); 533 int (*open)(struct drm_device *, drm_file_t *); 534 void (*preclose)(struct drm_device *, drm_file_t *); 535 void (*postclose)(struct drm_device *, drm_file_t *); 536 void (*lastclose)(struct drm_device *); 537 int (*unload)(struct drm_device *); 538 void (*reclaim_buffers_locked)(struct drm_device *, drm_file_t *); 539 int (*presetup)(struct drm_device *); 540 int (*postsetup)(struct drm_device *); 541 int (*open_helper)(struct drm_device *, drm_file_t *); 542 void (*free_filp_priv)(struct drm_device *, drm_file_t *); 543 void (*release)(struct drm_device *, void *); 544 int (*dma_ioctl)(DRM_IOCTL_ARGS); 545 void (*dma_ready)(struct drm_device *); 546 int (*dma_quiescent)(struct drm_device *); 547 int (*dma_flush_block_and_flush)(struct drm_device *, 548 int, drm_lock_flags_t); 549 int (*dma_flush_unblock)(struct drm_device *, int, 550 drm_lock_flags_t); 551 int (*context_ctor)(struct drm_device *, int); 552 int (*context_dtor)(struct drm_device *, int); 553 int (*kernel_context_switch)(struct drm_device *, int, int); 554 int (*kernel_context_switch_unlock)(struct drm_device *); 555 int (*device_is_agp) (struct drm_device *); 556 void (*irq_preinstall)(struct drm_device *); 557 void (*irq_postinstall)(struct drm_device *); 558 void (*irq_uninstall)(struct drm_device *dev); 559 uint_t (*irq_handler)(DRM_IRQ_ARGS); 560 int (*vblank_wait)(struct drm_device *, unsigned int *); 561 int (*vblank_wait2)(struct drm_device *, unsigned int *); 562 563 drm_ioctl_desc_t *driver_ioctls; 564 int max_driver_ioctl; 565 566 int buf_priv_size; 567 int driver_major; 568 int driver_minor; 569 int driver_patchlevel; 570 const char *driver_name; /* Simple driver name */ 571 const char *driver_desc; /* Longer driver name */ 572 const char *driver_date; /* Date of last major changes. */ 573 574 unsigned use_agp :1; 575 unsigned require_agp :1; 576 unsigned use_sg :1; 577 unsigned use_dma :1; 578 unsigned use_pci_dma :1; 579 unsigned use_dma_queue :1; 580 unsigned use_irq :1; 581 unsigned use_vbl_irq :1; 582 unsigned use_vbl_irq2 :1; 583 unsigned use_mtrr :1; 584 }; 585 586 587 /* 588 * hardware-specific code needs to initialize mutexes which 589 * can be used in interrupt context, so they need to know 590 * the interrupt priority. Interrupt cookie in drm_device 591 * structure is the intr_block field. 592 */ 593 #define DRM_INTR_PRI(dev) \ 594 DDI_INTR_PRI((dev)->intr_block) 595 596 struct drm_device { 597 drm_driver_t *driver; 598 drm_cminor_list_t minordevs; 599 dev_info_t *dip; 600 void *drm_handle; 601 int drm_supported; 602 const char *desc; /* current driver description */ 603 kmutex_t *irq_mutex; 604 kcondvar_t *irq_cv; 605 606 ddi_iblock_cookie_t intr_block; 607 uint32_t pci_device; /* PCI device id */ 608 uint32_t pci_vendor; 609 char *unique; /* Unique identifier: e.g., busid */ 610 int unique_len; /* Length of unique field */ 611 int if_version; /* Highest interface version set */ 612 int flags; /* Flags to open(2) */ 613 614 /* Locks */ 615 kmutex_t dma_lock; /* protects dev->dma */ 616 kmutex_t irq_lock; /* protects irq condition checks */ 617 kmutex_t dev_lock; /* protects everything else */ 618 drm_lock_data_t lock; /* Information on hardware lock */ 619 620 /* Usage Counters */ 621 int open_count; /* Outstanding files open */ 622 int buf_use; /* Buffers in use -- cannot alloc */ 623 624 /* Performance counters */ 625 unsigned long counters; 626 drm_stat_type_t types[15]; 627 uint32_t counts[15]; 628 629 /* Authentication */ 630 drm_file_list_t files; 631 drm_magic_head_t magiclist[DRM_HASH_SIZE]; 632 633 /* Linked list of mappable regions. Protected by dev_lock */ 634 drm_map_list_t maplist; 635 636 drm_local_map_t **context_sareas; 637 int max_context; 638 639 /* DMA queues (contexts) */ 640 drm_device_dma_t *dma; /* Optional pointer for DMA support */ 641 642 /* Context support */ 643 int irq; /* Interrupt used by board */ 644 int irq_enabled; /* True if the irq handler is enabled */ 645 int pci_domain; 646 int pci_bus; 647 int pci_slot; 648 int pci_func; 649 atomic_t context_flag; /* Context swapping flag */ 650 int last_context; /* Last current context */ 651 652 atomic_t vbl_received; 653 atomic_t vbl_received2; 654 drm_vbl_sig_list_t vbl_sig_list; 655 drm_vbl_sig_list_t vbl_sig_list2; 656 wait_queue_head_t vbl_queue; /* vbl wait channel */ 657 658 kmutex_t tasklet_lock; 659 void (*locked_tasklet_func)(struct drm_device *dev); 660 661 pid_t buf_pgid; 662 drm_agp_head_t *agp; 663 drm_sg_mem_t *sg; /* Scatter gather memory */ 664 uint32_t *ctx_bitmap; 665 void *dev_private; 666 unsigned int agp_buffer_token; 667 drm_local_map_t *agp_buffer_map; 668 669 kstat_t *asoft_ksp; /* kstat support */ 670 671 /* name Drawable information */ 672 kmutex_t drw_lock; 673 unsigned int drw_bitfield_length; 674 u32 *drw_bitfield; 675 unsigned int drw_info_length; 676 drm_drawable_info_t **drw_info; 677 678 /* 679 * Saving S3 context 680 */ 681 void *s3_private; 682 }; 683 684 /* Memory management support (drm_memory.c) */ 685 void drm_mem_init(void); 686 void drm_mem_uninit(void); 687 void *drm_alloc(size_t, int); 688 void *drm_calloc(size_t, size_t, int); 689 void *drm_realloc(void *, size_t, size_t, int); 690 void drm_free(void *, size_t, int); 691 int drm_ioremap(drm_device_t *, drm_local_map_t *); 692 void drm_ioremapfree(drm_local_map_t *); 693 694 void drm_core_ioremap(struct drm_local_map *, struct drm_device *); 695 void drm_core_ioremapfree(struct drm_local_map *, struct drm_device *); 696 697 void drm_pci_free(drm_device_t *, drm_dma_handle_t *); 698 void *drm_pci_alloc(drm_device_t *, size_t, size_t, dma_addr_t, int); 699 700 struct drm_local_map *drm_core_findmap(struct drm_device *, unsigned long); 701 702 int drm_context_switch(drm_device_t *, int, int); 703 int drm_context_switch_complete(drm_device_t *, int); 704 int drm_ctxbitmap_init(drm_device_t *); 705 void drm_ctxbitmap_cleanup(drm_device_t *); 706 void drm_ctxbitmap_free(drm_device_t *, int); 707 int drm_ctxbitmap_next(drm_device_t *); 708 709 /* Locking IOCTL support (drm_lock.c) */ 710 int drm_lock_take(drm_lock_data_t *, unsigned int); 711 int drm_lock_transfer(drm_device_t *, 712 volatile unsigned int *, unsigned int); 713 int drm_lock_free(drm_device_t *, 714 volatile unsigned int *, unsigned int); 715 716 /* Buffer management support (drm_bufs.c) */ 717 unsigned long drm_get_resource_start(drm_device_t *, unsigned int); 718 unsigned long drm_get_resource_len(drm_device_t *, unsigned int); 719 int drm_initmap(drm_device_t *, unsigned long, unsigned long, 720 unsigned int, int, int); 721 void drm_rmmap(drm_device_t *, drm_local_map_t *); 722 int drm_addmap(drm_device_t *, unsigned long, unsigned long, 723 drm_map_type_t, drm_map_flags_t, drm_local_map_t **); 724 int drm_order(unsigned long); 725 726 /* DMA support (drm_dma.c) */ 727 int drm_dma_setup(drm_device_t *); 728 void drm_dma_takedown(drm_device_t *); 729 void drm_free_buffer(drm_device_t *, drm_buf_t *); 730 void drm_reclaim_buffers(drm_device_t *, drm_file_t *); 731 #define drm_core_reclaim_buffers drm_reclaim_buffers 732 733 /* IRQ support (drm_irq.c) */ 734 int drm_irq_install(drm_device_t *); 735 int drm_irq_uninstall(drm_device_t *); 736 uint_t drm_irq_handler(DRM_IRQ_ARGS); 737 void drm_driver_irq_preinstall(drm_device_t *); 738 void drm_driver_irq_postinstall(drm_device_t *); 739 void drm_driver_irq_uninstall(drm_device_t *); 740 int drm_vblank_wait(drm_device_t *, unsigned int *); 741 void drm_vbl_send_signals(drm_device_t *); 742 void drm_locked_tasklet(drm_device_t *, void(*func)(drm_device_t *)); 743 744 /* AGP/GART support (drm_agpsupport.c) */ 745 int drm_device_is_agp(drm_device_t *); 746 int drm_device_is_pcie(drm_device_t *); 747 drm_agp_head_t *drm_agp_init(drm_device_t *); 748 void drm_agp_fini(drm_device_t *); 749 int drm_agp_do_release(drm_device_t *); 750 void *drm_agp_allocate_memory(size_t, uint32_t); 751 int drm_agp_free_memory(void *); 752 int drm_agp_bind_memory(unsigned int, uint32_t, drm_device_t *); 753 int drm_agp_unbind_memory(unsigned long, drm_device_t *); 754 755 /* kstat support (drm_kstats.c) */ 756 int drm_init_kstats(drm_device_t *); 757 void drm_fini_kstats(drm_device_t *); 758 759 /* Scatter Gather Support (drm_scatter.c) */ 760 void drm_sg_cleanup(drm_device_t *, drm_sg_mem_t *); 761 762 /* ATI PCIGART support (ati_pcigart.c) */ 763 int drm_ati_pcigart_init(drm_device_t *, drm_ati_pcigart_info *); 764 int drm_ati_pcigart_cleanup(drm_device_t *, drm_ati_pcigart_info *); 765 766 /* Locking IOCTL support (drm_drv.c) */ 767 int drm_lock(DRM_IOCTL_ARGS); 768 int drm_unlock(DRM_IOCTL_ARGS); 769 int drm_version(DRM_IOCTL_ARGS); 770 int drm_setversion(DRM_IOCTL_ARGS); 771 772 /* Misc. IOCTL support (drm_ioctl.c) */ 773 int drm_irq_by_busid(DRM_IOCTL_ARGS); 774 int drm_getunique(DRM_IOCTL_ARGS); 775 int drm_setunique(DRM_IOCTL_ARGS); 776 int drm_getmap(DRM_IOCTL_ARGS); 777 int drm_getclient(DRM_IOCTL_ARGS); 778 int drm_getstats(DRM_IOCTL_ARGS); 779 int drm_noop(DRM_IOCTL_ARGS); 780 781 /* Context IOCTL support (drm_context.c) */ 782 int drm_resctx(DRM_IOCTL_ARGS); 783 int drm_addctx(DRM_IOCTL_ARGS); 784 int drm_modctx(DRM_IOCTL_ARGS); 785 int drm_getctx(DRM_IOCTL_ARGS); 786 int drm_switchctx(DRM_IOCTL_ARGS); 787 int drm_newctx(DRM_IOCTL_ARGS); 788 int drm_rmctx(DRM_IOCTL_ARGS); 789 int drm_setsareactx(DRM_IOCTL_ARGS); 790 int drm_getsareactx(DRM_IOCTL_ARGS); 791 792 /* Drawable IOCTL support (drm_drawable.c) */ 793 int drm_adddraw(DRM_IOCTL_ARGS); 794 int drm_rmdraw(DRM_IOCTL_ARGS); 795 796 /* Authentication IOCTL support (drm_auth.c) */ 797 int drm_getmagic(DRM_IOCTL_ARGS); 798 int drm_authmagic(DRM_IOCTL_ARGS); 799 int drm_remove_magic(drm_device_t *, drm_magic_t); 800 drm_file_t *drm_find_file(drm_device_t *, drm_magic_t); 801 /* Buffer management support (drm_bufs.c) */ 802 int drm_addmap_ioctl(DRM_IOCTL_ARGS); 803 int drm_rmmap_ioctl(DRM_IOCTL_ARGS); 804 int drm_addbufs_ioctl(DRM_IOCTL_ARGS); 805 int drm_infobufs(DRM_IOCTL_ARGS); 806 int drm_markbufs(DRM_IOCTL_ARGS); 807 int drm_freebufs(DRM_IOCTL_ARGS); 808 int drm_mapbufs(DRM_IOCTL_ARGS); 809 810 /* DMA support (drm_dma.c) */ 811 int drm_dma(DRM_IOCTL_ARGS); 812 813 /* IRQ support (drm_irq.c) */ 814 int drm_control(DRM_IOCTL_ARGS); 815 int drm_wait_vblank(DRM_IOCTL_ARGS); 816 817 /* AGP/GART support (drm_agpsupport.c) */ 818 int drm_agp_acquire(DRM_IOCTL_ARGS); 819 int drm_agp_release(DRM_IOCTL_ARGS); 820 int drm_agp_enable(DRM_IOCTL_ARGS); 821 int drm_agp_info(DRM_IOCTL_ARGS); 822 int drm_agp_alloc(DRM_IOCTL_ARGS); 823 int drm_agp_free(DRM_IOCTL_ARGS); 824 int drm_agp_unbind(DRM_IOCTL_ARGS); 825 int drm_agp_bind(DRM_IOCTL_ARGS); 826 827 /* Scatter Gather Support (drm_scatter.c) */ 828 int drm_sg_alloc(DRM_IOCTL_ARGS); 829 int drm_sg_free(DRM_IOCTL_ARGS); 830 831 extern int drm_debug_flag; 832 833 834 /* We add function to support DRM_DEBUG,DRM_ERROR,DRM_INFO */ 835 extern void drm_debug(const char *fmt, ...); 836 extern void drm_error(const char *fmt, ...); 837 extern void drm_info(const char *fmt, ...); 838 839 #ifdef DEBUG 840 #define DRM_DEBUG if (drm_debug_flag >= 2) drm_debug 841 #define DRM_INFO if (drm_debug_flag >= 1) drm_info 842 #else 843 #define DRM_DEBUG(...) 844 #define DRM_INFO(...) 845 #endif 846 847 #define DRM_ERROR drm_error 848 849 850 #define MAX_INSTNUMS 16 851 852 extern int drm_dev_to_instance(dev_t); 853 extern int drm_dev_to_minor(dev_t); 854 extern void *drm_supp_register(dev_info_t *, drm_device_t *); 855 extern int drm_supp_unregister(void *); 856 857 extern int drm_open(drm_device_t *, drm_cminor_t *, int, int, cred_t *); 858 extern int drm_close(drm_device_t *, int, int, int, cred_t *); 859 extern int drm_attach(drm_device_t *); 860 extern int drm_detach(drm_device_t *); 861 extern int drm_probe(drm_device_t *, drm_pci_id_list_t *); 862 863 extern int drm_pci_init(drm_device_t *); 864 extern void drm_pci_end(drm_device_t *); 865 extern int pci_get_info(drm_device_t *, int *, int *, int *); 866 extern int pci_get_irq(drm_device_t *); 867 extern int pci_get_vendor(drm_device_t *); 868 extern int pci_get_device(drm_device_t *); 869 870 extern drm_drawable_info_t *drm_get_drawable_info(drm_device_t *, 871 drm_drawable_t); 872 873 /* File Operations helpers (drm_fops.c) */ 874 extern drm_file_t *drm_find_file_by_proc(drm_device_t *, cred_t *); 875 extern drm_cminor_t *drm_find_file_by_minor(drm_device_t *, int); 876 extern int drm_open_helper(drm_device_t *, drm_cminor_t *, int, int, 877 cred_t *); 878 879 #endif /* _DRMP_H */ 880