1 /* i915_irq.c -- IRQ support for the I915 -*- linux-c -*-
4 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
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.
29 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31 #include <linux/sysrq.h>
32 #include <linux/slab.h>
34 #include <drm/i915_drm.h>
36 #include "i915_trace.h"
37 #include "intel_drv.h"
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
47 static const u32 hpd_cpt
[] = {
48 [HPD_CRT
] = SDE_CRT_HOTPLUG_CPT
,
49 [HPD_SDVO_B
] = SDE_SDVOB_HOTPLUG_CPT
,
50 [HPD_PORT_B
] = SDE_PORTB_HOTPLUG_CPT
,
51 [HPD_PORT_C
] = SDE_PORTC_HOTPLUG_CPT
,
52 [HPD_PORT_D
] = SDE_PORTD_HOTPLUG_CPT
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
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
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
82 /* For display hotplug interrupt */
84 ironlake_enable_display_irq(drm_i915_private_t
*dev_priv
, u32 mask
)
86 assert_spin_locked(&dev_priv
->irq_lock
);
88 if ((dev_priv
->irq_mask
& mask
) != 0) {
89 dev_priv
->irq_mask
&= ~mask
;
90 I915_WRITE(DEIMR
, dev_priv
->irq_mask
);
96 ironlake_disable_display_irq(drm_i915_private_t
*dev_priv
, u32 mask
)
98 assert_spin_locked(&dev_priv
->irq_lock
);
100 if ((dev_priv
->irq_mask
& mask
) != mask
) {
101 dev_priv
->irq_mask
|= mask
;
102 I915_WRITE(DEIMR
, dev_priv
->irq_mask
);
107 static bool ivb_can_enable_err_int(struct drm_device
*dev
)
109 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
110 struct intel_crtc
*crtc
;
113 assert_spin_locked(&dev_priv
->irq_lock
);
115 for_each_pipe(pipe
) {
116 crtc
= to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
118 if (crtc
->cpu_fifo_underrun_disabled
)
125 static bool cpt_can_enable_serr_int(struct drm_device
*dev
)
127 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
129 struct intel_crtc
*crtc
;
131 assert_spin_locked(&dev_priv
->irq_lock
);
133 for_each_pipe(pipe
) {
134 crtc
= to_intel_crtc(dev_priv
->pipe_to_crtc_mapping
[pipe
]);
136 if (crtc
->pch_fifo_underrun_disabled
)
143 static void ironlake_set_fifo_underrun_reporting(struct drm_device
*dev
,
144 enum pipe pipe
, bool enable
)
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
;
151 ironlake_enable_display_irq(dev_priv
, bit
);
153 ironlake_disable_display_irq(dev_priv
, bit
);
156 static void ivybridge_set_fifo_underrun_reporting(struct drm_device
*dev
,
157 enum pipe pipe
, bool enable
)
159 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
161 I915_WRITE(GEN7_ERR_INT
, ERR_INT_FIFO_UNDERRUN(pipe
));
163 if (!ivb_can_enable_err_int(dev
))
166 ironlake_enable_display_irq(dev_priv
, DE_ERR_INT_IVB
);
168 bool was_enabled
= !(I915_READ(DEIMR
) & DE_ERR_INT_IVB
);
170 /* Change the state _after_ we've read out the current one. */
171 ironlake_disable_display_irq(dev_priv
, DE_ERR_INT_IVB
);
174 (I915_READ(GEN7_ERR_INT
) & ERR_INT_FIFO_UNDERRUN(pipe
))) {
175 DRM_DEBUG_KMS("uncleared fifo underrun on pipe %c\n",
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
187 static void ibx_display_interrupt_update(struct drm_i915_private
*dev_priv
,
188 uint32_t interrupt_mask
,
189 uint32_t enabled_irq_mask
)
191 uint32_t sdeimr
= I915_READ(SDEIMR
);
192 sdeimr
&= ~interrupt_mask
;
193 sdeimr
|= (~enabled_irq_mask
& interrupt_mask
);
195 assert_spin_locked(&dev_priv
->irq_lock
);
197 I915_WRITE(SDEIMR
, sdeimr
);
198 POSTING_READ(SDEIMR
);
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)
205 static void ibx_set_fifo_underrun_reporting(struct drm_device
*dev
,
206 enum transcoder pch_transcoder
,
209 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
210 uint32_t bit
= (pch_transcoder
== TRANSCODER_A
) ?
211 SDE_TRANSA_FIFO_UNDER
: SDE_TRANSB_FIFO_UNDER
;
214 ibx_enable_display_interrupt(dev_priv
, bit
);
216 ibx_disable_display_interrupt(dev_priv
, bit
);
219 static void cpt_set_fifo_underrun_reporting(struct drm_device
*dev
,
220 enum transcoder pch_transcoder
,
223 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
227 SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder
));
229 if (!cpt_can_enable_serr_int(dev
))
232 ibx_enable_display_interrupt(dev_priv
, SDE_ERROR_CPT
);
234 uint32_t tmp
= I915_READ(SERR_INT
);
235 bool was_enabled
= !(I915_READ(SDEIMR
) & SDE_ERROR_CPT
);
237 /* Change the state _after_ we've read out the current one. */
238 ibx_disable_display_interrupt(dev_priv
, SDE_ERROR_CPT
);
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
));
249 * intel_set_cpu_fifo_underrun_reporting - enable/disable FIFO underrun messages
252 * @enable: true if we want to report FIFO underrun errors, false otherwise
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.
260 * Returns the previous state of underrun reporting.
262 bool intel_set_cpu_fifo_underrun_reporting(struct drm_device
*dev
,
263 enum pipe pipe
, bool enable
)
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
);
271 spin_lock_irqsave(&dev_priv
->irq_lock
, flags
);
273 ret
= !intel_crtc
->cpu_fifo_underrun_disabled
;
278 intel_crtc
->cpu_fifo_underrun_disabled
= !enable
;
280 if (IS_GEN5(dev
) || IS_GEN6(dev
))
281 ironlake_set_fifo_underrun_reporting(dev
, pipe
, enable
);
282 else if (IS_GEN7(dev
))
283 ivybridge_set_fifo_underrun_reporting(dev
, pipe
, enable
);
286 spin_unlock_irqrestore(&dev_priv
->irq_lock
, flags
);
291 * intel_set_pch_fifo_underrun_reporting - enable/disable FIFO underrun messages
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
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.
302 * Returns the previous state of underrun reporting.
304 bool intel_set_pch_fifo_underrun_reporting(struct drm_device
*dev
,
305 enum transcoder pch_transcoder
,
308 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
309 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pch_transcoder
];
310 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
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.
323 spin_lock_irqsave(&dev_priv
->irq_lock
, flags
);
325 ret
= !intel_crtc
->pch_fifo_underrun_disabled
;
330 intel_crtc
->pch_fifo_underrun_disabled
= !enable
;
332 if (HAS_PCH_IBX(dev
))
333 ibx_set_fifo_underrun_reporting(dev
, pch_transcoder
, enable
);
335 cpt_set_fifo_underrun_reporting(dev
, pch_transcoder
, enable
);
338 spin_unlock_irqrestore(&dev_priv
->irq_lock
, flags
);
344 i915_enable_pipestat(drm_i915_private_t
*dev_priv
, int pipe
, u32 mask
)
346 u32 reg
= PIPESTAT(pipe
);
347 u32 pipestat
= I915_READ(reg
) & 0x7fff0000;
349 assert_spin_locked(&dev_priv
->irq_lock
);
351 if ((pipestat
& mask
) == mask
)
354 /* Enable the interrupt, clear any pending status */
355 pipestat
|= mask
| (mask
>> 16);
356 I915_WRITE(reg
, pipestat
);
361 i915_disable_pipestat(drm_i915_private_t
*dev_priv
, int pipe
, u32 mask
)
363 u32 reg
= PIPESTAT(pipe
);
364 u32 pipestat
= I915_READ(reg
) & 0x7fff0000;
366 assert_spin_locked(&dev_priv
->irq_lock
);
368 if ((pipestat
& mask
) == 0)
372 I915_WRITE(reg
, pipestat
);
377 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
379 static void i915_enable_asle_pipestat(struct drm_device
*dev
)
381 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
382 unsigned long irqflags
;
384 if (!dev_priv
->opregion
.asle
|| !IS_MOBILE(dev
))
387 spin_lock_irqsave(&dev_priv
->irq_lock
, irqflags
);
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
);
393 spin_unlock_irqrestore(&dev_priv
->irq_lock
, irqflags
);
397 * i915_pipe_enabled - check if a pipe is enabled
399 * @pipe: pipe to check
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.
406 i915_pipe_enabled(struct drm_device
*dev
, int pipe
)
408 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
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
);
415 return intel_crtc
->active
;
417 return I915_READ(PIPECONF(pipe
)) & PIPECONF_ENABLE
;
421 /* Called from drm generic code, passed a 'crtc', which
422 * we use as a pipe index
424 static u32
i915_get_vblank_counter(struct drm_device
*dev
, int pipe
)
426 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
427 unsigned long high_frame
;
428 unsigned long low_frame
;
429 u32 high1
, high2
, low
;
431 if (!i915_pipe_enabled(dev
, pipe
)) {
432 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
433 "pipe %c\n", pipe_name(pipe
));
437 high_frame
= PIPEFRAME(pipe
);
438 low_frame
= PIPEFRAMEPIXEL(pipe
);
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
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
;
449 } while (high1
!= high2
);
451 high1
>>= PIPE_FRAME_HIGH_SHIFT
;
452 low
>>= PIPE_FRAME_LOW_SHIFT
;
453 return (high1
<< 8) | low
;
456 static u32
gm45_get_vblank_counter(struct drm_device
*dev
, int pipe
)
458 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
459 int reg
= PIPE_FRMCOUNT_GM45(pipe
);
461 if (!i915_pipe_enabled(dev
, pipe
)) {
462 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
463 "pipe %c\n", pipe_name(pipe
));
467 return I915_READ(reg
);
470 static int i915_get_crtc_scanoutpos(struct drm_device
*dev
, int pipe
,
471 int *vpos
, int *hpos
)
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
;
478 enum transcoder cpu_transcoder
= intel_pipe_to_cpu_transcoder(dev_priv
,
481 if (!i915_pipe_enabled(dev
, pipe
)) {
482 DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
483 "pipe %c\n", pipe_name(pipe
));
488 vtotal
= 1 + ((I915_READ(VTOTAL(cpu_transcoder
)) >> 16) & 0x1fff);
490 if (INTEL_INFO(dev
)->gen
>= 4) {
491 /* No obvious pixelcount register. Only query vertical
492 * scanout position from Display scan line register.
494 position
= I915_READ(PIPEDSL(pipe
));
496 /* Decode into vertical scanout position. Don't have
497 * horizontal scanout position.
499 *vpos
= position
& 0x1fff;
502 /* Have access to pixelcount since start of frame.
503 * We can split this into vertical and horizontal
506 position
= (I915_READ(PIPEFRAMEPIXEL(pipe
)) & PIPE_PIXEL_MASK
) >> PIPE_PIXEL_SHIFT
;
508 htotal
= 1 + ((I915_READ(HTOTAL(cpu_transcoder
)) >> 16) & 0x1fff);
509 *vpos
= position
/ htotal
;
510 *hpos
= position
- (*vpos
* htotal
);
513 /* Query vblank area. */
514 vbl
= I915_READ(VBLANK(cpu_transcoder
));
516 /* Test position against vblank region. */
517 vbl_start
= vbl
& 0x1fff;
518 vbl_end
= (vbl
>> 16) & 0x1fff;
520 if ((*vpos
< vbl_start
) || (*vpos
> vbl_end
))
523 /* Inside "upper part" of vblank area? Apply corrective offset: */
524 if (in_vbl
&& (*vpos
>= vbl_start
))
525 *vpos
= *vpos
- vtotal
;
527 /* Readouts valid? */
529 ret
|= DRM_SCANOUTPOS_VALID
| DRM_SCANOUTPOS_ACCURATE
;
533 ret
|= DRM_SCANOUTPOS_INVBL
;
538 static int i915_get_vblank_timestamp(struct drm_device
*dev
, int pipe
,
540 struct timeval
*vblank_time
,
543 struct drm_crtc
*crtc
;
545 if (pipe
< 0 || pipe
>= INTEL_INFO(dev
)->num_pipes
) {
546 DRM_ERROR("Invalid crtc %d\n", pipe
);
550 /* Get drm_crtc to timestamp: */
551 crtc
= intel_get_crtc_for_pipe(dev
, pipe
);
553 DRM_ERROR("Invalid crtc %d\n", pipe
);
557 if (!crtc
->enabled
) {
558 DRM_DEBUG_KMS("crtc %d is disabled\n", pipe
);
562 /* Helper routine in DRM core does all the work: */
563 return drm_calc_vbltimestamp_from_scanoutpos(dev
, pipe
, max_error
,
568 static int intel_hpd_irq_event(struct drm_device
*dev
, struct drm_connector
*connector
)
570 enum drm_connector_status old_status
;
572 WARN_ON(!mutex_is_locked(&dev
->mode_config
.mutex
));
573 old_status
= connector
->status
;
575 connector
->status
= connector
->funcs
->detect(connector
, false);
576 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %d to %d\n",
578 drm_get_connector_name(connector
),
579 old_status
, connector
->status
);
580 return (old_status
!= connector
->status
);
584 * Handle hotplug events outside the interrupt handler proper.
586 #define I915_REENABLE_HOTPLUG_DELAY (2*60*1000)
588 static void i915_hotplug_work_func(struct work_struct
*work
)
590 drm_i915_private_t
*dev_priv
= container_of(work
, drm_i915_private_t
,
592 struct drm_device
*dev
= dev_priv
->dev
;
593 struct drm_mode_config
*mode_config
= &dev
->mode_config
;
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;
599 bool changed
= false;
602 /* HPD irq before everything is fully set up. */
603 if (!dev_priv
->enable_hotplug_processing
)
606 mutex_lock(&mode_config
->mutex
);
607 DRM_DEBUG_KMS("running encoder hotplug functions\n");
609 spin_lock_irqsave(&dev_priv
->irq_lock
, irqflags
);
611 hpd_event_bits
= dev_priv
->hpd_event_bits
;
612 dev_priv
->hpd_event_bits
= 0;
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
;
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
);
632 /* if there were no outputs to poll, poll was disabled,
633 * therefore make sure it's enabled when disabling HPD on
636 drm_kms_helper_poll_enable(dev
);
637 mod_timer(&dev_priv
->hotplug_reenable_timer
,
638 jiffies
+ msecs_to_jiffies(I915_REENABLE_HOTPLUG_DELAY
));
641 spin_unlock_irqrestore(&dev_priv
->irq_lock
, irqflags
);
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
))
653 mutex_unlock(&mode_config
->mutex
);
656 drm_kms_helper_hotplug_event(dev
);
659 static void ironlake_rps_change_irq_handler(struct drm_device
*dev
)
661 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
662 u32 busy_up
, busy_down
, max_avg
, min_avg
;
665 spin_lock(&mchdev_lock
);
667 I915_WRITE16(MEMINTRSTS
, I915_READ(MEMINTRSTS
));
669 new_delay
= dev_priv
->ips
.cur_delay
;
671 I915_WRITE16(MEMINTRSTS
, MEMINT_EVAL_CHG
);
672 busy_up
= I915_READ(RCPREVBSYTUPAVG
);
673 busy_down
= I915_READ(RCPREVBSYTDNAVG
);
674 max_avg
= I915_READ(RCBMAXAVG
);
675 min_avg
= I915_READ(RCBMINAVG
);
677 /* Handle RCS change request from hw */
678 if (busy_up
> max_avg
) {
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
;
683 } else if (busy_down
< min_avg
) {
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
;
690 if (ironlake_set_drps(dev
, new_delay
))
691 dev_priv
->ips
.cur_delay
= new_delay
;
693 spin_unlock(&mchdev_lock
);
698 static void notify_ring(struct drm_device
*dev
,
699 struct intel_ring_buffer
*ring
)
701 if (ring
->obj
== NULL
)
704 trace_i915_gem_request_complete(ring
, ring
->get_seqno(ring
, false));
706 wake_up_all(&ring
->irq_queue
);
707 i915_queue_hangcheck(dev
);
710 static void gen6_pm_rps_work(struct work_struct
*work
)
712 drm_i915_private_t
*dev_priv
= container_of(work
, drm_i915_private_t
,
717 spin_lock_irq(&dev_priv
->irq_lock
);
718 pm_iir
= dev_priv
->rps
.pm_iir
;
719 dev_priv
->rps
.pm_iir
= 0;
720 pm_imr
= I915_READ(GEN6_PMIMR
);
721 /* Make sure not to corrupt PMIMR state used by ringbuffer code */
722 I915_WRITE(GEN6_PMIMR
, pm_imr
& ~GEN6_PM_RPS_EVENTS
);
723 spin_unlock_irq(&dev_priv
->irq_lock
);
725 if ((pm_iir
& GEN6_PM_RPS_EVENTS
) == 0)
728 mutex_lock(&dev_priv
->rps
.hw_lock
);
730 if (pm_iir
& GEN6_PM_RP_UP_THRESHOLD
) {
731 new_delay
= dev_priv
->rps
.cur_delay
+ 1;
734 * For better performance, jump directly
735 * to RPe if we're below it.
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
;
741 new_delay
= dev_priv
->rps
.cur_delay
- 1;
743 /* sysfs frequency interfaces may have snuck in while servicing the
746 if (new_delay
>= dev_priv
->rps
.min_delay
&&
747 new_delay
<= dev_priv
->rps
.max_delay
) {
748 if (IS_VALLEYVIEW(dev_priv
->dev
))
749 valleyview_set_rps(dev_priv
->dev
, new_delay
);
751 gen6_set_rps(dev_priv
->dev
, new_delay
);
754 if (IS_VALLEYVIEW(dev_priv
->dev
)) {
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.
761 mod_delayed_work(dev_priv
->wq
, &dev_priv
->rps
.vlv_work
,
762 msecs_to_jiffies(100));
765 mutex_unlock(&dev_priv
->rps
.hw_lock
);
770 * ivybridge_parity_work - Workqueue called when a parity error interrupt
772 * @work: workqueue struct
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.
778 static void ivybridge_parity_work(struct work_struct
*work
)
780 drm_i915_private_t
*dev_priv
= container_of(work
, drm_i915_private_t
,
781 l3_parity
.error_work
);
782 u32 error_status
, row
, bank
, subbank
;
783 char *parity_event
[5];
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.
791 mutex_lock(&dev_priv
->dev
->struct_mutex
);
793 misccpctl
= I915_READ(GEN7_MISCCPCTL
);
794 I915_WRITE(GEN7_MISCCPCTL
, misccpctl
& ~GEN7_DOP_CLOCK_GATE_ENABLE
);
795 POSTING_READ(GEN7_MISCCPCTL
);
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
);
802 I915_WRITE(GEN7_L3CDERRST1
, GEN7_PARITY_ERROR_VALID
|
803 GEN7_L3CDERRST1_ENABLE
);
804 POSTING_READ(GEN7_L3CDERRST1
);
806 I915_WRITE(GEN7_MISCCPCTL
, misccpctl
);
808 spin_lock_irqsave(&dev_priv
->irq_lock
, flags
);
809 dev_priv
->gt_irq_mask
&= ~GT_RENDER_L3_PARITY_ERROR_INTERRUPT
;
810 I915_WRITE(GTIMR
, dev_priv
->gt_irq_mask
);
811 spin_unlock_irqrestore(&dev_priv
->irq_lock
, flags
);
813 mutex_unlock(&dev_priv
->dev
->struct_mutex
);
815 parity_event
[0] = "L3_PARITY_ERROR=1";
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
;
821 kobject_uevent_env(&dev_priv
->dev
->primary
->kdev
.kobj
,
822 KOBJ_CHANGE
, parity_event
);
824 DRM_DEBUG("Parity error: Row = %d, Bank = %d, Sub bank = %d.\n",
827 kfree(parity_event
[3]);
828 kfree(parity_event
[2]);
829 kfree(parity_event
[1]);
832 static void ivybridge_parity_error_irq_handler(struct drm_device
*dev
)
834 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
836 if (!HAS_L3_GPU_CACHE(dev
))
839 spin_lock(&dev_priv
->irq_lock
);
840 dev_priv
->gt_irq_mask
|= GT_RENDER_L3_PARITY_ERROR_INTERRUPT
;
841 I915_WRITE(GTIMR
, dev_priv
->gt_irq_mask
);
842 spin_unlock(&dev_priv
->irq_lock
);
844 queue_work(dev_priv
->wq
, &dev_priv
->l3_parity
.error_work
);
847 static void snb_gt_irq_handler(struct drm_device
*dev
,
848 struct drm_i915_private
*dev_priv
,
853 (GT_RENDER_USER_INTERRUPT
| GT_RENDER_PIPECTL_NOTIFY_INTERRUPT
))
854 notify_ring(dev
, &dev_priv
->ring
[RCS
]);
855 if (gt_iir
& GT_BSD_USER_INTERRUPT
)
856 notify_ring(dev
, &dev_priv
->ring
[VCS
]);
857 if (gt_iir
& GT_BLT_USER_INTERRUPT
)
858 notify_ring(dev
, &dev_priv
->ring
[BCS
]);
860 if (gt_iir
& (GT_BLT_CS_ERROR_INTERRUPT
|
861 GT_BSD_CS_ERROR_INTERRUPT
|
862 GT_RENDER_CS_MASTER_ERROR_INTERRUPT
)) {
863 DRM_ERROR("GT error interrupt 0x%08x\n", gt_iir
);
864 i915_handle_error(dev
, false);
867 if (gt_iir
& GT_RENDER_L3_PARITY_ERROR_INTERRUPT
)
868 ivybridge_parity_error_irq_handler(dev
);
871 /* Legacy way of handling PM interrupts */
872 static void gen6_rps_irq_handler(struct drm_i915_private
*dev_priv
,
876 * IIR bits should never already be set because IMR should
877 * prevent an interrupt from being shown in IIR. The warning
878 * displays a case where we've unsafely cleared
879 * dev_priv->rps.pm_iir. Although missing an interrupt of the same
880 * type is not a problem, it displays a problem in the logic.
882 * The mask bit in IMR is cleared by dev_priv->rps.work.
885 spin_lock(&dev_priv
->irq_lock
);
886 dev_priv
->rps
.pm_iir
|= pm_iir
;
887 I915_WRITE(GEN6_PMIMR
, dev_priv
->rps
.pm_iir
);
888 POSTING_READ(GEN6_PMIMR
);
889 spin_unlock(&dev_priv
->irq_lock
);
891 queue_work(dev_priv
->wq
, &dev_priv
->rps
.work
);
894 #define HPD_STORM_DETECT_PERIOD 1000
895 #define HPD_STORM_THRESHOLD 5
897 static inline void intel_hpd_irq_handler(struct drm_device
*dev
,
901 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
903 bool storm_detected
= false;
905 if (!hotplug_trigger
)
908 spin_lock(&dev_priv
->irq_lock
);
909 for (i
= 1; i
< HPD_NUM_PINS
; i
++) {
911 if (!(hpd
[i
] & hotplug_trigger
) ||
912 dev_priv
->hpd_stats
[i
].hpd_mark
!= HPD_ENABLED
)
915 dev_priv
->hpd_event_bits
|= (1 << i
);
916 if (!time_in_range(jiffies
, dev_priv
->hpd_stats
[i
].hpd_last_jiffies
,
917 dev_priv
->hpd_stats
[i
].hpd_last_jiffies
918 + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD
))) {
919 dev_priv
->hpd_stats
[i
].hpd_last_jiffies
= jiffies
;
920 dev_priv
->hpd_stats
[i
].hpd_cnt
= 0;
921 } else if (dev_priv
->hpd_stats
[i
].hpd_cnt
> HPD_STORM_THRESHOLD
) {
922 dev_priv
->hpd_stats
[i
].hpd_mark
= HPD_MARK_DISABLED
;
923 dev_priv
->hpd_event_bits
&= ~(1 << i
);
924 DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", i
);
925 storm_detected
= true;
927 dev_priv
->hpd_stats
[i
].hpd_cnt
++;
932 dev_priv
->display
.hpd_irq_setup(dev
);
933 spin_unlock(&dev_priv
->irq_lock
);
935 queue_work(dev_priv
->wq
,
936 &dev_priv
->hotplug_work
);
939 static void gmbus_irq_handler(struct drm_device
*dev
)
941 struct drm_i915_private
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
943 wake_up_all(&dev_priv
->gmbus_wait_queue
);
946 static void dp_aux_irq_handler(struct drm_device
*dev
)
948 struct drm_i915_private
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
950 wake_up_all(&dev_priv
->gmbus_wait_queue
);
953 /* Unlike gen6_rps_irq_handler() from which this function is originally derived,
954 * we must be able to deal with other PM interrupts. This is complicated because
955 * of the way in which we use the masks to defer the RPS work (which for
956 * posterity is necessary because of forcewake).
958 static void hsw_pm_irq_handler(struct drm_i915_private
*dev_priv
,
961 if (pm_iir
& GEN6_PM_RPS_EVENTS
) {
962 spin_lock(&dev_priv
->irq_lock
);
963 dev_priv
->rps
.pm_iir
|= pm_iir
& GEN6_PM_RPS_EVENTS
;
964 I915_WRITE(GEN6_PMIMR
, dev_priv
->rps
.pm_iir
);
965 /* never want to mask useful interrupts. (also posting read) */
966 WARN_ON(I915_READ_NOTRACE(GEN6_PMIMR
) & ~GEN6_PM_RPS_EVENTS
);
967 spin_unlock(&dev_priv
->irq_lock
);
969 queue_work(dev_priv
->wq
, &dev_priv
->rps
.work
);
972 if (pm_iir
& PM_VEBOX_USER_INTERRUPT
)
973 notify_ring(dev_priv
->dev
, &dev_priv
->ring
[VECS
]);
975 if (pm_iir
& PM_VEBOX_CS_ERROR_INTERRUPT
) {
976 DRM_ERROR("VEBOX CS error interrupt 0x%08x\n", pm_iir
);
977 i915_handle_error(dev_priv
->dev
, false);
981 static irqreturn_t
valleyview_irq_handler(int irq
, void *arg
)
983 struct drm_device
*dev
= (struct drm_device
*) arg
;
984 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
985 u32 iir
, gt_iir
, pm_iir
;
986 irqreturn_t ret
= IRQ_NONE
;
987 unsigned long irqflags
;
989 u32 pipe_stats
[I915_MAX_PIPES
];
991 atomic_inc(&dev_priv
->irq_received
);
994 iir
= I915_READ(VLV_IIR
);
995 gt_iir
= I915_READ(GTIIR
);
996 pm_iir
= I915_READ(GEN6_PMIIR
);
998 if (gt_iir
== 0 && pm_iir
== 0 && iir
== 0)
1003 snb_gt_irq_handler(dev
, dev_priv
, gt_iir
);
1005 spin_lock_irqsave(&dev_priv
->irq_lock
, irqflags
);
1006 for_each_pipe(pipe
) {
1007 int reg
= PIPESTAT(pipe
);
1008 pipe_stats
[pipe
] = I915_READ(reg
);
1011 * Clear the PIPE*STAT regs before the IIR
1013 if (pipe_stats
[pipe
] & 0x8000ffff) {
1014 if (pipe_stats
[pipe
] & PIPE_FIFO_UNDERRUN_STATUS
)
1015 DRM_DEBUG_DRIVER("pipe %c underrun\n",
1017 I915_WRITE(reg
, pipe_stats
[pipe
]);
1020 spin_unlock_irqrestore(&dev_priv
->irq_lock
, irqflags
);
1022 for_each_pipe(pipe
) {
1023 if (pipe_stats
[pipe
] & PIPE_VBLANK_INTERRUPT_STATUS
)
1024 drm_handle_vblank(dev
, pipe
);
1026 if (pipe_stats
[pipe
] & PLANE_FLIPDONE_INT_STATUS_VLV
) {
1027 intel_prepare_page_flip(dev
, pipe
);
1028 intel_finish_page_flip(dev
, pipe
);
1032 /* Consume port. Then clear IIR or we'll miss events */
1033 if (iir
& I915_DISPLAY_PORT_INTERRUPT
) {
1034 u32 hotplug_status
= I915_READ(PORT_HOTPLUG_STAT
);
1035 u32 hotplug_trigger
= hotplug_status
& HOTPLUG_INT_STATUS_I915
;
1037 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
1040 intel_hpd_irq_handler(dev
, hotplug_trigger
, hpd_status_i915
);
1042 I915_WRITE(PORT_HOTPLUG_STAT
, hotplug_status
);
1043 I915_READ(PORT_HOTPLUG_STAT
);
1046 if (pipe_stats
[0] & PIPE_GMBUS_INTERRUPT_STATUS
)
1047 gmbus_irq_handler(dev
);
1049 if (pm_iir
& GEN6_PM_RPS_EVENTS
)
1050 gen6_rps_irq_handler(dev_priv
, pm_iir
);
1052 I915_WRITE(GTIIR
, gt_iir
);
1053 I915_WRITE(GEN6_PMIIR
, pm_iir
);
1054 I915_WRITE(VLV_IIR
, iir
);
1061 static void ibx_irq_handler(struct drm_device
*dev
, u32 pch_iir
)
1063 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
1065 u32 hotplug_trigger
= pch_iir
& SDE_HOTPLUG_MASK
;
1067 intel_hpd_irq_handler(dev
, hotplug_trigger
, hpd_ibx
);
1069 if (pch_iir
& SDE_AUDIO_POWER_MASK
) {
1070 int port
= ffs((pch_iir
& SDE_AUDIO_POWER_MASK
) >>
1071 SDE_AUDIO_POWER_SHIFT
);
1072 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
1076 if (pch_iir
& SDE_AUX_MASK
)
1077 dp_aux_irq_handler(dev
);
1079 if (pch_iir
& SDE_GMBUS
)
1080 gmbus_irq_handler(dev
);
1082 if (pch_iir
& SDE_AUDIO_HDCP_MASK
)
1083 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
1085 if (pch_iir
& SDE_AUDIO_TRANS_MASK
)
1086 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
1088 if (pch_iir
& SDE_POISON
)
1089 DRM_ERROR("PCH poison interrupt\n");
1091 if (pch_iir
& SDE_FDI_MASK
)
1093 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1095 I915_READ(FDI_RX_IIR(pipe
)));
1097 if (pch_iir
& (SDE_TRANSB_CRC_DONE
| SDE_TRANSA_CRC_DONE
))
1098 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
1100 if (pch_iir
& (SDE_TRANSB_CRC_ERR
| SDE_TRANSA_CRC_ERR
))
1101 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
1103 if (pch_iir
& SDE_TRANSA_FIFO_UNDER
)
1104 if (intel_set_pch_fifo_underrun_reporting(dev
, TRANSCODER_A
,
1106 DRM_DEBUG_DRIVER("PCH transcoder A FIFO underrun\n");
1108 if (pch_iir
& SDE_TRANSB_FIFO_UNDER
)
1109 if (intel_set_pch_fifo_underrun_reporting(dev
, TRANSCODER_B
,
1111 DRM_DEBUG_DRIVER("PCH transcoder B FIFO underrun\n");
1114 static void ivb_err_int_handler(struct drm_device
*dev
)
1116 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1117 u32 err_int
= I915_READ(GEN7_ERR_INT
);
1119 if (err_int
& ERR_INT_POISON
)
1120 DRM_ERROR("Poison interrupt\n");
1122 if (err_int
& ERR_INT_FIFO_UNDERRUN_A
)
1123 if (intel_set_cpu_fifo_underrun_reporting(dev
, PIPE_A
, false))
1124 DRM_DEBUG_DRIVER("Pipe A FIFO underrun\n");
1126 if (err_int
& ERR_INT_FIFO_UNDERRUN_B
)
1127 if (intel_set_cpu_fifo_underrun_reporting(dev
, PIPE_B
, false))
1128 DRM_DEBUG_DRIVER("Pipe B FIFO underrun\n");
1130 if (err_int
& ERR_INT_FIFO_UNDERRUN_C
)
1131 if (intel_set_cpu_fifo_underrun_reporting(dev
, PIPE_C
, false))
1132 DRM_DEBUG_DRIVER("Pipe C FIFO underrun\n");
1134 I915_WRITE(GEN7_ERR_INT
, err_int
);
1137 static void cpt_serr_int_handler(struct drm_device
*dev
)
1139 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1140 u32 serr_int
= I915_READ(SERR_INT
);
1142 if (serr_int
& SERR_INT_POISON
)
1143 DRM_ERROR("PCH poison interrupt\n");
1145 if (serr_int
& SERR_INT_TRANS_A_FIFO_UNDERRUN
)
1146 if (intel_set_pch_fifo_underrun_reporting(dev
, TRANSCODER_A
,
1148 DRM_DEBUG_DRIVER("PCH transcoder A FIFO underrun\n");
1150 if (serr_int
& SERR_INT_TRANS_B_FIFO_UNDERRUN
)
1151 if (intel_set_pch_fifo_underrun_reporting(dev
, TRANSCODER_B
,
1153 DRM_DEBUG_DRIVER("PCH transcoder B FIFO underrun\n");
1155 if (serr_int
& SERR_INT_TRANS_C_FIFO_UNDERRUN
)
1156 if (intel_set_pch_fifo_underrun_reporting(dev
, TRANSCODER_C
,
1158 DRM_DEBUG_DRIVER("PCH transcoder C FIFO underrun\n");
1160 I915_WRITE(SERR_INT
, serr_int
);
1163 static void cpt_irq_handler(struct drm_device
*dev
, u32 pch_iir
)
1165 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
1167 u32 hotplug_trigger
= pch_iir
& SDE_HOTPLUG_MASK_CPT
;
1169 intel_hpd_irq_handler(dev
, hotplug_trigger
, hpd_cpt
);
1171 if (pch_iir
& SDE_AUDIO_POWER_MASK_CPT
) {
1172 int port
= ffs((pch_iir
& SDE_AUDIO_POWER_MASK_CPT
) >>
1173 SDE_AUDIO_POWER_SHIFT_CPT
);
1174 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
1178 if (pch_iir
& SDE_AUX_MASK_CPT
)
1179 dp_aux_irq_handler(dev
);
1181 if (pch_iir
& SDE_GMBUS_CPT
)
1182 gmbus_irq_handler(dev
);
1184 if (pch_iir
& SDE_AUDIO_CP_REQ_CPT
)
1185 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
1187 if (pch_iir
& SDE_AUDIO_CP_CHG_CPT
)
1188 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
1190 if (pch_iir
& SDE_FDI_MASK_CPT
)
1192 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1194 I915_READ(FDI_RX_IIR(pipe
)));
1196 if (pch_iir
& SDE_ERROR_CPT
)
1197 cpt_serr_int_handler(dev
);
1200 static irqreturn_t
ivybridge_irq_handler(int irq
, void *arg
)
1202 struct drm_device
*dev
= (struct drm_device
*) arg
;
1203 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
1204 u32 de_iir
, gt_iir
, de_ier
, pm_iir
, sde_ier
= 0;
1205 irqreturn_t ret
= IRQ_NONE
;
1208 atomic_inc(&dev_priv
->irq_received
);
1210 /* We get interrupts on unclaimed registers, so check for this before we
1211 * do any I915_{READ,WRITE}. */
1212 if (IS_HASWELL(dev
) &&
1213 (I915_READ_NOTRACE(FPGA_DBG
) & FPGA_DBG_RM_NOCLAIM
)) {
1214 DRM_ERROR("Unclaimed register before interrupt\n");
1215 I915_WRITE_NOTRACE(FPGA_DBG
, FPGA_DBG_RM_NOCLAIM
);
1218 /* disable master interrupt before clearing iir */
1219 de_ier
= I915_READ(DEIER
);
1220 I915_WRITE(DEIER
, de_ier
& ~DE_MASTER_IRQ_CONTROL
);
1222 /* Disable south interrupts. We'll only write to SDEIIR once, so further
1223 * interrupts will will be stored on its back queue, and then we'll be
1224 * able to process them after we restore SDEIER (as soon as we restore
1225 * it, we'll get an interrupt if SDEIIR still has something to process
1226 * due to its back queue). */
1227 if (!HAS_PCH_NOP(dev
)) {
1228 sde_ier
= I915_READ(SDEIER
);
1229 I915_WRITE(SDEIER
, 0);
1230 POSTING_READ(SDEIER
);
1233 /* On Haswell, also mask ERR_INT because we don't want to risk
1234 * generating "unclaimed register" interrupts from inside the interrupt
1236 if (IS_HASWELL(dev
)) {
1237 spin_lock(&dev_priv
->irq_lock
);
1238 ironlake_disable_display_irq(dev_priv
, DE_ERR_INT_IVB
);
1239 spin_unlock(&dev_priv
->irq_lock
);
1242 gt_iir
= I915_READ(GTIIR
);
1244 snb_gt_irq_handler(dev
, dev_priv
, gt_iir
);
1245 I915_WRITE(GTIIR
, gt_iir
);
1249 de_iir
= I915_READ(DEIIR
);
1251 if (de_iir
& DE_ERR_INT_IVB
)
1252 ivb_err_int_handler(dev
);
1254 if (de_iir
& DE_AUX_CHANNEL_A_IVB
)
1255 dp_aux_irq_handler(dev
);
1257 if (de_iir
& DE_GSE_IVB
)
1258 intel_opregion_asle_intr(dev
);
1260 for (i
= 0; i
< 3; i
++) {
1261 if (de_iir
& (DE_PIPEA_VBLANK_IVB
<< (5 * i
)))
1262 drm_handle_vblank(dev
, i
);
1263 if (de_iir
& (DE_PLANEA_FLIP_DONE_IVB
<< (5 * i
))) {
1264 intel_prepare_page_flip(dev
, i
);
1265 intel_finish_page_flip_plane(dev
, i
);
1269 /* check event from PCH */
1270 if (!HAS_PCH_NOP(dev
) && (de_iir
& DE_PCH_EVENT_IVB
)) {
1271 u32 pch_iir
= I915_READ(SDEIIR
);
1273 cpt_irq_handler(dev
, pch_iir
);
1275 /* clear PCH hotplug event before clear CPU irq */
1276 I915_WRITE(SDEIIR
, pch_iir
);
1279 I915_WRITE(DEIIR
, de_iir
);
1283 pm_iir
= I915_READ(GEN6_PMIIR
);
1285 if (IS_HASWELL(dev
))
1286 hsw_pm_irq_handler(dev_priv
, pm_iir
);
1287 else if (pm_iir
& GEN6_PM_RPS_EVENTS
)
1288 gen6_rps_irq_handler(dev_priv
, pm_iir
);
1289 I915_WRITE(GEN6_PMIIR
, pm_iir
);
1293 if (IS_HASWELL(dev
)) {
1294 spin_lock(&dev_priv
->irq_lock
);
1295 if (ivb_can_enable_err_int(dev
))
1296 ironlake_enable_display_irq(dev_priv
, DE_ERR_INT_IVB
);
1297 spin_unlock(&dev_priv
->irq_lock
);
1300 I915_WRITE(DEIER
, de_ier
);
1301 POSTING_READ(DEIER
);
1302 if (!HAS_PCH_NOP(dev
)) {
1303 I915_WRITE(SDEIER
, sde_ier
);
1304 POSTING_READ(SDEIER
);
1310 static void ilk_gt_irq_handler(struct drm_device
*dev
,
1311 struct drm_i915_private
*dev_priv
,
1315 (GT_RENDER_USER_INTERRUPT
| GT_RENDER_PIPECTL_NOTIFY_INTERRUPT
))
1316 notify_ring(dev
, &dev_priv
->ring
[RCS
]);
1317 if (gt_iir
& ILK_BSD_USER_INTERRUPT
)
1318 notify_ring(dev
, &dev_priv
->ring
[VCS
]);
1321 static irqreturn_t
ironlake_irq_handler(int irq
, void *arg
)
1323 struct drm_device
*dev
= (struct drm_device
*) arg
;
1324 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
1326 u32 de_iir
, gt_iir
, de_ier
, pm_iir
, sde_ier
;
1328 atomic_inc(&dev_priv
->irq_received
);
1330 /* disable master interrupt before clearing iir */
1331 de_ier
= I915_READ(DEIER
);
1332 I915_WRITE(DEIER
, de_ier
& ~DE_MASTER_IRQ_CONTROL
);
1333 POSTING_READ(DEIER
);
1335 /* Disable south interrupts. We'll only write to SDEIIR once, so further
1336 * interrupts will will be stored on its back queue, and then we'll be
1337 * able to process them after we restore SDEIER (as soon as we restore
1338 * it, we'll get an interrupt if SDEIIR still has something to process
1339 * due to its back queue). */
1340 sde_ier
= I915_READ(SDEIER
);
1341 I915_WRITE(SDEIER
, 0);
1342 POSTING_READ(SDEIER
);
1344 de_iir
= I915_READ(DEIIR
);
1345 gt_iir
= I915_READ(GTIIR
);
1346 pm_iir
= I915_READ(GEN6_PMIIR
);
1348 if (de_iir
== 0 && gt_iir
== 0 && (!IS_GEN6(dev
) || pm_iir
== 0))
1354 ilk_gt_irq_handler(dev
, dev_priv
, gt_iir
);
1356 snb_gt_irq_handler(dev
, dev_priv
, gt_iir
);
1358 if (de_iir
& DE_AUX_CHANNEL_A
)
1359 dp_aux_irq_handler(dev
);
1361 if (de_iir
& DE_GSE
)
1362 intel_opregion_asle_intr(dev
);
1364 if (de_iir
& DE_PIPEA_VBLANK
)
1365 drm_handle_vblank(dev
, 0);
1367 if (de_iir
& DE_PIPEB_VBLANK
)
1368 drm_handle_vblank(dev
, 1);
1370 if (de_iir
& DE_POISON
)
1371 DRM_ERROR("Poison interrupt\n");
1373 if (de_iir
& DE_PIPEA_FIFO_UNDERRUN
)
1374 if (intel_set_cpu_fifo_underrun_reporting(dev
, PIPE_A
, false))
1375 DRM_DEBUG_DRIVER("Pipe A FIFO underrun\n");
1377 if (de_iir
& DE_PIPEB_FIFO_UNDERRUN
)
1378 if (intel_set_cpu_fifo_underrun_reporting(dev
, PIPE_B
, false))
1379 DRM_DEBUG_DRIVER("Pipe B FIFO underrun\n");
1381 if (de_iir
& DE_PLANEA_FLIP_DONE
) {
1382 intel_prepare_page_flip(dev
, 0);
1383 intel_finish_page_flip_plane(dev
, 0);
1386 if (de_iir
& DE_PLANEB_FLIP_DONE
) {
1387 intel_prepare_page_flip(dev
, 1);
1388 intel_finish_page_flip_plane(dev
, 1);
1391 /* check event from PCH */
1392 if (de_iir
& DE_PCH_EVENT
) {
1393 u32 pch_iir
= I915_READ(SDEIIR
);
1395 if (HAS_PCH_CPT(dev
))
1396 cpt_irq_handler(dev
, pch_iir
);
1398 ibx_irq_handler(dev
, pch_iir
);
1400 /* should clear PCH hotplug event before clear CPU irq */
1401 I915_WRITE(SDEIIR
, pch_iir
);
1404 if (IS_GEN5(dev
) && de_iir
& DE_PCU_EVENT
)
1405 ironlake_rps_change_irq_handler(dev
);
1407 if (IS_GEN6(dev
) && pm_iir
& GEN6_PM_RPS_EVENTS
)
1408 gen6_rps_irq_handler(dev_priv
, pm_iir
);
1410 I915_WRITE(GTIIR
, gt_iir
);
1411 I915_WRITE(DEIIR
, de_iir
);
1412 I915_WRITE(GEN6_PMIIR
, pm_iir
);
1415 I915_WRITE(DEIER
, de_ier
);
1416 POSTING_READ(DEIER
);
1417 I915_WRITE(SDEIER
, sde_ier
);
1418 POSTING_READ(SDEIER
);
1424 * i915_error_work_func - do process context error handling work
1425 * @work: work struct
1427 * Fire an error uevent so userspace can see that a hang or error
1430 static void i915_error_work_func(struct work_struct
*work
)
1432 struct i915_gpu_error
*error
= container_of(work
, struct i915_gpu_error
,
1434 drm_i915_private_t
*dev_priv
= container_of(error
, drm_i915_private_t
,
1436 struct drm_device
*dev
= dev_priv
->dev
;
1437 struct intel_ring_buffer
*ring
;
1438 char *error_event
[] = { "ERROR=1", NULL
};
1439 char *reset_event
[] = { "RESET=1", NULL
};
1440 char *reset_done_event
[] = { "ERROR=0", NULL
};
1443 kobject_uevent_env(&dev
->primary
->kdev
.kobj
, KOBJ_CHANGE
, error_event
);
1446 * Note that there's only one work item which does gpu resets, so we
1447 * need not worry about concurrent gpu resets potentially incrementing
1448 * error->reset_counter twice. We only need to take care of another
1449 * racing irq/hangcheck declaring the gpu dead for a second time. A
1450 * quick check for that is good enough: schedule_work ensures the
1451 * correct ordering between hang detection and this work item, and since
1452 * the reset in-progress bit is only ever set by code outside of this
1453 * work we don't need to worry about any other races.
1455 if (i915_reset_in_progress(error
) && !i915_terminally_wedged(error
)) {
1456 DRM_DEBUG_DRIVER("resetting chip\n");
1457 kobject_uevent_env(&dev
->primary
->kdev
.kobj
, KOBJ_CHANGE
,
1460 ret
= i915_reset(dev
);
1464 * After all the gem state is reset, increment the reset
1465 * counter and wake up everyone waiting for the reset to
1468 * Since unlock operations are a one-sided barrier only,
1469 * we need to insert a barrier here to order any seqno
1471 * the counter increment.
1473 smp_mb__before_atomic_inc();
1474 atomic_inc(&dev_priv
->gpu_error
.reset_counter
);
1476 kobject_uevent_env(&dev
->primary
->kdev
.kobj
,
1477 KOBJ_CHANGE
, reset_done_event
);
1479 atomic_set(&error
->reset_counter
, I915_WEDGED
);
1482 for_each_ring(ring
, dev_priv
, i
)
1483 wake_up_all(&ring
->irq_queue
);
1485 intel_display_handle_reset(dev
);
1487 wake_up_all(&dev_priv
->gpu_error
.reset_queue
);
1491 static void i915_report_and_clear_eir(struct drm_device
*dev
)
1493 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1494 uint32_t instdone
[I915_NUM_INSTDONE_REG
];
1495 u32 eir
= I915_READ(EIR
);
1501 pr_err("render error detected, EIR: 0x%08x\n", eir
);
1503 i915_get_extra_instdone(dev
, instdone
);
1506 if (eir
& (GM45_ERROR_MEM_PRIV
| GM45_ERROR_CP_PRIV
)) {
1507 u32 ipeir
= I915_READ(IPEIR_I965
);
1509 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965
));
1510 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965
));
1511 for (i
= 0; i
< ARRAY_SIZE(instdone
); i
++)
1512 pr_err(" INSTDONE_%d: 0x%08x\n", i
, instdone
[i
]);
1513 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS
));
1514 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965
));
1515 I915_WRITE(IPEIR_I965
, ipeir
);
1516 POSTING_READ(IPEIR_I965
);
1518 if (eir
& GM45_ERROR_PAGE_TABLE
) {
1519 u32 pgtbl_err
= I915_READ(PGTBL_ER
);
1520 pr_err("page table error\n");
1521 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err
);
1522 I915_WRITE(PGTBL_ER
, pgtbl_err
);
1523 POSTING_READ(PGTBL_ER
);
1527 if (!IS_GEN2(dev
)) {
1528 if (eir
& I915_ERROR_PAGE_TABLE
) {
1529 u32 pgtbl_err
= I915_READ(PGTBL_ER
);
1530 pr_err("page table error\n");
1531 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err
);
1532 I915_WRITE(PGTBL_ER
, pgtbl_err
);
1533 POSTING_READ(PGTBL_ER
);
1537 if (eir
& I915_ERROR_MEMORY_REFRESH
) {
1538 pr_err("memory refresh error:\n");
1540 pr_err("pipe %c stat: 0x%08x\n",
1541 pipe_name(pipe
), I915_READ(PIPESTAT(pipe
)));
1542 /* pipestat has already been acked */
1544 if (eir
& I915_ERROR_INSTRUCTION
) {
1545 pr_err("instruction error\n");
1546 pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM
));
1547 for (i
= 0; i
< ARRAY_SIZE(instdone
); i
++)
1548 pr_err(" INSTDONE_%d: 0x%08x\n", i
, instdone
[i
]);
1549 if (INTEL_INFO(dev
)->gen
< 4) {
1550 u32 ipeir
= I915_READ(IPEIR
);
1552 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR
));
1553 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR
));
1554 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD
));
1555 I915_WRITE(IPEIR
, ipeir
);
1556 POSTING_READ(IPEIR
);
1558 u32 ipeir
= I915_READ(IPEIR_I965
);
1560 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965
));
1561 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965
));
1562 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS
));
1563 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965
));
1564 I915_WRITE(IPEIR_I965
, ipeir
);
1565 POSTING_READ(IPEIR_I965
);
1569 I915_WRITE(EIR
, eir
);
1571 eir
= I915_READ(EIR
);
1574 * some errors might have become stuck,
1577 DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir
);
1578 I915_WRITE(EMR
, I915_READ(EMR
) | eir
);
1579 I915_WRITE(IIR
, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT
);
1584 * i915_handle_error - handle an error interrupt
1587 * Do some basic checking of regsiter state at error interrupt time and
1588 * dump it to the syslog. Also call i915_capture_error_state() to make
1589 * sure we get a record and make it available in debugfs. Fire a uevent
1590 * so userspace knows something bad happened (should trigger collection
1591 * of a ring dump etc.).
1593 void i915_handle_error(struct drm_device
*dev
, bool wedged
)
1595 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1596 struct intel_ring_buffer
*ring
;
1599 i915_capture_error_state(dev
);
1600 i915_report_and_clear_eir(dev
);
1603 atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG
,
1604 &dev_priv
->gpu_error
.reset_counter
);
1607 * Wakeup waiting processes so that the reset work item
1608 * doesn't deadlock trying to grab various locks.
1610 for_each_ring(ring
, dev_priv
, i
)
1611 wake_up_all(&ring
->irq_queue
);
1614 queue_work(dev_priv
->wq
, &dev_priv
->gpu_error
.work
);
1617 static void __always_unused
i915_pageflip_stall_check(struct drm_device
*dev
, int pipe
)
1619 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
1620 struct drm_crtc
*crtc
= dev_priv
->pipe_to_crtc_mapping
[pipe
];
1621 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
1622 struct drm_i915_gem_object
*obj
;
1623 struct intel_unpin_work
*work
;
1624 unsigned long flags
;
1625 bool stall_detected
;
1627 /* Ignore early vblank irqs */
1628 if (intel_crtc
== NULL
)
1631 spin_lock_irqsave(&dev
->event_lock
, flags
);
1632 work
= intel_crtc
->unpin_work
;
1635 atomic_read(&work
->pending
) >= INTEL_FLIP_COMPLETE
||
1636 !work
->enable_stall_check
) {
1637 /* Either the pending flip IRQ arrived, or we're too early. Don't check */
1638 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
1642 /* Potential stall - if we see that the flip has happened, assume a missed interrupt */
1643 obj
= work
->pending_flip_obj
;
1644 if (INTEL_INFO(dev
)->gen
>= 4) {
1645 int dspsurf
= DSPSURF(intel_crtc
->plane
);
1646 stall_detected
= I915_HI_DISPBASE(I915_READ(dspsurf
)) ==
1647 i915_gem_obj_ggtt_offset(obj
);
1649 int dspaddr
= DSPADDR(intel_crtc
->plane
);
1650 stall_detected
= I915_READ(dspaddr
) == (i915_gem_obj_ggtt_offset(obj
) +
1651 crtc
->y
* crtc
->fb
->pitches
[0] +
1652 crtc
->x
* crtc
->fb
->bits_per_pixel
/8);
1655 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
1657 if (stall_detected
) {
1658 DRM_DEBUG_DRIVER("Pageflip stall detected\n");
1659 intel_prepare_page_flip(dev
, intel_crtc
->plane
);
1663 /* Called from drm generic code, passed 'crtc' which
1664 * we use as a pipe index
1666 static int i915_enable_vblank(struct drm_device
*dev
, int pipe
)
1668 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
1669 unsigned long irqflags
;
1671 if (!i915_pipe_enabled(dev
, pipe
))
1674 spin_lock_irqsave(&dev_priv
->irq_lock
, irqflags
);
1675 if (INTEL_INFO(dev
)->gen
>= 4)
1676 i915_enable_pipestat(dev_priv
, pipe
,
1677 PIPE_START_VBLANK_INTERRUPT_ENABLE
);
1679 i915_enable_pipestat(dev_priv
, pipe
,
1680 PIPE_VBLANK_INTERRUPT_ENABLE
);
1682 /* maintain vblank delivery even in deep C-states */
1683 if (dev_priv
->info
->gen
== 3)
1684 I915_WRITE(INSTPM
, _MASKED_BIT_DISABLE(INSTPM_AGPBUSY_DIS
));
1685 spin_unlock_irqrestore(&dev_priv
->irq_lock
, irqflags
);
1690 static int ironlake_enable_vblank(struct drm_device
*dev
, int pipe
)
1692 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
1693 unsigned long irqflags
;
1695 if (!i915_pipe_enabled(dev
, pipe
))
1698 spin_lock_irqsave(&dev_priv
->irq_lock
, irqflags
);
1699 ironlake_enable_display_irq(dev_priv
, (pipe
== 0) ?
1700 DE_PIPEA_VBLANK
: DE_PIPEB_VBLANK
);
1701 spin_unlock_irqrestore(&dev_priv
->irq_lock
, irqflags
);
1706 static int ivybridge_enable_vblank(struct drm_device
*dev
, int pipe
)
1708 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
1709 unsigned long irqflags
;
1711 if (!i915_pipe_enabled(dev
, pipe
))
1714 spin_lock_irqsave(&dev_priv
->irq_lock
, irqflags
);
1715 ironlake_enable_display_irq(dev_priv
,
1716 DE_PIPEA_VBLANK_IVB
<< (5 * pipe
));
1717 spin_unlock_irqrestore(&dev_priv
->irq_lock
, irqflags
);
1722 static int valleyview_enable_vblank(struct drm_device
*dev
, int pipe
)
1724 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
1725 unsigned long irqflags
;
1728 if (!i915_pipe_enabled(dev
, pipe
))
1731 spin_lock_irqsave(&dev_priv
->irq_lock
, irqflags
);
1732 imr
= I915_READ(VLV_IMR
);
1734 imr
&= ~I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT
;
1736 imr
&= ~I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT
;
1737 I915_WRITE(VLV_IMR
, imr
);
1738 i915_enable_pipestat(dev_priv
, pipe
,
1739 PIPE_START_VBLANK_INTERRUPT_ENABLE
);
1740 spin_unlock_irqrestore(&dev_priv
->irq_lock
, irqflags
);
1745 /* Called from drm generic code, passed 'crtc' which
1746 * we use as a pipe index
1748 static void i915_disable_vblank(struct drm_device
*dev
, int pipe
)
1750 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
1751 unsigned long irqflags
;
1753 spin_lock_irqsave(&dev_priv
->irq_lock
, irqflags
);
1754 if (dev_priv
->info
->gen
== 3)
1755 I915_WRITE(INSTPM
, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_DIS
));
1757 i915_disable_pipestat(dev_priv
, pipe
,
1758 PIPE_VBLANK_INTERRUPT_ENABLE
|
1759 PIPE_START_VBLANK_INTERRUPT_ENABLE
);
1760 spin_unlock_irqrestore(&dev_priv
->irq_lock
, irqflags
);
1763 static void ironlake_disable_vblank(struct drm_device
*dev
, int pipe
)
1765 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
1766 unsigned long irqflags
;
1768 spin_lock_irqsave(&dev_priv
->irq_lock
, irqflags
);
1769 ironlake_disable_display_irq(dev_priv
, (pipe
== 0) ?
1770 DE_PIPEA_VBLANK
: DE_PIPEB_VBLANK
);
1771 spin_unlock_irqrestore(&dev_priv
->irq_lock
, irqflags
);
1774 static void ivybridge_disable_vblank(struct drm_device
*dev
, int pipe
)
1776 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
1777 unsigned long irqflags
;
1779 spin_lock_irqsave(&dev_priv
->irq_lock
, irqflags
);
1780 ironlake_disable_display_irq(dev_priv
,
1781 DE_PIPEA_VBLANK_IVB
<< (pipe
* 5));
1782 spin_unlock_irqrestore(&dev_priv
->irq_lock
, irqflags
);
1785 static void valleyview_disable_vblank(struct drm_device
*dev
, int pipe
)
1787 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
1788 unsigned long irqflags
;
1791 spin_lock_irqsave(&dev_priv
->irq_lock
, irqflags
);
1792 i915_disable_pipestat(dev_priv
, pipe
,
1793 PIPE_START_VBLANK_INTERRUPT_ENABLE
);
1794 imr
= I915_READ(VLV_IMR
);
1796 imr
|= I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT
;
1798 imr
|= I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT
;
1799 I915_WRITE(VLV_IMR
, imr
);
1800 spin_unlock_irqrestore(&dev_priv
->irq_lock
, irqflags
);
1804 ring_last_seqno(struct intel_ring_buffer
*ring
)
1806 return list_entry(ring
->request_list
.prev
,
1807 struct drm_i915_gem_request
, list
)->seqno
;
1811 ring_idle(struct intel_ring_buffer
*ring
, u32 seqno
)
1813 return (list_empty(&ring
->request_list
) ||
1814 i915_seqno_passed(seqno
, ring_last_seqno(ring
)));
1817 static struct intel_ring_buffer
*
1818 semaphore_waits_for(struct intel_ring_buffer
*ring
, u32
*seqno
)
1820 struct drm_i915_private
*dev_priv
= ring
->dev
->dev_private
;
1821 u32 cmd
, ipehr
, acthd
, acthd_min
;
1823 ipehr
= I915_READ(RING_IPEHR(ring
->mmio_base
));
1824 if ((ipehr
& ~(0x3 << 16)) !=
1825 (MI_SEMAPHORE_MBOX
| MI_SEMAPHORE_COMPARE
| MI_SEMAPHORE_REGISTER
))
1828 /* ACTHD is likely pointing to the dword after the actual command,
1829 * so scan backwards until we find the MBOX.
1831 acthd
= intel_ring_get_active_head(ring
) & HEAD_ADDR
;
1832 acthd_min
= max((int)acthd
- 3 * 4, 0);
1834 cmd
= ioread32(ring
->virtual_start
+ acthd
);
1839 if (acthd
< acthd_min
)
1843 *seqno
= ioread32(ring
->virtual_start
+acthd
+4)+1;
1844 return &dev_priv
->ring
[(ring
->id
+ (((ipehr
>> 17) & 1) + 1)) % 3];
1847 static int semaphore_passed(struct intel_ring_buffer
*ring
)
1849 struct drm_i915_private
*dev_priv
= ring
->dev
->dev_private
;
1850 struct intel_ring_buffer
*signaller
;
1853 ring
->hangcheck
.deadlock
= true;
1855 signaller
= semaphore_waits_for(ring
, &seqno
);
1856 if (signaller
== NULL
|| signaller
->hangcheck
.deadlock
)
1859 /* cursory check for an unkickable deadlock */
1860 ctl
= I915_READ_CTL(signaller
);
1861 if (ctl
& RING_WAIT_SEMAPHORE
&& semaphore_passed(signaller
) < 0)
1864 return i915_seqno_passed(signaller
->get_seqno(signaller
, false), seqno
);
1867 static void semaphore_clear_deadlocks(struct drm_i915_private
*dev_priv
)
1869 struct intel_ring_buffer
*ring
;
1872 for_each_ring(ring
, dev_priv
, i
)
1873 ring
->hangcheck
.deadlock
= false;
1876 static enum intel_ring_hangcheck_action
1877 ring_stuck(struct intel_ring_buffer
*ring
, u32 acthd
)
1879 struct drm_device
*dev
= ring
->dev
;
1880 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1883 if (ring
->hangcheck
.acthd
!= acthd
)
1889 /* Is the chip hanging on a WAIT_FOR_EVENT?
1890 * If so we can simply poke the RB_WAIT bit
1891 * and break the hang. This should work on
1892 * all but the second generation chipsets.
1894 tmp
= I915_READ_CTL(ring
);
1895 if (tmp
& RING_WAIT
) {
1896 DRM_ERROR("Kicking stuck wait on %s\n",
1898 I915_WRITE_CTL(ring
, tmp
);
1902 if (INTEL_INFO(dev
)->gen
>= 6 && tmp
& RING_WAIT_SEMAPHORE
) {
1903 switch (semaphore_passed(ring
)) {
1907 DRM_ERROR("Kicking stuck semaphore on %s\n",
1909 I915_WRITE_CTL(ring
, tmp
);
1920 * This is called when the chip hasn't reported back with completed
1921 * batchbuffers in a long time. We keep track per ring seqno progress and
1922 * if there are no progress, hangcheck score for that ring is increased.
1923 * Further, acthd is inspected to see if the ring is stuck. On stuck case
1924 * we kick the ring. If we see no progress on three subsequent calls
1925 * we assume chip is wedged and try to fix it by resetting the chip.
1927 void i915_hangcheck_elapsed(unsigned long data
)
1929 struct drm_device
*dev
= (struct drm_device
*)data
;
1930 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
1931 struct intel_ring_buffer
*ring
;
1933 int busy_count
= 0, rings_hung
= 0;
1934 bool stuck
[I915_NUM_RINGS
] = { 0 };
1940 if (!i915_enable_hangcheck
)
1943 for_each_ring(ring
, dev_priv
, i
) {
1947 semaphore_clear_deadlocks(dev_priv
);
1949 seqno
= ring
->get_seqno(ring
, false);
1950 acthd
= intel_ring_get_active_head(ring
);
1952 if (ring
->hangcheck
.seqno
== seqno
) {
1953 if (ring_idle(ring
, seqno
)) {
1954 if (waitqueue_active(&ring
->irq_queue
)) {
1955 /* Issue a wake-up to catch stuck h/w. */
1956 DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
1958 wake_up_all(&ring
->irq_queue
);
1959 ring
->hangcheck
.score
+= HUNG
;
1965 /* We always increment the hangcheck score
1966 * if the ring is busy and still processing
1967 * the same request, so that no single request
1968 * can run indefinitely (such as a chain of
1969 * batches). The only time we do not increment
1970 * the hangcheck score on this ring, if this
1971 * ring is in a legitimate wait for another
1972 * ring. In that case the waiting ring is a
1973 * victim and we want to be sure we catch the
1974 * right culprit. Then every time we do kick
1975 * the ring, add a small increment to the
1976 * score so that we can catch a batch that is
1977 * being repeatedly kicked and so responsible
1978 * for stalling the machine.
1980 ring
->hangcheck
.action
= ring_stuck(ring
,
1983 switch (ring
->hangcheck
.action
) {
1998 ring
->hangcheck
.score
+= score
;
2001 /* Gradually reduce the count so that we catch DoS
2002 * attempts across multiple batches.
2004 if (ring
->hangcheck
.score
> 0)
2005 ring
->hangcheck
.score
--;
2008 ring
->hangcheck
.seqno
= seqno
;
2009 ring
->hangcheck
.acthd
= acthd
;
2013 for_each_ring(ring
, dev_priv
, i
) {
2014 if (ring
->hangcheck
.score
> FIRE
) {
2015 DRM_ERROR("%s on %s\n",
2016 stuck
[i
] ? "stuck" : "no progress",
2023 return i915_handle_error(dev
, true);
2026 /* Reset timer case chip hangs without another request
2028 i915_queue_hangcheck(dev
);
2031 void i915_queue_hangcheck(struct drm_device
*dev
)
2033 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2034 if (!i915_enable_hangcheck
)
2037 mod_timer(&dev_priv
->gpu_error
.hangcheck_timer
,
2038 round_jiffies_up(jiffies
+ DRM_I915_HANGCHECK_JIFFIES
));
2041 static void ibx_irq_preinstall(struct drm_device
*dev
)
2043 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2045 if (HAS_PCH_NOP(dev
))
2048 /* south display irq */
2049 I915_WRITE(SDEIMR
, 0xffffffff);
2051 * SDEIER is also touched by the interrupt handler to work around missed
2052 * PCH interrupts. Hence we can't update it after the interrupt handler
2053 * is enabled - instead we unconditionally enable all PCH interrupt
2054 * sources here, but then only unmask them as needed with SDEIMR.
2056 I915_WRITE(SDEIER
, 0xffffffff);
2057 POSTING_READ(SDEIER
);
2060 static void gen5_gt_irq_preinstall(struct drm_device
*dev
)
2062 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2065 I915_WRITE(GTIMR
, 0xffffffff);
2066 I915_WRITE(GTIER
, 0x0);
2067 POSTING_READ(GTIER
);
2069 if (INTEL_INFO(dev
)->gen
>= 6) {
2071 I915_WRITE(GEN6_PMIMR
, 0xffffffff);
2072 I915_WRITE(GEN6_PMIER
, 0x0);
2073 POSTING_READ(GEN6_PMIER
);
2079 static void ironlake_irq_preinstall(struct drm_device
*dev
)
2081 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
2083 atomic_set(&dev_priv
->irq_received
, 0);
2085 I915_WRITE(HWSTAM
, 0xeffe);
2087 I915_WRITE(DEIMR
, 0xffffffff);
2088 I915_WRITE(DEIER
, 0x0);
2089 POSTING_READ(DEIER
);
2091 gen5_gt_irq_preinstall(dev
);
2093 ibx_irq_preinstall(dev
);
2096 static void valleyview_irq_preinstall(struct drm_device
*dev
)
2098 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
2101 atomic_set(&dev_priv
->irq_received
, 0);
2104 I915_WRITE(VLV_IMR
, 0);
2105 I915_WRITE(RING_IMR(RENDER_RING_BASE
), 0);
2106 I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE
), 0);
2107 I915_WRITE(RING_IMR(BLT_RING_BASE
), 0);
2110 I915_WRITE(GTIIR
, I915_READ(GTIIR
));
2111 I915_WRITE(GTIIR
, I915_READ(GTIIR
));
2113 gen5_gt_irq_preinstall(dev
);
2115 I915_WRITE(DPINVGTT
, 0xff);
2117 I915_WRITE(PORT_HOTPLUG_EN
, 0);
2118 I915_WRITE(PORT_HOTPLUG_STAT
, I915_READ(PORT_HOTPLUG_STAT
));
2120 I915_WRITE(PIPESTAT(pipe
), 0xffff);
2121 I915_WRITE(VLV_IIR
, 0xffffffff);
2122 I915_WRITE(VLV_IMR
, 0xffffffff);
2123 I915_WRITE(VLV_IER
, 0x0);
2124 POSTING_READ(VLV_IER
);
2127 static void ibx_hpd_irq_setup(struct drm_device
*dev
)
2129 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
2130 struct drm_mode_config
*mode_config
= &dev
->mode_config
;
2131 struct intel_encoder
*intel_encoder
;
2132 u32 hotplug_irqs
, hotplug
, enabled_irqs
= 0;
2134 if (HAS_PCH_IBX(dev
)) {
2135 hotplug_irqs
= SDE_HOTPLUG_MASK
;
2136 list_for_each_entry(intel_encoder
, &mode_config
->encoder_list
, base
.head
)
2137 if (dev_priv
->hpd_stats
[intel_encoder
->hpd_pin
].hpd_mark
== HPD_ENABLED
)
2138 enabled_irqs
|= hpd_ibx
[intel_encoder
->hpd_pin
];
2140 hotplug_irqs
= SDE_HOTPLUG_MASK_CPT
;
2141 list_for_each_entry(intel_encoder
, &mode_config
->encoder_list
, base
.head
)
2142 if (dev_priv
->hpd_stats
[intel_encoder
->hpd_pin
].hpd_mark
== HPD_ENABLED
)
2143 enabled_irqs
|= hpd_cpt
[intel_encoder
->hpd_pin
];
2146 ibx_display_interrupt_update(dev_priv
, hotplug_irqs
, enabled_irqs
);
2149 * Enable digital hotplug on the PCH, and configure the DP short pulse
2150 * duration to 2ms (which is the minimum in the Display Port spec)
2152 * This register is the same on all known PCH chips.
2154 hotplug
= I915_READ(PCH_PORT_HOTPLUG
);
2155 hotplug
&= ~(PORTD_PULSE_DURATION_MASK
|PORTC_PULSE_DURATION_MASK
|PORTB_PULSE_DURATION_MASK
);
2156 hotplug
|= PORTD_HOTPLUG_ENABLE
| PORTD_PULSE_DURATION_2ms
;
2157 hotplug
|= PORTC_HOTPLUG_ENABLE
| PORTC_PULSE_DURATION_2ms
;
2158 hotplug
|= PORTB_HOTPLUG_ENABLE
| PORTB_PULSE_DURATION_2ms
;
2159 I915_WRITE(PCH_PORT_HOTPLUG
, hotplug
);
2162 static void ibx_irq_postinstall(struct drm_device
*dev
)
2164 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
2167 if (HAS_PCH_NOP(dev
))
2170 if (HAS_PCH_IBX(dev
)) {
2171 mask
= SDE_GMBUS
| SDE_AUX_MASK
| SDE_TRANSB_FIFO_UNDER
|
2172 SDE_TRANSA_FIFO_UNDER
| SDE_POISON
;
2174 mask
= SDE_GMBUS_CPT
| SDE_AUX_MASK_CPT
| SDE_ERROR_CPT
;
2176 I915_WRITE(SERR_INT
, I915_READ(SERR_INT
));
2179 I915_WRITE(SDEIIR
, I915_READ(SDEIIR
));
2180 I915_WRITE(SDEIMR
, ~mask
);
2183 static void gen5_gt_irq_postinstall(struct drm_device
*dev
)
2185 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2186 u32 pm_irqs
, gt_irqs
;
2188 pm_irqs
= gt_irqs
= 0;
2190 dev_priv
->gt_irq_mask
= ~0;
2191 if (HAS_L3_GPU_CACHE(dev
)) {
2192 /* L3 parity interrupt is always unmasked. */
2193 dev_priv
->gt_irq_mask
= ~GT_RENDER_L3_PARITY_ERROR_INTERRUPT
;
2194 gt_irqs
|= GT_RENDER_L3_PARITY_ERROR_INTERRUPT
;
2197 gt_irqs
|= GT_RENDER_USER_INTERRUPT
;
2199 gt_irqs
|= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT
|
2200 ILK_BSD_USER_INTERRUPT
;
2202 gt_irqs
|= GT_BLT_USER_INTERRUPT
| GT_BSD_USER_INTERRUPT
;
2205 I915_WRITE(GTIIR
, I915_READ(GTIIR
));
2206 I915_WRITE(GTIMR
, dev_priv
->gt_irq_mask
);
2207 I915_WRITE(GTIER
, gt_irqs
);
2208 POSTING_READ(GTIER
);
2210 if (INTEL_INFO(dev
)->gen
>= 6) {
2211 pm_irqs
|= GEN6_PM_RPS_EVENTS
;
2214 pm_irqs
|= PM_VEBOX_USER_INTERRUPT
;
2216 I915_WRITE(GEN6_PMIIR
, I915_READ(GEN6_PMIIR
));
2217 I915_WRITE(GEN6_PMIMR
, 0xffffffff);
2218 I915_WRITE(GEN6_PMIER
, pm_irqs
);
2219 POSTING_READ(GEN6_PMIER
);
2223 static int ironlake_irq_postinstall(struct drm_device
*dev
)
2225 unsigned long irqflags
;
2227 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
2228 /* enable kind of interrupts always enabled */
2229 u32 display_mask
= DE_MASTER_IRQ_CONTROL
| DE_GSE
| DE_PCH_EVENT
|
2230 DE_PLANEA_FLIP_DONE
| DE_PLANEB_FLIP_DONE
|
2231 DE_AUX_CHANNEL_A
| DE_PIPEB_FIFO_UNDERRUN
|
2232 DE_PIPEA_FIFO_UNDERRUN
| DE_POISON
;
2234 dev_priv
->irq_mask
= ~display_mask
;
2236 /* should always can generate irq */
2237 I915_WRITE(DEIIR
, I915_READ(DEIIR
));
2238 I915_WRITE(DEIMR
, dev_priv
->irq_mask
);
2239 I915_WRITE(DEIER
, display_mask
|
2240 DE_PIPEA_VBLANK
| DE_PIPEB_VBLANK
| DE_PCU_EVENT
);
2241 POSTING_READ(DEIER
);
2243 gen5_gt_irq_postinstall(dev
);
2245 ibx_irq_postinstall(dev
);
2247 if (IS_IRONLAKE_M(dev
)) {
2248 /* Enable PCU event interrupts
2250 * spinlocking not required here for correctness since interrupt
2251 * setup is guaranteed to run in single-threaded context. But we
2252 * need it to make the assert_spin_locked happy. */
2253 spin_lock_irqsave(&dev_priv
->irq_lock
, irqflags
);
2254 ironlake_enable_display_irq(dev_priv
, DE_PCU_EVENT
);
2255 spin_unlock_irqrestore(&dev_priv
->irq_lock
, irqflags
);
2261 static int ivybridge_irq_postinstall(struct drm_device
*dev
)
2263 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
2264 /* enable kind of interrupts always enabled */
2266 DE_MASTER_IRQ_CONTROL
| DE_GSE_IVB
| DE_PCH_EVENT_IVB
|
2267 DE_PLANEC_FLIP_DONE_IVB
|
2268 DE_PLANEB_FLIP_DONE_IVB
|
2269 DE_PLANEA_FLIP_DONE_IVB
|
2270 DE_AUX_CHANNEL_A_IVB
|
2273 dev_priv
->irq_mask
= ~display_mask
;
2275 /* should always can generate irq */
2276 I915_WRITE(GEN7_ERR_INT
, I915_READ(GEN7_ERR_INT
));
2277 I915_WRITE(DEIIR
, I915_READ(DEIIR
));
2278 I915_WRITE(DEIMR
, dev_priv
->irq_mask
);
2281 DE_PIPEC_VBLANK_IVB
|
2282 DE_PIPEB_VBLANK_IVB
|
2283 DE_PIPEA_VBLANK_IVB
);
2284 POSTING_READ(DEIER
);
2286 gen5_gt_irq_postinstall(dev
);
2288 ibx_irq_postinstall(dev
);
2293 static int valleyview_irq_postinstall(struct drm_device
*dev
)
2295 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
2297 u32 pipestat_enable
= PLANE_FLIP_DONE_INT_EN_VLV
;
2298 unsigned long irqflags
;
2300 enable_mask
= I915_DISPLAY_PORT_INTERRUPT
;
2301 enable_mask
|= I915_DISPLAY_PIPE_A_EVENT_INTERRUPT
|
2302 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT
|
2303 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT
|
2304 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT
;
2307 *Leave vblank interrupts masked initially. enable/disable will
2308 * toggle them based on usage.
2310 dev_priv
->irq_mask
= (~enable_mask
) |
2311 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT
|
2312 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT
;
2314 I915_WRITE(PORT_HOTPLUG_EN
, 0);
2315 POSTING_READ(PORT_HOTPLUG_EN
);
2317 I915_WRITE(VLV_IMR
, dev_priv
->irq_mask
);
2318 I915_WRITE(VLV_IER
, enable_mask
);
2319 I915_WRITE(VLV_IIR
, 0xffffffff);
2320 I915_WRITE(PIPESTAT(0), 0xffff);
2321 I915_WRITE(PIPESTAT(1), 0xffff);
2322 POSTING_READ(VLV_IER
);
2324 /* Interrupt setup is already guaranteed to be single-threaded, this is
2325 * just to make the assert_spin_locked check happy. */
2326 spin_lock_irqsave(&dev_priv
->irq_lock
, irqflags
);
2327 i915_enable_pipestat(dev_priv
, 0, pipestat_enable
);
2328 i915_enable_pipestat(dev_priv
, 0, PIPE_GMBUS_EVENT_ENABLE
);
2329 i915_enable_pipestat(dev_priv
, 1, pipestat_enable
);
2330 spin_unlock_irqrestore(&dev_priv
->irq_lock
, irqflags
);
2332 I915_WRITE(VLV_IIR
, 0xffffffff);
2333 I915_WRITE(VLV_IIR
, 0xffffffff);
2335 gen5_gt_irq_postinstall(dev
);
2337 /* ack & enable invalid PTE error interrupts */
2338 #if 0 /* FIXME: add support to irq handler for checking these bits */
2339 I915_WRITE(DPINVGTT
, DPINVGTT_STATUS_MASK
);
2340 I915_WRITE(DPINVGTT
, DPINVGTT_EN_MASK
);
2343 I915_WRITE(VLV_MASTER_IER
, MASTER_INTERRUPT_ENABLE
);
2348 static void valleyview_irq_uninstall(struct drm_device
*dev
)
2350 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
2356 del_timer_sync(&dev_priv
->hotplug_reenable_timer
);
2359 I915_WRITE(PIPESTAT(pipe
), 0xffff);
2361 I915_WRITE(HWSTAM
, 0xffffffff);
2362 I915_WRITE(PORT_HOTPLUG_EN
, 0);
2363 I915_WRITE(PORT_HOTPLUG_STAT
, I915_READ(PORT_HOTPLUG_STAT
));
2365 I915_WRITE(PIPESTAT(pipe
), 0xffff);
2366 I915_WRITE(VLV_IIR
, 0xffffffff);
2367 I915_WRITE(VLV_IMR
, 0xffffffff);
2368 I915_WRITE(VLV_IER
, 0x0);
2369 POSTING_READ(VLV_IER
);
2372 static void ironlake_irq_uninstall(struct drm_device
*dev
)
2374 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
2379 del_timer_sync(&dev_priv
->hotplug_reenable_timer
);
2381 I915_WRITE(HWSTAM
, 0xffffffff);
2383 I915_WRITE(DEIMR
, 0xffffffff);
2384 I915_WRITE(DEIER
, 0x0);
2385 I915_WRITE(DEIIR
, I915_READ(DEIIR
));
2387 I915_WRITE(GEN7_ERR_INT
, I915_READ(GEN7_ERR_INT
));
2389 I915_WRITE(GTIMR
, 0xffffffff);
2390 I915_WRITE(GTIER
, 0x0);
2391 I915_WRITE(GTIIR
, I915_READ(GTIIR
));
2393 if (HAS_PCH_NOP(dev
))
2396 I915_WRITE(SDEIMR
, 0xffffffff);
2397 I915_WRITE(SDEIER
, 0x0);
2398 I915_WRITE(SDEIIR
, I915_READ(SDEIIR
));
2399 if (HAS_PCH_CPT(dev
) || HAS_PCH_LPT(dev
))
2400 I915_WRITE(SERR_INT
, I915_READ(SERR_INT
));
2403 static void i8xx_irq_preinstall(struct drm_device
* dev
)
2405 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
2408 atomic_set(&dev_priv
->irq_received
, 0);
2411 I915_WRITE(PIPESTAT(pipe
), 0);
2412 I915_WRITE16(IMR
, 0xffff);
2413 I915_WRITE16(IER
, 0x0);
2414 POSTING_READ16(IER
);
2417 static int i8xx_irq_postinstall(struct drm_device
*dev
)
2419 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
2422 ~(I915_ERROR_PAGE_TABLE
| I915_ERROR_MEMORY_REFRESH
));
2424 /* Unmask the interrupts that we always want on. */
2425 dev_priv
->irq_mask
=
2426 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT
|
2427 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT
|
2428 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT
|
2429 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT
|
2430 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT
);
2431 I915_WRITE16(IMR
, dev_priv
->irq_mask
);
2434 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT
|
2435 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT
|
2436 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT
|
2437 I915_USER_INTERRUPT
);
2438 POSTING_READ16(IER
);
2444 * Returns true when a page flip has completed.
2446 static bool i8xx_handle_vblank(struct drm_device
*dev
,
2449 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
2450 u16 flip_pending
= DISPLAY_PLANE_FLIP_PENDING(pipe
);
2452 if (!drm_handle_vblank(dev
, pipe
))
2455 if ((iir
& flip_pending
) == 0)
2458 intel_prepare_page_flip(dev
, pipe
);
2460 /* We detect FlipDone by looking for the change in PendingFlip from '1'
2461 * to '0' on the following vblank, i.e. IIR has the Pendingflip
2462 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
2463 * the flip is completed (no longer pending). Since this doesn't raise
2464 * an interrupt per se, we watch for the change at vblank.
2466 if (I915_READ16(ISR
) & flip_pending
)
2469 intel_finish_page_flip(dev
, pipe
);
2474 static irqreturn_t
i8xx_irq_handler(int irq
, void *arg
)
2476 struct drm_device
*dev
= (struct drm_device
*) arg
;
2477 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
2480 unsigned long irqflags
;
2484 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT
|
2485 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT
;
2487 atomic_inc(&dev_priv
->irq_received
);
2489 iir
= I915_READ16(IIR
);
2493 while (iir
& ~flip_mask
) {
2494 /* Can't rely on pipestat interrupt bit in iir as it might
2495 * have been cleared after the pipestat interrupt was received.
2496 * It doesn't set the bit in iir again, but it still produces
2497 * interrupts (for non-MSI).
2499 spin_lock_irqsave(&dev_priv
->irq_lock
, irqflags
);
2500 if (iir
& I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT
)
2501 i915_handle_error(dev
, false);
2503 for_each_pipe(pipe
) {
2504 int reg
= PIPESTAT(pipe
);
2505 pipe_stats
[pipe
] = I915_READ(reg
);
2508 * Clear the PIPE*STAT regs before the IIR
2510 if (pipe_stats
[pipe
] & 0x8000ffff) {
2511 if (pipe_stats
[pipe
] & PIPE_FIFO_UNDERRUN_STATUS
)
2512 DRM_DEBUG_DRIVER("pipe %c underrun\n",
2514 I915_WRITE(reg
, pipe_stats
[pipe
]);
2518 spin_unlock_irqrestore(&dev_priv
->irq_lock
, irqflags
);
2520 I915_WRITE16(IIR
, iir
& ~flip_mask
);
2521 new_iir
= I915_READ16(IIR
); /* Flush posted writes */
2523 i915_update_dri1_breadcrumb(dev
);
2525 if (iir
& I915_USER_INTERRUPT
)
2526 notify_ring(dev
, &dev_priv
->ring
[RCS
]);
2528 if (pipe_stats
[0] & PIPE_VBLANK_INTERRUPT_STATUS
&&
2529 i8xx_handle_vblank(dev
, 0, iir
))
2530 flip_mask
&= ~DISPLAY_PLANE_FLIP_PENDING(0);
2532 if (pipe_stats
[1] & PIPE_VBLANK_INTERRUPT_STATUS
&&
2533 i8xx_handle_vblank(dev
, 1, iir
))
2534 flip_mask
&= ~DISPLAY_PLANE_FLIP_PENDING(1);
2542 static void i8xx_irq_uninstall(struct drm_device
* dev
)
2544 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
2547 for_each_pipe(pipe
) {
2548 /* Clear enable bits; then clear status bits */
2549 I915_WRITE(PIPESTAT(pipe
), 0);
2550 I915_WRITE(PIPESTAT(pipe
), I915_READ(PIPESTAT(pipe
)));
2552 I915_WRITE16(IMR
, 0xffff);
2553 I915_WRITE16(IER
, 0x0);
2554 I915_WRITE16(IIR
, I915_READ16(IIR
));
2557 static void i915_irq_preinstall(struct drm_device
* dev
)
2559 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
2562 atomic_set(&dev_priv
->irq_received
, 0);
2564 if (I915_HAS_HOTPLUG(dev
)) {
2565 I915_WRITE(PORT_HOTPLUG_EN
, 0);
2566 I915_WRITE(PORT_HOTPLUG_STAT
, I915_READ(PORT_HOTPLUG_STAT
));
2569 I915_WRITE16(HWSTAM
, 0xeffe);
2571 I915_WRITE(PIPESTAT(pipe
), 0);
2572 I915_WRITE(IMR
, 0xffffffff);
2573 I915_WRITE(IER
, 0x0);
2577 static int i915_irq_postinstall(struct drm_device
*dev
)
2579 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
2582 I915_WRITE(EMR
, ~(I915_ERROR_PAGE_TABLE
| I915_ERROR_MEMORY_REFRESH
));
2584 /* Unmask the interrupts that we always want on. */
2585 dev_priv
->irq_mask
=
2586 ~(I915_ASLE_INTERRUPT
|
2587 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT
|
2588 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT
|
2589 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT
|
2590 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT
|
2591 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT
);
2594 I915_ASLE_INTERRUPT
|
2595 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT
|
2596 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT
|
2597 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT
|
2598 I915_USER_INTERRUPT
;
2600 if (I915_HAS_HOTPLUG(dev
)) {
2601 I915_WRITE(PORT_HOTPLUG_EN
, 0);
2602 POSTING_READ(PORT_HOTPLUG_EN
);
2604 /* Enable in IER... */
2605 enable_mask
|= I915_DISPLAY_PORT_INTERRUPT
;
2606 /* and unmask in IMR */
2607 dev_priv
->irq_mask
&= ~I915_DISPLAY_PORT_INTERRUPT
;
2610 I915_WRITE(IMR
, dev_priv
->irq_mask
);
2611 I915_WRITE(IER
, enable_mask
);
2614 i915_enable_asle_pipestat(dev
);
2620 * Returns true when a page flip has completed.
2622 static bool i915_handle_vblank(struct drm_device
*dev
,
2623 int plane
, int pipe
, u32 iir
)
2625 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
2626 u32 flip_pending
= DISPLAY_PLANE_FLIP_PENDING(plane
);
2628 if (!drm_handle_vblank(dev
, pipe
))
2631 if ((iir
& flip_pending
) == 0)
2634 intel_prepare_page_flip(dev
, plane
);
2636 /* We detect FlipDone by looking for the change in PendingFlip from '1'
2637 * to '0' on the following vblank, i.e. IIR has the Pendingflip
2638 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
2639 * the flip is completed (no longer pending). Since this doesn't raise
2640 * an interrupt per se, we watch for the change at vblank.
2642 if (I915_READ(ISR
) & flip_pending
)
2645 intel_finish_page_flip(dev
, pipe
);
2650 static irqreturn_t
i915_irq_handler(int irq
, void *arg
)
2652 struct drm_device
*dev
= (struct drm_device
*) arg
;
2653 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
2654 u32 iir
, new_iir
, pipe_stats
[I915_MAX_PIPES
];
2655 unsigned long irqflags
;
2657 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT
|
2658 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT
;
2659 int pipe
, ret
= IRQ_NONE
;
2661 atomic_inc(&dev_priv
->irq_received
);
2663 iir
= I915_READ(IIR
);
2665 bool irq_received
= (iir
& ~flip_mask
) != 0;
2666 bool blc_event
= false;
2668 /* Can't rely on pipestat interrupt bit in iir as it might
2669 * have been cleared after the pipestat interrupt was received.
2670 * It doesn't set the bit in iir again, but it still produces
2671 * interrupts (for non-MSI).
2673 spin_lock_irqsave(&dev_priv
->irq_lock
, irqflags
);
2674 if (iir
& I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT
)
2675 i915_handle_error(dev
, false);
2677 for_each_pipe(pipe
) {
2678 int reg
= PIPESTAT(pipe
);
2679 pipe_stats
[pipe
] = I915_READ(reg
);
2681 /* Clear the PIPE*STAT regs before the IIR */
2682 if (pipe_stats
[pipe
] & 0x8000ffff) {
2683 if (pipe_stats
[pipe
] & PIPE_FIFO_UNDERRUN_STATUS
)
2684 DRM_DEBUG_DRIVER("pipe %c underrun\n",
2686 I915_WRITE(reg
, pipe_stats
[pipe
]);
2687 irq_received
= true;
2690 spin_unlock_irqrestore(&dev_priv
->irq_lock
, irqflags
);
2695 /* Consume port. Then clear IIR or we'll miss events */
2696 if ((I915_HAS_HOTPLUG(dev
)) &&
2697 (iir
& I915_DISPLAY_PORT_INTERRUPT
)) {
2698 u32 hotplug_status
= I915_READ(PORT_HOTPLUG_STAT
);
2699 u32 hotplug_trigger
= hotplug_status
& HOTPLUG_INT_STATUS_I915
;
2701 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
2704 intel_hpd_irq_handler(dev
, hotplug_trigger
, hpd_status_i915
);
2706 I915_WRITE(PORT_HOTPLUG_STAT
, hotplug_status
);
2707 POSTING_READ(PORT_HOTPLUG_STAT
);
2710 I915_WRITE(IIR
, iir
& ~flip_mask
);
2711 new_iir
= I915_READ(IIR
); /* Flush posted writes */
2713 if (iir
& I915_USER_INTERRUPT
)
2714 notify_ring(dev
, &dev_priv
->ring
[RCS
]);
2716 for_each_pipe(pipe
) {
2721 if (pipe_stats
[pipe
] & PIPE_VBLANK_INTERRUPT_STATUS
&&
2722 i915_handle_vblank(dev
, plane
, pipe
, iir
))
2723 flip_mask
&= ~DISPLAY_PLANE_FLIP_PENDING(plane
);
2725 if (pipe_stats
[pipe
] & PIPE_LEGACY_BLC_EVENT_STATUS
)
2729 if (blc_event
|| (iir
& I915_ASLE_INTERRUPT
))
2730 intel_opregion_asle_intr(dev
);
2732 /* With MSI, interrupts are only generated when iir
2733 * transitions from zero to nonzero. If another bit got
2734 * set while we were handling the existing iir bits, then
2735 * we would never get another interrupt.
2737 * This is fine on non-MSI as well, as if we hit this path
2738 * we avoid exiting the interrupt handler only to generate
2741 * Note that for MSI this could cause a stray interrupt report
2742 * if an interrupt landed in the time between writing IIR and
2743 * the posting read. This should be rare enough to never
2744 * trigger the 99% of 100,000 interrupts test for disabling
2749 } while (iir
& ~flip_mask
);
2751 i915_update_dri1_breadcrumb(dev
);
2756 static void i915_irq_uninstall(struct drm_device
* dev
)
2758 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
2761 del_timer_sync(&dev_priv
->hotplug_reenable_timer
);
2763 if (I915_HAS_HOTPLUG(dev
)) {
2764 I915_WRITE(PORT_HOTPLUG_EN
, 0);
2765 I915_WRITE(PORT_HOTPLUG_STAT
, I915_READ(PORT_HOTPLUG_STAT
));
2768 I915_WRITE16(HWSTAM
, 0xffff);
2769 for_each_pipe(pipe
) {
2770 /* Clear enable bits; then clear status bits */
2771 I915_WRITE(PIPESTAT(pipe
), 0);
2772 I915_WRITE(PIPESTAT(pipe
), I915_READ(PIPESTAT(pipe
)));
2774 I915_WRITE(IMR
, 0xffffffff);
2775 I915_WRITE(IER
, 0x0);
2777 I915_WRITE(IIR
, I915_READ(IIR
));
2780 static void i965_irq_preinstall(struct drm_device
* dev
)
2782 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
2785 atomic_set(&dev_priv
->irq_received
, 0);
2787 I915_WRITE(PORT_HOTPLUG_EN
, 0);
2788 I915_WRITE(PORT_HOTPLUG_STAT
, I915_READ(PORT_HOTPLUG_STAT
));
2790 I915_WRITE(HWSTAM
, 0xeffe);
2792 I915_WRITE(PIPESTAT(pipe
), 0);
2793 I915_WRITE(IMR
, 0xffffffff);
2794 I915_WRITE(IER
, 0x0);
2798 static int i965_irq_postinstall(struct drm_device
*dev
)
2800 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
2803 unsigned long irqflags
;
2805 /* Unmask the interrupts that we always want on. */
2806 dev_priv
->irq_mask
= ~(I915_ASLE_INTERRUPT
|
2807 I915_DISPLAY_PORT_INTERRUPT
|
2808 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT
|
2809 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT
|
2810 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT
|
2811 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT
|
2812 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT
);
2814 enable_mask
= ~dev_priv
->irq_mask
;
2815 enable_mask
&= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT
|
2816 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT
);
2817 enable_mask
|= I915_USER_INTERRUPT
;
2820 enable_mask
|= I915_BSD_USER_INTERRUPT
;
2822 /* Interrupt setup is already guaranteed to be single-threaded, this is
2823 * just to make the assert_spin_locked check happy. */
2824 spin_lock_irqsave(&dev_priv
->irq_lock
, irqflags
);
2825 i915_enable_pipestat(dev_priv
, 0, PIPE_GMBUS_EVENT_ENABLE
);
2826 spin_unlock_irqrestore(&dev_priv
->irq_lock
, irqflags
);
2829 * Enable some error detection, note the instruction error mask
2830 * bit is reserved, so we leave it masked.
2833 error_mask
= ~(GM45_ERROR_PAGE_TABLE
|
2834 GM45_ERROR_MEM_PRIV
|
2835 GM45_ERROR_CP_PRIV
|
2836 I915_ERROR_MEMORY_REFRESH
);
2838 error_mask
= ~(I915_ERROR_PAGE_TABLE
|
2839 I915_ERROR_MEMORY_REFRESH
);
2841 I915_WRITE(EMR
, error_mask
);
2843 I915_WRITE(IMR
, dev_priv
->irq_mask
);
2844 I915_WRITE(IER
, enable_mask
);
2847 I915_WRITE(PORT_HOTPLUG_EN
, 0);
2848 POSTING_READ(PORT_HOTPLUG_EN
);
2850 i915_enable_asle_pipestat(dev
);
2855 static void i915_hpd_irq_setup(struct drm_device
*dev
)
2857 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
2858 struct drm_mode_config
*mode_config
= &dev
->mode_config
;
2859 struct intel_encoder
*intel_encoder
;
2862 assert_spin_locked(&dev_priv
->irq_lock
);
2864 if (I915_HAS_HOTPLUG(dev
)) {
2865 hotplug_en
= I915_READ(PORT_HOTPLUG_EN
);
2866 hotplug_en
&= ~HOTPLUG_INT_EN_MASK
;
2867 /* Note HDMI and DP share hotplug bits */
2868 /* enable bits are the same for all generations */
2869 list_for_each_entry(intel_encoder
, &mode_config
->encoder_list
, base
.head
)
2870 if (dev_priv
->hpd_stats
[intel_encoder
->hpd_pin
].hpd_mark
== HPD_ENABLED
)
2871 hotplug_en
|= hpd_mask_i915
[intel_encoder
->hpd_pin
];
2872 /* Programming the CRT detection parameters tends
2873 to generate a spurious hotplug event about three
2874 seconds later. So just do it once.
2877 hotplug_en
|= CRT_HOTPLUG_ACTIVATION_PERIOD_64
;
2878 hotplug_en
&= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK
;
2879 hotplug_en
|= CRT_HOTPLUG_VOLTAGE_COMPARE_50
;
2881 /* Ignore TV since it's buggy */
2882 I915_WRITE(PORT_HOTPLUG_EN
, hotplug_en
);
2886 static irqreturn_t
i965_irq_handler(int irq
, void *arg
)
2888 struct drm_device
*dev
= (struct drm_device
*) arg
;
2889 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
2891 u32 pipe_stats
[I915_MAX_PIPES
];
2892 unsigned long irqflags
;
2894 int ret
= IRQ_NONE
, pipe
;
2896 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT
|
2897 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT
;
2899 atomic_inc(&dev_priv
->irq_received
);
2901 iir
= I915_READ(IIR
);
2904 bool blc_event
= false;
2906 irq_received
= (iir
& ~flip_mask
) != 0;
2908 /* Can't rely on pipestat interrupt bit in iir as it might
2909 * have been cleared after the pipestat interrupt was received.
2910 * It doesn't set the bit in iir again, but it still produces
2911 * interrupts (for non-MSI).
2913 spin_lock_irqsave(&dev_priv
->irq_lock
, irqflags
);
2914 if (iir
& I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT
)
2915 i915_handle_error(dev
, false);
2917 for_each_pipe(pipe
) {
2918 int reg
= PIPESTAT(pipe
);
2919 pipe_stats
[pipe
] = I915_READ(reg
);
2922 * Clear the PIPE*STAT regs before the IIR
2924 if (pipe_stats
[pipe
] & 0x8000ffff) {
2925 if (pipe_stats
[pipe
] & PIPE_FIFO_UNDERRUN_STATUS
)
2926 DRM_DEBUG_DRIVER("pipe %c underrun\n",
2928 I915_WRITE(reg
, pipe_stats
[pipe
]);
2932 spin_unlock_irqrestore(&dev_priv
->irq_lock
, irqflags
);
2939 /* Consume port. Then clear IIR or we'll miss events */
2940 if (iir
& I915_DISPLAY_PORT_INTERRUPT
) {
2941 u32 hotplug_status
= I915_READ(PORT_HOTPLUG_STAT
);
2942 u32 hotplug_trigger
= hotplug_status
& (IS_G4X(dev
) ?
2943 HOTPLUG_INT_STATUS_G4X
:
2944 HOTPLUG_INT_STATUS_I915
);
2946 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
2949 intel_hpd_irq_handler(dev
, hotplug_trigger
,
2950 IS_G4X(dev
) ? hpd_status_gen4
: hpd_status_i915
);
2952 I915_WRITE(PORT_HOTPLUG_STAT
, hotplug_status
);
2953 I915_READ(PORT_HOTPLUG_STAT
);
2956 I915_WRITE(IIR
, iir
& ~flip_mask
);
2957 new_iir
= I915_READ(IIR
); /* Flush posted writes */
2959 if (iir
& I915_USER_INTERRUPT
)
2960 notify_ring(dev
, &dev_priv
->ring
[RCS
]);
2961 if (iir
& I915_BSD_USER_INTERRUPT
)
2962 notify_ring(dev
, &dev_priv
->ring
[VCS
]);
2964 for_each_pipe(pipe
) {
2965 if (pipe_stats
[pipe
] & PIPE_START_VBLANK_INTERRUPT_STATUS
&&
2966 i915_handle_vblank(dev
, pipe
, pipe
, iir
))
2967 flip_mask
&= ~DISPLAY_PLANE_FLIP_PENDING(pipe
);
2969 if (pipe_stats
[pipe
] & PIPE_LEGACY_BLC_EVENT_STATUS
)
2974 if (blc_event
|| (iir
& I915_ASLE_INTERRUPT
))
2975 intel_opregion_asle_intr(dev
);
2977 if (pipe_stats
[0] & PIPE_GMBUS_INTERRUPT_STATUS
)
2978 gmbus_irq_handler(dev
);
2980 /* With MSI, interrupts are only generated when iir
2981 * transitions from zero to nonzero. If another bit got
2982 * set while we were handling the existing iir bits, then
2983 * we would never get another interrupt.
2985 * This is fine on non-MSI as well, as if we hit this path
2986 * we avoid exiting the interrupt handler only to generate
2989 * Note that for MSI this could cause a stray interrupt report
2990 * if an interrupt landed in the time between writing IIR and
2991 * the posting read. This should be rare enough to never
2992 * trigger the 99% of 100,000 interrupts test for disabling
2998 i915_update_dri1_breadcrumb(dev
);
3003 static void i965_irq_uninstall(struct drm_device
* dev
)
3005 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
3011 del_timer_sync(&dev_priv
->hotplug_reenable_timer
);
3013 I915_WRITE(PORT_HOTPLUG_EN
, 0);
3014 I915_WRITE(PORT_HOTPLUG_STAT
, I915_READ(PORT_HOTPLUG_STAT
));
3016 I915_WRITE(HWSTAM
, 0xffffffff);
3018 I915_WRITE(PIPESTAT(pipe
), 0);
3019 I915_WRITE(IMR
, 0xffffffff);
3020 I915_WRITE(IER
, 0x0);
3023 I915_WRITE(PIPESTAT(pipe
),
3024 I915_READ(PIPESTAT(pipe
)) & 0x8000ffff);
3025 I915_WRITE(IIR
, I915_READ(IIR
));
3028 static void i915_reenable_hotplug_timer_func(unsigned long data
)
3030 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*)data
;
3031 struct drm_device
*dev
= dev_priv
->dev
;
3032 struct drm_mode_config
*mode_config
= &dev
->mode_config
;
3033 unsigned long irqflags
;
3036 spin_lock_irqsave(&dev_priv
->irq_lock
, irqflags
);
3037 for (i
= (HPD_NONE
+ 1); i
< HPD_NUM_PINS
; i
++) {
3038 struct drm_connector
*connector
;
3040 if (dev_priv
->hpd_stats
[i
].hpd_mark
!= HPD_DISABLED
)
3043 dev_priv
->hpd_stats
[i
].hpd_mark
= HPD_ENABLED
;
3045 list_for_each_entry(connector
, &mode_config
->connector_list
, head
) {
3046 struct intel_connector
*intel_connector
= to_intel_connector(connector
);
3048 if (intel_connector
->encoder
->hpd_pin
== i
) {
3049 if (connector
->polled
!= intel_connector
->polled
)
3050 DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n",
3051 drm_get_connector_name(connector
));
3052 connector
->polled
= intel_connector
->polled
;
3053 if (!connector
->polled
)
3054 connector
->polled
= DRM_CONNECTOR_POLL_HPD
;
3058 if (dev_priv
->display
.hpd_irq_setup
)
3059 dev_priv
->display
.hpd_irq_setup(dev
);
3060 spin_unlock_irqrestore(&dev_priv
->irq_lock
, irqflags
);
3063 void intel_irq_init(struct drm_device
*dev
)
3065 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3067 INIT_WORK(&dev_priv
->hotplug_work
, i915_hotplug_work_func
);
3068 INIT_WORK(&dev_priv
->gpu_error
.work
, i915_error_work_func
);
3069 INIT_WORK(&dev_priv
->rps
.work
, gen6_pm_rps_work
);
3070 INIT_WORK(&dev_priv
->l3_parity
.error_work
, ivybridge_parity_work
);
3072 setup_timer(&dev_priv
->gpu_error
.hangcheck_timer
,
3073 i915_hangcheck_elapsed
,
3074 (unsigned long) dev
);
3075 setup_timer(&dev_priv
->hotplug_reenable_timer
, i915_reenable_hotplug_timer_func
,
3076 (unsigned long) dev_priv
);
3078 pm_qos_add_request(&dev_priv
->pm_qos
, PM_QOS_CPU_DMA_LATENCY
, PM_QOS_DEFAULT_VALUE
);
3080 dev
->driver
->get_vblank_counter
= i915_get_vblank_counter
;
3081 dev
->max_vblank_count
= 0xffffff; /* only 24 bits of frame count */
3082 if (IS_G4X(dev
) || INTEL_INFO(dev
)->gen
>= 5) {
3083 dev
->max_vblank_count
= 0xffffffff; /* full 32 bit counter */
3084 dev
->driver
->get_vblank_counter
= gm45_get_vblank_counter
;
3087 if (drm_core_check_feature(dev
, DRIVER_MODESET
))
3088 dev
->driver
->get_vblank_timestamp
= i915_get_vblank_timestamp
;
3090 dev
->driver
->get_vblank_timestamp
= NULL
;
3091 dev
->driver
->get_scanout_position
= i915_get_crtc_scanoutpos
;
3093 if (IS_VALLEYVIEW(dev
)) {
3094 dev
->driver
->irq_handler
= valleyview_irq_handler
;
3095 dev
->driver
->irq_preinstall
= valleyview_irq_preinstall
;
3096 dev
->driver
->irq_postinstall
= valleyview_irq_postinstall
;
3097 dev
->driver
->irq_uninstall
= valleyview_irq_uninstall
;
3098 dev
->driver
->enable_vblank
= valleyview_enable_vblank
;
3099 dev
->driver
->disable_vblank
= valleyview_disable_vblank
;
3100 dev_priv
->display
.hpd_irq_setup
= i915_hpd_irq_setup
;
3101 } else if (IS_IVYBRIDGE(dev
) || IS_HASWELL(dev
)) {
3102 /* Share uninstall handlers with ILK/SNB */
3103 dev
->driver
->irq_handler
= ivybridge_irq_handler
;
3104 dev
->driver
->irq_preinstall
= ironlake_irq_preinstall
;
3105 dev
->driver
->irq_postinstall
= ivybridge_irq_postinstall
;
3106 dev
->driver
->irq_uninstall
= ironlake_irq_uninstall
;
3107 dev
->driver
->enable_vblank
= ivybridge_enable_vblank
;
3108 dev
->driver
->disable_vblank
= ivybridge_disable_vblank
;
3109 dev_priv
->display
.hpd_irq_setup
= ibx_hpd_irq_setup
;
3110 } else if (HAS_PCH_SPLIT(dev
)) {
3111 dev
->driver
->irq_handler
= ironlake_irq_handler
;
3112 dev
->driver
->irq_preinstall
= ironlake_irq_preinstall
;
3113 dev
->driver
->irq_postinstall
= ironlake_irq_postinstall
;
3114 dev
->driver
->irq_uninstall
= ironlake_irq_uninstall
;
3115 dev
->driver
->enable_vblank
= ironlake_enable_vblank
;
3116 dev
->driver
->disable_vblank
= ironlake_disable_vblank
;
3117 dev_priv
->display
.hpd_irq_setup
= ibx_hpd_irq_setup
;
3119 if (INTEL_INFO(dev
)->gen
== 2) {
3120 dev
->driver
->irq_preinstall
= i8xx_irq_preinstall
;
3121 dev
->driver
->irq_postinstall
= i8xx_irq_postinstall
;
3122 dev
->driver
->irq_handler
= i8xx_irq_handler
;
3123 dev
->driver
->irq_uninstall
= i8xx_irq_uninstall
;
3124 } else if (INTEL_INFO(dev
)->gen
== 3) {
3125 dev
->driver
->irq_preinstall
= i915_irq_preinstall
;
3126 dev
->driver
->irq_postinstall
= i915_irq_postinstall
;
3127 dev
->driver
->irq_uninstall
= i915_irq_uninstall
;
3128 dev
->driver
->irq_handler
= i915_irq_handler
;
3129 dev_priv
->display
.hpd_irq_setup
= i915_hpd_irq_setup
;
3131 dev
->driver
->irq_preinstall
= i965_irq_preinstall
;
3132 dev
->driver
->irq_postinstall
= i965_irq_postinstall
;
3133 dev
->driver
->irq_uninstall
= i965_irq_uninstall
;
3134 dev
->driver
->irq_handler
= i965_irq_handler
;
3135 dev_priv
->display
.hpd_irq_setup
= i915_hpd_irq_setup
;
3137 dev
->driver
->enable_vblank
= i915_enable_vblank
;
3138 dev
->driver
->disable_vblank
= i915_disable_vblank
;
3142 void intel_hpd_init(struct drm_device
*dev
)
3144 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3145 struct drm_mode_config
*mode_config
= &dev
->mode_config
;
3146 struct drm_connector
*connector
;
3147 unsigned long irqflags
;
3150 for (i
= 1; i
< HPD_NUM_PINS
; i
++) {
3151 dev_priv
->hpd_stats
[i
].hpd_cnt
= 0;
3152 dev_priv
->hpd_stats
[i
].hpd_mark
= HPD_ENABLED
;
3154 list_for_each_entry(connector
, &mode_config
->connector_list
, head
) {
3155 struct intel_connector
*intel_connector
= to_intel_connector(connector
);
3156 connector
->polled
= intel_connector
->polled
;
3157 if (!connector
->polled
&& I915_HAS_HOTPLUG(dev
) && intel_connector
->encoder
->hpd_pin
> HPD_NONE
)
3158 connector
->polled
= DRM_CONNECTOR_POLL_HPD
;
3161 /* Interrupt setup is already guaranteed to be single-threaded, this is
3162 * just to make the assert_spin_locked checks happy. */
3163 spin_lock_irqsave(&dev_priv
->irq_lock
, irqflags
);
3164 if (dev_priv
->display
.hpd_irq_setup
)
3165 dev_priv
->display
.hpd_irq_setup(dev
);
3166 spin_unlock_irqrestore(&dev_priv
->irq_lock
, irqflags
);