drm/i915: Share the computation of ring size for RING_CTL register
authorChris Wilson <chris@chris-wilson.co.uk>
Tue, 4 Oct 2016 20:11:25 +0000 (21:11 +0100)
committerChris Wilson <chris@chris-wilson.co.uk>
Wed, 5 Oct 2016 07:40:05 +0000 (08:40 +0100)
Since both legacy and execlists want to populate the RING_CTL register,
share the computation of the right bits for the ring->size. We can then
stop masking errors and explicitly forbid them during creation!

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Mika Kuoppala <mika.kuoppala@intel.com>
Reviewed-by: Mika Kuoppala <mika.kuoppala@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20161004201132.21801-1-chris@chris-wilson.co.uk
drivers/gpu/drm/i915/i915_reg.h
drivers/gpu/drm/i915/intel_lrc.c
drivers/gpu/drm/i915/intel_ringbuffer.c

index 8d44cee710f0cc998a69e2d3e2f939cca1db85ef..acc767a52d8e8f3b6966ffbff78c032cfd1bfbe3 100644 (file)
@@ -1605,6 +1605,7 @@ enum skl_disp_power_wells {
 #define RING_HEAD(base)                _MMIO((base)+0x34)
 #define RING_START(base)       _MMIO((base)+0x38)
 #define RING_CTL(base)         _MMIO((base)+0x3c)
+#define   RING_CTL_SIZE(size)  ((size) - PAGE_SIZE) /* in bytes -> pages */
 #define RING_SYNC_0(base)      _MMIO((base)+0x40)
 #define RING_SYNC_1(base)      _MMIO((base)+0x44)
 #define RING_SYNC_2(base)      _MMIO((base)+0x48)
index 2d8eb2eb2b72fb50b9f94cc762a1909f41f12271..5ede272eb4d27d8afd33e04a198e24e8683ee0c8 100644 (file)
@@ -1946,7 +1946,7 @@ populate_lr_context(struct i915_gem_context *ctx,
                       RING_START(engine->mmio_base), 0);
        ASSIGN_CTX_REG(reg_state, CTX_RING_BUFFER_CONTROL,
                       RING_CTL(engine->mmio_base),
-                      ((ring->size - PAGE_SIZE) & RING_NR_PAGES) | RING_VALID);
+                      RING_CTL_SIZE(ring->size) | RING_VALID);
        ASSIGN_CTX_REG(reg_state, CTX_BB_HEAD_U,
                       RING_BBADDR_UDW(engine->mmio_base), 0);
        ASSIGN_CTX_REG(reg_state, CTX_BB_HEAD_L,
index 67ea9dd5921e905d32557b01e20a1020360778a8..8206e2aa03c6bbd6bb5eb49a5a878f415d279e37 100644 (file)
@@ -585,9 +585,7 @@ static int init_ring_common(struct intel_engine_cs *engine)
        I915_WRITE_TAIL(engine, ring->tail);
        (void)I915_READ_TAIL(engine);
 
-       I915_WRITE_CTL(engine,
-                       ((ring->size - PAGE_SIZE) & RING_NR_PAGES)
-                       | RING_VALID);
+       I915_WRITE_CTL(engine, RING_CTL_SIZE(ring->size) | RING_VALID);
 
        /* If the head is still not zero, the ring is dead */
        if (intel_wait_for_register_fw(dev_priv, RING_CTL(engine->mmio_base),
@@ -1951,6 +1949,7 @@ intel_engine_create_ring(struct intel_engine_cs *engine, int size)
        struct i915_vma *vma;
 
        GEM_BUG_ON(!is_power_of_2(size));
+       GEM_BUG_ON(RING_CTL_SIZE(size) & ~RING_NR_PAGES);
 
        ring = kzalloc(sizeof(*ring), GFP_KERNEL);
        if (!ring)