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