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 2963eeaf38SJesse Barnes #include <linux/sysrq.h> 305a0e3ad6STejun Heo #include <linux/slab.h> 31c0e09200SDave Airlie #include "drmP.h" 32c0e09200SDave Airlie #include "drm.h" 33c0e09200SDave Airlie #include "i915_drm.h" 34c0e09200SDave Airlie #include "i915_drv.h" 351c5d22f7SChris Wilson #include "i915_trace.h" 3679e53945SJesse Barnes #include "intel_drv.h" 37c0e09200SDave Airlie 38c0e09200SDave Airlie #define MAX_NOPID ((u32)~0) 39c0e09200SDave Airlie 407c463586SKeith Packard /** 417c463586SKeith Packard * Interrupts that are always left unmasked. 427c463586SKeith Packard * 437c463586SKeith Packard * Since pipe events are edge-triggered from the PIPESTAT register to IIR, 447c463586SKeith Packard * we leave them always unmasked in IMR and then control enabling them through 457c463586SKeith Packard * PIPESTAT alone. 467c463586SKeith Packard */ 476b95a207SKristian Høgsberg #define I915_INTERRUPT_ENABLE_FIX \ 486b95a207SKristian Høgsberg (I915_ASLE_INTERRUPT | \ 490a3e67a4SJesse Barnes I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | \ 5063eeaf38SJesse Barnes I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | \ 516b95a207SKristian Høgsberg I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | \ 526b95a207SKristian Høgsberg I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT | \ 5363eeaf38SJesse Barnes I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) 54ed4cb414SEric Anholt 557c463586SKeith Packard /** Interrupts that we mask and unmask at runtime. */ 56d1b851fcSZou Nan hai #define I915_INTERRUPT_ENABLE_VAR (I915_USER_INTERRUPT | I915_BSD_USER_INTERRUPT) 577c463586SKeith Packard 5879e53945SJesse Barnes #define I915_PIPE_VBLANK_STATUS (PIPE_START_VBLANK_INTERRUPT_STATUS |\ 5979e53945SJesse Barnes PIPE_VBLANK_INTERRUPT_STATUS) 6079e53945SJesse Barnes 6179e53945SJesse Barnes #define I915_PIPE_VBLANK_ENABLE (PIPE_START_VBLANK_INTERRUPT_ENABLE |\ 6279e53945SJesse Barnes PIPE_VBLANK_INTERRUPT_ENABLE) 6379e53945SJesse Barnes 6479e53945SJesse Barnes #define DRM_I915_VBLANK_PIPE_ALL (DRM_I915_VBLANK_PIPE_A | \ 6579e53945SJesse Barnes DRM_I915_VBLANK_PIPE_B) 6679e53945SJesse Barnes 678ee1c3dbSMatthew Garrett void 68f2b115e6SAdam Jackson ironlake_enable_graphics_irq(drm_i915_private_t *dev_priv, u32 mask) 69036a4a7dSZhenyu Wang { 70036a4a7dSZhenyu Wang if ((dev_priv->gt_irq_mask_reg & mask) != 0) { 71036a4a7dSZhenyu Wang dev_priv->gt_irq_mask_reg &= ~mask; 72036a4a7dSZhenyu Wang I915_WRITE(GTIMR, dev_priv->gt_irq_mask_reg); 733143a2bfSChris Wilson POSTING_READ(GTIMR); 74036a4a7dSZhenyu Wang } 75036a4a7dSZhenyu Wang } 76036a4a7dSZhenyu Wang 7762fdfeafSEric Anholt void 78f2b115e6SAdam Jackson ironlake_disable_graphics_irq(drm_i915_private_t *dev_priv, u32 mask) 79036a4a7dSZhenyu Wang { 80036a4a7dSZhenyu Wang if ((dev_priv->gt_irq_mask_reg & mask) != mask) { 81036a4a7dSZhenyu Wang dev_priv->gt_irq_mask_reg |= mask; 82036a4a7dSZhenyu Wang I915_WRITE(GTIMR, dev_priv->gt_irq_mask_reg); 833143a2bfSChris Wilson POSTING_READ(GTIMR); 84036a4a7dSZhenyu Wang } 85036a4a7dSZhenyu Wang } 86036a4a7dSZhenyu Wang 87036a4a7dSZhenyu Wang /* For display hotplug interrupt */ 88995b6762SChris Wilson static void 89f2b115e6SAdam Jackson ironlake_enable_display_irq(drm_i915_private_t *dev_priv, u32 mask) 90036a4a7dSZhenyu Wang { 91036a4a7dSZhenyu Wang if ((dev_priv->irq_mask_reg & mask) != 0) { 92036a4a7dSZhenyu Wang dev_priv->irq_mask_reg &= ~mask; 93036a4a7dSZhenyu Wang I915_WRITE(DEIMR, dev_priv->irq_mask_reg); 943143a2bfSChris Wilson POSTING_READ(DEIMR); 95036a4a7dSZhenyu Wang } 96036a4a7dSZhenyu Wang } 97036a4a7dSZhenyu Wang 98036a4a7dSZhenyu Wang static inline void 99f2b115e6SAdam Jackson ironlake_disable_display_irq(drm_i915_private_t *dev_priv, u32 mask) 100036a4a7dSZhenyu Wang { 101036a4a7dSZhenyu Wang if ((dev_priv->irq_mask_reg & mask) != mask) { 102036a4a7dSZhenyu Wang dev_priv->irq_mask_reg |= mask; 103036a4a7dSZhenyu Wang I915_WRITE(DEIMR, dev_priv->irq_mask_reg); 1043143a2bfSChris Wilson POSTING_READ(DEIMR); 105036a4a7dSZhenyu Wang } 106036a4a7dSZhenyu Wang } 107036a4a7dSZhenyu Wang 108036a4a7dSZhenyu Wang void 109ed4cb414SEric Anholt i915_enable_irq(drm_i915_private_t *dev_priv, u32 mask) 110ed4cb414SEric Anholt { 111ed4cb414SEric Anholt if ((dev_priv->irq_mask_reg & mask) != 0) { 112ed4cb414SEric Anholt dev_priv->irq_mask_reg &= ~mask; 113ed4cb414SEric Anholt I915_WRITE(IMR, dev_priv->irq_mask_reg); 1143143a2bfSChris Wilson POSTING_READ(IMR); 115ed4cb414SEric Anholt } 116ed4cb414SEric Anholt } 117ed4cb414SEric Anholt 11862fdfeafSEric Anholt void 119ed4cb414SEric Anholt i915_disable_irq(drm_i915_private_t *dev_priv, u32 mask) 120ed4cb414SEric Anholt { 121ed4cb414SEric Anholt if ((dev_priv->irq_mask_reg & mask) != mask) { 122ed4cb414SEric Anholt dev_priv->irq_mask_reg |= mask; 123ed4cb414SEric Anholt I915_WRITE(IMR, dev_priv->irq_mask_reg); 1243143a2bfSChris Wilson POSTING_READ(IMR); 125ed4cb414SEric Anholt } 126ed4cb414SEric Anholt } 127ed4cb414SEric Anholt 1287c463586SKeith Packard static inline u32 1297c463586SKeith Packard i915_pipestat(int pipe) 1307c463586SKeith Packard { 1317c463586SKeith Packard if (pipe == 0) 1327c463586SKeith Packard return PIPEASTAT; 1337c463586SKeith Packard if (pipe == 1) 1347c463586SKeith Packard return PIPEBSTAT; 1359c84ba4eSAndrew Morton BUG(); 1367c463586SKeith Packard } 1377c463586SKeith Packard 1387c463586SKeith Packard void 1397c463586SKeith Packard i915_enable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask) 1407c463586SKeith Packard { 1417c463586SKeith Packard if ((dev_priv->pipestat[pipe] & mask) != mask) { 1427c463586SKeith Packard u32 reg = i915_pipestat(pipe); 1437c463586SKeith Packard 1447c463586SKeith Packard dev_priv->pipestat[pipe] |= mask; 1457c463586SKeith Packard /* Enable the interrupt, clear any pending status */ 1467c463586SKeith Packard I915_WRITE(reg, dev_priv->pipestat[pipe] | (mask >> 16)); 1473143a2bfSChris Wilson POSTING_READ(reg); 1487c463586SKeith Packard } 1497c463586SKeith Packard } 1507c463586SKeith Packard 1517c463586SKeith Packard void 1527c463586SKeith Packard i915_disable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask) 1537c463586SKeith Packard { 1547c463586SKeith Packard if ((dev_priv->pipestat[pipe] & mask) != 0) { 1557c463586SKeith Packard u32 reg = i915_pipestat(pipe); 1567c463586SKeith Packard 1577c463586SKeith Packard dev_priv->pipestat[pipe] &= ~mask; 1587c463586SKeith Packard I915_WRITE(reg, dev_priv->pipestat[pipe]); 1593143a2bfSChris Wilson POSTING_READ(reg); 1607c463586SKeith Packard } 1617c463586SKeith Packard } 1627c463586SKeith Packard 163c0e09200SDave Airlie /** 16401c66889SZhao Yakui * intel_enable_asle - enable ASLE interrupt for OpRegion 16501c66889SZhao Yakui */ 16601c66889SZhao Yakui void intel_enable_asle (struct drm_device *dev) 16701c66889SZhao Yakui { 16801c66889SZhao Yakui drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 16901c66889SZhao Yakui 170c619eed4SEric Anholt if (HAS_PCH_SPLIT(dev)) 171f2b115e6SAdam Jackson ironlake_enable_display_irq(dev_priv, DE_GSE); 172edcb49caSZhao Yakui else { 17301c66889SZhao Yakui i915_enable_pipestat(dev_priv, 1, 174d874bcffSJesse Barnes PIPE_LEGACY_BLC_EVENT_ENABLE); 175a6c45cf0SChris Wilson if (INTEL_INFO(dev)->gen >= 4) 176edcb49caSZhao Yakui i915_enable_pipestat(dev_priv, 0, 177d874bcffSJesse Barnes PIPE_LEGACY_BLC_EVENT_ENABLE); 178edcb49caSZhao Yakui } 17901c66889SZhao Yakui } 18001c66889SZhao Yakui 18101c66889SZhao Yakui /** 1820a3e67a4SJesse Barnes * i915_pipe_enabled - check if a pipe is enabled 1830a3e67a4SJesse Barnes * @dev: DRM device 1840a3e67a4SJesse Barnes * @pipe: pipe to check 1850a3e67a4SJesse Barnes * 1860a3e67a4SJesse Barnes * Reading certain registers when the pipe is disabled can hang the chip. 1870a3e67a4SJesse Barnes * Use this routine to make sure the PLL is running and the pipe is active 1880a3e67a4SJesse Barnes * before reading such registers if unsure. 1890a3e67a4SJesse Barnes */ 1900a3e67a4SJesse Barnes static int 1910a3e67a4SJesse Barnes i915_pipe_enabled(struct drm_device *dev, int pipe) 1920a3e67a4SJesse Barnes { 1930a3e67a4SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 1945eddb70bSChris Wilson return I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE; 1950a3e67a4SJesse Barnes } 1960a3e67a4SJesse Barnes 19742f52ef8SKeith Packard /* Called from drm generic code, passed a 'crtc', which 19842f52ef8SKeith Packard * we use as a pipe index 19942f52ef8SKeith Packard */ 20042f52ef8SKeith Packard u32 i915_get_vblank_counter(struct drm_device *dev, int pipe) 2010a3e67a4SJesse Barnes { 2020a3e67a4SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2030a3e67a4SJesse Barnes unsigned long high_frame; 2040a3e67a4SJesse Barnes unsigned long low_frame; 2055eddb70bSChris Wilson u32 high1, high2, low; 2060a3e67a4SJesse Barnes 2070a3e67a4SJesse Barnes if (!i915_pipe_enabled(dev, pipe)) { 20844d98a61SZhao Yakui DRM_DEBUG_DRIVER("trying to get vblank count for disabled " 20944d98a61SZhao Yakui "pipe %d\n", pipe); 2100a3e67a4SJesse Barnes return 0; 2110a3e67a4SJesse Barnes } 2120a3e67a4SJesse Barnes 2135eddb70bSChris Wilson high_frame = pipe ? PIPEBFRAMEHIGH : PIPEAFRAMEHIGH; 2145eddb70bSChris Wilson low_frame = pipe ? PIPEBFRAMEPIXEL : PIPEAFRAMEPIXEL; 2155eddb70bSChris Wilson 2160a3e67a4SJesse Barnes /* 2170a3e67a4SJesse Barnes * High & low register fields aren't synchronized, so make sure 2180a3e67a4SJesse Barnes * we get a low value that's stable across two reads of the high 2190a3e67a4SJesse Barnes * register. 2200a3e67a4SJesse Barnes */ 2210a3e67a4SJesse Barnes do { 2225eddb70bSChris Wilson high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK; 2235eddb70bSChris Wilson low = I915_READ(low_frame) & PIPE_FRAME_LOW_MASK; 2245eddb70bSChris Wilson high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK; 2250a3e67a4SJesse Barnes } while (high1 != high2); 2260a3e67a4SJesse Barnes 2275eddb70bSChris Wilson high1 >>= PIPE_FRAME_HIGH_SHIFT; 2285eddb70bSChris Wilson low >>= PIPE_FRAME_LOW_SHIFT; 2295eddb70bSChris Wilson return (high1 << 8) | low; 2300a3e67a4SJesse Barnes } 2310a3e67a4SJesse Barnes 2329880b7a5SJesse Barnes u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe) 2339880b7a5SJesse Barnes { 2349880b7a5SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2359880b7a5SJesse Barnes int reg = pipe ? PIPEB_FRMCOUNT_GM45 : PIPEA_FRMCOUNT_GM45; 2369880b7a5SJesse Barnes 2379880b7a5SJesse Barnes if (!i915_pipe_enabled(dev, pipe)) { 23844d98a61SZhao Yakui DRM_DEBUG_DRIVER("trying to get vblank count for disabled " 23944d98a61SZhao Yakui "pipe %d\n", pipe); 2409880b7a5SJesse Barnes return 0; 2419880b7a5SJesse Barnes } 2429880b7a5SJesse Barnes 2439880b7a5SJesse Barnes return I915_READ(reg); 2449880b7a5SJesse Barnes } 2459880b7a5SJesse Barnes 2465ca58282SJesse Barnes /* 2475ca58282SJesse Barnes * Handle hotplug events outside the interrupt handler proper. 2485ca58282SJesse Barnes */ 2495ca58282SJesse Barnes static void i915_hotplug_work_func(struct work_struct *work) 2505ca58282SJesse Barnes { 2515ca58282SJesse Barnes drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t, 2525ca58282SJesse Barnes hotplug_work); 2535ca58282SJesse Barnes struct drm_device *dev = dev_priv->dev; 254c31c4ba3SKeith Packard struct drm_mode_config *mode_config = &dev->mode_config; 2554ef69c7aSChris Wilson struct intel_encoder *encoder; 2565ca58282SJesse Barnes 2574ef69c7aSChris Wilson list_for_each_entry(encoder, &mode_config->encoder_list, base.head) 2584ef69c7aSChris Wilson if (encoder->hot_plug) 2594ef69c7aSChris Wilson encoder->hot_plug(encoder); 260c31c4ba3SKeith Packard 2615ca58282SJesse Barnes /* Just fire off a uevent and let userspace tell us what to do */ 262eb1f8e4fSDave Airlie drm_helper_hpd_irq_event(dev); 2635ca58282SJesse Barnes } 2645ca58282SJesse Barnes 265f97108d1SJesse Barnes static void i915_handle_rps_change(struct drm_device *dev) 266f97108d1SJesse Barnes { 267f97108d1SJesse Barnes drm_i915_private_t *dev_priv = dev->dev_private; 268b5b72e89SMatthew Garrett u32 busy_up, busy_down, max_avg, min_avg; 269f97108d1SJesse Barnes u8 new_delay = dev_priv->cur_delay; 270f97108d1SJesse Barnes 2717648fa99SJesse Barnes I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG); 272b5b72e89SMatthew Garrett busy_up = I915_READ(RCPREVBSYTUPAVG); 273b5b72e89SMatthew Garrett busy_down = I915_READ(RCPREVBSYTDNAVG); 274f97108d1SJesse Barnes max_avg = I915_READ(RCBMAXAVG); 275f97108d1SJesse Barnes min_avg = I915_READ(RCBMINAVG); 276f97108d1SJesse Barnes 277f97108d1SJesse Barnes /* Handle RCS change request from hw */ 278b5b72e89SMatthew Garrett if (busy_up > max_avg) { 279f97108d1SJesse Barnes if (dev_priv->cur_delay != dev_priv->max_delay) 280f97108d1SJesse Barnes new_delay = dev_priv->cur_delay - 1; 281f97108d1SJesse Barnes if (new_delay < dev_priv->max_delay) 282f97108d1SJesse Barnes new_delay = dev_priv->max_delay; 283b5b72e89SMatthew Garrett } else if (busy_down < min_avg) { 284f97108d1SJesse Barnes if (dev_priv->cur_delay != dev_priv->min_delay) 285f97108d1SJesse Barnes new_delay = dev_priv->cur_delay + 1; 286f97108d1SJesse Barnes if (new_delay > dev_priv->min_delay) 287f97108d1SJesse Barnes new_delay = dev_priv->min_delay; 288f97108d1SJesse Barnes } 289f97108d1SJesse Barnes 2907648fa99SJesse Barnes if (ironlake_set_drps(dev, new_delay)) 291f97108d1SJesse Barnes dev_priv->cur_delay = new_delay; 292f97108d1SJesse Barnes 293f97108d1SJesse Barnes return; 294f97108d1SJesse Barnes } 295f97108d1SJesse Barnes 296549f7365SChris Wilson static void notify_ring(struct drm_device *dev, 297549f7365SChris Wilson struct intel_ring_buffer *ring) 298549f7365SChris Wilson { 299549f7365SChris Wilson struct drm_i915_private *dev_priv = dev->dev_private; 30078501eacSChris Wilson u32 seqno = ring->get_seqno(ring); 301b2223497SChris Wilson ring->irq_seqno = seqno; 302549f7365SChris Wilson trace_i915_gem_request_complete(dev, seqno); 303549f7365SChris Wilson wake_up_all(&ring->irq_queue); 304549f7365SChris Wilson dev_priv->hangcheck_count = 0; 305549f7365SChris Wilson mod_timer(&dev_priv->hangcheck_timer, 306549f7365SChris Wilson jiffies + msecs_to_jiffies(DRM_I915_HANGCHECK_PERIOD)); 307549f7365SChris Wilson } 308549f7365SChris Wilson 309995b6762SChris Wilson static irqreturn_t ironlake_irq_handler(struct drm_device *dev) 310036a4a7dSZhenyu Wang { 311036a4a7dSZhenyu Wang drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 312036a4a7dSZhenyu Wang int ret = IRQ_NONE; 3133ff99164SDave Airlie u32 de_iir, gt_iir, de_ier, pch_iir; 3142d7b8366SYuanhan Liu u32 hotplug_mask; 315036a4a7dSZhenyu Wang struct drm_i915_master_private *master_priv; 316881f47b6SXiang, Haihao u32 bsd_usr_interrupt = GT_BSD_USER_INTERRUPT; 317881f47b6SXiang, Haihao 318881f47b6SXiang, Haihao if (IS_GEN6(dev)) 319881f47b6SXiang, Haihao bsd_usr_interrupt = GT_GEN6_BSD_USER_INTERRUPT; 320036a4a7dSZhenyu Wang 3212d109a84SZou, Nanhai /* disable master interrupt before clearing iir */ 3222d109a84SZou, Nanhai de_ier = I915_READ(DEIER); 3232d109a84SZou, Nanhai I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL); 3243143a2bfSChris Wilson POSTING_READ(DEIER); 3252d109a84SZou, Nanhai 326036a4a7dSZhenyu Wang de_iir = I915_READ(DEIIR); 327036a4a7dSZhenyu Wang gt_iir = I915_READ(GTIIR); 328c650156aSZhenyu Wang pch_iir = I915_READ(SDEIIR); 329036a4a7dSZhenyu Wang 330c650156aSZhenyu Wang if (de_iir == 0 && gt_iir == 0 && pch_iir == 0) 331c7c85101SZou Nan hai goto done; 332036a4a7dSZhenyu Wang 3332d7b8366SYuanhan Liu if (HAS_PCH_CPT(dev)) 3342d7b8366SYuanhan Liu hotplug_mask = SDE_HOTPLUG_MASK_CPT; 3352d7b8366SYuanhan Liu else 3362d7b8366SYuanhan Liu hotplug_mask = SDE_HOTPLUG_MASK; 3372d7b8366SYuanhan Liu 338036a4a7dSZhenyu Wang ret = IRQ_HANDLED; 339036a4a7dSZhenyu Wang 340036a4a7dSZhenyu Wang if (dev->primary->master) { 341036a4a7dSZhenyu Wang master_priv = dev->primary->master->driver_priv; 342036a4a7dSZhenyu Wang if (master_priv->sarea_priv) 343036a4a7dSZhenyu Wang master_priv->sarea_priv->last_dispatch = 344036a4a7dSZhenyu Wang READ_BREADCRUMB(dev_priv); 345036a4a7dSZhenyu Wang } 346036a4a7dSZhenyu Wang 347549f7365SChris Wilson if (gt_iir & GT_PIPE_NOTIFY) 348549f7365SChris Wilson notify_ring(dev, &dev_priv->render_ring); 349881f47b6SXiang, Haihao if (gt_iir & bsd_usr_interrupt) 350549f7365SChris Wilson notify_ring(dev, &dev_priv->bsd_ring); 351549f7365SChris Wilson if (HAS_BLT(dev) && gt_iir & GT_BLT_USER_INTERRUPT) 352549f7365SChris Wilson notify_ring(dev, &dev_priv->blt_ring); 353036a4a7dSZhenyu Wang 35401c66889SZhao Yakui if (de_iir & DE_GSE) 3553b617967SChris Wilson intel_opregion_gse_intr(dev); 35601c66889SZhao Yakui 357f072d2e7SZhenyu Wang if (de_iir & DE_PLANEA_FLIP_DONE) { 358013d5aa2SJesse Barnes intel_prepare_page_flip(dev, 0); 3592bbda389SChris Wilson intel_finish_page_flip_plane(dev, 0); 360013d5aa2SJesse Barnes } 361013d5aa2SJesse Barnes 362f072d2e7SZhenyu Wang if (de_iir & DE_PLANEB_FLIP_DONE) { 363f072d2e7SZhenyu Wang intel_prepare_page_flip(dev, 1); 3642bbda389SChris Wilson intel_finish_page_flip_plane(dev, 1); 365013d5aa2SJesse Barnes } 366c062df61SLi Peng 367f072d2e7SZhenyu Wang if (de_iir & DE_PIPEA_VBLANK) 368f072d2e7SZhenyu Wang drm_handle_vblank(dev, 0); 369f072d2e7SZhenyu Wang 370f072d2e7SZhenyu Wang if (de_iir & DE_PIPEB_VBLANK) 371f072d2e7SZhenyu Wang drm_handle_vblank(dev, 1); 372f072d2e7SZhenyu Wang 373c650156aSZhenyu Wang /* check event from PCH */ 3742d7b8366SYuanhan Liu if ((de_iir & DE_PCH_EVENT) && (pch_iir & hotplug_mask)) 375c650156aSZhenyu Wang queue_work(dev_priv->wq, &dev_priv->hotplug_work); 376c650156aSZhenyu Wang 377f97108d1SJesse Barnes if (de_iir & DE_PCU_EVENT) { 3787648fa99SJesse Barnes I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS)); 379f97108d1SJesse Barnes i915_handle_rps_change(dev); 380f97108d1SJesse Barnes } 381f97108d1SJesse Barnes 382c7c85101SZou Nan hai /* should clear PCH hotplug event before clear CPU irq */ 383c7c85101SZou Nan hai I915_WRITE(SDEIIR, pch_iir); 384c7c85101SZou Nan hai I915_WRITE(GTIIR, gt_iir); 385c7c85101SZou Nan hai I915_WRITE(DEIIR, de_iir); 386036a4a7dSZhenyu Wang 387c7c85101SZou Nan hai done: 3882d109a84SZou, Nanhai I915_WRITE(DEIER, de_ier); 3893143a2bfSChris Wilson POSTING_READ(DEIER); 3902d109a84SZou, Nanhai 391036a4a7dSZhenyu Wang return ret; 392036a4a7dSZhenyu Wang } 393036a4a7dSZhenyu Wang 3948a905236SJesse Barnes /** 3958a905236SJesse Barnes * i915_error_work_func - do process context error handling work 3968a905236SJesse Barnes * @work: work struct 3978a905236SJesse Barnes * 3988a905236SJesse Barnes * Fire an error uevent so userspace can see that a hang or error 3998a905236SJesse Barnes * was detected. 4008a905236SJesse Barnes */ 4018a905236SJesse Barnes static void i915_error_work_func(struct work_struct *work) 4028a905236SJesse Barnes { 4038a905236SJesse Barnes drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t, 4048a905236SJesse Barnes error_work); 4058a905236SJesse Barnes struct drm_device *dev = dev_priv->dev; 406f316a42cSBen Gamari char *error_event[] = { "ERROR=1", NULL }; 407f316a42cSBen Gamari char *reset_event[] = { "RESET=1", NULL }; 408f316a42cSBen Gamari char *reset_done_event[] = { "ERROR=0", NULL }; 4098a905236SJesse Barnes 410f316a42cSBen Gamari kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, error_event); 4118a905236SJesse Barnes 412ba1234d1SBen Gamari if (atomic_read(&dev_priv->mm.wedged)) { 41344d98a61SZhao Yakui DRM_DEBUG_DRIVER("resetting chip\n"); 414f316a42cSBen Gamari kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, reset_event); 415f803aa55SChris Wilson if (!i915_reset(dev, GRDOM_RENDER)) { 416ba1234d1SBen Gamari atomic_set(&dev_priv->mm.wedged, 0); 417f316a42cSBen Gamari kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, reset_done_event); 418f316a42cSBen Gamari } 41930dbf0c0SChris Wilson complete_all(&dev_priv->error_completion); 420f316a42cSBen Gamari } 4218a905236SJesse Barnes } 4228a905236SJesse Barnes 4233bd3c932SChris Wilson #ifdef CONFIG_DEBUG_FS 4249df30794SChris Wilson static struct drm_i915_error_object * 4259df30794SChris Wilson i915_error_object_create(struct drm_device *dev, 426*05394f39SChris Wilson struct drm_i915_gem_object *src) 4279df30794SChris Wilson { 428e56660ddSChris Wilson drm_i915_private_t *dev_priv = dev->dev_private; 4299df30794SChris Wilson struct drm_i915_error_object *dst; 4309df30794SChris Wilson int page, page_count; 431e56660ddSChris Wilson u32 reloc_offset; 4329df30794SChris Wilson 433*05394f39SChris Wilson if (src == NULL || src->pages == NULL) 4349df30794SChris Wilson return NULL; 4359df30794SChris Wilson 436*05394f39SChris Wilson page_count = src->base.size / PAGE_SIZE; 4379df30794SChris Wilson 4389df30794SChris Wilson dst = kmalloc(sizeof(*dst) + page_count * sizeof (u32 *), GFP_ATOMIC); 4399df30794SChris Wilson if (dst == NULL) 4409df30794SChris Wilson return NULL; 4419df30794SChris Wilson 442*05394f39SChris Wilson reloc_offset = src->gtt_offset; 4439df30794SChris Wilson for (page = 0; page < page_count; page++) { 444788885aeSAndrew Morton unsigned long flags; 445e56660ddSChris Wilson void __iomem *s; 446e56660ddSChris Wilson void *d; 447788885aeSAndrew Morton 448e56660ddSChris Wilson d = kmalloc(PAGE_SIZE, GFP_ATOMIC); 4499df30794SChris Wilson if (d == NULL) 4509df30794SChris Wilson goto unwind; 451e56660ddSChris Wilson 452788885aeSAndrew Morton local_irq_save(flags); 453e56660ddSChris Wilson s = io_mapping_map_atomic_wc(dev_priv->mm.gtt_mapping, 4543e4d3af5SPeter Zijlstra reloc_offset); 455e56660ddSChris Wilson memcpy_fromio(d, s, PAGE_SIZE); 4563e4d3af5SPeter Zijlstra io_mapping_unmap_atomic(s); 457788885aeSAndrew Morton local_irq_restore(flags); 458e56660ddSChris Wilson 4599df30794SChris Wilson dst->pages[page] = d; 460e56660ddSChris Wilson 461e56660ddSChris Wilson reloc_offset += PAGE_SIZE; 4629df30794SChris Wilson } 4639df30794SChris Wilson dst->page_count = page_count; 464*05394f39SChris Wilson dst->gtt_offset = src->gtt_offset; 4659df30794SChris Wilson 4669df30794SChris Wilson return dst; 4679df30794SChris Wilson 4689df30794SChris Wilson unwind: 4699df30794SChris Wilson while (page--) 4709df30794SChris Wilson kfree(dst->pages[page]); 4719df30794SChris Wilson kfree(dst); 4729df30794SChris Wilson return NULL; 4739df30794SChris Wilson } 4749df30794SChris Wilson 4759df30794SChris Wilson static void 4769df30794SChris Wilson i915_error_object_free(struct drm_i915_error_object *obj) 4779df30794SChris Wilson { 4789df30794SChris Wilson int page; 4799df30794SChris Wilson 4809df30794SChris Wilson if (obj == NULL) 4819df30794SChris Wilson return; 4829df30794SChris Wilson 4839df30794SChris Wilson for (page = 0; page < obj->page_count; page++) 4849df30794SChris Wilson kfree(obj->pages[page]); 4859df30794SChris Wilson 4869df30794SChris Wilson kfree(obj); 4879df30794SChris Wilson } 4889df30794SChris Wilson 4899df30794SChris Wilson static void 4909df30794SChris Wilson i915_error_state_free(struct drm_device *dev, 4919df30794SChris Wilson struct drm_i915_error_state *error) 4929df30794SChris Wilson { 4939df30794SChris Wilson i915_error_object_free(error->batchbuffer[0]); 4949df30794SChris Wilson i915_error_object_free(error->batchbuffer[1]); 4959df30794SChris Wilson i915_error_object_free(error->ringbuffer); 4969df30794SChris Wilson kfree(error->active_bo); 4976ef3d427SChris Wilson kfree(error->overlay); 4989df30794SChris Wilson kfree(error); 4999df30794SChris Wilson } 5009df30794SChris Wilson 5019df30794SChris Wilson static u32 5029df30794SChris Wilson i915_get_bbaddr(struct drm_device *dev, u32 *ring) 5039df30794SChris Wilson { 5049df30794SChris Wilson u32 cmd; 5059df30794SChris Wilson 5069df30794SChris Wilson if (IS_I830(dev) || IS_845G(dev)) 5079df30794SChris Wilson cmd = MI_BATCH_BUFFER; 508a6c45cf0SChris Wilson else if (INTEL_INFO(dev)->gen >= 4) 5099df30794SChris Wilson cmd = (MI_BATCH_BUFFER_START | (2 << 6) | 5109df30794SChris Wilson MI_BATCH_NON_SECURE_I965); 5119df30794SChris Wilson else 5129df30794SChris Wilson cmd = (MI_BATCH_BUFFER_START | (2 << 6)); 5139df30794SChris Wilson 5149df30794SChris Wilson return ring[0] == cmd ? ring[1] : 0; 5159df30794SChris Wilson } 5169df30794SChris Wilson 5179df30794SChris Wilson static u32 5188168bd48SChris Wilson i915_ringbuffer_last_batch(struct drm_device *dev, 5198168bd48SChris Wilson struct intel_ring_buffer *ring) 5209df30794SChris Wilson { 5219df30794SChris Wilson struct drm_i915_private *dev_priv = dev->dev_private; 5229df30794SChris Wilson u32 head, bbaddr; 5238168bd48SChris Wilson u32 *val; 5249df30794SChris Wilson 5259df30794SChris Wilson /* Locate the current position in the ringbuffer and walk back 5269df30794SChris Wilson * to find the most recently dispatched batch buffer. 5279df30794SChris Wilson */ 5289df30794SChris Wilson bbaddr = 0; 5298168bd48SChris Wilson head = I915_READ_HEAD(ring) & HEAD_ADDR; 5308168bd48SChris Wilson val = (u32 *)(ring->virtual_start + head); 5319df30794SChris Wilson 5328168bd48SChris Wilson while (--val >= (u32 *)ring->virtual_start) { 5338168bd48SChris Wilson bbaddr = i915_get_bbaddr(dev, val); 5349df30794SChris Wilson if (bbaddr) 5359df30794SChris Wilson break; 5369df30794SChris Wilson } 5379df30794SChris Wilson 5389df30794SChris Wilson if (bbaddr == 0) { 5398168bd48SChris Wilson val = (u32 *)(ring->virtual_start + ring->size); 5408168bd48SChris Wilson while (--val >= (u32 *)ring->virtual_start) { 5418168bd48SChris Wilson bbaddr = i915_get_bbaddr(dev, val); 5429df30794SChris Wilson if (bbaddr) 5439df30794SChris Wilson break; 5449df30794SChris Wilson } 5459df30794SChris Wilson } 5469df30794SChris Wilson 5479df30794SChris Wilson return bbaddr; 5489df30794SChris Wilson } 5499df30794SChris Wilson 550c724e8a9SChris Wilson static u32 capture_bo_list(struct drm_i915_error_buffer *err, 551c724e8a9SChris Wilson int count, 552c724e8a9SChris Wilson struct list_head *head) 553c724e8a9SChris Wilson { 554c724e8a9SChris Wilson struct drm_i915_gem_object *obj; 555c724e8a9SChris Wilson int i = 0; 556c724e8a9SChris Wilson 557c724e8a9SChris Wilson list_for_each_entry(obj, head, mm_list) { 558c724e8a9SChris Wilson err->size = obj->base.size; 559c724e8a9SChris Wilson err->name = obj->base.name; 560c724e8a9SChris Wilson err->seqno = obj->last_rendering_seqno; 561c724e8a9SChris Wilson err->gtt_offset = obj->gtt_offset; 562c724e8a9SChris Wilson err->read_domains = obj->base.read_domains; 563c724e8a9SChris Wilson err->write_domain = obj->base.write_domain; 564c724e8a9SChris Wilson err->fence_reg = obj->fence_reg; 565c724e8a9SChris Wilson err->pinned = 0; 566c724e8a9SChris Wilson if (obj->pin_count > 0) 567c724e8a9SChris Wilson err->pinned = 1; 568c724e8a9SChris Wilson if (obj->user_pin_count > 0) 569c724e8a9SChris Wilson err->pinned = -1; 570c724e8a9SChris Wilson err->tiling = obj->tiling_mode; 571c724e8a9SChris Wilson err->dirty = obj->dirty; 572c724e8a9SChris Wilson err->purgeable = obj->madv != I915_MADV_WILLNEED; 5733685092bSChris Wilson err->ring = obj->ring ? obj->ring->id : 0; 574c724e8a9SChris Wilson 575c724e8a9SChris Wilson if (++i == count) 576c724e8a9SChris Wilson break; 577c724e8a9SChris Wilson 578c724e8a9SChris Wilson err++; 579c724e8a9SChris Wilson } 580c724e8a9SChris Wilson 581c724e8a9SChris Wilson return i; 582c724e8a9SChris Wilson } 583c724e8a9SChris Wilson 5848a905236SJesse Barnes /** 5858a905236SJesse Barnes * i915_capture_error_state - capture an error record for later analysis 5868a905236SJesse Barnes * @dev: drm device 5878a905236SJesse Barnes * 5888a905236SJesse Barnes * Should be called when an error is detected (either a hang or an error 5898a905236SJesse Barnes * interrupt) to capture error state from the time of the error. Fills 5908a905236SJesse Barnes * out a structure which becomes available in debugfs for user level tools 5918a905236SJesse Barnes * to pick up. 5928a905236SJesse Barnes */ 59363eeaf38SJesse Barnes static void i915_capture_error_state(struct drm_device *dev) 59463eeaf38SJesse Barnes { 59563eeaf38SJesse Barnes struct drm_i915_private *dev_priv = dev->dev_private; 596*05394f39SChris Wilson struct drm_i915_gem_object *obj; 59763eeaf38SJesse Barnes struct drm_i915_error_state *error; 598*05394f39SChris Wilson struct drm_i915_gem_object *batchbuffer[2]; 59963eeaf38SJesse Barnes unsigned long flags; 6009df30794SChris Wilson u32 bbaddr; 6019df30794SChris Wilson int count; 60263eeaf38SJesse Barnes 60363eeaf38SJesse Barnes spin_lock_irqsave(&dev_priv->error_lock, flags); 6049df30794SChris Wilson error = dev_priv->first_error; 6059df30794SChris Wilson spin_unlock_irqrestore(&dev_priv->error_lock, flags); 6069df30794SChris Wilson if (error) 6079df30794SChris Wilson return; 60863eeaf38SJesse Barnes 60963eeaf38SJesse Barnes error = kmalloc(sizeof(*error), GFP_ATOMIC); 61063eeaf38SJesse Barnes if (!error) { 6119df30794SChris Wilson DRM_DEBUG_DRIVER("out of memory, not capturing error state\n"); 6129df30794SChris Wilson return; 61363eeaf38SJesse Barnes } 61463eeaf38SJesse Barnes 6152fa772f3SChris Wilson DRM_DEBUG_DRIVER("generating error event\n"); 6162fa772f3SChris Wilson 617f787a5f5SChris Wilson error->seqno = 61878501eacSChris Wilson dev_priv->render_ring.get_seqno(&dev_priv->render_ring); 61963eeaf38SJesse Barnes error->eir = I915_READ(EIR); 62063eeaf38SJesse Barnes error->pgtbl_er = I915_READ(PGTBL_ER); 62163eeaf38SJesse Barnes error->pipeastat = I915_READ(PIPEASTAT); 62263eeaf38SJesse Barnes error->pipebstat = I915_READ(PIPEBSTAT); 62363eeaf38SJesse Barnes error->instpm = I915_READ(INSTPM); 624f406839fSChris Wilson error->error = 0; 625f406839fSChris Wilson if (INTEL_INFO(dev)->gen >= 6) { 626f406839fSChris Wilson error->error = I915_READ(ERROR_GEN6); 627add354ddSChris Wilson 6281d8f38f4SChris Wilson error->bcs_acthd = I915_READ(BCS_ACTHD); 6291d8f38f4SChris Wilson error->bcs_ipehr = I915_READ(BCS_IPEHR); 6301d8f38f4SChris Wilson error->bcs_ipeir = I915_READ(BCS_IPEIR); 6311d8f38f4SChris Wilson error->bcs_instdone = I915_READ(BCS_INSTDONE); 6321d8f38f4SChris Wilson error->bcs_seqno = 0; 6331d8f38f4SChris Wilson if (dev_priv->blt_ring.get_seqno) 6341d8f38f4SChris Wilson error->bcs_seqno = dev_priv->blt_ring.get_seqno(&dev_priv->blt_ring); 635add354ddSChris Wilson 636add354ddSChris Wilson error->vcs_acthd = I915_READ(VCS_ACTHD); 637add354ddSChris Wilson error->vcs_ipehr = I915_READ(VCS_IPEHR); 638add354ddSChris Wilson error->vcs_ipeir = I915_READ(VCS_IPEIR); 639add354ddSChris Wilson error->vcs_instdone = I915_READ(VCS_INSTDONE); 640add354ddSChris Wilson error->vcs_seqno = 0; 641add354ddSChris Wilson if (dev_priv->bsd_ring.get_seqno) 642add354ddSChris Wilson error->vcs_seqno = dev_priv->bsd_ring.get_seqno(&dev_priv->bsd_ring); 643f406839fSChris Wilson } 644f406839fSChris Wilson if (INTEL_INFO(dev)->gen >= 4) { 64563eeaf38SJesse Barnes error->ipeir = I915_READ(IPEIR_I965); 64663eeaf38SJesse Barnes error->ipehr = I915_READ(IPEHR_I965); 64763eeaf38SJesse Barnes error->instdone = I915_READ(INSTDONE_I965); 64863eeaf38SJesse Barnes error->instps = I915_READ(INSTPS); 64963eeaf38SJesse Barnes error->instdone1 = I915_READ(INSTDONE1); 65063eeaf38SJesse Barnes error->acthd = I915_READ(ACTHD_I965); 6519df30794SChris Wilson error->bbaddr = I915_READ64(BB_ADDR); 652f406839fSChris Wilson } else { 653f406839fSChris Wilson error->ipeir = I915_READ(IPEIR); 654f406839fSChris Wilson error->ipehr = I915_READ(IPEHR); 655f406839fSChris Wilson error->instdone = I915_READ(INSTDONE); 656f406839fSChris Wilson error->acthd = I915_READ(ACTHD); 657f406839fSChris Wilson error->bbaddr = 0; 6589df30794SChris Wilson } 6599df30794SChris Wilson 6608168bd48SChris Wilson bbaddr = i915_ringbuffer_last_batch(dev, &dev_priv->render_ring); 6619df30794SChris Wilson 6629df30794SChris Wilson /* Grab the current batchbuffer, most likely to have crashed. */ 6639df30794SChris Wilson batchbuffer[0] = NULL; 6649df30794SChris Wilson batchbuffer[1] = NULL; 6659df30794SChris Wilson count = 0; 666*05394f39SChris Wilson list_for_each_entry(obj, &dev_priv->mm.active_list, mm_list) { 6679df30794SChris Wilson if (batchbuffer[0] == NULL && 668*05394f39SChris Wilson bbaddr >= obj->gtt_offset && 669*05394f39SChris Wilson bbaddr < obj->gtt_offset + obj->base.size) 6709df30794SChris Wilson batchbuffer[0] = obj; 6719df30794SChris Wilson 6729df30794SChris Wilson if (batchbuffer[1] == NULL && 673*05394f39SChris Wilson error->acthd >= obj->gtt_offset && 674*05394f39SChris Wilson error->acthd < obj->gtt_offset + obj->base.size) 6759df30794SChris Wilson batchbuffer[1] = obj; 6769df30794SChris Wilson 6779df30794SChris Wilson count++; 6789df30794SChris Wilson } 679e56660ddSChris Wilson /* Scan the other lists for completeness for those bizarre errors. */ 680e56660ddSChris Wilson if (batchbuffer[0] == NULL || batchbuffer[1] == NULL) { 681*05394f39SChris Wilson list_for_each_entry(obj, &dev_priv->mm.flushing_list, mm_list) { 682e56660ddSChris Wilson if (batchbuffer[0] == NULL && 683*05394f39SChris Wilson bbaddr >= obj->gtt_offset && 684*05394f39SChris Wilson bbaddr < obj->gtt_offset + obj->base.size) 685e56660ddSChris Wilson batchbuffer[0] = obj; 686e56660ddSChris Wilson 687e56660ddSChris Wilson if (batchbuffer[1] == NULL && 688*05394f39SChris Wilson error->acthd >= obj->gtt_offset && 689*05394f39SChris Wilson error->acthd < obj->gtt_offset + obj->base.size) 690e56660ddSChris Wilson batchbuffer[1] = obj; 691e56660ddSChris Wilson 692e56660ddSChris Wilson if (batchbuffer[0] && batchbuffer[1]) 693e56660ddSChris Wilson break; 694e56660ddSChris Wilson } 695e56660ddSChris Wilson } 696e56660ddSChris Wilson if (batchbuffer[0] == NULL || batchbuffer[1] == NULL) { 697*05394f39SChris Wilson list_for_each_entry(obj, &dev_priv->mm.inactive_list, mm_list) { 698e56660ddSChris Wilson if (batchbuffer[0] == NULL && 699*05394f39SChris Wilson bbaddr >= obj->gtt_offset && 700*05394f39SChris Wilson bbaddr < obj->gtt_offset + obj->base.size) 701e56660ddSChris Wilson batchbuffer[0] = obj; 702e56660ddSChris Wilson 703e56660ddSChris Wilson if (batchbuffer[1] == NULL && 704*05394f39SChris Wilson error->acthd >= obj->gtt_offset && 705*05394f39SChris Wilson error->acthd < obj->gtt_offset + obj->base.size) 706e56660ddSChris Wilson batchbuffer[1] = obj; 707e56660ddSChris Wilson 708e56660ddSChris Wilson if (batchbuffer[0] && batchbuffer[1]) 709e56660ddSChris Wilson break; 710e56660ddSChris Wilson } 711e56660ddSChris Wilson } 7129df30794SChris Wilson 7139df30794SChris Wilson /* We need to copy these to an anonymous buffer as the simplest 714139d363bSAndrea Gelmini * method to avoid being overwritten by userspace. 7159df30794SChris Wilson */ 7169df30794SChris Wilson error->batchbuffer[0] = i915_error_object_create(dev, batchbuffer[0]); 717e56660ddSChris Wilson if (batchbuffer[1] != batchbuffer[0]) 7189df30794SChris Wilson error->batchbuffer[1] = i915_error_object_create(dev, batchbuffer[1]); 719e56660ddSChris Wilson else 720e56660ddSChris Wilson error->batchbuffer[1] = NULL; 7219df30794SChris Wilson 7229df30794SChris Wilson /* Record the ringbuffer */ 7238187a2b7SZou Nan hai error->ringbuffer = i915_error_object_create(dev, 724*05394f39SChris Wilson dev_priv->render_ring.obj); 7259df30794SChris Wilson 726c724e8a9SChris Wilson /* Record buffers on the active and pinned lists. */ 7279df30794SChris Wilson error->active_bo = NULL; 728c724e8a9SChris Wilson error->pinned_bo = NULL; 7299df30794SChris Wilson 730c724e8a9SChris Wilson error->active_bo_count = count; 731*05394f39SChris Wilson list_for_each_entry(obj, &dev_priv->mm.pinned_list, mm_list) 732c724e8a9SChris Wilson count++; 733c724e8a9SChris Wilson error->pinned_bo_count = count - error->active_bo_count; 734c724e8a9SChris Wilson 735c724e8a9SChris Wilson if (count) { 7369df30794SChris Wilson error->active_bo = kmalloc(sizeof(*error->active_bo)*count, 7379df30794SChris Wilson GFP_ATOMIC); 738c724e8a9SChris Wilson if (error->active_bo) 739c724e8a9SChris Wilson error->pinned_bo = 740c724e8a9SChris Wilson error->active_bo + error->active_bo_count; 7419df30794SChris Wilson } 742c724e8a9SChris Wilson 743c724e8a9SChris Wilson if (error->active_bo) 744c724e8a9SChris Wilson error->active_bo_count = 745c724e8a9SChris Wilson capture_bo_list(error->active_bo, 746c724e8a9SChris Wilson error->active_bo_count, 747c724e8a9SChris Wilson &dev_priv->mm.active_list); 748c724e8a9SChris Wilson 749c724e8a9SChris Wilson if (error->pinned_bo) 750c724e8a9SChris Wilson error->pinned_bo_count = 751c724e8a9SChris Wilson capture_bo_list(error->pinned_bo, 752c724e8a9SChris Wilson error->pinned_bo_count, 753c724e8a9SChris Wilson &dev_priv->mm.pinned_list); 75463eeaf38SJesse Barnes 7558a905236SJesse Barnes do_gettimeofday(&error->time); 7568a905236SJesse Barnes 7576ef3d427SChris Wilson error->overlay = intel_overlay_capture_error_state(dev); 758c4a1d9e4SChris Wilson error->display = intel_display_capture_error_state(dev); 7596ef3d427SChris Wilson 7609df30794SChris Wilson spin_lock_irqsave(&dev_priv->error_lock, flags); 7619df30794SChris Wilson if (dev_priv->first_error == NULL) { 76263eeaf38SJesse Barnes dev_priv->first_error = error; 7639df30794SChris Wilson error = NULL; 7649df30794SChris Wilson } 76563eeaf38SJesse Barnes spin_unlock_irqrestore(&dev_priv->error_lock, flags); 7669df30794SChris Wilson 7679df30794SChris Wilson if (error) 7689df30794SChris Wilson i915_error_state_free(dev, error); 7699df30794SChris Wilson } 7709df30794SChris Wilson 7719df30794SChris Wilson void i915_destroy_error_state(struct drm_device *dev) 7729df30794SChris Wilson { 7739df30794SChris Wilson struct drm_i915_private *dev_priv = dev->dev_private; 7749df30794SChris Wilson struct drm_i915_error_state *error; 7759df30794SChris Wilson 7769df30794SChris Wilson spin_lock(&dev_priv->error_lock); 7779df30794SChris Wilson error = dev_priv->first_error; 7789df30794SChris Wilson dev_priv->first_error = NULL; 7799df30794SChris Wilson spin_unlock(&dev_priv->error_lock); 7809df30794SChris Wilson 7819df30794SChris Wilson if (error) 7829df30794SChris Wilson i915_error_state_free(dev, error); 78363eeaf38SJesse Barnes } 7843bd3c932SChris Wilson #else 7853bd3c932SChris Wilson #define i915_capture_error_state(x) 7863bd3c932SChris Wilson #endif 78763eeaf38SJesse Barnes 78835aed2e6SChris Wilson static void i915_report_and_clear_eir(struct drm_device *dev) 789c0e09200SDave Airlie { 7908a905236SJesse Barnes struct drm_i915_private *dev_priv = dev->dev_private; 79163eeaf38SJesse Barnes u32 eir = I915_READ(EIR); 79263eeaf38SJesse Barnes 79335aed2e6SChris Wilson if (!eir) 79435aed2e6SChris Wilson return; 79563eeaf38SJesse Barnes 79663eeaf38SJesse Barnes printk(KERN_ERR "render error detected, EIR: 0x%08x\n", 79763eeaf38SJesse Barnes eir); 7988a905236SJesse Barnes 7998a905236SJesse Barnes if (IS_G4X(dev)) { 8008a905236SJesse Barnes if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) { 8018a905236SJesse Barnes u32 ipeir = I915_READ(IPEIR_I965); 8028a905236SJesse Barnes 8038a905236SJesse Barnes printk(KERN_ERR " IPEIR: 0x%08x\n", 8048a905236SJesse Barnes I915_READ(IPEIR_I965)); 8058a905236SJesse Barnes printk(KERN_ERR " IPEHR: 0x%08x\n", 8068a905236SJesse Barnes I915_READ(IPEHR_I965)); 8078a905236SJesse Barnes printk(KERN_ERR " INSTDONE: 0x%08x\n", 8088a905236SJesse Barnes I915_READ(INSTDONE_I965)); 8098a905236SJesse Barnes printk(KERN_ERR " INSTPS: 0x%08x\n", 8108a905236SJesse Barnes I915_READ(INSTPS)); 8118a905236SJesse Barnes printk(KERN_ERR " INSTDONE1: 0x%08x\n", 8128a905236SJesse Barnes I915_READ(INSTDONE1)); 8138a905236SJesse Barnes printk(KERN_ERR " ACTHD: 0x%08x\n", 8148a905236SJesse Barnes I915_READ(ACTHD_I965)); 8158a905236SJesse Barnes I915_WRITE(IPEIR_I965, ipeir); 8163143a2bfSChris Wilson POSTING_READ(IPEIR_I965); 8178a905236SJesse Barnes } 8188a905236SJesse Barnes if (eir & GM45_ERROR_PAGE_TABLE) { 8198a905236SJesse Barnes u32 pgtbl_err = I915_READ(PGTBL_ER); 8208a905236SJesse Barnes printk(KERN_ERR "page table error\n"); 8218a905236SJesse Barnes printk(KERN_ERR " PGTBL_ER: 0x%08x\n", 8228a905236SJesse Barnes pgtbl_err); 8238a905236SJesse Barnes I915_WRITE(PGTBL_ER, pgtbl_err); 8243143a2bfSChris Wilson POSTING_READ(PGTBL_ER); 8258a905236SJesse Barnes } 8268a905236SJesse Barnes } 8278a905236SJesse Barnes 828a6c45cf0SChris Wilson if (!IS_GEN2(dev)) { 82963eeaf38SJesse Barnes if (eir & I915_ERROR_PAGE_TABLE) { 83063eeaf38SJesse Barnes u32 pgtbl_err = I915_READ(PGTBL_ER); 83163eeaf38SJesse Barnes printk(KERN_ERR "page table error\n"); 83263eeaf38SJesse Barnes printk(KERN_ERR " PGTBL_ER: 0x%08x\n", 83363eeaf38SJesse Barnes pgtbl_err); 83463eeaf38SJesse Barnes I915_WRITE(PGTBL_ER, pgtbl_err); 8353143a2bfSChris Wilson POSTING_READ(PGTBL_ER); 83663eeaf38SJesse Barnes } 8378a905236SJesse Barnes } 8388a905236SJesse Barnes 83963eeaf38SJesse Barnes if (eir & I915_ERROR_MEMORY_REFRESH) { 84035aed2e6SChris Wilson u32 pipea_stats = I915_READ(PIPEASTAT); 84135aed2e6SChris Wilson u32 pipeb_stats = I915_READ(PIPEBSTAT); 84235aed2e6SChris Wilson 84363eeaf38SJesse Barnes printk(KERN_ERR "memory refresh error\n"); 84463eeaf38SJesse Barnes printk(KERN_ERR "PIPEASTAT: 0x%08x\n", 84563eeaf38SJesse Barnes pipea_stats); 84663eeaf38SJesse Barnes printk(KERN_ERR "PIPEBSTAT: 0x%08x\n", 84763eeaf38SJesse Barnes pipeb_stats); 84863eeaf38SJesse Barnes /* pipestat has already been acked */ 84963eeaf38SJesse Barnes } 85063eeaf38SJesse Barnes if (eir & I915_ERROR_INSTRUCTION) { 85163eeaf38SJesse Barnes printk(KERN_ERR "instruction error\n"); 85263eeaf38SJesse Barnes printk(KERN_ERR " INSTPM: 0x%08x\n", 85363eeaf38SJesse Barnes I915_READ(INSTPM)); 854a6c45cf0SChris Wilson if (INTEL_INFO(dev)->gen < 4) { 85563eeaf38SJesse Barnes u32 ipeir = I915_READ(IPEIR); 85663eeaf38SJesse Barnes 85763eeaf38SJesse Barnes printk(KERN_ERR " IPEIR: 0x%08x\n", 85863eeaf38SJesse Barnes I915_READ(IPEIR)); 85963eeaf38SJesse Barnes printk(KERN_ERR " IPEHR: 0x%08x\n", 86063eeaf38SJesse Barnes I915_READ(IPEHR)); 86163eeaf38SJesse Barnes printk(KERN_ERR " INSTDONE: 0x%08x\n", 86263eeaf38SJesse Barnes I915_READ(INSTDONE)); 86363eeaf38SJesse Barnes printk(KERN_ERR " ACTHD: 0x%08x\n", 86463eeaf38SJesse Barnes I915_READ(ACTHD)); 86563eeaf38SJesse Barnes I915_WRITE(IPEIR, ipeir); 8663143a2bfSChris Wilson POSTING_READ(IPEIR); 86763eeaf38SJesse Barnes } else { 86863eeaf38SJesse Barnes u32 ipeir = I915_READ(IPEIR_I965); 86963eeaf38SJesse Barnes 87063eeaf38SJesse Barnes printk(KERN_ERR " IPEIR: 0x%08x\n", 87163eeaf38SJesse Barnes I915_READ(IPEIR_I965)); 87263eeaf38SJesse Barnes printk(KERN_ERR " IPEHR: 0x%08x\n", 87363eeaf38SJesse Barnes I915_READ(IPEHR_I965)); 87463eeaf38SJesse Barnes printk(KERN_ERR " INSTDONE: 0x%08x\n", 87563eeaf38SJesse Barnes I915_READ(INSTDONE_I965)); 87663eeaf38SJesse Barnes printk(KERN_ERR " INSTPS: 0x%08x\n", 87763eeaf38SJesse Barnes I915_READ(INSTPS)); 87863eeaf38SJesse Barnes printk(KERN_ERR " INSTDONE1: 0x%08x\n", 87963eeaf38SJesse Barnes I915_READ(INSTDONE1)); 88063eeaf38SJesse Barnes printk(KERN_ERR " ACTHD: 0x%08x\n", 88163eeaf38SJesse Barnes I915_READ(ACTHD_I965)); 88263eeaf38SJesse Barnes I915_WRITE(IPEIR_I965, ipeir); 8833143a2bfSChris Wilson POSTING_READ(IPEIR_I965); 88463eeaf38SJesse Barnes } 88563eeaf38SJesse Barnes } 88663eeaf38SJesse Barnes 88763eeaf38SJesse Barnes I915_WRITE(EIR, eir); 8883143a2bfSChris Wilson POSTING_READ(EIR); 88963eeaf38SJesse Barnes eir = I915_READ(EIR); 89063eeaf38SJesse Barnes if (eir) { 89163eeaf38SJesse Barnes /* 89263eeaf38SJesse Barnes * some errors might have become stuck, 89363eeaf38SJesse Barnes * mask them. 89463eeaf38SJesse Barnes */ 89563eeaf38SJesse Barnes DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir); 89663eeaf38SJesse Barnes I915_WRITE(EMR, I915_READ(EMR) | eir); 89763eeaf38SJesse Barnes I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); 89863eeaf38SJesse Barnes } 89935aed2e6SChris Wilson } 90035aed2e6SChris Wilson 90135aed2e6SChris Wilson /** 90235aed2e6SChris Wilson * i915_handle_error - handle an error interrupt 90335aed2e6SChris Wilson * @dev: drm device 90435aed2e6SChris Wilson * 90535aed2e6SChris Wilson * Do some basic checking of regsiter state at error interrupt time and 90635aed2e6SChris Wilson * dump it to the syslog. Also call i915_capture_error_state() to make 90735aed2e6SChris Wilson * sure we get a record and make it available in debugfs. Fire a uevent 90835aed2e6SChris Wilson * so userspace knows something bad happened (should trigger collection 90935aed2e6SChris Wilson * of a ring dump etc.). 91035aed2e6SChris Wilson */ 911527f9e90SChris Wilson void i915_handle_error(struct drm_device *dev, bool wedged) 91235aed2e6SChris Wilson { 91335aed2e6SChris Wilson struct drm_i915_private *dev_priv = dev->dev_private; 91435aed2e6SChris Wilson 91535aed2e6SChris Wilson i915_capture_error_state(dev); 91635aed2e6SChris Wilson i915_report_and_clear_eir(dev); 9178a905236SJesse Barnes 918ba1234d1SBen Gamari if (wedged) { 91930dbf0c0SChris Wilson INIT_COMPLETION(dev_priv->error_completion); 920ba1234d1SBen Gamari atomic_set(&dev_priv->mm.wedged, 1); 921ba1234d1SBen Gamari 92211ed50ecSBen Gamari /* 92311ed50ecSBen Gamari * Wakeup waiting processes so they don't hang 92411ed50ecSBen Gamari */ 925f787a5f5SChris Wilson wake_up_all(&dev_priv->render_ring.irq_queue); 926f787a5f5SChris Wilson if (HAS_BSD(dev)) 927f787a5f5SChris Wilson wake_up_all(&dev_priv->bsd_ring.irq_queue); 928549f7365SChris Wilson if (HAS_BLT(dev)) 929549f7365SChris Wilson wake_up_all(&dev_priv->blt_ring.irq_queue); 93011ed50ecSBen Gamari } 93111ed50ecSBen Gamari 9329c9fe1f8SEric Anholt queue_work(dev_priv->wq, &dev_priv->error_work); 9338a905236SJesse Barnes } 9348a905236SJesse Barnes 9354e5359cdSSimon Farnsworth static void i915_pageflip_stall_check(struct drm_device *dev, int pipe) 9364e5359cdSSimon Farnsworth { 9374e5359cdSSimon Farnsworth drm_i915_private_t *dev_priv = dev->dev_private; 9384e5359cdSSimon Farnsworth struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; 9394e5359cdSSimon Farnsworth struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 940*05394f39SChris Wilson struct drm_i915_gem_object *obj; 9414e5359cdSSimon Farnsworth struct intel_unpin_work *work; 9424e5359cdSSimon Farnsworth unsigned long flags; 9434e5359cdSSimon Farnsworth bool stall_detected; 9444e5359cdSSimon Farnsworth 9454e5359cdSSimon Farnsworth /* Ignore early vblank irqs */ 9464e5359cdSSimon Farnsworth if (intel_crtc == NULL) 9474e5359cdSSimon Farnsworth return; 9484e5359cdSSimon Farnsworth 9494e5359cdSSimon Farnsworth spin_lock_irqsave(&dev->event_lock, flags); 9504e5359cdSSimon Farnsworth work = intel_crtc->unpin_work; 9514e5359cdSSimon Farnsworth 9524e5359cdSSimon Farnsworth if (work == NULL || work->pending || !work->enable_stall_check) { 9534e5359cdSSimon Farnsworth /* Either the pending flip IRQ arrived, or we're too early. Don't check */ 9544e5359cdSSimon Farnsworth spin_unlock_irqrestore(&dev->event_lock, flags); 9554e5359cdSSimon Farnsworth return; 9564e5359cdSSimon Farnsworth } 9574e5359cdSSimon Farnsworth 9584e5359cdSSimon Farnsworth /* Potential stall - if we see that the flip has happened, assume a missed interrupt */ 959*05394f39SChris Wilson obj = work->pending_flip_obj; 960a6c45cf0SChris Wilson if (INTEL_INFO(dev)->gen >= 4) { 9614e5359cdSSimon Farnsworth int dspsurf = intel_crtc->plane == 0 ? DSPASURF : DSPBSURF; 962*05394f39SChris Wilson stall_detected = I915_READ(dspsurf) == obj->gtt_offset; 9634e5359cdSSimon Farnsworth } else { 9644e5359cdSSimon Farnsworth int dspaddr = intel_crtc->plane == 0 ? DSPAADDR : DSPBADDR; 965*05394f39SChris Wilson stall_detected = I915_READ(dspaddr) == (obj->gtt_offset + 9664e5359cdSSimon Farnsworth crtc->y * crtc->fb->pitch + 9674e5359cdSSimon Farnsworth crtc->x * crtc->fb->bits_per_pixel/8); 9684e5359cdSSimon Farnsworth } 9694e5359cdSSimon Farnsworth 9704e5359cdSSimon Farnsworth spin_unlock_irqrestore(&dev->event_lock, flags); 9714e5359cdSSimon Farnsworth 9724e5359cdSSimon Farnsworth if (stall_detected) { 9734e5359cdSSimon Farnsworth DRM_DEBUG_DRIVER("Pageflip stall detected\n"); 9744e5359cdSSimon Farnsworth intel_prepare_page_flip(dev, intel_crtc->plane); 9754e5359cdSSimon Farnsworth } 9764e5359cdSSimon Farnsworth } 9774e5359cdSSimon Farnsworth 9788a905236SJesse Barnes irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS) 9798a905236SJesse Barnes { 9808a905236SJesse Barnes struct drm_device *dev = (struct drm_device *) arg; 9818a905236SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 9828a905236SJesse Barnes struct drm_i915_master_private *master_priv; 9838a905236SJesse Barnes u32 iir, new_iir; 9848a905236SJesse Barnes u32 pipea_stats, pipeb_stats; 9858a905236SJesse Barnes u32 vblank_status; 9868a905236SJesse Barnes int vblank = 0; 9878a905236SJesse Barnes unsigned long irqflags; 9888a905236SJesse Barnes int irq_received; 9898a905236SJesse Barnes int ret = IRQ_NONE; 9908a905236SJesse Barnes 9918a905236SJesse Barnes atomic_inc(&dev_priv->irq_received); 9928a905236SJesse Barnes 993bad720ffSEric Anholt if (HAS_PCH_SPLIT(dev)) 994f2b115e6SAdam Jackson return ironlake_irq_handler(dev); 9958a905236SJesse Barnes 9968a905236SJesse Barnes iir = I915_READ(IIR); 9978a905236SJesse Barnes 998a6c45cf0SChris Wilson if (INTEL_INFO(dev)->gen >= 4) 999d874bcffSJesse Barnes vblank_status = PIPE_START_VBLANK_INTERRUPT_STATUS; 1000e25e6601SJesse Barnes else 1001d874bcffSJesse Barnes vblank_status = PIPE_VBLANK_INTERRUPT_STATUS; 10028a905236SJesse Barnes 10038a905236SJesse Barnes for (;;) { 10048a905236SJesse Barnes irq_received = iir != 0; 10058a905236SJesse Barnes 10068a905236SJesse Barnes /* Can't rely on pipestat interrupt bit in iir as it might 10078a905236SJesse Barnes * have been cleared after the pipestat interrupt was received. 10088a905236SJesse Barnes * It doesn't set the bit in iir again, but it still produces 10098a905236SJesse Barnes * interrupts (for non-MSI). 10108a905236SJesse Barnes */ 10118a905236SJesse Barnes spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags); 10128a905236SJesse Barnes pipea_stats = I915_READ(PIPEASTAT); 10138a905236SJesse Barnes pipeb_stats = I915_READ(PIPEBSTAT); 10148a905236SJesse Barnes 10158a905236SJesse Barnes if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) 1016ba1234d1SBen Gamari i915_handle_error(dev, false); 10178a905236SJesse Barnes 10188a905236SJesse Barnes /* 10198a905236SJesse Barnes * Clear the PIPE(A|B)STAT regs before the IIR 10208a905236SJesse Barnes */ 10218a905236SJesse Barnes if (pipea_stats & 0x8000ffff) { 10228a905236SJesse Barnes if (pipea_stats & PIPE_FIFO_UNDERRUN_STATUS) 102344d98a61SZhao Yakui DRM_DEBUG_DRIVER("pipe a underrun\n"); 10248a905236SJesse Barnes I915_WRITE(PIPEASTAT, pipea_stats); 10258a905236SJesse Barnes irq_received = 1; 10268a905236SJesse Barnes } 10278a905236SJesse Barnes 10288a905236SJesse Barnes if (pipeb_stats & 0x8000ffff) { 10298a905236SJesse Barnes if (pipeb_stats & PIPE_FIFO_UNDERRUN_STATUS) 103044d98a61SZhao Yakui DRM_DEBUG_DRIVER("pipe b underrun\n"); 10318a905236SJesse Barnes I915_WRITE(PIPEBSTAT, pipeb_stats); 10328a905236SJesse Barnes irq_received = 1; 10338a905236SJesse Barnes } 10348a905236SJesse Barnes spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags); 10358a905236SJesse Barnes 10368a905236SJesse Barnes if (!irq_received) 10378a905236SJesse Barnes break; 10388a905236SJesse Barnes 10398a905236SJesse Barnes ret = IRQ_HANDLED; 10408a905236SJesse Barnes 10418a905236SJesse Barnes /* Consume port. Then clear IIR or we'll miss events */ 10428a905236SJesse Barnes if ((I915_HAS_HOTPLUG(dev)) && 10438a905236SJesse Barnes (iir & I915_DISPLAY_PORT_INTERRUPT)) { 10448a905236SJesse Barnes u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT); 10458a905236SJesse Barnes 104644d98a61SZhao Yakui DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n", 10478a905236SJesse Barnes hotplug_status); 10488a905236SJesse Barnes if (hotplug_status & dev_priv->hotplug_supported_mask) 10499c9fe1f8SEric Anholt queue_work(dev_priv->wq, 10509c9fe1f8SEric Anholt &dev_priv->hotplug_work); 10518a905236SJesse Barnes 10528a905236SJesse Barnes I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status); 10538a905236SJesse Barnes I915_READ(PORT_HOTPLUG_STAT); 105463eeaf38SJesse Barnes } 105563eeaf38SJesse Barnes 1056673a394bSEric Anholt I915_WRITE(IIR, iir); 1057cdfbc41fSEric Anholt new_iir = I915_READ(IIR); /* Flush posted writes */ 10587c463586SKeith Packard 10597c1c2871SDave Airlie if (dev->primary->master) { 10607c1c2871SDave Airlie master_priv = dev->primary->master->driver_priv; 10617c1c2871SDave Airlie if (master_priv->sarea_priv) 10627c1c2871SDave Airlie master_priv->sarea_priv->last_dispatch = 1063c99b058fSKristian Høgsberg READ_BREADCRUMB(dev_priv); 10647c1c2871SDave Airlie } 10650a3e67a4SJesse Barnes 1066549f7365SChris Wilson if (iir & I915_USER_INTERRUPT) 1067549f7365SChris Wilson notify_ring(dev, &dev_priv->render_ring); 1068d1b851fcSZou Nan hai if (HAS_BSD(dev) && (iir & I915_BSD_USER_INTERRUPT)) 1069549f7365SChris Wilson notify_ring(dev, &dev_priv->bsd_ring); 1070d1b851fcSZou Nan hai 10711afe3e9dSJesse Barnes if (iir & I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT) { 10726b95a207SKristian Høgsberg intel_prepare_page_flip(dev, 0); 10731afe3e9dSJesse Barnes if (dev_priv->flip_pending_is_done) 10741afe3e9dSJesse Barnes intel_finish_page_flip_plane(dev, 0); 10751afe3e9dSJesse Barnes } 10766b95a207SKristian Høgsberg 10771afe3e9dSJesse Barnes if (iir & I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT) { 107870565d00SJesse Barnes intel_prepare_page_flip(dev, 1); 10791afe3e9dSJesse Barnes if (dev_priv->flip_pending_is_done) 10801afe3e9dSJesse Barnes intel_finish_page_flip_plane(dev, 1); 10811afe3e9dSJesse Barnes } 10826b95a207SKristian Høgsberg 108305eff845SKeith Packard if (pipea_stats & vblank_status) { 10847c463586SKeith Packard vblank++; 10857c463586SKeith Packard drm_handle_vblank(dev, 0); 10864e5359cdSSimon Farnsworth if (!dev_priv->flip_pending_is_done) { 10874e5359cdSSimon Farnsworth i915_pageflip_stall_check(dev, 0); 10886b95a207SKristian Høgsberg intel_finish_page_flip(dev, 0); 10897c463586SKeith Packard } 10904e5359cdSSimon Farnsworth } 10917c463586SKeith Packard 109205eff845SKeith Packard if (pipeb_stats & vblank_status) { 10937c463586SKeith Packard vblank++; 10947c463586SKeith Packard drm_handle_vblank(dev, 1); 10954e5359cdSSimon Farnsworth if (!dev_priv->flip_pending_is_done) { 10964e5359cdSSimon Farnsworth i915_pageflip_stall_check(dev, 1); 10976b95a207SKristian Høgsberg intel_finish_page_flip(dev, 1); 10987c463586SKeith Packard } 10994e5359cdSSimon Farnsworth } 11007c463586SKeith Packard 1101d874bcffSJesse Barnes if ((pipea_stats & PIPE_LEGACY_BLC_EVENT_STATUS) || 1102d874bcffSJesse Barnes (pipeb_stats & PIPE_LEGACY_BLC_EVENT_STATUS) || 11037c463586SKeith Packard (iir & I915_ASLE_INTERRUPT)) 11043b617967SChris Wilson intel_opregion_asle_intr(dev); 11050a3e67a4SJesse Barnes 1106cdfbc41fSEric Anholt /* With MSI, interrupts are only generated when iir 1107cdfbc41fSEric Anholt * transitions from zero to nonzero. If another bit got 1108cdfbc41fSEric Anholt * set while we were handling the existing iir bits, then 1109cdfbc41fSEric Anholt * we would never get another interrupt. 1110cdfbc41fSEric Anholt * 1111cdfbc41fSEric Anholt * This is fine on non-MSI as well, as if we hit this path 1112cdfbc41fSEric Anholt * we avoid exiting the interrupt handler only to generate 1113cdfbc41fSEric Anholt * another one. 1114cdfbc41fSEric Anholt * 1115cdfbc41fSEric Anholt * Note that for MSI this could cause a stray interrupt report 1116cdfbc41fSEric Anholt * if an interrupt landed in the time between writing IIR and 1117cdfbc41fSEric Anholt * the posting read. This should be rare enough to never 1118cdfbc41fSEric Anholt * trigger the 99% of 100,000 interrupts test for disabling 1119cdfbc41fSEric Anholt * stray interrupts. 1120cdfbc41fSEric Anholt */ 1121cdfbc41fSEric Anholt iir = new_iir; 112205eff845SKeith Packard } 1123cdfbc41fSEric Anholt 112405eff845SKeith Packard return ret; 1125c0e09200SDave Airlie } 1126c0e09200SDave Airlie 1127c0e09200SDave Airlie static int i915_emit_irq(struct drm_device * dev) 1128c0e09200SDave Airlie { 1129c0e09200SDave Airlie drm_i915_private_t *dev_priv = dev->dev_private; 11307c1c2871SDave Airlie struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv; 1131c0e09200SDave Airlie 1132c0e09200SDave Airlie i915_kernel_lost_context(dev); 1133c0e09200SDave Airlie 113444d98a61SZhao Yakui DRM_DEBUG_DRIVER("\n"); 1135c0e09200SDave Airlie 1136c99b058fSKristian Høgsberg dev_priv->counter++; 1137c0e09200SDave Airlie if (dev_priv->counter > 0x7FFFFFFFUL) 1138c99b058fSKristian Høgsberg dev_priv->counter = 1; 11397c1c2871SDave Airlie if (master_priv->sarea_priv) 11407c1c2871SDave Airlie master_priv->sarea_priv->last_enqueue = dev_priv->counter; 1141c0e09200SDave Airlie 1142e1f99ce6SChris Wilson if (BEGIN_LP_RING(4) == 0) { 1143585fb111SJesse Barnes OUT_RING(MI_STORE_DWORD_INDEX); 11440baf823aSKeith Packard OUT_RING(I915_BREADCRUMB_INDEX << MI_STORE_DWORD_INDEX_SHIFT); 1145c0e09200SDave Airlie OUT_RING(dev_priv->counter); 1146585fb111SJesse Barnes OUT_RING(MI_USER_INTERRUPT); 1147c0e09200SDave Airlie ADVANCE_LP_RING(); 1148e1f99ce6SChris Wilson } 1149c0e09200SDave Airlie 1150c0e09200SDave Airlie return dev_priv->counter; 1151c0e09200SDave Airlie } 1152c0e09200SDave Airlie 11539d34e5dbSChris Wilson void i915_trace_irq_get(struct drm_device *dev, u32 seqno) 11549d34e5dbSChris Wilson { 11559d34e5dbSChris Wilson drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 11568187a2b7SZou Nan hai struct intel_ring_buffer *render_ring = &dev_priv->render_ring; 11579d34e5dbSChris Wilson 11589d34e5dbSChris Wilson if (dev_priv->trace_irq_seqno == 0) 115978501eacSChris Wilson render_ring->user_irq_get(render_ring); 11609d34e5dbSChris Wilson 11619d34e5dbSChris Wilson dev_priv->trace_irq_seqno = seqno; 11629d34e5dbSChris Wilson } 11639d34e5dbSChris Wilson 1164c0e09200SDave Airlie static int i915_wait_irq(struct drm_device * dev, int irq_nr) 1165c0e09200SDave Airlie { 1166c0e09200SDave Airlie drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 11677c1c2871SDave Airlie struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv; 1168c0e09200SDave Airlie int ret = 0; 11698187a2b7SZou Nan hai struct intel_ring_buffer *render_ring = &dev_priv->render_ring; 1170c0e09200SDave Airlie 117144d98a61SZhao Yakui DRM_DEBUG_DRIVER("irq_nr=%d breadcrumb=%d\n", irq_nr, 1172c0e09200SDave Airlie READ_BREADCRUMB(dev_priv)); 1173c0e09200SDave Airlie 1174ed4cb414SEric Anholt if (READ_BREADCRUMB(dev_priv) >= irq_nr) { 11757c1c2871SDave Airlie if (master_priv->sarea_priv) 11767c1c2871SDave Airlie master_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv); 1177c0e09200SDave Airlie return 0; 1178ed4cb414SEric Anholt } 1179c0e09200SDave Airlie 11807c1c2871SDave Airlie if (master_priv->sarea_priv) 11817c1c2871SDave Airlie master_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT; 1182c0e09200SDave Airlie 118378501eacSChris Wilson render_ring->user_irq_get(render_ring); 1184852835f3SZou Nan hai DRM_WAIT_ON(ret, dev_priv->render_ring.irq_queue, 3 * DRM_HZ, 1185c0e09200SDave Airlie READ_BREADCRUMB(dev_priv) >= irq_nr); 118678501eacSChris Wilson render_ring->user_irq_put(render_ring); 1187c0e09200SDave Airlie 1188c0e09200SDave Airlie if (ret == -EBUSY) { 1189c0e09200SDave Airlie DRM_ERROR("EBUSY -- rec: %d emitted: %d\n", 1190c0e09200SDave Airlie READ_BREADCRUMB(dev_priv), (int)dev_priv->counter); 1191c0e09200SDave Airlie } 1192c0e09200SDave Airlie 1193c0e09200SDave Airlie return ret; 1194c0e09200SDave Airlie } 1195c0e09200SDave Airlie 1196c0e09200SDave Airlie /* Needs the lock as it touches the ring. 1197c0e09200SDave Airlie */ 1198c0e09200SDave Airlie int i915_irq_emit(struct drm_device *dev, void *data, 1199c0e09200SDave Airlie struct drm_file *file_priv) 1200c0e09200SDave Airlie { 1201c0e09200SDave Airlie drm_i915_private_t *dev_priv = dev->dev_private; 1202c0e09200SDave Airlie drm_i915_irq_emit_t *emit = data; 1203c0e09200SDave Airlie int result; 1204c0e09200SDave Airlie 1205d3301d86SEric Anholt if (!dev_priv || !dev_priv->render_ring.virtual_start) { 1206c0e09200SDave Airlie DRM_ERROR("called with no initialization\n"); 1207c0e09200SDave Airlie return -EINVAL; 1208c0e09200SDave Airlie } 1209299eb93cSEric Anholt 1210299eb93cSEric Anholt RING_LOCK_TEST_WITH_RETURN(dev, file_priv); 1211299eb93cSEric Anholt 1212546b0974SEric Anholt mutex_lock(&dev->struct_mutex); 1213c0e09200SDave Airlie result = i915_emit_irq(dev); 1214546b0974SEric Anholt mutex_unlock(&dev->struct_mutex); 1215c0e09200SDave Airlie 1216c0e09200SDave Airlie if (DRM_COPY_TO_USER(emit->irq_seq, &result, sizeof(int))) { 1217c0e09200SDave Airlie DRM_ERROR("copy_to_user\n"); 1218c0e09200SDave Airlie return -EFAULT; 1219c0e09200SDave Airlie } 1220c0e09200SDave Airlie 1221c0e09200SDave Airlie return 0; 1222c0e09200SDave Airlie } 1223c0e09200SDave Airlie 1224c0e09200SDave Airlie /* Doesn't need the hardware lock. 1225c0e09200SDave Airlie */ 1226c0e09200SDave Airlie int i915_irq_wait(struct drm_device *dev, void *data, 1227c0e09200SDave Airlie struct drm_file *file_priv) 1228c0e09200SDave Airlie { 1229c0e09200SDave Airlie drm_i915_private_t *dev_priv = dev->dev_private; 1230c0e09200SDave Airlie drm_i915_irq_wait_t *irqwait = data; 1231c0e09200SDave Airlie 1232c0e09200SDave Airlie if (!dev_priv) { 1233c0e09200SDave Airlie DRM_ERROR("called with no initialization\n"); 1234c0e09200SDave Airlie return -EINVAL; 1235c0e09200SDave Airlie } 1236c0e09200SDave Airlie 1237c0e09200SDave Airlie return i915_wait_irq(dev, irqwait->irq_seq); 1238c0e09200SDave Airlie } 1239c0e09200SDave Airlie 124042f52ef8SKeith Packard /* Called from drm generic code, passed 'crtc' which 124142f52ef8SKeith Packard * we use as a pipe index 124242f52ef8SKeith Packard */ 124342f52ef8SKeith Packard int i915_enable_vblank(struct drm_device *dev, int pipe) 12440a3e67a4SJesse Barnes { 12450a3e67a4SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 1246e9d21d7fSKeith Packard unsigned long irqflags; 124771e0ffa5SJesse Barnes 12485eddb70bSChris Wilson if (!i915_pipe_enabled(dev, pipe)) 124971e0ffa5SJesse Barnes return -EINVAL; 12500a3e67a4SJesse Barnes 1251e9d21d7fSKeith Packard spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags); 1252bad720ffSEric Anholt if (HAS_PCH_SPLIT(dev)) 1253c062df61SLi Peng ironlake_enable_display_irq(dev_priv, (pipe == 0) ? 1254c062df61SLi Peng DE_PIPEA_VBLANK: DE_PIPEB_VBLANK); 1255a6c45cf0SChris Wilson else if (INTEL_INFO(dev)->gen >= 4) 12567c463586SKeith Packard i915_enable_pipestat(dev_priv, pipe, 12577c463586SKeith Packard PIPE_START_VBLANK_INTERRUPT_ENABLE); 12580a3e67a4SJesse Barnes else 12597c463586SKeith Packard i915_enable_pipestat(dev_priv, pipe, 12607c463586SKeith Packard PIPE_VBLANK_INTERRUPT_ENABLE); 1261e9d21d7fSKeith Packard spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags); 12620a3e67a4SJesse Barnes return 0; 12630a3e67a4SJesse Barnes } 12640a3e67a4SJesse Barnes 126542f52ef8SKeith Packard /* Called from drm generic code, passed 'crtc' which 126642f52ef8SKeith Packard * we use as a pipe index 126742f52ef8SKeith Packard */ 126842f52ef8SKeith Packard void i915_disable_vblank(struct drm_device *dev, int pipe) 12690a3e67a4SJesse Barnes { 12700a3e67a4SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 1271e9d21d7fSKeith Packard unsigned long irqflags; 12720a3e67a4SJesse Barnes 1273e9d21d7fSKeith Packard spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags); 1274bad720ffSEric Anholt if (HAS_PCH_SPLIT(dev)) 1275c062df61SLi Peng ironlake_disable_display_irq(dev_priv, (pipe == 0) ? 1276c062df61SLi Peng DE_PIPEA_VBLANK: DE_PIPEB_VBLANK); 1277c062df61SLi Peng else 12787c463586SKeith Packard i915_disable_pipestat(dev_priv, pipe, 12797c463586SKeith Packard PIPE_VBLANK_INTERRUPT_ENABLE | 12807c463586SKeith Packard PIPE_START_VBLANK_INTERRUPT_ENABLE); 1281e9d21d7fSKeith Packard spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags); 12820a3e67a4SJesse Barnes } 12830a3e67a4SJesse Barnes 128479e53945SJesse Barnes void i915_enable_interrupt (struct drm_device *dev) 128579e53945SJesse Barnes { 128679e53945SJesse Barnes struct drm_i915_private *dev_priv = dev->dev_private; 1287e170b030SZhenyu Wang 1288bad720ffSEric Anholt if (!HAS_PCH_SPLIT(dev)) 12893b617967SChris Wilson intel_opregion_enable_asle(dev); 129079e53945SJesse Barnes dev_priv->irq_enabled = 1; 129179e53945SJesse Barnes } 129279e53945SJesse Barnes 129379e53945SJesse Barnes 1294c0e09200SDave Airlie /* Set the vblank monitor pipe 1295c0e09200SDave Airlie */ 1296c0e09200SDave Airlie int i915_vblank_pipe_set(struct drm_device *dev, void *data, 1297c0e09200SDave Airlie struct drm_file *file_priv) 1298c0e09200SDave Airlie { 1299c0e09200SDave Airlie drm_i915_private_t *dev_priv = dev->dev_private; 1300c0e09200SDave Airlie 1301c0e09200SDave Airlie if (!dev_priv) { 1302c0e09200SDave Airlie DRM_ERROR("called with no initialization\n"); 1303c0e09200SDave Airlie return -EINVAL; 1304c0e09200SDave Airlie } 1305c0e09200SDave Airlie 1306c0e09200SDave Airlie return 0; 1307c0e09200SDave Airlie } 1308c0e09200SDave Airlie 1309c0e09200SDave Airlie int i915_vblank_pipe_get(struct drm_device *dev, void *data, 1310c0e09200SDave Airlie struct drm_file *file_priv) 1311c0e09200SDave Airlie { 1312c0e09200SDave Airlie drm_i915_private_t *dev_priv = dev->dev_private; 1313c0e09200SDave Airlie drm_i915_vblank_pipe_t *pipe = data; 1314c0e09200SDave Airlie 1315c0e09200SDave Airlie if (!dev_priv) { 1316c0e09200SDave Airlie DRM_ERROR("called with no initialization\n"); 1317c0e09200SDave Airlie return -EINVAL; 1318c0e09200SDave Airlie } 1319c0e09200SDave Airlie 13200a3e67a4SJesse Barnes pipe->pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B; 1321c0e09200SDave Airlie 1322c0e09200SDave Airlie return 0; 1323c0e09200SDave Airlie } 1324c0e09200SDave Airlie 1325c0e09200SDave Airlie /** 1326c0e09200SDave Airlie * Schedule buffer swap at given vertical blank. 1327c0e09200SDave Airlie */ 1328c0e09200SDave Airlie int i915_vblank_swap(struct drm_device *dev, void *data, 1329c0e09200SDave Airlie struct drm_file *file_priv) 1330c0e09200SDave Airlie { 1331bd95e0a4SEric Anholt /* The delayed swap mechanism was fundamentally racy, and has been 1332bd95e0a4SEric Anholt * removed. The model was that the client requested a delayed flip/swap 1333bd95e0a4SEric Anholt * from the kernel, then waited for vblank before continuing to perform 1334bd95e0a4SEric Anholt * rendering. The problem was that the kernel might wake the client 1335bd95e0a4SEric Anholt * up before it dispatched the vblank swap (since the lock has to be 1336bd95e0a4SEric Anholt * held while touching the ringbuffer), in which case the client would 1337bd95e0a4SEric Anholt * clear and start the next frame before the swap occurred, and 1338bd95e0a4SEric Anholt * flicker would occur in addition to likely missing the vblank. 1339bd95e0a4SEric Anholt * 1340bd95e0a4SEric Anholt * In the absence of this ioctl, userland falls back to a correct path 1341bd95e0a4SEric Anholt * of waiting for a vblank, then dispatching the swap on its own. 1342bd95e0a4SEric Anholt * Context switching to userland and back is plenty fast enough for 1343bd95e0a4SEric Anholt * meeting the requirements of vblank swapping. 13440a3e67a4SJesse Barnes */ 1345c0e09200SDave Airlie return -EINVAL; 1346c0e09200SDave Airlie } 1347c0e09200SDave Airlie 1348893eead0SChris Wilson static u32 1349893eead0SChris Wilson ring_last_seqno(struct intel_ring_buffer *ring) 1350852835f3SZou Nan hai { 1351893eead0SChris Wilson return list_entry(ring->request_list.prev, 1352893eead0SChris Wilson struct drm_i915_gem_request, list)->seqno; 1353893eead0SChris Wilson } 1354893eead0SChris Wilson 1355893eead0SChris Wilson static bool i915_hangcheck_ring_idle(struct intel_ring_buffer *ring, bool *err) 1356893eead0SChris Wilson { 1357893eead0SChris Wilson if (list_empty(&ring->request_list) || 1358893eead0SChris Wilson i915_seqno_passed(ring->get_seqno(ring), ring_last_seqno(ring))) { 1359893eead0SChris Wilson /* Issue a wake-up to catch stuck h/w. */ 1360b2223497SChris Wilson if (ring->waiting_seqno && waitqueue_active(&ring->irq_queue)) { 1361893eead0SChris Wilson DRM_ERROR("Hangcheck timer elapsed... %s idle [waiting on %d, at %d], missed IRQ?\n", 1362893eead0SChris Wilson ring->name, 1363b2223497SChris Wilson ring->waiting_seqno, 1364893eead0SChris Wilson ring->get_seqno(ring)); 1365893eead0SChris Wilson wake_up_all(&ring->irq_queue); 1366893eead0SChris Wilson *err = true; 1367893eead0SChris Wilson } 1368893eead0SChris Wilson return true; 1369893eead0SChris Wilson } 1370893eead0SChris Wilson return false; 1371f65d9421SBen Gamari } 1372f65d9421SBen Gamari 1373f65d9421SBen Gamari /** 1374f65d9421SBen Gamari * This is called when the chip hasn't reported back with completed 1375f65d9421SBen Gamari * batchbuffers in a long time. The first time this is called we simply record 1376f65d9421SBen Gamari * ACTHD. If ACTHD hasn't changed by the time the hangcheck timer elapses 1377f65d9421SBen Gamari * again, we assume the chip is wedged and try to fix it. 1378f65d9421SBen Gamari */ 1379f65d9421SBen Gamari void i915_hangcheck_elapsed(unsigned long data) 1380f65d9421SBen Gamari { 1381f65d9421SBen Gamari struct drm_device *dev = (struct drm_device *)data; 1382f65d9421SBen Gamari drm_i915_private_t *dev_priv = dev->dev_private; 1383cbb465e7SChris Wilson uint32_t acthd, instdone, instdone1; 1384893eead0SChris Wilson bool err = false; 1385893eead0SChris Wilson 1386893eead0SChris Wilson /* If all work is done then ACTHD clearly hasn't advanced. */ 1387893eead0SChris Wilson if (i915_hangcheck_ring_idle(&dev_priv->render_ring, &err) && 1388893eead0SChris Wilson i915_hangcheck_ring_idle(&dev_priv->bsd_ring, &err) && 1389893eead0SChris Wilson i915_hangcheck_ring_idle(&dev_priv->blt_ring, &err)) { 1390893eead0SChris Wilson dev_priv->hangcheck_count = 0; 1391893eead0SChris Wilson if (err) 1392893eead0SChris Wilson goto repeat; 1393893eead0SChris Wilson return; 1394893eead0SChris Wilson } 1395f65d9421SBen Gamari 1396a6c45cf0SChris Wilson if (INTEL_INFO(dev)->gen < 4) { 1397f65d9421SBen Gamari acthd = I915_READ(ACTHD); 1398cbb465e7SChris Wilson instdone = I915_READ(INSTDONE); 1399cbb465e7SChris Wilson instdone1 = 0; 1400cbb465e7SChris Wilson } else { 1401f65d9421SBen Gamari acthd = I915_READ(ACTHD_I965); 1402cbb465e7SChris Wilson instdone = I915_READ(INSTDONE_I965); 1403cbb465e7SChris Wilson instdone1 = I915_READ(INSTDONE1); 1404cbb465e7SChris Wilson } 1405f65d9421SBen Gamari 1406cbb465e7SChris Wilson if (dev_priv->last_acthd == acthd && 1407cbb465e7SChris Wilson dev_priv->last_instdone == instdone && 1408cbb465e7SChris Wilson dev_priv->last_instdone1 == instdone1) { 1409cbb465e7SChris Wilson if (dev_priv->hangcheck_count++ > 1) { 1410f65d9421SBen Gamari DRM_ERROR("Hangcheck timer elapsed... GPU hung\n"); 14118c80b59bSChris Wilson 14128c80b59bSChris Wilson if (!IS_GEN2(dev)) { 14138c80b59bSChris Wilson /* Is the chip hanging on a WAIT_FOR_EVENT? 14148c80b59bSChris Wilson * If so we can simply poke the RB_WAIT bit 14158c80b59bSChris Wilson * and break the hang. This should work on 14168c80b59bSChris Wilson * all but the second generation chipsets. 14178c80b59bSChris Wilson */ 14188168bd48SChris Wilson struct intel_ring_buffer *ring = &dev_priv->render_ring; 14198168bd48SChris Wilson u32 tmp = I915_READ_CTL(ring); 14208c80b59bSChris Wilson if (tmp & RING_WAIT) { 14218168bd48SChris Wilson I915_WRITE_CTL(ring, tmp); 1422893eead0SChris Wilson goto repeat; 14238c80b59bSChris Wilson } 14248c80b59bSChris Wilson } 14258c80b59bSChris Wilson 1426ba1234d1SBen Gamari i915_handle_error(dev, true); 1427f65d9421SBen Gamari return; 1428f65d9421SBen Gamari } 1429cbb465e7SChris Wilson } else { 1430cbb465e7SChris Wilson dev_priv->hangcheck_count = 0; 1431cbb465e7SChris Wilson 1432cbb465e7SChris Wilson dev_priv->last_acthd = acthd; 1433cbb465e7SChris Wilson dev_priv->last_instdone = instdone; 1434cbb465e7SChris Wilson dev_priv->last_instdone1 = instdone1; 1435cbb465e7SChris Wilson } 1436f65d9421SBen Gamari 1437893eead0SChris Wilson repeat: 1438f65d9421SBen Gamari /* Reset timer case chip hangs without another request being added */ 1439b3b079dbSChris Wilson mod_timer(&dev_priv->hangcheck_timer, 1440b3b079dbSChris Wilson jiffies + msecs_to_jiffies(DRM_I915_HANGCHECK_PERIOD)); 1441f65d9421SBen Gamari } 1442f65d9421SBen Gamari 1443c0e09200SDave Airlie /* drm_dma.h hooks 1444c0e09200SDave Airlie */ 1445f2b115e6SAdam Jackson static void ironlake_irq_preinstall(struct drm_device *dev) 1446036a4a7dSZhenyu Wang { 1447036a4a7dSZhenyu Wang drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 1448036a4a7dSZhenyu Wang 1449036a4a7dSZhenyu Wang I915_WRITE(HWSTAM, 0xeffe); 1450036a4a7dSZhenyu Wang 1451036a4a7dSZhenyu Wang /* XXX hotplug from PCH */ 1452036a4a7dSZhenyu Wang 1453036a4a7dSZhenyu Wang I915_WRITE(DEIMR, 0xffffffff); 1454036a4a7dSZhenyu Wang I915_WRITE(DEIER, 0x0); 14553143a2bfSChris Wilson POSTING_READ(DEIER); 1456036a4a7dSZhenyu Wang 1457036a4a7dSZhenyu Wang /* and GT */ 1458036a4a7dSZhenyu Wang I915_WRITE(GTIMR, 0xffffffff); 1459036a4a7dSZhenyu Wang I915_WRITE(GTIER, 0x0); 14603143a2bfSChris Wilson POSTING_READ(GTIER); 1461c650156aSZhenyu Wang 1462c650156aSZhenyu Wang /* south display irq */ 1463c650156aSZhenyu Wang I915_WRITE(SDEIMR, 0xffffffff); 1464c650156aSZhenyu Wang I915_WRITE(SDEIER, 0x0); 14653143a2bfSChris Wilson POSTING_READ(SDEIER); 1466036a4a7dSZhenyu Wang } 1467036a4a7dSZhenyu Wang 1468f2b115e6SAdam Jackson static int ironlake_irq_postinstall(struct drm_device *dev) 1469036a4a7dSZhenyu Wang { 1470036a4a7dSZhenyu Wang drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 1471036a4a7dSZhenyu Wang /* enable kind of interrupts always enabled */ 1472013d5aa2SJesse Barnes u32 display_mask = DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT | 1473013d5aa2SJesse Barnes DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE; 1474d1b851fcSZou Nan hai u32 render_mask = GT_PIPE_NOTIFY | GT_BSD_USER_INTERRUPT; 14752d7b8366SYuanhan Liu u32 hotplug_mask; 1476036a4a7dSZhenyu Wang 1477036a4a7dSZhenyu Wang dev_priv->irq_mask_reg = ~display_mask; 1478643ced9bSLi Peng dev_priv->de_irq_enable_reg = display_mask | DE_PIPEA_VBLANK | DE_PIPEB_VBLANK; 1479036a4a7dSZhenyu Wang 1480036a4a7dSZhenyu Wang /* should always can generate irq */ 1481036a4a7dSZhenyu Wang I915_WRITE(DEIIR, I915_READ(DEIIR)); 1482036a4a7dSZhenyu Wang I915_WRITE(DEIMR, dev_priv->irq_mask_reg); 1483036a4a7dSZhenyu Wang I915_WRITE(DEIER, dev_priv->de_irq_enable_reg); 14843143a2bfSChris Wilson POSTING_READ(DEIER); 1485036a4a7dSZhenyu Wang 1486549f7365SChris Wilson if (IS_GEN6(dev)) { 1487549f7365SChris Wilson render_mask = 1488549f7365SChris Wilson GT_PIPE_NOTIFY | 1489549f7365SChris Wilson GT_GEN6_BSD_USER_INTERRUPT | 1490549f7365SChris Wilson GT_BLT_USER_INTERRUPT; 1491549f7365SChris Wilson } 14923fdef020SZhenyu Wang 1493852835f3SZou Nan hai dev_priv->gt_irq_mask_reg = ~render_mask; 1494036a4a7dSZhenyu Wang dev_priv->gt_irq_enable_reg = render_mask; 1495036a4a7dSZhenyu Wang 1496036a4a7dSZhenyu Wang I915_WRITE(GTIIR, I915_READ(GTIIR)); 1497036a4a7dSZhenyu Wang I915_WRITE(GTIMR, dev_priv->gt_irq_mask_reg); 1498881f47b6SXiang, Haihao if (IS_GEN6(dev)) { 14993fdef020SZhenyu Wang I915_WRITE(GEN6_RENDER_IMR, ~GEN6_RENDER_PIPE_CONTROL_NOTIFY_INTERRUPT); 1500881f47b6SXiang, Haihao I915_WRITE(GEN6_BSD_IMR, ~GEN6_BSD_IMR_USER_INTERRUPT); 1501549f7365SChris Wilson I915_WRITE(GEN6_BLITTER_IMR, ~GEN6_BLITTER_USER_INTERRUPT); 1502881f47b6SXiang, Haihao } 1503881f47b6SXiang, Haihao 1504036a4a7dSZhenyu Wang I915_WRITE(GTIER, dev_priv->gt_irq_enable_reg); 15053143a2bfSChris Wilson POSTING_READ(GTIER); 1506036a4a7dSZhenyu Wang 15072d7b8366SYuanhan Liu if (HAS_PCH_CPT(dev)) { 15082d7b8366SYuanhan Liu hotplug_mask = SDE_CRT_HOTPLUG_CPT | SDE_PORTB_HOTPLUG_CPT | 15092d7b8366SYuanhan Liu SDE_PORTC_HOTPLUG_CPT | SDE_PORTD_HOTPLUG_CPT ; 15102d7b8366SYuanhan Liu } else { 15112d7b8366SYuanhan Liu hotplug_mask = SDE_CRT_HOTPLUG | SDE_PORTB_HOTPLUG | 15122d7b8366SYuanhan Liu SDE_PORTC_HOTPLUG | SDE_PORTD_HOTPLUG; 15132d7b8366SYuanhan Liu } 15142d7b8366SYuanhan Liu 1515c650156aSZhenyu Wang dev_priv->pch_irq_mask_reg = ~hotplug_mask; 1516c650156aSZhenyu Wang dev_priv->pch_irq_enable_reg = hotplug_mask; 1517c650156aSZhenyu Wang 1518c650156aSZhenyu Wang I915_WRITE(SDEIIR, I915_READ(SDEIIR)); 1519c650156aSZhenyu Wang I915_WRITE(SDEIMR, dev_priv->pch_irq_mask_reg); 1520c650156aSZhenyu Wang I915_WRITE(SDEIER, dev_priv->pch_irq_enable_reg); 15213143a2bfSChris Wilson POSTING_READ(SDEIER); 1522c650156aSZhenyu Wang 1523f97108d1SJesse Barnes if (IS_IRONLAKE_M(dev)) { 1524f97108d1SJesse Barnes /* Clear & enable PCU event interrupts */ 1525f97108d1SJesse Barnes I915_WRITE(DEIIR, DE_PCU_EVENT); 1526f97108d1SJesse Barnes I915_WRITE(DEIER, I915_READ(DEIER) | DE_PCU_EVENT); 1527f97108d1SJesse Barnes ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT); 1528f97108d1SJesse Barnes } 1529f97108d1SJesse Barnes 1530036a4a7dSZhenyu Wang return 0; 1531036a4a7dSZhenyu Wang } 1532036a4a7dSZhenyu Wang 1533c0e09200SDave Airlie void i915_driver_irq_preinstall(struct drm_device * dev) 1534c0e09200SDave Airlie { 1535c0e09200SDave Airlie drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 1536c0e09200SDave Airlie 153779e53945SJesse Barnes atomic_set(&dev_priv->irq_received, 0); 153879e53945SJesse Barnes 1539036a4a7dSZhenyu Wang INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func); 15408a905236SJesse Barnes INIT_WORK(&dev_priv->error_work, i915_error_work_func); 1541036a4a7dSZhenyu Wang 1542bad720ffSEric Anholt if (HAS_PCH_SPLIT(dev)) { 1543f2b115e6SAdam Jackson ironlake_irq_preinstall(dev); 1544036a4a7dSZhenyu Wang return; 1545036a4a7dSZhenyu Wang } 1546036a4a7dSZhenyu Wang 15475ca58282SJesse Barnes if (I915_HAS_HOTPLUG(dev)) { 15485ca58282SJesse Barnes I915_WRITE(PORT_HOTPLUG_EN, 0); 15495ca58282SJesse Barnes I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 15505ca58282SJesse Barnes } 15515ca58282SJesse Barnes 15520a3e67a4SJesse Barnes I915_WRITE(HWSTAM, 0xeffe); 15537c463586SKeith Packard I915_WRITE(PIPEASTAT, 0); 15547c463586SKeith Packard I915_WRITE(PIPEBSTAT, 0); 15550a3e67a4SJesse Barnes I915_WRITE(IMR, 0xffffffff); 1556ed4cb414SEric Anholt I915_WRITE(IER, 0x0); 15573143a2bfSChris Wilson POSTING_READ(IER); 1558c0e09200SDave Airlie } 1559c0e09200SDave Airlie 1560b01f2c3aSJesse Barnes /* 1561b01f2c3aSJesse Barnes * Must be called after intel_modeset_init or hotplug interrupts won't be 1562b01f2c3aSJesse Barnes * enabled correctly. 1563b01f2c3aSJesse Barnes */ 15640a3e67a4SJesse Barnes int i915_driver_irq_postinstall(struct drm_device *dev) 1565c0e09200SDave Airlie { 1566c0e09200SDave Airlie drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 15675ca58282SJesse Barnes u32 enable_mask = I915_INTERRUPT_ENABLE_FIX | I915_INTERRUPT_ENABLE_VAR; 156863eeaf38SJesse Barnes u32 error_mask; 15690a3e67a4SJesse Barnes 1570852835f3SZou Nan hai DRM_INIT_WAITQUEUE(&dev_priv->render_ring.irq_queue); 1571d1b851fcSZou Nan hai if (HAS_BSD(dev)) 1572d1b851fcSZou Nan hai DRM_INIT_WAITQUEUE(&dev_priv->bsd_ring.irq_queue); 1573549f7365SChris Wilson if (HAS_BLT(dev)) 1574549f7365SChris Wilson DRM_INIT_WAITQUEUE(&dev_priv->blt_ring.irq_queue); 1575d1b851fcSZou Nan hai 15760a3e67a4SJesse Barnes dev_priv->vblank_pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B; 1577ed4cb414SEric Anholt 1578bad720ffSEric Anholt if (HAS_PCH_SPLIT(dev)) 1579f2b115e6SAdam Jackson return ironlake_irq_postinstall(dev); 1580036a4a7dSZhenyu Wang 15817c463586SKeith Packard /* Unmask the interrupts that we always want on. */ 15827c463586SKeith Packard dev_priv->irq_mask_reg = ~I915_INTERRUPT_ENABLE_FIX; 15838ee1c3dbSMatthew Garrett 15847c463586SKeith Packard dev_priv->pipestat[0] = 0; 15857c463586SKeith Packard dev_priv->pipestat[1] = 0; 15867c463586SKeith Packard 15875ca58282SJesse Barnes if (I915_HAS_HOTPLUG(dev)) { 1588c496fa1fSAdam Jackson /* Enable in IER... */ 1589c496fa1fSAdam Jackson enable_mask |= I915_DISPLAY_PORT_INTERRUPT; 1590c496fa1fSAdam Jackson /* and unmask in IMR */ 1591c496fa1fSAdam Jackson dev_priv->irq_mask_reg &= ~I915_DISPLAY_PORT_INTERRUPT; 1592c496fa1fSAdam Jackson } 1593c496fa1fSAdam Jackson 1594c496fa1fSAdam Jackson /* 1595c496fa1fSAdam Jackson * Enable some error detection, note the instruction error mask 1596c496fa1fSAdam Jackson * bit is reserved, so we leave it masked. 1597c496fa1fSAdam Jackson */ 1598c496fa1fSAdam Jackson if (IS_G4X(dev)) { 1599c496fa1fSAdam Jackson error_mask = ~(GM45_ERROR_PAGE_TABLE | 1600c496fa1fSAdam Jackson GM45_ERROR_MEM_PRIV | 1601c496fa1fSAdam Jackson GM45_ERROR_CP_PRIV | 1602c496fa1fSAdam Jackson I915_ERROR_MEMORY_REFRESH); 1603c496fa1fSAdam Jackson } else { 1604c496fa1fSAdam Jackson error_mask = ~(I915_ERROR_PAGE_TABLE | 1605c496fa1fSAdam Jackson I915_ERROR_MEMORY_REFRESH); 1606c496fa1fSAdam Jackson } 1607c496fa1fSAdam Jackson I915_WRITE(EMR, error_mask); 1608c496fa1fSAdam Jackson 1609c496fa1fSAdam Jackson I915_WRITE(IMR, dev_priv->irq_mask_reg); 1610c496fa1fSAdam Jackson I915_WRITE(IER, enable_mask); 16113143a2bfSChris Wilson POSTING_READ(IER); 1612c496fa1fSAdam Jackson 1613c496fa1fSAdam Jackson if (I915_HAS_HOTPLUG(dev)) { 16145ca58282SJesse Barnes u32 hotplug_en = I915_READ(PORT_HOTPLUG_EN); 16155ca58282SJesse Barnes 1616b01f2c3aSJesse Barnes /* Note HDMI and DP share bits */ 1617b01f2c3aSJesse Barnes if (dev_priv->hotplug_supported_mask & HDMIB_HOTPLUG_INT_STATUS) 1618b01f2c3aSJesse Barnes hotplug_en |= HDMIB_HOTPLUG_INT_EN; 1619b01f2c3aSJesse Barnes if (dev_priv->hotplug_supported_mask & HDMIC_HOTPLUG_INT_STATUS) 1620b01f2c3aSJesse Barnes hotplug_en |= HDMIC_HOTPLUG_INT_EN; 1621b01f2c3aSJesse Barnes if (dev_priv->hotplug_supported_mask & HDMID_HOTPLUG_INT_STATUS) 1622b01f2c3aSJesse Barnes hotplug_en |= HDMID_HOTPLUG_INT_EN; 1623b01f2c3aSJesse Barnes if (dev_priv->hotplug_supported_mask & SDVOC_HOTPLUG_INT_STATUS) 1624b01f2c3aSJesse Barnes hotplug_en |= SDVOC_HOTPLUG_INT_EN; 1625b01f2c3aSJesse Barnes if (dev_priv->hotplug_supported_mask & SDVOB_HOTPLUG_INT_STATUS) 1626b01f2c3aSJesse Barnes hotplug_en |= SDVOB_HOTPLUG_INT_EN; 16272d1c9752SAndy Lutomirski if (dev_priv->hotplug_supported_mask & CRT_HOTPLUG_INT_STATUS) { 1628b01f2c3aSJesse Barnes hotplug_en |= CRT_HOTPLUG_INT_EN; 16292d1c9752SAndy Lutomirski 16302d1c9752SAndy Lutomirski /* Programming the CRT detection parameters tends 16312d1c9752SAndy Lutomirski to generate a spurious hotplug event about three 16322d1c9752SAndy Lutomirski seconds later. So just do it once. 16332d1c9752SAndy Lutomirski */ 16342d1c9752SAndy Lutomirski if (IS_G4X(dev)) 16352d1c9752SAndy Lutomirski hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64; 16362d1c9752SAndy Lutomirski hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50; 16372d1c9752SAndy Lutomirski } 16382d1c9752SAndy Lutomirski 1639b01f2c3aSJesse Barnes /* Ignore TV since it's buggy */ 1640b01f2c3aSJesse Barnes 16415ca58282SJesse Barnes I915_WRITE(PORT_HOTPLUG_EN, hotplug_en); 16425ca58282SJesse Barnes } 16435ca58282SJesse Barnes 16443b617967SChris Wilson intel_opregion_enable_asle(dev); 16450a3e67a4SJesse Barnes 16460a3e67a4SJesse Barnes return 0; 1647c0e09200SDave Airlie } 1648c0e09200SDave Airlie 1649f2b115e6SAdam Jackson static void ironlake_irq_uninstall(struct drm_device *dev) 1650036a4a7dSZhenyu Wang { 1651036a4a7dSZhenyu Wang drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 1652036a4a7dSZhenyu Wang I915_WRITE(HWSTAM, 0xffffffff); 1653036a4a7dSZhenyu Wang 1654036a4a7dSZhenyu Wang I915_WRITE(DEIMR, 0xffffffff); 1655036a4a7dSZhenyu Wang I915_WRITE(DEIER, 0x0); 1656036a4a7dSZhenyu Wang I915_WRITE(DEIIR, I915_READ(DEIIR)); 1657036a4a7dSZhenyu Wang 1658036a4a7dSZhenyu Wang I915_WRITE(GTIMR, 0xffffffff); 1659036a4a7dSZhenyu Wang I915_WRITE(GTIER, 0x0); 1660036a4a7dSZhenyu Wang I915_WRITE(GTIIR, I915_READ(GTIIR)); 1661036a4a7dSZhenyu Wang } 1662036a4a7dSZhenyu Wang 1663c0e09200SDave Airlie void i915_driver_irq_uninstall(struct drm_device * dev) 1664c0e09200SDave Airlie { 1665c0e09200SDave Airlie drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 1666c0e09200SDave Airlie 1667c0e09200SDave Airlie if (!dev_priv) 1668c0e09200SDave Airlie return; 1669c0e09200SDave Airlie 16700a3e67a4SJesse Barnes dev_priv->vblank_pipe = 0; 16710a3e67a4SJesse Barnes 1672bad720ffSEric Anholt if (HAS_PCH_SPLIT(dev)) { 1673f2b115e6SAdam Jackson ironlake_irq_uninstall(dev); 1674036a4a7dSZhenyu Wang return; 1675036a4a7dSZhenyu Wang } 1676036a4a7dSZhenyu Wang 16775ca58282SJesse Barnes if (I915_HAS_HOTPLUG(dev)) { 16785ca58282SJesse Barnes I915_WRITE(PORT_HOTPLUG_EN, 0); 16795ca58282SJesse Barnes I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 16805ca58282SJesse Barnes } 16815ca58282SJesse Barnes 16820a3e67a4SJesse Barnes I915_WRITE(HWSTAM, 0xffffffff); 16837c463586SKeith Packard I915_WRITE(PIPEASTAT, 0); 16847c463586SKeith Packard I915_WRITE(PIPEBSTAT, 0); 16850a3e67a4SJesse Barnes I915_WRITE(IMR, 0xffffffff); 1686ed4cb414SEric Anholt I915_WRITE(IER, 0x0); 1687c0e09200SDave Airlie 16887c463586SKeith Packard I915_WRITE(PIPEASTAT, I915_READ(PIPEASTAT) & 0x8000ffff); 16897c463586SKeith Packard I915_WRITE(PIPEBSTAT, I915_READ(PIPEBSTAT) & 0x8000ffff); 16907c463586SKeith Packard I915_WRITE(IIR, I915_READ(IIR)); 1691c0e09200SDave Airlie } 1692