drm/i915: Pad ringbuffer with NOOPs before wrapping
authorChris Wilson <chris@chris-wilson.co.uk>
Sat, 5 Sep 2009 17:07:06 +0000 (18:07 +0100)
committerEric Anholt <eric@anholt.net>
Sun, 6 Sep 2009 18:29:06 +0000 (11:29 -0700)
According to the docs, the ringbuffer is not allowed to wrap in the middle
of an instruction.

G45 PRM, Vol 1b, p101:
  While the “free space” wrap may allow commands to be wrapped around the
  end of the Ring Buffer, the wrap should only occur between commands.
  Padding (with NOP) may be required to follow this restriction.

Do as commanded.

[Having seen bug reports where there is evidence of split commands, but
apparently the GPU has continued on merrily before a bizarre and untimely
death, this may or may not fix a few random hangs.]

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
CC: Eric Anholt <eric@anholt.net>
Signed-off-by: Eric Anholt <eric@anholt.net>
drivers/gpu/drm/i915/i915_debugfs.c
drivers/gpu/drm/i915/i915_dma.c
drivers/gpu/drm/i915/i915_drv.h
drivers/gpu/drm/i915/i915_gem.c

index 8f28325bc5efdfd97eebbed1e44020ecd208d00c..1e3bdcee863c65166dd64f7dadc898ee65c6b087 100644 (file)
@@ -333,15 +333,13 @@ static int i915_ringbuffer_info(struct seq_file *m, void *data)
        struct drm_info_node *node = (struct drm_info_node *) m->private;
        struct drm_device *dev = node->minor->dev;
        drm_i915_private_t *dev_priv = dev->dev_private;
-       unsigned int head, tail, mask;
+       unsigned int head, tail;
 
        head = I915_READ(PRB0_HEAD) & HEAD_ADDR;
        tail = I915_READ(PRB0_TAIL) & TAIL_ADDR;
-       mask = dev_priv->ring.tail_mask;
 
        seq_printf(m, "RingHead :  %08x\n", head);
        seq_printf(m, "RingTail :  %08x\n", tail);
-       seq_printf(m, "RingMask :  %08x\n", mask);
        seq_printf(m, "RingSize :  %08lx\n", dev_priv->ring.Size);
        seq_printf(m, "Acthd :     %08x\n", I915_READ(IS_I965G(dev) ? ACTHD_I965 : ACTHD));
 
index 50d1f782768cc99ffc1e3a844f74a4c7898fcfed..f135bdcc6d5be345969fa4e4b8ee2d2cd853b3f4 100644 (file)
@@ -80,6 +80,34 @@ int i915_wait_ring(struct drm_device * dev, int n, const char *caller)
        return -EBUSY;
 }
 
