drmP.h revision 189130
1151912Sphk/* drmP.h -- Private header for Direct Rendering Manager -*- linux-c -*-
2151912Sphk * Created: Mon Jan  4 10:05:05 1999 by faith@precisioninsight.com
3209440Smav */
4151912Sphk/*-
5151912Sphk * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
6151912Sphk * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
7151912Sphk * All rights reserved.
8151912Sphk *
9151912Sphk * Permission is hereby granted, free of charge, to any person obtaining a
10151912Sphk * copy of this software and associated documentation files (the "Software"),
11151912Sphk * to deal in the Software without restriction, including without limitation
12151912Sphk * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13151912Sphk * and/or sell copies of the Software, and to permit persons to whom the
14151912Sphk * Software is furnished to do so, subject to the following conditions:
15151912Sphk *
16151912Sphk * The above copyright notice and this permission notice (including the next
17151912Sphk * paragraph) shall be included in all copies or substantial portions of the
18151912Sphk * Software.
19151912Sphk *
20151912Sphk * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21151912Sphk * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22151912Sphk * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
23151912Sphk * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24151912Sphk * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25151912Sphk * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26151912Sphk * OTHER DEALINGS IN THE SOFTWARE.
27151912Sphk *
28151912Sphk * Authors:
29151912Sphk *    Rickard E. (Rik) Faith <faith@valinux.com>
30151912Sphk *    Gareth Hughes <gareth@valinux.com>
31151912Sphk *
32268351Smarcel */
33209371Smav
34209371Smav#include <sys/cdefs.h>
35209371Smav__FBSDID("$FreeBSD: head/sys/dev/drm/drmP.h 189130 2009-02-28 02:37:55Z rnoland $");
36209371Smav
37151912Sphk#ifndef _DRM_P_H_
38273598Srpaulo#define _DRM_P_H_
39159217Snjl
40151912Sphk#if defined(_KERNEL) || defined(__KERNEL__)
41151912Sphk
42209371Smavstruct drm_device;
43151912Sphkstruct drm_file;
44273598Srpaulo
45151912Sphk#include <sys/param.h>
46209371Smav#include <sys/queue.h>
47209371Smav#include <sys/malloc.h>
48209371Smav#include <sys/kernel.h>
49151912Sphk#include <sys/module.h>
50159217Snjl#include <sys/systm.h>
51193530Sjkim#include <sys/conf.h>
52193530Sjkim#include <sys/stat.h>
53193530Sjkim#if __FreeBSD_version >= 700000
54151912Sphk#include <sys/priv.h>
55175385Sjhb#endif
56151912Sphk#include <sys/proc.h>
57209371Smav#include <sys/lock.h>
58209371Smav#include <sys/fcntl.h>
59209371Smav#include <sys/uio.h>
60209371Smav#include <sys/filio.h>
61203062Savg#include <sys/sysctl.h>
62240286Smav#include <sys/bus.h>
63203062Savg#include <sys/signalvar.h>
64213302Smav#include <sys/poll.h>
65232797Smav#include <sys/tree.h>
66203062Savg#include <vm/vm.h>
67151912Sphk#include <vm/pmap.h>
68151912Sphk#include <vm/vm_extern.h>
69209371Smav#include <vm/vm_map.h>
70169574Stakawata#include <vm/vm_param.h>
71151931Sscottl#include <machine/param.h>
72151935Sscottl#include <machine/pmap.h>
73151931Sscottl#include <machine/bus.h>
74151931Sscottl#include <machine/resource.h>
75209371Smav#include <machine/specialreg.h>
76151912Sphk#include <machine/sysarch.h>
77209371Smav#include <sys/endian.h>
78209371Smav#include <sys/mman.h>
79209371Smav#include <sys/rman.h>
80209371Smav#include <sys/memrange.h>
81209440Smav#if __FreeBSD_version >= 800004
82212533Smav#include <dev/agp/agpvar.h>
83212238Smav#else /* __FreeBSD_version >= 800004 */
84159217Snjl#include <pci/agpvar.h>
85209371Smav#endif /* __FreeBSD_version >= 800004 */
86209371Smav#include <sys/agpio.h>
87151912Sphk#include <sys/mutex.h>
88209371Smav#include <dev/pci/pcivar.h>
89209440Smav#include <dev/pci/pcireg.h>
90209371Smav#include <sys/selinfo.h>
91209371Smav#include <sys/bus.h>
92209371Smav
93209371Smav#include "dev/drm/drm.h"
94209371Smav#include "dev/drm/drm_linux_list.h"
95209371Smav#include "dev/drm/drm_atomic.h"
96209371Smav#include "dev/drm/drm_internal.h"
97209371Smav
98212323Smav#include <opt_drm.h>
99212323Smav#ifdef DRM_DEBUG
100209371Smav#undef DRM_DEBUG
101209371Smav#define DRM_DEBUG_DEFAULT_ON 1
102209371Smav#endif /* DRM_DEBUG */
103209371Smav
104209371Smav#if defined(DRM_LINUX) && DRM_LINUX && !defined(__amd64__)
105209371Smav#include <sys/file.h>
106209371Smav#include <sys/proc.h>
107212491Smav#include <machine/../linux/linux.h>
108209371Smav#include <machine/../linux/linux_proto.h>
109209371Smav#else
110209371Smav/* Either it was defined when it shouldn't be (FreeBSD amd64) or it isn't
111273598Srpaulo * supported on this OS yet.
112273598Srpaulo */
113273598Srpaulo#undef DRM_LINUX
114151912Sphk#define DRM_LINUX 0
115151912Sphk#endif
116273598Srpaulo
117273598Srpaulo/* driver capabilities and requirements mask */
118273598Srpaulo#define DRIVER_USE_AGP     0x1
119273598Srpaulo#define DRIVER_REQUIRE_AGP 0x2
120273598Srpaulo#define DRIVER_USE_MTRR    0x4
121273598Srpaulo#define DRIVER_PCI_DMA     0x8
122273598Srpaulo#define DRIVER_SG          0x10
123273598Srpaulo#define DRIVER_HAVE_DMA    0x20
124273598Srpaulo#define DRIVER_HAVE_IRQ    0x40
125273598Srpaulo#define DRIVER_DMA_QUEUE   0x100
126159217Snjl
127209371Smav
128151912Sphk#define DRM_HASH_SIZE	      16 /* Size of key hash table		  */
129159217Snjl#define DRM_KERNEL_CONTEXT    0	 /* Change drm_resctx if changed	  */
130159217Snjl#define DRM_RESERVED_CONTEXTS 1	 /* Change drm_resctx if changed	  */
131269515Sroyger
132269515SroygerMALLOC_DECLARE(DRM_MEM_DMA);
133269515SroygerMALLOC_DECLARE(DRM_MEM_SAREA);
134159217SnjlMALLOC_DECLARE(DRM_MEM_DRIVER);
135151912SphkMALLOC_DECLARE(DRM_MEM_MAGIC);
136151912SphkMALLOC_DECLARE(DRM_MEM_IOCTLS);
137209371SmavMALLOC_DECLARE(DRM_MEM_MAPS);
138151912SphkMALLOC_DECLARE(DRM_MEM_BUFS);
139151912SphkMALLOC_DECLARE(DRM_MEM_SEGS);
140175385SjhbMALLOC_DECLARE(DRM_MEM_PAGES);
141151912SphkMALLOC_DECLARE(DRM_MEM_FILES);
142151912SphkMALLOC_DECLARE(DRM_MEM_QUEUES);
143175361SjhbMALLOC_DECLARE(DRM_MEM_CMDS);
144209371SmavMALLOC_DECLARE(DRM_MEM_MAPPINGS);
145175361SjhbMALLOC_DECLARE(DRM_MEM_BUFLISTS);
146175361SjhbMALLOC_DECLARE(DRM_MEM_AGPLISTS);
147175385SjhbMALLOC_DECLARE(DRM_MEM_CTXBITMAP);
148175385SjhbMALLOC_DECLARE(DRM_MEM_SGLISTS);
149209440SmavMALLOC_DECLARE(DRM_MEM_DRAWABLE);
150209440Smav
151209440Smav#define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
152209440Smav
153185103Sjkim				/* Internal types and structures */
154185103Sjkim#define DRM_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
155175361Sjhb#define DRM_MIN(a,b) ((a)<(b)?(a):(b))
156175361Sjhb#define DRM_MAX(a,b) ((a)>(b)?(a):(b))
157175361Sjhb
158209371Smav#define DRM_IF_VERSION(maj, min) (maj << 16 | min)
159175361Sjhb
160175361Sjhb#define __OS_HAS_AGP	1
161175385Sjhb
162175385Sjhb#define DRM_DEV_MODE	(S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
163185103Sjkim#define DRM_DEV_UID	0
164185103Sjkim#define DRM_DEV_GID	0
165175361Sjhb
166175361Sjhb#define wait_queue_head_t	atomic_t
167209371Smav#define DRM_WAKEUP(w)		wakeup((void *)w)
168247463Smav#define DRM_WAKEUP_INT(w)	wakeup(w)
169209371Smav#define DRM_INIT_WAITQUEUE(queue) do {(void)(queue);} while (0)
170209371Smav
171209371Smav#define DRM_CURPROC		curthread
172209371Smav#define DRM_STRUCTPROC		struct thread
173212491Smav#define DRM_SPINTYPE		struct mtx
174209371Smav#define DRM_SPININIT(l,name)	mtx_init(l, name, NULL, MTX_DEF)
175209371Smav#define DRM_SPINUNINIT(l)	mtx_destroy(l)
176247463Smav#define DRM_SPINLOCK(l)		mtx_lock(l)
177209371Smav#define DRM_SPINUNLOCK(u)	mtx_unlock(u)
178247463Smav#define DRM_SPINLOCK_IRQSAVE(l, irqflags) do {		\
179209371Smav	mtx_lock(l);					\
180209371Smav	(void)irqflags;					\
181209371Smav} while (0)
182209371Smav#define DRM_SPINUNLOCK_IRQRESTORE(u, irqflags) mtx_unlock(u)
183247463Smav#define DRM_SPINLOCK_ASSERT(l)	mtx_assert(l, MA_OWNED)
184247463Smav#define DRM_CURRENTPID		curthread->td_proc->p_pid
185247463Smav#define DRM_LOCK()		mtx_lock(&dev->dev_lock)
186210290Smav#define DRM_UNLOCK() 		mtx_unlock(&dev->dev_lock)
187212238Smav#define DRM_SYSCTL_HANDLER_ARGS	(SYSCTL_HANDLER_ARGS)
188212238Smav
189212238Smav#define DRM_IRQ_ARGS		void *arg
190212491Smavtypedef void			irqreturn_t;
191212238Smav#define IRQ_HANDLED		/* nothing */
192212491Smav#define IRQ_NONE		/* nothing */
193209371Smav
194209371Smavenum {
195209371Smav	DRM_IS_NOT_AGP,
196209371Smav	DRM_IS_AGP,
197212491Smav	DRM_MIGHT_BE_AGP
198212491Smav};
199212491Smav#define DRM_AGP_MEM		struct agp_memory_info
200212491Smav
201209371Smav#define drm_get_device_from_kdev(_kdev) (_kdev->si_drv1)
202212238Smav
203212491Smav#define PAGE_ALIGN(addr) round_page(addr)
204212491Smav/* DRM_SUSER returns true if the user is superuser */
205212491Smav#if __FreeBSD_version >= 700000
206212491Smav#define DRM_SUSER(p)		(priv_check(p, PRIV_DRIVER) == 0)
207209371Smav#else
208224919Smav#define DRM_SUSER(p)		(suser(p) == 0)
209224919Smav#endif
210224919Smav#define DRM_AGP_FIND_DEVICE()	agp_find_device()
211224919Smav#define DRM_MTRR_WC		MDF_WRITECOMBINE
212212238Smav#define jiffies			ticks
213209371Smav
214209371Smavtypedef unsigned long dma_addr_t;
215209371Smavtypedef u_int64_t u64;
216209371Smavtypedef u_int32_t u32;
217209371Smavtypedef u_int16_t u16;
218209371Smavtypedef u_int8_t u8;
219209371Smav
220209371Smav/* DRM_READMEMORYBARRIER() prevents reordering of reads.
221209371Smav * DRM_WRITEMEMORYBARRIER() prevents reordering of writes.
222209371Smav * DRM_MEMORYBARRIER() prevents reordering of reads and writes.
223209371Smav */
224209371Smav#if defined(__i386__)
225209371Smav#define DRM_READMEMORYBARRIER()		__asm __volatile( \
226209371Smav					"lock; addl $0,0(%%esp)" : : : "memory");
227209371Smav#define DRM_WRITEMEMORYBARRIER()	__asm __volatile("" : : : "memory");
228209371Smav#define DRM_MEMORYBARRIER()		__asm __volatile( \
229209371Smav					"lock; addl $0,0(%%esp)" : : : "memory");
230209371Smav#elif defined(__alpha__)
231209371Smav#define DRM_READMEMORYBARRIER()		alpha_mb();
232209371Smav#define DRM_WRITEMEMORYBARRIER()	alpha_wmb();
233209371Smav#define DRM_MEMORYBARRIER()		alpha_mb();
234209371Smav#elif defined(__amd64__)
235209371Smav#define DRM_READMEMORYBARRIER()		__asm __volatile( \
236209371Smav					"lock; addl $0,0(%%rsp)" : : : "memory");
237209371Smav#define DRM_WRITEMEMORYBARRIER()	__asm __volatile("" : : : "memory");
238212491Smav#define DRM_MEMORYBARRIER()		__asm __volatile( \
239212491Smav					"lock; addl $0,0(%%rsp)" : : : "memory");
240212323Smav#endif
241212323Smav
242212323Smav#define DRM_READ8(map, offset)						\
243212323Smav	*(volatile u_int8_t *) (((unsigned long)(map)->handle) + (offset))
244212323Smav#define DRM_READ16(map, offset)						\
245212323Smav	*(volatile u_int16_t *) (((unsigned long)(map)->handle) + (offset))
246212323Smav#define DRM_READ32(map, offset)						\
247212323Smav	*(volatile u_int32_t *)(((unsigned long)(map)->handle) + (offset))
248212323Smav#define DRM_WRITE8(map, offset, val)					\
249212323Smav	*(volatile u_int8_t *) (((unsigned long)(map)->handle) + (offset)) = val
250212323Smav#define DRM_WRITE16(map, offset, val)					\
251212323Smav	*(volatile u_int16_t *) (((unsigned long)(map)->handle) + (offset)) = val
252212323Smav#define DRM_WRITE32(map, offset, val)					\
253212323Smav	*(volatile u_int32_t *)(((unsigned long)(map)->handle) + (offset)) = val
254212491Smav
255212491Smav#define DRM_VERIFYAREA_READ( uaddr, size )		\
256212323Smav	(!useracc(__DECONST(caddr_t, uaddr), size, VM_PROT_READ))
257212491Smav
258212323Smav#define DRM_COPY_TO_USER(user, kern, size) \
259212323Smav	copyout(kern, user, size)
260212323Smav#define DRM_COPY_FROM_USER(kern, user, size) \
261209371Smav	copyin(user, kern, size)
262209371Smav#define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) 	\
263212491Smav	copyin(arg2, arg1, arg3)
264209371Smav#define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3)	\
265212491Smav	copyout(arg2, arg1, arg3)
266212491Smav#define DRM_GET_USER_UNCHECKED(val, uaddr)		\
267209371Smav	((val) = fuword32(uaddr), 0)
268212491Smav
269209371Smav#define cpu_to_le32(x) htole32(x)
270209371Smav#define le32_to_cpu(x) le32toh(x)
271209371Smav
272209990Smav#define DRM_HZ			hz
273209990Smav#define DRM_UDELAY(udelay)	DELAY(udelay)
274209371Smav#define DRM_TIME_SLICE		(hz/20)  /* Time slice for GLXContexts	  */
275209371Smav
276209371Smav#define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do {	\
277209371Smav	(_map) = (_dev)->context_sareas[_ctx];		\
278209371Smav} while(0)
279209371Smav
280209371Smav#define LOCK_TEST_WITH_RETURN(dev, file_priv)				\
281209371Smavdo {									\
282209371Smav	if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) ||		\
283209371Smav	     dev->lock.file_priv != file_priv) {			\
284209371Smav		DRM_ERROR("%s called without lock held\n",		\
285209371Smav			   __FUNCTION__);				\
286209371Smav		return EINVAL;						\
287209371Smav	}								\
288209371Smav} while (0)
289209371Smav
290209371Smav/* Returns -errno to shared code */
291209371Smav#define DRM_WAIT_ON( ret, queue, timeout, condition )		\
292209371Smavfor ( ret = 0 ; !ret && !(condition) ; ) {			\
293209371Smav	DRM_UNLOCK();						\
294209371Smav	mtx_lock(&dev->irq_lock);				\
295209371Smav	if (!(condition))					\
296209371Smav	    ret = -mtx_sleep(&(queue), &dev->irq_lock, 		\
297209371Smav		PCATCH, "drmwtq", (timeout));			\
298208436Smav	mtx_unlock(&dev->irq_lock);				\
299209371Smav	DRM_LOCK();						\
300208436Smav}
301208436Smav
302208436Smav#define DRM_ERROR(fmt, ...) \
303208436Smav	printf("error: [" DRM_NAME ":pid%d:%s] *ERROR* " fmt,		\
304208438Smav	    DRM_CURRENTPID, __func__ , ##__VA_ARGS__)
305208436Smav
306208436Smav#define DRM_INFO(fmt, ...)  printf("info: [" DRM_NAME "] " fmt , ##__VA_ARGS__)
307208436Smav
308208436Smav#define DRM_DEBUG(fmt, ...) do {					\
309208436Smav	if (drm_debug_flag)						\
310208436Smav		printf("[" DRM_NAME ":pid%d:%s] " fmt, DRM_CURRENTPID,	\
311208436Smav			__func__ , ##__VA_ARGS__);			\
312209371Smav} while (0)
313209371Smav
314258164Smavtypedef struct drm_pci_id_list
315208436Smav{
316208436Smav	int vendor;
317208436Smav	int device;
318216263Sjhb	long driver_private;
319216263Sjhb	char *name;
320216263Sjhb} drm_pci_id_list_t;
321216263Sjhb
322216263Sjhbstruct drm_msi_blacklist_entry
323216263Sjhb{
324216263Sjhb	int vendor;
325216263Sjhb	int device;
326216263Sjhb};
327216263Sjhb
328216263Sjhb#define DRM_AUTH	0x1
329216263Sjhb#define DRM_MASTER	0x2
330216263Sjhb#define DRM_ROOT_ONLY	0x4
331216263Sjhbtypedef struct drm_ioctl_desc {
332216263Sjhb	unsigned long cmd;
333216263Sjhb	int (*func)(struct drm_device *dev, void *data,
334216263Sjhb		    struct drm_file *file_priv);
335273598Srpaulo	int flags;
336273598Srpaulo} drm_ioctl_desc_t;
337273598Srpaulo/**
338273598Srpaulo * Creates a driver or general drm_ioctl_desc array entry for the given
339273598Srpaulo * ioctl, for use by drm_ioctl().
340273598Srpaulo */
341273598Srpaulo#define DRM_IOCTL_DEF(ioctl, func, flags) \
342273598Srpaulo	[DRM_IOCTL_NR(ioctl)] = {ioctl, func, flags}
343273598Srpaulo
344273598Srpaulotypedef struct drm_magic_entry {
345273598Srpaulo	drm_magic_t	       magic;
346273598Srpaulo	struct drm_file	       *priv;
347273598Srpaulo	struct drm_magic_entry *next;
348273598Srpaulo} drm_magic_entry_t;
349273598Srpaulo
350273598Srpaulotypedef struct drm_magic_head {
351273598Srpaulo	struct drm_magic_entry *head;
352273598Srpaulo	struct drm_magic_entry *tail;
353273598Srpaulo} drm_magic_head_t;
354273598Srpaulo
355273598Srpaulotypedef struct drm_buf {
356273598Srpaulo	int		  idx;	       /* Index into master buflist	     */
357273598Srpaulo	int		  total;       /* Buffer size			     */
358273598Srpaulo	int		  order;       /* log-base-2(total)		     */
359273598Srpaulo	int		  used;	       /* Amount of buffer in use (for DMA)  */
360273598Srpaulo	unsigned long	  offset;      /* Byte offset (used internally)	     */
361273598Srpaulo	void		  *address;    /* Address of buffer		     */
362273598Srpaulo	unsigned long	  bus_address; /* Bus address of buffer		     */
363169592Snjl	struct drm_buf	  *next;       /* Kernel-only: used for free list    */
364273602Srpaulo	__volatile__ int  pending;     /* On hardware DMA queue		     */
365209371Smav	struct drm_file   *file_priv;  /* Unique identifier of holding process */
366169574Stakawata	int		  context;     /* Kernel queue for this buffer	     */
367169574Stakawata	enum {
368169574Stakawata		DRM_LIST_NONE	 = 0,
369169574Stakawata		DRM_LIST_FREE	 = 1,
370258164Smav		DRM_LIST_WAIT	 = 2,
371169574Stakawata		DRM_LIST_PEND	 = 3,
372172489Snjl		DRM_LIST_PRIO	 = 4,
373209371Smav		DRM_LIST_RECLAIM = 5
374172489Snjl	}		  list;	       /* Which list we're on		     */
375208436Smav
376208436Smav	int		  dev_priv_size; /* Size of buffer private stoarge   */
377208436Smav	void		  *dev_private;  /* Per-buffer private storage       */
378208436Smav} drm_buf_t;
379208436Smav
380208436Smavtypedef struct drm_freelist {
381258164Smav	int		  initialized; /* Freelist in use		   */
382208436Smav	atomic_t	  count;       /* Number of free buffers	   */
383258164Smav	drm_buf_t	  *next;       /* End pointer			   */
384258164Smav
385208436Smav	int		  low_mark;    /* Low water mark		   */
386258164Smav	int		  high_mark;   /* High water mark		   */
387258164Smav} drm_freelist_t;
388258164Smav
389258164Smavtypedef struct drm_dma_handle {
390258164Smav	void *vaddr;
391208436Smav	bus_addr_t busaddr;
392258164Smav	bus_dma_tag_t tag;
393208436Smav	bus_dmamap_t map;
394231161Sjkim} drm_dma_handle_t;
395208436Smav
396208436Smavtypedef struct drm_buf_entry {
397208436Smav	int		  buf_size;
398208436Smav	int		  buf_count;
399208436Smav	drm_buf_t	  *buflist;
400208436Smav	int		  seg_count;
401169574Stakawata	drm_dma_handle_t  **seglist;
402169574Stakawata	int		  page_order;
403169574Stakawata
404151912Sphk	drm_freelist_t	  freelist;
405209371Smav} drm_buf_entry_t;
406151912Sphk
407159217Snjltypedef TAILQ_HEAD(drm_file_list, drm_file) drm_file_list_t;
408159217Snjlstruct drm_file {
409269515Sroyger	TAILQ_ENTRY(drm_file) link;
410151912Sphk	struct drm_device *dev;
411199016Savg	int		  authenticated;
412208436Smav	int		  master;
413169592Snjl	int		  minor;
414151912Sphk	pid_t		  pid;
415159217Snjl	uid_t		  uid;
416151912Sphk	drm_magic_t	  magic;
417151912Sphk	unsigned long	  ioctl_count;
418151912Sphk	void		 *driver_priv;
419151912Sphk};
420209371Smav
421151912Sphktypedef struct drm_lock_data {
422209371Smav	struct drm_hw_lock	*hw_lock;	/* Hardware lock		   */
423209371Smav	struct drm_file   *file_priv;   /* Unique identifier of holding process (NULL is kernel)*/
424209371Smav	int		  lock_queue;	/* Queue of blocked processes	   */
425209371Smav	unsigned long	  lock_time;	/* Time of last lock in jiffies	   */
426209371Smav} drm_lock_data_t;
427212238Smav
428209371Smav/* This structure, in the struct drm_device, is always initialized while the
429151912Sphk * device
430151912Sphk * is open.  dev->dma_lock protects the incrementing of dev->buf_use, which
431151912Sphk * when set marks that no further bufs may be allocated until device teardown
432151912Sphk * occurs (when the last open of the device has closed).  The high/low
433151912Sphk * watermarks of bufs are only touched by the X Server, and thus not
434151912Sphk * concurrently accessed, so no locking is needed.
435151912Sphk */
436209371Smavtypedef struct drm_device_dma {
437209371Smav	drm_buf_entry_t	  bufs[DRM_MAX_ORDER+1];
438159217Snjl	int		  buf_count;
439159217Snjl	drm_buf_t	  **buflist;	/* Vector of pointers info bufs	   */
440159217Snjl	int		  seg_count;
441151912Sphk	int		  page_count;
442159217Snjl	unsigned long	  *pagelist;
443159217Snjl	unsigned long	  byte_count;
444159217Snjl	enum {
445159217Snjl		_DRM_DMA_USE_AGP = 0x01,
446159217Snjl		_DRM_DMA_USE_SG  = 0x02
447159217Snjl	} flags;
448159217Snjl} drm_device_dma_t;
449151912Sphk
450171547Snjltypedef struct drm_agp_mem {
451175361Sjhb	void               *handle;
452171547Snjl	unsigned long      bound; /* address */
453159217Snjl	int                pages;
454175385Sjhb	struct drm_agp_mem *prev;
455175361Sjhb	struct drm_agp_mem *next;
456175361Sjhb} drm_agp_mem_t;
457175361Sjhb
458175361Sjhbtypedef struct drm_agp_head {
459175361Sjhb	device_t	   agpdev;
460175361Sjhb	struct agp_info    info;
461175361Sjhb	const char         *chipset;
462209371Smav	drm_agp_mem_t      *memory;
463209440Smav	unsigned long      mode;
464209440Smav	int                enabled;
465209440Smav	int                acquired;
466209440Smav	unsigned long      base;
467209371Smav   	int 		   mtrr;
468209371Smav	int		   cant_use_aperture;
469209371Smav	unsigned long	   page_mask;
470209371Smav} drm_agp_head_t;
471209371Smav
472209371Smavtypedef struct drm_sg_mem {
473209371Smav	unsigned long		  handle;
474209371Smav	void			 *virtual;
475209371Smav	int			  pages;
476159217Snjl	dma_addr_t		 *busaddr;
477159217Snjl	struct drm_dma_handle	 *sg_dmah;	/* Handle for sg_pages   */
478209371Smav	struct drm_dma_handle	 *dmah;		/* Handle to PCI memory  */
479209440Smav						/* for ATI PCIGART table */
480209440Smav} drm_sg_mem_t;
481209440Smav
482209440Smavtypedef TAILQ_HEAD(drm_map_list, drm_local_map) drm_map_list_t;
483159217Snjl
484209371Smavtypedef struct drm_local_map {
485209371Smav	unsigned long	offset;	 /* Physical address (0 for SAREA)*/
486209371Smav	unsigned long	size;	 /* Physical size (bytes)	    */
487209371Smav	enum drm_map_type	type;	 /* Type of memory mapped		    */
488209371Smav	enum drm_map_flags	flags;	 /* Flags				    */
489209371Smav	void		*handle; /* User-space: "Handle" to pass to mmap    */
490209371Smav				 /* Kernel-space: kernel-virtual address    */
491212323Smav	int		mtrr;	 /* Boolean: MTRR used */
492212323Smav				 /* Private data			    */
493209371Smav	int		rid;	 /* PCI resource ID for bus_space */
494209371Smav	struct resource *bsr;
495209371Smav	bus_space_tag_t bst;
496209371Smav	bus_space_handle_t bsh;
497209371Smav	drm_dma_handle_t *dmah;
498209371Smav	TAILQ_ENTRY(drm_local_map) link;
499209371Smav} drm_local_map_t;
500209371Smav
501209371SmavTAILQ_HEAD(drm_vbl_sig_list, drm_vbl_sig);
502209371Smavtypedef struct drm_vbl_sig {
503209371Smav	TAILQ_ENTRY(drm_vbl_sig) link;
504209371Smav	unsigned int	sequence;
505159217Snjl	int		signo;
506209371Smav	int		pid;
507171547Snjl} drm_vbl_sig_t;
508171547Snjl
509171547Snjlstruct drm_vblank_info {
510171547Snjl	wait_queue_head_t queue;	/* vblank wait queue */
511175385Sjhb	atomic_t count;			/* number of VBLANK interrupts */
512171547Snjl					/* (driver must alloc the right number of counters) */
513175385Sjhb	struct drm_vbl_sig_list sigs;	/* signal list to send on VBLANK */
514171547Snjl	atomic_t refcount;		/* number of users of vblank interrupts */
515171547Snjl	u32 last;			/* protected by dev->vbl_lock, used */
516175361Sjhb					/* for wraparound handling */
517171547Snjl	int enabled;			/* so we don't call enable more than */
518171547Snjl					/* once per disable */
519171547Snjl	int inmodeset;			/* Display driver is setting mode */
520208436Smav};
521208436Smav
522209371Smav/* location of GART table */
523209371Smav#define DRM_ATI_GART_MAIN 1
524209371Smav#define DRM_ATI_GART_FB   2
525222222Sjkim
526209371Smav#define DRM_ATI_GART_PCI  1
527209371Smav#define DRM_ATI_GART_PCIE 2
528209371Smav#define DRM_ATI_GART_IGP  3
529208436Smav
530209371Smavstruct drm_ati_pcigart_info {
531209371Smav	int gart_table_location;
532209371Smav	int gart_reg_if;
533209371Smav	void *addr;
534209440Smav	dma_addr_t bus_addr;
535209440Smav	dma_addr_t table_mask;
536209440Smav	dma_addr_t member_mask;
537209440Smav	struct drm_dma_handle *table_handle;
538209440Smav	drm_local_map_t mapping;
539209440Smav	int table_size;
540209440Smav};
541209440Smav
542209440Smav#ifndef DMA_BIT_MASK
543209440Smav#define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : (1ULL<<(n)) - 1)
544209440Smav#endif
545209440Smav
546212238Smav#define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
547212238Smav
548212238Smavstruct drm_driver_info {
549209371Smav	int	(*load)(struct drm_device *, unsigned long flags);
550209371Smav	int	(*firstopen)(struct drm_device *);
551209371Smav	int	(*open)(struct drm_device *, struct drm_file *);
552209371Smav	void	(*preclose)(struct drm_device *, struct drm_file *file_priv);
553209371Smav	void	(*postclose)(struct drm_device *, struct drm_file *);
554209371Smav	void	(*lastclose)(struct drm_device *);
555209371Smav	int	(*unload)(struct drm_device *);
556240286Smav	void	(*reclaim_buffers_locked)(struct drm_device *,
557212238Smav					  struct drm_file *file_priv);
558212238Smav	int	(*dma_ioctl)(struct drm_device *dev, void *data,
559213302Smav			     struct drm_file *file_priv);
560213302Smav	void	(*dma_ready)(struct drm_device *);
561213302Smav	int	(*dma_quiescent)(struct drm_device *);
562213302Smav	int	(*dma_flush_block_and_flush)(struct drm_device *, int context,
563213302Smav					     enum drm_lock_flags flags);
564213302Smav	int	(*dma_flush_unblock)(struct drm_device *, int context,
565232797Smav				     enum drm_lock_flags flags);
566232797Smav	int	(*context_ctor)(struct drm_device *dev, int context);
567232797Smav	int	(*context_dtor)(struct drm_device *dev, int context);
568232797Smav	int	(*kernel_context_switch)(struct drm_device *dev, int old,
569232797Smav					 int new);
570232797Smav	int	(*kernel_context_switch_unlock)(struct drm_device *dev);
571232797Smav	void	(*irq_preinstall)(struct drm_device *dev);
572212238Smav	int	(*irq_postinstall)(struct drm_device *dev);
573212238Smav	void	(*irq_uninstall)(struct drm_device *dev);
574215473Sjhb	void	(*irq_handler)(DRM_IRQ_ARGS);
575212238Smav	u32	(*get_vblank_counter)(struct drm_device *dev, int crtc);
576212238Smav	int	(*enable_vblank)(struct drm_device *dev, int crtc);
577212238Smav	void	(*disable_vblank)(struct drm_device *dev, int crtc);
578212238Smav
579212238Smav	drm_pci_id_list_t *id_entry;	/* PCI ID, name, and chipset private */
580212238Smav
581212238Smav	/**
582212533Smav	 * Called by \c drm_device_is_agp.  Typically used to determine if a
583212533Smav	 * card is really attached to AGP or not.
584212533Smav	 *
585212533Smav	 * \param dev  DRM device handle
586212533Smav	 *
587212238Smav	 * \returns
588212238Smav	 * One of three values is returned depending on whether or not the
589212238Smav	 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
590212238Smav	 * (return of 1), or may or may not be AGP (return of 2).
591212238Smav	 */
592212238Smav	int	(*device_is_agp) (struct drm_device * dev);
593212238Smav
594209371Smav	drm_ioctl_desc_t *ioctls;
595209371Smav	int	max_ioctl;
596209440Smav
597209440Smav	int	buf_priv_size;
598209371Smav
599209440Smav	int	major;
600209371Smav	int	minor;
601209371Smav	int	patchlevel;
602209371Smav	const char *name;		/* Simple driver name		   */
603209371Smav	const char *desc;		/* Longer driver name		   */
604269897Sneel	const char *date;		/* Date of last major changes.	   */
605269897Sneel
606209440Smav	u32 driver_features;
607209440Smav};
608209440Smav
609212238Smav/* Length for the array of resource pointers for drm_get_resource_*. */
610212238Smav#define DRM_MAX_PCI_RESOURCE	3
611212238Smav
612212238Smav/**
613209440Smav * DRM device functions structure
614216263Sjhb */
615216490Sjhbstruct drm_device {
616216490Sjhb	struct drm_driver_info *driver;
617216490Sjhb	drm_pci_id_list_t *id_entry;	/* PCI ID, name, and chipset private */
618209440Smav
619209440Smav	u_int16_t pci_device;		/* PCI device id */
620209440Smav	u_int16_t pci_vendor;		/* PCI vendor id */
621216490Sjhb
622216490Sjhb	char		  *unique;	/* Unique identifier: e.g., busid  */
623216490Sjhb	int		  unique_len;	/* Length of unique field	   */
624209440Smav	device_t	  device;	/* Device instance from newbus     */
625209440Smav	struct cdev	  *devnode;	/* Device number for mknod	   */
626209440Smav	int		  if_version;	/* Highest interface version set */
627209371Smav
628209371Smav	int		  flags;	/* Flags to open(2)		   */
629209371Smav
630209371Smav				/* Locks */
631209371Smav	struct mtx	  vbl_lock;	/* protects vblank operations */
632209440Smav	struct mtx	  dma_lock;	/* protects dev->dma */
633209440Smav	struct mtx	  irq_lock;	/* protects irq condition checks */
634209371Smav	struct mtx	  dev_lock;	/* protects everything else */
635209371Smav	DRM_SPINTYPE	  drw_lock;
636209371Smav
637209371Smav				/* Usage Counters */
638209440Smav	int		  open_count;	/* Outstanding files open	   */
639209440Smav	int		  buf_use;	/* Buffers in use -- cannot alloc  */
640209440Smav
641209440Smav				/* Performance counters */
642209440Smav	unsigned long     counters;
643212533Smav	enum drm_stat_type	types[15];
644209440Smav	atomic_t          counts[15];
645209440Smav
646209440Smav				/* Authentication */
647209440Smav	drm_file_list_t   files;
648209440Smav	drm_magic_head_t  magiclist[DRM_HASH_SIZE];
649209440Smav
650209440Smav	/* Linked list of mappable regions. Protected by dev_lock */
651209440Smav	drm_map_list_t	  maplist;
652212323Smav
653209440Smav	drm_local_map_t	  **context_sareas;
654209440Smav	int		  max_context;
655209440Smav
656209440Smav	drm_lock_data_t	  lock;		/* Information on hardware lock	   */
657209440Smav
658209440Smav				/* DMA queues (contexts) */
659212238Smav	drm_device_dma_t  *dma;		/* Optional pointer for DMA support */
660212238Smav
661209440Smav				/* Context support */
662209371Smav	int		  irq;		/* Interrupt used by board	   */
663209371Smav	int		  irq_enabled;	/* True if the irq handler is enabled */
664215473Sjhb	int		  msi_enabled;	/* MSI enabled */
665209371Smav	int		  irqrid;	/* Interrupt used by board */
666209371Smav	struct resource   *irqr;	/* Resource for interrupt used by board	   */
667209371Smav	void		  *irqh;	/* Handle from bus_setup_intr      */
668209371Smav
669216263Sjhb	/* Storage of resource pointers for drm_get_resource_* */
670216490Sjhb	struct resource   *pcir[DRM_MAX_PCI_RESOURCE];
671216490Sjhb	int		  pcirid[DRM_MAX_PCI_RESOURCE];
672216490Sjhb
673216490Sjhb	int		  pci_domain;
674216490Sjhb	int		  pci_bus;
675216490Sjhb	int		  pci_slot;
676209371Smav	int		  pci_func;
677209371Smav
678209371Smav	atomic_t	  context_flag;	/* Context swapping flag	   */
679209371Smav	int		  last_context;	/* Last current context		   */
680209371Smav
681209371Smav	int		  vblank_disable_allowed;
682209371Smav	atomic_t 	  vbl_signal_pending;	/* number of signals pending on all crtcs */
683209371Smav	struct callout	  vblank_disable_timer;
684209371Smav	u32		  max_vblank_count;	/* size of vblank counter register */
685209371Smav	struct drm_vblank_info *vblank;		/* per crtc vblank info */
686209371Smav	int		  num_crtcs;
687209371Smav
688209440Smav	struct sigio      *buf_sigio;	/* Processes waiting for SIGIO     */
689209371Smav
690209440Smav				/* Sysctl support */
691209440Smav	struct drm_sysctl_info *sysctl;
692209440Smav
693209371Smav	drm_agp_head_t    *agp;
694212238Smav	drm_sg_mem_t      *sg;  /* Scatter gather memory */
695209371Smav	atomic_t          *ctx_bitmap;
696273602Srpaulo	void		  *dev_private;
697273602Srpaulo	unsigned int	  agp_buffer_token;
698209371Smav	drm_local_map_t   *agp_buffer_map;
699209371Smav
700209371Smav	struct unrhdr	  *drw_unrhdr;
701209371Smav	/* RB tree of drawable infos */
702209371Smav	RB_HEAD(drawable_tree, bsd_drm_drawable_info) drw_head;
703209371Smav};
704209371Smav
705209371Smavstatic __inline__ int drm_core_check_feature(struct drm_device *dev,
706209371Smav					     int feature)
707209371Smav{
708209371Smav	return ((dev->driver->driver_features & feature) ? 1 : 0);
709209371Smav}
710212238Smav
711212238Smav#if __OS_HAS_AGP
712212238Smavstatic inline int drm_core_has_AGP(struct drm_device *dev)
713209371Smav{
714209371Smav	return drm_core_check_feature(dev, DRIVER_USE_AGP);
715209371Smav}
716209371Smav#else
717209371Smav#define drm_core_has_AGP(dev) (0)
718209371Smav#endif
719209371Smav
720209371Smavextern int	drm_debug_flag;
721209371Smav
722209371Smav/* Device setup support (drm_drv.c) */
723209371Smavint	drm_probe(device_t nbdev, drm_pci_id_list_t *idlist);
724209371Smavint	drm_attach(device_t nbdev, drm_pci_id_list_t *idlist);
725209371Smavvoid	drm_close(void *data);
726209371Smavint	drm_detach(device_t nbdev);
727209371Smavd_ioctl_t drm_ioctl;
728209371Smavd_open_t drm_open;
729209371Smavd_read_t drm_read;
730209371Smavd_poll_t drm_poll;
731248170Smavd_mmap_t drm_mmap;
732248154Smavextern drm_local_map_t	*drm_getsarea(struct drm_device *dev);
733209371Smav
734209371Smav/* File operations helpers (drm_fops.c) */
735209371Smavextern int		drm_open_helper(struct cdev *kdev, int flags, int fmt,
736247463Smav					 DRM_STRUCTPROC *p,
737247463Smav					struct drm_device *dev);
738247463Smav
739209371Smav/* Memory management support (drm_memory.c) */
740209371Smavvoid	drm_mem_init(void);
741209371Smavvoid	drm_mem_uninit(void);
742209371Smavvoid	*drm_ioremap_wc(struct drm_device *dev, drm_local_map_t *map);
743209371Smavvoid	*drm_ioremap(struct drm_device *dev, drm_local_map_t *map);
744209371Smavvoid	drm_ioremapfree(drm_local_map_t *map);
745209371Smavint	drm_mtrr_add(unsigned long offset, size_t size, int flags);
746209371Smavint	drm_mtrr_del(int handle, unsigned long offset, size_t size, int flags);
747273598Srpaulo
748273598Srpauloint	drm_context_switch(struct drm_device *dev, int old, int new);
749273598Srpauloint	drm_context_switch_complete(struct drm_device *dev, int new);
750273598Srpaulo
751273598Srpauloint	drm_ctxbitmap_init(struct drm_device *dev);
752273598Srpaulovoid	drm_ctxbitmap_cleanup(struct drm_device *dev);
753273598Srpaulovoid	drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
754273598Srpauloint	drm_ctxbitmap_next(struct drm_device *dev);
755273598Srpaulo
756273598Srpaulo/* Locking IOCTL support (drm_lock.c) */
757273598Srpauloint	drm_lock_take(struct drm_lock_data *lock_data,
758273598Srpaulo		      unsigned int context);
759273598Srpauloint	drm_lock_transfer(struct drm_lock_data *lock_data,
760273598Srpaulo			  unsigned int context);
761273598Srpauloint	drm_lock_free(struct drm_lock_data *lock_data,
762273598Srpaulo		      unsigned int context);
763273598Srpaulo
764273598Srpaulo/* Buffer management support (drm_bufs.c) */
765273598Srpaulounsigned long drm_get_resource_start(struct drm_device *dev,
766273598Srpaulo				     unsigned int resource);
767159217Snjlunsigned long drm_get_resource_len(struct drm_device *dev,
768159217Snjl				   unsigned int resource);
769159217Snjlvoid	drm_rmmap(struct drm_device *dev, drm_local_map_t *map);
770159217Snjlint	drm_order(unsigned long size);
771209371Smavint	drm_addmap(struct drm_device *dev, unsigned long offset,
772159217Snjl		   unsigned long size,
773159217Snjl		   enum drm_map_type type, enum drm_map_flags flags,
774159217Snjl		   drm_local_map_t **map_ptr);
775159217Snjlint	drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc *request);
776159217Snjlint	drm_addbufs_sg(struct drm_device *dev, struct drm_buf_desc *request);
777159217Snjlint	drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc *request);
778159217Snjl
779168010Snjl/* DMA support (drm_dma.c) */
780209371Smavint	drm_dma_setup(struct drm_device *dev);
781175361Sjhbvoid	drm_dma_takedown(struct drm_device *dev);
782212541Smavvoid	drm_free_buffer(struct drm_device *dev, drm_buf_t *buf);
783175361Sjhbvoid	drm_reclaim_buffers(struct drm_device *dev, struct drm_file *file_priv);
784175361Sjhb#define drm_core_reclaim_buffers drm_reclaim_buffers
785175361Sjhb
786175361Sjhb/* IRQ support (drm_irq.c) */
787175361Sjhbint	drm_irq_install(struct drm_device *dev);
788175361Sjhbint	drm_irq_uninstall(struct drm_device *dev);
789212541Smavirqreturn_t drm_irq_handler(DRM_IRQ_ARGS);
790212541Smavvoid	drm_driver_irq_preinstall(struct drm_device *dev);
791175361Sjhbvoid	drm_driver_irq_postinstall(struct drm_device *dev);
792175361Sjhbvoid	drm_driver_irq_uninstall(struct drm_device *dev);
793175361Sjhbvoid	drm_handle_vblank(struct drm_device *dev, int crtc);
794175361Sjhbu32	drm_vblank_count(struct drm_device *dev, int crtc);
795175361Sjhbint	drm_vblank_get(struct drm_device *dev, int crtc);
796209371Smavvoid	drm_vblank_put(struct drm_device *dev, int crtc);
797168010Snjlvoid	drm_vblank_cleanup(struct drm_device *dev);
798209371Smavint	drm_vblank_wait(struct drm_device *dev, unsigned int *vbl_seq);
799209371Smavint	drm_vblank_init(struct drm_device *dev, int num_crtcs);
800209371Smavvoid	drm_vbl_send_signals(struct drm_device *dev, int crtc);
801168010Snjlint 	drm_modeset_ctl(struct drm_device *dev, void *data,
802168010Snjl			struct drm_file *file_priv);
803168010Snjl
804175361Sjhb/* AGP/PCI Express/GART support (drm_agpsupport.c) */
805209371Smavint	drm_device_is_agp(struct drm_device *dev);
806209371Smavint	drm_device_is_pcie(struct drm_device *dev);
807209371Smavdrm_agp_head_t *drm_agp_init(void);
808209371Smavint	drm_agp_acquire(struct drm_device *dev);
809209440Smavint	drm_agp_release(struct drm_device *dev);
810209371Smavint	drm_agp_info(struct drm_device * dev, struct drm_agp_info *info);
811273602Srpauloint	drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
812273602Srpaulovoid	*drm_agp_allocate_memory(size_t pages, u32 type);
813209371Smavint	drm_agp_free_memory(void *handle);
814209371Smavint	drm_agp_bind_memory(void *handle, off_t start);
815209371Smavint	drm_agp_unbind_memory(void *handle);
816209371Smavint	drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
817209371Smavint	drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
818209371Smavint	drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
819209371Smavint	drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
820209371Smav
821209371Smav/* Scatter Gather Support (drm_scatter.c) */
822209371Smavvoid	drm_sg_cleanup(drm_sg_mem_t *entry);
823209371Smavint	drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request);
824209371Smav
825212491Smav/* sysctl support (drm_sysctl.h) */
826209371Smavextern int		drm_sysctl_init(struct drm_device *dev);
827209371Smavextern int		drm_sysctl_cleanup(struct drm_device *dev);
828212491Smav
829209371Smav/* ATI PCIGART support (ati_pcigart.c) */
830209371Smavint	drm_ati_pcigart_init(struct drm_device *dev,
831209371Smav				struct drm_ati_pcigart_info *gart_info);
832212491Smavint	drm_ati_pcigart_cleanup(struct drm_device *dev,
833209371Smav				struct drm_ati_pcigart_info *gart_info);
834209371Smav
835209371Smav/* Locking IOCTL support (drm_drv.c) */
836209371Smavint	drm_lock(struct drm_device *dev, void *data,
837212491Smav		 struct drm_file *file_priv);
838209371Smavint	drm_unlock(struct drm_device *dev, void *data,
839212491Smav		   struct drm_file *file_priv);
840209371Smavint	drm_version(struct drm_device *dev, void *data,
841209371Smav		    struct drm_file *file_priv);
842209371Smavint	drm_setversion(struct drm_device *dev, void *data,
843209371Smav		       struct drm_file *file_priv);
844168010Snjl
845168010Snjl/* Misc. IOCTL support (drm_ioctl.c) */
846168010Snjlint	drm_irq_by_busid(struct drm_device *dev, void *data,
847159217Snjl			 struct drm_file *file_priv);
848159217Snjlint	drm_getunique(struct drm_device *dev, void *data,
849209371Smav		      struct drm_file *file_priv);
850159217Snjlint	drm_setunique(struct drm_device *dev, void *data,
851151912Sphk		      struct drm_file *file_priv);
852151912Sphkint	drm_getmap(struct drm_device *dev, void *data,
853151912Sphk		   struct drm_file *file_priv);
854151912Sphkint	drm_getclient(struct drm_device *dev, void *data,
855151912Sphk		      struct drm_file *file_priv);
856151912Sphkint	drm_getstats(struct drm_device *dev, void *data,
857151912Sphk		     struct drm_file *file_priv);
858151912Sphkint	drm_noop(struct drm_device *dev, void *data,
859175385Sjhb		 struct drm_file *file_priv);
860151912Sphk
861175385Sjhb/* Context IOCTL support (drm_context.c) */
862151912Sphkint	drm_resctx(struct drm_device *dev, void *data,
863175385Sjhb		   struct drm_file *file_priv);
864151912Sphkint	drm_addctx(struct drm_device *dev, void *data,
865151912Sphk		   struct drm_file *file_priv);
866151912Sphkint	drm_modctx(struct drm_device *dev, void *data,
867151912Sphk		   struct drm_file *file_priv);
868151912Sphkint	drm_getctx(struct drm_device *dev, void *data,
869151912Sphk		   struct drm_file *file_priv);
870159217Snjlint	drm_switchctx(struct drm_device *dev, void *data,
871151912Sphk		      struct drm_file *file_priv);
872151912Sphkint	drm_newctx(struct drm_device *dev, void *data,
873159217Snjl		   struct drm_file *file_priv);
874151912Sphkint	drm_rmctx(struct drm_device *dev, void *data,
875151912Sphk		  struct drm_file *file_priv);
876209371Smavint	drm_setsareactx(struct drm_device *dev, void *data,
877209371Smav			struct drm_file *file_priv);
878209371Smavint	drm_getsareactx(struct drm_device *dev, void *data,
879209371Smav			struct drm_file *file_priv);
880209371Smav
881209371Smav/* Drawable IOCTL support (drm_drawable.c) */
882209371Smavint	drm_adddraw(struct drm_device *dev, void *data,
883273602Srpaulo		    struct drm_file *file_priv);
884209371Smavint	drm_rmdraw(struct drm_device *dev, void *data,
885209371Smav		   struct drm_file *file_priv);
886209371Smavint	drm_update_draw(struct drm_device *dev, void *data,
887209371Smav			struct drm_file *file_priv);
888209371Smavstruct drm_drawable_info *drm_get_drawable_info(struct drm_device *dev,
889209371Smav						int handle);
890209371Smav
891209371Smav/* Drawable support (drm_drawable.c) */
892209371Smavvoid drm_drawable_free_all(struct drm_device *dev);
893209371Smav
894209371Smav/* Authentication IOCTL support (drm_auth.c) */
895209371Smavint	drm_getmagic(struct drm_device *dev, void *data,
896209371Smav		     struct drm_file *file_priv);
897209371Smavint	drm_authmagic(struct drm_device *dev, void *data,
898209371Smav		      struct drm_file *file_priv);
899209371Smav
900209371Smav/* Buffer management support (drm_bufs.c) */
901209371Smavint	drm_addmap_ioctl(struct drm_device *dev, void *data,
902209371Smav			 struct drm_file *file_priv);
903209371Smavint	drm_rmmap_ioctl(struct drm_device *dev, void *data,
904209371Smav			struct drm_file *file_priv);
905209371Smavint	drm_addbufs(struct drm_device *dev, void *data,
906151912Sphk		    struct drm_file *file_priv);
907209371Smavint	drm_infobufs(struct drm_device *dev, void *data,
908209371Smav		     struct drm_file *file_priv);
909209371Smavint	drm_markbufs(struct drm_device *dev, void *data,
910209371Smav		     struct drm_file *file_priv);
911209371Smavint	drm_freebufs(struct drm_device *dev, void *data,
912209371Smav		     struct drm_file *file_priv);
913151912Sphkint	drm_mapbufs(struct drm_device *dev, void *data,
914209371Smav		    struct drm_file *file_priv);
915209371Smav
916209371Smav/* DMA support (drm_dma.c) */
917209371Smavint	drm_dma(struct drm_device *dev, void *data, struct drm_file *file_priv);
918246128Ssbz
919151912Sphk/* IRQ support (drm_irq.c) */
920151912Sphkint	drm_control(struct drm_device *dev, void *data,
921209371Smav		    struct drm_file *file_priv);
922209371Smavint	drm_wait_vblank(struct drm_device *dev, void *data,
923209371Smav			struct drm_file *file_priv);
924209371Smav
925151912Sphk/* AGP/GART support (drm_agpsupport.c) */
926151912Sphkint	drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
927209371Smav			      struct drm_file *file_priv);
928209371Smavint	drm_agp_release_ioctl(struct drm_device *dev, void *data,
929			      struct drm_file *file_priv);
930int	drm_agp_enable_ioctl(struct drm_device *dev, void *data,
931			     struct drm_file *file_priv);
932int	drm_agp_info_ioctl(struct drm_device *dev, void *data,
933			   struct drm_file *file_priv);
934int	drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
935			    struct drm_file *file_priv);
936int	drm_agp_free_ioctl(struct drm_device *dev, void *data,
937			   struct drm_file *file_priv);
938int	drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
939			     struct drm_file *file_priv);
940int	drm_agp_bind_ioctl(struct drm_device *dev, void *data,
941			   struct drm_file *file_priv);
942
943/* Scatter Gather Support (drm_scatter.c) */
944int	drm_sg_alloc_ioctl(struct drm_device *dev, void *data,
945			   struct drm_file *file_priv);
946int	drm_sg_free(struct drm_device *dev, void *data,
947		    struct drm_file *file_priv);
948
949/* consistent PCI memory functions (drm_pci.c) */
950drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
951				size_t align, dma_addr_t maxaddr);
952void	drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah);
953
954/* Inline replacements for drm_alloc and friends */
955static __inline__ void *
956drm_alloc(size_t size, struct malloc_type *area)
957{
958	return malloc(size, area, M_NOWAIT);
959}
960
961static __inline__ void *
962drm_calloc(size_t nmemb, size_t size, struct malloc_type *area)
963{
964	return malloc(size * nmemb, area, M_NOWAIT | M_ZERO);
965}
966
967static __inline__ void *
968drm_realloc(void *oldpt, size_t oldsize, size_t size,
969    struct malloc_type *area)
970{
971	return reallocf(oldpt, size, area, M_NOWAIT);
972}
973
974static __inline__ void
975drm_free(void *pt, size_t size, struct malloc_type *area)
976{
977	free(pt, area);
978}
979
980/* Inline replacements for DRM_IOREMAP macros */
981static __inline__ void
982drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev)
983{
984	map->handle = drm_ioremap_wc(dev, map);
985}
986static __inline__ void
987drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev)
988{
989	map->handle = drm_ioremap(dev, map);
990}
991static __inline__ void
992drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev)
993{
994	if ( map->handle && map->size )
995		drm_ioremapfree(map);
996}
997
998static __inline__ struct drm_local_map *
999drm_core_findmap(struct drm_device *dev, unsigned long offset)
1000{
1001	drm_local_map_t *map;
1002
1003	DRM_SPINLOCK_ASSERT(&dev->dev_lock);
1004	TAILQ_FOREACH(map, &dev->maplist, link) {
1005		if (map->offset == offset)
1006			return map;
1007	}
1008	return NULL;
1009}
1010
1011static __inline__ void drm_core_dropmap(struct drm_map *map)
1012{
1013}
1014
1015#endif /* __KERNEL__ */
1016#endif /* _DRM_P_H_ */
1017