Skip to content

Commit 1b32102

Browse files
mlankhorstdanvet
authored andcommitted
drm/i915: Pass ww ctx to intel_pin_to_display_plane
Instead of multiple lockings, lock the object once, and perform the ww dance around attach_phys and pin_pages. Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com> Reviewed-by: Thomas Hellström <thomas.hellstrom@linux.intel.com> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch> Link: https://patchwork.freedesktop.org/patch/msgid/20210323155059.628690-23-maarten.lankhorst@linux.intel.com
1 parent d4fa4e7 commit 1b32102

File tree

8 files changed

+86
-64
lines changed

8 files changed

+86
-64
lines changed

drivers/gpu/drm/i915/display/intel_display.c

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,7 @@ static bool intel_plane_uses_fence(const struct intel_plane_state *plane_state)
10911091

10921092
struct i915_vma *
10931093
intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
1094+
bool phys_cursor,
10941095
const struct i915_ggtt_view *view,
10951096
bool uses_fence,
10961097
unsigned long *out_flags)
@@ -1099,14 +1100,19 @@ intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
10991100
struct drm_i915_private *dev_priv = to_i915(dev);
11001101
struct drm_i915_gem_object *obj = intel_fb_obj(fb);
11011102
intel_wakeref_t wakeref;
1103+
struct i915_gem_ww_ctx ww;
11021104
struct i915_vma *vma;
11031105
unsigned int pinctl;
11041106
u32 alignment;
1107+
int ret;
11051108

11061109
if (drm_WARN_ON(dev, !i915_gem_object_is_framebuffer(obj)))
11071110
return ERR_PTR(-EINVAL);
11081111

1109-
alignment = intel_surf_alignment(fb, 0);
1112+
if (phys_cursor)
1113+
alignment = intel_cursor_alignment(dev_priv);
1114+
else
1115+
alignment = intel_surf_alignment(fb, 0);
11101116
if (drm_WARN_ON(dev, alignment && !is_power_of_2(alignment)))
11111117
return ERR_PTR(-EINVAL);
11121118

@@ -1141,14 +1147,26 @@ intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
11411147
if (HAS_GMCH(dev_priv))
11421148
pinctl |= PIN_MAPPABLE;
11431149

1144-
vma = i915_gem_object_pin_to_display_plane(obj,
1145-
alignment, view, pinctl);
1146-
if (IS_ERR(vma))
1150+
i915_gem_ww_ctx_init(&ww, true);
1151+
retry:
1152+
ret = i915_gem_object_lock(obj, &ww);
1153+
if (!ret && phys_cursor)
1154+
ret = i915_gem_object_attach_phys(obj, alignment);
1155+
if (!ret)
1156+
ret = i915_gem_object_pin_pages(obj);
1157+
if (ret)
11471158
goto err;
11481159

