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