Skip to content

Commit ef1a191

Browse files
committed
drm/i915: Extract intel_plane_{pin,unpin}_fb()
We've replicated the fb pin/unpin code in a few places. Pull it into convenint helpers. Slight change in locking behaviour as intel_cleanup_plane_fb() now grab struct_mutex unconditionally. v2: Change the locking to be symmetric between pin and unpin Cc: Chris Wilson <chris@chris-wilson.co.uk> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20180221160235.11134-6-ville.syrjala@linux.intel.com Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
1 parent 32febd9 commit ef1a191

File tree

1 file changed

+45
-51
lines changed

1 file changed

+45
-51
lines changed

drivers/gpu/drm/i915/intel_display.c

Lines changed: 45 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -12656,6 +12656,42 @@ static void add_rps_boost_after_vblank(struct drm_crtc *crtc,
1265612656
add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait);
1265712657
}
1265812658

12659+
static int intel_plane_pin_fb(struct intel_plane_state *plane_state)
12660+
{
12661+
struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
12662+
struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
12663+
struct drm_framebuffer *fb = plane_state->base.fb;
12664+
struct i915_vma *vma;
12665+
12666+
if (plane->id == PLANE_CURSOR &&
12667+
INTEL_INFO(dev_priv)->cursor_needs_physical) {
12668+
struct drm_i915_gem_object *obj = intel_fb_obj(fb);
12669+
const int align = intel_cursor_alignment(dev_priv);
12670+
12671+
return i915_gem_object_attach_phys(obj, align);
12672+
}
12673+
12674+
vma = intel_pin_and_fence_fb_obj(fb,
12675+
plane_state->base.rotation,
12676+
intel_plane_uses_fence(plane_state),
12677+
&plane_state->flags);
12678+
if (IS_ERR(vma))
12679+
return PTR_ERR(vma);
12680+
12681+
plane_state->vma = vma;
12682+
12683+
return 0;
12684+
}
12685+
12686+
static void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state)
12687+
{
12688+
struct i915_vma *vma;
12689+
12690+
vma = fetch_and_zero(&old_plane_state->vma);
12691+
if (vma)
12692+
intel_unpin_fb_vma(vma, old_plane_state->flags);
12693+
}
12694+
1265912695
/**
1266012696
* intel_prepare_plane_fb - Prepare fb for usage on plane
1266112697
* @plane: drm plane to prepare for
@@ -12730,23 +12766,7 @@ intel_prepare_plane_fb(struct drm_plane *plane,
1273012766
return ret;
1273112767
}
1273212768

12733-
if (plane->type == DRM_PLANE_TYPE_CURSOR &&
12734-
INTEL_INFO(dev_priv)->cursor_needs_physical) {
12735-
const int align = intel_cursor_alignment(dev_priv);
12736-
12737-
ret = i915_gem_object_attach_phys(obj, align);
12738-
} else {
12739-
struct i915_vma *vma;
12740-
12741-
vma = intel_pin_and_fence_fb_obj(fb,
12742-
new_state->rotation,
12743-
intel_plane_uses_fence(to_intel_plane_state(new_state)),
12744-
&to_intel_plane_state(new_state)->flags);
12745-
if (!IS_ERR(vma))
12746-
to_intel_plane_state(new_state)->vma = vma;
12747-
else
12748-
ret = PTR_ERR(vma);
12749-
}
12769+
ret = intel_plane_pin_fb(to_intel_plane_state(new_state));
1275012770

1275112771
i915_gem_object_wait_priority(obj, 0, I915_PRIORITY_DISPLAY);
1275212772

@@ -12790,15 +12810,12 @@ void
1279012810
intel_cleanup_plane_fb(struct drm_plane *plane,
1279112811
struct drm_plane_state *old_state)
1279212812
{
12793-
struct i915_vma *vma;
12813+
struct drm_i915_private *dev_priv = to_i915(plane->dev);
1279412814

1279512815
/* Should only be called after a successful intel_prepare_plane_fb()! */
12796-
vma = fetch_and_zero(&to_intel_plane_state(old_state)->vma);
12797-
if (vma) {
12798-
mutex_lock(&plane->dev->struct_mutex);
12799-
intel_unpin_fb_vma(vma, to_intel_plane_state(old_state)->flags);
12800-
mutex_unlock(&plane->dev->struct_mutex);
12801-
}
12816+
mutex_lock(&dev_priv->drm.struct_mutex);
12817+
intel_plane_unpin_fb(to_intel_plane_state(old_state));
12818+
mutex_unlock(&dev_priv->drm.struct_mutex);
1280212819
}
1280312820

1280412821
int
@@ -13084,7 +13101,6 @@ intel_legacy_cursor_update(struct drm_plane *plane,
1308413101
struct intel_plane *intel_plane = to_intel_plane(plane);
1308513102
struct drm_framebuffer *old_fb;
1308613103
struct drm_crtc_state *crtc_state = crtc->state;
13087-
struct i915_vma *old_vma, *vma;
1308813104

1308913105
/*
1309013106
* When crtc is inactive or there is a modeset pending,
@@ -13143,28 +13159,9 @@ intel_legacy_cursor_update(struct drm_plane *plane,
1314313159
if (ret)
1314413160
goto out_free;
1314513161

13146-
if (INTEL_INFO(dev_priv)->cursor_needs_physical) {
13147-
int align = intel_cursor_alignment(dev_priv);
13148-
13149-
ret = i915_gem_object_attach_phys(intel_fb_obj(fb), align);
13150-
if (ret) {
13151-
DRM_DEBUG_KMS("failed to attach phys object\n");
13152-
goto out_unlock;
13153-
}
13154-
} else {
13155-
vma = intel_pin_and_fence_fb_obj(fb,
13156-
new_plane_state->rotation,
13157-
false,
13158-
&to_intel_plane_state(new_plane_state)->flags);
13159-
if (IS_ERR(vma)) {
13160-
DRM_DEBUG_KMS("failed to pin object\n");
13161-
13162-
ret = PTR_ERR(vma);
13163-
goto out_unlock;
13164-
}
13165-
13166-
to_intel_plane_state(new_plane_state)->vma = vma;
13167-
}
13162+
ret = intel_plane_pin_fb(to_intel_plane_state(new_plane_state));
13163+
if (ret)
13164+
goto out_unlock;
1316813165

1316913166
old_fb = old_plane_state->fb;
1317013167

@@ -13184,10 +13181,7 @@ intel_legacy_cursor_update(struct drm_plane *plane,
1318413181
intel_plane->disable_plane(intel_plane, to_intel_crtc(crtc));
1318513182
}
1318613183

13187-
old_vma = fetch_and_zero(&to_intel_plane_state(old_plane_state)->vma);
13188-
if (old_vma)
13189-
intel_unpin_fb_vma(old_vma,
13190-
to_intel_plane_state(old_plane_state)->flags);
13184+
intel_plane_unpin_fb(to_intel_plane_state(old_plane_state));
1319113185

1319213186
out_unlock:
1319313187
mutex_unlock(&dev_priv->drm.struct_mutex);

0 commit comments

Comments
 (0)