@@ -1226,8 +1226,7 @@ static int i915_gen6_forcewake_count_info(struct seq_file *m, void *data)
struct drm_device *dev = node->minor->dev;
struct drm_i915_private *dev_priv = dev->dev_private;
- seq_printf(m, "forcewake count = %d\n",
- atomic_read(&dev_priv->forcewake_count));
+ seq_printf(m, "forcewake count = %d\n", dev_priv->forcewake_count);
return 0;
}
@@ -2063,6 +2063,7 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)
spin_lock_init(&dev_priv->irq_lock);
spin_lock_init(&dev_priv->error_lock);
spin_lock_init(&dev_priv->rps_lock);
+ spin_lock_init(&dev_priv->forcewake_lock);
if (IS_MOBILE(dev) || !IS_GEN2(dev))
dev_priv->num_pipe = 2;
@@ -319,11 +319,14 @@ static void __gen6_gt_force_wake_get(struct drm_i915_private *dev_priv)
*/
void gen6_gt_force_wake_get(struct drm_i915_private *dev_priv)
{
- WARN_ON(!mutex_is_locked(&dev_priv->dev->struct_mutex));
+ unsigned long flags;
- /* Forcewake is atomic in case we get in here without the lock */
- if (atomic_add_return(1, &dev_priv->forcewake_count) == 1)
+ spin_lock_irqsave(&dev_priv->forcewake_lock, flags);
+
+ if (dev_priv->forcewake_count++ == 0)
__gen6_gt_force_wake_get(dev_priv);
+
+ spin_unlock_irqrestore(&dev_priv->forcewake_lock, flags);
}
static void __gen6_gt_force_wake_put(struct drm_i915_private *dev_priv)
@@ -337,10 +340,14 @@ static void __gen6_gt_force_wake_put(struct drm_i915_private *dev_priv)
*/
void gen6_gt_force_wake_put(struct drm_i915_private *dev_priv)
{
- WARN_ON(!mutex_is_locked(&dev_priv->dev->struct_mutex));
+ unsigned long flags;
- if (atomic_dec_and_test(&dev_priv->forcewake_count))
+ spin_lock_irqsave(&dev_priv->forcewake_lock, flags);
+
+ if (--dev_priv->forcewake_count == 0)
__gen6_gt_force_wake_put(dev_priv);
+
+ spin_unlock_irqrestore(&dev_priv->forcewake_lock, flags);
}
void __gen6_gt_wait_for_fifo(struct drm_i915_private *dev_priv)
@@ -717,7 +717,8 @@ typedef struct drm_i915_private {
struct drm_property *broadcast_rgb_property;
- atomic_t forcewake_count;
+ int forcewake_count;
+ spinlock_t forcewake_lock;
} drm_i915_private_t;
enum i915_cache_level {
We have forcewake in the interrupt handler in the following commit, so we have to use a spinlock instead of a mutex. Signed-off-by: Eric Anholt <eric@anholt.net> --- drivers/gpu/drm/i915/i915_debugfs.c | 3 +-- drivers/gpu/drm/i915/i915_dma.c | 1 + drivers/gpu/drm/i915/i915_drv.c | 17 ++++++++++++----- drivers/gpu/drm/i915/i915_drv.h | 3 ++- 4 files changed, 16 insertions(+), 8 deletions(-)