Commit afd65eb4 authored by Matt Roper's avatar Matt Roper Committed by Daniel Vetter

drm/i915: Ensure plane->state->fb stays in sync with plane->fb

plane->state->fb and plane->fb should always reference the same FB so
that atomic and legacy codepaths have the same view of display state.
In commit

        commit db068420560511de80ac59222644f2bdf278c3d5
        Author: Matt Roper <matthew.d.roper@intel.com>
        Date:   Fri Jan 30 16:22:36 2015 -0800

            drm/i915: Keep plane->state updated on pageflip

we already fixed one case where these two pointers could get out of
sync.  However it turns out there are a few other places (mainly dealing
with initial FB setup at boot) that directly set plane->fb and neglect
to update plane->state->fb.  If we never do a successful update through
the atomic pipeline, the RmFB cleanup code will look at the
plane->state->fb pointer, which has never actually been set to a
legitimate value, and try to clean it up, leading to BUG's.

Add a quick helper function to synchronize plane->state->fb with
plane->fb (and update reference counts accordingly) and call it
everywhere the driver tries to manually set plane->fb outside of the
atomic pipeline.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=88909Signed-off-by: default avatarMatt Roper <matthew.d.roper@intel.com>
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
parent 62659920
...@@ -2410,6 +2410,20 @@ intel_alloc_plane_obj(struct intel_crtc *crtc, ...@@ -2410,6 +2410,20 @@ intel_alloc_plane_obj(struct intel_crtc *crtc,
return false; return false;
} }
/* Update plane->state->fb to match plane->fb after driver-internal updates */
static void
update_state_fb(struct drm_plane *plane)
{
if (plane->fb == plane->state->fb)
return;
if (plane->state->fb)
drm_framebuffer_unreference(plane->state->fb);
plane->state->fb = plane->fb;
if (plane->state->fb)
drm_framebuffer_reference(plane->state->fb);
}
static void static void
intel_find_plane_obj(struct intel_crtc *intel_crtc, intel_find_plane_obj(struct intel_crtc *intel_crtc,
struct intel_initial_plane_config *plane_config) struct intel_initial_plane_config *plane_config)
...@@ -2456,6 +2470,8 @@ intel_find_plane_obj(struct intel_crtc *intel_crtc, ...@@ -2456,6 +2470,8 @@ intel_find_plane_obj(struct intel_crtc *intel_crtc,
break; break;
} }
} }
update_state_fb(intel_crtc->base.primary);
} }
static void i9xx_update_primary_plane(struct drm_crtc *crtc, static void i9xx_update_primary_plane(struct drm_crtc *crtc,
...@@ -6635,6 +6651,7 @@ i9xx_get_initial_plane_config(struct intel_crtc *crtc, ...@@ -6635,6 +6651,7 @@ i9xx_get_initial_plane_config(struct intel_crtc *crtc,
plane_config->size); plane_config->size);
crtc->base.primary->fb = fb; crtc->base.primary->fb = fb;
update_state_fb(crtc->base.primary);
} }
static void chv_crtc_clock_get(struct intel_crtc *crtc, static void chv_crtc_clock_get(struct intel_crtc *crtc,
...@@ -7672,6 +7689,7 @@ skylake_get_initial_plane_config(struct intel_crtc *crtc, ...@@ -7672,6 +7689,7 @@ skylake_get_initial_plane_config(struct intel_crtc *crtc,
plane_config->size); plane_config->size);
crtc->base.primary->fb = fb; crtc->base.primary->fb = fb;
update_state_fb(crtc->base.primary);
return; return;
error: error:
...@@ -7763,6 +7781,7 @@ ironlake_get_initial_plane_config(struct intel_crtc *crtc, ...@@ -7763,6 +7781,7 @@ ironlake_get_initial_plane_config(struct intel_crtc *crtc,
plane_config->size); plane_config->size);
crtc->base.primary->fb = fb; crtc->base.primary->fb = fb;
update_state_fb(crtc->base.primary);
} }
static bool ironlake_get_pipe_config(struct intel_crtc *crtc, static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
...@@ -9800,13 +9819,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc, ...@@ -9800,13 +9819,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
drm_gem_object_reference(&obj->base); drm_gem_object_reference(&obj->base);
crtc->primary->fb = fb; crtc->primary->fb = fb;
update_state_fb(crtc->primary);
/* Keep state structure in sync */
if (crtc->primary->state->fb)
drm_framebuffer_unreference(crtc->primary->state->fb);
crtc->primary->state->fb = fb;
if (crtc->primary->state->fb)
drm_framebuffer_reference(crtc->primary->state->fb);
work->pending_flip_obj = obj; work->pending_flip_obj = obj;
...@@ -9875,6 +9888,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc, ...@@ -9875,6 +9888,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
cleanup_pending: cleanup_pending:
atomic_dec(&intel_crtc->unpin_work_count); atomic_dec(&intel_crtc->unpin_work_count);
crtc->primary->fb = old_fb; crtc->primary->fb = old_fb;
update_state_fb(crtc->primary);
drm_framebuffer_unreference(work->old_fb); drm_framebuffer_unreference(work->old_fb);
drm_gem_object_unreference(&obj->base); drm_gem_object_unreference(&obj->base);
mutex_unlock(&dev->struct_mutex); mutex_unlock(&dev->struct_mutex);
...@@ -13709,6 +13723,7 @@ void intel_modeset_gem_init(struct drm_device *dev) ...@@ -13709,6 +13723,7 @@ void intel_modeset_gem_init(struct drm_device *dev)
to_intel_crtc(c)->pipe); to_intel_crtc(c)->pipe);
drm_framebuffer_unreference(c->primary->fb); drm_framebuffer_unreference(c->primary->fb);
c->primary->fb = NULL; c->primary->fb = NULL;
update_state_fb(c->primary);
} }
} }
mutex_unlock(&dev->struct_mutex); mutex_unlock(&dev->struct_mutex);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment