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/platform_device.h>
51#include <linux/poll.h>
52#include <linux/ratelimit.h>
53#include <linux/sched.h>
54#include <linux/slab.h>
55#include <linux/types.h>
56#include <linux/vmalloc.h>
57#include <linux/workqueue.h>
58#include <linux/dma-fence.h>
59#include <linux/module.h>
60
61#include <asm/mman.h>
62#include <asm/pgalloc.h>
63#include <linux/uaccess.h>
64
65#include <uapi/drm/drm.h>
66#include <uapi/drm/drm_mode.h>
67
68#include <drm/drm_agpsupport.h>
69#include <drm/drm_crtc.h>
70#include <drm/drm_fourcc.h>
71#include <drm/drm_global.h>
72#include <drm/drm_hashtab.h>
73#include <drm/drm_mm.h>
74#include <drm/drm_os_linux.h>
75#include <drm/drm_sarea.h>
76#include <drm/drm_drv.h>
77#include <drm/drm_prime.h>
78#include <drm/drm_pci.h>
79#include <drm/drm_file.h>
80#include <drm/drm_debugfs.h>
81#include <drm/drm_ioctl.h>
82#include <drm/drm_sysfs.h>
83#include <drm/drm_vblank.h>
84#include <drm/drm_irq.h>
85
86
87struct module;
88
89struct drm_device;
90struct drm_agp_head;
91struct drm_local_map;
92struct drm_device_dma;
93struct drm_gem_object;
94struct drm_master;
95struct drm_vblank_crtc;
96struct drm_vma_offset_manager;
97
98struct device_node;
99struct videomode;
100struct reservation_object;
101struct dma_buf_attachment;
102
103struct pci_dev;
104struct pci_controller;
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140#define DRM_UT_NONE 0x00
141#define DRM_UT_CORE 0x01
142#define DRM_UT_DRIVER 0x02
143#define DRM_UT_KMS 0x04
144#define DRM_UT_PRIME 0x08
145#define DRM_UT_ATOMIC 0x10
146#define DRM_UT_VBL 0x20
147#define DRM_UT_STATE 0x40
148
149
150
151
152
153
154
155
156
157#define _DRM_PRINTK(once, level, fmt, ...) \
158 do { \
159 printk##once(KERN_##level "[" DRM_NAME "] " fmt, \
160 ##__VA_ARGS__); \
161 } while (0)
162
163#define DRM_INFO(fmt, ...) \
164 _DRM_PRINTK(, INFO, fmt, ##__VA_ARGS__)
165#define DRM_NOTE(fmt, ...) \
166 _DRM_PRINTK(, NOTICE, fmt, ##__VA_ARGS__)
167#define DRM_WARN(fmt, ...) \
168 _DRM_PRINTK(, WARNING, fmt, ##__VA_ARGS__)
169
170#define DRM_INFO_ONCE(fmt, ...) \
171 _DRM_PRINTK(_once, INFO, fmt, ##__VA_ARGS__)
172#define DRM_NOTE_ONCE(fmt, ...) \
173 _DRM_PRINTK(_once, NOTICE, fmt, ##__VA_ARGS__)
174#define DRM_WARN_ONCE(fmt, ...) \
175 _DRM_PRINTK(_once, WARNING, fmt, ##__VA_ARGS__)
176
177
178
179
180
181
182
183#define DRM_DEV_ERROR(dev, fmt, ...) \
184 drm_dev_printk(dev, KERN_ERR, DRM_UT_NONE, __func__, " *ERROR*",\
185 fmt, ##__VA_ARGS__)
186#define DRM_ERROR(fmt, ...) \
187 drm_printk(KERN_ERR, DRM_UT_NONE, fmt, ##__VA_ARGS__)
188
189
190
191
192
193
194
195#define DRM_DEV_ERROR_RATELIMITED(dev, fmt, ...) \
196({ \
197 static DEFINE_RATELIMIT_STATE(_rs, \
198 DEFAULT_RATELIMIT_INTERVAL, \
199 DEFAULT_RATELIMIT_BURST); \
200 \
201 if (__ratelimit(&_rs)) \
202 DRM_DEV_ERROR(dev, fmt, ##__VA_ARGS__); \
203})
204#define DRM_ERROR_RATELIMITED(fmt, ...) \
205 DRM_DEV_ERROR_RATELIMITED(NULL, fmt, ##__VA_ARGS__)
206
207#define DRM_DEV_INFO(dev, fmt, ...) \
208 drm_dev_printk(dev, KERN_INFO, DRM_UT_NONE, __func__, "", fmt, \
209 ##__VA_ARGS__)
210
211#define DRM_DEV_INFO_ONCE(dev, fmt, ...) \
212({ \
213 static bool __print_once __read_mostly; \
214 if (!__print_once) { \
215 __print_once = true; \
216 DRM_DEV_INFO(dev, fmt, ##__VA_ARGS__); \
217 } \
218})
219
220
221
222
223
224
225
226#define DRM_DEV_DEBUG(dev, fmt, args...) \
227 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_CORE, __func__, "", fmt, \
228 ##args)
229#define DRM_DEBUG(fmt, ...) \
230 drm_printk(KERN_DEBUG, DRM_UT_CORE, fmt, ##__VA_ARGS__)
231
232#define DRM_DEV_DEBUG_DRIVER(dev, fmt, args...) \
233 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_DRIVER, __func__, "", \
234 fmt, ##args)
235#define DRM_DEBUG_DRIVER(fmt, ...) \
236 drm_printk(KERN_DEBUG, DRM_UT_DRIVER, fmt, ##__VA_ARGS__)
237
238#define DRM_DEV_DEBUG_KMS(dev, fmt, args...) \
239 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_KMS, __func__, "", fmt, \
240 ##args)
241#define DRM_DEBUG_KMS(fmt, ...) \
242 drm_printk(KERN_DEBUG, DRM_UT_KMS, fmt, ##__VA_ARGS__)
243
244#define DRM_DEV_DEBUG_PRIME(dev, fmt, args...) \
245 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_PRIME, __func__, "", \
246 fmt, ##args)
247#define DRM_DEBUG_PRIME(fmt, ...) \
248 drm_printk(KERN_DEBUG, DRM_UT_PRIME, fmt, ##__VA_ARGS__)
249
250#define DRM_DEV_DEBUG_ATOMIC(dev, fmt, args...) \
251 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_ATOMIC, __func__, "", \
252 fmt, ##args)
253#define DRM_DEBUG_ATOMIC(fmt, ...) \
254 drm_printk(KERN_DEBUG, DRM_UT_ATOMIC, fmt, ##__VA_ARGS__)
255
256#define DRM_DEV_DEBUG_VBL(dev, fmt, args...) \
257 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_VBL, __func__, "", fmt, \
258 ##args)
259#define DRM_DEBUG_VBL(fmt, ...) \
260 drm_printk(KERN_DEBUG, DRM_UT_VBL, fmt, ##__VA_ARGS__)
261
262#define _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, level, fmt, args...) \
263({ \
264 static DEFINE_RATELIMIT_STATE(_rs, \
265 DEFAULT_RATELIMIT_INTERVAL, \
266 DEFAULT_RATELIMIT_BURST); \
267 if (__ratelimit(&_rs)) \
268 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_ ## level, \
269 __func__, "", fmt, ##args); \
270})
271
272
273
274
275
276
277
278#define DRM_DEV_DEBUG_RATELIMITED(dev, fmt, args...) \
279 DEV__DRM_DEFINE_DEBUG_RATELIMITED(dev, CORE, fmt, ##args)
280#define DRM_DEBUG_RATELIMITED(fmt, args...) \
281 DRM_DEV_DEBUG_RATELIMITED(NULL, fmt, ##args)
282#define DRM_DEV_DEBUG_DRIVER_RATELIMITED(dev, fmt, args...) \
283 _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, DRIVER, fmt, ##args)
284#define DRM_DEBUG_DRIVER_RATELIMITED(fmt, args...) \
285 DRM_DEV_DEBUG_DRIVER_RATELIMITED(NULL, fmt, ##args)
286#define DRM_DEV_DEBUG_KMS_RATELIMITED(dev, fmt, args...) \
287 _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, KMS, fmt, ##args)
288#define DRM_DEBUG_KMS_RATELIMITED(fmt, args...) \
289 DRM_DEV_DEBUG_KMS_RATELIMITED(NULL, fmt, ##args)
290#define DRM_DEV_DEBUG_PRIME_RATELIMITED(dev, fmt, args...) \
291 _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, PRIME, fmt, ##args)
292#define DRM_DEBUG_PRIME_RATELIMITED(fmt, args...) \
293 DRM_DEV_DEBUG_PRIME_RATELIMITED(NULL, fmt, ##args)
294
295
296
297
298
299
300
301
302
303
304
305#define DRM_IF_VERSION(maj, min) (maj << 16 | min)
306
307
308
309
310
311
312struct drm_device {
313 struct list_head legacy_dev_list;
314 int if_version;
315
316
317
318 struct kref ref;
319 struct device *dev;
320 struct drm_driver *driver;
321 void *dev_private;
322 struct drm_minor *control;
323 struct drm_minor *primary;
324 struct drm_minor *render;
325 bool registered;
326
327
328 struct drm_master *master;
329
330 atomic_t unplugged;
331 struct inode *anon_inode;
332 char *unique;
333
334
335
336
337 struct mutex struct_mutex;
338 struct mutex master_mutex;
339
340
341
342
343 int open_count;
344 spinlock_t buf_lock;
345 int buf_use;
346 atomic_t buf_alloc;
347
348
349 struct mutex filelist_mutex;
350 struct list_head filelist;
351
352
353
354 struct list_head maplist;
355 struct drm_open_hash map_hash;
356
357
358
359 struct list_head ctxlist;
360 struct mutex ctxlist_mutex;
361
362 struct idr ctx_idr;
363
364 struct list_head vmalist;
365
366
367
368
369
370 struct drm_device_dma *dma;
371
372
373
374
375
376 __volatile__ long context_flag;
377 int last_context;
378
379
380
381
382
383
384
385
386
387 bool irq_enabled;
388 int irq;
389
390
391
392
393
394
395
396
397
398 bool vblank_disable_immediate;
399
400
401 struct drm_vblank_crtc *vblank;
402
403 spinlock_t vblank_time_lock;
404 spinlock_t vbl_lock;
405
406 u32 max_vblank_count;
407
408
409
410
411 struct list_head vblank_event_list;
412 spinlock_t event_lock;
413
414
415
416 struct drm_agp_head *agp;
417
418 struct pci_dev *pdev;
419#ifdef __alpha__
420 struct pci_controller *hose;
421#endif
422
423 struct drm_sg_mem *sg;
424 unsigned int num_crtcs;
425
426 struct {
427 int context;
428 struct drm_hw_lock *lock;
429 } sigdata;
430
431 struct drm_local_map *agp_buffer_map;
432 unsigned int agp_buffer_token;
433
434 struct drm_mode_config mode_config;
435
436
437
438 struct mutex object_name_lock;
439 struct idr object_name_idr;
440 struct drm_vma_offset_manager *vma_offset_manager;
441
442 int switch_power_state;
443};
444
445
446
447
448
449
450
451
452
453static inline bool drm_drv_uses_atomic_modeset(struct drm_device *dev)
454{
455 return dev->mode_config.funcs->atomic_commit != NULL;
456}
457
458#define DRM_SWITCH_POWER_ON 0
459#define DRM_SWITCH_POWER_OFF 1
460#define DRM_SWITCH_POWER_CHANGING 2
461#define DRM_SWITCH_POWER_DYNAMIC_OFF 3
462
463static __inline__ int drm_core_check_feature(struct drm_device *dev,
464 int feature)
465{
466 return ((dev->driver->driver_features & feature) ? 1 : 0);
467}
468
469static inline void drm_device_set_unplugged(struct drm_device *dev)
470{
471 smp_wmb();
472 atomic_set(&dev->unplugged, 1);
473}
474
475static inline int drm_device_is_unplugged(struct drm_device *dev)
476{
477 int ret = atomic_read(&dev->unplugged);
478 smp_rmb();
479 return ret;
480}
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496static __inline__ bool drm_can_sleep(void)
497{
498 if (in_atomic() || in_dbg_master() || irqs_disabled())
499 return false;
500 return true;
501}
502
503
504#define for_each_if(condition) if (!(condition)) {} else
505
506#endif
507