1149-
if (uses_fence && i915_vma_is_map_and_fenceable(vma)) {
1150-
int ret;
1160+
if (!ret) {
1161+
vma = i915_gem_object_pin_to_display_plane(obj, &ww, alignment,
1162+
view, pinctl);
1163+
if (IS_ERR(vma)) {
1164+
ret = PTR_ERR(vma);
1165+
goto err_unpin;
1166+
}
1167+
}
11511168

1169+
if (uses_fence && i915_vma_is_map_and_fenceable(vma)) {
11521170
/*
11531171
* Install a fence for tiled scan-out. Pre-i965 always needs a
11541172
* fence, whereas 965+ only requires a fence if using
@@ -1169,16 +1187,28 @@ intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
11691187
ret = i915_vma_pin_fence(vma);
11701188
if (ret != 0 && INTEL_GEN(dev_priv) < 4) {
11711189
i915_vma_unpin(vma);
1172-
vma = ERR_PTR(ret);
1173-
goto err;
1190+
goto err_unpin;
11741191
}
1192+
ret = 0;
11751193

1176-
if (ret == 0 && vma->fence)
1194+
if (vma->fence)
11771195
*out_flags |= PLANE_HAS_FENCE;
11781196
}
11791197

11801198
i915_vma_get(vma);
1199+
1200+
err_unpin:
1201+
i915_gem_object_unpin_pages(obj);
11811202
err:
1203+
if (ret == -EDEADLK) {
1204+
ret = i915_gem_ww_ctx_backoff(&ww);
1205+
if (!ret)
1206+
goto retry;
1207+
}
1208+
i915_gem_ww_ctx_fini(&ww);
1209+
if (ret)
1210+
vma = ERR_PTR(ret);
1211+
11821212
atomic_dec(&dev_priv->gpu_error.pending_fb_pin);
11831213
intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
11841214
return vma;
@@ -11333,19 +11363,11 @@ int intel_plane_pin_fb(struct intel_plane_state *plane_state)
1133311363
struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1133411364
struct drm_framebuffer *fb = plane_state->hw.fb;
1133511365
struct i915_vma *vma;
11366+
bool phys_cursor =
11367+
plane->id == PLANE_CURSOR &&
11368+
INTEL_INFO(dev_priv)->display.cursor_needs_physical;
1133611369

11337-
if (plane->id == PLANE_CURSOR &&
11338-
INTEL_INFO(dev_priv)->display.cursor_needs_physical) {
11339-
struct drm_i915_gem_object *obj = intel_fb_obj(fb);
11340-
const int align = intel_cursor_alignment(dev_priv);
11341-
int err;
11342-
11343-
err = i915_gem_object_attach_phys(obj, align);
11344-
if (err)
11345-
return err;
11346-
}
11347-
11348-
vma = intel_pin_and_fence_fb_obj(fb,
11370+
vma = intel_pin_and_fence_fb_obj(fb, phys_cursor,
1134911371
&plane_state->view,
1135011372
intel_plane_uses_fence(plane_state),
1135111373
&plane_state->flags);
@@ -11437,13 +11459,8 @@ intel_prepare_plane_fb(struct drm_plane *_plane,
1143711459
if (!obj)
1143811460
return 0;
1143911461

11440-
ret = i915_gem_object_pin_pages(obj);
11441-
if (ret)
11442-
return ret;
1144311462

1144411463
ret = intel_plane_pin_fb(new_plane_state);
11445-
11446-
i915_gem_object_unpin_pages(obj);
1144711464
if (ret)
1144811465
return ret;
1144911466

drivers/gpu/drm/i915/display/intel_display.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ void intel_release_load_detect_pipe(struct drm_connector *connector,
573573
struct intel_load_detect_pipe *old,
574574
struct drm_modeset_acquire_ctx *ctx);
575575
struct i915_vma *
576-
intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
576+
intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb, bool phys_cursor,
577577
const struct i915_ggtt_view *view,
578578
bool uses_fence,
579579
unsigned long *out_flags);

drivers/gpu/drm/i915/display/intel_fbdev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ static int intelfb_create(struct drm_fb_helper *helper,
211211
* This also validates that any existing fb inherited from the
212212
* BIOS is suitable for own access.
213213
*/
214-
vma = intel_pin_and_fence_fb_obj(&ifbdev->fb->base,
214+
vma = intel_pin_and_fence_fb_obj(&ifbdev->fb->base, false,
215215
&view, false, &flags);
216216
if (IS_ERR(vma)) {
217217
ret = PTR_ERR(vma);

drivers/gpu/drm/i915/display/intel_overlay.c

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,32 @@ static u32 overlay_cmd_reg(struct drm_intel_overlay_put_image *params)
755755
return cmd;
756756
}
757757

758+
static struct i915_vma *intel_overlay_pin_fb(struct drm_i915_gem_object *new_bo)
759+
{
760+
struct i915_gem_ww_ctx ww;
761+
struct i915_vma *vma;
762+
int ret;
763+
764+
i915_gem_ww_ctx_init(&ww, true);
765+
retry:
766+
ret = i915_gem_object_lock(new_bo, &ww);
767+
if (!ret) {
768+
vma = i915_gem_object_pin_to_display_plane(new_bo, &ww, 0,
769+
NULL, PIN_MAPPABLE);
770+
ret = PTR_ERR_OR_ZERO(vma);
771+
}
772+
if (ret == -EDEADLK) {
773+
ret = i915_gem_ww_ctx_backoff(&ww);
774+
if (!ret)
775+
goto retry;
776+
}
777+
i915_gem_ww_ctx_fini(&ww);
778+
if (ret)
779+
return ERR_PTR(ret);
780+
781+
return vma;
782+
}
783+
758784
static int intel_overlay_do_put_image(struct intel_overlay *overlay,
759785
struct drm_i915_gem_object *new_bo,
760786
struct drm_intel_overlay_put_image *params)
@@ -776,12 +802,10 @@ static int intel_overlay_do_put_image(struct intel_overlay *overlay,
776802

777803
atomic_inc(&dev_priv->gpu_error.pending_fb_pin);
778804

779-
vma = i915_gem_object_pin_to_display_plane(new_bo,
780-
0, NULL, PIN_MAPPABLE);
781-
if (IS_ERR(vma)) {
782-
ret = PTR_ERR(vma);
805+
vma = intel_overlay_pin_fb(new_bo);
806+
if (IS_ERR(vma))
783807
goto out_pin_section;
784-
}
808+
785809
i915_gem_object_flush_frontbuffer(new_bo, ORIGIN_DIRTYFB);
786810

787811
if (!overlay->active) {

drivers/gpu/drm/i915/gem/i915_gem_domain.c

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -366,24 +366,19 @@ int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data,
366366
*/
367367
struct i915_vma *
368368
i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,
369+
struct i915_gem_ww_ctx *ww,
369370
u32 alignment,
370371
const struct i915_ggtt_view *view,
371372
unsigned int flags)
372373
{
373374
struct drm_i915_private *i915 = to_i915(obj->base.dev);
374-
struct i915_gem_ww_ctx ww;
375375
struct i915_vma *vma;
376376
int ret;
377377

378378
/* Frame buffer must be in LMEM (no migration yet) */
379379
if (HAS_LMEM(i915) && !i915_gem_object_is_lmem(obj))
380380
return ERR_PTR(-EINVAL);
381381

382-
i915_gem_ww_ctx_init(&ww, true);
383-
retry:
384-
ret = i915_gem_object_lock(obj, &ww);
385-
if (ret)
386-
goto err;
387382
/*
388383
* The display engine is not coherent with the LLC cache on gen6. As
389384
* a result, we make sure that the pinning that is about to occur is
@@ -398,7 +393,7 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,
398393
HAS_WT(i915) ?
399394
I915_CACHE_WT : I915_CACHE_NONE);
400395
if (ret)
401-
goto err;
396+
return ERR_PTR(ret);
402397

403398
/*
404399
* As the user may map the buffer once pinned in the display plane
@@ -411,33 +406,20 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,
411406
vma = ERR_PTR(-ENOSPC);
412407
if ((flags & PIN_MAPPABLE) == 0 &&
413408
(!view || view->type == I915_GGTT_VIEW_NORMAL))
414-
vma = i915_gem_object_ggtt_pin_ww(obj, &ww, view, 0, alignment,
409+
vma = i915_gem_object_ggtt_pin_ww(obj, ww, view, 0, alignment,
415410
flags | PIN_MAPPABLE |
416411
PIN_NONBLOCK);
417412
if (IS_ERR(vma) && vma != ERR_PTR(-EDEADLK))
418-
vma = i915_gem_object_ggtt_pin_ww(obj, &ww, view, 0,
413+
vma = i915_gem_object_ggtt_pin_ww(obj, ww, view, 0,
419414
alignment, flags);
420-
if (IS_ERR(vma)) {
421-
ret = PTR_ERR(vma);
422-
goto err;
423-
}
415+
if (IS_ERR(vma))
416+
return vma;
424417

425418
vma->display_alignment = max_t(u64, vma->display_alignment, alignment);
426419
i915_vma_mark_scanout(vma);
427420

428421
i915_gem_object_flush_if_display_locked(obj);
429422

430-
err:
431-
if (ret == -EDEADLK) {
432-
ret = i915_gem_ww_ctx_backoff(&ww);
433-
if (!ret)
434-
goto retry;
435-
}
436-
i915_gem_ww_ctx_fini(&ww);
437-
438-
if (ret)
439-
return ERR_PTR(ret);
440-
441423
return vma;
442424
}
443425

drivers/gpu/drm/i915/gem/i915_gem_object.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ int __must_check
484484
i915_gem_object_set_to_cpu_domain(struct drm_i915_gem_object *obj, bool write);
485485
struct i915_vma * __must_check
486486
i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,
487+
struct i915_gem_ww_ctx *ww,
487488
u32 alignment,
488489
const struct i915_ggtt_view *view,
489490
unsigned int flags);

drivers/gpu/drm/i915/gem/i915_gem_phys.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ int i915_gem_object_attach_phys(struct drm_i915_gem_object *obj, int align)
219219
{
220220
int err;
221221

222+
assert_object_held(obj);
223+
222224
if (align > obj->base.size)
223225
return -EINVAL;
224226

@@ -232,13 +234,9 @@ int i915_gem_object_attach_phys(struct drm_i915_gem_object *obj, int align)
232234
if (err)
233235
return err;
234236

235-
err = i915_gem_object_lock_interruptible(obj, NULL);
236-
if (err)
237-
return err;
238-
239237
err = mutex_lock_interruptible(&obj->mm.lock);
240238
if (err)
241-
goto err_unlock;
239+
return err;
242240

243241
if (unlikely(!i915_gem_object_has_struct_page(obj)))
244242
goto out;
@@ -269,8 +267,6 @@ int i915_gem_object_attach_phys(struct drm_i915_gem_object *obj, int align)
269267

270268
out:
271269
mutex_unlock(&obj->mm.lock);
272-
err_unlock:
273-
i915_gem_object_unlock(obj);
274270
return err;
275271
}
276272

drivers/gpu/drm/i915/gem/selftests/i915_gem_phys.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ static int mock_phys_object(void *arg)
3131
goto out_obj;
3232
}
3333

34+
i915_gem_object_lock(obj, NULL);
3435
err = i915_gem_object_attach_phys(obj, PAGE_SIZE);
36+
i915_gem_object_unlock(obj);
3537
if (err) {
3638
pr_err("i915_gem_object_attach_phys failed, err=%d\n", err);
3739
goto out_obj;

0 commit comments

Comments
 (0)