Commit | Line | Data |
---|---|---|
0d6aa60b | 1 | /* i915_irq.c -- IRQ support for the I915 -*- linux-c -*- |
1da177e4 | 2 | */ |
0d6aa60b | 3 | /* |
1da177e4 LT |
4 | * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. |
5 | * All Rights Reserved. | |
bc54fd1a DA |
6 | * |
7 | * Permission is hereby granted, free of charge, to any person obtaining a | |
8 | * copy of this software and associated documentation files (the | |
9 | * "Software"), to deal in the Software without restriction, including | |
10 | * without limitation the rights to use, copy, modify, merge, publish, | |
11 | * distribute, sub license, and/or sell copies of the Software, and to | |
12 | * permit persons to whom the Software is furnished to do so, subject to | |
13 | * the following conditions: | |
14 | * | |
15 | * The above copyright notice and this permission notice (including the | |
16 | * next paragraph) shall be included in all copies or substantial portions | |
17 | * of the Software. | |
18 | * | |
19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
20 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
21 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. | |
22 | * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR | |
23 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | |
24 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | |
25 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
26 | * | |
0d6aa60b | 27 | */ |
1da177e4 | 28 | |
a70491cc JP |
29 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
30 | ||
63eeaf38 | 31 | #include <linux/sysrq.h> |
5a0e3ad6 | 32 | #include <linux/slab.h> |
760285e7 DH |
33 | #include <drm/drmP.h> |
34 | #include <drm/i915_drm.h> | |
1da177e4 | 35 | #include "i915_drv.h" |
1c5d22f7 | 36 | #include "i915_trace.h" |
79e53945 | 37 | #include "intel_drv.h" |
1da177e4 | 38 | |
e5868a31 EE |
39 | static const u32 hpd_ibx[] = { |
40 | [HPD_CRT] = SDE_CRT_HOTPLUG, | |
41 | [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG, | |
42 | [HPD_PORT_B] = SDE_PORTB_HOTPLUG, | |
43 | [HPD_PORT_C] = SDE_PORTC_HOTPLUG, | |
44 | [HPD_PORT_D] = SDE_PORTD_HOTPLUG | |
45 | }; | |
46 | ||
47 | static const u32 hpd_cpt[] = { | |
48 | [HPD_CRT] = SDE_CRT_HOTPLUG_CPT, | |
73c352a2 | 49 | [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT, |
e5868a31 EE |
50 | [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT, |
51 | [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT, | |
52 | [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT | |
53 | }; | |
54 | ||
55 | static const u32 hpd_mask_i915[] = { | |
56 | [HPD_CRT] = CRT_HOTPLUG_INT_EN, | |
57 | [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN, | |
58 | [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN, | |
59 | [HPD_PORT_B] = PORTB_HOTPLUG_INT_EN, | |
60 | [HPD_PORT_C] = PORTC_HOTPLUG_INT_EN, | |
61 | [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN | |
62 | }; | |
63 | ||
64 | static const u32 hpd_status_gen4[] = { | |
65 | [HPD_CRT] = CRT_HOTPLUG_INT_STATUS, | |
66 | [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X, | |
67 | [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X, | |
68 | [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS, | |
69 | [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS, | |
70 | [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS | |
71 | }; | |
72 | ||
e5868a31 EE |
73 | static const u32 hpd_status_i915[] = { /* i915 and valleyview are the same */ |
74 | [HPD_CRT] = CRT_HOTPLUG_INT_STATUS, | |
75 | [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915, | |
76 | [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915, | |
77 | [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS, | |
78 | [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS, | |
79 | [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS | |
80 | }; | |
81 | ||
036a4a7d | 82 | /* For display hotplug interrupt */ |
995b6762 | 83 | static void |
f2b115e6 | 84 | ironlake_enable_display_irq(drm_i915_private_t *dev_priv, u32 mask) |
036a4a7d | 85 | { |
4bc9d430 DV |
86 | assert_spin_locked(&dev_priv->irq_lock); |
87 | ||
1ec14ad3 CW |
88 | if ((dev_priv->irq_mask & mask) != 0) { |
89 | dev_priv->irq_mask &= ~mask; | |
90 | I915_WRITE(DEIMR, dev_priv->irq_mask); | |
3143a2bf | 91 | POSTING_READ(DEIMR); |
036a4a7d ZW |
92 | } |
93 | } | |
94 | ||
0ff9800a | 95 | static void |
f2b115e6 | 96 | ironlake_disable_display_irq(drm_i915_private_t *dev_priv, u32 mask) |
036a4a7d | 97 | { |
4bc9d430 DV |
98 | assert_spin_locked(&dev_priv->irq_lock); |
99 | ||
1ec14ad3 CW |
100 | if ((dev_priv->irq_mask & mask) != mask) { |
101 | dev_priv->irq_mask |= mask; | |
102 | I915_WRITE(DEIMR, dev_priv->irq_mask); | |
3143a2bf | 103 | POSTING_READ(DEIMR); |
036a4a7d ZW |
104 | } |
105 | } | |
106 | ||
8664281b PZ |
107 | static bool ivb_can_enable_err_int(struct drm_device *dev) |
108 | { | |
109 | struct drm_i915_private *dev_priv = dev->dev_private; | |
110 | struct intel_crtc *crtc; | |
111 | enum pipe pipe; | |
112 | ||
4bc9d430 DV |
113 | assert_spin_locked(&dev_priv->irq_lock); |
114 | ||
8664281b PZ |
115 | for_each_pipe(pipe) { |
116 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); | |
117 | ||
118 | if (crtc->cpu_fifo_underrun_disabled) | |
119 | return false; | |
120 | } | |
121 | ||
122 | return true; | |
123 | } | |
124 | ||
125 | static bool cpt_can_enable_serr_int(struct drm_device *dev) | |
126 | { | |
127 | struct drm_i915_private *dev_priv = dev->dev_private; | |
128 | enum pipe pipe; | |
129 | struct intel_crtc *crtc; | |
130 | ||
fee884ed DV |
131 | assert_spin_locked(&dev_priv->irq_lock); |
132 | ||
8664281b PZ |
133 | for_each_pipe(pipe) { |
134 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); | |
135 | ||
136 | if (crtc->pch_fifo_underrun_disabled) | |
137 | return false; | |
138 | } | |
139 | ||
140 | return true; | |
141 | } | |
142 | ||
143 | static void ironlake_set_fifo_underrun_reporting(struct drm_device *dev, | |
144 | enum pipe pipe, bool enable) | |
145 | { | |
146 | struct drm_i915_private *dev_priv = dev->dev_private; | |
147 | uint32_t bit = (pipe == PIPE_A) ? DE_PIPEA_FIFO_UNDERRUN : | |
148 | DE_PIPEB_FIFO_UNDERRUN; | |
149 | ||
150 | if (enable) | |
151 | ironlake_enable_display_irq(dev_priv, bit); | |
152 | else | |
153 | ironlake_disable_display_irq(dev_priv, bit); | |
154 | } | |
155 | ||
156 | static void ivybridge_set_fifo_underrun_reporting(struct drm_device *dev, | |
7336df65 | 157 | enum pipe pipe, bool enable) |
8664281b PZ |
158 | { |
159 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8664281b | 160 | if (enable) { |
7336df65 DV |
161 | I915_WRITE(GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe)); |
162 | ||
8664281b PZ |
163 | if (!ivb_can_enable_err_int(dev)) |
164 | return; | |
165 | ||
8664281b PZ |
166 | ironlake_enable_display_irq(dev_priv, DE_ERR_INT_IVB); |
167 | } else { | |
7336df65 DV |
168 | bool was_enabled = !(I915_READ(DEIMR) & DE_ERR_INT_IVB); |
169 | ||
170 | /* Change the state _after_ we've read out the current one. */ | |
8664281b | 171 | ironlake_disable_display_irq(dev_priv, DE_ERR_INT_IVB); |
7336df65 DV |
172 | |
173 | if (!was_enabled && | |
174 | (I915_READ(GEN7_ERR_INT) & ERR_INT_FIFO_UNDERRUN(pipe))) { | |
175 | DRM_DEBUG_KMS("uncleared fifo underrun on pipe %c\n", | |
176 | pipe_name(pipe)); | |
177 | } | |
8664281b PZ |
178 | } |
179 | } | |
180 | ||
fee884ed DV |
181 | /** |
182 | * ibx_display_interrupt_update - update SDEIMR | |
183 | * @dev_priv: driver private | |
184 | * @interrupt_mask: mask of interrupt bits to update | |
185 | * @enabled_irq_mask: mask of interrupt bits to enable | |
186 | */ | |
187 | static void ibx_display_interrupt_update(struct drm_i915_private *dev_priv, | |
188 | uint32_t interrupt_mask, | |
189 | uint32_t enabled_irq_mask) | |
190 | { | |
191 | uint32_t sdeimr = I915_READ(SDEIMR); | |
192 | sdeimr &= ~interrupt_mask; | |
193 | sdeimr |= (~enabled_irq_mask & interrupt_mask); | |
194 | ||
195 | assert_spin_locked(&dev_priv->irq_lock); | |
196 | ||
197 | I915_WRITE(SDEIMR, sdeimr); | |
198 | POSTING_READ(SDEIMR); | |
199 | } | |
200 | #define ibx_enable_display_interrupt(dev_priv, bits) \ | |
201 | ibx_display_interrupt_update((dev_priv), (bits), (bits)) | |
202 | #define ibx_disable_display_interrupt(dev_priv, bits) \ | |
203 | ibx_display_interrupt_update((dev_priv), (bits), 0) | |
204 | ||
de28075d DV |
205 | static void ibx_set_fifo_underrun_reporting(struct drm_device *dev, |
206 | enum transcoder pch_transcoder, | |
8664281b PZ |
207 | bool enable) |
208 | { | |
8664281b | 209 | struct drm_i915_private *dev_priv = dev->dev_private; |
de28075d DV |
210 | uint32_t bit = (pch_transcoder == TRANSCODER_A) ? |
211 | SDE_TRANSA_FIFO_UNDER : SDE_TRANSB_FIFO_UNDER; | |
8664281b PZ |
212 | |
213 | if (enable) | |
fee884ed | 214 | ibx_enable_display_interrupt(dev_priv, bit); |
8664281b | 215 | else |
fee884ed | 216 | ibx_disable_display_interrupt(dev_priv, bit); |
8664281b PZ |
217 | } |
218 | ||
219 | static void cpt_set_fifo_underrun_reporting(struct drm_device *dev, | |
220 | enum transcoder pch_transcoder, | |
221 | bool enable) | |
222 | { | |
223 | struct drm_i915_private *dev_priv = dev->dev_private; | |
224 | ||
225 | if (enable) { | |
1dd246fb DV |
226 | I915_WRITE(SERR_INT, |
227 | SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder)); | |
228 | ||
8664281b PZ |
229 | if (!cpt_can_enable_serr_int(dev)) |
230 | return; | |
231 | ||
fee884ed | 232 | ibx_enable_display_interrupt(dev_priv, SDE_ERROR_CPT); |
8664281b | 233 | } else { |
1dd246fb DV |
234 | uint32_t tmp = I915_READ(SERR_INT); |
235 | bool was_enabled = !(I915_READ(SDEIMR) & SDE_ERROR_CPT); | |
236 | ||
237 | /* Change the state _after_ we've read out the current one. */ | |
fee884ed | 238 | ibx_disable_display_interrupt(dev_priv, SDE_ERROR_CPT); |
1dd246fb DV |
239 | |
240 | if (!was_enabled && | |
241 | (tmp & SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder))) { | |
242 | DRM_DEBUG_KMS("uncleared pch fifo underrun on pch transcoder %c\n", | |
243 | transcoder_name(pch_transcoder)); | |
244 | } | |
8664281b | 245 | } |
8664281b PZ |
246 | } |
247 | ||
248 | /** | |
249 | * intel_set_cpu_fifo_underrun_reporting - enable/disable FIFO underrun messages | |
250 | * @dev: drm device | |
251 | * @pipe: pipe | |
252 | * @enable: true if we want to report FIFO underrun errors, false otherwise | |
253 | * | |
254 | * This function makes us disable or enable CPU fifo underruns for a specific | |
255 | * pipe. Notice that on some Gens (e.g. IVB, HSW), disabling FIFO underrun | |
256 | * reporting for one pipe may also disable all the other CPU error interruts for | |
257 | * the other pipes, due to the fact that there's just one interrupt mask/enable | |
258 | * bit for all the pipes. | |
259 | * | |
260 | * Returns the previous state of underrun reporting. | |
261 | */ | |
262 | bool intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev, | |
263 | enum pipe pipe, bool enable) | |
264 | { | |
265 | struct drm_i915_private *dev_priv = dev->dev_private; | |
266 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; | |
267 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
268 | unsigned long flags; | |
269 | bool ret; | |
270 | ||
271 | spin_lock_irqsave(&dev_priv->irq_lock, flags); | |
272 | ||
273 | ret = !intel_crtc->cpu_fifo_underrun_disabled; | |
274 | ||
275 | if (enable == ret) | |
276 | goto done; | |
277 | ||
278 | intel_crtc->cpu_fifo_underrun_disabled = !enable; | |
279 | ||
280 | if (IS_GEN5(dev) || IS_GEN6(dev)) | |
281 | ironlake_set_fifo_underrun_reporting(dev, pipe, enable); | |
282 | else if (IS_GEN7(dev)) | |
7336df65 | 283 | ivybridge_set_fifo_underrun_reporting(dev, pipe, enable); |
8664281b PZ |
284 | |
285 | done: | |
286 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); | |
287 | return ret; | |
288 | } | |
289 | ||
290 | /** | |
291 | * intel_set_pch_fifo_underrun_reporting - enable/disable FIFO underrun messages | |
292 | * @dev: drm device | |
293 | * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older) | |
294 | * @enable: true if we want to report FIFO underrun errors, false otherwise | |
295 | * | |
296 | * This function makes us disable or enable PCH fifo underruns for a specific | |
297 | * PCH transcoder. Notice that on some PCHs (e.g. CPT/PPT), disabling FIFO | |
298 | * underrun reporting for one transcoder may also disable all the other PCH | |
299 | * error interruts for the other transcoders, due to the fact that there's just | |
300 | * one interrupt mask/enable bit for all the transcoders. | |
301 | * | |
302 | * Returns the previous state of underrun reporting. | |
303 | */ | |
304 | bool intel_set_pch_fifo_underrun_reporting(struct drm_device *dev, | |
305 | enum transcoder pch_transcoder, | |
306 | bool enable) | |
307 | { | |
308 | struct drm_i915_private *dev_priv = dev->dev_private; | |
de28075d DV |
309 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pch_transcoder]; |
310 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
8664281b PZ |
311 | unsigned long flags; |
312 | bool ret; | |
313 | ||
de28075d DV |
314 | /* |
315 | * NOTE: Pre-LPT has a fixed cpu pipe -> pch transcoder mapping, but LPT | |
316 | * has only one pch transcoder A that all pipes can use. To avoid racy | |
317 | * pch transcoder -> pipe lookups from interrupt code simply store the | |
318 | * underrun statistics in crtc A. Since we never expose this anywhere | |
319 | * nor use it outside of the fifo underrun code here using the "wrong" | |
320 | * crtc on LPT won't cause issues. | |
321 | */ | |
8664281b PZ |
322 | |
323 | spin_lock_irqsave(&dev_priv->irq_lock, flags); | |
324 | ||
325 | ret = !intel_crtc->pch_fifo_underrun_disabled; | |
326 | ||
327 | if (enable == ret) | |
328 | goto done; | |
329 | ||
330 | intel_crtc->pch_fifo_underrun_disabled = !enable; | |
331 | ||
332 | if (HAS_PCH_IBX(dev)) | |
de28075d | 333 | ibx_set_fifo_underrun_reporting(dev, pch_transcoder, enable); |
8664281b PZ |
334 | else |
335 | cpt_set_fifo_underrun_reporting(dev, pch_transcoder, enable); | |
336 | ||
337 | done: | |
338 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); | |
339 | return ret; | |
340 | } | |
341 | ||
342 | ||
7c463586 KP |
343 | void |
344 | i915_enable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask) | |
345 | { | |
46c06a30 VS |
346 | u32 reg = PIPESTAT(pipe); |
347 | u32 pipestat = I915_READ(reg) & 0x7fff0000; | |
7c463586 | 348 | |
b79480ba DV |
349 | assert_spin_locked(&dev_priv->irq_lock); |
350 | ||
46c06a30 VS |
351 | if ((pipestat & mask) == mask) |
352 | return; | |
353 | ||
354 | /* Enable the interrupt, clear any pending status */ | |
355 | pipestat |= mask | (mask >> 16); | |
356 | I915_WRITE(reg, pipestat); | |
357 | POSTING_READ(reg); | |
7c463586 KP |
358 | } |
359 | ||
360 | void | |
361 | i915_disable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask) | |
362 | { | |
46c06a30 VS |
363 | u32 reg = PIPESTAT(pipe); |
364 | u32 pipestat = I915_READ(reg) & 0x7fff0000; | |
7c463586 | 365 | |
b79480ba DV |
366 | assert_spin_locked(&dev_priv->irq_lock); |
367 | ||
46c06a30 VS |
368 | if ((pipestat & mask) == 0) |
369 | return; | |
370 | ||
371 | pipestat &= ~mask; | |
372 | I915_WRITE(reg, pipestat); | |
373 | POSTING_READ(reg); | |
7c463586 KP |
374 | } |
375 | ||
01c66889 | 376 | /** |
f49e38dd | 377 | * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion |
01c66889 | 378 | */ |
f49e38dd | 379 | static void i915_enable_asle_pipestat(struct drm_device *dev) |
01c66889 | 380 | { |
1ec14ad3 CW |
381 | drm_i915_private_t *dev_priv = dev->dev_private; |
382 | unsigned long irqflags; | |
383 | ||
f49e38dd JN |
384 | if (!dev_priv->opregion.asle || !IS_MOBILE(dev)) |
385 | return; | |
386 | ||
1ec14ad3 | 387 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
01c66889 | 388 | |
f898780b JN |
389 | i915_enable_pipestat(dev_priv, 1, PIPE_LEGACY_BLC_EVENT_ENABLE); |
390 | if (INTEL_INFO(dev)->gen >= 4) | |
391 | i915_enable_pipestat(dev_priv, 0, PIPE_LEGACY_BLC_EVENT_ENABLE); | |
1ec14ad3 CW |
392 | |
393 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); | |
01c66889 ZY |
394 | } |
395 | ||
0a3e67a4 JB |
396 | /** |
397 | * i915_pipe_enabled - check if a pipe is enabled | |
398 | * @dev: DRM device | |
399 | * @pipe: pipe to check | |
400 | * | |
401 | * Reading certain registers when the pipe is disabled can hang the chip. | |
402 | * Use this routine to make sure the PLL is running and the pipe is active | |
403 | * before reading such registers if unsure. | |
404 | */ | |
405 | static int | |
406 | i915_pipe_enabled(struct drm_device *dev, int pipe) | |
407 | { | |
408 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; | |
702e7a56 | 409 | |
a01025af DV |
410 | if (drm_core_check_feature(dev, DRIVER_MODESET)) { |
411 | /* Locking is horribly broken here, but whatever. */ | |
412 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; | |
413 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
71f8ba6b | 414 | |
a01025af DV |
415 | return intel_crtc->active; |
416 | } else { | |
417 | return I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE; | |
418 | } | |
0a3e67a4 JB |
419 | } |
420 | ||
42f52ef8 KP |
421 | /* Called from drm generic code, passed a 'crtc', which |
422 | * we use as a pipe index | |
423 | */ | |
f71d4af4 | 424 | static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe) |
0a3e67a4 JB |
425 | { |
426 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; | |
427 | unsigned long high_frame; | |
428 | unsigned long low_frame; | |
5eddb70b | 429 | u32 high1, high2, low; |
0a3e67a4 JB |
430 | |
431 | if (!i915_pipe_enabled(dev, pipe)) { | |
44d98a61 | 432 | DRM_DEBUG_DRIVER("trying to get vblank count for disabled " |
9db4a9c7 | 433 | "pipe %c\n", pipe_name(pipe)); |
0a3e67a4 JB |
434 | return 0; |
435 | } | |
436 | ||
9db4a9c7 JB |
437 | high_frame = PIPEFRAME(pipe); |
438 | low_frame = PIPEFRAMEPIXEL(pipe); | |
5eddb70b | 439 | |
0a3e67a4 JB |
440 | /* |
441 | * High & low register fields aren't synchronized, so make sure | |
442 | * we get a low value that's stable across two reads of the high | |
443 | * register. | |
444 | */ | |
445 | do { | |
5eddb70b CW |
446 | high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK; |
447 | low = I915_READ(low_frame) & PIPE_FRAME_LOW_MASK; | |
448 | high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK; | |
0a3e67a4 JB |
449 | } while (high1 != high2); |
450 | ||
5eddb70b CW |
451 | high1 >>= PIPE_FRAME_HIGH_SHIFT; |
452 | low >>= PIPE_FRAME_LOW_SHIFT; | |
453 | return (high1 << 8) | low; | |
0a3e67a4 JB |
454 | } |
455 | ||
f71d4af4 | 456 | static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe) |
9880b7a5 JB |
457 | { |
458 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; | |
9db4a9c7 | 459 | int reg = PIPE_FRMCOUNT_GM45(pipe); |
9880b7a5 JB |
460 | |
461 | if (!i915_pipe_enabled(dev, pipe)) { | |
44d98a61 | 462 | DRM_DEBUG_DRIVER("trying to get vblank count for disabled " |
9db4a9c7 | 463 | "pipe %c\n", pipe_name(pipe)); |
9880b7a5 JB |
464 | return 0; |
465 | } | |
466 | ||
467 | return I915_READ(reg); | |
468 | } | |
469 | ||
f71d4af4 | 470 | static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe, |
0af7e4df MK |
471 | int *vpos, int *hpos) |
472 | { | |
473 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; | |
474 | u32 vbl = 0, position = 0; | |
475 | int vbl_start, vbl_end, htotal, vtotal; | |
476 | bool in_vbl = true; | |
477 | int ret = 0; | |
fe2b8f9d PZ |
478 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
479 | pipe); | |
0af7e4df MK |
480 | |
481 | if (!i915_pipe_enabled(dev, pipe)) { | |
482 | DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled " | |
9db4a9c7 | 483 | "pipe %c\n", pipe_name(pipe)); |
0af7e4df MK |
484 | return 0; |
485 | } | |
486 | ||
487 | /* Get vtotal. */ | |
fe2b8f9d | 488 | vtotal = 1 + ((I915_READ(VTOTAL(cpu_transcoder)) >> 16) & 0x1fff); |
0af7e4df MK |
489 | |
490 | if (INTEL_INFO(dev)->gen >= 4) { | |
491 | /* No obvious pixelcount register. Only query vertical | |
492 | * scanout position from Display scan line register. | |
493 | */ | |
494 | position = I915_READ(PIPEDSL(pipe)); | |
495 | ||
496 | /* Decode into vertical scanout position. Don't have | |
497 | * horizontal scanout position. | |
498 | */ | |
499 | *vpos = position & 0x1fff; | |
500 | *hpos = 0; | |
501 | } else { | |
502 | /* Have access to pixelcount since start of frame. | |
503 | * We can split this into vertical and horizontal | |
504 | * scanout position. | |
505 | */ | |
506 | position = (I915_READ(PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT; | |
507 | ||
fe2b8f9d | 508 | htotal = 1 + ((I915_READ(HTOTAL(cpu_transcoder)) >> 16) & 0x1fff); |
0af7e4df MK |
509 | *vpos = position / htotal; |
510 | *hpos = position - (*vpos * htotal); | |
511 | } | |
512 | ||
513 | /* Query vblank area. */ | |
fe2b8f9d | 514 | vbl = I915_READ(VBLANK(cpu_transcoder)); |
0af7e4df MK |
515 | |
516 | /* Test position against vblank region. */ | |
517 | vbl_start = vbl & 0x1fff; | |
518 | vbl_end = (vbl >> 16) & 0x1fff; | |
519 | ||
520 | if ((*vpos < vbl_start) || (*vpos > vbl_end)) | |
521 | in_vbl = false; | |
522 | ||
523 | /* Inside "upper part" of vblank area? Apply corrective offset: */ | |
524 | if (in_vbl && (*vpos >= vbl_start)) | |
525 | *vpos = *vpos - vtotal; | |
526 | ||
527 | /* Readouts valid? */ | |
528 | if (vbl > 0) | |
529 | ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE; | |
530 | ||
531 | /* In vblank? */ | |
532 | if (in_vbl) | |
533 | ret |= DRM_SCANOUTPOS_INVBL; | |
534 | ||
535 | return ret; | |
536 | } | |
537 | ||
f71d4af4 | 538 | static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe, |
0af7e4df MK |
539 | int *max_error, |
540 | struct timeval *vblank_time, | |
541 | unsigned flags) | |
542 | { | |
4041b853 | 543 | struct drm_crtc *crtc; |
0af7e4df | 544 | |
7eb552ae | 545 | if (pipe < 0 || pipe >= INTEL_INFO(dev)->num_pipes) { |
4041b853 | 546 | DRM_ERROR("Invalid crtc %d\n", pipe); |
0af7e4df MK |
547 | return -EINVAL; |
548 | } | |
549 | ||
550 | /* Get drm_crtc to timestamp: */ | |
4041b853 CW |
551 | crtc = intel_get_crtc_for_pipe(dev, pipe); |
552 | if (crtc == NULL) { | |
553 | DRM_ERROR("Invalid crtc %d\n", pipe); | |
554 | return -EINVAL; | |
555 | } | |
556 | ||
557 | if (!crtc->enabled) { | |
558 | DRM_DEBUG_KMS("crtc %d is disabled\n", pipe); | |
559 | return -EBUSY; | |
560 | } | |
0af7e4df MK |
561 | |
562 | /* Helper routine in DRM core does all the work: */ | |
4041b853 CW |
563 | return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error, |
564 | vblank_time, flags, | |
565 | crtc); | |
0af7e4df MK |
566 | } |
567 | ||
321a1b30 EE |
568 | static int intel_hpd_irq_event(struct drm_device *dev, struct drm_connector *connector) |
569 | { | |
570 | enum drm_connector_status old_status; | |
571 | ||
572 | WARN_ON(!mutex_is_locked(&dev->mode_config.mutex)); | |
573 | old_status = connector->status; | |
574 | ||
575 | connector->status = connector->funcs->detect(connector, false); | |
576 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %d to %d\n", | |
577 | connector->base.id, | |
578 | drm_get_connector_name(connector), | |
579 | old_status, connector->status); | |
580 | return (old_status != connector->status); | |
581 | } | |
582 | ||
5ca58282 JB |
583 | /* |
584 | * Handle hotplug events outside the interrupt handler proper. | |
585 | */ | |
ac4c16c5 EE |
586 | #define I915_REENABLE_HOTPLUG_DELAY (2*60*1000) |
587 | ||
5ca58282 JB |
588 | static void i915_hotplug_work_func(struct work_struct *work) |
589 | { | |
590 | drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t, | |
591 | hotplug_work); | |
592 | struct drm_device *dev = dev_priv->dev; | |
c31c4ba3 | 593 | struct drm_mode_config *mode_config = &dev->mode_config; |
cd569aed EE |
594 | struct intel_connector *intel_connector; |
595 | struct intel_encoder *intel_encoder; | |
596 | struct drm_connector *connector; | |
597 | unsigned long irqflags; | |
598 | bool hpd_disabled = false; | |
321a1b30 | 599 | bool changed = false; |
142e2398 | 600 | u32 hpd_event_bits; |
4ef69c7a | 601 | |
52d7eced DV |
602 | /* HPD irq before everything is fully set up. */ |
603 | if (!dev_priv->enable_hotplug_processing) | |
604 | return; | |
605 | ||
a65e34c7 | 606 | mutex_lock(&mode_config->mutex); |
e67189ab JB |
607 | DRM_DEBUG_KMS("running encoder hotplug functions\n"); |
608 | ||
cd569aed | 609 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
142e2398 EE |
610 | |
611 | hpd_event_bits = dev_priv->hpd_event_bits; | |
612 | dev_priv->hpd_event_bits = 0; | |
cd569aed EE |
613 | list_for_each_entry(connector, &mode_config->connector_list, head) { |
614 | intel_connector = to_intel_connector(connector); | |
615 | intel_encoder = intel_connector->encoder; | |
616 | if (intel_encoder->hpd_pin > HPD_NONE && | |
617 | dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_MARK_DISABLED && | |
618 | connector->polled == DRM_CONNECTOR_POLL_HPD) { | |
619 | DRM_INFO("HPD interrupt storm detected on connector %s: " | |
620 | "switching from hotplug detection to polling\n", | |
621 | drm_get_connector_name(connector)); | |
622 | dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark = HPD_DISABLED; | |
623 | connector->polled = DRM_CONNECTOR_POLL_CONNECT | |
624 | | DRM_CONNECTOR_POLL_DISCONNECT; | |
625 | hpd_disabled = true; | |
626 | } | |
142e2398 EE |
627 | if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) { |
628 | DRM_DEBUG_KMS("Connector %s (pin %i) received hotplug event.\n", | |
629 | drm_get_connector_name(connector), intel_encoder->hpd_pin); | |
630 | } | |
cd569aed EE |
631 | } |
632 | /* if there were no outputs to poll, poll was disabled, | |
633 | * therefore make sure it's enabled when disabling HPD on | |
634 | * some connectors */ | |
ac4c16c5 | 635 | if (hpd_disabled) { |
cd569aed | 636 | drm_kms_helper_poll_enable(dev); |
ac4c16c5 EE |
637 | mod_timer(&dev_priv->hotplug_reenable_timer, |
638 | jiffies + msecs_to_jiffies(I915_REENABLE_HOTPLUG_DELAY)); | |
639 | } | |
cd569aed EE |
640 | |
641 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); | |
642 | ||
321a1b30 EE |
643 | list_for_each_entry(connector, &mode_config->connector_list, head) { |
644 | intel_connector = to_intel_connector(connector); | |
645 | intel_encoder = intel_connector->encoder; | |
646 | if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) { | |
647 | if (intel_encoder->hot_plug) | |
648 | intel_encoder->hot_plug(intel_encoder); | |
649 | if (intel_hpd_irq_event(dev, connector)) | |
650 | changed = true; | |
651 | } | |
652 | } | |
40ee3381 KP |
653 | mutex_unlock(&mode_config->mutex); |
654 | ||
321a1b30 EE |
655 | if (changed) |
656 | drm_kms_helper_hotplug_event(dev); | |
5ca58282 JB |
657 | } |
658 | ||
d0ecd7e2 | 659 | static void ironlake_rps_change_irq_handler(struct drm_device *dev) |
f97108d1 JB |
660 | { |
661 | drm_i915_private_t *dev_priv = dev->dev_private; | |
b5b72e89 | 662 | u32 busy_up, busy_down, max_avg, min_avg; |
9270388e | 663 | u8 new_delay; |
9270388e | 664 | |
d0ecd7e2 | 665 | spin_lock(&mchdev_lock); |
f97108d1 | 666 | |
73edd18f DV |
667 | I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS)); |
668 | ||
20e4d407 | 669 | new_delay = dev_priv->ips.cur_delay; |
9270388e | 670 | |
7648fa99 | 671 | I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG); |
b5b72e89 MG |
672 | busy_up = I915_READ(RCPREVBSYTUPAVG); |
673 | busy_down = I915_READ(RCPREVBSYTDNAVG); | |
f97108d1 JB |
674 | max_avg = I915_READ(RCBMAXAVG); |
675 | min_avg = I915_READ(RCBMINAVG); | |
676 | ||
677 | /* Handle RCS change request from hw */ | |
b5b72e89 | 678 | if (busy_up > max_avg) { |
20e4d407 DV |
679 | if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay) |
680 | new_delay = dev_priv->ips.cur_delay - 1; | |
681 | if (new_delay < dev_priv->ips.max_delay) | |
682 | new_delay = dev_priv->ips.max_delay; | |
b5b72e89 | 683 | } else if (busy_down < min_avg) { |
20e4d407 DV |
684 | if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay) |
685 | new_delay = dev_priv->ips.cur_delay + 1; | |
686 | if (new_delay > dev_priv->ips.min_delay) | |
687 | new_delay = dev_priv->ips.min_delay; | |
f97108d1 JB |
688 | } |
689 | ||
7648fa99 | 690 | if (ironlake_set_drps(dev, new_delay)) |
20e4d407 | 691 | dev_priv->ips.cur_delay = new_delay; |
f97108d1 | 692 | |
d0ecd7e2 | 693 | spin_unlock(&mchdev_lock); |
9270388e | 694 | |
f97108d1 JB |
695 | return; |
696 | } | |
697 | ||
549f7365 CW |
698 | static void notify_ring(struct drm_device *dev, |
699 | struct intel_ring_buffer *ring) | |
700 | { | |
475553de CW |
701 | if (ring->obj == NULL) |
702 | return; | |
703 | ||
b2eadbc8 | 704 | trace_i915_gem_request_complete(ring, ring->get_seqno(ring, false)); |
9862e600 | 705 | |
549f7365 | 706 | wake_up_all(&ring->irq_queue); |
10cd45b6 | 707 | i915_queue_hangcheck(dev); |
549f7365 CW |
708 | } |
709 | ||
4912d041 | 710 | static void gen6_pm_rps_work(struct work_struct *work) |
3b8d8d91 | 711 | { |
4912d041 | 712 | drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t, |
c6a828d3 | 713 | rps.work); |
4912d041 | 714 | u32 pm_iir, pm_imr; |
7b9e0ae6 | 715 | u8 new_delay; |
4912d041 | 716 | |
59cdb63d | 717 | spin_lock_irq(&dev_priv->irq_lock); |
c6a828d3 DV |
718 | pm_iir = dev_priv->rps.pm_iir; |
719 | dev_priv->rps.pm_iir = 0; | |
4912d041 | 720 | pm_imr = I915_READ(GEN6_PMIMR); |
4848405c BW |
721 | /* Make sure not to corrupt PMIMR state used by ringbuffer code */ |
722 | I915_WRITE(GEN6_PMIMR, pm_imr & ~GEN6_PM_RPS_EVENTS); | |
59cdb63d | 723 | spin_unlock_irq(&dev_priv->irq_lock); |
3b8d8d91 | 724 | |
4848405c | 725 | if ((pm_iir & GEN6_PM_RPS_EVENTS) == 0) |
3b8d8d91 JB |
726 | return; |
727 | ||
4fc688ce | 728 | mutex_lock(&dev_priv->rps.hw_lock); |
7b9e0ae6 | 729 | |
7425034a | 730 | if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) { |
c6a828d3 | 731 | new_delay = dev_priv->rps.cur_delay + 1; |
7425034a VS |
732 | |
733 | /* | |
734 | * For better performance, jump directly | |
735 | * to RPe if we're below it. | |
736 | */ | |
737 | if (IS_VALLEYVIEW(dev_priv->dev) && | |
738 | dev_priv->rps.cur_delay < dev_priv->rps.rpe_delay) | |
739 | new_delay = dev_priv->rps.rpe_delay; | |
740 | } else | |
c6a828d3 | 741 | new_delay = dev_priv->rps.cur_delay - 1; |
3b8d8d91 | 742 | |
79249636 BW |
743 | /* sysfs frequency interfaces may have snuck in while servicing the |
744 | * interrupt | |
745 | */ | |
d8289c9e VS |
746 | if (new_delay >= dev_priv->rps.min_delay && |
747 | new_delay <= dev_priv->rps.max_delay) { | |
0a073b84 JB |
748 | if (IS_VALLEYVIEW(dev_priv->dev)) |
749 | valleyview_set_rps(dev_priv->dev, new_delay); | |
750 | else | |
751 | gen6_set_rps(dev_priv->dev, new_delay); | |
79249636 | 752 | } |
3b8d8d91 | 753 | |
52ceb908 JB |
754 | if (IS_VALLEYVIEW(dev_priv->dev)) { |
755 | /* | |
756 | * On VLV, when we enter RC6 we may not be at the minimum | |
757 | * voltage level, so arm a timer to check. It should only | |
758 | * fire when there's activity or once after we've entered | |
759 | * RC6, and then won't be re-armed until the next RPS interrupt. | |
760 | */ | |
761 | mod_delayed_work(dev_priv->wq, &dev_priv->rps.vlv_work, | |
762 | msecs_to_jiffies(100)); | |
763 | } | |
764 | ||
4fc688ce | 765 | mutex_unlock(&dev_priv->rps.hw_lock); |
3b8d8d91 JB |
766 | } |
767 | ||
e3689190 BW |
768 | |
769 | /** | |
770 | * ivybridge_parity_work - Workqueue called when a parity error interrupt | |
771 | * occurred. | |
772 | * @work: workqueue struct | |
773 | * | |
774 | * Doesn't actually do anything except notify userspace. As a consequence of | |
775 | * this event, userspace should try to remap the bad rows since statistically | |
776 | * it is likely the same row is more likely to go bad again. | |
777 | */ | |
778 | static void ivybridge_parity_work(struct work_struct *work) | |
779 | { | |
780 | drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t, | |
a4da4fa4 | 781 | l3_parity.error_work); |
e3689190 BW |
782 | u32 error_status, row, bank, subbank; |
783 | char *parity_event[5]; | |
784 | uint32_t misccpctl; | |
785 | unsigned long flags; | |
786 | ||
787 | /* We must turn off DOP level clock gating to access the L3 registers. | |
788 | * In order to prevent a get/put style interface, acquire struct mutex | |
789 | * any time we access those registers. | |
790 | */ | |
791 | mutex_lock(&dev_priv->dev->struct_mutex); | |
792 | ||
793 | misccpctl = I915_READ(GEN7_MISCCPCTL); | |
794 | I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE); | |
795 | POSTING_READ(GEN7_MISCCPCTL); | |
796 | ||
797 | error_status = I915_READ(GEN7_L3CDERRST1); | |
798 | row = GEN7_PARITY_ERROR_ROW(error_status); | |
799 | bank = GEN7_PARITY_ERROR_BANK(error_status); | |
800 | subbank = GEN7_PARITY_ERROR_SUBBANK(error_status); | |
801 | ||
802 | I915_WRITE(GEN7_L3CDERRST1, GEN7_PARITY_ERROR_VALID | | |
803 | GEN7_L3CDERRST1_ENABLE); | |
804 | POSTING_READ(GEN7_L3CDERRST1); | |
805 | ||
806 | I915_WRITE(GEN7_MISCCPCTL, misccpctl); | |
807 | ||
808 | spin_lock_irqsave(&dev_priv->irq_lock, flags); | |
cc609d5d | 809 | dev_priv->gt_irq_mask &= ~GT_RENDER_L3_PARITY_ERROR_INTERRUPT; |
e3689190 BW |
810 | I915_WRITE(GTIMR, dev_priv->gt_irq_mask); |
811 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); | |
812 | ||
813 | mutex_unlock(&dev_priv->dev->struct_mutex); | |
814 | ||
cce723ed | 815 | parity_event[0] = I915_L3_PARITY_UEVENT "=1"; |
e3689190 BW |
816 | parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row); |
817 | parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank); | |
818 | parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank); | |
819 | parity_event[4] = NULL; | |
820 | ||
821 | kobject_uevent_env(&dev_priv->dev->primary->kdev.kobj, | |
822 | KOBJ_CHANGE, parity_event); | |
823 | ||
824 | DRM_DEBUG("Parity error: Row = %d, Bank = %d, Sub bank = %d.\n", | |
825 | row, bank, subbank); | |
826 | ||
827 | kfree(parity_event[3]); | |
828 | kfree(parity_event[2]); | |
829 | kfree(parity_event[1]); | |
830 | } | |
831 | ||
d0ecd7e2 | 832 | static void ivybridge_parity_error_irq_handler(struct drm_device *dev) |
e3689190 BW |
833 | { |
834 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; | |
e3689190 | 835 | |
e1ef7cc2 | 836 | if (!HAS_L3_GPU_CACHE(dev)) |
e3689190 BW |
837 | return; |
838 | ||
d0ecd7e2 | 839 | spin_lock(&dev_priv->irq_lock); |
cc609d5d | 840 | dev_priv->gt_irq_mask |= GT_RENDER_L3_PARITY_ERROR_INTERRUPT; |
e3689190 | 841 | I915_WRITE(GTIMR, dev_priv->gt_irq_mask); |
d0ecd7e2 | 842 | spin_unlock(&dev_priv->irq_lock); |
e3689190 | 843 | |
a4da4fa4 | 844 | queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work); |
e3689190 BW |
845 | } |
846 | ||
f1af8fc1 PZ |
847 | static void ilk_gt_irq_handler(struct drm_device *dev, |
848 | struct drm_i915_private *dev_priv, | |
849 | u32 gt_iir) | |
850 | { | |
851 | if (gt_iir & | |
852 | (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT)) | |
853 | notify_ring(dev, &dev_priv->ring[RCS]); | |
854 | if (gt_iir & ILK_BSD_USER_INTERRUPT) | |
855 | notify_ring(dev, &dev_priv->ring[VCS]); | |
856 | } | |
857 | ||
e7b4c6b1 DV |
858 | static void snb_gt_irq_handler(struct drm_device *dev, |
859 | struct drm_i915_private *dev_priv, | |
860 | u32 gt_iir) | |
861 | { | |
862 | ||
cc609d5d BW |
863 | if (gt_iir & |
864 | (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT)) | |
e7b4c6b1 | 865 | notify_ring(dev, &dev_priv->ring[RCS]); |
cc609d5d | 866 | if (gt_iir & GT_BSD_USER_INTERRUPT) |
e7b4c6b1 | 867 | notify_ring(dev, &dev_priv->ring[VCS]); |
cc609d5d | 868 | if (gt_iir & GT_BLT_USER_INTERRUPT) |
e7b4c6b1 DV |
869 | notify_ring(dev, &dev_priv->ring[BCS]); |
870 | ||
cc609d5d BW |
871 | if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT | |
872 | GT_BSD_CS_ERROR_INTERRUPT | | |
873 | GT_RENDER_CS_MASTER_ERROR_INTERRUPT)) { | |
e7b4c6b1 DV |
874 | DRM_ERROR("GT error interrupt 0x%08x\n", gt_iir); |
875 | i915_handle_error(dev, false); | |
876 | } | |
e3689190 | 877 | |
cc609d5d | 878 | if (gt_iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT) |
d0ecd7e2 | 879 | ivybridge_parity_error_irq_handler(dev); |
e7b4c6b1 DV |
880 | } |
881 | ||
baf02a1f | 882 | /* Legacy way of handling PM interrupts */ |
d0ecd7e2 DV |
883 | static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, |
884 | u32 pm_iir) | |
fc6826d1 | 885 | { |
fc6826d1 CW |
886 | /* |
887 | * IIR bits should never already be set because IMR should | |
888 | * prevent an interrupt from being shown in IIR. The warning | |
889 | * displays a case where we've unsafely cleared | |
c6a828d3 | 890 | * dev_priv->rps.pm_iir. Although missing an interrupt of the same |
fc6826d1 CW |
891 | * type is not a problem, it displays a problem in the logic. |
892 | * | |
c6a828d3 | 893 | * The mask bit in IMR is cleared by dev_priv->rps.work. |
fc6826d1 CW |
894 | */ |
895 | ||
59cdb63d | 896 | spin_lock(&dev_priv->irq_lock); |
c6a828d3 DV |
897 | dev_priv->rps.pm_iir |= pm_iir; |
898 | I915_WRITE(GEN6_PMIMR, dev_priv->rps.pm_iir); | |
fc6826d1 | 899 | POSTING_READ(GEN6_PMIMR); |
59cdb63d | 900 | spin_unlock(&dev_priv->irq_lock); |
fc6826d1 | 901 | |
c6a828d3 | 902 | queue_work(dev_priv->wq, &dev_priv->rps.work); |
fc6826d1 CW |
903 | } |
904 | ||
b543fb04 EE |
905 | #define HPD_STORM_DETECT_PERIOD 1000 |
906 | #define HPD_STORM_THRESHOLD 5 | |
907 | ||
10a504de | 908 | static inline void intel_hpd_irq_handler(struct drm_device *dev, |
22062dba DV |
909 | u32 hotplug_trigger, |
910 | const u32 *hpd) | |
b543fb04 EE |
911 | { |
912 | drm_i915_private_t *dev_priv = dev->dev_private; | |
b543fb04 | 913 | int i; |
10a504de | 914 | bool storm_detected = false; |
b543fb04 | 915 | |
91d131d2 DV |
916 | if (!hotplug_trigger) |
917 | return; | |
918 | ||
b5ea2d56 | 919 | spin_lock(&dev_priv->irq_lock); |
b543fb04 | 920 | for (i = 1; i < HPD_NUM_PINS; i++) { |
821450c6 | 921 | |
b543fb04 EE |
922 | if (!(hpd[i] & hotplug_trigger) || |
923 | dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED) | |
924 | continue; | |
925 | ||
bc5ead8c | 926 | dev_priv->hpd_event_bits |= (1 << i); |
b543fb04 EE |
927 | if (!time_in_range(jiffies, dev_priv->hpd_stats[i].hpd_last_jiffies, |
928 | dev_priv->hpd_stats[i].hpd_last_jiffies | |
929 | + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD))) { | |
930 | dev_priv->hpd_stats[i].hpd_last_jiffies = jiffies; | |
931 | dev_priv->hpd_stats[i].hpd_cnt = 0; | |
932 | } else if (dev_priv->hpd_stats[i].hpd_cnt > HPD_STORM_THRESHOLD) { | |
933 | dev_priv->hpd_stats[i].hpd_mark = HPD_MARK_DISABLED; | |
142e2398 | 934 | dev_priv->hpd_event_bits &= ~(1 << i); |
b543fb04 | 935 | DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", i); |
10a504de | 936 | storm_detected = true; |
b543fb04 EE |
937 | } else { |
938 | dev_priv->hpd_stats[i].hpd_cnt++; | |
939 | } | |
940 | } | |
941 | ||
10a504de DV |
942 | if (storm_detected) |
943 | dev_priv->display.hpd_irq_setup(dev); | |
b5ea2d56 | 944 | spin_unlock(&dev_priv->irq_lock); |
5876fa0d DV |
945 | |
946 | queue_work(dev_priv->wq, | |
947 | &dev_priv->hotplug_work); | |
b543fb04 EE |
948 | } |
949 | ||
515ac2bb DV |
950 | static void gmbus_irq_handler(struct drm_device *dev) |
951 | { | |
28c70f16 DV |
952 | struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private; |
953 | ||
28c70f16 | 954 | wake_up_all(&dev_priv->gmbus_wait_queue); |
515ac2bb DV |
955 | } |
956 | ||
ce99c256 DV |
957 | static void dp_aux_irq_handler(struct drm_device *dev) |
958 | { | |
9ee32fea DV |
959 | struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private; |
960 | ||
9ee32fea | 961 | wake_up_all(&dev_priv->gmbus_wait_queue); |
ce99c256 DV |
962 | } |
963 | ||
d0ecd7e2 | 964 | /* Unlike gen6_rps_irq_handler() from which this function is originally derived, |
baf02a1f BW |
965 | * we must be able to deal with other PM interrupts. This is complicated because |
966 | * of the way in which we use the masks to defer the RPS work (which for | |
967 | * posterity is necessary because of forcewake). | |
968 | */ | |
969 | static void hsw_pm_irq_handler(struct drm_i915_private *dev_priv, | |
970 | u32 pm_iir) | |
971 | { | |
41a05a3a | 972 | if (pm_iir & GEN6_PM_RPS_EVENTS) { |
59cdb63d | 973 | spin_lock(&dev_priv->irq_lock); |
41a05a3a | 974 | dev_priv->rps.pm_iir |= pm_iir & GEN6_PM_RPS_EVENTS; |
baf02a1f BW |
975 | I915_WRITE(GEN6_PMIMR, dev_priv->rps.pm_iir); |
976 | /* never want to mask useful interrupts. (also posting read) */ | |
4848405c | 977 | WARN_ON(I915_READ_NOTRACE(GEN6_PMIMR) & ~GEN6_PM_RPS_EVENTS); |
59cdb63d | 978 | spin_unlock(&dev_priv->irq_lock); |
2adbee62 DV |
979 | |
980 | queue_work(dev_priv->wq, &dev_priv->rps.work); | |
baf02a1f | 981 | } |
baf02a1f | 982 | |
41a05a3a DV |
983 | if (pm_iir & PM_VEBOX_USER_INTERRUPT) |
984 | notify_ring(dev_priv->dev, &dev_priv->ring[VECS]); | |
12638c57 | 985 | |
41a05a3a DV |
986 | if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) { |
987 | DRM_ERROR("VEBOX CS error interrupt 0x%08x\n", pm_iir); | |
988 | i915_handle_error(dev_priv->dev, false); | |
12638c57 | 989 | } |
baf02a1f BW |
990 | } |
991 | ||
ff1f525e | 992 | static irqreturn_t valleyview_irq_handler(int irq, void *arg) |
7e231dbe JB |
993 | { |
994 | struct drm_device *dev = (struct drm_device *) arg; | |
995 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; | |
996 | u32 iir, gt_iir, pm_iir; | |
997 | irqreturn_t ret = IRQ_NONE; | |
998 | unsigned long irqflags; | |
999 | int pipe; | |
1000 | u32 pipe_stats[I915_MAX_PIPES]; | |
7e231dbe JB |
1001 | |
1002 | atomic_inc(&dev_priv->irq_received); | |
1003 | ||
7e231dbe JB |
1004 | while (true) { |
1005 | iir = I915_READ(VLV_IIR); | |
1006 | gt_iir = I915_READ(GTIIR); | |
1007 | pm_iir = I915_READ(GEN6_PMIIR); | |
1008 | ||
1009 | if (gt_iir == 0 && pm_iir == 0 && iir == 0) | |
1010 | goto out; | |
1011 | ||
1012 | ret = IRQ_HANDLED; | |
1013 | ||
e7b4c6b1 | 1014 | snb_gt_irq_handler(dev, dev_priv, gt_iir); |
7e231dbe JB |
1015 | |
1016 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); | |
1017 | for_each_pipe(pipe) { | |
1018 | int reg = PIPESTAT(pipe); | |
1019 | pipe_stats[pipe] = I915_READ(reg); | |
1020 | ||
1021 | /* | |
1022 | * Clear the PIPE*STAT regs before the IIR | |
1023 | */ | |
1024 | if (pipe_stats[pipe] & 0x8000ffff) { | |
1025 | if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) | |
1026 | DRM_DEBUG_DRIVER("pipe %c underrun\n", | |
1027 | pipe_name(pipe)); | |
1028 | I915_WRITE(reg, pipe_stats[pipe]); | |
1029 | } | |
1030 | } | |
1031 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); | |
1032 | ||
31acc7f5 JB |
1033 | for_each_pipe(pipe) { |
1034 | if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS) | |
1035 | drm_handle_vblank(dev, pipe); | |
1036 | ||
1037 | if (pipe_stats[pipe] & PLANE_FLIPDONE_INT_STATUS_VLV) { | |
1038 | intel_prepare_page_flip(dev, pipe); | |
1039 | intel_finish_page_flip(dev, pipe); | |
1040 | } | |
1041 | } | |
1042 | ||
7e231dbe JB |
1043 | /* Consume port. Then clear IIR or we'll miss events */ |
1044 | if (iir & I915_DISPLAY_PORT_INTERRUPT) { | |
1045 | u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT); | |
b543fb04 | 1046 | u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915; |
7e231dbe JB |
1047 | |
1048 | DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n", | |
1049 | hotplug_status); | |
91d131d2 DV |
1050 | |
1051 | intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915); | |
1052 | ||
7e231dbe JB |
1053 | I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status); |
1054 | I915_READ(PORT_HOTPLUG_STAT); | |
1055 | } | |
1056 | ||
515ac2bb DV |
1057 | if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS) |
1058 | gmbus_irq_handler(dev); | |
7e231dbe | 1059 | |
4848405c | 1060 | if (pm_iir & GEN6_PM_RPS_EVENTS) |
d0ecd7e2 | 1061 | gen6_rps_irq_handler(dev_priv, pm_iir); |
7e231dbe JB |
1062 | |
1063 | I915_WRITE(GTIIR, gt_iir); | |
1064 | I915_WRITE(GEN6_PMIIR, pm_iir); | |
1065 | I915_WRITE(VLV_IIR, iir); | |
1066 | } | |
1067 | ||
1068 | out: | |
1069 | return ret; | |
1070 | } | |
1071 | ||
23e81d69 | 1072 | static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir) |
776ad806 JB |
1073 | { |
1074 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; | |
9db4a9c7 | 1075 | int pipe; |
b543fb04 | 1076 | u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK; |
776ad806 | 1077 | |
91d131d2 DV |
1078 | intel_hpd_irq_handler(dev, hotplug_trigger, hpd_ibx); |
1079 | ||
cfc33bf7 VS |
1080 | if (pch_iir & SDE_AUDIO_POWER_MASK) { |
1081 | int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >> | |
1082 | SDE_AUDIO_POWER_SHIFT); | |
776ad806 | 1083 | DRM_DEBUG_DRIVER("PCH audio power change on port %d\n", |
cfc33bf7 VS |
1084 | port_name(port)); |
1085 | } | |
776ad806 | 1086 | |
ce99c256 DV |
1087 | if (pch_iir & SDE_AUX_MASK) |
1088 | dp_aux_irq_handler(dev); | |
1089 | ||
776ad806 | 1090 | if (pch_iir & SDE_GMBUS) |
515ac2bb | 1091 | gmbus_irq_handler(dev); |
776ad806 JB |
1092 | |
1093 | if (pch_iir & SDE_AUDIO_HDCP_MASK) | |
1094 | DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n"); | |
1095 | ||
1096 | if (pch_iir & SDE_AUDIO_TRANS_MASK) | |
1097 | DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n"); | |
1098 | ||
1099 | if (pch_iir & SDE_POISON) | |
1100 | DRM_ERROR("PCH poison interrupt\n"); | |
1101 | ||
9db4a9c7 JB |
1102 | if (pch_iir & SDE_FDI_MASK) |
1103 | for_each_pipe(pipe) | |
1104 | DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n", | |
1105 | pipe_name(pipe), | |
1106 | I915_READ(FDI_RX_IIR(pipe))); | |
776ad806 JB |
1107 | |
1108 | if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE)) | |
1109 | DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n"); | |
1110 | ||
1111 | if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR)) | |
1112 | DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n"); | |
1113 | ||
776ad806 | 1114 | if (pch_iir & SDE_TRANSA_FIFO_UNDER) |
8664281b PZ |
1115 | if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, |
1116 | false)) | |
1117 | DRM_DEBUG_DRIVER("PCH transcoder A FIFO underrun\n"); | |
1118 | ||
1119 | if (pch_iir & SDE_TRANSB_FIFO_UNDER) | |
1120 | if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B, | |
1121 | false)) | |
1122 | DRM_DEBUG_DRIVER("PCH transcoder B FIFO underrun\n"); | |
1123 | } | |
1124 | ||
1125 | static void ivb_err_int_handler(struct drm_device *dev) | |
1126 | { | |
1127 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1128 | u32 err_int = I915_READ(GEN7_ERR_INT); | |
1129 | ||
de032bf4 PZ |
1130 | if (err_int & ERR_INT_POISON) |
1131 | DRM_ERROR("Poison interrupt\n"); | |
1132 | ||
8664281b PZ |
1133 | if (err_int & ERR_INT_FIFO_UNDERRUN_A) |
1134 | if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_A, false)) | |
1135 | DRM_DEBUG_DRIVER("Pipe A FIFO underrun\n"); | |
1136 | ||
1137 | if (err_int & ERR_INT_FIFO_UNDERRUN_B) | |
1138 | if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_B, false)) | |
1139 | DRM_DEBUG_DRIVER("Pipe B FIFO underrun\n"); | |
1140 | ||
1141 | if (err_int & ERR_INT_FIFO_UNDERRUN_C) | |
1142 | if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_C, false)) | |
1143 | DRM_DEBUG_DRIVER("Pipe C FIFO underrun\n"); | |
1144 | ||
1145 | I915_WRITE(GEN7_ERR_INT, err_int); | |
1146 | } | |
1147 | ||
1148 | static void cpt_serr_int_handler(struct drm_device *dev) | |
1149 | { | |
1150 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1151 | u32 serr_int = I915_READ(SERR_INT); | |
1152 | ||
de032bf4 PZ |
1153 | if (serr_int & SERR_INT_POISON) |
1154 | DRM_ERROR("PCH poison interrupt\n"); | |
1155 | ||
8664281b PZ |
1156 | if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN) |
1157 | if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, | |
1158 | false)) | |
1159 | DRM_DEBUG_DRIVER("PCH transcoder A FIFO underrun\n"); | |
1160 | ||
1161 | if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN) | |
1162 | if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B, | |
1163 | false)) | |
1164 | DRM_DEBUG_DRIVER("PCH transcoder B FIFO underrun\n"); | |
1165 | ||
1166 | if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN) | |
1167 | if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_C, | |
1168 | false)) | |
1169 | DRM_DEBUG_DRIVER("PCH transcoder C FIFO underrun\n"); | |
1170 | ||
1171 | I915_WRITE(SERR_INT, serr_int); | |
776ad806 JB |
1172 | } |
1173 | ||
23e81d69 AJ |
1174 | static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir) |
1175 | { | |
1176 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; | |
1177 | int pipe; | |
b543fb04 | 1178 | u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT; |
23e81d69 | 1179 | |
91d131d2 DV |
1180 | intel_hpd_irq_handler(dev, hotplug_trigger, hpd_cpt); |
1181 | ||
cfc33bf7 VS |
1182 | if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) { |
1183 | int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >> | |
1184 | SDE_AUDIO_POWER_SHIFT_CPT); | |
1185 | DRM_DEBUG_DRIVER("PCH audio power change on port %c\n", | |
1186 | port_name(port)); | |
1187 | } | |
23e81d69 AJ |
1188 | |
1189 | if (pch_iir & SDE_AUX_MASK_CPT) | |
ce99c256 | 1190 | dp_aux_irq_handler(dev); |
23e81d69 AJ |
1191 | |
1192 | if (pch_iir & SDE_GMBUS_CPT) | |
515ac2bb | 1193 | gmbus_irq_handler(dev); |
23e81d69 AJ |
1194 | |
1195 | if (pch_iir & SDE_AUDIO_CP_REQ_CPT) | |
1196 | DRM_DEBUG_DRIVER("Audio CP request interrupt\n"); | |
1197 | ||
1198 | if (pch_iir & SDE_AUDIO_CP_CHG_CPT) | |
1199 | DRM_DEBUG_DRIVER("Audio CP change interrupt\n"); | |
1200 | ||
1201 | if (pch_iir & SDE_FDI_MASK_CPT) | |
1202 | for_each_pipe(pipe) | |
1203 | DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n", | |
1204 | pipe_name(pipe), | |
1205 | I915_READ(FDI_RX_IIR(pipe))); | |
8664281b PZ |
1206 | |
1207 | if (pch_iir & SDE_ERROR_CPT) | |
1208 | cpt_serr_int_handler(dev); | |
23e81d69 AJ |
1209 | } |
1210 | ||
c008bc6e PZ |
1211 | static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir) |
1212 | { | |
1213 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1214 | ||
1215 | if (de_iir & DE_AUX_CHANNEL_A) | |
1216 | dp_aux_irq_handler(dev); | |
1217 | ||
1218 | if (de_iir & DE_GSE) | |
1219 | intel_opregion_asle_intr(dev); | |
1220 | ||
1221 | if (de_iir & DE_PIPEA_VBLANK) | |
1222 | drm_handle_vblank(dev, 0); | |
1223 | ||
1224 | if (de_iir & DE_PIPEB_VBLANK) | |
1225 | drm_handle_vblank(dev, 1); | |
1226 | ||
1227 | if (de_iir & DE_POISON) | |
1228 | DRM_ERROR("Poison interrupt\n"); | |
1229 | ||
1230 | if (de_iir & DE_PIPEA_FIFO_UNDERRUN) | |
1231 | if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_A, false)) | |
1232 | DRM_DEBUG_DRIVER("Pipe A FIFO underrun\n"); | |
1233 | ||
1234 | if (de_iir & DE_PIPEB_FIFO_UNDERRUN) | |
1235 | if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_B, false)) | |
1236 | DRM_DEBUG_DRIVER("Pipe B FIFO underrun\n"); | |
1237 | ||
1238 | if (de_iir & DE_PLANEA_FLIP_DONE) { | |
1239 | intel_prepare_page_flip(dev, 0); | |
1240 | intel_finish_page_flip_plane(dev, 0); | |
1241 | } | |
1242 | ||
1243 | if (de_iir & DE_PLANEB_FLIP_DONE) { | |
1244 | intel_prepare_page_flip(dev, 1); | |
1245 | intel_finish_page_flip_plane(dev, 1); | |
1246 | } | |
1247 | ||
1248 | /* check event from PCH */ | |
1249 | if (de_iir & DE_PCH_EVENT) { | |
1250 | u32 pch_iir = I915_READ(SDEIIR); | |
1251 | ||
1252 | if (HAS_PCH_CPT(dev)) | |
1253 | cpt_irq_handler(dev, pch_iir); | |
1254 | else | |
1255 | ibx_irq_handler(dev, pch_iir); | |
1256 | ||
1257 | /* should clear PCH hotplug event before clear CPU irq */ | |
1258 | I915_WRITE(SDEIIR, pch_iir); | |
1259 | } | |
1260 | ||
1261 | if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT) | |
1262 | ironlake_rps_change_irq_handler(dev); | |
1263 | } | |
1264 | ||
9719fb98 PZ |
1265 | static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir) |
1266 | { | |
1267 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1268 | int i; | |
1269 | ||
1270 | if (de_iir & DE_ERR_INT_IVB) | |
1271 | ivb_err_int_handler(dev); | |
1272 | ||
1273 | if (de_iir & DE_AUX_CHANNEL_A_IVB) | |
1274 | dp_aux_irq_handler(dev); | |
1275 | ||
1276 | if (de_iir & DE_GSE_IVB) | |
1277 | intel_opregion_asle_intr(dev); | |
1278 | ||
1279 | for (i = 0; i < 3; i++) { | |
1280 | if (de_iir & (DE_PIPEA_VBLANK_IVB << (5 * i))) | |
1281 | drm_handle_vblank(dev, i); | |
1282 | if (de_iir & (DE_PLANEA_FLIP_DONE_IVB << (5 * i))) { | |
1283 | intel_prepare_page_flip(dev, i); | |
1284 | intel_finish_page_flip_plane(dev, i); | |
1285 | } | |
1286 | } | |
1287 | ||
1288 | /* check event from PCH */ | |
1289 | if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) { | |
1290 | u32 pch_iir = I915_READ(SDEIIR); | |
1291 | ||
1292 | cpt_irq_handler(dev, pch_iir); | |
1293 | ||
1294 | /* clear PCH hotplug event before clear CPU irq */ | |
1295 | I915_WRITE(SDEIIR, pch_iir); | |
1296 | } | |
1297 | } | |
1298 | ||
f1af8fc1 | 1299 | static irqreturn_t ironlake_irq_handler(int irq, void *arg) |
b1f14ad0 JB |
1300 | { |
1301 | struct drm_device *dev = (struct drm_device *) arg; | |
1302 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; | |
f1af8fc1 | 1303 | u32 de_iir, gt_iir, de_ier, sde_ier = 0; |
0e43406b | 1304 | irqreturn_t ret = IRQ_NONE; |
b1f14ad0 JB |
1305 | |
1306 | atomic_inc(&dev_priv->irq_received); | |
1307 | ||
8664281b PZ |
1308 | /* We get interrupts on unclaimed registers, so check for this before we |
1309 | * do any I915_{READ,WRITE}. */ | |
907b28c5 | 1310 | intel_uncore_check_errors(dev); |
8664281b | 1311 | |
b1f14ad0 JB |
1312 | /* disable master interrupt before clearing iir */ |
1313 | de_ier = I915_READ(DEIER); | |
1314 | I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL); | |
23a78516 | 1315 | POSTING_READ(DEIER); |
b1f14ad0 | 1316 | |
44498aea PZ |
1317 | /* Disable south interrupts. We'll only write to SDEIIR once, so further |
1318 | * interrupts will will be stored on its back queue, and then we'll be | |
1319 | * able to process them after we restore SDEIER (as soon as we restore | |
1320 | * it, we'll get an interrupt if SDEIIR still has something to process | |
1321 | * due to its back queue). */ | |
ab5c608b BW |
1322 | if (!HAS_PCH_NOP(dev)) { |
1323 | sde_ier = I915_READ(SDEIER); | |
1324 | I915_WRITE(SDEIER, 0); | |
1325 | POSTING_READ(SDEIER); | |
1326 | } | |
44498aea | 1327 | |
8664281b PZ |
1328 | /* On Haswell, also mask ERR_INT because we don't want to risk |
1329 | * generating "unclaimed register" interrupts from inside the interrupt | |
1330 | * handler. */ | |
4bc9d430 DV |
1331 | if (IS_HASWELL(dev)) { |
1332 | spin_lock(&dev_priv->irq_lock); | |
8664281b | 1333 | ironlake_disable_display_irq(dev_priv, DE_ERR_INT_IVB); |
4bc9d430 DV |
1334 | spin_unlock(&dev_priv->irq_lock); |
1335 | } | |
8664281b | 1336 | |
b1f14ad0 | 1337 | gt_iir = I915_READ(GTIIR); |
0e43406b | 1338 | if (gt_iir) { |
d8fc8a47 | 1339 | if (INTEL_INFO(dev)->gen >= 6) |
f1af8fc1 | 1340 | snb_gt_irq_handler(dev, dev_priv, gt_iir); |
d8fc8a47 PZ |
1341 | else |
1342 | ilk_gt_irq_handler(dev, dev_priv, gt_iir); | |
0e43406b CW |
1343 | I915_WRITE(GTIIR, gt_iir); |
1344 | ret = IRQ_HANDLED; | |
b1f14ad0 JB |
1345 | } |
1346 | ||
0e43406b CW |
1347 | de_iir = I915_READ(DEIIR); |
1348 | if (de_iir) { | |
f1af8fc1 PZ |
1349 | if (INTEL_INFO(dev)->gen >= 7) |
1350 | ivb_display_irq_handler(dev, de_iir); | |
1351 | else | |
1352 | ilk_display_irq_handler(dev, de_iir); | |
0e43406b CW |
1353 | I915_WRITE(DEIIR, de_iir); |
1354 | ret = IRQ_HANDLED; | |
b1f14ad0 JB |
1355 | } |
1356 | ||
f1af8fc1 PZ |
1357 | if (INTEL_INFO(dev)->gen >= 6) { |
1358 | u32 pm_iir = I915_READ(GEN6_PMIIR); | |
1359 | if (pm_iir) { | |
1360 | if (IS_HASWELL(dev)) | |
1361 | hsw_pm_irq_handler(dev_priv, pm_iir); | |
1362 | else if (pm_iir & GEN6_PM_RPS_EVENTS) | |
1363 | gen6_rps_irq_handler(dev_priv, pm_iir); | |
1364 | I915_WRITE(GEN6_PMIIR, pm_iir); | |
1365 | ret = IRQ_HANDLED; | |
1366 | } | |
0e43406b | 1367 | } |
b1f14ad0 | 1368 | |
4bc9d430 DV |
1369 | if (IS_HASWELL(dev)) { |
1370 | spin_lock(&dev_priv->irq_lock); | |
1371 | if (ivb_can_enable_err_int(dev)) | |
1372 | ironlake_enable_display_irq(dev_priv, DE_ERR_INT_IVB); | |
1373 | spin_unlock(&dev_priv->irq_lock); | |
1374 | } | |
8664281b | 1375 | |
b1f14ad0 JB |
1376 | I915_WRITE(DEIER, de_ier); |
1377 | POSTING_READ(DEIER); | |
ab5c608b BW |
1378 | if (!HAS_PCH_NOP(dev)) { |
1379 | I915_WRITE(SDEIER, sde_ier); | |
1380 | POSTING_READ(SDEIER); | |
1381 | } | |
b1f14ad0 JB |
1382 | |
1383 | return ret; | |
1384 | } | |
1385 | ||
8a905236 JB |
1386 | /** |
1387 | * i915_error_work_func - do process context error handling work | |
1388 | * @work: work struct | |
1389 | * | |
1390 | * Fire an error uevent so userspace can see that a hang or error | |
1391 | * was detected. | |
1392 | */ | |
1393 | static void i915_error_work_func(struct work_struct *work) | |
1394 | { | |
1f83fee0 DV |
1395 | struct i915_gpu_error *error = container_of(work, struct i915_gpu_error, |
1396 | work); | |
1397 | drm_i915_private_t *dev_priv = container_of(error, drm_i915_private_t, | |
1398 | gpu_error); | |
8a905236 | 1399 | struct drm_device *dev = dev_priv->dev; |
f69061be | 1400 | struct intel_ring_buffer *ring; |
cce723ed BW |
1401 | char *error_event[] = { I915_ERROR_UEVENT "=1", NULL }; |
1402 | char *reset_event[] = { I915_RESET_UEVENT "=1", NULL }; | |
1403 | char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL }; | |
f69061be | 1404 | int i, ret; |
8a905236 | 1405 | |
f316a42c BG |
1406 | kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, error_event); |
1407 | ||
7db0ba24 DV |
1408 | /* |
1409 | * Note that there's only one work item which does gpu resets, so we | |
1410 | * need not worry about concurrent gpu resets potentially incrementing | |
1411 | * error->reset_counter twice. We only need to take care of another | |
1412 | * racing irq/hangcheck declaring the gpu dead for a second time. A | |
1413 | * quick check for that is good enough: schedule_work ensures the | |
1414 | * correct ordering between hang detection and this work item, and since | |
1415 | * the reset in-progress bit is only ever set by code outside of this | |
1416 | * work we don't need to worry about any other races. | |
1417 | */ | |
1418 | if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) { | |
f803aa55 | 1419 | DRM_DEBUG_DRIVER("resetting chip\n"); |
7db0ba24 DV |
1420 | kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, |
1421 | reset_event); | |
1f83fee0 | 1422 | |
f69061be DV |
1423 | ret = i915_reset(dev); |
1424 | ||
1425 | if (ret == 0) { | |
1426 | /* | |
1427 | * After all the gem state is reset, increment the reset | |
1428 | * counter and wake up everyone waiting for the reset to | |
1429 | * complete. | |
1430 | * | |
1431 | * Since unlock operations are a one-sided barrier only, | |
1432 | * we need to insert a barrier here to order any seqno | |
1433 | * updates before | |
1434 | * the counter increment. | |
1435 | */ | |
1436 | smp_mb__before_atomic_inc(); | |
1437 | atomic_inc(&dev_priv->gpu_error.reset_counter); | |
1438 | ||
1439 | kobject_uevent_env(&dev->primary->kdev.kobj, | |
1440 | KOBJ_CHANGE, reset_done_event); | |
1f83fee0 DV |
1441 | } else { |
1442 | atomic_set(&error->reset_counter, I915_WEDGED); | |
f316a42c | 1443 | } |
1f83fee0 | 1444 | |
f69061be DV |
1445 | for_each_ring(ring, dev_priv, i) |
1446 | wake_up_all(&ring->irq_queue); | |
1447 | ||
96a02917 VS |
1448 | intel_display_handle_reset(dev); |
1449 | ||
1f83fee0 | 1450 | wake_up_all(&dev_priv->gpu_error.reset_queue); |
f316a42c | 1451 | } |
8a905236 JB |
1452 | } |
1453 | ||
35aed2e6 | 1454 | static void i915_report_and_clear_eir(struct drm_device *dev) |
8a905236 JB |
1455 | { |
1456 | struct drm_i915_private *dev_priv = dev->dev_private; | |
bd9854f9 | 1457 | uint32_t instdone[I915_NUM_INSTDONE_REG]; |
8a905236 | 1458 | u32 eir = I915_READ(EIR); |
050ee91f | 1459 | int pipe, i; |
8a905236 | 1460 | |
35aed2e6 CW |
1461 | if (!eir) |
1462 | return; | |
8a905236 | 1463 | |
a70491cc | 1464 | pr_err("render error detected, EIR: 0x%08x\n", eir); |
8a905236 | 1465 | |
bd9854f9 BW |
1466 | i915_get_extra_instdone(dev, instdone); |
1467 | ||
8a905236 JB |
1468 | if (IS_G4X(dev)) { |
1469 | if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) { | |
1470 | u32 ipeir = I915_READ(IPEIR_I965); | |
1471 | ||
a70491cc JP |
1472 | pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965)); |
1473 | pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965)); | |
050ee91f BW |
1474 | for (i = 0; i < ARRAY_SIZE(instdone); i++) |
1475 | pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]); | |
a70491cc | 1476 | pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS)); |
a70491cc | 1477 | pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965)); |
8a905236 | 1478 | I915_WRITE(IPEIR_I965, ipeir); |
3143a2bf | 1479 | POSTING_READ(IPEIR_I965); |
8a905236 JB |
1480 | } |
1481 | if (eir & GM45_ERROR_PAGE_TABLE) { | |
1482 | u32 pgtbl_err = I915_READ(PGTBL_ER); | |
a70491cc JP |
1483 | pr_err("page table error\n"); |
1484 | pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err); | |
8a905236 | 1485 | I915_WRITE(PGTBL_ER, pgtbl_err); |
3143a2bf | 1486 | POSTING_READ(PGTBL_ER); |
8a905236 JB |
1487 | } |
1488 | } | |
1489 | ||
a6c45cf0 | 1490 | if (!IS_GEN2(dev)) { |
8a905236 JB |
1491 | if (eir & I915_ERROR_PAGE_TABLE) { |
1492 | u32 pgtbl_err = I915_READ(PGTBL_ER); | |
a70491cc JP |
1493 | pr_err("page table error\n"); |
1494 | pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err); | |
8a905236 | 1495 | I915_WRITE(PGTBL_ER, pgtbl_err); |
3143a2bf | 1496 | POSTING_READ(PGTBL_ER); |
8a905236 JB |
1497 | } |
1498 | } | |
1499 | ||
1500 | if (eir & I915_ERROR_MEMORY_REFRESH) { | |
a70491cc | 1501 | pr_err("memory refresh error:\n"); |
9db4a9c7 | 1502 | for_each_pipe(pipe) |
a70491cc | 1503 | pr_err("pipe %c stat: 0x%08x\n", |
9db4a9c7 | 1504 | pipe_name(pipe), I915_READ(PIPESTAT(pipe))); |
8a905236 JB |
1505 | /* pipestat has already been acked */ |
1506 | } | |
1507 | if (eir & I915_ERROR_INSTRUCTION) { | |
a70491cc JP |
1508 | pr_err("instruction error\n"); |
1509 | pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM)); | |
050ee91f BW |
1510 | for (i = 0; i < ARRAY_SIZE(instdone); i++) |
1511 | pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]); | |
a6c45cf0 | 1512 | if (INTEL_INFO(dev)->gen < 4) { |
8a905236 JB |
1513 | u32 ipeir = I915_READ(IPEIR); |
1514 | ||
a70491cc JP |
1515 | pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR)); |
1516 | pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR)); | |
a70491cc | 1517 | pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD)); |
8a905236 | 1518 | I915_WRITE(IPEIR, ipeir); |
3143a2bf | 1519 | POSTING_READ(IPEIR); |
8a905236 JB |
1520 | } else { |
1521 | u32 ipeir = I915_READ(IPEIR_I965); | |
1522 | ||
a70491cc JP |
1523 | pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965)); |
1524 | pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965)); | |
a70491cc | 1525 | pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS)); |
a70491cc | 1526 | pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965)); |
8a905236 | 1527 | I915_WRITE(IPEIR_I965, ipeir); |
3143a2bf | 1528 | POSTING_READ(IPEIR_I965); |
8a905236 JB |
1529 | } |
1530 | } | |
1531 | ||
1532 | I915_WRITE(EIR, eir); | |
3143a2bf | 1533 | POSTING_READ(EIR); |
8a905236 JB |
1534 | eir = I915_READ(EIR); |
1535 | if (eir) { | |
1536 | /* | |
1537 | * some errors might have become stuck, | |
1538 | * mask them. | |
1539 | */ | |
1540 | DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir); | |
1541 | I915_WRITE(EMR, I915_READ(EMR) | eir); | |
1542 | I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); | |
1543 | } | |
35aed2e6 CW |
1544 | } |
1545 | ||
1546 | /** | |
1547 | * i915_handle_error - handle an error interrupt | |
1548 | * @dev: drm device | |
1549 | * | |
1550 | * Do some basic checking of regsiter state at error interrupt time and | |
1551 | * dump it to the syslog. Also call i915_capture_error_state() to make | |
1552 | * sure we get a record and make it available in debugfs. Fire a uevent | |
1553 | * so userspace knows something bad happened (should trigger collection | |
1554 | * of a ring dump etc.). | |
1555 | */ | |
527f9e90 | 1556 | void i915_handle_error(struct drm_device *dev, bool wedged) |
35aed2e6 CW |
1557 | { |
1558 | struct drm_i915_private *dev_priv = dev->dev_private; | |
b4519513 CW |
1559 | struct intel_ring_buffer *ring; |
1560 | int i; | |
35aed2e6 CW |
1561 | |
1562 | i915_capture_error_state(dev); | |
1563 | i915_report_and_clear_eir(dev); | |
8a905236 | 1564 | |
ba1234d1 | 1565 | if (wedged) { |
f69061be DV |
1566 | atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG, |
1567 | &dev_priv->gpu_error.reset_counter); | |
ba1234d1 | 1568 | |
11ed50ec | 1569 | /* |
1f83fee0 DV |
1570 | * Wakeup waiting processes so that the reset work item |
1571 | * doesn't deadlock trying to grab various locks. | |
11ed50ec | 1572 | */ |
b4519513 CW |
1573 | for_each_ring(ring, dev_priv, i) |
1574 | wake_up_all(&ring->irq_queue); | |
11ed50ec BG |
1575 | } |
1576 | ||
99584db3 | 1577 | queue_work(dev_priv->wq, &dev_priv->gpu_error.work); |
8a905236 JB |
1578 | } |
1579 | ||
21ad8330 | 1580 | static void __always_unused i915_pageflip_stall_check(struct drm_device *dev, int pipe) |
4e5359cd SF |
1581 | { |
1582 | drm_i915_private_t *dev_priv = dev->dev_private; | |
1583 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; | |
1584 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
05394f39 | 1585 | struct drm_i915_gem_object *obj; |
4e5359cd SF |
1586 | struct intel_unpin_work *work; |
1587 | unsigned long flags; | |
1588 | bool stall_detected; | |
1589 | ||
1590 | /* Ignore early vblank irqs */ | |
1591 | if (intel_crtc == NULL) | |
1592 | return; | |
1593 | ||
1594 | spin_lock_irqsave(&dev->event_lock, flags); | |
1595 | work = intel_crtc->unpin_work; | |
1596 | ||
e7d841ca CW |
1597 | if (work == NULL || |
1598 | atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE || | |
1599 | !work->enable_stall_check) { | |
4e5359cd SF |
1600 | /* Either the pending flip IRQ arrived, or we're too early. Don't check */ |
1601 | spin_unlock_irqrestore(&dev->event_lock, flags); | |
1602 | return; | |
1603 | } | |
1604 | ||
1605 | /* Potential stall - if we see that the flip has happened, assume a missed interrupt */ | |
05394f39 | 1606 | obj = work->pending_flip_obj; |
a6c45cf0 | 1607 | if (INTEL_INFO(dev)->gen >= 4) { |
9db4a9c7 | 1608 | int dspsurf = DSPSURF(intel_crtc->plane); |
446f2545 | 1609 | stall_detected = I915_HI_DISPBASE(I915_READ(dspsurf)) == |
f343c5f6 | 1610 | i915_gem_obj_ggtt_offset(obj); |
4e5359cd | 1611 | } else { |
9db4a9c7 | 1612 | int dspaddr = DSPADDR(intel_crtc->plane); |
f343c5f6 | 1613 | stall_detected = I915_READ(dspaddr) == (i915_gem_obj_ggtt_offset(obj) + |
01f2c773 | 1614 | crtc->y * crtc->fb->pitches[0] + |
4e5359cd SF |
1615 | crtc->x * crtc->fb->bits_per_pixel/8); |
1616 | } | |
1617 | ||
1618 | spin_unlock_irqrestore(&dev->event_lock, flags); | |
1619 | ||
1620 | if (stall_detected) { | |
1621 | DRM_DEBUG_DRIVER("Pageflip stall detected\n"); | |
1622 | intel_prepare_page_flip(dev, intel_crtc->plane); | |
1623 | } | |
1624 | } | |
1625 | ||
42f52ef8 KP |
1626 | /* Called from drm generic code, passed 'crtc' which |
1627 | * we use as a pipe index | |
1628 | */ | |
f71d4af4 | 1629 | static int i915_enable_vblank(struct drm_device *dev, int pipe) |
0a3e67a4 JB |
1630 | { |
1631 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; | |
e9d21d7f | 1632 | unsigned long irqflags; |
71e0ffa5 | 1633 | |
5eddb70b | 1634 | if (!i915_pipe_enabled(dev, pipe)) |
71e0ffa5 | 1635 | return -EINVAL; |
0a3e67a4 | 1636 | |
1ec14ad3 | 1637 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
f796cf8f | 1638 | if (INTEL_INFO(dev)->gen >= 4) |
7c463586 KP |
1639 | i915_enable_pipestat(dev_priv, pipe, |
1640 | PIPE_START_VBLANK_INTERRUPT_ENABLE); | |
e9d21d7f | 1641 | else |
7c463586 KP |
1642 | i915_enable_pipestat(dev_priv, pipe, |
1643 | PIPE_VBLANK_INTERRUPT_ENABLE); | |
8692d00e CW |
1644 | |
1645 | /* maintain vblank delivery even in deep C-states */ | |
1646 | if (dev_priv->info->gen == 3) | |
6b26c86d | 1647 | I915_WRITE(INSTPM, _MASKED_BIT_DISABLE(INSTPM_AGPBUSY_DIS)); |
1ec14ad3 | 1648 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
8692d00e | 1649 | |
0a3e67a4 JB |
1650 | return 0; |
1651 | } | |
1652 | ||
f71d4af4 | 1653 | static int ironlake_enable_vblank(struct drm_device *dev, int pipe) |
f796cf8f JB |
1654 | { |
1655 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; | |
1656 | unsigned long irqflags; | |
b518421f PZ |
1657 | uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) : |
1658 | DE_PIPE_VBLANK_ILK(pipe); | |
f796cf8f JB |
1659 | |
1660 | if (!i915_pipe_enabled(dev, pipe)) | |
1661 | return -EINVAL; | |
1662 | ||
1663 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); | |
b518421f | 1664 | ironlake_enable_display_irq(dev_priv, bit); |
b1f14ad0 JB |
1665 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
1666 | ||
1667 | return 0; | |
1668 | } | |
1669 | ||
7e231dbe JB |
1670 | static int valleyview_enable_vblank(struct drm_device *dev, int pipe) |
1671 | { | |
1672 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; | |
1673 | unsigned long irqflags; | |
31acc7f5 | 1674 | u32 imr; |
7e231dbe JB |
1675 | |
1676 | if (!i915_pipe_enabled(dev, pipe)) | |
1677 | return -EINVAL; | |
1678 | ||
1679 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); | |
7e231dbe | 1680 | imr = I915_READ(VLV_IMR); |
31acc7f5 | 1681 | if (pipe == 0) |
7e231dbe | 1682 | imr &= ~I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT; |
31acc7f5 | 1683 | else |
7e231dbe | 1684 | imr &= ~I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT; |
7e231dbe | 1685 | I915_WRITE(VLV_IMR, imr); |
31acc7f5 JB |
1686 | i915_enable_pipestat(dev_priv, pipe, |
1687 | PIPE_START_VBLANK_INTERRUPT_ENABLE); | |
7e231dbe JB |
1688 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
1689 | ||
1690 | return 0; | |
1691 | } | |
1692 | ||
42f52ef8 KP |
1693 | /* Called from drm generic code, passed 'crtc' which |
1694 | * we use as a pipe index | |
1695 | */ | |
f71d4af4 | 1696 | static void i915_disable_vblank(struct drm_device *dev, int pipe) |
0a3e67a4 JB |
1697 | { |
1698 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; | |
e9d21d7f | 1699 | unsigned long irqflags; |
0a3e67a4 | 1700 | |
1ec14ad3 | 1701 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
8692d00e | 1702 | if (dev_priv->info->gen == 3) |
6b26c86d | 1703 | I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_DIS)); |
8692d00e | 1704 | |
f796cf8f JB |
1705 | i915_disable_pipestat(dev_priv, pipe, |
1706 | PIPE_VBLANK_INTERRUPT_ENABLE | | |
1707 | PIPE_START_VBLANK_INTERRUPT_ENABLE); | |
1708 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); | |
1709 | } | |
1710 | ||
f71d4af4 | 1711 | static void ironlake_disable_vblank(struct drm_device *dev, int pipe) |
f796cf8f JB |
1712 | { |
1713 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; | |
1714 | unsigned long irqflags; | |
b518421f PZ |
1715 | uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) : |
1716 | DE_PIPE_VBLANK_ILK(pipe); | |
f796cf8f JB |
1717 | |
1718 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); | |
b518421f | 1719 | ironlake_disable_display_irq(dev_priv, bit); |
b1f14ad0 JB |
1720 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
1721 | } | |
1722 | ||
7e231dbe JB |
1723 | static void valleyview_disable_vblank(struct drm_device *dev, int pipe) |
1724 | { | |
1725 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; | |
1726 | unsigned long irqflags; | |
31acc7f5 | 1727 | u32 imr; |
7e231dbe JB |
1728 | |
1729 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); | |
31acc7f5 JB |
1730 | i915_disable_pipestat(dev_priv, pipe, |
1731 | PIPE_START_VBLANK_INTERRUPT_ENABLE); | |
7e231dbe | 1732 | imr = I915_READ(VLV_IMR); |
31acc7f5 | 1733 | if (pipe == 0) |
7e231dbe | 1734 | imr |= I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT; |
31acc7f5 | 1735 | else |
7e231dbe | 1736 | imr |= I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT; |
7e231dbe | 1737 | I915_WRITE(VLV_IMR, imr); |
7e231dbe JB |
1738 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
1739 | } | |
1740 | ||
893eead0 CW |
1741 | static u32 |
1742 | ring_last_seqno(struct intel_ring_buffer *ring) | |
852835f3 | 1743 | { |
893eead0 CW |
1744 | return list_entry(ring->request_list.prev, |
1745 | struct drm_i915_gem_request, list)->seqno; | |
1746 | } | |
1747 | ||
9107e9d2 CW |
1748 | static bool |
1749 | ring_idle(struct intel_ring_buffer *ring, u32 seqno) | |
1750 | { | |
1751 | return (list_empty(&ring->request_list) || | |
1752 | i915_seqno_passed(seqno, ring_last_seqno(ring))); | |
f65d9421 BG |
1753 | } |
1754 | ||
6274f212 CW |
1755 | static struct intel_ring_buffer * |
1756 | semaphore_waits_for(struct intel_ring_buffer *ring, u32 *seqno) | |
a24a11e6 CW |
1757 | { |
1758 | struct drm_i915_private *dev_priv = ring->dev->dev_private; | |
6274f212 | 1759 | u32 cmd, ipehr, acthd, acthd_min; |
a24a11e6 CW |
1760 | |
1761 | ipehr = I915_READ(RING_IPEHR(ring->mmio_base)); | |
1762 | if ((ipehr & ~(0x3 << 16)) != | |
1763 | (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE | MI_SEMAPHORE_REGISTER)) | |
6274f212 | 1764 | return NULL; |
a24a11e6 CW |
1765 | |
1766 | /* ACTHD is likely pointing to the dword after the actual command, | |
1767 | * so scan backwards until we find the MBOX. | |
1768 | */ | |
6274f212 | 1769 | acthd = intel_ring_get_active_head(ring) & HEAD_ADDR; |
a24a11e6 CW |
1770 | acthd_min = max((int)acthd - 3 * 4, 0); |
1771 | do { | |
1772 | cmd = ioread32(ring->virtual_start + acthd); | |
1773 | if (cmd == ipehr) | |
1774 | break; | |
1775 | ||
1776 | acthd -= 4; | |
1777 | if (acthd < acthd_min) | |
6274f212 | 1778 | return NULL; |
a24a11e6 CW |
1779 | } while (1); |
1780 | ||
6274f212 CW |
1781 | *seqno = ioread32(ring->virtual_start+acthd+4)+1; |
1782 | return &dev_priv->ring[(ring->id + (((ipehr >> 17) & 1) + 1)) % 3]; | |
a24a11e6 CW |
1783 | } |
1784 | ||
6274f212 CW |
1785 | static int semaphore_passed(struct intel_ring_buffer *ring) |
1786 | { | |
1787 | struct drm_i915_private *dev_priv = ring->dev->dev_private; | |
1788 | struct intel_ring_buffer *signaller; | |
1789 | u32 seqno, ctl; | |
1790 | ||
1791 | ring->hangcheck.deadlock = true; | |
1792 | ||
1793 | signaller = semaphore_waits_for(ring, &seqno); | |
1794 | if (signaller == NULL || signaller->hangcheck.deadlock) | |
1795 | return -1; | |
1796 | ||
1797 | /* cursory check for an unkickable deadlock */ | |
1798 | ctl = I915_READ_CTL(signaller); | |
1799 | if (ctl & RING_WAIT_SEMAPHORE && semaphore_passed(signaller) < 0) | |
1800 | return -1; | |
1801 | ||
1802 | return i915_seqno_passed(signaller->get_seqno(signaller, false), seqno); | |
1803 | } | |
1804 | ||
1805 | static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv) | |
1806 | { | |
1807 | struct intel_ring_buffer *ring; | |
1808 | int i; | |
1809 | ||
1810 | for_each_ring(ring, dev_priv, i) | |
1811 | ring->hangcheck.deadlock = false; | |
1812 | } | |
1813 | ||
ad8beaea MK |
1814 | static enum intel_ring_hangcheck_action |
1815 | ring_stuck(struct intel_ring_buffer *ring, u32 acthd) | |
1ec14ad3 CW |
1816 | { |
1817 | struct drm_device *dev = ring->dev; | |
1818 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9107e9d2 CW |
1819 | u32 tmp; |
1820 | ||
6274f212 CW |
1821 | if (ring->hangcheck.acthd != acthd) |
1822 | return active; | |
1823 | ||
9107e9d2 | 1824 | if (IS_GEN2(dev)) |
6274f212 | 1825 | return hung; |
9107e9d2 CW |
1826 | |
1827 | /* Is the chip hanging on a WAIT_FOR_EVENT? | |
1828 | * If so we can simply poke the RB_WAIT bit | |
1829 | * and break the hang. This should work on | |
1830 | * all but the second generation chipsets. | |
1831 | */ | |
1832 | tmp = I915_READ_CTL(ring); | |
1ec14ad3 CW |
1833 | if (tmp & RING_WAIT) { |
1834 | DRM_ERROR("Kicking stuck wait on %s\n", | |
1835 | ring->name); | |
1836 | I915_WRITE_CTL(ring, tmp); | |
6274f212 CW |
1837 | return kick; |
1838 | } | |
1839 | ||
1840 | if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) { | |
1841 | switch (semaphore_passed(ring)) { | |
1842 | default: | |
1843 | return hung; | |
1844 | case 1: | |
1845 | DRM_ERROR("Kicking stuck semaphore on %s\n", | |
1846 | ring->name); | |
1847 | I915_WRITE_CTL(ring, tmp); | |
1848 | return kick; | |
1849 | case 0: | |
1850 | return wait; | |
1851 | } | |
9107e9d2 | 1852 | } |
ed5cbb03 | 1853 | |
6274f212 | 1854 | return hung; |
ed5cbb03 MK |
1855 | } |
1856 | ||
f65d9421 BG |
1857 | /** |
1858 | * This is called when the chip hasn't reported back with completed | |
05407ff8 MK |
1859 | * batchbuffers in a long time. We keep track per ring seqno progress and |
1860 | * if there are no progress, hangcheck score for that ring is increased. | |
1861 | * Further, acthd is inspected to see if the ring is stuck. On stuck case | |
1862 | * we kick the ring. If we see no progress on three subsequent calls | |
1863 | * we assume chip is wedged and try to fix it by resetting the chip. | |
f65d9421 BG |
1864 | */ |
1865 | void i915_hangcheck_elapsed(unsigned long data) | |
1866 | { | |
1867 | struct drm_device *dev = (struct drm_device *)data; | |
1868 | drm_i915_private_t *dev_priv = dev->dev_private; | |
b4519513 | 1869 | struct intel_ring_buffer *ring; |
b4519513 | 1870 | int i; |
05407ff8 | 1871 | int busy_count = 0, rings_hung = 0; |
9107e9d2 CW |
1872 | bool stuck[I915_NUM_RINGS] = { 0 }; |
1873 | #define BUSY 1 | |
1874 | #define KICK 5 | |
1875 | #define HUNG 20 | |
1876 | #define FIRE 30 | |
893eead0 | 1877 | |
3e0dc6b0 BW |
1878 | if (!i915_enable_hangcheck) |
1879 | return; | |
1880 | ||
b4519513 | 1881 | for_each_ring(ring, dev_priv, i) { |
05407ff8 | 1882 | u32 seqno, acthd; |
9107e9d2 | 1883 | bool busy = true; |
05407ff8 | 1884 | |
6274f212 CW |
1885 | semaphore_clear_deadlocks(dev_priv); |
1886 | ||
05407ff8 MK |
1887 | seqno = ring->get_seqno(ring, false); |
1888 | acthd = intel_ring_get_active_head(ring); | |
b4519513 | 1889 | |
9107e9d2 CW |
1890 | if (ring->hangcheck.seqno == seqno) { |
1891 | if (ring_idle(ring, seqno)) { | |
1892 | if (waitqueue_active(&ring->irq_queue)) { | |
1893 | /* Issue a wake-up to catch stuck h/w. */ | |
1894 | DRM_ERROR("Hangcheck timer elapsed... %s idle\n", | |
1895 | ring->name); | |
1896 | wake_up_all(&ring->irq_queue); | |
1897 | ring->hangcheck.score += HUNG; | |
1898 | } else | |
1899 | busy = false; | |
05407ff8 | 1900 | } else { |
9107e9d2 CW |
1901 | int score; |
1902 | ||
6274f212 CW |
1903 | /* We always increment the hangcheck score |
1904 | * if the ring is busy and still processing | |
1905 | * the same request, so that no single request | |
1906 | * can run indefinitely (such as a chain of | |
1907 | * batches). The only time we do not increment | |
1908 | * the hangcheck score on this ring, if this | |
1909 | * ring is in a legitimate wait for another | |
1910 | * ring. In that case the waiting ring is a | |
1911 | * victim and we want to be sure we catch the | |
1912 | * right culprit. Then every time we do kick | |
1913 | * the ring, add a small increment to the | |
1914 | * score so that we can catch a batch that is | |
1915 | * being repeatedly kicked and so responsible | |
1916 | * for stalling the machine. | |
1917 | */ | |
ad8beaea MK |
1918 | ring->hangcheck.action = ring_stuck(ring, |
1919 | acthd); | |
1920 | ||
1921 | switch (ring->hangcheck.action) { | |
6274f212 CW |
1922 | case wait: |
1923 | score = 0; | |
1924 | break; | |
1925 | case active: | |
9107e9d2 | 1926 | score = BUSY; |
6274f212 CW |
1927 | break; |
1928 | case kick: | |
1929 | score = KICK; | |
1930 | break; | |
1931 | case hung: | |
1932 | score = HUNG; | |
1933 | stuck[i] = true; | |
1934 | break; | |
1935 | } | |
9107e9d2 | 1936 | ring->hangcheck.score += score; |
05407ff8 | 1937 | } |
9107e9d2 CW |
1938 | } else { |
1939 | /* Gradually reduce the count so that we catch DoS | |
1940 | * attempts across multiple batches. | |
1941 | */ | |
1942 | if (ring->hangcheck.score > 0) | |
1943 | ring->hangcheck.score--; | |
d1e61e7f CW |
1944 | } |
1945 | ||
05407ff8 MK |
1946 | ring->hangcheck.seqno = seqno; |
1947 | ring->hangcheck.acthd = acthd; | |
9107e9d2 | 1948 | busy_count += busy; |
893eead0 | 1949 | } |
b9201c14 | 1950 | |
92cab734 | 1951 | for_each_ring(ring, dev_priv, i) { |
9107e9d2 | 1952 | if (ring->hangcheck.score > FIRE) { |
acd78c11 | 1953 | DRM_ERROR("%s on %s\n", |
05407ff8 | 1954 | stuck[i] ? "stuck" : "no progress", |
a43adf07 CW |
1955 | ring->name); |
1956 | rings_hung++; | |
92cab734 MK |
1957 | } |
1958 | } | |
1959 | ||
05407ff8 MK |
1960 | if (rings_hung) |
1961 | return i915_handle_error(dev, true); | |
f65d9421 | 1962 | |
05407ff8 MK |
1963 | if (busy_count) |
1964 | /* Reset timer case chip hangs without another request | |
1965 | * being added */ | |
10cd45b6 MK |
1966 | i915_queue_hangcheck(dev); |
1967 | } | |
1968 | ||
1969 | void i915_queue_hangcheck(struct drm_device *dev) | |
1970 | { | |
1971 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1972 | if (!i915_enable_hangcheck) | |
1973 | return; | |
1974 | ||
1975 | mod_timer(&dev_priv->gpu_error.hangcheck_timer, | |
1976 | round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES)); | |
f65d9421 BG |
1977 | } |
1978 | ||
91738a95 PZ |
1979 | static void ibx_irq_preinstall(struct drm_device *dev) |
1980 | { | |
1981 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1982 | ||
1983 | if (HAS_PCH_NOP(dev)) | |
1984 | return; | |
1985 | ||
1986 | /* south display irq */ | |
1987 | I915_WRITE(SDEIMR, 0xffffffff); | |
1988 | /* | |
1989 | * SDEIER is also touched by the interrupt handler to work around missed | |
1990 | * PCH interrupts. Hence we can't update it after the interrupt handler | |
1991 | * is enabled - instead we unconditionally enable all PCH interrupt | |
1992 | * sources here, but then only unmask them as needed with SDEIMR. | |
1993 | */ | |
1994 | I915_WRITE(SDEIER, 0xffffffff); | |
1995 | POSTING_READ(SDEIER); | |
1996 | } | |
1997 | ||
d18ea1b5 DV |
1998 | static void gen5_gt_irq_preinstall(struct drm_device *dev) |
1999 | { | |
2000 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2001 | ||
2002 | /* and GT */ | |
2003 | I915_WRITE(GTIMR, 0xffffffff); | |
2004 | I915_WRITE(GTIER, 0x0); | |
2005 | POSTING_READ(GTIER); | |
2006 | ||
2007 | if (INTEL_INFO(dev)->gen >= 6) { | |
2008 | /* and PM */ | |
2009 | I915_WRITE(GEN6_PMIMR, 0xffffffff); | |
2010 | I915_WRITE(GEN6_PMIER, 0x0); | |
2011 | POSTING_READ(GEN6_PMIER); | |
2012 | } | |
2013 | } | |
2014 | ||
1da177e4 LT |
2015 | /* drm_dma.h hooks |
2016 | */ | |
f71d4af4 | 2017 | static void ironlake_irq_preinstall(struct drm_device *dev) |
036a4a7d ZW |
2018 | { |
2019 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; | |
2020 | ||
4697995b JB |
2021 | atomic_set(&dev_priv->irq_received, 0); |
2022 | ||
036a4a7d | 2023 | I915_WRITE(HWSTAM, 0xeffe); |
bdfcdb63 | 2024 | |
036a4a7d ZW |
2025 | I915_WRITE(DEIMR, 0xffffffff); |
2026 | I915_WRITE(DEIER, 0x0); | |
3143a2bf | 2027 | POSTING_READ(DEIER); |
036a4a7d | 2028 | |
d18ea1b5 | 2029 | gen5_gt_irq_preinstall(dev); |
c650156a | 2030 | |
91738a95 | 2031 | ibx_irq_preinstall(dev); |
7d99163d BW |
2032 | } |
2033 | ||
7e231dbe JB |
2034 | static void valleyview_irq_preinstall(struct drm_device *dev) |
2035 | { | |
2036 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; | |
2037 | int pipe; | |
2038 | ||
2039 | atomic_set(&dev_priv->irq_received, 0); | |
2040 | ||
7e231dbe JB |
2041 | /* VLV magic */ |
2042 | I915_WRITE(VLV_IMR, 0); | |
2043 | I915_WRITE(RING_IMR(RENDER_RING_BASE), 0); | |
2044 | I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0); | |
2045 | I915_WRITE(RING_IMR(BLT_RING_BASE), 0); | |
2046 | ||
7e231dbe JB |
2047 | /* and GT */ |
2048 | I915_WRITE(GTIIR, I915_READ(GTIIR)); | |
2049 | I915_WRITE(GTIIR, I915_READ(GTIIR)); | |
d18ea1b5 DV |
2050 | |
2051 | gen5_gt_irq_preinstall(dev); | |
7e231dbe JB |
2052 | |
2053 | I915_WRITE(DPINVGTT, 0xff); | |
2054 | ||
2055 | I915_WRITE(PORT_HOTPLUG_EN, 0); | |
2056 | I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); | |
2057 | for_each_pipe(pipe) | |
2058 | I915_WRITE(PIPESTAT(pipe), 0xffff); | |
2059 | I915_WRITE(VLV_IIR, 0xffffffff); | |
2060 | I915_WRITE(VLV_IMR, 0xffffffff); | |
2061 | I915_WRITE(VLV_IER, 0x0); | |
2062 | POSTING_READ(VLV_IER); | |
2063 | } | |
2064 | ||
82a28bcf | 2065 | static void ibx_hpd_irq_setup(struct drm_device *dev) |
7fe0b973 KP |
2066 | { |
2067 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; | |
82a28bcf DV |
2068 | struct drm_mode_config *mode_config = &dev->mode_config; |
2069 | struct intel_encoder *intel_encoder; | |
fee884ed | 2070 | u32 hotplug_irqs, hotplug, enabled_irqs = 0; |
82a28bcf DV |
2071 | |
2072 | if (HAS_PCH_IBX(dev)) { | |
fee884ed | 2073 | hotplug_irqs = SDE_HOTPLUG_MASK; |
82a28bcf | 2074 | list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head) |
cd569aed | 2075 | if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED) |
fee884ed | 2076 | enabled_irqs |= hpd_ibx[intel_encoder->hpd_pin]; |
82a28bcf | 2077 | } else { |
fee884ed | 2078 | hotplug_irqs = SDE_HOTPLUG_MASK_CPT; |
82a28bcf | 2079 | list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head) |
cd569aed | 2080 | if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED) |
fee884ed | 2081 | enabled_irqs |= hpd_cpt[intel_encoder->hpd_pin]; |
82a28bcf | 2082 | } |
7fe0b973 | 2083 | |
fee884ed | 2084 | ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs); |
82a28bcf DV |
2085 | |
2086 | /* | |
2087 | * Enable digital hotplug on the PCH, and configure the DP short pulse | |
2088 | * duration to 2ms (which is the minimum in the Display Port spec) | |
2089 | * | |
2090 | * This register is the same on all known PCH chips. | |
2091 | */ | |
7fe0b973 KP |
2092 | hotplug = I915_READ(PCH_PORT_HOTPLUG); |
2093 | hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK); | |
2094 | hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms; | |
2095 | hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms; | |
2096 | hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms; | |
2097 | I915_WRITE(PCH_PORT_HOTPLUG, hotplug); | |
2098 | } | |
2099 | ||
d46da437 PZ |
2100 | static void ibx_irq_postinstall(struct drm_device *dev) |
2101 | { | |
2102 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; | |
82a28bcf | 2103 | u32 mask; |
e5868a31 | 2104 | |
692a04cf DV |
2105 | if (HAS_PCH_NOP(dev)) |
2106 | return; | |
2107 | ||
8664281b PZ |
2108 | if (HAS_PCH_IBX(dev)) { |
2109 | mask = SDE_GMBUS | SDE_AUX_MASK | SDE_TRANSB_FIFO_UNDER | | |
de032bf4 | 2110 | SDE_TRANSA_FIFO_UNDER | SDE_POISON; |
8664281b PZ |
2111 | } else { |
2112 | mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT | SDE_ERROR_CPT; | |
2113 | ||
2114 | I915_WRITE(SERR_INT, I915_READ(SERR_INT)); | |
2115 | } | |
ab5c608b | 2116 | |
d46da437 PZ |
2117 | I915_WRITE(SDEIIR, I915_READ(SDEIIR)); |
2118 | I915_WRITE(SDEIMR, ~mask); | |
d46da437 PZ |
2119 | } |
2120 | ||
0a9a8c91 DV |
2121 | static void gen5_gt_irq_postinstall(struct drm_device *dev) |
2122 | { | |
2123 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2124 | u32 pm_irqs, gt_irqs; | |
2125 | ||
2126 | pm_irqs = gt_irqs = 0; | |
2127 | ||
2128 | dev_priv->gt_irq_mask = ~0; | |
2129 | if (HAS_L3_GPU_CACHE(dev)) { | |
2130 | /* L3 parity interrupt is always unmasked. */ | |
2131 | dev_priv->gt_irq_mask = ~GT_RENDER_L3_PARITY_ERROR_INTERRUPT; | |
2132 | gt_irqs |= GT_RENDER_L3_PARITY_ERROR_INTERRUPT; | |
2133 | } | |
2134 | ||
2135 | gt_irqs |= GT_RENDER_USER_INTERRUPT; | |
2136 | if (IS_GEN5(dev)) { | |
2137 | gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT | | |
2138 | ILK_BSD_USER_INTERRUPT; | |
2139 | } else { | |
2140 | gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT; | |
2141 | } | |
2142 | ||
2143 | I915_WRITE(GTIIR, I915_READ(GTIIR)); | |
2144 | I915_WRITE(GTIMR, dev_priv->gt_irq_mask); | |
2145 | I915_WRITE(GTIER, gt_irqs); | |
2146 | POSTING_READ(GTIER); | |
2147 | ||
2148 | if (INTEL_INFO(dev)->gen >= 6) { | |
2149 | pm_irqs |= GEN6_PM_RPS_EVENTS; | |
2150 | ||
2151 | if (HAS_VEBOX(dev)) | |
2152 | pm_irqs |= PM_VEBOX_USER_INTERRUPT; | |
2153 | ||
2154 | I915_WRITE(GEN6_PMIIR, I915_READ(GEN6_PMIIR)); | |
2155 | I915_WRITE(GEN6_PMIMR, 0xffffffff); | |
2156 | I915_WRITE(GEN6_PMIER, pm_irqs); | |
2157 | POSTING_READ(GEN6_PMIER); | |
2158 | } | |
2159 | } | |
2160 | ||
f71d4af4 | 2161 | static int ironlake_irq_postinstall(struct drm_device *dev) |
036a4a7d | 2162 | { |
4bc9d430 | 2163 | unsigned long irqflags; |
036a4a7d | 2164 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; |
8e76f8dc PZ |
2165 | u32 display_mask, extra_mask; |
2166 | ||
2167 | if (INTEL_INFO(dev)->gen >= 7) { | |
2168 | display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB | | |
2169 | DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB | | |
2170 | DE_PLANEB_FLIP_DONE_IVB | | |
2171 | DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB | | |
2172 | DE_ERR_INT_IVB); | |
2173 | extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB | | |
2174 | DE_PIPEA_VBLANK_IVB); | |
2175 | ||
2176 | I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT)); | |
2177 | } else { | |
2178 | display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT | | |
2179 | DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE | | |
2180 | DE_AUX_CHANNEL_A | DE_PIPEB_FIFO_UNDERRUN | | |
2181 | DE_PIPEA_FIFO_UNDERRUN | DE_POISON); | |
2182 | extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT; | |
2183 | } | |
036a4a7d | 2184 | |
1ec14ad3 | 2185 | dev_priv->irq_mask = ~display_mask; |
036a4a7d ZW |
2186 | |
2187 | /* should always can generate irq */ | |
2188 | I915_WRITE(DEIIR, I915_READ(DEIIR)); | |
1ec14ad3 | 2189 | I915_WRITE(DEIMR, dev_priv->irq_mask); |
8e76f8dc | 2190 | I915_WRITE(DEIER, display_mask | extra_mask); |
3143a2bf | 2191 | POSTING_READ(DEIER); |
036a4a7d | 2192 | |
0a9a8c91 | 2193 | gen5_gt_irq_postinstall(dev); |
036a4a7d | 2194 | |
d46da437 | 2195 | ibx_irq_postinstall(dev); |
7fe0b973 | 2196 | |
f97108d1 | 2197 | if (IS_IRONLAKE_M(dev)) { |
6005ce42 DV |
2198 | /* Enable PCU event interrupts |
2199 | * | |
2200 | * spinlocking not required here for correctness since interrupt | |
4bc9d430 DV |
2201 | * setup is guaranteed to run in single-threaded context. But we |
2202 | * need it to make the assert_spin_locked happy. */ | |
2203 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); | |
f97108d1 | 2204 | ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT); |
4bc9d430 | 2205 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
f97108d1 JB |
2206 | } |
2207 | ||
036a4a7d ZW |
2208 | return 0; |
2209 | } | |
2210 | ||
7e231dbe JB |
2211 | static int valleyview_irq_postinstall(struct drm_device *dev) |
2212 | { | |
2213 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; | |
7e231dbe | 2214 | u32 enable_mask; |
31acc7f5 | 2215 | u32 pipestat_enable = PLANE_FLIP_DONE_INT_EN_VLV; |
b79480ba | 2216 | unsigned long irqflags; |
7e231dbe JB |
2217 | |
2218 | enable_mask = I915_DISPLAY_PORT_INTERRUPT; | |
31acc7f5 JB |
2219 | enable_mask |= I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | |
2220 | I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT | | |
2221 | I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | | |
7e231dbe JB |
2222 | I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT; |
2223 | ||
31acc7f5 JB |
2224 | /* |
2225 | *Leave vblank interrupts masked initially. enable/disable will | |
2226 | * toggle them based on usage. | |
2227 | */ | |
2228 | dev_priv->irq_mask = (~enable_mask) | | |
2229 | I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT | | |
2230 | I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT; | |
7e231dbe | 2231 | |
20afbda2 DV |
2232 | I915_WRITE(PORT_HOTPLUG_EN, 0); |
2233 | POSTING_READ(PORT_HOTPLUG_EN); | |
2234 | ||
7e231dbe JB |
2235 | I915_WRITE(VLV_IMR, dev_priv->irq_mask); |
2236 | I915_WRITE(VLV_IER, enable_mask); | |
2237 | I915_WRITE(VLV_IIR, 0xffffffff); | |
2238 | I915_WRITE(PIPESTAT(0), 0xffff); | |
2239 | I915_WRITE(PIPESTAT(1), 0xffff); | |
2240 | POSTING_READ(VLV_IER); | |
2241 | ||
b79480ba DV |
2242 | /* Interrupt setup is already guaranteed to be single-threaded, this is |
2243 | * just to make the assert_spin_locked check happy. */ | |
2244 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); | |
31acc7f5 | 2245 | i915_enable_pipestat(dev_priv, 0, pipestat_enable); |
515ac2bb | 2246 | i915_enable_pipestat(dev_priv, 0, PIPE_GMBUS_EVENT_ENABLE); |
31acc7f5 | 2247 | i915_enable_pipestat(dev_priv, 1, pipestat_enable); |
b79480ba | 2248 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
31acc7f5 | 2249 | |
7e231dbe JB |
2250 | I915_WRITE(VLV_IIR, 0xffffffff); |
2251 | I915_WRITE(VLV_IIR, 0xffffffff); | |
2252 | ||
0a9a8c91 | 2253 | gen5_gt_irq_postinstall(dev); |
7e231dbe JB |
2254 | |
2255 | /* ack & enable invalid PTE error interrupts */ | |
2256 | #if 0 /* FIXME: add support to irq handler for checking these bits */ | |
2257 | I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK); | |
2258 | I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK); | |
2259 | #endif | |
2260 | ||
2261 | I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE); | |
20afbda2 DV |
2262 | |
2263 | return 0; | |
2264 | } | |
2265 | ||
7e231dbe JB |
2266 | static void valleyview_irq_uninstall(struct drm_device *dev) |
2267 | { | |
2268 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; | |
2269 | int pipe; | |
2270 | ||
2271 | if (!dev_priv) | |
2272 | return; | |
2273 | ||
ac4c16c5 EE |
2274 | del_timer_sync(&dev_priv->hotplug_reenable_timer); |
2275 | ||
7e231dbe JB |
2276 | for_each_pipe(pipe) |
2277 | I915_WRITE(PIPESTAT(pipe), 0xffff); | |
2278 | ||
2279 | I915_WRITE(HWSTAM, 0xffffffff); | |
2280 | I915_WRITE(PORT_HOTPLUG_EN, 0); | |
2281 | I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); | |
2282 | for_each_pipe(pipe) | |
2283 | I915_WRITE(PIPESTAT(pipe), 0xffff); | |
2284 | I915_WRITE(VLV_IIR, 0xffffffff); | |
2285 | I915_WRITE(VLV_IMR, 0xffffffff); | |
2286 | I915_WRITE(VLV_IER, 0x0); | |
2287 | POSTING_READ(VLV_IER); | |
2288 | } | |
2289 | ||
f71d4af4 | 2290 | static void ironlake_irq_uninstall(struct drm_device *dev) |
036a4a7d ZW |
2291 | { |
2292 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; | |
4697995b JB |
2293 | |
2294 | if (!dev_priv) | |
2295 | return; | |
2296 | ||
ac4c16c5 EE |
2297 | del_timer_sync(&dev_priv->hotplug_reenable_timer); |
2298 | ||
036a4a7d ZW |
2299 | I915_WRITE(HWSTAM, 0xffffffff); |
2300 | ||
2301 | I915_WRITE(DEIMR, 0xffffffff); | |
2302 | I915_WRITE(DEIER, 0x0); | |
2303 | I915_WRITE(DEIIR, I915_READ(DEIIR)); | |
8664281b PZ |
2304 | if (IS_GEN7(dev)) |
2305 | I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT)); | |
036a4a7d ZW |
2306 | |
2307 | I915_WRITE(GTIMR, 0xffffffff); | |
2308 | I915_WRITE(GTIER, 0x0); | |
2309 | I915_WRITE(GTIIR, I915_READ(GTIIR)); | |
192aac1f | 2310 | |
ab5c608b BW |
2311 | if (HAS_PCH_NOP(dev)) |
2312 | return; | |
2313 | ||
192aac1f KP |
2314 | I915_WRITE(SDEIMR, 0xffffffff); |
2315 | I915_WRITE(SDEIER, 0x0); | |
2316 | I915_WRITE(SDEIIR, I915_READ(SDEIIR)); | |
8664281b PZ |
2317 | if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev)) |
2318 | I915_WRITE(SERR_INT, I915_READ(SERR_INT)); | |
036a4a7d ZW |
2319 | } |
2320 | ||
a266c7d5 | 2321 | static void i8xx_irq_preinstall(struct drm_device * dev) |
1da177e4 LT |
2322 | { |
2323 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; | |
9db4a9c7 | 2324 | int pipe; |
91e3738e | 2325 | |
a266c7d5 | 2326 | atomic_set(&dev_priv->irq_received, 0); |
5ca58282 | 2327 | |
9db4a9c7 JB |
2328 | for_each_pipe(pipe) |
2329 | I915_WRITE(PIPESTAT(pipe), 0); | |
a266c7d5 CW |
2330 | I915_WRITE16(IMR, 0xffff); |
2331 | I915_WRITE16(IER, 0x0); | |
2332 | POSTING_READ16(IER); | |
c2798b19 CW |
2333 | } |
2334 | ||
2335 | static int i8xx_irq_postinstall(struct drm_device *dev) | |
2336 | { | |
2337 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; | |
2338 | ||
c2798b19 CW |
2339 | I915_WRITE16(EMR, |
2340 | ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH)); | |
2341 | ||
2342 | /* Unmask the interrupts that we always want on. */ | |
2343 | dev_priv->irq_mask = | |
2344 | ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | | |
2345 | I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | | |
2346 | I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | | |
2347 | I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT | | |
2348 | I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); | |
2349 | I915_WRITE16(IMR, dev_priv->irq_mask); | |
2350 | ||
2351 | I915_WRITE16(IER, | |
2352 | I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | | |
2353 | I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | | |
2354 | I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT | | |
2355 | I915_USER_INTERRUPT); | |
2356 | POSTING_READ16(IER); | |
2357 | ||
2358 | return 0; | |
2359 | } | |
2360 | ||
90a72f87 VS |
2361 | /* |
2362 | * Returns true when a page flip has completed. | |
2363 | */ | |
2364 | static bool i8xx_handle_vblank(struct drm_device *dev, | |
2365 | int pipe, u16 iir) | |
2366 | { | |
2367 | drm_i915_private_t *dev_priv = dev->dev_private; | |
2368 | u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(pipe); | |
2369 | ||
2370 | if (!drm_handle_vblank(dev, pipe)) | |
2371 | return false; | |
2372 | ||
2373 | if ((iir & flip_pending) == 0) | |
2374 | return false; | |
2375 | ||
2376 | intel_prepare_page_flip(dev, pipe); | |
2377 | ||
2378 | /* We detect FlipDone by looking for the change in PendingFlip from '1' | |
2379 | * to '0' on the following vblank, i.e. IIR has the Pendingflip | |
2380 | * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence | |
2381 | * the flip is completed (no longer pending). Since this doesn't raise | |
2382 | * an interrupt per se, we watch for the change at vblank. | |
2383 | */ | |
2384 | if (I915_READ16(ISR) & flip_pending) | |
2385 | return false; | |
2386 | ||
2387 | intel_finish_page_flip(dev, pipe); | |
2388 | ||
2389 | return true; | |
2390 | } | |
2391 | ||
ff1f525e | 2392 | static irqreturn_t i8xx_irq_handler(int irq, void *arg) |
c2798b19 CW |
2393 | { |
2394 | struct drm_device *dev = (struct drm_device *) arg; | |
2395 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; | |
c2798b19 CW |
2396 | u16 iir, new_iir; |
2397 | u32 pipe_stats[2]; | |
2398 | unsigned long irqflags; | |
2399 | int irq_received; | |
2400 | int pipe; | |
2401 | u16 flip_mask = | |
2402 | I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | | |
2403 | I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT; | |
2404 | ||
2405 | atomic_inc(&dev_priv->irq_received); | |
2406 | ||
2407 | iir = I915_READ16(IIR); | |
2408 | if (iir == 0) | |
2409 | return IRQ_NONE; | |
2410 | ||
2411 | while (iir & ~flip_mask) { | |
2412 | /* Can't rely on pipestat interrupt bit in iir as it might | |
2413 | * have been cleared after the pipestat interrupt was received. | |
2414 | * It doesn't set the bit in iir again, but it still produces | |
2415 | * interrupts (for non-MSI). | |
2416 | */ | |
2417 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); | |
2418 | if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) | |
2419 | i915_handle_error(dev, false); | |
2420 | ||
2421 | for_each_pipe(pipe) { | |
2422 | int reg = PIPESTAT(pipe); | |
2423 | pipe_stats[pipe] = I915_READ(reg); | |
2424 | ||
2425 | /* | |
2426 | * Clear the PIPE*STAT regs before the IIR | |
2427 | */ | |
2428 | if (pipe_stats[pipe] & 0x8000ffff) { | |
2429 | if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) | |
2430 | DRM_DEBUG_DRIVER("pipe %c underrun\n", | |
2431 | pipe_name(pipe)); | |
2432 | I915_WRITE(reg, pipe_stats[pipe]); | |
2433 | irq_received = 1; | |
2434 | } | |
2435 | } | |
2436 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); | |
2437 | ||
2438 | I915_WRITE16(IIR, iir & ~flip_mask); | |
2439 | new_iir = I915_READ16(IIR); /* Flush posted writes */ | |
2440 | ||
d05c617e | 2441 | i915_update_dri1_breadcrumb(dev); |
c2798b19 CW |
2442 | |
2443 | if (iir & I915_USER_INTERRUPT) | |
2444 | notify_ring(dev, &dev_priv->ring[RCS]); | |
2445 | ||
2446 | if (pipe_stats[0] & PIPE_VBLANK_INTERRUPT_STATUS && | |
90a72f87 VS |
2447 | i8xx_handle_vblank(dev, 0, iir)) |
2448 | flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(0); | |
c2798b19 CW |
2449 | |
2450 | if (pipe_stats[1] & PIPE_VBLANK_INTERRUPT_STATUS && | |
90a72f87 VS |
2451 | i8xx_handle_vblank(dev, 1, iir)) |
2452 | flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(1); | |
c2798b19 CW |
2453 | |
2454 | iir = new_iir; | |
2455 | } | |
2456 | ||
2457 | return IRQ_HANDLED; | |
2458 | } | |
2459 | ||
2460 | static void i8xx_irq_uninstall(struct drm_device * dev) | |
2461 | { | |
2462 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; | |
2463 | int pipe; | |
2464 | ||
c2798b19 CW |
2465 | for_each_pipe(pipe) { |
2466 | /* Clear enable bits; then clear status bits */ | |
2467 | I915_WRITE(PIPESTAT(pipe), 0); | |
2468 | I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe))); | |
2469 | } | |
2470 | I915_WRITE16(IMR, 0xffff); | |
2471 | I915_WRITE16(IER, 0x0); | |
2472 | I915_WRITE16(IIR, I915_READ16(IIR)); | |
2473 | } | |
2474 | ||
a266c7d5 CW |
2475 | static void i915_irq_preinstall(struct drm_device * dev) |
2476 | { | |
2477 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; | |
2478 | int pipe; | |
2479 | ||
2480 | atomic_set(&dev_priv->irq_received, 0); | |
2481 | ||
2482 | if (I915_HAS_HOTPLUG(dev)) { | |
2483 | I915_WRITE(PORT_HOTPLUG_EN, 0); | |
2484 | I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); | |
2485 | } | |
2486 | ||
00d98ebd | 2487 | I915_WRITE16(HWSTAM, 0xeffe); |
a266c7d5 CW |
2488 | for_each_pipe(pipe) |
2489 | I915_WRITE(PIPESTAT(pipe), 0); | |
2490 | I915_WRITE(IMR, 0xffffffff); | |
2491 | I915_WRITE(IER, 0x0); | |
2492 | POSTING_READ(IER); | |
2493 | } | |
2494 | ||
2495 | static int i915_irq_postinstall(struct drm_device *dev) | |
2496 | { | |
2497 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; | |
38bde180 | 2498 | u32 enable_mask; |
a266c7d5 | 2499 | |
38bde180 CW |
2500 | I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH)); |
2501 | ||
2502 | /* Unmask the interrupts that we always want on. */ | |
2503 | dev_priv->irq_mask = | |
2504 | ~(I915_ASLE_INTERRUPT | | |
2505 | I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | | |
2506 | I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | | |
2507 | I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | | |
2508 | I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT | | |
2509 | I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); | |
2510 | ||
2511 | enable_mask = | |
2512 | I915_ASLE_INTERRUPT | | |
2513 | I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | | |
2514 | I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | | |
2515 | I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT | | |
2516 | I915_USER_INTERRUPT; | |
2517 | ||
a266c7d5 | 2518 | if (I915_HAS_HOTPLUG(dev)) { |
20afbda2 DV |
2519 | I915_WRITE(PORT_HOTPLUG_EN, 0); |
2520 | POSTING_READ(PORT_HOTPLUG_EN); | |
2521 | ||
a266c7d5 CW |
2522 | /* Enable in IER... */ |
2523 | enable_mask |= I915_DISPLAY_PORT_INTERRUPT; | |
2524 | /* and unmask in IMR */ | |
2525 | dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT; | |
2526 | } | |
2527 | ||
a266c7d5 CW |
2528 | I915_WRITE(IMR, dev_priv->irq_mask); |
2529 | I915_WRITE(IER, enable_mask); | |
2530 | POSTING_READ(IER); | |
2531 | ||
f49e38dd | 2532 | i915_enable_asle_pipestat(dev); |
20afbda2 DV |
2533 | |
2534 | return 0; | |
2535 | } | |
2536 | ||
90a72f87 VS |
2537 | /* |
2538 | * Returns true when a page flip has completed. | |
2539 | */ | |
2540 | static bool i915_handle_vblank(struct drm_device *dev, | |
2541 | int plane, int pipe, u32 iir) | |
2542 | { | |
2543 | drm_i915_private_t *dev_priv = dev->dev_private; | |
2544 | u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane); | |
2545 | ||
2546 | if (!drm_handle_vblank(dev, pipe)) | |
2547 | return false; | |
2548 | ||
2549 | if ((iir & flip_pending) == 0) | |
2550 | return false; | |
2551 | ||
2552 | intel_prepare_page_flip(dev, plane); | |
2553 | ||
2554 | /* We detect FlipDone by looking for the change in PendingFlip from '1' | |
2555 | * to '0' on the following vblank, i.e. IIR has the Pendingflip | |
2556 | * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence | |
2557 | * the flip is completed (no longer pending). Since this doesn't raise | |
2558 | * an interrupt per se, we watch for the change at vblank. | |
2559 | */ | |
2560 | if (I915_READ(ISR) & flip_pending) | |
2561 | return false; | |
2562 | ||
2563 | intel_finish_page_flip(dev, pipe); | |
2564 | ||
2565 | return true; | |
2566 | } | |
2567 | ||
ff1f525e | 2568 | static irqreturn_t i915_irq_handler(int irq, void *arg) |
a266c7d5 CW |
2569 | { |
2570 | struct drm_device *dev = (struct drm_device *) arg; | |
2571 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; | |
8291ee90 | 2572 | u32 iir, new_iir, pipe_stats[I915_MAX_PIPES]; |
a266c7d5 | 2573 | unsigned long irqflags; |
38bde180 CW |
2574 | u32 flip_mask = |
2575 | I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | | |
2576 | I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT; | |
38bde180 | 2577 | int pipe, ret = IRQ_NONE; |
a266c7d5 CW |
2578 | |
2579 | atomic_inc(&dev_priv->irq_received); | |
2580 | ||
2581 | iir = I915_READ(IIR); | |
38bde180 CW |
2582 | do { |
2583 | bool irq_received = (iir & ~flip_mask) != 0; | |
8291ee90 | 2584 | bool blc_event = false; |
a266c7d5 CW |
2585 | |
2586 | /* Can't rely on pipestat interrupt bit in iir as it might | |
2587 | * have been cleared after the pipestat interrupt was received. | |
2588 | * It doesn't set the bit in iir again, but it still produces | |
2589 | * interrupts (for non-MSI). | |
2590 | */ | |
2591 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); | |
2592 | if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) | |
2593 | i915_handle_error(dev, false); | |
2594 | ||
2595 | for_each_pipe(pipe) { | |
2596 | int reg = PIPESTAT(pipe); | |
2597 | pipe_stats[pipe] = I915_READ(reg); | |
2598 | ||
38bde180 | 2599 | /* Clear the PIPE*STAT regs before the IIR */ |
a266c7d5 CW |
2600 | if (pipe_stats[pipe] & 0x8000ffff) { |
2601 | if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) | |
2602 | DRM_DEBUG_DRIVER("pipe %c underrun\n", | |
2603 | pipe_name(pipe)); | |
2604 | I915_WRITE(reg, pipe_stats[pipe]); | |
38bde180 | 2605 | irq_received = true; |
a266c7d5 CW |
2606 | } |
2607 | } | |
2608 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); | |
2609 | ||
2610 | if (!irq_received) | |
2611 | break; | |
2612 | ||
a266c7d5 CW |
2613 | /* Consume port. Then clear IIR or we'll miss events */ |
2614 | if ((I915_HAS_HOTPLUG(dev)) && | |
2615 | (iir & I915_DISPLAY_PORT_INTERRUPT)) { | |
2616 | u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT); | |
b543fb04 | 2617 | u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915; |
a266c7d5 CW |
2618 | |
2619 | DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n", | |
2620 | hotplug_status); | |
91d131d2 DV |
2621 | |
2622 | intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915); | |
2623 | ||
a266c7d5 | 2624 | I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status); |
38bde180 | 2625 | POSTING_READ(PORT_HOTPLUG_STAT); |
a266c7d5 CW |
2626 | } |
2627 | ||
38bde180 | 2628 | I915_WRITE(IIR, iir & ~flip_mask); |
a266c7d5 CW |
2629 | new_iir = I915_READ(IIR); /* Flush posted writes */ |
2630 | ||
a266c7d5 CW |
2631 | if (iir & I915_USER_INTERRUPT) |
2632 | notify_ring(dev, &dev_priv->ring[RCS]); | |
a266c7d5 | 2633 | |
a266c7d5 | 2634 | for_each_pipe(pipe) { |
38bde180 CW |
2635 | int plane = pipe; |
2636 | if (IS_MOBILE(dev)) | |
2637 | plane = !plane; | |
90a72f87 | 2638 | |
8291ee90 | 2639 | if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS && |
90a72f87 VS |
2640 | i915_handle_vblank(dev, plane, pipe, iir)) |
2641 | flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane); | |
a266c7d5 CW |
2642 | |
2643 | if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS) | |
2644 | blc_event = true; | |
2645 | } | |
2646 | ||
a266c7d5 CW |
2647 | if (blc_event || (iir & I915_ASLE_INTERRUPT)) |
2648 | intel_opregion_asle_intr(dev); | |
2649 | ||
2650 | /* With MSI, interrupts are only generated when iir | |
2651 | * transitions from zero to nonzero. If another bit got | |
2652 | * set while we were handling the existing iir bits, then | |
2653 | * we would never get another interrupt. | |
2654 | * | |
2655 | * This is fine on non-MSI as well, as if we hit this path | |
2656 | * we avoid exiting the interrupt handler only to generate | |
2657 | * another one. | |
2658 | * | |
2659 | * Note that for MSI this could cause a stray interrupt report | |
2660 | * if an interrupt landed in the time between writing IIR and | |
2661 | * the posting read. This should be rare enough to never | |
2662 | * trigger the 99% of 100,000 interrupts test for disabling | |
2663 | * stray interrupts. | |
2664 | */ | |
38bde180 | 2665 | ret = IRQ_HANDLED; |
a266c7d5 | 2666 | iir = new_iir; |
38bde180 | 2667 | } while (iir & ~flip_mask); |
a266c7d5 | 2668 | |
d05c617e | 2669 | i915_update_dri1_breadcrumb(dev); |
8291ee90 | 2670 | |
a266c7d5 CW |
2671 | return ret; |
2672 | } | |
2673 | ||
2674 | static void i915_irq_uninstall(struct drm_device * dev) | |
2675 | { | |
2676 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; | |
2677 | int pipe; | |
2678 | ||
ac4c16c5 EE |
2679 | del_timer_sync(&dev_priv->hotplug_reenable_timer); |
2680 | ||
a266c7d5 CW |
2681 | if (I915_HAS_HOTPLUG(dev)) { |
2682 | I915_WRITE(PORT_HOTPLUG_EN, 0); | |
2683 | I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); | |
2684 | } | |
2685 | ||
00d98ebd | 2686 | I915_WRITE16(HWSTAM, 0xffff); |
55b39755 CW |
2687 | for_each_pipe(pipe) { |
2688 | /* Clear enable bits; then clear status bits */ | |
a266c7d5 | 2689 | I915_WRITE(PIPESTAT(pipe), 0); |
55b39755 CW |
2690 | I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe))); |
2691 | } | |
a266c7d5 CW |
2692 | I915_WRITE(IMR, 0xffffffff); |
2693 | I915_WRITE(IER, 0x0); | |
2694 | ||
a266c7d5 CW |
2695 | I915_WRITE(IIR, I915_READ(IIR)); |
2696 | } | |
2697 | ||
2698 | static void i965_irq_preinstall(struct drm_device * dev) | |
2699 | { | |
2700 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; | |
2701 | int pipe; | |
2702 | ||
2703 | atomic_set(&dev_priv->irq_received, 0); | |
2704 | ||
adca4730 CW |
2705 | I915_WRITE(PORT_HOTPLUG_EN, 0); |
2706 | I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); | |
a266c7d5 CW |
2707 | |
2708 | I915_WRITE(HWSTAM, 0xeffe); | |
2709 | for_each_pipe(pipe) | |
2710 | I915_WRITE(PIPESTAT(pipe), 0); | |
2711 | I915_WRITE(IMR, 0xffffffff); | |
2712 | I915_WRITE(IER, 0x0); | |
2713 | POSTING_READ(IER); | |
2714 | } | |
2715 | ||
2716 | static int i965_irq_postinstall(struct drm_device *dev) | |
2717 | { | |
2718 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; | |
bbba0a97 | 2719 | u32 enable_mask; |
a266c7d5 | 2720 | u32 error_mask; |
b79480ba | 2721 | unsigned long irqflags; |
a266c7d5 | 2722 | |
a266c7d5 | 2723 | /* Unmask the interrupts that we always want on. */ |
bbba0a97 | 2724 | dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT | |
adca4730 | 2725 | I915_DISPLAY_PORT_INTERRUPT | |
bbba0a97 CW |
2726 | I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | |
2727 | I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | | |
2728 | I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | | |
2729 | I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT | | |
2730 | I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); | |
2731 | ||
2732 | enable_mask = ~dev_priv->irq_mask; | |
21ad8330 VS |
2733 | enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | |
2734 | I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT); | |
bbba0a97 CW |
2735 | enable_mask |= I915_USER_INTERRUPT; |
2736 | ||
2737 | if (IS_G4X(dev)) | |
2738 | enable_mask |= I915_BSD_USER_INTERRUPT; | |
a266c7d5 | 2739 | |
b79480ba DV |
2740 | /* Interrupt setup is already guaranteed to be single-threaded, this is |
2741 | * just to make the assert_spin_locked check happy. */ | |
2742 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); | |
515ac2bb | 2743 | i915_enable_pipestat(dev_priv, 0, PIPE_GMBUS_EVENT_ENABLE); |
b79480ba | 2744 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
a266c7d5 | 2745 | |
a266c7d5 CW |
2746 | /* |
2747 | * Enable some error detection, note the instruction error mask | |
2748 | * bit is reserved, so we leave it masked. | |
2749 | */ | |
2750 | if (IS_G4X(dev)) { | |
2751 | error_mask = ~(GM45_ERROR_PAGE_TABLE | | |
2752 | GM45_ERROR_MEM_PRIV | | |
2753 | GM45_ERROR_CP_PRIV | | |
2754 | I915_ERROR_MEMORY_REFRESH); | |
2755 | } else { | |
2756 | error_mask = ~(I915_ERROR_PAGE_TABLE | | |
2757 | I915_ERROR_MEMORY_REFRESH); | |
2758 | } | |
2759 | I915_WRITE(EMR, error_mask); | |
2760 | ||
2761 | I915_WRITE(IMR, dev_priv->irq_mask); | |
2762 | I915_WRITE(IER, enable_mask); | |
2763 | POSTING_READ(IER); | |
2764 | ||
20afbda2 DV |
2765 | I915_WRITE(PORT_HOTPLUG_EN, 0); |
2766 | POSTING_READ(PORT_HOTPLUG_EN); | |
2767 | ||
f49e38dd | 2768 | i915_enable_asle_pipestat(dev); |
20afbda2 DV |
2769 | |
2770 | return 0; | |
2771 | } | |
2772 | ||
bac56d5b | 2773 | static void i915_hpd_irq_setup(struct drm_device *dev) |
20afbda2 DV |
2774 | { |
2775 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; | |
e5868a31 | 2776 | struct drm_mode_config *mode_config = &dev->mode_config; |
cd569aed | 2777 | struct intel_encoder *intel_encoder; |
20afbda2 DV |
2778 | u32 hotplug_en; |
2779 | ||
b5ea2d56 DV |
2780 | assert_spin_locked(&dev_priv->irq_lock); |
2781 | ||
bac56d5b EE |
2782 | if (I915_HAS_HOTPLUG(dev)) { |
2783 | hotplug_en = I915_READ(PORT_HOTPLUG_EN); | |
2784 | hotplug_en &= ~HOTPLUG_INT_EN_MASK; | |
2785 | /* Note HDMI and DP share hotplug bits */ | |
e5868a31 | 2786 | /* enable bits are the same for all generations */ |
cd569aed EE |
2787 | list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head) |
2788 | if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED) | |
2789 | hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin]; | |
bac56d5b EE |
2790 | /* Programming the CRT detection parameters tends |
2791 | to generate a spurious hotplug event about three | |
2792 | seconds later. So just do it once. | |
2793 | */ | |
2794 | if (IS_G4X(dev)) | |
2795 | hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64; | |
85fc95ba | 2796 | hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK; |
bac56d5b | 2797 | hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50; |
a266c7d5 | 2798 | |
bac56d5b EE |
2799 | /* Ignore TV since it's buggy */ |
2800 | I915_WRITE(PORT_HOTPLUG_EN, hotplug_en); | |
2801 | } | |
a266c7d5 CW |
2802 | } |
2803 | ||
ff1f525e | 2804 | static irqreturn_t i965_irq_handler(int irq, void *arg) |
a266c7d5 CW |
2805 | { |
2806 | struct drm_device *dev = (struct drm_device *) arg; | |
2807 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; | |
a266c7d5 CW |
2808 | u32 iir, new_iir; |
2809 | u32 pipe_stats[I915_MAX_PIPES]; | |
a266c7d5 CW |
2810 | unsigned long irqflags; |
2811 | int irq_received; | |
2812 | int ret = IRQ_NONE, pipe; | |
21ad8330 VS |
2813 | u32 flip_mask = |
2814 | I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | | |
2815 | I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT; | |
a266c7d5 CW |
2816 | |
2817 | atomic_inc(&dev_priv->irq_received); | |
2818 | ||
2819 | iir = I915_READ(IIR); | |
2820 | ||
a266c7d5 | 2821 | for (;;) { |
2c8ba29f CW |
2822 | bool blc_event = false; |
2823 | ||
21ad8330 | 2824 | irq_received = (iir & ~flip_mask) != 0; |
a266c7d5 CW |
2825 | |
2826 | /* Can't rely on pipestat interrupt bit in iir as it might | |
2827 | * have been cleared after the pipestat interrupt was received. | |
2828 | * It doesn't set the bit in iir again, but it still produces | |
2829 | * interrupts (for non-MSI). | |
2830 | */ | |
2831 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); | |
2832 | if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) | |
2833 | i915_handle_error(dev, false); | |
2834 | ||
2835 | for_each_pipe(pipe) { | |
2836 | int reg = PIPESTAT(pipe); | |
2837 | pipe_stats[pipe] = I915_READ(reg); | |
2838 | ||
2839 | /* | |
2840 | * Clear the PIPE*STAT regs before the IIR | |
2841 | */ | |
2842 | if (pipe_stats[pipe] & 0x8000ffff) { | |
2843 | if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) | |
2844 | DRM_DEBUG_DRIVER("pipe %c underrun\n", | |
2845 | pipe_name(pipe)); | |
2846 | I915_WRITE(reg, pipe_stats[pipe]); | |
2847 | irq_received = 1; | |
2848 | } | |
2849 | } | |
2850 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); | |
2851 | ||
2852 | if (!irq_received) | |
2853 | break; | |
2854 | ||
2855 | ret = IRQ_HANDLED; | |
2856 | ||
2857 | /* Consume port. Then clear IIR or we'll miss events */ | |
adca4730 | 2858 | if (iir & I915_DISPLAY_PORT_INTERRUPT) { |
a266c7d5 | 2859 | u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT); |
b543fb04 EE |
2860 | u32 hotplug_trigger = hotplug_status & (IS_G4X(dev) ? |
2861 | HOTPLUG_INT_STATUS_G4X : | |
4f7fd709 | 2862 | HOTPLUG_INT_STATUS_I915); |
a266c7d5 CW |
2863 | |
2864 | DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n", | |
2865 | hotplug_status); | |
91d131d2 DV |
2866 | |
2867 | intel_hpd_irq_handler(dev, hotplug_trigger, | |
2868 | IS_G4X(dev) ? hpd_status_gen4 : hpd_status_i915); | |
2869 | ||
a266c7d5 CW |
2870 | I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status); |
2871 | I915_READ(PORT_HOTPLUG_STAT); | |
2872 | } | |
2873 | ||
21ad8330 | 2874 | I915_WRITE(IIR, iir & ~flip_mask); |
a266c7d5 CW |
2875 | new_iir = I915_READ(IIR); /* Flush posted writes */ |
2876 | ||
a266c7d5 CW |
2877 | if (iir & I915_USER_INTERRUPT) |
2878 | notify_ring(dev, &dev_priv->ring[RCS]); | |
2879 | if (iir & I915_BSD_USER_INTERRUPT) | |
2880 | notify_ring(dev, &dev_priv->ring[VCS]); | |
2881 | ||
a266c7d5 | 2882 | for_each_pipe(pipe) { |
2c8ba29f | 2883 | if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS && |
90a72f87 VS |
2884 | i915_handle_vblank(dev, pipe, pipe, iir)) |
2885 | flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe); | |
a266c7d5 CW |
2886 | |
2887 | if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS) | |
2888 | blc_event = true; | |
2889 | } | |
2890 | ||
2891 | ||
2892 | if (blc_event || (iir & I915_ASLE_INTERRUPT)) | |
2893 | intel_opregion_asle_intr(dev); | |
2894 | ||
515ac2bb DV |
2895 | if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS) |
2896 | gmbus_irq_handler(dev); | |
2897 | ||
a266c7d5 CW |
2898 | /* With MSI, interrupts are only generated when iir |
2899 | * transitions from zero to nonzero. If another bit got | |
2900 | * set while we were handling the existing iir bits, then | |
2901 | * we would never get another interrupt. | |
2902 | * | |
2903 | * This is fine on non-MSI as well, as if we hit this path | |
2904 | * we avoid exiting the interrupt handler only to generate | |
2905 | * another one. | |
2906 | * | |
2907 | * Note that for MSI this could cause a stray interrupt report | |
2908 | * if an interrupt landed in the time between writing IIR and | |
2909 | * the posting read. This should be rare enough to never | |
2910 | * trigger the 99% of 100,000 interrupts test for disabling | |
2911 | * stray interrupts. | |
2912 | */ | |
2913 | iir = new_iir; | |
2914 | } | |
2915 | ||
d05c617e | 2916 | i915_update_dri1_breadcrumb(dev); |
2c8ba29f | 2917 | |
a266c7d5 CW |
2918 | return ret; |
2919 | } | |
2920 | ||
2921 | static void i965_irq_uninstall(struct drm_device * dev) | |
2922 | { | |
2923 | drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; | |
2924 | int pipe; | |
2925 | ||
2926 | if (!dev_priv) | |
2927 | return; | |
2928 | ||
ac4c16c5 EE |
2929 | del_timer_sync(&dev_priv->hotplug_reenable_timer); |
2930 | ||
adca4730 CW |
2931 | I915_WRITE(PORT_HOTPLUG_EN, 0); |
2932 | I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); | |
a266c7d5 CW |
2933 | |
2934 | I915_WRITE(HWSTAM, 0xffffffff); | |
2935 | for_each_pipe(pipe) | |
2936 | I915_WRITE(PIPESTAT(pipe), 0); | |
2937 | I915_WRITE(IMR, 0xffffffff); | |
2938 | I915_WRITE(IER, 0x0); | |
2939 | ||
2940 | for_each_pipe(pipe) | |
2941 | I915_WRITE(PIPESTAT(pipe), | |
2942 | I915_READ(PIPESTAT(pipe)) & 0x8000ffff); | |
2943 | I915_WRITE(IIR, I915_READ(IIR)); | |
2944 | } | |
2945 | ||
ac4c16c5 EE |
2946 | static void i915_reenable_hotplug_timer_func(unsigned long data) |
2947 | { | |
2948 | drm_i915_private_t *dev_priv = (drm_i915_private_t *)data; | |
2949 | struct drm_device *dev = dev_priv->dev; | |
2950 | struct drm_mode_config *mode_config = &dev->mode_config; | |
2951 | unsigned long irqflags; | |
2952 | int i; | |
2953 | ||
2954 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); | |
2955 | for (i = (HPD_NONE + 1); i < HPD_NUM_PINS; i++) { | |
2956 | struct drm_connector *connector; | |
2957 | ||
2958 | if (dev_priv->hpd_stats[i].hpd_mark != HPD_DISABLED) | |
2959 | continue; | |
2960 | ||
2961 | dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED; | |
2962 | ||
2963 | list_for_each_entry(connector, &mode_config->connector_list, head) { | |
2964 | struct intel_connector *intel_connector = to_intel_connector(connector); | |
2965 | ||
2966 | if (intel_connector->encoder->hpd_pin == i) { | |
2967 | if (connector->polled != intel_connector->polled) | |
2968 | DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n", | |
2969 | drm_get_connector_name(connector)); | |
2970 | connector->polled = intel_connector->polled; | |
2971 | if (!connector->polled) | |
2972 | connector->polled = DRM_CONNECTOR_POLL_HPD; | |
2973 | } | |
2974 | } | |
2975 | } | |
2976 | if (dev_priv->display.hpd_irq_setup) | |
2977 | dev_priv->display.hpd_irq_setup(dev); | |
2978 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); | |
2979 | } | |
2980 | ||
f71d4af4 JB |
2981 | void intel_irq_init(struct drm_device *dev) |
2982 | { | |
8b2e326d CW |
2983 | struct drm_i915_private *dev_priv = dev->dev_private; |
2984 | ||
2985 | INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func); | |
99584db3 | 2986 | INIT_WORK(&dev_priv->gpu_error.work, i915_error_work_func); |
c6a828d3 | 2987 | INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work); |
a4da4fa4 | 2988 | INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work); |
8b2e326d | 2989 | |
99584db3 DV |
2990 | setup_timer(&dev_priv->gpu_error.hangcheck_timer, |
2991 | i915_hangcheck_elapsed, | |
61bac78e | 2992 | (unsigned long) dev); |
ac4c16c5 EE |
2993 | setup_timer(&dev_priv->hotplug_reenable_timer, i915_reenable_hotplug_timer_func, |
2994 | (unsigned long) dev_priv); | |
61bac78e | 2995 | |
97a19a24 | 2996 | pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE); |
9ee32fea | 2997 | |
f71d4af4 JB |
2998 | dev->driver->get_vblank_counter = i915_get_vblank_counter; |
2999 | dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */ | |
7d4e146f | 3000 | if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) { |
f71d4af4 JB |
3001 | dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */ |
3002 | dev->driver->get_vblank_counter = gm45_get_vblank_counter; | |
3003 | } | |
3004 | ||
c3613de9 KP |
3005 | if (drm_core_check_feature(dev, DRIVER_MODESET)) |
3006 | dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp; | |
3007 | else | |
3008 | dev->driver->get_vblank_timestamp = NULL; | |
f71d4af4 JB |
3009 | dev->driver->get_scanout_position = i915_get_crtc_scanoutpos; |
3010 | ||
7e231dbe JB |
3011 | if (IS_VALLEYVIEW(dev)) { |
3012 | dev->driver->irq_handler = valleyview_irq_handler; | |
3013 | dev->driver->irq_preinstall = valleyview_irq_preinstall; | |
3014 | dev->driver->irq_postinstall = valleyview_irq_postinstall; | |
3015 | dev->driver->irq_uninstall = valleyview_irq_uninstall; | |
3016 | dev->driver->enable_vblank = valleyview_enable_vblank; | |
3017 | dev->driver->disable_vblank = valleyview_disable_vblank; | |
fa00abe0 | 3018 | dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup; |
f71d4af4 JB |
3019 | } else if (HAS_PCH_SPLIT(dev)) { |
3020 | dev->driver->irq_handler = ironlake_irq_handler; | |
3021 | dev->driver->irq_preinstall = ironlake_irq_preinstall; | |
3022 | dev->driver->irq_postinstall = ironlake_irq_postinstall; | |
3023 | dev->driver->irq_uninstall = ironlake_irq_uninstall; | |
3024 | dev->driver->enable_vblank = ironlake_enable_vblank; | |
3025 | dev->driver->disable_vblank = ironlake_disable_vblank; | |
82a28bcf | 3026 | dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup; |
f71d4af4 | 3027 | } else { |
c2798b19 CW |
3028 | if (INTEL_INFO(dev)->gen == 2) { |
3029 | dev->driver->irq_preinstall = i8xx_irq_preinstall; | |
3030 | dev->driver->irq_postinstall = i8xx_irq_postinstall; | |
3031 | dev->driver->irq_handler = i8xx_irq_handler; | |
3032 | dev->driver->irq_uninstall = i8xx_irq_uninstall; | |
a266c7d5 CW |
3033 | } else if (INTEL_INFO(dev)->gen == 3) { |
3034 | dev->driver->irq_preinstall = i915_irq_preinstall; | |
3035 | dev->driver->irq_postinstall = i915_irq_postinstall; | |
3036 | dev->driver->irq_uninstall = i915_irq_uninstall; | |
3037 | dev->driver->irq_handler = i915_irq_handler; | |
20afbda2 | 3038 | dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup; |
c2798b19 | 3039 | } else { |
a266c7d5 CW |
3040 | dev->driver->irq_preinstall = i965_irq_preinstall; |
3041 | dev->driver->irq_postinstall = i965_irq_postinstall; | |
3042 | dev->driver->irq_uninstall = i965_irq_uninstall; | |
3043 | dev->driver->irq_handler = i965_irq_handler; | |
bac56d5b | 3044 | dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup; |
c2798b19 | 3045 | } |
f71d4af4 JB |
3046 | dev->driver->enable_vblank = i915_enable_vblank; |
3047 | dev->driver->disable_vblank = i915_disable_vblank; | |
3048 | } | |
3049 | } | |
20afbda2 DV |
3050 | |
3051 | void intel_hpd_init(struct drm_device *dev) | |
3052 | { | |
3053 | struct drm_i915_private *dev_priv = dev->dev_private; | |
821450c6 EE |
3054 | struct drm_mode_config *mode_config = &dev->mode_config; |
3055 | struct drm_connector *connector; | |
b5ea2d56 | 3056 | unsigned long irqflags; |
821450c6 | 3057 | int i; |
20afbda2 | 3058 | |
821450c6 EE |
3059 | for (i = 1; i < HPD_NUM_PINS; i++) { |
3060 | dev_priv->hpd_stats[i].hpd_cnt = 0; | |
3061 | dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED; | |
3062 | } | |
3063 | list_for_each_entry(connector, &mode_config->connector_list, head) { | |
3064 | struct intel_connector *intel_connector = to_intel_connector(connector); | |
3065 | connector->polled = intel_connector->polled; | |
3066 | if (!connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE) | |
3067 | connector->polled = DRM_CONNECTOR_POLL_HPD; | |
3068 | } | |
b5ea2d56 DV |
3069 | |
3070 | /* Interrupt setup is already guaranteed to be single-threaded, this is | |
3071 | * just to make the assert_spin_locked checks happy. */ | |
3072 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); | |
20afbda2 DV |
3073 | if (dev_priv->display.hpd_irq_setup) |
3074 | dev_priv->display.hpd_irq_setup(dev); | |
b5ea2d56 | 3075 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
20afbda2 | 3076 | } |