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> 30c0e09200SDave Airlie #include "drmP.h" 31c0e09200SDave Airlie #include "drm.h" 32c0e09200SDave Airlie #include "i915_drm.h" 33c0e09200SDave Airlie #include "i915_drv.h" 3479e53945SJesse Barnes #include "intel_drv.h" 35c0e09200SDave Airlie 36c0e09200SDave Airlie #define MAX_NOPID ((u32)~0) 37c0e09200SDave Airlie 387c463586SKeith Packard /** 397c463586SKeith Packard * Interrupts that are always left unmasked. 407c463586SKeith Packard * 417c463586SKeith Packard * Since pipe events are edge-triggered from the PIPESTAT register to IIR, 427c463586SKeith Packard * we leave them always unmasked in IMR and then control enabling them through 437c463586SKeith Packard * PIPESTAT alone. 447c463586SKeith Packard */ 457c463586SKeith Packard #define I915_INTERRUPT_ENABLE_FIX (I915_ASLE_INTERRUPT | \ 460a3e67a4SJesse Barnes I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | \ 4763eeaf38SJesse Barnes I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | \ 4863eeaf38SJesse Barnes I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) 49ed4cb414SEric Anholt 507c463586SKeith Packard /** Interrupts that we mask and unmask at runtime. */ 517c463586SKeith Packard #define I915_INTERRUPT_ENABLE_VAR (I915_USER_INTERRUPT) 527c463586SKeith Packard 5379e53945SJesse Barnes #define I915_PIPE_VBLANK_STATUS (PIPE_START_VBLANK_INTERRUPT_STATUS |\ 5479e53945SJesse Barnes PIPE_VBLANK_INTERRUPT_STATUS) 5579e53945SJesse Barnes 5679e53945SJesse Barnes #define I915_PIPE_VBLANK_ENABLE (PIPE_START_VBLANK_INTERRUPT_ENABLE |\ 5779e53945SJesse Barnes PIPE_VBLANK_INTERRUPT_ENABLE) 5879e53945SJesse Barnes 5979e53945SJesse Barnes #define DRM_I915_VBLANK_PIPE_ALL (DRM_I915_VBLANK_PIPE_A | \ 6079e53945SJesse Barnes DRM_I915_VBLANK_PIPE_B) 6179e53945SJesse Barnes 628ee1c3dbSMatthew Garrett void 63036a4a7dSZhenyu Wang igdng_enable_graphics_irq(drm_i915_private_t *dev_priv, u32 mask) 64036a4a7dSZhenyu Wang { 65036a4a7dSZhenyu Wang if ((dev_priv->gt_irq_mask_reg & mask) != 0) { 66036a4a7dSZhenyu Wang dev_priv->gt_irq_mask_reg &= ~mask; 67036a4a7dSZhenyu Wang I915_WRITE(GTIMR, dev_priv->gt_irq_mask_reg); 68036a4a7dSZhenyu Wang (void) I915_READ(GTIMR); 69036a4a7dSZhenyu Wang } 70036a4a7dSZhenyu Wang } 71036a4a7dSZhenyu Wang 72036a4a7dSZhenyu Wang static inline void 73036a4a7dSZhenyu Wang igdng_disable_graphics_irq(drm_i915_private_t *dev_priv, u32 mask) 74036a4a7dSZhenyu Wang { 75036a4a7dSZhenyu Wang if ((dev_priv->gt_irq_mask_reg & mask) != mask) { 76036a4a7dSZhenyu Wang dev_priv->gt_irq_mask_reg |= mask; 77036a4a7dSZhenyu Wang I915_WRITE(GTIMR, dev_priv->gt_irq_mask_reg); 78036a4a7dSZhenyu Wang (void) I915_READ(GTIMR); 79036a4a7dSZhenyu Wang } 80036a4a7dSZhenyu Wang } 81036a4a7dSZhenyu Wang 82036a4a7dSZhenyu Wang /* For display hotplug interrupt */ 83036a4a7dSZhenyu Wang void 84036a4a7dSZhenyu Wang igdng_enable_display_irq(drm_i915_private_t *dev_priv, u32 mask) 85036a4a7dSZhenyu Wang { 86036a4a7dSZhenyu Wang if ((dev_priv->irq_mask_reg & mask) != 0) { 87036a4a7dSZhenyu Wang dev_priv->irq_mask_reg &= ~mask; 88036a4a7dSZhenyu Wang I915_WRITE(DEIMR, dev_priv->irq_mask_reg); 89036a4a7dSZhenyu Wang (void) I915_READ(DEIMR); 90036a4a7dSZhenyu Wang } 91036a4a7dSZhenyu Wang } 92036a4a7dSZhenyu Wang 93036a4a7dSZhenyu Wang static inline void 94036a4a7dSZhenyu Wang igdng_disable_display_irq(drm_i915_private_t *dev_priv, u32 mask) 95036a4a7dSZhenyu Wang { 96036a4a7dSZhenyu Wang if ((dev_priv->irq_mask_reg & mask) != mask) { 97036a4a7dSZhenyu Wang dev_priv->irq_mask_reg |= mask; 98036a4a7dSZhenyu Wang I915_WRITE(DEIMR, dev_priv->irq_mask_reg); 99036a4a7dSZhenyu Wang (void) I915_READ(DEIMR); 100036a4a7dSZhenyu Wang } 101036a4a7dSZhenyu Wang } 102036a4a7dSZhenyu Wang 103036a4a7dSZhenyu Wang void 104ed4cb414SEric Anholt i915_enable_irq(drm_i915_private_t *dev_priv, u32 mask) 105ed4cb414SEric Anholt { 106ed4cb414SEric Anholt if ((dev_priv->irq_mask_reg & mask) != 0) { 107ed4cb414SEric Anholt dev_priv->irq_mask_reg &= ~mask; 108ed4cb414SEric Anholt I915_WRITE(IMR, dev_priv->irq_mask_reg); 109ed4cb414SEric Anholt (void) I915_READ(IMR); 110ed4cb414SEric Anholt } 111ed4cb414SEric Anholt } 112ed4cb414SEric Anholt 113ed4cb414SEric Anholt static inline void 114ed4cb414SEric Anholt i915_disable_irq(drm_i915_private_t *dev_priv, u32 mask) 115ed4cb414SEric Anholt { 116ed4cb414SEric Anholt if ((dev_priv->irq_mask_reg & mask) != mask) { 117ed4cb414SEric Anholt dev_priv->irq_mask_reg |= mask; 118ed4cb414SEric Anholt I915_WRITE(IMR, dev_priv->irq_mask_reg); 119ed4cb414SEric Anholt (void) I915_READ(IMR); 120ed4cb414SEric Anholt } 121ed4cb414SEric Anholt } 122ed4cb414SEric Anholt 1237c463586SKeith Packard static inline u32 1247c463586SKeith Packard i915_pipestat(int pipe) 1257c463586SKeith Packard { 1267c463586SKeith Packard if (pipe == 0) 1277c463586SKeith Packard return PIPEASTAT; 1287c463586SKeith Packard if (pipe == 1) 1297c463586SKeith Packard return PIPEBSTAT; 1309c84ba4eSAndrew Morton BUG(); 1317c463586SKeith Packard } 1327c463586SKeith Packard 1337c463586SKeith Packard void 1347c463586SKeith Packard i915_enable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask) 1357c463586SKeith Packard { 1367c463586SKeith Packard if ((dev_priv->pipestat[pipe] & mask) != mask) { 1377c463586SKeith Packard u32 reg = i915_pipestat(pipe); 1387c463586SKeith Packard 1397c463586SKeith Packard dev_priv->pipestat[pipe] |= mask; 1407c463586SKeith Packard /* Enable the interrupt, clear any pending status */ 1417c463586SKeith Packard I915_WRITE(reg, dev_priv->pipestat[pipe] | (mask >> 16)); 1427c463586SKeith Packard (void) I915_READ(reg); 1437c463586SKeith Packard } 1447c463586SKeith Packard } 1457c463586SKeith Packard 1467c463586SKeith Packard void 1477c463586SKeith Packard i915_disable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask) 1487c463586SKeith Packard { 1497c463586SKeith Packard if ((dev_priv->pipestat[pipe] & mask) != 0) { 1507c463586SKeith Packard u32 reg = i915_pipestat(pipe); 1517c463586SKeith Packard 1527c463586SKeith Packard dev_priv->pipestat[pipe] &= ~mask; 1537c463586SKeith Packard I915_WRITE(reg, dev_priv->pipestat[pipe]); 1547c463586SKeith Packard (void) I915_READ(reg); 1557c463586SKeith Packard } 1567c463586SKeith Packard } 1577c463586SKeith Packard 158c0e09200SDave Airlie /** 1590a3e67a4SJesse Barnes * i915_pipe_enabled - check if a pipe is enabled 1600a3e67a4SJesse Barnes * @dev: DRM device 1610a3e67a4SJesse Barnes * @pipe: pipe to check 1620a3e67a4SJesse Barnes * 1630a3e67a4SJesse Barnes * Reading certain registers when the pipe is disabled can hang the chip. 1640a3e67a4SJesse Barnes * Use this routine to make sure the PLL is running and the pipe is active 1650a3e67a4SJesse Barnes * before reading such registers if unsure. 1660a3e67a4SJesse Barnes */ 1670a3e67a4SJesse Barnes static int 1680a3e67a4SJesse Barnes i915_pipe_enabled(struct drm_device *dev, int pipe) 1690a3e67a4SJesse Barnes { 1700a3e67a4SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 1710a3e67a4SJesse Barnes unsigned long pipeconf = pipe ? PIPEBCONF : PIPEACONF; 1720a3e67a4SJesse Barnes 1730a3e67a4SJesse Barnes if (I915_READ(pipeconf) & PIPEACONF_ENABLE) 1740a3e67a4SJesse Barnes return 1; 1750a3e67a4SJesse Barnes 1760a3e67a4SJesse Barnes return 0; 1770a3e67a4SJesse Barnes } 1780a3e67a4SJesse Barnes 17942f52ef8SKeith Packard /* Called from drm generic code, passed a 'crtc', which 18042f52ef8SKeith Packard * we use as a pipe index 18142f52ef8SKeith Packard */ 18242f52ef8SKeith Packard u32 i915_get_vblank_counter(struct drm_device *dev, int pipe) 1830a3e67a4SJesse Barnes { 1840a3e67a4SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 1850a3e67a4SJesse Barnes unsigned long high_frame; 1860a3e67a4SJesse Barnes unsigned long low_frame; 1870a3e67a4SJesse Barnes u32 high1, high2, low, count; 1880a3e67a4SJesse Barnes 1890a3e67a4SJesse Barnes high_frame = pipe ? PIPEBFRAMEHIGH : PIPEAFRAMEHIGH; 1900a3e67a4SJesse Barnes low_frame = pipe ? PIPEBFRAMEPIXEL : PIPEAFRAMEPIXEL; 1910a3e67a4SJesse Barnes 1920a3e67a4SJesse Barnes if (!i915_pipe_enabled(dev, pipe)) { 1936cb504c2SFrans Pop DRM_DEBUG("trying to get vblank count for disabled pipe %d\n", pipe); 1940a3e67a4SJesse Barnes return 0; 1950a3e67a4SJesse Barnes } 1960a3e67a4SJesse Barnes 1970a3e67a4SJesse Barnes /* 1980a3e67a4SJesse Barnes * High & low register fields aren't synchronized, so make sure 1990a3e67a4SJesse Barnes * we get a low value that's stable across two reads of the high 2000a3e67a4SJesse Barnes * register. 2010a3e67a4SJesse Barnes */ 2020a3e67a4SJesse Barnes do { 2030a3e67a4SJesse Barnes high1 = ((I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK) >> 2040a3e67a4SJesse Barnes PIPE_FRAME_HIGH_SHIFT); 2050a3e67a4SJesse Barnes low = ((I915_READ(low_frame) & PIPE_FRAME_LOW_MASK) >> 2060a3e67a4SJesse Barnes PIPE_FRAME_LOW_SHIFT); 2070a3e67a4SJesse Barnes high2 = ((I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK) >> 2080a3e67a4SJesse Barnes PIPE_FRAME_HIGH_SHIFT); 2090a3e67a4SJesse Barnes } while (high1 != high2); 2100a3e67a4SJesse Barnes 2110a3e67a4SJesse Barnes count = (high1 << 8) | low; 2120a3e67a4SJesse Barnes 2130a3e67a4SJesse Barnes return count; 2140a3e67a4SJesse Barnes } 2150a3e67a4SJesse Barnes 2169880b7a5SJesse Barnes u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe) 2179880b7a5SJesse Barnes { 2189880b7a5SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 2199880b7a5SJesse Barnes int reg = pipe ? PIPEB_FRMCOUNT_GM45 : PIPEA_FRMCOUNT_GM45; 2209880b7a5SJesse Barnes 2219880b7a5SJesse Barnes if (!i915_pipe_enabled(dev, pipe)) { 2226cb504c2SFrans Pop DRM_DEBUG("trying to get vblank count for disabled pipe %d\n", pipe); 2239880b7a5SJesse Barnes return 0; 2249880b7a5SJesse Barnes } 2259880b7a5SJesse Barnes 2269880b7a5SJesse Barnes return I915_READ(reg); 2279880b7a5SJesse Barnes } 2289880b7a5SJesse Barnes 2295ca58282SJesse Barnes /* 2305ca58282SJesse Barnes * Handle hotplug events outside the interrupt handler proper. 2315ca58282SJesse Barnes */ 2325ca58282SJesse Barnes static void i915_hotplug_work_func(struct work_struct *work) 2335ca58282SJesse Barnes { 2345ca58282SJesse Barnes drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t, 2355ca58282SJesse Barnes hotplug_work); 2365ca58282SJesse Barnes struct drm_device *dev = dev_priv->dev; 237c31c4ba3SKeith Packard struct drm_mode_config *mode_config = &dev->mode_config; 238c31c4ba3SKeith Packard struct drm_connector *connector; 2395ca58282SJesse Barnes 240c31c4ba3SKeith Packard if (mode_config->num_connector) { 241c31c4ba3SKeith Packard list_for_each_entry(connector, &mode_config->connector_list, head) { 242c31c4ba3SKeith Packard struct intel_output *intel_output = to_intel_output(connector); 243c31c4ba3SKeith Packard 244c31c4ba3SKeith Packard if (intel_output->hot_plug) 245c31c4ba3SKeith Packard (*intel_output->hot_plug) (intel_output); 246c31c4ba3SKeith Packard } 247c31c4ba3SKeith Packard } 2485ca58282SJesse Barnes /* Just fire off a uevent and let userspace tell us what to do */ 2495ca58282SJesse Barnes drm_sysfs_hotplug_event(dev); 2505ca58282SJesse Barnes } 2515ca58282SJesse Barnes 252036a4a7dSZhenyu Wang irqreturn_t igdng_irq_handler(struct drm_device *dev) 253036a4a7dSZhenyu Wang { 254036a4a7dSZhenyu Wang drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 255036a4a7dSZhenyu Wang int ret = IRQ_NONE; 256036a4a7dSZhenyu Wang u32 de_iir, gt_iir; 257036a4a7dSZhenyu Wang u32 new_de_iir, new_gt_iir; 258036a4a7dSZhenyu Wang struct drm_i915_master_private *master_priv; 259036a4a7dSZhenyu Wang 260036a4a7dSZhenyu Wang de_iir = I915_READ(DEIIR); 261036a4a7dSZhenyu Wang gt_iir = I915_READ(GTIIR); 262036a4a7dSZhenyu Wang 263036a4a7dSZhenyu Wang for (;;) { 264036a4a7dSZhenyu Wang if (de_iir == 0 && gt_iir == 0) 265036a4a7dSZhenyu Wang break; 266036a4a7dSZhenyu Wang 267036a4a7dSZhenyu Wang ret = IRQ_HANDLED; 268036a4a7dSZhenyu Wang 269036a4a7dSZhenyu Wang I915_WRITE(DEIIR, de_iir); 270036a4a7dSZhenyu Wang new_de_iir = I915_READ(DEIIR); 271036a4a7dSZhenyu Wang I915_WRITE(GTIIR, gt_iir); 272036a4a7dSZhenyu Wang new_gt_iir = I915_READ(GTIIR); 273036a4a7dSZhenyu Wang 274036a4a7dSZhenyu Wang if (dev->primary->master) { 275036a4a7dSZhenyu Wang master_priv = dev->primary->master->driver_priv; 276036a4a7dSZhenyu Wang if (master_priv->sarea_priv) 277036a4a7dSZhenyu Wang master_priv->sarea_priv->last_dispatch = 278036a4a7dSZhenyu Wang READ_BREADCRUMB(dev_priv); 279036a4a7dSZhenyu Wang } 280036a4a7dSZhenyu Wang 281036a4a7dSZhenyu Wang if (gt_iir & GT_USER_INTERRUPT) { 282036a4a7dSZhenyu Wang dev_priv->mm.irq_gem_seqno = i915_get_gem_seqno(dev); 283036a4a7dSZhenyu Wang DRM_WAKEUP(&dev_priv->irq_queue); 284036a4a7dSZhenyu Wang } 285036a4a7dSZhenyu Wang 286036a4a7dSZhenyu Wang de_iir = new_de_iir; 287036a4a7dSZhenyu Wang gt_iir = new_gt_iir; 288036a4a7dSZhenyu Wang } 289036a4a7dSZhenyu Wang 290036a4a7dSZhenyu Wang return ret; 291036a4a7dSZhenyu Wang } 292036a4a7dSZhenyu Wang 2938a905236SJesse Barnes /** 2948a905236SJesse Barnes * i915_error_work_func - do process context error handling work 2958a905236SJesse Barnes * @work: work struct 2968a905236SJesse Barnes * 2978a905236SJesse Barnes * Fire an error uevent so userspace can see that a hang or error 2988a905236SJesse Barnes * was detected. 2998a905236SJesse Barnes */ 3008a905236SJesse Barnes static void i915_error_work_func(struct work_struct *work) 3018a905236SJesse Barnes { 3028a905236SJesse Barnes drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t, 3038a905236SJesse Barnes error_work); 3048a905236SJesse Barnes struct drm_device *dev = dev_priv->dev; 3058a905236SJesse Barnes char *event_string = "ERROR=1"; 3068a905236SJesse Barnes char *envp[] = { event_string, NULL }; 3078a905236SJesse Barnes 3088a905236SJesse Barnes DRM_DEBUG("generating error event\n"); 3098a905236SJesse Barnes 3108a905236SJesse Barnes kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, envp); 3118a905236SJesse Barnes } 3128a905236SJesse Barnes 3138a905236SJesse Barnes /** 3148a905236SJesse Barnes * i915_capture_error_state - capture an error record for later analysis 3158a905236SJesse Barnes * @dev: drm device 3168a905236SJesse Barnes * 3178a905236SJesse Barnes * Should be called when an error is detected (either a hang or an error 3188a905236SJesse Barnes * interrupt) to capture error state from the time of the error. Fills 3198a905236SJesse Barnes * out a structure which becomes available in debugfs for user level tools 3208a905236SJesse Barnes * to pick up. 3218a905236SJesse Barnes */ 32263eeaf38SJesse Barnes static void i915_capture_error_state(struct drm_device *dev) 32363eeaf38SJesse Barnes { 32463eeaf38SJesse Barnes struct drm_i915_private *dev_priv = dev->dev_private; 32563eeaf38SJesse Barnes struct drm_i915_error_state *error; 32663eeaf38SJesse Barnes unsigned long flags; 32763eeaf38SJesse Barnes 32863eeaf38SJesse Barnes spin_lock_irqsave(&dev_priv->error_lock, flags); 32963eeaf38SJesse Barnes if (dev_priv->first_error) 33063eeaf38SJesse Barnes goto out; 33163eeaf38SJesse Barnes 33263eeaf38SJesse Barnes error = kmalloc(sizeof(*error), GFP_ATOMIC); 33363eeaf38SJesse Barnes if (!error) { 33463eeaf38SJesse Barnes DRM_DEBUG("out ot memory, not capturing error state\n"); 33563eeaf38SJesse Barnes goto out; 33663eeaf38SJesse Barnes } 33763eeaf38SJesse Barnes 33863eeaf38SJesse Barnes error->eir = I915_READ(EIR); 33963eeaf38SJesse Barnes error->pgtbl_er = I915_READ(PGTBL_ER); 34063eeaf38SJesse Barnes error->pipeastat = I915_READ(PIPEASTAT); 34163eeaf38SJesse Barnes error->pipebstat = I915_READ(PIPEBSTAT); 34263eeaf38SJesse Barnes error->instpm = I915_READ(INSTPM); 34363eeaf38SJesse Barnes if (!IS_I965G(dev)) { 34463eeaf38SJesse Barnes error->ipeir = I915_READ(IPEIR); 34563eeaf38SJesse Barnes error->ipehr = I915_READ(IPEHR); 34663eeaf38SJesse Barnes error->instdone = I915_READ(INSTDONE); 34763eeaf38SJesse Barnes error->acthd = I915_READ(ACTHD); 34863eeaf38SJesse Barnes } else { 34963eeaf38SJesse Barnes error->ipeir = I915_READ(IPEIR_I965); 35063eeaf38SJesse Barnes error->ipehr = I915_READ(IPEHR_I965); 35163eeaf38SJesse Barnes error->instdone = I915_READ(INSTDONE_I965); 35263eeaf38SJesse Barnes error->instps = I915_READ(INSTPS); 35363eeaf38SJesse Barnes error->instdone1 = I915_READ(INSTDONE1); 35463eeaf38SJesse Barnes error->acthd = I915_READ(ACTHD_I965); 35563eeaf38SJesse Barnes } 35663eeaf38SJesse Barnes 3578a905236SJesse Barnes do_gettimeofday(&error->time); 3588a905236SJesse Barnes 35963eeaf38SJesse Barnes dev_priv->first_error = error; 36063eeaf38SJesse Barnes 36163eeaf38SJesse Barnes out: 36263eeaf38SJesse Barnes spin_unlock_irqrestore(&dev_priv->error_lock, flags); 36363eeaf38SJesse Barnes } 36463eeaf38SJesse Barnes 3658a905236SJesse Barnes /** 3668a905236SJesse Barnes * i915_handle_error - handle an error interrupt 3678a905236SJesse Barnes * @dev: drm device 3688a905236SJesse Barnes * 3698a905236SJesse Barnes * Do some basic checking of regsiter state at error interrupt time and 3708a905236SJesse Barnes * dump it to the syslog. Also call i915_capture_error_state() to make 3718a905236SJesse Barnes * sure we get a record and make it available in debugfs. Fire a uevent 3728a905236SJesse Barnes * so userspace knows something bad happened (should trigger collection 3738a905236SJesse Barnes * of a ring dump etc.). 3748a905236SJesse Barnes */ 3758a905236SJesse Barnes static void i915_handle_error(struct drm_device *dev) 376c0e09200SDave Airlie { 3778a905236SJesse Barnes struct drm_i915_private *dev_priv = dev->dev_private; 37863eeaf38SJesse Barnes u32 eir = I915_READ(EIR); 3798a905236SJesse Barnes u32 pipea_stats = I915_READ(PIPEASTAT); 3808a905236SJesse Barnes u32 pipeb_stats = I915_READ(PIPEBSTAT); 38163eeaf38SJesse Barnes 38263eeaf38SJesse Barnes i915_capture_error_state(dev); 38363eeaf38SJesse Barnes 38463eeaf38SJesse Barnes printk(KERN_ERR "render error detected, EIR: 0x%08x\n", 38563eeaf38SJesse Barnes eir); 3868a905236SJesse Barnes 3878a905236SJesse Barnes if (IS_G4X(dev)) { 3888a905236SJesse Barnes if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) { 3898a905236SJesse Barnes u32 ipeir = I915_READ(IPEIR_I965); 3908a905236SJesse Barnes 3918a905236SJesse Barnes printk(KERN_ERR " IPEIR: 0x%08x\n", 3928a905236SJesse Barnes I915_READ(IPEIR_I965)); 3938a905236SJesse Barnes printk(KERN_ERR " IPEHR: 0x%08x\n", 3948a905236SJesse Barnes I915_READ(IPEHR_I965)); 3958a905236SJesse Barnes printk(KERN_ERR " INSTDONE: 0x%08x\n", 3968a905236SJesse Barnes I915_READ(INSTDONE_I965)); 3978a905236SJesse Barnes printk(KERN_ERR " INSTPS: 0x%08x\n", 3988a905236SJesse Barnes I915_READ(INSTPS)); 3998a905236SJesse Barnes printk(KERN_ERR " INSTDONE1: 0x%08x\n", 4008a905236SJesse Barnes I915_READ(INSTDONE1)); 4018a905236SJesse Barnes printk(KERN_ERR " ACTHD: 0x%08x\n", 4028a905236SJesse Barnes I915_READ(ACTHD_I965)); 4038a905236SJesse Barnes I915_WRITE(IPEIR_I965, ipeir); 4048a905236SJesse Barnes (void)I915_READ(IPEIR_I965); 4058a905236SJesse Barnes } 4068a905236SJesse Barnes if (eir & GM45_ERROR_PAGE_TABLE) { 4078a905236SJesse Barnes u32 pgtbl_err = I915_READ(PGTBL_ER); 4088a905236SJesse Barnes printk(KERN_ERR "page table error\n"); 4098a905236SJesse Barnes printk(KERN_ERR " PGTBL_ER: 0x%08x\n", 4108a905236SJesse Barnes pgtbl_err); 4118a905236SJesse Barnes I915_WRITE(PGTBL_ER, pgtbl_err); 4128a905236SJesse Barnes (void)I915_READ(PGTBL_ER); 4138a905236SJesse Barnes } 4148a905236SJesse Barnes } 4158a905236SJesse Barnes 4168a905236SJesse Barnes if (IS_I9XX(dev)) { 41763eeaf38SJesse Barnes if (eir & I915_ERROR_PAGE_TABLE) { 41863eeaf38SJesse Barnes u32 pgtbl_err = I915_READ(PGTBL_ER); 41963eeaf38SJesse Barnes printk(KERN_ERR "page table error\n"); 42063eeaf38SJesse Barnes printk(KERN_ERR " PGTBL_ER: 0x%08x\n", 42163eeaf38SJesse Barnes pgtbl_err); 42263eeaf38SJesse Barnes I915_WRITE(PGTBL_ER, pgtbl_err); 42363eeaf38SJesse Barnes (void)I915_READ(PGTBL_ER); 42463eeaf38SJesse Barnes } 4258a905236SJesse Barnes } 4268a905236SJesse Barnes 42763eeaf38SJesse Barnes if (eir & I915_ERROR_MEMORY_REFRESH) { 42863eeaf38SJesse Barnes printk(KERN_ERR "memory refresh error\n"); 42963eeaf38SJesse Barnes printk(KERN_ERR "PIPEASTAT: 0x%08x\n", 43063eeaf38SJesse Barnes pipea_stats); 43163eeaf38SJesse Barnes printk(KERN_ERR "PIPEBSTAT: 0x%08x\n", 43263eeaf38SJesse Barnes pipeb_stats); 43363eeaf38SJesse Barnes /* pipestat has already been acked */ 43463eeaf38SJesse Barnes } 43563eeaf38SJesse Barnes if (eir & I915_ERROR_INSTRUCTION) { 43663eeaf38SJesse Barnes printk(KERN_ERR "instruction error\n"); 43763eeaf38SJesse Barnes printk(KERN_ERR " INSTPM: 0x%08x\n", 43863eeaf38SJesse Barnes I915_READ(INSTPM)); 43963eeaf38SJesse Barnes if (!IS_I965G(dev)) { 44063eeaf38SJesse Barnes u32 ipeir = I915_READ(IPEIR); 44163eeaf38SJesse Barnes 44263eeaf38SJesse Barnes printk(KERN_ERR " IPEIR: 0x%08x\n", 44363eeaf38SJesse Barnes I915_READ(IPEIR)); 44463eeaf38SJesse Barnes printk(KERN_ERR " IPEHR: 0x%08x\n", 44563eeaf38SJesse Barnes I915_READ(IPEHR)); 44663eeaf38SJesse Barnes printk(KERN_ERR " INSTDONE: 0x%08x\n", 44763eeaf38SJesse Barnes I915_READ(INSTDONE)); 44863eeaf38SJesse Barnes printk(KERN_ERR " ACTHD: 0x%08x\n", 44963eeaf38SJesse Barnes I915_READ(ACTHD)); 45063eeaf38SJesse Barnes I915_WRITE(IPEIR, ipeir); 45163eeaf38SJesse Barnes (void)I915_READ(IPEIR); 45263eeaf38SJesse Barnes } else { 45363eeaf38SJesse Barnes u32 ipeir = I915_READ(IPEIR_I965); 45463eeaf38SJesse Barnes 45563eeaf38SJesse Barnes printk(KERN_ERR " IPEIR: 0x%08x\n", 45663eeaf38SJesse Barnes I915_READ(IPEIR_I965)); 45763eeaf38SJesse Barnes printk(KERN_ERR " IPEHR: 0x%08x\n", 45863eeaf38SJesse Barnes I915_READ(IPEHR_I965)); 45963eeaf38SJesse Barnes printk(KERN_ERR " INSTDONE: 0x%08x\n", 46063eeaf38SJesse Barnes I915_READ(INSTDONE_I965)); 46163eeaf38SJesse Barnes printk(KERN_ERR " INSTPS: 0x%08x\n", 46263eeaf38SJesse Barnes I915_READ(INSTPS)); 46363eeaf38SJesse Barnes printk(KERN_ERR " INSTDONE1: 0x%08x\n", 46463eeaf38SJesse Barnes I915_READ(INSTDONE1)); 46563eeaf38SJesse Barnes printk(KERN_ERR " ACTHD: 0x%08x\n", 46663eeaf38SJesse Barnes I915_READ(ACTHD_I965)); 46763eeaf38SJesse Barnes I915_WRITE(IPEIR_I965, ipeir); 46863eeaf38SJesse Barnes (void)I915_READ(IPEIR_I965); 46963eeaf38SJesse Barnes } 47063eeaf38SJesse Barnes } 47163eeaf38SJesse Barnes 47263eeaf38SJesse Barnes I915_WRITE(EIR, eir); 47363eeaf38SJesse Barnes (void)I915_READ(EIR); 47463eeaf38SJesse Barnes eir = I915_READ(EIR); 47563eeaf38SJesse Barnes if (eir) { 47663eeaf38SJesse Barnes /* 47763eeaf38SJesse Barnes * some errors might have become stuck, 47863eeaf38SJesse Barnes * mask them. 47963eeaf38SJesse Barnes */ 48063eeaf38SJesse Barnes DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir); 48163eeaf38SJesse Barnes I915_WRITE(EMR, I915_READ(EMR) | eir); 48263eeaf38SJesse Barnes I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT); 48363eeaf38SJesse Barnes } 4848a905236SJesse Barnes 485*11ed50ecSBen Gamari if (dev_priv->mm.wedged) { 486*11ed50ecSBen Gamari /* 487*11ed50ecSBen Gamari * Wakeup waiting processes so they don't hang 488*11ed50ecSBen Gamari */ 489*11ed50ecSBen Gamari printk("i915: Waking up sleeping processes\n"); 490*11ed50ecSBen Gamari DRM_WAKEUP(&dev_priv->irq_queue); 491*11ed50ecSBen Gamari } 492*11ed50ecSBen Gamari 4939c9fe1f8SEric Anholt queue_work(dev_priv->wq, &dev_priv->error_work); 4948a905236SJesse Barnes } 4958a905236SJesse Barnes 4968a905236SJesse Barnes irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS) 4978a905236SJesse Barnes { 4988a905236SJesse Barnes struct drm_device *dev = (struct drm_device *) arg; 4998a905236SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 5008a905236SJesse Barnes struct drm_i915_master_private *master_priv; 5018a905236SJesse Barnes u32 iir, new_iir; 5028a905236SJesse Barnes u32 pipea_stats, pipeb_stats; 5038a905236SJesse Barnes u32 vblank_status; 5048a905236SJesse Barnes u32 vblank_enable; 5058a905236SJesse Barnes int vblank = 0; 5068a905236SJesse Barnes unsigned long irqflags; 5078a905236SJesse Barnes int irq_received; 5088a905236SJesse Barnes int ret = IRQ_NONE; 5098a905236SJesse Barnes 5108a905236SJesse Barnes atomic_inc(&dev_priv->irq_received); 5118a905236SJesse Barnes 5128a905236SJesse Barnes if (IS_IGDNG(dev)) 5138a905236SJesse Barnes return igdng_irq_handler(dev); 5148a905236SJesse Barnes 5158a905236SJesse Barnes iir = I915_READ(IIR); 5168a905236SJesse Barnes 5178a905236SJesse Barnes if (IS_I965G(dev)) { 5188a905236SJesse Barnes vblank_status = I915_START_VBLANK_INTERRUPT_STATUS; 5198a905236SJesse Barnes vblank_enable = PIPE_START_VBLANK_INTERRUPT_ENABLE; 5208a905236SJesse Barnes } else { 5218a905236SJesse Barnes vblank_status = I915_VBLANK_INTERRUPT_STATUS; 5228a905236SJesse Barnes vblank_enable = I915_VBLANK_INTERRUPT_ENABLE; 5238a905236SJesse Barnes } 5248a905236SJesse Barnes 5258a905236SJesse Barnes for (;;) { 5268a905236SJesse Barnes irq_received = iir != 0; 5278a905236SJesse Barnes 5288a905236SJesse Barnes /* Can't rely on pipestat interrupt bit in iir as it might 5298a905236SJesse Barnes * have been cleared after the pipestat interrupt was received. 5308a905236SJesse Barnes * It doesn't set the bit in iir again, but it still produces 5318a905236SJesse Barnes * interrupts (for non-MSI). 5328a905236SJesse Barnes */ 5338a905236SJesse Barnes spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags); 5348a905236SJesse Barnes pipea_stats = I915_READ(PIPEASTAT); 5358a905236SJesse Barnes pipeb_stats = I915_READ(PIPEBSTAT); 5368a905236SJesse Barnes 5378a905236SJesse Barnes if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT) 5388a905236SJesse Barnes i915_handle_error(dev); 5398a905236SJesse Barnes 5408a905236SJesse Barnes /* 5418a905236SJesse Barnes * Clear the PIPE(A|B)STAT regs before the IIR 5428a905236SJesse Barnes */ 5438a905236SJesse Barnes if (pipea_stats & 0x8000ffff) { 5448a905236SJesse Barnes if (pipea_stats & PIPE_FIFO_UNDERRUN_STATUS) 5458a905236SJesse Barnes DRM_DEBUG("pipe a underrun\n"); 5468a905236SJesse Barnes I915_WRITE(PIPEASTAT, pipea_stats); 5478a905236SJesse Barnes irq_received = 1; 5488a905236SJesse Barnes } 5498a905236SJesse Barnes 5508a905236SJesse Barnes if (pipeb_stats & 0x8000ffff) { 5518a905236SJesse Barnes if (pipeb_stats & PIPE_FIFO_UNDERRUN_STATUS) 5528a905236SJesse Barnes DRM_DEBUG("pipe b underrun\n"); 5538a905236SJesse Barnes I915_WRITE(PIPEBSTAT, pipeb_stats); 5548a905236SJesse Barnes irq_received = 1; 5558a905236SJesse Barnes } 5568a905236SJesse Barnes spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags); 5578a905236SJesse Barnes 5588a905236SJesse Barnes if (!irq_received) 5598a905236SJesse Barnes break; 5608a905236SJesse Barnes 5618a905236SJesse Barnes ret = IRQ_HANDLED; 5628a905236SJesse Barnes 5638a905236SJesse Barnes /* Consume port. Then clear IIR or we'll miss events */ 5648a905236SJesse Barnes if ((I915_HAS_HOTPLUG(dev)) && 5658a905236SJesse Barnes (iir & I915_DISPLAY_PORT_INTERRUPT)) { 5668a905236SJesse Barnes u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT); 5678a905236SJesse Barnes 5688a905236SJesse Barnes DRM_DEBUG("hotplug event received, stat 0x%08x\n", 5698a905236SJesse Barnes hotplug_status); 5708a905236SJesse Barnes if (hotplug_status & dev_priv->hotplug_supported_mask) 5719c9fe1f8SEric Anholt queue_work(dev_priv->wq, 5729c9fe1f8SEric Anholt &dev_priv->hotplug_work); 5738a905236SJesse Barnes 5748a905236SJesse Barnes I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status); 5758a905236SJesse Barnes I915_READ(PORT_HOTPLUG_STAT); 57604302965SShaohua Li 57704302965SShaohua Li /* EOS interrupts occurs */ 57804302965SShaohua Li if (IS_IGD(dev) && 57904302965SShaohua Li (hotplug_status & CRT_EOS_INT_STATUS)) { 58004302965SShaohua Li u32 temp; 58104302965SShaohua Li 58204302965SShaohua Li DRM_DEBUG("EOS interrupt occurs\n"); 58304302965SShaohua Li /* status is already cleared */ 58404302965SShaohua Li temp = I915_READ(ADPA); 58504302965SShaohua Li temp &= ~ADPA_DAC_ENABLE; 58604302965SShaohua Li I915_WRITE(ADPA, temp); 58704302965SShaohua Li 58804302965SShaohua Li temp = I915_READ(PORT_HOTPLUG_EN); 58904302965SShaohua Li temp &= ~CRT_EOS_INT_EN; 59004302965SShaohua Li I915_WRITE(PORT_HOTPLUG_EN, temp); 59104302965SShaohua Li 59204302965SShaohua Li temp = I915_READ(PORT_HOTPLUG_STAT); 59304302965SShaohua Li if (temp & CRT_EOS_INT_STATUS) 59404302965SShaohua Li I915_WRITE(PORT_HOTPLUG_STAT, 59504302965SShaohua Li CRT_EOS_INT_STATUS); 59604302965SShaohua Li } 59763eeaf38SJesse Barnes } 59863eeaf38SJesse Barnes 599673a394bSEric Anholt I915_WRITE(IIR, iir); 600cdfbc41fSEric Anholt new_iir = I915_READ(IIR); /* Flush posted writes */ 6017c463586SKeith Packard 6027c1c2871SDave Airlie if (dev->primary->master) { 6037c1c2871SDave Airlie master_priv = dev->primary->master->driver_priv; 6047c1c2871SDave Airlie if (master_priv->sarea_priv) 6057c1c2871SDave Airlie master_priv->sarea_priv->last_dispatch = 606c99b058fSKristian Høgsberg READ_BREADCRUMB(dev_priv); 6077c1c2871SDave Airlie } 6080a3e67a4SJesse Barnes 609673a394bSEric Anholt if (iir & I915_USER_INTERRUPT) { 610673a394bSEric Anholt dev_priv->mm.irq_gem_seqno = i915_get_gem_seqno(dev); 611673a394bSEric Anholt DRM_WAKEUP(&dev_priv->irq_queue); 612f65d9421SBen Gamari dev_priv->hangcheck_count = 0; 613f65d9421SBen Gamari mod_timer(&dev_priv->hangcheck_timer, jiffies + DRM_I915_HANGCHECK_PERIOD); 614673a394bSEric Anholt } 615673a394bSEric Anholt 61605eff845SKeith Packard if (pipea_stats & vblank_status) { 6177c463586SKeith Packard vblank++; 6187c463586SKeith Packard drm_handle_vblank(dev, 0); 6197c463586SKeith Packard } 6207c463586SKeith Packard 62105eff845SKeith Packard if (pipeb_stats & vblank_status) { 6227c463586SKeith Packard vblank++; 6237c463586SKeith Packard drm_handle_vblank(dev, 1); 6247c463586SKeith Packard } 6257c463586SKeith Packard 6267c463586SKeith Packard if ((pipeb_stats & I915_LEGACY_BLC_EVENT_STATUS) || 6277c463586SKeith Packard (iir & I915_ASLE_INTERRUPT)) 628673a394bSEric Anholt opregion_asle_intr(dev); 6290a3e67a4SJesse Barnes 630cdfbc41fSEric Anholt /* With MSI, interrupts are only generated when iir 631cdfbc41fSEric Anholt * transitions from zero to nonzero. If another bit got 632cdfbc41fSEric Anholt * set while we were handling the existing iir bits, then 633cdfbc41fSEric Anholt * we would never get another interrupt. 634cdfbc41fSEric Anholt * 635cdfbc41fSEric Anholt * This is fine on non-MSI as well, as if we hit this path 636cdfbc41fSEric Anholt * we avoid exiting the interrupt handler only to generate 637cdfbc41fSEric Anholt * another one. 638cdfbc41fSEric Anholt * 639cdfbc41fSEric Anholt * Note that for MSI this could cause a stray interrupt report 640cdfbc41fSEric Anholt * if an interrupt landed in the time between writing IIR and 641cdfbc41fSEric Anholt * the posting read. This should be rare enough to never 642cdfbc41fSEric Anholt * trigger the 99% of 100,000 interrupts test for disabling 643cdfbc41fSEric Anholt * stray interrupts. 644cdfbc41fSEric Anholt */ 645cdfbc41fSEric Anholt iir = new_iir; 64605eff845SKeith Packard } 647cdfbc41fSEric Anholt 64805eff845SKeith Packard return ret; 649c0e09200SDave Airlie } 650c0e09200SDave Airlie 651c0e09200SDave Airlie static int i915_emit_irq(struct drm_device * dev) 652c0e09200SDave Airlie { 653c0e09200SDave Airlie drm_i915_private_t *dev_priv = dev->dev_private; 6547c1c2871SDave Airlie struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv; 655c0e09200SDave Airlie RING_LOCALS; 656c0e09200SDave Airlie 657c0e09200SDave Airlie i915_kernel_lost_context(dev); 658c0e09200SDave Airlie 659c0e09200SDave Airlie DRM_DEBUG("\n"); 660c0e09200SDave Airlie 661c99b058fSKristian Høgsberg dev_priv->counter++; 662c0e09200SDave Airlie if (dev_priv->counter > 0x7FFFFFFFUL) 663c99b058fSKristian Høgsberg dev_priv->counter = 1; 6647c1c2871SDave Airlie if (master_priv->sarea_priv) 6657c1c2871SDave Airlie master_priv->sarea_priv->last_enqueue = dev_priv->counter; 666c0e09200SDave Airlie 6670baf823aSKeith Packard BEGIN_LP_RING(4); 668585fb111SJesse Barnes OUT_RING(MI_STORE_DWORD_INDEX); 6690baf823aSKeith Packard OUT_RING(I915_BREADCRUMB_INDEX << MI_STORE_DWORD_INDEX_SHIFT); 670c0e09200SDave Airlie OUT_RING(dev_priv->counter); 671585fb111SJesse Barnes OUT_RING(MI_USER_INTERRUPT); 672c0e09200SDave Airlie ADVANCE_LP_RING(); 673c0e09200SDave Airlie 674c0e09200SDave Airlie return dev_priv->counter; 675c0e09200SDave Airlie } 676c0e09200SDave Airlie 677673a394bSEric Anholt void i915_user_irq_get(struct drm_device *dev) 678ed4cb414SEric Anholt { 679ed4cb414SEric Anholt drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 680e9d21d7fSKeith Packard unsigned long irqflags; 681ed4cb414SEric Anholt 682e9d21d7fSKeith Packard spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags); 683036a4a7dSZhenyu Wang if (dev->irq_enabled && (++dev_priv->user_irq_refcount == 1)) { 684036a4a7dSZhenyu Wang if (IS_IGDNG(dev)) 685036a4a7dSZhenyu Wang igdng_enable_graphics_irq(dev_priv, GT_USER_INTERRUPT); 686036a4a7dSZhenyu Wang else 687ed4cb414SEric Anholt i915_enable_irq(dev_priv, I915_USER_INTERRUPT); 688036a4a7dSZhenyu Wang } 689e9d21d7fSKeith Packard spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags); 690ed4cb414SEric Anholt } 691ed4cb414SEric Anholt 6920a3e67a4SJesse Barnes void i915_user_irq_put(struct drm_device *dev) 693ed4cb414SEric Anholt { 694ed4cb414SEric Anholt drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 695e9d21d7fSKeith Packard unsigned long irqflags; 696ed4cb414SEric Anholt 697e9d21d7fSKeith Packard spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags); 698ed4cb414SEric Anholt BUG_ON(dev->irq_enabled && dev_priv->user_irq_refcount <= 0); 699036a4a7dSZhenyu Wang if (dev->irq_enabled && (--dev_priv->user_irq_refcount == 0)) { 700036a4a7dSZhenyu Wang if (IS_IGDNG(dev)) 701036a4a7dSZhenyu Wang igdng_disable_graphics_irq(dev_priv, GT_USER_INTERRUPT); 702036a4a7dSZhenyu Wang else 703ed4cb414SEric Anholt i915_disable_irq(dev_priv, I915_USER_INTERRUPT); 704036a4a7dSZhenyu Wang } 705e9d21d7fSKeith Packard spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags); 706ed4cb414SEric Anholt } 707ed4cb414SEric Anholt 708c0e09200SDave Airlie static int i915_wait_irq(struct drm_device * dev, int irq_nr) 709c0e09200SDave Airlie { 710c0e09200SDave Airlie drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 7117c1c2871SDave Airlie struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv; 712c0e09200SDave Airlie int ret = 0; 713c0e09200SDave Airlie 714c0e09200SDave Airlie DRM_DEBUG("irq_nr=%d breadcrumb=%d\n", irq_nr, 715c0e09200SDave Airlie READ_BREADCRUMB(dev_priv)); 716c0e09200SDave Airlie 717ed4cb414SEric Anholt if (READ_BREADCRUMB(dev_priv) >= irq_nr) { 7187c1c2871SDave Airlie if (master_priv->sarea_priv) 7197c1c2871SDave Airlie master_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv); 720c0e09200SDave Airlie return 0; 721ed4cb414SEric Anholt } 722c0e09200SDave Airlie 7237c1c2871SDave Airlie if (master_priv->sarea_priv) 7247c1c2871SDave Airlie master_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT; 725c0e09200SDave Airlie 726ed4cb414SEric Anholt i915_user_irq_get(dev); 727c0e09200SDave Airlie DRM_WAIT_ON(ret, dev_priv->irq_queue, 3 * DRM_HZ, 728c0e09200SDave Airlie READ_BREADCRUMB(dev_priv) >= irq_nr); 729ed4cb414SEric Anholt i915_user_irq_put(dev); 730c0e09200SDave Airlie 731c0e09200SDave Airlie if (ret == -EBUSY) { 732c0e09200SDave Airlie DRM_ERROR("EBUSY -- rec: %d emitted: %d\n", 733c0e09200SDave Airlie READ_BREADCRUMB(dev_priv), (int)dev_priv->counter); 734c0e09200SDave Airlie } 735c0e09200SDave Airlie 736c0e09200SDave Airlie return ret; 737c0e09200SDave Airlie } 738c0e09200SDave Airlie 739c0e09200SDave Airlie /* Needs the lock as it touches the ring. 740c0e09200SDave Airlie */ 741c0e09200SDave Airlie int i915_irq_emit(struct drm_device *dev, void *data, 742c0e09200SDave Airlie struct drm_file *file_priv) 743c0e09200SDave Airlie { 744c0e09200SDave Airlie drm_i915_private_t *dev_priv = dev->dev_private; 745c0e09200SDave Airlie drm_i915_irq_emit_t *emit = data; 746c0e09200SDave Airlie int result; 747c0e09200SDave Airlie 74807f4f8bfSEric Anholt if (!dev_priv || !dev_priv->ring.virtual_start) { 749c0e09200SDave Airlie DRM_ERROR("called with no initialization\n"); 750c0e09200SDave Airlie return -EINVAL; 751c0e09200SDave Airlie } 752299eb93cSEric Anholt 753299eb93cSEric Anholt RING_LOCK_TEST_WITH_RETURN(dev, file_priv); 754299eb93cSEric Anholt 755546b0974SEric Anholt mutex_lock(&dev->struct_mutex); 756c0e09200SDave Airlie result = i915_emit_irq(dev); 757546b0974SEric Anholt mutex_unlock(&dev->struct_mutex); 758c0e09200SDave Airlie 759c0e09200SDave Airlie if (DRM_COPY_TO_USER(emit->irq_seq, &result, sizeof(int))) { 760c0e09200SDave Airlie DRM_ERROR("copy_to_user\n"); 761c0e09200SDave Airlie return -EFAULT; 762c0e09200SDave Airlie } 763c0e09200SDave Airlie 764c0e09200SDave Airlie return 0; 765c0e09200SDave Airlie } 766c0e09200SDave Airlie 767c0e09200SDave Airlie /* Doesn't need the hardware lock. 768c0e09200SDave Airlie */ 769c0e09200SDave Airlie int i915_irq_wait(struct drm_device *dev, void *data, 770c0e09200SDave Airlie struct drm_file *file_priv) 771c0e09200SDave Airlie { 772c0e09200SDave Airlie drm_i915_private_t *dev_priv = dev->dev_private; 773c0e09200SDave Airlie drm_i915_irq_wait_t *irqwait = data; 774c0e09200SDave Airlie 775c0e09200SDave Airlie if (!dev_priv) { 776c0e09200SDave Airlie DRM_ERROR("called with no initialization\n"); 777c0e09200SDave Airlie return -EINVAL; 778c0e09200SDave Airlie } 779c0e09200SDave Airlie 780c0e09200SDave Airlie return i915_wait_irq(dev, irqwait->irq_seq); 781c0e09200SDave Airlie } 782c0e09200SDave Airlie 78342f52ef8SKeith Packard /* Called from drm generic code, passed 'crtc' which 78442f52ef8SKeith Packard * we use as a pipe index 78542f52ef8SKeith Packard */ 78642f52ef8SKeith Packard int i915_enable_vblank(struct drm_device *dev, int pipe) 7870a3e67a4SJesse Barnes { 7880a3e67a4SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 789e9d21d7fSKeith Packard unsigned long irqflags; 79071e0ffa5SJesse Barnes int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF; 79171e0ffa5SJesse Barnes u32 pipeconf; 79271e0ffa5SJesse Barnes 79371e0ffa5SJesse Barnes pipeconf = I915_READ(pipeconf_reg); 79471e0ffa5SJesse Barnes if (!(pipeconf & PIPEACONF_ENABLE)) 79571e0ffa5SJesse Barnes return -EINVAL; 7960a3e67a4SJesse Barnes 797036a4a7dSZhenyu Wang if (IS_IGDNG(dev)) 798036a4a7dSZhenyu Wang return 0; 799036a4a7dSZhenyu Wang 800e9d21d7fSKeith Packard spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags); 8010a3e67a4SJesse Barnes if (IS_I965G(dev)) 8027c463586SKeith Packard i915_enable_pipestat(dev_priv, pipe, 8037c463586SKeith Packard PIPE_START_VBLANK_INTERRUPT_ENABLE); 8040a3e67a4SJesse Barnes else 8057c463586SKeith Packard i915_enable_pipestat(dev_priv, pipe, 8067c463586SKeith Packard PIPE_VBLANK_INTERRUPT_ENABLE); 807e9d21d7fSKeith Packard spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags); 8080a3e67a4SJesse Barnes return 0; 8090a3e67a4SJesse Barnes } 8100a3e67a4SJesse Barnes 81142f52ef8SKeith Packard /* Called from drm generic code, passed 'crtc' which 81242f52ef8SKeith Packard * we use as a pipe index 81342f52ef8SKeith Packard */ 81442f52ef8SKeith Packard void i915_disable_vblank(struct drm_device *dev, int pipe) 8150a3e67a4SJesse Barnes { 8160a3e67a4SJesse Barnes drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 817e9d21d7fSKeith Packard unsigned long irqflags; 8180a3e67a4SJesse Barnes 819036a4a7dSZhenyu Wang if (IS_IGDNG(dev)) 820036a4a7dSZhenyu Wang return; 821036a4a7dSZhenyu Wang 822e9d21d7fSKeith Packard spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags); 8237c463586SKeith Packard i915_disable_pipestat(dev_priv, pipe, 8247c463586SKeith Packard PIPE_VBLANK_INTERRUPT_ENABLE | 8257c463586SKeith Packard PIPE_START_VBLANK_INTERRUPT_ENABLE); 826e9d21d7fSKeith Packard spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags); 8270a3e67a4SJesse Barnes } 8280a3e67a4SJesse Barnes 82979e53945SJesse Barnes void i915_enable_interrupt (struct drm_device *dev) 83079e53945SJesse Barnes { 83179e53945SJesse Barnes struct drm_i915_private *dev_priv = dev->dev_private; 832e170b030SZhenyu Wang 833e170b030SZhenyu Wang if (!IS_IGDNG(dev)) 83479e53945SJesse Barnes opregion_enable_asle(dev); 83579e53945SJesse Barnes dev_priv->irq_enabled = 1; 83679e53945SJesse Barnes } 83779e53945SJesse Barnes 83879e53945SJesse Barnes 839c0e09200SDave Airlie /* Set the vblank monitor pipe 840c0e09200SDave Airlie */ 841c0e09200SDave Airlie int i915_vblank_pipe_set(struct drm_device *dev, void *data, 842c0e09200SDave Airlie struct drm_file *file_priv) 843c0e09200SDave Airlie { 844c0e09200SDave Airlie drm_i915_private_t *dev_priv = dev->dev_private; 845c0e09200SDave Airlie 846c0e09200SDave Airlie if (!dev_priv) { 847c0e09200SDave Airlie DRM_ERROR("called with no initialization\n"); 848c0e09200SDave Airlie return -EINVAL; 849c0e09200SDave Airlie } 850c0e09200SDave Airlie 851c0e09200SDave Airlie return 0; 852c0e09200SDave Airlie } 853c0e09200SDave Airlie 854c0e09200SDave Airlie int i915_vblank_pipe_get(struct drm_device *dev, void *data, 855c0e09200SDave Airlie struct drm_file *file_priv) 856c0e09200SDave Airlie { 857c0e09200SDave Airlie drm_i915_private_t *dev_priv = dev->dev_private; 858c0e09200SDave Airlie drm_i915_vblank_pipe_t *pipe = data; 859c0e09200SDave Airlie 860c0e09200SDave Airlie if (!dev_priv) { 861c0e09200SDave Airlie DRM_ERROR("called with no initialization\n"); 862c0e09200SDave Airlie return -EINVAL; 863c0e09200SDave Airlie } 864c0e09200SDave Airlie 8650a3e67a4SJesse Barnes pipe->pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B; 866c0e09200SDave Airlie 867c0e09200SDave Airlie return 0; 868c0e09200SDave Airlie } 869c0e09200SDave Airlie 870c0e09200SDave Airlie /** 871c0e09200SDave Airlie * Schedule buffer swap at given vertical blank. 872c0e09200SDave Airlie */ 873c0e09200SDave Airlie int i915_vblank_swap(struct drm_device *dev, void *data, 874c0e09200SDave Airlie struct drm_file *file_priv) 875c0e09200SDave Airlie { 876bd95e0a4SEric Anholt /* The delayed swap mechanism was fundamentally racy, and has been 877bd95e0a4SEric Anholt * removed. The model was that the client requested a delayed flip/swap 878bd95e0a4SEric Anholt * from the kernel, then waited for vblank before continuing to perform 879bd95e0a4SEric Anholt * rendering. The problem was that the kernel might wake the client 880bd95e0a4SEric Anholt * up before it dispatched the vblank swap (since the lock has to be 881bd95e0a4SEric Anholt * held while touching the ringbuffer), in which case the client would 882bd95e0a4SEric Anholt * clear and start the next frame before the swap occurred, and 883bd95e0a4SEric Anholt * flicker would occur in addition to likely missing the vblank. 884bd95e0a4SEric Anholt * 885bd95e0a4SEric Anholt * In the absence of this ioctl, userland falls back to a correct path 886bd95e0a4SEric Anholt * of waiting for a vblank, then dispatching the swap on its own. 887bd95e0a4SEric Anholt * Context switching to userland and back is plenty fast enough for 888bd95e0a4SEric Anholt * meeting the requirements of vblank swapping. 8890a3e67a4SJesse Barnes */ 890c0e09200SDave Airlie return -EINVAL; 891c0e09200SDave Airlie } 892c0e09200SDave Airlie 893f65d9421SBen Gamari struct drm_i915_gem_request *i915_get_tail_request(struct drm_device *dev) { 894f65d9421SBen Gamari drm_i915_private_t *dev_priv = dev->dev_private; 895f65d9421SBen Gamari return list_entry(dev_priv->mm.request_list.prev, struct drm_i915_gem_request, list); 896f65d9421SBen Gamari } 897f65d9421SBen Gamari 898f65d9421SBen Gamari /** 899f65d9421SBen Gamari * This is called when the chip hasn't reported back with completed 900f65d9421SBen Gamari * batchbuffers in a long time. The first time this is called we simply record 901f65d9421SBen Gamari * ACTHD. If ACTHD hasn't changed by the time the hangcheck timer elapses 902f65d9421SBen Gamari * again, we assume the chip is wedged and try to fix it. 903f65d9421SBen Gamari */ 904f65d9421SBen Gamari void i915_hangcheck_elapsed(unsigned long data) 905f65d9421SBen Gamari { 906f65d9421SBen Gamari struct drm_device *dev = (struct drm_device *)data; 907f65d9421SBen Gamari drm_i915_private_t *dev_priv = dev->dev_private; 908f65d9421SBen Gamari uint32_t acthd; 909f65d9421SBen Gamari 910f65d9421SBen Gamari if (!IS_I965G(dev)) 911f65d9421SBen Gamari acthd = I915_READ(ACTHD); 912f65d9421SBen Gamari else 913f65d9421SBen Gamari acthd = I915_READ(ACTHD_I965); 914f65d9421SBen Gamari 915f65d9421SBen Gamari /* If all work is done then ACTHD clearly hasn't advanced. */ 916f65d9421SBen Gamari if (list_empty(&dev_priv->mm.request_list) || 917f65d9421SBen Gamari i915_seqno_passed(i915_get_gem_seqno(dev), i915_get_tail_request(dev)->seqno)) { 918f65d9421SBen Gamari dev_priv->hangcheck_count = 0; 919f65d9421SBen Gamari return; 920f65d9421SBen Gamari } 921f65d9421SBen Gamari 922f65d9421SBen Gamari if (dev_priv->last_acthd == acthd && dev_priv->hangcheck_count > 0) { 923f65d9421SBen Gamari DRM_ERROR("Hangcheck timer elapsed... GPU hung\n"); 924f65d9421SBen Gamari dev_priv->mm.wedged = true; /* Hopefully this is atomic */ 925f65d9421SBen Gamari i915_handle_error(dev); 926f65d9421SBen Gamari return; 927f65d9421SBen Gamari } 928f65d9421SBen Gamari 929f65d9421SBen Gamari /* Reset timer case chip hangs without another request being added */ 930f65d9421SBen Gamari mod_timer(&dev_priv->hangcheck_timer, jiffies + DRM_I915_HANGCHECK_PERIOD); 931f65d9421SBen Gamari 932f65d9421SBen Gamari if (acthd != dev_priv->last_acthd) 933f65d9421SBen Gamari dev_priv->hangcheck_count = 0; 934f65d9421SBen Gamari else 935f65d9421SBen Gamari dev_priv->hangcheck_count++; 936f65d9421SBen Gamari 937f65d9421SBen Gamari dev_priv->last_acthd = acthd; 938f65d9421SBen Gamari } 939f65d9421SBen Gamari 940c0e09200SDave Airlie /* drm_dma.h hooks 941c0e09200SDave Airlie */ 942036a4a7dSZhenyu Wang static void igdng_irq_preinstall(struct drm_device *dev) 943036a4a7dSZhenyu Wang { 944036a4a7dSZhenyu Wang drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 945036a4a7dSZhenyu Wang 946036a4a7dSZhenyu Wang I915_WRITE(HWSTAM, 0xeffe); 947036a4a7dSZhenyu Wang 948036a4a7dSZhenyu Wang /* XXX hotplug from PCH */ 949036a4a7dSZhenyu Wang 950036a4a7dSZhenyu Wang I915_WRITE(DEIMR, 0xffffffff); 951036a4a7dSZhenyu Wang I915_WRITE(DEIER, 0x0); 952036a4a7dSZhenyu Wang (void) I915_READ(DEIER); 953036a4a7dSZhenyu Wang 954036a4a7dSZhenyu Wang /* and GT */ 955036a4a7dSZhenyu Wang I915_WRITE(GTIMR, 0xffffffff); 956036a4a7dSZhenyu Wang I915_WRITE(GTIER, 0x0); 957036a4a7dSZhenyu Wang (void) I915_READ(GTIER); 958036a4a7dSZhenyu Wang } 959036a4a7dSZhenyu Wang 960036a4a7dSZhenyu Wang static int igdng_irq_postinstall(struct drm_device *dev) 961036a4a7dSZhenyu Wang { 962036a4a7dSZhenyu Wang drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 963036a4a7dSZhenyu Wang /* enable kind of interrupts always enabled */ 964036a4a7dSZhenyu Wang u32 display_mask = DE_MASTER_IRQ_CONTROL /*| DE_PCH_EVENT */; 965036a4a7dSZhenyu Wang u32 render_mask = GT_USER_INTERRUPT; 966036a4a7dSZhenyu Wang 967036a4a7dSZhenyu Wang dev_priv->irq_mask_reg = ~display_mask; 968036a4a7dSZhenyu Wang dev_priv->de_irq_enable_reg = display_mask; 969036a4a7dSZhenyu Wang 970036a4a7dSZhenyu Wang /* should always can generate irq */ 971036a4a7dSZhenyu Wang I915_WRITE(DEIIR, I915_READ(DEIIR)); 972036a4a7dSZhenyu Wang I915_WRITE(DEIMR, dev_priv->irq_mask_reg); 973036a4a7dSZhenyu Wang I915_WRITE(DEIER, dev_priv->de_irq_enable_reg); 974036a4a7dSZhenyu Wang (void) I915_READ(DEIER); 975036a4a7dSZhenyu Wang 976036a4a7dSZhenyu Wang /* user interrupt should be enabled, but masked initial */ 977036a4a7dSZhenyu Wang dev_priv->gt_irq_mask_reg = 0xffffffff; 978036a4a7dSZhenyu Wang dev_priv->gt_irq_enable_reg = render_mask; 979036a4a7dSZhenyu Wang 980036a4a7dSZhenyu Wang I915_WRITE(GTIIR, I915_READ(GTIIR)); 981036a4a7dSZhenyu Wang I915_WRITE(GTIMR, dev_priv->gt_irq_mask_reg); 982036a4a7dSZhenyu Wang I915_WRITE(GTIER, dev_priv->gt_irq_enable_reg); 983036a4a7dSZhenyu Wang (void) I915_READ(GTIER); 984036a4a7dSZhenyu Wang 985036a4a7dSZhenyu Wang return 0; 986036a4a7dSZhenyu Wang } 987036a4a7dSZhenyu Wang 988c0e09200SDave Airlie void i915_driver_irq_preinstall(struct drm_device * dev) 989c0e09200SDave Airlie { 990c0e09200SDave Airlie drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 991c0e09200SDave Airlie 99279e53945SJesse Barnes atomic_set(&dev_priv->irq_received, 0); 99379e53945SJesse Barnes 994036a4a7dSZhenyu Wang INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func); 9958a905236SJesse Barnes INIT_WORK(&dev_priv->error_work, i915_error_work_func); 996036a4a7dSZhenyu Wang 997036a4a7dSZhenyu Wang if (IS_IGDNG(dev)) { 998036a4a7dSZhenyu Wang igdng_irq_preinstall(dev); 999036a4a7dSZhenyu Wang return; 1000036a4a7dSZhenyu Wang } 1001036a4a7dSZhenyu Wang 10025ca58282SJesse Barnes if (I915_HAS_HOTPLUG(dev)) { 10035ca58282SJesse Barnes I915_WRITE(PORT_HOTPLUG_EN, 0); 10045ca58282SJesse Barnes I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 10055ca58282SJesse Barnes } 10065ca58282SJesse Barnes 10070a3e67a4SJesse Barnes I915_WRITE(HWSTAM, 0xeffe); 10087c463586SKeith Packard I915_WRITE(PIPEASTAT, 0); 10097c463586SKeith Packard I915_WRITE(PIPEBSTAT, 0); 10100a3e67a4SJesse Barnes I915_WRITE(IMR, 0xffffffff); 1011ed4cb414SEric Anholt I915_WRITE(IER, 0x0); 10127c463586SKeith Packard (void) I915_READ(IER); 1013c0e09200SDave Airlie } 1014c0e09200SDave Airlie 10150a3e67a4SJesse Barnes int i915_driver_irq_postinstall(struct drm_device *dev) 1016c0e09200SDave Airlie { 1017c0e09200SDave Airlie drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 10185ca58282SJesse Barnes u32 enable_mask = I915_INTERRUPT_ENABLE_FIX | I915_INTERRUPT_ENABLE_VAR; 101963eeaf38SJesse Barnes u32 error_mask; 10200a3e67a4SJesse Barnes 1021036a4a7dSZhenyu Wang DRM_INIT_WAITQUEUE(&dev_priv->irq_queue); 1022036a4a7dSZhenyu Wang 10230a3e67a4SJesse Barnes dev_priv->vblank_pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B; 1024ed4cb414SEric Anholt 1025036a4a7dSZhenyu Wang if (IS_IGDNG(dev)) 1026036a4a7dSZhenyu Wang return igdng_irq_postinstall(dev); 1027036a4a7dSZhenyu Wang 10287c463586SKeith Packard /* Unmask the interrupts that we always want on. */ 10297c463586SKeith Packard dev_priv->irq_mask_reg = ~I915_INTERRUPT_ENABLE_FIX; 10308ee1c3dbSMatthew Garrett 10317c463586SKeith Packard dev_priv->pipestat[0] = 0; 10327c463586SKeith Packard dev_priv->pipestat[1] = 0; 10337c463586SKeith Packard 10345ca58282SJesse Barnes if (I915_HAS_HOTPLUG(dev)) { 10355ca58282SJesse Barnes u32 hotplug_en = I915_READ(PORT_HOTPLUG_EN); 10365ca58282SJesse Barnes 10375ca58282SJesse Barnes /* Leave other bits alone */ 10385ca58282SJesse Barnes hotplug_en |= HOTPLUG_EN_MASK; 10395ca58282SJesse Barnes I915_WRITE(PORT_HOTPLUG_EN, hotplug_en); 10405ca58282SJesse Barnes 10415ca58282SJesse Barnes dev_priv->hotplug_supported_mask = CRT_HOTPLUG_INT_STATUS | 10425ca58282SJesse Barnes TV_HOTPLUG_INT_STATUS | SDVOC_HOTPLUG_INT_STATUS | 10435ca58282SJesse Barnes SDVOB_HOTPLUG_INT_STATUS; 10445ca58282SJesse Barnes if (IS_G4X(dev)) { 10455ca58282SJesse Barnes dev_priv->hotplug_supported_mask |= 10465ca58282SJesse Barnes HDMIB_HOTPLUG_INT_STATUS | 10475ca58282SJesse Barnes HDMIC_HOTPLUG_INT_STATUS | 10485ca58282SJesse Barnes HDMID_HOTPLUG_INT_STATUS; 10495ca58282SJesse Barnes } 10505ca58282SJesse Barnes /* Enable in IER... */ 10515ca58282SJesse Barnes enable_mask |= I915_DISPLAY_PORT_INTERRUPT; 10525ca58282SJesse Barnes /* and unmask in IMR */ 10535ca58282SJesse Barnes i915_enable_irq(dev_priv, I915_DISPLAY_PORT_INTERRUPT); 10545ca58282SJesse Barnes } 10555ca58282SJesse Barnes 105663eeaf38SJesse Barnes /* 105763eeaf38SJesse Barnes * Enable some error detection, note the instruction error mask 105863eeaf38SJesse Barnes * bit is reserved, so we leave it masked. 105963eeaf38SJesse Barnes */ 106063eeaf38SJesse Barnes if (IS_G4X(dev)) { 106163eeaf38SJesse Barnes error_mask = ~(GM45_ERROR_PAGE_TABLE | 106263eeaf38SJesse Barnes GM45_ERROR_MEM_PRIV | 106363eeaf38SJesse Barnes GM45_ERROR_CP_PRIV | 106463eeaf38SJesse Barnes I915_ERROR_MEMORY_REFRESH); 106563eeaf38SJesse Barnes } else { 106663eeaf38SJesse Barnes error_mask = ~(I915_ERROR_PAGE_TABLE | 106763eeaf38SJesse Barnes I915_ERROR_MEMORY_REFRESH); 106863eeaf38SJesse Barnes } 106963eeaf38SJesse Barnes I915_WRITE(EMR, error_mask); 107063eeaf38SJesse Barnes 10717c463586SKeith Packard /* Disable pipe interrupt enables, clear pending pipe status */ 10727c463586SKeith Packard I915_WRITE(PIPEASTAT, I915_READ(PIPEASTAT) & 0x8000ffff); 10737c463586SKeith Packard I915_WRITE(PIPEBSTAT, I915_READ(PIPEBSTAT) & 0x8000ffff); 10747c463586SKeith Packard /* Clear pending interrupt status */ 10757c463586SKeith Packard I915_WRITE(IIR, I915_READ(IIR)); 10767c463586SKeith Packard 10775ca58282SJesse Barnes I915_WRITE(IER, enable_mask); 10787c463586SKeith Packard I915_WRITE(IMR, dev_priv->irq_mask_reg); 1079ed4cb414SEric Anholt (void) I915_READ(IER); 1080ed4cb414SEric Anholt 10818ee1c3dbSMatthew Garrett opregion_enable_asle(dev); 10820a3e67a4SJesse Barnes 10830a3e67a4SJesse Barnes return 0; 1084c0e09200SDave Airlie } 1085c0e09200SDave Airlie 1086036a4a7dSZhenyu Wang static void igdng_irq_uninstall(struct drm_device *dev) 1087036a4a7dSZhenyu Wang { 1088036a4a7dSZhenyu Wang drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 1089036a4a7dSZhenyu Wang I915_WRITE(HWSTAM, 0xffffffff); 1090036a4a7dSZhenyu Wang 1091036a4a7dSZhenyu Wang I915_WRITE(DEIMR, 0xffffffff); 1092036a4a7dSZhenyu Wang I915_WRITE(DEIER, 0x0); 1093036a4a7dSZhenyu Wang I915_WRITE(DEIIR, I915_READ(DEIIR)); 1094036a4a7dSZhenyu Wang 1095036a4a7dSZhenyu Wang I915_WRITE(GTIMR, 0xffffffff); 1096036a4a7dSZhenyu Wang I915_WRITE(GTIER, 0x0); 1097036a4a7dSZhenyu Wang I915_WRITE(GTIIR, I915_READ(GTIIR)); 1098036a4a7dSZhenyu Wang } 1099036a4a7dSZhenyu Wang 1100c0e09200SDave Airlie void i915_driver_irq_uninstall(struct drm_device * dev) 1101c0e09200SDave Airlie { 1102c0e09200SDave Airlie drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 1103c0e09200SDave Airlie 1104c0e09200SDave Airlie if (!dev_priv) 1105c0e09200SDave Airlie return; 1106c0e09200SDave Airlie 11070a3e67a4SJesse Barnes dev_priv->vblank_pipe = 0; 11080a3e67a4SJesse Barnes 1109036a4a7dSZhenyu Wang if (IS_IGDNG(dev)) { 1110036a4a7dSZhenyu Wang igdng_irq_uninstall(dev); 1111036a4a7dSZhenyu Wang return; 1112036a4a7dSZhenyu Wang } 1113036a4a7dSZhenyu Wang 11145ca58282SJesse Barnes if (I915_HAS_HOTPLUG(dev)) { 11155ca58282SJesse Barnes I915_WRITE(PORT_HOTPLUG_EN, 0); 11165ca58282SJesse Barnes I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 11175ca58282SJesse Barnes } 11185ca58282SJesse Barnes 11190a3e67a4SJesse Barnes I915_WRITE(HWSTAM, 0xffffffff); 11207c463586SKeith Packard I915_WRITE(PIPEASTAT, 0); 11217c463586SKeith Packard I915_WRITE(PIPEBSTAT, 0); 11220a3e67a4SJesse Barnes I915_WRITE(IMR, 0xffffffff); 1123ed4cb414SEric Anholt I915_WRITE(IER, 0x0); 1124c0e09200SDave Airlie 11257c463586SKeith Packard I915_WRITE(PIPEASTAT, I915_READ(PIPEASTAT) & 0x8000ffff); 11267c463586SKeith Packard I915_WRITE(PIPEBSTAT, I915_READ(PIPEBSTAT) & 0x8000ffff); 11277c463586SKeith Packard I915_WRITE(IIR, I915_READ(IIR)); 1128c0e09200SDave Airlie } 1129