Merge branch 'vendor/LIBRESSL'
[dragonfly.git] / sys / dev / drm / include / drm / drmP.h
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 #if defined(_KERNEL) || defined(__KERNEL__)
36
37 #include <sys/param.h>
38 #include <sys/queue.h>
39 #include <sys/malloc.h>
40 #include <sys/kernel.h>
41 #include <sys/ktr.h>
42 #include <sys/module.h>
43 #include <sys/systm.h>
44 #include <sys/device.h>
45 #include <sys/sglist.h>
46 #include <sys/stat.h>
47 #include <sys/priv.h>
48 #include <sys/proc.h>
49 #include <sys/lock.h>
50 #include <sys/spinlock.h>
51 #include <sys/spinlock2.h>
52 #include <sys/fcntl.h>
53 #include <sys/uio.h>
54 #include <sys/filio.h>
55 #include <sys/sysctl.h>
56 #include <sys/bus.h>
57 #include <sys/queue.h>
58 #include <sys/signalvar.h>
59 #include <sys/poll.h>
60 #include <linux/highmem.h>
61 #include <sys/sbuf.h>
62 #include <sys/taskqueue.h>
63 #include <sys/tree.h>
64 #include <vm/vm.h>
65 #include <vm/pmap.h>
66 #include <vm/vm_extern.h>
67 #include <vm/vm_kern.h>
68 #include <vm/vm_map.h>
69 #include <vm/vm_object.h>
70 #include <vm/vm_page2.h>
71 #include <vm/vm_pager.h>
72 #include <vm/vm_param.h>
73 #include <machine/param.h>
74 #include <machine/pmap.h>
75 #ifdef __x86_64__
76 #include <machine/specialreg.h>
77 #endif
78 #include <machine/sysarch.h>
79 #include <sys/endian.h>
80 #include <sys/mman.h>
81 #include <sys/rman.h>
82 #include <sys/memrange.h>
83 #include <sys/mutex.h>
84
85 #include <linux/atomic.h>
86 #include <linux/bug.h>
87 #include <linux/dma-mapping.h>
88 #include <linux/capability.h>
89 #include <linux/err.h>
90 #include <linux/idr.h>
91 #include <linux/pci.h>
92 #include <linux/jiffies.h>
93 #include <linux/kernel.h>
94 #include <linux/fs.h>
95 #include <linux/kref.h>
96 #include <linux/list.h>
97 #include <linux/mm.h>
98 #include <linux/moduleparam.h>
99 #include <linux/mutex.h>
100 #include <linux/pci.h>
101 #include <linux/slab.h>
102 #include <linux/scatterlist.h>
103 #include <linux/timer.h>
104 #include <asm/io.h>
105 #include <linux/seq_file.h>
106 #include <linux/types.h>
107 #include <linux/vmalloc.h>
108 #include <linux/wait.h>
109 #include <linux/workqueue.h>
110
111 #include <asm/uaccess.h>
112
113 #include <uapi_drm/drm.h>
114 #include <uapi_drm/drm_mode.h>
115
116 #include <drm/drm_agpsupport.h>
117 #include <drm/drm_crtc.h>
118 #include <drm/drm_global.h>
119 #include <drm/drm_hashtab.h>
120 #include <drm/drm_mem_util.h>
121 #include <drm/drm_mm.h>
122 #include <drm/drm_os_linux.h>
123 #include <uapi_drm/drm_sarea.h>
124 #include <drm/drm_vma_manager.h>
125
126 struct drm_file;
127 struct drm_device;
128 struct drm_agp_head;
129 struct drm_local_map;
130 struct drm_device_dma;
131 struct drm_dma_handle;
132 struct drm_gem_object;
133
134 struct device_node;
135 #ifdef CONFIG_VIDEOMODE_HELPERS
136 struct videomode;       /* XXX empty struct in videomode.h ? */
137 #endif
138 struct reservation_object;
139 struct dma_buf_attachment;
140
141 /*
142  * 4 debug categories are defined:
143  *
144  * CORE: Used in the generic drm code: drm_ioctl.c, drm_mm.c, drm_memory.c, ...
145  *       This is the category used by the DRM_DEBUG() macro.
146  *
147  * DRIVER: Used in the vendor specific part of the driver: i915, radeon, ...
148  *         This is the category used by the DRM_DEBUG_DRIVER() macro.
149  *
150  * KMS: used in the modesetting code.
151  *      This is the category used by the DRM_DEBUG_KMS() macro.
152  *
153  * PRIME: used in the prime code.
154  *        This is the category used by the DRM_DEBUG_PRIME() macro.
155  *
156  * ATOMIC: used in the atomic code.
157  *        This is the category used by the DRM_DEBUG_ATOMIC() macro.
158  *
159  *
160  * PID: used as modifier to include PID number in messages.
161  *        This is the category used by the all debug macros.
162  *
163  * FIOCTL: used in failed ioctl debugging.
164  *        This is the category used by the DRM_DEBUG_FIOCTL() macro.
165  *
166  * IOCTL: used in ioctl debugging.
167  *        This is the category used by the DRM_DEBUG_IOCTL() macro.
168  *
169  * VBLANK: used in vblank debugging.
170  *        This is the category used by the DRM_DEBUG_VBLANK() macro.
171  *
172  * Enabling verbose debug messages is done through the drm.debug parameter,
173  * each category being enabled by a bit.
174  *
175  * drm.debug=0x1 will enable CORE messages
176  * drm.debug=0x2 will enable DRIVER messages
177  * drm.debug=0x3 will enable CORE and DRIVER messages
178  * ...
179  * drm.debug=0xf will enable all messages
180  *
181  * An interesting feature is that it's possible to enable verbose logging at
182  * run-time by using hw.drm.debug sysctl variable:
183  *   # sysctl hw.drm.debug=0xfff
184  */
185 #define DRM_UT_CORE             0x01
186 #define DRM_UT_DRIVER           0x02
187 #define DRM_UT_KMS              0x04
188 #define DRM_UT_PRIME            0x08
189 #define DRM_UT_ATOMIC           0x10
190 #define DRM_UT_VBL              0x20
191 /* Extra DragonFly debug categories */
192 #ifdef __DragonFly__
193 #define DRM_UT_RES7             0x40    /* reserved for future expansion */
194 #define DRM_UT_RES8             0x80    /* reserved for future expansion */
195 #define DRM_UT_PID              0x100
196 #define DRM_UT_FIOCTL           0x200
197 #define DRM_UT_IOCTL            0x400
198 #define DRM_UT_VBLANK           0x800
199 #endif
200
201 extern __printflike(2, 3)
202 void drm_ut_debug_printk(const char *function_name,
203                          const char *format, ...);
204 extern __printflike(2, 3)
205 void drm_err(const char *func, const char *format, ...);
206
207 /***********************************************************************/
208 /** \name DRM template customization defaults */
209 /*@{*/
210
211 /* driver capabilities and requirements mask */
212 #define DRIVER_USE_AGP                  0x1
213 #define DRIVER_PCI_DMA                  0x8
214 #define DRIVER_SG                       0x10
215 #define DRIVER_HAVE_DMA                 0x20
216 #define DRIVER_HAVE_IRQ                 0x40
217 #define DRIVER_IRQ_SHARED               0x80
218 #define DRIVER_GEM                      0x1000
219 #define DRIVER_MODESET                  0x2000
220 #define DRIVER_PRIME                    0x4000
221 #define DRIVER_RENDER                   0x8000
222 #define DRIVER_ATOMIC                   0x10000
223 #define DRIVER_KMS_LEGACY_CONTEXT       0x20000
224
225 #define DRM_MAGIC_HASH_ORDER  4  /**< Size of key hash table. Must be power of 2. */
226
227 /***********************************************************************/
228 /** \name Macros to make printk easier */
229 /*@{*/
230
231 /**
232  * Error output.
233  *
234  * \param fmt printf() like format string.
235  * \param arg arguments
236  */
237 #define DRM_ERROR(fmt, ...)                             \
238         drm_err(__func__, fmt, ##__VA_ARGS__)
239
240 /**
241  * Rate limited error output.  Like DRM_ERROR() but won't flood the log.
242  *
243  * \param fmt printf() like format string.
244  * \param arg arguments
245  */
246 #define DRM_ERROR_RATELIMITED(fmt, ...)                         \
247 ({                                                                      \
248         static struct krate krate_derr = { .freq = 1, .count = -16 };   \
249                                                                         \
250         krateprintf(&krate_derr, "error: [" DRM_NAME ":%s] *ERROR* "    \
251             fmt, __func__, ##__VA_ARGS__);                              \
252 })
253
254 #define DRM_INFO(fmt, ...)                              \
255         printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
256
257 #define DRM_INFO_ONCE(fmt, ...)                         \
258         printk_once(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
259
260 /**
261  * Debug output.
262  *
263  * \param fmt printf() like format string.
264  * \param arg arguments
265  */
266 #define DRM_DEBUG(fmt, args...)                                         \
267         do {                                                            \
268                 if (unlikely(drm_debug & DRM_UT_CORE))                  \
269                         drm_ut_debug_printk(__func__, fmt, ##args);     \
270         } while (0)
271
272 #define DRM_DEBUG_DRIVER(fmt, args...)                                  \
273         do {                                                            \
274                 if (unlikely(drm_debug & DRM_UT_DRIVER))                \
275                         drm_ut_debug_printk(__func__, fmt, ##args);     \
276         } while (0)
277 #define DRM_DEBUG_KMS(fmt, args...)                                     \
278         do {                                                            \
279                 if (unlikely(drm_debug & DRM_UT_KMS))                   \
280                         drm_ut_debug_printk(__func__, fmt, ##args);     \
281         } while (0)
282 #define DRM_DEBUG_PRIME(fmt, args...)                                   \
283         do {                                                            \
284                 if (unlikely(drm_debug & DRM_UT_PRIME))                 \
285                         drm_ut_debug_printk(__func__, fmt, ##args);     \
286         } while (0)
287 #define DRM_DEBUG_ATOMIC(fmt, args...)                                  \
288         do {                                                            \
289                 if (unlikely(drm_debug & DRM_UT_ATOMIC))                \
290                         drm_ut_debug_printk(__func__, fmt, ##args);     \
291         } while (0)
292
293 #ifdef __DragonFly__
294 #define DRM_DEBUG_FIOCTL(fmt, args...)                                  \
295         do {                                                            \
296                 if (unlikely(drm_debug & DRM_UT_FIOCTL))                \
297                         drm_ut_debug_printk(__func__, fmt, ##args);     \
298         } while (0)
299 #define DRM_DEBUG_IOCTL(fmt, args...)                                   \
300         do {                                                            \
301                 if (unlikely(drm_debug & DRM_UT_IOCTL))                 \
302                         drm_ut_debug_printk(__func__, fmt, ##args);     \
303         } while (0)
304 #define DRM_DEBUG_VBLANK(fmt, args...)                                  \
305         do {                                                            \
306                 if (unlikely(drm_debug & DRM_UT_VBLANK))                \
307                         drm_ut_debug_printk(__func__, fmt, ##args);     \
308         } while (0)
309 #define DRM_DEBUG_VBL(fmt, args...)                                     \
310         do {                                                            \
311                 if (unlikely(drm_debug & DRM_UT_VBL))           \
312                         drm_ut_debug_printk(__func__, fmt, ##args);     \
313         } while (0)
314 #endif
315
316 /*@}*/
317
318 /***********************************************************************/
319 /** \name Internal types and structures */
320 /*@{*/
321
322 SYSCTL_DECL(_hw_drm);
323
324 #define DRM_MAX(a,b) ((a)>(b)?(a):(b))
325
326 #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
327
328 #define DRM_DEV_MODE    (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
329 #define DRM_DEV_UID     UID_ROOT
330 #define DRM_DEV_GID     GID_WHEEL
331
332 #define DRM_CURPROC             curthread
333 #define DRM_STRUCTPROC          struct thread
334 #define DRM_LOCK(dev)           lockmgr(&(dev)->struct_mutex, LK_EXCLUSIVE)
335 #define DRM_UNLOCK(dev)         lockmgr(&(dev)->struct_mutex, LK_RELEASE)
336 #define DRM_LOCK_SLEEP(dev, chan, flags, msg, timeout)                  \
337     (lksleep((chan), &(dev)->struct_mutex, (flags), (msg), (timeout)))
338 #if defined(INVARIANTS)
339 #define DRM_LOCK_ASSERT(dev)    KKASSERT(lockstatus(&(dev)->struct_mutex, curthread) != 0);
340 #define DRM_UNLOCK_ASSERT(dev)  KKASSERT(lockstatus(&(dev)->struct_mutex, curthread) == 0);
341 #else
342 #define DRM_LOCK_ASSERT(d)
343 #define DRM_UNLOCK_ASSERT(d)
344 #endif
345
346 #define DRM_SYSCTL_HANDLER_ARGS (SYSCTL_HANDLER_ARGS)
347
348 typedef void                    irqreturn_t;
349 #define IRQ_HANDLED             /* nothing */
350 #define IRQ_NONE                /* nothing */
351
352 #define drm_get_device_from_kdev(_kdev) (_kdev->si_drv1)
353
354 #define DRM_MTRR_WC             MDF_WRITECOMBINE
355
356 int vm_phys_fictitious_reg_range(vm_paddr_t start, vm_paddr_t end,
357     vm_memattr_t memattr);
358 void vm_phys_fictitious_unreg_range(vm_paddr_t start, vm_paddr_t end);
359 vm_page_t vm_phys_fictitious_to_vm_page(vm_paddr_t pa);
360
361 /* drm_memory.c */
362 int     drm_mtrr_add(unsigned long offset, size_t size, int flags);
363 int     drm_mtrr_del(int handle, unsigned long offset, size_t size, int flags);
364
365 typedef struct drm_pci_id_list
366 {
367         int vendor;
368         int device;
369         long driver_private;
370         char *name;
371 } drm_pci_id_list_t;
372
373 /**
374  * Ioctl function type.
375  *
376  * \param inode device inode.
377  * \param file_priv DRM file private pointer.
378  * \param cmd command.
379  * \param arg argument.
380  */
381 typedef int drm_ioctl_t(struct drm_device *dev, void *data,
382                         struct drm_file *file_priv);
383
384 typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
385                                unsigned long arg);
386
387 #define DRM_IOCTL_NR(n)                ((n) & 0xff)
388
389 #define DRM_AUTH        0x1
390 #define DRM_MASTER      0x2
391 #define DRM_ROOT_ONLY   0x4
392 #define DRM_CONTROL_ALLOW 0x8
393 #define DRM_UNLOCKED    0x10
394 #define DRM_RENDER_ALLOW 0x20
395
396 struct drm_ioctl_desc {
397         unsigned int cmd;
398         int flags;
399         drm_ioctl_t *func;
400         unsigned int cmd_drv;
401         const char *name;
402 };
403
404 /**
405  * Creates a driver or general drm_ioctl_desc array entry for the given
406  * ioctl, for use by drm_ioctl().
407  */
408
409 #define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags)                         \
410         [DRM_IOCTL_NR(DRM_##ioctl)] = {                                 \
411                 .cmd = DRM_##ioctl,                                     \
412                 .func = _func,                                          \
413                 .flags = _flags,                                        \
414                 .cmd_drv = DRM_IOCTL_##ioctl,                           \
415                 .name = #ioctl                                          \
416         }
417
418 typedef struct drm_magic_entry {
419         struct list_head head;
420         struct drm_hash_item hash_item;
421         struct drm_file        *priv;
422         struct drm_magic_entry *next;
423 } drm_magic_entry_t;
424
425 /* Event queued up for userspace to read */
426 struct drm_pending_event {
427         struct drm_event *event;
428         struct list_head link;
429         struct drm_file *file_priv;
430         pid_t pid; /* pid of requester, no guarantee it's valid by the time
431                       we deliver the event, for tracing only */
432         void (*destroy)(struct drm_pending_event *event);
433 };
434
435 /* initial implementaton using a linked list - todo hashtab */
436 struct drm_prime_file_private {
437         struct list_head head;
438 #ifdef DUMBBELL_WIP
439         struct mutex lock;
440 #endif /* DUMBBELL_WIP */
441 };
442
443 /** File private data */
444 struct drm_file {
445         int authenticated;
446         struct drm_device *dev;
447         int               master;
448
449         /* true when the client has asked us to expose stereo 3D mode flags */
450         bool stereo_allowed;
451         /*
452          * true if client understands CRTC primary planes and cursor planes
453          * in the plane list
454          */
455         unsigned universal_planes:1;
456         /* true if client understands atomic properties */
457         unsigned atomic:1;
458
459         pid_t             pid;
460         uid_t             uid;
461         drm_magic_t       magic;
462         unsigned long     ioctl_count;
463         struct list_head lhead;
464         struct kqinfo     dkq;
465
466         /** Mapping of mm object handles to object pointers. */
467         struct idr object_idr;
468         /** Lock for synchronization of access to object_idr. */
469         struct lock table_lock;
470
471         void *driver_priv;
472
473         int               is_master;
474         struct drm_master *masterp;
475
476         /**
477          * fbs - List of framebuffers associated with this file.
478          *
479          * Protected by fbs_lock. Note that the fbs list holds a reference on
480          * the fb object to prevent it from untimely disappearing.
481          */
482         struct list_head fbs;
483         struct lock fbs_lock;
484
485         /** User-created blob properties; this retains a reference on the
486          *  property. */
487         struct list_head blobs;
488
489         wait_queue_head_t event_wait;
490         struct list_head pending_event_list;
491         struct list_head event_list;
492         int event_space;
493
494         struct lock event_read_lock;
495
496         struct drm_prime_file_private prime;
497 };
498
499 /**
500  * Lock data.
501  */
502 struct drm_lock_data {
503         struct drm_hw_lock *hw_lock;    /**< Hardware lock */
504         /** Private of lock holder's file (NULL=kernel) */
505         struct drm_file *file_priv;
506         wait_queue_head_t lock_queue;   /**< Queue of blocked processes */
507         unsigned long lock_time;        /**< Time of last lock in jiffies */
508 };
509
510 /**
511  * GEM specific mm private for tracking GEM objects
512  */
513 struct drm_gem_mm {
514         struct drm_vma_offset_manager vma_manager;
515         struct drm_mm offset_manager;   /**< Offset mgmt for buffer objects */
516         struct drm_open_hash offset_hash; /**< User token hash table for maps */
517         struct unrhdr *idxunr;
518 };
519
520 /**
521  * struct drm_master - drm master structure
522  *
523  * @refcount: Refcount for this master object.
524  * @minor: Link back to minor char device we are master for. Immutable.
525  * @unique: Unique identifier: e.g. busid. Protected by drm_global_mutex.
526  * @unique_len: Length of unique field. Protected by drm_global_mutex.
527  * @unique_size: Amount allocated. Protected by drm_global_mutex.
528  * @magiclist: Hash of used authentication tokens. Protected by struct_mutex.
529  * @magicfree: List of used authentication tokens. Protected by struct_mutex.
530  * @lock: DRI lock information.
531  * @driver_priv: Pointer to driver-private information.
532  */
533 struct drm_master {
534         struct kref refcount;           /* refcount for this master */
535         struct list_head head;          /**< each minor contains a list of masters */
536         struct drm_minor *minor;        /**< link back to minor we are a master for */
537         char *unique;                   /**< Unique identifier: e.g., busid */
538         int unique_len;                 /**< Length of unique field */
539         int unique_size;                /**< amount allocated */
540         int blocked;                    /**< Blocked due to VC switch? */
541         struct drm_open_hash magiclist;
542         struct list_head magicfree;
543         struct drm_lock_data lock;
544         void *driver_priv;
545 };
546
547 /* Size of ringbuffer for vblank timestamps. Just double-buffer
548  * in initial implementation.
549  */
550 #define DRM_VBLANKTIME_RBSIZE 2
551
552 /* Flags and return codes for get_vblank_timestamp() driver function. */
553 #define DRM_CALLED_FROM_VBLIRQ 1
554 #define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
555 #define DRM_VBLANKTIME_IN_VBLANK         (1 << 1)
556
557 /* get_scanout_position() return flags */
558 #define DRM_SCANOUTPOS_VALID        (1 << 0)
559 #define DRM_SCANOUTPOS_IN_VBLANK    (1 << 1)
560 #define DRM_SCANOUTPOS_ACCURATE     (1 << 2)
561
562 /**
563  * DRM driver structure. This structure represent the common code for
564  * a family of cards. There will one drm_device for each card present
565  * in this family
566  */
567 struct drm_driver {
568         int (*load) (struct drm_device *, unsigned long flags);
569         int (*use_msi) (struct drm_device *, unsigned long flags);
570         int (*firstopen) (struct drm_device *);
571         int (*open) (struct drm_device *, struct drm_file *);
572         void (*preclose) (struct drm_device *, struct drm_file *file_priv);
573         void (*postclose) (struct drm_device *, struct drm_file *);
574         void (*lastclose) (struct drm_device *);
575         int (*unload) (struct drm_device *);
576         void (*reclaim_buffers_locked) (struct drm_device *,
577                                         struct drm_file *file_priv);
578         int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
579         int (*dma_quiescent) (struct drm_device *);
580         int (*context_ctor) (struct drm_device *dev, int context);
581         int (*context_dtor) (struct drm_device *dev, int context);
582
583         /**
584          * get_vblank_counter - get raw hardware vblank counter
585          * @dev: DRM device
586          * @pipe: counter to fetch
587          *
588          * Driver callback for fetching a raw hardware vblank counter for @crtc.
589          * If a device doesn't have a hardware counter, the driver can simply
590          * return the value of drm_vblank_count. The DRM core will account for
591          * missed vblank events while interrupts where disabled based on system
592          * timestamps.
593          *
594          * Wraparound handling and loss of events due to modesetting is dealt
595          * with in the DRM core code.
596          *
597          * RETURNS
598          * Raw vblank counter value.
599          */
600         u32 (*get_vblank_counter) (struct drm_device *dev, unsigned int pipe);
601
602         /**
603          * enable_vblank - enable vblank interrupt events
604          * @dev: DRM device
605          * @pipe: which irq to enable
606          *
607          * Enable vblank interrupts for @crtc.  If the device doesn't have
608          * a hardware vblank counter, this routine should be a no-op, since
609          * interrupts will have to stay on to keep the count accurate.
610          *
611          * RETURNS
612          * Zero on success, appropriate errno if the given @crtc's vblank
613          * interrupt cannot be enabled.
614          */
615         int (*enable_vblank) (struct drm_device *dev, unsigned int pipe);
616
617         /**
618          * disable_vblank - disable vblank interrupt events
619          * @dev: DRM device
620          * @pipe: which irq to enable
621          *
622          * Disable vblank interrupts for @crtc.  If the device doesn't have
623          * a hardware vblank counter, this routine should be a no-op, since
624          * interrupts will have to stay on to keep the count accurate.
625          */
626         void (*disable_vblank) (struct drm_device *dev, unsigned int pipe);
627
628         /**
629          * Called by \c drm_device_is_agp.  Typically used to determine if a
630          * card is really attached to AGP or not.
631          *
632          * \param dev  DRM device handle
633          *
634          * \returns
635          * One of three values is returned depending on whether or not the
636          * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
637          * (return of 1), or may or may not be AGP (return of 2).
638          */
639         int (*device_is_agp) (struct drm_device *dev);
640
641         /**
642          * Called by vblank timestamping code.
643          *
644          * Return the current display scanout position from a crtc, and an
645          * optional accurate ktime_get timestamp of when position was measured.
646          *
647          * \param dev  DRM device.
648          * \param pipe Id of the crtc to query.
649          * \param flags Flags from the caller (DRM_CALLED_FROM_VBLIRQ or 0).
650          * \param *vpos Target location for current vertical scanout position.
651          * \param *hpos Target location for current horizontal scanout position.
652          * \param *stime Target location for timestamp taken immediately before
653          *               scanout position query. Can be NULL to skip timestamp.
654          * \param *etime Target location for timestamp taken immediately after
655          *               scanout position query. Can be NULL to skip timestamp.
656          *
657          * Returns vpos as a positive number while in active scanout area.
658          * Returns vpos as a negative number inside vblank, counting the number
659          * of scanlines to go until end of vblank, e.g., -1 means "one scanline
660          * until start of active scanout / end of vblank."
661          *
662          * \return Flags, or'ed together as follows:
663          *
664          * DRM_SCANOUTPOS_VALID = Query successful.
665          * DRM_SCANOUTPOS_INVBL = Inside vblank.
666          * DRM_SCANOUTPOS_ACCURATE = Returned position is accurate. A lack of
667          * this flag means that returned position may be offset by a constant
668          * but unknown small number of scanlines wrt. real scanout position.
669          *
670          */
671         int (*get_scanout_position) (struct drm_device *dev, unsigned int pipe,
672                                      unsigned int flags, int *vpos, int *hpos,
673                                      ktime_t *stime, ktime_t *etime,
674                                      const struct drm_display_mode *mode);
675
676         /**
677          * Called by \c drm_get_last_vbltimestamp. Should return a precise
678          * timestamp when the most recent VBLANK interval ended or will end.
679          *
680          * Specifically, the timestamp in @vblank_time should correspond as
681          * closely as possible to the time when the first video scanline of
682          * the video frame after the end of VBLANK will start scanning out,
683          * the time immediately after end of the VBLANK interval. If the
684          * @crtc is currently inside VBLANK, this will be a time in the future.
685          * If the @crtc is currently scanning out a frame, this will be the
686          * past start time of the current scanout. This is meant to adhere
687          * to the OpenML OML_sync_control extension specification.
688          *
689          * \param dev dev DRM device handle.
690          * \param pipe crtc for which timestamp should be returned.
691          * \param *max_error Maximum allowable timestamp error in nanoseconds.
692          *                   Implementation should strive to provide timestamp
693          *                   with an error of at most *max_error nanoseconds.
694          *                   Returns true upper bound on error for timestamp.
695          * \param *vblank_time Target location for returned vblank timestamp.
696          * \param flags 0 = Defaults, no special treatment needed.
697          * \param       DRM_CALLED_FROM_VBLIRQ = Function is called from vblank
698          *              irq handler. Some drivers need to apply some workarounds
699          *              for gpu-specific vblank irq quirks if flag is set.
700          *
701          * \returns
702          * Zero if timestamping isn't supported in current display mode or a
703          * negative number on failure. A positive status code on success,
704          * which describes how the vblank_time timestamp was computed.
705          */
706         int (*get_vblank_timestamp) (struct drm_device *dev, unsigned int pipe,
707                                      int *max_error,
708                                      struct timeval *vblank_time,
709                                      unsigned flags);
710
711         /* these have to be filled in */
712
713         void (*irq_handler) (void *arg);
714         void (*irq_preinstall) (struct drm_device *dev);
715         int (*irq_postinstall) (struct drm_device *dev);
716         void (*irq_uninstall) (struct drm_device *dev);
717
718         /**
719          * Driver-specific constructor for drm_gem_objects, to set up
720          * obj->driver_private.
721          *
722          * Returns 0 on success.
723          */
724         void (*gem_free_object) (struct drm_gem_object *obj);
725         int (*gem_open_object) (struct drm_gem_object *, struct drm_file *);
726         void (*gem_close_object) (struct drm_gem_object *, struct drm_file *);
727
728         int (*sysctl_init) (struct drm_device *dev,
729                     struct sysctl_ctx_list *ctx, struct sysctl_oid *top);
730         void (*sysctl_cleanup) (struct drm_device *dev);
731
732         drm_pci_id_list_t *id_entry;    /* PCI ID, name, and chipset private */
733
734         /* dumb alloc support */
735         int (*dumb_create)(struct drm_file *file_priv,
736                            struct drm_device *dev,
737                            struct drm_mode_create_dumb *args);
738         int (*dumb_map_offset)(struct drm_file *file_priv,
739                                struct drm_device *dev, uint32_t handle,
740                                uint64_t *offset);
741         int (*dumb_destroy)(struct drm_file *file_priv,
742                             struct drm_device *dev,
743                             uint32_t handle);
744
745         /* Driver private ops for this object */
746         struct cdev_pager_ops *gem_pager_ops;
747
748         int major;
749         int minor;
750         int patchlevel;
751         const char *name;               /* Simple driver name              */
752         const char *desc;               /* Longer driver name              */
753         const char *date;               /* Date of last major changes.     */
754
755         u32 driver_features;
756         int dev_priv_size;
757         const struct drm_ioctl_desc *ioctls;
758         int num_ioctls;
759 };
760
761 /**
762  * Info file list entry. This structure represents a debugfs or proc file to
763  * be created by the drm core
764  */
765 struct drm_info_list {
766         const char *name; /** file name */
767         int (*show)(struct seq_file*, void*); /** show callback */
768         u32 driver_features; /**< Required driver features for this entry */
769         void *data;
770 };
771
772 /**
773  * debugfs node structure. This structure represents a debugfs file.
774  */
775 struct drm_info_node {
776         struct list_head list;
777         struct drm_minor *minor;
778         const struct drm_info_list *info_ent;
779         struct dentry *dent;
780 };
781
782 /**
783  * DRM minor structure. This structure represents a drm minor number.
784  */
785 struct drm_minor {
786         int index;                      /**< Minor device number */
787         int type;                       /**< Control or render */
788         device_t kdev;                  /**< OS device */
789         struct drm_device *dev;
790
791         /* currently active master for this node. Protected by master_mutex */
792         struct drm_master *master;
793 };
794
795 struct drm_pending_vblank_event {
796         struct drm_pending_event base;
797         unsigned int pipe;
798         struct drm_event_vblank event;
799 };
800
801 struct drm_vblank_crtc {
802         struct drm_device *dev;         /* pointer to the drm_device */
803         wait_queue_head_t queue;        /**< VBLANK wait queue */
804         struct timer_list disable_timer;                /* delayed disable timer */
805
806         /* vblank counter, protected by dev->vblank_time_lock for writes */
807         u32 count;
808         /* vblank timestamps, protected by dev->vblank_time_lock for writes */
809         struct timeval time[DRM_VBLANKTIME_RBSIZE];
810
811         atomic_t refcount;              /* number of users of vblank interruptsper crtc */
812         u32 last;                       /* protected by dev->vbl_lock, used */
813                                         /* for wraparound handling */
814         u32 last_wait;                  /* Last vblank seqno waited per CRTC */
815         unsigned int inmodeset;         /* Display driver is setting mode */
816         unsigned int pipe;              /* crtc index */
817         int framedur_ns;                /* frame/field duration in ns */
818         int linedur_ns;                 /* line duration in ns */
819         int pixeldur_ns;                /* pixel duration in ns */
820         bool enabled;                   /* so we don't call enable more than
821                                            once per disable */
822 };
823
824 struct drm_sysctl_info {
825         struct sysctl_ctx_list ctx;
826         char   name[2];
827 };
828
829 /* Length for the array of resource pointers for drm_get_resource_*. */
830 #define DRM_MAX_PCI_RESOURCE    6
831
832 /**
833  * DRM device structure. This structure represent a complete card that
834  * may contain multiple heads.
835  */
836 struct drm_device {
837         drm_pci_id_list_t *id_entry;    /* PCI ID, name, and chipset private */
838
839         char              *unique;      /* Unique identifier: e.g., busid  */
840         int               unique_len;   /* Length of unique field          */
841         struct cdev       *devnode;     /* Device number for mknod         */
842         int               if_version;   /* Highest interface version set */
843
844         int               flags;        /* Flags to open(2)                */
845
846                                 /* Locks */
847         struct spinlock   dma_lock;     /* protects dev->dma */
848         struct lwkt_serialize irq_lock; /* protects irq condition checks */
849         struct lock       dev_lock;     /* protects everything else */
850
851         /** \name Locks */
852         /*@{ */
853         struct lock struct_mutex;       /**< For others */
854         struct lock master_mutex;       /**< For drm_minor::master */
855         /*@} */
856
857         /** \name Usage Counters */
858         /*@{ */
859         int open_count;                 /**< Outstanding files open, protected by drm_global_mutex. */
860         struct spinlock buf_lock;       /**< For drm_device::buf_use and a few other things. */
861         int buf_use;                    /**< Buffers in use -- cannot alloc */
862         atomic_t buf_alloc;             /**< Buffer allocation in progress */
863         /*@} */
864
865
866         /** \name Performance counters */
867         /*@{ */
868         unsigned long     counters;
869         enum drm_stat_type      types[15];
870         atomic_t          counts[15];
871         /*@} */
872
873                                 /* Authentication */
874         struct drm_open_hash magiclist; /**< magic hash table */
875         struct list_head magicfree;
876
877         struct list_head filelist;
878
879         /** \name Memory management */
880         /*@{ */
881         struct list_head maplist;       /**< Linked list of regions */
882         int map_count;                  /**< Number of mappable regions */
883         struct drm_open_hash map_hash;  /**< User token hash table for maps */
884
885         /** \name Context handle management */
886         /*@{ */
887         struct list_head ctxlist;       /**< Linked list of context handles */
888         int ctx_count;                  /**< Number of context handles */
889         struct lock ctxlist_mutex;      /**< For ctxlist */
890
891         struct idr ctx_idr;
892
893         /*@} */
894
895         struct drm_lock_data lock;      /* Information on hardware lock    */
896
897         /** \name DMA support */
898         /*@{ */
899         struct drm_device_dma *dma;             /**< Optional pointer for DMA support */
900         /*@} */
901
902         int               irq_type;     /* IRQ type (MSI enabled or not) */
903         int               irqrid;       /* Interrupt used by board */
904         struct resource   *irqr;        /* Resource for interrupt used by board    */
905         void              *irqh;        /* Handle from bus_setup_intr      */
906
907         /* Storage of resource pointers for drm_get_resource_* */
908         struct resource   *pcir[DRM_MAX_PCI_RESOURCE];
909         int               pcirid[DRM_MAX_PCI_RESOURCE];
910
911         int               pci_domain;
912         int               pci_bus;
913         int               pci_slot;
914         int               pci_func;
915
916         /** \name Context support */
917         /*@{ */
918
919         __volatile__ long context_flag; /**< Context swapping flag */
920         __volatile__ long interrupt_flag; /**< Interruption handler flag */
921         __volatile__ long dma_flag;     /**< DMA dispatch flag */
922         wait_queue_head_t context_wait; /**< Processes waiting on ctx switch */
923         int last_checked;               /**< Last context checked for DMA */
924         int last_context;               /**< Last current context */
925         unsigned long last_switch;      /**< jiffies at last context switch */
926         /*@} */
927
928         /** \name VBLANK IRQ support */
929         /*@{ */
930         int irq_enabled;                /**< True if irq handler is enabled */
931         int irq;                        /* Interrupt used by board */
932
933         /*
934          * At load time, disabling the vblank interrupt won't be allowed since
935          * old clients may not call the modeset ioctl and therefore misbehave.
936          * Once the modeset ioctl *has* been called though, we can safely
937          * disable them when unused.
938          */
939         bool vblank_disable_allowed;
940
941         /*
942          * If true, vblank interrupt will be disabled immediately when the
943          * refcount drops to zero, as opposed to via the vblank disable
944          * timer.
945          * This can be set to true it the hardware has a working vblank
946          * counter and the driver uses drm_vblank_on() and drm_vblank_off()
947          * appropriately.
948          */
949         bool vblank_disable_immediate;
950
951         /* array of size num_crtcs */
952         struct drm_vblank_crtc *vblank;
953
954         struct lock vblank_time_lock;    /**< Protects vblank count and time updates during vblank enable/disable */
955         struct lock vbl_lock;
956         struct timer_list vblank_disable_timer;
957
958         u32 max_vblank_count;           /**< size of vblank counter register */
959
960         /**
961          * List of events
962          */
963         struct list_head vblank_event_list;
964         struct lock event_lock;
965
966         /*@} */
967
968         struct sigio      *buf_sigio;   /* Processes waiting for SIGIO     */
969
970                                 /* Sysctl support */
971         struct drm_sysctl_info *sysctl;
972
973
974         struct drm_sg_mem *sg;  /**< Scatter gather memory */
975         unsigned int num_crtcs;                  /**< Number of CRTCs on this device */
976
977         unsigned long     *ctx_bitmap;
978         void              *dev_private;
979
980         void              *drm_ttm_bdev;
981
982         /*@} */
983
984         struct drm_agp_head *agp;       /**< AGP data */
985
986         struct device *dev;             /**< Device structure */
987         struct pci_dev *pdev;           /**< PCI device structure */
988
989         struct drm_driver *driver;
990         struct drm_local_map *agp_buffer_map;
991         unsigned int agp_buffer_token;
992         struct drm_minor *control;              /**< Control node for card */
993         struct drm_minor *primary;              /**< render type primary screen head */
994
995         struct drm_mode_config mode_config;     /**< Current mode config */
996
997         /** \name GEM information */
998         /*@{ */
999         struct lock object_name_lock;
1000         struct idr object_name_idr;
1001         /*@} */
1002         void             *mm_private;
1003
1004         void *sysctl_private;
1005         char busid_str[128];
1006         int modesetting;
1007
1008         int switch_power_state;
1009
1010         atomic_t unplugged; /* device has been unplugged or gone away */
1011 };
1012
1013 #define DRM_SWITCH_POWER_ON 0
1014 #define DRM_SWITCH_POWER_OFF 1
1015 #define DRM_SWITCH_POWER_CHANGING 2
1016 #define DRM_SWITCH_POWER_DYNAMIC_OFF 3
1017
1018 static __inline__ int drm_core_check_feature(struct drm_device *dev,
1019                                              int feature)
1020 {
1021         return ((dev->driver->driver_features & feature) ? 1 : 0);
1022 }
1023
1024 static inline void drm_device_set_unplugged(struct drm_device *dev)
1025 {
1026         smp_wmb();
1027         atomic_set(&dev->unplugged, 1);
1028 }
1029
1030 static inline int drm_device_is_unplugged(struct drm_device *dev)
1031 {
1032         int ret = atomic_read(&dev->unplugged);
1033         smp_rmb();
1034         return ret;
1035 }
1036
1037 static inline bool drm_is_primary_client(const struct drm_file *file_priv)
1038 {
1039         return 0 /* file_priv->minor->type == DRM_MINOR_LEGACY */;
1040 }
1041
1042 /**
1043  * drm_is_master() - Check whether a DRM open-file is DRM-Master
1044  * @file: DRM open-file context
1045  *
1046  * This checks whether a DRM open-file context is owner of the master context
1047  * attached to it. If a file owns a master context, it's called DRM-Master.
1048  * Per DRM device, only one such file can be DRM-Master at a time.
1049  *
1050  * Returns: True if the file is DRM-Master, otherwise false.
1051  */
1052 static inline bool drm_is_master(const struct drm_file *file)
1053 {
1054 #if 0
1055         return file->master && file->master == file->minor->master;
1056 #else
1057         return true;
1058 #endif
1059 }
1060
1061 /******************************************************************/
1062 /** \name Internal function definitions */
1063 /*@{*/
1064
1065                                 /* Driver support (drm_drv.h) */
1066 extern int drm_ioctl_permit(u32 flags, struct drm_file *file_priv);
1067 int     drm_probe(device_t kdev, drm_pci_id_list_t *idlist);
1068 int     drm_attach(device_t kdev, drm_pci_id_list_t *idlist);
1069 int     drm_create_cdevs(device_t kdev);
1070 d_ioctl_t drm_ioctl;
1071 extern bool drm_ioctl_flags(unsigned int nr, unsigned int *flags);
1072
1073                                 /* Device support (drm_fops.h) */
1074 d_open_t drm_open;
1075 d_close_t drm_close;
1076 d_read_t drm_read;
1077 d_kqfilter_t drm_kqfilter;
1078 int drm_release(device_t kdev);
1079
1080 d_mmap_t drm_mmap;
1081 d_mmap_single_t drm_mmap_single;
1082
1083 void drm_cdevpriv_dtor(void *cd);
1084
1085 int drm_add_busid_modesetting(struct drm_device *dev,
1086     struct sysctl_ctx_list *ctx, struct sysctl_oid *top);
1087
1088 /* File operations helpers (drm_fops.c) */
1089 extern int              drm_open_helper(struct cdev *kdev, int flags, int fmt,
1090                                          DRM_STRUCTPROC *p,
1091                                         struct drm_device *dev,
1092                                         struct file *fp);
1093 int drm_event_reserve_init_locked(struct drm_device *dev,
1094                                   struct drm_file *file_priv,
1095                                   struct drm_pending_event *p,
1096                                   struct drm_event *e);
1097 int drm_event_reserve_init(struct drm_device *dev,
1098                            struct drm_file *file_priv,
1099                            struct drm_pending_event *p,
1100                            struct drm_event *e);
1101 void drm_event_cancel_free(struct drm_device *dev,
1102                            struct drm_pending_event *p);
1103 void drm_send_event_locked(struct drm_device *dev, struct drm_pending_event *e);
1104 void drm_send_event(struct drm_device *dev, struct drm_pending_event *e);
1105
1106 /* Misc. IOCTL support (drm_ioctl.c) */
1107 int drm_noop(struct drm_device *dev, void *data,
1108              struct drm_file *file_priv);
1109 int drm_invalid_op(struct drm_device *dev, void *data,
1110                    struct drm_file *file_priv);
1111
1112 /* Cache management (drm_cache.c) */
1113 void drm_clflush_pages(struct vm_page *pages[], unsigned long num_pages);
1114 void drm_clflush_sg(struct sg_table *st);
1115 void drm_clflush_virt_range(void *addr, unsigned long length);
1116
1117 /*
1118  * These are exported to drivers so that they can implement fencing using
1119  * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
1120  */
1121
1122 unsigned long drm_get_resource_start(struct drm_device *dev,
1123                                      unsigned int resource);
1124 unsigned long drm_get_resource_len(struct drm_device *dev,
1125                                    unsigned int resource);
1126
1127                                 /* IRQ support (drm_irq.h) */
1128 extern int drm_irq_install(struct drm_device *dev, int irq);
1129 extern int drm_irq_uninstall(struct drm_device *dev);
1130
1131 extern int drm_vblank_init(struct drm_device *dev, unsigned int num_crtcs);
1132 extern int drm_wait_vblank(struct drm_device *dev, void *data,
1133                            struct drm_file *filp);
1134 extern u32 drm_vblank_count(struct drm_device *dev, unsigned int pipe);
1135 extern u32 drm_crtc_vblank_count(struct drm_crtc *crtc);
1136 extern u32 drm_vblank_count_and_time(struct drm_device *dev, unsigned int pipe,
1137                                      struct timeval *vblanktime);
1138 extern u32 drm_crtc_vblank_count_and_time(struct drm_crtc *crtc,
1139                                           struct timeval *vblanktime);
1140 extern void drm_send_vblank_event(struct drm_device *dev, unsigned int pipe,
1141                                   struct drm_pending_vblank_event *e);
1142 extern void drm_crtc_send_vblank_event(struct drm_crtc *crtc,
1143                                        struct drm_pending_vblank_event *e);
1144 extern void drm_arm_vblank_event(struct drm_device *dev, unsigned int pipe,
1145                                  struct drm_pending_vblank_event *e);
1146 extern void drm_crtc_arm_vblank_event(struct drm_crtc *crtc,
1147                                       struct drm_pending_vblank_event *e);
1148 extern bool drm_handle_vblank(struct drm_device *dev, unsigned int pipe);
1149 extern bool drm_crtc_handle_vblank(struct drm_crtc *crtc);
1150 extern int drm_vblank_get(struct drm_device *dev, unsigned int pipe);
1151 extern void drm_vblank_put(struct drm_device *dev, unsigned int pipe);
1152 extern int drm_crtc_vblank_get(struct drm_crtc *crtc);
1153 extern void drm_crtc_vblank_put(struct drm_crtc *crtc);
1154 extern void drm_wait_one_vblank(struct drm_device *dev, unsigned int pipe);
1155 extern void drm_crtc_wait_one_vblank(struct drm_crtc *crtc);
1156 extern void drm_vblank_off(struct drm_device *dev, unsigned int pipe);
1157 extern void drm_vblank_on(struct drm_device *dev, unsigned int pipe);
1158 extern void drm_crtc_vblank_off(struct drm_crtc *crtc);
1159 extern void drm_crtc_vblank_reset(struct drm_crtc *crtc);
1160 extern void drm_crtc_vblank_on(struct drm_crtc *crtc);
1161 extern void drm_vblank_cleanup(struct drm_device *dev);
1162 extern u32 drm_vblank_no_hw_counter(struct drm_device *dev, unsigned int pipe);
1163
1164 extern int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
1165                                                  unsigned int pipe, int *max_error,
1166                                                  struct timeval *vblank_time,
1167                                                  unsigned flags,
1168                                                  const struct drm_display_mode *mode);
1169 extern void drm_calc_timestamping_constants(struct drm_crtc *crtc,
1170                                             const struct drm_display_mode *mode);
1171
1172 /**
1173  * drm_crtc_vblank_waitqueue - get vblank waitqueue for the CRTC
1174  * @crtc: which CRTC's vblank waitqueue to retrieve
1175  *
1176  * This function returns a pointer to the vblank waitqueue for the CRTC.
1177  * Drivers can use this to implement vblank waits using wait_event() & co.
1178  */
1179 static inline wait_queue_head_t *drm_crtc_vblank_waitqueue(struct drm_crtc *crtc)
1180 {
1181         return &crtc->dev->vblank[drm_crtc_index(crtc)].queue;
1182 }
1183
1184 /* Modesetting support */
1185 extern void drm_vblank_pre_modeset(struct drm_device *dev, unsigned int pipe);
1186 extern void drm_vblank_post_modeset(struct drm_device *dev, unsigned int pipe);
1187
1188                                 /* Stub support (drm_stub.h) */
1189
1190 extern void drm_put_dev(struct drm_device *dev);
1191 extern void drm_unplug_dev(struct drm_device *dev);
1192 extern unsigned int drm_debug;
1193 extern bool drm_atomic;
1194
1195 /* consistent PCI memory functions (drm_pci.c) */
1196 extern struct drm_dma_handle *drm_pci_alloc(struct drm_device *dev, size_t size,
1197                                             size_t align);
1198 extern void drm_pci_free(struct drm_device *dev, struct drm_dma_handle * dmah);
1199
1200                                /* sysfs support (drm_sysfs.c) */
1201 extern void drm_sysfs_hotplug_event(struct drm_device *dev);
1202
1203 /* sysctl support (drm_sysctl.h) */
1204 extern int drm_sysctl_init(struct drm_device *dev);
1205 extern int drm_sysctl_cleanup(struct drm_device *dev);
1206
1207 /* XXX: These are here only because of drm_sysctl.c */
1208 extern int drm_vblank_offdelay;
1209 extern unsigned int drm_timestamp_precision;
1210
1211 int drm_gem_mmap_single(struct drm_device *dev, vm_ooffset_t *offset,
1212     vm_size_t size, struct vm_object **obj_res, int nprot);
1213
1214 struct ttm_bo_device;
1215 int ttm_bo_mmap_single(struct ttm_bo_device *bdev, vm_ooffset_t *offset,
1216     vm_size_t size, struct vm_object **obj_res, int nprot);
1217 struct ttm_buffer_object;
1218 void ttm_bo_release_mmap(struct ttm_buffer_object *bo);
1219
1220 /* simplified version of kvasnrprintf() for drm needs. */
1221 char *drm_vasprintf(int flags, const char *format, __va_list ap) __printflike(2, 0);
1222 char *drm_asprintf(int flags, const char *format, ...) __printflike(2, 3);
1223
1224 /* XXX glue logic, should be done in drm_pci_init(), pending drm update */
1225 void drm_init_pdev(device_t dev, struct pci_dev **pdev);
1226 void drm_fini_pdev(struct pci_dev **pdev);
1227 void drm_print_pdev(struct pci_dev *pdev);
1228
1229 /* Inline drm_free() helper for area kfree() */
1230 static __inline__ void
1231 drm_free(void *pt, struct malloc_type *area)
1232 {
1233         /* kfree is special!!! */
1234         if (pt != NULL)
1235                 (kfree)(pt, area);
1236 }
1237
1238 struct drm_device *drm_dev_alloc(struct drm_driver *driver,
1239                                  struct device *parent);
1240 void drm_dev_ref(struct drm_device *dev);
1241 void drm_dev_unref(struct drm_device *dev);
1242 int drm_dev_register(struct drm_device *dev, unsigned long flags);
1243 void drm_dev_unregister(struct drm_device *dev);
1244 int drm_dev_set_unique(struct drm_device *dev, const char *fmt, ...);
1245
1246
1247 /* PCI section */
1248 static __inline__ int drm_pci_device_is_agp(struct drm_device *dev)
1249 {
1250         if (dev->driver->device_is_agp != NULL) {
1251                 int err = (*dev->driver->device_is_agp) (dev);
1252
1253                 if (err != 2) {
1254                         return err;
1255                 }
1256         }
1257
1258         return (pci_find_extcap(dev->pdev->dev.bsddev, PCIY_AGP, NULL) == 0);
1259 }
1260
1261 #define DRM_PCIE_SPEED_25 1
1262 #define DRM_PCIE_SPEED_50 2
1263 #define DRM_PCIE_SPEED_80 4
1264
1265 extern int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *speed_mask);
1266
1267 /* XXX bad */
1268 #define drm_can_sleep() (HZ & 1)
1269
1270 #endif /* __KERNEL__ */
1271
1272 /* helper for handling conditionals in various for_each macros */
1273 #define for_each_if(condition) if (!(condition)) {} else
1274
1275 #endif /* _DRM_P_H_ */