Re: [PATCH v3 06/10] drm: rcar-du: Handle CRTC configuration from commit tail handler

2019-06-18 Thread Ulrich Hecht


> On June 17, 2019 at 11:09 PM Laurent Pinchart 
>  wrote:
> 
> 
> From: Kieran Bingham 
> 
> The CRTC mode setting and routing configuration are performed at the
> earliest of atomic enable and atomic begin, to ensure that a valid
> configuration is applied to the hardware before the CRTC gets enabled
> and before planes are setup (the latter being required in particular by
> the VSP). This requires the rcar_du_crtc structure to track the CRTC
> enabled state.
> 
> Simplify the code and remove the manual state tracking by moving CRTC
> setup to a new rcar_du_crtc_atomic_modeset() function, called directly
> from the commit tail handler. The function iterates over all CRTCs in
> the state transaction and performs CRTC mode setting, routing
> configuration and VSP configuration.
> 
> drm_crtc_vblank_on() has to be called from the atomic begin handler, to
> ensure that vertical blanking reporting is enabled before the call to
> drm_crtc_vblank_get() in the atomic flush handler. As the
> drm_crtc_vblank_on() and drm_crtc_vblank_off() calls don't need to be
> balanced this is not an issue. A balanced alternative would have been to
> call drm_crtc_vblank_on() and drm_crtc_vblank_off() from the CRTC exit
> and enter standby handlers respectively, but
> drm_atomic_helper_commit_modeset_disables() complains if
> drm_crtc_vblank_off() hasn't been called by the atomic disable handler.
> 
> As a result, the vsp1_du_atomic_flush() operation can be called with the
> DRM pipeline disabled. Correct operation has been ensured by "media:
> vsp1: drm: Don't configure hardware when the pipeline is disabled".
> 
> Signed-off-by: Kieran Bingham 
> Signed-off-by: Laurent Pinchart 
> ---
> Changes since v2:
> 
> - Deconstruct rcar_du_crtc_setup() completely
> ---
>  drivers/gpu/drm/rcar-du/rcar_du_crtc.c | 89 +++---
>  drivers/gpu/drm/rcar-du/rcar_du_crtc.h |  4 +-
>  drivers/gpu/drm/rcar-du/rcar_du_kms.c  |  1 +
>  3 files changed, 42 insertions(+), 52 deletions(-)
> 
> diff --git a/drivers/gpu/drm/rcar-du/rcar_du_crtc.c 
> b/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
> index 23f4bdef0e3a..d11a474f6f72 100644
> --- a/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
> +++ b/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
> @@ -478,22 +478,6 @@ static void rcar_du_crtc_wait_page_flip(struct 
> rcar_du_crtc *rcrtc)
>   * Start/Stop and Suspend/Resume
>   */
>  
> -static void rcar_du_crtc_setup(struct rcar_du_crtc *rcrtc)
> -{
> - /* Configure display timings and output routing */
> - rcar_du_crtc_set_display_timing(rcrtc);
> - rcar_du_group_set_routing(rcrtc->group);
> -
> - /* Enable the VSP compositor. */
> - if (rcar_du_has(rcrtc->dev, RCAR_DU_FEATURE_VSP1_SOURCE)) {
> - rcar_du_vsp_modeset(rcrtc);
> - rcar_du_vsp_enable(rcrtc);
> - }
> -
> - /* Turn vertical blanking interrupt reporting on. */
> - drm_crtc_vblank_on(&rcrtc->crtc);
> -}
> -
>  static int rcar_du_crtc_exit_standby(struct rcar_du_crtc *rcrtc)
>  {
>   int ret;
> @@ -534,24 +518,6 @@ static void rcar_du_crtc_enter_standby(struct 
> rcar_du_crtc *rcrtc)
>   clk_disable_unprepare(rcrtc->clock);
>  }
>  
> -static void rcar_du_crtc_get(struct rcar_du_crtc *rcrtc)
> -{
> - /*
> -  * Guard against double-get, as the function is called from both the
> -  * .atomic_enable() and .atomic_begin() handlers.
> -  */
> - if (rcrtc->initialized)
> - return;
> -
> - rcar_du_crtc_setup(rcrtc);
> - rcrtc->initialized = true;
> -}
> -
> -static void rcar_du_crtc_put(struct rcar_du_crtc *rcrtc)
> -{
> - rcrtc->initialized = false;
> -}
> -
>  static void rcar_du_crtc_start(struct rcar_du_crtc *rcrtc)
>  {
>   bool interlaced;
> @@ -716,6 +682,40 @@ int rcar_du_crtc_atomic_enter_standby(struct drm_device 
> *dev,
>   return 0;
>  }
>  
> +/*
> + * Configure the mode for all CRTCs that require it. For now we only handle 
> mode
> + * set on the VSP, CRTC configuration will be handled later.
> + */
> +int rcar_du_crtc_atomic_modeset(struct drm_device *dev,
> + struct drm_atomic_state *state)
> +{
> + struct drm_crtc_state *crtc_state;
> + struct drm_crtc *crtc;
> + unsigned int i;
> +
> + for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
> + struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc);
> +
> + /*
> +  * Skip commits that don't change the mode. We manually skip
> +  * inactive CRTCs as disabling a CRTC is considered as a mode
> +  * set by drm_atomic_crtc_needs_modeset().
> +  */
> + if (!drm_atomic_crtc_needs_modeset(crtc_state) ||
> + !crtc_state->active)
> + continue;
> +
> + /* Configure display timings and output routing. */
> + rcar_du_crtc_set_display_timing(rcrtc);
> + rcar_du_group_set_routing(rcrtc->group);
> +
> + if (rcar_du_has(rcrtc->dev, R

[PATCH v3 06/10] drm: rcar-du: Handle CRTC configuration from commit tail handler

2019-06-17 Thread Laurent Pinchart
From: Kieran Bingham 

The CRTC mode setting and routing configuration are performed at the
earliest of atomic enable and atomic begin, to ensure that a valid
configuration is applied to the hardware before the CRTC gets enabled
and before planes are setup (the latter being required in particular by
the VSP). This requires the rcar_du_crtc structure to track the CRTC
enabled state.

Simplify the code and remove the manual state tracking by moving CRTC
setup to a new rcar_du_crtc_atomic_modeset() function, called directly
from the commit tail handler. The function iterates over all CRTCs in
the state transaction and performs CRTC mode setting, routing
configuration and VSP configuration.

drm_crtc_vblank_on() has to be called from the atomic begin handler, to
ensure that vertical blanking reporting is enabled before the call to
drm_crtc_vblank_get() in the atomic flush handler. As the
drm_crtc_vblank_on() and drm_crtc_vblank_off() calls don't need to be
balanced this is not an issue. A balanced alternative would have been to
call drm_crtc_vblank_on() and drm_crtc_vblank_off() from the CRTC exit
and enter standby handlers respectively, but
drm_atomic_helper_commit_modeset_disables() complains if
drm_crtc_vblank_off() hasn't been called by the atomic disable handler.

As a result, the vsp1_du_atomic_flush() operation can be called with the
DRM pipeline disabled. Correct operation has been ensured by "media:
vsp1: drm: Don't configure hardware when the pipeline is disabled".

Signed-off-by: Kieran Bingham 
Signed-off-by: Laurent Pinchart 
---
Changes since v2:

- Deconstruct rcar_du_crtc_setup() completely
---
 drivers/gpu/drm/rcar-du/rcar_du_crtc.c | 89 +++---
 drivers/gpu/drm/rcar-du/rcar_du_crtc.h |  4 +-
 drivers/gpu/drm/rcar-du/rcar_du_kms.c  |  1 +
 3 files changed, 42 insertions(+), 52 deletions(-)

diff --git a/drivers/gpu/drm/rcar-du/rcar_du_crtc.c 
b/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
index 23f4bdef0e3a..d11a474f6f72 100644
--- a/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
+++ b/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
@@ -478,22 +478,6 @@ static void rcar_du_crtc_wait_page_flip(struct 
rcar_du_crtc *rcrtc)
  * Start/Stop and Suspend/Resume
  */
 
-static void rcar_du_crtc_setup(struct rcar_du_crtc *rcrtc)
-{
-   /* Configure display timings and output routing */
-   rcar_du_crtc_set_display_timing(rcrtc);
-   rcar_du_group_set_routing(rcrtc->group);
-
-   /* Enable the VSP compositor. */
-   if (rcar_du_has(rcrtc->dev, RCAR_DU_FEATURE_VSP1_SOURCE)) {
-   rcar_du_vsp_modeset(rcrtc);
-   rcar_du_vsp_enable(rcrtc);
-   }
-
-   /* Turn vertical blanking interrupt reporting on. */
-   drm_crtc_vblank_on(&rcrtc->crtc);
-}
-
 static int rcar_du_crtc_exit_standby(struct rcar_du_crtc *rcrtc)
 {
int ret;
@@ -534,24 +518,6 @@ static void rcar_du_crtc_enter_standby(struct rcar_du_crtc 
*rcrtc)
clk_disable_unprepare(rcrtc->clock);
 }
 
-static void rcar_du_crtc_get(struct rcar_du_crtc *rcrtc)
-{
-   /*
-* Guard against double-get, as the function is called from both the
-* .atomic_enable() and .atomic_begin() handlers.
-*/
-   if (rcrtc->initialized)
-   return;
-
-   rcar_du_crtc_setup(rcrtc);
-   rcrtc->initialized = true;
-}
-
-static void rcar_du_crtc_put(struct rcar_du_crtc *rcrtc)
-{
-   rcrtc->initialized = false;
-}
-
 static void rcar_du_crtc_start(struct rcar_du_crtc *rcrtc)
 {
bool interlaced;
@@ -716,6 +682,40 @@ int rcar_du_crtc_atomic_enter_standby(struct drm_device 
*dev,
return 0;
 }
 
+/*
+ * Configure the mode for all CRTCs that require it. For now we only handle 
mode
+ * set on the VSP, CRTC configuration will be handled later.
+ */
+int rcar_du_crtc_atomic_modeset(struct drm_device *dev,
+   struct drm_atomic_state *state)
+{
+   struct drm_crtc_state *crtc_state;
+   struct drm_crtc *crtc;
+   unsigned int i;
+
+   for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
+   struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc);
+
+   /*
+* Skip commits that don't change the mode. We manually skip
+* inactive CRTCs as disabling a CRTC is considered as a mode
+* set by drm_atomic_crtc_needs_modeset().
+*/
+   if (!drm_atomic_crtc_needs_modeset(crtc_state) ||
+   !crtc_state->active)
+   continue;
+
+   /* Configure display timings and output routing. */
+   rcar_du_crtc_set_display_timing(rcrtc);
+   rcar_du_group_set_routing(rcrtc->group);
+
+   if (rcar_du_has(rcrtc->dev, RCAR_DU_FEATURE_VSP1_SOURCE))
+   rcar_du_vsp_modeset(rcrtc);
+   }
+
+   return 0;
+}
+
 static void rcar_du_crtc_atomic_enable(struct drm_crtc *crtc,
   struct drm_crtc_state *old_