Rev 5178 | Rev 6082 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5270 | serge | 1 | /* |
2 | * Internal Header for the Direct Rendering Manager |
||
1408 | serge | 3 | * |
4 | * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. |
||
5 | * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. |
||
1964 | serge | 6 | * Copyright (c) 2009-2010, Code Aurora Forum. |
1408 | serge | 7 | * All rights reserved. |
8 | * |
||
5270 | serge | 9 | * Author: Rickard E. (Rik) Faith |
10 | * Author: Gareth Hughes |
||
11 | * |
||
1408 | serge | 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 | |||
2967 | Serge | 35 | #include |
5270 | serge | 36 | #include |
2967 | Serge | 37 | |
5270 | serge | 38 | #include |
39 | #include |
||
40 | #include |
||
41 | #include |
||
42 | #include |
||
1408 | serge | 43 | #include |
44 | #include |
||
5270 | serge | 45 | #include |
46 | |||
1408 | serge | 47 | #include |
2967 | Serge | 48 | #include |
3031 | serge | 49 | #include |
5270 | serge | 50 | #include |
51 | #include |
||
3391 | Serge | 52 | #include |
1408 | serge | 53 | |
3763 | Serge | 54 | #include |
55 | #include |
||
56 | |||
5056 | serge | 57 | |
3747 | Serge | 58 | #include |
5056 | serge | 59 | #include |
60 | #include |
||
5270 | serge | 61 | #include |
3482 | Serge | 62 | #include |
63 | |||
5270 | serge | 64 | #include |
65 | #include |
||
3482 | Serge | 66 | |
5270 | serge | 67 | #include |
68 | #include |
||
69 | #include |
||
70 | #include |
||
71 | #include |
||
72 | #include |
||
73 | #include |
||
74 | #include |
||
4103 | Serge | 75 | #include |
1408 | serge | 76 | |
3031 | serge | 77 | struct module; |
1408 | serge | 78 | |
79 | struct drm_file; |
||
80 | struct drm_device; |
||
5270 | serge | 81 | struct drm_agp_head; |
82 | struct drm_local_map; |
||
83 | struct drm_device_dma; |
||
84 | struct drm_dma_handle; |
||
85 | struct drm_gem_object; |
||
1408 | serge | 86 | |
3391 | Serge | 87 | struct device_node; |
88 | struct videomode; |
||
5056 | serge | 89 | struct reservation_object; |
5270 | serge | 90 | struct dma_buf_attachment; |
4103 | Serge | 91 | |
92 | struct inode; |
||
93 | struct poll_table_struct; |
||
94 | struct sg_table; |
||
95 | |||
1408 | serge | 96 | #define KHZ2PICOS(a) (1000000000UL/(a)) |
97 | |||
3031 | serge | 98 | /* |
5056 | serge | 99 | * 4 debug categories are defined: |
3031 | serge | 100 | * |
5056 | serge | 101 | * CORE: Used in the generic drm code: drm_ioctl.c, drm_mm.c, drm_memory.c, ... |
102 | * This is the category used by the DRM_DEBUG() macro. |
||
3031 | serge | 103 | * |
5056 | serge | 104 | * DRIVER: Used in the vendor specific part of the driver: i915, radeon, ... |
105 | * This is the category used by the DRM_DEBUG_DRIVER() macro. |
||
3031 | serge | 106 | * |
5056 | serge | 107 | * KMS: used in the modesetting code. |
108 | * This is the category used by the DRM_DEBUG_KMS() macro. |
||
109 | * |
||
110 | * PRIME: used in the prime code. |
||
111 | * This is the category used by the DRM_DEBUG_PRIME() macro. |
||
112 | * |
||
113 | * Enabling verbose debug messages is done through the drm.debug parameter, |
||
114 | * each category being enabled by a bit. |
||
115 | * |
||
116 | * drm.debug=0x1 will enable CORE messages |
||
117 | * drm.debug=0x2 will enable DRIVER messages |
||
118 | * drm.debug=0x3 will enable CORE and DRIVER messages |
||
119 | * ... |
||
120 | * drm.debug=0xf will enable all messages |
||
121 | * |
||
122 | * An interesting feature is that it's possible to enable verbose logging at |
||
123 | * run-time by echoing the debug value in its sysfs node: |
||
124 | * # echo 0xf > /sys/module/drm/parameters/debug |
||
3031 | serge | 125 | */ |
5056 | serge | 126 | #define DRM_UT_CORE 0x01 |
127 | #define DRM_UT_DRIVER 0x02 |
||
128 | #define DRM_UT_KMS 0x04 |
||
129 | #define DRM_UT_PRIME 0x08 |
||
3031 | serge | 130 | |
5056 | serge | 131 | extern __printf(2, 3) |
132 | void drm_ut_debug_printk(const char *function_name, |
||
1408 | serge | 133 | const char *format, ...); |
5270 | serge | 134 | extern __printf(1, 2) |
135 | void drm_err(const char *format, ...); |
||
1408 | serge | 136 | |
137 | /***********************************************************************/ |
||
138 | /** \name DRM template customization defaults */ |
||
139 | /*@{*/ |
||
140 | |||
141 | /* driver capabilities and requirements mask */ |
||
142 | #define DRIVER_USE_AGP 0x1 |
||
143 | #define DRIVER_PCI_DMA 0x8 |
||
144 | #define DRIVER_SG 0x10 |
||
145 | #define DRIVER_HAVE_DMA 0x20 |
||
146 | #define DRIVER_HAVE_IRQ 0x40 |
||
147 | #define DRIVER_IRQ_SHARED 0x80 |
||
148 | #define DRIVER_GEM 0x1000 |
||
149 | #define DRIVER_MODESET 0x2000 |
||
3031 | serge | 150 | #define DRIVER_PRIME 0x4000 |
4103 | Serge | 151 | #define DRIVER_RENDER 0x8000 |
1408 | serge | 152 | |
153 | /***********************************************************************/ |
||
154 | /** \name Macros to make printk easier */ |
||
155 | /*@{*/ |
||
156 | |||
157 | /** |
||
158 | * Error output. |
||
159 | * |
||
160 | * \param fmt printf() like format string. |
||
161 | * \param arg arguments |
||
162 | */ |
||
3031 | serge | 163 | #define DRM_ERROR(fmt, ...) \ |
5270 | serge | 164 | drm_err(fmt, ##__VA_ARGS__) |
1408 | serge | 165 | |
4559 | Serge | 166 | /** |
167 | * Rate limited error output. Like DRM_ERROR() but won't flood the log. |
||
168 | * |
||
169 | * \param fmt printf() like format string. |
||
170 | * \param arg arguments |
||
171 | */ |
||
172 | #define DRM_ERROR_RATELIMITED(fmt, ...) \ |
||
173 | ({ \ |
||
174 | static DEFINE_RATELIMIT_STATE(_rs, \ |
||
175 | DEFAULT_RATELIMIT_INTERVAL, \ |
||
176 | DEFAULT_RATELIMIT_BURST); \ |
||
177 | \ |
||
178 | if (__ratelimit(&_rs)) \ |
||
5270 | serge | 179 | drm_err(fmt, ##__VA_ARGS__); \ |
4559 | Serge | 180 | }) |
181 | |||
3031 | serge | 182 | #define DRM_INFO(fmt, ...) \ |
183 | printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__) |
||
1408 | serge | 184 | |
5056 | serge | 185 | #define DRM_INFO_ONCE(fmt, ...) \ |
186 | printk_once(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__) |
||
187 | |||
1408 | serge | 188 | /** |
189 | * Debug output. |
||
190 | * |
||
191 | * \param fmt printf() like format string. |
||
192 | * \param arg arguments |
||
193 | */ |
||
194 | #if DRM_DEBUG_CODE |
||
5056 | serge | 195 | #define DRM_DEBUG(fmt, args...) \ |
3031 | serge | 196 | do { \ |
5056 | serge | 197 | printk(KERN_INFO "[" DRM_NAME "] " fmt, ##args); \ |
1408 | serge | 198 | } while (0) |
199 | |||
5056 | serge | 200 | #define DRM_DEBUG_DRIVER(fmt, args...) \ |
3031 | serge | 201 | do { \ |
5056 | serge | 202 | printk(KERN_INFO "[" DRM_NAME "] " fmt, ##args); \ |
3031 | serge | 203 | } while (0) |
5056 | serge | 204 | #define DRM_DEBUG_KMS(fmt, args...) \ |
1408 | serge | 205 | do { \ |
5056 | serge | 206 | printk(KERN_INFO "[" DRM_NAME "] " fmt, ##args); \ |
1408 | serge | 207 | } while (0) |
5056 | serge | 208 | #define DRM_DEBUG_PRIME(fmt, args...) \ |
1408 | serge | 209 | do { \ |
5056 | serge | 210 | printk(KERN_INFO "[" DRM_NAME "] " fmt, ##args); \ |
1408 | serge | 211 | } while (0) |
212 | #else |
||
213 | #define DRM_DEBUG_DRIVER(fmt, args...) do { } while (0) |
||
214 | #define DRM_DEBUG_KMS(fmt, args...) do { } while (0) |
||
3031 | serge | 215 | #define DRM_DEBUG_PRIME(fmt, args...) do { } while (0) |
1408 | serge | 216 | #define DRM_DEBUG(fmt, arg...) do { } while (0) |
217 | #endif |
||
218 | |||
219 | /*@}*/ |
||
220 | |||
221 | /***********************************************************************/ |
||
222 | /** \name Internal types and structures */ |
||
223 | /*@{*/ |
||
224 | |||
225 | #define DRM_IF_VERSION(maj, min) (maj << 16 | min) |
||
226 | |||
227 | /** |
||
228 | * Ioctl function type. |
||
229 | * |
||
230 | * \param inode device inode. |
||
231 | * \param file_priv DRM file private pointer. |
||
232 | * \param cmd command. |
||
233 | * \param arg argument. |
||
234 | */ |
||
235 | typedef int drm_ioctl_t(struct drm_device *dev, void *data, |
||
236 | struct drm_file *file_priv); |
||
237 | |||
238 | typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd, |
||
239 | unsigned long arg); |
||
240 | |||
241 | #define DRM_IOCTL_NR(n) _IOC_NR(n) |
||
242 | #define DRM_MAJOR 226 |
||
243 | |||
244 | #define DRM_AUTH 0x1 |
||
245 | #define DRM_MASTER 0x2 |
||
246 | #define DRM_ROOT_ONLY 0x4 |
||
247 | #define DRM_CONTROL_ALLOW 0x8 |
||
248 | #define DRM_UNLOCKED 0x10 |
||
4103 | Serge | 249 | #define DRM_RENDER_ALLOW 0x20 |
1408 | serge | 250 | |
251 | struct drm_ioctl_desc { |
||
252 | unsigned int cmd; |
||
253 | int flags; |
||
254 | drm_ioctl_t *func; |
||
1964 | serge | 255 | unsigned int cmd_drv; |
3747 | Serge | 256 | const char *name; |
1408 | serge | 257 | }; |
258 | |||
259 | /** |
||
260 | * Creates a driver or general drm_ioctl_desc array entry for the given |
||
261 | * ioctl, for use by drm_ioctl(). |
||
262 | */ |
||
263 | |||
1964 | serge | 264 | #define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags) \ |
3747 | Serge | 265 | [DRM_IOCTL_NR(DRM_##ioctl)] = {.cmd = DRM_##ioctl, .func = _func, .flags = _flags, .cmd_drv = DRM_IOCTL_##ioctl, .name = #ioctl} |
1964 | serge | 266 | |
1408 | serge | 267 | /* Event queued up for userspace to read */ |
268 | struct drm_pending_event { |
||
269 | struct drm_event *event; |
||
270 | struct list_head link; |
||
271 | struct drm_file *file_priv; |
||
1964 | serge | 272 | pid_t pid; /* pid of requester, no guarantee it's valid by the time |
273 | we deliver the event, for tracing only */ |
||
1408 | serge | 274 | void (*destroy)(struct drm_pending_event *event); |
275 | }; |
||
276 | |||
3031 | serge | 277 | /* initial implementaton using a linked list - todo hashtab */ |
278 | struct drm_prime_file_private { |
||
279 | struct list_head head; |
||
280 | struct mutex lock; |
||
281 | }; |
||
282 | |||
1408 | serge | 283 | /** File private data */ |
284 | struct drm_file { |
||
4559 | Serge | 285 | unsigned authenticated :1; |
5056 | serge | 286 | /* Whether we're master for a minor. Protected by master_mutex */ |
287 | unsigned is_master :1; |
||
4559 | Serge | 288 | /* true when the client has asked us to expose stereo 3D mode flags */ |
289 | unsigned stereo_allowed :1; |
||
5056 | serge | 290 | /* |
291 | * true if client understands CRTC primary planes and cursor planes |
||
292 | * in the plane list |
||
293 | */ |
||
294 | unsigned universal_planes:1; |
||
1408 | serge | 295 | struct list_head lhead; |
296 | unsigned long lock_count; |
||
297 | |||
298 | /** Mapping of mm object handles to object pointers. */ |
||
299 | struct idr object_idr; |
||
300 | /** Lock for synchronization of access to object_idr. */ |
||
301 | spinlock_t table_lock; |
||
302 | |||
303 | void *driver_priv; |
||
304 | |||
5056 | serge | 305 | struct drm_master *master; /* master this node is currently associated with |
306 | N.B. not always minor->master */ |
||
307 | /** |
||
308 | * fbs - List of framebuffers associated with this file. |
||
309 | * |
||
310 | * Protected by fbs_lock. Note that the fbs list holds a reference on |
||
311 | * the fb object to prevent it from untimely disappearing. |
||
312 | */ |
||
1408 | serge | 313 | struct list_head fbs; |
5056 | serge | 314 | struct mutex fbs_lock; |
1408 | serge | 315 | |
316 | wait_queue_head_t event_wait; |
||
317 | struct list_head event_list; |
||
318 | int event_space; |
||
319 | }; |
||
320 | |||
321 | /** |
||
322 | * Lock data. |
||
323 | */ |
||
324 | struct drm_lock_data { |
||
325 | struct drm_hw_lock *hw_lock; /**< Hardware lock */ |
||
326 | /** Private of lock holder's file (NULL=kernel) */ |
||
327 | struct drm_file *file_priv; |
||
328 | wait_queue_head_t lock_queue; /**< Queue of blocked processes */ |
||
329 | unsigned long lock_time; /**< Time of last lock in jiffies */ |
||
330 | spinlock_t spinlock; |
||
331 | uint32_t kernel_waiters; |
||
332 | uint32_t user_waiters; |
||
333 | int idle_has_lock; |
||
334 | }; |
||
335 | |||
336 | /** |
||
5056 | serge | 337 | * struct drm_master - drm master structure |
338 | * |
||
339 | * @refcount: Refcount for this master object. |
||
340 | * @minor: Link back to minor char device we are master for. Immutable. |
||
341 | * @unique: Unique identifier: e.g. busid. Protected by drm_global_mutex. |
||
342 | * @unique_len: Length of unique field. Protected by drm_global_mutex. |
||
343 | * @magiclist: Hash of used authentication tokens. Protected by struct_mutex. |
||
344 | * @magicfree: List of used authentication tokens. Protected by struct_mutex. |
||
345 | * @lock: DRI lock information. |
||
346 | * @driver_priv: Pointer to driver-private information. |
||
347 | */ |
||
1408 | serge | 348 | struct drm_master { |
5056 | serge | 349 | struct kref refcount; |
350 | struct drm_minor *minor; |
||
351 | char *unique; |
||
352 | int unique_len; |
||
5270 | serge | 353 | struct drm_open_hash magiclist; |
354 | struct list_head magicfree; |
||
355 | struct drm_lock_data lock; |
||
5056 | serge | 356 | void *driver_priv; |
1408 | serge | 357 | }; |
358 | |||
1964 | serge | 359 | /* Size of ringbuffer for vblank timestamps. Just double-buffer |
360 | * in initial implementation. |
||
361 | */ |
||
362 | #define DRM_VBLANKTIME_RBSIZE 2 |
||
363 | |||
364 | /* Flags and return codes for get_vblank_timestamp() driver function. */ |
||
365 | #define DRM_CALLED_FROM_VBLIRQ 1 |
||
366 | #define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0) |
||
5270 | serge | 367 | #define DRM_VBLANKTIME_IN_VBLANK (1 << 1) |
1964 | serge | 368 | |
369 | /* get_scanout_position() return flags */ |
||
370 | #define DRM_SCANOUTPOS_VALID (1 << 0) |
||
5270 | serge | 371 | #define DRM_SCANOUTPOS_IN_VBLANK (1 << 1) |
1964 | serge | 372 | #define DRM_SCANOUTPOS_ACCURATE (1 << 2) |
373 | |||
1408 | serge | 374 | /** |
375 | * DRM driver structure. This structure represent the common code for |
||
376 | * a family of cards. There will one drm_device for each card present |
||
377 | * in this family |
||
378 | */ |
||
379 | struct drm_driver { |
||
380 | int (*load) (struct drm_device *, unsigned long flags); |
||
381 | int (*open) (struct drm_device *, struct drm_file *); |
||
382 | |||
383 | /** |
||
384 | * get_vblank_counter - get raw hardware vblank counter |
||
385 | * @dev: DRM device |
||
386 | * @crtc: counter to fetch |
||
387 | * |
||
3031 | serge | 388 | * Driver callback for fetching a raw hardware vblank counter for @crtc. |
389 | * If a device doesn't have a hardware counter, the driver can simply |
||
390 | * return the value of drm_vblank_count. The DRM core will account for |
||
391 | * missed vblank events while interrupts where disabled based on system |
||
392 | * timestamps. |
||
1408 | serge | 393 | * |
394 | * Wraparound handling and loss of events due to modesetting is dealt |
||
395 | * with in the DRM core code. |
||
396 | * |
||
397 | * RETURNS |
||
398 | * Raw vblank counter value. |
||
399 | */ |
||
400 | u32 (*get_vblank_counter) (struct drm_device *dev, int crtc); |
||
401 | |||
402 | /** |
||
403 | * enable_vblank - enable vblank interrupt events |
||
404 | * @dev: DRM device |
||
405 | * @crtc: which irq to enable |
||
406 | * |
||
407 | * Enable vblank interrupts for @crtc. If the device doesn't have |
||
408 | * a hardware vblank counter, this routine should be a no-op, since |
||
409 | * interrupts will have to stay on to keep the count accurate. |
||
410 | * |
||
411 | * RETURNS |
||
412 | * Zero on success, appropriate errno if the given @crtc's vblank |
||
413 | * interrupt cannot be enabled. |
||
414 | */ |
||
415 | int (*enable_vblank) (struct drm_device *dev, int crtc); |
||
416 | |||
417 | /** |
||
418 | * disable_vblank - disable vblank interrupt events |
||
419 | * @dev: DRM device |
||
420 | * @crtc: which irq to enable |
||
421 | * |
||
422 | * Disable vblank interrupts for @crtc. If the device doesn't have |
||
423 | * a hardware vblank counter, this routine should be a no-op, since |
||
424 | * interrupts will have to stay on to keep the count accurate. |
||
425 | */ |
||
426 | void (*disable_vblank) (struct drm_device *dev, int crtc); |
||
427 | /** |
||
1964 | serge | 428 | * Called by vblank timestamping code. |
429 | * |
||
4559 | Serge | 430 | * Return the current display scanout position from a crtc, and an |
431 | * optional accurate ktime_get timestamp of when position was measured. |
||
1964 | serge | 432 | * |
433 | * \param dev DRM device. |
||
434 | * \param crtc Id of the crtc to query. |
||
4559 | Serge | 435 | * \param flags Flags from the caller (DRM_CALLED_FROM_VBLIRQ or 0). |
1964 | serge | 436 | * \param *vpos Target location for current vertical scanout position. |
437 | * \param *hpos Target location for current horizontal scanout position. |
||
4559 | Serge | 438 | * \param *stime Target location for timestamp taken immediately before |
439 | * scanout position query. Can be NULL to skip timestamp. |
||
440 | * \param *etime Target location for timestamp taken immediately after |
||
441 | * scanout position query. Can be NULL to skip timestamp. |
||
1964 | serge | 442 | * |
443 | * Returns vpos as a positive number while in active scanout area. |
||
444 | * Returns vpos as a negative number inside vblank, counting the number |
||
445 | * of scanlines to go until end of vblank, e.g., -1 means "one scanline |
||
446 | * until start of active scanout / end of vblank." |
||
447 | * |
||
448 | * \return Flags, or'ed together as follows: |
||
449 | * |
||
450 | * DRM_SCANOUTPOS_VALID = Query successful. |
||
451 | * DRM_SCANOUTPOS_INVBL = Inside vblank. |
||
452 | * DRM_SCANOUTPOS_ACCURATE = Returned position is accurate. A lack of |
||
453 | * this flag means that returned position may be offset by a constant |
||
454 | * but unknown small number of scanlines wrt. real scanout position. |
||
455 | * |
||
456 | */ |
||
457 | int (*get_scanout_position) (struct drm_device *dev, int crtc, |
||
4559 | Serge | 458 | unsigned int flags, |
459 | int *vpos, int *hpos, void *stime, |
||
460 | void *etime); |
||
1964 | serge | 461 | |
462 | /** |
||
463 | * Called by \c drm_get_last_vbltimestamp. Should return a precise |
||
464 | * timestamp when the most recent VBLANK interval ended or will end. |
||
465 | * |
||
466 | * Specifically, the timestamp in @vblank_time should correspond as |
||
467 | * closely as possible to the time when the first video scanline of |
||
468 | * the video frame after the end of VBLANK will start scanning out, |
||
2967 | Serge | 469 | * the time immediately after end of the VBLANK interval. If the |
1964 | serge | 470 | * @crtc is currently inside VBLANK, this will be a time in the future. |
471 | * If the @crtc is currently scanning out a frame, this will be the |
||
472 | * past start time of the current scanout. This is meant to adhere |
||
473 | * to the OpenML OML_sync_control extension specification. |
||
474 | * |
||
475 | * \param dev dev DRM device handle. |
||
476 | * \param crtc crtc for which timestamp should be returned. |
||
477 | * \param *max_error Maximum allowable timestamp error in nanoseconds. |
||
478 | * Implementation should strive to provide timestamp |
||
479 | * with an error of at most *max_error nanoseconds. |
||
480 | * Returns true upper bound on error for timestamp. |
||
481 | * \param *vblank_time Target location for returned vblank timestamp. |
||
482 | * \param flags 0 = Defaults, no special treatment needed. |
||
483 | * \param DRM_CALLED_FROM_VBLIRQ = Function is called from vblank |
||
484 | * irq handler. Some drivers need to apply some workarounds |
||
485 | * for gpu-specific vblank irq quirks if flag is set. |
||
486 | * |
||
487 | * \returns |
||
488 | * Zero if timestamping isn't supported in current display mode or a |
||
489 | * negative number on failure. A positive status code on success, |
||
490 | * which describes how the vblank_time timestamp was computed. |
||
491 | */ |
||
492 | int (*get_vblank_timestamp) (struct drm_device *dev, int crtc, |
||
493 | int *max_error, |
||
494 | struct timeval *vblank_time, |
||
495 | unsigned flags); |
||
496 | |||
1408 | serge | 497 | /* these have to be filled in */ |
498 | |||
5056 | serge | 499 | irqreturn_t(*irq_handler) (int irq, void *arg); |
1408 | serge | 500 | void (*irq_preinstall) (struct drm_device *dev); |
501 | int (*irq_postinstall) (struct drm_device *dev); |
||
502 | void (*irq_uninstall) (struct drm_device *dev); |
||
503 | |||
504 | /** |
||
505 | * Driver-specific constructor for drm_gem_objects, to set up |
||
506 | * obj->driver_private. |
||
507 | * |
||
508 | * Returns 0 on success. |
||
509 | */ |
||
510 | void (*gem_free_object) (struct drm_gem_object *obj); |
||
2967 | Serge | 511 | int (*gem_open_object) (struct drm_gem_object *, struct drm_file *); |
512 | void (*gem_close_object) (struct drm_gem_object *, struct drm_file *); |
||
1408 | serge | 513 | u32 driver_features; |
5056 | serge | 514 | int dev_priv_size; |
1408 | serge | 515 | }; |
516 | |||
5056 | serge | 517 | enum drm_minor_type { |
518 | DRM_MINOR_LEGACY, |
||
519 | DRM_MINOR_CONTROL, |
||
520 | DRM_MINOR_RENDER, |
||
521 | DRM_MINOR_CNT, |
||
522 | }; |
||
1408 | serge | 523 | |
524 | /** |
||
525 | * Info file list entry. This structure represents a debugfs or proc file to |
||
526 | * be created by the drm core |
||
527 | */ |
||
528 | struct drm_info_list { |
||
529 | const char *name; /** file name */ |
||
2967 | Serge | 530 | // int (*show)(struct seq_file*, void*); /** show callback */ |
1408 | serge | 531 | u32 driver_features; /**< Required driver features for this entry */ |
532 | void *data; |
||
533 | }; |
||
534 | |||
535 | /** |
||
536 | * debugfs node structure. This structure represents a debugfs file. |
||
537 | */ |
||
538 | struct drm_info_node { |
||
539 | struct list_head list; |
||
540 | struct drm_minor *minor; |
||
4065 | Serge | 541 | const struct drm_info_list *info_ent; |
1408 | serge | 542 | struct dentry *dent; |
543 | }; |
||
544 | |||
545 | /** |
||
546 | * DRM minor structure. This structure represents a drm minor number. |
||
547 | */ |
||
548 | struct drm_minor { |
||
549 | int index; /**< Minor device number */ |
||
550 | int type; /**< Control or render */ |
||
2967 | Serge | 551 | // struct device kdev; /**< Linux device */ |
1408 | serge | 552 | struct drm_device *dev; |
553 | |||
5056 | serge | 554 | struct dentry *debugfs_root; |
1408 | serge | 555 | |
5056 | serge | 556 | struct list_head debugfs_list; |
557 | struct mutex debugfs_lock; /* Protects debugfs_list. */ |
||
1408 | serge | 558 | |
5056 | serge | 559 | /* currently active master for this node. Protected by master_mutex */ |
560 | struct drm_master *master; |
||
561 | struct drm_mode_group mode_group; |
||
1964 | serge | 562 | }; |
1408 | serge | 563 | |
564 | |||
5270 | serge | 565 | struct drm_pending_vblank_event { |
566 | struct drm_pending_event base; |
||
567 | int pipe; |
||
568 | struct drm_event_vblank event; |
||
569 | }; |
||
1408 | serge | 570 | |
5270 | serge | 571 | struct drm_vblank_crtc { |
572 | struct drm_device *dev; /* pointer to the drm_device */ |
||
573 | wait_queue_head_t queue; /**< VBLANK wait queue */ |
||
574 | struct timeval time[DRM_VBLANKTIME_RBSIZE]; /**< timestamp of current count */ |
||
575 | struct timer_list disable_timer; /* delayed disable timer */ |
||
576 | atomic_t count; /**< number of VBLANK interrupts */ |
||
577 | atomic_t refcount; /* number of users of vblank interruptsper crtc */ |
||
578 | u32 last; /* protected by dev->vbl_lock, used */ |
||
579 | /* for wraparound handling */ |
||
580 | u32 last_wait; /* Last vblank seqno waited per CRTC */ |
||
581 | unsigned int inmodeset; /* Display driver is setting mode */ |
||
582 | int crtc; /* crtc index */ |
||
583 | bool enabled; /* so we don't call enable more than |
||
584 | once per disable */ |
||
585 | }; |
||
586 | |||
1408 | serge | 587 | /** |
588 | * DRM device structure. This structure represent a complete card that |
||
589 | * may contain multiple heads. |
||
590 | */ |
||
591 | struct drm_device { |
||
4559 | Serge | 592 | struct list_head legacy_dev_list;/**< list of devices per driver for stealth attach cleanup */ |
1408 | serge | 593 | int if_version; /**< Highest interface version set */ |
594 | |||
5270 | serge | 595 | /** \name Lifetime Management */ |
596 | /*@{ */ |
||
597 | struct kref ref; /**< Object ref-count */ |
||
5056 | serge | 598 | struct device *dev; /**< Device structure of bus-device */ |
599 | struct drm_driver *driver; /**< DRM driver managing the device */ |
||
600 | void *dev_private; /**< DRM driver private data */ |
||
601 | struct drm_minor *primary; /**< Primary node */ |
||
602 | atomic_t unplugged; /**< Flag whether dev is dead */ |
||
1408 | serge | 603 | /** \name Locks */ |
604 | /*@{ */ |
||
1630 | serge | 605 | struct mutex struct_mutex; /**< For others */ |
5056 | serge | 606 | struct mutex master_mutex; /**< For drm_minor::master and drm_file::is_master */ |
1408 | serge | 607 | /*@} */ |
608 | |||
609 | /** \name Usage Counters */ |
||
610 | /*@{ */ |
||
5056 | serge | 611 | int open_count; /**< Outstanding files open, protected by drm_global_mutex. */ |
612 | spinlock_t buf_lock; /**< For drm_device::buf_use and a few other things. */ |
||
1408 | serge | 613 | int buf_use; /**< Buffers in use -- cannot alloc */ |
614 | atomic_t buf_alloc; /**< Buffer allocation in progress */ |
||
615 | /*@} */ |
||
616 | |||
617 | struct list_head filelist; |
||
618 | |||
619 | /** \name Memory management */ |
||
620 | /*@{ */ |
||
621 | struct list_head maplist; /**< Linked list of regions */ |
||
622 | |||
623 | /** \name Context handle management */ |
||
624 | /*@{ */ |
||
625 | struct list_head ctxlist; /**< Linked list of context handles */ |
||
1630 | serge | 626 | struct mutex ctxlist_mutex; /**< For ctxlist */ |
1408 | serge | 627 | |
1964 | serge | 628 | struct idr ctx_idr; |
1408 | serge | 629 | |
630 | struct list_head vmalist; /**< List of vmas (for debugging) */ |
||
631 | |||
632 | /*@} */ |
||
633 | |||
3031 | serge | 634 | /** \name DMA support */ |
1408 | serge | 635 | /*@{ */ |
636 | // struct drm_device_dma *dma; /**< Optional pointer for DMA support */ |
||
637 | /*@} */ |
||
638 | |||
639 | /** \name Context support */ |
||
640 | /*@{ */ |
||
4559 | Serge | 641 | bool irq_enabled; /**< True if irq handler is enabled */ |
5056 | serge | 642 | int irq; |
643 | |||
1408 | serge | 644 | __volatile__ long context_flag; /**< Context swapping flag */ |
645 | int last_context; /**< Last current context */ |
||
646 | /*@} */ |
||
647 | |||
648 | /** \name VBLANK IRQ support */ |
||
649 | /*@{ */ |
||
650 | |||
651 | /* |
||
652 | * At load time, disabling the vblank interrupt won't be allowed since |
||
653 | * old clients may not call the modeset ioctl and therefore misbehave. |
||
654 | * Once the modeset ioctl *has* been called though, we can safely |
||
655 | * disable them when unused. |
||
656 | */ |
||
4559 | Serge | 657 | bool vblank_disable_allowed; |
1408 | serge | 658 | |
5270 | serge | 659 | /* |
660 | * If true, vblank interrupt will be disabled immediately when the |
||
661 | * refcount drops to zero, as opposed to via the vblank disable |
||
662 | * timer. |
||
663 | * This can be set to true it the hardware has a working vblank |
||
664 | * counter and the driver uses drm_vblank_on() and drm_vblank_off() |
||
665 | * appropriately. |
||
666 | */ |
||
667 | bool vblank_disable_immediate; |
||
668 | |||
5056 | serge | 669 | /* array of size num_crtcs */ |
670 | struct drm_vblank_crtc *vblank; |
||
1408 | serge | 671 | |
5056 | serge | 672 | spinlock_t vblank_time_lock; /**< Protects vblank count and time updates during vblank enable/disable */ |
673 | spinlock_t vbl_lock; |
||
674 | |||
1408 | serge | 675 | u32 max_vblank_count; /**< size of vblank counter register */ |
676 | |||
1964 | serge | 677 | /** |
678 | * List of events |
||
679 | */ |
||
680 | struct list_head vblank_event_list; |
||
681 | spinlock_t event_lock; |
||
682 | |||
1408 | serge | 683 | /*@} */ |
684 | |||
685 | // struct drm_agp_head *agp; /**< AGP data */ |
||
686 | |||
687 | struct pci_dev *pdev; /**< PCI device structure */ |
||
5056 | serge | 688 | |
1964 | serge | 689 | unsigned int num_crtcs; /**< Number of CRTCs on this device */ |
1408 | serge | 690 | |
5270 | serge | 691 | struct { |
692 | int context; |
||
693 | struct drm_hw_lock *lock; |
||
694 | } sigdata; |
||
1408 | serge | 695 | |
696 | struct drm_mode_config mode_config; /**< Current mode config */ |
||
697 | |||
698 | /** \name GEM information */ |
||
699 | /*@{ */ |
||
4103 | Serge | 700 | struct mutex object_name_lock; |
1964 | serge | 701 | struct idr object_name_idr; |
4559 | Serge | 702 | struct drm_vma_offset_manager *vma_offset_manager; |
1408 | serge | 703 | /*@} */ |
1964 | serge | 704 | int switch_power_state; |
1408 | serge | 705 | }; |
706 | |||
1964 | serge | 707 | #define DRM_SWITCH_POWER_ON 0 |
708 | #define DRM_SWITCH_POWER_OFF 1 |
||
709 | #define DRM_SWITCH_POWER_CHANGING 2 |
||
4103 | Serge | 710 | #define DRM_SWITCH_POWER_DYNAMIC_OFF 3 |
1964 | serge | 711 | |
3482 | Serge | 712 | static __inline__ int drm_core_check_feature(struct drm_device *dev, |
713 | int feature) |
||
714 | { |
||
715 | return ((dev->driver->driver_features & feature) ? 1 : 0); |
||
716 | } |
||
1964 | serge | 717 | |
4065 | Serge | 718 | static inline void drm_device_set_unplugged(struct drm_device *dev) |
1408 | serge | 719 | { |
4065 | Serge | 720 | smp_wmb(); |
721 | atomic_set(&dev->unplugged, 1); |
||
1408 | serge | 722 | } |
723 | |||
4065 | Serge | 724 | static inline int drm_device_is_unplugged(struct drm_device *dev) |
1408 | serge | 725 | { |
4065 | Serge | 726 | int ret = atomic_read(&dev->unplugged); |
727 | smp_rmb(); |
||
728 | return ret; |
||
1408 | serge | 729 | } |
730 | |||
731 | |||
732 | /******************************************************************/ |
||
733 | /** \name Internal function definitions */ |
||
734 | /*@{*/ |
||
735 | |||
736 | /* Driver support (drm_drv.h) */ |
||
737 | extern long drm_ioctl(struct file *filp, |
||
738 | unsigned int cmd, unsigned long arg); |
||
739 | extern long drm_compat_ioctl(struct file *filp, |
||
740 | unsigned int cmd, unsigned long arg); |
||
5056 | serge | 741 | extern bool drm_ioctl_flags(unsigned int nr, unsigned int *flags); |
1408 | serge | 742 | |
743 | /* Device support (drm_fops.h) */ |
||
744 | extern int drm_open(struct inode *inode, struct file *filp); |
||
745 | extern ssize_t drm_read(struct file *filp, char __user *buffer, |
||
746 | size_t count, loff_t *offset); |
||
747 | extern int drm_release(struct inode *inode, struct file *filp); |
||
748 | |||
749 | /* Mapping support (drm_vm.h) */ |
||
750 | extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait); |
||
751 | |||
5270 | serge | 752 | /* Misc. IOCTL support (drm_ioctl.c) */ |
753 | int drm_noop(struct drm_device *dev, void *data, |
||
1408 | serge | 754 | struct drm_file *file_priv); |
755 | |||
756 | /* Cache management (drm_cache.c) */ |
||
757 | void drm_clflush_pages(struct page *pages[], unsigned long num_pages); |
||
3031 | serge | 758 | void drm_clflush_sg(struct sg_table *st); |
5056 | serge | 759 | void drm_clflush_virt_range(void *addr, unsigned long length); |
1408 | serge | 760 | |
761 | /* |
||
762 | * These are exported to drivers so that they can implement fencing using |
||
763 | * DMA quiscent + idle. DMA quiescent usually requires the hardware lock. |
||
764 | */ |
||
765 | |||
766 | /* IRQ support (drm_irq.h) */ |
||
5056 | serge | 767 | extern int drm_irq_install(struct drm_device *dev, int irq); |
1408 | serge | 768 | extern int drm_irq_uninstall(struct drm_device *dev); |
769 | |||
770 | extern int drm_vblank_init(struct drm_device *dev, int num_crtcs); |
||
771 | extern int drm_wait_vblank(struct drm_device *dev, void *data, |
||
772 | struct drm_file *filp); |
||
773 | extern u32 drm_vblank_count(struct drm_device *dev, int crtc); |
||
1964 | serge | 774 | extern u32 drm_vblank_count_and_time(struct drm_device *dev, int crtc, |
775 | struct timeval *vblanktime); |
||
3391 | Serge | 776 | extern void drm_send_vblank_event(struct drm_device *dev, int crtc, |
777 | struct drm_pending_vblank_event *e); |
||
1964 | serge | 778 | extern bool drm_handle_vblank(struct drm_device *dev, int crtc); |
1408 | serge | 779 | extern int drm_vblank_get(struct drm_device *dev, int crtc); |
780 | extern void drm_vblank_put(struct drm_device *dev, int crtc); |
||
5056 | serge | 781 | extern int drm_crtc_vblank_get(struct drm_crtc *crtc); |
782 | extern void drm_crtc_vblank_put(struct drm_crtc *crtc); |
||
5270 | serge | 783 | extern void drm_wait_one_vblank(struct drm_device *dev, int crtc); |
784 | extern void drm_crtc_wait_one_vblank(struct drm_crtc *crtc); |
||
1408 | serge | 785 | extern void drm_vblank_off(struct drm_device *dev, int crtc); |
5056 | serge | 786 | extern void drm_vblank_on(struct drm_device *dev, int crtc); |
787 | extern void drm_crtc_vblank_off(struct drm_crtc *crtc); |
||
788 | extern void drm_crtc_vblank_on(struct drm_crtc *crtc); |
||
1408 | serge | 789 | extern void drm_vblank_cleanup(struct drm_device *dev); |
5056 | serge | 790 | |
1964 | serge | 791 | extern int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev, |
792 | int crtc, int *max_error, |
||
793 | struct timeval *vblank_time, |
||
794 | unsigned flags, |
||
4559 | Serge | 795 | const struct drm_crtc *refcrtc, |
796 | const struct drm_display_mode *mode); |
||
797 | extern void drm_calc_timestamping_constants(struct drm_crtc *crtc, |
||
798 | const struct drm_display_mode *mode); |
||
1964 | serge | 799 | |
5270 | serge | 800 | /** |
801 | * drm_crtc_vblank_waitqueue - get vblank waitqueue for the CRTC |
||
802 | * @crtc: which CRTC's vblank waitqueue to retrieve |
||
803 | * |
||
804 | * This function returns a pointer to the vblank waitqueue for the CRTC. |
||
805 | * Drivers can use this to implement vblank waits using wait_event() & co. |
||
806 | */ |
||
807 | static inline wait_queue_head_t *drm_crtc_vblank_waitqueue(struct drm_crtc *crtc) |
||
808 | { |
||
809 | return &crtc->dev->vblank[drm_crtc_index(crtc)].queue; |
||
810 | } |
||
1964 | serge | 811 | |
1408 | serge | 812 | /* Modesetting support */ |
813 | extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc); |
||
814 | extern void drm_vblank_post_modeset(struct drm_device *dev, int crtc); |
||
815 | |||
816 | /* Stub support (drm_stub.h) */ |
||
817 | extern struct drm_master *drm_master_get(struct drm_master *master); |
||
818 | extern void drm_master_put(struct drm_master **master); |
||
1964 | serge | 819 | |
1408 | serge | 820 | extern void drm_put_dev(struct drm_device *dev); |
3031 | serge | 821 | extern void drm_unplug_dev(struct drm_device *dev); |
1408 | serge | 822 | extern unsigned int drm_debug; |
823 | |||
824 | /* Debugfs support */ |
||
825 | #if defined(CONFIG_DEBUG_FS) |
||
4559 | Serge | 826 | extern int drm_debugfs_create_files(const struct drm_info_list *files, |
827 | int count, struct dentry *root, |
||
1408 | serge | 828 | struct drm_minor *minor); |
4559 | Serge | 829 | extern int drm_debugfs_remove_files(const struct drm_info_list *files, |
830 | int count, struct drm_minor *minor); |
||
831 | #else |
||
832 | static inline int drm_debugfs_create_files(const struct drm_info_list *files, |
||
833 | int count, struct dentry *root, |
||
834 | struct drm_minor *minor) |
||
835 | { |
||
836 | return 0; |
||
837 | } |
||
838 | |||
839 | static inline int drm_debugfs_remove_files(const struct drm_info_list *files, |
||
840 | int count, struct drm_minor *minor) |
||
841 | { |
||
842 | return 0; |
||
843 | } |
||
1408 | serge | 844 | #endif |
845 | |||
5270 | serge | 846 | extern struct dma_buf *drm_gem_prime_export(struct drm_device *dev, |
847 | struct drm_gem_object *obj, int flags); |
||
848 | extern int drm_gem_prime_handle_to_fd(struct drm_device *dev, |
||
849 | struct drm_file *file_priv, uint32_t handle, uint32_t flags, |
||
850 | int *prime_fd); |
||
851 | extern struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev, |
||
852 | struct dma_buf *dma_buf); |
||
853 | extern int drm_gem_prime_fd_to_handle(struct drm_device *dev, |
||
854 | struct drm_file *file_priv, int prime_fd, uint32_t *handle); |
||
855 | extern void drm_gem_dmabuf_release(struct dma_buf *dma_buf); |
||
1408 | serge | 856 | |
5270 | serge | 857 | extern int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages, |
858 | dma_addr_t *addrs, int max_pages); |
||
859 | extern struct sg_table *drm_prime_pages_to_sg(struct page **pages, unsigned int nr_pages); |
||
860 | extern void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg); |
||
1408 | serge | 861 | |
862 | |||
5270 | serge | 863 | extern struct drm_dma_handle *drm_pci_alloc(struct drm_device *dev, size_t size, |
1428 | serge | 864 | size_t align); |
5270 | serge | 865 | extern void drm_pci_free(struct drm_device *dev, struct drm_dma_handle * dmah); |
1408 | serge | 866 | |
867 | /* sysfs support (drm_sysfs.c) */ |
||
868 | extern void drm_sysfs_hotplug_event(struct drm_device *dev); |
||
2967 | Serge | 869 | |
1408 | serge | 870 | |
5178 | serge | 871 | struct drm_device *drm_dev_alloc(struct drm_driver *driver, |
872 | struct device *parent); |
||
873 | void drm_dev_ref(struct drm_device *dev); |
||
874 | void drm_dev_unref(struct drm_device *dev); |
||
5270 | serge | 875 | int drm_dev_register(struct drm_device *dev, unsigned long flags); |
876 | void drm_dev_unregister(struct drm_device *dev); |
||
877 | int drm_dev_set_unique(struct drm_device *dev, const char *fmt, ...); |
||
5178 | serge | 878 | |
5270 | serge | 879 | struct drm_minor *drm_minor_acquire(unsigned int minor_id); |
880 | void drm_minor_release(struct drm_minor *minor); |
||
881 | |||
4103 | Serge | 882 | /*@}*/ |
3031 | serge | 883 | |
5178 | serge | 884 | /* PCI section */ |
885 | static __inline__ int drm_pci_device_is_agp(struct drm_device *dev) |
||
886 | { |
||
1408 | serge | 887 | |
5178 | serge | 888 | return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP); |
889 | } |
||
890 | void drm_pci_agp_destroy(struct drm_device *dev); |
||
891 | |||
5056 | serge | 892 | #if 0 |
893 | extern int drm_pci_init(struct drm_driver *driver, struct pci_driver *pdriver); |
||
894 | extern void drm_pci_exit(struct drm_driver *driver, struct pci_driver *pdriver); |
||
4103 | Serge | 895 | extern int drm_get_pci_dev(struct pci_dev *pdev, |
896 | const struct pci_device_id *ent, |
||
897 | struct drm_driver *driver); |
||
5056 | serge | 898 | #endif |
1408 | serge | 899 | |
3031 | serge | 900 | #define DRM_PCIE_SPEED_25 1 |
901 | #define DRM_PCIE_SPEED_50 2 |
||
902 | #define DRM_PCIE_SPEED_80 4 |
||
1408 | serge | 903 | |
3031 | serge | 904 | extern int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *speed_mask); |
905 | |||
2967 | Serge | 906 | |
907 | static __inline__ int drm_device_is_pcie(struct drm_device *dev) |
||
908 | { |
||
909 | return pci_find_capability(dev->pdev, PCI_CAP_ID_EXP); |
||
910 | } |
||
3031 | serge | 911 | |
4559 | Serge | 912 | #define LFB_SIZE 0x1000000 |
4103 | Serge | 913 | extern struct drm_device *main_device; |
914 | extern struct drm_file *drm_file_handlers[256]; |
||
3391 | Serge | 915 | |
1408 | serge | 916 | #endif>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><>><>><>><>><>>>>><> |