195584Sanholt/* drmP.h -- Private header for Direct Rendering Manager -*- linux-c -*- 2145132Sanholt * Created: Mon Jan 4 10:05:05 1999 by faith@precisioninsight.com 3145132Sanholt */ 4139749Simp/*- 595584Sanholt * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. 695584Sanholt * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 795584Sanholt * All rights reserved. 895584Sanholt * 995584Sanholt * Permission is hereby granted, free of charge, to any person obtaining a 1095584Sanholt * copy of this software and associated documentation files (the "Software"), 1195584Sanholt * to deal in the Software without restriction, including without limitation 1295584Sanholt * the rights to use, copy, modify, merge, publish, distribute, sublicense, 1395584Sanholt * and/or sell copies of the Software, and to permit persons to whom the 1495584Sanholt * Software is furnished to do so, subject to the following conditions: 1595584Sanholt * 1695584Sanholt * The above copyright notice and this permission notice (including the next 1795584Sanholt * paragraph) shall be included in all copies or substantial portions of the 1895584Sanholt * Software. 1995584Sanholt * 2095584Sanholt * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 2195584Sanholt * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 2295584Sanholt * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 2395584Sanholt * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 2495584Sanholt * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 2595584Sanholt * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 2695584Sanholt * OTHER DEALINGS IN THE SOFTWARE. 2795584Sanholt * 2895584Sanholt * Authors: 2995584Sanholt * Rickard E. (Rik) Faith <faith@valinux.com> 3095584Sanholt * Gareth Hughes <gareth@valinux.com> 31119098Sanholt * 3295584Sanholt */ 3395584Sanholt 34152909Sanholt#include <sys/cdefs.h> 35152909Sanholt__FBSDID("$FreeBSD$"); 36152909Sanholt 3795584Sanholt#ifndef _DRM_P_H_ 3895584Sanholt#define _DRM_P_H_ 3995584Sanholt 4095584Sanholt#if defined(_KERNEL) || defined(__KERNEL__) 4195584Sanholt 42182080Srnolandstruct drm_device; 43183573Srnolandstruct drm_file; 4495584Sanholt 45145132Sanholt#include <sys/param.h> 46145132Sanholt#include <sys/queue.h> 47145132Sanholt#include <sys/malloc.h> 48145132Sanholt#include <sys/kernel.h> 49145132Sanholt#include <sys/module.h> 50145132Sanholt#include <sys/systm.h> 51145132Sanholt#include <sys/conf.h> 52207067Srnoland#include <sys/sglist.h> 53145132Sanholt#include <sys/stat.h> 54164033Srwatson#if __FreeBSD_version >= 700000 55164033Srwatson#include <sys/priv.h> 56164033Srwatson#endif 57145132Sanholt#include <sys/proc.h> 58145132Sanholt#include <sys/lock.h> 59145132Sanholt#include <sys/fcntl.h> 60145132Sanholt#include <sys/uio.h> 61145132Sanholt#include <sys/filio.h> 62248084Sattilio#include <sys/rwlock.h> 63145132Sanholt#include <sys/sysctl.h> 64145132Sanholt#include <sys/bus.h> 65203288Srnoland#include <sys/queue.h> 66145132Sanholt#include <sys/signalvar.h> 67145132Sanholt#include <sys/poll.h> 68203288Srnoland#include <sys/taskqueue.h> 69182080Srnoland#include <sys/tree.h> 70145132Sanholt#include <vm/vm.h> 71145132Sanholt#include <vm/pmap.h> 72145132Sanholt#include <vm/vm_extern.h> 73207067Srnoland#include <vm/vm_kern.h> 74145132Sanholt#include <vm/vm_map.h> 75203288Srnoland#include <vm/vm_object.h> 76203288Srnoland#include <vm/vm_page.h> 77207067Srnoland#include <vm/vm_pager.h> 78145132Sanholt#include <vm/vm_param.h> 79207067Srnoland#include <vm/vm_phys.h> 80145132Sanholt#include <machine/param.h> 81145132Sanholt#include <machine/pmap.h> 82145132Sanholt#include <machine/bus.h> 83145132Sanholt#include <machine/resource.h> 84215367Snwhitehorn#if defined(__i386__) || defined(__amd64__) 85183573Srnoland#include <machine/specialreg.h> 86215367Snwhitehorn#endif 87145132Sanholt#include <machine/sysarch.h> 88145132Sanholt#include <sys/endian.h> 89242132Snwhitehorn#if _BYTE_ORDER == _BIG_ENDIAN 90242132Snwhitehorn#define __BIG_ENDIAN 1 91242132Snwhitehorn#else 92242132Snwhitehorn#define __LITTLE_ENDIAN 1 93242132Snwhitehorn#endif 94145132Sanholt#include <sys/mman.h> 95145132Sanholt#include <sys/rman.h> 96145132Sanholt#include <sys/memrange.h> 97173573Sjhb#if __FreeBSD_version >= 800004 98173573Sjhb#include <dev/agp/agpvar.h> 99182080Srnoland#else /* __FreeBSD_version >= 800004 */ 100145132Sanholt#include <pci/agpvar.h> 101182080Srnoland#endif /* __FreeBSD_version >= 800004 */ 102145132Sanholt#include <sys/agpio.h> 103145132Sanholt#include <sys/mutex.h> 104145132Sanholt#include <dev/pci/pcivar.h> 105186299Srnoland#include <dev/pci/pcireg.h> 106145132Sanholt#include <sys/selinfo.h> 107145132Sanholt#include <sys/bus.h> 10895584Sanholt 109145132Sanholt#include "dev/drm/drm.h" 110145132Sanholt#include "dev/drm/drm_atomic.h" 111182080Srnoland#include "dev/drm/drm_internal.h" 112203287Srnoland#include "dev/drm/drm_linux_list.h" 113145132Sanholt 114145132Sanholt#include <opt_drm.h> 115145132Sanholt#ifdef DRM_DEBUG 116145132Sanholt#undef DRM_DEBUG 117145132Sanholt#define DRM_DEBUG_DEFAULT_ON 1 118145132Sanholt#endif /* DRM_DEBUG */ 11995584Sanholt 120145132Sanholt#if defined(DRM_LINUX) && DRM_LINUX && !defined(__amd64__) 121145132Sanholt#include <sys/file.h> 122145132Sanholt#include <sys/proc.h> 123145132Sanholt#include <machine/../linux/linux.h> 124145132Sanholt#include <machine/../linux/linux_proto.h> 125145132Sanholt#else 126145132Sanholt/* Either it was defined when it shouldn't be (FreeBSD amd64) or it isn't 127145132Sanholt * supported on this OS yet. 128145132Sanholt */ 129145132Sanholt#undef DRM_LINUX 130145132Sanholt#define DRM_LINUX 0 131145132Sanholt#endif 13295584Sanholt 133183573Srnoland/* driver capabilities and requirements mask */ 134183573Srnoland#define DRIVER_USE_AGP 0x1 135183573Srnoland#define DRIVER_REQUIRE_AGP 0x2 136183573Srnoland#define DRIVER_USE_MTRR 0x4 137183573Srnoland#define DRIVER_PCI_DMA 0x8 138183573Srnoland#define DRIVER_SG 0x10 139183573Srnoland#define DRIVER_HAVE_DMA 0x20 140183573Srnoland#define DRIVER_HAVE_IRQ 0x40 141183573Srnoland#define DRIVER_DMA_QUEUE 0x100 142183573Srnoland 143183573Srnoland 14495584Sanholt#define DRM_HASH_SIZE 16 /* Size of key hash table */ 14595584Sanholt#define DRM_KERNEL_CONTEXT 0 /* Change drm_resctx if changed */ 14695584Sanholt#define DRM_RESERVED_CONTEXTS 1 /* Change drm_resctx if changed */ 14795584Sanholt 148183833SrnolandMALLOC_DECLARE(DRM_MEM_DMA); 149183833SrnolandMALLOC_DECLARE(DRM_MEM_SAREA); 150183833SrnolandMALLOC_DECLARE(DRM_MEM_DRIVER); 151183833SrnolandMALLOC_DECLARE(DRM_MEM_MAGIC); 152183833SrnolandMALLOC_DECLARE(DRM_MEM_IOCTLS); 153183833SrnolandMALLOC_DECLARE(DRM_MEM_MAPS); 154183833SrnolandMALLOC_DECLARE(DRM_MEM_BUFS); 155183833SrnolandMALLOC_DECLARE(DRM_MEM_SEGS); 156183833SrnolandMALLOC_DECLARE(DRM_MEM_PAGES); 157183833SrnolandMALLOC_DECLARE(DRM_MEM_FILES); 158183833SrnolandMALLOC_DECLARE(DRM_MEM_QUEUES); 159183833SrnolandMALLOC_DECLARE(DRM_MEM_CMDS); 160183833SrnolandMALLOC_DECLARE(DRM_MEM_MAPPINGS); 161183833SrnolandMALLOC_DECLARE(DRM_MEM_BUFLISTS); 162183833SrnolandMALLOC_DECLARE(DRM_MEM_AGPLISTS); 163183833SrnolandMALLOC_DECLARE(DRM_MEM_CTXBITMAP); 164183833SrnolandMALLOC_DECLARE(DRM_MEM_SGLISTS); 165183833SrnolandMALLOC_DECLARE(DRM_MEM_DRAWABLE); 166203287SrnolandMALLOC_DECLARE(DRM_MEM_MM); 167203287SrnolandMALLOC_DECLARE(DRM_MEM_HASHTAB); 16895584Sanholt 169196466SrnolandSYSCTL_DECL(_hw_drm); 170196466Srnoland 17195584Sanholt#define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8) 17295584Sanholt 17395584Sanholt /* Internal types and structures */ 17495584Sanholt#define DRM_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) 17595584Sanholt#define DRM_MIN(a,b) ((a)<(b)?(a):(b)) 17695584Sanholt#define DRM_MAX(a,b) ((a)>(b)?(a):(b)) 17795584Sanholt 178122580Sanholt#define DRM_IF_VERSION(maj, min) (maj << 16 | min) 179122580Sanholt 180145132Sanholt#define __OS_HAS_AGP 1 181145132Sanholt 182145132Sanholt#define DRM_DEV_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) 183145132Sanholt#define DRM_DEV_UID 0 184145132Sanholt#define DRM_DEV_GID 0 185145132Sanholt 186145132Sanholt#define wait_queue_head_t atomic_t 187145132Sanholt#define DRM_WAKEUP(w) wakeup((void *)w) 188145132Sanholt#define DRM_WAKEUP_INT(w) wakeup(w) 189162132Sanholt#define DRM_INIT_WAITQUEUE(queue) do {(void)(queue);} while (0) 190145132Sanholt 191145132Sanholt#define DRM_CURPROC curthread 192145132Sanholt#define DRM_STRUCTPROC struct thread 193145132Sanholt#define DRM_SPINTYPE struct mtx 194182080Srnoland#define DRM_SPININIT(l,name) mtx_init(l, name, NULL, MTX_DEF) 195182080Srnoland#define DRM_SPINUNINIT(l) mtx_destroy(l) 196145132Sanholt#define DRM_SPINLOCK(l) mtx_lock(l) 197182080Srnoland#define DRM_SPINUNLOCK(u) mtx_unlock(u) 198182080Srnoland#define DRM_SPINLOCK_IRQSAVE(l, irqflags) do { \ 199182080Srnoland mtx_lock(l); \ 200182080Srnoland (void)irqflags; \ 201182080Srnoland} while (0) 202182080Srnoland#define DRM_SPINUNLOCK_IRQRESTORE(u, irqflags) mtx_unlock(u) 203145132Sanholt#define DRM_SPINLOCK_ASSERT(l) mtx_assert(l, MA_OWNED) 204145132Sanholt#define DRM_CURRENTPID curthread->td_proc->p_pid 205145132Sanholt#define DRM_LOCK() mtx_lock(&dev->dev_lock) 206145132Sanholt#define DRM_UNLOCK() mtx_unlock(&dev->dev_lock) 207145132Sanholt#define DRM_SYSCTL_HANDLER_ARGS (SYSCTL_HANDLER_ARGS) 208145132Sanholt 209145132Sanholt#define DRM_IRQ_ARGS void *arg 210145132Sanholttypedef void irqreturn_t; 211145132Sanholt#define IRQ_HANDLED /* nothing */ 212145132Sanholt#define IRQ_NONE /* nothing */ 213145132Sanholt 214203287Srnoland#define unlikely(x) __builtin_expect(!!(x), 0) 215203287Srnoland#define container_of(ptr, type, member) ({ \ 216203287Srnoland __typeof( ((type *)0)->member ) *__mptr = (ptr); \ 217203287Srnoland (type *)( (char *)__mptr - offsetof(type,member) );}) 218203287Srnoland 219152909Sanholtenum { 220152909Sanholt DRM_IS_NOT_AGP, 221157831Sanholt DRM_IS_AGP, 222157831Sanholt DRM_MIGHT_BE_AGP 223152909Sanholt}; 224152909Sanholt#define DRM_AGP_MEM struct agp_memory_info 225152909Sanholt 226182080Srnoland#define drm_get_device_from_kdev(_kdev) (_kdev->si_drv1) 227145132Sanholt 228145132Sanholt#define PAGE_ALIGN(addr) round_page(addr) 229152909Sanholt/* DRM_SUSER returns true if the user is superuser */ 230164033Srwatson#if __FreeBSD_version >= 700000 231182080Srnoland#define DRM_SUSER(p) (priv_check(p, PRIV_DRIVER) == 0) 232164033Srwatson#else 233152909Sanholt#define DRM_SUSER(p) (suser(p) == 0) 234164033Srwatson#endif 235145132Sanholt#define DRM_AGP_FIND_DEVICE() agp_find_device() 236145132Sanholt#define DRM_MTRR_WC MDF_WRITECOMBINE 237145132Sanholt#define jiffies ticks 238145132Sanholt 239207118Srnolandtypedef vm_paddr_t dma_addr_t; 240162132Sanholttypedef u_int64_t u64; 241145132Sanholttypedef u_int32_t u32; 242145132Sanholttypedef u_int16_t u16; 243145132Sanholttypedef u_int8_t u8; 244145132Sanholt 245145132Sanholt/* DRM_READMEMORYBARRIER() prevents reordering of reads. 246145132Sanholt * DRM_WRITEMEMORYBARRIER() prevents reordering of writes. 247145132Sanholt * DRM_MEMORYBARRIER() prevents reordering of reads and writes. 248145132Sanholt */ 249198692Srnoland#define DRM_READMEMORYBARRIER() rmb() 250198692Srnoland#define DRM_WRITEMEMORYBARRIER() wmb() 251198692Srnoland#define DRM_MEMORYBARRIER() mb() 252145132Sanholt 253145132Sanholt#define DRM_READ8(map, offset) \ 254207066Srnoland *(volatile u_int8_t *)(((vm_offset_t)(map)->virtual) + \ 255189910Srnoland (vm_offset_t)(offset)) 256145132Sanholt#define DRM_READ16(map, offset) \ 257215367Snwhitehorn le16toh(*(volatile u_int16_t *)(((vm_offset_t)(map)->virtual) + \ 258215367Snwhitehorn (vm_offset_t)(offset))) 259145132Sanholt#define DRM_READ32(map, offset) \ 260215367Snwhitehorn le32toh(*(volatile u_int32_t *)(((vm_offset_t)(map)->virtual) + \ 261215367Snwhitehorn (vm_offset_t)(offset))) 262145132Sanholt#define DRM_WRITE8(map, offset, val) \ 263207066Srnoland *(volatile u_int8_t *)(((vm_offset_t)(map)->virtual) + \ 264189910Srnoland (vm_offset_t)(offset)) = val 265145132Sanholt#define DRM_WRITE16(map, offset, val) \ 266207066Srnoland *(volatile u_int16_t *)(((vm_offset_t)(map)->virtual) + \ 267215367Snwhitehorn (vm_offset_t)(offset)) = htole16(val) 268145132Sanholt#define DRM_WRITE32(map, offset, val) \ 269207066Srnoland *(volatile u_int32_t *)(((vm_offset_t)(map)->virtual) + \ 270215367Snwhitehorn (vm_offset_t)(offset)) = htole32(val) 271145132Sanholt 272145132Sanholt#define DRM_VERIFYAREA_READ( uaddr, size ) \ 273145132Sanholt (!useracc(__DECONST(caddr_t, uaddr), size, VM_PROT_READ)) 274145132Sanholt 275145132Sanholt#define DRM_COPY_TO_USER(user, kern, size) \ 276145132Sanholt copyout(kern, user, size) 277145132Sanholt#define DRM_COPY_FROM_USER(kern, user, size) \ 278145132Sanholt copyin(user, kern, size) 279145132Sanholt#define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) \ 280145132Sanholt copyin(arg2, arg1, arg3) 281145132Sanholt#define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3) \ 282145132Sanholt copyout(arg2, arg1, arg3) 283145132Sanholt#define DRM_GET_USER_UNCHECKED(val, uaddr) \ 284145132Sanholt ((val) = fuword32(uaddr), 0) 285145132Sanholt 286145132Sanholt#define cpu_to_le32(x) htole32(x) 287145132Sanholt#define le32_to_cpu(x) le32toh(x) 288145132Sanholt 289145132Sanholt#define DRM_HZ hz 290145132Sanholt#define DRM_UDELAY(udelay) DELAY(udelay) 291145132Sanholt#define DRM_TIME_SLICE (hz/20) /* Time slice for GLXContexts */ 292145132Sanholt 29395584Sanholt#define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \ 29495584Sanholt (_map) = (_dev)->context_sareas[_ctx]; \ 29595584Sanholt} while(0) 29695584Sanholt 297182080Srnoland#define LOCK_TEST_WITH_RETURN(dev, file_priv) \ 298145132Sanholtdo { \ 299145132Sanholt if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) || \ 300182080Srnoland dev->lock.file_priv != file_priv) { \ 301145132Sanholt DRM_ERROR("%s called without lock held\n", \ 302145132Sanholt __FUNCTION__); \ 303145132Sanholt return EINVAL; \ 304145132Sanholt } \ 305145132Sanholt} while (0) 306145132Sanholt 307182080Srnoland/* Returns -errno to shared code */ 308145132Sanholt#define DRM_WAIT_ON( ret, queue, timeout, condition ) \ 309145132Sanholtfor ( ret = 0 ; !ret && !(condition) ; ) { \ 310145132Sanholt DRM_UNLOCK(); \ 311145132Sanholt mtx_lock(&dev->irq_lock); \ 312145132Sanholt if (!(condition)) \ 313189045Srnoland ret = -mtx_sleep(&(queue), &dev->irq_lock, \ 314189045Srnoland PCATCH, "drmwtq", (timeout)); \ 315145132Sanholt mtx_unlock(&dev->irq_lock); \ 316145132Sanholt DRM_LOCK(); \ 317145132Sanholt} 318145132Sanholt 319186386Srnoland#define DRM_ERROR(fmt, ...) \ 320145132Sanholt printf("error: [" DRM_NAME ":pid%d:%s] *ERROR* " fmt, \ 321186386Srnoland DRM_CURRENTPID, __func__ , ##__VA_ARGS__) 322145132Sanholt 323186386Srnoland#define DRM_INFO(fmt, ...) printf("info: [" DRM_NAME "] " fmt , ##__VA_ARGS__) 324145132Sanholt 325186386Srnoland#define DRM_DEBUG(fmt, ...) do { \ 326145132Sanholt if (drm_debug_flag) \ 327145132Sanholt printf("[" DRM_NAME ":pid%d:%s] " fmt, DRM_CURRENTPID, \ 328186386Srnoland __func__ , ##__VA_ARGS__); \ 329145132Sanholt} while (0) 330145132Sanholt 331121447Sanholttypedef struct drm_pci_id_list 332121447Sanholt{ 333121447Sanholt int vendor; 334121447Sanholt int device; 335121447Sanholt long driver_private; 336121447Sanholt char *name; 337121447Sanholt} drm_pci_id_list_t; 338121447Sanholt 339189052Srnolandstruct drm_msi_blacklist_entry 340189052Srnoland{ 341189052Srnoland int vendor; 342189052Srnoland int device; 343189052Srnoland}; 344189052Srnoland 345152909Sanholt#define DRM_AUTH 0x1 346152909Sanholt#define DRM_MASTER 0x2 347152909Sanholt#define DRM_ROOT_ONLY 0x4 34895584Sanholttypedef struct drm_ioctl_desc { 349182080Srnoland unsigned long cmd; 350182080Srnoland int (*func)(struct drm_device *dev, void *data, 351182080Srnoland struct drm_file *file_priv); 352152909Sanholt int flags; 35395584Sanholt} drm_ioctl_desc_t; 354182080Srnoland/** 355182080Srnoland * Creates a driver or general drm_ioctl_desc array entry for the given 356182080Srnoland * ioctl, for use by drm_ioctl(). 357182080Srnoland */ 358182080Srnoland#define DRM_IOCTL_DEF(ioctl, func, flags) \ 359182080Srnoland [DRM_IOCTL_NR(ioctl)] = {ioctl, func, flags} 36095584Sanholt 36195584Sanholttypedef struct drm_magic_entry { 36295584Sanholt drm_magic_t magic; 36395584Sanholt struct drm_file *priv; 36495584Sanholt struct drm_magic_entry *next; 36595584Sanholt} drm_magic_entry_t; 36695584Sanholt 36795584Sanholttypedef struct drm_magic_head { 36895584Sanholt struct drm_magic_entry *head; 36995584Sanholt struct drm_magic_entry *tail; 37095584Sanholt} drm_magic_head_t; 37195584Sanholt 37295584Sanholttypedef struct drm_buf { 37395584Sanholt int idx; /* Index into master buflist */ 37495584Sanholt int total; /* Buffer size */ 37595584Sanholt int order; /* log-base-2(total) */ 37695584Sanholt int used; /* Amount of buffer in use (for DMA) */ 37795584Sanholt unsigned long offset; /* Byte offset (used internally) */ 37895584Sanholt void *address; /* Address of buffer */ 37995584Sanholt unsigned long bus_address; /* Bus address of buffer */ 38095584Sanholt struct drm_buf *next; /* Kernel-only: used for free list */ 38195584Sanholt __volatile__ int pending; /* On hardware DMA queue */ 382182080Srnoland struct drm_file *file_priv; /* Unique identifier of holding process */ 38395584Sanholt int context; /* Kernel queue for this buffer */ 38495584Sanholt enum { 38595584Sanholt DRM_LIST_NONE = 0, 38695584Sanholt DRM_LIST_FREE = 1, 38795584Sanholt DRM_LIST_WAIT = 2, 38895584Sanholt DRM_LIST_PEND = 3, 38995584Sanholt DRM_LIST_PRIO = 4, 39095584Sanholt DRM_LIST_RECLAIM = 5 39195584Sanholt } list; /* Which list we're on */ 39295584Sanholt 39395584Sanholt int dev_priv_size; /* Size of buffer private stoarge */ 39495584Sanholt void *dev_private; /* Per-buffer private storage */ 39595584Sanholt} drm_buf_t; 39695584Sanholt 39795584Sanholttypedef struct drm_freelist { 39895584Sanholt int initialized; /* Freelist in use */ 39995584Sanholt atomic_t count; /* Number of free buffers */ 40095584Sanholt drm_buf_t *next; /* End pointer */ 40195584Sanholt 40295584Sanholt int low_mark; /* Low water mark */ 40395584Sanholt int high_mark; /* High water mark */ 40495584Sanholt} drm_freelist_t; 40595584Sanholt 406152909Sanholttypedef struct drm_dma_handle { 407152909Sanholt void *vaddr; 408152909Sanholt bus_addr_t busaddr; 409152909Sanholt bus_dma_tag_t tag; 410152909Sanholt bus_dmamap_t map; 411152909Sanholt} drm_dma_handle_t; 412152909Sanholt 41395584Sanholttypedef struct drm_buf_entry { 41495584Sanholt int buf_size; 41595584Sanholt int buf_count; 41695584Sanholt drm_buf_t *buflist; 41795584Sanholt int seg_count; 418152909Sanholt drm_dma_handle_t **seglist; 41995584Sanholt int page_order; 42095584Sanholt 42195584Sanholt drm_freelist_t freelist; 42295584Sanholt} drm_buf_entry_t; 42395584Sanholt 42495584Sanholttypedef TAILQ_HEAD(drm_file_list, drm_file) drm_file_list_t; 42595584Sanholtstruct drm_file { 42695584Sanholt TAILQ_ENTRY(drm_file) link; 427183573Srnoland struct drm_device *dev; 42895584Sanholt int authenticated; 429152909Sanholt int master; 43095584Sanholt pid_t pid; 43195584Sanholt uid_t uid; 43295584Sanholt drm_magic_t magic; 43395584Sanholt unsigned long ioctl_count; 434145132Sanholt void *driver_priv; 43595584Sanholt}; 43695584Sanholt 43795584Sanholttypedef struct drm_lock_data { 438183573Srnoland struct drm_hw_lock *hw_lock; /* Hardware lock */ 439182080Srnoland struct drm_file *file_priv; /* Unique identifier of holding process (NULL is kernel)*/ 440121447Sanholt int lock_queue; /* Queue of blocked processes */ 44195584Sanholt unsigned long lock_time; /* Time of last lock in jiffies */ 44295584Sanholt} drm_lock_data_t; 44395584Sanholt 444182080Srnoland/* This structure, in the struct drm_device, is always initialized while the 445182080Srnoland * device 446121447Sanholt * is open. dev->dma_lock protects the incrementing of dev->buf_use, which 447121447Sanholt * when set marks that no further bufs may be allocated until device teardown 448121447Sanholt * occurs (when the last open of the device has closed). The high/low 449121447Sanholt * watermarks of bufs are only touched by the X Server, and thus not 450121447Sanholt * concurrently accessed, so no locking is needed. 451121447Sanholt */ 45295584Sanholttypedef struct drm_device_dma { 45395584Sanholt drm_buf_entry_t bufs[DRM_MAX_ORDER+1]; 45495584Sanholt int buf_count; 45595584Sanholt drm_buf_t **buflist; /* Vector of pointers info bufs */ 45695584Sanholt int seg_count; 45795584Sanholt int page_count; 45895584Sanholt unsigned long *pagelist; 45995584Sanholt unsigned long byte_count; 46095584Sanholt enum { 46195584Sanholt _DRM_DMA_USE_AGP = 0x01, 46295584Sanholt _DRM_DMA_USE_SG = 0x02 46395584Sanholt } flags; 46495584Sanholt} drm_device_dma_t; 46595584Sanholt 46695584Sanholttypedef struct drm_agp_mem { 46795584Sanholt void *handle; 46895584Sanholt unsigned long bound; /* address */ 46995584Sanholt int pages; 47095584Sanholt struct drm_agp_mem *prev; 47195584Sanholt struct drm_agp_mem *next; 47295584Sanholt} drm_agp_mem_t; 47395584Sanholt 47495584Sanholttypedef struct drm_agp_head { 47595584Sanholt device_t agpdev; 47695584Sanholt struct agp_info info; 47795584Sanholt const char *chipset; 47895584Sanholt drm_agp_mem_t *memory; 47995584Sanholt unsigned long mode; 48095584Sanholt int enabled; 48195584Sanholt int acquired; 48295584Sanholt unsigned long base; 483124164Sanholt int mtrr; 48495584Sanholt int cant_use_aperture; 48595584Sanholt unsigned long page_mask; 48695584Sanholt} drm_agp_head_t; 48795584Sanholt 48895584Sanholttypedef struct drm_sg_mem { 489207067Srnoland vm_offset_t vaddr; 490207067Srnoland vm_paddr_t *busaddr; 491207067Srnoland vm_pindex_t pages; 49295584Sanholt} drm_sg_mem_t; 49395584Sanholt 494207066Srnoland#define DRM_MAP_HANDLE_BITS (sizeof(void *) == 4 ? 4 : 24) 495207066Srnoland#define DRM_MAP_HANDLE_SHIFT (sizeof(void *) * 8 - DRM_MAP_HANDLE_BITS) 496145132Sanholttypedef TAILQ_HEAD(drm_map_list, drm_local_map) drm_map_list_t; 497145132Sanholt 498112015Sanholttypedef struct drm_local_map { 499207066Srnoland unsigned long offset; /* Physical address (0 for SAREA) */ 500207066Srnoland unsigned long size; /* Physical size (bytes) */ 501207066Srnoland enum drm_map_type type; /* Type of memory mapped */ 502207066Srnoland enum drm_map_flags flags; /* Flags */ 503207066Srnoland void *handle; /* User-space: "Handle" to pass to mmap */ 504207066Srnoland /* Kernel-space: kernel-virtual address */ 505207066Srnoland int mtrr; /* Boolean: MTRR used */ 506207066Srnoland /* Private data */ 507207066Srnoland int rid; /* PCI resource ID for bus_space */ 508207066Srnoland void *virtual; /* Kernel-space: kernel-virtual address */ 509145132Sanholt struct resource *bsr; 510145132Sanholt bus_space_tag_t bst; 511145132Sanholt bus_space_handle_t bsh; 512152909Sanholt drm_dma_handle_t *dmah; 513145132Sanholt TAILQ_ENTRY(drm_local_map) link; 514112015Sanholt} drm_local_map_t; 515112015Sanholt 516182080Srnolandstruct drm_vblank_info { 517182080Srnoland wait_queue_head_t queue; /* vblank wait queue */ 518182080Srnoland atomic_t count; /* number of VBLANK interrupts */ 519182080Srnoland /* (driver must alloc the right number of counters) */ 520182080Srnoland atomic_t refcount; /* number of users of vblank interrupts */ 521182080Srnoland u32 last; /* protected by dev->vbl_lock, used */ 522182080Srnoland /* for wraparound handling */ 523182080Srnoland int enabled; /* so we don't call enable more than */ 524182080Srnoland /* once per disable */ 525182080Srnoland int inmodeset; /* Display driver is setting mode */ 526182080Srnoland}; 527182080Srnoland 528152909Sanholt/* location of GART table */ 529152909Sanholt#define DRM_ATI_GART_MAIN 1 530152909Sanholt#define DRM_ATI_GART_FB 2 531145132Sanholt 532182080Srnoland#define DRM_ATI_GART_PCI 1 533182080Srnoland#define DRM_ATI_GART_PCIE 2 534182080Srnoland#define DRM_ATI_GART_IGP 3 535182080Srnoland 536182080Srnolandstruct drm_ati_pcigart_info { 537152909Sanholt int gart_table_location; 538182080Srnoland int gart_reg_if; 539152909Sanholt void *addr; 540152909Sanholt dma_addr_t bus_addr; 541182080Srnoland dma_addr_t table_mask; 542182080Srnoland dma_addr_t member_mask; 543182080Srnoland struct drm_dma_handle *table_handle; 544152909Sanholt drm_local_map_t mapping; 545182080Srnoland int table_size; 546190399Srnoland struct drm_dma_handle *dmah; /* handle for ATI PCIGART table */ 547182080Srnoland}; 548152909Sanholt 549182080Srnoland#ifndef DMA_BIT_MASK 550182080Srnoland#define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : (1ULL<<(n)) - 1) 551182080Srnoland#endif 552182080Srnoland 553182080Srnoland#define upper_32_bits(n) ((u32)(((n) >> 16) >> 16)) 554182080Srnoland 555152909Sanholtstruct drm_driver_info { 556152909Sanholt int (*load)(struct drm_device *, unsigned long flags); 557152909Sanholt int (*firstopen)(struct drm_device *); 558183573Srnoland int (*open)(struct drm_device *, struct drm_file *); 559182080Srnoland void (*preclose)(struct drm_device *, struct drm_file *file_priv); 560183573Srnoland void (*postclose)(struct drm_device *, struct drm_file *); 561152909Sanholt void (*lastclose)(struct drm_device *); 562152909Sanholt int (*unload)(struct drm_device *); 563182080Srnoland void (*reclaim_buffers_locked)(struct drm_device *, 564182080Srnoland struct drm_file *file_priv); 565182080Srnoland int (*dma_ioctl)(struct drm_device *dev, void *data, 566182080Srnoland struct drm_file *file_priv); 567145132Sanholt void (*dma_ready)(struct drm_device *); 568145132Sanholt int (*dma_quiescent)(struct drm_device *); 569145132Sanholt int (*dma_flush_block_and_flush)(struct drm_device *, int context, 570183573Srnoland enum drm_lock_flags flags); 571145132Sanholt int (*dma_flush_unblock)(struct drm_device *, int context, 572183573Srnoland enum drm_lock_flags flags); 573145132Sanholt int (*context_ctor)(struct drm_device *dev, int context); 574145132Sanholt int (*context_dtor)(struct drm_device *dev, int context); 575145132Sanholt int (*kernel_context_switch)(struct drm_device *dev, int old, 576145132Sanholt int new); 577145132Sanholt int (*kernel_context_switch_unlock)(struct drm_device *dev); 578182080Srnoland void (*irq_preinstall)(struct drm_device *dev); 579182080Srnoland int (*irq_postinstall)(struct drm_device *dev); 580182080Srnoland void (*irq_uninstall)(struct drm_device *dev); 581145132Sanholt void (*irq_handler)(DRM_IRQ_ARGS); 582182080Srnoland u32 (*get_vblank_counter)(struct drm_device *dev, int crtc); 583182080Srnoland int (*enable_vblank)(struct drm_device *dev, int crtc); 584182080Srnoland void (*disable_vblank)(struct drm_device *dev, int crtc); 585145132Sanholt 586152909Sanholt drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */ 587145132Sanholt 588152909Sanholt /** 589152909Sanholt * Called by \c drm_device_is_agp. Typically used to determine if a 590152909Sanholt * card is really attached to AGP or not. 591152909Sanholt * 592152909Sanholt * \param dev DRM device handle 593152909Sanholt * 594152909Sanholt * \returns 595152909Sanholt * One of three values is returned depending on whether or not the 596152909Sanholt * card is absolutely \b not AGP (return of 0), absolutely \b is AGP 597152909Sanholt * (return of 1), or may or may not be AGP (return of 2). 598152909Sanholt */ 599152909Sanholt int (*device_is_agp) (struct drm_device * dev); 600145132Sanholt 601152909Sanholt drm_ioctl_desc_t *ioctls; 602152909Sanholt int max_ioctl; 603145132Sanholt 604152909Sanholt int buf_priv_size; 605152909Sanholt 606152909Sanholt int major; 607152909Sanholt int minor; 608152909Sanholt int patchlevel; 609152909Sanholt const char *name; /* Simple driver name */ 610152909Sanholt const char *desc; /* Longer driver name */ 611152909Sanholt const char *date; /* Date of last major changes. */ 612152909Sanholt 613183573Srnoland u32 driver_features; 614152909Sanholt}; 615145132Sanholt 616152909Sanholt/* Length for the array of resource pointers for drm_get_resource_*. */ 617189911Srnoland#define DRM_MAX_PCI_RESOURCE 6 618152909Sanholt 619152909Sanholt/** 620152909Sanholt * DRM device functions structure 621152909Sanholt */ 622152909Sanholtstruct drm_device { 623183573Srnoland struct drm_driver_info *driver; 624152909Sanholt drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */ 625152909Sanholt 626162132Sanholt u_int16_t pci_device; /* PCI device id */ 627162132Sanholt u_int16_t pci_vendor; /* PCI vendor id */ 628162132Sanholt 62995584Sanholt char *unique; /* Unique identifier: e.g., busid */ 63095584Sanholt int unique_len; /* Length of unique field */ 63195584Sanholt device_t device; /* Device instance from newbus */ 632145132Sanholt struct cdev *devnode; /* Device number for mknod */ 633122580Sanholt int if_version; /* Highest interface version set */ 63495584Sanholt 63595584Sanholt int flags; /* Flags to open(2) */ 63695584Sanholt 63795584Sanholt /* Locks */ 638182080Srnoland struct mtx vbl_lock; /* protects vblank operations */ 639121447Sanholt struct mtx dma_lock; /* protects dev->dma */ 640145132Sanholt struct mtx irq_lock; /* protects irq condition checks */ 641121447Sanholt struct mtx dev_lock; /* protects everything else */ 642182080Srnoland DRM_SPINTYPE drw_lock; 643182080Srnoland 64495584Sanholt /* Usage Counters */ 64595584Sanholt int open_count; /* Outstanding files open */ 64695584Sanholt int buf_use; /* Buffers in use -- cannot alloc */ 64795584Sanholt 64895584Sanholt /* Performance counters */ 64995584Sanholt unsigned long counters; 650183573Srnoland enum drm_stat_type types[15]; 65195584Sanholt atomic_t counts[15]; 65295584Sanholt 65395584Sanholt /* Authentication */ 65495584Sanholt drm_file_list_t files; 65595584Sanholt drm_magic_head_t magiclist[DRM_HASH_SIZE]; 65695584Sanholt 657121447Sanholt /* Linked list of mappable regions. Protected by dev_lock */ 658145132Sanholt drm_map_list_t maplist; 659207066Srnoland struct unrhdr *map_unrhdr; 66095584Sanholt 661112015Sanholt drm_local_map_t **context_sareas; 66295584Sanholt int max_context; 66395584Sanholt 66495584Sanholt drm_lock_data_t lock; /* Information on hardware lock */ 66595584Sanholt 66695584Sanholt /* DMA queues (contexts) */ 66795584Sanholt drm_device_dma_t *dma; /* Optional pointer for DMA support */ 66895584Sanholt 66995584Sanholt /* Context support */ 67095584Sanholt int irq; /* Interrupt used by board */ 671122580Sanholt int irq_enabled; /* True if the irq handler is enabled */ 672189049Srnoland int msi_enabled; /* MSI enabled */ 673122580Sanholt int irqrid; /* Interrupt used by board */ 67495584Sanholt struct resource *irqr; /* Resource for interrupt used by board */ 67595584Sanholt void *irqh; /* Handle from bus_setup_intr */ 676122580Sanholt 677152909Sanholt /* Storage of resource pointers for drm_get_resource_* */ 678152909Sanholt struct resource *pcir[DRM_MAX_PCI_RESOURCE]; 679152909Sanholt int pcirid[DRM_MAX_PCI_RESOURCE]; 680152909Sanholt 681122580Sanholt int pci_domain; 682122580Sanholt int pci_bus; 683122580Sanholt int pci_slot; 684122580Sanholt int pci_func; 685122580Sanholt 686112015Sanholt atomic_t context_flag; /* Context swapping flag */ 68795584Sanholt int last_context; /* Last current context */ 68895584Sanholt 689182080Srnoland int vblank_disable_allowed; 690182080Srnoland struct callout vblank_disable_timer; 691182080Srnoland u32 max_vblank_count; /* size of vblank counter register */ 692182080Srnoland struct drm_vblank_info *vblank; /* per crtc vblank info */ 693182080Srnoland int num_crtcs; 694182080Srnoland 69595584Sanholt struct sigio *buf_sigio; /* Processes waiting for SIGIO */ 69695584Sanholt 69795584Sanholt /* Sysctl support */ 69895584Sanholt struct drm_sysctl_info *sysctl; 69995584Sanholt 70095584Sanholt drm_agp_head_t *agp; 70195584Sanholt drm_sg_mem_t *sg; /* Scatter gather memory */ 702112015Sanholt atomic_t *ctx_bitmap; 70395584Sanholt void *dev_private; 704152909Sanholt unsigned int agp_buffer_token; 705145132Sanholt drm_local_map_t *agp_buffer_map; 706182080Srnoland 707182080Srnoland struct unrhdr *drw_unrhdr; 708182080Srnoland /* RB tree of drawable infos */ 709182080Srnoland RB_HEAD(drawable_tree, bsd_drm_drawable_info) drw_head; 71095584Sanholt}; 71195584Sanholt 712183573Srnolandstatic __inline__ int drm_core_check_feature(struct drm_device *dev, 713183573Srnoland int feature) 714183573Srnoland{ 715183573Srnoland return ((dev->driver->driver_features & feature) ? 1 : 0); 716183573Srnoland} 717183573Srnoland 718183573Srnoland#if __OS_HAS_AGP 719183573Srnolandstatic inline int drm_core_has_AGP(struct drm_device *dev) 720183573Srnoland{ 721183573Srnoland return drm_core_check_feature(dev, DRIVER_USE_AGP); 722183573Srnoland} 723183573Srnoland#else 724183573Srnoland#define drm_core_has_AGP(dev) (0) 725183573Srnoland#endif 726183573Srnoland 727145132Sanholtextern int drm_debug_flag; 72895584Sanholt 729145132Sanholt/* Device setup support (drm_drv.c) */ 730189563Srnolandint drm_probe(device_t kdev, drm_pci_id_list_t *idlist); 731189563Srnolandint drm_attach(device_t kdev, drm_pci_id_list_t *idlist); 732183573Srnolandvoid drm_close(void *data); 733189563Srnolandint drm_detach(device_t kdev); 734145132Sanholtd_ioctl_t drm_ioctl; 735145132Sanholtd_open_t drm_open; 736145132Sanholtd_read_t drm_read; 737145132Sanholtd_poll_t drm_poll; 738145132Sanholtd_mmap_t drm_mmap; 739182080Srnolandextern drm_local_map_t *drm_getsarea(struct drm_device *dev); 740145132Sanholt 741145132Sanholt/* File operations helpers (drm_fops.c) */ 742182080Srnolandextern int drm_open_helper(struct cdev *kdev, int flags, int fmt, 743182080Srnoland DRM_STRUCTPROC *p, 744182080Srnoland struct drm_device *dev); 745145132Sanholt 746145132Sanholt/* Memory management support (drm_memory.c) */ 747145132Sanholtvoid drm_mem_init(void); 748145132Sanholtvoid drm_mem_uninit(void); 749183573Srnolandvoid *drm_ioremap_wc(struct drm_device *dev, drm_local_map_t *map); 750182080Srnolandvoid *drm_ioremap(struct drm_device *dev, drm_local_map_t *map); 751145132Sanholtvoid drm_ioremapfree(drm_local_map_t *map); 752145132Sanholtint drm_mtrr_add(unsigned long offset, size_t size, int flags); 753152909Sanholtint drm_mtrr_del(int handle, unsigned long offset, size_t size, int flags); 75495584Sanholt 755182080Srnolandint drm_context_switch(struct drm_device *dev, int old, int new); 756182080Srnolandint drm_context_switch_complete(struct drm_device *dev, int new); 75795584Sanholt 758182080Srnolandint drm_ctxbitmap_init(struct drm_device *dev); 759182080Srnolandvoid drm_ctxbitmap_cleanup(struct drm_device *dev); 760182080Srnolandvoid drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle); 761182080Srnolandint drm_ctxbitmap_next(struct drm_device *dev); 76295584Sanholt 763145132Sanholt/* Locking IOCTL support (drm_lock.c) */ 764183573Srnolandint drm_lock_take(struct drm_lock_data *lock_data, 765183573Srnoland unsigned int context); 766183573Srnolandint drm_lock_transfer(struct drm_lock_data *lock_data, 767182080Srnoland unsigned int context); 768183573Srnolandint drm_lock_free(struct drm_lock_data *lock_data, 769182080Srnoland unsigned int context); 77095584Sanholt 771145132Sanholt/* Buffer management support (drm_bufs.c) */ 772182080Srnolandunsigned long drm_get_resource_start(struct drm_device *dev, 773182080Srnoland unsigned int resource); 774182080Srnolandunsigned long drm_get_resource_len(struct drm_device *dev, 775182080Srnoland unsigned int resource); 776182080Srnolandvoid drm_rmmap(struct drm_device *dev, drm_local_map_t *map); 777145132Sanholtint drm_order(unsigned long size); 778182080Srnolandint drm_addmap(struct drm_device *dev, unsigned long offset, 779182080Srnoland unsigned long size, 780183573Srnoland enum drm_map_type type, enum drm_map_flags flags, 781152909Sanholt drm_local_map_t **map_ptr); 782183573Srnolandint drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc *request); 783183573Srnolandint drm_addbufs_sg(struct drm_device *dev, struct drm_buf_desc *request); 784183573Srnolandint drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc *request); 78595584Sanholt 786145132Sanholt/* DMA support (drm_dma.c) */ 787182080Srnolandint drm_dma_setup(struct drm_device *dev); 788182080Srnolandvoid drm_dma_takedown(struct drm_device *dev); 789182080Srnolandvoid drm_free_buffer(struct drm_device *dev, drm_buf_t *buf); 790182080Srnolandvoid drm_reclaim_buffers(struct drm_device *dev, struct drm_file *file_priv); 791152909Sanholt#define drm_core_reclaim_buffers drm_reclaim_buffers 792121447Sanholt 793145132Sanholt/* IRQ support (drm_irq.c) */ 794182080Srnolandint drm_irq_install(struct drm_device *dev); 795182080Srnolandint drm_irq_uninstall(struct drm_device *dev); 796145132Sanholtirqreturn_t drm_irq_handler(DRM_IRQ_ARGS); 797182080Srnolandvoid drm_driver_irq_preinstall(struct drm_device *dev); 798182080Srnolandvoid drm_driver_irq_postinstall(struct drm_device *dev); 799182080Srnolandvoid drm_driver_irq_uninstall(struct drm_device *dev); 800182080Srnolandvoid drm_handle_vblank(struct drm_device *dev, int crtc); 801182080Srnolandu32 drm_vblank_count(struct drm_device *dev, int crtc); 802182080Srnolandint drm_vblank_get(struct drm_device *dev, int crtc); 803182080Srnolandvoid drm_vblank_put(struct drm_device *dev, int crtc); 804189130Srnolandvoid drm_vblank_cleanup(struct drm_device *dev); 805182080Srnolandint drm_vblank_wait(struct drm_device *dev, unsigned int *vbl_seq); 806182080Srnolandint drm_vblank_init(struct drm_device *dev, int num_crtcs); 807182080Srnolandint drm_modeset_ctl(struct drm_device *dev, void *data, 808182080Srnoland struct drm_file *file_priv); 80995584Sanholt 810148211Sanholt/* AGP/PCI Express/GART support (drm_agpsupport.c) */ 811182080Srnolandint drm_device_is_agp(struct drm_device *dev); 812182080Srnolandint drm_device_is_pcie(struct drm_device *dev); 813145132Sanholtdrm_agp_head_t *drm_agp_init(void); 814182080Srnolandint drm_agp_acquire(struct drm_device *dev); 815182080Srnolandint drm_agp_release(struct drm_device *dev); 816183573Srnolandint drm_agp_info(struct drm_device * dev, struct drm_agp_info *info); 817183573Srnolandint drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode); 818145132Sanholtvoid *drm_agp_allocate_memory(size_t pages, u32 type); 819145132Sanholtint drm_agp_free_memory(void *handle); 820145132Sanholtint drm_agp_bind_memory(void *handle, off_t start); 821145132Sanholtint drm_agp_unbind_memory(void *handle); 822183573Srnolandint drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request); 823183573Srnolandint drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request); 824183573Srnolandint drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request); 825183573Srnolandint drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request); 82695584Sanholt 827145132Sanholt/* Scatter Gather Support (drm_scatter.c) */ 828145132Sanholtvoid drm_sg_cleanup(drm_sg_mem_t *entry); 829183573Srnolandint drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request); 83095584Sanholt 831145132Sanholt/* sysctl support (drm_sysctl.h) */ 832182080Srnolandextern int drm_sysctl_init(struct drm_device *dev); 833182080Srnolandextern int drm_sysctl_cleanup(struct drm_device *dev); 83495584Sanholt 835145132Sanholt/* ATI PCIGART support (ati_pcigart.c) */ 836182080Srnolandint drm_ati_pcigart_init(struct drm_device *dev, 837182080Srnoland struct drm_ati_pcigart_info *gart_info); 838182080Srnolandint drm_ati_pcigart_cleanup(struct drm_device *dev, 839182080Srnoland struct drm_ati_pcigart_info *gart_info); 84095584Sanholt 841145132Sanholt/* Locking IOCTL support (drm_drv.c) */ 842182080Srnolandint drm_lock(struct drm_device *dev, void *data, 843182080Srnoland struct drm_file *file_priv); 844182080Srnolandint drm_unlock(struct drm_device *dev, void *data, 845182080Srnoland struct drm_file *file_priv); 846182080Srnolandint drm_version(struct drm_device *dev, void *data, 847182080Srnoland struct drm_file *file_priv); 848182080Srnolandint drm_setversion(struct drm_device *dev, void *data, 849182080Srnoland struct drm_file *file_priv); 850113995Sanholt 851145132Sanholt/* Misc. IOCTL support (drm_ioctl.c) */ 852182080Srnolandint drm_irq_by_busid(struct drm_device *dev, void *data, 853182080Srnoland struct drm_file *file_priv); 854182080Srnolandint drm_getunique(struct drm_device *dev, void *data, 855182080Srnoland struct drm_file *file_priv); 856182080Srnolandint drm_setunique(struct drm_device *dev, void *data, 857182080Srnoland struct drm_file *file_priv); 858182080Srnolandint drm_getmap(struct drm_device *dev, void *data, 859182080Srnoland struct drm_file *file_priv); 860182080Srnolandint drm_getclient(struct drm_device *dev, void *data, 861182080Srnoland struct drm_file *file_priv); 862182080Srnolandint drm_getstats(struct drm_device *dev, void *data, 863182080Srnoland struct drm_file *file_priv); 864182080Srnolandint drm_noop(struct drm_device *dev, void *data, 865182080Srnoland struct drm_file *file_priv); 866113995Sanholt 867145132Sanholt/* Context IOCTL support (drm_context.c) */ 868182080Srnolandint drm_resctx(struct drm_device *dev, void *data, 869182080Srnoland struct drm_file *file_priv); 870182080Srnolandint drm_addctx(struct drm_device *dev, void *data, 871183573Srnoland struct drm_file *file_priv); 872182080Srnolandint drm_modctx(struct drm_device *dev, void *data, 873182080Srnoland struct drm_file *file_priv); 874182080Srnolandint drm_getctx(struct drm_device *dev, void *data, 875182080Srnoland struct drm_file *file_priv); 876182080Srnolandint drm_switchctx(struct drm_device *dev, void *data, 877182080Srnoland struct drm_file *file_priv); 878182080Srnolandint drm_newctx(struct drm_device *dev, void *data, 879182080Srnoland struct drm_file *file_priv); 880182080Srnolandint drm_rmctx(struct drm_device *dev, void *data, 881182080Srnoland struct drm_file *file_priv); 882182080Srnolandint drm_setsareactx(struct drm_device *dev, void *data, 883182080Srnoland struct drm_file *file_priv); 884182080Srnolandint drm_getsareactx(struct drm_device *dev, void *data, 885182080Srnoland struct drm_file *file_priv); 886113995Sanholt 887145132Sanholt/* Drawable IOCTL support (drm_drawable.c) */ 888182080Srnolandint drm_adddraw(struct drm_device *dev, void *data, 889182080Srnoland struct drm_file *file_priv); 890182080Srnolandint drm_rmdraw(struct drm_device *dev, void *data, 891182080Srnoland struct drm_file *file_priv); 892182080Srnolandint drm_update_draw(struct drm_device *dev, void *data, 893182080Srnoland struct drm_file *file_priv); 894182080Srnolandstruct drm_drawable_info *drm_get_drawable_info(struct drm_device *dev, 895182080Srnoland int handle); 896113995Sanholt 897182080Srnoland/* Drawable support (drm_drawable.c) */ 898182080Srnolandvoid drm_drawable_free_all(struct drm_device *dev); 899182080Srnoland 900145132Sanholt/* Authentication IOCTL support (drm_auth.c) */ 901182080Srnolandint drm_getmagic(struct drm_device *dev, void *data, 902182080Srnoland struct drm_file *file_priv); 903182080Srnolandint drm_authmagic(struct drm_device *dev, void *data, 904182080Srnoland struct drm_file *file_priv); 905113995Sanholt 906145132Sanholt/* Buffer management support (drm_bufs.c) */ 907182080Srnolandint drm_addmap_ioctl(struct drm_device *dev, void *data, 908182080Srnoland struct drm_file *file_priv); 909182080Srnolandint drm_rmmap_ioctl(struct drm_device *dev, void *data, 910182080Srnoland struct drm_file *file_priv); 911189099Srnolandint drm_addbufs(struct drm_device *dev, void *data, 912189099Srnoland struct drm_file *file_priv); 913182080Srnolandint drm_infobufs(struct drm_device *dev, void *data, 914182080Srnoland struct drm_file *file_priv); 915182080Srnolandint drm_markbufs(struct drm_device *dev, void *data, 916182080Srnoland struct drm_file *file_priv); 917182080Srnolandint drm_freebufs(struct drm_device *dev, void *data, 918182080Srnoland struct drm_file *file_priv); 919182080Srnolandint drm_mapbufs(struct drm_device *dev, void *data, 920182080Srnoland struct drm_file *file_priv); 921113995Sanholt 922145132Sanholt/* DMA support (drm_dma.c) */ 923182080Srnolandint drm_dma(struct drm_device *dev, void *data, struct drm_file *file_priv); 924113995Sanholt 925145132Sanholt/* IRQ support (drm_irq.c) */ 926183573Srnolandint drm_control(struct drm_device *dev, void *data, 927183573Srnoland struct drm_file *file_priv); 928182080Srnolandint drm_wait_vblank(struct drm_device *dev, void *data, 929182080Srnoland struct drm_file *file_priv); 930113995Sanholt 931145132Sanholt/* AGP/GART support (drm_agpsupport.c) */ 932182080Srnolandint drm_agp_acquire_ioctl(struct drm_device *dev, void *data, 933182080Srnoland struct drm_file *file_priv); 934182080Srnolandint drm_agp_release_ioctl(struct drm_device *dev, void *data, 935182080Srnoland struct drm_file *file_priv); 936182080Srnolandint drm_agp_enable_ioctl(struct drm_device *dev, void *data, 937182080Srnoland struct drm_file *file_priv); 938182080Srnolandint drm_agp_info_ioctl(struct drm_device *dev, void *data, 939182080Srnoland struct drm_file *file_priv); 940182080Srnolandint drm_agp_alloc_ioctl(struct drm_device *dev, void *data, 941182080Srnoland struct drm_file *file_priv); 942182080Srnolandint drm_agp_free_ioctl(struct drm_device *dev, void *data, 943182080Srnoland struct drm_file *file_priv); 944182080Srnolandint drm_agp_unbind_ioctl(struct drm_device *dev, void *data, 945182080Srnoland struct drm_file *file_priv); 946182080Srnolandint drm_agp_bind_ioctl(struct drm_device *dev, void *data, 947182080Srnoland struct drm_file *file_priv); 948113995Sanholt 949145132Sanholt/* Scatter Gather Support (drm_scatter.c) */ 950182080Srnolandint drm_sg_alloc_ioctl(struct drm_device *dev, void *data, 951182080Srnoland struct drm_file *file_priv); 952182080Srnolandint drm_sg_free(struct drm_device *dev, void *data, 953182080Srnoland struct drm_file *file_priv); 954113995Sanholt 955145132Sanholt/* consistent PCI memory functions (drm_pci.c) */ 956182080Srnolanddrm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size, 957182080Srnoland size_t align, dma_addr_t maxaddr); 958182080Srnolandvoid drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah); 959145132Sanholt 960183833Srnoland/* Inline replacements for drm_alloc and friends */ 961183833Srnolandstatic __inline__ void * 962183833Srnolanddrm_alloc(size_t size, struct malloc_type *area) 963183833Srnoland{ 964183833Srnoland return malloc(size, area, M_NOWAIT); 965183833Srnoland} 966183833Srnoland 967183833Srnolandstatic __inline__ void * 968183833Srnolanddrm_calloc(size_t nmemb, size_t size, struct malloc_type *area) 969183833Srnoland{ 970183833Srnoland return malloc(size * nmemb, area, M_NOWAIT | M_ZERO); 971183833Srnoland} 972183833Srnoland 973183833Srnolandstatic __inline__ void * 974183833Srnolanddrm_realloc(void *oldpt, size_t oldsize, size_t size, 975183833Srnoland struct malloc_type *area) 976183833Srnoland{ 977183833Srnoland return reallocf(oldpt, size, area, M_NOWAIT); 978183833Srnoland} 979183833Srnoland 980183833Srnolandstatic __inline__ void 981183833Srnolanddrm_free(void *pt, size_t size, struct malloc_type *area) 982183833Srnoland{ 983183833Srnoland free(pt, area); 984183833Srnoland} 985183833Srnoland 986145132Sanholt/* Inline replacements for DRM_IOREMAP macros */ 987182080Srnolandstatic __inline__ void 988183573Srnolanddrm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev) 989183573Srnoland{ 990207066Srnoland map->virtual = drm_ioremap_wc(dev, map); 991183573Srnoland} 992183573Srnolandstatic __inline__ void 993182080Srnolanddrm_core_ioremap(struct drm_local_map *map, struct drm_device *dev) 994145132Sanholt{ 995207066Srnoland map->virtual = drm_ioremap(dev, map); 996145132Sanholt} 997182080Srnolandstatic __inline__ void 998182080Srnolanddrm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev) 999145132Sanholt{ 1000207066Srnoland if ( map->virtual && map->size ) 1001145132Sanholt drm_ioremapfree(map); 1002145132Sanholt} 1003145132Sanholt 1004182080Srnolandstatic __inline__ struct drm_local_map * 1005182080Srnolanddrm_core_findmap(struct drm_device *dev, unsigned long offset) 1006145132Sanholt{ 1007145132Sanholt drm_local_map_t *map; 1008145132Sanholt 1009145132Sanholt DRM_SPINLOCK_ASSERT(&dev->dev_lock); 1010145132Sanholt TAILQ_FOREACH(map, &dev->maplist, link) { 1011207066Srnoland if (offset == (unsigned long)map->handle) 1012145132Sanholt return map; 1013145132Sanholt } 1014145132Sanholt return NULL; 1015145132Sanholt} 1016145132Sanholt 1017145132Sanholtstatic __inline__ void drm_core_dropmap(struct drm_map *map) 1018145132Sanholt{ 1019145132Sanholt} 1020145132Sanholt 102195584Sanholt#endif /* __KERNEL__ */ 1022112015Sanholt#endif /* _DRM_P_H_ */ 1023