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