1c0e09200SDave Airlie /* i915_irq.c -- IRQ support for the I915 -*- linux-c -*- 2c0e09200SDave Airlie */ 3c0e09200SDave Airlie /* 4c0e09200SDave Airlie * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. 5c0e09200SDave Airlie * All Rights Reserved. 6c0e09200SDave Airlie * 7c0e09200SDave Airlie * Permission is hereby granted, free of charge, to any person obtaining a 8c0e09200SDave Airlie * copy of this software and associated documentation files (the 9c0e09200SDave Airlie * "Software"), to deal in the Software without restriction, including 10c0e09200SDave Airlie * without limitation the rights to use, copy, modify, merge, publish, 11c0e09200SDave Airlie * distribute, sub license, and/or sell copies of the Software, and to 12c0e09200SDave Airlie * permit persons to whom the Software is furnished to do so, subject to 13c0e09200SDave Airlie * the following conditions: 14c0e09200SDave Airlie * 15c0e09200SDave Airlie * The above copyright notice and this permission notice (including the 16c0e09200SDave Airlie * next paragraph) shall be included in all copies or substantial portions 17c0e09200SDave Airlie * of the Software. 18c0e09200SDave Airlie * 19c0e09200SDave Airlie * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 20c0e09200SDave Airlie * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21c0e09200SDave Airlie * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 22c0e09200SDave Airlie * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 23c0e09200SDave Airlie * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 24c0e09200SDave Airlie * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 25c0e09200SDave Airlie * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26c0e09200SDave Airlie * 27c0e09200SDave Airlie */ 28c0e09200SDave Airlie 29a70491ccSJoe Perches #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 30a70491ccSJoe Perches 3163eeaf38SJesse Barnes #include <linux/sysrq.h> 325a0e3ad6STejun Heo #include <linux/slab.h> 33c0e09200SDave Airlie #include "drmP.h" 34c0e09200SDave Airlie #include "drm.h" 35c0e09200SDave Airlie #include "i915_drm.h" 36c0e09200SDave Airlie #include "i915_drv.h" 371c5d22f7SChris Wilson #include "i915_trace.h" 3879e53945SJesse Barnes #include "intel_drv.h" 39c0e09200SDave Airlie 40c0e09200SDave Airlie #define MAX_NOPID ((u32)~0) 41c0e09200SDave Airlie 427c463586SKeith Packard /** 437c463586SKeith Packard * Interrupts that are always left unmasked. 447c463586SKeith Packard * 457c463586SKeith Packard * Since pipe events are edge-triggered from the PIPESTAT register to IIR, 467c463586SKeith Packard * we leave them always unmasked in IMR and then control enabling them through 477c463586SKeith Packard * PIPESTAT alone. 487c463586SKeith Packard */ 496b95a207SKristian Høgsberg #define I915_INTERRUPT_ENABLE_FIX \ 506b95a207SKristian Høgsberg (I915_ASLE_INTERRUPT | \ 510a3e67a4SJesse Barnes I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | \ 5263eeaf38SJesse Barnes I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | \ 536b95a207SKristian Høgsberg I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | \ 546b95a207SKristian Høgsberg I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT | \ 5563eeaf38SJesse Barnes I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) 56ed4cb414SEric Anholt 577c463586SKeith Packard /** Interrupts that we mask and unmask at runtime. */ 58d1b851fcSZou Nan hai #define I915_INTERRUPT_ENABLE_VAR (I915_USER_INTERRUPT | I915_BSD_USER_INTERRUPT) 597c463586SKeith Packard 6079e53945SJesse Barnes #define I915_PIPE_VBLANK_STATUS (PIPE_START_VBLANK_INTERRUPT_STATUS |\ 6179e53945SJesse Barnes PIPE_VBLANK_INTERRUPT_STATUS) 6279e53945SJesse Barnes 6379e53945SJesse Barnes #define I915_PIPE_VBLANK_ENABLE (PIPE_START_VBLANK_INTERRUPT_ENABLE |\ 6479e53945SJesse Barnes PIPE_VBLANK_INTERRUPT_ENABLE) 6579e53945SJesse Barnes 6679e53945SJesse Barnes #define DRM_I915_VBLANK_PIPE_ALL (DRM_I915_VBLANK_PIPE_A | \ 6779e53945SJesse Barnes DRM_I915_VBLANK_PIPE_B) 6879e53945SJesse Barnes 69036a4a7dSZhenyu Wang /* For display hotplug interrupt */ 70995b6762SChris Wilson static void 71f2b115e6SAdam Jackson ironlake_enable_display_irq(drm_i915_private_t *dev_priv, u32 mask) 72036a4a7dSZhenyu Wang { 731ec14ad3SChris Wilson if ((dev_priv->irq_mask & mask) != 0) { 741ec14ad3SChris Wilson dev_priv->irq_mask &= ~mask; 751ec14ad3SChris Wilson I915_WRITE(DEIMR, dev_priv->irq_mask); 763143a2bfSChris Wilson POSTING_READ(DEIMR); 77036a4a7dSZhenyu Wang } 78036a4a7dSZhenyu Wang } 79036a4a7dSZhenyu Wang 80036a4a7dSZhenyu Wang static inline void 81f2b115e6SAdam Jackson ironlake_disable_display_irq(drm_i915_private_t *dev_priv, u32 mask) 82036a4a7dSZhenyu Wang { 831ec14ad3SChris Wilson if ((dev_priv->irq_mask & mask) != mask) { 841ec14ad3SChris Wilson dev_priv->irq_mask |= mask; 851ec14ad3SChris Wilson I915_WRITE(DEIMR, dev_priv->irq_mask); 863143a2bfSChris Wilson POSTING_READ(DEIMR); 87036a4a7dSZhenyu Wang } 88036a4a7dSZhenyu Wang } 89036a4a7dSZhenyu Wang 907c463586SKeith Packard void 917c463586SKeith Packard i915_enable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask) 927c463586SKeith Packard { 937c463586SKeith Packard if ((dev_priv->pipestat[pipe] & mask) != mask) { 949db4a9c7SJesse Barnes u32 reg = PIPESTAT(pipe); 957c463586SKeith Packard 967c463586SKeith Packard dev_priv->pipestat[pipe] |= mask; 977c463586SKeith Packard /* Enable the interrupt, clear any pending status */ 987c463586SKeith Packard I915_WRITE(reg, dev_priv->pipestat[pipe] | (mask >> 16)); 993143a2bfSChris Wilson POSTING_READ(reg); 1007c463586SKeith Packard } 1017c463586SKeith Packard } 1027c463586SKeith Packard 1037c463586SKeith Packard void 1047c463586SKeith Packard i915_disable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask) 1057c463586SKeith Packard { 1067c463586SKeith Packard if ((dev_priv->pipestat[pipe] & mask) != 0) { 1079db4a9c7SJesse Barnes u32 reg = PIPESTAT(pipe); 1087c463586SKeith Packard 1097c463586SKeith Packard dev_priv->pipestat[pipe] &= ~mask; 1107c463586SKeith Packard I915_WRITE(reg, dev_priv->pipestat[pipe]); 1113143a2bfSChris Wilson POSTING_READ(reg); 1127c463586SKeith Packard } 1137c463586SKeith Packard } 1147c463586SKeith Packard 115c0e09200SDave Airlie /** 11601c66889SZhao Yakui * intel_enable_asle - enable ASLE interrupt for OpRegion 11701c66889SZhao Yakui */ 11801c66889SZhao Yakui void intel_enable_asle(struct drm_device *dev) 11901c66889SZhao Yakui { 1201ec14ad3SChris Wilson drm_i915_private_t *dev_priv = dev->dev_private; 1211ec14ad3SChris Wilson unsigned long irqflags; 1221ec14ad3SChris Wilson 1237e231dbeSJesse Barnes /* FIXME: opregion/asle for VLV */ 1247e231dbeSJesse Barnes if (IS_VALLEYVIEW(dev)) 1257e231dbeSJesse Barnes return; 1267e231dbeSJesse Barnes 1271ec14ad3SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 12801c66889SZhao Yakui 129c619eed4SEric Anholt if (HAS_PCH_SPLIT(dev)) 130f2b115e6SAdam Jackson ironlake_enable_display_irq(dev_priv, DE_GSE); 131edcb49caSZhao Yakui else { 13201c66889SZhao Yakui i915_enable_pipestat(dev_priv, 1, 133d874bcffSJesse Barnes PIPE_LEGACY_BLC_EVENT_ENABLE); 134a6c45cf0SChris Wilson if (INTEL_INFO(dev)->gen >= 4) 135edcb49caSZhao Yakui i915_enable_pipestat(dev_priv, 0, 136d874bcffSJesse Barnes PIPE_LEGACY_BLC_EVENT_ENABLE); 137edcb49caSZhao Yakui } 1381ec14ad3SChris Wilson 1391ec14ad3SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 14001c66889SZhao Yakui } 14101c66889SZhao Yakui 14201c66889SZhao Yakui /** 1430a3e67a4SJesse Barnes * i915_pipe_enabled - check if a pipe is enabled 1440a3e67a4SJesse Barnes * @dev: DRM device 1450a3e67a4SJesse Barnes * @pipe: pipe to check 1460a3e67a4SJesse Barnes * 1470a3e67a4SJesse Barnes * Reading certain registers when the pipe is disabled can hang the chip. 1480a3e67a4SJesse Barnes * Use this routine to make sure the PLL is running and the pipe is active 1490a3e67a4SJesse Barnes * before reading such registers if unsure. 1500a3e67a4SJesse Barnes */ 1510a3e67a4SJesse Barnes static int 1520a3e67a4SJesse Barnes i915_pipe_enabled(struct drm_device *dev, int pipe) 1530a3e67a4SJesse Barnes { 1540a3e67a4SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 1555eddb70bSChris Wilson return I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE; 1560a3e67a4SJesse Barnes } 1570a3e67a4SJesse Barnes 15842f52ef8SKeith Packard /* Called from drm generic code, passed a 'crtc', which 15942f52ef8SKeith Packard * we use as a pipe index 16042f52ef8SKeith Packard */ 161f71d4af4SJesse Barnes static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe) 1620a3e67a4SJesse Barnes { 1630a3e67a4SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 1640a3e67a4SJesse Barnes unsigned long high_frame; 1650a3e67a4SJesse Barnes unsigned long low_frame; 1665eddb70bSChris Wilson u32 high1, high2, low; 1670a3e67a4SJesse Barnes 1680a3e67a4SJesse Barnes if (!i915_pipe_enabled(dev, pipe)) { 16944d98a61SZhao Yakui DRM_DEBUG_DRIVER("trying to get vblank count for disabled " 1709db4a9c7SJesse Barnes "pipe %c\n", pipe_name(pipe)); 1710a3e67a4SJesse Barnes return 0; 1720a3e67a4SJesse Barnes } 1730a3e67a4SJesse Barnes 1749db4a9c7SJesse Barnes high_frame = PIPEFRAME(pipe); 1759db4a9c7SJesse Barnes low_frame = PIPEFRAMEPIXEL(pipe); 1765eddb70bSChris Wilson 1770a3e67a4SJesse Barnes /* 1780a3e67a4SJesse Barnes * High & low register fields aren't synchronized, so make sure 1790a3e67a4SJesse Barnes * we get a low value that's stable across two reads of the high 1800a3e67a4SJesse Barnes * register. 1810a3e67a4SJesse Barnes */ 1820a3e67a4SJesse Barnes do { 1835eddb70bSChris Wilson high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK; 1845eddb70bSChris Wilson low = I915_READ(low_frame) & PIPE_FRAME_LOW_MASK; 1855eddb70bSChris Wilson high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK; 1860a3e67a4SJesse Barnes } while (high1 != high2); 1870a3e67a4SJesse Barnes 1885eddb70bSChris Wilson high1 >>= PIPE_FRAME_HIGH_SHIFT; 1895eddb70bSChris Wilson low >>= PIPE_FRAME_LOW_SHIFT; 1905eddb70bSChris Wilson return (high1 << 8) | low; 1910a3e67a4SJesse Barnes } 1920a3e67a4SJesse Barnes 193f71d4af4SJesse Barnes static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe) 1949880b7a5SJesse Barnes { 1959880b7a5SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 1969db4a9c7SJesse Barnes int reg = PIPE_FRMCOUNT_GM45(pipe); 1979880b7a5SJesse Barnes 1989880b7a5SJesse Barnes if (!i915_pipe_enabled(dev, pipe)) { 19944d98a61SZhao Yakui DRM_DEBUG_DRIVER("trying to get vblank count for disabled " 2009db4a9c7SJesse Barnes "pipe %c\n", pipe_name(pipe)); 2019880b7a5SJesse Barnes return 0; 2029880b7a5SJesse Barnes } 2039880b7a5SJesse Barnes 2049880b7a5SJesse Barnes return I915_READ(reg); 2059880b7a5SJesse Barnes } 2069880b7a5SJesse Barnes 207f71d4af4SJesse Barnes static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe, 2080af7e4dfSMario Kleiner int *vpos, int *hpos) 2090af7e4dfSMario Kleiner { 2100af7e4dfSMario Kleiner drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2110af7e4dfSMario Kleiner u32 vbl = 0, position = 0; 2120af7e4dfSMario Kleiner int vbl_start, vbl_end, htotal, vtotal; 2130af7e4dfSMario Kleiner bool in_vbl = true; 2140af7e4dfSMario Kleiner int ret = 0; 2150af7e4dfSMario Kleiner 2160af7e4dfSMario Kleiner if (!i915_pipe_enabled(dev, pipe)) { 2170af7e4dfSMario Kleiner DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled " 2189db4a9c7SJesse Barnes "pipe %c\n", pipe_name(pipe)); 2190af7e4dfSMario Kleiner return 0; 2200af7e4dfSMario Kleiner } 2210af7e4dfSMario Kleiner 2220af7e4dfSMario Kleiner /* Get vtotal. */ 2230af7e4dfSMario Kleiner vtotal = 1 + ((I915_READ(VTOTAL(pipe)) >> 16) & 0x1fff); 2240af7e4dfSMario Kleiner 2250af7e4dfSMario Kleiner if (INTEL_INFO(dev)->gen >= 4) { 2260af7e4dfSMario Kleiner /* No obvious pixelcount register. Only query vertical 2270af7e4dfSMario Kleiner * scanout position from Display scan line register. 2280af7e4dfSMario Kleiner */ 2290af7e4dfSMario Kleiner position = I915_READ(PIPEDSL(pipe)); 2300af7e4dfSMario Kleiner 2310af7e4dfSMario Kleiner /* Decode into vertical scanout position. Don't have 2320af7e4dfSMario Kleiner * horizontal scanout position. 2330af7e4dfSMario Kleiner */ 2340af7e4dfSMario Kleiner *vpos = position & 0x1fff; 2350af7e4dfSMario Kleiner *hpos = 0; 2360af7e4dfSMario Kleiner } else { 2370af7e4dfSMario Kleiner /* Have access to pixelcount since start of frame. 2380af7e4dfSMario Kleiner * We can split this into vertical and horizontal 2390af7e4dfSMario Kleiner * scanout position. 2400af7e4dfSMario Kleiner */ 2410af7e4dfSMario Kleiner position = (I915_READ(PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT; 2420af7e4dfSMario Kleiner 2430af7e4dfSMario Kleiner htotal = 1 + ((I915_READ(HTOTAL(pipe)) >> 16) & 0x1fff); 2440af7e4dfSMario Kleiner *vpos = position / htotal; 2450af7e4dfSMario Kleiner *hpos = position - (*vpos * htotal); 2460af7e4dfSMario Kleiner } 2470af7e4dfSMario Kleiner 2480af7e4dfSMario Kleiner /* Query vblank area. */ 2490af7e4dfSMario Kleiner vbl = I915_READ(VBLANK(pipe)); 2500af7e4dfSMario Kleiner 2510af7e4dfSMario Kleiner /* Test position against vblank region. */ 2520af7e4dfSMario Kleiner vbl_start = vbl & 0x1fff; 2530af7e4dfSMario Kleiner vbl_end = (vbl >> 16) & 0x1fff; 2540af7e4dfSMario Kleiner 2550af7e4dfSMario Kleiner if ((*vpos < vbl_start) || (*vpos > vbl_end)) 2560af7e4dfSMario Kleiner in_vbl = false; 2570af7e4dfSMario Kleiner 2580af7e4dfSMario Kleiner /* Inside "upper part" of vblank area? Apply corrective offset: */ 2590af7e4dfSMario Kleiner if (in_vbl && (*vpos >= vbl_start)) 2600af7e4dfSMario Kleiner *vpos = *vpos - vtotal; 2610af7e4dfSMario Kleiner 2620af7e4dfSMario Kleiner /* Readouts valid? */ 2630af7e4dfSMario Kleiner if (vbl > 0) 2640af7e4dfSMario Kleiner ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE; 2650af7e4dfSMario Kleiner 2660af7e4dfSMario Kleiner /* In vblank? */ 2670af7e4dfSMario Kleiner if (in_vbl) 2680af7e4dfSMario Kleiner ret |= DRM_SCANOUTPOS_INVBL; 2690af7e4dfSMario Kleiner 2700af7e4dfSMario Kleiner return ret; 2710af7e4dfSMario Kleiner } 2720af7e4dfSMario Kleiner 273f71d4af4SJesse Barnes static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe, 2740af7e4dfSMario Kleiner int *max_error, 2750af7e4dfSMario Kleiner struct timeval *vblank_time, 2760af7e4dfSMario Kleiner unsigned flags) 2770af7e4dfSMario Kleiner { 2784041b853SChris Wilson struct drm_i915_private *dev_priv = dev->dev_private; 2794041b853SChris Wilson struct drm_crtc *crtc; 2800af7e4dfSMario Kleiner 2814041b853SChris Wilson if (pipe < 0 || pipe >= dev_priv->num_pipe) { 2824041b853SChris Wilson DRM_ERROR("Invalid crtc %d\n", pipe); 2830af7e4dfSMario Kleiner return -EINVAL; 2840af7e4dfSMario Kleiner } 2850af7e4dfSMario Kleiner 2860af7e4dfSMario Kleiner /* Get drm_crtc to timestamp: */ 2874041b853SChris Wilson crtc = intel_get_crtc_for_pipe(dev, pipe); 2884041b853SChris Wilson if (crtc == NULL) { 2894041b853SChris Wilson DRM_ERROR("Invalid crtc %d\n", pipe); 2904041b853SChris Wilson return -EINVAL; 2914041b853SChris Wilson } 2924041b853SChris Wilson 2934041b853SChris Wilson if (!crtc->enabled) { 2944041b853SChris Wilson DRM_DEBUG_KMS("crtc %d is disabled\n", pipe); 2954041b853SChris Wilson return -EBUSY; 2964041b853SChris Wilson } 2970af7e4dfSMario Kleiner 2980af7e4dfSMario Kleiner /* Helper routine in DRM core does all the work: */ 2994041b853SChris Wilson return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error, 3004041b853SChris Wilson vblank_time, flags, 3014041b853SChris Wilson crtc); 3020af7e4dfSMario Kleiner } 3030af7e4dfSMario Kleiner 3045ca58282SJesse Barnes /* 3055ca58282SJesse Barnes * Handle hotplug events outside the interrupt handler proper. 3065ca58282SJesse Barnes */ 3075ca58282SJesse Barnes static void i915_hotplug_work_func(struct work_struct *work) 3085ca58282SJesse Barnes { 3095ca58282SJesse Barnes drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t, 3105ca58282SJesse Barnes hotplug_work); 3115ca58282SJesse Barnes struct drm_device *dev = dev_priv->dev; 312c31c4ba3SKeith Packard struct drm_mode_config *mode_config = &dev->mode_config; 3134ef69c7aSChris Wilson struct intel_encoder *encoder; 3145ca58282SJesse Barnes 315a65e34c7SKeith Packard mutex_lock(&mode_config->mutex); 316e67189abSJesse Barnes DRM_DEBUG_KMS("running encoder hotplug functions\n"); 317e67189abSJesse Barnes 3184ef69c7aSChris Wilson list_for_each_entry(encoder, &mode_config->encoder_list, base.head) 3194ef69c7aSChris Wilson if (encoder->hot_plug) 3204ef69c7aSChris Wilson encoder->hot_plug(encoder); 321c31c4ba3SKeith Packard 32240ee3381SKeith Packard mutex_unlock(&mode_config->mutex); 32340ee3381SKeith Packard 3245ca58282SJesse Barnes /* Just fire off a uevent and let userspace tell us what to do */ 325eb1f8e4fSDave Airlie drm_helper_hpd_irq_event(dev); 3265ca58282SJesse Barnes } 3275ca58282SJesse Barnes 328f97108d1SJesse Barnes static void i915_handle_rps_change(struct drm_device *dev) 329f97108d1SJesse Barnes { 330f97108d1SJesse Barnes drm_i915_private_t *dev_priv = dev->dev_private; 331b5b72e89SMatthew Garrett u32 busy_up, busy_down, max_avg, min_avg; 332f97108d1SJesse Barnes u8 new_delay = dev_priv->cur_delay; 333f97108d1SJesse Barnes 3347648fa99SJesse Barnes I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG); 335b5b72e89SMatthew Garrett busy_up = I915_READ(RCPREVBSYTUPAVG); 336b5b72e89SMatthew Garrett busy_down = I915_READ(RCPREVBSYTDNAVG); 337f97108d1SJesse Barnes max_avg = I915_READ(RCBMAXAVG); 338f97108d1SJesse Barnes min_avg = I915_READ(RCBMINAVG); 339f97108d1SJesse Barnes 340f97108d1SJesse Barnes /* Handle RCS change request from hw */ 341b5b72e89SMatthew Garrett if (busy_up > max_avg) { 342f97108d1SJesse Barnes if (dev_priv->cur_delay != dev_priv->max_delay) 343f97108d1SJesse Barnes new_delay = dev_priv->cur_delay - 1; 344f97108d1SJesse Barnes if (new_delay < dev_priv->max_delay) 345f97108d1SJesse Barnes new_delay = dev_priv->max_delay; 346b5b72e89SMatthew Garrett } else if (busy_down < min_avg) { 347f97108d1SJesse Barnes if (dev_priv->cur_delay != dev_priv->min_delay) 348f97108d1SJesse Barnes new_delay = dev_priv->cur_delay + 1; 349f97108d1SJesse Barnes if (new_delay > dev_priv->min_delay) 350f97108d1SJesse Barnes new_delay = dev_priv->min_delay; 351f97108d1SJesse Barnes } 352f97108d1SJesse Barnes 3537648fa99SJesse Barnes if (ironlake_set_drps(dev, new_delay)) 354f97108d1SJesse Barnes dev_priv->cur_delay = new_delay; 355f97108d1SJesse Barnes 356f97108d1SJesse Barnes return; 357f97108d1SJesse Barnes } 358f97108d1SJesse Barnes 359549f7365SChris Wilson static void notify_ring(struct drm_device *dev, 360549f7365SChris Wilson struct intel_ring_buffer *ring) 361549f7365SChris Wilson { 362549f7365SChris Wilson struct drm_i915_private *dev_priv = dev->dev_private; 363475553deSChris Wilson u32 seqno; 3649862e600SChris Wilson 365475553deSChris Wilson if (ring->obj == NULL) 366475553deSChris Wilson return; 367475553deSChris Wilson 368475553deSChris Wilson seqno = ring->get_seqno(ring); 369db53a302SChris Wilson trace_i915_gem_request_complete(ring, seqno); 3709862e600SChris Wilson 3719862e600SChris Wilson ring->irq_seqno = seqno; 372549f7365SChris Wilson wake_up_all(&ring->irq_queue); 3733e0dc6b0SBen Widawsky if (i915_enable_hangcheck) { 374549f7365SChris Wilson dev_priv->hangcheck_count = 0; 375549f7365SChris Wilson mod_timer(&dev_priv->hangcheck_timer, 3763e0dc6b0SBen Widawsky jiffies + 3773e0dc6b0SBen Widawsky msecs_to_jiffies(DRM_I915_HANGCHECK_PERIOD)); 3783e0dc6b0SBen Widawsky } 379549f7365SChris Wilson } 380549f7365SChris Wilson 3814912d041SBen Widawsky static void gen6_pm_rps_work(struct work_struct *work) 3823b8d8d91SJesse Barnes { 3834912d041SBen Widawsky drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t, 3844912d041SBen Widawsky rps_work); 3853b8d8d91SJesse Barnes u8 new_delay = dev_priv->cur_delay; 3864912d041SBen Widawsky u32 pm_iir, pm_imr; 3873b8d8d91SJesse Barnes 3884912d041SBen Widawsky spin_lock_irq(&dev_priv->rps_lock); 3894912d041SBen Widawsky pm_iir = dev_priv->pm_iir; 3904912d041SBen Widawsky dev_priv->pm_iir = 0; 3914912d041SBen Widawsky pm_imr = I915_READ(GEN6_PMIMR); 392a9e2641dSDaniel Vetter I915_WRITE(GEN6_PMIMR, 0); 3934912d041SBen Widawsky spin_unlock_irq(&dev_priv->rps_lock); 3944912d041SBen Widawsky 3953b8d8d91SJesse Barnes if (!pm_iir) 3963b8d8d91SJesse Barnes return; 3973b8d8d91SJesse Barnes 3984912d041SBen Widawsky mutex_lock(&dev_priv->dev->struct_mutex); 3993b8d8d91SJesse Barnes if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) { 4003b8d8d91SJesse Barnes if (dev_priv->cur_delay != dev_priv->max_delay) 4013b8d8d91SJesse Barnes new_delay = dev_priv->cur_delay + 1; 4023b8d8d91SJesse Barnes if (new_delay > dev_priv->max_delay) 4033b8d8d91SJesse Barnes new_delay = dev_priv->max_delay; 4043b8d8d91SJesse Barnes } else if (pm_iir & (GEN6_PM_RP_DOWN_THRESHOLD | GEN6_PM_RP_DOWN_TIMEOUT)) { 4054912d041SBen Widawsky gen6_gt_force_wake_get(dev_priv); 4063b8d8d91SJesse Barnes if (dev_priv->cur_delay != dev_priv->min_delay) 4073b8d8d91SJesse Barnes new_delay = dev_priv->cur_delay - 1; 4083b8d8d91SJesse Barnes if (new_delay < dev_priv->min_delay) { 4093b8d8d91SJesse Barnes new_delay = dev_priv->min_delay; 4103b8d8d91SJesse Barnes I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, 4113b8d8d91SJesse Barnes I915_READ(GEN6_RP_INTERRUPT_LIMITS) | 4123b8d8d91SJesse Barnes ((new_delay << 16) & 0x3f0000)); 4133b8d8d91SJesse Barnes } else { 4143b8d8d91SJesse Barnes /* Make sure we continue to get down interrupts 4153b8d8d91SJesse Barnes * until we hit the minimum frequency */ 4163b8d8d91SJesse Barnes I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, 4173b8d8d91SJesse Barnes I915_READ(GEN6_RP_INTERRUPT_LIMITS) & ~0x3f0000); 4183b8d8d91SJesse Barnes } 4194912d041SBen Widawsky gen6_gt_force_wake_put(dev_priv); 4203b8d8d91SJesse Barnes } 4213b8d8d91SJesse Barnes 4224912d041SBen Widawsky gen6_set_rps(dev_priv->dev, new_delay); 4233b8d8d91SJesse Barnes dev_priv->cur_delay = new_delay; 4243b8d8d91SJesse Barnes 4254912d041SBen Widawsky /* 4264912d041SBen Widawsky * rps_lock not held here because clearing is non-destructive. There is 4274912d041SBen Widawsky * an *extremely* unlikely race with gen6_rps_enable() that is prevented 4284912d041SBen Widawsky * by holding struct_mutex for the duration of the write. 4294912d041SBen Widawsky */ 4304912d041SBen Widawsky mutex_unlock(&dev_priv->dev->struct_mutex); 4313b8d8d91SJesse Barnes } 4323b8d8d91SJesse Barnes 433e7b4c6b1SDaniel Vetter static void snb_gt_irq_handler(struct drm_device *dev, 434e7b4c6b1SDaniel Vetter struct drm_i915_private *dev_priv, 435e7b4c6b1SDaniel Vetter u32 gt_iir) 436e7b4c6b1SDaniel Vetter { 437e7b4c6b1SDaniel Vetter 438e7b4c6b1SDaniel Vetter if (gt_iir & (GEN6_RENDER_USER_INTERRUPT | 439e7b4c6b1SDaniel Vetter GEN6_RENDER_PIPE_CONTROL_NOTIFY_INTERRUPT)) 440e7b4c6b1SDaniel Vetter notify_ring(dev, &dev_priv->ring[RCS]); 441e7b4c6b1SDaniel Vetter if (gt_iir & GEN6_BSD_USER_INTERRUPT) 442e7b4c6b1SDaniel Vetter notify_ring(dev, &dev_priv->ring[VCS]); 443e7b4c6b1SDaniel Vetter if (gt_iir & GEN6_BLITTER_USER_INTERRUPT) 444e7b4c6b1SDaniel Vetter notify_ring(dev, &dev_priv->ring[BCS]); 445e7b4c6b1SDaniel Vetter 446e7b4c6b1SDaniel Vetter if (gt_iir & (GT_GEN6_BLT_CS_ERROR_INTERRUPT | 447e7b4c6b1SDaniel Vetter GT_GEN6_BSD_CS_ERROR_INTERRUPT | 448e7b4c6b1SDaniel Vetter GT_RENDER_CS_ERROR_INTERRUPT)) { 449e7b4c6b1SDaniel Vetter DRM_ERROR("GT error interrupt 0x%08x\n", gt_iir); 450e7b4c6b1SDaniel Vetter i915_handle_error(dev, false); 451e7b4c6b1SDaniel Vetter } 452e7b4c6b1SDaniel Vetter } 453e7b4c6b1SDaniel Vetter 454fc6826d1SChris Wilson static void gen6_queue_rps_work(struct drm_i915_private *dev_priv, 455fc6826d1SChris Wilson u32 pm_iir) 456fc6826d1SChris Wilson { 457fc6826d1SChris Wilson unsigned long flags; 458fc6826d1SChris Wilson 459fc6826d1SChris Wilson /* 460fc6826d1SChris Wilson * IIR bits should never already be set because IMR should 461fc6826d1SChris Wilson * prevent an interrupt from being shown in IIR. The warning 462fc6826d1SChris Wilson * displays a case where we've unsafely cleared 463fc6826d1SChris Wilson * dev_priv->pm_iir. Although missing an interrupt of the same 464fc6826d1SChris Wilson * type is not a problem, it displays a problem in the logic. 465fc6826d1SChris Wilson * 466fc6826d1SChris Wilson * The mask bit in IMR is cleared by rps_work. 467fc6826d1SChris Wilson */ 468fc6826d1SChris Wilson 469fc6826d1SChris Wilson spin_lock_irqsave(&dev_priv->rps_lock, flags); 470fc6826d1SChris Wilson WARN(dev_priv->pm_iir & pm_iir, "Missed a PM interrupt\n"); 471fc6826d1SChris Wilson dev_priv->pm_iir |= pm_iir; 472fc6826d1SChris Wilson I915_WRITE(GEN6_PMIMR, dev_priv->pm_iir); 473fc6826d1SChris Wilson POSTING_READ(GEN6_PMIMR); 474fc6826d1SChris Wilson spin_unlock_irqrestore(&dev_priv->rps_lock, flags); 475fc6826d1SChris Wilson 476fc6826d1SChris Wilson queue_work(dev_priv->wq, &dev_priv->rps_work); 477fc6826d1SChris Wilson } 478fc6826d1SChris Wilson 4797e231dbeSJesse Barnes static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS) 4807e231dbeSJesse Barnes { 4817e231dbeSJesse Barnes struct drm_device *dev = (struct drm_device *) arg; 4827e231dbeSJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 4837e231dbeSJesse Barnes u32 iir, gt_iir, pm_iir; 4847e231dbeSJesse Barnes irqreturn_t ret = IRQ_NONE; 4857e231dbeSJesse Barnes unsigned long irqflags; 4867e231dbeSJesse Barnes int pipe; 4877e231dbeSJesse Barnes u32 pipe_stats[I915_MAX_PIPES]; 4887e231dbeSJesse Barnes u32 vblank_status; 4897e231dbeSJesse Barnes int vblank = 0; 4907e231dbeSJesse Barnes bool blc_event; 4917e231dbeSJesse Barnes 4927e231dbeSJesse Barnes atomic_inc(&dev_priv->irq_received); 4937e231dbeSJesse Barnes 4947e231dbeSJesse Barnes vblank_status = PIPE_START_VBLANK_INTERRUPT_STATUS | 4957e231dbeSJesse Barnes PIPE_VBLANK_INTERRUPT_STATUS; 4967e231dbeSJesse Barnes 4977e231dbeSJesse Barnes while (true) { 4987e231dbeSJesse Barnes iir = I915_READ(VLV_IIR); 4997e231dbeSJesse Barnes gt_iir = I915_READ(GTIIR); 5007e231dbeSJesse Barnes pm_iir = I915_READ(GEN6_PMIIR); 5017e231dbeSJesse Barnes 5027e231dbeSJesse Barnes if (gt_iir == 0 && pm_iir == 0 && iir == 0) 5037e231dbeSJesse Barnes goto out; 5047e231dbeSJesse Barnes 5057e231dbeSJesse Barnes ret = IRQ_HANDLED; 5067e231dbeSJesse Barnes 507e7b4c6b1SDaniel Vetter snb_gt_irq_handler(dev, dev_priv, gt_iir); 5087e231dbeSJesse Barnes 5097e231dbeSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 5107e231dbeSJesse Barnes for_each_pipe(pipe) { 5117e231dbeSJesse Barnes int reg = PIPESTAT(pipe); 5127e231dbeSJesse Barnes pipe_stats[pipe] = I915_READ(reg); 5137e231dbeSJesse Barnes 5147e231dbeSJesse Barnes /* 5157e231dbeSJesse Barnes * Clear the PIPE*STAT regs before the IIR 5167e231dbeSJesse Barnes */ 5177e231dbeSJesse Barnes if (pipe_stats[pipe] & 0x8000ffff) { 5187e231dbeSJesse Barnes if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) 5197e231dbeSJesse Barnes DRM_DEBUG_DRIVER("pipe %c underrun\n", 5207e231dbeSJesse Barnes pipe_name(pipe)); 5217e231dbeSJesse Barnes I915_WRITE(reg, pipe_stats[pipe]); 5227e231dbeSJesse Barnes } 5237e231dbeSJesse Barnes } 5247e231dbeSJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 5257e231dbeSJesse Barnes 5267e231dbeSJesse Barnes /* Consume port. Then clear IIR or we'll miss events */ 5277e231dbeSJesse Barnes if (iir & I915_DISPLAY_PORT_INTERRUPT) { 5287e231dbeSJesse Barnes u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT); 5297e231dbeSJesse Barnes 5307e231dbeSJesse Barnes DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n", 5317e231dbeSJesse Barnes hotplug_status); 5327e231dbeSJesse Barnes if (hotplug_status & dev_priv->hotplug_supported_mask) 5337e231dbeSJesse Barnes queue_work(dev_priv->wq, 5347e231dbeSJesse Barnes &dev_priv->hotplug_work); 5357e231dbeSJesse Barnes 5367e231dbeSJesse Barnes I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status); 5377e231dbeSJesse Barnes I915_READ(PORT_HOTPLUG_STAT); 5387e231dbeSJesse Barnes } 5397e231dbeSJesse Barnes 5407e231dbeSJesse Barnes 5417e231dbeSJesse Barnes if (iir & I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT) { 5427e231dbeSJesse Barnes drm_handle_vblank(dev, 0); 5437e231dbeSJesse Barnes vblank++; 5447e231dbeSJesse Barnes intel_finish_page_flip(dev, 0); 5457e231dbeSJesse Barnes } 5467e231dbeSJesse Barnes 5477e231dbeSJesse Barnes if (iir & I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT) { 5487e231dbeSJesse Barnes drm_handle_vblank(dev, 1); 5497e231dbeSJesse Barnes vblank++; 5507e231dbeSJesse Barnes intel_finish_page_flip(dev, 0); 5517e231dbeSJesse Barnes } 5527e231dbeSJesse Barnes 5537e231dbeSJesse Barnes if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS) 5547e231dbeSJesse Barnes blc_event = true; 5557e231dbeSJesse Barnes 556fc6826d1SChris Wilson if (pm_iir & GEN6_PM_DEFERRED_EVENTS) 557fc6826d1SChris Wilson gen6_queue_rps_work(dev_priv, pm_iir); 5587e231dbeSJesse Barnes 5597e231dbeSJesse Barnes I915_WRITE(GTIIR, gt_iir); 5607e231dbeSJesse Barnes I915_WRITE(GEN6_PMIIR, pm_iir); 5617e231dbeSJesse Barnes I915_WRITE(VLV_IIR, iir); 5627e231dbeSJesse Barnes } 5637e231dbeSJesse Barnes 5647e231dbeSJesse Barnes out: 5657e231dbeSJesse Barnes return ret; 5667e231dbeSJesse Barnes } 5677e231dbeSJesse Barnes 568776ad806SJesse Barnes static void pch_irq_handler(struct drm_device *dev) 569776ad806SJesse Barnes { 570776ad806SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 571776ad806SJesse Barnes u32 pch_iir; 5729db4a9c7SJesse Barnes int pipe; 573776ad806SJesse Barnes 574776ad806SJesse Barnes pch_iir = I915_READ(SDEIIR); 575776ad806SJesse Barnes 576776ad806SJesse Barnes if (pch_iir & SDE_AUDIO_POWER_MASK) 577776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH audio power change on port %d\n", 578776ad806SJesse Barnes (pch_iir & SDE_AUDIO_POWER_MASK) >> 579776ad806SJesse Barnes SDE_AUDIO_POWER_SHIFT); 580776ad806SJesse Barnes 581776ad806SJesse Barnes if (pch_iir & SDE_GMBUS) 582776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH GMBUS interrupt\n"); 583776ad806SJesse Barnes 584776ad806SJesse Barnes if (pch_iir & SDE_AUDIO_HDCP_MASK) 585776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n"); 586776ad806SJesse Barnes 587776ad806SJesse Barnes if (pch_iir & SDE_AUDIO_TRANS_MASK) 588776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n"); 589776ad806SJesse Barnes 590776ad806SJesse Barnes if (pch_iir & SDE_POISON) 591776ad806SJesse Barnes DRM_ERROR("PCH poison interrupt\n"); 592776ad806SJesse Barnes 5939db4a9c7SJesse Barnes if (pch_iir & SDE_FDI_MASK) 5949db4a9c7SJesse Barnes for_each_pipe(pipe) 5959db4a9c7SJesse Barnes DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n", 5969db4a9c7SJesse Barnes pipe_name(pipe), 5979db4a9c7SJesse Barnes I915_READ(FDI_RX_IIR(pipe))); 598776ad806SJesse Barnes 599776ad806SJesse Barnes if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE)) 600776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n"); 601776ad806SJesse Barnes 602776ad806SJesse Barnes if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR)) 603776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n"); 604776ad806SJesse Barnes 605776ad806SJesse Barnes if (pch_iir & SDE_TRANSB_FIFO_UNDER) 606776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH transcoder B underrun interrupt\n"); 607776ad806SJesse Barnes if (pch_iir & SDE_TRANSA_FIFO_UNDER) 608776ad806SJesse Barnes DRM_DEBUG_DRIVER("PCH transcoder A underrun interrupt\n"); 609776ad806SJesse Barnes } 610776ad806SJesse Barnes 611f71d4af4SJesse Barnes static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS) 612b1f14ad0SJesse Barnes { 613b1f14ad0SJesse Barnes struct drm_device *dev = (struct drm_device *) arg; 614b1f14ad0SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 615b1f14ad0SJesse Barnes int ret = IRQ_NONE; 616b1f14ad0SJesse Barnes u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir; 617b1f14ad0SJesse Barnes struct drm_i915_master_private *master_priv; 618b1f14ad0SJesse Barnes 619b1f14ad0SJesse Barnes atomic_inc(&dev_priv->irq_received); 620b1f14ad0SJesse Barnes 621b1f14ad0SJesse Barnes /* disable master interrupt before clearing iir */ 622b1f14ad0SJesse Barnes de_ier = I915_READ(DEIER); 623b1f14ad0SJesse Barnes I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL); 624b1f14ad0SJesse Barnes POSTING_READ(DEIER); 625b1f14ad0SJesse Barnes 626b1f14ad0SJesse Barnes de_iir = I915_READ(DEIIR); 627b1f14ad0SJesse Barnes gt_iir = I915_READ(GTIIR); 628b1f14ad0SJesse Barnes pch_iir = I915_READ(SDEIIR); 629b1f14ad0SJesse Barnes pm_iir = I915_READ(GEN6_PMIIR); 630b1f14ad0SJesse Barnes 631b1f14ad0SJesse Barnes if (de_iir == 0 && gt_iir == 0 && pch_iir == 0 && pm_iir == 0) 632b1f14ad0SJesse Barnes goto done; 633b1f14ad0SJesse Barnes 634b1f14ad0SJesse Barnes ret = IRQ_HANDLED; 635b1f14ad0SJesse Barnes 636b1f14ad0SJesse Barnes if (dev->primary->master) { 637b1f14ad0SJesse Barnes master_priv = dev->primary->master->driver_priv; 638b1f14ad0SJesse Barnes if (master_priv->sarea_priv) 639b1f14ad0SJesse Barnes master_priv->sarea_priv->last_dispatch = 640b1f14ad0SJesse Barnes READ_BREADCRUMB(dev_priv); 641b1f14ad0SJesse Barnes } 642b1f14ad0SJesse Barnes 643e7b4c6b1SDaniel Vetter snb_gt_irq_handler(dev, dev_priv, gt_iir); 644b1f14ad0SJesse Barnes 645b1f14ad0SJesse Barnes if (de_iir & DE_GSE_IVB) 646b1f14ad0SJesse Barnes intel_opregion_gse_intr(dev); 647b1f14ad0SJesse Barnes 648b1f14ad0SJesse Barnes if (de_iir & DE_PLANEA_FLIP_DONE_IVB) { 649b1f14ad0SJesse Barnes intel_prepare_page_flip(dev, 0); 650b1f14ad0SJesse Barnes intel_finish_page_flip_plane(dev, 0); 651b1f14ad0SJesse Barnes } 652b1f14ad0SJesse Barnes 653b1f14ad0SJesse Barnes if (de_iir & DE_PLANEB_FLIP_DONE_IVB) { 654b1f14ad0SJesse Barnes intel_prepare_page_flip(dev, 1); 655b1f14ad0SJesse Barnes intel_finish_page_flip_plane(dev, 1); 656b1f14ad0SJesse Barnes } 657b1f14ad0SJesse Barnes 658b1f14ad0SJesse Barnes if (de_iir & DE_PIPEA_VBLANK_IVB) 659b1f14ad0SJesse Barnes drm_handle_vblank(dev, 0); 660b1f14ad0SJesse Barnes 661f6b07f45SDan Carpenter if (de_iir & DE_PIPEB_VBLANK_IVB) 662b1f14ad0SJesse Barnes drm_handle_vblank(dev, 1); 663b1f14ad0SJesse Barnes 664b1f14ad0SJesse Barnes /* check event from PCH */ 665b1f14ad0SJesse Barnes if (de_iir & DE_PCH_EVENT_IVB) { 666b1f14ad0SJesse Barnes if (pch_iir & SDE_HOTPLUG_MASK_CPT) 667b1f14ad0SJesse Barnes queue_work(dev_priv->wq, &dev_priv->hotplug_work); 668b1f14ad0SJesse Barnes pch_irq_handler(dev); 669b1f14ad0SJesse Barnes } 670b1f14ad0SJesse Barnes 671fc6826d1SChris Wilson if (pm_iir & GEN6_PM_DEFERRED_EVENTS) 672fc6826d1SChris Wilson gen6_queue_rps_work(dev_priv, pm_iir); 673b1f14ad0SJesse Barnes 674b1f14ad0SJesse Barnes /* should clear PCH hotplug event before clear CPU irq */ 675b1f14ad0SJesse Barnes I915_WRITE(SDEIIR, pch_iir); 676b1f14ad0SJesse Barnes I915_WRITE(GTIIR, gt_iir); 677b1f14ad0SJesse Barnes I915_WRITE(DEIIR, de_iir); 678b1f14ad0SJesse Barnes I915_WRITE(GEN6_PMIIR, pm_iir); 679b1f14ad0SJesse Barnes 680b1f14ad0SJesse Barnes done: 681b1f14ad0SJesse Barnes I915_WRITE(DEIER, de_ier); 682b1f14ad0SJesse Barnes POSTING_READ(DEIER); 683b1f14ad0SJesse Barnes 684b1f14ad0SJesse Barnes return ret; 685b1f14ad0SJesse Barnes } 686b1f14ad0SJesse Barnes 687e7b4c6b1SDaniel Vetter static void ilk_gt_irq_handler(struct drm_device *dev, 688e7b4c6b1SDaniel Vetter struct drm_i915_private *dev_priv, 689e7b4c6b1SDaniel Vetter u32 gt_iir) 690e7b4c6b1SDaniel Vetter { 691e7b4c6b1SDaniel Vetter if (gt_iir & (GT_USER_INTERRUPT | GT_PIPE_NOTIFY)) 692e7b4c6b1SDaniel Vetter notify_ring(dev, &dev_priv->ring[RCS]); 693e7b4c6b1SDaniel Vetter if (gt_iir & GT_BSD_USER_INTERRUPT) 694e7b4c6b1SDaniel Vetter notify_ring(dev, &dev_priv->ring[VCS]); 695e7b4c6b1SDaniel Vetter } 696e7b4c6b1SDaniel Vetter 697f71d4af4SJesse Barnes static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS) 698036a4a7dSZhenyu Wang { 6994697995bSJesse Barnes struct drm_device *dev = (struct drm_device *) arg; 700036a4a7dSZhenyu Wang drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 701036a4a7dSZhenyu Wang int ret = IRQ_NONE; 7023b8d8d91SJesse Barnes u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir; 7032d7b8366SYuanhan Liu u32 hotplug_mask; 704036a4a7dSZhenyu Wang struct drm_i915_master_private *master_priv; 705881f47b6SXiang, Haihao 7064697995bSJesse Barnes atomic_inc(&dev_priv->irq_received); 7074697995bSJesse Barnes 7082d109a84SZou, Nanhai /* disable master interrupt before clearing iir */ 7092d109a84SZou, Nanhai de_ier = I915_READ(DEIER); 7102d109a84SZou, Nanhai I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL); 7113143a2bfSChris Wilson POSTING_READ(DEIER); 7122d109a84SZou, Nanhai 713036a4a7dSZhenyu Wang de_iir = I915_READ(DEIIR); 714036a4a7dSZhenyu Wang gt_iir = I915_READ(GTIIR); 715c650156aSZhenyu Wang pch_iir = I915_READ(SDEIIR); 7163b8d8d91SJesse Barnes pm_iir = I915_READ(GEN6_PMIIR); 717036a4a7dSZhenyu Wang 7183b8d8d91SJesse Barnes if (de_iir == 0 && gt_iir == 0 && pch_iir == 0 && 7193b8d8d91SJesse Barnes (!IS_GEN6(dev) || pm_iir == 0)) 720c7c85101SZou Nan hai goto done; 721036a4a7dSZhenyu Wang 7222d7b8366SYuanhan Liu if (HAS_PCH_CPT(dev)) 7232d7b8366SYuanhan Liu hotplug_mask = SDE_HOTPLUG_MASK_CPT; 7242d7b8366SYuanhan Liu else 7252d7b8366SYuanhan Liu hotplug_mask = SDE_HOTPLUG_MASK; 7262d7b8366SYuanhan Liu 727036a4a7dSZhenyu Wang ret = IRQ_HANDLED; 728036a4a7dSZhenyu Wang 729036a4a7dSZhenyu Wang if (dev->primary->master) { 730036a4a7dSZhenyu Wang master_priv = dev->primary->master->driver_priv; 731036a4a7dSZhenyu Wang if (master_priv->sarea_priv) 732036a4a7dSZhenyu Wang master_priv->sarea_priv->last_dispatch = 733036a4a7dSZhenyu Wang READ_BREADCRUMB(dev_priv); 734036a4a7dSZhenyu Wang } 735036a4a7dSZhenyu Wang 736e7b4c6b1SDaniel Vetter if (IS_GEN5(dev)) 737e7b4c6b1SDaniel Vetter ilk_gt_irq_handler(dev, dev_priv, gt_iir); 738e7b4c6b1SDaniel Vetter else 739e7b4c6b1SDaniel Vetter snb_gt_irq_handler(dev, dev_priv, gt_iir); 740036a4a7dSZhenyu Wang 74101c66889SZhao Yakui if (de_iir & DE_GSE) 7423b617967SChris Wilson intel_opregion_gse_intr(dev); 74301c66889SZhao Yakui 744f072d2e7SZhenyu Wang if (de_iir & DE_PLANEA_FLIP_DONE) { 745013d5aa2SJesse Barnes intel_prepare_page_flip(dev, 0); 7462bbda389SChris Wilson intel_finish_page_flip_plane(dev, 0); 747013d5aa2SJesse Barnes } 748013d5aa2SJesse Barnes 749f072d2e7SZhenyu Wang if (de_iir & DE_PLANEB_FLIP_DONE) { 750f072d2e7SZhenyu Wang intel_prepare_page_flip(dev, 1); 7512bbda389SChris Wilson intel_finish_page_flip_plane(dev, 1); 752013d5aa2SJesse Barnes } 753c062df61SLi Peng 754f072d2e7SZhenyu Wang if (de_iir & DE_PIPEA_VBLANK) 755f072d2e7SZhenyu Wang drm_handle_vblank(dev, 0); 756f072d2e7SZhenyu Wang 757f072d2e7SZhenyu Wang if (de_iir & DE_PIPEB_VBLANK) 758f072d2e7SZhenyu Wang drm_handle_vblank(dev, 1); 759f072d2e7SZhenyu Wang 760c650156aSZhenyu Wang /* check event from PCH */ 761776ad806SJesse Barnes if (de_iir & DE_PCH_EVENT) { 762776ad806SJesse Barnes if (pch_iir & hotplug_mask) 763c650156aSZhenyu Wang queue_work(dev_priv->wq, &dev_priv->hotplug_work); 764776ad806SJesse Barnes pch_irq_handler(dev); 765776ad806SJesse Barnes } 766c650156aSZhenyu Wang 767f97108d1SJesse Barnes if (de_iir & DE_PCU_EVENT) { 7687648fa99SJesse Barnes I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS)); 769f97108d1SJesse Barnes i915_handle_rps_change(dev); 770f97108d1SJesse Barnes } 771f97108d1SJesse Barnes 772fc6826d1SChris Wilson if (IS_GEN6(dev) && pm_iir & GEN6_PM_DEFERRED_EVENTS) 773fc6826d1SChris Wilson gen6_queue_rps_work(dev_priv, pm_iir); 7743b8d8d91SJesse Barnes 775c7c85101SZou Nan hai /* should clear PCH hotplug event before clear CPU irq */ 776c7c85101SZou Nan hai I915_WRITE(SDEIIR, pch_iir); 777c7c85101SZou Nan hai I915_WRITE(GTIIR, gt_iir); 778c7c85101SZou Nan hai I915_WRITE(DEIIR, de_iir); 7794912d041SBen Widawsky I915_WRITE(GEN6_PMIIR, pm_iir); 780036a4a7dSZhenyu Wang 781c7c85101SZou Nan hai done: 7822d109a84SZou, Nanhai I915_WRITE(DEIER, de_ier); 7833143a2bfSChris Wilson POSTING_READ(DEIER); 7842d109a84SZou, Nanhai 785036a4a7dSZhenyu Wang return ret; 786036a4a7dSZhenyu Wang } 787036a4a7dSZhenyu Wang 7888a905236SJesse Barnes /** 7898a905236SJesse Barnes * i915_error_work_func - do process context error handling work 7908a905236SJesse Barnes * @work: work struct 7918a905236SJesse Barnes * 7928a905236SJesse Barnes * Fire an error uevent so userspace can see that a hang or error 7938a905236SJesse Barnes * was detected. 7948a905236SJesse Barnes */ 7958a905236SJesse Barnes static void i915_error_work_func(struct work_struct *work) 7968a905236SJesse Barnes { 7978a905236SJesse Barnes drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t, 7988a905236SJesse Barnes error_work); 7998a905236SJesse Barnes struct drm_device *dev = dev_priv->dev; 800f316a42cSBen Gamari char *error_event[] = { "ERROR=1", NULL }; 801f316a42cSBen Gamari char *reset_event[] = { "RESET=1", NULL }; 802f316a42cSBen Gamari char *reset_done_event[] = { "ERROR=0", NULL }; 8038a905236SJesse Barnes 804f316a42cSBen Gamari kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, error_event); 8058a905236SJesse Barnes 806ba1234d1SBen Gamari if (atomic_read(&dev_priv->mm.wedged)) { 80744d98a61SZhao Yakui DRM_DEBUG_DRIVER("resetting chip\n"); 808f316a42cSBen Gamari kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, reset_event); 809f803aa55SChris Wilson if (!i915_reset(dev, GRDOM_RENDER)) { 810ba1234d1SBen Gamari atomic_set(&dev_priv->mm.wedged, 0); 811f316a42cSBen Gamari kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, reset_done_event); 812f316a42cSBen Gamari } 81330dbf0c0SChris Wilson complete_all(&dev_priv->error_completion); 814f316a42cSBen Gamari } 8158a905236SJesse Barnes } 8168a905236SJesse Barnes 8173bd3c932SChris Wilson #ifdef CONFIG_DEBUG_FS 8189df30794SChris Wilson static struct drm_i915_error_object * 819bcfb2e28SChris Wilson i915_error_object_create(struct drm_i915_private *dev_priv, 82005394f39SChris Wilson struct drm_i915_gem_object *src) 8219df30794SChris Wilson { 8229df30794SChris Wilson struct drm_i915_error_object *dst; 8239df30794SChris Wilson int page, page_count; 824e56660ddSChris Wilson u32 reloc_offset; 8259df30794SChris Wilson 82605394f39SChris Wilson if (src == NULL || src->pages == NULL) 8279df30794SChris Wilson return NULL; 8289df30794SChris Wilson 82905394f39SChris Wilson page_count = src->base.size / PAGE_SIZE; 8309df30794SChris Wilson 8319df30794SChris Wilson dst = kmalloc(sizeof(*dst) + page_count * sizeof(u32 *), GFP_ATOMIC); 8329df30794SChris Wilson if (dst == NULL) 8339df30794SChris Wilson return NULL; 8349df30794SChris Wilson 83505394f39SChris Wilson reloc_offset = src->gtt_offset; 8369df30794SChris Wilson for (page = 0; page < page_count; page++) { 837788885aeSAndrew Morton unsigned long flags; 838e56660ddSChris Wilson void *d; 839788885aeSAndrew Morton 840e56660ddSChris Wilson d = kmalloc(PAGE_SIZE, GFP_ATOMIC); 8419df30794SChris Wilson if (d == NULL) 8429df30794SChris Wilson goto unwind; 843e56660ddSChris Wilson 844788885aeSAndrew Morton local_irq_save(flags); 84574898d7eSDaniel Vetter if (reloc_offset < dev_priv->mm.gtt_mappable_end && 84674898d7eSDaniel Vetter src->has_global_gtt_mapping) { 847172975aaSChris Wilson void __iomem *s; 848172975aaSChris Wilson 849172975aaSChris Wilson /* Simply ignore tiling or any overlapping fence. 850172975aaSChris Wilson * It's part of the error state, and this hopefully 851172975aaSChris Wilson * captures what the GPU read. 852172975aaSChris Wilson */ 853172975aaSChris Wilson 854e56660ddSChris Wilson s = io_mapping_map_atomic_wc(dev_priv->mm.gtt_mapping, 8553e4d3af5SPeter Zijlstra reloc_offset); 856e56660ddSChris Wilson memcpy_fromio(d, s, PAGE_SIZE); 8573e4d3af5SPeter Zijlstra io_mapping_unmap_atomic(s); 858172975aaSChris Wilson } else { 859172975aaSChris Wilson void *s; 860172975aaSChris Wilson 861172975aaSChris Wilson drm_clflush_pages(&src->pages[page], 1); 862172975aaSChris Wilson 863172975aaSChris Wilson s = kmap_atomic(src->pages[page]); 864172975aaSChris Wilson memcpy(d, s, PAGE_SIZE); 865172975aaSChris Wilson kunmap_atomic(s); 866172975aaSChris Wilson 867172975aaSChris Wilson drm_clflush_pages(&src->pages[page], 1); 868172975aaSChris Wilson } 869788885aeSAndrew Morton local_irq_restore(flags); 870e56660ddSChris Wilson 8719df30794SChris Wilson dst->pages[page] = d; 872e56660ddSChris Wilson 873e56660ddSChris Wilson reloc_offset += PAGE_SIZE; 8749df30794SChris Wilson } 8759df30794SChris Wilson dst->page_count = page_count; 87605394f39SChris Wilson dst->gtt_offset = src->gtt_offset; 8779df30794SChris Wilson 8789df30794SChris Wilson return dst; 8799df30794SChris Wilson 8809df30794SChris Wilson unwind: 8819df30794SChris Wilson while (page--) 8829df30794SChris Wilson kfree(dst->pages[page]); 8839df30794SChris Wilson kfree(dst); 8849df30794SChris Wilson return NULL; 8859df30794SChris Wilson } 8869df30794SChris Wilson 8879df30794SChris Wilson static void 8889df30794SChris Wilson i915_error_object_free(struct drm_i915_error_object *obj) 8899df30794SChris Wilson { 8909df30794SChris Wilson int page; 8919df30794SChris Wilson 8929df30794SChris Wilson if (obj == NULL) 8939df30794SChris Wilson return; 8949df30794SChris Wilson 8959df30794SChris Wilson for (page = 0; page < obj->page_count; page++) 8969df30794SChris Wilson kfree(obj->pages[page]); 8979df30794SChris Wilson 8989df30794SChris Wilson kfree(obj); 8999df30794SChris Wilson } 9009df30794SChris Wilson 9019df30794SChris Wilson static void 9029df30794SChris Wilson i915_error_state_free(struct drm_device *dev, 9039df30794SChris Wilson struct drm_i915_error_state *error) 9049df30794SChris Wilson { 905e2f973d5SChris Wilson int i; 906e2f973d5SChris Wilson 90752d39a21SChris Wilson for (i = 0; i < ARRAY_SIZE(error->ring); i++) { 90852d39a21SChris Wilson i915_error_object_free(error->ring[i].batchbuffer); 90952d39a21SChris Wilson i915_error_object_free(error->ring[i].ringbuffer); 91052d39a21SChris Wilson kfree(error->ring[i].requests); 91152d39a21SChris Wilson } 912e2f973d5SChris Wilson 9139df30794SChris Wilson kfree(error->active_bo); 9146ef3d427SChris Wilson kfree(error->overlay); 9159df30794SChris Wilson kfree(error); 9169df30794SChris Wilson } 9171b50247aSChris Wilson static void capture_bo(struct drm_i915_error_buffer *err, 9181b50247aSChris Wilson struct drm_i915_gem_object *obj) 919c724e8a9SChris Wilson { 920c724e8a9SChris Wilson err->size = obj->base.size; 921c724e8a9SChris Wilson err->name = obj->base.name; 922c724e8a9SChris Wilson err->seqno = obj->last_rendering_seqno; 923c724e8a9SChris Wilson err->gtt_offset = obj->gtt_offset; 924c724e8a9SChris Wilson err->read_domains = obj->base.read_domains; 925c724e8a9SChris Wilson err->write_domain = obj->base.write_domain; 926c724e8a9SChris Wilson err->fence_reg = obj->fence_reg; 927c724e8a9SChris Wilson err->pinned = 0; 928c724e8a9SChris Wilson if (obj->pin_count > 0) 929c724e8a9SChris Wilson err->pinned = 1; 930c724e8a9SChris Wilson if (obj->user_pin_count > 0) 931c724e8a9SChris Wilson err->pinned = -1; 932c724e8a9SChris Wilson err->tiling = obj->tiling_mode; 933c724e8a9SChris Wilson err->dirty = obj->dirty; 934c724e8a9SChris Wilson err->purgeable = obj->madv != I915_MADV_WILLNEED; 93596154f2fSDaniel Vetter err->ring = obj->ring ? obj->ring->id : -1; 93693dfb40cSChris Wilson err->cache_level = obj->cache_level; 9371b50247aSChris Wilson } 938c724e8a9SChris Wilson 9391b50247aSChris Wilson static u32 capture_active_bo(struct drm_i915_error_buffer *err, 9401b50247aSChris Wilson int count, struct list_head *head) 9411b50247aSChris Wilson { 9421b50247aSChris Wilson struct drm_i915_gem_object *obj; 9431b50247aSChris Wilson int i = 0; 9441b50247aSChris Wilson 9451b50247aSChris Wilson list_for_each_entry(obj, head, mm_list) { 9461b50247aSChris Wilson capture_bo(err++, obj); 947c724e8a9SChris Wilson if (++i == count) 948c724e8a9SChris Wilson break; 9491b50247aSChris Wilson } 950c724e8a9SChris Wilson 9511b50247aSChris Wilson return i; 9521b50247aSChris Wilson } 9531b50247aSChris Wilson 9541b50247aSChris Wilson static u32 capture_pinned_bo(struct drm_i915_error_buffer *err, 9551b50247aSChris Wilson int count, struct list_head *head) 9561b50247aSChris Wilson { 9571b50247aSChris Wilson struct drm_i915_gem_object *obj; 9581b50247aSChris Wilson int i = 0; 9591b50247aSChris Wilson 9601b50247aSChris Wilson list_for_each_entry(obj, head, gtt_list) { 9611b50247aSChris Wilson if (obj->pin_count == 0) 9621b50247aSChris Wilson continue; 9631b50247aSChris Wilson 9641b50247aSChris Wilson capture_bo(err++, obj); 9651b50247aSChris Wilson if (++i == count) 9661b50247aSChris Wilson break; 967c724e8a9SChris Wilson } 968c724e8a9SChris Wilson 969c724e8a9SChris Wilson return i; 970c724e8a9SChris Wilson } 971c724e8a9SChris Wilson 972748ebc60SChris Wilson static void i915_gem_record_fences(struct drm_device *dev, 973748ebc60SChris Wilson struct drm_i915_error_state *error) 974748ebc60SChris Wilson { 975748ebc60SChris Wilson struct drm_i915_private *dev_priv = dev->dev_private; 976748ebc60SChris Wilson int i; 977748ebc60SChris Wilson 978748ebc60SChris Wilson /* Fences */ 979748ebc60SChris Wilson switch (INTEL_INFO(dev)->gen) { 980775d17b6SDaniel Vetter case 7: 981748ebc60SChris Wilson case 6: 982748ebc60SChris Wilson for (i = 0; i < 16; i++) 983748ebc60SChris Wilson error->fence[i] = I915_READ64(FENCE_REG_SANDYBRIDGE_0 + (i * 8)); 984748ebc60SChris Wilson break; 985748ebc60SChris Wilson case 5: 986748ebc60SChris Wilson case 4: 987748ebc60SChris Wilson for (i = 0; i < 16; i++) 988748ebc60SChris Wilson error->fence[i] = I915_READ64(FENCE_REG_965_0 + (i * 8)); 989748ebc60SChris Wilson break; 990748ebc60SChris Wilson case 3: 991748ebc60SChris Wilson if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) 992748ebc60SChris Wilson for (i = 0; i < 8; i++) 993748ebc60SChris Wilson error->fence[i+8] = I915_READ(FENCE_REG_945_8 + (i * 4)); 994748ebc60SChris Wilson case 2: 995748ebc60SChris Wilson for (i = 0; i < 8; i++) 996748ebc60SChris Wilson error->fence[i] = I915_READ(FENCE_REG_830_0 + (i * 4)); 997748ebc60SChris Wilson break; 998748ebc60SChris Wilson 999748ebc60SChris Wilson } 1000748ebc60SChris Wilson } 1001748ebc60SChris Wilson 1002bcfb2e28SChris Wilson static struct drm_i915_error_object * 1003bcfb2e28SChris Wilson i915_error_first_batchbuffer(struct drm_i915_private *dev_priv, 1004bcfb2e28SChris Wilson struct intel_ring_buffer *ring) 1005bcfb2e28SChris Wilson { 1006bcfb2e28SChris Wilson struct drm_i915_gem_object *obj; 1007bcfb2e28SChris Wilson u32 seqno; 1008bcfb2e28SChris Wilson 1009bcfb2e28SChris Wilson if (!ring->get_seqno) 1010bcfb2e28SChris Wilson return NULL; 1011bcfb2e28SChris Wilson 1012bcfb2e28SChris Wilson seqno = ring->get_seqno(ring); 1013bcfb2e28SChris Wilson list_for_each_entry(obj, &dev_priv->mm.active_list, mm_list) { 1014bcfb2e28SChris Wilson if (obj->ring != ring) 1015bcfb2e28SChris Wilson continue; 1016bcfb2e28SChris Wilson 1017c37d9a5dSChris Wilson if (i915_seqno_passed(seqno, obj->last_rendering_seqno)) 1018bcfb2e28SChris Wilson continue; 1019bcfb2e28SChris Wilson 1020bcfb2e28SChris Wilson if ((obj->base.read_domains & I915_GEM_DOMAIN_COMMAND) == 0) 1021bcfb2e28SChris Wilson continue; 1022bcfb2e28SChris Wilson 1023bcfb2e28SChris Wilson /* We need to copy these to an anonymous buffer as the simplest 1024bcfb2e28SChris Wilson * method to avoid being overwritten by userspace. 1025bcfb2e28SChris Wilson */ 1026bcfb2e28SChris Wilson return i915_error_object_create(dev_priv, obj); 1027bcfb2e28SChris Wilson } 1028bcfb2e28SChris Wilson 1029bcfb2e28SChris Wilson return NULL; 1030bcfb2e28SChris Wilson } 1031bcfb2e28SChris Wilson 1032d27b1e0eSDaniel Vetter static void i915_record_ring_state(struct drm_device *dev, 1033d27b1e0eSDaniel Vetter struct drm_i915_error_state *error, 1034d27b1e0eSDaniel Vetter struct intel_ring_buffer *ring) 1035d27b1e0eSDaniel Vetter { 1036d27b1e0eSDaniel Vetter struct drm_i915_private *dev_priv = dev->dev_private; 1037d27b1e0eSDaniel Vetter 103833f3f518SDaniel Vetter if (INTEL_INFO(dev)->gen >= 6) { 103933f3f518SDaniel Vetter error->fault_reg[ring->id] = I915_READ(RING_FAULT_REG(ring)); 10407e3b8737SDaniel Vetter error->semaphore_mboxes[ring->id][0] 10417e3b8737SDaniel Vetter = I915_READ(RING_SYNC_0(ring->mmio_base)); 10427e3b8737SDaniel Vetter error->semaphore_mboxes[ring->id][1] 10437e3b8737SDaniel Vetter = I915_READ(RING_SYNC_1(ring->mmio_base)); 104433f3f518SDaniel Vetter } 1045c1cd90edSDaniel Vetter 1046d27b1e0eSDaniel Vetter if (INTEL_INFO(dev)->gen >= 4) { 10479d2f41faSDaniel Vetter error->faddr[ring->id] = I915_READ(RING_DMA_FADD(ring->mmio_base)); 1048d27b1e0eSDaniel Vetter error->ipeir[ring->id] = I915_READ(RING_IPEIR(ring->mmio_base)); 1049d27b1e0eSDaniel Vetter error->ipehr[ring->id] = I915_READ(RING_IPEHR(ring->mmio_base)); 1050d27b1e0eSDaniel Vetter error->instdone[ring->id] = I915_READ(RING_INSTDONE(ring->mmio_base)); 1051c1cd90edSDaniel Vetter error->instps[ring->id] = I915_READ(RING_INSTPS(ring->mmio_base)); 1052d27b1e0eSDaniel Vetter if (ring->id == RCS) { 1053d27b1e0eSDaniel Vetter error->instdone1 = I915_READ(INSTDONE1); 1054d27b1e0eSDaniel Vetter error->bbaddr = I915_READ64(BB_ADDR); 1055d27b1e0eSDaniel Vetter } 1056d27b1e0eSDaniel Vetter } else { 10579d2f41faSDaniel Vetter error->faddr[ring->id] = I915_READ(DMA_FADD_I8XX); 1058d27b1e0eSDaniel Vetter error->ipeir[ring->id] = I915_READ(IPEIR); 1059d27b1e0eSDaniel Vetter error->ipehr[ring->id] = I915_READ(IPEHR); 1060d27b1e0eSDaniel Vetter error->instdone[ring->id] = I915_READ(INSTDONE); 1061d27b1e0eSDaniel Vetter } 1062d27b1e0eSDaniel Vetter 1063c1cd90edSDaniel Vetter error->instpm[ring->id] = I915_READ(RING_INSTPM(ring->mmio_base)); 1064d27b1e0eSDaniel Vetter error->seqno[ring->id] = ring->get_seqno(ring); 1065d27b1e0eSDaniel Vetter error->acthd[ring->id] = intel_ring_get_active_head(ring); 1066c1cd90edSDaniel Vetter error->head[ring->id] = I915_READ_HEAD(ring); 1067c1cd90edSDaniel Vetter error->tail[ring->id] = I915_READ_TAIL(ring); 10687e3b8737SDaniel Vetter 10697e3b8737SDaniel Vetter error->cpu_ring_head[ring->id] = ring->head; 10707e3b8737SDaniel Vetter error->cpu_ring_tail[ring->id] = ring->tail; 1071d27b1e0eSDaniel Vetter } 1072d27b1e0eSDaniel Vetter 107352d39a21SChris Wilson static void i915_gem_record_rings(struct drm_device *dev, 107452d39a21SChris Wilson struct drm_i915_error_state *error) 107552d39a21SChris Wilson { 107652d39a21SChris Wilson struct drm_i915_private *dev_priv = dev->dev_private; 107752d39a21SChris Wilson struct drm_i915_gem_request *request; 107852d39a21SChris Wilson int i, count; 107952d39a21SChris Wilson 108052d39a21SChris Wilson for (i = 0; i < I915_NUM_RINGS; i++) { 108152d39a21SChris Wilson struct intel_ring_buffer *ring = &dev_priv->ring[i]; 108252d39a21SChris Wilson 108352d39a21SChris Wilson if (ring->obj == NULL) 108452d39a21SChris Wilson continue; 108552d39a21SChris Wilson 108652d39a21SChris Wilson i915_record_ring_state(dev, error, ring); 108752d39a21SChris Wilson 108852d39a21SChris Wilson error->ring[i].batchbuffer = 108952d39a21SChris Wilson i915_error_first_batchbuffer(dev_priv, ring); 109052d39a21SChris Wilson 109152d39a21SChris Wilson error->ring[i].ringbuffer = 109252d39a21SChris Wilson i915_error_object_create(dev_priv, ring->obj); 109352d39a21SChris Wilson 109452d39a21SChris Wilson count = 0; 109552d39a21SChris Wilson list_for_each_entry(request, &ring->request_list, list) 109652d39a21SChris Wilson count++; 109752d39a21SChris Wilson 109852d39a21SChris Wilson error->ring[i].num_requests = count; 109952d39a21SChris Wilson error->ring[i].requests = 110052d39a21SChris Wilson kmalloc(count*sizeof(struct drm_i915_error_request), 110152d39a21SChris Wilson GFP_ATOMIC); 110252d39a21SChris Wilson if (error->ring[i].requests == NULL) { 110352d39a21SChris Wilson error->ring[i].num_requests = 0; 110452d39a21SChris Wilson continue; 110552d39a21SChris Wilson } 110652d39a21SChris Wilson 110752d39a21SChris Wilson count = 0; 110852d39a21SChris Wilson list_for_each_entry(request, &ring->request_list, list) { 110952d39a21SChris Wilson struct drm_i915_error_request *erq; 111052d39a21SChris Wilson 111152d39a21SChris Wilson erq = &error->ring[i].requests[count++]; 111252d39a21SChris Wilson erq->seqno = request->seqno; 111352d39a21SChris Wilson erq->jiffies = request->emitted_jiffies; 1114ee4f42b1SChris Wilson erq->tail = request->tail; 111552d39a21SChris Wilson } 111652d39a21SChris Wilson } 111752d39a21SChris Wilson } 111852d39a21SChris Wilson 11198a905236SJesse Barnes /** 11208a905236SJesse Barnes * i915_capture_error_state - capture an error record for later analysis 11218a905236SJesse Barnes * @dev: drm device 11228a905236SJesse Barnes * 11238a905236SJesse Barnes * Should be called when an error is detected (either a hang or an error 11248a905236SJesse Barnes * interrupt) to capture error state from the time of the error. Fills 11258a905236SJesse Barnes * out a structure which becomes available in debugfs for user level tools 11268a905236SJesse Barnes * to pick up. 11278a905236SJesse Barnes */ 112863eeaf38SJesse Barnes static void i915_capture_error_state(struct drm_device *dev) 112963eeaf38SJesse Barnes { 113063eeaf38SJesse Barnes struct drm_i915_private *dev_priv = dev->dev_private; 113105394f39SChris Wilson struct drm_i915_gem_object *obj; 113263eeaf38SJesse Barnes struct drm_i915_error_state *error; 113363eeaf38SJesse Barnes unsigned long flags; 11349db4a9c7SJesse Barnes int i, pipe; 113563eeaf38SJesse Barnes 113663eeaf38SJesse Barnes spin_lock_irqsave(&dev_priv->error_lock, flags); 11379df30794SChris Wilson error = dev_priv->first_error; 11389df30794SChris Wilson spin_unlock_irqrestore(&dev_priv->error_lock, flags); 11399df30794SChris Wilson if (error) 11409df30794SChris Wilson return; 114163eeaf38SJesse Barnes 11429db4a9c7SJesse Barnes /* Account for pipe specific data like PIPE*STAT */ 114333f3f518SDaniel Vetter error = kzalloc(sizeof(*error), GFP_ATOMIC); 114463eeaf38SJesse Barnes if (!error) { 11459df30794SChris Wilson DRM_DEBUG_DRIVER("out of memory, not capturing error state\n"); 11469df30794SChris Wilson return; 114763eeaf38SJesse Barnes } 114863eeaf38SJesse Barnes 1149b6f7833bSChris Wilson DRM_INFO("capturing error event; look for more information in /debug/dri/%d/i915_error_state\n", 1150b6f7833bSChris Wilson dev->primary->index); 11512fa772f3SChris Wilson 115263eeaf38SJesse Barnes error->eir = I915_READ(EIR); 115363eeaf38SJesse Barnes error->pgtbl_er = I915_READ(PGTBL_ER); 11549db4a9c7SJesse Barnes for_each_pipe(pipe) 11559db4a9c7SJesse Barnes error->pipestat[pipe] = I915_READ(PIPESTAT(pipe)); 1156d27b1e0eSDaniel Vetter 115733f3f518SDaniel Vetter if (INTEL_INFO(dev)->gen >= 6) { 1158f406839fSChris Wilson error->error = I915_READ(ERROR_GEN6); 115933f3f518SDaniel Vetter error->done_reg = I915_READ(DONE_REG); 116033f3f518SDaniel Vetter } 1161add354ddSChris Wilson 1162748ebc60SChris Wilson i915_gem_record_fences(dev, error); 116352d39a21SChris Wilson i915_gem_record_rings(dev, error); 11649df30794SChris Wilson 1165c724e8a9SChris Wilson /* Record buffers on the active and pinned lists. */ 11669df30794SChris Wilson error->active_bo = NULL; 1167c724e8a9SChris Wilson error->pinned_bo = NULL; 11689df30794SChris Wilson 1169bcfb2e28SChris Wilson i = 0; 1170bcfb2e28SChris Wilson list_for_each_entry(obj, &dev_priv->mm.active_list, mm_list) 1171bcfb2e28SChris Wilson i++; 1172bcfb2e28SChris Wilson error->active_bo_count = i; 11731b50247aSChris Wilson list_for_each_entry(obj, &dev_priv->mm.gtt_list, gtt_list) 11741b50247aSChris Wilson if (obj->pin_count) 1175bcfb2e28SChris Wilson i++; 1176bcfb2e28SChris Wilson error->pinned_bo_count = i - error->active_bo_count; 1177c724e8a9SChris Wilson 11788e934dbfSChris Wilson error->active_bo = NULL; 11798e934dbfSChris Wilson error->pinned_bo = NULL; 1180bcfb2e28SChris Wilson if (i) { 1181bcfb2e28SChris Wilson error->active_bo = kmalloc(sizeof(*error->active_bo)*i, 11829df30794SChris Wilson GFP_ATOMIC); 1183c724e8a9SChris Wilson if (error->active_bo) 1184c724e8a9SChris Wilson error->pinned_bo = 1185c724e8a9SChris Wilson error->active_bo + error->active_bo_count; 11869df30794SChris Wilson } 1187c724e8a9SChris Wilson 1188c724e8a9SChris Wilson if (error->active_bo) 1189c724e8a9SChris Wilson error->active_bo_count = 11901b50247aSChris Wilson capture_active_bo(error->active_bo, 1191c724e8a9SChris Wilson error->active_bo_count, 1192c724e8a9SChris Wilson &dev_priv->mm.active_list); 1193c724e8a9SChris Wilson 1194c724e8a9SChris Wilson if (error->pinned_bo) 1195c724e8a9SChris Wilson error->pinned_bo_count = 11961b50247aSChris Wilson capture_pinned_bo(error->pinned_bo, 1197c724e8a9SChris Wilson error->pinned_bo_count, 11981b50247aSChris Wilson &dev_priv->mm.gtt_list); 119963eeaf38SJesse Barnes 12008a905236SJesse Barnes do_gettimeofday(&error->time); 12018a905236SJesse Barnes 12026ef3d427SChris Wilson error->overlay = intel_overlay_capture_error_state(dev); 1203c4a1d9e4SChris Wilson error->display = intel_display_capture_error_state(dev); 12046ef3d427SChris Wilson 12059df30794SChris Wilson spin_lock_irqsave(&dev_priv->error_lock, flags); 12069df30794SChris Wilson if (dev_priv->first_error == NULL) { 120763eeaf38SJesse Barnes dev_priv->first_error = error; 12089df30794SChris Wilson error = NULL; 12099df30794SChris Wilson } 121063eeaf38SJesse Barnes spin_unlock_irqrestore(&dev_priv->error_lock, flags); 12119df30794SChris Wilson 12129df30794SChris Wilson if (error) 12139df30794SChris Wilson i915_error_state_free(dev, error); 12149df30794SChris Wilson } 12159df30794SChris Wilson 12169df30794SChris Wilson void i915_destroy_error_state(struct drm_device *dev) 12179df30794SChris Wilson { 12189df30794SChris Wilson struct drm_i915_private *dev_priv = dev->dev_private; 12199df30794SChris Wilson struct drm_i915_error_state *error; 12206dc0e816SBen Widawsky unsigned long flags; 12219df30794SChris Wilson 12226dc0e816SBen Widawsky spin_lock_irqsave(&dev_priv->error_lock, flags); 12239df30794SChris Wilson error = dev_priv->first_error; 12249df30794SChris Wilson dev_priv->first_error = NULL; 12256dc0e816SBen Widawsky spin_unlock_irqrestore(&dev_priv->error_lock, flags); 12269df30794SChris Wilson 12279df30794SChris Wilson if (error) 12289df30794SChris Wilson i915_error_state_free(dev, error); 122963eeaf38SJesse Barnes } 12303bd3c932SChris Wilson #else 12313bd3c932SChris Wilson #define i915_capture_error_state(x) 12323bd3c932SChris Wilson #endif 123363eeaf38SJesse Barnes 123435aed2e6SChris Wilson static void i915_report_and_clear_eir(struct drm_device *dev) 1235c0e09200SDave Airlie { 12368a905236SJesse Barnes struct drm_i915_private *dev_priv = dev->dev_private; 123763eeaf38SJesse Barnes u32 eir = I915_READ(EIR); 12389db4a9c7SJesse Barnes int pipe; 123963eeaf38SJesse Barnes 124035aed2e6SChris Wilson if (!eir) 124135aed2e6SChris Wilson return; 124263eeaf38SJesse Barnes 1243a70491ccSJoe Perches pr_err("render error detected, EIR: 0x%08x\n", eir); 12448a905236SJesse Barnes 12458a905236SJesse Barnes if (IS_G4X(dev)) { 12468a905236SJesse Barnes if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) { 12478a905236SJesse Barnes u32 ipeir = I915_READ(IPEIR_I965); 12488a905236SJesse Barnes 1249a70491ccSJoe Perches pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965)); 1250a70491ccSJoe Perches pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965)); 1251a70491ccSJoe Perches pr_err(" INSTDONE: 0x%08x\n", 12528a905236SJesse Barnes I915_READ(INSTDONE_I965)); 1253a70491ccSJoe Perches pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS)); 1254a70491ccSJoe Perches pr_err(" INSTDONE1: 0x%08x\n", I915_READ(INSTDONE1)); 1255a70491ccSJoe Perches pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965)); 12568a905236SJesse Barnes I915_WRITE(IPEIR_I965, ipeir); 12573143a2bfSChris Wilson POSTING_READ(IPEIR_I965); 12588a905236SJesse Barnes } 12598a905236SJesse Barnes if (eir & GM45_ERROR_PAGE_TABLE) { 12608a905236SJesse Barnes u32 pgtbl_err = I915_READ(PGTBL_ER); 1261a70491ccSJoe Perches pr_err("page table error\n"); 1262a70491ccSJoe Perches pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err); 12638a905236SJesse Barnes I915_WRITE(PGTBL_ER, pgtbl_err); 12643143a2bfSChris Wilson POSTING_READ(PGTBL_ER); 12658a905236SJesse Barnes } 12668a905236SJesse Barnes } 12678a905236SJesse Barnes 1268a6c45cf0SChris Wilson if (!IS_GEN2(dev)) { 126963eeaf38SJesse Barnes if (eir & I915_ERROR_PAGE_TABLE) { 127063eeaf38SJesse Barnes u32 pgtbl_err = I915_READ(PGTBL_ER); 1271a70491ccSJoe Perches pr_err("page table error\n"); 1272a70491ccSJoe Perches pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err); 127363eeaf38SJesse Barnes I915_WRITE(PGTBL_ER, pgtbl_err); 12743143a2bfSChris Wilson POSTING_READ(PGTBL_ER); 127563eeaf38SJesse Barnes } 12768a905236SJesse Barnes } 12778a905236SJesse Barnes 127863eeaf38SJesse Barnes if (eir & I915_ERROR_MEMORY_REFRESH) { 1279a70491ccSJoe Perches pr_err("memory refresh error:\n"); 12809db4a9c7SJesse Barnes for_each_pipe(pipe) 1281a70491ccSJoe Perches pr_err("pipe %c stat: 0x%08x\n", 12829db4a9c7SJesse Barnes pipe_name(pipe), I915_READ(PIPESTAT(pipe))); 128363eeaf38SJesse Barnes /* pipestat has already been acked */ 128463eeaf38SJesse Barnes } 128563eeaf38SJesse Barnes if (eir & I915_ERROR_INSTRUCTION) { 1286a70491ccSJoe Perches pr_err("instruction error\n"); 1287a70491ccSJoe Perches pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM)); 1288a6c45cf0SChris Wilson if (INTEL_INFO(dev)->gen < 4) { 128963eeaf38SJesse Barnes u32 ipeir = I915_READ(IPEIR); 129063eeaf38SJesse Barnes 1291a70491ccSJoe Perches pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR)); 1292a70491ccSJoe Perches pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR)); 1293a70491ccSJoe Perches pr_err(" INSTDONE: 0x%08x\n", I915_READ(INSTDONE)); 1294a70491ccSJoe Perches pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD)); 129563eeaf38SJesse Barnes I915_WRITE(IPEIR, ipeir); 12963143a2bfSChris Wilson POSTING_READ(IPEIR); 129763eeaf38SJesse Barnes } else { 129863eeaf38SJesse Barnes u32 ipeir = I915_READ(IPEIR_I965); 129963eeaf38SJesse Barnes 1300a70491ccSJoe Perches pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965)); 1301a70491ccSJoe Perches pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965)); 1302a70491ccSJoe Perches pr_err(" INSTDONE: 0x%08x\n", 130363eeaf38SJesse Barnes I915_READ(INSTDONE_I965)); 1304a70491ccSJoe Perches pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS)); 1305a70491ccSJoe Perches pr_err(" INSTDONE1: 0x%08x\n", I915_READ(INSTDONE1)); 1306a70491ccSJoe Perches pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965)); 130763eeaf38SJesse Barnes I915_WRITE(IPEIR_I965, ipeir); 13083143a2bfSChris Wilson POSTING_READ(IPEIR_I965); 130963eeaf38SJesse Barnes } 131063eeaf38SJesse Barnes } 131163eeaf38SJesse Barnes 131263eeaf38SJesse Barnes I915_WRITE(EIR, eir); 13133143a2bfSChris Wilson POSTING_READ(EIR); 131463eeaf38SJesse Barnes eir = I915_READ(EIR); 131563eeaf38SJesse Barnes if (eir) { 131663eeaf38SJesse Barnes /* 131763eeaf38SJesse Barnes * some errors might have become stuck, 131863eeaf38SJesse Barnes * mask them. 131963eeaf38SJesse Barnes */ 132063eeaf38SJesse Barnes DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir); 132163eeaf38SJesse Barnes I915_WRITE(EMR, I915_READ(EMR) | eir); 132263eeaf38SJesse Barnes I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); 132363eeaf38SJesse Barnes } 132435aed2e6SChris Wilson } 132535aed2e6SChris Wilson 132635aed2e6SChris Wilson /** 132735aed2e6SChris Wilson * i915_handle_error - handle an error interrupt 132835aed2e6SChris Wilson * @dev: drm device 132935aed2e6SChris Wilson * 133035aed2e6SChris Wilson * Do some basic checking of regsiter state at error interrupt time and 133135aed2e6SChris Wilson * dump it to the syslog. Also call i915_capture_error_state() to make 133235aed2e6SChris Wilson * sure we get a record and make it available in debugfs. Fire a uevent 133335aed2e6SChris Wilson * so userspace knows something bad happened (should trigger collection 133435aed2e6SChris Wilson * of a ring dump etc.). 133535aed2e6SChris Wilson */ 1336527f9e90SChris Wilson void i915_handle_error(struct drm_device *dev, bool wedged) 133735aed2e6SChris Wilson { 133835aed2e6SChris Wilson struct drm_i915_private *dev_priv = dev->dev_private; 133935aed2e6SChris Wilson 134035aed2e6SChris Wilson i915_capture_error_state(dev); 134135aed2e6SChris Wilson i915_report_and_clear_eir(dev); 13428a905236SJesse Barnes 1343ba1234d1SBen Gamari if (wedged) { 134430dbf0c0SChris Wilson INIT_COMPLETION(dev_priv->error_completion); 1345ba1234d1SBen Gamari atomic_set(&dev_priv->mm.wedged, 1); 1346ba1234d1SBen Gamari 134711ed50ecSBen Gamari /* 134811ed50ecSBen Gamari * Wakeup waiting processes so they don't hang 134911ed50ecSBen Gamari */ 13501ec14ad3SChris Wilson wake_up_all(&dev_priv->ring[RCS].irq_queue); 1351f787a5f5SChris Wilson if (HAS_BSD(dev)) 13521ec14ad3SChris Wilson wake_up_all(&dev_priv->ring[VCS].irq_queue); 1353549f7365SChris Wilson if (HAS_BLT(dev)) 13541ec14ad3SChris Wilson wake_up_all(&dev_priv->ring[BCS].irq_queue); 135511ed50ecSBen Gamari } 135611ed50ecSBen Gamari 13579c9fe1f8SEric Anholt queue_work(dev_priv->wq, &dev_priv->error_work); 13588a905236SJesse Barnes } 13598a905236SJesse Barnes 13604e5359cdSSimon Farnsworth static void i915_pageflip_stall_check(struct drm_device *dev, int pipe) 13614e5359cdSSimon Farnsworth { 13624e5359cdSSimon Farnsworth drm_i915_private_t *dev_priv = dev->dev_private; 13634e5359cdSSimon Farnsworth struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; 13644e5359cdSSimon Farnsworth struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 136505394f39SChris Wilson struct drm_i915_gem_object *obj; 13664e5359cdSSimon Farnsworth struct intel_unpin_work *work; 13674e5359cdSSimon Farnsworth unsigned long flags; 13684e5359cdSSimon Farnsworth bool stall_detected; 13694e5359cdSSimon Farnsworth 13704e5359cdSSimon Farnsworth /* Ignore early vblank irqs */ 13714e5359cdSSimon Farnsworth if (intel_crtc == NULL) 13724e5359cdSSimon Farnsworth return; 13734e5359cdSSimon Farnsworth 13744e5359cdSSimon Farnsworth spin_lock_irqsave(&dev->event_lock, flags); 13754e5359cdSSimon Farnsworth work = intel_crtc->unpin_work; 13764e5359cdSSimon Farnsworth 13774e5359cdSSimon Farnsworth if (work == NULL || work->pending || !work->enable_stall_check) { 13784e5359cdSSimon Farnsworth /* Either the pending flip IRQ arrived, or we're too early. Don't check */ 13794e5359cdSSimon Farnsworth spin_unlock_irqrestore(&dev->event_lock, flags); 13804e5359cdSSimon Farnsworth return; 13814e5359cdSSimon Farnsworth } 13824e5359cdSSimon Farnsworth 13834e5359cdSSimon Farnsworth /* Potential stall - if we see that the flip has happened, assume a missed interrupt */ 138405394f39SChris Wilson obj = work->pending_flip_obj; 1385a6c45cf0SChris Wilson if (INTEL_INFO(dev)->gen >= 4) { 13869db4a9c7SJesse Barnes int dspsurf = DSPSURF(intel_crtc->plane); 1387446f2545SArmin Reese stall_detected = I915_HI_DISPBASE(I915_READ(dspsurf)) == 1388446f2545SArmin Reese obj->gtt_offset; 13894e5359cdSSimon Farnsworth } else { 13909db4a9c7SJesse Barnes int dspaddr = DSPADDR(intel_crtc->plane); 139105394f39SChris Wilson stall_detected = I915_READ(dspaddr) == (obj->gtt_offset + 139201f2c773SVille Syrjälä crtc->y * crtc->fb->pitches[0] + 13934e5359cdSSimon Farnsworth crtc->x * crtc->fb->bits_per_pixel/8); 13944e5359cdSSimon Farnsworth } 13954e5359cdSSimon Farnsworth 13964e5359cdSSimon Farnsworth spin_unlock_irqrestore(&dev->event_lock, flags); 13974e5359cdSSimon Farnsworth 13984e5359cdSSimon Farnsworth if (stall_detected) { 13994e5359cdSSimon Farnsworth DRM_DEBUG_DRIVER("Pageflip stall detected\n"); 14004e5359cdSSimon Farnsworth intel_prepare_page_flip(dev, intel_crtc->plane); 14014e5359cdSSimon Farnsworth } 14024e5359cdSSimon Farnsworth } 14034e5359cdSSimon Farnsworth 1404c0e09200SDave Airlie static int i915_emit_irq(struct drm_device * dev) 1405c0e09200SDave Airlie { 1406c0e09200SDave Airlie drm_i915_private_t *dev_priv = dev->dev_private; 14077c1c2871SDave Airlie struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv; 1408c0e09200SDave Airlie 1409c0e09200SDave Airlie i915_kernel_lost_context(dev); 1410c0e09200SDave Airlie 141144d98a61SZhao Yakui DRM_DEBUG_DRIVER("\n"); 1412c0e09200SDave Airlie 1413c99b058fSKristian Høgsberg dev_priv->counter++; 1414c0e09200SDave Airlie if (dev_priv->counter > 0x7FFFFFFFUL) 1415c99b058fSKristian Høgsberg dev_priv->counter = 1; 14167c1c2871SDave Airlie if (master_priv->sarea_priv) 14177c1c2871SDave Airlie master_priv->sarea_priv->last_enqueue = dev_priv->counter; 1418c0e09200SDave Airlie 1419e1f99ce6SChris Wilson if (BEGIN_LP_RING(4) == 0) { 1420585fb111SJesse Barnes OUT_RING(MI_STORE_DWORD_INDEX); 14210baf823aSKeith Packard OUT_RING(I915_BREADCRUMB_INDEX << MI_STORE_DWORD_INDEX_SHIFT); 1422c0e09200SDave Airlie OUT_RING(dev_priv->counter); 1423585fb111SJesse Barnes OUT_RING(MI_USER_INTERRUPT); 1424c0e09200SDave Airlie ADVANCE_LP_RING(); 1425e1f99ce6SChris Wilson } 1426c0e09200SDave Airlie 1427c0e09200SDave Airlie return dev_priv->counter; 1428c0e09200SDave Airlie } 1429c0e09200SDave Airlie 1430c0e09200SDave Airlie static int i915_wait_irq(struct drm_device * dev, int irq_nr) 1431c0e09200SDave Airlie { 1432c0e09200SDave Airlie drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 14337c1c2871SDave Airlie struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv; 1434c0e09200SDave Airlie int ret = 0; 14351ec14ad3SChris Wilson struct intel_ring_buffer *ring = LP_RING(dev_priv); 1436c0e09200SDave Airlie 143744d98a61SZhao Yakui DRM_DEBUG_DRIVER("irq_nr=%d breadcrumb=%d\n", irq_nr, 1438c0e09200SDave Airlie READ_BREADCRUMB(dev_priv)); 1439c0e09200SDave Airlie 1440ed4cb414SEric Anholt if (READ_BREADCRUMB(dev_priv) >= irq_nr) { 14417c1c2871SDave Airlie if (master_priv->sarea_priv) 14427c1c2871SDave Airlie master_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv); 1443c0e09200SDave Airlie return 0; 1444ed4cb414SEric Anholt } 1445c0e09200SDave Airlie 14467c1c2871SDave Airlie if (master_priv->sarea_priv) 14477c1c2871SDave Airlie master_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT; 1448c0e09200SDave Airlie 1449b13c2b96SChris Wilson if (ring->irq_get(ring)) { 14501ec14ad3SChris Wilson DRM_WAIT_ON(ret, ring->irq_queue, 3 * DRM_HZ, 1451c0e09200SDave Airlie READ_BREADCRUMB(dev_priv) >= irq_nr); 14521ec14ad3SChris Wilson ring->irq_put(ring); 14535a9a8d1aSChris Wilson } else if (wait_for(READ_BREADCRUMB(dev_priv) >= irq_nr, 3000)) 14545a9a8d1aSChris Wilson ret = -EBUSY; 1455c0e09200SDave Airlie 1456c0e09200SDave Airlie if (ret == -EBUSY) { 1457c0e09200SDave Airlie DRM_ERROR("EBUSY -- rec: %d emitted: %d\n", 1458c0e09200SDave Airlie READ_BREADCRUMB(dev_priv), (int)dev_priv->counter); 1459c0e09200SDave Airlie } 1460c0e09200SDave Airlie 1461c0e09200SDave Airlie return ret; 1462c0e09200SDave Airlie } 1463c0e09200SDave Airlie 1464c0e09200SDave Airlie /* Needs the lock as it touches the ring. 1465c0e09200SDave Airlie */ 1466c0e09200SDave Airlie int i915_irq_emit(struct drm_device *dev, void *data, 1467c0e09200SDave Airlie struct drm_file *file_priv) 1468c0e09200SDave Airlie { 1469c0e09200SDave Airlie drm_i915_private_t *dev_priv = dev->dev_private; 1470c0e09200SDave Airlie drm_i915_irq_emit_t *emit = data; 1471c0e09200SDave Airlie int result; 1472c0e09200SDave Airlie 1473cd9d4e9fSDaniel Vetter if (drm_core_check_feature(dev, DRIVER_MODESET)) 1474cd9d4e9fSDaniel Vetter return -ENODEV; 1475cd9d4e9fSDaniel Vetter 14761ec14ad3SChris Wilson if (!dev_priv || !LP_RING(dev_priv)->virtual_start) { 1477c0e09200SDave Airlie DRM_ERROR("called with no initialization\n"); 1478c0e09200SDave Airlie return -EINVAL; 1479c0e09200SDave Airlie } 1480299eb93cSEric Anholt 1481299eb93cSEric Anholt RING_LOCK_TEST_WITH_RETURN(dev, file_priv); 1482299eb93cSEric Anholt 1483546b0974SEric Anholt mutex_lock(&dev->struct_mutex); 1484c0e09200SDave Airlie result = i915_emit_irq(dev); 1485546b0974SEric Anholt mutex_unlock(&dev->struct_mutex); 1486c0e09200SDave Airlie 1487c0e09200SDave Airlie if (DRM_COPY_TO_USER(emit->irq_seq, &result, sizeof(int))) { 1488c0e09200SDave Airlie DRM_ERROR("copy_to_user\n"); 1489c0e09200SDave Airlie return -EFAULT; 1490c0e09200SDave Airlie } 1491c0e09200SDave Airlie 1492c0e09200SDave Airlie return 0; 1493c0e09200SDave Airlie } 1494c0e09200SDave Airlie 1495c0e09200SDave Airlie /* Doesn't need the hardware lock. 1496c0e09200SDave Airlie */ 1497c0e09200SDave Airlie int i915_irq_wait(struct drm_device *dev, void *data, 1498c0e09200SDave Airlie struct drm_file *file_priv) 1499c0e09200SDave Airlie { 1500c0e09200SDave Airlie drm_i915_private_t *dev_priv = dev->dev_private; 1501c0e09200SDave Airlie drm_i915_irq_wait_t *irqwait = data; 1502c0e09200SDave Airlie 1503cd9d4e9fSDaniel Vetter if (drm_core_check_feature(dev, DRIVER_MODESET)) 1504cd9d4e9fSDaniel Vetter return -ENODEV; 1505cd9d4e9fSDaniel Vetter 1506c0e09200SDave Airlie if (!dev_priv) { 1507c0e09200SDave Airlie DRM_ERROR("called with no initialization\n"); 1508c0e09200SDave Airlie return -EINVAL; 1509c0e09200SDave Airlie } 1510c0e09200SDave Airlie 1511c0e09200SDave Airlie return i915_wait_irq(dev, irqwait->irq_seq); 1512c0e09200SDave Airlie } 1513c0e09200SDave Airlie 151442f52ef8SKeith Packard /* Called from drm generic code, passed 'crtc' which 151542f52ef8SKeith Packard * we use as a pipe index 151642f52ef8SKeith Packard */ 1517f71d4af4SJesse Barnes static int i915_enable_vblank(struct drm_device *dev, int pipe) 15180a3e67a4SJesse Barnes { 15190a3e67a4SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 1520e9d21d7fSKeith Packard unsigned long irqflags; 152171e0ffa5SJesse Barnes 15225eddb70bSChris Wilson if (!i915_pipe_enabled(dev, pipe)) 152371e0ffa5SJesse Barnes return -EINVAL; 15240a3e67a4SJesse Barnes 15251ec14ad3SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 1526f796cf8fSJesse Barnes if (INTEL_INFO(dev)->gen >= 4) 15277c463586SKeith Packard i915_enable_pipestat(dev_priv, pipe, 15287c463586SKeith Packard PIPE_START_VBLANK_INTERRUPT_ENABLE); 15290a3e67a4SJesse Barnes else 15307c463586SKeith Packard i915_enable_pipestat(dev_priv, pipe, 15317c463586SKeith Packard PIPE_VBLANK_INTERRUPT_ENABLE); 15328692d00eSChris Wilson 15338692d00eSChris Wilson /* maintain vblank delivery even in deep C-states */ 15348692d00eSChris Wilson if (dev_priv->info->gen == 3) 15356b26c86dSDaniel Vetter I915_WRITE(INSTPM, _MASKED_BIT_DISABLE(INSTPM_AGPBUSY_DIS)); 15361ec14ad3SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 15378692d00eSChris Wilson 15380a3e67a4SJesse Barnes return 0; 15390a3e67a4SJesse Barnes } 15400a3e67a4SJesse Barnes 1541f71d4af4SJesse Barnes static int ironlake_enable_vblank(struct drm_device *dev, int pipe) 1542f796cf8fSJesse Barnes { 1543f796cf8fSJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 1544f796cf8fSJesse Barnes unsigned long irqflags; 1545f796cf8fSJesse Barnes 1546f796cf8fSJesse Barnes if (!i915_pipe_enabled(dev, pipe)) 1547f796cf8fSJesse Barnes return -EINVAL; 1548f796cf8fSJesse Barnes 1549f796cf8fSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 1550f796cf8fSJesse Barnes ironlake_enable_display_irq(dev_priv, (pipe == 0) ? 1551f796cf8fSJesse Barnes DE_PIPEA_VBLANK : DE_PIPEB_VBLANK); 1552f796cf8fSJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 1553f796cf8fSJesse Barnes 1554f796cf8fSJesse Barnes return 0; 1555f796cf8fSJesse Barnes } 1556f796cf8fSJesse Barnes 1557f71d4af4SJesse Barnes static int ivybridge_enable_vblank(struct drm_device *dev, int pipe) 1558b1f14ad0SJesse Barnes { 1559b1f14ad0SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 1560b1f14ad0SJesse Barnes unsigned long irqflags; 1561b1f14ad0SJesse Barnes 1562b1f14ad0SJesse Barnes if (!i915_pipe_enabled(dev, pipe)) 1563b1f14ad0SJesse Barnes return -EINVAL; 1564b1f14ad0SJesse Barnes 1565b1f14ad0SJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 1566b1f14ad0SJesse Barnes ironlake_enable_display_irq(dev_priv, (pipe == 0) ? 1567b1f14ad0SJesse Barnes DE_PIPEA_VBLANK_IVB : DE_PIPEB_VBLANK_IVB); 1568b1f14ad0SJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 1569b1f14ad0SJesse Barnes 1570b1f14ad0SJesse Barnes return 0; 1571b1f14ad0SJesse Barnes } 1572b1f14ad0SJesse Barnes 15737e231dbeSJesse Barnes static int valleyview_enable_vblank(struct drm_device *dev, int pipe) 15747e231dbeSJesse Barnes { 15757e231dbeSJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 15767e231dbeSJesse Barnes unsigned long irqflags; 15777e231dbeSJesse Barnes u32 dpfl, imr; 15787e231dbeSJesse Barnes 15797e231dbeSJesse Barnes if (!i915_pipe_enabled(dev, pipe)) 15807e231dbeSJesse Barnes return -EINVAL; 15817e231dbeSJesse Barnes 15827e231dbeSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 15837e231dbeSJesse Barnes dpfl = I915_READ(VLV_DPFLIPSTAT); 15847e231dbeSJesse Barnes imr = I915_READ(VLV_IMR); 15857e231dbeSJesse Barnes if (pipe == 0) { 15867e231dbeSJesse Barnes dpfl |= PIPEA_VBLANK_INT_EN; 15877e231dbeSJesse Barnes imr &= ~I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT; 15887e231dbeSJesse Barnes } else { 15897e231dbeSJesse Barnes dpfl |= PIPEA_VBLANK_INT_EN; 15907e231dbeSJesse Barnes imr &= ~I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT; 15917e231dbeSJesse Barnes } 15927e231dbeSJesse Barnes I915_WRITE(VLV_DPFLIPSTAT, dpfl); 15937e231dbeSJesse Barnes I915_WRITE(VLV_IMR, imr); 15947e231dbeSJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 15957e231dbeSJesse Barnes 15967e231dbeSJesse Barnes return 0; 15977e231dbeSJesse Barnes } 15987e231dbeSJesse Barnes 159942f52ef8SKeith Packard /* Called from drm generic code, passed 'crtc' which 160042f52ef8SKeith Packard * we use as a pipe index 160142f52ef8SKeith Packard */ 1602f71d4af4SJesse Barnes static void i915_disable_vblank(struct drm_device *dev, int pipe) 16030a3e67a4SJesse Barnes { 16040a3e67a4SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 1605e9d21d7fSKeith Packard unsigned long irqflags; 16060a3e67a4SJesse Barnes 16071ec14ad3SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 16088692d00eSChris Wilson if (dev_priv->info->gen == 3) 16096b26c86dSDaniel Vetter I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_DIS)); 16108692d00eSChris Wilson 16117c463586SKeith Packard i915_disable_pipestat(dev_priv, pipe, 16127c463586SKeith Packard PIPE_VBLANK_INTERRUPT_ENABLE | 16137c463586SKeith Packard PIPE_START_VBLANK_INTERRUPT_ENABLE); 16141ec14ad3SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 16150a3e67a4SJesse Barnes } 16160a3e67a4SJesse Barnes 1617f71d4af4SJesse Barnes static void ironlake_disable_vblank(struct drm_device *dev, int pipe) 1618f796cf8fSJesse Barnes { 1619f796cf8fSJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 1620f796cf8fSJesse Barnes unsigned long irqflags; 1621f796cf8fSJesse Barnes 1622f796cf8fSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 1623f796cf8fSJesse Barnes ironlake_disable_display_irq(dev_priv, (pipe == 0) ? 1624f796cf8fSJesse Barnes DE_PIPEA_VBLANK : DE_PIPEB_VBLANK); 1625f796cf8fSJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 1626f796cf8fSJesse Barnes } 1627f796cf8fSJesse Barnes 1628f71d4af4SJesse Barnes static void ivybridge_disable_vblank(struct drm_device *dev, int pipe) 1629b1f14ad0SJesse Barnes { 1630b1f14ad0SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 1631b1f14ad0SJesse Barnes unsigned long irqflags; 1632b1f14ad0SJesse Barnes 1633b1f14ad0SJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 1634b1f14ad0SJesse Barnes ironlake_disable_display_irq(dev_priv, (pipe == 0) ? 1635b1f14ad0SJesse Barnes DE_PIPEA_VBLANK_IVB : DE_PIPEB_VBLANK_IVB); 1636b1f14ad0SJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 1637b1f14ad0SJesse Barnes } 1638b1f14ad0SJesse Barnes 16397e231dbeSJesse Barnes static void valleyview_disable_vblank(struct drm_device *dev, int pipe) 16407e231dbeSJesse Barnes { 16417e231dbeSJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 16427e231dbeSJesse Barnes unsigned long irqflags; 16437e231dbeSJesse Barnes u32 dpfl, imr; 16447e231dbeSJesse Barnes 16457e231dbeSJesse Barnes spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 16467e231dbeSJesse Barnes dpfl = I915_READ(VLV_DPFLIPSTAT); 16477e231dbeSJesse Barnes imr = I915_READ(VLV_IMR); 16487e231dbeSJesse Barnes if (pipe == 0) { 16497e231dbeSJesse Barnes dpfl &= ~PIPEA_VBLANK_INT_EN; 16507e231dbeSJesse Barnes imr |= I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT; 16517e231dbeSJesse Barnes } else { 16527e231dbeSJesse Barnes dpfl &= ~PIPEB_VBLANK_INT_EN; 16537e231dbeSJesse Barnes imr |= I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT; 16547e231dbeSJesse Barnes } 16557e231dbeSJesse Barnes I915_WRITE(VLV_IMR, imr); 16567e231dbeSJesse Barnes I915_WRITE(VLV_DPFLIPSTAT, dpfl); 16577e231dbeSJesse Barnes spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 16587e231dbeSJesse Barnes } 16597e231dbeSJesse Barnes 16607e231dbeSJesse Barnes 1661c0e09200SDave Airlie /* Set the vblank monitor pipe 1662c0e09200SDave Airlie */ 1663c0e09200SDave Airlie int i915_vblank_pipe_set(struct drm_device *dev, void *data, 1664c0e09200SDave Airlie struct drm_file *file_priv) 1665c0e09200SDave Airlie { 1666c0e09200SDave Airlie drm_i915_private_t *dev_priv = dev->dev_private; 1667c0e09200SDave Airlie 1668cd9d4e9fSDaniel Vetter if (drm_core_check_feature(dev, DRIVER_MODESET)) 1669cd9d4e9fSDaniel Vetter return -ENODEV; 1670cd9d4e9fSDaniel Vetter 1671c0e09200SDave Airlie if (!dev_priv) { 1672c0e09200SDave Airlie DRM_ERROR("called with no initialization\n"); 1673c0e09200SDave Airlie return -EINVAL; 1674c0e09200SDave Airlie } 1675c0e09200SDave Airlie 1676c0e09200SDave Airlie return 0; 1677c0e09200SDave Airlie } 1678c0e09200SDave Airlie 1679c0e09200SDave Airlie int i915_vblank_pipe_get(struct drm_device *dev, void *data, 1680c0e09200SDave Airlie struct drm_file *file_priv) 1681c0e09200SDave Airlie { 1682c0e09200SDave Airlie drm_i915_private_t *dev_priv = dev->dev_private; 1683c0e09200SDave Airlie drm_i915_vblank_pipe_t *pipe = data; 1684c0e09200SDave Airlie 1685cd9d4e9fSDaniel Vetter if (drm_core_check_feature(dev, DRIVER_MODESET)) 1686cd9d4e9fSDaniel Vetter return -ENODEV; 1687cd9d4e9fSDaniel Vetter 1688c0e09200SDave Airlie if (!dev_priv) { 1689c0e09200SDave Airlie DRM_ERROR("called with no initialization\n"); 1690c0e09200SDave Airlie return -EINVAL; 1691c0e09200SDave Airlie } 1692c0e09200SDave Airlie 16930a3e67a4SJesse Barnes pipe->pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B; 1694c0e09200SDave Airlie 1695c0e09200SDave Airlie return 0; 1696c0e09200SDave Airlie } 1697c0e09200SDave Airlie 1698c0e09200SDave Airlie /** 1699c0e09200SDave Airlie * Schedule buffer swap at given vertical blank. 1700c0e09200SDave Airlie */ 1701c0e09200SDave Airlie int i915_vblank_swap(struct drm_device *dev, void *data, 1702c0e09200SDave Airlie struct drm_file *file_priv) 1703c0e09200SDave Airlie { 1704bd95e0a4SEric Anholt /* The delayed swap mechanism was fundamentally racy, and has been 1705bd95e0a4SEric Anholt * removed. The model was that the client requested a delayed flip/swap 1706bd95e0a4SEric Anholt * from the kernel, then waited for vblank before continuing to perform 1707bd95e0a4SEric Anholt * rendering. The problem was that the kernel might wake the client 1708bd95e0a4SEric Anholt * up before it dispatched the vblank swap (since the lock has to be 1709bd95e0a4SEric Anholt * held while touching the ringbuffer), in which case the client would 1710bd95e0a4SEric Anholt * clear and start the next frame before the swap occurred, and 1711bd95e0a4SEric Anholt * flicker would occur in addition to likely missing the vblank. 1712bd95e0a4SEric Anholt * 1713bd95e0a4SEric Anholt * In the absence of this ioctl, userland falls back to a correct path 1714bd95e0a4SEric Anholt * of waiting for a vblank, then dispatching the swap on its own. 1715bd95e0a4SEric Anholt * Context switching to userland and back is plenty fast enough for 1716bd95e0a4SEric Anholt * meeting the requirements of vblank swapping. 17170a3e67a4SJesse Barnes */ 1718c0e09200SDave Airlie return -EINVAL; 1719c0e09200SDave Airlie } 1720c0e09200SDave Airlie 1721893eead0SChris Wilson static u32 1722893eead0SChris Wilson ring_last_seqno(struct intel_ring_buffer *ring) 1723852835f3SZou Nan hai { 1724893eead0SChris Wilson return list_entry(ring->request_list.prev, 1725893eead0SChris Wilson struct drm_i915_gem_request, list)->seqno; 1726893eead0SChris Wilson } 1727893eead0SChris Wilson 1728893eead0SChris Wilson static bool i915_hangcheck_ring_idle(struct intel_ring_buffer *ring, bool *err) 1729893eead0SChris Wilson { 1730893eead0SChris Wilson if (list_empty(&ring->request_list) || 1731893eead0SChris Wilson i915_seqno_passed(ring->get_seqno(ring), ring_last_seqno(ring))) { 1732893eead0SChris Wilson /* Issue a wake-up to catch stuck h/w. */ 1733b2223497SChris Wilson if (ring->waiting_seqno && waitqueue_active(&ring->irq_queue)) { 1734893eead0SChris Wilson DRM_ERROR("Hangcheck timer elapsed... %s idle [waiting on %d, at %d], missed IRQ?\n", 1735893eead0SChris Wilson ring->name, 1736b2223497SChris Wilson ring->waiting_seqno, 1737893eead0SChris Wilson ring->get_seqno(ring)); 1738893eead0SChris Wilson wake_up_all(&ring->irq_queue); 1739893eead0SChris Wilson *err = true; 1740893eead0SChris Wilson } 1741893eead0SChris Wilson return true; 1742893eead0SChris Wilson } 1743893eead0SChris Wilson return false; 1744f65d9421SBen Gamari } 1745f65d9421SBen Gamari 17461ec14ad3SChris Wilson static bool kick_ring(struct intel_ring_buffer *ring) 17471ec14ad3SChris Wilson { 17481ec14ad3SChris Wilson struct drm_device *dev = ring->dev; 17491ec14ad3SChris Wilson struct drm_i915_private *dev_priv = dev->dev_private; 17501ec14ad3SChris Wilson u32 tmp = I915_READ_CTL(ring); 17511ec14ad3SChris Wilson if (tmp & RING_WAIT) { 17521ec14ad3SChris Wilson DRM_ERROR("Kicking stuck wait on %s\n", 17531ec14ad3SChris Wilson ring->name); 17541ec14ad3SChris Wilson I915_WRITE_CTL(ring, tmp); 17551ec14ad3SChris Wilson return true; 17561ec14ad3SChris Wilson } 17571ec14ad3SChris Wilson return false; 17581ec14ad3SChris Wilson } 17591ec14ad3SChris Wilson 1760d1e61e7fSChris Wilson static bool i915_hangcheck_hung(struct drm_device *dev) 1761d1e61e7fSChris Wilson { 1762d1e61e7fSChris Wilson drm_i915_private_t *dev_priv = dev->dev_private; 1763d1e61e7fSChris Wilson 1764d1e61e7fSChris Wilson if (dev_priv->hangcheck_count++ > 1) { 1765d1e61e7fSChris Wilson DRM_ERROR("Hangcheck timer elapsed... GPU hung\n"); 1766d1e61e7fSChris Wilson i915_handle_error(dev, true); 1767d1e61e7fSChris Wilson 1768d1e61e7fSChris Wilson if (!IS_GEN2(dev)) { 1769d1e61e7fSChris Wilson /* Is the chip hanging on a WAIT_FOR_EVENT? 1770d1e61e7fSChris Wilson * If so we can simply poke the RB_WAIT bit 1771d1e61e7fSChris Wilson * and break the hang. This should work on 1772d1e61e7fSChris Wilson * all but the second generation chipsets. 1773d1e61e7fSChris Wilson */ 1774d1e61e7fSChris Wilson if (kick_ring(&dev_priv->ring[RCS])) 1775d1e61e7fSChris Wilson return false; 1776d1e61e7fSChris Wilson 1777d1e61e7fSChris Wilson if (HAS_BSD(dev) && kick_ring(&dev_priv->ring[VCS])) 1778d1e61e7fSChris Wilson return false; 1779d1e61e7fSChris Wilson 1780d1e61e7fSChris Wilson if (HAS_BLT(dev) && kick_ring(&dev_priv->ring[BCS])) 1781d1e61e7fSChris Wilson return false; 1782d1e61e7fSChris Wilson } 1783d1e61e7fSChris Wilson 1784d1e61e7fSChris Wilson return true; 1785d1e61e7fSChris Wilson } 1786d1e61e7fSChris Wilson 1787d1e61e7fSChris Wilson return false; 1788d1e61e7fSChris Wilson } 1789d1e61e7fSChris Wilson 1790f65d9421SBen Gamari /** 1791f65d9421SBen Gamari * This is called when the chip hasn't reported back with completed 1792f65d9421SBen Gamari * batchbuffers in a long time. The first time this is called we simply record 1793f65d9421SBen Gamari * ACTHD. If ACTHD hasn't changed by the time the hangcheck timer elapses 1794f65d9421SBen Gamari * again, we assume the chip is wedged and try to fix it. 1795f65d9421SBen Gamari */ 1796f65d9421SBen Gamari void i915_hangcheck_elapsed(unsigned long data) 1797f65d9421SBen Gamari { 1798f65d9421SBen Gamari struct drm_device *dev = (struct drm_device *)data; 1799f65d9421SBen Gamari drm_i915_private_t *dev_priv = dev->dev_private; 1800097354ebSDaniel Vetter uint32_t acthd, instdone, instdone1, acthd_bsd, acthd_blt; 1801893eead0SChris Wilson bool err = false; 1802893eead0SChris Wilson 18033e0dc6b0SBen Widawsky if (!i915_enable_hangcheck) 18043e0dc6b0SBen Widawsky return; 18053e0dc6b0SBen Widawsky 1806893eead0SChris Wilson /* If all work is done then ACTHD clearly hasn't advanced. */ 18071ec14ad3SChris Wilson if (i915_hangcheck_ring_idle(&dev_priv->ring[RCS], &err) && 18081ec14ad3SChris Wilson i915_hangcheck_ring_idle(&dev_priv->ring[VCS], &err) && 18091ec14ad3SChris Wilson i915_hangcheck_ring_idle(&dev_priv->ring[BCS], &err)) { 1810d1e61e7fSChris Wilson if (err) { 1811d1e61e7fSChris Wilson if (i915_hangcheck_hung(dev)) 1812d1e61e7fSChris Wilson return; 1813d1e61e7fSChris Wilson 1814893eead0SChris Wilson goto repeat; 1815d1e61e7fSChris Wilson } 1816d1e61e7fSChris Wilson 1817d1e61e7fSChris Wilson dev_priv->hangcheck_count = 0; 1818893eead0SChris Wilson return; 1819893eead0SChris Wilson } 1820f65d9421SBen Gamari 1821a6c45cf0SChris Wilson if (INTEL_INFO(dev)->gen < 4) { 1822cbb465e7SChris Wilson instdone = I915_READ(INSTDONE); 1823cbb465e7SChris Wilson instdone1 = 0; 1824cbb465e7SChris Wilson } else { 1825cbb465e7SChris Wilson instdone = I915_READ(INSTDONE_I965); 1826cbb465e7SChris Wilson instdone1 = I915_READ(INSTDONE1); 1827cbb465e7SChris Wilson } 1828097354ebSDaniel Vetter acthd = intel_ring_get_active_head(&dev_priv->ring[RCS]); 1829097354ebSDaniel Vetter acthd_bsd = HAS_BSD(dev) ? 1830097354ebSDaniel Vetter intel_ring_get_active_head(&dev_priv->ring[VCS]) : 0; 1831097354ebSDaniel Vetter acthd_blt = HAS_BLT(dev) ? 1832097354ebSDaniel Vetter intel_ring_get_active_head(&dev_priv->ring[BCS]) : 0; 1833f65d9421SBen Gamari 1834cbb465e7SChris Wilson if (dev_priv->last_acthd == acthd && 1835097354ebSDaniel Vetter dev_priv->last_acthd_bsd == acthd_bsd && 1836097354ebSDaniel Vetter dev_priv->last_acthd_blt == acthd_blt && 1837cbb465e7SChris Wilson dev_priv->last_instdone == instdone && 1838cbb465e7SChris Wilson dev_priv->last_instdone1 == instdone1) { 1839d1e61e7fSChris Wilson if (i915_hangcheck_hung(dev)) 1840f65d9421SBen Gamari return; 1841cbb465e7SChris Wilson } else { 1842cbb465e7SChris Wilson dev_priv->hangcheck_count = 0; 1843cbb465e7SChris Wilson 1844cbb465e7SChris Wilson dev_priv->last_acthd = acthd; 1845097354ebSDaniel Vetter dev_priv->last_acthd_bsd = acthd_bsd; 1846097354ebSDaniel Vetter dev_priv->last_acthd_blt = acthd_blt; 1847cbb465e7SChris Wilson dev_priv->last_instdone = instdone; 1848cbb465e7SChris Wilson dev_priv->last_instdone1 = instdone1; 1849cbb465e7SChris Wilson } 1850f65d9421SBen Gamari 1851893eead0SChris Wilson repeat: 1852f65d9421SBen Gamari /* Reset timer case chip hangs without another request being added */ 1853b3b079dbSChris Wilson mod_timer(&dev_priv->hangcheck_timer, 1854b3b079dbSChris Wilson jiffies + msecs_to_jiffies(DRM_I915_HANGCHECK_PERIOD)); 1855f65d9421SBen Gamari } 1856f65d9421SBen Gamari 1857c0e09200SDave Airlie /* drm_dma.h hooks 1858c0e09200SDave Airlie */ 1859f71d4af4SJesse Barnes static void ironlake_irq_preinstall(struct drm_device *dev) 1860036a4a7dSZhenyu Wang { 1861036a4a7dSZhenyu Wang drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 1862036a4a7dSZhenyu Wang 18634697995bSJesse Barnes atomic_set(&dev_priv->irq_received, 0); 18644697995bSJesse Barnes 18654697995bSJesse Barnes 1866036a4a7dSZhenyu Wang I915_WRITE(HWSTAM, 0xeffe); 1867bdfcdb63SDaniel Vetter 1868036a4a7dSZhenyu Wang /* XXX hotplug from PCH */ 1869036a4a7dSZhenyu Wang 1870036a4a7dSZhenyu Wang I915_WRITE(DEIMR, 0xffffffff); 1871036a4a7dSZhenyu Wang I915_WRITE(DEIER, 0x0); 18723143a2bfSChris Wilson POSTING_READ(DEIER); 1873036a4a7dSZhenyu Wang 1874036a4a7dSZhenyu Wang /* and GT */ 1875036a4a7dSZhenyu Wang I915_WRITE(GTIMR, 0xffffffff); 1876036a4a7dSZhenyu Wang I915_WRITE(GTIER, 0x0); 18773143a2bfSChris Wilson POSTING_READ(GTIER); 1878c650156aSZhenyu Wang 1879c650156aSZhenyu Wang /* south display irq */ 1880c650156aSZhenyu Wang I915_WRITE(SDEIMR, 0xffffffff); 1881c650156aSZhenyu Wang I915_WRITE(SDEIER, 0x0); 18823143a2bfSChris Wilson POSTING_READ(SDEIER); 1883036a4a7dSZhenyu Wang } 1884036a4a7dSZhenyu Wang 18857e231dbeSJesse Barnes static void valleyview_irq_preinstall(struct drm_device *dev) 18867e231dbeSJesse Barnes { 18877e231dbeSJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 18887e231dbeSJesse Barnes int pipe; 18897e231dbeSJesse Barnes 18907e231dbeSJesse Barnes atomic_set(&dev_priv->irq_received, 0); 18917e231dbeSJesse Barnes 18927e231dbeSJesse Barnes /* VLV magic */ 18937e231dbeSJesse Barnes I915_WRITE(VLV_IMR, 0); 18947e231dbeSJesse Barnes I915_WRITE(RING_IMR(RENDER_RING_BASE), 0); 18957e231dbeSJesse Barnes I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0); 18967e231dbeSJesse Barnes I915_WRITE(RING_IMR(BLT_RING_BASE), 0); 18977e231dbeSJesse Barnes 18987e231dbeSJesse Barnes /* and GT */ 18997e231dbeSJesse Barnes I915_WRITE(GTIIR, I915_READ(GTIIR)); 19007e231dbeSJesse Barnes I915_WRITE(GTIIR, I915_READ(GTIIR)); 19017e231dbeSJesse Barnes I915_WRITE(GTIMR, 0xffffffff); 19027e231dbeSJesse Barnes I915_WRITE(GTIER, 0x0); 19037e231dbeSJesse Barnes POSTING_READ(GTIER); 19047e231dbeSJesse Barnes 19057e231dbeSJesse Barnes I915_WRITE(DPINVGTT, 0xff); 19067e231dbeSJesse Barnes 19077e231dbeSJesse Barnes I915_WRITE(PORT_HOTPLUG_EN, 0); 19087e231dbeSJesse Barnes I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 19097e231dbeSJesse Barnes for_each_pipe(pipe) 19107e231dbeSJesse Barnes I915_WRITE(PIPESTAT(pipe), 0xffff); 19117e231dbeSJesse Barnes I915_WRITE(VLV_IIR, 0xffffffff); 19127e231dbeSJesse Barnes I915_WRITE(VLV_IMR, 0xffffffff); 19137e231dbeSJesse Barnes I915_WRITE(VLV_IER, 0x0); 19147e231dbeSJesse Barnes POSTING_READ(VLV_IER); 19157e231dbeSJesse Barnes } 19167e231dbeSJesse Barnes 19177fe0b973SKeith Packard /* 19187fe0b973SKeith Packard * Enable digital hotplug on the PCH, and configure the DP short pulse 19197fe0b973SKeith Packard * duration to 2ms (which is the minimum in the Display Port spec) 19207fe0b973SKeith Packard * 19217fe0b973SKeith Packard * This register is the same on all known PCH chips. 19227fe0b973SKeith Packard */ 19237fe0b973SKeith Packard 19247fe0b973SKeith Packard static void ironlake_enable_pch_hotplug(struct drm_device *dev) 19257fe0b973SKeith Packard { 19267fe0b973SKeith Packard drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 19277fe0b973SKeith Packard u32 hotplug; 19287fe0b973SKeith Packard 19297fe0b973SKeith Packard hotplug = I915_READ(PCH_PORT_HOTPLUG); 19307fe0b973SKeith Packard hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK); 19317fe0b973SKeith Packard hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms; 19327fe0b973SKeith Packard hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms; 19337fe0b973SKeith Packard hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms; 19347fe0b973SKeith Packard I915_WRITE(PCH_PORT_HOTPLUG, hotplug); 19357fe0b973SKeith Packard } 19367fe0b973SKeith Packard 1937f71d4af4SJesse Barnes static int ironlake_irq_postinstall(struct drm_device *dev) 1938036a4a7dSZhenyu Wang { 1939036a4a7dSZhenyu Wang drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 1940036a4a7dSZhenyu Wang /* enable kind of interrupts always enabled */ 1941013d5aa2SJesse Barnes u32 display_mask = DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT | 1942013d5aa2SJesse Barnes DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE; 19431ec14ad3SChris Wilson u32 render_irqs; 19442d7b8366SYuanhan Liu u32 hotplug_mask; 1945036a4a7dSZhenyu Wang 19464697995bSJesse Barnes dev_priv->vblank_pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B; 19471ec14ad3SChris Wilson dev_priv->irq_mask = ~display_mask; 1948036a4a7dSZhenyu Wang 1949036a4a7dSZhenyu Wang /* should always can generate irq */ 1950036a4a7dSZhenyu Wang I915_WRITE(DEIIR, I915_READ(DEIIR)); 19511ec14ad3SChris Wilson I915_WRITE(DEIMR, dev_priv->irq_mask); 19521ec14ad3SChris Wilson I915_WRITE(DEIER, display_mask | DE_PIPEA_VBLANK | DE_PIPEB_VBLANK); 19533143a2bfSChris Wilson POSTING_READ(DEIER); 1954036a4a7dSZhenyu Wang 19551ec14ad3SChris Wilson dev_priv->gt_irq_mask = ~0; 1956036a4a7dSZhenyu Wang 1957036a4a7dSZhenyu Wang I915_WRITE(GTIIR, I915_READ(GTIIR)); 19581ec14ad3SChris Wilson I915_WRITE(GTIMR, dev_priv->gt_irq_mask); 1959881f47b6SXiang, Haihao 19601ec14ad3SChris Wilson if (IS_GEN6(dev)) 19611ec14ad3SChris Wilson render_irqs = 19621ec14ad3SChris Wilson GT_USER_INTERRUPT | 1963e2a1e2f0SBen Widawsky GEN6_BSD_USER_INTERRUPT | 1964e2a1e2f0SBen Widawsky GEN6_BLITTER_USER_INTERRUPT; 19651ec14ad3SChris Wilson else 19661ec14ad3SChris Wilson render_irqs = 196788f23b8fSChris Wilson GT_USER_INTERRUPT | 1968c6df541cSChris Wilson GT_PIPE_NOTIFY | 19691ec14ad3SChris Wilson GT_BSD_USER_INTERRUPT; 19701ec14ad3SChris Wilson I915_WRITE(GTIER, render_irqs); 19713143a2bfSChris Wilson POSTING_READ(GTIER); 1972036a4a7dSZhenyu Wang 19732d7b8366SYuanhan Liu if (HAS_PCH_CPT(dev)) { 19749035a97aSChris Wilson hotplug_mask = (SDE_CRT_HOTPLUG_CPT | 19759035a97aSChris Wilson SDE_PORTB_HOTPLUG_CPT | 19769035a97aSChris Wilson SDE_PORTC_HOTPLUG_CPT | 19779035a97aSChris Wilson SDE_PORTD_HOTPLUG_CPT); 19782d7b8366SYuanhan Liu } else { 19799035a97aSChris Wilson hotplug_mask = (SDE_CRT_HOTPLUG | 19809035a97aSChris Wilson SDE_PORTB_HOTPLUG | 19819035a97aSChris Wilson SDE_PORTC_HOTPLUG | 19829035a97aSChris Wilson SDE_PORTD_HOTPLUG | 19839035a97aSChris Wilson SDE_AUX_MASK); 19842d7b8366SYuanhan Liu } 19852d7b8366SYuanhan Liu 19861ec14ad3SChris Wilson dev_priv->pch_irq_mask = ~hotplug_mask; 1987c650156aSZhenyu Wang 1988c650156aSZhenyu Wang I915_WRITE(SDEIIR, I915_READ(SDEIIR)); 19891ec14ad3SChris Wilson I915_WRITE(SDEIMR, dev_priv->pch_irq_mask); 19901ec14ad3SChris Wilson I915_WRITE(SDEIER, hotplug_mask); 19913143a2bfSChris Wilson POSTING_READ(SDEIER); 1992c650156aSZhenyu Wang 19937fe0b973SKeith Packard ironlake_enable_pch_hotplug(dev); 19947fe0b973SKeith Packard 1995f97108d1SJesse Barnes if (IS_IRONLAKE_M(dev)) { 1996f97108d1SJesse Barnes /* Clear & enable PCU event interrupts */ 1997f97108d1SJesse Barnes I915_WRITE(DEIIR, DE_PCU_EVENT); 1998f97108d1SJesse Barnes I915_WRITE(DEIER, I915_READ(DEIER) | DE_PCU_EVENT); 1999f97108d1SJesse Barnes ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT); 2000f97108d1SJesse Barnes } 2001f97108d1SJesse Barnes 2002036a4a7dSZhenyu Wang return 0; 2003036a4a7dSZhenyu Wang } 2004036a4a7dSZhenyu Wang 2005f71d4af4SJesse Barnes static int ivybridge_irq_postinstall(struct drm_device *dev) 2006b1f14ad0SJesse Barnes { 2007b1f14ad0SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2008b1f14ad0SJesse Barnes /* enable kind of interrupts always enabled */ 2009b1f14ad0SJesse Barnes u32 display_mask = DE_MASTER_IRQ_CONTROL | DE_GSE_IVB | 2010b1f14ad0SJesse Barnes DE_PCH_EVENT_IVB | DE_PLANEA_FLIP_DONE_IVB | 2011b1f14ad0SJesse Barnes DE_PLANEB_FLIP_DONE_IVB; 2012b1f14ad0SJesse Barnes u32 render_irqs; 2013b1f14ad0SJesse Barnes u32 hotplug_mask; 2014b1f14ad0SJesse Barnes 2015b1f14ad0SJesse Barnes dev_priv->vblank_pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B; 2016b1f14ad0SJesse Barnes dev_priv->irq_mask = ~display_mask; 2017b1f14ad0SJesse Barnes 2018b1f14ad0SJesse Barnes /* should always can generate irq */ 2019b1f14ad0SJesse Barnes I915_WRITE(DEIIR, I915_READ(DEIIR)); 2020b1f14ad0SJesse Barnes I915_WRITE(DEIMR, dev_priv->irq_mask); 2021b1f14ad0SJesse Barnes I915_WRITE(DEIER, display_mask | DE_PIPEA_VBLANK_IVB | 2022b1f14ad0SJesse Barnes DE_PIPEB_VBLANK_IVB); 2023b1f14ad0SJesse Barnes POSTING_READ(DEIER); 2024b1f14ad0SJesse Barnes 2025b1f14ad0SJesse Barnes dev_priv->gt_irq_mask = ~0; 2026b1f14ad0SJesse Barnes 2027b1f14ad0SJesse Barnes I915_WRITE(GTIIR, I915_READ(GTIIR)); 2028b1f14ad0SJesse Barnes I915_WRITE(GTIMR, dev_priv->gt_irq_mask); 2029b1f14ad0SJesse Barnes 2030e2a1e2f0SBen Widawsky render_irqs = GT_USER_INTERRUPT | GEN6_BSD_USER_INTERRUPT | 2031e2a1e2f0SBen Widawsky GEN6_BLITTER_USER_INTERRUPT; 2032b1f14ad0SJesse Barnes I915_WRITE(GTIER, render_irqs); 2033b1f14ad0SJesse Barnes POSTING_READ(GTIER); 2034b1f14ad0SJesse Barnes 2035b1f14ad0SJesse Barnes hotplug_mask = (SDE_CRT_HOTPLUG_CPT | 2036b1f14ad0SJesse Barnes SDE_PORTB_HOTPLUG_CPT | 2037b1f14ad0SJesse Barnes SDE_PORTC_HOTPLUG_CPT | 2038b1f14ad0SJesse Barnes SDE_PORTD_HOTPLUG_CPT); 2039b1f14ad0SJesse Barnes dev_priv->pch_irq_mask = ~hotplug_mask; 2040b1f14ad0SJesse Barnes 2041b1f14ad0SJesse Barnes I915_WRITE(SDEIIR, I915_READ(SDEIIR)); 2042b1f14ad0SJesse Barnes I915_WRITE(SDEIMR, dev_priv->pch_irq_mask); 2043b1f14ad0SJesse Barnes I915_WRITE(SDEIER, hotplug_mask); 2044b1f14ad0SJesse Barnes POSTING_READ(SDEIER); 2045b1f14ad0SJesse Barnes 20467fe0b973SKeith Packard ironlake_enable_pch_hotplug(dev); 20477fe0b973SKeith Packard 2048b1f14ad0SJesse Barnes return 0; 2049b1f14ad0SJesse Barnes } 2050b1f14ad0SJesse Barnes 20517e231dbeSJesse Barnes static int valleyview_irq_postinstall(struct drm_device *dev) 20527e231dbeSJesse Barnes { 20537e231dbeSJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 20547e231dbeSJesse Barnes u32 render_irqs; 20557e231dbeSJesse Barnes u32 enable_mask; 20567e231dbeSJesse Barnes u32 hotplug_en = I915_READ(PORT_HOTPLUG_EN); 20577e231dbeSJesse Barnes u16 msid; 20587e231dbeSJesse Barnes 20597e231dbeSJesse Barnes enable_mask = I915_DISPLAY_PORT_INTERRUPT; 20607e231dbeSJesse Barnes enable_mask |= I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT | 20617e231dbeSJesse Barnes I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT; 20627e231dbeSJesse Barnes 20637e231dbeSJesse Barnes dev_priv->irq_mask = ~enable_mask; 20647e231dbeSJesse Barnes 20657e231dbeSJesse Barnes dev_priv->pipestat[0] = 0; 20667e231dbeSJesse Barnes dev_priv->pipestat[1] = 0; 20677e231dbeSJesse Barnes 20687e231dbeSJesse Barnes dev_priv->vblank_pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B; 20697e231dbeSJesse Barnes 20707e231dbeSJesse Barnes /* Hack for broken MSIs on VLV */ 20717e231dbeSJesse Barnes pci_write_config_dword(dev_priv->dev->pdev, 0x94, 0xfee00000); 20727e231dbeSJesse Barnes pci_read_config_word(dev->pdev, 0x98, &msid); 20737e231dbeSJesse Barnes msid &= 0xff; /* mask out delivery bits */ 20747e231dbeSJesse Barnes msid |= (1<<14); 20757e231dbeSJesse Barnes pci_write_config_word(dev_priv->dev->pdev, 0x98, msid); 20767e231dbeSJesse Barnes 20777e231dbeSJesse Barnes I915_WRITE(VLV_IMR, dev_priv->irq_mask); 20787e231dbeSJesse Barnes I915_WRITE(VLV_IER, enable_mask); 20797e231dbeSJesse Barnes I915_WRITE(VLV_IIR, 0xffffffff); 20807e231dbeSJesse Barnes I915_WRITE(PIPESTAT(0), 0xffff); 20817e231dbeSJesse Barnes I915_WRITE(PIPESTAT(1), 0xffff); 20827e231dbeSJesse Barnes POSTING_READ(VLV_IER); 20837e231dbeSJesse Barnes 20847e231dbeSJesse Barnes I915_WRITE(VLV_IIR, 0xffffffff); 20857e231dbeSJesse Barnes I915_WRITE(VLV_IIR, 0xffffffff); 20867e231dbeSJesse Barnes 20877e231dbeSJesse Barnes render_irqs = GT_GEN6_BLT_FLUSHDW_NOTIFY_INTERRUPT | 20887e231dbeSJesse Barnes GT_GEN6_BLT_CS_ERROR_INTERRUPT | 2089e2a1e2f0SBen Widawsky GT_GEN6_BLT_USER_INTERRUPT | 20907e231dbeSJesse Barnes GT_GEN6_BSD_USER_INTERRUPT | 20917e231dbeSJesse Barnes GT_GEN6_BSD_CS_ERROR_INTERRUPT | 20927e231dbeSJesse Barnes GT_GEN7_L3_PARITY_ERROR_INTERRUPT | 20937e231dbeSJesse Barnes GT_PIPE_NOTIFY | 20947e231dbeSJesse Barnes GT_RENDER_CS_ERROR_INTERRUPT | 20957e231dbeSJesse Barnes GT_SYNC_STATUS | 20967e231dbeSJesse Barnes GT_USER_INTERRUPT; 20977e231dbeSJesse Barnes 20987e231dbeSJesse Barnes dev_priv->gt_irq_mask = ~render_irqs; 20997e231dbeSJesse Barnes 21007e231dbeSJesse Barnes I915_WRITE(GTIIR, I915_READ(GTIIR)); 21017e231dbeSJesse Barnes I915_WRITE(GTIIR, I915_READ(GTIIR)); 21027e231dbeSJesse Barnes I915_WRITE(GTIMR, 0); 21037e231dbeSJesse Barnes I915_WRITE(GTIER, render_irqs); 21047e231dbeSJesse Barnes POSTING_READ(GTIER); 21057e231dbeSJesse Barnes 21067e231dbeSJesse Barnes /* ack & enable invalid PTE error interrupts */ 21077e231dbeSJesse Barnes #if 0 /* FIXME: add support to irq handler for checking these bits */ 21087e231dbeSJesse Barnes I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK); 21097e231dbeSJesse Barnes I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK); 21107e231dbeSJesse Barnes #endif 21117e231dbeSJesse Barnes 21127e231dbeSJesse Barnes I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE); 21137e231dbeSJesse Barnes #if 0 /* FIXME: check register definitions; some have moved */ 21147e231dbeSJesse Barnes /* Note HDMI and DP share bits */ 21157e231dbeSJesse Barnes if (dev_priv->hotplug_supported_mask & HDMIB_HOTPLUG_INT_STATUS) 21167e231dbeSJesse Barnes hotplug_en |= HDMIB_HOTPLUG_INT_EN; 21177e231dbeSJesse Barnes if (dev_priv->hotplug_supported_mask & HDMIC_HOTPLUG_INT_STATUS) 21187e231dbeSJesse Barnes hotplug_en |= HDMIC_HOTPLUG_INT_EN; 21197e231dbeSJesse Barnes if (dev_priv->hotplug_supported_mask & HDMID_HOTPLUG_INT_STATUS) 21207e231dbeSJesse Barnes hotplug_en |= HDMID_HOTPLUG_INT_EN; 21217e231dbeSJesse Barnes if (dev_priv->hotplug_supported_mask & SDVOC_HOTPLUG_INT_STATUS) 21227e231dbeSJesse Barnes hotplug_en |= SDVOC_HOTPLUG_INT_EN; 21237e231dbeSJesse Barnes if (dev_priv->hotplug_supported_mask & SDVOB_HOTPLUG_INT_STATUS) 21247e231dbeSJesse Barnes hotplug_en |= SDVOB_HOTPLUG_INT_EN; 21257e231dbeSJesse Barnes if (dev_priv->hotplug_supported_mask & CRT_HOTPLUG_INT_STATUS) { 21267e231dbeSJesse Barnes hotplug_en |= CRT_HOTPLUG_INT_EN; 21277e231dbeSJesse Barnes hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50; 21287e231dbeSJesse Barnes } 21297e231dbeSJesse Barnes #endif 21307e231dbeSJesse Barnes 21317e231dbeSJesse Barnes I915_WRITE(PORT_HOTPLUG_EN, hotplug_en); 21327e231dbeSJesse Barnes 21337e231dbeSJesse Barnes return 0; 21347e231dbeSJesse Barnes } 21357e231dbeSJesse Barnes 21367e231dbeSJesse Barnes static void valleyview_irq_uninstall(struct drm_device *dev) 21377e231dbeSJesse Barnes { 21387e231dbeSJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 21397e231dbeSJesse Barnes int pipe; 21407e231dbeSJesse Barnes 21417e231dbeSJesse Barnes if (!dev_priv) 21427e231dbeSJesse Barnes return; 21437e231dbeSJesse Barnes 21447e231dbeSJesse Barnes dev_priv->vblank_pipe = 0; 21457e231dbeSJesse Barnes 21467e231dbeSJesse Barnes for_each_pipe(pipe) 21477e231dbeSJesse Barnes I915_WRITE(PIPESTAT(pipe), 0xffff); 21487e231dbeSJesse Barnes 21497e231dbeSJesse Barnes I915_WRITE(HWSTAM, 0xffffffff); 21507e231dbeSJesse Barnes I915_WRITE(PORT_HOTPLUG_EN, 0); 21517e231dbeSJesse Barnes I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 21527e231dbeSJesse Barnes for_each_pipe(pipe) 21537e231dbeSJesse Barnes I915_WRITE(PIPESTAT(pipe), 0xffff); 21547e231dbeSJesse Barnes I915_WRITE(VLV_IIR, 0xffffffff); 21557e231dbeSJesse Barnes I915_WRITE(VLV_IMR, 0xffffffff); 21567e231dbeSJesse Barnes I915_WRITE(VLV_IER, 0x0); 21577e231dbeSJesse Barnes POSTING_READ(VLV_IER); 21587e231dbeSJesse Barnes } 21597e231dbeSJesse Barnes 2160f71d4af4SJesse Barnes static void ironlake_irq_uninstall(struct drm_device *dev) 2161036a4a7dSZhenyu Wang { 2162036a4a7dSZhenyu Wang drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 21634697995bSJesse Barnes 21644697995bSJesse Barnes if (!dev_priv) 21654697995bSJesse Barnes return; 21664697995bSJesse Barnes 21674697995bSJesse Barnes dev_priv->vblank_pipe = 0; 21684697995bSJesse Barnes 2169036a4a7dSZhenyu Wang I915_WRITE(HWSTAM, 0xffffffff); 2170036a4a7dSZhenyu Wang 2171036a4a7dSZhenyu Wang I915_WRITE(DEIMR, 0xffffffff); 2172036a4a7dSZhenyu Wang I915_WRITE(DEIER, 0x0); 2173036a4a7dSZhenyu Wang I915_WRITE(DEIIR, I915_READ(DEIIR)); 2174036a4a7dSZhenyu Wang 2175036a4a7dSZhenyu Wang I915_WRITE(GTIMR, 0xffffffff); 2176036a4a7dSZhenyu Wang I915_WRITE(GTIER, 0x0); 2177036a4a7dSZhenyu Wang I915_WRITE(GTIIR, I915_READ(GTIIR)); 2178192aac1fSKeith Packard 2179192aac1fSKeith Packard I915_WRITE(SDEIMR, 0xffffffff); 2180192aac1fSKeith Packard I915_WRITE(SDEIER, 0x0); 2181192aac1fSKeith Packard I915_WRITE(SDEIIR, I915_READ(SDEIIR)); 2182036a4a7dSZhenyu Wang } 2183036a4a7dSZhenyu Wang 2184c2798b19SChris Wilson static void i8xx_irq_preinstall(struct drm_device * dev) 2185c2798b19SChris Wilson { 2186c2798b19SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2187c2798b19SChris Wilson int pipe; 2188c2798b19SChris Wilson 2189c2798b19SChris Wilson atomic_set(&dev_priv->irq_received, 0); 2190c2798b19SChris Wilson 2191c2798b19SChris Wilson for_each_pipe(pipe) 2192c2798b19SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 2193c2798b19SChris Wilson I915_WRITE16(IMR, 0xffff); 2194c2798b19SChris Wilson I915_WRITE16(IER, 0x0); 2195c2798b19SChris Wilson POSTING_READ16(IER); 2196c2798b19SChris Wilson } 2197c2798b19SChris Wilson 2198c2798b19SChris Wilson static int i8xx_irq_postinstall(struct drm_device *dev) 2199c2798b19SChris Wilson { 2200c2798b19SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2201c2798b19SChris Wilson 2202c2798b19SChris Wilson dev_priv->vblank_pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B; 2203c2798b19SChris Wilson 2204c2798b19SChris Wilson dev_priv->pipestat[0] = 0; 2205c2798b19SChris Wilson dev_priv->pipestat[1] = 0; 2206c2798b19SChris Wilson 2207c2798b19SChris Wilson I915_WRITE16(EMR, 2208c2798b19SChris Wilson ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH)); 2209c2798b19SChris Wilson 2210c2798b19SChris Wilson /* Unmask the interrupts that we always want on. */ 2211c2798b19SChris Wilson dev_priv->irq_mask = 2212c2798b19SChris Wilson ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 2213c2798b19SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 2214c2798b19SChris Wilson I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 2215c2798b19SChris Wilson I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT | 2216c2798b19SChris Wilson I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); 2217c2798b19SChris Wilson I915_WRITE16(IMR, dev_priv->irq_mask); 2218c2798b19SChris Wilson 2219c2798b19SChris Wilson I915_WRITE16(IER, 2220c2798b19SChris Wilson I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 2221c2798b19SChris Wilson I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 2222c2798b19SChris Wilson I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT | 2223c2798b19SChris Wilson I915_USER_INTERRUPT); 2224c2798b19SChris Wilson POSTING_READ16(IER); 2225c2798b19SChris Wilson 2226c2798b19SChris Wilson return 0; 2227c2798b19SChris Wilson } 2228c2798b19SChris Wilson 2229c2798b19SChris Wilson static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS) 2230c2798b19SChris Wilson { 2231c2798b19SChris Wilson struct drm_device *dev = (struct drm_device *) arg; 2232c2798b19SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2233c2798b19SChris Wilson struct drm_i915_master_private *master_priv; 2234c2798b19SChris Wilson u16 iir, new_iir; 2235c2798b19SChris Wilson u32 pipe_stats[2]; 2236c2798b19SChris Wilson unsigned long irqflags; 2237c2798b19SChris Wilson int irq_received; 2238c2798b19SChris Wilson int pipe; 2239c2798b19SChris Wilson u16 flip_mask = 2240c2798b19SChris Wilson I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | 2241c2798b19SChris Wilson I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT; 2242c2798b19SChris Wilson 2243c2798b19SChris Wilson atomic_inc(&dev_priv->irq_received); 2244c2798b19SChris Wilson 2245c2798b19SChris Wilson iir = I915_READ16(IIR); 2246c2798b19SChris Wilson if (iir == 0) 2247c2798b19SChris Wilson return IRQ_NONE; 2248c2798b19SChris Wilson 2249c2798b19SChris Wilson while (iir & ~flip_mask) { 2250c2798b19SChris Wilson /* Can't rely on pipestat interrupt bit in iir as it might 2251c2798b19SChris Wilson * have been cleared after the pipestat interrupt was received. 2252c2798b19SChris Wilson * It doesn't set the bit in iir again, but it still produces 2253c2798b19SChris Wilson * interrupts (for non-MSI). 2254c2798b19SChris Wilson */ 2255c2798b19SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2256c2798b19SChris Wilson if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) 2257c2798b19SChris Wilson i915_handle_error(dev, false); 2258c2798b19SChris Wilson 2259c2798b19SChris Wilson for_each_pipe(pipe) { 2260c2798b19SChris Wilson int reg = PIPESTAT(pipe); 2261c2798b19SChris Wilson pipe_stats[pipe] = I915_READ(reg); 2262c2798b19SChris Wilson 2263c2798b19SChris Wilson /* 2264c2798b19SChris Wilson * Clear the PIPE*STAT regs before the IIR 2265c2798b19SChris Wilson */ 2266c2798b19SChris Wilson if (pipe_stats[pipe] & 0x8000ffff) { 2267c2798b19SChris Wilson if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) 2268c2798b19SChris Wilson DRM_DEBUG_DRIVER("pipe %c underrun\n", 2269c2798b19SChris Wilson pipe_name(pipe)); 2270c2798b19SChris Wilson I915_WRITE(reg, pipe_stats[pipe]); 2271c2798b19SChris Wilson irq_received = 1; 2272c2798b19SChris Wilson } 2273c2798b19SChris Wilson } 2274c2798b19SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2275c2798b19SChris Wilson 2276c2798b19SChris Wilson I915_WRITE16(IIR, iir & ~flip_mask); 2277c2798b19SChris Wilson new_iir = I915_READ16(IIR); /* Flush posted writes */ 2278c2798b19SChris Wilson 2279c2798b19SChris Wilson if (dev->primary->master) { 2280c2798b19SChris Wilson master_priv = dev->primary->master->driver_priv; 2281c2798b19SChris Wilson if (master_priv->sarea_priv) 2282c2798b19SChris Wilson master_priv->sarea_priv->last_dispatch = 2283c2798b19SChris Wilson READ_BREADCRUMB(dev_priv); 2284c2798b19SChris Wilson } 2285c2798b19SChris Wilson 2286c2798b19SChris Wilson if (iir & I915_USER_INTERRUPT) 2287c2798b19SChris Wilson notify_ring(dev, &dev_priv->ring[RCS]); 2288c2798b19SChris Wilson 2289c2798b19SChris Wilson if (pipe_stats[0] & PIPE_VBLANK_INTERRUPT_STATUS && 2290c2798b19SChris Wilson drm_handle_vblank(dev, 0)) { 2291c2798b19SChris Wilson if (iir & I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT) { 2292c2798b19SChris Wilson intel_prepare_page_flip(dev, 0); 2293c2798b19SChris Wilson intel_finish_page_flip(dev, 0); 2294c2798b19SChris Wilson flip_mask &= ~I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT; 2295c2798b19SChris Wilson } 2296c2798b19SChris Wilson } 2297c2798b19SChris Wilson 2298c2798b19SChris Wilson if (pipe_stats[1] & PIPE_VBLANK_INTERRUPT_STATUS && 2299c2798b19SChris Wilson drm_handle_vblank(dev, 1)) { 2300c2798b19SChris Wilson if (iir & I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT) { 2301c2798b19SChris Wilson intel_prepare_page_flip(dev, 1); 2302c2798b19SChris Wilson intel_finish_page_flip(dev, 1); 2303c2798b19SChris Wilson flip_mask &= ~I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT; 2304c2798b19SChris Wilson } 2305c2798b19SChris Wilson } 2306c2798b19SChris Wilson 2307c2798b19SChris Wilson iir = new_iir; 2308c2798b19SChris Wilson } 2309c2798b19SChris Wilson 2310c2798b19SChris Wilson return IRQ_HANDLED; 2311c2798b19SChris Wilson } 2312c2798b19SChris Wilson 2313c2798b19SChris Wilson static void i8xx_irq_uninstall(struct drm_device * dev) 2314c2798b19SChris Wilson { 2315c2798b19SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2316c2798b19SChris Wilson int pipe; 2317c2798b19SChris Wilson 2318c2798b19SChris Wilson dev_priv->vblank_pipe = 0; 2319c2798b19SChris Wilson 2320c2798b19SChris Wilson for_each_pipe(pipe) { 2321c2798b19SChris Wilson /* Clear enable bits; then clear status bits */ 2322c2798b19SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 2323c2798b19SChris Wilson I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe))); 2324c2798b19SChris Wilson } 2325c2798b19SChris Wilson I915_WRITE16(IMR, 0xffff); 2326c2798b19SChris Wilson I915_WRITE16(IER, 0x0); 2327c2798b19SChris Wilson I915_WRITE16(IIR, I915_READ16(IIR)); 2328c2798b19SChris Wilson } 2329c2798b19SChris Wilson 2330a266c7d5SChris Wilson static void i915_irq_preinstall(struct drm_device * dev) 2331a266c7d5SChris Wilson { 2332a266c7d5SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2333a266c7d5SChris Wilson int pipe; 2334a266c7d5SChris Wilson 2335a266c7d5SChris Wilson atomic_set(&dev_priv->irq_received, 0); 2336a266c7d5SChris Wilson 2337a266c7d5SChris Wilson if (I915_HAS_HOTPLUG(dev)) { 2338a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_EN, 0); 2339a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 2340a266c7d5SChris Wilson } 2341a266c7d5SChris Wilson 2342a266c7d5SChris Wilson I915_WRITE(HWSTAM, 0xeffe); 2343a266c7d5SChris Wilson for_each_pipe(pipe) 2344a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 2345a266c7d5SChris Wilson I915_WRITE(IMR, 0xffffffff); 2346a266c7d5SChris Wilson I915_WRITE(IER, 0x0); 2347a266c7d5SChris Wilson POSTING_READ(IER); 2348a266c7d5SChris Wilson } 2349a266c7d5SChris Wilson 2350a266c7d5SChris Wilson static int i915_irq_postinstall(struct drm_device *dev) 2351a266c7d5SChris Wilson { 2352a266c7d5SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2353a266c7d5SChris Wilson u32 enable_mask = I915_INTERRUPT_ENABLE_FIX | I915_INTERRUPT_ENABLE_VAR; 2354a266c7d5SChris Wilson u32 error_mask; 2355a266c7d5SChris Wilson 2356a266c7d5SChris Wilson dev_priv->vblank_pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B; 2357a266c7d5SChris Wilson 2358a266c7d5SChris Wilson /* Unmask the interrupts that we always want on. */ 2359a266c7d5SChris Wilson dev_priv->irq_mask = ~I915_INTERRUPT_ENABLE_FIX; 2360a266c7d5SChris Wilson 2361a266c7d5SChris Wilson dev_priv->pipestat[0] = 0; 2362a266c7d5SChris Wilson dev_priv->pipestat[1] = 0; 2363a266c7d5SChris Wilson 2364a266c7d5SChris Wilson if (I915_HAS_HOTPLUG(dev)) { 2365a266c7d5SChris Wilson /* Enable in IER... */ 2366a266c7d5SChris Wilson enable_mask |= I915_DISPLAY_PORT_INTERRUPT; 2367a266c7d5SChris Wilson /* and unmask in IMR */ 2368a266c7d5SChris Wilson dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT; 2369a266c7d5SChris Wilson } 2370a266c7d5SChris Wilson 2371a266c7d5SChris Wilson /* 2372a266c7d5SChris Wilson * Enable some error detection, note the instruction error mask 2373a266c7d5SChris Wilson * bit is reserved, so we leave it masked. 2374a266c7d5SChris Wilson */ 2375a266c7d5SChris Wilson if (IS_G4X(dev)) { 2376a266c7d5SChris Wilson error_mask = ~(GM45_ERROR_PAGE_TABLE | 2377a266c7d5SChris Wilson GM45_ERROR_MEM_PRIV | 2378a266c7d5SChris Wilson GM45_ERROR_CP_PRIV | 2379a266c7d5SChris Wilson I915_ERROR_MEMORY_REFRESH); 2380a266c7d5SChris Wilson } else { 2381a266c7d5SChris Wilson error_mask = ~(I915_ERROR_PAGE_TABLE | 2382a266c7d5SChris Wilson I915_ERROR_MEMORY_REFRESH); 2383a266c7d5SChris Wilson } 2384a266c7d5SChris Wilson I915_WRITE(EMR, error_mask); 2385a266c7d5SChris Wilson 2386a266c7d5SChris Wilson I915_WRITE(IMR, dev_priv->irq_mask); 2387a266c7d5SChris Wilson I915_WRITE(IER, enable_mask); 2388a266c7d5SChris Wilson POSTING_READ(IER); 2389a266c7d5SChris Wilson 2390a266c7d5SChris Wilson if (I915_HAS_HOTPLUG(dev)) { 2391a266c7d5SChris Wilson u32 hotplug_en = I915_READ(PORT_HOTPLUG_EN); 2392a266c7d5SChris Wilson 2393a266c7d5SChris Wilson /* Note HDMI and DP share bits */ 2394a266c7d5SChris Wilson if (dev_priv->hotplug_supported_mask & HDMIB_HOTPLUG_INT_STATUS) 2395a266c7d5SChris Wilson hotplug_en |= HDMIB_HOTPLUG_INT_EN; 2396a266c7d5SChris Wilson if (dev_priv->hotplug_supported_mask & HDMIC_HOTPLUG_INT_STATUS) 2397a266c7d5SChris Wilson hotplug_en |= HDMIC_HOTPLUG_INT_EN; 2398a266c7d5SChris Wilson if (dev_priv->hotplug_supported_mask & HDMID_HOTPLUG_INT_STATUS) 2399a266c7d5SChris Wilson hotplug_en |= HDMID_HOTPLUG_INT_EN; 2400a266c7d5SChris Wilson if (dev_priv->hotplug_supported_mask & SDVOC_HOTPLUG_INT_STATUS) 2401a266c7d5SChris Wilson hotplug_en |= SDVOC_HOTPLUG_INT_EN; 2402a266c7d5SChris Wilson if (dev_priv->hotplug_supported_mask & SDVOB_HOTPLUG_INT_STATUS) 2403a266c7d5SChris Wilson hotplug_en |= SDVOB_HOTPLUG_INT_EN; 2404a266c7d5SChris Wilson if (dev_priv->hotplug_supported_mask & CRT_HOTPLUG_INT_STATUS) { 2405a266c7d5SChris Wilson hotplug_en |= CRT_HOTPLUG_INT_EN; 2406a266c7d5SChris Wilson 2407a266c7d5SChris Wilson /* Programming the CRT detection parameters tends 2408a266c7d5SChris Wilson to generate a spurious hotplug event about three 2409a266c7d5SChris Wilson seconds later. So just do it once. 2410a266c7d5SChris Wilson */ 2411a266c7d5SChris Wilson if (IS_G4X(dev)) 2412a266c7d5SChris Wilson hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64; 2413a266c7d5SChris Wilson hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50; 2414a266c7d5SChris Wilson } 2415a266c7d5SChris Wilson 2416a266c7d5SChris Wilson /* Ignore TV since it's buggy */ 2417a266c7d5SChris Wilson 2418a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_EN, hotplug_en); 2419a266c7d5SChris Wilson } 2420a266c7d5SChris Wilson 2421a266c7d5SChris Wilson intel_opregion_enable_asle(dev); 2422a266c7d5SChris Wilson 2423a266c7d5SChris Wilson return 0; 2424a266c7d5SChris Wilson } 2425a266c7d5SChris Wilson 2426a266c7d5SChris Wilson static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS) 2427a266c7d5SChris Wilson { 2428a266c7d5SChris Wilson struct drm_device *dev = (struct drm_device *) arg; 2429a266c7d5SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2430a266c7d5SChris Wilson struct drm_i915_master_private *master_priv; 2431a266c7d5SChris Wilson u32 iir, new_iir; 2432a266c7d5SChris Wilson u32 pipe_stats[I915_MAX_PIPES]; 2433a266c7d5SChris Wilson u32 vblank_status; 2434a266c7d5SChris Wilson int vblank = 0; 2435a266c7d5SChris Wilson unsigned long irqflags; 2436a266c7d5SChris Wilson int irq_received; 2437a266c7d5SChris Wilson int ret = IRQ_NONE, pipe; 2438a266c7d5SChris Wilson bool blc_event = false; 2439a266c7d5SChris Wilson 2440a266c7d5SChris Wilson atomic_inc(&dev_priv->irq_received); 2441a266c7d5SChris Wilson 2442a266c7d5SChris Wilson iir = I915_READ(IIR); 2443a266c7d5SChris Wilson 2444a266c7d5SChris Wilson if (INTEL_INFO(dev)->gen >= 4) 2445a266c7d5SChris Wilson vblank_status = PIPE_START_VBLANK_INTERRUPT_STATUS; 2446a266c7d5SChris Wilson else 2447a266c7d5SChris Wilson vblank_status = PIPE_VBLANK_INTERRUPT_STATUS; 2448a266c7d5SChris Wilson 2449a266c7d5SChris Wilson for (;;) { 2450a266c7d5SChris Wilson irq_received = iir != 0; 2451a266c7d5SChris Wilson 2452a266c7d5SChris Wilson /* Can't rely on pipestat interrupt bit in iir as it might 2453a266c7d5SChris Wilson * have been cleared after the pipestat interrupt was received. 2454a266c7d5SChris Wilson * It doesn't set the bit in iir again, but it still produces 2455a266c7d5SChris Wilson * interrupts (for non-MSI). 2456a266c7d5SChris Wilson */ 2457a266c7d5SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2458a266c7d5SChris Wilson if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) 2459a266c7d5SChris Wilson i915_handle_error(dev, false); 2460a266c7d5SChris Wilson 2461a266c7d5SChris Wilson for_each_pipe(pipe) { 2462a266c7d5SChris Wilson int reg = PIPESTAT(pipe); 2463a266c7d5SChris Wilson pipe_stats[pipe] = I915_READ(reg); 2464a266c7d5SChris Wilson 2465a266c7d5SChris Wilson /* 2466a266c7d5SChris Wilson * Clear the PIPE*STAT regs before the IIR 2467a266c7d5SChris Wilson */ 2468a266c7d5SChris Wilson if (pipe_stats[pipe] & 0x8000ffff) { 2469a266c7d5SChris Wilson if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) 2470a266c7d5SChris Wilson DRM_DEBUG_DRIVER("pipe %c underrun\n", 2471a266c7d5SChris Wilson pipe_name(pipe)); 2472a266c7d5SChris Wilson I915_WRITE(reg, pipe_stats[pipe]); 2473a266c7d5SChris Wilson irq_received = 1; 2474a266c7d5SChris Wilson } 2475a266c7d5SChris Wilson } 2476a266c7d5SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2477a266c7d5SChris Wilson 2478a266c7d5SChris Wilson if (!irq_received) 2479a266c7d5SChris Wilson break; 2480a266c7d5SChris Wilson 2481a266c7d5SChris Wilson ret = IRQ_HANDLED; 2482a266c7d5SChris Wilson 2483a266c7d5SChris Wilson /* Consume port. Then clear IIR or we'll miss events */ 2484a266c7d5SChris Wilson if ((I915_HAS_HOTPLUG(dev)) && 2485a266c7d5SChris Wilson (iir & I915_DISPLAY_PORT_INTERRUPT)) { 2486a266c7d5SChris Wilson u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT); 2487a266c7d5SChris Wilson 2488a266c7d5SChris Wilson DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n", 2489a266c7d5SChris Wilson hotplug_status); 2490a266c7d5SChris Wilson if (hotplug_status & dev_priv->hotplug_supported_mask) 2491a266c7d5SChris Wilson queue_work(dev_priv->wq, 2492a266c7d5SChris Wilson &dev_priv->hotplug_work); 2493a266c7d5SChris Wilson 2494a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status); 2495a266c7d5SChris Wilson I915_READ(PORT_HOTPLUG_STAT); 2496a266c7d5SChris Wilson } 2497a266c7d5SChris Wilson 2498a266c7d5SChris Wilson I915_WRITE(IIR, iir); 2499a266c7d5SChris Wilson new_iir = I915_READ(IIR); /* Flush posted writes */ 2500a266c7d5SChris Wilson 2501a266c7d5SChris Wilson if (dev->primary->master) { 2502a266c7d5SChris Wilson master_priv = dev->primary->master->driver_priv; 2503a266c7d5SChris Wilson if (master_priv->sarea_priv) 2504a266c7d5SChris Wilson master_priv->sarea_priv->last_dispatch = 2505a266c7d5SChris Wilson READ_BREADCRUMB(dev_priv); 2506a266c7d5SChris Wilson } 2507a266c7d5SChris Wilson 2508a266c7d5SChris Wilson if (iir & I915_USER_INTERRUPT) 2509a266c7d5SChris Wilson notify_ring(dev, &dev_priv->ring[RCS]); 2510a266c7d5SChris Wilson if (iir & I915_BSD_USER_INTERRUPT) 2511a266c7d5SChris Wilson notify_ring(dev, &dev_priv->ring[VCS]); 2512a266c7d5SChris Wilson 2513*4f7d1e79SChris Wilson if (iir & I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT) 2514a266c7d5SChris Wilson intel_prepare_page_flip(dev, 0); 2515a266c7d5SChris Wilson 2516*4f7d1e79SChris Wilson if (iir & I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT) 2517a266c7d5SChris Wilson intel_prepare_page_flip(dev, 1); 2518a266c7d5SChris Wilson 2519a266c7d5SChris Wilson for_each_pipe(pipe) { 2520a266c7d5SChris Wilson if (pipe_stats[pipe] & vblank_status && 2521a266c7d5SChris Wilson drm_handle_vblank(dev, pipe)) { 2522a266c7d5SChris Wilson vblank++; 2523a266c7d5SChris Wilson i915_pageflip_stall_check(dev, pipe); 2524a266c7d5SChris Wilson intel_finish_page_flip(dev, pipe); 2525a266c7d5SChris Wilson } 2526a266c7d5SChris Wilson 2527a266c7d5SChris Wilson if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS) 2528a266c7d5SChris Wilson blc_event = true; 2529a266c7d5SChris Wilson } 2530a266c7d5SChris Wilson 2531a266c7d5SChris Wilson 2532a266c7d5SChris Wilson if (blc_event || (iir & I915_ASLE_INTERRUPT)) 2533a266c7d5SChris Wilson intel_opregion_asle_intr(dev); 2534a266c7d5SChris Wilson 2535a266c7d5SChris Wilson /* With MSI, interrupts are only generated when iir 2536a266c7d5SChris Wilson * transitions from zero to nonzero. If another bit got 2537a266c7d5SChris Wilson * set while we were handling the existing iir bits, then 2538a266c7d5SChris Wilson * we would never get another interrupt. 2539a266c7d5SChris Wilson * 2540a266c7d5SChris Wilson * This is fine on non-MSI as well, as if we hit this path 2541a266c7d5SChris Wilson * we avoid exiting the interrupt handler only to generate 2542a266c7d5SChris Wilson * another one. 2543a266c7d5SChris Wilson * 2544a266c7d5SChris Wilson * Note that for MSI this could cause a stray interrupt report 2545a266c7d5SChris Wilson * if an interrupt landed in the time between writing IIR and 2546a266c7d5SChris Wilson * the posting read. This should be rare enough to never 2547a266c7d5SChris Wilson * trigger the 99% of 100,000 interrupts test for disabling 2548a266c7d5SChris Wilson * stray interrupts. 2549a266c7d5SChris Wilson */ 2550a266c7d5SChris Wilson iir = new_iir; 2551a266c7d5SChris Wilson } 2552a266c7d5SChris Wilson 2553a266c7d5SChris Wilson return ret; 2554a266c7d5SChris Wilson } 2555a266c7d5SChris Wilson 2556a266c7d5SChris Wilson static void i915_irq_uninstall(struct drm_device * dev) 2557a266c7d5SChris Wilson { 2558a266c7d5SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2559a266c7d5SChris Wilson int pipe; 2560a266c7d5SChris Wilson 2561a266c7d5SChris Wilson if (!dev_priv) 2562a266c7d5SChris Wilson return; 2563a266c7d5SChris Wilson 2564a266c7d5SChris Wilson dev_priv->vblank_pipe = 0; 2565a266c7d5SChris Wilson 2566a266c7d5SChris Wilson if (I915_HAS_HOTPLUG(dev)) { 2567a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_EN, 0); 2568a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 2569a266c7d5SChris Wilson } 2570a266c7d5SChris Wilson 2571a266c7d5SChris Wilson I915_WRITE(HWSTAM, 0xffffffff); 2572a266c7d5SChris Wilson for_each_pipe(pipe) 2573a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 2574a266c7d5SChris Wilson I915_WRITE(IMR, 0xffffffff); 2575a266c7d5SChris Wilson I915_WRITE(IER, 0x0); 2576a266c7d5SChris Wilson 2577a266c7d5SChris Wilson for_each_pipe(pipe) 2578a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 2579a266c7d5SChris Wilson I915_READ(PIPESTAT(pipe)) & 0x8000ffff); 2580a266c7d5SChris Wilson I915_WRITE(IIR, I915_READ(IIR)); 2581a266c7d5SChris Wilson } 2582a266c7d5SChris Wilson 2583a266c7d5SChris Wilson static void i965_irq_preinstall(struct drm_device * dev) 2584a266c7d5SChris Wilson { 2585a266c7d5SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2586a266c7d5SChris Wilson int pipe; 2587a266c7d5SChris Wilson 2588a266c7d5SChris Wilson atomic_set(&dev_priv->irq_received, 0); 2589a266c7d5SChris Wilson 2590a266c7d5SChris Wilson if (I915_HAS_HOTPLUG(dev)) { 2591a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_EN, 0); 2592a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 2593a266c7d5SChris Wilson } 2594a266c7d5SChris Wilson 2595a266c7d5SChris Wilson I915_WRITE(HWSTAM, 0xeffe); 2596a266c7d5SChris Wilson for_each_pipe(pipe) 2597a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 2598a266c7d5SChris Wilson I915_WRITE(IMR, 0xffffffff); 2599a266c7d5SChris Wilson I915_WRITE(IER, 0x0); 2600a266c7d5SChris Wilson POSTING_READ(IER); 2601a266c7d5SChris Wilson } 2602a266c7d5SChris Wilson 2603a266c7d5SChris Wilson static int i965_irq_postinstall(struct drm_device *dev) 2604a266c7d5SChris Wilson { 2605a266c7d5SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2606a266c7d5SChris Wilson u32 enable_mask = I915_INTERRUPT_ENABLE_FIX | I915_INTERRUPT_ENABLE_VAR; 2607a266c7d5SChris Wilson u32 error_mask; 2608a266c7d5SChris Wilson 2609a266c7d5SChris Wilson dev_priv->vblank_pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B; 2610a266c7d5SChris Wilson 2611a266c7d5SChris Wilson /* Unmask the interrupts that we always want on. */ 2612a266c7d5SChris Wilson dev_priv->irq_mask = ~I915_INTERRUPT_ENABLE_FIX; 2613a266c7d5SChris Wilson 2614a266c7d5SChris Wilson dev_priv->pipestat[0] = 0; 2615a266c7d5SChris Wilson dev_priv->pipestat[1] = 0; 2616a266c7d5SChris Wilson 2617a266c7d5SChris Wilson if (I915_HAS_HOTPLUG(dev)) { 2618a266c7d5SChris Wilson /* Enable in IER... */ 2619a266c7d5SChris Wilson enable_mask |= I915_DISPLAY_PORT_INTERRUPT; 2620a266c7d5SChris Wilson /* and unmask in IMR */ 2621a266c7d5SChris Wilson dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT; 2622a266c7d5SChris Wilson } 2623a266c7d5SChris Wilson 2624a266c7d5SChris Wilson /* 2625a266c7d5SChris Wilson * Enable some error detection, note the instruction error mask 2626a266c7d5SChris Wilson * bit is reserved, so we leave it masked. 2627a266c7d5SChris Wilson */ 2628a266c7d5SChris Wilson if (IS_G4X(dev)) { 2629a266c7d5SChris Wilson error_mask = ~(GM45_ERROR_PAGE_TABLE | 2630a266c7d5SChris Wilson GM45_ERROR_MEM_PRIV | 2631a266c7d5SChris Wilson GM45_ERROR_CP_PRIV | 2632a266c7d5SChris Wilson I915_ERROR_MEMORY_REFRESH); 2633a266c7d5SChris Wilson } else { 2634a266c7d5SChris Wilson error_mask = ~(I915_ERROR_PAGE_TABLE | 2635a266c7d5SChris Wilson I915_ERROR_MEMORY_REFRESH); 2636a266c7d5SChris Wilson } 2637a266c7d5SChris Wilson I915_WRITE(EMR, error_mask); 2638a266c7d5SChris Wilson 2639a266c7d5SChris Wilson I915_WRITE(IMR, dev_priv->irq_mask); 2640a266c7d5SChris Wilson I915_WRITE(IER, enable_mask); 2641a266c7d5SChris Wilson POSTING_READ(IER); 2642a266c7d5SChris Wilson 2643a266c7d5SChris Wilson if (I915_HAS_HOTPLUG(dev)) { 2644a266c7d5SChris Wilson u32 hotplug_en = I915_READ(PORT_HOTPLUG_EN); 2645a266c7d5SChris Wilson 2646a266c7d5SChris Wilson /* Note HDMI and DP share bits */ 2647a266c7d5SChris Wilson if (dev_priv->hotplug_supported_mask & HDMIB_HOTPLUG_INT_STATUS) 2648a266c7d5SChris Wilson hotplug_en |= HDMIB_HOTPLUG_INT_EN; 2649a266c7d5SChris Wilson if (dev_priv->hotplug_supported_mask & HDMIC_HOTPLUG_INT_STATUS) 2650a266c7d5SChris Wilson hotplug_en |= HDMIC_HOTPLUG_INT_EN; 2651a266c7d5SChris Wilson if (dev_priv->hotplug_supported_mask & HDMID_HOTPLUG_INT_STATUS) 2652a266c7d5SChris Wilson hotplug_en |= HDMID_HOTPLUG_INT_EN; 2653a266c7d5SChris Wilson if (dev_priv->hotplug_supported_mask & SDVOC_HOTPLUG_INT_STATUS) 2654a266c7d5SChris Wilson hotplug_en |= SDVOC_HOTPLUG_INT_EN; 2655a266c7d5SChris Wilson if (dev_priv->hotplug_supported_mask & SDVOB_HOTPLUG_INT_STATUS) 2656a266c7d5SChris Wilson hotplug_en |= SDVOB_HOTPLUG_INT_EN; 2657a266c7d5SChris Wilson if (dev_priv->hotplug_supported_mask & CRT_HOTPLUG_INT_STATUS) { 2658a266c7d5SChris Wilson hotplug_en |= CRT_HOTPLUG_INT_EN; 2659a266c7d5SChris Wilson 2660a266c7d5SChris Wilson /* Programming the CRT detection parameters tends 2661a266c7d5SChris Wilson to generate a spurious hotplug event about three 2662a266c7d5SChris Wilson seconds later. So just do it once. 2663a266c7d5SChris Wilson */ 2664a266c7d5SChris Wilson if (IS_G4X(dev)) 2665a266c7d5SChris Wilson hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64; 2666a266c7d5SChris Wilson hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50; 2667a266c7d5SChris Wilson } 2668a266c7d5SChris Wilson 2669a266c7d5SChris Wilson /* Ignore TV since it's buggy */ 2670a266c7d5SChris Wilson 2671a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_EN, hotplug_en); 2672a266c7d5SChris Wilson } 2673a266c7d5SChris Wilson 2674a266c7d5SChris Wilson intel_opregion_enable_asle(dev); 2675a266c7d5SChris Wilson 2676a266c7d5SChris Wilson return 0; 2677a266c7d5SChris Wilson } 2678a266c7d5SChris Wilson 2679a266c7d5SChris Wilson static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS) 2680a266c7d5SChris Wilson { 2681a266c7d5SChris Wilson struct drm_device *dev = (struct drm_device *) arg; 2682a266c7d5SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2683a266c7d5SChris Wilson struct drm_i915_master_private *master_priv; 2684a266c7d5SChris Wilson u32 iir, new_iir; 2685a266c7d5SChris Wilson u32 pipe_stats[I915_MAX_PIPES]; 2686a266c7d5SChris Wilson u32 vblank_status; 2687a266c7d5SChris Wilson int vblank = 0; 2688a266c7d5SChris Wilson unsigned long irqflags; 2689a266c7d5SChris Wilson int irq_received; 2690a266c7d5SChris Wilson int ret = IRQ_NONE, pipe; 2691a266c7d5SChris Wilson bool blc_event = false; 2692a266c7d5SChris Wilson 2693a266c7d5SChris Wilson atomic_inc(&dev_priv->irq_received); 2694a266c7d5SChris Wilson 2695a266c7d5SChris Wilson iir = I915_READ(IIR); 2696a266c7d5SChris Wilson 2697a266c7d5SChris Wilson if (INTEL_INFO(dev)->gen >= 4) 2698a266c7d5SChris Wilson vblank_status = PIPE_START_VBLANK_INTERRUPT_STATUS; 2699a266c7d5SChris Wilson else 2700a266c7d5SChris Wilson vblank_status = PIPE_VBLANK_INTERRUPT_STATUS; 2701a266c7d5SChris Wilson 2702a266c7d5SChris Wilson for (;;) { 2703a266c7d5SChris Wilson irq_received = iir != 0; 2704a266c7d5SChris Wilson 2705a266c7d5SChris Wilson /* Can't rely on pipestat interrupt bit in iir as it might 2706a266c7d5SChris Wilson * have been cleared after the pipestat interrupt was received. 2707a266c7d5SChris Wilson * It doesn't set the bit in iir again, but it still produces 2708a266c7d5SChris Wilson * interrupts (for non-MSI). 2709a266c7d5SChris Wilson */ 2710a266c7d5SChris Wilson spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2711a266c7d5SChris Wilson if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) 2712a266c7d5SChris Wilson i915_handle_error(dev, false); 2713a266c7d5SChris Wilson 2714a266c7d5SChris Wilson for_each_pipe(pipe) { 2715a266c7d5SChris Wilson int reg = PIPESTAT(pipe); 2716a266c7d5SChris Wilson pipe_stats[pipe] = I915_READ(reg); 2717a266c7d5SChris Wilson 2718a266c7d5SChris Wilson /* 2719a266c7d5SChris Wilson * Clear the PIPE*STAT regs before the IIR 2720a266c7d5SChris Wilson */ 2721a266c7d5SChris Wilson if (pipe_stats[pipe] & 0x8000ffff) { 2722a266c7d5SChris Wilson if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) 2723a266c7d5SChris Wilson DRM_DEBUG_DRIVER("pipe %c underrun\n", 2724a266c7d5SChris Wilson pipe_name(pipe)); 2725a266c7d5SChris Wilson I915_WRITE(reg, pipe_stats[pipe]); 2726a266c7d5SChris Wilson irq_received = 1; 2727a266c7d5SChris Wilson } 2728a266c7d5SChris Wilson } 2729a266c7d5SChris Wilson spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2730a266c7d5SChris Wilson 2731a266c7d5SChris Wilson if (!irq_received) 2732a266c7d5SChris Wilson break; 2733a266c7d5SChris Wilson 2734a266c7d5SChris Wilson ret = IRQ_HANDLED; 2735a266c7d5SChris Wilson 2736a266c7d5SChris Wilson /* Consume port. Then clear IIR or we'll miss events */ 2737a266c7d5SChris Wilson if ((I915_HAS_HOTPLUG(dev)) && 2738a266c7d5SChris Wilson (iir & I915_DISPLAY_PORT_INTERRUPT)) { 2739a266c7d5SChris Wilson u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT); 2740a266c7d5SChris Wilson 2741a266c7d5SChris Wilson DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n", 2742a266c7d5SChris Wilson hotplug_status); 2743a266c7d5SChris Wilson if (hotplug_status & dev_priv->hotplug_supported_mask) 2744a266c7d5SChris Wilson queue_work(dev_priv->wq, 2745a266c7d5SChris Wilson &dev_priv->hotplug_work); 2746a266c7d5SChris Wilson 2747a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status); 2748a266c7d5SChris Wilson I915_READ(PORT_HOTPLUG_STAT); 2749a266c7d5SChris Wilson } 2750a266c7d5SChris Wilson 2751a266c7d5SChris Wilson I915_WRITE(IIR, iir); 2752a266c7d5SChris Wilson new_iir = I915_READ(IIR); /* Flush posted writes */ 2753a266c7d5SChris Wilson 2754a266c7d5SChris Wilson if (dev->primary->master) { 2755a266c7d5SChris Wilson master_priv = dev->primary->master->driver_priv; 2756a266c7d5SChris Wilson if (master_priv->sarea_priv) 2757a266c7d5SChris Wilson master_priv->sarea_priv->last_dispatch = 2758a266c7d5SChris Wilson READ_BREADCRUMB(dev_priv); 2759a266c7d5SChris Wilson } 2760a266c7d5SChris Wilson 2761a266c7d5SChris Wilson if (iir & I915_USER_INTERRUPT) 2762a266c7d5SChris Wilson notify_ring(dev, &dev_priv->ring[RCS]); 2763a266c7d5SChris Wilson if (iir & I915_BSD_USER_INTERRUPT) 2764a266c7d5SChris Wilson notify_ring(dev, &dev_priv->ring[VCS]); 2765a266c7d5SChris Wilson 2766*4f7d1e79SChris Wilson if (iir & I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT) 2767a266c7d5SChris Wilson intel_prepare_page_flip(dev, 0); 2768a266c7d5SChris Wilson 2769*4f7d1e79SChris Wilson if (iir & I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT) 2770a266c7d5SChris Wilson intel_prepare_page_flip(dev, 1); 2771a266c7d5SChris Wilson 2772a266c7d5SChris Wilson for_each_pipe(pipe) { 2773a266c7d5SChris Wilson if (pipe_stats[pipe] & vblank_status && 2774a266c7d5SChris Wilson drm_handle_vblank(dev, pipe)) { 2775a266c7d5SChris Wilson vblank++; 2776a266c7d5SChris Wilson i915_pageflip_stall_check(dev, pipe); 2777a266c7d5SChris Wilson intel_finish_page_flip(dev, pipe); 2778a266c7d5SChris Wilson } 2779a266c7d5SChris Wilson 2780a266c7d5SChris Wilson if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS) 2781a266c7d5SChris Wilson blc_event = true; 2782a266c7d5SChris Wilson } 2783a266c7d5SChris Wilson 2784a266c7d5SChris Wilson 2785a266c7d5SChris Wilson if (blc_event || (iir & I915_ASLE_INTERRUPT)) 2786a266c7d5SChris Wilson intel_opregion_asle_intr(dev); 2787a266c7d5SChris Wilson 2788a266c7d5SChris Wilson /* With MSI, interrupts are only generated when iir 2789a266c7d5SChris Wilson * transitions from zero to nonzero. If another bit got 2790a266c7d5SChris Wilson * set while we were handling the existing iir bits, then 2791a266c7d5SChris Wilson * we would never get another interrupt. 2792a266c7d5SChris Wilson * 2793a266c7d5SChris Wilson * This is fine on non-MSI as well, as if we hit this path 2794a266c7d5SChris Wilson * we avoid exiting the interrupt handler only to generate 2795a266c7d5SChris Wilson * another one. 2796a266c7d5SChris Wilson * 2797a266c7d5SChris Wilson * Note that for MSI this could cause a stray interrupt report 2798a266c7d5SChris Wilson * if an interrupt landed in the time between writing IIR and 2799a266c7d5SChris Wilson * the posting read. This should be rare enough to never 2800a266c7d5SChris Wilson * trigger the 99% of 100,000 interrupts test for disabling 2801a266c7d5SChris Wilson * stray interrupts. 2802a266c7d5SChris Wilson */ 2803a266c7d5SChris Wilson iir = new_iir; 2804a266c7d5SChris Wilson } 2805a266c7d5SChris Wilson 2806a266c7d5SChris Wilson return ret; 2807a266c7d5SChris Wilson } 2808a266c7d5SChris Wilson 2809a266c7d5SChris Wilson static void i965_irq_uninstall(struct drm_device * dev) 2810a266c7d5SChris Wilson { 2811a266c7d5SChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2812a266c7d5SChris Wilson int pipe; 2813a266c7d5SChris Wilson 2814a266c7d5SChris Wilson if (!dev_priv) 2815a266c7d5SChris Wilson return; 2816a266c7d5SChris Wilson 2817a266c7d5SChris Wilson dev_priv->vblank_pipe = 0; 2818a266c7d5SChris Wilson 2819a266c7d5SChris Wilson if (I915_HAS_HOTPLUG(dev)) { 2820a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_EN, 0); 2821a266c7d5SChris Wilson I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 2822a266c7d5SChris Wilson } 2823a266c7d5SChris Wilson 2824a266c7d5SChris Wilson I915_WRITE(HWSTAM, 0xffffffff); 2825a266c7d5SChris Wilson for_each_pipe(pipe) 2826a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 0); 2827a266c7d5SChris Wilson I915_WRITE(IMR, 0xffffffff); 2828a266c7d5SChris Wilson I915_WRITE(IER, 0x0); 2829a266c7d5SChris Wilson 2830a266c7d5SChris Wilson for_each_pipe(pipe) 2831a266c7d5SChris Wilson I915_WRITE(PIPESTAT(pipe), 2832a266c7d5SChris Wilson I915_READ(PIPESTAT(pipe)) & 0x8000ffff); 2833a266c7d5SChris Wilson I915_WRITE(IIR, I915_READ(IIR)); 2834a266c7d5SChris Wilson } 2835a266c7d5SChris Wilson 2836f71d4af4SJesse Barnes void intel_irq_init(struct drm_device *dev) 2837f71d4af4SJesse Barnes { 28388b2e326dSChris Wilson struct drm_i915_private *dev_priv = dev->dev_private; 28398b2e326dSChris Wilson 28408b2e326dSChris Wilson INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func); 28418b2e326dSChris Wilson INIT_WORK(&dev_priv->error_work, i915_error_work_func); 28428b2e326dSChris Wilson INIT_WORK(&dev_priv->rps_work, gen6_pm_rps_work); 28438b2e326dSChris Wilson 2844f71d4af4SJesse Barnes dev->driver->get_vblank_counter = i915_get_vblank_counter; 2845f71d4af4SJesse Barnes dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */ 28467e231dbeSJesse Barnes if (IS_G4X(dev) || IS_GEN5(dev) || IS_GEN6(dev) || IS_IVYBRIDGE(dev) || 28477e231dbeSJesse Barnes IS_VALLEYVIEW(dev)) { 2848f71d4af4SJesse Barnes dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */ 2849f71d4af4SJesse Barnes dev->driver->get_vblank_counter = gm45_get_vblank_counter; 2850f71d4af4SJesse Barnes } 2851f71d4af4SJesse Barnes 2852c3613de9SKeith Packard if (drm_core_check_feature(dev, DRIVER_MODESET)) 2853f71d4af4SJesse Barnes dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp; 2854c3613de9SKeith Packard else 2855c3613de9SKeith Packard dev->driver->get_vblank_timestamp = NULL; 2856f71d4af4SJesse Barnes dev->driver->get_scanout_position = i915_get_crtc_scanoutpos; 2857f71d4af4SJesse Barnes 28587e231dbeSJesse Barnes if (IS_VALLEYVIEW(dev)) { 28597e231dbeSJesse Barnes dev->driver->irq_handler = valleyview_irq_handler; 28607e231dbeSJesse Barnes dev->driver->irq_preinstall = valleyview_irq_preinstall; 28617e231dbeSJesse Barnes dev->driver->irq_postinstall = valleyview_irq_postinstall; 28627e231dbeSJesse Barnes dev->driver->irq_uninstall = valleyview_irq_uninstall; 28637e231dbeSJesse Barnes dev->driver->enable_vblank = valleyview_enable_vblank; 28647e231dbeSJesse Barnes dev->driver->disable_vblank = valleyview_disable_vblank; 28657e231dbeSJesse Barnes } else if (IS_IVYBRIDGE(dev)) { 2866f71d4af4SJesse Barnes /* Share pre & uninstall handlers with ILK/SNB */ 2867f71d4af4SJesse Barnes dev->driver->irq_handler = ivybridge_irq_handler; 2868f71d4af4SJesse Barnes dev->driver->irq_preinstall = ironlake_irq_preinstall; 2869f71d4af4SJesse Barnes dev->driver->irq_postinstall = ivybridge_irq_postinstall; 2870f71d4af4SJesse Barnes dev->driver->irq_uninstall = ironlake_irq_uninstall; 2871f71d4af4SJesse Barnes dev->driver->enable_vblank = ivybridge_enable_vblank; 2872f71d4af4SJesse Barnes dev->driver->disable_vblank = ivybridge_disable_vblank; 2873f71d4af4SJesse Barnes } else if (HAS_PCH_SPLIT(dev)) { 2874f71d4af4SJesse Barnes dev->driver->irq_handler = ironlake_irq_handler; 2875f71d4af4SJesse Barnes dev->driver->irq_preinstall = ironlake_irq_preinstall; 2876f71d4af4SJesse Barnes dev->driver->irq_postinstall = ironlake_irq_postinstall; 2877f71d4af4SJesse Barnes dev->driver->irq_uninstall = ironlake_irq_uninstall; 2878f71d4af4SJesse Barnes dev->driver->enable_vblank = ironlake_enable_vblank; 2879f71d4af4SJesse Barnes dev->driver->disable_vblank = ironlake_disable_vblank; 2880f71d4af4SJesse Barnes } else { 2881c2798b19SChris Wilson if (INTEL_INFO(dev)->gen == 2) { 2882c2798b19SChris Wilson dev->driver->irq_preinstall = i8xx_irq_preinstall; 2883c2798b19SChris Wilson dev->driver->irq_postinstall = i8xx_irq_postinstall; 2884c2798b19SChris Wilson dev->driver->irq_handler = i8xx_irq_handler; 2885c2798b19SChris Wilson dev->driver->irq_uninstall = i8xx_irq_uninstall; 2886a266c7d5SChris Wilson } else if (INTEL_INFO(dev)->gen == 3) { 2887*4f7d1e79SChris Wilson /* IIR "flip pending" means done if this bit is set */ 2888*4f7d1e79SChris Wilson I915_WRITE(ECOSKPD, _MASKED_BIT_DISABLE(ECO_FLIP_DONE)); 2889*4f7d1e79SChris Wilson 2890a266c7d5SChris Wilson dev->driver->irq_preinstall = i915_irq_preinstall; 2891a266c7d5SChris Wilson dev->driver->irq_postinstall = i915_irq_postinstall; 2892a266c7d5SChris Wilson dev->driver->irq_uninstall = i915_irq_uninstall; 2893a266c7d5SChris Wilson dev->driver->irq_handler = i915_irq_handler; 2894c2798b19SChris Wilson } else { 2895a266c7d5SChris Wilson dev->driver->irq_preinstall = i965_irq_preinstall; 2896a266c7d5SChris Wilson dev->driver->irq_postinstall = i965_irq_postinstall; 2897a266c7d5SChris Wilson dev->driver->irq_uninstall = i965_irq_uninstall; 2898a266c7d5SChris Wilson dev->driver->irq_handler = i965_irq_handler; 2899c2798b19SChris Wilson } 2900f71d4af4SJesse Barnes dev->driver->enable_vblank = i915_enable_vblank; 2901f71d4af4SJesse Barnes dev->driver->disable_vblank = i915_disable_vblank; 2902f71d4af4SJesse Barnes } 2903f71d4af4SJesse Barnes } 2904