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