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