Skip to content

Commit 829a0af

Browse files
committed
drm/i915: Group all the global context information together
Create a substruct to hold all the global context state under drm_i915_private. Signed-off-by: Chris Wilson <[email protected]> Reviewed-by: Joonas Lahtinen <[email protected]> Link: http://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent c58949f commit 829a0af

File tree

11 files changed

+58
-49
lines changed

11 files changed

+58
-49
lines changed

drivers/gpu/drm/i915/i915_debugfs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,7 +1966,7 @@ static int i915_context_status(struct seq_file *m, void *unused)
19661966
if (ret)
19671967
return ret;
19681968

1969-
list_for_each_entry(ctx, &dev_priv->context_list, link) {
1969+
list_for_each_entry(ctx, &dev_priv->contexts.list, link) {
19701970
seq_printf(m, "HW context %u ", ctx->hw_id);
19711971
if (ctx->pid) {
19721972
struct task_struct *task;
@@ -2072,7 +2072,7 @@ static int i915_dump_lrc(struct seq_file *m, void *unused)
20722072
if (ret)
20732073
return ret;
20742074

2075-
list_for_each_entry(ctx, &dev_priv->context_list, link)
2075+
list_for_each_entry(ctx, &dev_priv->contexts.list, link)
20762076
for_each_engine(engine, dev_priv, id)
20772077
i915_dump_lrc_obj(m, ctx, engine);
20782078

drivers/gpu/drm/i915/i915_drv.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -588,13 +588,13 @@ static void i915_gem_fini(struct drm_i915_private *dev_priv)
588588
mutex_lock(&dev_priv->drm.struct_mutex);
589589
intel_uc_fini_hw(dev_priv);
590590
i915_gem_cleanup_engines(dev_priv);
591-
i915_gem_context_fini(dev_priv);
591+
i915_gem_contexts_fini(dev_priv);
592592
i915_gem_cleanup_userptr(dev_priv);
593593
mutex_unlock(&dev_priv->drm.struct_mutex);
594594

595595
i915_gem_drain_freed_objects(dev_priv);
596596

597-
WARN_ON(!list_empty(&dev_priv->context_list));
597+
WARN_ON(!list_empty(&dev_priv->contexts.list));
598598
}
599599

600600
static int i915_load_modeset_init(struct drm_device *dev)
@@ -1425,9 +1425,10 @@ static void i915_driver_release(struct drm_device *dev)
14251425

14261426
static int i915_driver_open(struct drm_device *dev, struct drm_file *file)
14271427
{
1428+
struct drm_i915_private *i915 = to_i915(dev);
14281429
int ret;
14291430

1430-
ret = i915_gem_open(dev, file);
1431+
ret = i915_gem_open(i915, file);
14311432
if (ret)
14321433
return ret;
14331434

@@ -1457,7 +1458,7 @@ static void i915_driver_postclose(struct drm_device *dev, struct drm_file *file)
14571458
struct drm_i915_file_private *file_priv = file->driver_priv;
14581459

14591460
mutex_lock(&dev->struct_mutex);
1460-
i915_gem_context_close(dev, file);
1461+
i915_gem_context_close(file);
14611462
i915_gem_release(dev, file);
14621463
mutex_unlock(&dev->struct_mutex);
14631464

drivers/gpu/drm/i915/i915_drv.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2235,13 +2235,6 @@ struct drm_i915_private {
22352235
DECLARE_HASHTABLE(mm_structs, 7);
22362236
struct mutex mm_lock;
22372237

2238-
/* The hw wants to have a stable context identifier for the lifetime
2239-
* of the context (for OA, PASID, faults, etc). This is limited
2240-
* in execlists to 21 bits.
2241-
*/
2242-
struct ida context_hw_ida;
2243-
#define MAX_CONTEXT_HW_ID (1<<21) /* exclusive */
2244-
22452238
/* Kernel Modesetting */
22462239

22472240
struct intel_crtc *plane_to_crtc_mapping[I915_MAX_PIPES];
@@ -2320,7 +2313,16 @@ struct drm_i915_private {
23202313
*/
23212314
struct mutex av_mutex;
23222315

2323-
struct list_head context_list;
2316+
struct {
2317+
struct list_head list;
2318+
2319+
/* The hw wants to have a stable context identifier for the
2320+
* lifetime of the context (for OA, PASID, faults, etc).
2321+
* This is limited in execlists to 21 bits.
2322+
*/
2323+
struct ida hw_ida;
2324+
#define MAX_CONTEXT_HW_ID (1<<21) /* exclusive */
2325+
} contexts;
23242326

23252327
u32 fdi_rx_config;
23262328

@@ -3498,7 +3500,7 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,
34983500
void i915_gem_object_unpin_from_display_plane(struct i915_vma *vma);
34993501
int i915_gem_object_attach_phys(struct drm_i915_gem_object *obj,
35003502
int align);
3501-
int i915_gem_open(struct drm_device *dev, struct drm_file *file);
3503+
int i915_gem_open(struct drm_i915_private *i915, struct drm_file *file);
35023504
void i915_gem_release(struct drm_device *dev, struct drm_file *file);
35033505

35043506
int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,

drivers/gpu/drm/i915/i915_gem.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3098,7 +3098,7 @@ void i915_gem_set_wedged(struct drm_i915_private *dev_priv)
30983098

30993099
stop_machine(__i915_gem_set_wedged_BKL, dev_priv, NULL);
31003100

3101-
i915_gem_context_lost(dev_priv);
3101+
i915_gem_contexts_lost(dev_priv);
31023102

31033103
mod_delayed_work(dev_priv->wq, &dev_priv->gt.idle_work, 0);
31043104
}
@@ -4564,7 +4564,7 @@ int i915_gem_suspend(struct drm_i915_private *dev_priv)
45644564
goto err_unlock;
45654565

45664566
assert_kernel_context_is_current(dev_priv);
4567-
i915_gem_context_lost(dev_priv);
4567+
i915_gem_contexts_lost(dev_priv);
45684568
mutex_unlock(&dev->struct_mutex);
45694569

45704570
intel_guc_suspend(dev_priv);
@@ -4811,7 +4811,7 @@ int i915_gem_init(struct drm_i915_private *dev_priv)
48114811
if (ret)
48124812
goto out_unlock;
48134813

4814-
ret = i915_gem_context_init(dev_priv);
4814+
ret = i915_gem_contexts_init(dev_priv);
48154815
if (ret)
48164816
goto out_unlock;
48174817

@@ -4921,7 +4921,6 @@ i915_gem_load_init(struct drm_i915_private *dev_priv)
49214921
if (err)
49224922
goto err_priorities;
49234923

4924-
INIT_LIST_HEAD(&dev_priv->context_list);
49254924
INIT_WORK(&dev_priv->mm.free_work, __i915_gem_free_work);
49264925
init_llist_head(&dev_priv->mm.free_list);
49274926
INIT_LIST_HEAD(&dev_priv->mm.unbound_list);
@@ -5045,7 +5044,7 @@ void i915_gem_release(struct drm_device *dev, struct drm_file *file)
50455044
}
50465045
}
50475046

5048-
int i915_gem_open(struct drm_device *dev, struct drm_file *file)
5047+
int i915_gem_open(struct drm_i915_private *i915, struct drm_file *file)
50495048
{
50505049
struct drm_i915_file_private *file_priv;
50515050
int ret;
@@ -5057,7 +5056,7 @@ int i915_gem_open(struct drm_device *dev, struct drm_file *file)
50575056
return -ENOMEM;
50585057

50595058
file->driver_priv = file_priv;
5060-
file_priv->dev_priv = to_i915(dev);
5059+
file_priv->dev_priv = i915;
50615060
file_priv->file = file;
50625061
INIT_LIST_HEAD(&file_priv->rps.link);
50635062

@@ -5066,7 +5065,7 @@ int i915_gem_open(struct drm_device *dev, struct drm_file *file)
50665065

50675066
file_priv->bsd_engine = -1;
50685067

5069-
ret = i915_gem_context_open(dev, file);
5068+
ret = i915_gem_context_open(i915, file);
50705069
if (ret)
50715070
kfree(file_priv);
50725071

drivers/gpu/drm/i915/i915_gem_context.c

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ void i915_gem_context_free(struct kref *ctx_ref)
188188

189189
list_del(&ctx->link);
190190

191-
ida_simple_remove(&ctx->i915->context_hw_ida, ctx->hw_id);
191+
ida_simple_remove(&ctx->i915->contexts.hw_ida, ctx->hw_id);
192192
kfree(ctx);
193193
}
194194

@@ -205,15 +205,15 @@ static int assign_hw_id(struct drm_i915_private *dev_priv, unsigned *out)
205205
{
206206
int ret;
207207

208-
ret = ida_simple_get(&dev_priv->context_hw_ida,
208+
ret = ida_simple_get(&dev_priv->contexts.hw_ida,
209209
0, MAX_CONTEXT_HW_ID, GFP_KERNEL);
210210
if (ret < 0) {
211211
/* Contexts are only released when no longer active.
212212
* Flush any pending retires to hopefully release some
213213
* stale contexts and try again.
214214
*/
215215
i915_gem_retire_requests(dev_priv);
216-
ret = ida_simple_get(&dev_priv->context_hw_ida,
216+
ret = ida_simple_get(&dev_priv->contexts.hw_ida,
217217
0, MAX_CONTEXT_HW_ID, GFP_KERNEL);
218218
if (ret < 0)
219219
return ret;
@@ -265,7 +265,7 @@ __create_hw_context(struct drm_i915_private *dev_priv,
265265
}
266266

267267
kref_init(&ctx->ref);
268-
list_add_tail(&ctx->link, &dev_priv->context_list);
268+
list_add_tail(&ctx->link, &dev_priv->contexts.list);
269269
ctx->i915 = dev_priv;
270270
ctx->priority = I915_PRIORITY_NORMAL;
271271

@@ -418,7 +418,7 @@ i915_gem_context_create_gvt(struct drm_device *dev)
418418
return ctx;
419419
}
420420

421-
int i915_gem_context_init(struct drm_i915_private *dev_priv)
421+
int i915_gem_contexts_init(struct drm_i915_private *dev_priv)
422422
{
423423
struct i915_gem_context *ctx;
424424

@@ -427,6 +427,8 @@ int i915_gem_context_init(struct drm_i915_private *dev_priv)
427427
if (WARN_ON(dev_priv->kernel_context))
428428
return 0;
429429

430+
INIT_LIST_HEAD(&dev_priv->contexts.list);
431+
430432
if (intel_vgpu_active(dev_priv) &&
431433
HAS_LOGICAL_RING_CONTEXTS(dev_priv)) {
432434
if (!i915.enable_execlists) {
@@ -437,7 +439,7 @@ int i915_gem_context_init(struct drm_i915_private *dev_priv)
437439

438440
/* Using the simple ida interface, the max is limited by sizeof(int) */
439441
BUILD_BUG_ON(MAX_CONTEXT_HW_ID > INT_MAX);
440-
ida_init(&dev_priv->context_hw_ida);
442+
ida_init(&dev_priv->contexts.hw_ida);
441443

442444
ctx = i915_gem_create_context(dev_priv, NULL);
443445
if (IS_ERR(ctx)) {
@@ -463,7 +465,7 @@ int i915_gem_context_init(struct drm_i915_private *dev_priv)
463465
return 0;
464466
}
465467

466-
void i915_gem_context_lost(struct drm_i915_private *dev_priv)
468+
void i915_gem_contexts_lost(struct drm_i915_private *dev_priv)
467469
{
468470
struct intel_engine_cs *engine;
469471
enum intel_engine_id id;
@@ -484,7 +486,7 @@ void i915_gem_context_lost(struct drm_i915_private *dev_priv)
484486
if (!i915.enable_execlists) {
485487
struct i915_gem_context *ctx;
486488

487-
list_for_each_entry(ctx, &dev_priv->context_list, link) {
489+
list_for_each_entry(ctx, &dev_priv->contexts.list, link) {
488490
if (!i915_gem_context_is_default(ctx))
489491
continue;
490492

@@ -503,7 +505,7 @@ void i915_gem_context_lost(struct drm_i915_private *dev_priv)
503505
}
504506
}
505507

506-
void i915_gem_context_fini(struct drm_i915_private *dev_priv)
508+
void i915_gem_contexts_fini(struct drm_i915_private *dev_priv)
507509
{
508510
struct i915_gem_context *dctx = dev_priv->kernel_context;
509511

@@ -514,7 +516,7 @@ void i915_gem_context_fini(struct drm_i915_private *dev_priv)
514516
context_close(dctx);
515517
dev_priv->kernel_context = NULL;
516518

517-
ida_destroy(&dev_priv->context_hw_ida);
519+
ida_destroy(&dev_priv->contexts.hw_ida);
518520
}
519521

520522
static int context_idr_cleanup(int id, void *p, void *data)
@@ -525,16 +527,17 @@ static int context_idr_cleanup(int id, void *p, void *data)
525527
return 0;
526528
}
527529

528-
int i915_gem_context_open(struct drm_device *dev, struct drm_file *file)
530+
int i915_gem_context_open(struct drm_i915_private *i915,
531+
struct drm_file *file)
529532
{
530533
struct drm_i915_file_private *file_priv = file->driver_priv;
531534
struct i915_gem_context *ctx;
532535

533536
idr_init(&file_priv->context_idr);
534537

535-
mutex_lock(&dev->struct_mutex);
536-
ctx = i915_gem_create_context(to_i915(dev), file_priv);
537-
mutex_unlock(&dev->struct_mutex);
538+
mutex_lock(&i915->drm.struct_mutex);
539+
ctx = i915_gem_create_context(i915, file_priv);
540+
mutex_unlock(&i915->drm.struct_mutex);
538541

539542
GEM_BUG_ON(i915_gem_context_is_kernel(ctx));
540543

@@ -546,11 +549,11 @@ int i915_gem_context_open(struct drm_device *dev, struct drm_file *file)
546549
return 0;
547550
}
548551

549-
void i915_gem_context_close(struct drm_device *dev, struct drm_file *file)
552+
void i915_gem_context_close(struct drm_file *file)
550553
{
551554
struct drm_i915_file_private *file_priv = file->driver_priv;
552555

553-
lockdep_assert_held(&dev->struct_mutex);
556+
lockdep_assert_held(&file_priv->dev_priv->drm.struct_mutex);
554557

555558
idr_for_each(&file_priv->context_idr, context_idr_cleanup, NULL);
556559
idr_destroy(&file_priv->context_idr);

drivers/gpu/drm/i915/i915_gem_context.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,17 @@ static inline bool i915_gem_context_is_kernel(struct i915_gem_context *ctx)
273273
}
274274

275275
/* i915_gem_context.c */
276-
int __must_check i915_gem_context_init(struct drm_i915_private *dev_priv);
277-
void i915_gem_context_lost(struct drm_i915_private *dev_priv);
278-
void i915_gem_context_fini(struct drm_i915_private *dev_priv);
279-
int i915_gem_context_open(struct drm_device *dev, struct drm_file *file);
280-
void i915_gem_context_close(struct drm_device *dev, struct drm_file *file);
276+
int __must_check i915_gem_contexts_init(struct drm_i915_private *dev_priv);
277+
void i915_gem_contexts_lost(struct drm_i915_private *dev_priv);
278+
void i915_gem_contexts_fini(struct drm_i915_private *dev_priv);
279+
280+
int i915_gem_context_open(struct drm_i915_private *i915,
281+
struct drm_file *file);
282+
void i915_gem_context_close(struct drm_file *file);
283+
281284
int i915_switch_context(struct drm_i915_gem_request *req);
282285
int i915_gem_switch_to_kernel_context(struct drm_i915_private *dev_priv);
286+
283287
void i915_gem_context_free(struct kref *ctx_ref);
284288
struct i915_gem_context *
285289
i915_gem_context_create_gvt(struct drm_device *dev);

drivers/gpu/drm/i915/i915_perf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1746,7 +1746,7 @@ static int gen8_configure_all_contexts(struct drm_i915_private *dev_priv,
17461746
goto out;
17471747

17481748
/* Update all contexts now that we've stalled the submission. */
1749-
list_for_each_entry(ctx, &dev_priv->context_list, link) {
1749+
list_for_each_entry(ctx, &dev_priv->contexts.list, link) {
17501750
struct intel_context *ce = &ctx->engine[RCS];
17511751
u32 *regs;
17521752

drivers/gpu/drm/i915/i915_sysfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ i915_l3_write(struct file *filp, struct kobject *kobj,
209209
memcpy(*remap_info + (offset/4), buf, count);
210210

211211
/* NB: We defer the remapping until we switch to the context */
212-
list_for_each_entry(ctx, &dev_priv->context_list, link)
212+
list_for_each_entry(ctx, &dev_priv->contexts.list, link)
213213
ctx->remap_slice |= (1<<slice);
214214

215215
ret = count;

drivers/gpu/drm/i915/intel_lrc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2071,7 +2071,7 @@ void intel_lr_context_resume(struct drm_i915_private *dev_priv)
20712071
* So to avoid that we reset the context images upon resume. For
20722072
* simplicity, we just zero everything out.
20732073
*/
2074-
list_for_each_entry(ctx, &dev_priv->context_list, link) {
2074+
list_for_each_entry(ctx, &dev_priv->contexts.list, link) {
20752075
for_each_engine(engine, dev_priv, id) {
20762076
struct intel_context *ce = &ctx->engine[engine->id];
20772077
u32 *reg;

drivers/gpu/drm/i915/selftests/mock_context.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ mock_context(struct drm_i915_private *i915,
4848
if (!ctx->vma_lut.ht)
4949
goto err_free;
5050

51-
ret = ida_simple_get(&i915->context_hw_ida,
51+
ret = ida_simple_get(&i915->contexts.hw_ida,
5252
0, MAX_CONTEXT_HW_ID, GFP_KERNEL);
5353
if (ret < 0)
5454
goto err_vma_ht;

drivers/gpu/drm/i915/selftests/mock_gem_device.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static void mock_device_release(struct drm_device *dev)
6161
mutex_lock(&i915->drm.struct_mutex);
6262
for_each_engine(engine, i915, id)
6363
mock_engine_free(engine);
64-
i915_gem_context_fini(i915);
64+
i915_gem_contexts_fini(i915);
6565
mutex_unlock(&i915->drm.struct_mutex);
6666

6767
drain_workqueue(i915->wq);
@@ -160,7 +160,7 @@ struct drm_i915_private *mock_gem_device(void)
160160
INIT_LIST_HEAD(&i915->mm.unbound_list);
161161
INIT_LIST_HEAD(&i915->mm.bound_list);
162162

163-
ida_init(&i915->context_hw_ida);
163+
ida_init(&i915->contexts.hw_ida);
164164

165165
INIT_DELAYED_WORK(&i915->gt.retire_work, mock_retire_work_handler);
166166
INIT_DELAYED_WORK(&i915->gt.idle_work, mock_idle_work_handler);

0 commit comments

Comments
 (0)