drm/atomic: add new drm_debug bit to dump atomic state
[linux-2.6-block.git] / include / drm / drmP.h
CommitLineData
1da177e4 1/*
d7d2c48e
DH
2 * Internal Header for the Direct Rendering Manager
3 *
1da177e4
LT
4 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
5 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
dcdb1674 6 * Copyright (c) 2009-2010, Code Aurora Forum.
1da177e4
LT
7 * All rights reserved.
8 *
d7d2c48e
DH
9 * Author: Rickard E. (Rik) Faith <faith@valinux.com>
10 * Author: Gareth Hughes <gareth@valinux.com>
11 *
1da177e4
LT
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
96993908
DH
35#include <linux/agp_backend.h>
36#include <linux/cdev.h>
37#include <linux/dma-mapping.h>
38#include <linux/file.h>
1da177e4 39#include <linux/fs.h>
96993908
DH
40#include <linux/highmem.h>
41#include <linux/idr.h>
1da177e4 42#include <linux/init.h>
96993908 43#include <linux/io.h>
1da177e4 44#include <linux/jiffies.h>
96993908
DH
45#include <linux/kernel.h>
46#include <linux/kref.h>
47#include <linux/miscdevice.h>
1da177e4 48#include <linux/mm.h>
30e2fb18 49#include <linux/mutex.h>
96993908
DH
50#include <linux/pci.h>
51#include <linux/platform_device.h>
52#include <linux/poll.h>
5d13d425 53#include <linux/ratelimit.h>
077675c1 54#include <linux/rbtree.h>
96993908
DH
55#include <linux/sched.h>
56#include <linux/slab.h>
1da177e4 57#include <linux/types.h>
d6db6564 58#include <linux/vmalloc.h>
96993908 59#include <linux/workqueue.h>
f54d1867 60#include <linux/dma-fence.h>
96993908
DH
61
62#include <asm/mman.h>
1da177e4 63#include <asm/pgalloc.h>
96993908
DH
64#include <asm/uaccess.h>
65
d7d2c48e
DH
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>
ae4df11a 71#include <drm/drm_fourcc.h>
d7d2c48e 72#include <drm/drm_global.h>
96993908 73#include <drm/drm_hashtab.h>
d7d2c48e 74#include <drm/drm_mem_util.h>
96993908
DH
75#include <drm/drm_mm.h>
76#include <drm/drm_os_linux.h>
19218e48 77#include <drm/drm_sarea.h>
0de23977 78#include <drm/drm_vma_manager.h>
1da177e4 79
de477254
PG
80struct module;
81
c153f45f
EA
82struct drm_file;
83struct drm_device;
cc5ea594 84struct drm_agp_head;
ba8286fa
DV
85struct drm_local_map;
86struct drm_device_dma;
87struct drm_dma_handle;
d9fc9413 88struct drm_gem_object;
3b96a0b1 89struct drm_master;
34a67dd7 90struct drm_vblank_crtc;
c153f45f 91
edb37a95 92struct device_node;
ebc64e45 93struct videomode;
3aac4502 94struct reservation_object;
b5e9c1a2 95struct dma_buf_attachment;
ebc64e45 96
87fdff81 97/*
346fea63 98 * The following categories are defined:
1414b76c
LD
99 *
100 * CORE: Used in the generic drm code: drm_ioctl.c, drm_mm.c, drm_memory.c, ...
101 * This is the category used by the DRM_DEBUG() macro.
102 *
103 * DRIVER: Used in the vendor specific part of the driver: i915, radeon, ...
104 * This is the category used by the DRM_DEBUG_DRIVER() macro.
87fdff81 105 *
1414b76c
LD
106 * KMS: used in the modesetting code.
107 * This is the category used by the DRM_DEBUG_KMS() macro.
87fdff81 108 *
1414b76c
LD
109 * PRIME: used in the prime code.
110 * This is the category used by the DRM_DEBUG_PRIME() macro.
87fdff81 111 *
17a38d9c
DV
112 * ATOMIC: used in the atomic code.
113 * This is the category used by the DRM_DEBUG_ATOMIC() macro.
114 *
235fabe0
VS
115 * VBL: used for verbose debug message in the vblank code
116 * This is the category used by the DRM_DEBUG_VBL() macro.
117 *
1414b76c
LD
118 * Enabling verbose debug messages is done through the drm.debug parameter,
119 * each category being enabled by a bit.
120 *
121 * drm.debug=0x1 will enable CORE messages
122 * drm.debug=0x2 will enable DRIVER messages
123 * drm.debug=0x3 will enable CORE and DRIVER messages
124 * ...
235fabe0 125 * drm.debug=0x3f will enable all messages
1414b76c
LD
126 *
127 * An interesting feature is that it's possible to enable verbose logging at
128 * run-time by echoing the debug value in its sysfs node:
129 * # echo 0xf > /sys/module/drm/parameters/debug
87fdff81 130 */
c4e68a58 131#define DRM_UT_NONE 0x00
1414b76c
LD
132#define DRM_UT_CORE 0x01
133#define DRM_UT_DRIVER 0x02
134#define DRM_UT_KMS 0x04
135#define DRM_UT_PRIME 0x08
17a38d9c 136#define DRM_UT_ATOMIC 0x10
235fabe0 137#define DRM_UT_VBL 0x20
fceffb32 138#define DRM_UT_STATE 0x40
4fefcb27 139
c4e68a58
SP
140extern __printf(6, 7)
141void drm_dev_printk(const struct device *dev, const char *level,
142 unsigned int category, const char *function_name,
143 const char *prefix, const char *format, ...);
144
6bd488db 145extern __printf(3, 4)
c4e68a58 146void drm_printk(const char *level, unsigned int category,
c4e68a58 147 const char *format, ...);
5ad3d883 148
1da177e4
LT
149/***********************************************************************/
150/** \name DRM template customization defaults */
151/*@{*/
152
153/* driver capabilities and requirements mask */
0e975980 154#define DRIVER_USE_AGP 0x1
3cbf6a5d 155#define DRIVER_LEGACY 0x2
0e975980
PA
156#define DRIVER_PCI_DMA 0x8
157#define DRIVER_SG 0x10
158#define DRIVER_HAVE_DMA 0x20
159#define DRIVER_HAVE_IRQ 0x40
160#define DRIVER_IRQ_SHARED 0x80
161#define DRIVER_GEM 0x1000
162#define DRIVER_MODESET 0x2000
163#define DRIVER_PRIME 0x4000
164#define DRIVER_RENDER 0x8000
165#define DRIVER_ATOMIC 0x10000
166#define DRIVER_KMS_LEGACY_CONTEXT 0x20000
8410ea3b 167
1da177e4 168/***********************************************************************/
1da177e4
LT
169/** \name Macros to make printk easier */
170/*@{*/
171
30b0da8d
DG
172#define _DRM_PRINTK(once, level, fmt, ...) \
173 do { \
174 printk##once(KERN_##level "[" DRM_NAME "] " fmt, \
175 ##__VA_ARGS__); \
176 } while (0)
177
178#define DRM_INFO(fmt, ...) \
179 _DRM_PRINTK(, INFO, fmt, ##__VA_ARGS__)
180#define DRM_NOTE(fmt, ...) \
181 _DRM_PRINTK(, NOTICE, fmt, ##__VA_ARGS__)
182#define DRM_WARN(fmt, ...) \
183 _DRM_PRINTK(, WARNING, fmt, ##__VA_ARGS__)
184
185#define DRM_INFO_ONCE(fmt, ...) \
186 _DRM_PRINTK(_once, INFO, fmt, ##__VA_ARGS__)
187#define DRM_NOTE_ONCE(fmt, ...) \
188 _DRM_PRINTK(_once, NOTICE, fmt, ##__VA_ARGS__)
189#define DRM_WARN_ONCE(fmt, ...) \
190 _DRM_PRINTK(_once, WARNING, fmt, ##__VA_ARGS__)
191
1da177e4
LT
192/**
193 * Error output.
194 *
195 * \param fmt printf() like format string.
196 * \param arg arguments
197 */
c4e68a58
SP
198#define DRM_DEV_ERROR(dev, fmt, ...) \
199 drm_dev_printk(dev, KERN_ERR, DRM_UT_NONE, __func__, " *ERROR*",\
200 fmt, ##__VA_ARGS__)
201#define DRM_ERROR(fmt, ...) \
6bd488db 202 drm_printk(KERN_ERR, DRM_UT_NONE, fmt, ##__VA_ARGS__)
1da177e4 203
5d13d425
RC
204/**
205 * Rate limited error output. Like DRM_ERROR() but won't flood the log.
206 *
207 * \param fmt printf() like format string.
208 * \param arg arguments
209 */
c4e68a58 210#define DRM_DEV_ERROR_RATELIMITED(dev, fmt, ...) \
5d13d425
RC
211({ \
212 static DEFINE_RATELIMIT_STATE(_rs, \
213 DEFAULT_RATELIMIT_INTERVAL, \
214 DEFAULT_RATELIMIT_BURST); \
215 \
216 if (__ratelimit(&_rs)) \
c4e68a58 217 DRM_DEV_ERROR(dev, fmt, ##__VA_ARGS__); \
5d13d425 218})
c4e68a58
SP
219#define DRM_ERROR_RATELIMITED(fmt, ...) \
220 DRM_DEV_ERROR_RATELIMITED(NULL, fmt, ##__VA_ARGS__)
5d13d425 221
c4e68a58
SP
222#define DRM_DEV_INFO(dev, fmt, ...) \
223 drm_dev_printk(dev, KERN_INFO, DRM_UT_NONE, __func__, "", fmt, \
224 ##__VA_ARGS__)
1da177e4 225
c4e68a58
SP
226#define DRM_DEV_INFO_ONCE(dev, fmt, ...) \
227({ \
228 static bool __print_once __read_mostly; \
229 if (!__print_once) { \
230 __print_once = true; \
231 DRM_DEV_INFO(dev, fmt, ##__VA_ARGS__); \
232 } \
233})
48b8f631 234
1da177e4
LT
235/**
236 * Debug output.
b5e89ed5 237 *
1da177e4
LT
238 * \param fmt printf() like format string.
239 * \param arg arguments
240 */
c4e68a58
SP
241#define DRM_DEV_DEBUG(dev, fmt, args...) \
242 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_CORE, __func__, "", fmt, \
243 ##args)
6bd488db
JP
244#define DRM_DEBUG(fmt, ...) \
245 drm_printk(KERN_DEBUG, DRM_UT_CORE, fmt, ##__VA_ARGS__)
4fefcb27 246
c4e68a58
SP
247#define DRM_DEV_DEBUG_DRIVER(dev, fmt, args...) \
248 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_DRIVER, __func__, "", \
249 fmt, ##args)
6bd488db
JP
250#define DRM_DEBUG_DRIVER(fmt, ...) \
251 drm_printk(KERN_DEBUG, DRM_UT_DRIVER, fmt, ##__VA_ARGS__)
c4e68a58
SP
252
253#define DRM_DEV_DEBUG_KMS(dev, fmt, args...) \
254 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_KMS, __func__, "", fmt, \
255 ##args)
6bd488db
JP
256#define DRM_DEBUG_KMS(fmt, ...) \
257 drm_printk(KERN_DEBUG, DRM_UT_KMS, fmt, ##__VA_ARGS__)
c4e68a58
SP
258
259#define DRM_DEV_DEBUG_PRIME(dev, fmt, args...) \
260 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_PRIME, __func__, "", \
261 fmt, ##args)
6bd488db
JP
262#define DRM_DEBUG_PRIME(fmt, ...) \
263 drm_printk(KERN_DEBUG, DRM_UT_PRIME, fmt, ##__VA_ARGS__)
c4e68a58
SP
264
265#define DRM_DEV_DEBUG_ATOMIC(dev, fmt, args...) \
266 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_ATOMIC, __func__, "", \
267 fmt, ##args)
6bd488db
JP
268#define DRM_DEBUG_ATOMIC(fmt, ...) \
269 drm_printk(KERN_DEBUG, DRM_UT_ATOMIC, fmt, ##__VA_ARGS__)
c4e68a58
SP
270
271#define DRM_DEV_DEBUG_VBL(dev, fmt, args...) \
272 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_VBL, __func__, "", fmt, \
273 ##args)
6bd488db
JP
274#define DRM_DEBUG_VBL(fmt, ...) \
275 drm_printk(KERN_DEBUG, DRM_UT_VBL, fmt, ##__VA_ARGS__)
1da177e4 276
c4e68a58
SP
277#define _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, level, fmt, args...) \
278({ \
279 static DEFINE_RATELIMIT_STATE(_rs, \
280 DEFAULT_RATELIMIT_INTERVAL, \
281 DEFAULT_RATELIMIT_BURST); \
282 if (__ratelimit(&_rs)) \
283 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_ ## level, \
284 __func__, "", fmt, ##args); \
285})
27528c66
L
286
287/**
288 * Rate limited debug output. Like DRM_DEBUG() but won't flood the log.
289 *
290 * \param fmt printf() like format string.
291 * \param arg arguments
292 */
c4e68a58
SP
293#define DRM_DEV_DEBUG_RATELIMITED(dev, fmt, args...) \
294 DEV__DRM_DEFINE_DEBUG_RATELIMITED(dev, CORE, fmt, ##args)
27528c66 295#define DRM_DEBUG_RATELIMITED(fmt, args...) \
c4e68a58
SP
296 DRM_DEV_DEBUG_RATELIMITED(NULL, fmt, ##args)
297#define DRM_DEV_DEBUG_DRIVER_RATELIMITED(dev, fmt, args...) \
298 _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, DRIVER, fmt, ##args)
27528c66 299#define DRM_DEBUG_DRIVER_RATELIMITED(fmt, args...) \
c4e68a58
SP
300 DRM_DEV_DEBUG_DRIVER_RATELIMITED(NULL, fmt, ##args)
301#define DRM_DEV_DEBUG_KMS_RATELIMITED(dev, fmt, args...) \
302 _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, KMS, fmt, ##args)
27528c66 303#define DRM_DEBUG_KMS_RATELIMITED(fmt, args...) \
c4e68a58
SP
304 DRM_DEV_DEBUG_KMS_RATELIMITED(NULL, fmt, ##args)
305#define DRM_DEV_DEBUG_PRIME_RATELIMITED(dev, fmt, args...) \
306 _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, PRIME, fmt, ##args)
27528c66 307#define DRM_DEBUG_PRIME_RATELIMITED(fmt, args...) \
c4e68a58 308 DRM_DEV_DEBUG_PRIME_RATELIMITED(NULL, fmt, ##args)
27528c66 309
65c7dc18
RC
310/* Format strings and argument splitters to simplify printing
311 * various "complex" objects
312 */
313#define DRM_MODE_FMT "%d:\"%s\" %d %d %d %d %d %d %d %d %d %d 0x%x 0x%x"
314#define DRM_MODE_ARG(m) \
315 (m)->base.id, (m)->name, (m)->vrefresh, (m)->clock, \
316 (m)->hdisplay, (m)->hsync_start, (m)->hsync_end, (m)->htotal, \
317 (m)->vdisplay, (m)->vsync_start, (m)->vsync_end, (m)->vtotal, \
318 (m)->type, (m)->flags
319
320#define DRM_RECT_FMT "%dx%d%+d%+d"
321#define DRM_RECT_ARG(r) drm_rect_width(r), drm_rect_height(r), (r)->x1, (r)->y1
322
323/* for rect's in fixed-point format: */
324#define DRM_RECT_FP_FMT "%d.%06ux%d.%06u%+d.%06u%+d.%06u"
325#define DRM_RECT_FP_ARG(r) \
326 drm_rect_width(r) >> 16, ((drm_rect_width(r) & 0xffff) * 15625) >> 10, \
327 drm_rect_height(r) >> 16, ((drm_rect_height(r) & 0xffff) * 15625) >> 10, \
328 (r)->x1 >> 16, (((r)->x1 & 0xffff) * 15625) >> 10, \
329 (r)->y1 >> 16, (((r)->y1 & 0xffff) * 15625) >> 10
330
1da177e4
LT
331/*@}*/
332
1da177e4
LT
333/***********************************************************************/
334/** \name Internal types and structures */
335/*@{*/
336
1da177e4 337#define DRM_IF_VERSION(maj, min) (maj << 16 | min)
1da177e4 338
1da177e4
LT
339/**
340 * Ioctl function type.
341 *
342 * \param inode device inode.
6c340eac 343 * \param file_priv DRM file private pointer.
1da177e4
LT
344 * \param cmd command.
345 * \param arg argument.
346 */
c153f45f
EA
347typedef int drm_ioctl_t(struct drm_device *dev, void *data,
348 struct drm_file *file_priv);
1da177e4 349
9a186645
DA
350typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
351 unsigned long arg);
352
1a95916f
KH
353#define DRM_IOCTL_NR(n) _IOC_NR(n)
354#define DRM_MAJOR 226
355
a7a2cc31
DA
356#define DRM_AUTH 0x1
357#define DRM_MASTER 0x2
358#define DRM_ROOT_ONLY 0x4
f453ba04 359#define DRM_CONTROL_ALLOW 0x8
ed8b6704 360#define DRM_UNLOCKED 0x10
1793126f 361#define DRM_RENDER_ALLOW 0x20
a7a2cc31 362
c153f45f
EA
363struct drm_ioctl_desc {
364 unsigned int cmd;
a7a2cc31 365 int flags;
c972d750 366 drm_ioctl_t *func;
b9434d0f 367 const char *name;
c153f45f
EA
368};
369
370/**
371 * Creates a driver or general drm_ioctl_desc array entry for the given
372 * ioctl, for use by drm_ioctl().
373 */
1b2f1489 374
066626d5
EV
375#define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags) \
376 [DRM_IOCTL_NR(DRM_IOCTL_##ioctl) - DRM_COMMAND_BASE] = { \
377 .cmd = DRM_IOCTL_##ioctl, \
378 .func = _func, \
379 .flags = _flags, \
380 .name = #ioctl \
381 }
1da177e4 382
c9a9c5e0
KH
383/* Event queued up for userspace to read */
384struct drm_pending_event {
3b24f7d6 385 struct completion *completion;
c9a9c5e0 386 struct drm_event *event;
f54d1867 387 struct dma_fence *fence;
c9a9c5e0 388 struct list_head link;
681047b4 389 struct list_head pending_link;
c9a9c5e0 390 struct drm_file *file_priv;
b9c2c9ae
JB
391 pid_t pid; /* pid of requester, no guarantee it's valid by the time
392 we deliver the event, for tracing only */
c9a9c5e0
KH
393};
394
3248877e 395struct drm_prime_file_private {
3248877e 396 struct mutex lock;
077675c1
CW
397 struct rb_root dmabufs;
398 struct rb_root handles;
3248877e
DA
399};
400
1da177e4 401/** File private data */
84b1fd10 402struct drm_file {
39868bd7 403 unsigned authenticated :1;
39868bd7
CW
404 /* true when the client has asked us to expose stereo 3D mode flags */
405 unsigned stereo_allowed :1;
681e7ec7
MR
406 /*
407 * true if client understands CRTC primary planes and cursor planes
408 * in the plane list
409 */
410 unsigned universal_planes:1;
88a48e29
RC
411 /* true if client understands atomic properties */
412 unsigned atomic:1;
a0af2e53 413 /*
0aae5920 414 * This client is the creator of @master.
a0af2e53
TH
415 * Protected by struct drm_device::master_mutex.
416 */
0aae5920 417 unsigned is_master:1;
39868bd7 418
5fce5e0b 419 struct pid *pid;
b5e89ed5 420 drm_magic_t magic;
bd1b331f 421 struct list_head lhead;
2c14f28b 422 struct drm_minor *minor;
b5e89ed5 423 unsigned long lock_count;
7c1c2871 424
673a394b
EA
425 /** Mapping of mm object handles to object pointers. */
426 struct idr object_idr;
427 /** Lock for synchronization of access to object_idr. */
428 spinlock_t table_lock;
7c1c2871 429
6c340eac 430 struct file *filp;
8562b3f2 431 void *driver_priv;
7c1c2871 432
7c1c2871 433 struct drm_master *master; /* master this node is currently associated with
95c081c1 434 N.B. not always dev->master */
4b096ac1
DV
435 /**
436 * fbs - List of framebuffers associated with this file.
437 *
438 * Protected by fbs_lock. Note that the fbs list holds a reference on
439 * the fb object to prevent it from untimely disappearing.
440 */
f453ba04 441 struct list_head fbs;
4b096ac1 442 struct mutex fbs_lock;
c9a9c5e0 443
e2f5d2ea
DS
444 /** User-created blob properties; this retains a reference on the
445 * property. */
446 struct list_head blobs;
447
c9a9c5e0 448 wait_queue_head_t event_wait;
681047b4 449 struct list_head pending_event_list;
c9a9c5e0
KH
450 struct list_head event_list;
451 int event_space;
3248877e 452
9b2c0b7f
CW
453 struct mutex event_read_lock;
454
3248877e 455 struct drm_prime_file_private prime;
84b1fd10 456};
1da177e4 457
1da177e4
LT
458/**
459 * Lock data.
460 */
55910517 461struct drm_lock_data {
c60ce623 462 struct drm_hw_lock *hw_lock; /**< Hardware lock */
8562b3f2
DA
463 /** Private of lock holder's file (NULL=kernel) */
464 struct drm_file *file_priv;
1da177e4 465 wait_queue_head_t lock_queue; /**< Queue of blocked processes */
b5e89ed5 466 unsigned long lock_time; /**< Time of last lock in jiffies */
040ac320
TH
467 spinlock_t spinlock;
468 uint32_t kernel_waiters;
469 uint32_t user_waiters;
470 int idle_has_lock;
55910517 471};
1da177e4 472
27641c3f
MK
473/* Flags and return codes for get_vblank_timestamp() driver function. */
474#define DRM_CALLED_FROM_VBLIRQ 1
475#define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
3d3cbd84 476#define DRM_VBLANKTIME_IN_VBLANK (1 << 1)
27641c3f
MK
477
478/* get_scanout_position() return flags */
479#define DRM_SCANOUTPOS_VALID (1 << 0)
3d3cbd84 480#define DRM_SCANOUTPOS_IN_VBLANK (1 << 1)
27641c3f
MK
481#define DRM_SCANOUTPOS_ACCURATE (1 << 2)
482
1da177e4
LT
483/**
484 * DRM driver structure. This structure represent the common code for
485 * a family of cards. There will one drm_device for each card present
486 * in this family
487 */
1da177e4 488struct drm_driver {
22eae947
DA
489 int (*load) (struct drm_device *, unsigned long flags);
490 int (*firstopen) (struct drm_device *);
84b1fd10 491 int (*open) (struct drm_device *, struct drm_file *);
6c340eac 492 void (*preclose) (struct drm_device *, struct drm_file *file_priv);
84b1fd10 493 void (*postclose) (struct drm_device *, struct drm_file *);
22eae947
DA
494 void (*lastclose) (struct drm_device *);
495 int (*unload) (struct drm_device *);
c153f45f 496 int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
b5e89ed5 497 int (*dma_quiescent) (struct drm_device *);
84b1fd10 498 int (*context_dtor) (struct drm_device *dev, int context);
915b4d11 499 int (*set_busid)(struct drm_device *dev, struct drm_master *master);
b5e89ed5 500
0a3e67a4
JB
501 /**
502 * get_vblank_counter - get raw hardware vblank counter
503 * @dev: DRM device
88e72717 504 * @pipe: counter to fetch
0a3e67a4 505 *
3b02ab88
LP
506 * Driver callback for fetching a raw hardware vblank counter for @crtc.
507 * If a device doesn't have a hardware counter, the driver can simply
33779007 508 * use drm_vblank_no_hw_counter() function. The DRM core will account for
3b02ab88
LP
509 * missed vblank events while interrupts where disabled based on system
510 * timestamps.
0a3e67a4
JB
511 *
512 * Wraparound handling and loss of events due to modesetting is dealt
513 * with in the DRM core code.
514 *
515 * RETURNS
516 * Raw vblank counter value.
517 */
88e72717 518 u32 (*get_vblank_counter) (struct drm_device *dev, unsigned int pipe);
0a3e67a4
JB
519
520 /**
521 * enable_vblank - enable vblank interrupt events
522 * @dev: DRM device
88e72717 523 * @pipe: which irq to enable
0a3e67a4
JB
524 *
525 * Enable vblank interrupts for @crtc. If the device doesn't have
33779007
LD
526 * a hardware vblank counter, the driver should use the
527 * drm_vblank_no_hw_counter() function that keeps a virtual counter.
0a3e67a4
JB
528 *
529 * RETURNS
530 * Zero on success, appropriate errno if the given @crtc's vblank
531 * interrupt cannot be enabled.
532 */
88e72717 533 int (*enable_vblank) (struct drm_device *dev, unsigned int pipe);
0a3e67a4
JB
534
535 /**
536 * disable_vblank - disable vblank interrupt events
537 * @dev: DRM device
88e72717 538 * @pipe: which irq to enable
0a3e67a4
JB
539 *
540 * Disable vblank interrupts for @crtc. If the device doesn't have
33779007
LD
541 * a hardware vblank counter, the driver should use the
542 * drm_vblank_no_hw_counter() function that keeps a virtual counter.
0a3e67a4 543 */
88e72717 544 void (*disable_vblank) (struct drm_device *dev, unsigned int pipe);
0a3e67a4 545
cda17380
DA
546 /**
547 * Called by \c drm_device_is_agp. Typically used to determine if a
548 * card is really attached to AGP or not.
549 *
550 * \param dev DRM device handle
551 *
552 * \returns
553 * One of three values is returned depending on whether or not the
554 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
555 * (return of 1), or may or may not be AGP (return of 2).
556 */
84b1fd10 557 int (*device_is_agp) (struct drm_device *dev);
cda17380 558
27641c3f
MK
559 /**
560 * Called by vblank timestamping code.
561 *
8f6fce03
MK
562 * Return the current display scanout position from a crtc, and an
563 * optional accurate ktime_get timestamp of when position was measured.
27641c3f
MK
564 *
565 * \param dev DRM device.
88e72717 566 * \param pipe Id of the crtc to query.
abca9e45 567 * \param flags Flags from the caller (DRM_CALLED_FROM_VBLIRQ or 0).
27641c3f
MK
568 * \param *vpos Target location for current vertical scanout position.
569 * \param *hpos Target location for current horizontal scanout position.
8f6fce03
MK
570 * \param *stime Target location for timestamp taken immediately before
571 * scanout position query. Can be NULL to skip timestamp.
572 * \param *etime Target location for timestamp taken immediately after
573 * scanout position query. Can be NULL to skip timestamp.
3bb403bf 574 * \param mode Current display timings.
27641c3f
MK
575 *
576 * Returns vpos as a positive number while in active scanout area.
577 * Returns vpos as a negative number inside vblank, counting the number
578 * of scanlines to go until end of vblank, e.g., -1 means "one scanline
579 * until start of active scanout / end of vblank."
580 *
581 * \return Flags, or'ed together as follows:
582 *
25985edc 583 * DRM_SCANOUTPOS_VALID = Query successful.
27641c3f
MK
584 * DRM_SCANOUTPOS_INVBL = Inside vblank.
585 * DRM_SCANOUTPOS_ACCURATE = Returned position is accurate. A lack of
586 * this flag means that returned position may be offset by a constant
587 * but unknown small number of scanlines wrt. real scanout position.
588 *
589 */
88e72717
TR
590 int (*get_scanout_position) (struct drm_device *dev, unsigned int pipe,
591 unsigned int flags, int *vpos, int *hpos,
3bb403bf
VS
592 ktime_t *stime, ktime_t *etime,
593 const struct drm_display_mode *mode);
27641c3f
MK
594
595 /**
596 * Called by \c drm_get_last_vbltimestamp. Should return a precise
597 * timestamp when the most recent VBLANK interval ended or will end.
598 *
599 * Specifically, the timestamp in @vblank_time should correspond as
600 * closely as possible to the time when the first video scanline of
601 * the video frame after the end of VBLANK will start scanning out,
42b2aa86 602 * the time immediately after end of the VBLANK interval. If the
27641c3f
MK
603 * @crtc is currently inside VBLANK, this will be a time in the future.
604 * If the @crtc is currently scanning out a frame, this will be the
605 * past start time of the current scanout. This is meant to adhere
606 * to the OpenML OML_sync_control extension specification.
607 *
608 * \param dev dev DRM device handle.
88e72717 609 * \param pipe crtc for which timestamp should be returned.
27641c3f
MK
610 * \param *max_error Maximum allowable timestamp error in nanoseconds.
611 * Implementation should strive to provide timestamp
612 * with an error of at most *max_error nanoseconds.
613 * Returns true upper bound on error for timestamp.
614 * \param *vblank_time Target location for returned vblank timestamp.
615 * \param flags 0 = Defaults, no special treatment needed.
616 * \param DRM_CALLED_FROM_VBLIRQ = Function is called from vblank
617 * irq handler. Some drivers need to apply some workarounds
618 * for gpu-specific vblank irq quirks if flag is set.
619 *
620 * \returns
621 * Zero if timestamping isn't supported in current display mode or a
622 * negative number on failure. A positive status code on success,
623 * which describes how the vblank_time timestamp was computed.
624 */
88e72717 625 int (*get_vblank_timestamp) (struct drm_device *dev, unsigned int pipe,
27641c3f
MK
626 int *max_error,
627 struct timeval *vblank_time,
628 unsigned flags);
629
1da177e4 630 /* these have to be filled in */
b5e89ed5 631
e9f0d76f 632 irqreturn_t(*irq_handler) (int irq, void *arg);
84b1fd10 633 void (*irq_preinstall) (struct drm_device *dev);
0a3e67a4 634 int (*irq_postinstall) (struct drm_device *dev);
84b1fd10 635 void (*irq_uninstall) (struct drm_device *dev);
22eae947 636
7c1c2871
DA
637 /* Master routines */
638 int (*master_create)(struct drm_device *dev, struct drm_master *master);
639 void (*master_destroy)(struct drm_device *dev, struct drm_master *master);
862302ff
TH
640 /**
641 * master_set is called whenever the minor master is set.
642 * master_drop is called whenever the minor master is dropped.
643 */
644
645 int (*master_set)(struct drm_device *dev, struct drm_file *file_priv,
646 bool from_open);
d6ed682e 647 void (*master_drop)(struct drm_device *dev, struct drm_file *file_priv);
7c1c2871 648
955b12de
BG
649 int (*debugfs_init)(struct drm_minor *minor);
650 void (*debugfs_cleanup)(struct drm_minor *minor);
673a394b
EA
651
652 /**
9f0ba539 653 * @gem_free_object: deconstructor for drm_gem_objects
673a394b 654 *
9f0ba539
DV
655 * This is deprecated and should not be used by new drivers. Use
656 * @gem_free_object_unlocked instead.
673a394b 657 */
673a394b 658 void (*gem_free_object) (struct drm_gem_object *obj);
9f0ba539
DV
659
660 /**
661 * @gem_free_object_unlocked: deconstructor for drm_gem_objects
662 *
663 * This is for drivers which are not encumbered with dev->struct_mutex
664 * legacy locking schemes. Use this hook instead of @gem_free_object.
665 */
666 void (*gem_free_object_unlocked) (struct drm_gem_object *obj);
667
304eda32
BS
668 int (*gem_open_object) (struct drm_gem_object *, struct drm_file *);
669 void (*gem_close_object) (struct drm_gem_object *, struct drm_file *);
673a394b 670
10028c5a
EA
671 /**
672 * Hook for allocating the GEM object struct, for use by core
673 * helpers.
674 */
675 struct drm_gem_object *(*gem_create_object)(struct drm_device *dev,
676 size_t size);
677
3248877e
DA
678 /* prime: */
679 /* export handle -> fd (see drm_gem_prime_handle_to_fd() helper) */
680 int (*prime_handle_to_fd)(struct drm_device *dev, struct drm_file *file_priv,
681 uint32_t handle, uint32_t flags, int *prime_fd);
682 /* import fd -> handle (see drm_gem_prime_fd_to_handle() helper) */
683 int (*prime_fd_to_handle)(struct drm_device *dev, struct drm_file *file_priv,
684 int prime_fd, uint32_t *handle);
685 /* export GEM -> dmabuf */
686 struct dma_buf * (*gem_prime_export)(struct drm_device *dev,
687 struct drm_gem_object *obj, int flags);
688 /* import dmabuf -> GEM */
689 struct drm_gem_object * (*gem_prime_import)(struct drm_device *dev,
690 struct dma_buf *dma_buf);
89177644
AP
691 /* low-level interface used by drm_gem_prime_{import,export} */
692 int (*gem_prime_pin)(struct drm_gem_object *obj);
102d6dba 693 void (*gem_prime_unpin)(struct drm_gem_object *obj);
3aac4502
ML
694 struct reservation_object * (*gem_prime_res_obj)(
695 struct drm_gem_object *obj);
89177644
AP
696 struct sg_table *(*gem_prime_get_sg_table)(struct drm_gem_object *obj);
697 struct drm_gem_object *(*gem_prime_import_sg_table)(
b5e9c1a2
ML
698 struct drm_device *dev,
699 struct dma_buf_attachment *attach,
89177644
AP
700 struct sg_table *sgt);
701 void *(*gem_prime_vmap)(struct drm_gem_object *obj);
702 void (*gem_prime_vunmap)(struct drm_gem_object *obj, void *vaddr);
7c397cd9
JS
703 int (*gem_prime_mmap)(struct drm_gem_object *obj,
704 struct vm_area_struct *vma);
3248877e 705
28d52043
DA
706 /* vga arb irq handler */
707 void (*vgaarb_irq)(struct drm_device *dev, bool state);
708
ff72145b
DA
709 /* dumb alloc support */
710 int (*dumb_create)(struct drm_file *file_priv,
711 struct drm_device *dev,
712 struct drm_mode_create_dumb *args);
713 int (*dumb_map_offset)(struct drm_file *file_priv,
714 struct drm_device *dev, uint32_t handle,
715 uint64_t *offset);
716 int (*dumb_destroy)(struct drm_file *file_priv,
717 struct drm_device *dev,
718 uint32_t handle);
719
a2c0a97b 720 /* Driver private ops for this object */
78b68556 721 const struct vm_operations_struct *gem_vm_ops;
a2c0a97b 722
22eae947
DA
723 int major;
724 int minor;
725 int patchlevel;
726 char *name;
727 char *desc;
728 char *date;
729
1da177e4
LT
730 u32 driver_features;
731 int dev_priv_size;
baa70943 732 const struct drm_ioctl_desc *ioctls;
1da177e4 733 int num_ioctls;
e08e96de 734 const struct file_operations *fops;
8410ea3b 735
b3f2333d
DV
736 /* List of devices hanging off this driver with stealth attach. */
737 struct list_head legacy_dev_list;
1da177e4
LT
738};
739
cb8a239b 740enum drm_minor_type {
a3ccc461 741 DRM_MINOR_PRIMARY,
cb8a239b
DH
742 DRM_MINOR_CONTROL,
743 DRM_MINOR_RENDER,
744 DRM_MINOR_CNT,
745};
2c14f28b 746
955b12de
BG
747/**
748 * Info file list entry. This structure represents a debugfs or proc file to
749 * be created by the drm core
750 */
751struct drm_info_list {
752 const char *name; /** file name */
753 int (*show)(struct seq_file*, void*); /** show callback */
754 u32 driver_features; /**< Required driver features for this entry */
755 void *data;
756};
757
758/**
759 * debugfs node structure. This structure represents a debugfs file.
760 */
761struct drm_info_node {
762 struct list_head list;
763 struct drm_minor *minor;
ce089b54 764 const struct drm_info_list *info_ent;
955b12de
BG
765 struct dentry *dent;
766};
767
1da177e4 768/**
2c14f28b 769 * DRM minor structure. This structure represents a drm minor number.
1da177e4 770 */
2c14f28b
DA
771struct drm_minor {
772 int index; /**< Minor device number */
773 int type; /**< Control or render */
5bdebb18 774 struct device *kdev; /**< Linux device */
1da177e4 775 struct drm_device *dev;
955b12de 776
955b12de 777 struct dentry *debugfs_root;
b3e067c0
MS
778
779 struct list_head debugfs_list;
780 struct mutex debugfs_lock; /* Protects debugfs_list. */
84b1fd10 781};
1da177e4
LT
782
783/**
784 * DRM device structure. This structure represent a complete card that
785 * may contain multiple heads.
786 */
84b1fd10 787struct drm_device {
b3f2333d 788 struct list_head legacy_dev_list;/**< list of devices per driver for stealth attach cleanup */
b5e89ed5 789 int if_version; /**< Highest interface version set */
1da177e4 790
45e212d2
DH
791 /** \name Lifetime Management */
792 /*@{ */
099d1c29 793 struct kref ref; /**< Object ref-count */
45e212d2
DH
794 struct device *dev; /**< Device structure of bus-device */
795 struct drm_driver *driver; /**< DRM driver managing the device */
796 void *dev_private; /**< DRM driver private data */
45e212d2
DH
797 struct drm_minor *control; /**< Control node */
798 struct drm_minor *primary; /**< Primary node */
799 struct drm_minor *render; /**< Render node */
95c081c1
DV
800
801 /* currently active master for this device. Protected by master_mutex */
802 struct drm_master *master;
803
45e212d2 804 atomic_t unplugged; /**< Flag whether dev is dead */
07b48c3a 805 struct inode *anon_inode; /**< inode for private address-space */
ca8e2ad7 806 char *unique; /**< unique name of the device */
45e212d2
DH
807 /*@} */
808
1da177e4 809 /** \name Locks */
b5e89ed5 810 /*@{ */
30e2fb18 811 struct mutex struct_mutex; /**< For others */
c996fd0b 812 struct mutex master_mutex; /**< For drm_minor::master and drm_file::is_master */
b5e89ed5 813 /*@} */
1da177e4
LT
814
815 /** \name Usage Counters */
b5e89ed5 816 /*@{ */
fc8fd40e 817 int open_count; /**< Outstanding files open, protected by drm_global_mutex. */
2177a218 818 spinlock_t buf_lock; /**< For drm_device::buf_use and a few other things. */
b5e89ed5
DA
819 int buf_use; /**< Buffers in use -- cannot alloc */
820 atomic_t buf_alloc; /**< Buffer allocation in progress */
821 /*@} */
1da177e4 822
1d2ac403 823 struct mutex filelist_mutex;
bd1b331f 824 struct list_head filelist;
1da177e4
LT
825
826 /** \name Memory management */
b5e89ed5 827 /*@{ */
bd1b331f 828 struct list_head maplist; /**< Linked list of regions */
e0be428e 829 struct drm_open_hash map_hash; /**< User token hash table for maps */
1da177e4
LT
830
831 /** \name Context handle management */
b5e89ed5 832 /*@{ */
bd1b331f 833 struct list_head ctxlist; /**< Linked list of context handles */
30e2fb18 834 struct mutex ctxlist_mutex; /**< For ctxlist */
1da177e4 835
62968144 836 struct idr ctx_idr;
1da177e4 837
bd1b331f 838 struct list_head vmalist; /**< List of vmas (for debugging) */
f453ba04 839
b5e89ed5 840 /*@} */
1da177e4 841
a344a7e7 842 /** \name DMA support */
b5e89ed5 843 /*@{ */
cdd55a29 844 struct drm_device_dma *dma; /**< Optional pointer for DMA support */
b5e89ed5 845 /*@} */
1da177e4
LT
846
847 /** \name Context support */
b5e89ed5 848 /*@{ */
7c1a38e3 849
1da177e4 850 __volatile__ long context_flag; /**< Context swapping flag */
b5e89ed5 851 int last_context; /**< Last current context */
b5e89ed5
DA
852 /*@} */
853
1da177e4 854 /** \name VBLANK IRQ support */
b5e89ed5 855 /*@{ */
b46004b7
TR
856 bool irq_enabled;
857 int irq;
b5e89ed5 858
00185e66
VS
859 /*
860 * If true, vblank interrupt will be disabled immediately when the
861 * refcount drops to zero, as opposed to via the vblank disable
862 * timer.
863 * This can be set to true it the hardware has a working vblank
864 * counter and the driver uses drm_vblank_on() and drm_vblank_off()
865 * appropriately.
866 */
867 bool vblank_disable_immediate;
868
5380e929
VS
869 /* array of size num_crtcs */
870 struct drm_vblank_crtc *vblank;
0a3e67a4 871
27641c3f 872 spinlock_t vblank_time_lock; /**< Protects vblank count and time updates during vblank enable/disable */
b5e89ed5 873 spinlock_t vbl_lock;
0a3e67a4
JB
874
875 u32 max_vblank_count; /**< size of vblank counter register */
b5e89ed5 876
c9a9c5e0
KH
877 /**
878 * List of events
879 */
880 struct list_head vblank_event_list;
881 spinlock_t event_lock;
882
b5e89ed5 883 /*@} */
b5e89ed5 884
55910517 885 struct drm_agp_head *agp; /**< AGP data */
1da177e4 886
b5e89ed5 887 struct pci_dev *pdev; /**< PCI device structure */
1da177e4 888#ifdef __alpha__
1da177e4 889 struct pci_controller *hose;
1da177e4 890#endif
dcdb1674
JC
891
892 struct platform_device *platformdev; /**< Platform device struture */
dc5698e8 893 struct virtio_device *virtdev;
dcdb1674 894
55910517 895 struct drm_sg_mem *sg; /**< Scatter gather memory */
19227561 896 unsigned int num_crtcs; /**< Number of CRTCs on this device */
b5e89ed5 897
69d516c0
DH
898 struct {
899 int context;
900 struct drm_hw_lock *lock;
901 } sigdata;
902
f77d390c 903 struct drm_local_map *agp_buffer_map;
d1f2b55a 904 unsigned int agp_buffer_token;
bea5679f 905
417009fb 906 struct drm_mode_config mode_config; /**< Current mode config */
f453ba04 907
673a394b
EA
908 /** \name GEM information */
909 /*@{ */
cd4f013f 910 struct mutex object_name_lock;
673a394b 911 struct idr object_name_idr;
b04a5906 912 struct drm_vma_offset_manager *vma_offset_manager;
673a394b 913 /*@} */
5bcf719b 914 int switch_power_state;
84b1fd10 915};
1da177e4 916
34a67dd7
DV
917#include <drm/drm_irq.h>
918
5bcf719b
DA
919#define DRM_SWITCH_POWER_ON 0
920#define DRM_SWITCH_POWER_OFF 1
921#define DRM_SWITCH_POWER_CHANGING 2
13bb9cc8 922#define DRM_SWITCH_POWER_DYNAMIC_OFF 3
5bcf719b 923
b5e89ed5
DA
924static __inline__ int drm_core_check_feature(struct drm_device *dev,
925 int feature)
1da177e4
LT
926{
927 return ((dev->driver->driver_features & feature) ? 1 : 0);
928}
929
2c07a21d
DA
930static inline void drm_device_set_unplugged(struct drm_device *dev)
931{
932 smp_wmb();
933 atomic_set(&dev->unplugged, 1);
934}
935
936static inline int drm_device_is_unplugged(struct drm_device *dev)
937{
938 int ret = atomic_read(&dev->unplugged);
939 smp_rmb();
940 return ret;
941}
942
43683057 943static inline bool drm_is_render_client(const struct drm_file *file_priv)
1793126f
DH
944{
945 return file_priv->minor->type == DRM_MINOR_RENDER;
946}
947
ac05dbc5
TH
948static inline bool drm_is_control_client(const struct drm_file *file_priv)
949{
950 return file_priv->minor->type == DRM_MINOR_CONTROL;
951}
952
43683057
TH
953static inline bool drm_is_primary_client(const struct drm_file *file_priv)
954{
a3ccc461 955 return file_priv->minor->type == DRM_MINOR_PRIMARY;
43683057
TH
956}
957
1da177e4
LT
958/******************************************************************/
959/** \name Internal function definitions */
960/*@{*/
961
1da177e4 962 /* Driver support (drm_drv.h) */
5101020c 963extern int drm_ioctl_permit(u32 flags, struct drm_file *file_priv);
ed8b6704
AB
964extern long drm_ioctl(struct file *filp,
965 unsigned int cmd, unsigned long arg);
55edf41b 966#ifdef CONFIG_COMPAT
b5e89ed5
DA
967extern long drm_compat_ioctl(struct file *filp,
968 unsigned int cmd, unsigned long arg);
55edf41b
JN
969#else
970/* Let drm_compat_ioctl be assigned to .compat_ioctl unconditionally */
971#define drm_compat_ioctl NULL
972#endif
4beb6d9f 973extern bool drm_ioctl_flags(unsigned int nr, unsigned int *flags);
1da177e4 974
bcb877e4
DV
975/* File Operations (drm_fops.c) */
976int drm_open(struct inode *inode, struct file *filp);
977ssize_t drm_read(struct file *filp, char __user *buffer,
978 size_t count, loff_t *offset);
979int drm_release(struct inode *inode, struct file *filp);
bcb877e4 980unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
4020b220
DV
981int drm_event_reserve_init_locked(struct drm_device *dev,
982 struct drm_file *file_priv,
983 struct drm_pending_event *p,
984 struct drm_event *e);
2dd500f1
DV
985int drm_event_reserve_init(struct drm_device *dev,
986 struct drm_file *file_priv,
987 struct drm_pending_event *p,
988 struct drm_event *e);
989void drm_event_cancel_free(struct drm_device *dev,
990 struct drm_pending_event *p);
fb740cf2
DV
991void drm_send_event_locked(struct drm_device *dev, struct drm_pending_event *e);
992void drm_send_event(struct drm_device *dev, struct drm_pending_event *e);
1da177e4 993
78238757
DV
994/* Misc. IOCTL support (drm_ioctl.c) */
995int drm_noop(struct drm_device *dev, void *data,
996 struct drm_file *file_priv);
4b63539b
DV
997int drm_invalid_op(struct drm_device *dev, void *data,
998 struct drm_file *file_priv);
1da177e4 999
673a394b
EA
1000/* Cache management (drm_cache.c) */
1001void drm_clflush_pages(struct page *pages[], unsigned long num_pages);
9da3da66 1002void drm_clflush_sg(struct sg_table *st);
c2d15359 1003void drm_clflush_virt_range(void *addr, unsigned long length);
673a394b 1004
040ac320
TH
1005/*
1006 * These are exported to drivers so that they can implement fencing using
1007 * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
1008 */
1009
0a3e67a4 1010/* Modesetting support */
cc1ef118
TR
1011extern void drm_vblank_pre_modeset(struct drm_device *dev, unsigned int pipe);
1012extern void drm_vblank_post_modeset(struct drm_device *dev, unsigned int pipe);
1da177e4 1013
b3ac9f25
DV
1014/* drm_drv.c */
1015void drm_put_dev(struct drm_device *dev);
1016void drm_unplug_dev(struct drm_device *dev);
b5e89ed5 1017extern unsigned int drm_debug;
2c14f28b 1018
955b12de
BG
1019 /* Debugfs support */
1020#if defined(CONFIG_DEBUG_FS)
7d74795b
LD
1021extern int drm_debugfs_create_files(const struct drm_info_list *files,
1022 int count, struct dentry *root,
1023 struct drm_minor *minor);
1024extern int drm_debugfs_remove_files(const struct drm_info_list *files,
1025 int count, struct drm_minor *minor);
66ee52e2 1026#else
66ee52e2
TR
1027static inline int drm_debugfs_create_files(const struct drm_info_list *files,
1028 int count, struct dentry *root,
1029 struct drm_minor *minor)
1030{
1031 return 0;
1032}
1033
1034static inline int drm_debugfs_remove_files(const struct drm_info_list *files,
1035 int count, struct drm_minor *minor)
1036{
1037 return 0;
1038}
955b12de
BG
1039#endif
1040
a4fce9cb
CW
1041struct dma_buf_export_info;
1042
89177644 1043extern struct dma_buf *drm_gem_prime_export(struct drm_device *dev,
56a76c01
CW
1044 struct drm_gem_object *obj,
1045 int flags);
3248877e
DA
1046extern int drm_gem_prime_handle_to_fd(struct drm_device *dev,
1047 struct drm_file *file_priv, uint32_t handle, uint32_t flags,
1048 int *prime_fd);
89177644
AP
1049extern struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,
1050 struct dma_buf *dma_buf);
3248877e
DA
1051extern int drm_gem_prime_fd_to_handle(struct drm_device *dev,
1052 struct drm_file *file_priv, int prime_fd, uint32_t *handle);
a4fce9cb
CW
1053struct dma_buf *drm_gem_dmabuf_export(struct drm_device *dev,
1054 struct dma_buf_export_info *exp_info);
c1d6798d 1055extern void drm_gem_dmabuf_release(struct dma_buf *dma_buf);
3248877e 1056
51ab7ba2
DA
1057extern int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages,
1058 dma_addr_t *addrs, int max_pages);
34eab43e 1059extern struct sg_table *drm_prime_pages_to_sg(struct page **pages, unsigned int nr_pages);
3248877e
DA
1060extern void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg);
1061
1da177e4 1062
ba8286fa
DV
1063extern struct drm_dma_handle *drm_pci_alloc(struct drm_device *dev, size_t size,
1064 size_t align);
1065extern void drm_pci_free(struct drm_device *dev, struct drm_dma_handle * dmah);
1da177e4
LT
1066
1067 /* sysfs support (drm_sysfs.c) */
f453ba04 1068extern void drm_sysfs_hotplug_event(struct drm_device *dev);
1da177e4 1069
673a394b 1070
1bb72532
DH
1071struct drm_device *drm_dev_alloc(struct drm_driver *driver,
1072 struct device *parent);
b209aca3
CW
1073int drm_dev_init(struct drm_device *dev,
1074 struct drm_driver *driver,
1075 struct device *parent);
099d1c29
DH
1076void drm_dev_ref(struct drm_device *dev);
1077void drm_dev_unref(struct drm_device *dev);
c22f0ace 1078int drm_dev_register(struct drm_device *dev, unsigned long flags);
c3a49737 1079void drm_dev_unregister(struct drm_device *dev);
1616c525
DH
1080
1081struct drm_minor *drm_minor_acquire(unsigned int minor_id);
1082void drm_minor_release(struct drm_minor *minor);
1083
8410ea3b
DA
1084/*@}*/
1085
1086/* PCI section */
1087static __inline__ int drm_pci_device_is_agp(struct drm_device *dev)
1088{
b5e89ed5
DA
1089 if (dev->driver->device_is_agp != NULL) {
1090 int err = (*dev->driver->device_is_agp) (dev);
1091
cda17380
DA
1092 if (err != 2) {
1093 return err;
1094 }
1095 }
1096
1097 return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
1098}
4efafebe 1099void drm_pci_agp_destroy(struct drm_device *dev);
cda17380 1100
8410ea3b
DA
1101extern int drm_pci_init(struct drm_driver *driver, struct pci_driver *pdriver);
1102extern void drm_pci_exit(struct drm_driver *driver, struct pci_driver *pdriver);
a9e3c90c 1103#ifdef CONFIG_PCI
8410ea3b 1104extern int drm_get_pci_dev(struct pci_dev *pdev,
dcdb1674
JC
1105 const struct pci_device_id *ent,
1106 struct drm_driver *driver);
915b4d11 1107extern int drm_pci_set_busid(struct drm_device *dev, struct drm_master *master);
a9e3c90c
TR
1108#else
1109static inline int drm_get_pci_dev(struct pci_dev *pdev,
1110 const struct pci_device_id *ent,
1111 struct drm_driver *driver)
1112{
1113 return -ENOSYS;
1114}
1115
1116static inline int drm_pci_set_busid(struct drm_device *dev,
1117 struct drm_master *master)
1118{
1119 return -ENOSYS;
1120}
1121#endif
8410ea3b 1122
f4297784
DA
1123#define DRM_PCIE_SPEED_25 1
1124#define DRM_PCIE_SPEED_50 2
1125#define DRM_PCIE_SPEED_80 4
1126
1127extern int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *speed_mask);
60d8edd4 1128extern int drm_pcie_get_max_link_width(struct drm_device *dev, u32 *mlw);
8410ea3b
DA
1129
1130/* platform section */
1131extern int drm_platform_init(struct drm_driver *driver, struct platform_device *platform_device);
8410ea3b 1132
cc1f7194
DA
1133/* returns true if currently okay to sleep */
1134static __inline__ bool drm_can_sleep(void)
1135{
1136 if (in_atomic() || in_dbg_master() || irqs_disabled())
1137 return false;
1138 return true;
1139}
1140
373701b1
JN
1141/* helper for handling conditionals in various for_each macros */
1142#define for_each_if(condition) if (!(condition)) {} else
1143
1da177e4 1144#endif