xref: /dragonfly/sys/dev/drm/include/drm/drmP.h (revision a85cb24f)
1 /*
2  * Internal Header for the Direct Rendering Manager
3  *
4  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
5  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
6  * Copyright (c) 2009-2010, Code Aurora Forum.
7  * All rights reserved.
8  *
9  * Author: Rickard E. (Rik) Faith <faith@valinux.com>
10  * Author: Gareth Hughes <gareth@valinux.com>
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a
13  * copy of this software and associated documentation files (the "Software"),
14  * to deal in the Software without restriction, including without limitation
15  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16  * and/or sell copies of the Software, and to permit persons to whom the
17  * Software is furnished to do so, subject to the following conditions:
18  *
19  * The above copyright notice and this permission notice (including the next
20  * paragraph) shall be included in all copies or substantial portions of the
21  * Software.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
26  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
27  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
28  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29  * OTHER DEALINGS IN THE SOFTWARE.
30  */
31 
32 #ifndef _DRM_P_H_
33 #define _DRM_P_H_
34 
35 #include <linux/agp_backend.h>
36 #include <linux/cdev.h>
37 #include <linux/dma-mapping.h>
38 #include <linux/file.h>
39 #include <linux/fs.h>
40 #include <linux/highmem.h>
41 #include <linux/idr.h>
42 #include <linux/init.h>
43 #include <linux/io.h>
44 #include <linux/jiffies.h>
45 #include <linux/kernel.h>
46 #include <linux/kref.h>
47 #include <linux/miscdevice.h>
48 #include <linux/mm.h>
49 #include <linux/mutex.h>
50 #include <linux/platform_device.h>
51 #include <linux/poll.h>
52 #include <linux/ratelimit.h>
53 #include <linux/sched.h>
54 #include <linux/slab.h>
55 #include <linux/types.h>
56 #include <linux/vmalloc.h>
57 #include <linux/workqueue.h>
58 #include <linux/dma-fence.h>
59 #include <linux/module.h>
60 
61 #include <asm/mman.h>
62 #include <asm/pgalloc.h>
63 #include <linux/uaccess.h>
64 
65 #include <uapi/drm/drm.h>
66 #include <uapi/drm/drm_mode.h>
67 
68 #include <drm/drm_agpsupport.h>
69 #include <drm/drm_crtc.h>
70 #include <drm/drm_fourcc.h>
71 #include <drm/drm_global.h>
72 #include <drm/drm_hashtab.h>
73 #include <drm/drm_mem_util.h>
74 #include <drm/drm_mm.h>
75 #include <drm/drm_os_linux.h>
76 #include <drm/drm_sarea.h>
77 #include <drm/drm_drv.h>
78 #include <drm/drm_prime.h>
79 #include <drm/drm_pci.h>
80 #include <drm/drm_file.h>
81 #include <drm/drm_debugfs.h>
82 #include <drm/drm_ioctl.h>
83 #include <drm/drm_sysfs.h>
84 
85 #ifdef __DragonFly__
86 #include <drm/drm_auth.h>	/* for struct drm_lock_data */
87 
88 #include <sys/conf.h>
89 #include <sys/sysctl.h>
90 
91 #include <vm/vm_extern.h>
92 #include <vm/vm_pager.h>
93 #endif
94 
95 struct module;
96 
97 struct drm_device;
98 struct drm_agp_head;
99 struct drm_local_map;
100 struct drm_device_dma;
101 struct drm_gem_object;
102 struct drm_master;
103 struct drm_vblank_crtc;
104 struct drm_vma_offset_manager;
105 
106 struct device_node;
107 struct videomode;
108 struct reservation_object;
109 struct dma_buf_attachment;
110 
111 struct pci_dev;
112 struct pci_controller;
113 
114 /*
115  * The following categories are defined:
116  *
117  * CORE: Used in the generic drm code: drm_ioctl.c, drm_mm.c, drm_memory.c, ...
118  *	 This is the category used by the DRM_DEBUG() macro.
119  *
120  * DRIVER: Used in the vendor specific part of the driver: i915, radeon, ...
121  *	   This is the category used by the DRM_DEBUG_DRIVER() macro.
122  *
123  * KMS: used in the modesetting code.
124  *	This is the category used by the DRM_DEBUG_KMS() macro.
125  *
126  * PRIME: used in the prime code.
127  *	  This is the category used by the DRM_DEBUG_PRIME() macro.
128  *
129  * ATOMIC: used in the atomic code.
130  *	  This is the category used by the DRM_DEBUG_ATOMIC() macro.
131  *
132  * VBL: used for verbose debug message in the vblank code
133  *	  This is the category used by the DRM_DEBUG_VBL() macro.
134  *
135  * DragonFly-specific categories:
136  *
137  * PID: used as modifier to include PID number in messages.
138  *	  This is the category used by the all debug macros.
139  *
140  * FIOCTL: used in failed ioctl debugging.
141  *	  This is the category used by the DRM_DEBUG_FIOCTL() macro.
142  *
143  * IOCTL: used in ioctl debugging.
144  *	  This is the category used by the DRM_DEBUG_IOCTL() macro.
145  *
146  * Enabling verbose debug messages is done through the drm.debug parameter,
147  * each category being enabled by a bit.
148  *
149  * drm.debug=0x1 will enable CORE messages
150  * drm.debug=0x2 will enable DRIVER messages
151  * drm.debug=0x3 will enable CORE and DRIVER messages
152  * ...
153  * drm.debug=0x3f will enable all messages
154  *
155  * An interesting feature is that it's possible to enable verbose logging at
156  * run-time by using the hw.drm.debug sysctl variable:
157  *   # sysctl hw.drm.debug=0xfff
158  */
159 #define DRM_UT_NONE		0x00
160 #define DRM_UT_CORE 		0x01
161 #define DRM_UT_DRIVER		0x02
162 #define DRM_UT_KMS		0x04
163 #define DRM_UT_PRIME		0x08
164 #define DRM_UT_ATOMIC		0x10
165 #define DRM_UT_VBL		0x20
166 #define DRM_UT_STATE		0x40
167 /* Extra DragonFly debug categories */
168 #ifdef __DragonFly__
169 #define DRM_UT_RES8		0x80	/* reserved for future expansion */
170 #define DRM_UT_PID		0x100
171 #define DRM_UT_FIOCTL		0x200
172 #define DRM_UT_IOCTL		0x400
173 
174 extern __printflike(2, 3)
175 void drm_ut_debug_printk(const char *function_name,
176 			 const char *format, ...);
177 extern __printflike(2, 3)
178 void drm_err(const char *func, const char *format, ...);
179 #endif
180 
181 /***********************************************************************/
182 /** \name DRM template customization defaults */
183 /*@{*/
184 
185 /***********************************************************************/
186 /** \name Macros to make printk easier */
187 /*@{*/
188 
189 #define _DRM_PRINTK(once, level, fmt, ...)				\
190 	do {								\
191 		printk##once(KERN_##level "[" DRM_NAME "] " fmt,	\
192 			     ##__VA_ARGS__);				\
193 	} while (0)
194 
195 #define DRM_INFO(fmt, ...)						\
196 	_DRM_PRINTK(, INFO, fmt, ##__VA_ARGS__)
197 #define DRM_NOTE(fmt, ...)						\
198 	_DRM_PRINTK(, NOTICE, fmt, ##__VA_ARGS__)
199 #define DRM_WARN(fmt, ...)						\
200 	_DRM_PRINTK(, WARNING, fmt, ##__VA_ARGS__)
201 
202 #define DRM_INFO_ONCE(fmt, ...)						\
203 	_DRM_PRINTK(_once, INFO, fmt, ##__VA_ARGS__)
204 #define DRM_NOTE_ONCE(fmt, ...)						\
205 	_DRM_PRINTK(_once, NOTICE, fmt, ##__VA_ARGS__)
206 #define DRM_WARN_ONCE(fmt, ...)						\
207 	_DRM_PRINTK(_once, WARNING, fmt, ##__VA_ARGS__)
208 
209 /**
210  * Error output.
211  *
212  * \param fmt printf() like format string.
213  * \param arg arguments
214  */
215 #define DRM_DEV_ERROR(dev, fmt, ...)					\
216 	drm_dev_printk(dev, KERN_ERR, DRM_UT_NONE, __func__, " *ERROR*",\
217 		       fmt, ##__VA_ARGS__)
218 #define DRM_ERROR(fmt, ...)						\
219 	drm_err(__func__, fmt, ##__VA_ARGS__)
220 
221 /**
222  * Rate limited error output.  Like DRM_ERROR() but won't flood the log.
223  *
224  * \param fmt printf() like format string.
225  * \param arg arguments
226  */
227 #define DRM_DEV_ERROR_RATELIMITED(dev, fmt, ...)			\
228 ({									\
229 	static DEFINE_RATELIMIT_STATE(_rs,				\
230 				      DEFAULT_RATELIMIT_INTERVAL,	\
231 				      DEFAULT_RATELIMIT_BURST);		\
232 									\
233 	if (__ratelimit(&_rs))						\
234 		DRM_DEV_ERROR(dev, fmt, ##__VA_ARGS__);			\
235 })
236 #define DRM_ERROR_RATELIMITED(fmt, ...)					\
237 	DRM_DEV_ERROR_RATELIMITED(NULL, fmt, ##__VA_ARGS__)
238 
239 #define DRM_DEV_INFO(dev, fmt, ...)					\
240 	drm_dev_printk(dev, KERN_INFO, DRM_UT_NONE, __func__, "", fmt,	\
241 		       ##__VA_ARGS__)
242 
243 #define DRM_DEV_INFO_ONCE(dev, fmt, ...)				\
244 ({									\
245 	static bool __print_once __read_mostly;				\
246 	if (!__print_once) {						\
247 		__print_once = true;					\
248 		DRM_DEV_INFO(dev, fmt, ##__VA_ARGS__);			\
249 	}								\
250 })
251 
252 /**
253  * Debug output.
254  *
255  * \param fmt printf() like format string.
256  * \param arg arguments
257  */
258 #define DRM_DEV_DEBUG(dev, fmt, args...)				\
259 	drm_dev_printk(dev, KERN_DEBUG, DRM_UT_CORE, __func__, "", fmt,	\
260 		       ##args)
261 #define DRM_DEBUG(fmt, args...)						\
262 	do {								\
263 		if (unlikely(drm_debug & DRM_UT_CORE))			\
264 			drm_ut_debug_printk(__func__, fmt, ##args);	\
265 	} while (0)
266 
267 #define DRM_DEV_DEBUG_DRIVER(dev, fmt, args...)				\
268 	drm_dev_printk(dev, KERN_DEBUG, DRM_UT_DRIVER, __func__, "",	\
269 		       fmt, ##args)
270 #define DRM_DEBUG_DRIVER(fmt, args...)					\
271 	do {								\
272 		if (unlikely(drm_debug & DRM_UT_DRIVER))		\
273 			drm_ut_debug_printk(__func__, fmt, ##args);	\
274 	} while (0)
275 
276 #define DRM_DEV_DEBUG_KMS(dev, fmt, args...)				\
277 	drm_dev_printk(dev, KERN_DEBUG, DRM_UT_KMS, __func__, "", fmt,	\
278 		       ##args)
279 #define DRM_DEBUG_KMS(fmt, args...)					\
280 	do {								\
281 		if (unlikely(drm_debug & DRM_UT_KMS))			\
282 			drm_ut_debug_printk(__func__, fmt, ##args);	\
283 	} while (0)
284 
285 #define DRM_DEV_DEBUG_PRIME(dev, fmt, args...)				\
286 	drm_dev_printk(dev, KERN_DEBUG, DRM_UT_PRIME, __func__, "",	\
287 		       fmt, ##args)
288 #define DRM_DEBUG_PRIME(fmt, args...)					\
289 	do {								\
290 		if (unlikely(drm_debug & DRM_UT_PRIME))			\
291 			drm_ut_debug_printk(__func__, fmt, ##args);	\
292 	} while (0)
293 
294 #define DRM_DEV_DEBUG_ATOMIC(dev, fmt, args...)				\
295 	drm_dev_printk(dev, KERN_DEBUG, DRM_UT_ATOMIC, __func__, "",	\
296 		       fmt, ##args)
297 #define DRM_DEBUG_ATOMIC(fmt, ...)						\
298 	do {									\
299 		if (unlikely(drm_debug & DRM_UT_ATOMIC))			\
300 			drm_ut_debug_printk(__func__, fmt, ##__VA_ARGS__);	\
301 	} while(0)
302 
303 #define DRM_DEV_DEBUG_VBL(dev, fmt, args...)				\
304 	drm_dev_printk(dev, KERN_DEBUG, DRM_UT_VBL, __func__, "", fmt,	\
305 		       ##args)
306 #define DRM_DEBUG_VBL(fmt, args...)					\
307 	do {								\
308 		if (unlikely(drm_debug & DRM_UT_VBL))			\
309 			drm_ut_debug_printk(__func__, fmt, ##args);	\
310 	} while (0)
311 
312 #ifdef __DragonFly__
313 #define DRM_DEBUG_FIOCTL(fmt, args...)					\
314 	do {								\
315 		if (unlikely(drm_debug & DRM_UT_FIOCTL))		\
316 			drm_ut_debug_printk(__func__, fmt, ##args);	\
317 	} while (0)
318 #define DRM_DEBUG_IOCTL(fmt, args...)					\
319 	do {								\
320 		if (unlikely(drm_debug & DRM_UT_IOCTL))			\
321 			drm_ut_debug_printk(__func__, fmt, ##args);	\
322 	} while (0)
323 #define DRM_DEBUG_VBLANK	DRM_DEBUG_VBL
324 #endif	/* __DragonFly__ */
325 
326 #define _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, level, fmt, args...)	\
327 ({									\
328 	static DEFINE_RATELIMIT_STATE(_rs,				\
329 				      DEFAULT_RATELIMIT_INTERVAL,	\
330 				      DEFAULT_RATELIMIT_BURST);		\
331 	if (__ratelimit(&_rs))						\
332 		drm_dev_printk(dev, KERN_DEBUG, DRM_UT_ ## level,	\
333 			       __func__, "", fmt, ##args);		\
334 })
335 
336 /**
337  * Rate limited debug output. Like DRM_DEBUG() but won't flood the log.
338  *
339  * \param fmt printf() like format string.
340  * \param arg arguments
341  */
342 #define DRM_DEV_DEBUG_RATELIMITED(dev, fmt, args...)			\
343 	DEV__DRM_DEFINE_DEBUG_RATELIMITED(dev, CORE, fmt, ##args)
344 #define DRM_DEBUG_RATELIMITED(fmt, args...)				\
345 	DRM_DEV_DEBUG_RATELIMITED(NULL, fmt, ##args)
346 #define DRM_DEV_DEBUG_DRIVER_RATELIMITED(dev, fmt, args...)		\
347 	_DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, DRIVER, fmt, ##args)
348 #define DRM_DEBUG_DRIVER_RATELIMITED(fmt, args...)			\
349 	DRM_DEV_DEBUG_DRIVER_RATELIMITED(NULL, fmt, ##args)
350 #define DRM_DEV_DEBUG_KMS_RATELIMITED(dev, fmt, args...)		\
351 	_DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, KMS, fmt, ##args)
352 #define DRM_DEBUG_KMS_RATELIMITED(fmt, args...)				\
353 	DRM_DEV_DEBUG_KMS_RATELIMITED(NULL, fmt, ##args)
354 #define DRM_DEV_DEBUG_PRIME_RATELIMITED(dev, fmt, args...)		\
355 	_DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, PRIME, fmt, ##args)
356 #define DRM_DEBUG_PRIME_RATELIMITED(fmt, args...)			\
357 	DRM_DEV_DEBUG_PRIME_RATELIMITED(NULL, fmt, ##args)
358 
359 /* Format strings and argument splitters to simplify printing
360  * various "complex" objects
361  */
362 #define DRM_MODE_FMT    "%d:\"%s\" %d %d %d %d %d %d %d %d %d %d 0x%x 0x%x"
363 #define DRM_MODE_ARG(m) \
364 	(m)->base.id, (m)->name, (m)->vrefresh, (m)->clock, \
365 	(m)->hdisplay, (m)->hsync_start, (m)->hsync_end, (m)->htotal, \
366 	(m)->vdisplay, (m)->vsync_start, (m)->vsync_end, (m)->vtotal, \
367 	(m)->type, (m)->flags
368 
369 #define DRM_RECT_FMT    "%dx%d%+d%+d"
370 #define DRM_RECT_ARG(r) drm_rect_width(r), drm_rect_height(r), (r)->x1, (r)->y1
371 
372 /* for rect's in fixed-point format: */
373 #define DRM_RECT_FP_FMT "%d.%06ux%d.%06u%+d.%06u%+d.%06u"
374 #define DRM_RECT_FP_ARG(r) \
375 		drm_rect_width(r) >> 16, ((drm_rect_width(r) & 0xffff) * 15625) >> 10, \
376 		drm_rect_height(r) >> 16, ((drm_rect_height(r) & 0xffff) * 15625) >> 10, \
377 		(r)->x1 >> 16, (((r)->x1 & 0xffff) * 15625) >> 10, \
378 		(r)->y1 >> 16, (((r)->y1 & 0xffff) * 15625) >> 10
379 
380 /*@}*/
381 
382 /***********************************************************************/
383 /** \name Internal types and structures */
384 /*@{*/
385 
386 #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
387 
388 #define DRM_DEV_MODE	(S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
389 #define DRM_DEV_UID	UID_ROOT
390 #define DRM_DEV_GID	GID_WHEEL
391 
392 #define DRM_CURPROC		curthread
393 #define DRM_STRUCTPROC		struct thread
394 #define DRM_LOCK(dev)		lockmgr(&(dev)->struct_mutex, LK_EXCLUSIVE)
395 #define DRM_UNLOCK(dev)		lockmgr(&(dev)->struct_mutex, LK_RELEASE)
396 
397 #define DRM_SYSCTL_HANDLER_ARGS	(SYSCTL_HANDLER_ARGS)
398 
399 #define drm_get_device_from_kdev(_kdev) (_kdev->si_drv1)
400 
401 int vm_phys_fictitious_reg_range(vm_paddr_t start, vm_paddr_t end,
402     vm_memattr_t memattr);
403 void vm_phys_fictitious_unreg_range(vm_paddr_t start, vm_paddr_t end);
404 vm_page_t vm_phys_fictitious_to_vm_page(vm_paddr_t pa);
405 
406 /* Flags and return codes for get_vblank_timestamp() driver function. */
407 #define DRM_CALLED_FROM_VBLIRQ 1
408 #define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
409 
410 /* get_scanout_position() return flags */
411 #define DRM_SCANOUTPOS_VALID        (1 << 0)
412 #define DRM_SCANOUTPOS_IN_VBLANK    (1 << 1)
413 #define DRM_SCANOUTPOS_ACCURATE     (1 << 2)
414 
415 #ifdef __DragonFly__
416 struct drm_sysctl_info {
417 	struct sysctl_ctx_list ctx;
418 	char   name[2];
419 };
420 
421 /* Length for the array of resource pointers for drm_get_resource_*. */
422 #define DRM_MAX_PCI_RESOURCE	6
423 #endif
424 
425 /**
426  * DRM device structure. This structure represent a complete card that
427  * may contain multiple heads.
428  */
429 struct drm_device {
430 	struct list_head legacy_dev_list;/**< list of devices per driver for stealth attach cleanup */
431 	int if_version;			/**< Highest interface version set */
432 
433 	/** \name Lifetime Management */
434 	/*@{ */
435 	struct kref ref;		/**< Object ref-count */
436 	struct device *dev;		/**< Device structure of bus-device */
437 	struct drm_driver *driver;	/**< DRM driver managing the device */
438 	void *dev_private;		/**< DRM driver private data */
439 	struct drm_minor *control;		/**< Control node */
440 	struct drm_minor *primary;		/**< Primary node */
441 	struct drm_minor *render;		/**< Render node */
442 	bool registered;
443 
444 	/* currently active master for this device. Protected by master_mutex */
445 	struct drm_master *master;
446 
447 	atomic_t unplugged;			/**< Flag whether dev is dead */
448 	struct inode *anon_inode;		/**< inode for private address-space */
449 	char *unique;				/**< unique name of the device */
450 	/*@} */
451 
452 	/** \name Locks */
453 	/*@{ */
454 	struct lock struct_mutex;	/**< For others */
455 	struct lock master_mutex;      /**< For drm_minor::master and drm_file::is_master */
456 	/*@} */
457 
458 	/** \name Usage Counters */
459 	/*@{ */
460 	int open_count;			/**< Outstanding files open, protected by drm_global_mutex. */
461 	spinlock_t buf_lock;		/**< For drm_device::buf_use and a few other things. */
462 	int buf_use;			/**< Buffers in use -- cannot alloc */
463 	atomic_t buf_alloc;		/**< Buffer allocation in progress */
464 	/*@} */
465 
466 	struct lock filelist_mutex;
467 	struct list_head filelist;
468 
469 	/** \name Memory management */
470 	/*@{ */
471 	struct list_head maplist;	/**< Linked list of regions */
472 	struct drm_open_hash map_hash;	/**< User token hash table for maps */
473 
474 	/** \name Context handle management */
475 	/*@{ */
476 	struct list_head ctxlist;	/**< Linked list of context handles */
477 	struct lock ctxlist_mutex;	/**< For ctxlist */
478 
479 	struct idr ctx_idr;
480 
481 	struct list_head vmalist;	/**< List of vmas (for debugging) */
482 
483 	/*@} */
484 
485 	/** \name DMA support */
486 	/*@{ */
487 	struct drm_device_dma *dma;		/**< Optional pointer for DMA support */
488 	/*@} */
489 
490 	/** \name Context support */
491 	/*@{ */
492 
493 	__volatile__ long context_flag;	/**< Context swapping flag */
494 	int last_context;		/**< Last current context */
495 	/*@} */
496 
497 	/** \name VBLANK IRQ support */
498 	/*@{ */
499 	bool irq_enabled;
500 	int irq;
501 
502 	/*
503 	 * If true, vblank interrupt will be disabled immediately when the
504 	 * refcount drops to zero, as opposed to via the vblank disable
505 	 * timer.
506 	 * This can be set to true it the hardware has a working vblank
507 	 * counter and the driver uses drm_vblank_on() and drm_vblank_off()
508 	 * appropriately.
509 	 */
510 	bool vblank_disable_immediate;
511 
512 	/* array of size num_crtcs */
513 	struct drm_vblank_crtc *vblank;
514 
515 	spinlock_t vblank_time_lock;    /**< Protects vblank count and time updates during vblank enable/disable */
516 	spinlock_t vbl_lock;
517 
518 	u32 max_vblank_count;           /**< size of vblank counter register */
519 
520 	/**
521 	 * List of events
522 	 */
523 	struct list_head vblank_event_list;
524 	spinlock_t event_lock;
525 
526 	/*@} */
527 
528 	struct drm_agp_head *agp;	/**< AGP data */
529 
530 	struct pci_dev *pdev;		/**< PCI device structure */
531 #ifdef __alpha__
532 	struct pci_controller *hose;
533 #endif
534 
535 	struct virtio_device *virtdev;
536 
537 	struct drm_sg_mem *sg;	/**< Scatter gather memory */
538 	unsigned int num_crtcs;                  /**< Number of CRTCs on this device */
539 
540 	struct {
541 		int context;
542 		struct drm_hw_lock *lock;
543 	} sigdata;
544 
545 	struct drm_local_map *agp_buffer_map;
546 	unsigned int agp_buffer_token;
547 
548 	struct drm_mode_config mode_config;	/**< Current mode config */
549 
550 	/** \name GEM information */
551 	/*@{ */
552 	struct lock object_name_lock;
553 	struct idr object_name_idr;
554 	struct drm_vma_offset_manager *vma_offset_manager;
555 	/*@} */
556 	int switch_power_state;
557 #ifdef __DragonFly__
558 	/* Storage of resource pointers for drm_get_resource_* */
559 	struct resource   *pcir[DRM_MAX_PCI_RESOURCE];
560 	int		  pcirid[DRM_MAX_PCI_RESOURCE];
561 
562 	int		  pci_domain;
563 	int		  pci_bus;
564 	int		  pci_slot;
565 	int		  pci_func;
566 	char busid_str[128];
567 	int modesetting;
568 	void             *mm_private;
569 	struct drm_sysctl_info *sysctl;
570 
571 	struct idr magic_map;
572 
573 	int		  unique_len;	/* Length of unique field	   */
574 	struct cdev	  *devnode;	/* Device number for mknod	   */
575 
576 	struct lwkt_serialize irq_lock;	/* protects irq condition checks */
577 
578 	struct sigio      *buf_sigio;	/* Processes waiting for SIGIO     */
579 	void		  *drm_ttm_bdev;
580 
581 	struct drm_lock_data lock;	/* Information on hardware lock	   */
582 #endif
583 };
584 
585 /**
586  * drm_drv_uses_atomic_modeset - check if the driver implements
587  * atomic_commit()
588  * @dev: DRM device
589  *
590  * This check is useful if drivers do not have DRIVER_ATOMIC set but
591  * have atomic modesetting internally implemented.
592  */
593 static inline bool drm_drv_uses_atomic_modeset(struct drm_device *dev)
594 {
595 	return dev->mode_config.funcs->atomic_commit != NULL;
596 }
597 
598 #include <drm/drm_irq.h>
599 
600 #define DRM_SWITCH_POWER_ON 0
601 #define DRM_SWITCH_POWER_OFF 1
602 #define DRM_SWITCH_POWER_CHANGING 2
603 #define DRM_SWITCH_POWER_DYNAMIC_OFF 3
604 
605 static __inline__ int drm_core_check_feature(struct drm_device *dev,
606 					     int feature)
607 {
608 	return ((dev->driver->driver_features & feature) ? 1 : 0);
609 }
610 
611 static inline void drm_device_set_unplugged(struct drm_device *dev)
612 {
613 	smp_wmb();
614 	atomic_set(&dev->unplugged, 1);
615 }
616 
617 static inline int drm_device_is_unplugged(struct drm_device *dev)
618 {
619 	int ret = atomic_read(&dev->unplugged);
620 	smp_rmb();
621 	return ret;
622 }
623 
624 /******************************************************************/
625 /** \name Internal function definitions */
626 /*@{*/
627 
628 #ifdef __DragonFly__
629 int    drm_create_cdevs(device_t kdev);
630 
631 d_kqfilter_t drm_kqfilter;
632 d_mmap_t drm_mmap;
633 d_mmap_single_t drm_mmap_single;
634 
635 int drm_device_detach(device_t kdev);
636 
637 void drm_cdevpriv_dtor(void *cd);
638 
639 int drm_add_busid_modesetting(struct drm_device *dev,
640     struct sysctl_ctx_list *ctx, struct sysctl_oid *top);
641 
642 /* XXX glue logic, should be done in drm_pci_init(), pending drm update */
643 void drm_init_pdev(device_t dev, struct pci_dev **pdev);
644 void drm_fini_pdev(struct pci_dev **pdev);
645 void drm_print_pdev(struct pci_dev *pdev);
646 #endif
647 
648 /*
649  * These are exported to drivers so that they can implement fencing using
650  * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
651  */
652 
653 /*@}*/
654 
655 /* returns true if currently okay to sleep */
656 static __inline__ bool drm_can_sleep(void)
657 {
658 	if (in_atomic() || in_dbg_master() || irqs_disabled())
659 		return false;
660 	return true;
661 }
662 
663 /* helper for handling conditionals in various for_each macros */
664 #define for_each_if(condition) if (!(condition)) {} else
665 
666 #ifdef __DragonFly__
667 struct drm_softc {
668 	void *drm_driver_data;
669 };
670 
671 /* sysctl support (drm_sysctl.h) */
672 extern int drm_sysctl_init(struct drm_device *dev);
673 extern int drm_sysctl_cleanup(struct drm_device *dev);
674 unsigned long drm_get_resource_start(struct drm_device *dev,
675 				     unsigned int resource);
676 unsigned long drm_get_resource_len(struct drm_device *dev,
677 				   unsigned int resource);
678 
679 int ttm_bo_mmap_single(struct drm_device *dev, vm_ooffset_t *offset,
680     vm_size_t size, struct vm_object **obj_res, int nprot);
681 
682 int drm_gem_mmap_single(struct drm_device *dev, vm_ooffset_t *offset,
683     vm_size_t size, struct vm_object **obj_res, int nprot);
684 
685 /* XXX: These are here only because of drm_sysctl.c */
686 extern int drm_vblank_offdelay;
687 extern unsigned int drm_timestamp_precision;
688 
689 static __inline__ int drm_pci_device_is_agp(struct drm_device *dev)
690 {
691 	return (pci_find_extcap(dev->pdev->dev.bsddev, PCIY_AGP, NULL) == 0);
692 }
693 void drm_pci_agp_destroy(struct drm_device *dev);
694 #endif
695 
696 #endif
697