1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32#ifndef _DRM_P_H_
33#define _DRM_P_H_
34
35#include <linux/agp_backend.h>
36#include <linux/cdev.h>
37#include <linux/dma-mapping.h>
38#include <linux/file.h>
39#include <linux/fs.h>
40#include <linux/highmem.h>
41#include <linux/idr.h>
42#include <linux/init.h>
43#include <linux/io.h>
44#include <linux/jiffies.h>
45#include <linux/kernel.h>
46#include <linux/kref.h>
47#include <linux/miscdevice.h>
48#include <linux/mm.h>
49#include <linux/mutex.h>
50#include <linux/pci.h>
51#include <linux/platform_device.h>
52#include <linux/poll.h>
53#include <linux/ratelimit.h>
54#include <linux/sched.h>
55#include <linux/slab.h>
56#include <linux/types.h>
57#include <linux/vmalloc.h>
58#include <linux/workqueue.h>
59
60#include <asm/mman.h>
61#include <asm/pgalloc.h>
62#include <asm/uaccess.h>
63
64#include <uapi/drm/drm.h>
65#include <uapi/drm/drm_mode.h>
66
67#include <drm/drm_agpsupport.h>
68#include <drm/drm_crtc.h>
69#include <drm/drm_global.h>
70#include <drm/drm_hashtab.h>
71#include <drm/drm_mem_util.h>
72#include <drm/drm_mm.h>
73#include <drm/drm_os_linux.h>
74#include <drm/drm_sarea.h>
75#include <drm/drm_vma_manager.h>
76
77struct module;
78
79struct drm_file;
80struct drm_device;
81struct drm_agp_head;
82struct drm_local_map;
83struct drm_device_dma;
84struct drm_dma_handle;
85struct drm_gem_object;
86
87struct device_node;
88struct videomode;
89struct reservation_object;
90struct dma_buf_attachment;
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126#define DRM_UT_CORE 0x01
127#define DRM_UT_DRIVER 0x02
128#define DRM_UT_KMS 0x04
129#define DRM_UT_PRIME 0x08
130#define DRM_UT_ATOMIC 0x10
131#define DRM_UT_VBL 0x20
132
133extern __printf(2, 3)
134void drm_ut_debug_printk(const char *function_name,
135 const char *format, ...);
136extern __printf(1, 2)
137void drm_err(const char *format, ...);
138
139
140
141
142
143
144#define DRIVER_USE_AGP 0x1
145#define DRIVER_PCI_DMA 0x8
146#define DRIVER_SG 0x10
147#define DRIVER_HAVE_DMA 0x20
148#define DRIVER_HAVE_IRQ 0x40
149#define DRIVER_IRQ_SHARED 0x80
150#define DRIVER_GEM 0x1000
151#define DRIVER_MODESET 0x2000
152#define DRIVER_PRIME 0x4000
153#define DRIVER_RENDER 0x8000
154#define DRIVER_ATOMIC 0x10000
155#define DRIVER_KMS_LEGACY_CONTEXT 0x20000
156
157
158
159
160
161
162
163
164
165
166
167#define DRM_ERROR(fmt, ...) \
168 drm_err(fmt, ##__VA_ARGS__)
169
170
171
172
173
174
175
176#define DRM_ERROR_RATELIMITED(fmt, ...) \
177({ \
178 static DEFINE_RATELIMIT_STATE(_rs, \
179 DEFAULT_RATELIMIT_INTERVAL, \
180 DEFAULT_RATELIMIT_BURST); \
181 \
182 if (__ratelimit(&_rs)) \
183 drm_err(fmt, ##__VA_ARGS__); \
184})
185
186#define DRM_INFO(fmt, ...) \
187 printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
188
189#define DRM_INFO_ONCE(fmt, ...) \
190 printk_once(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
191
192
193
194
195
196
197
198#define DRM_DEBUG(fmt, args...) \
199 do { \
200 if (unlikely(drm_debug & DRM_UT_CORE)) \
201 drm_ut_debug_printk(__func__, fmt, ##args); \
202 } while (0)
203
204#define DRM_DEBUG_DRIVER(fmt, args...) \
205 do { \
206 if (unlikely(drm_debug & DRM_UT_DRIVER)) \
207 drm_ut_debug_printk(__func__, fmt, ##args); \
208 } while (0)
209#define DRM_DEBUG_KMS(fmt, args...) \
210 do { \
211 if (unlikely(drm_debug & DRM_UT_KMS)) \
212 drm_ut_debug_printk(__func__, fmt, ##args); \
213 } while (0)
214#define DRM_DEBUG_PRIME(fmt, args...) \
215 do { \
216 if (unlikely(drm_debug & DRM_UT_PRIME)) \
217 drm_ut_debug_printk(__func__, fmt, ##args); \
218 } while (0)
219#define DRM_DEBUG_ATOMIC(fmt, args...) \
220 do { \
221 if (unlikely(drm_debug & DRM_UT_ATOMIC)) \
222 drm_ut_debug_printk(__func__, fmt, ##args); \
223 } while (0)
224#define DRM_DEBUG_VBL(fmt, args...) \
225 do { \
226 if (unlikely(drm_debug & DRM_UT_VBL)) \
227 drm_ut_debug_printk(__func__, fmt, ##args); \
228 } while (0)
229
230
231
232
233
234
235
236#define DRM_IF_VERSION(maj, min) (maj << 16 | min)
237
238
239
240
241
242
243
244
245
246typedef int drm_ioctl_t(struct drm_device *dev, void *data,
247 struct drm_file *file_priv);
248
249typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
250 unsigned long arg);
251
252#define DRM_IOCTL_NR(n) _IOC_NR(n)
253#define DRM_MAJOR 226
254
255#define DRM_AUTH 0x1
256#define DRM_MASTER 0x2
257#define DRM_ROOT_ONLY 0x4
258#define DRM_CONTROL_ALLOW 0x8
259#define DRM_UNLOCKED 0x10
260#define DRM_RENDER_ALLOW 0x20
261
262struct drm_ioctl_desc {
263 unsigned int cmd;
264 int flags;
265 drm_ioctl_t *func;
266 const char *name;
267};
268
269
270
271
272
273
274#define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags) \
275 [DRM_IOCTL_NR(DRM_IOCTL_##ioctl) - DRM_COMMAND_BASE] = { \
276 .cmd = DRM_IOCTL_##ioctl, \
277 .func = _func, \
278 .flags = _flags, \
279 .name = #ioctl \
280 }
281
282
283struct drm_pending_event {
284 struct drm_event *event;
285 struct list_head link;
286 struct list_head pending_link;
287 struct drm_file *file_priv;
288 pid_t pid;
289
290 void (*destroy)(struct drm_pending_event *event);
291};
292
293
294struct drm_prime_file_private {
295 struct list_head head;
296 struct mutex lock;
297};
298
299
300struct drm_file {
301 unsigned authenticated :1;
302
303 unsigned is_master :1;
304
305 unsigned stereo_allowed :1;
306
307
308
309
310 unsigned universal_planes:1;
311
312 unsigned atomic:1;
313
314
315
316
317 unsigned allowed_master:1;
318
319 struct pid *pid;
320 kuid_t uid;
321 drm_magic_t magic;
322 struct list_head lhead;
323 struct drm_minor *minor;
324 unsigned long lock_count;
325
326
327 struct idr object_idr;
328
329 spinlock_t table_lock;
330
331 struct file *filp;
332 void *driver_priv;
333
334 struct drm_master *master;
335
336
337
338
339
340
341
342 struct list_head fbs;
343 struct mutex fbs_lock;
344
345
346
347 struct list_head blobs;
348
349 wait_queue_head_t event_wait;
350 struct list_head pending_event_list;
351 struct list_head event_list;
352 int event_space;
353
354 struct mutex event_read_lock;
355
356 struct drm_prime_file_private prime;
357};
358
359
360
361
362struct drm_lock_data {
363 struct drm_hw_lock *hw_lock;
364
365 struct drm_file *file_priv;
366 wait_queue_head_t lock_queue;
367 unsigned long lock_time;
368 spinlock_t spinlock;
369 uint32_t kernel_waiters;
370 uint32_t user_waiters;
371 int idle_has_lock;
372};
373
374
375
376
377
378
379
380
381
382
383
384
385struct drm_master {
386 struct kref refcount;
387 struct drm_minor *minor;
388 char *unique;
389 int unique_len;
390 struct idr magic_map;
391 struct drm_lock_data lock;
392 void *driver_priv;
393};
394
395
396
397
398#define DRM_VBLANKTIME_RBSIZE 2
399
400
401#define DRM_CALLED_FROM_VBLIRQ 1
402#define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
403#define DRM_VBLANKTIME_IN_VBLANK (1 << 1)
404
405
406#define DRM_SCANOUTPOS_VALID (1 << 0)
407#define DRM_SCANOUTPOS_IN_VBLANK (1 << 1)
408#define DRM_SCANOUTPOS_ACCURATE (1 << 2)
409
410
411
412
413
414
415struct drm_driver {
416 int (*load) (struct drm_device *, unsigned long flags);
417 int (*firstopen) (struct drm_device *);
418 int (*open) (struct drm_device *, struct drm_file *);
419 void (*preclose) (struct drm_device *, struct drm_file *file_priv);
420 void (*postclose) (struct drm_device *, struct drm_file *);
421 void (*lastclose) (struct drm_device *);
422 int (*unload) (struct drm_device *);
423 int (*suspend) (struct drm_device *, pm_message_t state);
424 int (*resume) (struct drm_device *);
425 int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
426 int (*dma_quiescent) (struct drm_device *);
427 int (*context_dtor) (struct drm_device *dev, int context);
428 int (*set_busid)(struct drm_device *dev, struct drm_master *master);
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447 u32 (*get_vblank_counter) (struct drm_device *dev, unsigned int pipe);
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462 int (*enable_vblank) (struct drm_device *dev, unsigned int pipe);
463
464
465
466
467
468
469
470
471
472
473 void (*disable_vblank) (struct drm_device *dev, unsigned int pipe);
474
475
476
477
478
479
480
481
482
483
484
485
486 int (*device_is_agp) (struct drm_device *dev);
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519 int (*get_scanout_position) (struct drm_device *dev, unsigned int pipe,
520 unsigned int flags, int *vpos, int *hpos,
521 ktime_t *stime, ktime_t *etime,
522 const struct drm_display_mode *mode);
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554 int (*get_vblank_timestamp) (struct drm_device *dev, unsigned int pipe,
555 int *max_error,
556 struct timeval *vblank_time,
557 unsigned flags);
558
559
560
561 irqreturn_t(*irq_handler) (int irq, void *arg);
562 void (*irq_preinstall) (struct drm_device *dev);
563 int (*irq_postinstall) (struct drm_device *dev);
564 void (*irq_uninstall) (struct drm_device *dev);
565
566
567 int (*master_create)(struct drm_device *dev, struct drm_master *master);
568 void (*master_destroy)(struct drm_device *dev, struct drm_master *master);
569
570
571
572
573
574 int (*master_set)(struct drm_device *dev, struct drm_file *file_priv,
575 bool from_open);
576 void (*master_drop)(struct drm_device *dev, struct drm_file *file_priv,
577 bool from_release);
578
579 int (*debugfs_init)(struct drm_minor *minor);
580 void (*debugfs_cleanup)(struct drm_minor *minor);
581
582
583
584
585
586
587
588 void (*gem_free_object) (struct drm_gem_object *obj);
589 int (*gem_open_object) (struct drm_gem_object *, struct drm_file *);
590 void (*gem_close_object) (struct drm_gem_object *, struct drm_file *);
591
592
593
594
595
596 struct drm_gem_object *(*gem_create_object)(struct drm_device *dev,
597 size_t size);
598
599
600
601 int (*prime_handle_to_fd)(struct drm_device *dev, struct drm_file *file_priv,
602 uint32_t handle, uint32_t flags, int *prime_fd);
603
604 int (*prime_fd_to_handle)(struct drm_device *dev, struct drm_file *file_priv,
605 int prime_fd, uint32_t *handle);
606
607 struct dma_buf * (*gem_prime_export)(struct drm_device *dev,
608 struct drm_gem_object *obj, int flags);
609
610 struct drm_gem_object * (*gem_prime_import)(struct drm_device *dev,
611 struct dma_buf *dma_buf);
612
613 int (*gem_prime_pin)(struct drm_gem_object *obj);
614 void (*gem_prime_unpin)(struct drm_gem_object *obj);
615 struct reservation_object * (*gem_prime_res_obj)(
616 struct drm_gem_object *obj);
617 struct sg_table *(*gem_prime_get_sg_table)(struct drm_gem_object *obj);
618 struct drm_gem_object *(*gem_prime_import_sg_table)(
619 struct drm_device *dev,
620 struct dma_buf_attachment *attach,
621 struct sg_table *sgt);
622 void *(*gem_prime_vmap)(struct drm_gem_object *obj);
623 void (*gem_prime_vunmap)(struct drm_gem_object *obj, void *vaddr);
624 int (*gem_prime_mmap)(struct drm_gem_object *obj,
625 struct vm_area_struct *vma);
626
627
628 void (*vgaarb_irq)(struct drm_device *dev, bool state);
629
630
631 int (*dumb_create)(struct drm_file *file_priv,
632 struct drm_device *dev,
633 struct drm_mode_create_dumb *args);
634 int (*dumb_map_offset)(struct drm_file *file_priv,
635 struct drm_device *dev, uint32_t handle,
636 uint64_t *offset);
637 int (*dumb_destroy)(struct drm_file *file_priv,
638 struct drm_device *dev,
639 uint32_t handle);
640
641
642 const struct vm_operations_struct *gem_vm_ops;
643
644 int major;
645 int minor;
646 int patchlevel;
647 char *name;
648 char *desc;
649 char *date;
650
651 u32 driver_features;
652 int dev_priv_size;
653 const struct drm_ioctl_desc *ioctls;
654 int num_ioctls;
655 const struct file_operations *fops;
656
657
658 struct list_head legacy_dev_list;
659};
660
661enum drm_minor_type {
662 DRM_MINOR_LEGACY,
663 DRM_MINOR_CONTROL,
664 DRM_MINOR_RENDER,
665 DRM_MINOR_CNT,
666};
667
668
669
670
671
672struct drm_info_list {
673 const char *name;
674 int (*show)(struct seq_file*, void*);
675 u32 driver_features;
676 void *data;
677};
678
679
680
681
682struct drm_info_node {
683 struct list_head list;
684 struct drm_minor *minor;
685 const struct drm_info_list *info_ent;
686 struct dentry *dent;
687};
688
689
690
691
692struct drm_minor {
693 int index;
694 int type;
695 struct device *kdev;
696 struct drm_device *dev;
697
698 struct dentry *debugfs_root;
699
700 struct list_head debugfs_list;
701 struct mutex debugfs_lock;
702
703
704 struct drm_master *master;
705};
706
707
708struct drm_pending_vblank_event {
709 struct drm_pending_event base;
710 unsigned int pipe;
711 struct drm_event_vblank event;
712};
713
714struct drm_vblank_crtc {
715 struct drm_device *dev;
716 wait_queue_head_t queue;
717 struct timer_list disable_timer;
718
719
720 u32 count;
721
722 struct timeval time[DRM_VBLANKTIME_RBSIZE];
723
724 atomic_t refcount;
725 u32 last;
726
727 u32 last_wait;
728 unsigned int inmodeset;
729 unsigned int pipe;
730 int framedur_ns;
731 int linedur_ns;
732 bool enabled;
733
734};
735
736
737
738
739
740struct drm_device {
741 struct list_head legacy_dev_list;
742 int if_version;
743
744
745
746 struct kref ref;
747 struct device *dev;
748 struct drm_driver *driver;
749 void *dev_private;
750 struct drm_minor *control;
751 struct drm_minor *primary;
752 struct drm_minor *render;
753 atomic_t unplugged;
754 struct inode *anon_inode;
755 char *unique;
756
757
758
759
760 struct mutex struct_mutex;
761 struct mutex master_mutex;
762
763
764
765
766 int open_count;
767 spinlock_t buf_lock;
768 int buf_use;
769 atomic_t buf_alloc;
770
771
772 struct list_head filelist;
773
774
775
776 struct list_head maplist;
777 struct drm_open_hash map_hash;
778
779
780
781 struct list_head ctxlist;
782 struct mutex ctxlist_mutex;
783
784 struct idr ctx_idr;
785
786 struct list_head vmalist;
787
788
789
790
791
792 struct drm_device_dma *dma;
793
794
795
796
797
798 __volatile__ long context_flag;
799 int last_context;
800
801
802
803
804 bool irq_enabled;
805 int irq;
806
807
808
809
810
811
812
813 bool vblank_disable_allowed;
814
815
816
817
818
819
820
821
822
823 bool vblank_disable_immediate;
824
825
826 struct drm_vblank_crtc *vblank;
827
828 spinlock_t vblank_time_lock;
829 spinlock_t vbl_lock;
830
831 u32 max_vblank_count;
832
833
834
835
836 struct list_head vblank_event_list;
837 spinlock_t event_lock;
838
839
840
841 struct drm_agp_head *agp;
842
843 struct pci_dev *pdev;
844#ifdef __alpha__
845 struct pci_controller *hose;
846#endif
847
848 struct platform_device *platformdev;
849 struct virtio_device *virtdev;
850
851 struct drm_sg_mem *sg;
852 unsigned int num_crtcs;
853
854 struct {
855 int context;
856 struct drm_hw_lock *lock;
857 } sigdata;
858
859 struct drm_local_map *agp_buffer_map;
860 unsigned int agp_buffer_token;
861
862 struct drm_mode_config mode_config;
863
864
865
866 struct mutex object_name_lock;
867 struct idr object_name_idr;
868 struct drm_vma_offset_manager *vma_offset_manager;
869
870 int switch_power_state;
871};
872
873#define DRM_SWITCH_POWER_ON 0
874#define DRM_SWITCH_POWER_OFF 1
875#define DRM_SWITCH_POWER_CHANGING 2
876#define DRM_SWITCH_POWER_DYNAMIC_OFF 3
877
878static __inline__ int drm_core_check_feature(struct drm_device *dev,
879 int feature)
880{
881 return ((dev->driver->driver_features & feature) ? 1 : 0);
882}
883
884static inline void drm_device_set_unplugged(struct drm_device *dev)
885{
886 smp_wmb();
887 atomic_set(&dev->unplugged, 1);
888}
889
890static inline int drm_device_is_unplugged(struct drm_device *dev)
891{
892 int ret = atomic_read(&dev->unplugged);
893 smp_rmb();
894 return ret;
895}
896
897static inline bool drm_is_render_client(const struct drm_file *file_priv)
898{
899 return file_priv->minor->type == DRM_MINOR_RENDER;
900}
901
902static inline bool drm_is_control_client(const struct drm_file *file_priv)
903{
904 return file_priv->minor->type == DRM_MINOR_CONTROL;
905}
906
907static inline bool drm_is_primary_client(const struct drm_file *file_priv)
908{
909 return file_priv->minor->type == DRM_MINOR_LEGACY;
910}
911
912
913
914
915
916
917extern int drm_ioctl_permit(u32 flags, struct drm_file *file_priv);
918extern long drm_ioctl(struct file *filp,
919 unsigned int cmd, unsigned long arg);
920extern long drm_compat_ioctl(struct file *filp,
921 unsigned int cmd, unsigned long arg);
922extern bool drm_ioctl_flags(unsigned int nr, unsigned int *flags);
923
924
925int drm_open(struct inode *inode, struct file *filp);
926ssize_t drm_read(struct file *filp, char __user *buffer,
927 size_t count, loff_t *offset);
928int drm_release(struct inode *inode, struct file *filp);
929int drm_new_set_master(struct drm_device *dev, struct drm_file *fpriv);
930unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
931int drm_event_reserve_init_locked(struct drm_device *dev,
932 struct drm_file *file_priv,
933 struct drm_pending_event *p,
934 struct drm_event *e);
935int drm_event_reserve_init(struct drm_device *dev,
936 struct drm_file *file_priv,
937 struct drm_pending_event *p,
938 struct drm_event *e);
939void drm_event_cancel_free(struct drm_device *dev,
940 struct drm_pending_event *p);
941void drm_send_event_locked(struct drm_device *dev, struct drm_pending_event *e);
942void drm_send_event(struct drm_device *dev, struct drm_pending_event *e);
943
944
945int drm_noop(struct drm_device *dev, void *data,
946 struct drm_file *file_priv);
947int drm_invalid_op(struct drm_device *dev, void *data,
948 struct drm_file *file_priv);
949
950
951void drm_clflush_pages(struct page *pages[], unsigned long num_pages);
952void drm_clflush_sg(struct sg_table *st);
953void drm_clflush_virt_range(void *addr, unsigned long length);
954
955
956
957
958
959
960
961extern int drm_irq_install(struct drm_device *dev, int irq);
962extern int drm_irq_uninstall(struct drm_device *dev);
963
964extern int drm_vblank_init(struct drm_device *dev, unsigned int num_crtcs);
965extern int drm_wait_vblank(struct drm_device *dev, void *data,
966 struct drm_file *filp);
967extern u32 drm_vblank_count(struct drm_device *dev, unsigned int pipe);
968extern u32 drm_crtc_vblank_count(struct drm_crtc *crtc);
969extern u32 drm_vblank_count_and_time(struct drm_device *dev, unsigned int pipe,
970 struct timeval *vblanktime);
971extern u32 drm_crtc_vblank_count_and_time(struct drm_crtc *crtc,
972 struct timeval *vblanktime);
973extern void drm_send_vblank_event(struct drm_device *dev, unsigned int pipe,
974 struct drm_pending_vblank_event *e);
975extern void drm_crtc_send_vblank_event(struct drm_crtc *crtc,
976 struct drm_pending_vblank_event *e);
977extern void drm_arm_vblank_event(struct drm_device *dev, unsigned int pipe,
978 struct drm_pending_vblank_event *e);
979extern void drm_crtc_arm_vblank_event(struct drm_crtc *crtc,
980 struct drm_pending_vblank_event *e);
981extern bool drm_handle_vblank(struct drm_device *dev, unsigned int pipe);
982extern bool drm_crtc_handle_vblank(struct drm_crtc *crtc);
983extern int drm_vblank_get(struct drm_device *dev, unsigned int pipe);
984extern void drm_vblank_put(struct drm_device *dev, unsigned int pipe);
985extern int drm_crtc_vblank_get(struct drm_crtc *crtc);
986extern void drm_crtc_vblank_put(struct drm_crtc *crtc);
987extern void drm_wait_one_vblank(struct drm_device *dev, unsigned int pipe);
988extern void drm_crtc_wait_one_vblank(struct drm_crtc *crtc);
989extern void drm_vblank_off(struct drm_device *dev, unsigned int pipe);
990extern void drm_vblank_on(struct drm_device *dev, unsigned int pipe);
991extern void drm_crtc_vblank_off(struct drm_crtc *crtc);
992extern void drm_crtc_vblank_reset(struct drm_crtc *crtc);
993extern void drm_crtc_vblank_on(struct drm_crtc *crtc);
994extern void drm_vblank_cleanup(struct drm_device *dev);
995extern u32 drm_vblank_no_hw_counter(struct drm_device *dev, unsigned int pipe);
996
997extern int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
998 unsigned int pipe, int *max_error,
999 struct timeval *vblank_time,
1000 unsigned flags,
1001 const struct drm_display_mode *mode);
1002extern void drm_calc_timestamping_constants(struct drm_crtc *crtc,
1003 const struct drm_display_mode *mode);
1004
1005
1006
1007
1008
1009
1010
1011
1012static inline wait_queue_head_t *drm_crtc_vblank_waitqueue(struct drm_crtc *crtc)
1013{
1014 return &crtc->dev->vblank[drm_crtc_index(crtc)].queue;
1015}
1016
1017
1018extern void drm_vblank_pre_modeset(struct drm_device *dev, unsigned int pipe);
1019extern void drm_vblank_post_modeset(struct drm_device *dev, unsigned int pipe);
1020
1021
1022extern struct drm_master *drm_master_get(struct drm_master *master);
1023extern void drm_master_put(struct drm_master **master);
1024
1025extern void drm_put_dev(struct drm_device *dev);
1026extern void drm_unplug_dev(struct drm_device *dev);
1027extern unsigned int drm_debug;
1028extern bool drm_atomic;
1029
1030
1031#if defined(CONFIG_DEBUG_FS)
1032extern int drm_debugfs_create_files(const struct drm_info_list *files,
1033 int count, struct dentry *root,
1034 struct drm_minor *minor);
1035extern int drm_debugfs_remove_files(const struct drm_info_list *files,
1036 int count, struct drm_minor *minor);
1037#else
1038static inline int drm_debugfs_create_files(const struct drm_info_list *files,
1039 int count, struct dentry *root,
1040 struct drm_minor *minor)
1041{
1042 return 0;
1043}
1044
1045static inline int drm_debugfs_remove_files(const struct drm_info_list *files,
1046 int count, struct drm_minor *minor)
1047{
1048 return 0;
1049}
1050#endif
1051
1052extern struct dma_buf *drm_gem_prime_export(struct drm_device *dev,
1053 struct drm_gem_object *obj, int flags);
1054extern int drm_gem_prime_handle_to_fd(struct drm_device *dev,
1055 struct drm_file *file_priv, uint32_t handle, uint32_t flags,
1056 int *prime_fd);
1057extern struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,
1058 struct dma_buf *dma_buf);
1059extern int drm_gem_prime_fd_to_handle(struct drm_device *dev,
1060 struct drm_file *file_priv, int prime_fd, uint32_t *handle);
1061extern void drm_gem_dmabuf_release(struct dma_buf *dma_buf);
1062
1063extern int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages,
1064 dma_addr_t *addrs, int max_pages);
1065extern struct sg_table *drm_prime_pages_to_sg(struct page **pages, unsigned int nr_pages);
1066extern void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg);
1067
1068
1069extern struct drm_dma_handle *drm_pci_alloc(struct drm_device *dev, size_t size,
1070 size_t align);
1071extern void drm_pci_free(struct drm_device *dev, struct drm_dma_handle * dmah);
1072
1073
1074extern void drm_sysfs_hotplug_event(struct drm_device *dev);
1075
1076
1077struct drm_device *drm_dev_alloc(struct drm_driver *driver,
1078 struct device *parent);
1079void drm_dev_ref(struct drm_device *dev);
1080void drm_dev_unref(struct drm_device *dev);
1081int drm_dev_register(struct drm_device *dev, unsigned long flags);
1082void drm_dev_unregister(struct drm_device *dev);
1083int drm_dev_set_unique(struct drm_device *dev, const char *name);
1084
1085struct drm_minor *drm_minor_acquire(unsigned int minor_id);
1086void drm_minor_release(struct drm_minor *minor);
1087
1088
1089
1090
1091static __inline__ int drm_pci_device_is_agp(struct drm_device *dev)
1092{
1093 if (dev->driver->device_is_agp != NULL) {
1094 int err = (*dev->driver->device_is_agp) (dev);
1095
1096 if (err != 2) {
1097 return err;
1098 }
1099 }
1100
1101 return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
1102}
1103void drm_pci_agp_destroy(struct drm_device *dev);
1104
1105extern int drm_pci_init(struct drm_driver *driver, struct pci_driver *pdriver);
1106extern void drm_pci_exit(struct drm_driver *driver, struct pci_driver *pdriver);
1107#ifdef CONFIG_PCI
1108extern int drm_get_pci_dev(struct pci_dev *pdev,
1109 const struct pci_device_id *ent,
1110 struct drm_driver *driver);
1111extern int drm_pci_set_busid(struct drm_device *dev, struct drm_master *master);
1112#else
1113static inline int drm_get_pci_dev(struct pci_dev *pdev,
1114 const struct pci_device_id *ent,
1115 struct drm_driver *driver)
1116{
1117 return -ENOSYS;
1118}
1119
1120static inline int drm_pci_set_busid(struct drm_device *dev,
1121 struct drm_master *master)
1122{
1123 return -ENOSYS;
1124}
1125#endif
1126
1127#define DRM_PCIE_SPEED_25 1
1128#define DRM_PCIE_SPEED_50 2
1129#define DRM_PCIE_SPEED_80 4
1130
1131extern int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *speed_mask);
1132extern int drm_pcie_get_max_link_width(struct drm_device *dev, u32 *mlw);
1133
1134
1135extern int drm_platform_init(struct drm_driver *driver, struct platform_device *platform_device);
1136extern int drm_platform_set_busid(struct drm_device *d, struct drm_master *m);
1137
1138
1139static __inline__ bool drm_can_sleep(void)
1140{
1141 if (in_atomic() || in_dbg_master() || irqs_disabled())
1142 return false;
1143 return true;
1144}
1145
1146
1147#define for_each_if(condition) if (!(condition)) {} else
1148
1149#endif
1150