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 DH |
58 | #include <linux/workqueue.h> |
59 | ||
60 | #include <asm/mman.h> | |
1da177e4 | 61 | #include <asm/pgalloc.h> |
96993908 DH |
62 | #include <asm/uaccess.h> |
63 | ||
d7d2c48e DH |
64 | #include <uapi/drm/drm.h> |
65 | #include <uapi/drm/drm_mode.h> | |
66 | ||
67 | #include <drm/drm_agpsupport.h> | |
68 | #include <drm/drm_crtc.h> | |
69 | #include <drm/drm_global.h> | |
96993908 | 70 | #include <drm/drm_hashtab.h> |
d7d2c48e | 71 | #include <drm/drm_mem_util.h> |
96993908 DH |
72 | #include <drm/drm_mm.h> |
73 | #include <drm/drm_os_linux.h> | |
19218e48 | 74 | #include <drm/drm_sarea.h> |
0de23977 | 75 | #include <drm/drm_vma_manager.h> |
1da177e4 | 76 | |
de477254 PG |
77 | struct module; |
78 | ||
c153f45f EA |
79 | struct drm_file; |
80 | struct drm_device; | |
cc5ea594 | 81 | struct drm_agp_head; |
ba8286fa DV |
82 | struct drm_local_map; |
83 | struct drm_device_dma; | |
84 | struct drm_dma_handle; | |
c153f45f | 85 | |
edb37a95 | 86 | struct device_node; |
ebc64e45 | 87 | struct videomode; |
3aac4502 | 88 | struct reservation_object; |
ebc64e45 | 89 | |
87fdff81 | 90 | /* |
1414b76c LD |
91 | * 4 debug categories are defined: |
92 | * | |
93 | * CORE: Used in the generic drm code: drm_ioctl.c, drm_mm.c, drm_memory.c, ... | |
94 | * This is the category used by the DRM_DEBUG() macro. | |
95 | * | |
96 | * DRIVER: Used in the vendor specific part of the driver: i915, radeon, ... | |
97 | * This is the category used by the DRM_DEBUG_DRIVER() macro. | |
87fdff81 | 98 | * |
1414b76c LD |
99 | * KMS: used in the modesetting code. |
100 | * This is the category used by the DRM_DEBUG_KMS() macro. | |
87fdff81 | 101 | * |
1414b76c LD |
102 | * PRIME: used in the prime code. |
103 | * This is the category used by the DRM_DEBUG_PRIME() macro. | |
87fdff81 | 104 | * |
1414b76c LD |
105 | * Enabling verbose debug messages is done through the drm.debug parameter, |
106 | * each category being enabled by a bit. | |
107 | * | |
108 | * drm.debug=0x1 will enable CORE messages | |
109 | * drm.debug=0x2 will enable DRIVER messages | |
110 | * drm.debug=0x3 will enable CORE and DRIVER messages | |
111 | * ... | |
112 | * drm.debug=0xf will enable all messages | |
113 | * | |
114 | * An interesting feature is that it's possible to enable verbose logging at | |
115 | * run-time by echoing the debug value in its sysfs node: | |
116 | * # echo 0xf > /sys/module/drm/parameters/debug | |
87fdff81 | 117 | */ |
1414b76c LD |
118 | #define DRM_UT_CORE 0x01 |
119 | #define DRM_UT_DRIVER 0x02 | |
120 | #define DRM_UT_KMS 0x04 | |
121 | #define DRM_UT_PRIME 0x08 | |
4fefcb27 | 122 | |
1287aa90 LD |
123 | extern __printf(2, 3) |
124 | void drm_ut_debug_printk(const char *function_name, | |
b9075fa9 JP |
125 | const char *format, ...); |
126 | extern __printf(2, 3) | |
9908fb65 | 127 | void drm_err(const char *func, const char *format, ...); |
5ad3d883 | 128 | |
1da177e4 LT |
129 | /***********************************************************************/ |
130 | /** \name DRM template customization defaults */ | |
131 | /*@{*/ | |
132 | ||
133 | /* driver capabilities and requirements mask */ | |
134 | #define DRIVER_USE_AGP 0x1 | |
1da177e4 LT |
135 | #define DRIVER_PCI_DMA 0x8 |
136 | #define DRIVER_SG 0x10 | |
137 | #define DRIVER_HAVE_DMA 0x20 | |
138 | #define DRIVER_HAVE_IRQ 0x40 | |
139 | #define DRIVER_IRQ_SHARED 0x80 | |
673a394b | 140 | #define DRIVER_GEM 0x1000 |
f453ba04 | 141 | #define DRIVER_MODESET 0x2000 |
3248877e | 142 | #define DRIVER_PRIME 0x4000 |
1793126f | 143 | #define DRIVER_RENDER 0x8000 |
8410ea3b | 144 | |
1da177e4 | 145 | /***********************************************************************/ |
1da177e4 LT |
146 | /** \name Macros to make printk easier */ |
147 | /*@{*/ | |
148 | ||
149 | /** | |
150 | * Error output. | |
151 | * | |
152 | * \param fmt printf() like format string. | |
153 | * \param arg arguments | |
154 | */ | |
5ad3d883 JP |
155 | #define DRM_ERROR(fmt, ...) \ |
156 | drm_err(__func__, fmt, ##__VA_ARGS__) | |
1da177e4 | 157 | |
5d13d425 RC |
158 | /** |
159 | * Rate limited error output. Like DRM_ERROR() but won't flood the log. | |
160 | * | |
161 | * \param fmt printf() like format string. | |
162 | * \param arg arguments | |
163 | */ | |
164 | #define DRM_ERROR_RATELIMITED(fmt, ...) \ | |
165 | ({ \ | |
166 | static DEFINE_RATELIMIT_STATE(_rs, \ | |
167 | DEFAULT_RATELIMIT_INTERVAL, \ | |
168 | DEFAULT_RATELIMIT_BURST); \ | |
169 | \ | |
170 | if (__ratelimit(&_rs)) \ | |
171 | drm_err(__func__, fmt, ##__VA_ARGS__); \ | |
172 | }) | |
173 | ||
5ad3d883 JP |
174 | #define DRM_INFO(fmt, ...) \ |
175 | printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__) | |
1da177e4 | 176 | |
48b8f631 JN |
177 | #define DRM_INFO_ONCE(fmt, ...) \ |
178 | printk_once(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__) | |
179 | ||
1da177e4 LT |
180 | /** |
181 | * Debug output. | |
b5e89ed5 | 182 | * |
1da177e4 LT |
183 | * \param fmt printf() like format string. |
184 | * \param arg arguments | |
185 | */ | |
4fefcb27 | 186 | #define DRM_DEBUG(fmt, args...) \ |
1da177e4 | 187 | do { \ |
a73d4e91 | 188 | if (unlikely(drm_debug & DRM_UT_CORE)) \ |
1287aa90 | 189 | drm_ut_debug_printk(__func__, fmt, ##args); \ |
4fefcb27 | 190 | } while (0) |
191 | ||
8a4c47f3 | 192 | #define DRM_DEBUG_DRIVER(fmt, args...) \ |
4fefcb27 | 193 | do { \ |
a73d4e91 | 194 | if (unlikely(drm_debug & DRM_UT_DRIVER)) \ |
1287aa90 | 195 | drm_ut_debug_printk(__func__, fmt, ##args); \ |
4fefcb27 | 196 | } while (0) |
a73d4e91 | 197 | #define DRM_DEBUG_KMS(fmt, args...) \ |
4fefcb27 | 198 | do { \ |
a73d4e91 | 199 | if (unlikely(drm_debug & DRM_UT_KMS)) \ |
1287aa90 | 200 | drm_ut_debug_printk(__func__, fmt, ##args); \ |
4fefcb27 | 201 | } while (0) |
3248877e DA |
202 | #define DRM_DEBUG_PRIME(fmt, args...) \ |
203 | do { \ | |
a73d4e91 | 204 | if (unlikely(drm_debug & DRM_UT_PRIME)) \ |
1287aa90 | 205 | drm_ut_debug_printk(__func__, fmt, ##args); \ |
1da177e4 | 206 | } while (0) |
1da177e4 | 207 | |
1da177e4 LT |
208 | /*@}*/ |
209 | ||
1da177e4 LT |
210 | /***********************************************************************/ |
211 | /** \name Internal types and structures */ | |
212 | /*@{*/ | |
213 | ||
1da177e4 | 214 | #define DRM_IF_VERSION(maj, min) (maj << 16 | min) |
1da177e4 | 215 | |
1da177e4 LT |
216 | /** |
217 | * Ioctl function type. | |
218 | * | |
219 | * \param inode device inode. | |
6c340eac | 220 | * \param file_priv DRM file private pointer. |
1da177e4 LT |
221 | * \param cmd command. |
222 | * \param arg argument. | |
223 | */ | |
c153f45f EA |
224 | typedef int drm_ioctl_t(struct drm_device *dev, void *data, |
225 | struct drm_file *file_priv); | |
1da177e4 | 226 | |
9a186645 DA |
227 | typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd, |
228 | unsigned long arg); | |
229 | ||
1a95916f KH |
230 | #define DRM_IOCTL_NR(n) _IOC_NR(n) |
231 | #define DRM_MAJOR 226 | |
232 | ||
a7a2cc31 DA |
233 | #define DRM_AUTH 0x1 |
234 | #define DRM_MASTER 0x2 | |
235 | #define DRM_ROOT_ONLY 0x4 | |
f453ba04 | 236 | #define DRM_CONTROL_ALLOW 0x8 |
ed8b6704 | 237 | #define DRM_UNLOCKED 0x10 |
1793126f | 238 | #define DRM_RENDER_ALLOW 0x20 |
a7a2cc31 | 239 | |
c153f45f EA |
240 | struct drm_ioctl_desc { |
241 | unsigned int cmd; | |
a7a2cc31 | 242 | int flags; |
c972d750 | 243 | drm_ioctl_t *func; |
1b2f1489 | 244 | unsigned int cmd_drv; |
b9434d0f | 245 | const char *name; |
c153f45f EA |
246 | }; |
247 | ||
248 | /** | |
249 | * Creates a driver or general drm_ioctl_desc array entry for the given | |
250 | * ioctl, for use by drm_ioctl(). | |
251 | */ | |
1b2f1489 DA |
252 | |
253 | #define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags) \ | |
b9434d0f | 254 | [DRM_IOCTL_NR(DRM_##ioctl)] = {.cmd = DRM_##ioctl, .func = _func, .flags = _flags, .cmd_drv = DRM_IOCTL_##ioctl, .name = #ioctl} |
1da177e4 | 255 | |
c9a9c5e0 KH |
256 | /* Event queued up for userspace to read */ |
257 | struct drm_pending_event { | |
258 | struct drm_event *event; | |
259 | struct list_head link; | |
260 | struct drm_file *file_priv; | |
b9c2c9ae JB |
261 | pid_t pid; /* pid of requester, no guarantee it's valid by the time |
262 | we deliver the event, for tracing only */ | |
c9a9c5e0 KH |
263 | void (*destroy)(struct drm_pending_event *event); |
264 | }; | |
265 | ||
3248877e DA |
266 | /* initial implementaton using a linked list - todo hashtab */ |
267 | struct drm_prime_file_private { | |
268 | struct list_head head; | |
269 | struct mutex lock; | |
270 | }; | |
271 | ||
1da177e4 | 272 | /** File private data */ |
84b1fd10 | 273 | struct drm_file { |
39868bd7 | 274 | unsigned authenticated :1; |
c996fd0b TH |
275 | /* Whether we're master for a minor. Protected by master_mutex */ |
276 | unsigned is_master :1; | |
39868bd7 CW |
277 | /* true when the client has asked us to expose stereo 3D mode flags */ |
278 | unsigned stereo_allowed :1; | |
681e7ec7 MR |
279 | /* |
280 | * true if client understands CRTC primary planes and cursor planes | |
281 | * in the plane list | |
282 | */ | |
283 | unsigned universal_planes:1; | |
39868bd7 | 284 | |
5fce5e0b EB |
285 | struct pid *pid; |
286 | kuid_t uid; | |
b5e89ed5 | 287 | drm_magic_t magic; |
bd1b331f | 288 | struct list_head lhead; |
2c14f28b | 289 | struct drm_minor *minor; |
b5e89ed5 | 290 | unsigned long lock_count; |
7c1c2871 | 291 | |
673a394b EA |
292 | /** Mapping of mm object handles to object pointers. */ |
293 | struct idr object_idr; | |
294 | /** Lock for synchronization of access to object_idr. */ | |
295 | spinlock_t table_lock; | |
7c1c2871 | 296 | |
6c340eac | 297 | struct file *filp; |
8562b3f2 | 298 | void *driver_priv; |
7c1c2871 | 299 | |
7c1c2871 DA |
300 | struct drm_master *master; /* master this node is currently associated with |
301 | N.B. not always minor->master */ | |
4b096ac1 DV |
302 | /** |
303 | * fbs - List of framebuffers associated with this file. | |
304 | * | |
305 | * Protected by fbs_lock. Note that the fbs list holds a reference on | |
306 | * the fb object to prevent it from untimely disappearing. | |
307 | */ | |
f453ba04 | 308 | struct list_head fbs; |
4b096ac1 | 309 | struct mutex fbs_lock; |
c9a9c5e0 KH |
310 | |
311 | wait_queue_head_t event_wait; | |
312 | struct list_head event_list; | |
313 | int event_space; | |
3248877e DA |
314 | |
315 | struct drm_prime_file_private prime; | |
84b1fd10 | 316 | }; |
1da177e4 | 317 | |
1da177e4 LT |
318 | /** |
319 | * Lock data. | |
320 | */ | |
55910517 | 321 | struct drm_lock_data { |
c60ce623 | 322 | struct drm_hw_lock *hw_lock; /**< Hardware lock */ |
8562b3f2 DA |
323 | /** Private of lock holder's file (NULL=kernel) */ |
324 | struct drm_file *file_priv; | |
1da177e4 | 325 | wait_queue_head_t lock_queue; /**< Queue of blocked processes */ |
b5e89ed5 | 326 | unsigned long lock_time; /**< Time of last lock in jiffies */ |
040ac320 TH |
327 | spinlock_t spinlock; |
328 | uint32_t kernel_waiters; | |
329 | uint32_t user_waiters; | |
330 | int idle_has_lock; | |
55910517 | 331 | }; |
1da177e4 | 332 | |
673a394b EA |
333 | /** |
334 | * This structure defines the drm_mm memory object, which will be used by the | |
335 | * DRM for its buffer objects. | |
336 | */ | |
337 | struct drm_gem_object { | |
338 | /** Reference count of this object */ | |
339 | struct kref refcount; | |
340 | ||
a8e11d1c DV |
341 | /** |
342 | * handle_count - gem file_priv handle count of this object | |
343 | * | |
344 | * Each handle also holds a reference. Note that when the handle_count | |
345 | * drops to 0 any global names (e.g. the id in the flink namespace) will | |
346 | * be cleared. | |
347 | * | |
348 | * Protected by dev->object_name_lock. | |
349 | * */ | |
350 | unsigned handle_count; | |
673a394b EA |
351 | |
352 | /** Related drm device */ | |
353 | struct drm_device *dev; | |
354 | ||
355 | /** File representing the shmem storage */ | |
356 | struct file *filp; | |
357 | ||
a2c0a97b | 358 | /* Mapping info for this object */ |
0de23977 | 359 | struct drm_vma_offset_node vma_node; |
a2c0a97b | 360 | |
673a394b EA |
361 | /** |
362 | * Size of the object, in bytes. Immutable over the object's | |
363 | * lifetime. | |
364 | */ | |
365 | size_t size; | |
366 | ||
367 | /** | |
368 | * Global name for this object, starts at 1. 0 means unnamed. | |
369 | * Access is covered by the object_name_lock in the related drm_device | |
370 | */ | |
371 | int name; | |
372 | ||
373 | /** | |
374 | * Memory domains. These monitor which caches contain read/write data | |
375 | * related to the object. When transitioning from one set of domains | |
376 | * to another, the driver is called to ensure that caches are suitably | |
377 | * flushed and invalidated | |
378 | */ | |
379 | uint32_t read_domains; | |
380 | uint32_t write_domain; | |
381 | ||
382 | /** | |
383 | * While validating an exec operation, the | |
384 | * new read/write domain values are computed here. | |
385 | * They will be transferred to the above values | |
386 | * at the point that any cache flushing occurs | |
387 | */ | |
388 | uint32_t pending_read_domains; | |
389 | uint32_t pending_write_domain; | |
390 | ||
319c933c DV |
391 | /** |
392 | * dma_buf - dma buf associated with this GEM object | |
393 | * | |
394 | * Pointer to the dma-buf associated with this gem object (either | |
395 | * through importing or exporting). We break the resulting reference | |
396 | * loop when the last gem handle for this object is released. | |
397 | * | |
398 | * Protected by obj->object_name_lock | |
399 | */ | |
400 | struct dma_buf *dma_buf; | |
3248877e | 401 | |
7106bf96 DV |
402 | /** |
403 | * import_attach - dma buf attachment backing this object | |
404 | * | |
405 | * Any foreign dma_buf imported as a gem object has this set to the | |
406 | * attachment point for the device. This is invariant over the lifetime | |
407 | * of a gem object. | |
408 | * | |
409 | * The driver's ->gem_free_object callback is responsible for cleaning | |
410 | * up the dma_buf attachment and references acquired at import time. | |
838cd445 DV |
411 | * |
412 | * Note that the drm gem/prime core does not depend upon drivers setting | |
413 | * this field any more. So for drivers where this doesn't make sense | |
414 | * (e.g. virtual devices or a displaylink behind an usb bus) they can | |
415 | * simply leave it as NULL. | |
7106bf96 | 416 | */ |
3248877e | 417 | struct dma_buf_attachment *import_attach; |
673a394b EA |
418 | }; |
419 | ||
c996fd0b TH |
420 | /** |
421 | * struct drm_master - drm master structure | |
422 | * | |
423 | * @refcount: Refcount for this master object. | |
424 | * @minor: Link back to minor char device we are master for. Immutable. | |
425 | * @unique: Unique identifier: e.g. busid. Protected by drm_global_mutex. | |
426 | * @unique_len: Length of unique field. Protected by drm_global_mutex. | |
c996fd0b TH |
427 | * @magiclist: Hash of used authentication tokens. Protected by struct_mutex. |
428 | * @magicfree: List of used authentication tokens. Protected by struct_mutex. | |
429 | * @lock: DRI lock information. | |
430 | * @driver_priv: Pointer to driver-private information. | |
431 | */ | |
7c1c2871 | 432 | struct drm_master { |
c996fd0b TH |
433 | struct kref refcount; |
434 | struct drm_minor *minor; | |
435 | char *unique; | |
436 | int unique_len; | |
7c1c2871 DA |
437 | struct drm_open_hash magiclist; |
438 | struct list_head magicfree; | |
c996fd0b TH |
439 | struct drm_lock_data lock; |
440 | void *driver_priv; | |
7c1c2871 DA |
441 | }; |
442 | ||
27641c3f MK |
443 | /* Size of ringbuffer for vblank timestamps. Just double-buffer |
444 | * in initial implementation. | |
445 | */ | |
446 | #define DRM_VBLANKTIME_RBSIZE 2 | |
447 | ||
448 | /* Flags and return codes for get_vblank_timestamp() driver function. */ | |
449 | #define DRM_CALLED_FROM_VBLIRQ 1 | |
450 | #define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0) | |
3d3cbd84 | 451 | #define DRM_VBLANKTIME_IN_VBLANK (1 << 1) |
27641c3f MK |
452 | |
453 | /* get_scanout_position() return flags */ | |
454 | #define DRM_SCANOUTPOS_VALID (1 << 0) | |
3d3cbd84 | 455 | #define DRM_SCANOUTPOS_IN_VBLANK (1 << 1) |
27641c3f MK |
456 | #define DRM_SCANOUTPOS_ACCURATE (1 << 2) |
457 | ||
1da177e4 LT |
458 | /** |
459 | * DRM driver structure. This structure represent the common code for | |
460 | * a family of cards. There will one drm_device for each card present | |
461 | * in this family | |
462 | */ | |
1da177e4 | 463 | struct drm_driver { |
22eae947 DA |
464 | int (*load) (struct drm_device *, unsigned long flags); |
465 | int (*firstopen) (struct drm_device *); | |
84b1fd10 | 466 | int (*open) (struct drm_device *, struct drm_file *); |
6c340eac | 467 | void (*preclose) (struct drm_device *, struct drm_file *file_priv); |
84b1fd10 | 468 | void (*postclose) (struct drm_device *, struct drm_file *); |
22eae947 DA |
469 | void (*lastclose) (struct drm_device *); |
470 | int (*unload) (struct drm_device *); | |
b932ccb5 | 471 | int (*suspend) (struct drm_device *, pm_message_t state); |
e8b962b6 | 472 | int (*resume) (struct drm_device *); |
c153f45f | 473 | int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv); |
b5e89ed5 | 474 | int (*dma_quiescent) (struct drm_device *); |
84b1fd10 | 475 | int (*context_dtor) (struct drm_device *dev, int context); |
915b4d11 | 476 | int (*set_busid)(struct drm_device *dev, struct drm_master *master); |
b5e89ed5 | 477 | |
0a3e67a4 JB |
478 | /** |
479 | * get_vblank_counter - get raw hardware vblank counter | |
480 | * @dev: DRM device | |
481 | * @crtc: counter to fetch | |
482 | * | |
3b02ab88 LP |
483 | * Driver callback for fetching a raw hardware vblank counter for @crtc. |
484 | * If a device doesn't have a hardware counter, the driver can simply | |
485 | * return the value of drm_vblank_count. The DRM core will account for | |
486 | * missed vblank events while interrupts where disabled based on system | |
487 | * timestamps. | |
0a3e67a4 JB |
488 | * |
489 | * Wraparound handling and loss of events due to modesetting is dealt | |
490 | * with in the DRM core code. | |
491 | * | |
492 | * RETURNS | |
493 | * Raw vblank counter value. | |
494 | */ | |
495 | u32 (*get_vblank_counter) (struct drm_device *dev, int crtc); | |
496 | ||
497 | /** | |
498 | * enable_vblank - enable vblank interrupt events | |
499 | * @dev: DRM device | |
500 | * @crtc: which irq to enable | |
501 | * | |
502 | * Enable vblank interrupts for @crtc. If the device doesn't have | |
503 | * a hardware vblank counter, this routine should be a no-op, since | |
504 | * interrupts will have to stay on to keep the count accurate. | |
505 | * | |
506 | * RETURNS | |
507 | * Zero on success, appropriate errno if the given @crtc's vblank | |
508 | * interrupt cannot be enabled. | |
509 | */ | |
510 | int (*enable_vblank) (struct drm_device *dev, int crtc); | |
511 | ||
512 | /** | |
513 | * disable_vblank - disable vblank interrupt events | |
514 | * @dev: DRM device | |
515 | * @crtc: which irq to enable | |
516 | * | |
517 | * Disable vblank interrupts for @crtc. If the device doesn't have | |
518 | * a hardware vblank counter, this routine should be a no-op, since | |
519 | * interrupts will have to stay on to keep the count accurate. | |
520 | */ | |
521 | void (*disable_vblank) (struct drm_device *dev, int crtc); | |
522 | ||
cda17380 DA |
523 | /** |
524 | * Called by \c drm_device_is_agp. Typically used to determine if a | |
525 | * card is really attached to AGP or not. | |
526 | * | |
527 | * \param dev DRM device handle | |
528 | * | |
529 | * \returns | |
530 | * One of three values is returned depending on whether or not the | |
531 | * card is absolutely \b not AGP (return of 0), absolutely \b is AGP | |
532 | * (return of 1), or may or may not be AGP (return of 2). | |
533 | */ | |
84b1fd10 | 534 | int (*device_is_agp) (struct drm_device *dev); |
cda17380 | 535 | |
27641c3f MK |
536 | /** |
537 | * Called by vblank timestamping code. | |
538 | * | |
8f6fce03 MK |
539 | * Return the current display scanout position from a crtc, and an |
540 | * optional accurate ktime_get timestamp of when position was measured. | |
27641c3f MK |
541 | * |
542 | * \param dev DRM device. | |
543 | * \param crtc Id of the crtc to query. | |
abca9e45 | 544 | * \param flags Flags from the caller (DRM_CALLED_FROM_VBLIRQ or 0). |
27641c3f MK |
545 | * \param *vpos Target location for current vertical scanout position. |
546 | * \param *hpos Target location for current horizontal scanout position. | |
8f6fce03 MK |
547 | * \param *stime Target location for timestamp taken immediately before |
548 | * scanout position query. Can be NULL to skip timestamp. | |
549 | * \param *etime Target location for timestamp taken immediately after | |
550 | * scanout position query. Can be NULL to skip timestamp. | |
27641c3f MK |
551 | * |
552 | * Returns vpos as a positive number while in active scanout area. | |
553 | * Returns vpos as a negative number inside vblank, counting the number | |
554 | * of scanlines to go until end of vblank, e.g., -1 means "one scanline | |
555 | * until start of active scanout / end of vblank." | |
556 | * | |
557 | * \return Flags, or'ed together as follows: | |
558 | * | |
25985edc | 559 | * DRM_SCANOUTPOS_VALID = Query successful. |
27641c3f MK |
560 | * DRM_SCANOUTPOS_INVBL = Inside vblank. |
561 | * DRM_SCANOUTPOS_ACCURATE = Returned position is accurate. A lack of | |
562 | * this flag means that returned position may be offset by a constant | |
563 | * but unknown small number of scanlines wrt. real scanout position. | |
564 | * | |
565 | */ | |
566 | int (*get_scanout_position) (struct drm_device *dev, int crtc, | |
abca9e45 | 567 | unsigned int flags, |
8f6fce03 MK |
568 | int *vpos, int *hpos, ktime_t *stime, |
569 | ktime_t *etime); | |
27641c3f MK |
570 | |
571 | /** | |
572 | * Called by \c drm_get_last_vbltimestamp. Should return a precise | |
573 | * timestamp when the most recent VBLANK interval ended or will end. | |
574 | * | |
575 | * Specifically, the timestamp in @vblank_time should correspond as | |
576 | * closely as possible to the time when the first video scanline of | |
577 | * the video frame after the end of VBLANK will start scanning out, | |
42b2aa86 | 578 | * the time immediately after end of the VBLANK interval. If the |
27641c3f MK |
579 | * @crtc is currently inside VBLANK, this will be a time in the future. |
580 | * If the @crtc is currently scanning out a frame, this will be the | |
581 | * past start time of the current scanout. This is meant to adhere | |
582 | * to the OpenML OML_sync_control extension specification. | |
583 | * | |
584 | * \param dev dev DRM device handle. | |
585 | * \param crtc crtc for which timestamp should be returned. | |
586 | * \param *max_error Maximum allowable timestamp error in nanoseconds. | |
587 | * Implementation should strive to provide timestamp | |
588 | * with an error of at most *max_error nanoseconds. | |
589 | * Returns true upper bound on error for timestamp. | |
590 | * \param *vblank_time Target location for returned vblank timestamp. | |
591 | * \param flags 0 = Defaults, no special treatment needed. | |
592 | * \param DRM_CALLED_FROM_VBLIRQ = Function is called from vblank | |
593 | * irq handler. Some drivers need to apply some workarounds | |
594 | * for gpu-specific vblank irq quirks if flag is set. | |
595 | * | |
596 | * \returns | |
597 | * Zero if timestamping isn't supported in current display mode or a | |
598 | * negative number on failure. A positive status code on success, | |
599 | * which describes how the vblank_time timestamp was computed. | |
600 | */ | |
601 | int (*get_vblank_timestamp) (struct drm_device *dev, int crtc, | |
602 | int *max_error, | |
603 | struct timeval *vblank_time, | |
604 | unsigned flags); | |
605 | ||
1da177e4 | 606 | /* these have to be filled in */ |
b5e89ed5 | 607 | |
e9f0d76f | 608 | irqreturn_t(*irq_handler) (int irq, void *arg); |
84b1fd10 | 609 | void (*irq_preinstall) (struct drm_device *dev); |
0a3e67a4 | 610 | int (*irq_postinstall) (struct drm_device *dev); |
84b1fd10 | 611 | void (*irq_uninstall) (struct drm_device *dev); |
22eae947 | 612 | |
7c1c2871 DA |
613 | /* Master routines */ |
614 | int (*master_create)(struct drm_device *dev, struct drm_master *master); | |
615 | void (*master_destroy)(struct drm_device *dev, struct drm_master *master); | |
862302ff TH |
616 | /** |
617 | * master_set is called whenever the minor master is set. | |
618 | * master_drop is called whenever the minor master is dropped. | |
619 | */ | |
620 | ||
621 | int (*master_set)(struct drm_device *dev, struct drm_file *file_priv, | |
622 | bool from_open); | |
623 | void (*master_drop)(struct drm_device *dev, struct drm_file *file_priv, | |
624 | bool from_release); | |
7c1c2871 | 625 | |
955b12de BG |
626 | int (*debugfs_init)(struct drm_minor *minor); |
627 | void (*debugfs_cleanup)(struct drm_minor *minor); | |
673a394b EA |
628 | |
629 | /** | |
630 | * Driver-specific constructor for drm_gem_objects, to set up | |
631 | * obj->driver_private. | |
632 | * | |
633 | * Returns 0 on success. | |
634 | */ | |
673a394b | 635 | void (*gem_free_object) (struct drm_gem_object *obj); |
304eda32 BS |
636 | int (*gem_open_object) (struct drm_gem_object *, struct drm_file *); |
637 | void (*gem_close_object) (struct drm_gem_object *, struct drm_file *); | |
673a394b | 638 | |
3248877e DA |
639 | /* prime: */ |
640 | /* export handle -> fd (see drm_gem_prime_handle_to_fd() helper) */ | |
641 | int (*prime_handle_to_fd)(struct drm_device *dev, struct drm_file *file_priv, | |
642 | uint32_t handle, uint32_t flags, int *prime_fd); | |
643 | /* import fd -> handle (see drm_gem_prime_fd_to_handle() helper) */ | |
644 | int (*prime_fd_to_handle)(struct drm_device *dev, struct drm_file *file_priv, | |
645 | int prime_fd, uint32_t *handle); | |
646 | /* export GEM -> dmabuf */ | |
647 | struct dma_buf * (*gem_prime_export)(struct drm_device *dev, | |
648 | struct drm_gem_object *obj, int flags); | |
649 | /* import dmabuf -> GEM */ | |
650 | struct drm_gem_object * (*gem_prime_import)(struct drm_device *dev, | |
651 | struct dma_buf *dma_buf); | |
89177644 AP |
652 | /* low-level interface used by drm_gem_prime_{import,export} */ |
653 | int (*gem_prime_pin)(struct drm_gem_object *obj); | |
102d6dba | 654 | void (*gem_prime_unpin)(struct drm_gem_object *obj); |
3aac4502 ML |
655 | struct reservation_object * (*gem_prime_res_obj)( |
656 | struct drm_gem_object *obj); | |
89177644 AP |
657 | struct sg_table *(*gem_prime_get_sg_table)(struct drm_gem_object *obj); |
658 | struct drm_gem_object *(*gem_prime_import_sg_table)( | |
659 | struct drm_device *dev, size_t size, | |
660 | struct sg_table *sgt); | |
661 | void *(*gem_prime_vmap)(struct drm_gem_object *obj); | |
662 | void (*gem_prime_vunmap)(struct drm_gem_object *obj, void *vaddr); | |
7c397cd9 JS |
663 | int (*gem_prime_mmap)(struct drm_gem_object *obj, |
664 | struct vm_area_struct *vma); | |
3248877e | 665 | |
28d52043 DA |
666 | /* vga arb irq handler */ |
667 | void (*vgaarb_irq)(struct drm_device *dev, bool state); | |
668 | ||
ff72145b DA |
669 | /* dumb alloc support */ |
670 | int (*dumb_create)(struct drm_file *file_priv, | |
671 | struct drm_device *dev, | |
672 | struct drm_mode_create_dumb *args); | |
673 | int (*dumb_map_offset)(struct drm_file *file_priv, | |
674 | struct drm_device *dev, uint32_t handle, | |
675 | uint64_t *offset); | |
676 | int (*dumb_destroy)(struct drm_file *file_priv, | |
677 | struct drm_device *dev, | |
678 | uint32_t handle); | |
679 | ||
a2c0a97b | 680 | /* Driver private ops for this object */ |
78b68556 | 681 | const struct vm_operations_struct *gem_vm_ops; |
a2c0a97b | 682 | |
22eae947 DA |
683 | int major; |
684 | int minor; | |
685 | int patchlevel; | |
686 | char *name; | |
687 | char *desc; | |
688 | char *date; | |
689 | ||
1da177e4 LT |
690 | u32 driver_features; |
691 | int dev_priv_size; | |
baa70943 | 692 | const struct drm_ioctl_desc *ioctls; |
1da177e4 | 693 | int num_ioctls; |
e08e96de | 694 | const struct file_operations *fops; |
8410ea3b | 695 | |
b3f2333d DV |
696 | /* List of devices hanging off this driver with stealth attach. */ |
697 | struct list_head legacy_dev_list; | |
1da177e4 LT |
698 | }; |
699 | ||
cb8a239b DH |
700 | enum drm_minor_type { |
701 | DRM_MINOR_LEGACY, | |
702 | DRM_MINOR_CONTROL, | |
703 | DRM_MINOR_RENDER, | |
704 | DRM_MINOR_CNT, | |
705 | }; | |
2c14f28b | 706 | |
955b12de BG |
707 | /** |
708 | * Info file list entry. This structure represents a debugfs or proc file to | |
709 | * be created by the drm core | |
710 | */ | |
711 | struct drm_info_list { | |
712 | const char *name; /** file name */ | |
713 | int (*show)(struct seq_file*, void*); /** show callback */ | |
714 | u32 driver_features; /**< Required driver features for this entry */ | |
715 | void *data; | |
716 | }; | |
717 | ||
718 | /** | |
719 | * debugfs node structure. This structure represents a debugfs file. | |
720 | */ | |
721 | struct drm_info_node { | |
722 | struct list_head list; | |
723 | struct drm_minor *minor; | |
ce089b54 | 724 | const struct drm_info_list *info_ent; |
955b12de BG |
725 | struct dentry *dent; |
726 | }; | |
727 | ||
1da177e4 | 728 | /** |
2c14f28b | 729 | * DRM minor structure. This structure represents a drm minor number. |
1da177e4 | 730 | */ |
2c14f28b DA |
731 | struct drm_minor { |
732 | int index; /**< Minor device number */ | |
733 | int type; /**< Control or render */ | |
5bdebb18 | 734 | struct device *kdev; /**< Linux device */ |
1da177e4 | 735 | struct drm_device *dev; |
955b12de | 736 | |
955b12de | 737 | struct dentry *debugfs_root; |
b3e067c0 MS |
738 | |
739 | struct list_head debugfs_list; | |
740 | struct mutex debugfs_lock; /* Protects debugfs_list. */ | |
955b12de | 741 | |
c996fd0b TH |
742 | /* currently active master for this node. Protected by master_mutex */ |
743 | struct drm_master *master; | |
f453ba04 | 744 | struct drm_mode_group mode_group; |
84b1fd10 | 745 | }; |
1da177e4 | 746 | |
1794d257 | 747 | |
c9a9c5e0 KH |
748 | struct drm_pending_vblank_event { |
749 | struct drm_pending_event base; | |
750 | int pipe; | |
751 | struct drm_event_vblank event; | |
752 | }; | |
753 | ||
5380e929 | 754 | struct drm_vblank_crtc { |
e69595c2 | 755 | struct drm_device *dev; /* pointer to the drm_device */ |
5380e929 VS |
756 | wait_queue_head_t queue; /**< VBLANK wait queue */ |
757 | struct timeval time[DRM_VBLANKTIME_RBSIZE]; /**< timestamp of current count */ | |
e69595c2 | 758 | struct timer_list disable_timer; /* delayed disable timer */ |
5380e929 VS |
759 | atomic_t count; /**< number of VBLANK interrupts */ |
760 | atomic_t refcount; /* number of users of vblank interruptsper crtc */ | |
761 | u32 last; /* protected by dev->vbl_lock, used */ | |
762 | /* for wraparound handling */ | |
763 | u32 last_wait; /* Last vblank seqno waited per CRTC */ | |
764 | unsigned int inmodeset; /* Display driver is setting mode */ | |
e69595c2 | 765 | int crtc; /* crtc index */ |
5380e929 VS |
766 | bool enabled; /* so we don't call enable more than |
767 | once per disable */ | |
768 | }; | |
769 | ||
1da177e4 LT |
770 | /** |
771 | * DRM device structure. This structure represent a complete card that | |
772 | * may contain multiple heads. | |
773 | */ | |
84b1fd10 | 774 | struct drm_device { |
b3f2333d | 775 | struct list_head legacy_dev_list;/**< list of devices per driver for stealth attach cleanup */ |
b5e89ed5 | 776 | int if_version; /**< Highest interface version set */ |
1da177e4 | 777 | |
45e212d2 DH |
778 | /** \name Lifetime Management */ |
779 | /*@{ */ | |
099d1c29 | 780 | struct kref ref; /**< Object ref-count */ |
45e212d2 DH |
781 | struct device *dev; /**< Device structure of bus-device */ |
782 | struct drm_driver *driver; /**< DRM driver managing the device */ | |
783 | void *dev_private; /**< DRM driver private data */ | |
45e212d2 DH |
784 | struct drm_minor *control; /**< Control node */ |
785 | struct drm_minor *primary; /**< Primary node */ | |
786 | struct drm_minor *render; /**< Render node */ | |
787 | atomic_t unplugged; /**< Flag whether dev is dead */ | |
07b48c3a | 788 | struct inode *anon_inode; /**< inode for private address-space */ |
ca8e2ad7 | 789 | char *unique; /**< unique name of the device */ |
45e212d2 DH |
790 | /*@} */ |
791 | ||
1da177e4 | 792 | /** \name Locks */ |
b5e89ed5 | 793 | /*@{ */ |
30e2fb18 | 794 | struct mutex struct_mutex; /**< For others */ |
c996fd0b | 795 | struct mutex master_mutex; /**< For drm_minor::master and drm_file::is_master */ |
b5e89ed5 | 796 | /*@} */ |
1da177e4 LT |
797 | |
798 | /** \name Usage Counters */ | |
b5e89ed5 | 799 | /*@{ */ |
fc8fd40e | 800 | int open_count; /**< Outstanding files open, protected by drm_global_mutex. */ |
2177a218 | 801 | spinlock_t buf_lock; /**< For drm_device::buf_use and a few other things. */ |
b5e89ed5 DA |
802 | int buf_use; /**< Buffers in use -- cannot alloc */ |
803 | atomic_t buf_alloc; /**< Buffer allocation in progress */ | |
804 | /*@} */ | |
1da177e4 | 805 | |
bd1b331f | 806 | struct list_head filelist; |
1da177e4 LT |
807 | |
808 | /** \name Memory management */ | |
b5e89ed5 | 809 | /*@{ */ |
bd1b331f | 810 | struct list_head maplist; /**< Linked list of regions */ |
e0be428e | 811 | struct drm_open_hash map_hash; /**< User token hash table for maps */ |
1da177e4 LT |
812 | |
813 | /** \name Context handle management */ | |
b5e89ed5 | 814 | /*@{ */ |
bd1b331f | 815 | struct list_head ctxlist; /**< Linked list of context handles */ |
30e2fb18 | 816 | struct mutex ctxlist_mutex; /**< For ctxlist */ |
1da177e4 | 817 | |
62968144 | 818 | struct idr ctx_idr; |
1da177e4 | 819 | |
bd1b331f | 820 | struct list_head vmalist; /**< List of vmas (for debugging) */ |
f453ba04 | 821 | |
b5e89ed5 | 822 | /*@} */ |
1da177e4 | 823 | |
a344a7e7 | 824 | /** \name DMA support */ |
b5e89ed5 | 825 | /*@{ */ |
cdd55a29 | 826 | struct drm_device_dma *dma; /**< Optional pointer for DMA support */ |
b5e89ed5 | 827 | /*@} */ |
1da177e4 LT |
828 | |
829 | /** \name Context support */ | |
b5e89ed5 | 830 | /*@{ */ |
4423843c | 831 | bool irq_enabled; /**< True if irq handler is enabled */ |
7c1a38e3 DV |
832 | int irq; |
833 | ||
1da177e4 | 834 | __volatile__ long context_flag; /**< Context swapping flag */ |
b5e89ed5 | 835 | int last_context; /**< Last current context */ |
b5e89ed5 DA |
836 | /*@} */ |
837 | ||
1da177e4 | 838 | /** \name VBLANK IRQ support */ |
b5e89ed5 DA |
839 | /*@{ */ |
840 | ||
0a3e67a4 JB |
841 | /* |
842 | * At load time, disabling the vblank interrupt won't be allowed since | |
843 | * old clients may not call the modeset ioctl and therefore misbehave. | |
844 | * Once the modeset ioctl *has* been called though, we can safely | |
845 | * disable them when unused. | |
846 | */ | |
ba0bf120 | 847 | bool vblank_disable_allowed; |
0a3e67a4 | 848 | |
00185e66 VS |
849 | /* |
850 | * If true, vblank interrupt will be disabled immediately when the | |
851 | * refcount drops to zero, as opposed to via the vblank disable | |
852 | * timer. | |
853 | * This can be set to true it the hardware has a working vblank | |
854 | * counter and the driver uses drm_vblank_on() and drm_vblank_off() | |
855 | * appropriately. | |
856 | */ | |
857 | bool vblank_disable_immediate; | |
858 | ||
5380e929 VS |
859 | /* array of size num_crtcs */ |
860 | struct drm_vblank_crtc *vblank; | |
0a3e67a4 | 861 | |
27641c3f | 862 | spinlock_t vblank_time_lock; /**< Protects vblank count and time updates during vblank enable/disable */ |
b5e89ed5 | 863 | spinlock_t vbl_lock; |
0a3e67a4 JB |
864 | |
865 | u32 max_vblank_count; /**< size of vblank counter register */ | |
b5e89ed5 | 866 | |
c9a9c5e0 KH |
867 | /** |
868 | * List of events | |
869 | */ | |
870 | struct list_head vblank_event_list; | |
871 | spinlock_t event_lock; | |
872 | ||
b5e89ed5 | 873 | /*@} */ |
b5e89ed5 | 874 | |
55910517 | 875 | struct drm_agp_head *agp; /**< AGP data */ |
1da177e4 | 876 | |
b5e89ed5 | 877 | struct pci_dev *pdev; /**< PCI device structure */ |
1da177e4 | 878 | #ifdef __alpha__ |
1da177e4 | 879 | struct pci_controller *hose; |
1da177e4 | 880 | #endif |
dcdb1674 JC |
881 | |
882 | struct platform_device *platformdev; /**< Platform device struture */ | |
883 | ||
55910517 | 884 | struct drm_sg_mem *sg; /**< Scatter gather memory */ |
19227561 | 885 | unsigned int num_crtcs; /**< Number of CRTCs on this device */ |
b5e89ed5 DA |
886 | sigset_t sigmask; |
887 | ||
69d516c0 DH |
888 | struct { |
889 | int context; | |
890 | struct drm_hw_lock *lock; | |
891 | } sigdata; | |
892 | ||
f77d390c | 893 | struct drm_local_map *agp_buffer_map; |
d1f2b55a | 894 | unsigned int agp_buffer_token; |
bea5679f | 895 | |
f453ba04 DA |
896 | struct drm_mode_config mode_config; /**< Current mode config */ |
897 | ||
673a394b EA |
898 | /** \name GEM information */ |
899 | /*@{ */ | |
cd4f013f | 900 | struct mutex object_name_lock; |
673a394b | 901 | struct idr object_name_idr; |
b04a5906 | 902 | struct drm_vma_offset_manager *vma_offset_manager; |
673a394b | 903 | /*@} */ |
5bcf719b | 904 | int switch_power_state; |
84b1fd10 | 905 | }; |
1da177e4 | 906 | |
5bcf719b DA |
907 | #define DRM_SWITCH_POWER_ON 0 |
908 | #define DRM_SWITCH_POWER_OFF 1 | |
909 | #define DRM_SWITCH_POWER_CHANGING 2 | |
13bb9cc8 | 910 | #define DRM_SWITCH_POWER_DYNAMIC_OFF 3 |
5bcf719b | 911 | |
b5e89ed5 DA |
912 | static __inline__ int drm_core_check_feature(struct drm_device *dev, |
913 | int feature) | |
1da177e4 LT |
914 | { |
915 | return ((dev->driver->driver_features & feature) ? 1 : 0); | |
916 | } | |
917 | ||
2c07a21d DA |
918 | static inline void drm_device_set_unplugged(struct drm_device *dev) |
919 | { | |
920 | smp_wmb(); | |
921 | atomic_set(&dev->unplugged, 1); | |
922 | } | |
923 | ||
924 | static inline int drm_device_is_unplugged(struct drm_device *dev) | |
925 | { | |
926 | int ret = atomic_read(&dev->unplugged); | |
927 | smp_rmb(); | |
928 | return ret; | |
929 | } | |
930 | ||
43683057 | 931 | static inline bool drm_is_render_client(const struct drm_file *file_priv) |
1793126f DH |
932 | { |
933 | return file_priv->minor->type == DRM_MINOR_RENDER; | |
934 | } | |
935 | ||
ac05dbc5 TH |
936 | static inline bool drm_is_control_client(const struct drm_file *file_priv) |
937 | { | |
938 | return file_priv->minor->type == DRM_MINOR_CONTROL; | |
939 | } | |
940 | ||
43683057 TH |
941 | static inline bool drm_is_primary_client(const struct drm_file *file_priv) |
942 | { | |
943 | return file_priv->minor->type == DRM_MINOR_LEGACY; | |
944 | } | |
945 | ||
1da177e4 LT |
946 | /******************************************************************/ |
947 | /** \name Internal function definitions */ | |
948 | /*@{*/ | |
949 | ||
1da177e4 | 950 | /* Driver support (drm_drv.h) */ |
ed8b6704 AB |
951 | extern long drm_ioctl(struct file *filp, |
952 | unsigned int cmd, unsigned long arg); | |
b5e89ed5 DA |
953 | extern long drm_compat_ioctl(struct file *filp, |
954 | unsigned int cmd, unsigned long arg); | |
4beb6d9f | 955 | extern bool drm_ioctl_flags(unsigned int nr, unsigned int *flags); |
1da177e4 LT |
956 | |
957 | /* Device support (drm_fops.h) */ | |
b5e89ed5 | 958 | extern int drm_open(struct inode *inode, struct file *filp); |
c9a9c5e0 KH |
959 | extern ssize_t drm_read(struct file *filp, char __user *buffer, |
960 | size_t count, loff_t *offset); | |
b5e89ed5 | 961 | extern int drm_release(struct inode *inode, struct file *filp); |
1da177e4 LT |
962 | |
963 | /* Mapping support (drm_vm.h) */ | |
b5e89ed5 | 964 | extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait); |
1da177e4 | 965 | |
78238757 DV |
966 | /* Misc. IOCTL support (drm_ioctl.c) */ |
967 | int drm_noop(struct drm_device *dev, void *data, | |
968 | struct drm_file *file_priv); | |
1da177e4 | 969 | |
673a394b EA |
970 | /* Cache management (drm_cache.c) */ |
971 | void drm_clflush_pages(struct page *pages[], unsigned long num_pages); | |
9da3da66 | 972 | void drm_clflush_sg(struct sg_table *st); |
c2d15359 | 973 | void drm_clflush_virt_range(void *addr, unsigned long length); |
673a394b | 974 | |
040ac320 TH |
975 | /* |
976 | * These are exported to drivers so that they can implement fencing using | |
977 | * DMA quiscent + idle. DMA quiescent usually requires the hardware lock. | |
978 | */ | |
979 | ||
1da177e4 | 980 | /* IRQ support (drm_irq.h) */ |
bb0f1b5c | 981 | extern int drm_irq_install(struct drm_device *dev, int irq); |
84b1fd10 | 982 | extern int drm_irq_uninstall(struct drm_device *dev); |
b5e89ed5 | 983 | |
0a3e67a4 | 984 | extern int drm_vblank_init(struct drm_device *dev, int num_crtcs); |
af6061af | 985 | extern int drm_wait_vblank(struct drm_device *dev, void *data, |
0a3e67a4 | 986 | struct drm_file *filp); |
0a3e67a4 | 987 | extern u32 drm_vblank_count(struct drm_device *dev, int crtc); |
27641c3f MK |
988 | extern u32 drm_vblank_count_and_time(struct drm_device *dev, int crtc, |
989 | struct timeval *vblanktime); | |
c6eefa17 RC |
990 | extern void drm_send_vblank_event(struct drm_device *dev, int crtc, |
991 | struct drm_pending_vblank_event *e); | |
78c6e170 | 992 | extern bool drm_handle_vblank(struct drm_device *dev, int crtc); |
0a3e67a4 JB |
993 | extern int drm_vblank_get(struct drm_device *dev, int crtc); |
994 | extern void drm_vblank_put(struct drm_device *dev, int crtc); | |
89dd6a4b DV |
995 | extern int drm_crtc_vblank_get(struct drm_crtc *crtc); |
996 | extern void drm_crtc_vblank_put(struct drm_crtc *crtc); | |
e8450f51 DV |
997 | extern void drm_wait_one_vblank(struct drm_device *dev, int crtc); |
998 | extern void drm_crtc_wait_one_vblank(struct drm_crtc *crtc); | |
778c9026 | 999 | extern void drm_vblank_off(struct drm_device *dev, int crtc); |
f2752282 | 1000 | extern void drm_vblank_on(struct drm_device *dev, int crtc); |
89dd6a4b DV |
1001 | extern void drm_crtc_vblank_off(struct drm_crtc *crtc); |
1002 | extern void drm_crtc_vblank_on(struct drm_crtc *crtc); | |
52440211 | 1003 | extern void drm_vblank_cleanup(struct drm_device *dev); |
89dd6a4b | 1004 | |
27641c3f MK |
1005 | extern int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev, |
1006 | int crtc, int *max_error, | |
1007 | struct timeval *vblank_time, | |
1008 | unsigned flags, | |
7da903ef VS |
1009 | const struct drm_crtc *refcrtc, |
1010 | const struct drm_display_mode *mode); | |
545cdd55 VS |
1011 | extern void drm_calc_timestamping_constants(struct drm_crtc *crtc, |
1012 | const struct drm_display_mode *mode); | |
27641c3f | 1013 | |
020178a1 VS |
1014 | /** |
1015 | * drm_crtc_vblank_waitqueue - get vblank waitqueue for the CRTC | |
1016 | * @crtc: which CRTC's vblank waitqueue to retrieve | |
1017 | * | |
1018 | * This function returns a pointer to the vblank waitqueue for the CRTC. | |
1019 | * Drivers can use this to implement vblank waits using wait_event() & co. | |
1020 | */ | |
1021 | static inline wait_queue_head_t *drm_crtc_vblank_waitqueue(struct drm_crtc *crtc) | |
1022 | { | |
1023 | return &crtc->dev->vblank[drm_crtc_index(crtc)].queue; | |
1024 | } | |
ebc64e45 | 1025 | |
0a3e67a4 | 1026 | /* Modesetting support */ |
f453ba04 DA |
1027 | extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc); |
1028 | extern void drm_vblank_post_modeset(struct drm_device *dev, int crtc); | |
1da177e4 | 1029 | |
1da177e4 | 1030 | /* Stub support (drm_stub.h) */ |
7c1c2871 DA |
1031 | extern struct drm_master *drm_master_get(struct drm_master *master); |
1032 | extern void drm_master_put(struct drm_master **master); | |
8410ea3b | 1033 | |
112b715e | 1034 | extern void drm_put_dev(struct drm_device *dev); |
2c07a21d | 1035 | extern void drm_unplug_dev(struct drm_device *dev); |
b5e89ed5 | 1036 | extern unsigned int drm_debug; |
2c14f28b | 1037 | |
955b12de BG |
1038 | /* Debugfs support */ |
1039 | #if defined(CONFIG_DEBUG_FS) | |
7d74795b LD |
1040 | extern int drm_debugfs_create_files(const struct drm_info_list *files, |
1041 | int count, struct dentry *root, | |
1042 | struct drm_minor *minor); | |
1043 | extern int drm_debugfs_remove_files(const struct drm_info_list *files, | |
1044 | int count, struct drm_minor *minor); | |
66ee52e2 | 1045 | #else |
66ee52e2 TR |
1046 | static inline int drm_debugfs_create_files(const struct drm_info_list *files, |
1047 | int count, struct dentry *root, | |
1048 | struct drm_minor *minor) | |
1049 | { | |
1050 | return 0; | |
1051 | } | |
1052 | ||
1053 | static inline int drm_debugfs_remove_files(const struct drm_info_list *files, | |
1054 | int count, struct drm_minor *minor) | |
1055 | { | |
1056 | return 0; | |
1057 | } | |
955b12de BG |
1058 | #endif |
1059 | ||
89177644 AP |
1060 | extern struct dma_buf *drm_gem_prime_export(struct drm_device *dev, |
1061 | struct drm_gem_object *obj, int flags); | |
3248877e DA |
1062 | extern int drm_gem_prime_handle_to_fd(struct drm_device *dev, |
1063 | struct drm_file *file_priv, uint32_t handle, uint32_t flags, | |
1064 | int *prime_fd); | |
89177644 AP |
1065 | extern struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev, |
1066 | struct dma_buf *dma_buf); | |
3248877e DA |
1067 | extern int drm_gem_prime_fd_to_handle(struct drm_device *dev, |
1068 | struct drm_file *file_priv, int prime_fd, uint32_t *handle); | |
c1d6798d | 1069 | extern void drm_gem_dmabuf_release(struct dma_buf *dma_buf); |
3248877e | 1070 | |
51ab7ba2 DA |
1071 | extern int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages, |
1072 | dma_addr_t *addrs, int max_pages); | |
3248877e DA |
1073 | extern struct sg_table *drm_prime_pages_to_sg(struct page **pages, int nr_pages); |
1074 | extern void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg); | |
1075 | ||
43387b37 DV |
1076 | int drm_gem_dumb_destroy(struct drm_file *file, |
1077 | struct drm_device *dev, | |
1078 | uint32_t handle); | |
3248877e | 1079 | |
1da177e4 | 1080 | |
ba8286fa DV |
1081 | extern struct drm_dma_handle *drm_pci_alloc(struct drm_device *dev, size_t size, |
1082 | size_t align); | |
1083 | extern void drm_pci_free(struct drm_device *dev, struct drm_dma_handle * dmah); | |
1da177e4 LT |
1084 | |
1085 | /* sysfs support (drm_sysfs.c) */ | |
f453ba04 | 1086 | extern void drm_sysfs_hotplug_event(struct drm_device *dev); |
1da177e4 | 1087 | |
673a394b | 1088 | /* Graphics Execution Manager library functions (drm_gem.c) */ |
fd632aa3 | 1089 | void drm_gem_object_release(struct drm_gem_object *obj); |
673a394b | 1090 | void drm_gem_object_free(struct kref *kref); |
1d397043 DV |
1091 | int drm_gem_object_init(struct drm_device *dev, |
1092 | struct drm_gem_object *obj, size_t size); | |
89c8233f DH |
1093 | void drm_gem_private_object_init(struct drm_device *dev, |
1094 | struct drm_gem_object *obj, size_t size); | |
ab00b3e5 JB |
1095 | void drm_gem_vm_open(struct vm_area_struct *vma); |
1096 | void drm_gem_vm_close(struct vm_area_struct *vma); | |
1c5aafa6 LP |
1097 | int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size, |
1098 | struct vm_area_struct *vma); | |
a2c0a97b | 1099 | int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma); |
673a394b EA |
1100 | |
1101 | static inline void | |
1102 | drm_gem_object_reference(struct drm_gem_object *obj) | |
1103 | { | |
1104 | kref_get(&obj->refcount); | |
1105 | } | |
1106 | ||
1107 | static inline void | |
1108 | drm_gem_object_unreference(struct drm_gem_object *obj) | |
1109 | { | |
c3ae90c0 LB |
1110 | if (obj != NULL) |
1111 | kref_put(&obj->refcount, drm_gem_object_free); | |
1112 | } | |
673a394b | 1113 | |
c3ae90c0 LB |
1114 | static inline void |
1115 | drm_gem_object_unreference_unlocked(struct drm_gem_object *obj) | |
1116 | { | |
7fc65eb7 | 1117 | if (obj && !atomic_add_unless(&obj->refcount.refcount, -1, 1)) { |
39b4d07a | 1118 | struct drm_device *dev = obj->dev; |
7fc65eb7 | 1119 | |
39b4d07a | 1120 | mutex_lock(&dev->struct_mutex); |
7fc65eb7 CW |
1121 | if (likely(atomic_dec_and_test(&obj->refcount.refcount))) |
1122 | drm_gem_object_free(&obj->refcount); | |
39b4d07a CW |
1123 | mutex_unlock(&dev->struct_mutex); |
1124 | } | |
673a394b EA |
1125 | } |
1126 | ||
1127 | int drm_gem_handle_create(struct drm_file *file_priv, | |
1128 | struct drm_gem_object *obj, | |
a1a2d1d3 | 1129 | u32 *handlep); |
ff72145b | 1130 | int drm_gem_handle_delete(struct drm_file *filp, u32 handle); |
673a394b | 1131 | |
c3ae90c0 | 1132 | |
75ef8b3b RC |
1133 | void drm_gem_free_mmap_offset(struct drm_gem_object *obj); |
1134 | int drm_gem_create_mmap_offset(struct drm_gem_object *obj); | |
367bbd49 | 1135 | int drm_gem_create_mmap_offset_size(struct drm_gem_object *obj, size_t size); |
75ef8b3b | 1136 | |
0cdbe8ac | 1137 | struct page **drm_gem_get_pages(struct drm_gem_object *obj); |
bcc5c9d5 RC |
1138 | void drm_gem_put_pages(struct drm_gem_object *obj, struct page **pages, |
1139 | bool dirty, bool accessed); | |
1140 | ||
673a394b EA |
1141 | struct drm_gem_object *drm_gem_object_lookup(struct drm_device *dev, |
1142 | struct drm_file *filp, | |
a1a2d1d3 | 1143 | u32 handle); |
673a394b | 1144 | |
1bb72532 DH |
1145 | struct drm_device *drm_dev_alloc(struct drm_driver *driver, |
1146 | struct device *parent); | |
099d1c29 DH |
1147 | void drm_dev_ref(struct drm_device *dev); |
1148 | void drm_dev_unref(struct drm_device *dev); | |
c22f0ace | 1149 | int drm_dev_register(struct drm_device *dev, unsigned long flags); |
c3a49737 | 1150 | void drm_dev_unregister(struct drm_device *dev); |
ca8e2ad7 | 1151 | int drm_dev_set_unique(struct drm_device *dev, const char *fmt, ...); |
1616c525 DH |
1152 | |
1153 | struct drm_minor *drm_minor_acquire(unsigned int minor_id); | |
1154 | void drm_minor_release(struct drm_minor *minor); | |
1155 | ||
8410ea3b DA |
1156 | /*@}*/ |
1157 | ||
1158 | /* PCI section */ | |
1159 | static __inline__ int drm_pci_device_is_agp(struct drm_device *dev) | |
1160 | { | |
b5e89ed5 DA |
1161 | if (dev->driver->device_is_agp != NULL) { |
1162 | int err = (*dev->driver->device_is_agp) (dev); | |
1163 | ||
cda17380 DA |
1164 | if (err != 2) { |
1165 | return err; | |
1166 | } | |
1167 | } | |
1168 | ||
1169 | return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP); | |
1170 | } | |
4efafebe | 1171 | void drm_pci_agp_destroy(struct drm_device *dev); |
cda17380 | 1172 | |
8410ea3b DA |
1173 | extern int drm_pci_init(struct drm_driver *driver, struct pci_driver *pdriver); |
1174 | extern void drm_pci_exit(struct drm_driver *driver, struct pci_driver *pdriver); | |
1175 | extern int drm_get_pci_dev(struct pci_dev *pdev, | |
dcdb1674 JC |
1176 | const struct pci_device_id *ent, |
1177 | struct drm_driver *driver); | |
915b4d11 | 1178 | extern int drm_pci_set_busid(struct drm_device *dev, struct drm_master *master); |
8410ea3b | 1179 | |
f4297784 DA |
1180 | #define DRM_PCIE_SPEED_25 1 |
1181 | #define DRM_PCIE_SPEED_50 2 | |
1182 | #define DRM_PCIE_SPEED_80 4 | |
1183 | ||
1184 | extern int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *speed_mask); | |
8410ea3b DA |
1185 | |
1186 | /* platform section */ | |
1187 | extern int drm_platform_init(struct drm_driver *driver, struct platform_device *platform_device); | |
915b4d11 | 1188 | extern int drm_platform_set_busid(struct drm_device *d, struct drm_master *m); |
8410ea3b | 1189 | |
cc1f7194 DA |
1190 | /* returns true if currently okay to sleep */ |
1191 | static __inline__ bool drm_can_sleep(void) | |
1192 | { | |
1193 | if (in_atomic() || in_dbg_master() || irqs_disabled()) | |
1194 | return false; | |
1195 | return true; | |
1196 | } | |
1197 | ||
1da177e4 | 1198 | #endif |