+/* As a ringbuffer is only allowed to wrap between instructions, fill
+ * the tail with NOOPs.
+ */
+int i915_wrap_ring(struct drm_device *dev)
+{
+       drm_i915_private_t *dev_priv = dev->dev_private;
+       volatile unsigned int *virt;
+       int rem;
+
+       rem = dev_priv->ring.Size - dev_priv->ring.tail;
+       if (dev_priv->ring.space < rem) {
+               int ret = i915_wait_ring(dev, rem, __func__);
+               if (ret)
+                       return ret;
+       }
+       dev_priv->ring.space -= rem;
+
+       virt = (unsigned int *)
+               (dev_priv->ring.virtual_start + dev_priv->ring.tail);
+       rem /= 4;
+       while (rem--)
+               *virt++ = MI_NOOP;
+
+       dev_priv->ring.tail = 0;
+
+       return 0;
+}
+
 /**
  * Sets up the hardware status page for devices that need a physical address
  * in the register.
@@ -200,7 +228,6 @@ static int i915_initialize(struct drm_device * dev, drm_i915_init_t * init)
                }
 
                dev_priv->ring.Size = init->ring_size;
-               dev_priv->ring.tail_mask = dev_priv->ring.Size - 1;
 
                dev_priv->ring.map.offset = init->ring_start;
                dev_priv->ring.map.size = init->ring_size;
index 76914ae65c3126e17929226d2a084b732c7cebdc..2d5bce643e6a1acc77cda7fcf971d186c6683563 100644 (file)
@@ -85,7 +85,6 @@ struct drm_i915_gem_phys_object {
 };
 
 typedef struct _drm_i915_ring_buffer {
-       int tail_mask;
        unsigned long Size;
        u8 *virtual_start;
        int head;
@@ -790,33 +789,32 @@ extern void intel_modeset_cleanup(struct drm_device *dev);
 
 #define I915_VERBOSE 0
 
-#define RING_LOCALS    unsigned int outring, ringmask, outcount; \
-                        volatile char *virt;
-
-#define BEGIN_LP_RING(n) do {                          \
-       if (I915_VERBOSE)                               \
-               DRM_DEBUG("BEGIN_LP_RING(%d)\n", (n));  \
-       if (dev_priv->ring.space < (n)*4)               \
-               i915_wait_ring(dev, (n)*4, __func__);           \
-       outcount = 0;                                   \
-       outring = dev_priv->ring.tail;                  \
-       ringmask = dev_priv->ring.tail_mask;            \
-       virt = dev_priv->ring.virtual_start;            \
+#define RING_LOCALS    volatile unsigned int *ring_virt__;
+
+#define BEGIN_LP_RING(n) do {                                          \
+       int bytes__ = 4*(n);                                            \
+       if (I915_VERBOSE) DRM_DEBUG("BEGIN_LP_RING(%d)\n", (n));        \
+       /* a wrap must occur between instructions so pad beforehand */  \
+       if (unlikely (dev_priv->ring.tail + bytes__ > dev_priv->ring.Size)) \
+               i915_wrap_ring(dev);                                    \
+       if (unlikely (dev_priv->ring.space < bytes__))                  \
+               i915_wait_ring(dev, bytes__, __func__);                 \
+       ring_virt__ = (unsigned int *)                                  \
+               (dev_priv->ring.virtual_start + dev_priv->ring.tail);   \
+       dev_priv->ring.tail += bytes__;                                 \
+       dev_priv->ring.tail &= dev_priv->ring.Size - 1;                 \
+       dev_priv->ring.space -= bytes__;                                \
 } while (0)
 
-#define OUT_RING(n) do {                                       \
+#define OUT_RING(n) do {                                               \
        if (I915_VERBOSE) DRM_DEBUG("   OUT_RING %x\n", (int)(n));      \
-       *(volatile unsigned int *)(virt + outring) = (n);       \
-        outcount++;                                            \
-       outring += 4;                                           \
-       outring &= ringmask;                                    \
+       *ring_virt__++ = (n);                                           \
 } while (0)
 
 #define ADVANCE_LP_RING() do {                                         \
-       if (I915_VERBOSE) DRM_DEBUG("ADVANCE_LP_RING %x\n", outring);   \
-       dev_priv->ring.tail = outring;                                  \
-       dev_priv->ring.space -= outcount * 4;                           \
-       I915_WRITE(PRB0_TAIL, outring);                 \
+       if (I915_VERBOSE)                                               \
+               DRM_DEBUG("ADVANCE_LP_RING %x\n", dev_priv->ring.tail); \
+       I915_WRITE(PRB0_TAIL, dev_priv->ring.tail);                     \
 } while(0)
 
 /**
@@ -839,6 +837,7 @@ extern void intel_modeset_cleanup(struct drm_device *dev);
 #define I915_GEM_HWS_INDEX             0x20
 #define I915_BREADCRUMB_INDEX          0x21
 
+extern int i915_wrap_ring(struct drm_device * dev);
 extern int i915_wait_ring(struct drm_device * dev, int n, const char *caller);
 
 #define IS_I830(dev) ((dev)->pci_device == 0x3577)
index 73b58193afed72d1e43338871731b04b259150b6..076752112a39059625901497842ecaf64514e9f0 100644 (file)
@@ -4099,7 +4099,6 @@ i915_gem_init_ringbuffer(struct drm_device *dev)
 
        /* Set up the kernel mapping for the ring. */
        ring->Size = obj->size;
-       ring->tail_mask = obj->size - 1;
 
        ring->map.offset = dev->agp->base + obj_priv->gtt_offset;
        ring->map.size = obj->size;