[Intel-gfx] [PATCH v1.1 2/5] drm/atomic: Make prepare_fb/cleanup_fb only take state, v2.

Rob Clark robdclark at gmail.com
Wed Jul 22 06:23:27 PDT 2015


On Thu, Jul 16, 2015 at 10:13 AM, Maarten Lankhorst
<maarten.lankhorst at linux.intel.com> wrote:
> This removes the need to separately track fb changes i915.
>
> Changes since v1:
> - Add dri-devel to cc.
> - Fix a check in intel's prepare and cleanup fb to take rotation
>   into account.
>
> Cc: dri-devel at lists.freedesktop.org
> Signed-off-by: Maarten Lankhorst <maarten.lankhorst at linux.intel.com>

Reviewed-by: Rob Clark <robdclark at gmail.com>

> ---
> diff --git a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c
> index be9fa8220499..36fda86b3518 100644
> --- a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c
> +++ b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c
> @@ -712,11 +712,13 @@ static int atmel_hlcdc_plane_atomic_check(struct drm_plane *p,
>  }
>
>  static int atmel_hlcdc_plane_prepare_fb(struct drm_plane *p,
> -                                       struct drm_framebuffer *fb,
>                                         const struct drm_plane_state *new_state)
>  {
>         struct atmel_hlcdc_plane *plane = drm_plane_to_atmel_hlcdc_plane(p);
>
> +       if (!new_state->fb)
> +               return 0;
> +
>         return atmel_hlcdc_layer_update_start(&plane->layer);
>  }
>
> diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c
> index 0898afbc9e23..e52dfc828e60 100644
> --- a/drivers/gpu/drm/drm_atomic_helper.c
> +++ b/drivers/gpu/drm/drm_atomic_helper.c
> @@ -1063,17 +1063,14 @@ int drm_atomic_helper_prepare_planes(struct drm_device *dev,
>                 const struct drm_plane_helper_funcs *funcs;
>                 struct drm_plane *plane = state->planes[i];
>                 struct drm_plane_state *plane_state = state->plane_states[i];
> -               struct drm_framebuffer *fb;
>
>                 if (!plane)
>                         continue;
>
>                 funcs = plane->helper_private;
>
> -               fb = plane_state->fb;
> -
> -               if (fb && funcs->prepare_fb) {
> -                       ret = funcs->prepare_fb(plane, fb, plane_state);
> +               if (funcs->prepare_fb) {
> +                       ret = funcs->prepare_fb(plane, plane_state);
>                         if (ret)
>                                 goto fail;
>                 }
> @@ -1086,17 +1083,14 @@ fail:
>                 const struct drm_plane_helper_funcs *funcs;
>                 struct drm_plane *plane = state->planes[i];
>                 struct drm_plane_state *plane_state = state->plane_states[i];
> -               struct drm_framebuffer *fb;
>
>                 if (!plane)
>                         continue;
>
>                 funcs = plane->helper_private;
>
> -               fb = state->plane_states[i]->fb;
> -
> -               if (fb && funcs->cleanup_fb)
> -                       funcs->cleanup_fb(plane, fb, plane_state);
> +               if (funcs->cleanup_fb)
> +                       funcs->cleanup_fb(plane, plane_state);
>
>         }
>
> @@ -1252,14 +1246,11 @@ void drm_atomic_helper_cleanup_planes(struct drm_device *dev,
>
>         for_each_plane_in_state(old_state, plane, plane_state, i) {
>                 const struct drm_plane_helper_funcs *funcs;
> -               struct drm_framebuffer *old_fb;
>
>                 funcs = plane->helper_private;
>
> -               old_fb = plane_state->fb;
> -
> -               if (old_fb && funcs->cleanup_fb)
> -                       funcs->cleanup_fb(plane, old_fb, plane_state);
> +               if (funcs->cleanup_fb)
> +                       funcs->cleanup_fb(plane, plane_state);
>         }
>  }
>  EXPORT_SYMBOL(drm_atomic_helper_cleanup_planes);
> diff --git a/drivers/gpu/drm/drm_plane_helper.c b/drivers/gpu/drm/drm_plane_helper.c
> index b07a213f5655..03b7afe455e6 100644
> --- a/drivers/gpu/drm/drm_plane_helper.c
> +++ b/drivers/gpu/drm/drm_plane_helper.c
> @@ -425,7 +425,7 @@ int drm_plane_helper_commit(struct drm_plane *plane,
>
>         if (plane_funcs->prepare_fb && plane_state->fb &&
>             plane_state->fb != old_fb) {
> -               ret = plane_funcs->prepare_fb(plane, plane_state->fb,
> +               ret = plane_funcs->prepare_fb(plane,
>                                               plane_state);
>                 if (ret)
>                         goto out;
> @@ -478,8 +478,8 @@ int drm_plane_helper_commit(struct drm_plane *plane,
>                 ret = 0;
>         }
>
> -       if (plane_funcs->cleanup_fb && old_fb)
> -               plane_funcs->cleanup_fb(plane, old_fb, plane_state);
> +       if (plane_funcs->cleanup_fb)
> +               plane_funcs->cleanup_fb(plane, plane_state);
>  out:
>         if (plane_state) {
>                 if (plane->funcs->atomic_destroy_state)
> diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
> index 7dbfeacf0f38..b3990264e137 100644
> --- a/drivers/gpu/drm/i915/intel_display.c
> +++ b/drivers/gpu/drm/i915/intel_display.c
> @@ -4775,17 +4775,6 @@ static void intel_pre_plane_update(struct intel_crtc *crtc)
>         struct drm_device *dev = crtc->base.dev;
>         struct drm_i915_private *dev_priv = dev->dev_private;
>         struct intel_crtc_atomic_commit *atomic = &crtc->atomic;
> -       struct drm_plane *p;
> -
> -       /* Track fb's for any planes being disabled */
> -       drm_for_each_plane_mask(p, dev, atomic->disabled_planes) {
> -               struct intel_plane *plane = to_intel_plane(p);
> -
> -               mutex_lock(&dev->struct_mutex);
> -               i915_gem_track_fb(intel_fb_obj(plane->base.fb), NULL,
> -                                 plane->frontbuffer_bit);
> -               mutex_unlock(&dev->struct_mutex);
> -       }
>
>         if (atomic->wait_for_flips)
>                 intel_crtc_wait_for_pending_flips(&crtc->base);
> @@ -11668,14 +11657,6 @@ int intel_plane_atomic_calc_changes(struct drm_crtc_state *crtc_state,
>                         return ret;
>         }
>
> -       /*
> -        * Disabling a plane is always okay; we just need to update
> -        * fb tracking in a special way since cleanup_fb() won't
> -        * get called by the plane helpers.
> -        */
> -       if (old_plane_state->base.fb && !fb)
> -               intel_crtc->atomic.disabled_planes |= 1 << i;
> -
>         was_visible = old_plane_state->visible;
>         visible = to_intel_plane_state(plane_state)->visible;
>
> @@ -13479,21 +13460,26 @@ static void intel_shared_dpll_init(struct drm_device *dev)
>   */
>  int
>  intel_prepare_plane_fb(struct drm_plane *plane,
> -                      struct drm_framebuffer *fb,
>                        const struct drm_plane_state *new_state)
>  {
>         struct drm_device *dev = plane->dev;
> +       struct drm_framebuffer *fb = new_state->fb;
>         struct intel_plane *intel_plane = to_intel_plane(plane);
>         struct drm_i915_gem_object *obj = intel_fb_obj(fb);
> -       struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->fb);
> +       struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->state->fb);
>         int ret = 0;
>
> -       if (!obj)
> +       if (!obj && !old_obj)
> +               return 0;
> +
> +       if (obj == old_obj && new_state->rotation == plane->state->rotation)
>                 return 0;
>
>         mutex_lock(&dev->struct_mutex);
>
> -       if (plane->type == DRM_PLANE_TYPE_CURSOR &&
> +       if (!obj) {
> +               ret = 0;
> +       } else if (plane->type == DRM_PLANE_TYPE_CURSOR &&
>             INTEL_INFO(dev)->cursor_needs_physical) {
>                 int align = IS_I830(dev) ? 16 * 1024 : 256;
>                 ret = i915_gem_object_attach_phys(obj, align);
> @@ -13520,21 +13506,29 @@ intel_prepare_plane_fb(struct drm_plane *plane,
>   */
>  void
>  intel_cleanup_plane_fb(struct drm_plane *plane,
> -                      struct drm_framebuffer *fb,
>                        const struct drm_plane_state *old_state)
>  {
>         struct drm_device *dev = plane->dev;
> -       struct drm_i915_gem_object *obj = intel_fb_obj(fb);
> +       struct intel_plane *intel_plane = to_intel_plane(plane);
> +       struct drm_i915_gem_object *old_obj = intel_fb_obj(old_state->fb);
> +       struct drm_i915_gem_object *obj = intel_fb_obj(plane->fb);
>
> -       if (WARN_ON(!obj))
> +       if (!obj && !old_obj)
>                 return;
>
> -       if (plane->type != DRM_PLANE_TYPE_CURSOR ||
> -           !INTEL_INFO(dev)->cursor_needs_physical) {
> -               mutex_lock(&dev->struct_mutex);
> -               intel_unpin_fb_obj(fb, old_state);
> -               mutex_unlock(&dev->struct_mutex);
> -       }
> +       if (obj == old_obj && old_state->rotation == plane->state->rotation)
> +               return;
> +
> +       mutex_lock(&dev->struct_mutex);
> +       if (old_obj && (plane->type != DRM_PLANE_TYPE_CURSOR ||
> +           !INTEL_INFO(dev)->cursor_needs_physical))
> +               intel_unpin_fb_obj(old_state->fb, old_state);
> +
> +       /* prepare_fb aborted? */
> +       if ((old_obj && (old_obj->frontbuffer_bits & intel_plane->frontbuffer_bit)) ||
> +           (obj && !(obj->frontbuffer_bits & intel_plane->frontbuffer_bit)))
> +               i915_gem_track_fb(old_obj, obj, intel_plane->frontbuffer_bit);
> +       mutex_unlock(&dev->struct_mutex);
>  }
>
>  int
> diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
> index 3b00d00c0bc0..bee8a9669482 100644
> --- a/drivers/gpu/drm/i915/intel_drv.h
> +++ b/drivers/gpu/drm/i915/intel_drv.h
> @@ -497,7 +497,6 @@ struct intel_crtc_atomic_commit {
>         bool disable_cxsr;
>         bool pre_disable_primary;
>         bool update_wm_pre, update_wm_post;
> -       unsigned disabled_planes;
>
>         /* Sleepable operations to perform after commit */
>         unsigned fb_bits;
> @@ -1039,10 +1038,8 @@ void intel_finish_page_flip(struct drm_device *dev, int pipe);
>  void intel_finish_page_flip_plane(struct drm_device *dev, int plane);
>  void intel_check_page_flip(struct drm_device *dev, int pipe);
>  int intel_prepare_plane_fb(struct drm_plane *plane,
> -                          struct drm_framebuffer *fb,
>                            const struct drm_plane_state *new_state);
>  void intel_cleanup_plane_fb(struct drm_plane *plane,
> -                           struct drm_framebuffer *fb,
>                             const struct drm_plane_state *old_state);
>  int intel_plane_atomic_get_property(struct drm_plane *plane,
>                                     const struct drm_plane_state *state,
> diff --git a/drivers/gpu/drm/msm/mdp/mdp4/mdp4_plane.c b/drivers/gpu/drm/msm/mdp/mdp4/mdp4_plane.c
> index 0d1dbb737933..60e83c3765c2 100644
> --- a/drivers/gpu/drm/msm/mdp/mdp4/mdp4_plane.c
> +++ b/drivers/gpu/drm/msm/mdp/mdp4/mdp4_plane.c
> @@ -98,22 +98,28 @@ static const struct drm_plane_funcs mdp4_plane_funcs = {
>  };
>
>  static int mdp4_plane_prepare_fb(struct drm_plane *plane,
> -               struct drm_framebuffer *fb,
>                 const struct drm_plane_state *new_state)
>  {
>         struct mdp4_plane *mdp4_plane = to_mdp4_plane(plane);
>         struct mdp4_kms *mdp4_kms = get_kms(plane);
> +       struct drm_framebuffer *fb = new_state->fb;
> +
> +       if (!fb)
> +               return 0;
>
>         DBG("%s: prepare: FB[%u]", mdp4_plane->name, fb->base.id);
>         return msm_framebuffer_prepare(fb, mdp4_kms->id);
>  }
>
>  static void mdp4_plane_cleanup_fb(struct drm_plane *plane,
> -               struct drm_framebuffer *fb,
>                 const struct drm_plane_state *old_state)
>  {
>         struct mdp4_plane *mdp4_plane = to_mdp4_plane(plane);
>         struct mdp4_kms *mdp4_kms = get_kms(plane);
> +       struct drm_framebuffer *fb = old_state->fb;
> +
> +       if (!fb)
> +               return;
>
>         DBG("%s: cleanup: FB[%u]", mdp4_plane->name, fb->base.id);
>         msm_framebuffer_cleanup(fb, mdp4_kms->id);
> diff --git a/drivers/gpu/drm/msm/mdp/mdp5/mdp5_plane.c b/drivers/gpu/drm/msm/mdp/mdp5/mdp5_plane.c
> index 57b8f56ae9d0..d0f627b962f3 100644
> --- a/drivers/gpu/drm/msm/mdp/mdp5/mdp5_plane.c
> +++ b/drivers/gpu/drm/msm/mdp/mdp5/mdp5_plane.c
> @@ -156,11 +156,14 @@ static const struct drm_plane_funcs mdp5_plane_funcs = {
>  };
>
>  static int mdp5_plane_prepare_fb(struct drm_plane *plane,
> -               struct drm_framebuffer *fb,
>                 const struct drm_plane_state *new_state)
>  {
>         struct mdp5_plane *mdp5_plane = to_mdp5_plane(plane);
>         struct mdp5_kms *mdp5_kms = get_kms(plane);
> +       struct drm_framebuffer *fb = new_state->fb;
> +
> +       if (!new_state->fb)
> +               return 0;
>
>         DBG("%s: prepare: FB[%u]", mdp5_plane->name, fb->base.id);
>         return msm_framebuffer_prepare(fb, mdp5_kms->id);
> @@ -172,6 +175,10 @@ static void mdp5_plane_cleanup_fb(struct drm_plane *plane,
>  {
>         struct mdp5_plane *mdp5_plane = to_mdp5_plane(plane);
>         struct mdp5_kms *mdp5_kms = get_kms(plane);
> +       struct drm_framebuffer *fb = old_state->fb;
> +
> +       if (!fb)
> +               return;
>
>         DBG("%s: cleanup: FB[%u]", mdp5_plane->name, fb->base.id);
>         msm_framebuffer_cleanup(fb, mdp5_kms->id);
> diff --git a/drivers/gpu/drm/omapdrm/omap_plane.c b/drivers/gpu/drm/omapdrm/omap_plane.c
> index 098904696a5c..09e363bb55f2 100644
> --- a/drivers/gpu/drm/omapdrm/omap_plane.c
> +++ b/drivers/gpu/drm/omapdrm/omap_plane.c
> @@ -60,17 +60,19 @@ to_omap_plane_state(struct drm_plane_state *state)
>  }
>
>  static int omap_plane_prepare_fb(struct drm_plane *plane,
> -                                struct drm_framebuffer *fb,
>                                  const struct drm_plane_state *new_state)
>  {
> -       return omap_framebuffer_pin(fb);
> +       if (!new_state->fb)
> +               return 0;
> +
> +       return omap_framebuffer_pin(new_state->fb);
>  }
>
>  static void omap_plane_cleanup_fb(struct drm_plane *plane,
> -                                 struct drm_framebuffer *fb,
>                                   const struct drm_plane_state *old_state)
>  {
> -       omap_framebuffer_unpin(fb);
> +       if (old_state->fb)
> +               omap_framebuffer_unpin(old_state->fb);
>  }
>
>  static void omap_plane_atomic_update(struct drm_plane *plane,
> diff --git a/drivers/gpu/drm/sti/sti_drm_plane.c b/drivers/gpu/drm/sti/sti_drm_plane.c
> index 64d4ed43dda3..f3717292e748 100644
> --- a/drivers/gpu/drm/sti/sti_drm_plane.c
> +++ b/drivers/gpu/drm/sti/sti_drm_plane.c
> @@ -147,14 +147,12 @@ static struct drm_plane_funcs sti_drm_plane_funcs = {
>  };
>
>  static int sti_drm_plane_prepare_fb(struct drm_plane *plane,
> -                                 struct drm_framebuffer *fb,
>                                   const struct drm_plane_state *new_state)
>  {
>         return 0;
>  }
>
>  static void sti_drm_plane_cleanup_fb(struct drm_plane *plane,
> -                                  struct drm_framebuffer *fb,
>                                    const struct drm_plane_state *old_fb)
>  {
>  }
> diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
> index a287e4fec865..d447701173e6 100644
> --- a/drivers/gpu/drm/tegra/dc.c
> +++ b/drivers/gpu/drm/tegra/dc.c
> @@ -472,14 +472,12 @@ static const struct drm_plane_funcs tegra_primary_plane_funcs = {
>  };
>
>  static int tegra_plane_prepare_fb(struct drm_plane *plane,
> -                                 struct drm_framebuffer *fb,
>                                   const struct drm_plane_state *new_state)
>  {
>         return 0;
>  }
>
>  static void tegra_plane_cleanup_fb(struct drm_plane *plane,
> -                                  struct drm_framebuffer *fb,
>                                    const struct drm_plane_state *old_fb)
>  {
>  }
> diff --git a/include/drm/drm_plane_helper.h b/include/drm/drm_plane_helper.h
> index 96e16283afb9..5ffca4e51e40 100644
> --- a/include/drm/drm_plane_helper.h
> +++ b/include/drm/drm_plane_helper.h
> @@ -59,10 +59,8 @@ extern int drm_crtc_init(struct drm_device *dev,
>   */
>  struct drm_plane_helper_funcs {
>         int (*prepare_fb)(struct drm_plane *plane,
> -                         struct drm_framebuffer *fb,
>                           const struct drm_plane_state *new_state);
>         void (*cleanup_fb)(struct drm_plane *plane,
> -                          struct drm_framebuffer *fb,
>                            const struct drm_plane_state *old_state);
>
>         int (*atomic_check)(struct drm_plane *plane,
>
> _______________________________________________
> dri-devel mailing list
> dri-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel


More information about the Intel-gfx mailing list