1494N/A/*
1611N/A * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
1494N/A */
1494N/A
1494N/A/* i915_irq.c -- IRQ support for the I915 -*- linux-c -*-
1494N/A */
1494N/A/*
1494N/A * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
1494N/A * Copyright (c) 2009, 2012, Intel Corporation.
1494N/A * All Rights Reserved.
1494N/A *
1494N/A * Permission is hereby granted, free of charge, to any person obtaining a
1494N/A * copy of this software and associated documentation files (the
1494N/A * "Software"), to deal in the Software without restriction, including
1494N/A * without limitation the rights to use, copy, modify, merge, publish,
1494N/A * distribute, sub license, and/or sell copies of the Software, and to
1494N/A * permit persons to whom the Software is furnished to do so, subject to
1494N/A * the following conditions:
1494N/A *
1494N/A * The above copyright notice and this permission notice (including the
1494N/A * next paragraph) shall be included in all copies or substantial portions
1494N/A * of the Software.
1494N/A *
1494N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1494N/A * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1494N/A * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
1494N/A * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
1494N/A * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
1494N/A * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
1494N/A * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1494N/A *
1494N/A */
1494N/A
1494N/A#include "drmP.h"
1494N/A#include "drm.h"
1494N/A#include "i915_drm.h"
1494N/A#include "i915_drv.h"
1494N/A#include "intel_drv.h"
1494N/A
1494N/Astatic const u32 hpd_ibx[] = {
1494N/A [HPD_CRT] = SDE_CRT_HOTPLUG,
1494N/A [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG,
1494N/A [HPD_PORT_B] = SDE_PORTB_HOTPLUG,
1494N/A [HPD_PORT_C] = SDE_PORTC_HOTPLUG,
1494N/A [HPD_PORT_D] = SDE_PORTD_HOTPLUG
1494N/A};
1494N/A
1494N/Astatic const u32 hpd_cpt[] = {
1494N/A [HPD_CRT] = SDE_CRT_HOTPLUG_CPT,
1494N/A [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT,
1494N/A [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
1494N/A [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
1494N/A [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT
1494N/A};
1494N/A
1494N/Astatic const u32 hpd_mask_i915[] = {
1494N/A [HPD_CRT] = CRT_HOTPLUG_INT_EN,
1494N/A [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN,
1494N/A [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN,
1494N/A [HPD_PORT_B] = PORTB_HOTPLUG_INT_EN,
1494N/A [HPD_PORT_C] = PORTC_HOTPLUG_INT_EN,
1494N/A [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN
1494N/A};
1494N/A
1494N/Astatic const u32 hpd_status_gen4[] = {
1494N/A [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
1494N/A [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X,
1494N/A [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X,
1494N/A [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
1494N/A [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
1494N/A [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
1494N/A};
1494N/A
1494N/Astatic const u32 hpd_status_i915[] = { /* i915 and valleyview are the same */
1494N/A [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
1494N/A [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915,
1494N/A [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915,
1494N/A [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
1494N/A [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
1494N/A [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
1494N/A};
1494N/A
1494N/A/* For display hotplug interrupt */
1494N/Astatic void
1494N/Aironlake_enable_display_irq(drm_i915_private_t *dev_priv, u32 mask)
1494N/A{
1494N/A assert_spin_locked(&dev_priv->irq_lock);
1494N/A
1494N/A if ((dev_priv->irq_mask & mask) != 0) {
1494N/A dev_priv->irq_mask &= ~mask;
1494N/A I915_WRITE(DEIMR, dev_priv->irq_mask);
1494N/A POSTING_READ(DEIMR);
1494N/A }
1494N/A}
1494N/A
1494N/Astatic void
1494N/Aironlake_disable_display_irq(drm_i915_private_t *dev_priv, u32 mask)
1494N/A{
1494N/A assert_spin_locked(&dev_priv->irq_lock);
1494N/A
1494N/A if ((dev_priv->irq_mask & mask) != mask) {
1494N/A dev_priv->irq_mask |= mask;
1494N/A I915_WRITE(DEIMR, dev_priv->irq_mask);
1494N/A POSTING_READ(DEIMR);
1494N/A }
1494N/A}
1494N/A
1494N/Astatic bool ivb_can_enable_err_int(struct drm_device *dev)
1494N/A{
1494N/A struct drm_i915_private *dev_priv = dev->dev_private;
1494N/A struct intel_crtc *crtc;
1494N/A enum pipe pipe;
1494N/A
1494N/A assert_spin_locked(&dev_priv->irq_lock);
1494N/A
1494N/A for_each_pipe(pipe) {
1494N/A crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
1494N/A
1494N/A if (crtc->cpu_fifo_underrun_disabled)
1494N/A return false;
1494N/A }
1494N/A
1494N/A return true;
1494N/A}
1494N/A
1494N/Astatic bool cpt_can_enable_serr_int(struct drm_device *dev)
1494N/A{
1494N/A struct drm_i915_private *dev_priv = dev->dev_private;
1494N/A enum pipe pipe;
1494N/A struct intel_crtc *crtc;
1494N/A
1494N/A for_each_pipe(pipe) {
1494N/A crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
1494N/A
1494N/A if (crtc->pch_fifo_underrun_disabled)
1494N/A return false;
1494N/A }
1494N/A
1494N/A return true;
1494N/A}
1494N/A
1494N/Astatic void ironlake_set_fifo_underrun_reporting(struct drm_device *dev,
1494N/A enum pipe pipe, bool enable)
1494N/A{
1494N/A struct drm_i915_private *dev_priv = dev->dev_private;
1494N/A uint32_t bit = (pipe == PIPE_A) ? DE_PIPEA_FIFO_UNDERRUN :
1494N/A DE_PIPEB_FIFO_UNDERRUN;
1494N/A
1494N/A if (enable)
1494N/A ironlake_enable_display_irq(dev_priv, bit);
1494N/A else
1494N/A ironlake_disable_display_irq(dev_priv, bit);
1494N/A}
1494N/A
1494N/Astatic void ivybridge_set_fifo_underrun_reporting(struct drm_device *dev,
1494N/A bool enable)
1494N/A{
1494N/A struct drm_i915_private *dev_priv = dev->dev_private;
1494N/A
1494N/A if (enable) {
1494N/A if (!ivb_can_enable_err_int(dev))
1494N/A return;
1494N/A
1494N/A I915_WRITE(GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN_A |
1494N/A ERR_INT_FIFO_UNDERRUN_B |
1494N/A ERR_INT_FIFO_UNDERRUN_C);
1494N/A
1494N/A ironlake_enable_display_irq(dev_priv, DE_ERR_INT_IVB);
1494N/A } else {
1494N/A ironlake_disable_display_irq(dev_priv, DE_ERR_INT_IVB);
1494N/A }
1494N/A}
1494N/A
1494N/Astatic void ibx_set_fifo_underrun_reporting(struct intel_crtc *crtc,
1494N/A bool enable)
1494N/A{
1494N/A struct drm_device *dev = crtc->base.dev;
1494N/A struct drm_i915_private *dev_priv = dev->dev_private;
1494N/A uint32_t bit = (crtc->pipe == PIPE_A) ? SDE_TRANSA_FIFO_UNDER :
1494N/A SDE_TRANSB_FIFO_UNDER;
1494N/A
1494N/A if (enable)
1494N/A I915_WRITE(SDEIMR, I915_READ(SDEIMR) & ~bit);
1494N/A else
1494N/A I915_WRITE(SDEIMR, I915_READ(SDEIMR) | bit);
1494N/A
1494N/A POSTING_READ(SDEIMR);
1494N/A}
1494N/A
1494N/Astatic void cpt_set_fifo_underrun_reporting(struct drm_device *dev,
1494N/A enum transcoder pch_transcoder,
1494N/A bool enable)
1494N/A{
1494N/A struct drm_i915_private *dev_priv = dev->dev_private;
1494N/A
1494N/A if (enable) {
1494N/A if (!cpt_can_enable_serr_int(dev))
1494N/A return;
1494N/A
1494N/A I915_WRITE(SERR_INT, SERR_INT_TRANS_A_FIFO_UNDERRUN |
1494N/A SERR_INT_TRANS_B_FIFO_UNDERRUN |
1494N/A SERR_INT_TRANS_C_FIFO_UNDERRUN);
1494N/A
1494N/A I915_WRITE(SDEIMR, I915_READ(SDEIMR) & ~SDE_ERROR_CPT);
1494N/A } else {
1494N/A I915_WRITE(SDEIMR, I915_READ(SDEIMR) | SDE_ERROR_CPT);
1494N/A }
1494N/A
1494N/A POSTING_READ(SDEIMR);
1494N/A}
1494N/A
1494N/A/**
1494N/A * intel_set_cpu_fifo_underrun_reporting - enable/disable FIFO underrun messages
1494N/A * @dev: drm device
1494N/A * @pipe: pipe
1494N/A * @enable: true if we want to report FIFO underrun errors, false otherwise
1494N/A *
1494N/A * This function makes us disable or enable CPU fifo underruns for a specific
1494N/A * pipe. Notice that on some Gens (e.g. IVB, HSW), disabling FIFO underrun
1494N/A * reporting for one pipe may also disable all the other CPU error interruts for
1494N/A * the other pipes, due to the fact that there's just one interrupt mask/enable
1494N/A * bit for all the pipes.
1494N/A *
1494N/A * Returns the previous state of underrun reporting.
1494N/A */
1494N/Abool intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
1494N/A enum pipe pipe, bool enable)
1494N/A{
1494N/A struct drm_i915_private *dev_priv = dev->dev_private;
1494N/A struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
1494N/A struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1494N/A unsigned long flags;
1494N/A bool ret;
1494N/A
1494N/A spin_lock_irqsave(&dev_priv->irq_lock, flags);
1494N/A
1494N/A ret = !intel_crtc->cpu_fifo_underrun_disabled;
1494N/A
1494N/A if (enable == ret)
1494N/A goto done;
1494N/A
1494N/A intel_crtc->cpu_fifo_underrun_disabled = !enable;
1494N/A
1494N/A if (IS_GEN5(dev) || IS_GEN6(dev))
1494N/A ironlake_set_fifo_underrun_reporting(dev, pipe, enable);
1494N/A else if (IS_GEN7(dev))
1494N/A ivybridge_set_fifo_underrun_reporting(dev, enable);
1494N/A
1494N/Adone:
1494N/A spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
1494N/A return ret;
1494N/A}
1494N/A
1494N/A/**
1494N/A * intel_set_pch_fifo_underrun_reporting - enable/disable FIFO underrun messages
1494N/A * @dev: drm device
1494N/A * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
1494N/A * @enable: true if we want to report FIFO underrun errors, false otherwise
1494N/A *
1494N/A * This function makes us disable or enable PCH fifo underruns for a specific
1494N/A * PCH transcoder. Notice that on some PCHs (e.g. CPT/PPT), disabling FIFO
1494N/A * underrun reporting for one transcoder may also disable all the other PCH
1494N/A * error interruts for the other transcoders, due to the fact that there's just
1494N/A * one interrupt mask/enable bit for all the transcoders.
1494N/A *
1494N/A * Returns the previous state of underrun reporting.
1494N/A */
1494N/Abool intel_set_pch_fifo_underrun_reporting(struct drm_device *dev,
1494N/A enum transcoder pch_transcoder,
1494N/A bool enable)
1494N/A{
1494N/A struct drm_i915_private *dev_priv = dev->dev_private;
1494N/A enum pipe p;
1494N/A struct drm_crtc *crtc;
1494N/A struct intel_crtc *intel_crtc;
1494N/A unsigned long flags;
1494N/A bool ret;
1494N/A
1494N/A if (HAS_PCH_LPT(dev)) {
1494N/A crtc = NULL;
1494N/A for_each_pipe(p) {
1494N/A struct drm_crtc *c = dev_priv->pipe_to_crtc_mapping[p];
1494N/A if (intel_pipe_has_type(c, INTEL_OUTPUT_ANALOG)) {
1494N/A crtc = c;
1494N/A break;
1494N/A }
1494N/A }
1494N/A if (!crtc) {
1494N/A DRM_ERROR("PCH FIFO underrun, but no CRTC using the PCH found\n");
1494N/A return false;
1494N/A }
1494N/A } else {
1494N/A crtc = dev_priv->pipe_to_crtc_mapping[pch_transcoder];
1494N/A }
1494N/A intel_crtc = to_intel_crtc(crtc);
1494N/A
1494N/A spin_lock_irqsave(&dev_priv->irq_lock, flags);
1494N/A
1494N/A ret = !intel_crtc->pch_fifo_underrun_disabled;
1494N/A
1494N/A if (enable == ret)
1494N/A goto done;
1494N/A
1494N/A intel_crtc->pch_fifo_underrun_disabled = !enable;
1494N/A
1494N/A if (HAS_PCH_IBX(dev))
1494N/A ibx_set_fifo_underrun_reporting(intel_crtc, enable);
1494N/A else
1494N/A cpt_set_fifo_underrun_reporting(dev, pch_transcoder, enable);
1494N/A
1494N/Adone:
1494N/A spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
1494N/A return ret;
1494N/A}
1494N/A
1494N/A
1494N/Avoid
1494N/Ai915_enable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask)
1494N/A{
1494N/A u32 reg = PIPESTAT(pipe);
1494N/A u32 pipestat = I915_READ(reg) & 0x7fff0000;
1494N/A
1494N/A if ((pipestat & mask) == mask)
1494N/A return;
1494N/A
1494N/A /* Enable the interrupt, clear any pending status */
1494N/A pipestat |= mask | (mask >> 16);
1494N/A I915_WRITE(reg, pipestat);
1494N/A POSTING_READ(reg);
1494N/A}
1494N/A
1494N/Avoid
1494N/Ai915_disable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask)
1494N/A{
1494N/A u32 reg = PIPESTAT(pipe);
1494N/A u32 pipestat = I915_READ(reg) & 0x7fff0000;
1494N/A
1494N/A if ((pipestat & mask) == 0)
1494N/A return;
1494N/A
1494N/A pipestat &= ~mask;
1494N/A I915_WRITE(reg, pipestat);
1494N/A POSTING_READ(reg);
1494N/A }
1494N/A
1494N/A/**
1494N/A * i915_pipe_enabled - check if a pipe is enabled
1494N/A * @dev: DRM device
1494N/A * @pipe: pipe to check
1494N/A *
1494N/A * Reading certain registers when the pipe is disabled can hang the chip.
1494N/A * Use this routine to make sure the PLL is running and the pipe is active
1494N/A * before reading such registers if unsure.
1494N/A */
1494N/Astatic int
1494N/Ai915_pipe_enabled(struct drm_device *dev, int pipe)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A
1494N/A if (drm_core_check_feature(dev, DRIVER_MODESET)) {
1494N/A /* Locking is horribly broken here, but whatever. */
1494N/A struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
1494N/A struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1494N/A
1494N/A return intel_crtc->active;
1494N/A } else {
1494N/A return I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE;
1494N/A }
1494N/A}
1494N/A
1494N/A/* Called from drm generic code, passed a 'crtc', which
1494N/A * we use as a pipe index
1494N/A */
1494N/Astatic u32 i915_get_vblank_counter(struct drm_device *dev, int pipe)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A unsigned long high_frame;
1494N/A unsigned long low_frame;
1494N/A u32 high1, high2, low;
1494N/A
1494N/A if (!i915_pipe_enabled(dev, pipe)) {
1494N/A DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
1494N/A "pipe %c\n", pipe_name(pipe));
1494N/A return 0;
1494N/A }
1494N/A
1494N/A high_frame = PIPEFRAME(pipe);
1494N/A low_frame = PIPEFRAMEPIXEL(pipe);
1494N/A
1494N/A /*
1494N/A * High & low register fields aren't synchronized, so make sure
1494N/A * we get a low value that's stable across two reads of the high
1494N/A * register.
1494N/A */
1494N/A do {
1494N/A high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
1494N/A low = I915_READ(low_frame) & PIPE_FRAME_LOW_MASK;
1494N/A high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
1494N/A } while (high1 != high2);
1494N/A
1494N/A high1 >>= PIPE_FRAME_HIGH_SHIFT;
1494N/A low >>= PIPE_FRAME_LOW_SHIFT;
1494N/A return (high1 << 8) | low;
1494N/A}
1494N/A
1494N/Astatic u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A int reg = PIPE_FRMCOUNT_GM45(pipe);
1494N/A
1494N/A if (!i915_pipe_enabled(dev, pipe)) {
1494N/A DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
1494N/A "pipe %c\n", pipe_name(pipe));
1494N/A return 0;
1494N/A }
1494N/A
1494N/A return I915_READ(reg);
1494N/A}
1494N/A
1494N/Astatic int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
1494N/A int *vpos, int *hpos)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A u32 vbl = 0, position = 0;
1494N/A int vbl_start, vbl_end, htotal, vtotal;
1494N/A bool in_vbl = true;
1494N/A int ret = 0;
1494N/A enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1494N/A pipe);
1494N/A
1494N/A if (!i915_pipe_enabled(dev, pipe)) {
1494N/A DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
1494N/A "pipe %c\n", pipe_name(pipe));
1494N/A return 0;
1494N/A }
1494N/A
1494N/A /* Get vtotal. */
1494N/A vtotal = 1 + ((I915_READ(VTOTAL(cpu_transcoder)) >> 16) & 0x1fff);
1494N/A
1494N/A if (INTEL_INFO(dev)->gen >= 4) {
1494N/A /* No obvious pixelcount register. Only query vertical
1494N/A * scanout position from Display scan line register.
1494N/A */
1494N/A position = I915_READ(PIPEDSL(pipe));
1494N/A
1494N/A /* Decode into vertical scanout position. Don't have
1494N/A * horizontal scanout position.
1494N/A */
1494N/A *vpos = position & 0x1fff;
1494N/A *hpos = 0;
1494N/A } else {
1494N/A /* Have access to pixelcount since start of frame.
1494N/A * We can split this into vertical and horizontal
1494N/A * scanout position.
1494N/A */
1494N/A position = (I915_READ(PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
1494N/A
1494N/A htotal = 1 + ((I915_READ(HTOTAL(cpu_transcoder)) >> 16) & 0x1fff);
1494N/A *vpos = position / htotal;
1494N/A *hpos = position - (*vpos * htotal);
1494N/A }
1494N/A
1494N/A /* Query vblank area. */
1494N/A vbl = I915_READ(VBLANK(cpu_transcoder));
1494N/A
1494N/A /* Test position against vblank region. */
1494N/A vbl_start = vbl & 0x1fff;
1494N/A vbl_end = (vbl >> 16) & 0x1fff;
1494N/A
1494N/A if ((*vpos < vbl_start) || (*vpos > vbl_end))
1494N/A in_vbl = false;
1494N/A
1494N/A /* Inside "upper part" of vblank area? Apply corrective offset: */
1494N/A if (in_vbl && (*vpos >= vbl_start))
1494N/A *vpos = *vpos - vtotal;
1494N/A
1494N/A /* Readouts valid? */
1494N/A if (vbl > 0)
1494N/A ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
1494N/A
1494N/A /* In vblank? */
1494N/A if (in_vbl)
1494N/A ret |= DRM_SCANOUTPOS_INVBL;
1494N/A
1494N/A return ret;
1494N/A}
1494N/A
1494N/Astatic int i915_get_vblank_timestamp(struct drm_device *dev, int pipe,
1494N/A int *max_error,
1494N/A struct timeval *vblank_time,
1494N/A unsigned flags)
1494N/A{
1494N/A struct drm_crtc *crtc;
1494N/A
1494N/A if (pipe < 0 || pipe >= INTEL_INFO(dev)->num_pipes) {
1494N/A DRM_ERROR("Invalid crtc %d\n", pipe);
1494N/A return -EINVAL;
1494N/A }
1494N/A
1494N/A /* Get drm_crtc to timestamp: */
1494N/A crtc = intel_get_crtc_for_pipe(dev, pipe);
1494N/A if (crtc == NULL) {
1494N/A DRM_ERROR("Invalid crtc %d\n", pipe);
1494N/A return -EINVAL;
1494N/A }
1494N/A
1494N/A if (!crtc->enabled) {
1494N/A DRM_DEBUG_KMS("crtc %d is disabled\n", pipe);
1494N/A return -EBUSY;
1494N/A }
1494N/A
1494N/A /* Helper routine in DRM core does all the work: */
1494N/A return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
1494N/A vblank_time, flags,
1494N/A crtc);
1494N/A}
1494N/A
1494N/Astatic int intel_hpd_irq_event(struct drm_device *dev, struct drm_connector *connector)
1494N/A{
1494N/A enum drm_connector_status old_status;
1494N/A
1494N/A WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
1494N/A old_status = connector->status;
1494N/A
1494N/A connector->status = connector->funcs->detect(connector, false);
1494N/A DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %d to %d\n",
1494N/A connector->base.id,
1494N/A drm_get_connector_name(connector),
1494N/A old_status, connector->status);
1494N/A return (old_status != connector->status);
1494N/A}
1494N/A
1494N/A/*
1494N/A * Handle hotplug events outside the interrupt handler proper.
1494N/A */
1494N/A#define I915_REENABLE_HOTPLUG_DELAY (2*60*1000)
1494N/A
1494N/Astatic void i915_hotplug_work_func(struct work_struct *work)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
1494N/A hotplug_work);
1494N/A struct drm_device *dev = dev_priv->dev;
1494N/A struct drm_mode_config *mode_config = &dev->mode_config;
1494N/A struct intel_connector *intel_connector;
1494N/A struct intel_encoder *intel_encoder;
1494N/A struct drm_connector *connector;
1494N/A unsigned long irqflags;
1494N/A bool hpd_disabled = false;
1494N/A bool changed = false;
1494N/A u32 hpd_event_bits;
1494N/A
1494N/A /* HPD irq before everything is fully set up. */
1494N/A if (!dev_priv->enable_hotplug_processing)
1494N/A return;
1494N/A
1494N/A mutex_lock(&mode_config->mutex);
1494N/A DRM_DEBUG_KMS("running encoder hotplug functions\n");
1494N/A
1494N/A spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
1494N/A
1494N/A hpd_event_bits = dev_priv->hpd_event_bits;
1494N/A dev_priv->hpd_event_bits = 0;
1494N/A list_for_each_entry(connector, struct drm_connector, &mode_config->connector_list, head) {
1494N/A intel_connector = to_intel_connector(connector);
1494N/A intel_encoder = intel_connector->encoder;
1494N/A if (intel_encoder->hpd_pin > HPD_NONE &&
1494N/A dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_MARK_DISABLED &&
1494N/A connector->polled == DRM_CONNECTOR_POLL_HPD) {
1494N/A DRM_INFO("HPD interrupt storm detected on connector %s: "
1494N/A "switching from hotplug detection to polling\n",
1494N/A drm_get_connector_name(connector));
1494N/A dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark = HPD_DISABLED;
1494N/A connector->polled = DRM_CONNECTOR_POLL_CONNECT
1494N/A | DRM_CONNECTOR_POLL_DISCONNECT;
1494N/A hpd_disabled = true;
1494N/A }
1494N/A if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
1494N/A DRM_DEBUG_KMS("Connector %s (pin %i) received hotplug event.\n",
1494N/A drm_get_connector_name(connector), intel_encoder->hpd_pin);
1494N/A }
1494N/A }
1494N/A /* if there were no outputs to poll, poll was disabled,
1494N/A * therefore make sure it's enabled when disabling HPD on
1494N/A * some connectors */
1494N/A if (hpd_disabled) {
1494N/A drm_kms_helper_poll_enable(dev);
1494N/A mod_timer(&dev_priv->hotplug_reenable_timer,
1494N/A msecs_to_jiffies(I915_REENABLE_HOTPLUG_DELAY));
1494N/A }
1494N/A
1494N/A spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1494N/A
1494N/A list_for_each_entry(connector, struct drm_connector, &mode_config->connector_list, head) {
1494N/A intel_connector = to_intel_connector(connector);
1494N/A intel_encoder = intel_connector->encoder;
1494N/A if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
1494N/A if (intel_encoder->hot_plug)
1494N/A intel_encoder->hot_plug(intel_encoder);
1494N/A if (intel_hpd_irq_event(dev, connector))
1494N/A changed = true;
1494N/A }
1494N/A }
1494N/A mutex_unlock(&mode_config->mutex);
1494N/A
1494N/A if (changed)
1494N/A drm_kms_helper_hotplug_event(dev);
1494N/A}
1494N/A
1494N/Astatic void ironlake_handle_rps_change(struct drm_device *dev)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = dev->dev_private;
1494N/A u32 busy_up, busy_down, max_avg, min_avg;
1494N/A u8 new_delay;
1494N/A unsigned long flags;
1494N/A
1494N/A spin_lock_irqsave(&mchdev_lock, flags);
1494N/A
1494N/A I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
1494N/A
1494N/A new_delay = dev_priv->ips.cur_delay;
1494N/A
1494N/A I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
1494N/A busy_up = I915_READ(RCPREVBSYTUPAVG);
1494N/A busy_down = I915_READ(RCPREVBSYTDNAVG);
1494N/A max_avg = I915_READ(RCBMAXAVG);
1494N/A min_avg = I915_READ(RCBMINAVG);
1494N/A
1494N/A /* Handle RCS change request from hw */
1494N/A if (busy_up > max_avg) {
1494N/A if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
1494N/A new_delay = dev_priv->ips.cur_delay - 1;
1494N/A if (new_delay < dev_priv->ips.max_delay)
1494N/A new_delay = dev_priv->ips.max_delay;
1494N/A } else if (busy_down < min_avg) {
1494N/A if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
1494N/A new_delay = dev_priv->ips.cur_delay + 1;
1494N/A if (new_delay > dev_priv->ips.min_delay)
1494N/A new_delay = dev_priv->ips.min_delay;
1494N/A }
1494N/A
1494N/A if (ironlake_set_drps(dev, new_delay))
1494N/A dev_priv->ips.cur_delay = new_delay;
1494N/A
1494N/A spin_unlock_irqrestore(&mchdev_lock, flags);
1494N/A
1494N/A return;
1494N/A}
1494N/A
1494N/Astatic void notify_ring(struct drm_device *dev,
1494N/A struct intel_ring_buffer *ring)
1494N/A{
1494N/A struct drm_i915_private *dev_priv = dev->dev_private;
1494N/A
1494N/A if (ring->obj == NULL)
1494N/A return;
1494N/A
1494N/A DRM_WAKEUP(&ring->irq_queue);
1494N/A if (i915_enable_hangcheck && !dev_priv->gpu_hang) {
1494N/A mod_timer(&dev_priv->gpu_error.hangcheck_timer,
1494N/A msecs_to_jiffies(DRM_I915_HANGCHECK_PERIOD));
1494N/A }
1494N/A}
1494N/A
1494N/Astatic void gen6_pm_rps_work(struct work_struct *work)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
1494N/A rps.work);
1494N/A u32 pm_iir, pm_imr;
1494N/A u8 new_delay;
1494N/A
1494N/A spin_lock_irq(&dev_priv->rps.lock);
1494N/A pm_iir = dev_priv->rps.pm_iir;
1494N/A dev_priv->rps.pm_iir = 0;
1494N/A pm_imr = I915_READ(GEN6_PMIMR);
1494N/A I915_WRITE(GEN6_PMIMR, pm_imr & ~GEN6_PM_RPS_EVENTS);
1494N/A spin_unlock_irq(&dev_priv->rps.lock);
1494N/A
1494N/A if ((pm_iir & GEN6_PM_RPS_EVENTS) == 0)
1494N/A return;
1494N/A
1494N/A mutex_lock(&dev_priv->rps.hw_lock);
1494N/A
1494N/A if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
1494N/A new_delay = dev_priv->rps.cur_delay + 1;
1494N/A
1494N/A /*
1494N/A * For better performance, jump directly
1494N/A * to RPe if we're below it.
1494N/A */
1494N/A if (IS_VALLEYVIEW(dev_priv->dev) &&
1494N/A dev_priv->rps.cur_delay < dev_priv->rps.rpe_delay)
1494N/A new_delay = dev_priv->rps.rpe_delay;
1494N/A } else
1494N/A new_delay = dev_priv->rps.cur_delay - 1;
1494N/A
1494N/A /* sysfs frequency interfaces may have snuck in while servicing the
1494N/A * interrupt
1494N/A */
1494N/A if (new_delay >= dev_priv->rps.min_delay &&
1494N/A new_delay <= dev_priv->rps.max_delay) {
1494N/A if (IS_VALLEYVIEW(dev_priv->dev))
1494N/A valleyview_set_rps(dev_priv->dev, new_delay);
1494N/A else
1494N/A gen6_set_rps(dev_priv->dev, new_delay);
1494N/A }
1494N/A
1494N/A mutex_unlock(&dev_priv->rps.hw_lock);
1494N/A }
1494N/A
1494N/A
1494N/A/**
1494N/A * ivybridge_parity_work - Workqueue called when a parity error interrupt
1494N/A * occurred.
1494N/A * @work: workqueue struct
1494N/A *
1494N/A * Doesn't actually do anything except notify userspace. As a consequence of
1494N/A * this event, userspace should try to remap the bad rows since statistically
1494N/A * it is likely the same row is more likely to go bad again.
1494N/A */
1494N/Astatic void ivybridge_parity_work(struct work_struct *work)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
1494N/A l3_parity.error_work);
1494N/A u32 error_status, row, bank, subbank;
1494N/A uint32_t misccpctl;
1494N/A unsigned long flags;
1494N/A
1494N/A /* We must turn off DOP level clock gating to access the L3 registers.
1494N/A * In order to prevent a get/put style interface, acquire struct mutex
1494N/A * any time we access those registers.
1494N/A */
1494N/A mutex_lock(&dev_priv->dev->struct_mutex);
1494N/A
1494N/A misccpctl = I915_READ(GEN7_MISCCPCTL);
1494N/A I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1494N/A POSTING_READ(GEN7_MISCCPCTL);
1494N/A
1494N/A error_status = I915_READ(GEN7_L3CDERRST1);
1494N/A row = GEN7_PARITY_ERROR_ROW(error_status);
1494N/A bank = GEN7_PARITY_ERROR_BANK(error_status);
1494N/A subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1494N/A
1494N/A I915_WRITE(GEN7_L3CDERRST1, GEN7_PARITY_ERROR_VALID |
1494N/A GEN7_L3CDERRST1_ENABLE);
1494N/A POSTING_READ(GEN7_L3CDERRST1);
1494N/A
1494N/A I915_WRITE(GEN7_MISCCPCTL, misccpctl);
1494N/A
1494N/A spin_lock_irqsave(&dev_priv->irq_lock, flags);
1494N/A dev_priv->gt_irq_mask &= ~GT_RENDER_L3_PARITY_ERROR_INTERRUPT;
1494N/A I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
1494N/A spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
1494N/A
1494N/A mutex_unlock(&dev_priv->dev->struct_mutex);
1494N/A
1494N/A DRM_DEBUG("Parity error: Row = %d, Bank = %d, Sub bank = %d.\n",
1494N/A row, bank, subbank);
1494N/A}
1494N/A
1494N/Astatic void ivybridge_handle_parity_error(struct drm_device *dev)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A unsigned long flags;
1494N/A
1494N/A if (!HAS_L3_GPU_CACHE(dev))
1494N/A return;
1494N/A
1494N/A spin_lock_irqsave(&dev_priv->irq_lock, flags);
1494N/A dev_priv->gt_irq_mask |= GT_RENDER_L3_PARITY_ERROR_INTERRUPT;
1494N/A I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
1494N/A spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
1494N/A
1494N/A queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
1494N/A}
1494N/A
1494N/Astatic void snb_gt_irq_handler(struct drm_device *dev,
1494N/A struct drm_i915_private *dev_priv,
1494N/A u32 gt_iir)
1494N/A{
1494N/A
1494N/A if (gt_iir &
1494N/A (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
1494N/A notify_ring(dev, &dev_priv->ring[RCS]);
1494N/A if (gt_iir & GT_BSD_USER_INTERRUPT)
1494N/A notify_ring(dev, &dev_priv->ring[VCS]);
1494N/A if (gt_iir & GT_BLT_USER_INTERRUPT)
1494N/A notify_ring(dev, &dev_priv->ring[BCS]);
1494N/A
1494N/A if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
1494N/A GT_BSD_CS_ERROR_INTERRUPT |
1494N/A GT_RENDER_CS_MASTER_ERROR_INTERRUPT)) {
1494N/A DRM_ERROR("GT error interrupt 0x%08x\n", gt_iir);
1494N/A i915_handle_error(dev, false);
1494N/A }
1494N/A
1494N/A if (gt_iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
1494N/A ivybridge_handle_parity_error(dev);
1494N/A}
1494N/A
1494N/Astatic void gen6_queue_rps_work(struct drm_i915_private *dev_priv,
1494N/A u32 pm_iir)
1494N/A{
1494N/A unsigned long flags;
1494N/A
1494N/A /*
1494N/A * IIR bits should never already be set because IMR should
1494N/A * prevent an interrupt from being shown in IIR. The warning
1494N/A * displays a case where we've unsafely cleared
1494N/A * dev_priv->rps.pm_iir. Although missing an interrupt of the same
1494N/A * type is not a problem, it displays a problem in the logic.
1494N/A *
1494N/A * The mask bit in IMR is cleared by dev_priv->rps.work.
1494N/A */
1494N/A
1494N/A spin_lock_irqsave(&dev_priv->rps.lock, flags);
1494N/A dev_priv->rps.pm_iir |= pm_iir;
1494N/A I915_WRITE(GEN6_PMIMR, dev_priv->rps.pm_iir);
1494N/A POSTING_READ(GEN6_PMIMR);
1494N/A spin_unlock_irqrestore(&dev_priv->rps.lock, flags);
1494N/A
1494N/A queue_work(dev_priv->wq, &dev_priv->rps.work);
1494N/A}
1494N/A
1494N/A#define HPD_STORM_DETECT_PERIOD 1000
1494N/A#define HPD_STORM_THRESHOLD 5
1494N/A
1494N/Astatic inline void intel_hpd_irq_handler(struct drm_device *dev,
1494N/A u32 hotplug_trigger,
1494N/A const u32 *hpd)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = dev->dev_private;
1494N/A int i;
1494N/A bool storm_detected = false;
1494N/A
1494N/A if (!hotplug_trigger)
1494N/A return;
1494N/A
1494N/A spin_lock(&dev_priv->irq_lock);
1494N/A for (i = 1; i < HPD_NUM_PINS; i++) {
1494N/A
1494N/A if (!(hpd[i] & hotplug_trigger) ||
1494N/A dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED)
1494N/A continue;
1494N/A
1494N/A dev_priv->hpd_event_bits |= (1 << i);
1494N/A if (!time_in_range(jiffies, dev_priv->hpd_stats[i].hpd_last_jiffies,
1494N/A dev_priv->hpd_stats[i].hpd_last_jiffies
1494N/A + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD))) {
1494N/A dev_priv->hpd_stats[i].hpd_last_jiffies = jiffies;
1494N/A dev_priv->hpd_stats[i].hpd_cnt = 0;
1494N/A } else if (dev_priv->hpd_stats[i].hpd_cnt > HPD_STORM_THRESHOLD) {
1494N/A dev_priv->hpd_stats[i].hpd_mark = HPD_MARK_DISABLED;
1494N/A dev_priv->hpd_event_bits &= ~(1 << i);
1494N/A DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", i);
1494N/A storm_detected = true;
1494N/A } else {
1494N/A dev_priv->hpd_stats[i].hpd_cnt++;
1494N/A }
1494N/A }
1494N/A
1494N/A if (storm_detected)
1494N/A dev_priv->display.hpd_irq_setup(dev);
1494N/A spin_unlock(&dev_priv->irq_lock);
1494N/A
1494N/A queue_work(dev_priv->wq,
1494N/A &dev_priv->hotplug_work);
1494N/A}
1494N/A
1494N/Astatic void gmbus_irq_handler(struct drm_device *dev)
1494N/A{
1494N/A struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A
1494N/A wake_up_all(&dev_priv->gmbus_wait_queue);
1494N/A}
1494N/A
1494N/Astatic void dp_aux_irq_handler(struct drm_device *dev)
1494N/A{
1494N/A struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A
1494N/A wake_up_all(&dev_priv->gmbus_wait_queue);
1494N/A}
1494N/A
1494N/A/* Unlike gen6_queue_rps_work() from which this function is originally derived,
1494N/A * we must be able to deal with other PM interrupts. This is complicated because
1494N/A * of the way in which we use the masks to defer the RPS work (which for
1494N/A * posterity is necessary because of forcewake).
1494N/A */
1494N/Astatic void hsw_pm_irq_handler(struct drm_i915_private *dev_priv,
1494N/A u32 pm_iir)
1494N/A{
1494N/A unsigned long flags;
1494N/A
1494N/A spin_lock_irqsave(&dev_priv->rps.lock, flags);
1494N/A dev_priv->rps.pm_iir |= pm_iir & GEN6_PM_RPS_EVENTS;
1494N/A if (dev_priv->rps.pm_iir) {
1494N/A I915_WRITE(GEN6_PMIMR, dev_priv->rps.pm_iir);
1494N/A /* never want to mask useful interrupts. (also posting read) */
1494N/A WARN_ON(I915_READ_NOTRACE(GEN6_PMIMR) & ~GEN6_PM_RPS_EVENTS);
1494N/A /* TODO: if queue_work is slow, move it out of the spinlock */
1494N/A queue_work(dev_priv->wq, &dev_priv->rps.work);
1494N/A }
1494N/A spin_unlock_irqrestore(&dev_priv->rps.lock, flags);
1494N/A
1494N/A if (pm_iir & ~GEN6_PM_RPS_EVENTS) {
1494N/A if (pm_iir & PM_VEBOX_USER_INTERRUPT)
1494N/A notify_ring(dev_priv->dev, &dev_priv->ring[VECS]);
1494N/A
1494N/A if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) {
1494N/A DRM_ERROR("VEBOX CS error interrupt 0x%08x\n", pm_iir);
1494N/A i915_handle_error(dev_priv->dev, false);
1494N/A }
1494N/A }
1494N/A}
1494N/A
1494N/Astatic irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
1494N/A{
1494N/A /* LINTED */
1494N/A struct drm_device *dev = (struct drm_device *) arg;
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A u32 iir, gt_iir, pm_iir;
1494N/A irqreturn_t ret = IRQ_NONE;
1494N/A unsigned long irqflags;
1494N/A int pipe;
1611N/A u32 pipe_stats[I915_MAX_PIPES] = { 0 };
1494N/A
1494N/A atomic_inc(&dev_priv->irq_received);
1494N/A
1494N/A while (true) {
1494N/A iir = I915_READ(VLV_IIR);
1494N/A gt_iir = I915_READ(GTIIR);
1494N/A pm_iir = I915_READ(GEN6_PMIIR);
1494N/A
1494N/A if (gt_iir == 0 && pm_iir == 0 && iir == 0)
1494N/A goto out;
1494N/A
1494N/A ret = IRQ_HANDLED;
1494N/A
1494N/A snb_gt_irq_handler(dev, dev_priv, gt_iir);
1494N/A
1494N/A spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
1494N/A for_each_pipe(pipe) {
1494N/A int reg = PIPESTAT(pipe);
1494N/A pipe_stats[pipe] = I915_READ(reg);
1494N/A
1494N/A /*
1494N/A * Clear the PIPE*STAT regs before the IIR
1494N/A */
1494N/A if (pipe_stats[pipe] & 0x8000ffff) {
1494N/A if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1494N/A DRM_DEBUG_DRIVER("pipe %c underrun\n",
1494N/A pipe_name(pipe));
1494N/A I915_WRITE(reg, pipe_stats[pipe]);
1494N/A }
1494N/A }
1494N/A spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1494N/A
1494N/A for_each_pipe(pipe) {
1494N/A if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
1494N/A drm_handle_vblank(dev, pipe);
1494N/A
1494N/A if (pipe_stats[pipe] & PLANE_FLIPDONE_INT_STATUS_VLV) {
1494N/A intel_prepare_page_flip(dev, pipe);
1494N/A intel_finish_page_flip(dev, pipe);
1494N/A }
1494N/A }
1494N/A
1494N/A /* Consume port. Then clear IIR or we'll miss events */
1494N/A if (iir & I915_DISPLAY_PORT_INTERRUPT) {
1494N/A u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
1494N/A u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
1494N/A
1494N/A DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
1494N/A hotplug_status);
1494N/A
1494N/A intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
1494N/A
1494N/A I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1494N/A I915_READ(PORT_HOTPLUG_STAT);
1494N/A }
1494N/A
1494N/A if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
1494N/A gmbus_irq_handler(dev);
1494N/A
1494N/A if (pm_iir & GEN6_PM_RPS_EVENTS)
1494N/A gen6_queue_rps_work(dev_priv, pm_iir);
1494N/A
1494N/A I915_WRITE(GTIIR, gt_iir);
1494N/A I915_WRITE(GEN6_PMIIR, pm_iir);
1494N/A I915_WRITE(VLV_IIR, iir);
1494N/A }
1494N/A
1494N/Aout:
1494N/A return ret;
1494N/A}
1494N/A
1494N/Astatic void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A int pipe;
1494N/A u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
1494N/A
1494N/A intel_hpd_irq_handler(dev, hotplug_trigger, hpd_ibx);
1494N/A
1494N/A if (pch_iir & SDE_AUDIO_POWER_MASK) {
1494N/A int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
1494N/A SDE_AUDIO_POWER_SHIFT);
1494N/A DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
1494N/A port_name(port));
1494N/A }
1494N/A
1494N/A if (pch_iir & SDE_AUX_MASK)
1494N/A dp_aux_irq_handler(dev);
1494N/A
1494N/A if (pch_iir & SDE_GMBUS)
1494N/A gmbus_irq_handler(dev);
1494N/A
1494N/A if (pch_iir & SDE_AUDIO_HDCP_MASK)
1494N/A DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
1494N/A
1494N/A if (pch_iir & SDE_AUDIO_TRANS_MASK)
1494N/A DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
1494N/A
1494N/A if (pch_iir & SDE_POISON)
1494N/A DRM_ERROR("PCH poison interrupt\n");
1494N/A
1494N/A if (pch_iir & SDE_FDI_MASK)
1494N/A for_each_pipe(pipe)
1494N/A DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1494N/A pipe_name(pipe),
1494N/A I915_READ(FDI_RX_IIR(pipe)));
1494N/A
1494N/A if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
1494N/A DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
1494N/A
1494N/A if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
1494N/A DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
1494N/A
1494N/A if (pch_iir & SDE_TRANSA_FIFO_UNDER)
1494N/A if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
1494N/A false))
1494N/A DRM_DEBUG_DRIVER("PCH transcoder A FIFO underrun\n");
1494N/A
1494N/A if (pch_iir & SDE_TRANSB_FIFO_UNDER)
1494N/A if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
1494N/A false))
1494N/A DRM_DEBUG_DRIVER("PCH transcoder B FIFO underrun\n");
1494N/A}
1494N/A
1494N/Astatic void ivb_err_int_handler(struct drm_device *dev)
1494N/A{
1494N/A struct drm_i915_private *dev_priv = dev->dev_private;
1494N/A u32 err_int = I915_READ(GEN7_ERR_INT);
1494N/A
1494N/A if (err_int & ERR_INT_POISON)
1494N/A DRM_ERROR("Poison interrupt\n");
1494N/A
1494N/A if (err_int & ERR_INT_FIFO_UNDERRUN_A)
1494N/A if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_A, false))
1494N/A DRM_DEBUG_DRIVER("Pipe A FIFO underrun\n");
1494N/A
1494N/A if (err_int & ERR_INT_FIFO_UNDERRUN_B)
1494N/A if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_B, false))
1494N/A DRM_DEBUG_DRIVER("Pipe B FIFO underrun\n");
1494N/A
1494N/A if (err_int & ERR_INT_FIFO_UNDERRUN_C)
1494N/A if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_C, false))
1494N/A DRM_DEBUG_DRIVER("Pipe C FIFO underrun\n");
1494N/A
1494N/A I915_WRITE(GEN7_ERR_INT, err_int);
1494N/A}
1494N/A
1494N/Astatic void cpt_serr_int_handler(struct drm_device *dev)
1494N/A{
1494N/A struct drm_i915_private *dev_priv = dev->dev_private;
1494N/A u32 serr_int = I915_READ(SERR_INT);
1494N/A
1494N/A if (serr_int & SERR_INT_POISON)
1494N/A DRM_ERROR("PCH poison interrupt\n");
1494N/A
1494N/A if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
1494N/A if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
1494N/A false))
1494N/A DRM_DEBUG_DRIVER("PCH transcoder A FIFO underrun\n");
1494N/A
1494N/A if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
1494N/A if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
1494N/A false))
1494N/A DRM_DEBUG_DRIVER("PCH transcoder B FIFO underrun\n");
1494N/A
1494N/A if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
1494N/A if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_C,
1494N/A false))
1494N/A DRM_DEBUG_DRIVER("PCH transcoder C FIFO underrun\n");
1494N/A
1494N/A I915_WRITE(SERR_INT, serr_int);
1494N/A}
1494N/A
1494N/Astatic void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A int pipe;
1494N/A u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
1494N/A
1494N/A intel_hpd_irq_handler(dev, hotplug_trigger, hpd_cpt);
1494N/A
1494N/A if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
1494N/A int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
1494N/A SDE_AUDIO_POWER_SHIFT_CPT);
1494N/A DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
1494N/A port_name(port));
1494N/A }
1494N/A
1494N/A if (pch_iir & SDE_AUX_MASK_CPT)
1494N/A dp_aux_irq_handler(dev);
1494N/A
1494N/A if (pch_iir & SDE_GMBUS_CPT)
1494N/A gmbus_irq_handler(dev);
1494N/A
1494N/A if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
1494N/A DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
1494N/A
1494N/A if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
1494N/A DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
1494N/A
1494N/A if (pch_iir & SDE_FDI_MASK_CPT)
1494N/A for_each_pipe(pipe)
1494N/A DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1494N/A pipe_name(pipe),
1494N/A I915_READ(FDI_RX_IIR(pipe)));
1494N/A
1494N/A if (pch_iir & SDE_ERROR_CPT)
1494N/A cpt_serr_int_handler(dev);
1494N/A}
1494N/A
1494N/Astatic irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
1494N/A{
1494N/A /* LINTED */
1494N/A struct drm_device *dev = (struct drm_device *) arg;
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A u32 de_iir, gt_iir, de_ier, pm_iir, sde_ier;
1494N/A irqreturn_t ret = IRQ_NONE;
1494N/A int i;
1494N/A
1494N/A atomic_inc(&dev_priv->irq_received);
1494N/A
1494N/A /* We get interrupts on unclaimed registers, so check for this before we
1494N/A * do any I915_{READ,WRITE}. */
1494N/A if (IS_HASWELL(dev) &&
1494N/A (I915_READ_NOTRACE(FPGA_DBG) & FPGA_DBG_RM_NOCLAIM)) {
1494N/A DRM_ERROR("Unclaimed register before interrupt\n");
1494N/A I915_WRITE_NOTRACE(FPGA_DBG, FPGA_DBG_RM_NOCLAIM);
1494N/A }
1494N/A
1494N/A /* disable master interrupt before clearing iir */
1494N/A de_ier = I915_READ(DEIER);
1494N/A I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
1494N/A
1494N/A /* Disable south interrupts. We'll only write to SDEIIR once, so further
1494N/A * interrupts will will be stored on its back queue, and then we'll be
1494N/A * able to process them after we restore SDEIER (as soon as we restore
1494N/A * it, we'll get an interrupt if SDEIIR still has something to process
1494N/A * due to its back queue). */
1494N/A if (!HAS_PCH_NOP(dev)) {
1494N/A sde_ier = I915_READ(SDEIER);
1494N/A I915_WRITE(SDEIER, 0);
1494N/A POSTING_READ(SDEIER);
1494N/A }
1494N/A
1494N/A /* On Haswell, also mask ERR_INT because we don't want to risk
1494N/A * generating "unclaimed register" interrupts from inside the interrupt
1494N/A * handler. */
1494N/A if (IS_HASWELL(dev)) {
1494N/A spin_lock(&dev_priv->irq_lock);
1494N/A ironlake_disable_display_irq(dev_priv, DE_ERR_INT_IVB);
1494N/A spin_unlock(&dev_priv->irq_lock);
1494N/A }
1494N/A
1494N/A gt_iir = I915_READ(GTIIR);
1494N/A if (gt_iir) {
1494N/A snb_gt_irq_handler(dev, dev_priv, gt_iir);
1494N/A I915_WRITE(GTIIR, gt_iir);
1494N/A ret = IRQ_HANDLED;
1494N/A }
1494N/A
1494N/A de_iir = I915_READ(DEIIR);
1494N/A if (de_iir) {
1494N/A if (de_iir & DE_ERR_INT_IVB)
1494N/A ivb_err_int_handler(dev);
1494N/A
1494N/A if (de_iir & DE_AUX_CHANNEL_A_IVB)
1494N/A dp_aux_irq_handler(dev);
1494N/A
1494N/A
1494N/A for (i = 0; i < 3; i++) {
1494N/A if (de_iir & (DE_PIPEA_VBLANK_IVB << (5 * i)))
1494N/A drm_handle_vblank(dev, i);
1494N/A if (de_iir & (DE_PLANEA_FLIP_DONE_IVB << (5 * i))) {
1494N/A intel_prepare_page_flip(dev, i);
1494N/A intel_finish_page_flip_plane(dev, i);
1494N/A }
1494N/A }
1494N/A
1494N/A /* check event from PCH */
1494N/A if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) {
1494N/A u32 pch_iir = I915_READ(SDEIIR);
1494N/A
1494N/A cpt_irq_handler(dev, pch_iir);
1494N/A
1494N/A /* clear PCH hotplug event before clear CPU irq */
1494N/A I915_WRITE(SDEIIR, pch_iir);
1494N/A }
1494N/A
1494N/A I915_WRITE(DEIIR, de_iir);
1494N/A ret = IRQ_HANDLED;
1494N/A }
1494N/A
1494N/A pm_iir = I915_READ(GEN6_PMIIR);
1494N/A if (pm_iir) {
1494N/A if (IS_HASWELL(dev))
1494N/A hsw_pm_irq_handler(dev_priv, pm_iir);
1494N/A else if (pm_iir & GEN6_PM_RPS_EVENTS)
1494N/A gen6_queue_rps_work(dev_priv, pm_iir);
1494N/A I915_WRITE(GEN6_PMIIR, pm_iir);
1494N/A ret = IRQ_HANDLED;
1494N/A }
1494N/A
1494N/A if (IS_HASWELL(dev)) {
1494N/A spin_lock(&dev_priv->irq_lock);
1494N/A if (ivb_can_enable_err_int(dev))
1494N/A ironlake_enable_display_irq(dev_priv, DE_ERR_INT_IVB);
1494N/A spin_unlock(&dev_priv->irq_lock);
1494N/A }
1494N/A
1494N/A I915_WRITE(DEIER, de_ier);
1494N/A POSTING_READ(DEIER);
1494N/A if (!HAS_PCH_NOP(dev)) {
1494N/A I915_WRITE(SDEIER, sde_ier);
1494N/A POSTING_READ(SDEIER);
1494N/A }
1494N/A
1494N/A return ret;
1494N/A}
1494N/A
1494N/Astatic void ilk_gt_irq_handler(struct drm_device *dev,
1494N/A struct drm_i915_private *dev_priv,
1494N/A u32 gt_iir)
1494N/A{
1494N/A if (gt_iir &
1494N/A (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
1494N/A notify_ring(dev, &dev_priv->ring[RCS]);
1494N/A if (gt_iir & ILK_BSD_USER_INTERRUPT)
1494N/A notify_ring(dev, &dev_priv->ring[VCS]);
1494N/A}
1494N/A
1494N/Astatic irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
1494N/A{
1494N/A struct drm_device *dev = (struct drm_device *)(uintptr_t) arg;
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A int ret = IRQ_NONE;
1494N/A u32 de_iir, gt_iir, de_ier, pm_iir, sde_ier;
1494N/A
1494N/A atomic_inc(&dev_priv->irq_received);
1494N/A
1494N/A /* disable master interrupt before clearing iir */
1494N/A de_ier = I915_READ(DEIER);
1494N/A I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
1494N/A POSTING_READ(DEIER);
1494N/A
1494N/A /* Disable south interrupts. We'll only write to SDEIIR once, so further
1494N/A * interrupts will will be stored on its back queue, and then we'll be
1494N/A * able to process them after we restore SDEIER (as soon as we restore
1494N/A * it, we'll get an interrupt if SDEIIR still has something to process
1494N/A * due to its back queue). */
1494N/A sde_ier = I915_READ(SDEIER);
1494N/A I915_WRITE(SDEIER, 0);
1494N/A POSTING_READ(SDEIER);
1494N/A
1494N/A de_iir = I915_READ(DEIIR);
1494N/A gt_iir = I915_READ(GTIIR);
1494N/A pm_iir = I915_READ(GEN6_PMIIR);
1494N/A
1494N/A if (de_iir == 0 && gt_iir == 0 && (!IS_GEN6(dev) || pm_iir == 0))
1494N/A goto done;
1494N/A
1494N/A ret = IRQ_HANDLED;
1494N/A
1494N/A if (IS_GEN5(dev))
1494N/A ilk_gt_irq_handler(dev, dev_priv, gt_iir);
1494N/A else
1494N/A snb_gt_irq_handler(dev, dev_priv, gt_iir);
1494N/A
1494N/A if (de_iir & DE_AUX_CHANNEL_A)
1494N/A dp_aux_irq_handler(dev);
1494N/A
1494N/A
1494N/A if (de_iir & DE_PIPEA_VBLANK)
1494N/A drm_handle_vblank(dev, 0);
1494N/A
1494N/A if (de_iir & DE_PIPEB_VBLANK)
1494N/A drm_handle_vblank(dev, 1);
1494N/A
1494N/A if (de_iir & DE_POISON)
1494N/A DRM_ERROR("Poison interrupt\n");
1494N/A
1494N/A if (de_iir & DE_PIPEA_FIFO_UNDERRUN)
1494N/A if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_A, false))
1494N/A DRM_DEBUG_DRIVER("Pipe A FIFO underrun\n");
1494N/A
1494N/A if (de_iir & DE_PIPEB_FIFO_UNDERRUN)
1494N/A if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_B, false))
1494N/A DRM_DEBUG_DRIVER("Pipe B FIFO underrun\n");
1494N/A
1494N/A if (de_iir & DE_PLANEA_FLIP_DONE) {
1494N/A intel_prepare_page_flip(dev, 0);
1494N/A intel_finish_page_flip_plane(dev, 0);
1494N/A }
1494N/A
1494N/A if (de_iir & DE_PLANEB_FLIP_DONE) {
1494N/A intel_prepare_page_flip(dev, 1);
1494N/A intel_finish_page_flip_plane(dev, 1);
1494N/A }
1494N/A
1494N/A /* check event from PCH */
1494N/A if (de_iir & DE_PCH_EVENT) {
1494N/A u32 pch_iir = I915_READ(SDEIIR);
1494N/A
1494N/A if (HAS_PCH_CPT(dev))
1494N/A cpt_irq_handler(dev, pch_iir);
1494N/A else
1494N/A ibx_irq_handler(dev, pch_iir);
1494N/A
1494N/A /* should clear PCH hotplug event before clear CPU irq */
1494N/A I915_WRITE(SDEIIR, pch_iir);
1494N/A }
1494N/A
1494N/A if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
1494N/A ironlake_handle_rps_change(dev);
1494N/A
1494N/A if (IS_GEN6(dev) && pm_iir & GEN6_PM_RPS_EVENTS)
1494N/A gen6_queue_rps_work(dev_priv, pm_iir);
1494N/A
1494N/A I915_WRITE(GTIIR, gt_iir);
1494N/A I915_WRITE(DEIIR, de_iir);
1494N/A I915_WRITE(GEN6_PMIIR, pm_iir);
1494N/A
1494N/Adone:
1494N/A I915_WRITE(DEIER, de_ier);
1494N/A POSTING_READ(DEIER);
1494N/A I915_WRITE(SDEIER, sde_ier);
1494N/A POSTING_READ(SDEIER);
1494N/A
1494N/A return ret;
1494N/A}
1494N/A
1494N/A/**
1494N/A * i915_error_work_func - do process context error handling work
1494N/A * @work: work struct
1494N/A *
1494N/A * Fire an error uevent so userspace can see that a hang or error
1494N/A * was detected.
1494N/A */
1494N/Astatic void i915_error_work_func(struct work_struct *work)
1494N/A{
1494N/A struct i915_gpu_error *error = container_of(work, struct i915_gpu_error,
1494N/A work);
1494N/A drm_i915_private_t *dev_priv = container_of(error, drm_i915_private_t,
1494N/A gpu_error);
1494N/A struct drm_device *dev = dev_priv->dev;
1494N/A struct intel_ring_buffer *ring;
1494N/A /* LINTED */
1494N/A char *error_event[] = { "ERROR=1", NULL };
1494N/A /* LINTED */
1494N/A char *reset_event[] = { "RESET=1", NULL };
1494N/A /* LINTED */
1494N/A char *reset_done_event[] = { "ERROR=0", NULL };
1494N/A int i, ret;
1494N/A
1494N/A DRM_DEBUG_DRIVER("generating error event\n");
1494N/A /* OSOL_i915: kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, error_event); */
1494N/A
1494N/A /*
1494N/A * Note that there's only one work item which does gpu resets, so we
1494N/A * need not worry about concurrent gpu resets potentially incrementing
1494N/A * error->reset_counter twice. We only need to take care of another
1494N/A * racing irq/hangcheck declaring the gpu dead for a second time. A
1494N/A * quick check for that is good enough: schedule_work ensures the
1494N/A * correct ordering between hang detection and this work item, and since
1494N/A * the reset in-progress bit is only ever set by code outside of this
1494N/A * work we don't need to worry about any other races.
1494N/A */
1494N/A if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) {
1494N/A DRM_DEBUG_DRIVER("resetting chip\n");
1494N/A /* OSOL_i915: kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, reset_event); */
1494N/A ret = i915_reset(dev);
1494N/A
1494N/A if (ret == 0) {
1494N/A /*
1494N/A * After all the gem state is reset, increment the reset
1494N/A * counter and wake up everyone waiting for the reset to
1494N/A * complete.
1494N/A *
1494N/A * Since unlock operations are a one-sided barrier only,
1494N/A * we need to insert a barrier here to order any seqno
1494N/A * updates before
1494N/A * the counter increment.
1494N/A */
1494N/A atomic_inc(&dev_priv->gpu_error.reset_counter);
1494N/A if (gpu_dump > 0) {
1494N/A for_each_ring(ring, dev_priv, i)
1494N/A ring_dump(dev, ring);
1494N/A register_dump(dev);
1494N/A gtt_dump(dev);
1494N/A }
1494N/A } else {
1494N/A atomic_set(&error->reset_counter, I915_WEDGED);
1494N/A }
1494N/A
1494N/A for_each_ring(ring, dev_priv, i)
1494N/A wake_up_all(&ring->irq_queue);
1494N/A
1494N/A wake_up_all(&dev_priv->gpu_error.reset_queue);
1494N/A DRM_INFO("resetting done");
1494N/A }
1494N/A}
1494N/A
1494N/A/* NB: please notice the memset */
1494N/Astatic void i915_get_extra_instdone(struct drm_device *dev,
1494N/A uint32_t *instdone)
1494N/A{
1494N/A struct drm_i915_private *dev_priv = dev->dev_private;
1494N/A (void) memset(instdone, 0, sizeof(*instdone) * I915_NUM_INSTDONE_REG);
1494N/A
1494N/A switch(INTEL_INFO(dev)->gen) {
1494N/A case 2:
1494N/A case 3:
1494N/A instdone[0] = I915_READ(INSTDONE);
1494N/A break;
1494N/A case 4:
1494N/A case 5:
1494N/A case 6:
1494N/A instdone[0] = I915_READ(INSTDONE_I965);
1494N/A instdone[1] = I915_READ(INSTDONE1);
1494N/A break;
1494N/A default:
1494N/A DRM_INFO("Unsupported platform\n");
1494N/A case 7:
1494N/A instdone[0] = I915_READ(GEN7_INSTDONE_1);
1494N/A instdone[1] = I915_READ(GEN7_SC_INSTDONE);
1494N/A instdone[2] = I915_READ(GEN7_SAMPLER_INSTDONE);
1494N/A instdone[3] = I915_READ(GEN7_ROW_INSTDONE);
1494N/A break;
1494N/A }
1494N/A}
1494N/A
1494N/A#ifdef CONFIG_DEBUG_FS
1494N/Astatic struct drm_i915_error_object *
1494N/Ai915_error_object_create_sized(struct drm_i915_private *dev_priv,
1494N/A struct drm_i915_gem_object *src,
1494N/A const int num_pages)
1494N/A{
1494N/A struct drm_i915_error_object *dst;
1494N/A int i;
1494N/A u32 reloc_offset;
1494N/A
1494N/A if (src == NULL || src->pages == NULL)
1494N/A return NULL;
1494N/A
1494N/A dst = kmalloc(sizeof(*dst) + num_pages * sizeof(u32 *), GFP_ATOMIC);
1494N/A if (dst == NULL)
1494N/A return NULL;
1494N/A
1494N/A reloc_offset = src->gtt_offset;
1494N/A for (i = 0; i < num_pages; i++) {
1494N/A unsigned long flags;
1494N/A void *d;
1494N/A
1494N/A d = kmalloc(PAGE_SIZE, GFP_ATOMIC);
1494N/A if (d == NULL)
1494N/A goto unwind;
1494N/A
1494N/A local_irq_save(flags);
1494N/A if (reloc_offset < dev_priv->gtt.mappable_end &&
1494N/A src->has_global_gtt_mapping) {
1494N/A void __iomem *s;
1494N/A
1494N/A /* Simply ignore tiling or any overlapping fence.
1494N/A * It's part of the error state, and this hopefully
1494N/A * captures what the GPU read.
1494N/A */
1494N/A
1494N/A s = io_mapping_map_atomic_wc(dev_priv->gtt.mappable,
1494N/A reloc_offset);
1494N/A memcpy_fromio(d, s, PAGE_SIZE);
1494N/A io_mapping_unmap_atomic(s);
1494N/A } else if (src->stolen) {
1494N/A unsigned long offset;
1494N/A
1494N/A offset = dev_priv->mm.stolen_base;
1494N/A offset += src->stolen->start;
1494N/A offset += i << PAGE_SHIFT;
1494N/A
1494N/A memcpy_fromio(d, (void __iomem *) offset, PAGE_SIZE);
1494N/A } else {
1494N/A struct page *page;
1494N/A void *s;
1494N/A
1494N/A page = i915_gem_object_get_page(src, i);
1494N/A
1494N/A drm_clflush_pages(&page, 1);
1494N/A
1494N/A s = kmap_atomic(page);
1494N/A memcpy(d, s, PAGE_SIZE);
1494N/A kunmap_atomic(s);
1494N/A
1494N/A drm_clflush_pages(&page, 1);
1494N/A }
1494N/A local_irq_restore(flags);
1494N/A
1494N/A dst->pages[i] = d;
1494N/A
1494N/A reloc_offset += PAGE_SIZE;
1494N/A }
1494N/A dst->page_count = num_pages;
1494N/A dst->gtt_offset = src->gtt_offset;
1494N/A
1494N/A return dst;
1494N/A
1494N/Aunwind:
1494N/A while (i--)
1494N/A kfree(dst->pages[i]);
1494N/A kfree(dst);
1494N/A return NULL;
1494N/A}
1494N/A#define i915_error_object_create(dev_priv, src) \
1494N/A i915_error_object_create_sized((dev_priv), (src), \
1494N/A (src)->base.size>>PAGE_SHIFT)
1494N/A
1494N/Astatic void
1494N/Ai915_error_object_free(struct drm_i915_error_object *obj)
1494N/A{
1494N/A int page;
1494N/A
1494N/A if (obj == NULL)
1494N/A return;
1494N/A
1494N/A for (page = 0; page < obj->page_count; page++)
1494N/A kfree(obj->pages[page]);
1494N/A
1494N/A kfree(obj);
1494N/A}
1494N/A
1494N/Avoid
1494N/Ai915_error_state_free(struct kref *error_ref)
1494N/A{
1494N/A struct drm_i915_error_state *error = container_of(error_ref,
1494N/A typeof(*error), ref);
1494N/A int i;
1494N/A
1494N/A for (i = 0; i < ARRAY_SIZE(error->ring); i++) {
1494N/A i915_error_object_free(error->ring[i].batchbuffer);
1494N/A i915_error_object_free(error->ring[i].ringbuffer);
1494N/A i915_error_object_free(error->ring[i].ctx);
1494N/A kfree(error->ring[i].requests);
1494N/A }
1494N/A
1494N/A kfree(error->active_bo);
1494N/A kfree(error->overlay);
1494N/A kfree(error->display);
1494N/A kfree(error);
1494N/A}
1494N/Astatic void capture_bo(struct drm_i915_error_buffer *err,
1494N/A struct drm_i915_gem_object *obj)
1494N/A{
1494N/A err->size = obj->base.size;
1494N/A err->name = obj->base.name;
1494N/A err->rseqno = obj->last_read_seqno;
1494N/A err->wseqno = obj->last_write_seqno;
1494N/A err->gtt_offset = obj->gtt_offset;
1494N/A err->read_domains = obj->base.read_domains;
1494N/A err->write_domain = obj->base.write_domain;
1494N/A err->fence_reg = obj->fence_reg;
1494N/A err->pinned = 0;
1494N/A if (obj->pin_count > 0)
1494N/A err->pinned = 1;
1494N/A if (obj->user_pin_count > 0)
1494N/A err->pinned = -1;
1494N/A err->tiling = obj->tiling_mode;
1494N/A err->dirty = obj->dirty;
1494N/A err->purgeable = obj->madv != I915_MADV_WILLNEED;
1494N/A err->ring = obj->ring ? obj->ring->id : -1;
1494N/A err->cache_level = obj->cache_level;
1494N/A}
1494N/A
1494N/Astatic u32 capture_active_bo(struct drm_i915_error_buffer *err,
1494N/A int count, struct list_head *head)
1494N/A{
1494N/A struct drm_i915_gem_object *obj;
1494N/A int i = 0;
1494N/A
1494N/A list_for_each_entry(obj, head, mm_list) {
1494N/A capture_bo(err++, obj);
1494N/A if (++i == count)
1494N/A break;
1494N/A }
1494N/A
1494N/A return i;
1494N/A}
1494N/A
1494N/Astatic u32 capture_pinned_bo(struct drm_i915_error_buffer *err,
1494N/A int count, struct list_head *head)
1494N/A{
1494N/A struct drm_i915_gem_object *obj;
1494N/A int i = 0;
1494N/A
1494N/A list_for_each_entry(obj, head, global_list) {
1494N/A if (obj->pin_count == 0)
1494N/A continue;
1494N/A
1494N/A capture_bo(err++, obj);
1494N/A if (++i == count)
1494N/A break;
1494N/A }
1494N/A
1494N/A return i;
1494N/A}
1494N/A
1494N/Astatic void i915_gem_record_fences(struct drm_device *dev,
1494N/A struct drm_i915_error_state *error)
1494N/A{
1494N/A struct drm_i915_private *dev_priv = dev->dev_private;
1494N/A int i;
1494N/A
1494N/A /* Fences */
1494N/A switch (INTEL_INFO(dev)->gen) {
1494N/A case 7:
1494N/A case 6:
1494N/A for (i = 0; i < dev_priv->num_fence_regs; i++)
1494N/A error->fence[i] = I915_READ64(FENCE_REG_SANDYBRIDGE_0 + (i * 8));
1494N/A break;
1494N/A case 5:
1494N/A case 4:
1494N/A for (i = 0; i < 16; i++)
1494N/A error->fence[i] = I915_READ64(FENCE_REG_965_0 + (i * 8));
1494N/A break;
1494N/A case 3:
1494N/A if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
1494N/A for (i = 0; i < 8; i++)
1494N/A error->fence[i+8] = I915_READ(FENCE_REG_945_8 + (i * 4));
1494N/A case 2:
1494N/A for (i = 0; i < 8; i++)
1494N/A error->fence[i] = I915_READ(FENCE_REG_830_0 + (i * 4));
1494N/A break;
1494N/A
1494N/A default:
1494N/A BUG();
1494N/A }
1494N/A}
1494N/A
1494N/Astatic struct drm_i915_error_object *
1494N/Ai915_error_first_batchbuffer(struct drm_i915_private *dev_priv,
1494N/A struct intel_ring_buffer *ring)
1494N/A{
1494N/A struct drm_i915_gem_object *obj;
1494N/A u32 seqno;
1494N/A
1494N/A if (!ring->get_seqno)
1494N/A return NULL;
1494N/A
1494N/A if (HAS_BROKEN_CS_TLB(dev_priv->dev)) {
1494N/A u32 acthd = I915_READ(ACTHD);
1494N/A
1494N/A if (WARN_ON(ring->id != RCS))
1494N/A return NULL;
1494N/A
1494N/A obj = ring->private;
1494N/A if (acthd >= obj->gtt_offset &&
1494N/A acthd < obj->gtt_offset + obj->base.size)
1494N/A return i915_error_object_create(dev_priv, obj);
1494N/A }
1494N/A
1494N/A seqno = ring->get_seqno(ring, false);
1494N/A list_for_each_entry(obj, &dev_priv->mm.active_list, mm_list) {
1494N/A if (obj->ring != ring)
1494N/A continue;
1494N/A
1494N/A if (i915_seqno_passed(seqno, obj->last_read_seqno))
1494N/A continue;
1494N/A
1494N/A if ((obj->base.read_domains & I915_GEM_DOMAIN_COMMAND) == 0)
1494N/A continue;
1494N/A
1494N/A /* We need to copy these to an anonymous buffer as the simplest
1494N/A * method to avoid being overwritten by userspace.
1494N/A */
1494N/A return i915_error_object_create(dev_priv, obj);
1494N/A }
1494N/A
1494N/A return NULL;
1494N/A}
1494N/A
1494N/Astatic void i915_record_ring_state(struct drm_device *dev,
1494N/A struct drm_i915_error_state *error,
1494N/A struct intel_ring_buffer *ring)
1494N/A{
1494N/A struct drm_i915_private *dev_priv = dev->dev_private;
1494N/A
1494N/A if (INTEL_INFO(dev)->gen >= 6) {
1494N/A error->rc_psmi[ring->id] = I915_READ(ring->mmio_base + 0x50);
1494N/A error->fault_reg[ring->id] = I915_READ(RING_FAULT_REG(ring));
1494N/A error->semaphore_mboxes[ring->id][0]
1494N/A = I915_READ(RING_SYNC_0(ring->mmio_base));
1494N/A error->semaphore_mboxes[ring->id][1]
1494N/A = I915_READ(RING_SYNC_1(ring->mmio_base));
1494N/A error->semaphore_seqno[ring->id][0] = ring->sync_seqno[0];
1494N/A error->semaphore_seqno[ring->id][1] = ring->sync_seqno[1];
1494N/A }
1494N/A
1494N/A if (INTEL_INFO(dev)->gen >= 4) {
1494N/A error->faddr[ring->id] = I915_READ(RING_DMA_FADD(ring->mmio_base));
1494N/A error->ipeir[ring->id] = I915_READ(RING_IPEIR(ring->mmio_base));
1494N/A error->ipehr[ring->id] = I915_READ(RING_IPEHR(ring->mmio_base));
1494N/A error->instdone[ring->id] = I915_READ(RING_INSTDONE(ring->mmio_base));
1494N/A error->instps[ring->id] = I915_READ(RING_INSTPS(ring->mmio_base));
1494N/A if (ring->id == RCS)
1494N/A error->bbaddr = I915_READ64(BB_ADDR);
1494N/A } else {
1494N/A error->faddr[ring->id] = I915_READ(DMA_FADD_I8XX);
1494N/A error->ipeir[ring->id] = I915_READ(IPEIR);
1494N/A error->ipehr[ring->id] = I915_READ(IPEHR);
1494N/A error->instdone[ring->id] = I915_READ(INSTDONE);
1494N/A }
1494N/A
1494N/A error->waiting[ring->id] = waitqueue_active(&ring->irq_queue);
1494N/A error->instpm[ring->id] = I915_READ(RING_INSTPM(ring->mmio_base));
1494N/A error->seqno[ring->id] = ring->get_seqno(ring, false);
1494N/A error->acthd[ring->id] = intel_ring_get_active_head(ring);
1494N/A error->head[ring->id] = I915_READ_HEAD(ring);
1494N/A error->tail[ring->id] = I915_READ_TAIL(ring);
1494N/A error->ctl[ring->id] = I915_READ_CTL(ring);
1494N/A
1494N/A error->cpu_ring_head[ring->id] = ring->head;
1494N/A error->cpu_ring_tail[ring->id] = ring->tail;
1494N/A}
1494N/A
1494N/A
1494N/Astatic void i915_gem_record_active_context(struct intel_ring_buffer *ring,
1494N/A struct drm_i915_error_state *error,
1494N/A struct drm_i915_error_ring *ering)
1494N/A{
1494N/A struct drm_i915_private *dev_priv = ring->dev->dev_private;
1494N/A struct drm_i915_gem_object *obj;
1494N/A
1494N/A /* Currently render ring is the only HW context user */
1494N/A if (ring->id != RCS || !error->ccid)
1494N/A return;
1494N/A
1494N/A list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
1494N/A if ((error->ccid & PAGE_MASK) == obj->gtt_offset) {
1494N/A ering->ctx = i915_error_object_create_sized(dev_priv,
1494N/A obj, 1);
1494N/A }
1494N/A }
1494N/A}
1494N/A
1494N/Astatic void i915_gem_record_rings(struct drm_device *dev,
1494N/A struct drm_i915_error_state *error)
1494N/A{
1494N/A struct drm_i915_private *dev_priv = dev->dev_private;
1494N/A struct intel_ring_buffer *ring;
1494N/A struct drm_i915_gem_request *request;
1494N/A int i, count;
1494N/A
1494N/A for_each_ring(ring, dev_priv, i) {
1494N/A i915_record_ring_state(dev, error, ring);
1494N/A
1494N/A error->ring[i].batchbuffer =
1494N/A i915_error_first_batchbuffer(dev_priv, ring);
1494N/A
1494N/A error->ring[i].ringbuffer =
1494N/A i915_error_object_create(dev_priv, ring->obj);
1494N/A
1494N/A
1494N/A i915_gem_record_active_context(ring, error, &error->ring[i]);
1494N/A
1494N/A count = 0;
1494N/A list_for_each_entry(request, &ring->request_list, list)
1494N/A count++;
1494N/A
1494N/A error->ring[i].num_requests = count;
1494N/A error->ring[i].requests =
1494N/A kmalloc(count*sizeof(struct drm_i915_error_request),
1494N/A GFP_ATOMIC);
1494N/A if (error->ring[i].requests == NULL) {
1494N/A error->ring[i].num_requests = 0;
1494N/A continue;
1494N/A }
1494N/A
1494N/A count = 0;
1494N/A list_for_each_entry(request, &ring->request_list, list) {
1494N/A struct drm_i915_error_request *erq;
1494N/A
1494N/A erq = &error->ring[i].requests[count++];
1494N/A erq->seqno = request->seqno;
1494N/A erq->jiffies = request->emitted_jiffies;
1494N/A erq->tail = request->tail;
1494N/A }
1494N/A }
1494N/A}
1494N/A
1494N/A/**
1494N/A * i915_capture_error_state - capture an error record for later analysis
1494N/A * @dev: drm device
1494N/A *
1494N/A * Should be called when an error is detected (either a hang or an error
1494N/A * interrupt) to capture error state from the time of the error. Fills
1494N/A * out a structure which becomes available in debugfs for user level tools
1494N/A * to pick up.
1494N/A */
1494N/Astatic void i915_capture_error_state(struct drm_device *dev)
1494N/A{
1494N/A struct drm_i915_private *dev_priv = dev->dev_private;
1494N/A struct drm_i915_gem_object *obj;
1494N/A struct drm_i915_error_state *error;
1494N/A unsigned long flags;
1494N/A int i, pipe;
1494N/A
1494N/A spin_lock_irqsave(&dev_priv->gpu_error.lock, flags);
1494N/A error = dev_priv->gpu_error.first_error;
1494N/A spin_unlock_irqrestore(&dev_priv->gpu_error.lock, flags);
1494N/A if (error)
1494N/A return;
1494N/A
1494N/A /* Account for pipe specific data like PIPE*STAT */
1494N/A error = kzalloc(sizeof(*error), GFP_ATOMIC);
1494N/A if (!error) {
1494N/A DRM_DEBUG_DRIVER("out of memory, not capturing error state\n");
1494N/A return;
1494N/A }
1494N/A
1494N/A DRM_INFO("capturing error event; look for more information in "
1494N/A "/sys/kernel/debug/dri/%d/i915_error_state\n",
1494N/A dev->primary->index);
1494N/A
1494N/A kref_init(&error->ref);
1494N/A error->eir = I915_READ(EIR);
1494N/A error->pgtbl_er = I915_READ(PGTBL_ER);
1494N/A if (HAS_HW_CONTEXTS(dev))
1494N/A error->ccid = I915_READ(CCID);
1494N/A
1494N/A if (HAS_PCH_SPLIT(dev))
1494N/A error->ier = I915_READ(DEIER) | I915_READ(GTIER);
1494N/A else if (IS_VALLEYVIEW(dev))
1494N/A error->ier = I915_READ(GTIER) | I915_READ(VLV_IER);
1494N/A else if (IS_GEN2(dev))
1494N/A error->ier = I915_READ16(IER);
1494N/A else
1494N/A error->ier = I915_READ(IER);
1494N/A
1494N/A if (INTEL_INFO(dev)->gen >= 6)
1494N/A error->derrmr = I915_READ(DERRMR);
1494N/A
1494N/A if (IS_VALLEYVIEW(dev))
1494N/A error->forcewake = I915_READ(FORCEWAKE_VLV);
1494N/A else if (INTEL_INFO(dev)->gen >= 7)
1494N/A error->forcewake = I915_READ(FORCEWAKE_MT);
1494N/A else if (INTEL_INFO(dev)->gen == 6)
1494N/A error->forcewake = I915_READ(FORCEWAKE);
1494N/A
1494N/A if (!HAS_PCH_SPLIT(dev))
1494N/A for_each_pipe(pipe)
1494N/A error->pipestat[pipe] = I915_READ(PIPESTAT(pipe));
1494N/A
1494N/A if (INTEL_INFO(dev)->gen >= 6) {
1494N/A error->error = I915_READ(ERROR_GEN6);
1494N/A error->done_reg = I915_READ(DONE_REG);
1494N/A }
1494N/A
1494N/A if (INTEL_INFO(dev)->gen == 7)
1494N/A error->err_int = I915_READ(GEN7_ERR_INT);
1494N/A
1494N/A i915_get_extra_instdone(dev, error->extra_instdone);
1494N/A
1494N/A i915_gem_record_fences(dev, error);
1494N/A i915_gem_record_rings(dev, error);
1494N/A
1494N/A /* Record buffers on the active and pinned lists. */
1494N/A error->active_bo = NULL;
1494N/A error->pinned_bo = NULL;
1494N/A
1494N/A i = 0;
1494N/A list_for_each_entry(obj, &dev_priv->mm.active_list, mm_list)
1494N/A i++;
1494N/A error->active_bo_count = i;
1494N/A list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list)
1494N/A if (obj->pin_count)
1494N/A i++;
1494N/A error->pinned_bo_count = i - error->active_bo_count;
1494N/A
1494N/A error->active_bo = NULL;
1494N/A error->pinned_bo = NULL;
1494N/A if (i) {
1494N/A error->active_bo = kmalloc(sizeof(*error->active_bo)*i,
1494N/A GFP_ATOMIC);
1494N/A if (error->active_bo)
1494N/A error->pinned_bo =
1494N/A error->active_bo + error->active_bo_count;
1494N/A }
1494N/A
1494N/A if (error->active_bo)
1494N/A error->active_bo_count =
1494N/A capture_active_bo(error->active_bo,
1494N/A error->active_bo_count,
1494N/A &dev_priv->mm.active_list);
1494N/A
1494N/A if (error->pinned_bo)
1494N/A error->pinned_bo_count =
1494N/A capture_pinned_bo(error->pinned_bo,
1494N/A error->pinned_bo_count,
1494N/A &dev_priv->mm.bound_list);
1494N/A
1494N/A do_gettimeofday(&error->time);
1494N/A
1494N/A error->overlay = intel_overlay_capture_error_state(dev);
1494N/A error->display = intel_display_capture_error_state(dev);
1494N/A
1494N/A spin_lock_irqsave(&dev_priv->gpu_error.lock, flags);
1494N/A if (dev_priv->gpu_error.first_error == NULL) {
1494N/A dev_priv->gpu_error.first_error = error;
1494N/A error = NULL;
1494N/A }
1494N/A spin_unlock_irqrestore(&dev_priv->gpu_error.lock, flags);
1494N/A
1494N/A if (error)
1494N/A i915_error_state_free(&error->ref);
1494N/A}
1494N/A
1494N/Avoid i915_destroy_error_state(struct drm_device *dev)
1494N/A{
1494N/A struct drm_i915_private *dev_priv = dev->dev_private;
1494N/A struct drm_i915_error_state *error;
1494N/A unsigned long flags;
1494N/A
1494N/A spin_lock_irqsave(&dev_priv->gpu_error.lock, flags);
1494N/A error = dev_priv->gpu_error.first_error;
1494N/A dev_priv->gpu_error.first_error = NULL;
1494N/A spin_unlock_irqrestore(&dev_priv->gpu_error.lock, flags);
1494N/A
1494N/A if (error)
1494N/A kref_put(&error->ref, i915_error_state_free);
1494N/A}
1494N/A#else
1494N/A#define i915_capture_error_state(x)
1494N/A#endif
1494N/A
1494N/Astatic void i915_report_and_clear_eir(struct drm_device *dev)
1494N/A{
1494N/A struct drm_i915_private *dev_priv = dev->dev_private;
1494N/A uint32_t instdone[I915_NUM_INSTDONE_REG];
1494N/A u32 eir = I915_READ(EIR);
1494N/A int pipe;
1494N/A
1494N/A if (!eir)
1494N/A return;
1494N/A
1494N/A DRM_ERROR("render error detected, EIR: 0x%08x\n", eir);
1494N/A
1494N/A i915_get_extra_instdone(dev, instdone);
1494N/A
1494N/A if (IS_G4X(dev)) {
1494N/A if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
1494N/A u32 ipeir = I915_READ(IPEIR_I965);
1494N/A
1494N/A DRM_DEBUG(" IPEIR: 0x%08x\n",
1494N/A I915_READ(IPEIR_I965));
1494N/A DRM_DEBUG(" IPEHR: 0x%08x\n",
1494N/A I915_READ(IPEHR_I965));
1494N/A DRM_DEBUG(" INSTDONE: 0x%08x\n",
1494N/A I915_READ(INSTDONE_I965));
1494N/A DRM_DEBUG(" INSTPS: 0x%08x\n",
1494N/A I915_READ(INSTPS));
1494N/A DRM_DEBUG(" INSTDONE1: 0x%08x\n",
1494N/A I915_READ(INSTDONE1));
1494N/A DRM_DEBUG(" ACTHD: 0x%08x\n",
1494N/A I915_READ(ACTHD_I965));
1494N/A I915_WRITE(IPEIR_I965, ipeir);
1494N/A POSTING_READ(IPEIR_I965);
1494N/A }
1494N/A if (eir & GM45_ERROR_PAGE_TABLE) {
1494N/A u32 pgtbl_err = I915_READ(PGTBL_ER);
1494N/A DRM_DEBUG("page table error\n");
1494N/A DRM_DEBUG(" PGTBL_ER: 0x%08x\n",
1494N/A pgtbl_err);
1494N/A I915_WRITE(PGTBL_ER, pgtbl_err);
1494N/A POSTING_READ(PGTBL_ER);
1494N/A }
1494N/A }
1494N/A
1494N/A if (!IS_GEN2(dev)) {
1494N/A if (eir & I915_ERROR_PAGE_TABLE) {
1494N/A u32 pgtbl_err = I915_READ(PGTBL_ER);
1494N/A DRM_DEBUG("page table error\n");
1494N/A DRM_DEBUG(" PGTBL_ER: 0x%08x\n",
1494N/A pgtbl_err);
1494N/A I915_WRITE(PGTBL_ER, pgtbl_err);
1494N/A POSTING_READ(PGTBL_ER);
1494N/A }
1494N/A }
1494N/A
1494N/A if (eir & I915_ERROR_MEMORY_REFRESH) {
1494N/A DRM_DEBUG("memory refresh error:\n");
1494N/A for_each_pipe(pipe)
1494N/A DRM_DEBUG("pipe %c stat: 0x%08x\n",
1494N/A pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
1494N/A /* pipestat has already been acked */
1494N/A }
1494N/A if (eir & I915_ERROR_INSTRUCTION) {
1494N/A DRM_DEBUG("instruction error\n");
1494N/A DRM_DEBUG(" INSTPM: 0x%08x\n",
1494N/A I915_READ(INSTPM));
1494N/A if (INTEL_INFO(dev)->gen < 4) {
1494N/A u32 ipeir = I915_READ(IPEIR);
1494N/A
1494N/A DRM_DEBUG(" IPEIR: 0x%08x\n",
1494N/A I915_READ(IPEIR));
1494N/A DRM_DEBUG(" IPEHR: 0x%08x\n",
1494N/A I915_READ(IPEHR));
1494N/A DRM_DEBUG(" INSTDONE: 0x%08x\n",
1494N/A I915_READ(INSTDONE));
1494N/A DRM_DEBUG(" ACTHD: 0x%08x\n",
1494N/A I915_READ(ACTHD));
1494N/A I915_WRITE(IPEIR, ipeir);
1494N/A POSTING_READ(IPEIR);
1494N/A } else {
1494N/A u32 ipeir = I915_READ(IPEIR_I965);
1494N/A
1494N/A DRM_DEBUG(" IPEIR: 0x%08x\n",
1494N/A I915_READ(IPEIR_I965));
1494N/A DRM_DEBUG(" IPEHR: 0x%08x\n",
1494N/A I915_READ(IPEHR_I965));
1494N/A DRM_DEBUG(" INSTDONE: 0x%08x\n",
1494N/A I915_READ(INSTDONE_I965));
1494N/A DRM_DEBUG(" INSTPS: 0x%08x\n",
1494N/A I915_READ(INSTPS));
1494N/A DRM_DEBUG(" INSTDONE1: 0x%08x\n",
1494N/A I915_READ(INSTDONE1));
1494N/A DRM_DEBUG(" ACTHD: 0x%08x\n",
1494N/A I915_READ(ACTHD_I965));
1494N/A I915_WRITE(IPEIR_I965, ipeir);
1494N/A POSTING_READ(IPEIR_I965);
1494N/A }
1494N/A }
1494N/A
1494N/A I915_WRITE(EIR, eir);
1494N/A POSTING_READ(EIR);
1494N/A eir = I915_READ(EIR);
1494N/A if (eir) {
1494N/A /*
1494N/A * some errors might have become stuck,
1494N/A * mask them.
1494N/A */
1494N/A DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
1494N/A I915_WRITE(EMR, I915_READ(EMR) | eir);
1494N/A I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
1494N/A }
1494N/A}
1494N/A
1494N/A/**
1494N/A * i915_handle_error - handle an error interrupt
1494N/A * @dev: drm device
1494N/A *
1494N/A * Do some basic checking of regsiter state at error interrupt time and
1494N/A * dump it to the syslog. Also call i915_capture_error_state() to make
1494N/A * sure we get a record and make it available in debugfs. Fire a uevent
1494N/A * so userspace knows something bad happened (should trigger collection
1494N/A * of a ring dump etc.).
1494N/A */
1494N/Avoid i915_handle_error(struct drm_device *dev, bool wedged)
1494N/A{
1494N/A struct drm_i915_private *dev_priv = dev->dev_private;
1494N/A struct intel_ring_buffer *ring;
1494N/A int i;
1494N/A
1494N/A i915_capture_error_state(dev);
1494N/A i915_report_and_clear_eir(dev);
1494N/A
1494N/A if (wedged) {
1494N/A atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG,
1494N/A &dev_priv->gpu_error.reset_counter);
1494N/A
1494N/A /*
1494N/A * Wakeup waiting processes so they don't hang
1494N/A */
1494N/A for_each_ring(ring, dev_priv, i)
1494N/A wake_up_all(&ring->irq_queue);
1494N/A }
1494N/A
1494N/A (void) queue_work(dev_priv->wq, &dev_priv->gpu_error.work);
1494N/A}
1494N/A
1494N/Astatic void i915_pageflip_stall_check(struct drm_device *dev, int pipe)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = dev->dev_private;
1494N/A struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
1494N/A struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1494N/A struct drm_i915_gem_object *obj;
1494N/A struct intel_unpin_work *work;
1494N/A unsigned long flags;
1494N/A bool stall_detected;
1494N/A
1494N/A /* Ignore early vblank irqs */
1494N/A if (intel_crtc == NULL)
1494N/A return;
1494N/A
1494N/A spin_lock_irqsave(&dev->event_lock, flags);
1494N/A work = intel_crtc->unpin_work;
1494N/A
1494N/A if (work == NULL ||
1494N/A atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE ||
1494N/A !work->enable_stall_check) {
1494N/A /* Either the pending flip IRQ arrived, or we're too early. Don't check */
1494N/A spin_unlock_irqrestore(&dev->event_lock, flags);
1494N/A return;
1494N/A }
1494N/A
1494N/A /* Potential stall - if we see that the flip has happened, assume a missed interrupt */
1494N/A obj = work->pending_flip_obj;
1494N/A if (INTEL_INFO(dev)->gen >= 4) {
1494N/A int dspsurf = DSPSURF(intel_crtc->plane);
1494N/A stall_detected = I915_HI_DISPBASE(I915_READ(dspsurf)) ==
1494N/A obj->gtt_offset;
1494N/A } else {
1494N/A int dspaddr = DSPADDR(intel_crtc->plane);
1494N/A stall_detected = I915_READ(dspaddr) == (obj->gtt_offset +
1494N/A crtc->y * crtc->fb->pitches[0] +
1494N/A crtc->x * crtc->fb->bits_per_pixel/8);
1494N/A }
1494N/A
1494N/A spin_unlock_irqrestore(&dev->event_lock, flags);
1494N/A
1494N/A if (stall_detected) {
1494N/A DRM_DEBUG_DRIVER("Pageflip stall detected\n");
1494N/A intel_prepare_page_flip(dev, intel_crtc->plane);
1494N/A }
1494N/A}
1494N/A
1494N/A/* Called from drm generic code, passed 'crtc' which
1494N/A * we use as a pipe index
1494N/A */
1494N/Astatic int i915_enable_vblank(struct drm_device *dev, int pipe)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A unsigned long irqflags;
1494N/A
1494N/A if (!i915_pipe_enabled(dev, pipe))
1494N/A return -EINVAL;
1494N/A
1494N/A spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
1494N/A if (INTEL_INFO(dev)->gen >= 4)
1494N/A i915_enable_pipestat(dev_priv, pipe,
1494N/A PIPE_START_VBLANK_INTERRUPT_ENABLE);
1494N/A else
1494N/A i915_enable_pipestat(dev_priv, pipe,
1494N/A PIPE_VBLANK_INTERRUPT_ENABLE);
1494N/A
1494N/A /* maintain vblank delivery even in deep C-states */
1494N/A if (dev_priv->info->gen == 3)
1494N/A I915_WRITE(INSTPM, _MASKED_BIT_DISABLE(INSTPM_AGPBUSY_DIS));
1494N/A spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1494N/A
1494N/A return 0;
1494N/A}
1494N/A
1494N/Astatic int ironlake_enable_vblank(struct drm_device *dev, int pipe)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A unsigned long irqflags;
1494N/A
1494N/A if (!i915_pipe_enabled(dev, pipe))
1494N/A return -EINVAL;
1494N/A
1494N/A spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
1494N/A ironlake_enable_display_irq(dev_priv, (pipe == 0) ?
1494N/A DE_PIPEA_VBLANK: DE_PIPEB_VBLANK);
1494N/A spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1494N/A
1494N/A return 0;
1494N/A}
1494N/A
1494N/Astatic int ivybridge_enable_vblank(struct drm_device *dev, int pipe)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A unsigned long irqflags;
1494N/A
1494N/A if (!i915_pipe_enabled(dev, pipe))
1494N/A return -EINVAL;
1494N/A
1494N/A spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
1494N/A ironlake_enable_display_irq(dev_priv,
1494N/A DE_PIPEA_VBLANK_IVB << (5 * pipe));
1494N/A spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1494N/A
1494N/A return 0;
1494N/A}
1494N/A
1494N/Astatic int valleyview_enable_vblank(struct drm_device *dev, int pipe)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A unsigned long irqflags;
1494N/A u32 imr;
1494N/A
1494N/A if (!i915_pipe_enabled(dev, pipe))
1494N/A return -EINVAL;
1494N/A
1494N/A spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
1494N/A imr = I915_READ(VLV_IMR);
1494N/A if (pipe == 0)
1494N/A imr &= ~I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
1494N/A else
1494N/A imr &= ~I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
1494N/A I915_WRITE(VLV_IMR, imr);
1494N/A i915_enable_pipestat(dev_priv, pipe,
1494N/A PIPE_START_VBLANK_INTERRUPT_ENABLE);
1494N/A spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1494N/A
1494N/A return 0;
1494N/A}
1494N/A
1494N/A/* Called from drm generic code, passed 'crtc' which
1494N/A * we use as a pipe index
1494N/A */
1494N/Astatic void i915_disable_vblank(struct drm_device *dev, int pipe)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A unsigned long irqflags;
1494N/A
1494N/A spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
1494N/A if (dev_priv->info->gen == 3)
1494N/A I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_DIS));
1494N/A
1494N/A i915_disable_pipestat(dev_priv, pipe,
1494N/A PIPE_VBLANK_INTERRUPT_ENABLE |
1494N/A PIPE_START_VBLANK_INTERRUPT_ENABLE);
1494N/A spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1494N/A}
1494N/A
1494N/Astatic void ironlake_disable_vblank(struct drm_device *dev, int pipe)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A unsigned long irqflags;
1494N/A
1494N/A spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
1494N/A ironlake_disable_display_irq(dev_priv, (pipe == 0) ?
1494N/A DE_PIPEA_VBLANK : DE_PIPEB_VBLANK);
1494N/A spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1494N/A}
1494N/A
1494N/Astatic void ivybridge_disable_vblank(struct drm_device *dev, int pipe)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A unsigned long irqflags;
1494N/A
1494N/A spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
1494N/A ironlake_disable_display_irq(dev_priv,
1494N/A DE_PIPEA_VBLANK_IVB << (pipe * 5));
1494N/A spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1494N/A}
1494N/A
1494N/Astatic void valleyview_disable_vblank(struct drm_device *dev, int pipe)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A unsigned long irqflags;
1494N/A u32 imr;
1494N/A
1494N/A spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
1494N/A i915_disable_pipestat(dev_priv, pipe,
1494N/A PIPE_START_VBLANK_INTERRUPT_ENABLE);
1494N/A imr = I915_READ(VLV_IMR);
1494N/A if (pipe == 0)
1494N/A imr |= I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
1494N/A else
1494N/A imr |= I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
1494N/A I915_WRITE(VLV_IMR, imr);
1494N/A spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1494N/A}
1494N/A
1494N/Astatic u32
1494N/Aring_last_seqno(struct intel_ring_buffer *ring)
1494N/A{
1494N/A struct drm_i915_gem_request *last_req;
1494N/A last_req = list_entry(ring->request_list.prev,
1494N/A struct drm_i915_gem_request, list);
1494N/A return (last_req->seqno);
1494N/A}
1494N/A
1494N/Astatic bool
1494N/Aring_idle(struct intel_ring_buffer *ring, u32 seqno)
1494N/A{
1494N/A return (list_empty(&ring->request_list) ||
1494N/A i915_seqno_passed(seqno, ring_last_seqno(ring)));
1494N/A}
1494N/A
1494N/Astatic struct intel_ring_buffer *
1494N/Asemaphore_waits_for(struct intel_ring_buffer *ring, u32 *seqno)
1494N/A{
1494N/A struct drm_i915_private *dev_priv = ring->dev->dev_private;
1494N/A u32 cmd, ipehr, acthd, acthd_min;
1494N/A u32 *tmp;
1494N/A
1494N/A ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
1494N/A if ((ipehr & ~(0x3 << 16)) !=
1494N/A (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE | MI_SEMAPHORE_REGISTER))
1494N/A return NULL;
1494N/A
1494N/A /* ACTHD is likely pointing to the dword after the actual command,
1494N/A * so scan backwards until we find the MBOX.
1494N/A */
1494N/A acthd = intel_ring_get_active_head(ring) & HEAD_ADDR;
1494N/A acthd_min = max((int)acthd - 3 * 4, 0);
1494N/A do {
1494N/A tmp = (u32 *)((intptr_t)ring->virtual_start + acthd);
1494N/A cmd = *tmp;
1494N/A if (cmd == ipehr)
1494N/A break;
1494N/A
1494N/A acthd -= 4;
1494N/A if (acthd < acthd_min)
1494N/A return NULL;
1494N/A } while (1);
1494N/A
1494N/A tmp = (u32 *)((intptr_t)ring->virtual_start + acthd + 4 );
1494N/A *seqno = *tmp+1;
1494N/A return &dev_priv->ring[(ring->id + (((ipehr >> 17) & 1) + 1)) % 3];
1494N/A}
1494N/A
1494N/Astatic int semaphore_passed(struct intel_ring_buffer *ring)
1494N/A{
1494N/A struct drm_i915_private *dev_priv = ring->dev->dev_private;
1494N/A struct intel_ring_buffer *signaller;
1494N/A u32 seqno, ctl;
1494N/A
1494N/A ring->hangcheck.deadlock = true;
1494N/A
1494N/A signaller = semaphore_waits_for(ring, &seqno);
1494N/A if (signaller == NULL || signaller->hangcheck.deadlock)
1494N/A return -1;
1494N/A
1494N/A /* cursory check for an unkickable deadlock */
1494N/A ctl = I915_READ_CTL(signaller);
1494N/A if (ctl & RING_WAIT_SEMAPHORE && semaphore_passed(signaller) < 0)
1494N/A return -1;
1494N/A
1494N/A return i915_seqno_passed(signaller->get_seqno(signaller, false), seqno);
1494N/A}
1494N/A
1494N/Astatic void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
1494N/A{
1494N/A struct intel_ring_buffer *ring;
1494N/A int i;
1494N/A
1494N/A for_each_ring(ring, dev_priv, i)
1494N/A ring->hangcheck.deadlock = false;
1494N/A}
1494N/A
1494N/Astatic enum intel_ring_hangcheck_action
1494N/Aring_stuck(struct intel_ring_buffer *ring, u32 acthd)
1494N/A{
1494N/A struct drm_device *dev = ring->dev;
1494N/A struct drm_i915_private *dev_priv = dev->dev_private;
1494N/A u32 tmp;
1494N/A
1494N/A if (ring->hangcheck.acthd != acthd)
1494N/A return active;
1494N/A
1494N/A if (IS_GEN2(dev))
1494N/A return hung;
1494N/A
1494N/A /* Is the chip hanging on a WAIT_FOR_EVENT?
1494N/A * If so we can simply poke the RB_WAIT bit
1494N/A * and break the hang. This should work on
1494N/A * all but the second generation chipsets.
1494N/A */
1494N/A tmp = I915_READ_CTL(ring);
1494N/A if (tmp & RING_WAIT) {
1494N/A DRM_ERROR("Kicking stuck wait on %s\n",
1494N/A ring->name);
1494N/A I915_WRITE_CTL(ring, tmp);
1494N/A return kick;
1494N/A }
1494N/A
1494N/A if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) {
1494N/A switch (semaphore_passed(ring)) {
1494N/A default:
1494N/A return hung;
1494N/A case 1:
1494N/A DRM_ERROR("Kicking stuck semaphore on %s\n",
1494N/A ring->name);
1494N/A I915_WRITE_CTL(ring, tmp);
1494N/A return kick;
1494N/A case 0:
1494N/A return wait;
1494N/A }
1494N/A }
1494N/A
1494N/A return hung;
1494N/A}
1494N/A
1494N/A/**
1494N/A * This is called when the chip hasn't reported back with completed
1494N/A * batchbuffers in a long time. The first time this is called we simply record
1494N/A * ACTHD. If ACTHD hasn't changed by the time the hangcheck timer elapses
1494N/A * Further, acthd is inspected to see if the ring is stuck. On stuck case
1494N/A * we kick the ring. If we see no progress on three subsequent calls
1494N/A * again, we assume the chip is wedged and try to fix it.
1494N/A */
1494N/Avoid i915_hangcheck_elapsed(void* data)
1494N/A{
1494N/A struct drm_device *dev = (struct drm_device *)data;
1494N/A drm_i915_private_t *dev_priv = dev->dev_private;
1494N/A struct intel_ring_buffer *ring;
1494N/A int i;
1494N/A int busy_count = 0, rings_hung = 0;
1494N/A bool stuck[I915_NUM_RINGS] = { 0 };
1494N/A#define BUSY 1
1494N/A#define KICK 5
1494N/A#define HUNG 20
1494N/A#define FIRE 30
1494N/A
1494N/A if (!i915_enable_hangcheck)
1494N/A return;
1494N/A
1494N/A for_each_ring(ring, dev_priv, i) {
1494N/A u32 seqno, acthd;
1494N/A bool busy = true;
1494N/A
1494N/A semaphore_clear_deadlocks(dev_priv);
1494N/A
1494N/A seqno = ring->get_seqno(ring, false);
1494N/A acthd = intel_ring_get_active_head(ring);
1494N/A
1494N/A if (ring->hangcheck.seqno == seqno) {
1494N/A if (ring_idle(ring, seqno)) {
1494N/A if (mutex_is_locked(&ring->irq_queue.lock)) {
1494N/A /* Issue a wake-up to catch stuck h/w. */
1494N/A DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
1494N/A ring->name);
1494N/A wake_up_all(&ring->irq_queue);
1494N/A ring->hangcheck.score += HUNG;
1494N/A } else
1494N/A busy = false;
1494N/A } else {
1494N/A int score = 0;
1494N/A
1494N/A /* We always increment the hangcheck score
1494N/A * if the ring is busy and still processing
1494N/A * the same request, so that no single request
1494N/A * can run indefinitely (such as a chain of
1494N/A * batches). The only time we do not increment
1494N/A * the hangcheck score on this ring, if this
1494N/A * ring is in a legitimate wait for another
1494N/A * ring. In that case the waiting ring is a
1494N/A * victim and we want to be sure we catch the
1494N/A * right culprit. Then every time we do kick
1494N/A * the ring, add a small increment to the
1494N/A * score so that we can catch a batch that is
1494N/A * being repeatedly kicked and so responsible
1494N/A * for stalling the machine.
1494N/A */
1494N/A ring->hangcheck.action = ring_stuck(ring,
1494N/A acthd);
1494N/A
1494N/A switch (ring->hangcheck.action) {
1494N/A case wait:
1494N/A score = 0;
1494N/A break;
1494N/A case active:
1494N/A score = BUSY;
1494N/A break;
1494N/A case kick:
1494N/A score = KICK;
1494N/A break;
1494N/A case hung:
1494N/A score = HUNG;
1494N/A stuck[i] = true;
1494N/A break;
1494N/A }
1494N/A ring->hangcheck.score += score;
1494N/A }
1494N/A } else {
1494N/A /* Gradually reduce the count so that we catch DoS
1494N/A * attempts across multiple batches.
1494N/A */
1494N/A if (ring->hangcheck.score > 0)
1494N/A ring->hangcheck.score--;
1494N/A }
1494N/A
1494N/A ring->hangcheck.seqno = seqno;
1494N/A ring->hangcheck.acthd = acthd;
1494N/A busy_count += busy;
1494N/A }
1494N/A
1494N/A for_each_ring(ring, dev_priv, i) {
1494N/A if (ring->hangcheck.score > FIRE) {
1494N/A DRM_ERROR("%s on %s\n",
1494N/A stuck[i] ? "stuck" : "no progress",
1494N/A ring->name);
1494N/A rings_hung++;
1494N/A }
1494N/A }
1494N/A
1494N/A if (rings_hung) {
1494N/A i915_handle_error(dev, true);
1494N/A return;
1494N/A }
1494N/A
1494N/A if (busy_count)
1494N/A /* Reset timer case chip hangs without another request
1494N/A * being added */
1494N/A mod_timer(&dev_priv->gpu_error.hangcheck_timer,
1494N/A msecs_to_jiffies(DRM_I915_HANGCHECK_PERIOD));
1494N/A}
1494N/A
1494N/Astatic void ibx_irq_preinstall(struct drm_device *dev)
1494N/A{
1494N/A struct drm_i915_private *dev_priv = dev->dev_private;
1494N/A
1494N/A if (HAS_PCH_NOP(dev))
1494N/A return;
1494N/A
1494N/A /* south display irq */
1494N/A I915_WRITE(SDEIMR, 0xffffffff);
1494N/A /*
1494N/A * SDEIER is also touched by the interrupt handler to work around missed
1494N/A * PCH interrupts. Hence we can't update it after the interrupt handler
1494N/A * is enabled - instead we unconditionally enable all PCH interrupt
1494N/A * sources here, but then only unmask them as needed with SDEIMR.
1494N/A */
1494N/A I915_WRITE(SDEIER, 0xffffffff);
1494N/A POSTING_READ(SDEIER);
1494N/A}
1494N/A
1494N/A/* drm_dma.h hooks
1494N/A*/
1494N/Astatic void ironlake_irq_preinstall(struct drm_device *dev)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A
1494N/A atomic_set(&dev_priv->irq_received, 0);
1494N/A
1494N/A I915_WRITE(HWSTAM, 0xeffe);
1494N/A
1494N/A /* XXX hotplug from PCH */
1494N/A
1494N/A I915_WRITE(DEIMR, 0xffffffff);
1494N/A I915_WRITE(DEIER, 0x0);
1494N/A POSTING_READ(DEIER);
1494N/A
1494N/A /* and GT */
1494N/A I915_WRITE(GTIMR, 0xffffffff);
1494N/A I915_WRITE(GTIER, 0x0);
1494N/A POSTING_READ(GTIER);
1494N/A
1494N/A ibx_irq_preinstall(dev);
1494N/A}
1494N/A
1494N/Astatic void ivybridge_irq_preinstall(struct drm_device *dev)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A
1494N/A atomic_set(&dev_priv->irq_received, 0);
1494N/A
1494N/A I915_WRITE(HWSTAM, 0xeffe);
1494N/A
1494N/A /* XXX hotplug from PCH */
1494N/A
1494N/A I915_WRITE(DEIMR, 0xffffffff);
1494N/A I915_WRITE(DEIER, 0x0);
1494N/A POSTING_READ(DEIER);
1494N/A
1494N/A /* and GT */
1494N/A I915_WRITE(GTIMR, 0xffffffff);
1494N/A I915_WRITE(GTIER, 0x0);
1494N/A POSTING_READ(GTIER);
1494N/A
1494N/A /* Power management */
1494N/A I915_WRITE(GEN6_PMIMR, 0xffffffff);
1494N/A I915_WRITE(GEN6_PMIER, 0x0);
1494N/A POSTING_READ(GEN6_PMIER);
1494N/A
1494N/A ibx_irq_preinstall(dev);
1494N/A}
1494N/A
1494N/Astatic void valleyview_irq_preinstall(struct drm_device *dev)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A int pipe;
1494N/A
1494N/A atomic_set(&dev_priv->irq_received, 0);
1494N/A
1494N/A /* VLV magic */
1494N/A I915_WRITE(VLV_IMR, 0);
1494N/A I915_WRITE(RING_IMR(RENDER_RING_BASE), 0);
1494N/A I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0);
1494N/A I915_WRITE(RING_IMR(BLT_RING_BASE), 0);
1494N/A
1494N/A /* and GT */
1494N/A I915_WRITE(GTIIR, I915_READ(GTIIR));
1494N/A I915_WRITE(GTIIR, I915_READ(GTIIR));
1494N/A I915_WRITE(GTIMR, 0xffffffff);
1494N/A I915_WRITE(GTIER, 0x0);
1494N/A POSTING_READ(GTIER);
1494N/A
1494N/A I915_WRITE(DPINVGTT, 0xff);
1494N/A
1494N/A I915_WRITE(PORT_HOTPLUG_EN, 0);
1494N/A I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
1494N/A for_each_pipe(pipe)
1494N/A I915_WRITE(PIPESTAT(pipe), 0xffff);
1494N/A I915_WRITE(VLV_IIR, 0xffffffff);
1494N/A I915_WRITE(VLV_IMR, 0xffffffff);
1494N/A I915_WRITE(VLV_IER, 0x0);
1494N/A POSTING_READ(VLV_IER);
1494N/A}
1494N/A
1494N/Astatic void ibx_hpd_irq_setup(struct drm_device *dev)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A struct drm_mode_config *mode_config = &dev->mode_config;
1494N/A struct intel_encoder *intel_encoder;
1494N/A u32 mask = ~I915_READ(SDEIMR);
1494N/A u32 hotplug;
1494N/A
1494N/A if (HAS_PCH_IBX(dev)) {
1494N/A mask &= ~SDE_HOTPLUG_MASK;
1494N/A list_for_each_entry(intel_encoder, struct intel_encoder, &mode_config->encoder_list, base.head)
1494N/A if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
1494N/A mask |= hpd_ibx[intel_encoder->hpd_pin];
1494N/A } else {
1494N/A mask &= ~SDE_HOTPLUG_MASK_CPT;
1494N/A list_for_each_entry(intel_encoder, struct intel_encoder, &mode_config->encoder_list, base.head)
1494N/A if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
1494N/A mask |= hpd_cpt[intel_encoder->hpd_pin];
1494N/A }
1494N/A
1494N/A I915_WRITE(SDEIMR, ~mask);
1494N/A
1494N/A /*
1494N/A * Enable digital hotplug on the PCH, and configure the DP short pulse
1494N/A * duration to 2ms (which is the minimum in the Display Port spec)
1494N/A *
1494N/A * This register is the same on all known PCH chips.
1494N/A */
1494N/A hotplug = I915_READ(PCH_PORT_HOTPLUG);
1494N/A hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
1494N/A hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
1494N/A hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
1494N/A hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
1494N/A I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
1494N/A}
1494N/A
1494N/Astatic void ibx_irq_postinstall(struct drm_device *dev)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A u32 mask;
1494N/A
1494N/A if (HAS_PCH_NOP(dev))
1494N/A return;
1494N/A
1494N/A if (HAS_PCH_IBX(dev)) {
1494N/A mask = SDE_GMBUS | SDE_AUX_MASK | SDE_TRANSB_FIFO_UNDER |
1494N/A SDE_TRANSA_FIFO_UNDER | SDE_POISON;
1494N/A } else {
1494N/A mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT | SDE_ERROR_CPT;
1494N/A
1494N/A I915_WRITE(SERR_INT, I915_READ(SERR_INT));
1494N/A }
1494N/A
1494N/A I915_WRITE(SDEIIR, I915_READ(SDEIIR));
1494N/A I915_WRITE(SDEIMR, ~mask);
1494N/A}
1494N/A
1494N/Astatic int ironlake_irq_postinstall(struct drm_device *dev)
1494N/A{
1494N/A unsigned long irqflags;
1494N/A
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A /* enable kind of interrupts always enabled */
1494N/A u32 display_mask = DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
1494N/A DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
1494N/A DE_AUX_CHANNEL_A | DE_PIPEB_FIFO_UNDERRUN |
1494N/A DE_PIPEA_FIFO_UNDERRUN | DE_POISON;
1494N/A u32 gt_irqs;
1494N/A
1494N/A dev_priv->irq_mask = ~display_mask;
1494N/A
1494N/A /* should always can generate irq */
1494N/A I915_WRITE(DEIIR, I915_READ(DEIIR));
1494N/A I915_WRITE(DEIMR, dev_priv->irq_mask);
1494N/A I915_WRITE(DEIER, display_mask |
1494N/A DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT);
1494N/A
1494N/A /* LINTED */
1494N/A dev_priv->gt_irq_mask = ~0;
1494N/A
1494N/A I915_WRITE(GTIIR, I915_READ(GTIIR));
1494N/A I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
1494N/A
1494N/A gt_irqs = GT_RENDER_USER_INTERRUPT;
1494N/A
1494N/A if (IS_GEN6(dev))
1494N/A gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
1494N/A else
1494N/A gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT |
1494N/A ILK_BSD_USER_INTERRUPT;
1494N/A
1494N/A I915_WRITE(GTIER, gt_irqs);
1494N/A
1494N/A ibx_irq_postinstall(dev);
1494N/A POSTING_READ(GTIER);
1494N/A POSTING_READ(DEIER);
1494N/A
1494N/A if (IS_IRONLAKE_M(dev)) {
1494N/A /* Enable PCU event interrupts
1494N/A *
1494N/A * spinlocking not required here for correctness since interrupt
1494N/A * setup is guaranteed to run in single-threaded context. But we
1494N/A * need it to make the assert_spin_locked happy. */
1494N/A spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
1494N/A ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
1494N/A spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1494N/A }
1494N/A
1494N/A return 0;
1494N/A}
1494N/A
1494N/Astatic int ivybridge_irq_postinstall(struct drm_device *dev)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A /* enable kind of interrupts always enabled */
1494N/A u32 display_mask =
1494N/A DE_MASTER_IRQ_CONTROL | DE_GSE_IVB | DE_PCH_EVENT_IVB |
1494N/A DE_PLANEC_FLIP_DONE_IVB |
1494N/A DE_PLANEB_FLIP_DONE_IVB |
1494N/A DE_PLANEA_FLIP_DONE_IVB |
1494N/A DE_AUX_CHANNEL_A_IVB |
1494N/A DE_ERR_INT_IVB;
1494N/A u32 pm_irqs = GEN6_PM_RPS_EVENTS;
1494N/A u32 gt_irqs;
1494N/A
1494N/A dev_priv->irq_mask = ~display_mask;
1494N/A
1494N/A /* should always can generate irq */
1494N/A I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
1494N/A I915_WRITE(DEIIR, I915_READ(DEIIR));
1494N/A I915_WRITE(DEIMR, dev_priv->irq_mask);
1494N/A I915_WRITE(DEIER,
1494N/A display_mask |
1494N/A DE_PIPEC_VBLANK_IVB |
1494N/A DE_PIPEB_VBLANK_IVB |
1494N/A DE_PIPEA_VBLANK_IVB);
1494N/A POSTING_READ(DEIER);
1494N/A
1494N/A /* LINTED */
1494N/A dev_priv->gt_irq_mask = ~GT_RENDER_L3_PARITY_ERROR_INTERRUPT;
1494N/A
1494N/A I915_WRITE(GTIIR, I915_READ(GTIIR));
1494N/A I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
1494N/A
1494N/A gt_irqs = GT_RENDER_USER_INTERRUPT | GT_BSD_USER_INTERRUPT |
1494N/A GT_BLT_USER_INTERRUPT | GT_RENDER_L3_PARITY_ERROR_INTERRUPT;
1494N/A I915_WRITE(GTIER, gt_irqs);
1494N/A POSTING_READ(GTIER);
1494N/A
1494N/A I915_WRITE(GEN6_PMIIR, I915_READ(GEN6_PMIIR));
1494N/A if (HAS_VEBOX(dev))
1494N/A pm_irqs |= PM_VEBOX_USER_INTERRUPT |
1494N/A PM_VEBOX_CS_ERROR_INTERRUPT;
1494N/A
1494N/A /* Our enable/disable rps functions may touch these registers so
1494N/A * make sure to set a known state for only the non-RPS bits.
1494N/A * The RMW is extra paranoia since this should be called after being set
1494N/A * to a known state in preinstall.
1494N/A * */
1494N/A I915_WRITE(GEN6_PMIMR,
1494N/A (I915_READ(GEN6_PMIMR) | ~GEN6_PM_RPS_EVENTS) & ~pm_irqs);
1494N/A I915_WRITE(GEN6_PMIER,
1494N/A (I915_READ(GEN6_PMIER) & GEN6_PM_RPS_EVENTS) | pm_irqs);
1494N/A POSTING_READ(GEN6_PMIER);
1494N/A
1494N/A ibx_irq_postinstall(dev);
1494N/A
1494N/A return 0;
1494N/A}
1494N/A
1494N/Astatic int valleyview_irq_postinstall(struct drm_device *dev)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A u32 gt_irqs;
1494N/A u32 enable_mask;
1494N/A u32 pipestat_enable = PLANE_FLIP_DONE_INT_EN_VLV;
1494N/A
1494N/A enable_mask = I915_DISPLAY_PORT_INTERRUPT;
1494N/A enable_mask |= I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
1494N/A I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
1494N/A I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
1494N/A I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
1494N/A
1494N/A /*
1494N/A *Leave vblank interrupts masked initially. enable/disable will
1494N/A * toggle them based on usage.
1494N/A */
1494N/A dev_priv->irq_mask = (~enable_mask) |
1494N/A I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
1494N/A I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
1494N/A
1494N/A I915_WRITE(PORT_HOTPLUG_EN, 0);
1494N/A POSTING_READ(PORT_HOTPLUG_EN);
1494N/A
1494N/A I915_WRITE(VLV_IMR, dev_priv->irq_mask);
1494N/A I915_WRITE(VLV_IER, enable_mask);
1494N/A I915_WRITE(VLV_IIR, 0xffffffff);
1494N/A I915_WRITE(PIPESTAT(0), 0xffff);
1494N/A I915_WRITE(PIPESTAT(1), 0xffff);
1494N/A POSTING_READ(VLV_IER);
1494N/A
1494N/A i915_enable_pipestat(dev_priv, 0, pipestat_enable);
1494N/A i915_enable_pipestat(dev_priv, 0, PIPE_GMBUS_EVENT_ENABLE);
1494N/A i915_enable_pipestat(dev_priv, 1, pipestat_enable);
1494N/A
1494N/A I915_WRITE(VLV_IIR, 0xffffffff);
1494N/A I915_WRITE(VLV_IIR, 0xffffffff);
1494N/A
1494N/A I915_WRITE(GTIIR, I915_READ(GTIIR));
1494N/A I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
1494N/A
1494N/A gt_irqs = GT_RENDER_USER_INTERRUPT | GT_BSD_USER_INTERRUPT |
1494N/A GT_BLT_USER_INTERRUPT;
1494N/A I915_WRITE(GTIER, gt_irqs);
1494N/A POSTING_READ(GTIER);
1494N/A
1494N/A /* ack & enable invalid PTE error interrupts */
1494N/A#if 0 /* FIXME: add support to irq handler for checking these bits */
1494N/A I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
1494N/A I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK);
1494N/A#endif
1494N/A
1494N/A I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
1494N/A
1494N/A return 0;
1494N/A}
1494N/A
1494N/Astatic void valleyview_irq_uninstall(struct drm_device *dev)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A int pipe;
1494N/A
1494N/A if (!dev_priv)
1494N/A return;
1494N/A
1494N/A del_timer_sync(&dev_priv->hotplug_reenable_timer);
1494N/A
1494N/A for_each_pipe(pipe)
1494N/A I915_WRITE(PIPESTAT(pipe), 0xffff);
1494N/A
1494N/A I915_WRITE(HWSTAM, 0xffffffff);
1494N/A I915_WRITE(PORT_HOTPLUG_EN, 0);
1494N/A I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
1494N/A for_each_pipe(pipe)
1494N/A I915_WRITE(PIPESTAT(pipe), 0xffff);
1494N/A I915_WRITE(VLV_IIR, 0xffffffff);
1494N/A I915_WRITE(VLV_IMR, 0xffffffff);
1494N/A I915_WRITE(VLV_IER, 0x0);
1494N/A POSTING_READ(VLV_IER);
1494N/A}
1494N/A
1494N/Astatic void ironlake_irq_uninstall(struct drm_device *dev)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A
1494N/A if (!dev_priv)
1494N/A return;
1494N/A
1494N/A del_timer_sync(&dev_priv->hotplug_reenable_timer);
1494N/A
1494N/A I915_WRITE(HWSTAM, 0xffffffff);
1494N/A
1494N/A I915_WRITE(DEIMR, 0xffffffff);
1494N/A I915_WRITE(DEIER, 0x0);
1494N/A I915_WRITE(DEIIR, I915_READ(DEIIR));
1494N/A if (IS_GEN7(dev))
1494N/A I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
1494N/A
1494N/A I915_WRITE(GTIMR, 0xffffffff);
1494N/A I915_WRITE(GTIER, 0x0);
1494N/A I915_WRITE(GTIIR, I915_READ(GTIIR));
1494N/A
1494N/A if (HAS_PCH_NOP(dev))
1494N/A return;
1494N/A
1494N/A I915_WRITE(SDEIMR, 0xffffffff);
1494N/A I915_WRITE(SDEIER, 0x0);
1494N/A I915_WRITE(SDEIIR, I915_READ(SDEIIR));
1494N/A if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
1494N/A I915_WRITE(SERR_INT, I915_READ(SERR_INT));
1494N/A}
1494N/A
1494N/Astatic void i8xx_irq_preinstall(struct drm_device * dev)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A int pipe;
1494N/A
1494N/A atomic_set(&dev_priv->irq_received, 0);
1494N/A
1494N/A for_each_pipe(pipe)
1494N/A I915_WRITE(PIPESTAT(pipe), 0);
1494N/A I915_WRITE16(IMR, 0xffff);
1494N/A I915_WRITE16(IER, 0x0);
1494N/A POSTING_READ16(IER);
1494N/A}
1494N/A
1494N/Astatic int i8xx_irq_postinstall(struct drm_device *dev)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A
1494N/A I915_WRITE16(EMR,
1494N/A ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
1494N/A
1494N/A /* Unmask the interrupts that we always want on. */
1494N/A /* LINTED */
1494N/A dev_priv->irq_mask =
1494N/A ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
1494N/A I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
1494N/A I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
1494N/A I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
1494N/A I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
1494N/A I915_WRITE16(IMR, dev_priv->irq_mask);
1494N/A
1494N/A I915_WRITE16(IER,
1494N/A I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
1494N/A I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
1494N/A I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
1494N/A I915_USER_INTERRUPT);
1494N/A POSTING_READ16(IER);
1494N/A
1494N/A return 0;
1494N/A}
1494N/A
1494N/A/*
1494N/A * Returns true when a page flip has completed.
1494N/A */
1494N/Astatic bool i8xx_handle_vblank(struct drm_device *dev,
1494N/A int pipe, u16 iir)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = dev->dev_private;
1494N/A u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(pipe);
1494N/A
1494N/A if (!drm_handle_vblank(dev, pipe))
1494N/A return false;
1494N/A
1494N/A if ((iir & flip_pending) == 0)
1494N/A return false;
1494N/A
1494N/A intel_prepare_page_flip(dev, pipe);
1494N/A
1494N/A /* We detect FlipDone by looking for the change in PendingFlip from '1'
1494N/A * to '0' on the following vblank, i.e. IIR has the Pendingflip
1494N/A * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
1494N/A * the flip is completed (no longer pending). Since this doesn't raise
1494N/A * an interrupt per se, we watch for the change at vblank.
1494N/A */
1494N/A if (I915_READ16(ISR) & flip_pending)
1494N/A return false;
1494N/A
1494N/A intel_finish_page_flip(dev, pipe);
1494N/A
1494N/A return true;
1494N/A}
1494N/A
1494N/Astatic irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
1494N/A{
1494N/A /* LINTED */
1494N/A struct drm_device *dev = (struct drm_device *) arg;
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A u16 iir, new_iir;
1611N/A u32 pipe_stats[2] = { 0 };
1494N/A unsigned long irqflags;
1494N/A int pipe;
1494N/A u16 flip_mask =
1494N/A I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
1494N/A I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
1494N/A
1494N/A atomic_inc(&dev_priv->irq_received);
1494N/A
1494N/A iir = I915_READ16(IIR);
1494N/A if (iir == 0)
1494N/A return IRQ_NONE;
1494N/A
1494N/A while (iir & ~flip_mask) {
1494N/A /* Can't rely on pipestat interrupt bit in iir as it might
1494N/A * have been cleared after the pipestat interrupt was received.
1494N/A * It doesn't set the bit in iir again, but it still produces
1494N/A * interrupts (for non-MSI).
1494N/A */
1494N/A spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
1494N/A if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
1494N/A i915_handle_error(dev, false);
1494N/A
1494N/A for_each_pipe(pipe) {
1494N/A int reg = PIPESTAT(pipe);
1494N/A pipe_stats[pipe] = I915_READ(reg);
1494N/A
1494N/A /*
1494N/A * Clear the PIPE*STAT regs before the IIR
1494N/A */
1494N/A if (pipe_stats[pipe] & 0x8000ffff) {
1494N/A if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1494N/A DRM_DEBUG_DRIVER("pipe %c underrun\n",
1494N/A pipe_name(pipe));
1494N/A I915_WRITE(reg, pipe_stats[pipe]);
1494N/A }
1494N/A }
1494N/A spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1494N/A
1494N/A I915_WRITE16(IIR, iir & ~flip_mask);
1494N/A new_iir = I915_READ16(IIR); /* Flush posted writes */
1494N/A
1494N/A i915_update_dri1_breadcrumb(dev);
1494N/A
1494N/A if (iir & I915_USER_INTERRUPT)
1494N/A notify_ring(dev, &dev_priv->ring[RCS]);
1494N/A
1494N/A if (pipe_stats[0] & PIPE_VBLANK_INTERRUPT_STATUS &&
1494N/A i8xx_handle_vblank(dev, 0, iir))
1494N/A flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(0);
1494N/A
1494N/A if (pipe_stats[1] & PIPE_VBLANK_INTERRUPT_STATUS &&
1494N/A i8xx_handle_vblank(dev, 1, iir))
1494N/A flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(1);
1494N/A
1494N/A iir = new_iir;
1494N/A }
1494N/A
1494N/A return IRQ_HANDLED;
1494N/A}
1494N/A
1494N/Astatic void i8xx_irq_uninstall(struct drm_device * dev)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A int pipe;
1494N/A
1494N/A for_each_pipe(pipe) {
1494N/A /* Clear enable bits; then clear status bits */
1494N/A I915_WRITE(PIPESTAT(pipe), 0);
1494N/A I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
1494N/A }
1494N/A I915_WRITE16(IMR, 0xffff);
1494N/A I915_WRITE16(IER, 0x0);
1494N/A I915_WRITE16(IIR, I915_READ16(IIR));
1494N/A}
1494N/A
1494N/Astatic void i915_irq_preinstall(struct drm_device * dev)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A int pipe;
1494N/A
1494N/A atomic_set(&dev_priv->irq_received, 0);
1494N/A
1494N/A if (I915_HAS_HOTPLUG(dev)) {
1494N/A I915_WRITE(PORT_HOTPLUG_EN, 0);
1494N/A I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
1494N/A }
1494N/A
1494N/A I915_WRITE16(HWSTAM, 0xeffe);
1494N/A for_each_pipe(pipe)
1494N/A I915_WRITE(PIPESTAT(pipe), 0);
1494N/A I915_WRITE(IMR, 0xffffffff);
1494N/A I915_WRITE(IER, 0x0);
1494N/A POSTING_READ(IER);
1494N/A}
1494N/A
1494N/Astatic int i915_irq_postinstall(struct drm_device *dev)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A u32 enable_mask;
1494N/A
1494N/A I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
1494N/A
1494N/A /* Unmask the interrupts that we always want on. */
1494N/A /* LINTED */
1494N/A dev_priv->irq_mask =
1494N/A ~(I915_ASLE_INTERRUPT |
1494N/A I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
1494N/A I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
1494N/A I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
1494N/A I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
1494N/A I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
1494N/A
1494N/A enable_mask =
1494N/A I915_ASLE_INTERRUPT |
1494N/A I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
1494N/A I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
1494N/A I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
1494N/A I915_USER_INTERRUPT;
1494N/A
1494N/A if (I915_HAS_HOTPLUG(dev)) {
1494N/A I915_WRITE(PORT_HOTPLUG_EN, 0);
1494N/A POSTING_READ(PORT_HOTPLUG_EN);
1494N/A
1494N/A /* Enable in IER... */
1494N/A enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
1494N/A /* and unmask in IMR */
1494N/A dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
1494N/A }
1494N/A
1494N/A I915_WRITE(IMR, dev_priv->irq_mask);
1494N/A I915_WRITE(IER, enable_mask);
1494N/A POSTING_READ(IER);
1494N/A
1494N/A
1494N/A return 0;
1494N/A}
1494N/A
1494N/A/*
1494N/A * Returns true when a page flip has completed.
1494N/A */
1494N/Astatic bool i915_handle_vblank(struct drm_device *dev,
1494N/A int plane, int pipe, u32 iir)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = dev->dev_private;
1494N/A u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
1494N/A
1494N/A if (!drm_handle_vblank(dev, pipe))
1494N/A return false;
1494N/A
1494N/A if ((iir & flip_pending) == 0)
1494N/A return false;
1494N/A
1494N/A intel_prepare_page_flip(dev, plane);
1494N/A
1494N/A /* We detect FlipDone by looking for the change in PendingFlip from '1'
1494N/A * to '0' on the following vblank, i.e. IIR has the Pendingflip
1494N/A * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
1494N/A * the flip is completed (no longer pending). Since this doesn't raise
1494N/A * an interrupt per se, we watch for the change at vblank.
1494N/A */
1494N/A if (I915_READ(ISR) & flip_pending)
1494N/A return false;
1494N/A
1494N/A intel_finish_page_flip(dev, pipe);
1494N/A
1494N/A return true;
1494N/A}
1494N/A
1494N/Astatic irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
1494N/A{
1494N/A /* LINTED */
1494N/A struct drm_device *dev = (struct drm_device *) arg;
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1611N/A u32 iir, new_iir, pipe_stats[I915_MAX_PIPES] = { 0 };
1494N/A unsigned long irqflags;
1494N/A u32 flip_mask =
1494N/A I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
1494N/A I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
1494N/A int pipe, ret = IRQ_NONE;
1494N/A
1494N/A atomic_inc(&dev_priv->irq_received);
1494N/A
1494N/A iir = I915_READ(IIR);
1494N/A do {
1494N/A bool irq_received = (iir & ~flip_mask) != 0;
1494N/A
1494N/A /* Can't rely on pipestat interrupt bit in iir as it might
1494N/A * have been cleared after the pipestat interrupt was received.
1494N/A * It doesn't set the bit in iir again, but it still produces
1494N/A * interrupts (for non-MSI).
1494N/A */
1494N/A spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
1494N/A if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
1494N/A i915_handle_error(dev, false);
1494N/A
1494N/A for_each_pipe(pipe) {
1494N/A int reg = PIPESTAT(pipe);
1494N/A pipe_stats[pipe] = I915_READ(reg);
1494N/A
1494N/A /* Clear the PIPE*STAT regs before the IIR */
1494N/A if (pipe_stats[pipe] & 0x8000ffff) {
1494N/A if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1494N/A DRM_DEBUG_DRIVER("pipe %c underrun\n",
1494N/A pipe_name(pipe));
1494N/A I915_WRITE(reg, pipe_stats[pipe]);
1494N/A irq_received = true;
1494N/A }
1494N/A }
1494N/A spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1494N/A
1494N/A if (!irq_received)
1494N/A break;
1494N/A
1494N/A /* Consume port. Then clear IIR or we'll miss events */
1494N/A if ((I915_HAS_HOTPLUG(dev)) &&
1494N/A (iir & I915_DISPLAY_PORT_INTERRUPT)) {
1494N/A u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
1494N/A u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
1494N/A
1494N/A DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
1494N/A hotplug_status);
1494N/A
1494N/A intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
1494N/A
1494N/A I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1494N/A POSTING_READ(PORT_HOTPLUG_STAT);
1494N/A }
1494N/A
1494N/A I915_WRITE(IIR, iir & ~flip_mask);
1494N/A new_iir = I915_READ(IIR); /* Flush posted writes */
1494N/A
1494N/A if (iir & I915_USER_INTERRUPT)
1494N/A notify_ring(dev, &dev_priv->ring[RCS]);
1494N/A
1494N/A for_each_pipe(pipe) {
1494N/A int plane = pipe;
1494N/A if (IS_MOBILE(dev))
1494N/A plane = !plane;
1494N/A
1494N/A if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
1494N/A i915_handle_vblank(dev, plane, pipe, iir))
1494N/A flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
1494N/A
1494N/A }
1494N/A
1494N/A
1494N/A /* With MSI, interrupts are only generated when iir
1494N/A * transitions from zero to nonzero. If another bit got
1494N/A * set while we were handling the existing iir bits, then
1494N/A * we would never get another interrupt.
1494N/A *
1494N/A * This is fine on non-MSI as well, as if we hit this path
1494N/A * we avoid exiting the interrupt handler only to generate
1494N/A * another one.
1494N/A *
1494N/A * Note that for MSI this could cause a stray interrupt report
1494N/A * if an interrupt landed in the time between writing IIR and
1494N/A * the posting read. This should be rare enough to never
1494N/A * trigger the 99% of 100,000 interrupts test for disabling
1494N/A * stray interrupts.
1494N/A */
1494N/A ret = IRQ_HANDLED;
1494N/A iir = new_iir;
1494N/A } while (iir & ~flip_mask);
1494N/A
1494N/A i915_update_dri1_breadcrumb(dev);
1494N/A
1494N/A return ret;
1494N/A}
1494N/A
1494N/Astatic void i915_irq_uninstall(struct drm_device * dev)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A int pipe;
1494N/A
1494N/A del_timer_sync(&dev_priv->hotplug_reenable_timer);
1494N/A
1494N/A if (I915_HAS_HOTPLUG(dev)) {
1494N/A I915_WRITE(PORT_HOTPLUG_EN, 0);
1494N/A I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
1494N/A }
1494N/A
1494N/A I915_WRITE16(HWSTAM, 0xffff);
1494N/A for_each_pipe(pipe) {
1494N/A /* Clear enable bits; then clear status bits */
1494N/A I915_WRITE(PIPESTAT(pipe), 0);
1494N/A I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
1494N/A }
1494N/A I915_WRITE(IMR, 0xffffffff);
1494N/A I915_WRITE(IER, 0x0);
1494N/A
1494N/A I915_WRITE(IIR, I915_READ(IIR));
1494N/A}
1494N/A
1494N/Astatic void i965_irq_preinstall(struct drm_device * dev)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A int pipe;
1494N/A
1494N/A atomic_set(&dev_priv->irq_received, 0);
1494N/A
1494N/A I915_WRITE(PORT_HOTPLUG_EN, 0);
1494N/A I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
1494N/A
1494N/A I915_WRITE(HWSTAM, 0xeffe);
1494N/A for_each_pipe(pipe)
1494N/A I915_WRITE(PIPESTAT(pipe), 0);
1494N/A I915_WRITE(IMR, 0xffffffff);
1494N/A I915_WRITE(IER, 0x0);
1494N/A POSTING_READ(IER);
1494N/A}
1494N/A
1494N/Astatic int i965_irq_postinstall(struct drm_device *dev)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A u32 enable_mask;
1494N/A u32 error_mask;
1494N/A
1494N/A /* Unmask the interrupts that we always want on. */
1494N/A /* LINTED */
1494N/A dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
1494N/A I915_DISPLAY_PORT_INTERRUPT |
1494N/A I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
1494N/A I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
1494N/A I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
1494N/A I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
1494N/A I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
1494N/A
1494N/A enable_mask = ~dev_priv->irq_mask;
1494N/A enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
1494N/A I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
1494N/A enable_mask |= I915_USER_INTERRUPT;
1494N/A
1494N/A if (IS_G4X(dev))
1494N/A enable_mask |= I915_BSD_USER_INTERRUPT;
1494N/A
1494N/A i915_enable_pipestat(dev_priv, 0, PIPE_GMBUS_EVENT_ENABLE);
1494N/A
1494N/A /*
1494N/A * Enable some error detection, note the instruction error mask
1494N/A * bit is reserved, so we leave it masked.
1494N/A */
1494N/A if (IS_G4X(dev)) {
1494N/A /* LINTED */
1494N/A error_mask = ~(GM45_ERROR_PAGE_TABLE |
1494N/A GM45_ERROR_MEM_PRIV |
1494N/A GM45_ERROR_CP_PRIV |
1494N/A I915_ERROR_MEMORY_REFRESH);
1494N/A } else {
1494N/A /* LINTED */
1494N/A error_mask = ~(I915_ERROR_PAGE_TABLE |
1494N/A I915_ERROR_MEMORY_REFRESH);
1494N/A }
1494N/A I915_WRITE(EMR, error_mask);
1494N/A
1494N/A I915_WRITE(IMR, dev_priv->irq_mask);
1494N/A I915_WRITE(IER, enable_mask);
1494N/A POSTING_READ(IER);
1494N/A
1494N/A I915_WRITE(PORT_HOTPLUG_EN, 0);
1494N/A POSTING_READ(PORT_HOTPLUG_EN);
1494N/A
1494N/A
1494N/A return 0;
1494N/A}
1494N/A
1494N/Astatic void i915_hpd_irq_setup(struct drm_device *dev)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A struct drm_mode_config *mode_config = &dev->mode_config;
1494N/A struct intel_encoder *intel_encoder;
1494N/A u32 hotplug_en;
1494N/A
1494N/A assert_spin_locked(&dev_priv->irq_lock);
1494N/A
1494N/A if (I915_HAS_HOTPLUG(dev)) {
1494N/A hotplug_en = I915_READ(PORT_HOTPLUG_EN);
1494N/A hotplug_en &= ~HOTPLUG_INT_EN_MASK;
1494N/A /* Note HDMI and DP share hotplug bits */
1494N/A /* enable bits are the same for all generations */
1494N/A list_for_each_entry(intel_encoder, struct intel_encoder, &mode_config->encoder_list, base.head)
1494N/A if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
1494N/A hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin];
1494N/A /* Programming the CRT detection parameters tends
1494N/A to generate a spurious hotplug event about three
1494N/A seconds later. So just do it once.
1494N/A */
1494N/A if (IS_G4X(dev))
1494N/A hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
1494N/A hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK;
1494N/A hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
1494N/A
1494N/A /* Ignore TV since it's buggy */
1494N/A I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
1494N/A }
1494N/A}
1494N/A
1494N/Astatic irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
1494N/A{
1494N/A /* LINTED */
1494N/A struct drm_device *dev = (struct drm_device *) arg;
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A u32 iir, new_iir;
1611N/A u32 pipe_stats[I915_MAX_PIPES] = { 0 };
1494N/A unsigned long irqflags;
1494N/A int irq_received;
1494N/A int ret = IRQ_NONE, pipe;
1494N/A u32 flip_mask =
1494N/A I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
1494N/A I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
1494N/A
1494N/A atomic_inc(&dev_priv->irq_received);
1494N/A
1494N/A iir = I915_READ(IIR);
1494N/A
1494N/A for (;;) {
1494N/A
1494N/A irq_received = (iir & ~flip_mask) != 0;
1494N/A
1494N/A /* Can't rely on pipestat interrupt bit in iir as it might
1494N/A * have been cleared after the pipestat interrupt was received.
1494N/A * It doesn't set the bit in iir again, but it still produces
1494N/A * interrupts (for non-MSI).
1494N/A */
1494N/A spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
1494N/A if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
1494N/A i915_handle_error(dev, false);
1494N/A
1494N/A for_each_pipe(pipe) {
1494N/A int reg = PIPESTAT(pipe);
1494N/A pipe_stats[pipe] = I915_READ(reg);
1494N/A
1494N/A /*
1494N/A * Clear the PIPE*STAT regs before the IIR
1494N/A */
1494N/A if (pipe_stats[pipe] & 0x8000ffff) {
1494N/A if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1494N/A DRM_DEBUG_DRIVER("pipe %c underrun\n",
1494N/A pipe_name(pipe));
1494N/A I915_WRITE(reg, pipe_stats[pipe]);
1494N/A irq_received = 1;
1494N/A }
1494N/A }
1494N/A spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1494N/A
1494N/A if (!irq_received)
1494N/A break;
1494N/A
1494N/A ret = IRQ_HANDLED;
1494N/A
1494N/A /* Consume port. Then clear IIR or we'll miss events */
1494N/A if (iir & I915_DISPLAY_PORT_INTERRUPT) {
1494N/A u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
1494N/A u32 hotplug_trigger = hotplug_status & (IS_G4X(dev) ?
1494N/A HOTPLUG_INT_STATUS_G4X :
1494N/A HOTPLUG_INT_STATUS_I915);
1494N/A
1494N/A DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
1494N/A hotplug_status);
1494N/A
1494N/A intel_hpd_irq_handler(dev, hotplug_trigger,
1494N/A IS_G4X(dev) ? hpd_status_gen4 : hpd_status_i915);
1494N/A
1494N/A I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1494N/A I915_READ(PORT_HOTPLUG_STAT);
1494N/A }
1494N/A
1494N/A I915_WRITE(IIR, iir & ~flip_mask);
1494N/A new_iir = I915_READ(IIR); /* Flush posted writes */
1494N/A
1494N/A if (iir & I915_USER_INTERRUPT)
1494N/A notify_ring(dev, &dev_priv->ring[RCS]);
1494N/A if (iir & I915_BSD_USER_INTERRUPT)
1494N/A notify_ring(dev, &dev_priv->ring[VCS]);
1494N/A
1494N/A for_each_pipe(pipe) {
1494N/A if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
1494N/A i915_handle_vblank(dev, pipe, pipe, iir))
1494N/A flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
1494N/A
1494N/A }
1494N/A
1494N/A
1494N/A
1494N/A /* With MSI, interrupts are only generated when iir
1494N/A * transitions from zero to nonzero. If another bit got
1494N/A * set while we were handling the existing iir bits, then
1494N/A * we would never get another interrupt.
1494N/A *
1494N/A * This is fine on non-MSI as well, as if we hit this path
1494N/A * we avoid exiting the interrupt handler only to generate
1494N/A * another one.
1494N/A *
1494N/A * Note that for MSI this could cause a stray interrupt report
1494N/A * if an interrupt landed in the time between writing IIR and
1494N/A * the posting read. This should be rare enough to never
1494N/A * trigger the 99% of 100,000 interrupts test for disabling
1494N/A * stray interrupts.
1494N/A */
1494N/A iir = new_iir;
1494N/A }
1494N/A
1494N/A i915_update_dri1_breadcrumb(dev);
1494N/A
1494N/A return ret;
1494N/A}
1494N/A
1494N/Astatic void i965_irq_uninstall(struct drm_device * dev)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1494N/A int pipe;
1494N/A
1494N/A if (!dev_priv)
1494N/A return;
1494N/A
1494N/A del_timer_sync(&dev_priv->hotplug_reenable_timer);
1494N/A
1494N/A I915_WRITE(PORT_HOTPLUG_EN, 0);
1494N/A I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
1494N/A
1494N/A I915_WRITE(HWSTAM, 0xffffffff);
1494N/A for_each_pipe(pipe)
1494N/A I915_WRITE(PIPESTAT(pipe), 0);
1494N/A I915_WRITE(IMR, 0xffffffff);
1494N/A I915_WRITE(IER, 0x0);
1494N/A
1494N/A for_each_pipe(pipe)
1494N/A I915_WRITE(PIPESTAT(pipe),
1494N/A I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
1494N/A I915_WRITE(IIR, I915_READ(IIR));
1494N/A}
1494N/A
1494N/Astatic void i915_reenable_hotplug_timer_func(void* data)
1494N/A{
1494N/A drm_i915_private_t *dev_priv = (drm_i915_private_t *)data;
1494N/A struct drm_device *dev = dev_priv->dev;
1494N/A struct drm_mode_config *mode_config = &dev->mode_config;
1494N/A unsigned long irqflags;
1494N/A int i;
1494N/A
1494N/A spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
1494N/A for (i = (HPD_NONE + 1); i < HPD_NUM_PINS; i++) {
1494N/A struct drm_connector *connector;
1494N/A
1494N/A if (dev_priv->hpd_stats[i].hpd_mark != HPD_DISABLED)
1494N/A continue;
1494N/A
1494N/A dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
1494N/A
1494N/A list_for_each_entry(connector, struct drm_connector, &mode_config->connector_list, head) {
1494N/A struct intel_connector *intel_connector = to_intel_connector(connector);
1494N/A
1494N/A if (intel_connector->encoder->hpd_pin == i) {
1494N/A if (connector->polled != intel_connector->polled)
1494N/A DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n",
1494N/A drm_get_connector_name(connector));
1494N/A connector->polled = intel_connector->polled;
1494N/A if (!connector->polled)
1494N/A connector->polled = DRM_CONNECTOR_POLL_HPD;
1494N/A }
1494N/A }
1494N/A }
1494N/A if (dev_priv->display.hpd_irq_setup)
1494N/A dev_priv->display.hpd_irq_setup(dev);
1494N/A spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1494N/A}
1494N/A
1494N/Avoid intel_irq_init(struct drm_device *dev)
1494N/A{
1494N/A struct drm_i915_private *dev_priv = dev->dev_private;
1494N/A
1494N/A INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
1494N/A INIT_WORK(&dev_priv->gpu_error.work, i915_error_work_func);
1494N/A INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
1494N/A INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
1494N/A
1494N/A init_timer(&dev_priv->gpu_error.hangcheck_timer);
1494N/A setup_timer(&dev_priv->gpu_error.hangcheck_timer,
1494N/A i915_hangcheck_elapsed,
1494N/A (void *) dev);
1494N/A init_timer(&dev_priv->hotplug_reenable_timer);
1494N/A setup_timer(&dev_priv->hotplug_reenable_timer, i915_reenable_hotplug_timer_func,
1494N/A (void *) dev_priv);
1494N/A
1494N/A
1494N/A dev->driver->get_vblank_counter = i915_get_vblank_counter;
1494N/A dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
1494N/A if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
1494N/A dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
1494N/A dev->driver->get_vblank_counter = gm45_get_vblank_counter;
1494N/A }
1494N/A
1494N/A if (drm_core_check_feature(dev, DRIVER_MODESET))
1494N/A dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
1494N/A else
1494N/A dev->driver->get_vblank_timestamp = NULL;
1494N/A dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
1494N/A
1494N/A if (IS_VALLEYVIEW(dev)) {
1494N/A dev->driver->irq_handler = valleyview_irq_handler;
1494N/A dev->driver->irq_preinstall = valleyview_irq_preinstall;
1494N/A dev->driver->irq_postinstall = valleyview_irq_postinstall;
1494N/A dev->driver->irq_uninstall = valleyview_irq_uninstall;
1494N/A dev->driver->enable_vblank = valleyview_enable_vblank;
1494N/A dev->driver->disable_vblank = valleyview_disable_vblank;
1494N/A dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
1494N/A } else if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) {
1494N/A /* Share pre & uninstall handlers with ILK/SNB */
1494N/A dev->driver->irq_handler = ivybridge_irq_handler;
1494N/A dev->driver->irq_preinstall = ivybridge_irq_preinstall;
1494N/A dev->driver->irq_postinstall = ivybridge_irq_postinstall;
1494N/A dev->driver->irq_uninstall = ironlake_irq_uninstall;
1494N/A dev->driver->enable_vblank = ivybridge_enable_vblank;
1494N/A dev->driver->disable_vblank = ivybridge_disable_vblank;
1494N/A dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
1494N/A } else if (HAS_PCH_SPLIT(dev)) {
1494N/A dev->driver->irq_handler = ironlake_irq_handler;
1494N/A dev->driver->irq_preinstall = ironlake_irq_preinstall;
1494N/A dev->driver->irq_postinstall = ironlake_irq_postinstall;
1494N/A dev->driver->irq_uninstall = ironlake_irq_uninstall;
1494N/A dev->driver->enable_vblank = ironlake_enable_vblank;
1494N/A dev->driver->disable_vblank = ironlake_disable_vblank;
1494N/A dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
1494N/A } else {
1494N/A if (INTEL_INFO(dev)->gen == 2) {
1494N/A dev->driver->irq_preinstall = i8xx_irq_preinstall;
1494N/A dev->driver->irq_postinstall = i8xx_irq_postinstall;
1494N/A dev->driver->irq_handler = i8xx_irq_handler;
1494N/A dev->driver->irq_uninstall = i8xx_irq_uninstall;
1494N/A } else if (INTEL_INFO(dev)->gen == 3) {
1494N/A dev->driver->irq_preinstall = i915_irq_preinstall;
1494N/A dev->driver->irq_postinstall = i915_irq_postinstall;
1494N/A dev->driver->irq_uninstall = i915_irq_uninstall;
1494N/A dev->driver->irq_handler = i915_irq_handler;
1494N/A dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
1494N/A } else {
1494N/A dev->driver->irq_preinstall = i965_irq_preinstall;
1494N/A dev->driver->irq_postinstall = i965_irq_postinstall;
1494N/A dev->driver->irq_uninstall = i965_irq_uninstall;
1494N/A dev->driver->irq_handler = i965_irq_handler;
1494N/A dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
1494N/A }
1494N/A dev->driver->enable_vblank = i915_enable_vblank;
1494N/A dev->driver->disable_vblank = i915_disable_vblank;
1494N/A }
1494N/A}
1494N/A
1494N/Avoid intel_hpd_init(struct drm_device *dev)
1494N/A{
1494N/A struct drm_i915_private *dev_priv = dev->dev_private;
1494N/A struct drm_mode_config *mode_config = &dev->mode_config;
1494N/A struct drm_connector *connector;
1494N/A unsigned long irqflags;
1494N/A int i;
1494N/A
1494N/A for (i = 1; i < HPD_NUM_PINS; i++) {
1494N/A dev_priv->hpd_stats[i].hpd_cnt = 0;
1494N/A dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
1494N/A }
1494N/A list_for_each_entry(connector, struct drm_connector, &mode_config->connector_list, head) {
1494N/A struct intel_connector *intel_connector = to_intel_connector(connector);
1494N/A connector->polled = intel_connector->polled;
1494N/A if (!connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE)
1494N/A connector->polled = DRM_CONNECTOR_POLL_HPD;
1494N/A }
1494N/A
1494N/A /* Interrupt setup is already guaranteed to be single-threaded, this is
1494N/A * just to make the assert_spin_locked checks happy. */
1494N/A spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
1494N/A if (dev_priv->display.hpd_irq_setup)
1494N/A dev_priv->display.hpd_irq_setup(dev);
1494N/A spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1494N/A}