Rev 3031 | Rev 4075 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1963 | serge | 1 | /** |
2 | * \file drm_irq.c |
||
3 | * IRQ support |
||
4 | * |
||
5 | * \author Rickard E. (Rik) Faith |
||
6 | * \author Gareth Hughes |
||
7 | */ |
||
8 | |||
9 | /* |
||
10 | * Created: Fri Mar 19 14:30:16 1999 by faith@valinux.com |
||
11 | * |
||
12 | * Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas. |
||
13 | * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. |
||
14 | * All Rights Reserved. |
||
15 | * |
||
16 | * Permission is hereby granted, free of charge, to any person obtaining a |
||
17 | * copy of this software and associated documentation files (the "Software"), |
||
18 | * to deal in the Software without restriction, including without limitation |
||
19 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||
20 | * and/or sell copies of the Software, and to permit persons to whom the |
||
21 | * Software is furnished to do so, subject to the following conditions: |
||
22 | * |
||
23 | * The above copyright notice and this permission notice (including the next |
||
24 | * paragraph) shall be included in all copies or substantial portions of the |
||
25 | * Software. |
||
26 | * |
||
27 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
28 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
29 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||
30 | * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
||
31 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
||
32 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
||
33 | * OTHER DEALINGS IN THE SOFTWARE. |
||
34 | */ |
||
35 | |||
3031 | serge | 36 | #include |
1963 | serge | 37 | #include |
38 | //#include "drm_trace.h" |
||
39 | |||
40 | //#include |
||
41 | #include |
||
42 | |||
43 | //#include |
||
3031 | serge | 44 | #include |
1963 | serge | 45 | |
46 | /* Access macro for slots in vblank timestamp ringbuffer. */ |
||
47 | #define vblanktimestamp(dev, crtc, count) ( \ |
||
48 | (dev)->_vblank_time[(crtc) * DRM_VBLANKTIME_RBSIZE + \ |
||
49 | ((count) % DRM_VBLANKTIME_RBSIZE)]) |
||
50 | |||
51 | /* Retry timestamp calculation up to 3 times to satisfy |
||
52 | * drm_timestamp_precision before giving up. |
||
53 | */ |
||
54 | #define DRM_TIMESTAMP_MAXRETRIES 3 |
||
55 | |||
56 | /* Threshold in nanoseconds for detection of redundant |
||
57 | * vblank irq in drm_handle_vblank(). 1 msec should be ok. |
||
58 | */ |
||
59 | #define DRM_REDUNDANT_VBLIRQ_THRESH_NS 1000000 |
||
60 | |||
61 | |||
62 | static inline u64 div_u64(u64 dividend, u32 divisor) |
||
63 | { |
||
64 | u32 remainder; |
||
65 | return div_u64_rem(dividend, divisor, &remainder); |
||
66 | } |
||
67 | |||
68 | |||
69 | u64 div64_u64(u64 dividend, u64 divisor) |
||
70 | { |
||
71 | u32 high, d; |
||
72 | |||
73 | high = divisor >> 32; |
||
74 | if (high) { |
||
75 | unsigned int shift = fls(high); |
||
76 | |||
77 | d = divisor >> shift; |
||
78 | dividend >>= shift; |
||
79 | } else |
||
80 | d = divisor; |
||
81 | |||
82 | return div_u64(dividend, d); |
||
83 | } |
||
84 | |||
85 | |||
86 | /** |
||
87 | * drm_calc_timestamping_constants - Calculate and |
||
88 | * store various constants which are later needed by |
||
89 | * vblank and swap-completion timestamping, e.g, by |
||
90 | * drm_calc_vbltimestamp_from_scanoutpos(). |
||
91 | * They are derived from crtc's true scanout timing, |
||
92 | * so they take things like panel scaling or other |
||
93 | * adjustments into account. |
||
94 | * |
||
95 | * @crtc drm_crtc whose timestamp constants should be updated. |
||
96 | * |
||
97 | */ |
||
98 | void drm_calc_timestamping_constants(struct drm_crtc *crtc) |
||
99 | { |
||
100 | s64 linedur_ns = 0, pixeldur_ns = 0, framedur_ns = 0; |
||
101 | u64 dotclock; |
||
102 | |||
103 | /* Dot clock in Hz: */ |
||
104 | dotclock = (u64) crtc->hwmode.clock * 1000; |
||
105 | |||
106 | /* Fields of interlaced scanout modes are only halve a frame duration. |
||
107 | * Double the dotclock to get halve the frame-/line-/pixelduration. |
||
108 | */ |
||
109 | if (crtc->hwmode.flags & DRM_MODE_FLAG_INTERLACE) |
||
110 | dotclock *= 2; |
||
111 | |||
112 | /* Valid dotclock? */ |
||
113 | if (dotclock > 0) { |
||
3480 | Serge | 114 | int frame_size; |
1963 | serge | 115 | /* Convert scanline length in pixels and video dot clock to |
116 | * line duration, frame duration and pixel duration in |
||
117 | * nanoseconds: |
||
118 | */ |
||
119 | pixeldur_ns = (s64) div64_u64(1000000000, dotclock); |
||
120 | linedur_ns = (s64) div64_u64(((u64) crtc->hwmode.crtc_htotal * |
||
121 | 1000000000), dotclock); |
||
3480 | Serge | 122 | frame_size = crtc->hwmode.crtc_htotal * |
123 | crtc->hwmode.crtc_vtotal; |
||
124 | framedur_ns = (s64) div64_u64((u64) frame_size * 1000000000, |
||
125 | dotclock); |
||
1963 | serge | 126 | } else |
127 | DRM_ERROR("crtc %d: Can't calculate constants, dotclock = 0!\n", |
||
128 | crtc->base.id); |
||
129 | |||
130 | crtc->pixeldur_ns = pixeldur_ns; |
||
131 | crtc->linedur_ns = linedur_ns; |
||
132 | crtc->framedur_ns = framedur_ns; |
||
133 | |||
134 | DRM_DEBUG("crtc %d: hwmode: htotal %d, vtotal %d, vdisplay %d\n", |
||
135 | crtc->base.id, crtc->hwmode.crtc_htotal, |
||
136 | crtc->hwmode.crtc_vtotal, crtc->hwmode.crtc_vdisplay); |
||
137 | DRM_DEBUG("crtc %d: clock %d kHz framedur %d linedur %d, pixeldur %d\n", |
||
138 | crtc->base.id, (int) dotclock/1000, (int) framedur_ns, |
||
139 | (int) linedur_ns, (int) pixeldur_ns); |
||
140 | } |
||
141 | |||
3031 | serge | 142 | |
143 | /** |
||
144 | * drm_vblank_pre_modeset - account for vblanks across mode sets |
||
145 | * @dev: DRM device |
||
146 | * @crtc: CRTC in question |
||
147 | * |
||
148 | * Account for vblank events across mode setting events, which will likely |
||
149 | * reset the hardware frame counter. |
||
150 | */ |
||
151 | void drm_vblank_pre_modeset(struct drm_device *dev, int crtc) |
||
152 | { |
||
153 | #if 0 |
||
154 | /* vblank is not initialized (IRQ not installed ?) */ |
||
155 | if (!dev->num_crtcs) |
||
156 | return; |
||
157 | /* |
||
158 | * To avoid all the problems that might happen if interrupts |
||
159 | * were enabled/disabled around or between these calls, we just |
||
160 | * have the kernel take a reference on the CRTC (just once though |
||
161 | * to avoid corrupting the count if multiple, mismatch calls occur), |
||
162 | * so that interrupts remain enabled in the interim. |
||
163 | */ |
||
164 | if (!dev->vblank_inmodeset[crtc]) { |
||
165 | dev->vblank_inmodeset[crtc] = 0x1; |
||
166 | if (drm_vblank_get(dev, crtc) == 0) |
||
167 | dev->vblank_inmodeset[crtc] |= 0x2; |
||
168 | } |
||
169 | #endif |
||
170 | } |
||
171 | EXPORT_SYMBOL(drm_vblank_pre_modeset); |
||
172 | |||
173 | void drm_vblank_post_modeset(struct drm_device *dev, int crtc) |
||
174 | { |
||
175 | #if 0 |
||
176 | unsigned long irqflags; |
||
177 | |||
178 | if (dev->vblank_inmodeset[crtc]) { |
||
179 | spin_lock_irqsave(&dev->vbl_lock, irqflags); |
||
180 | dev->vblank_disable_allowed = 1; |
||
181 | spin_unlock_irqrestore(&dev->vbl_lock, irqflags); |
||
182 | |||
183 | if (dev->vblank_inmodeset[crtc] & 0x2) |
||
184 | drm_vblank_put(dev, crtc); |
||
185 | |||
186 | dev->vblank_inmodeset[crtc] = 0; |
||
187 | } |
||
188 | #endif |
||
189 | } |
||
190 | EXPORT_SYMBOL(drm_vblank_post_modeset); |