]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - include/drm/drmP.h
Replace <asm/uaccess.h> with <linux/uaccess.h> globally
[mirror_ubuntu-artful-kernel.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>
7c0f6ba6 64#include <linux/uaccess.h>
96993908 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>
85e634bc 79#include <drm/drm_drv.h>
1da177e4 80
de477254
PG
81struct module;
82
c153f45f
EA
83struct drm_file;
84struct drm_device;
cc5ea594 85struct drm_agp_head;
ba8286fa
DV
86struct drm_local_map;
87struct drm_device_dma;
88struct drm_dma_handle;
d9fc9413 89struct drm_gem_object;
3b96a0b1 90struct drm_master;
34a67dd7 91struct drm_vblank_crtc;
c153f45f 92
edb37a95 93struct device_node;
ebc64e45 94struct videomode;
3aac4502 95struct reservation_object;
b5e9c1a2 96struct dma_buf_attachment;
ebc64e45 97
87fdff81 98/*
346fea63 99 * The following categories are defined:
1414b76c
LD
100 *
101 * CORE: Used in the generic drm code: drm_ioctl.c, drm_mm.c, drm_memory.c, ...
102 * This is the category used by the DRM_DEBUG() macro.
103 *
104 * DRIVER: Used in the vendor specific part of the driver: i915, radeon, ...
105 * This is the category used by the DRM_DEBUG_DRIVER() macro.
87fdff81 106 *
1414b76c
LD
107 * KMS: used in the modesetting code.
108 * This is the category used by the DRM_DEBUG_KMS() macro.
87fdff81 109 *
1414b76c
LD
110 * PRIME: used in the prime code.
111 * This is the category used by the DRM_DEBUG_PRIME() macro.
87fdff81 112 *
17a38d9c
DV
113 * ATOMIC: used in the atomic code.
114 * This is the category used by the DRM_DEBUG_ATOMIC() macro.
115 *
235fabe0
VS
116 * VBL: used for verbose debug message in the vblank code
117 * This is the category used by the DRM_DEBUG_VBL() macro.
118 *
1414b76c
LD
119 * Enabling verbose debug messages is done through the drm.debug parameter,
120 * each category being enabled by a bit.
121 *
122 * drm.debug=0x1 will enable CORE messages
123 * drm.debug=0x2 will enable DRIVER messages
124 * drm.debug=0x3 will enable CORE and DRIVER messages
125 * ...
235fabe0 126 * drm.debug=0x3f will enable all messages
1414b76c
LD
127 *
128 * An interesting feature is that it's possible to enable verbose logging at
129 * run-time by echoing the debug value in its sysfs node:
130 * # echo 0xf > /sys/module/drm/parameters/debug
87fdff81 131 */
c4e68a58 132#define DRM_UT_NONE 0x00
1414b76c
LD
133#define DRM_UT_CORE 0x01
134#define DRM_UT_DRIVER 0x02
135#define DRM_UT_KMS 0x04
136#define DRM_UT_PRIME 0x08
17a38d9c 137#define DRM_UT_ATOMIC 0x10
235fabe0 138#define DRM_UT_VBL 0x20
fceffb32 139#define DRM_UT_STATE 0x40
4fefcb27 140
1da177e4
LT
141/***********************************************************************/
142/** \name DRM template customization defaults */
143/*@{*/
144
1da177e4 145/***********************************************************************/
1da177e4
LT
146/** \name Macros to make printk easier */
147/*@{*/
148
30b0da8d
DG
149#define _DRM_PRINTK(once, level, fmt, ...) \
150 do { \
151 printk##once(KERN_##level "[" DRM_NAME "] " fmt, \
152 ##__VA_ARGS__); \
153 } while (0)
154
155#define DRM_INFO(fmt, ...) \
156 _DRM_PRINTK(, INFO, fmt, ##__VA_ARGS__)
157#define DRM_NOTE(fmt, ...) \
158 _DRM_PRINTK(, NOTICE, fmt, ##__VA_ARGS__)
159#define DRM_WARN(fmt, ...) \
160 _DRM_PRINTK(, WARNING, fmt, ##__VA_ARGS__)
161
162#define DRM_INFO_ONCE(fmt, ...) \
163 _DRM_PRINTK(_once, INFO, fmt, ##__VA_ARGS__)
164#define DRM_NOTE_ONCE(fmt, ...) \
165 _DRM_PRINTK(_once, NOTICE, fmt, ##__VA_ARGS__)
166#define DRM_WARN_ONCE(fmt, ...) \
167 _DRM_PRINTK(_once, WARNING, fmt, ##__VA_ARGS__)
168
1da177e4
LT
169/**
170 * Error output.
171 *
172 * \param fmt printf() like format string.
173 * \param arg arguments
174 */
c4e68a58
SP
175#define DRM_DEV_ERROR(dev, fmt, ...) \
176 drm_dev_printk(dev, KERN_ERR, DRM_UT_NONE, __func__, " *ERROR*",\
177 fmt, ##__VA_ARGS__)
178#define DRM_ERROR(fmt, ...) \
6bd488db 179 drm_printk(KERN_ERR, DRM_UT_NONE, fmt, ##__VA_ARGS__)
1da177e4 180
5d13d425
RC
181/**
182 * Rate limited error output. Like DRM_ERROR() but won't flood the log.
183 *
184 * \param fmt printf() like format string.
185 * \param arg arguments
186 */
c4e68a58 187#define DRM_DEV_ERROR_RATELIMITED(dev, fmt, ...) \
5d13d425
RC
188({ \
189 static DEFINE_RATELIMIT_STATE(_rs, \
190 DEFAULT_RATELIMIT_INTERVAL, \
191 DEFAULT_RATELIMIT_BURST); \
192 \
193 if (__ratelimit(&_rs)) \
c4e68a58 194 DRM_DEV_ERROR(dev, fmt, ##__VA_ARGS__); \
5d13d425 195})
c4e68a58
SP
196#define DRM_ERROR_RATELIMITED(fmt, ...) \
197 DRM_DEV_ERROR_RATELIMITED(NULL, fmt, ##__VA_ARGS__)
5d13d425 198
c4e68a58
SP
199#define DRM_DEV_INFO(dev, fmt, ...) \
200 drm_dev_printk(dev, KERN_INFO, DRM_UT_NONE, __func__, "", fmt, \
201 ##__VA_ARGS__)
1da177e4 202
c4e68a58
SP
203#define DRM_DEV_INFO_ONCE(dev, fmt, ...) \
204({ \
205 static bool __print_once __read_mostly; \
206 if (!__print_once) { \
207 __print_once = true; \
208 DRM_DEV_INFO(dev, fmt, ##__VA_ARGS__); \
209 } \
210})
48b8f631 211
1da177e4
LT
212/**
213 * Debug output.
b5e89ed5 214 *
1da177e4
LT
215 * \param fmt printf() like format string.
216 * \param arg arguments
217 */
c4e68a58
SP
218#define DRM_DEV_DEBUG(dev, fmt, args...) \
219 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_CORE, __func__, "", fmt, \
220 ##args)
6bd488db
JP
221#define DRM_DEBUG(fmt, ...) \
222 drm_printk(KERN_DEBUG, DRM_UT_CORE, fmt, ##__VA_ARGS__)
4fefcb27 223
c4e68a58
SP
224#define DRM_DEV_DEBUG_DRIVER(dev, fmt, args...) \
225 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_DRIVER, __func__, "", \
226 fmt, ##args)
6bd488db
JP
227#define DRM_DEBUG_DRIVER(fmt, ...) \
228 drm_printk(KERN_DEBUG, DRM_UT_DRIVER, fmt, ##__VA_ARGS__)
c4e68a58
SP
229
230#define DRM_DEV_DEBUG_KMS(dev, fmt, args...) \
231 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_KMS, __func__, "", fmt, \
232 ##args)
6bd488db
JP
233#define DRM_DEBUG_KMS(fmt, ...) \
234 drm_printk(KERN_DEBUG, DRM_UT_KMS, fmt, ##__VA_ARGS__)
c4e68a58
SP
235
236#define DRM_DEV_DEBUG_PRIME(dev, fmt, args...) \
237 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_PRIME, __func__, "", \
238 fmt, ##args)
6bd488db
JP
239#define DRM_DEBUG_PRIME(fmt, ...) \
240 drm_printk(KERN_DEBUG, DRM_UT_PRIME, fmt, ##__VA_ARGS__)
c4e68a58
SP
241
242#define DRM_DEV_DEBUG_ATOMIC(dev, fmt, args...) \
243 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_ATOMIC, __func__, "", \
244 fmt, ##args)
6bd488db
JP
245#define DRM_DEBUG_ATOMIC(fmt, ...) \
246 drm_printk(KERN_DEBUG, DRM_UT_ATOMIC, fmt, ##__VA_ARGS__)
c4e68a58
SP
247
248#define DRM_DEV_DEBUG_VBL(dev, fmt, args...) \
249 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_VBL, __func__, "", fmt, \
250 ##args)
6bd488db
JP
251#define DRM_DEBUG_VBL(fmt, ...) \
252 drm_printk(KERN_DEBUG, DRM_UT_VBL, fmt, ##__VA_ARGS__)
1da177e4 253
c4e68a58
SP
254#define _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, level, fmt, args...) \
255({ \
256 static DEFINE_RATELIMIT_STATE(_rs, \
257 DEFAULT_RATELIMIT_INTERVAL, \
258 DEFAULT_RATELIMIT_BURST); \
259 if (__ratelimit(&_rs)) \
260 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_ ## level, \
261 __func__, "", fmt, ##args); \
262})
27528c66
L
263
264/**
265 * Rate limited debug output. Like DRM_DEBUG() but won't flood the log.
266 *
267 * \param fmt printf() like format string.
268 * \param arg arguments
269 */
c4e68a58
SP
270#define DRM_DEV_DEBUG_RATELIMITED(dev, fmt, args...) \
271 DEV__DRM_DEFINE_DEBUG_RATELIMITED(dev, CORE, fmt, ##args)
27528c66 272#define DRM_DEBUG_RATELIMITED(fmt, args...) \
c4e68a58
SP
273 DRM_DEV_DEBUG_RATELIMITED(NULL, fmt, ##args)
274#define DRM_DEV_DEBUG_DRIVER_RATELIMITED(dev, fmt, args...) \
275 _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, DRIVER, fmt, ##args)
27528c66 276#define DRM_DEBUG_DRIVER_RATELIMITED(fmt, args...) \
c4e68a58
SP
277 DRM_DEV_DEBUG_DRIVER_RATELIMITED(NULL, fmt, ##args)
278#define DRM_DEV_DEBUG_KMS_RATELIMITED(dev, fmt, args...) \
279 _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, KMS, fmt, ##args)
27528c66 280#define DRM_DEBUG_KMS_RATELIMITED(fmt, args...) \
c4e68a58
SP
281 DRM_DEV_DEBUG_KMS_RATELIMITED(NULL, fmt, ##args)
282#define DRM_DEV_DEBUG_PRIME_RATELIMITED(dev, fmt, args...) \
283 _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, PRIME, fmt, ##args)
27528c66 284#define DRM_DEBUG_PRIME_RATELIMITED(fmt, args...) \
c4e68a58 285 DRM_DEV_DEBUG_PRIME_RATELIMITED(NULL, fmt, ##args)
27528c66 286
65c7dc18
RC
287/* Format strings and argument splitters to simplify printing
288 * various "complex" objects
289 */
290#define DRM_MODE_FMT "%d:\"%s\" %d %d %d %d %d %d %d %d %d %d 0x%x 0x%x"
291#define DRM_MODE_ARG(m) \
292 (m)->base.id, (m)->name, (m)->vrefresh, (m)->clock, \
293 (m)->hdisplay, (m)->hsync_start, (m)->hsync_end, (m)->htotal, \
294 (m)->vdisplay, (m)->vsync_start, (m)->vsync_end, (m)->vtotal, \
295 (m)->type, (m)->flags
296
297#define DRM_RECT_FMT "%dx%d%+d%+d"
298#define DRM_RECT_ARG(r) drm_rect_width(r), drm_rect_height(r), (r)->x1, (r)->y1
299
300/* for rect's in fixed-point format: */
301#define DRM_RECT_FP_FMT "%d.%06ux%d.%06u%+d.%06u%+d.%06u"
302#define DRM_RECT_FP_ARG(r) \
303 drm_rect_width(r) >> 16, ((drm_rect_width(r) & 0xffff) * 15625) >> 10, \
304 drm_rect_height(r) >> 16, ((drm_rect_height(r) & 0xffff) * 15625) >> 10, \
305 (r)->x1 >> 16, (((r)->x1 & 0xffff) * 15625) >> 10, \
306 (r)->y1 >> 16, (((r)->y1 & 0xffff) * 15625) >> 10
307
1da177e4
LT
308/*@}*/
309
1da177e4
LT
310/***********************************************************************/
311/** \name Internal types and structures */
312/*@{*/
313
1da177e4 314#define DRM_IF_VERSION(maj, min) (maj << 16 | min)
1da177e4 315
1da177e4
LT
316/**
317 * Ioctl function type.
318 *
319 * \param inode device inode.
6c340eac 320 * \param file_priv DRM file private pointer.
1da177e4
LT
321 * \param cmd command.
322 * \param arg argument.
323 */
c153f45f
EA
324typedef int drm_ioctl_t(struct drm_device *dev, void *data,
325 struct drm_file *file_priv);
1da177e4 326
9a186645
DA
327typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
328 unsigned long arg);
329
1a95916f
KH
330#define DRM_IOCTL_NR(n) _IOC_NR(n)
331#define DRM_MAJOR 226
332
a7a2cc31
DA
333#define DRM_AUTH 0x1
334#define DRM_MASTER 0x2
335#define DRM_ROOT_ONLY 0x4
f453ba04 336#define DRM_CONTROL_ALLOW 0x8
ed8b6704 337#define DRM_UNLOCKED 0x10
1793126f 338#define DRM_RENDER_ALLOW 0x20
a7a2cc31 339
c153f45f
EA
340struct drm_ioctl_desc {
341 unsigned int cmd;
a7a2cc31 342 int flags;
c972d750 343 drm_ioctl_t *func;
b9434d0f 344 const char *name;
c153f45f
EA
345};
346
347/**
348 * Creates a driver or general drm_ioctl_desc array entry for the given
349 * ioctl, for use by drm_ioctl().
350 */
1b2f1489 351
066626d5
EV
352#define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags) \
353 [DRM_IOCTL_NR(DRM_IOCTL_##ioctl) - DRM_COMMAND_BASE] = { \
354 .cmd = DRM_IOCTL_##ioctl, \
355 .func = _func, \
356 .flags = _flags, \
357 .name = #ioctl \
358 }
1da177e4 359
c9a9c5e0
KH
360/* Event queued up for userspace to read */
361struct drm_pending_event {
3b24f7d6 362 struct completion *completion;
c9a9c5e0 363 struct drm_event *event;
f54d1867 364 struct dma_fence *fence;
c9a9c5e0 365 struct list_head link;
681047b4 366 struct list_head pending_link;
c9a9c5e0 367 struct drm_file *file_priv;
b9c2c9ae
JB
368 pid_t pid; /* pid of requester, no guarantee it's valid by the time
369 we deliver the event, for tracing only */
c9a9c5e0
KH
370};
371
3248877e 372struct drm_prime_file_private {
3248877e 373 struct mutex lock;
077675c1
CW
374 struct rb_root dmabufs;
375 struct rb_root handles;
3248877e
DA
376};
377
1da177e4 378/** File private data */
84b1fd10 379struct drm_file {
39868bd7 380 unsigned authenticated :1;
39868bd7
CW
381 /* true when the client has asked us to expose stereo 3D mode flags */
382 unsigned stereo_allowed :1;
681e7ec7
MR
383 /*
384 * true if client understands CRTC primary planes and cursor planes
385 * in the plane list
386 */
387 unsigned universal_planes:1;
88a48e29
RC
388 /* true if client understands atomic properties */
389 unsigned atomic:1;
a0af2e53 390 /*
0aae5920 391 * This client is the creator of @master.
a0af2e53
TH
392 * Protected by struct drm_device::master_mutex.
393 */
0aae5920 394 unsigned is_master:1;
39868bd7 395
5fce5e0b 396 struct pid *pid;
b5e89ed5 397 drm_magic_t magic;
bd1b331f 398 struct list_head lhead;
2c14f28b 399 struct drm_minor *minor;
b5e89ed5 400 unsigned long lock_count;
7c1c2871 401
673a394b
EA
402 /** Mapping of mm object handles to object pointers. */
403 struct idr object_idr;
404 /** Lock for synchronization of access to object_idr. */
405 spinlock_t table_lock;
7c1c2871 406
6c340eac 407 struct file *filp;
8562b3f2 408 void *driver_priv;
7c1c2871 409
7c1c2871 410 struct drm_master *master; /* master this node is currently associated with
95c081c1 411 N.B. not always dev->master */
4b096ac1
DV
412 /**
413 * fbs - List of framebuffers associated with this file.
414 *
415 * Protected by fbs_lock. Note that the fbs list holds a reference on
416 * the fb object to prevent it from untimely disappearing.
417 */
f453ba04 418 struct list_head fbs;
4b096ac1 419 struct mutex fbs_lock;
c9a9c5e0 420
e2f5d2ea
DS
421 /** User-created blob properties; this retains a reference on the
422 * property. */
423 struct list_head blobs;
424
c9a9c5e0 425 wait_queue_head_t event_wait;
681047b4 426 struct list_head pending_event_list;
c9a9c5e0
KH
427 struct list_head event_list;
428 int event_space;
3248877e 429
9b2c0b7f
CW
430 struct mutex event_read_lock;
431
3248877e 432 struct drm_prime_file_private prime;
84b1fd10 433};
1da177e4 434
1da177e4
LT
435/**
436 * Lock data.
437 */
55910517 438struct drm_lock_data {
c60ce623 439 struct drm_hw_lock *hw_lock; /**< Hardware lock */
8562b3f2
DA
440 /** Private of lock holder's file (NULL=kernel) */
441 struct drm_file *file_priv;
1da177e4 442 wait_queue_head_t lock_queue; /**< Queue of blocked processes */
b5e89ed5 443 unsigned long lock_time; /**< Time of last lock in jiffies */
040ac320
TH
444 spinlock_t spinlock;
445 uint32_t kernel_waiters;
446 uint32_t user_waiters;
447 int idle_has_lock;
55910517 448};
1da177e4 449
27641c3f
MK
450/* Flags and return codes for get_vblank_timestamp() driver function. */
451#define DRM_CALLED_FROM_VBLIRQ 1
452#define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
3d3cbd84 453#define DRM_VBLANKTIME_IN_VBLANK (1 << 1)
27641c3f
MK
454
455/* get_scanout_position() return flags */
456#define DRM_SCANOUTPOS_VALID (1 << 0)
3d3cbd84 457#define DRM_SCANOUTPOS_IN_VBLANK (1 << 1)
27641c3f
MK
458#define DRM_SCANOUTPOS_ACCURATE (1 << 2)
459
cb8a239b 460enum drm_minor_type {
a3ccc461 461 DRM_MINOR_PRIMARY,
cb8a239b
DH
462 DRM_MINOR_CONTROL,
463 DRM_MINOR_RENDER,
464 DRM_MINOR_CNT,
465};
2c14f28b 466
955b12de
BG
467/**
468 * Info file list entry. This structure represents a debugfs or proc file to
469 * be created by the drm core
470 */
471struct drm_info_list {
472 const char *name; /** file name */
473 int (*show)(struct seq_file*, void*); /** show callback */
474 u32 driver_features; /**< Required driver features for this entry */
475 void *data;
476};
477
478/**
479 * debugfs node structure. This structure represents a debugfs file.
480 */
481struct drm_info_node {
482 struct list_head list;
483 struct drm_minor *minor;
ce089b54 484 const struct drm_info_list *info_ent;
955b12de
BG
485 struct dentry *dent;
486};
487
1da177e4 488/**
2c14f28b 489 * DRM minor structure. This structure represents a drm minor number.
1da177e4 490 */
2c14f28b
DA
491struct drm_minor {
492 int index; /**< Minor device number */
493 int type; /**< Control or render */
5bdebb18 494 struct device *kdev; /**< Linux device */
1da177e4 495 struct drm_device *dev;
955b12de 496
955b12de 497 struct dentry *debugfs_root;
b3e067c0
MS
498
499 struct list_head debugfs_list;
500 struct mutex debugfs_lock; /* Protects debugfs_list. */
84b1fd10 501};
1da177e4
LT
502
503/**
504 * DRM device structure. This structure represent a complete card that
505 * may contain multiple heads.
506 */
84b1fd10 507struct drm_device {
b3f2333d 508 struct list_head legacy_dev_list;/**< list of devices per driver for stealth attach cleanup */
b5e89ed5 509 int if_version; /**< Highest interface version set */
1da177e4 510
45e212d2
DH
511 /** \name Lifetime Management */
512 /*@{ */
099d1c29 513 struct kref ref; /**< Object ref-count */
45e212d2
DH
514 struct device *dev; /**< Device structure of bus-device */
515 struct drm_driver *driver; /**< DRM driver managing the device */
516 void *dev_private; /**< DRM driver private data */
45e212d2
DH
517 struct drm_minor *control; /**< Control node */
518 struct drm_minor *primary; /**< Primary node */
519 struct drm_minor *render; /**< Render node */
95c081c1
DV
520
521 /* currently active master for this device. Protected by master_mutex */
522 struct drm_master *master;
523
45e212d2 524 atomic_t unplugged; /**< Flag whether dev is dead */
07b48c3a 525 struct inode *anon_inode; /**< inode for private address-space */
ca8e2ad7 526 char *unique; /**< unique name of the device */
45e212d2
DH
527 /*@} */
528
1da177e4 529 /** \name Locks */
b5e89ed5 530 /*@{ */
30e2fb18 531 struct mutex struct_mutex; /**< For others */
c996fd0b 532 struct mutex master_mutex; /**< For drm_minor::master and drm_file::is_master */
b5e89ed5 533 /*@} */
1da177e4
LT
534
535 /** \name Usage Counters */
b5e89ed5 536 /*@{ */
fc8fd40e 537 int open_count; /**< Outstanding files open, protected by drm_global_mutex. */
2177a218 538 spinlock_t buf_lock; /**< For drm_device::buf_use and a few other things. */
b5e89ed5
DA
539 int buf_use; /**< Buffers in use -- cannot alloc */
540 atomic_t buf_alloc; /**< Buffer allocation in progress */
541 /*@} */
1da177e4 542
1d2ac403 543 struct mutex filelist_mutex;
bd1b331f 544 struct list_head filelist;
1da177e4
LT
545
546 /** \name Memory management */
b5e89ed5 547 /*@{ */
bd1b331f 548 struct list_head maplist; /**< Linked list of regions */
e0be428e 549 struct drm_open_hash map_hash; /**< User token hash table for maps */
1da177e4
LT
550
551 /** \name Context handle management */
b5e89ed5 552 /*@{ */
bd1b331f 553 struct list_head ctxlist; /**< Linked list of context handles */
30e2fb18 554 struct mutex ctxlist_mutex; /**< For ctxlist */
1da177e4 555
62968144 556 struct idr ctx_idr;
1da177e4 557
bd1b331f 558 struct list_head vmalist; /**< List of vmas (for debugging) */
f453ba04 559
b5e89ed5 560 /*@} */
1da177e4 561
a344a7e7 562 /** \name DMA support */
b5e89ed5 563 /*@{ */
cdd55a29 564 struct drm_device_dma *dma; /**< Optional pointer for DMA support */
b5e89ed5 565 /*@} */
1da177e4
LT
566
567 /** \name Context support */
b5e89ed5 568 /*@{ */
7c1a38e3 569
1da177e4 570 __volatile__ long context_flag; /**< Context swapping flag */
b5e89ed5 571 int last_context; /**< Last current context */
b5e89ed5
DA
572 /*@} */
573
1da177e4 574 /** \name VBLANK IRQ support */
b5e89ed5 575 /*@{ */
b46004b7
TR
576 bool irq_enabled;
577 int irq;
b5e89ed5 578
00185e66
VS
579 /*
580 * If true, vblank interrupt will be disabled immediately when the
581 * refcount drops to zero, as opposed to via the vblank disable
582 * timer.
583 * This can be set to true it the hardware has a working vblank
584 * counter and the driver uses drm_vblank_on() and drm_vblank_off()
585 * appropriately.
586 */
587 bool vblank_disable_immediate;
588
5380e929
VS
589 /* array of size num_crtcs */
590 struct drm_vblank_crtc *vblank;
0a3e67a4 591
27641c3f 592 spinlock_t vblank_time_lock; /**< Protects vblank count and time updates during vblank enable/disable */
b5e89ed5 593 spinlock_t vbl_lock;
0a3e67a4
JB
594
595 u32 max_vblank_count; /**< size of vblank counter register */
b5e89ed5 596
c9a9c5e0
KH
597 /**
598 * List of events
599 */
600 struct list_head vblank_event_list;
601 spinlock_t event_lock;
602
b5e89ed5 603 /*@} */
b5e89ed5 604
55910517 605 struct drm_agp_head *agp; /**< AGP data */
1da177e4 606
b5e89ed5 607 struct pci_dev *pdev; /**< PCI device structure */
1da177e4 608#ifdef __alpha__
1da177e4 609 struct pci_controller *hose;
1da177e4 610#endif
dcdb1674
JC
611
612 struct platform_device *platformdev; /**< Platform device struture */
dc5698e8 613 struct virtio_device *virtdev;
dcdb1674 614
55910517 615 struct drm_sg_mem *sg; /**< Scatter gather memory */
19227561 616 unsigned int num_crtcs; /**< Number of CRTCs on this device */
b5e89ed5 617
69d516c0
DH
618 struct {
619 int context;
620 struct drm_hw_lock *lock;
621 } sigdata;
622
f77d390c 623 struct drm_local_map *agp_buffer_map;
d1f2b55a 624 unsigned int agp_buffer_token;
bea5679f 625
417009fb 626 struct drm_mode_config mode_config; /**< Current mode config */
f453ba04 627
673a394b
EA
628 /** \name GEM information */
629 /*@{ */
cd4f013f 630 struct mutex object_name_lock;
673a394b 631 struct idr object_name_idr;
b04a5906 632 struct drm_vma_offset_manager *vma_offset_manager;
673a394b 633 /*@} */
5bcf719b 634 int switch_power_state;
84b1fd10 635};
1da177e4 636
34a67dd7
DV
637#include <drm/drm_irq.h>
638
5bcf719b
DA
639#define DRM_SWITCH_POWER_ON 0
640#define DRM_SWITCH_POWER_OFF 1
641#define DRM_SWITCH_POWER_CHANGING 2
13bb9cc8 642#define DRM_SWITCH_POWER_DYNAMIC_OFF 3
5bcf719b 643
b5e89ed5
DA
644static __inline__ int drm_core_check_feature(struct drm_device *dev,
645 int feature)
1da177e4
LT
646{
647 return ((dev->driver->driver_features & feature) ? 1 : 0);
648}
649
2c07a21d
DA
650static inline void drm_device_set_unplugged(struct drm_device *dev)
651{
652 smp_wmb();
653 atomic_set(&dev->unplugged, 1);
654}
655
656static inline int drm_device_is_unplugged(struct drm_device *dev)
657{
658 int ret = atomic_read(&dev->unplugged);
659 smp_rmb();
660 return ret;
661}
662
43683057 663static inline bool drm_is_render_client(const struct drm_file *file_priv)
1793126f
DH
664{
665 return file_priv->minor->type == DRM_MINOR_RENDER;
666}
667
ac05dbc5
TH
668static inline bool drm_is_control_client(const struct drm_file *file_priv)
669{
670 return file_priv->minor->type == DRM_MINOR_CONTROL;
671}
672
43683057
TH
673static inline bool drm_is_primary_client(const struct drm_file *file_priv)
674{
a3ccc461 675 return file_priv->minor->type == DRM_MINOR_PRIMARY;
43683057
TH
676}
677
1da177e4
LT
678/******************************************************************/
679/** \name Internal function definitions */
680/*@{*/
681
1da177e4 682 /* Driver support (drm_drv.h) */
5101020c 683extern int drm_ioctl_permit(u32 flags, struct drm_file *file_priv);
ed8b6704
AB
684extern long drm_ioctl(struct file *filp,
685 unsigned int cmd, unsigned long arg);
55edf41b 686#ifdef CONFIG_COMPAT
b5e89ed5
DA
687extern long drm_compat_ioctl(struct file *filp,
688 unsigned int cmd, unsigned long arg);
55edf41b
JN
689#else
690/* Let drm_compat_ioctl be assigned to .compat_ioctl unconditionally */
691#define drm_compat_ioctl NULL
692#endif
4beb6d9f 693extern bool drm_ioctl_flags(unsigned int nr, unsigned int *flags);
1da177e4 694
bcb877e4
DV
695/* File Operations (drm_fops.c) */
696int drm_open(struct inode *inode, struct file *filp);
697ssize_t drm_read(struct file *filp, char __user *buffer,
698 size_t count, loff_t *offset);
699int drm_release(struct inode *inode, struct file *filp);
bcb877e4 700unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
4020b220
DV
701int drm_event_reserve_init_locked(struct drm_device *dev,
702 struct drm_file *file_priv,
703 struct drm_pending_event *p,
704 struct drm_event *e);
2dd500f1
DV
705int drm_event_reserve_init(struct drm_device *dev,
706 struct drm_file *file_priv,
707 struct drm_pending_event *p,
708 struct drm_event *e);
709void drm_event_cancel_free(struct drm_device *dev,
710 struct drm_pending_event *p);
fb740cf2
DV
711void drm_send_event_locked(struct drm_device *dev, struct drm_pending_event *e);
712void drm_send_event(struct drm_device *dev, struct drm_pending_event *e);
1da177e4 713
78238757
DV
714/* Misc. IOCTL support (drm_ioctl.c) */
715int drm_noop(struct drm_device *dev, void *data,
716 struct drm_file *file_priv);
4b63539b
DV
717int drm_invalid_op(struct drm_device *dev, void *data,
718 struct drm_file *file_priv);
1da177e4 719
673a394b
EA
720/* Cache management (drm_cache.c) */
721void drm_clflush_pages(struct page *pages[], unsigned long num_pages);
9da3da66 722void drm_clflush_sg(struct sg_table *st);
c2d15359 723void drm_clflush_virt_range(void *addr, unsigned long length);
673a394b 724
040ac320
TH
725/*
726 * These are exported to drivers so that they can implement fencing using
727 * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
728 */
729
955b12de
BG
730 /* Debugfs support */
731#if defined(CONFIG_DEBUG_FS)
7d74795b
LD
732extern int drm_debugfs_create_files(const struct drm_info_list *files,
733 int count, struct dentry *root,
734 struct drm_minor *minor);
735extern int drm_debugfs_remove_files(const struct drm_info_list *files,
736 int count, struct drm_minor *minor);
66ee52e2 737#else
66ee52e2
TR
738static inline int drm_debugfs_create_files(const struct drm_info_list *files,
739 int count, struct dentry *root,
740 struct drm_minor *minor)
741{
742 return 0;
743}
744
745static inline int drm_debugfs_remove_files(const struct drm_info_list *files,
746 int count, struct drm_minor *minor)
747{
748 return 0;
749}
955b12de
BG
750#endif
751
a4fce9cb
CW
752struct dma_buf_export_info;
753
89177644 754extern struct dma_buf *drm_gem_prime_export(struct drm_device *dev,
56a76c01
CW
755 struct drm_gem_object *obj,
756 int flags);
3248877e
DA
757extern int drm_gem_prime_handle_to_fd(struct drm_device *dev,
758 struct drm_file *file_priv, uint32_t handle, uint32_t flags,
759 int *prime_fd);
89177644
AP
760extern struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,
761 struct dma_buf *dma_buf);
3248877e
DA
762extern int drm_gem_prime_fd_to_handle(struct drm_device *dev,
763 struct drm_file *file_priv, int prime_fd, uint32_t *handle);
a4fce9cb
CW
764struct dma_buf *drm_gem_dmabuf_export(struct drm_device *dev,
765 struct dma_buf_export_info *exp_info);
c1d6798d 766extern void drm_gem_dmabuf_release(struct dma_buf *dma_buf);
3248877e 767
51ab7ba2
DA
768extern int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages,
769 dma_addr_t *addrs, int max_pages);
34eab43e 770extern struct sg_table *drm_prime_pages_to_sg(struct page **pages, unsigned int nr_pages);
3248877e
DA
771extern void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg);
772
1da177e4 773
ba8286fa
DV
774extern struct drm_dma_handle *drm_pci_alloc(struct drm_device *dev, size_t size,
775 size_t align);
776extern void drm_pci_free(struct drm_device *dev, struct drm_dma_handle * dmah);
1da177e4
LT
777
778 /* sysfs support (drm_sysfs.c) */
f453ba04 779extern void drm_sysfs_hotplug_event(struct drm_device *dev);
1da177e4 780
673a394b 781
8410ea3b
DA
782/*@}*/
783
784/* PCI section */
785static __inline__ int drm_pci_device_is_agp(struct drm_device *dev)
786{
b5e89ed5
DA
787 if (dev->driver->device_is_agp != NULL) {
788 int err = (*dev->driver->device_is_agp) (dev);
789
cda17380
DA
790 if (err != 2) {
791 return err;
792 }
793 }
794
795 return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
796}
4efafebe 797void drm_pci_agp_destroy(struct drm_device *dev);
cda17380 798
8410ea3b
DA
799extern int drm_pci_init(struct drm_driver *driver, struct pci_driver *pdriver);
800extern void drm_pci_exit(struct drm_driver *driver, struct pci_driver *pdriver);
a9e3c90c 801#ifdef CONFIG_PCI
8410ea3b 802extern int drm_get_pci_dev(struct pci_dev *pdev,
dcdb1674
JC
803 const struct pci_device_id *ent,
804 struct drm_driver *driver);
915b4d11 805extern int drm_pci_set_busid(struct drm_device *dev, struct drm_master *master);
a9e3c90c
TR
806#else
807static inline int drm_get_pci_dev(struct pci_dev *pdev,
808 const struct pci_device_id *ent,
809 struct drm_driver *driver)
810{
811 return -ENOSYS;
812}
813
814static inline int drm_pci_set_busid(struct drm_device *dev,
815 struct drm_master *master)
816{
817 return -ENOSYS;
818}
819#endif
8410ea3b 820
f4297784
DA
821#define DRM_PCIE_SPEED_25 1
822#define DRM_PCIE_SPEED_50 2
823#define DRM_PCIE_SPEED_80 4
824
825extern int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *speed_mask);
60d8edd4 826extern int drm_pcie_get_max_link_width(struct drm_device *dev, u32 *mlw);
8410ea3b
DA
827
828/* platform section */
829extern int drm_platform_init(struct drm_driver *driver, struct platform_device *platform_device);
8410ea3b 830
cc1f7194
DA
831/* returns true if currently okay to sleep */
832static __inline__ bool drm_can_sleep(void)
833{
834 if (in_atomic() || in_dbg_master() || irqs_disabled())
835 return false;
836 return true;
837}
838
373701b1
JN
839/* helper for handling conditionals in various for_each macros */
840#define for_each_if(condition) if (!(condition)) {} else
841
1da177e4 842#endif