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