From: Oscar Mateo <oscar.mateo@xxxxxxxxx> Thanks to the previous functions and intel_ringbuffer_get(), every function that needs to be context-aware can get the ringbuffer from the appropriate place. Others (either pre-GEN8 or that clearly manipulate the rings's default ringbuffer) get it directly from the engine. Signed-off-by: Oscar Mateo <oscar.mateo@xxxxxxxxx> --- drivers/gpu/drm/i915/i915_dma.c | 2 +- drivers/gpu/drm/i915/i915_gem.c | 6 +- drivers/gpu/drm/i915/i915_gem_execbuffer.c | 18 +++--- drivers/gpu/drm/i915/i915_gpu_error.c | 6 +- drivers/gpu/drm/i915/i915_irq.c | 2 +- drivers/gpu/drm/i915/intel_ringbuffer.c | 92 +++++++++++++++--------------- drivers/gpu/drm/i915/intel_ringbuffer.h | 13 ++--- 7 files changed, 70 insertions(+), 69 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c index 166fbdf..7bdb9be 100644 --- a/drivers/gpu/drm/i915/i915_dma.c +++ b/drivers/gpu/drm/i915/i915_dma.c @@ -242,7 +242,7 @@ static int i915_dma_resume(struct drm_device * dev) DRM_DEBUG_DRIVER("%s\n", __func__); - if (__get_ringbuf(ring)->virtual_start == NULL) { + if (ring->default_ringbuf.virtual_start == NULL) { DRM_ERROR("can not ioremap virtual address for" " ring buffer\n"); return -ENOMEM; diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index 26bd68f..4a22560 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -2481,6 +2481,7 @@ i915_gem_retire_requests_ring(struct intel_engine *ring) while (!list_empty(&ring->request_list)) { struct drm_i915_gem_request *request; + struct intel_ringbuffer *ringbuf; request = list_first_entry(&ring->request_list, struct drm_i915_gem_request, @@ -2490,12 +2491,15 @@ i915_gem_retire_requests_ring(struct intel_engine *ring) break; trace_i915_gem_request_retire(ring, request->seqno); + + ringbuf = intel_ringbuffer_get(ring, request->ctx); + /* We know the GPU must have read the request to have * sent us the seqno + interrupt, so use the position * of tail of the request to update the last known position * of the GPU head. */ - __get_ringbuf(ring)->last_retired_head = request->tail; + ringbuf->last_retired_head = request->tail; i915_gem_free_request(request); } diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c index e78ed94..823ad3d 100644 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c @@ -1001,12 +1001,12 @@ i915_reset_gen7_sol_offsets(struct drm_device *dev, return PTR_ERR(ringbuf); for (i = 0; i < 4; i++) { - intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1)); - intel_ring_emit(ring, GEN7_SO_WRITE_OFFSET(i)); - intel_ring_emit(ring, 0); + intel_ringbuffer_emit(ringbuf, MI_LOAD_REGISTER_IMM(1)); + intel_ringbuffer_emit(ringbuf, GEN7_SO_WRITE_OFFSET(i)); + intel_ringbuffer_emit(ringbuf, 0); } - intel_ring_advance(ring); + intel_ringbuffer_advance(ringbuf); return 0; } @@ -1299,11 +1299,11 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data, goto err; } - intel_ring_emit(ring, MI_NOOP); - intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1)); - intel_ring_emit(ring, INSTPM); - intel_ring_emit(ring, mask << 16 | mode); - intel_ring_advance(ring); + intel_ringbuffer_emit(ringbuf, MI_NOOP); + intel_ringbuffer_emit(ringbuf, MI_LOAD_REGISTER_IMM(1)); + intel_ringbuffer_emit(ringbuf, INSTPM); + intel_ringbuffer_emit(ringbuf, mask << 16 | mode); + intel_ringbuffer_advance(ringbuf); dev_priv->relative_constants_mode = mode; } diff --git a/drivers/gpu/drm/i915/i915_gpu_error.c b/drivers/gpu/drm/i915/i915_gpu_error.c index a7b165f..6724e32 100644 --- a/drivers/gpu/drm/i915/i915_gpu_error.c +++ b/drivers/gpu/drm/i915/i915_gpu_error.c @@ -823,8 +823,8 @@ static void i915_record_ring_state(struct drm_device *dev, ering->hws = I915_READ(mmio); } - ering->cpu_ring_head = __get_ringbuf(ring)->head; - ering->cpu_ring_tail = __get_ringbuf(ring)->tail; + ering->cpu_ring_head = ring->default_ringbuf.head; + ering->cpu_ring_tail = ring->default_ringbuf.tail; ering->hangcheck_score = ring->hangcheck.score; ering->hangcheck_action = ring->hangcheck.action; @@ -928,7 +928,7 @@ static void i915_gem_record_rings(struct drm_device *dev, } error->ring[i].ringbuffer = - i915_error_ggtt_object_create(dev_priv, __get_ringbuf(ring)->obj); + i915_error_ggtt_object_create(dev_priv, ring->default_ringbuf.obj); if (ring->status_page.obj) error->ring[i].hws_page = diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c index e0c3a01..873ae50 100644 --- a/drivers/gpu/drm/i915/i915_irq.c +++ b/drivers/gpu/drm/i915/i915_irq.c @@ -2610,7 +2610,7 @@ static struct intel_engine * semaphore_waits_for(struct intel_engine *ring, u32 *seqno) { struct drm_i915_private *dev_priv = ring->dev->dev_private; - struct intel_ringbuffer *ringbuf = __get_ringbuf(ring); + struct intel_ringbuffer *ringbuf = &ring->default_ringbuf; u32 cmd, ipehr, head; int i; diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.c b/drivers/gpu/drm/i915/intel_ringbuffer.c index 6292e75..f18bfb2 100644 --- a/drivers/gpu/drm/i915/intel_ringbuffer.c +++ b/drivers/gpu/drm/i915/intel_ringbuffer.c @@ -40,10 +40,8 @@ */ #define CACHELINE_BYTES 64 -static inline int ring_space(struct intel_engine *ring) +static inline int ring_space(struct intel_ringbuffer *ringbuf) { - struct intel_ringbuffer *ringbuf = __get_ringbuf(ring); - int space = (ringbuf->head & HEAD_ADDR) - (ringbuf->tail + I915_RING_FREE_SPACE); if (space < 0) space += ringbuf->size; @@ -59,7 +57,7 @@ static bool intel_ring_stopped(struct intel_engine *ring) void intel_ringbuffer_advance_and_submit(struct intel_engine *ring, struct i915_hw_context *ctx) { - struct intel_ringbuffer *ringbuf = __get_ringbuf(ring); + struct intel_ringbuffer *ringbuf = intel_ringbuffer_get(ring, ctx); ringbuf->tail &= ringbuf->size - 1; if (intel_ring_stopped(ring)) @@ -413,13 +411,13 @@ gen8_render_ring_flush(struct intel_engine *ring, if (IS_ERR_OR_NULL(ringbuf)) return PTR_ERR(ringbuf); - intel_ring_emit(ring, GFX_OP_PIPE_CONTROL(6)); - intel_ring_emit(ring, flags); - intel_ring_emit(ring, scratch_addr); - intel_ring_emit(ring, 0); - intel_ring_emit(ring, 0); - intel_ring_emit(ring, 0); - intel_ring_advance(ring); + intel_ringbuffer_emit(ringbuf, GFX_OP_PIPE_CONTROL(6)); + intel_ringbuffer_emit(ringbuf, flags); + intel_ringbuffer_emit(ringbuf, scratch_addr); + intel_ringbuffer_emit(ringbuf, 0); + intel_ringbuffer_emit(ringbuf, 0); + intel_ringbuffer_emit(ringbuf, 0); + intel_ringbuffer_advance(ringbuf); return 0; @@ -487,7 +485,7 @@ static int init_ring_common(struct intel_engine *ring) { struct drm_device *dev = ring->dev; struct drm_i915_private *dev_priv = dev->dev_private; - struct intel_ringbuffer *ringbuf = __get_ringbuf(ring); + struct intel_ringbuffer *ringbuf = &ring->default_ringbuf; struct drm_i915_gem_object *obj = ringbuf->obj; int ret = 0; @@ -549,7 +547,7 @@ static int init_ring_common(struct intel_engine *ring) else { ringbuf->head = I915_READ_HEAD(ring); ringbuf->tail = I915_READ_TAIL(ring) & TAIL_ADDR; - ringbuf->space = ring_space(ring); + ringbuf->space = ring_space(ringbuf); ringbuf->last_retired_head = -1; } @@ -1387,10 +1385,8 @@ static int init_phys_status_page(struct intel_engine *ring) return 0; } -void intel_destroy_ring_buffer(struct intel_engine *ring) +void intel_destroy_ring_buffer(struct intel_ringbuffer *ringbuf) { - struct intel_ringbuffer *ringbuf = __get_ringbuf(ring); - if (!ringbuf->obj) return; @@ -1400,12 +1396,11 @@ void intel_destroy_ring_buffer(struct intel_engine *ring) ringbuf->obj = NULL; } -int intel_allocate_ring_buffer(struct intel_engine *ring) +int intel_allocate_ring_buffer(struct drm_device *dev, + struct intel_ringbuffer *ringbuf) { - struct drm_device *dev = ring->dev; struct drm_i915_private *dev_priv = to_i915(dev); struct drm_i915_gem_object *obj; - struct intel_ringbuffer *ringbuf = __get_ringbuf(ring); int ret; if (ringbuf->obj) @@ -1448,7 +1443,7 @@ err_unref: static int intel_init_ring(struct drm_device *dev, struct intel_engine *ring) { - struct intel_ringbuffer *ringbuf = __get_ringbuf(ring); + struct intel_ringbuffer *ringbuf = &ring->default_ringbuf; int ret; INIT_LIST_HEAD(&ring->active_list); @@ -1469,7 +1464,7 @@ static int intel_init_ring(struct drm_device *dev, return ret; } - ret = intel_allocate_ring_buffer(ring); + ret = intel_allocate_ring_buffer(dev, &ring->default_ringbuf); if (ret) { DRM_ERROR("Failed to allocate ringbuffer %s: %d\n", ring->name, ret); return ret; @@ -1491,7 +1486,7 @@ static int intel_init_ring(struct drm_device *dev, void intel_cleanup_ring(struct intel_engine *ring) { struct drm_i915_private *dev_priv = to_i915(ring->dev); - struct intel_ringbuffer *ringbuf = __get_ringbuf(ring); + struct intel_ringbuffer *ringbuf = &ring->default_ringbuf; if (ringbuf->obj == NULL) return; @@ -1499,7 +1494,7 @@ void intel_cleanup_ring(struct intel_engine *ring) intel_stop_ring(ring); WARN_ON((I915_READ_MODE(ring) & MODE_IDLE) == 0); - intel_destroy_ring_buffer(ring); + intel_destroy_ring_buffer(&ring->default_ringbuf); ring->preallocated_lazy_request = NULL; ring->outstanding_lazy_seqno = 0; @@ -1509,10 +1504,11 @@ void intel_cleanup_ring(struct intel_engine *ring) cleanup_status_page(ring); } -static int intel_ring_wait_request(struct intel_engine *ring, int n) +static int intel_ring_wait_request(struct intel_engine *ring, + struct i915_hw_context *ctx, int n) { struct drm_i915_gem_request *request; - struct intel_ringbuffer *ringbuf = __get_ringbuf(ring); + struct intel_ringbuffer *ringbuf = intel_ringbuffer_get(ring, ctx); u32 seqno = 0, tail; int ret; @@ -1520,7 +1516,7 @@ static int intel_ring_wait_request(struct intel_engine *ring, int n) ringbuf->head = ringbuf->last_retired_head; ringbuf->last_retired_head = -1; - ringbuf->space = ring_space(ring); + ringbuf->space = ring_space(ringbuf); if (ringbuf->space >= n) return 0; } @@ -1556,7 +1552,7 @@ static int intel_ring_wait_request(struct intel_engine *ring, int n) return ret; ringbuf->head = tail; - ringbuf->space = ring_space(ring); + ringbuf->space = ring_space(ringbuf); if (WARN_ON(ringbuf->space < n)) return -ENOSPC; @@ -1568,11 +1564,11 @@ static int ring_wait_for_space(struct intel_engine *ring, { struct drm_device *dev = ring->dev; struct drm_i915_private *dev_priv = dev->dev_private; - struct intel_ringbuffer *ringbuf = __get_ringbuf(ring); + struct intel_ringbuffer *ringbuf = intel_ringbuffer_get(ring, ctx); unsigned long end; int ret; - ret = intel_ring_wait_request(ring, n); + ret = intel_ring_wait_request(ring, ctx, n); if (ret != -ENOSPC) return ret; @@ -1589,7 +1585,7 @@ static int ring_wait_for_space(struct intel_engine *ring, do { ringbuf->head = I915_READ_HEAD(ring); - ringbuf->space = ring_space(ring); + ringbuf->space = ring_space(ringbuf); if (ringbuf->space >= n) { trace_i915_ring_wait_end(ring); return 0; @@ -1617,7 +1613,7 @@ static int intel_wrap_ring_buffer(struct intel_engine *ring, struct i915_hw_context *ctx) { uint32_t __iomem *virt; - struct intel_ringbuffer *ringbuf = __get_ringbuf(ring); + struct intel_ringbuffer *ringbuf = intel_ringbuffer_get(ring, ctx); int rem = ringbuf->size - ringbuf->tail; if (ringbuf->space < rem) { @@ -1632,7 +1628,7 @@ static int intel_wrap_ring_buffer(struct intel_engine *ring, iowrite32(MI_NOOP, virt++); ringbuf->tail = 0; - ringbuf->space = ring_space(ring); + ringbuf->space = ring_space(ringbuf); return 0; } @@ -1682,7 +1678,7 @@ intel_ring_alloc_seqno(struct intel_engine *ring) static int __intel_ring_prepare(struct intel_engine *ring, struct i915_hw_context *ctx, int bytes) { - struct intel_ringbuffer *ringbuf = __get_ringbuf(ring); + struct intel_ringbuffer *ringbuf = intel_ringbuffer_get(ring, ctx); int ret; if (unlikely(ringbuf->tail + bytes > ringbuf->effective_size)) { @@ -1701,6 +1697,13 @@ static int __intel_ring_prepare(struct intel_engine *ring, } struct intel_ringbuffer * +intel_ringbuffer_get(struct intel_engine *ring, struct i915_hw_context *ctx) +{ + /* For the time being, the only ringbuffer is in the engine */ + return &ring->default_ringbuf; +} + +struct intel_ringbuffer * intel_ringbuffer_begin(struct intel_engine *ring, struct i915_hw_context *ctx, int num_dwords) @@ -1732,22 +1735,21 @@ intel_ringbuffer_begin(struct intel_engine *ring, int intel_ringbuffer_cacheline_align(struct intel_engine *ring, struct i915_hw_context *ctx) { - struct intel_ringbuffer *ringbuf = __get_ringbuf(ring); + struct intel_ringbuffer *ringbuf = intel_ringbuffer_get(ring, ctx); int num_dwords = (ringbuf->tail & (CACHELINE_BYTES - 1)) / sizeof(uint32_t); - int ret; if (num_dwords == 0) return 0; num_dwords = CACHELINE_BYTES / sizeof(uint32_t) - num_dwords; - ret = intel_ring_begin(ring, num_dwords); - if (ret) - return ret; + ringbuf = intel_ringbuffer_begin(ring, ctx, num_dwords); + if (IS_ERR_OR_NULL(ringbuf)) + return PTR_ERR(ringbuf); while (num_dwords--) intel_ring_emit(ring, MI_NOOP); - intel_ring_advance(ring); + intel_ringbuffer_advance(ringbuf); return 0; } @@ -1854,11 +1856,11 @@ gen8_ring_dispatch_execbuffer(struct intel_engine *ring, return PTR_ERR(ringbuf); /* FIXME(BDW): Address space and security selectors. */ - intel_ring_emit(ring, MI_BATCH_BUFFER_START_GEN8 | (ppgtt<<8)); - intel_ring_emit(ring, lower_32_bits(offset)); - intel_ring_emit(ring, upper_32_bits(offset)); - intel_ring_emit(ring, MI_NOOP); - intel_ring_advance(ring); + intel_ringbuffer_emit(ringbuf, MI_BATCH_BUFFER_START_GEN8 | (ppgtt<<8)); + intel_ringbuffer_emit(ringbuf, lower_32_bits(offset)); + intel_ringbuffer_emit(ringbuf, upper_32_bits(offset)); + intel_ringbuffer_emit(ringbuf, MI_NOOP); + intel_ringbuffer_advance(ringbuf); return 0; } @@ -2060,7 +2062,7 @@ int intel_render_ring_init_dri(struct drm_device *dev, u64 start, u32 size) { struct drm_i915_private *dev_priv = dev->dev_private; struct intel_engine *ring = &dev_priv->ring[RCS]; - struct intel_ringbuffer *ringbuf = __get_ringbuf(ring); + struct intel_ringbuffer *ringbuf = &ring->default_ringbuf; int ret; if (INTEL_INFO(dev)->gen >= 6) { diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.h b/drivers/gpu/drm/i915/intel_ringbuffer.h index 59280b2..dd85a2b 100644 --- a/drivers/gpu/drm/i915/intel_ringbuffer.h +++ b/drivers/gpu/drm/i915/intel_ringbuffer.h @@ -219,16 +219,10 @@ struct intel_engine { u32 (*get_cmd_length_mask)(u32 cmd_header); }; -/* This is a temporary define to help us transition to per-context ringbuffers */ -static inline struct intel_ringbuffer *__get_ringbuf(struct intel_engine *ring) -{ - return &ring->default_ringbuf; -} - static inline bool intel_ring_initialized(struct intel_engine *ring) { - return __get_ringbuf(ring)->obj != NULL; + return ring->default_ringbuf.obj != NULL; } static inline unsigned @@ -372,8 +366,9 @@ int intel_init_vebox_ring(struct drm_device *dev); u64 intel_ring_get_active_head(struct intel_engine *ring); void intel_ring_setup_status_page(struct intel_engine *ring); -void intel_destroy_ring_buffer(struct intel_engine *ring); -int intel_allocate_ring_buffer(struct intel_engine *ring); +void intel_destroy_ring_buffer(struct intel_ringbuffer *ringbuf); +int intel_allocate_ring_buffer(struct drm_device *dev, + struct intel_ringbuffer *ringbuf); static inline u32 intel_ring_get_seqno(struct intel_engine *ring) { -- 1.9.0 _______________________________________________ Intel-gfx mailing list Intel-gfx@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/intel-gfx