xref: /dragonfly/sys/dev/drm/include/drm/drmP.h (revision c6f73aab)
1 /**
2  * \file drmP.h
3  * Private header for Direct Rendering Manager
4  *
5  * \author Rickard E. (Rik) Faith <faith@valinux.com>
6  * \author Gareth Hughes <gareth@valinux.com>
7  */
8 
9 /*
10  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
11  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
12  * Copyright (c) 2009-2010, Code Aurora Forum.
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 
35 #ifndef _DRM_P_H_
36 #define _DRM_P_H_
37 
38 #if defined(_KERNEL) || defined(__KERNEL__)
39 
40 #include <sys/param.h>
41 #include <sys/queue.h>
42 #include <sys/malloc.h>
43 #include <sys/kernel.h>
44 #include <sys/ktr.h>
45 #include <sys/module.h>
46 #include <sys/systm.h>
47 #include <sys/device.h>
48 #include <sys/sglist.h>
49 #include <sys/stat.h>
50 #include <sys/priv.h>
51 #include <sys/proc.h>
52 #include <sys/lock.h>
53 #include <sys/spinlock.h>
54 #include <sys/spinlock2.h>
55 #include <sys/fcntl.h>
56 #include <sys/uio.h>
57 #include <sys/filio.h>
58 #include <sys/sysctl.h>
59 #include <sys/bus.h>
60 #include <sys/queue.h>
61 #include <sys/signalvar.h>
62 #include <sys/poll.h>
63 #include <sys/sbuf.h>
64 #include <sys/taskqueue.h>
65 #include <sys/tree.h>
66 #include <vm/vm.h>
67 #include <vm/pmap.h>
68 #include <vm/vm_extern.h>
69 #include <vm/vm_kern.h>
70 #include <vm/vm_map.h>
71 #include <vm/vm_object.h>
72 #include <vm/vm_page2.h>
73 #include <vm/vm_pager.h>
74 #include <vm/vm_param.h>
75 #include <machine/param.h>
76 #include <machine/pmap.h>
77 #ifdef __x86_64__
78 #include <machine/specialreg.h>
79 #endif
80 #include <machine/sysarch.h>
81 #include <sys/endian.h>
82 #include <sys/mman.h>
83 #include <sys/rman.h>
84 #include <sys/memrange.h>
85 #include <dev/agp/agpvar.h>
86 #include <sys/agpio.h>
87 #include <sys/mutex.h>
88 
89 MALLOC_DECLARE(M_DRM);
90 
91 #include <uapi_drm/drm.h>
92 #include <uapi_drm/drm_sarea.h>
93 
94 #include <linux/atomic.h>
95 #include <linux/bug.h>
96 #include <linux/capability.h>
97 #include <linux/err.h>
98 #include <linux/idr.h>
99 #include <linux/pci.h>
100 #include <linux/jiffies.h>
101 #include <linux/kernel.h>
102 #include <linux/kref.h>
103 #include <linux/list.h>
104 #include <linux/mm.h>
105 #include <linux/moduleparam.h>
106 #include <linux/mutex.h>
107 #include <linux/slab.h>
108 #include <linux/scatterlist.h>
109 #include <linux/timer.h>
110 #include <asm/io.h>
111 #include <linux/seq_file.h>
112 #include <linux/types.h>
113 #include <linux/wait.h>
114 #include <linux/workqueue.h>
115 
116 #include <asm/uaccess.h>
117 
118 #include <drm/drm_vma_manager.h>
119 
120 struct drm_file;
121 struct drm_device;
122 
123 struct device_node;
124 struct videomode;
125 
126 #include <drm/drm_os_linux.h>
127 #include <drm/drm_hashtab.h>
128 #include <drm/drm_mm.h>
129 
130 /*
131  * 4 debug categories are defined:
132  *
133  * CORE: Used in the generic drm code: drm_ioctl.c, drm_mm.c, drm_memory.c, ...
134  *	 This is the category used by the DRM_DEBUG() macro.
135  *
136  * DRIVER: Used in the vendor specific part of the driver: i915, radeon, ...
137  *	   This is the category used by the DRM_DEBUG_DRIVER() macro.
138  *
139  * KMS: used in the modesetting code.
140  *	This is the category used by the DRM_DEBUG_KMS() macro.
141  *
142  * PRIME: used in the prime code.
143  *	  This is the category used by the DRM_DEBUG_PRIME() macro.
144  *
145  * Enabling verbose debug messages is done through the drm.debug parameter,
146  * each category being enabled by a bit.
147  *
148  * drm.debug=0x1 will enable CORE messages
149  * drm.debug=0x2 will enable DRIVER messages
150  * drm.debug=0x3 will enable CORE and DRIVER messages
151  * ...
152  * drm.debug=0xf will enable all messages
153  *
154  * An interesting feature is that it's possible to enable verbose logging at
155  * run-time by echoing the debug value in its sysfs node:
156  *   # echo 0xf > /sys/module/drm/parameters/debug
157  */
158 #define DRM_UT_CORE 		0x01
159 #define DRM_UT_DRIVER		0x02
160 #define DRM_UT_KMS		0x04
161 #define DRM_UT_PRIME		0x08
162 
163 #ifdef DRM_DEBUG
164 #  if DRM_DEBUG>1
165 #    define DRM_DEBUG_DEFAULT_ON 2
166 #  else
167 #    define DRM_DEBUG_DEFAULT_ON 1
168 #  endif
169 #undef DRM_DEBUG
170 #endif /* DRM_DEBUG */
171 
172 #define	DRM_DEBUGBITS_DEBUG		0x1
173 #define	DRM_DEBUGBITS_KMS		0x2
174 #define	DRM_DEBUGBITS_FAILED_IOCTL	0x4
175 #define	DRM_DEBUGBITS_VERBOSE		0x8
176 
177 void drm_ut_debug_printk(unsigned int request_level,
178 			 const char *prefix,
179 			 const char *function_name,
180 			 const char *format, ...);
181 
182 int drm_err(const char *func, const char *format, ...);
183 
184 /***********************************************************************/
185 /** \name DRM template customization defaults */
186 /*@{*/
187 
188 /* driver capabilities and requirements mask */
189 #define DRIVER_USE_AGP     0x1
190 #define DRIVER_REQUIRE_AGP 0x2
191 #define DRIVER_PCI_DMA     0x8
192 #define DRIVER_SG          0x10
193 #define DRIVER_HAVE_DMA    0x20
194 #define DRIVER_HAVE_IRQ    0x40
195 #define DRIVER_IRQ_SHARED  0x80
196 #define DRIVER_DMA_QUEUE   0x200
197 #define DRIVER_GEM         0x1000
198 #define DRIVER_MODESET     0x2000
199 #define DRIVER_PRIME       0x4000
200 #define DRIVER_RENDER      0x8000
201 
202 /***********************************************************************/
203 /** \name Begin the DRM... */
204 /*@{*/
205 
206 #define DRM_DEBUG_CODE 2	  /**< Include debugging code if > 1, then
207 				     also include looping detection. */
208 
209 #define DRM_MAGIC_HASH_ORDER  4  /**< Size of key hash table. Must be power of 2. */
210 #define DRM_KERNEL_CONTEXT    0	 /**< Change drm_resctx if changed */
211 #define DRM_RESERVED_CONTEXTS 1	 /**< Change drm_resctx if changed */
212 
213 #define DRM_MAP_HASH_OFFSET 0x10000000
214 
215 #define	DRM_GEM_MAPPING_MASK	(3ULL << 62)
216 #define	DRM_GEM_MAPPING_KEY	(2ULL << 62) /* Non-canonical address form */
217 #define	DRM_GEM_MAX_IDX		0x3fffff
218 #define	DRM_GEM_MAPPING_IDX(o)	(((o) >> 40) & DRM_GEM_MAX_IDX)
219 #define	DRM_GEM_MAPPING_OFF(i)	(((uint64_t)(i)) << 40)
220 #define	DRM_GEM_MAPPING_MAPOFF(o) \
221     ((o) & ~(DRM_GEM_MAPPING_OFF(DRM_GEM_MAX_IDX) | DRM_GEM_MAPPING_KEY))
222 
223 SYSCTL_DECL(_hw_drm);
224 
225 #define DRM_MAX(a,b) ((a)>(b)?(a):(b))
226 
227 #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
228 
229 #define __OS_HAS_AGP	1
230 
231 #define DRM_DEV_MODE	(S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
232 #define DRM_DEV_UID	0
233 #define DRM_DEV_GID	0
234 
235 #define DRM_CURPROC		curthread
236 #define DRM_STRUCTPROC		struct thread
237 #define DRM_CURRENTPID		(curproc != NULL ? curproc->p_pid : -1)
238 #define DRM_LOCK(dev)		lockmgr(&(dev)->struct_mutex, LK_EXCLUSIVE)
239 #define DRM_UNLOCK(dev)		lockmgr(&(dev)->struct_mutex, LK_RELEASE)
240 #define	DRM_LOCK_SLEEP(dev, chan, flags, msg, timeout)			\
241     (lksleep((chan), &(dev)->struct_mutex, (flags), (msg), (timeout)))
242 #if defined(INVARIANTS)
243 #define	DRM_LOCK_ASSERT(dev)	KKASSERT(lockstatus(&(dev)->struct_mutex, curthread) != 0);
244 #define	DRM_UNLOCK_ASSERT(dev)	KKASSERT(lockstatus(&(dev)->struct_mutex, curthread) == 0);
245 #else
246 #define	DRM_LOCK_ASSERT(d)
247 #define	DRM_UNLOCK_ASSERT(d)
248 #endif
249 
250 #define DRM_SYSCTL_HANDLER_ARGS	(SYSCTL_HANDLER_ARGS)
251 
252 typedef void			irqreturn_t;
253 #define IRQ_HANDLED		/* nothing */
254 #define IRQ_NONE		/* nothing */
255 
256 enum {
257 	DRM_IS_NOT_AGP,
258 	DRM_IS_AGP,
259 	DRM_MIGHT_BE_AGP
260 };
261 #define DRM_AGP_MEM		struct agp_memory_info
262 
263 #define drm_get_device_from_kdev(_kdev) (_kdev->si_drv1)
264 
265 #define DRM_AGP_FIND_DEVICE()	agp_find_device()
266 #define DRM_MTRR_WC		MDF_WRITECOMBINE
267 
268 #define LOCK_TEST_WITH_RETURN(dev, file_priv)				\
269 do {									\
270 	if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) ||		\
271 	     dev->lock.file_priv != file_priv) {			\
272 		DRM_ERROR("%s called without lock held\n",		\
273 			   __FUNCTION__);				\
274 		return EINVAL;						\
275 	}								\
276 } while (0)
277 
278 /* Returns -errno to shared code */
279 #define DRM_WAIT_ON( ret, queue, timeout, condition )		\
280 for ( ret = 0 ; !ret && !(condition) ; ) {			\
281 	DRM_UNLOCK(dev);					\
282 	lwkt_serialize_enter(&dev->irq_lock);			\
283 	if (!(condition)) {					\
284             tsleep_interlock(&(queue), PCATCH);			\
285             lwkt_serialize_exit(&dev->irq_lock);		\
286             ret = -tsleep(&(queue), PCATCH | PINTERLOCKED,	\
287 			  "drmwtq", (timeout));			\
288         } else {                                                \
289                 lwkt_serialize_exit(&dev->irq_lock);            \
290         }                                                 	\
291 	DRM_LOCK(dev);						\
292 }
293 
294 int vm_phys_fictitious_reg_range(vm_paddr_t start, vm_paddr_t end,
295     vm_memattr_t memattr);
296 void vm_phys_fictitious_unreg_range(vm_paddr_t start, vm_paddr_t end);
297 vm_page_t vm_phys_fictitious_to_vm_page(vm_paddr_t pa);
298 
299 /***********************************************************************/
300 /** \name Macros to make printk easier */
301 /*@{*/
302 
303 /**
304  * Error output.
305  *
306  * \param fmt printf() like format string.
307  * \param arg arguments
308  */
309 #define DRM_ERROR(fmt, ...) \
310 	kprintf("error: [" DRM_NAME ":pid%d:%s] *ERROR* " fmt,		\
311 	    DRM_CURRENTPID, __func__ , ##__VA_ARGS__)
312 
313 #define DRM_INFO(fmt, ...)  kprintf("info: [" DRM_NAME "] " fmt , ##__VA_ARGS__)
314 
315 #define DRM_INFO_ONCE(fmt, ...)				\
316 	printk_once(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
317 
318 #define DRM_DEBUG(fmt, ...) do {					\
319 	if ((drm_debug & DRM_DEBUGBITS_DEBUG) != 0)		\
320 		kprintf("[" DRM_NAME ":pid%d:%s] " fmt, DRM_CURRENTPID,	\
321 			__func__ , ##__VA_ARGS__);			\
322 } while (0)
323 
324 #define DRM_DEBUG_VERBOSE(fmt, ...) do {				\
325 	if ((drm_debug & DRM_DEBUGBITS_VERBOSE) != 0)		\
326 		kprintf("[" DRM_NAME ":pid%d:%s] " fmt, DRM_CURRENTPID,	\
327 			__func__ , ##__VA_ARGS__);			\
328 } while (0)
329 
330 #define DRM_DEBUG_KMS(fmt, ...) do {					\
331 	if ((drm_debug & DRM_DEBUGBITS_KMS) != 0)			\
332 		kprintf("[" DRM_NAME ":KMS:pid%d:%s] " fmt, DRM_CURRENTPID,\
333 			__func__ , ##__VA_ARGS__);			\
334 } while (0)
335 
336 #define DRM_DEBUG_DRIVER(fmt, ...) do {					\
337 	if ((drm_debug & DRM_DEBUGBITS_KMS) != 0)			\
338 		kprintf("[" DRM_NAME ":KMS:pid%d:%s] " fmt, DRM_CURRENTPID,\
339 			__func__ , ##__VA_ARGS__);			\
340 } while (0)
341 
342 #define DRM_LOG_KMS(fmt, ...) do {					\
343 	kprintf("[" DRM_NAME ":KMS:pid%d:%s] " fmt, DRM_CURRENTPID,	\
344 			__func__ , ##__VA_ARGS__);			\
345 } while (0)
346 
347 #define	dev_dbg(dev, fmt, ...) do {					\
348 	if ((drm_debug& DRM_DEBUGBITS_KMS) != 0) {			\
349 		device_printf((dev), "debug: " fmt, ## __VA_ARGS__);	\
350 	}								\
351 } while (0)
352 
353 typedef struct drm_pci_id_list
354 {
355 	int vendor;
356 	int device;
357 	long driver_private;
358 	char *name;
359 } drm_pci_id_list_t;
360 
361 struct drm_msi_blacklist_entry
362 {
363 	int vendor;
364 	int device;
365 };
366 
367 /**
368  * Ioctl function type.
369  *
370  * \param inode device inode.
371  * \param file_priv DRM file private pointer.
372  * \param cmd command.
373  * \param arg argument.
374  */
375 typedef int drm_ioctl_t(struct drm_device *dev, void *data,
376 			struct drm_file *file_priv);
377 
378 typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
379 			       unsigned long arg);
380 
381 #define DRM_IOCTL_NR(n)                ((n) & 0xff)
382 
383 #define DRM_AUTH	0x1
384 #define DRM_MASTER	0x2
385 #define DRM_ROOT_ONLY	0x4
386 #define DRM_CONTROL_ALLOW 0x8
387 #define DRM_UNLOCKED	0x10
388 #define DRM_RENDER_ALLOW 0x20
389 
390 struct drm_ioctl_desc {
391 	unsigned int cmd;
392 	int flags;
393 	drm_ioctl_t *func;
394 	unsigned int cmd_drv;
395 	const char *name;
396 };
397 
398 /**
399  * Creates a driver or general drm_ioctl_desc array entry for the given
400  * ioctl, for use by drm_ioctl().
401  */
402 #define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags)			\
403 	[DRM_IOCTL_NR(DRM_##ioctl)] = {.cmd = DRM_##ioctl, .func = _func, .flags = _flags, .cmd_drv = DRM_IOCTL_##ioctl}
404 
405 typedef struct drm_magic_entry {
406 	struct list_head head;
407 	struct drm_hash_item hash_item;
408 	struct drm_file	       *priv;
409 	struct drm_magic_entry *next;
410 } drm_magic_entry_t;
411 
412 typedef struct drm_magic_head {
413 	struct drm_magic_entry *head;
414 	struct drm_magic_entry *tail;
415 } drm_magic_head_t;
416 
417 typedef struct drm_buf {
418 	int idx;		       /**< Index into master buflist */
419 	int total;		       /**< Buffer size */
420 	int order;		       /**< log-base-2(total) */
421 	int used;		       /**< Amount of buffer in use (for DMA) */
422 	unsigned long offset;	       /**< Byte offset (used internally) */
423 	void *address;		       /**< Address of buffer */
424 	unsigned long bus_address;     /**< Bus address of buffer */
425 	struct drm_buf *next;	       /**< Kernel-only: used for free list */
426 	__volatile__ int waiting;      /**< On kernel DMA queue */
427 	__volatile__ int pending;      /**< On hardware DMA queue */
428 	struct drm_file *file_priv;    /**< Private of holding file descr */
429 	int context;		       /**< Kernel queue for this buffer */
430 	int while_locked;	       /**< Dispatch this buffer while locked */
431 	enum {
432 		DRM_LIST_NONE = 0,
433 		DRM_LIST_FREE = 1,
434 		DRM_LIST_WAIT = 2,
435 		DRM_LIST_PEND = 3,
436 		DRM_LIST_PRIO = 4,
437 		DRM_LIST_RECLAIM = 5
438 	} list;			       /**< Which list we're on */
439 
440 	int dev_priv_size;		 /**< Size of buffer private storage */
441 	void *dev_private;		 /**< Per-buffer private storage */
442 } drm_buf_t;
443 
444 /** bufs is one longer than it has to be */
445 struct drm_waitlist {
446 	int count;			/**< Number of possible buffers */
447 	struct drm_buf **bufs;		/**< List of pointers to buffers */
448 	struct drm_buf **rp;			/**< Read pointer */
449 	struct drm_buf **wp;			/**< Write pointer */
450 	struct drm_buf **end;		/**< End pointer */
451 	spinlock_t read_lock;
452 	spinlock_t write_lock;
453 };
454 
455 struct drm_freelist {
456 	int		  initialized; /* Freelist in use		   */
457 	atomic_t	  count;       /* Number of free buffers	   */
458 	drm_buf_t	  *next;       /* End pointer			   */
459 
460 	wait_queue_head_t waiting;     /**< Processes waiting on free bufs */
461 	int		  low_mark;    /* Low water mark		   */
462 	int		  high_mark;   /* High water mark		   */
463 };
464 
465 typedef struct drm_dma_handle {
466 	void *vaddr;
467 	size_t size;
468 	bus_addr_t busaddr;
469 	bus_dma_tag_t tag;
470 	bus_dmamap_t map;
471 } drm_dma_handle_t;
472 
473 typedef struct drm_buf_entry {
474 	int		  buf_size;
475 	int		  buf_count;
476 	drm_buf_t	  *buflist;
477 	int		  seg_count;
478 	drm_dma_handle_t  **seglist;
479 	int		  page_order;
480 
481 	struct drm_freelist freelist;
482 } drm_buf_entry_t;
483 
484 /* Event queued up for userspace to read */
485 struct drm_pending_event {
486 	struct drm_event *event;
487 	struct list_head link;
488 	struct drm_file *file_priv;
489 	pid_t pid; /* pid of requester, no guarantee it's valid by the time
490 		      we deliver the event, for tracing only */
491 	void (*destroy)(struct drm_pending_event *event);
492 };
493 
494 /* initial implementaton using a linked list - todo hashtab */
495 struct drm_prime_file_private {
496 	struct list_head head;
497 #ifdef DUMBBELL_WIP
498 	struct mutex lock;
499 #endif /* DUMBBELL_WIP */
500 };
501 
502 /** File private data */
503 struct drm_file {
504 	int authenticated;
505 	struct drm_device *dev;
506 	int		  master;
507 
508 	/* true when the client has asked us to expose stereo 3D mode flags */
509 	bool stereo_allowed;
510 	/*
511 	 * true if client understands CRTC primary planes and cursor planes
512 	 * in the plane list
513 	 */
514 	unsigned universal_planes:1;
515 
516 	pid_t		  pid;
517 	uid_t		  uid;
518 	drm_magic_t	  magic;
519 	unsigned long	  ioctl_count;
520 	struct list_head lhead;
521 	struct kqinfo	  dkq;
522 
523 	/** Mapping of mm object handles to object pointers. */
524 	struct idr object_idr;
525 	/** Lock for synchronization of access to object_idr. */
526 	struct lock table_lock;
527 
528 	void		 *driver_priv;
529 
530 	int		  is_master;
531 	struct drm_master *masterp;
532 
533 	/**
534 	 * fbs - List of framebuffers associated with this file.
535 	 *
536 	 * Protected by fbs_lock. Note that the fbs list holds a reference on
537 	 * the fb object to prevent it from untimely disappearing.
538 	 */
539 	struct list_head fbs;
540 	struct lock fbs_lock;
541 
542 	wait_queue_head_t event_wait;
543 	struct list_head  event_list;
544 	int		  event_space;
545 
546 	struct drm_prime_file_private prime;
547 };
548 
549 /** Wait queue */
550 struct drm_queue {
551 	atomic_t use_count;		/**< Outstanding uses (+1) */
552 	atomic_t finalization;		/**< Finalization in progress */
553 	atomic_t block_count;		/**< Count of processes waiting */
554 	atomic_t block_read;		/**< Queue blocked for reads */
555 	wait_queue_head_t read_queue;	/**< Processes waiting on block_read */
556 	atomic_t block_write;		/**< Queue blocked for writes */
557 	wait_queue_head_t write_queue;	/**< Processes waiting on block_write */
558 	atomic_t total_queued;		/**< Total queued statistic */
559 	atomic_t total_flushed;		/**< Total flushes statistic */
560 	atomic_t total_locks;		/**< Total locks statistics */
561 	enum drm_ctx_flags flags;	/**< Context preserving and 2D-only */
562 	struct drm_waitlist waitlist;	/**< Pending buffers */
563 	wait_queue_head_t flush_queue;	/**< Processes waiting until flush */
564 };
565 
566 /**
567  * Lock data.
568  */
569 struct drm_lock_data {
570 	struct drm_hw_lock *hw_lock;	/**< Hardware lock */
571 	/** Private of lock holder's file (NULL=kernel) */
572 	struct drm_file *file_priv;
573 	wait_queue_head_t lock_queue;	/**< Queue of blocked processes */
574 	unsigned long lock_time;	/**< Time of last lock in jiffies */
575 };
576 
577 /* This structure, in the struct drm_device, is always initialized while the
578  * device
579  * is open.  dev->dma_lock protects the incrementing of dev->buf_use, which
580  * when set marks that no further bufs may be allocated until device teardown
581  * occurs (when the last open of the device has closed).  The high/low
582  * watermarks of bufs are only touched by the X Server, and thus not
583  * concurrently accessed, so no locking is needed.
584  */
585 typedef struct drm_device_dma {
586 
587 	struct drm_buf_entry bufs[DRM_MAX_ORDER + 1];	/**< buffers, grouped by their size order */
588 	int buf_count;			/**< total number of buffers */
589 	struct drm_buf **buflist;		/**< Vector of pointers into drm_device_dma::bufs */
590 	int seg_count;
591 	int page_count;			/**< number of pages */
592 	unsigned long *pagelist;	/**< page list */
593 	unsigned long byte_count;
594 	enum {
595 		_DRM_DMA_USE_AGP = 0x01,
596 		_DRM_DMA_USE_SG = 0x02,
597 		_DRM_DMA_USE_FB = 0x04,
598 		_DRM_DMA_USE_PCI_RO = 0x08
599 	} flags;
600 
601 } drm_device_dma_t;
602 
603 typedef struct drm_agp_mem {
604 	void               *handle;
605 	unsigned long      bound; /* address */
606 	int                pages;
607 	struct drm_agp_mem *prev;
608 	struct drm_agp_mem *next;
609 } drm_agp_mem_t;
610 
611 typedef struct drm_agp_head {
612 	device_t	   agpdev;
613 	struct agp_info    agp_info;
614 	const char         *chipset;
615 	drm_agp_mem_t      *memory;
616 	unsigned long      mode;
617 	int                enabled;
618 	int                acquired;
619 	unsigned long      base;
620 	int		   agp_mtrr;
621 	int		   cant_use_aperture;
622 	unsigned long	   page_mask;
623 } drm_agp_head_t;
624 
625 typedef struct drm_sg_mem {
626 	vm_offset_t vaddr;
627 	vm_paddr_t *busaddr;
628 	vm_pindex_t pages;
629 } drm_sg_mem_t;
630 
631 /**
632  * Kernel side of a mapping
633  */
634 struct drm_local_map {
635 	resource_size_t offset;	 /**< Requested physical address (0 for SAREA)*/
636 	unsigned long size;	 /**< Requested physical size (bytes) */
637 	enum drm_map_type type;	 /**< Type of memory to map */
638 	enum drm_map_flags flags;	 /**< Flags */
639 	void *handle;		 /**< User-space: "Handle" to pass to mmap() */
640 				 /**< Kernel-space: kernel-virtual address */
641 	int mtrr;		 /**< MTRR slot used */
642 };
643 
644 typedef struct drm_local_map drm_local_map_t;
645 
646 /**
647  * Mappings list
648  */
649 struct drm_map_list {
650 	struct list_head head;		/**< list head */
651 	struct drm_hash_item hash;
652 	struct drm_local_map *map;	/**< mapping */
653 	uint64_t user_token;
654 	struct drm_master *master;
655 	struct drm_mm_node *file_offset_node;	/**< fake offset */
656 };
657 
658 /**
659  * Context handle list
660  */
661 struct drm_ctx_list {
662 	struct list_head head;		/**< list head */
663 	drm_context_t handle;		/**< context handle */
664 	struct drm_file *tag;		/**< associated fd private data */
665 };
666 
667 /* location of GART table */
668 #define DRM_ATI_GART_MAIN 1
669 #define DRM_ATI_GART_FB   2
670 
671 #define DRM_ATI_GART_PCI 1
672 #define DRM_ATI_GART_PCIE 2
673 #define DRM_ATI_GART_IGP 3
674 
675 struct drm_ati_pcigart_info {
676 	int gart_table_location;
677 	int gart_reg_if;
678 	void *addr;
679 	dma_addr_t bus_addr;
680 	dma_addr_t table_mask;
681 	dma_addr_t member_mask;
682 	struct drm_dma_handle *table_handle;
683 	drm_local_map_t mapping;
684 	int table_size;
685 	struct drm_dma_handle *dmah; /* handle for ATI PCIGART table */
686 };
687 
688 /**
689  * GEM specific mm private for tracking GEM objects
690  */
691 struct drm_gem_mm {
692 	struct drm_vma_offset_manager vma_manager;
693 	struct drm_mm offset_manager;	/**< Offset mgmt for buffer objects */
694 	struct drm_open_hash offset_hash; /**< User token hash table for maps */
695 	struct unrhdr *idxunr;
696 };
697 
698 struct drm_gem_object {
699 	/** Reference count of this object */
700 	struct kref refcount;
701 
702 	/**
703 	 * handle_count - gem file_priv handle count of this object
704 	 *
705 	 * Each handle also holds a reference. Note that when the handle_count
706 	 * drops to 0 any global names (e.g. the id in the flink namespace) will
707 	 * be cleared.
708 	 *
709 	 * Protected by dev->object_name_lock.
710 	 * */
711 	unsigned handle_count;
712 
713 	/** Related drm device */
714 	struct drm_device *dev;
715 
716 	/** File representing the shmem storage: filp in Linux parlance */
717 	vm_object_t vm_obj;
718 
719 	/* Mapping info for this object */
720 	struct drm_vma_offset_node vma_node;
721 	bool on_map;
722 	struct drm_hash_item map_list;
723 
724 	/**
725 	 * Size of the object, in bytes.  Immutable over the object's
726 	 * lifetime.
727 	 */
728 	size_t size;
729 
730 	/**
731 	 * Global name for this object, starts at 1. 0 means unnamed.
732 	 * Access is covered by the object_name_lock in the related drm_device
733 	 */
734 	int name;
735 
736 	/**
737 	 * Memory domains. These monitor which caches contain read/write data
738 	 * related to the object. When transitioning from one set of domains
739 	 * to another, the driver is called to ensure that caches are suitably
740 	 * flushed and invalidated
741 	 */
742 	uint32_t read_domains;
743 	uint32_t write_domain;
744 
745 	/**
746 	 * While validating an exec operation, the
747 	 * new read/write domain values are computed here.
748 	 * They will be transferred to the above values
749 	 * at the point that any cache flushing occurs
750 	 */
751 	uint32_t pending_read_domains;
752 	uint32_t pending_write_domain;
753 
754 #ifdef DUMBBELL_WIP
755 	/* dma buf exported from this GEM object */
756 	struct dma_buf *export_dma_buf;
757 
758 	/* dma buf attachment backing this object */
759 	struct dma_buf_attachment *import_attach;
760 #endif /* DUMBBELL_WIP */
761 };
762 
763 #include "drm_crtc.h"
764 
765 /**
766  * struct drm_master - drm master structure
767  *
768  * @refcount: Refcount for this master object.
769  * @minor: Link back to minor char device we are master for. Immutable.
770  * @unique: Unique identifier: e.g. busid. Protected by drm_global_mutex.
771  * @unique_len: Length of unique field. Protected by drm_global_mutex.
772  * @unique_size: Amount allocated. Protected by drm_global_mutex.
773  * @magiclist: Hash of used authentication tokens. Protected by struct_mutex.
774  * @magicfree: List of used authentication tokens. Protected by struct_mutex.
775  * @lock: DRI lock information.
776  * @driver_priv: Pointer to driver-private information.
777  */
778 struct drm_master {
779 
780 	struct kref refcount; /* refcount for this master */
781 
782 	struct list_head head; /**< each minor contains a list of masters */
783 	struct drm_minor *minor; /**< link back to minor we are a master for */
784 
785 	char *unique;			/**< Unique identifier: e.g., busid */
786 	int unique_len;			/**< Length of unique field */
787 	int unique_size;		/**< amount allocated */
788 
789 	int blocked;			/**< Blocked due to VC switch? */
790 
791 	struct drm_open_hash magiclist;
792 	struct list_head magicfree;
793 	struct drm_lock_data lock;
794 	void *driver_priv;
795 };
796 
797 /* Size of ringbuffer for vblank timestamps. Just double-buffer
798  * in initial implementation.
799  */
800 #define DRM_VBLANKTIME_RBSIZE 2
801 
802 /* Flags and return codes for get_vblank_timestamp() driver function. */
803 #define DRM_CALLED_FROM_VBLIRQ 1
804 #define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
805 #define DRM_VBLANKTIME_INVBL             (1 << 1)
806 
807 /* get_scanout_position() return flags */
808 #define DRM_SCANOUTPOS_VALID        (1 << 0)
809 #define DRM_SCANOUTPOS_INVBL        (1 << 1)
810 #define DRM_SCANOUTPOS_ACCURATE     (1 << 2)
811 
812 #ifndef DMA_BIT_MASK
813 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : (1ULL<<(n)) - 1)
814 #endif
815 
816 #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
817 
818 /**
819  * DRM driver structure. This structure represent the common code for
820  * a family of cards. There will one drm_device for each card present
821  * in this family
822  */
823 struct drm_driver {
824 	int	(*load)(struct drm_device *, unsigned long flags);
825 	int	(*use_msi)(struct drm_device *, unsigned long flags);
826 	int	(*firstopen)(struct drm_device *);
827 	int	(*open)(struct drm_device *, struct drm_file *);
828 	void	(*preclose)(struct drm_device *, struct drm_file *file_priv);
829 	void	(*postclose)(struct drm_device *, struct drm_file *);
830 	void	(*lastclose)(struct drm_device *);
831 	int	(*unload)(struct drm_device *);
832 	void	(*reclaim_buffers_locked)(struct drm_device *,
833 					  struct drm_file *file_priv);
834 	int	(*dma_ioctl)(struct drm_device *dev, void *data,
835 			     struct drm_file *file_priv);
836 	void	(*dma_ready)(struct drm_device *);
837 	int	(*dma_quiescent)(struct drm_device *);
838 	int	(*dma_flush_block_and_flush)(struct drm_device *, int context,
839 					     enum drm_lock_flags flags);
840 	int	(*dma_flush_unblock)(struct drm_device *, int context,
841 				     enum drm_lock_flags flags);
842 	int	(*context_ctor)(struct drm_device *dev, int context);
843 	int	(*context_dtor)(struct drm_device *dev, int context);
844 	int	(*kernel_context_switch)(struct drm_device *dev, int old,
845 					 int new);
846 	int	(*kernel_context_switch_unlock)(struct drm_device *dev);
847 	void	(*irq_preinstall)(struct drm_device *dev);
848 	int	(*irq_postinstall)(struct drm_device *dev);
849 	void	(*irq_uninstall)(struct drm_device *dev);
850 	void	(*irq_handler)(void *arg);
851 
852 	u32	(*get_vblank_counter)(struct drm_device *dev, int crtc);
853 	int	(*enable_vblank)(struct drm_device *dev, int crtc);
854 	void	(*disable_vblank)(struct drm_device *dev, int crtc);
855 
856 	/**
857 	 * Called by vblank timestamping code.
858 	 *
859 	 * Return the current display scanout position from a crtc, and an
860 	 * optional accurate ktime_get timestamp of when position was measured.
861 	 *
862 	 * \param dev  DRM device.
863 	 * \param crtc Id of the crtc to query.
864 	 * \param flags Flags from the caller (DRM_CALLED_FROM_VBLIRQ or 0).
865 	 * \param *vpos Target location for current vertical scanout position.
866 	 * \param *hpos Target location for current horizontal scanout position.
867 	 * \param *stime Target location for timestamp taken immediately before
868 	 *               scanout position query. Can be NULL to skip timestamp.
869 	 * \param *etime Target location for timestamp taken immediately after
870 	 *               scanout position query. Can be NULL to skip timestamp.
871 	 *
872 	 * Returns vpos as a positive number while in active scanout area.
873 	 * Returns vpos as a negative number inside vblank, counting the number
874 	 * of scanlines to go until end of vblank, e.g., -1 means "one scanline
875 	 * until start of active scanout / end of vblank."
876 	 *
877 	 * \return Flags, or'ed together as follows:
878 	 *
879 	 * DRM_SCANOUTPOS_VALID = Query successful.
880 	 * DRM_SCANOUTPOS_INVBL = Inside vblank.
881 	 * DRM_SCANOUTPOS_ACCURATE = Returned position is accurate. A lack of
882 	 * this flag means that returned position may be offset by a constant
883 	 * but unknown small number of scanlines wrt. real scanout position.
884 	 *
885 	 */
886 	int (*get_scanout_position) (struct drm_device *dev, int crtc,
887 				     unsigned int flags,
888 				     int *vpos, int *hpos, ktime_t *stime,
889 				     ktime_t *etime);
890 
891 	int	(*get_vblank_timestamp)(struct drm_device *dev, int crtc,
892 		    int *max_error, struct timeval *vblank_time,
893 		    unsigned flags);
894 
895 	void	(*gem_free_object)(struct drm_gem_object *obj);
896 	int	(*gem_open_object)(struct drm_gem_object *, struct drm_file *);
897 	void	(*gem_close_object)(struct drm_gem_object *, struct drm_file *);
898 
899 	struct cdev_pager_ops *gem_pager_ops;
900 
901 	int	(*dumb_create)(struct drm_file *file_priv,
902 		    struct drm_device *dev, struct drm_mode_create_dumb *args);
903 	int	(*dumb_map_offset)(struct drm_file *file_priv,
904 		    struct drm_device *dev, uint32_t handle, uint64_t *offset);
905 	int	(*dumb_destroy)(struct drm_file *file_priv,
906 		    struct drm_device *dev, uint32_t handle);
907 
908 	int	(*sysctl_init)(struct drm_device *dev,
909 		    struct sysctl_ctx_list *ctx, struct sysctl_oid *top);
910 	void	(*sysctl_cleanup)(struct drm_device *dev);
911 
912 	drm_pci_id_list_t *id_entry;	/* PCI ID, name, and chipset private */
913 
914 	/**
915 	 * Called by \c drm_device_is_agp.  Typically used to determine if a
916 	 * card is really attached to AGP or not.
917 	 *
918 	 * \param dev  DRM device handle
919 	 *
920 	 * \returns
921 	 * One of three values is returned depending on whether or not the
922 	 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
923 	 * (return of 1), or may or may not be AGP (return of 2).
924 	 */
925 	int	(*device_is_agp) (struct drm_device * dev);
926 
927 	int	major;
928 	int	minor;
929 	int	patchlevel;
930 	const char *name;		/* Simple driver name		   */
931 	const char *desc;		/* Longer driver name		   */
932 	const char *date;		/* Date of last major changes.	   */
933 
934 	u32 driver_features;
935 	int dev_priv_size;
936 	const struct drm_ioctl_desc *ioctls;
937 	int num_ioctls;
938 };
939 
940 /**
941  * Info file list entry. This structure represents a debugfs or proc file to
942  * be created by the drm core
943  */
944 struct drm_info_list {
945 	const char *name; /** file name */
946 	int (*show)(struct seq_file*, void*); /** show callback */
947 	u32 driver_features; /**< Required driver features for this entry */
948 	void *data;
949 };
950 
951 /**
952  * debugfs node structure. This structure represents a debugfs file.
953  */
954 struct drm_info_node {
955 	struct list_head list;
956 	struct drm_minor *minor;
957 	const struct drm_info_list *info_ent;
958 	struct dentry *dent;
959 };
960 
961 /**
962  * DRM minor structure. This structure represents a drm minor number.
963  */
964 struct drm_minor {
965 	int index;			/**< Minor device number */
966 	int type;                       /**< Control or render */
967 	device_t kdev;			/**< OS device */
968 	struct drm_device *dev;
969 
970 	struct drm_master *master; /* currently active master for this node */
971 	struct list_head master_list;
972 	struct drm_mode_group mode_group;
973 };
974 
975 struct drm_pending_vblank_event {
976 	struct drm_pending_event base;
977 	int pipe;
978 	struct drm_event_vblank event;
979 };
980 
981 struct drm_sysctl_info {
982 	struct sysctl_ctx_list ctx;
983 	char   name[2];
984 };
985 
986 /* Length for the array of resource pointers for drm_get_resource_*. */
987 #define DRM_MAX_PCI_RESOURCE	6
988 
989 struct drm_vblank_crtc {
990 	struct drm_device *dev;		/* pointer to the drm_device */
991 	wait_queue_head_t queue;	/**< VBLANK wait queue */
992 	struct timeval time[DRM_VBLANKTIME_RBSIZE];	/**< timestamp of current count */
993 	struct timer_list disable_timer;		/* delayed disable timer */
994 	atomic_t count;			/**< number of VBLANK interrupts */
995 	atomic_t refcount;		/* number of users of vblank interruptsper crtc */
996 	u32 last;			/* protected by dev->vbl_lock, used */
997 					/* for wraparound handling */
998 	u32 last_wait;			/* Last vblank seqno waited per CRTC */
999 	unsigned int inmodeset;		/* Display driver is setting mode */
1000 	int crtc;			/* crtc index */
1001 	bool enabled;			/* so we don't call enable more than
1002 					   once per disable */
1003 };
1004 
1005 /**
1006  * DRM device structure. This structure represent a complete card that
1007  * may contain multiple heads.
1008  */
1009 struct drm_device {
1010 	drm_pci_id_list_t *id_entry;	/* PCI ID, name, and chipset private */
1011 
1012 	uint16_t pci_subdevice;		/* PCI subsystem device id */
1013 	uint16_t pci_subvendor;		/* PCI subsystem vendor id */
1014 
1015 	char		  *unique;	/* Unique identifier: e.g., busid  */
1016 	int		  unique_len;	/* Length of unique field	   */
1017 	struct cdev	  *devnode;	/* Device number for mknod	   */
1018 	int		  if_version;	/* Highest interface version set */
1019 
1020 	int		  flags;	/* Flags to open(2)		   */
1021 
1022 				/* Locks */
1023 	struct spinlock	  dma_lock;	/* protects dev->dma */
1024 	struct lwkt_serialize irq_lock;	/* protects irq condition checks */
1025 	struct lock	  dev_lock;	/* protects everything else */
1026 
1027 	/** \name Locks */
1028 	/*@{ */
1029 	struct lock struct_mutex;	/**< For others */
1030 	/*@} */
1031 
1032 	/** \name Usage Counters */
1033 	/*@{ */
1034 	int open_count;			/**< Outstanding files open, protected by drm_global_mutex. */
1035 	int		  buf_use;	/* Buffers in use -- cannot alloc  */
1036 	/*@} */
1037 
1038 
1039 	/** \name Performance counters */
1040 	/*@{ */
1041 	unsigned long     counters;
1042 	enum drm_stat_type	types[15];
1043 	atomic_t          counts[15];
1044 	/*@} */
1045 
1046 				/* Authentication */
1047 	struct drm_open_hash magiclist;	/**< magic hash table */
1048 	struct list_head magicfree;
1049 
1050 	struct list_head filelist;
1051 
1052 	/** \name Memory management */
1053 	/*@{ */
1054 	struct list_head maplist;	/**< Linked list of regions */
1055 	int map_count;			/**< Number of mappable regions */
1056 	struct drm_open_hash map_hash;	/**< User token hash table for maps */
1057 
1058 	/** \name Context handle management */
1059 	/*@{ */
1060 	struct list_head ctxlist;	/**< Linked list of context handles */
1061 	int ctx_count;			/**< Number of context handles */
1062 	struct lock ctxlist_mutex;	/**< For ctxlist */
1063 
1064 	struct idr ctx_idr;
1065 
1066 	/*@} */
1067 
1068 	struct drm_lock_data lock;	/* Information on hardware lock	   */
1069 
1070 				/* DMA queues (contexts) */
1071 	drm_device_dma_t  *dma;		/* Optional pointer for DMA support */
1072 
1073 	int		  irq;		/* Interrupt used by board	   */
1074 	int		  irq_type;	/* IRQ type (MSI enabled or not) */
1075 	int		  irqrid;	/* Interrupt used by board */
1076 	struct resource   *irqr;	/* Resource for interrupt used by board	   */
1077 	void		  *irqh;	/* Handle from bus_setup_intr      */
1078 
1079 	/* Storage of resource pointers for drm_get_resource_* */
1080 	struct resource   *pcir[DRM_MAX_PCI_RESOURCE];
1081 	int		  pcirid[DRM_MAX_PCI_RESOURCE];
1082 
1083 	int		  pci_domain;
1084 	int		  pci_bus;
1085 	int		  pci_slot;
1086 	int		  pci_func;
1087 
1088 	/** \name Context support */
1089 	/*@{ */
1090 	int irq_enabled;		/**< True if irq handler is enabled */
1091 	__volatile__ long context_flag;	/**< Context swapping flag */
1092 	__volatile__ long interrupt_flag; /**< Interruption handler flag */
1093 	__volatile__ long dma_flag;	/**< DMA dispatch flag */
1094 	wait_queue_head_t context_wait;	/**< Processes waiting on ctx switch */
1095 	int last_checked;		/**< Last context checked for DMA */
1096 	int last_context;		/**< Last current context */
1097 	unsigned long last_switch;	/**< jiffies at last context switch */
1098 	/*@} */
1099 
1100 	/** \name VBLANK IRQ support */
1101 	/*@{ */
1102 
1103 	/*
1104 	 * At load time, disabling the vblank interrupt won't be allowed since
1105 	 * old clients may not call the modeset ioctl and therefore misbehave.
1106 	 * Once the modeset ioctl *has* been called though, we can safely
1107 	 * disable them when unused.
1108 	 */
1109 	bool vblank_disable_allowed;
1110 
1111 	/* array of size num_crtcs */
1112 	struct drm_vblank_crtc *vblank;
1113 
1114 	struct lock vblank_time_lock;    /**< Protects vblank count and time updates during vblank enable/disable */
1115 	struct lock vbl_lock;
1116 	struct timer_list vblank_disable_timer;
1117 
1118 	u32 max_vblank_count;           /**< size of vblank counter register */
1119 
1120 	/**
1121 	 * List of events
1122 	 */
1123 	struct list_head vblank_event_list;
1124 	struct lock event_lock;
1125 
1126 	/*@} */
1127 
1128 	struct sigio      *buf_sigio;	/* Processes waiting for SIGIO     */
1129 
1130 				/* Sysctl support */
1131 	struct drm_sysctl_info *sysctl;
1132 	int		  sysctl_node_idx;
1133 
1134 
1135 	drm_sg_mem_t      *sg;  /* Scatter gather memory */
1136 	unsigned int num_crtcs;                  /**< Number of CRTCs on this device */
1137 
1138 	unsigned long     *ctx_bitmap;
1139 	void		  *dev_private;
1140 
1141 	void		  *drm_ttm_bdev;
1142 
1143 	/*@} */
1144 
1145 	struct drm_agp_head *agp;	/**< AGP data */
1146 
1147 	struct device *dev;             /**< Device structure */
1148 	struct pci_dev *pdev;		/**< PCI device structure */
1149 	int pci_vendor;			/**< PCI vendor id */
1150 	int pci_device;			/**< PCI device id */
1151 
1152 	struct drm_driver *driver;
1153 	struct drm_local_map *agp_buffer_map;
1154 	unsigned int agp_buffer_token;
1155 	struct drm_minor *control;		/**< Control node for card */
1156 	struct drm_minor *primary;		/**< render type primary screen head */
1157 
1158         struct drm_mode_config mode_config;	/**< Current mode config */
1159 
1160 	/** \name GEM information */
1161 	/*@{ */
1162 	struct lock object_name_lock;
1163 	struct idr object_name_idr;
1164 	/*@} */
1165 	void             *mm_private;
1166 
1167 	void *sysctl_private;
1168 	char busid_str[128];
1169 	int modesetting;
1170 
1171 	int switch_power_state;
1172 
1173 	atomic_t unplugged; /* device has been unplugged or gone away */
1174 };
1175 
1176 #define DRM_SWITCH_POWER_ON 0
1177 #define DRM_SWITCH_POWER_OFF 1
1178 #define DRM_SWITCH_POWER_CHANGING 2
1179 #define DRM_SWITCH_POWER_DYNAMIC_OFF 3
1180 
1181 static __inline__ int drm_core_check_feature(struct drm_device *dev,
1182 					     int feature)
1183 {
1184 	return ((dev->driver->driver_features & feature) ? 1 : 0);
1185 }
1186 
1187 static inline int drm_device_is_unplugged(struct drm_device *dev)
1188 {
1189 	int ret = atomic_read(&dev->unplugged);
1190 	smp_rmb();
1191 	return ret;
1192 }
1193 
1194 static inline bool drm_is_primary_client(const struct drm_file *file_priv)
1195 {
1196 	return 0 /* file_priv->minor->type == DRM_MINOR_LEGACY */;
1197 }
1198 
1199 #if __OS_HAS_AGP
1200 static inline int drm_core_has_AGP(struct drm_device *dev)
1201 {
1202 	return drm_core_check_feature(dev, DRIVER_USE_AGP);
1203 }
1204 #else
1205 #define drm_core_has_AGP(dev) (0)
1206 #endif
1207 
1208 enum dmi_field {
1209         DMI_NONE,
1210         DMI_BIOS_VENDOR,
1211         DMI_BIOS_VERSION,
1212         DMI_BIOS_DATE,
1213         DMI_SYS_VENDOR,
1214         DMI_PRODUCT_NAME,
1215         DMI_PRODUCT_VERSION,
1216         DMI_PRODUCT_SERIAL,
1217         DMI_PRODUCT_UUID,
1218         DMI_BOARD_VENDOR,
1219         DMI_BOARD_NAME,
1220         DMI_BOARD_VERSION,
1221         DMI_BOARD_SERIAL,
1222         DMI_BOARD_ASSET_TAG,
1223         DMI_CHASSIS_VENDOR,
1224         DMI_CHASSIS_TYPE,
1225         DMI_CHASSIS_VERSION,
1226         DMI_CHASSIS_SERIAL,
1227         DMI_CHASSIS_ASSET_TAG,
1228         DMI_STRING_MAX,
1229 };
1230 
1231 struct dmi_strmatch {
1232 	unsigned char slot;
1233 	char substr[79];
1234 };
1235 
1236 struct dmi_system_id {
1237         int (*callback)(const struct dmi_system_id *);
1238         const char *ident;
1239         struct dmi_strmatch matches[4];
1240 };
1241 #define	DMI_MATCH(a, b) {(a), (b)}
1242 bool dmi_check_system(const struct dmi_system_id *);
1243 
1244 extern int	drm_notyet_flag;
1245 extern unsigned int drm_debug;
1246 extern unsigned int drm_rnodes;
1247 extern unsigned int drm_universal_planes;
1248 
1249 extern unsigned int drm_vblank_offdelay;
1250 extern unsigned int drm_timestamp_precision;
1251 extern unsigned int drm_timestamp_monotonic;
1252 
1253 /* Device setup support (drm_drv.c) */
1254 int	drm_probe(device_t kdev, drm_pci_id_list_t *idlist);
1255 int	drm_attach(device_t kdev, drm_pci_id_list_t *idlist);
1256 int	drm_create_cdevs(device_t kdev);
1257 
1258 d_ioctl_t drm_ioctl;
1259 extern int drm_lastclose(struct drm_device *dev);
1260 
1261 				/* Device support (drm_fops.h) */
1262 extern struct lock drm_global_mutex;
1263 d_open_t drm_open;
1264 d_close_t drm_close;
1265 d_read_t drm_read;
1266 d_kqfilter_t drm_kqfilter;
1267 int drm_release(device_t kdev);
1268 
1269 d_mmap_t drm_mmap;
1270 d_mmap_single_t drm_mmap_single;
1271 extern drm_local_map_t	*drm_getsarea(struct drm_device *dev);
1272 
1273 void drm_cdevpriv_dtor(void *cd);
1274 
1275 void drm_event_wakeup(struct drm_pending_event *e);
1276 
1277 int drm_add_busid_modesetting(struct drm_device *dev,
1278     struct sysctl_ctx_list *ctx, struct sysctl_oid *top);
1279 
1280 /* File operations helpers (drm_fops.c) */
1281 extern int		drm_open_helper(struct cdev *kdev, int flags, int fmt,
1282 					 DRM_STRUCTPROC *p,
1283 					struct drm_device *dev,
1284 					struct file *fp);
1285 extern struct drm_file	*drm_find_file_by_proc(struct drm_device *dev,
1286 					DRM_STRUCTPROC *p);
1287 
1288 #ifdef DUMBBELL_WIP
1289 extern int drm_gem_prime_handle_to_fd(struct drm_device *dev,
1290 		struct drm_file *file_priv, uint32_t handle, uint32_t flags,
1291 		int *prime_fd);
1292 extern int drm_gem_prime_fd_to_handle(struct drm_device *dev,
1293 		struct drm_file *file_priv, int prime_fd, uint32_t *handle);
1294 
1295 extern int drm_prime_handle_to_fd_ioctl(struct drm_device *dev, void *data,
1296 					struct drm_file *file_priv);
1297 extern int drm_prime_fd_to_handle_ioctl(struct drm_device *dev, void *data,
1298 					struct drm_file *file_priv);
1299 
1300 extern int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, vm_page_t *pages,
1301 					    dma_addr_t *addrs, int max_pages);
1302 #endif /* DUMBBELL_WIP */
1303 extern struct sg_table *drm_prime_pages_to_sg(vm_page_t *pages, int nr_pages);
1304 extern void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg);
1305 
1306 int drm_gem_dumb_destroy(struct drm_file *file,
1307 			 struct drm_device *dev,
1308 			 uint32_t handle);
1309 
1310 #ifdef DUMBBELL_WIP
1311 void drm_prime_init_file_private(struct drm_prime_file_private *prime_fpriv);
1312 void drm_prime_destroy_file_private(struct drm_prime_file_private *prime_fpriv);
1313 int drm_prime_add_imported_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf, uint32_t handle);
1314 int drm_prime_lookup_imported_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf, uint32_t *handle);
1315 void drm_prime_remove_imported_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf);
1316 
1317 int drm_prime_add_dma_buf(struct drm_device *dev, struct drm_gem_object *obj);
1318 int drm_prime_lookup_obj(struct drm_device *dev, struct dma_buf *buf,
1319 			 struct drm_gem_object **obj);
1320 #endif /* DUMBBELL_WIP */
1321 
1322 				/* Memory management support (drm_memory.h) */
1323 #include <drm/drm_memory.h>
1324 void	drm_mem_init(void);
1325 void	drm_mem_uninit(void);
1326 void	*drm_ioremap_wc(struct drm_device *dev, drm_local_map_t *map);
1327 void	*drm_ioremap(struct drm_device *dev, drm_local_map_t *map);
1328 void	drm_ioremapfree(drm_local_map_t *map);
1329 int	drm_mtrr_add(unsigned long offset, size_t size, int flags);
1330 int	drm_mtrr_del(int handle, unsigned long offset, size_t size, int flags);
1331 
1332 int	drm_ctxbitmap_init(struct drm_device *dev);
1333 void	drm_ctxbitmap_cleanup(struct drm_device *dev);
1334 void	drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
1335 
1336 /* Locking IOCTL support (drm_lock.c) */
1337 int	drm_lock_take(struct drm_lock_data *lock_data,
1338 		      unsigned int context);
1339 int	drm_lock_transfer(struct drm_lock_data *lock_data,
1340 			  unsigned int context);
1341 int	drm_lock_free(struct drm_lock_data *lock_data,
1342 		      unsigned int context);
1343 
1344 /*
1345  * These are exported to drivers so that they can implement fencing using
1346  * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
1347  */
1348 
1349 unsigned long drm_get_resource_start(struct drm_device *dev,
1350 				     unsigned int resource);
1351 unsigned long drm_get_resource_len(struct drm_device *dev,
1352 				   unsigned int resource);
1353 void	drm_rmmap(struct drm_device *dev, drm_local_map_t *map);
1354 int	drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc *request);
1355 int	drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc *request);
1356 extern int drm_addmap(struct drm_device *dev, resource_size_t offset,
1357 		      unsigned int size, enum drm_map_type type,
1358 		      enum drm_map_flags flags, struct drm_local_map **map_ptr);
1359 
1360 /* DMA support (drm_dma.c) */
1361 int	drm_dma_setup(struct drm_device *dev);
1362 void	drm_dma_takedown(struct drm_device *dev);
1363 void	drm_free_buffer(struct drm_device *dev, drm_buf_t *buf);
1364 void	drm_reclaim_buffers(struct drm_device *dev, struct drm_file *file_priv);
1365 #define drm_core_reclaim_buffers drm_reclaim_buffers
1366 
1367 				/* IRQ support (drm_irq.h) */
1368 extern int drm_irq_install(struct drm_device *dev, int irq);
1369 int	drm_irq_uninstall(struct drm_device *dev);
1370 void	drm_driver_irq_preinstall(struct drm_device *dev);
1371 void	drm_driver_irq_postinstall(struct drm_device *dev);
1372 void	drm_driver_irq_uninstall(struct drm_device *dev);
1373 
1374 extern int drm_vblank_init(struct drm_device *dev, int num_crtcs);
1375 extern int drm_wait_vblank(struct drm_device *dev, void *data,
1376 			   struct drm_file *filp);
1377 extern u32 drm_vblank_count(struct drm_device *dev, int crtc);
1378 extern u32 drm_vblank_count_and_time(struct drm_device *dev, int crtc,
1379 				     struct timeval *vblanktime);
1380 extern void drm_send_vblank_event(struct drm_device *dev, int crtc,
1381 				     struct drm_pending_vblank_event *e);
1382 extern bool drm_handle_vblank(struct drm_device *dev, int crtc);
1383 extern int drm_vblank_get(struct drm_device *dev, int crtc);
1384 extern void drm_vblank_put(struct drm_device *dev, int crtc);
1385 extern int drm_crtc_vblank_get(struct drm_crtc *crtc);
1386 extern void drm_crtc_vblank_put(struct drm_crtc *crtc);
1387 extern void drm_vblank_off(struct drm_device *dev, int crtc);
1388 extern void drm_vblank_on(struct drm_device *dev, int crtc);
1389 extern void drm_crtc_vblank_off(struct drm_crtc *crtc);
1390 extern void drm_crtc_vblank_on(struct drm_crtc *crtc);
1391 extern void drm_vblank_cleanup(struct drm_device *dev);
1392 
1393 extern u32 drm_get_last_vbltimestamp(struct drm_device *dev, int crtc,
1394 				     struct timeval *tvblank, unsigned flags);
1395 extern int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
1396 						 int crtc, int *max_error,
1397 						 struct timeval *vblank_time,
1398 						 unsigned flags,
1399 						 const struct drm_crtc *refcrtc,
1400 						 const struct drm_display_mode *mode);
1401 extern void drm_calc_timestamping_constants(struct drm_crtc *crtc,
1402 					    const struct drm_display_mode *mode);
1403 
1404 /* Modesetting support */
1405 extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
1406 extern void drm_vblank_post_modeset(struct drm_device *dev, int crtc);
1407 extern int drm_modeset_ctl(struct drm_device *dev, void *data,
1408 			   struct drm_file *file_priv);
1409 
1410 /* AGP/PCI Express/GART support (drm_agpsupport.c) */
1411 int	drm_device_is_agp(struct drm_device *dev);
1412 int	drm_device_is_pcie(struct drm_device *dev);
1413 drm_agp_head_t *drm_agp_init(void);
1414 int	drm_agp_acquire(struct drm_device *dev);
1415 int	drm_agp_release(struct drm_device *dev);
1416 int	drm_agp_info(struct drm_device * dev, struct drm_agp_info *info);
1417 int	drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
1418 void	*drm_agp_allocate_memory(size_t pages, u32 type);
1419 int	drm_agp_free_memory(void *handle);
1420 int	drm_agp_bind_memory(void *handle, off_t start);
1421 int	drm_agp_unbind_memory(void *handle);
1422 int	drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
1423 int	drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
1424 int	drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
1425 int	drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
1426 
1427 				/* Scatter Gather Support (drm_scatter.h) */
1428 extern void drm_legacy_sg_cleanup(struct drm_device *dev);
1429 extern int drm_sg_alloc(struct drm_device *dev, void *data,
1430 			struct drm_file *file_priv);
1431 
1432 /* Scatter Gather Support (drm_scatter.c) */
1433 void	drm_sg_cleanup(drm_sg_mem_t *entry);
1434 
1435 /* sysctl support (drm_sysctl.h) */
1436 extern int		drm_sysctl_init(struct drm_device *dev);
1437 extern int		drm_sysctl_cleanup(struct drm_device *dev);
1438 
1439 /* ATI PCIGART support (ati_pcigart.c) */
1440 int	drm_ati_pcigart_init(struct drm_device *dev,
1441 				struct drm_ati_pcigart_info *gart_info);
1442 int	drm_ati_pcigart_cleanup(struct drm_device *dev,
1443 				struct drm_ati_pcigart_info *gart_info);
1444 
1445 /* Cache management (drm_memory.c) */
1446 void	drm_clflush_pages(vm_page_t *pages, unsigned long num_pages);
1447 
1448 /* Locking IOCTL support (drm_drv.c) */
1449 int	drm_lock(struct drm_device *dev, void *data,
1450 		 struct drm_file *file_priv);
1451 int	drm_unlock(struct drm_device *dev, void *data,
1452 		   struct drm_file *file_priv);
1453 int	drm_version(struct drm_device *dev, void *data,
1454 		    struct drm_file *file_priv);
1455 int	drm_setversion(struct drm_device *dev, void *data,
1456 		       struct drm_file *file_priv);
1457 
1458 /* Misc. IOCTL support (drm_ioctl.c) */
1459 int	drm_irq_by_busid(struct drm_device *dev, void *data,
1460 			 struct drm_file *file_priv);
1461 int	drm_getunique(struct drm_device *dev, void *data,
1462 		      struct drm_file *file_priv);
1463 int	drm_setunique(struct drm_device *dev, void *data,
1464 		      struct drm_file *file_priv);
1465 int	drm_getmap(struct drm_device *dev, void *data,
1466 		   struct drm_file *file_priv);
1467 int	drm_getclient(struct drm_device *dev, void *data,
1468 		      struct drm_file *file_priv);
1469 int	drm_getstats(struct drm_device *dev, void *data,
1470 		     struct drm_file *file_priv);
1471 int	drm_getcap(struct drm_device *dev, void *data,
1472 		     struct drm_file *file_priv);
1473 extern int drm_setclientcap(struct drm_device *dev, void *data,
1474 			    struct drm_file *file_priv);
1475 int	drm_noop(struct drm_device *dev, void *data,
1476 		 struct drm_file *file_priv);
1477 
1478 /* Context IOCTL support (drm_context.c) */
1479 int	drm_resctx(struct drm_device *dev, void *data,
1480 		   struct drm_file *file_priv);
1481 int	drm_addctx(struct drm_device *dev, void *data,
1482 		   struct drm_file *file_priv);
1483 int	drm_getctx(struct drm_device *dev, void *data,
1484 		   struct drm_file *file_priv);
1485 int	drm_switchctx(struct drm_device *dev, void *data,
1486 		      struct drm_file *file_priv);
1487 int	drm_newctx(struct drm_device *dev, void *data,
1488 		   struct drm_file *file_priv);
1489 int	drm_rmctx(struct drm_device *dev, void *data,
1490 		  struct drm_file *file_priv);
1491 int	drm_setsareactx(struct drm_device *dev, void *data,
1492 			struct drm_file *file_priv);
1493 int	drm_getsareactx(struct drm_device *dev, void *data,
1494 			struct drm_file *file_priv);
1495 
1496 /* Authentication IOCTL support (drm_auth.c) */
1497 int	drm_getmagic(struct drm_device *dev, void *data,
1498 		     struct drm_file *file_priv);
1499 int	drm_authmagic(struct drm_device *dev, void *data,
1500 		      struct drm_file *file_priv);
1501 
1502 /* Cache management (drm_cache.c) */
1503 void drm_clflush_virt_range(void *addr, unsigned long length);
1504 
1505 /* Buffer management support (drm_bufs.c) */
1506 int	drm_addmap_ioctl(struct drm_device *dev, void *data,
1507 			 struct drm_file *file_priv);
1508 int	drm_rmmap_ioctl(struct drm_device *dev, void *data,
1509 			struct drm_file *file_priv);
1510 int	drm_addbufs(struct drm_device *dev, void *data,
1511 		    struct drm_file *file_priv);
1512 int	drm_infobufs(struct drm_device *dev, void *data,
1513 		     struct drm_file *file_priv);
1514 int	drm_markbufs(struct drm_device *dev, void *data,
1515 		     struct drm_file *file_priv);
1516 int	drm_freebufs(struct drm_device *dev, void *data,
1517 		     struct drm_file *file_priv);
1518 int	drm_mapbufs(struct drm_device *dev, void *data,
1519 		    struct drm_file *file_priv);
1520 
1521 /* DMA support (drm_dma.c) */
1522 int	drm_dma(struct drm_device *dev, void *data, struct drm_file *file_priv);
1523 
1524 /* IRQ support (drm_irq.c) */
1525 int	drm_control(struct drm_device *dev, void *data,
1526 		    struct drm_file *file_priv);
1527 
1528 /* AGP/GART support (drm_agpsupport.c) */
1529 int	drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
1530 			      struct drm_file *file_priv);
1531 int	drm_agp_release_ioctl(struct drm_device *dev, void *data,
1532 			      struct drm_file *file_priv);
1533 int	drm_agp_enable_ioctl(struct drm_device *dev, void *data,
1534 			     struct drm_file *file_priv);
1535 int	drm_agp_info_ioctl(struct drm_device *dev, void *data,
1536 			   struct drm_file *file_priv);
1537 int	drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
1538 			    struct drm_file *file_priv);
1539 int	drm_agp_free_ioctl(struct drm_device *dev, void *data,
1540 			   struct drm_file *file_priv);
1541 int	drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
1542 			     struct drm_file *file_priv);
1543 int	drm_agp_bind_ioctl(struct drm_device *dev, void *data,
1544 			   struct drm_file *file_priv);
1545 
1546 				/* Stub support (drm_stub.h) */
1547 extern int drm_setmaster_ioctl(struct drm_device *dev, void *data,
1548 			       struct drm_file *file_priv);
1549 extern int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
1550 				struct drm_file *file_priv);
1551 
1552 /* Scatter Gather Support (drm_scatter.c) */
1553 int	drm_sg_alloc_ioctl(struct drm_device *dev, void *data,
1554 			   struct drm_file *file_priv);
1555 int	drm_sg_free(struct drm_device *dev, void *data,
1556 		    struct drm_file *file_priv);
1557 
1558 /* consistent PCI memory functions (drm_pci.c) */
1559 extern drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
1560 				       size_t align);
1561 void	drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah);
1562 
1563 			       /* sysfs support (drm_sysfs.c) */
1564 struct drm_sysfs_class;
1565 extern struct class *drm_sysfs_create(struct module *owner, char *name);
1566 extern void drm_sysfs_destroy(void);
1567 extern int drm_sysfs_device_add(struct drm_minor *minor);
1568 extern void drm_sysfs_hotplug_event(struct drm_device *dev);
1569 extern void drm_sysfs_device_remove(struct drm_minor *minor);
1570 extern int drm_sysfs_connector_add(struct drm_connector *connector);
1571 extern void drm_sysfs_connector_remove(struct drm_connector *connector);
1572 
1573 /* Graphics Execution Manager library functions (drm_gem.c) */
1574 int drm_gem_init(struct drm_device *dev);
1575 void drm_gem_destroy(struct drm_device *dev);
1576 void drm_gem_object_release(struct drm_gem_object *obj);
1577 void drm_gem_object_free(struct kref *kref);
1578 int drm_gem_object_init(struct drm_device *dev,
1579 			struct drm_gem_object *obj, size_t size);
1580 void drm_gem_private_object_init(struct drm_device *dev,
1581 				 struct drm_gem_object *obj, size_t size);
1582 void drm_gem_vm_open(struct vm_area_struct *vma);
1583 void drm_gem_vm_close(struct vm_area_struct *vma);
1584 int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size,
1585 		     struct vm_area_struct *vma);
1586 int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
1587 
1588 int i915_gem_pager_ctor(void *handle, vm_ooffset_t size, vm_prot_t prot,
1589     vm_ooffset_t foff, struct ucred *cred, u_short *color);
1590 void i915_gem_pager_dtor(void * handle);
1591 
1592 #include <drm/drm_global.h>
1593 
1594 static inline void
1595 drm_gem_object_reference(struct drm_gem_object *obj)
1596 {
1597 	kref_get(&obj->refcount);
1598 }
1599 
1600 static inline void
1601 drm_gem_object_unreference(struct drm_gem_object *obj)
1602 {
1603 	if (obj != NULL)
1604 		kref_put(&obj->refcount, drm_gem_object_free);
1605 }
1606 
1607 static inline void
1608 drm_gem_object_unreference_unlocked(struct drm_gem_object *obj)
1609 {
1610 	if (obj != NULL) {
1611 		struct drm_device *dev = obj->dev;
1612 		DRM_LOCK(dev);
1613 		kref_put(&obj->refcount, drm_gem_object_free);
1614 		DRM_UNLOCK(dev);
1615 	}
1616 }
1617 
1618 int drm_gem_handle_create_tail(struct drm_file *file_priv,
1619 			       struct drm_gem_object *obj,
1620 			       u32 *handlep);
1621 int drm_gem_handle_create(struct drm_file *file_priv,
1622 			  struct drm_gem_object *obj,
1623 			  u32 *handlep);
1624 int drm_gem_handle_delete(struct drm_file *filp, u32 handle);
1625 
1626 struct drm_gem_object *drm_gem_object_lookup(struct drm_device *dev,
1627 					     struct drm_file *filp,
1628 					     u32 handle);
1629 int drm_gem_close_ioctl(struct drm_device *dev, void *data,
1630 			struct drm_file *file_priv);
1631 int drm_gem_flink_ioctl(struct drm_device *dev, void *data,
1632 			struct drm_file *file_priv);
1633 int drm_gem_open_ioctl(struct drm_device *dev, void *data,
1634 		       struct drm_file *file_priv);
1635 void drm_gem_open(struct drm_device *dev, struct drm_file *file_priv);
1636 void drm_gem_release(struct drm_device *dev, struct drm_file *file_priv);
1637 
1638 void drm_gem_free_mmap_offset(struct drm_gem_object *obj);
1639 int drm_gem_create_mmap_offset(struct drm_gem_object *obj);
1640 int drm_gem_create_mmap_offset_size(struct drm_gem_object *obj, size_t size);
1641 
1642 int drm_gem_mmap_single(struct drm_device *dev, vm_ooffset_t *offset,
1643     vm_size_t size, struct vm_object **obj_res, int nprot);
1644 void drm_gem_pager_dtr(void *obj);
1645 
1646 struct ttm_bo_device;
1647 int ttm_bo_mmap_single(struct ttm_bo_device *bdev, vm_ooffset_t *offset,
1648     vm_size_t size, struct vm_object **obj_res, int nprot);
1649 struct ttm_buffer_object;
1650 void ttm_bo_release_mmap(struct ttm_buffer_object *bo);
1651 
1652 void drm_device_lock_mtx(struct drm_device *dev);
1653 void drm_device_unlock_mtx(struct drm_device *dev);
1654 int drm_device_sleep_mtx(struct drm_device *dev, void *chan, int flags,
1655     const char *msg, int timeout);
1656 void drm_device_assert_mtx_locked(struct drm_device *dev);
1657 void drm_device_assert_mtx_unlocked(struct drm_device *dev);
1658 
1659 void drm_device_lock_struct(struct drm_device *dev);
1660 void drm_device_unlock_struct(struct drm_device *dev);
1661 int drm_device_sleep_struct(struct drm_device *dev, void *chan, int flags,
1662     const char *msg, int timeout);
1663 void drm_device_assert_struct_locked(struct drm_device *dev);
1664 void drm_device_assert_struct_unlocked(struct drm_device *dev);
1665 
1666 void drm_compat_locking_init(struct drm_device *dev);
1667 void drm_sleep_locking_init(struct drm_device *dev);
1668 
1669 /* XXX glue logic, should be done in drm_pci_init(), pending drm update */
1670 void drm_init_pdev(struct device *dev, struct pci_dev **pdev);
1671 void drm_fini_pdev(struct pci_dev **pdev);
1672 
1673 /* Inline replacements for drm_alloc and friends */
1674 static __inline__ void *
1675 drm_alloc(size_t size, struct malloc_type *area)
1676 {
1677 	return kmalloc(size, area, M_WAITOK | M_NULLOK);
1678 }
1679 
1680 static __inline__ void *
1681 drm_calloc(size_t nmemb, size_t size, struct malloc_type *area)
1682 {
1683 	return kmalloc(size * nmemb, area, M_WAITOK | M_NULLOK | M_ZERO);
1684 }
1685 
1686 static __inline__ void
1687 drm_free(void *pt, struct malloc_type *area)
1688 {
1689 	kfree(pt);
1690 }
1691 
1692 static __inline__ void
1693 drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev)
1694 {
1695 	map->handle = drm_ioremap_wc(dev, map);
1696 }
1697 static __inline__ void
1698 drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev)
1699 {
1700 	map->handle = drm_ioremap(dev, map);
1701 }
1702 static __inline__ void
1703 drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev)
1704 {
1705 	if ( map->handle && map->size )
1706 		drm_ioremapfree(map);
1707 }
1708 
1709 static __inline__ struct drm_local_map *
1710 drm_core_findmap(struct drm_device *dev, unsigned long offset)
1711 {
1712 	struct drm_map_list *_entry;
1713 
1714 	list_for_each_entry(_entry, &dev->maplist, head) {
1715 		if (offset == (unsigned long)_entry->map->handle)
1716 			return _entry->map;
1717 	}
1718 	return NULL;
1719 }
1720 
1721 static __inline__ void drm_core_dropmap(struct drm_map *map)
1722 {
1723 }
1724 
1725 #include <drm/drm_mem_util.h>
1726 
1727 /* FreeBSD compatibility macros */
1728 #define VM_OBJECT_WLOCK(object)		VM_OBJECT_LOCK(object)
1729 #define VM_OBJECT_WUNLOCK(object)	VM_OBJECT_UNLOCK(object)
1730 
1731 #define DRM_PCIE_SPEED_25 1
1732 #define DRM_PCIE_SPEED_50 2
1733 #define DRM_PCIE_SPEED_80 4
1734 
1735 extern int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *speed_mask);
1736 
1737 /* XXX bad */
1738 #define	drm_can_sleep()	(HZ & 1)
1739 
1740 #endif /* __KERNEL__ */
1741 #endif /* _DRM_P_H_ */
1742