Merge tag 'v3.10.56' into update
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / gpu / drm / i915 / intel_ringbuffer.c
index 1d5d613eb6be4d21affe491af19a3eaba99325ee..4605c3877c955cc7374583df3b37784e1cd34056 100644 (file)
@@ -396,6 +396,9 @@ static int init_ring_common(struct intel_ring_buffer *ring)
                }
        }
 
+       /* Enforce ordering by reading HEAD register back */
+       I915_READ_HEAD(ring);
+
        /* Initialize the ring. This must happen _after_ we've cleared the ring
         * registers with the above sequence (the readback of the HEAD registers
         * also enforces ordering), otherwise the hw might lose the new ring
@@ -490,9 +493,6 @@ cleanup_pipe_control(struct intel_ring_buffer *ring)
        struct pipe_control *pc = ring->private;
        struct drm_i915_gem_object *obj;
 
-       if (!ring->private)
-               return;
-
        obj = pc->obj;
 
        kunmap(sg_page(obj->pages->sgl));
@@ -500,7 +500,6 @@ cleanup_pipe_control(struct intel_ring_buffer *ring)
        drm_gem_object_unreference(&obj->base);
 
        kfree(pc);
-       ring->private = NULL;
 }
 
 static int init_render_ring(struct intel_ring_buffer *ring)
@@ -571,7 +570,10 @@ static void render_ring_cleanup(struct intel_ring_buffer *ring)
        if (HAS_BROKEN_CS_TLB(dev))
                drm_gem_object_unreference(to_gem_object(ring->private));
 
-       cleanup_pipe_control(ring);
+       if (INTEL_INFO(dev)->gen >= 5)
+               cleanup_pipe_control(ring);
+
+       ring->private = NULL;
 }
 
 static void
@@ -908,6 +910,18 @@ void intel_ring_setup_status_page(struct intel_ring_buffer *ring)
 
        I915_WRITE(mmio, (u32)ring->status_page.gfx_addr);
        POSTING_READ(mmio);
+
+       /* Flush the TLB for this page */
+       if (INTEL_INFO(dev)->gen >= 6) {
+               u32 reg = RING_INSTPM(ring->mmio_base);
+               I915_WRITE(reg,
+                          _MASKED_BIT_ENABLE(INSTPM_TLB_INVALIDATE |
+                                             INSTPM_SYNC_FLUSH));
+               if (wait_for((I915_READ(reg) & INSTPM_SYNC_FLUSH) == 0,
+                            1000))
+                       DRM_ERROR("%s: wait for SyncFlush to complete for TLB invalidation timed out\n",
+                                 ring->name);
+       }
 }
 
 static int
@@ -1448,8 +1462,8 @@ intel_ring_alloc_seqno(struct intel_ring_buffer *ring)
        return i915_gem_get_seqno(ring->dev, &ring->outstanding_lazy_request);
 }
 
-static int __intel_ring_begin(struct intel_ring_buffer *ring,
-                             int bytes)
+static int __intel_ring_prepare(struct intel_ring_buffer *ring,
+                               int bytes)
 {
        int ret;
 
@@ -1465,7 +1479,6 @@ static int __intel_ring_begin(struct intel_ring_buffer *ring,
                        return ret;
        }
 
-       ring->space -= bytes;
        return 0;
 }
 
@@ -1480,12 +1493,17 @@ int intel_ring_begin(struct intel_ring_buffer *ring,
        if (ret)
                return ret;
 
+       ret = __intel_ring_prepare(ring, num_dwords * sizeof(uint32_t));
+       if (ret)
+               return ret;
+
        /* Preallocate the olr before touching the ring */
        ret = intel_ring_alloc_seqno(ring);
        if (ret)
                return ret;
 
-       return __intel_ring_begin(ring, num_dwords * sizeof(uint32_t));
+       ring->space -= num_dwords * sizeof(uint32_t);
+       return 0;
 }
 
 void intel_ring_init_seqno(struct intel_ring_buffer *ring, u32 seqno)