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