Skip to content

Commit 2107637

Browse files
Nick Hoathdanvet
authored andcommitted
drm/i915: Remove FIXME_lrc_ctx backpointer
The first pass implementation of execlists required a backpointer to the context to be held in the intel_ringbuffer. However the context pointer is available higher in the call stack. Remove the backpointer from the ring buffer structure and instead pass it down through the call stack. v2: Integrate this changeset with the removal of duplicate request/execlist queue item members. v3: Rebase v4: Rebase. Remove passing of context when the request is passed. Signed-off-by: Nick Hoath <[email protected]> Reviewed-by: Thomas Daniel <[email protected]> Signed-off-by: Daniel Vetter <[email protected]>
1 parent 72f95af commit 2107637

File tree

4 files changed

+52
-39
lines changed

4 files changed

+52
-39
lines changed

drivers/gpu/drm/i915/i915_gem.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2422,8 +2422,7 @@ int __i915_add_request(struct intel_engine_cs *ring,
24222422
return -ENOMEM;
24232423

24242424
if (i915.enable_execlists) {
2425-
struct intel_context *ctx = request->ctx;
2426-
ringbuf = ctx->engine[ring->id].ringbuf;
2425+
ringbuf = request->ctx->engine[ring->id].ringbuf;
24272426
} else
24282427
ringbuf = ring->buffer;
24292428

@@ -2436,7 +2435,7 @@ int __i915_add_request(struct intel_engine_cs *ring,
24362435
* what.
24372436
*/
24382437
if (i915.enable_execlists) {
2439-
ret = logical_ring_flush_all_caches(ringbuf);
2438+
ret = logical_ring_flush_all_caches(ringbuf, request->ctx);
24402439
if (ret)
24412440
return ret;
24422441
} else {

drivers/gpu/drm/i915/intel_lrc.c

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,8 @@ static int execlists_context_queue(struct intel_engine_cs *ring,
559559
if (request == NULL)
560560
return -ENOMEM;
561561
request->ring = ring;
562+
} else {
563+
WARN_ON(to != request->ctx);
562564
}
563565
request->ctx = to;
564566
request->tail = tail;
@@ -599,7 +601,8 @@ static int execlists_context_queue(struct intel_engine_cs *ring,
599601
return 0;
600602
}
601603

602-
static int logical_ring_invalidate_all_caches(struct intel_ringbuffer *ringbuf)
604+
static int logical_ring_invalidate_all_caches(struct intel_ringbuffer *ringbuf,
605+
struct intel_context *ctx)
603606
{
604607
struct intel_engine_cs *ring = ringbuf->ring;
605608
uint32_t flush_domains;
@@ -609,7 +612,8 @@ static int logical_ring_invalidate_all_caches(struct intel_ringbuffer *ringbuf)
609612
if (ring->gpu_caches_dirty)
610613
flush_domains = I915_GEM_GPU_DOMAINS;
611614

612-
ret = ring->emit_flush(ringbuf, I915_GEM_GPU_DOMAINS, flush_domains);
615+
ret = ring->emit_flush(ringbuf, ctx,
616+
I915_GEM_GPU_DOMAINS, flush_domains);
613617
if (ret)
614618
return ret;
615619

@@ -618,6 +622,7 @@ static int logical_ring_invalidate_all_caches(struct intel_ringbuffer *ringbuf)
618622
}
619623

620624
static int execlists_move_to_gpu(struct intel_ringbuffer *ringbuf,
625+
struct intel_context *ctx,
621626
struct list_head *vmas)
622627
{
623628
struct intel_engine_cs *ring = ringbuf->ring;
@@ -645,7 +650,7 @@ static int execlists_move_to_gpu(struct intel_ringbuffer *ringbuf,
645650
/* Unconditionally invalidate gpu caches and ensure that we do flush
646651
* any residual writes from the previous batch.
647652
*/
648-
return logical_ring_invalidate_all_caches(ringbuf);
653+
return logical_ring_invalidate_all_caches(ringbuf, ctx);
649654
}
650655

651656
/**
@@ -725,13 +730,13 @@ int intel_execlists_submission(struct drm_device *dev, struct drm_file *file,
725730
return -EINVAL;
726731
}
727732

728-
ret = execlists_move_to_gpu(ringbuf, vmas);
733+
ret = execlists_move_to_gpu(ringbuf, ctx, vmas);
729734
if (ret)
730735
return ret;
731736

732737
if (ring == &dev_priv->ring[RCS] &&
733738
instp_mode != dev_priv->relative_constants_mode) {
734-
ret = intel_logical_ring_begin(ringbuf, 4);
739+
ret = intel_logical_ring_begin(ringbuf, ctx, 4);
735740
if (ret)
736741
return ret;
737742

@@ -744,7 +749,7 @@ int intel_execlists_submission(struct drm_device *dev, struct drm_file *file,
744749
dev_priv->relative_constants_mode = instp_mode;
745750
}
746751

747-
ret = ring->emit_bb_start(ringbuf, exec_start, flags);
752+
ret = ring->emit_bb_start(ringbuf, ctx, exec_start, flags);
748753
if (ret)
749754
return ret;
750755

@@ -807,15 +812,16 @@ void intel_logical_ring_stop(struct intel_engine_cs *ring)
807812
I915_WRITE_MODE(ring, _MASKED_BIT_DISABLE(STOP_RING));
808813
}
809814

810-
int logical_ring_flush_all_caches(struct intel_ringbuffer *ringbuf)
815+
int logical_ring_flush_all_caches(struct intel_ringbuffer *ringbuf,
816+
struct intel_context *ctx)
811817
{
812818
struct intel_engine_cs *ring = ringbuf->ring;
813819
int ret;
814820

815821
if (!ring->gpu_caches_dirty)
816822
return 0;
817823

818-
ret = ring->emit_flush(ringbuf, 0, I915_GEM_GPU_DOMAINS);
824+
ret = ring->emit_flush(ringbuf, ctx, 0, I915_GEM_GPU_DOMAINS);
819825
if (ret)
820826
return ret;
821827

@@ -833,10 +839,10 @@ int logical_ring_flush_all_caches(struct intel_ringbuffer *ringbuf)
833839
* point, the tail *inside* the context is updated and the ELSP written to.
834840
*/
835841
void intel_logical_ring_advance_and_submit(struct intel_ringbuffer *ringbuf,
842+
struct intel_context *ctx,
836843
struct drm_i915_gem_request *request)
837844
{
838845
struct intel_engine_cs *ring = ringbuf->ring;
839-
struct intel_context *ctx = ringbuf->FIXME_lrc_ctx;
840846

841847
intel_logical_ring_advance(ringbuf);
842848

@@ -974,6 +980,7 @@ static int logical_ring_wait_request(struct intel_ringbuffer *ringbuf,
974980
}
975981

976982
static int logical_ring_wait_for_space(struct intel_ringbuffer *ringbuf,
983+
struct intel_context *ctx,
977984
int bytes)
978985
{
979986
struct intel_engine_cs *ring = ringbuf->ring;
@@ -987,7 +994,7 @@ static int logical_ring_wait_for_space(struct intel_ringbuffer *ringbuf,
987994
return ret;
988995

989996
/* Force the context submission in case we have been skipping it */
990-
intel_logical_ring_advance_and_submit(ringbuf, NULL);
997+
intel_logical_ring_advance_and_submit(ringbuf, ctx, NULL);
991998

992999
/* With GEM the hangcheck timer should kick us out of the loop,
9931000
* leaving it early runs the risk of corrupting GEM state (due
@@ -1022,13 +1029,14 @@ static int logical_ring_wait_for_space(struct intel_ringbuffer *ringbuf,
10221029
return ret;
10231030
}
10241031

1025-
static int logical_ring_wrap_buffer(struct intel_ringbuffer *ringbuf)
1032+
static int logical_ring_wrap_buffer(struct intel_ringbuffer *ringbuf,
1033+
struct intel_context *ctx)
10261034
{
10271035
uint32_t __iomem *virt;
10281036
int rem = ringbuf->size - ringbuf->tail;
10291037

10301038
if (ringbuf->space < rem) {
1031-
int ret = logical_ring_wait_for_space(ringbuf, rem);
1039+
int ret = logical_ring_wait_for_space(ringbuf, ctx, rem);
10321040

10331041
if (ret)
10341042
return ret;
@@ -1045,18 +1053,19 @@ static int logical_ring_wrap_buffer(struct intel_ringbuffer *ringbuf)
10451053
return 0;
10461054
}
10471055

1048-
static int logical_ring_prepare(struct intel_ringbuffer *ringbuf, int bytes)
1056+
static int logical_ring_prepare(struct intel_ringbuffer *ringbuf,
1057+
struct intel_context *ctx, int bytes)
10491058
{
10501059
int ret;
10511060

10521061
if (unlikely(ringbuf->tail + bytes > ringbuf->effective_size)) {
1053-
ret = logical_ring_wrap_buffer(ringbuf);
1062+
ret = logical_ring_wrap_buffer(ringbuf, ctx);
10541063
if (unlikely(ret))
10551064
return ret;
10561065
}
10571066

10581067
if (unlikely(ringbuf->space < bytes)) {
1059-
ret = logical_ring_wait_for_space(ringbuf, bytes);
1068+
ret = logical_ring_wait_for_space(ringbuf, ctx, bytes);
10601069
if (unlikely(ret))
10611070
return ret;
10621071
}
@@ -1077,7 +1086,8 @@ static int logical_ring_prepare(struct intel_ringbuffer *ringbuf, int bytes)
10771086
*
10781087
* Return: non-zero if the ringbuffer is not ready to be written to.
10791088
*/
1080-
int intel_logical_ring_begin(struct intel_ringbuffer *ringbuf, int num_dwords)
1089+
int intel_logical_ring_begin(struct intel_ringbuffer *ringbuf,
1090+
struct intel_context *ctx, int num_dwords)
10811091
{
10821092
struct intel_engine_cs *ring = ringbuf->ring;
10831093
struct drm_device *dev = ring->dev;
@@ -1089,12 +1099,12 @@ int intel_logical_ring_begin(struct intel_ringbuffer *ringbuf, int num_dwords)
10891099
if (ret)
10901100
return ret;
10911101

1092-
ret = logical_ring_prepare(ringbuf, num_dwords * sizeof(uint32_t));
1102+
ret = logical_ring_prepare(ringbuf, ctx, num_dwords * sizeof(uint32_t));
10931103
if (ret)
10941104
return ret;
10951105

10961106
/* Preallocate the olr before touching the ring */
1097-
ret = logical_ring_alloc_request(ring, ringbuf->FIXME_lrc_ctx);
1107+
ret = logical_ring_alloc_request(ring, ctx);
10981108
if (ret)
10991109
return ret;
11001110

@@ -1115,11 +1125,11 @@ static int intel_logical_ring_workarounds_emit(struct intel_engine_cs *ring,
11151125
return 0;
11161126

11171127
ring->gpu_caches_dirty = true;
1118-
ret = logical_ring_flush_all_caches(ringbuf);
1128+
ret = logical_ring_flush_all_caches(ringbuf, ctx);
11191129
if (ret)
11201130
return ret;
11211131

1122-
ret = intel_logical_ring_begin(ringbuf, w->count * 2 + 2);
1132+
ret = intel_logical_ring_begin(ringbuf, ctx, w->count * 2 + 2);
11231133
if (ret)
11241134
return ret;
11251135

@@ -1133,7 +1143,7 @@ static int intel_logical_ring_workarounds_emit(struct intel_engine_cs *ring,
11331143
intel_logical_ring_advance(ringbuf);
11341144

11351145
ring->gpu_caches_dirty = true;
1136-
ret = logical_ring_flush_all_caches(ringbuf);
1146+
ret = logical_ring_flush_all_caches(ringbuf, ctx);
11371147
if (ret)
11381148
return ret;
11391149

@@ -1184,12 +1194,13 @@ static int gen8_init_render_ring(struct intel_engine_cs *ring)
11841194
}
11851195

11861196
static int gen8_emit_bb_start(struct intel_ringbuffer *ringbuf,
1197+
struct intel_context *ctx,
11871198
u64 offset, unsigned flags)
11881199
{
11891200
bool ppgtt = !(flags & I915_DISPATCH_SECURE);
11901201
int ret;
11911202

1192-
ret = intel_logical_ring_begin(ringbuf, 4);
1203+
ret = intel_logical_ring_begin(ringbuf, ctx, 4);
11931204
if (ret)
11941205
return ret;
11951206

@@ -1237,6 +1248,7 @@ static void gen8_logical_ring_put_irq(struct intel_engine_cs *ring)
12371248
}
12381249

12391250
static int gen8_emit_flush(struct intel_ringbuffer *ringbuf,
1251+
struct intel_context *ctx,
12401252
u32 invalidate_domains,
12411253
u32 unused)
12421254
{
@@ -1246,7 +1258,7 @@ static int gen8_emit_flush(struct intel_ringbuffer *ringbuf,
12461258
uint32_t cmd;
12471259
int ret;
12481260

1249-
ret = intel_logical_ring_begin(ringbuf, 4);
1261+
ret = intel_logical_ring_begin(ringbuf, ctx, 4);
12501262
if (ret)
12511263
return ret;
12521264

@@ -1275,6 +1287,7 @@ static int gen8_emit_flush(struct intel_ringbuffer *ringbuf,
12751287
}
12761288

12771289
static int gen8_emit_flush_render(struct intel_ringbuffer *ringbuf,
1290+
struct intel_context *ctx,
12781291
u32 invalidate_domains,
12791292
u32 flush_domains)
12801293
{
@@ -1301,7 +1314,7 @@ static int gen8_emit_flush_render(struct intel_ringbuffer *ringbuf,
13011314
flags |= PIPE_CONTROL_GLOBAL_GTT_IVB;
13021315
}
13031316

1304-
ret = intel_logical_ring_begin(ringbuf, 6);
1317+
ret = intel_logical_ring_begin(ringbuf, ctx, 6);
13051318
if (ret)
13061319
return ret;
13071320

@@ -1333,7 +1346,7 @@ static int gen8_emit_request(struct intel_ringbuffer *ringbuf,
13331346
u32 cmd;
13341347
int ret;
13351348

1336-
ret = intel_logical_ring_begin(ringbuf, 6);
1349+
ret = intel_logical_ring_begin(ringbuf, request->ctx, 6);
13371350
if (ret)
13381351
return ret;
13391352

@@ -1349,7 +1362,7 @@ static int gen8_emit_request(struct intel_ringbuffer *ringbuf,
13491362
i915_gem_request_get_seqno(ring->outstanding_lazy_request));
13501363
intel_logical_ring_emit(ringbuf, MI_USER_INTERRUPT);
13511364
intel_logical_ring_emit(ringbuf, MI_NOOP);
1352-
intel_logical_ring_advance_and_submit(ringbuf, request);
1365+
intel_logical_ring_advance_and_submit(ringbuf, request->ctx, request);
13531366

13541367
return 0;
13551368
}
@@ -1636,6 +1649,7 @@ int intel_lr_context_render_state_init(struct intel_engine_cs *ring,
16361649
return 0;
16371650

16381651
ret = ring->emit_bb_start(ringbuf,
1652+
ctx,
16391653
so.ggtt_offset,
16401654
I915_DISPATCH_SECURE);
16411655
if (ret)
@@ -1892,7 +1906,6 @@ int intel_lr_context_deferred_create(struct intel_context *ctx,
18921906
}
18931907

18941908
ringbuf->ring = ring;
1895-
ringbuf->FIXME_lrc_ctx = ctx;
18961909

18971910
ringbuf->size = 32 * PAGE_SIZE;
18981911
ringbuf->effective_size = ringbuf->size;

drivers/gpu/drm/i915/intel_lrc.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ void intel_logical_ring_stop(struct intel_engine_cs *ring);
3838
void intel_logical_ring_cleanup(struct intel_engine_cs *ring);
3939
int intel_logical_rings_init(struct drm_device *dev);
4040

41-
int logical_ring_flush_all_caches(struct intel_ringbuffer *ringbuf);
41+
int logical_ring_flush_all_caches(struct intel_ringbuffer *ringbuf,
42+
struct intel_context *ctx);
4243
void intel_logical_ring_advance_and_submit(
4344
struct intel_ringbuffer *ringbuf,
45+
struct intel_context *ctx,
4446
struct drm_i915_gem_request *request);
4547
/**
4648
* intel_logical_ring_advance() - advance the ringbuffer tail
@@ -63,7 +65,9 @@ static inline void intel_logical_ring_emit(struct intel_ringbuffer *ringbuf,
6365
iowrite32(data, ringbuf->virtual_start + ringbuf->tail);
6466
ringbuf->tail += 4;
6567
}
66-
int intel_logical_ring_begin(struct intel_ringbuffer *ringbuf, int num_dwords);
68+
int intel_logical_ring_begin(struct intel_ringbuffer *ringbuf,
69+
struct intel_context *ctx,
70+
int num_dwords);
6771

6872
/* Logical Ring Contexts */
6973
int intel_lr_context_render_state_init(struct intel_engine_cs *ring,

drivers/gpu/drm/i915/intel_ringbuffer.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,6 @@ struct intel_ringbuffer {
9999

100100
struct intel_engine_cs *ring;
101101

102-
/*
103-
* FIXME: This backpointer is an artifact of the history of how the
104-
* execlist patches came into being. It will get removed once the basic
105-
* code has landed.
106-
*/
107-
struct intel_context *FIXME_lrc_ctx;
108-
109102
u32 head;
110103
u32 tail;
111104
int space;
@@ -123,6 +116,8 @@ struct intel_ringbuffer {
123116
u32 last_retired_head;
124117
};
125118

119+
struct intel_context;
120+
126121
struct intel_engine_cs {
127122
const char *name;
128123
enum intel_ring_id {
@@ -242,9 +237,11 @@ struct intel_engine_cs {
242237
int (*emit_request)(struct intel_ringbuffer *ringbuf,
243238
struct drm_i915_gem_request *request);
244239
int (*emit_flush)(struct intel_ringbuffer *ringbuf,
240+
struct intel_context *ctx,
245241
u32 invalidate_domains,
246242
u32 flush_domains);
247243
int (*emit_bb_start)(struct intel_ringbuffer *ringbuf,
244+
struct intel_context *ctx,
248245
u64 offset, unsigned flags);
249246

250247
/**

0 commit comments

Comments
 (0)