drm/vc4: Rework the HVS muxing code
Subsystems (3)
PATCH v4 1/2 drm/vc4: kms: Store the unassigned channel list in the state
In reply to Maxime RipardIf a CRTC is enabled but not active, and that we're then doing a page flip on another CRTC, drm_atomic_get_crtc_state will bring the first CRTC state into the global state, and will make us wait for its vblank as well, even though that might never occur.
Instead of creating the list of the free channels each time atomic_check is called, and calling drm_atomic_get_crtc_state to retrieve the allocated channels, let's create a private state object in the main atomic state, and use it to store the available channels.
Since vc4 has a semaphore (with a value of 1, so a lock) in its commit implementation to serialize all the commits, even the nonblocking ones, we are free from the use-after-free race if two subsequent commits are not ran in their submission order.
--- drivers/gpu/drm/vc4/vc4_drv.h | 1 + drivers/gpu/drm/vc4/vc4_kms.c | 126 +++++++++++++++++++++++++++------- 2 files changed, 102 insertions(+), 25 deletions(-)
drivers/gpu/drm/vc4/vc4_drv.h +1 -0
@@ -219,6 +219,7 @@ struct vc4_dev {struct drm_modeset_lock ctm_state_lock;struct drm_private_obj ctm_manager; +struct drm_private_obj hvs_channels;struct drm_private_obj load_tracker;/* List of vc4_debugfs_info_entry for adding to debugfs once
drivers/gpu/drm/vc4/vc4_kms.c +101 -25
189 lines not on this page · raw message
Signature · 7 lines
2.28.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
v4 cover drm/vc4: Rework the HVS muxing code
Hi,
Here's a second attempt at fixing the current issues we have with the muxing code that results in a PV muxing its HVS muxing when only another CRTC is modified by a state, or vblank timeouts when trying to wait for a vblank on a single CRTC while another one is inactive but enabled.
Let me know what you think,
Maxime
Changes from v3:
- Pulled some patches from the atomic_helper_commit series that reorder / cleanup some code added here
- s/needs_muxing/update_muxing/, and some cleanups suggested by Thomas
- Removed the patches already applied
Changes from v1:
- Dropped the code trying to access all the CRTCs (whether in the state or not) state
- Added Hoegeun Kwon's tags
- Fixed a build bisection error
- Cleaned up the private state using drmm_add_action_or_reset
- Rebased on current linux next
Maxime Ripard (2):
drm/vc4: kms: Store the unassigned channel list in the state drm/vc4: kms: Don't disable the muxing of an active CRTC
drivers/gpu/drm/vc4/vc4_drv.h | 4 + drivers/gpu/drm/vc4/vc4_kms.c | 199 ++++++++++++++++++++++++---------- 2 files changed, 146 insertions(+), 57 deletions(-)
Signature · 7 lines
2.28.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v4 2/2 drm/vc4: kms: Don't disable the muxing of an active CRTC
The current HVS muxing code will consider the CRTCs in a given state to setup their muxing in the HVS, and disable the other CRTCs muxes.
However, it's valid to only update a single CRTC with a state, and in this situation we would mux out a CRTC that was enabled but left untouched by the new state.
Fix this by setting a flag on the CRTC state when the muxing has been changed, and only change the muxing configuration when that flag is there.
--- drivers/gpu/drm/vc4/vc4_drv.h | 3 ++ drivers/gpu/drm/vc4/vc4_kms.c | 81 +++++++++++++++++++---------------- 2 files changed, 48 insertions(+), 36 deletions(-)
drivers/gpu/drm/vc4/vc4_drv.h +3 -0
@@ -532,6 +532,9 @@ struct vc4_crtc_state {unsigned int top;unsigned int bottom; } margins; + +/* Transitional state below, only valid during atomic commits */ +bool update_muxing; };#define VC4_HVS_CHANNEL_DISABLED ((unsigned int)-1)
drivers/gpu/drm/vc4/vc4_kms.c +45 -36
122 lines not on this page · raw message
Signature · 7 lines
2.28.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v4 2/2] drm/vc4: kms: Don't disable the muxing of an active CRTC
Am 20.11.20 um 15:42 schrieb Maxime Ripard:
Quoted 7 lines
The current HVS muxing code will consider the CRTCs in a given state to setup their muxing in the HVS, and disable the other CRTCs muxes.
However, it's valid to only update a single CRTC with a state, and in this situation we would mux out a CRTC that was enabled but left untouched by the new state.
Quoted 7 lines
Fix this by setting a flag on the CRTC state when the muxing has been changed, and only change the muxing configuration when that flag is there.
Fixes 87ebcd42fb7b ("drm/vc4: crtc: Assign output to channel automatically")Reviewed-by Hoegeun Kwon <[email protected]>Tested-by Hoegeun Kwon <[email protected]>Signed-off-by Maxime Ripard <[email protected]>
Quoted 149 lines
--- drivers/gpu/drm/vc4/vc4_drv.h | 3 ++ drivers/gpu/drm/vc4/vc4_kms.c | 81 +++++++++++++++++++---------------- 2 files changed, 48 insertions(+), 36 deletions(-)drivers/gpu/drm/vc4/vc4_drv.h +3
-0@@ -532,6 +532,9 @@ struct vc4_crtc_state {unsigned int top;unsigned int bottom; } margins; + +/* Transitional state below, only valid during atomic commits */ +bool update_muxing; };#define VC4_HVS_CHANNEL_DISABLED ((unsigned int)-1)drivers/gpu/drm/vc4/vc4_kms.c +45
-36@@ -239,10 +239,7 @@ static void vc5_hvs_pv_muxing_commit(struct vc4_dev *vc4, {struct drm_crtc_state *crtc_state;struct drm_crtc *crtc; -unsigned char dsp2_mux =0 ; -unsigned char dsp3_mux =3 ; -unsigned char dsp4_mux =3 ; -unsigned char dsp5_mux =3 ; +unsigned char mux;unsigned int i;u32 reg;@@ -250,50 +247,59 @@ static void vc5_hvs_pv_muxing_commit(struct vc4_dev *vc4,struct vc4_crtc_state *vc4_state =to_vc4_crtc_state (crtc_state);struct vc4_crtc *vc4_crtc =to_vc4_crtc (crtc); -if (!crtc_state->active) +if (!vc4_state->update_muxing)continue ;switch (vc4_crtc->data->hvs_output) {case 2 : - dsp2_mux = (vc4_state->assigned_channel ==2 ) ?0 :1 ; + mux = (vc4_state->assigned_channel ==2 ) ?0 :1 ; + reg =HVS_READ (SCALER_DISPECTRL ); +HVS_WRITE (SCALER_DISPECTRL , + (reg & ~SCALER_DISPECTRL_DSP2_MUX_MASK ) | +VC4_SET_FIELD (mux,SCALER_DISPECTRL_DSP2_MUX ));break ;case 3 : - dsp3_mux = vc4_state->assigned_channel; +if (vc4_state->assigned_channel ==VC4_HVS_CHANNEL_DISABLED ) + mux =3 ; +else + mux = vc4_state->assigned_channel; + + reg =HVS_READ (SCALER_DISPCTRL ); +HVS_WRITE (SCALER_DISPCTRL , + (reg & ~SCALER_DISPCTRL_DSP3_MUX_MASK ) | +VC4_SET_FIELD (mux,SCALER_DISPCTRL_DSP3_MUX ));break ;case 4 : - dsp4_mux = vc4_state->assigned_channel; +if (vc4_state->assigned_channel ==VC4_HVS_CHANNEL_DISABLED ) + mux =3 ; +else + mux = vc4_state->assigned_channel; + + reg =HVS_READ (SCALER_DISPEOLN ); +HVS_WRITE (SCALER_DISPEOLN , + (reg & ~SCALER_DISPEOLN_DSP4_MUX_MASK ) | +VC4_SET_FIELD (mux,SCALER_DISPEOLN_DSP4_MUX )); +break ;case 5 : - dsp5_mux = vc4_state->assigned_channel; +if (vc4_state->assigned_channel ==VC4_HVS_CHANNEL_DISABLED ) + mux =3 ; +else + mux = vc4_state->assigned_channel; + + reg =HVS_READ (SCALER_DISPDITHER ); +HVS_WRITE (SCALER_DISPDITHER , + (reg & ~SCALER_DISPDITHER_DSP5_MUX_MASK ) | +VC4_SET_FIELD (mux,SCALER_DISPDITHER_DSP5_MUX ));break ;default :break ; } } - - reg =HVS_READ (SCALER_DISPECTRL ); -HVS_WRITE (SCALER_DISPECTRL , - (reg & ~SCALER_DISPECTRL_DSP2_MUX_MASK ) | -VC4_SET_FIELD (dsp2_mux,SCALER_DISPECTRL_DSP2_MUX )); - - reg =HVS_READ (SCALER_DISPCTRL ); -HVS_WRITE (SCALER_DISPCTRL , - (reg & ~SCALER_DISPCTRL_DSP3_MUX_MASK ) | -VC4_SET_FIELD (dsp3_mux,SCALER_DISPCTRL_DSP3_MUX )); - - reg =HVS_READ (SCALER_DISPEOLN ); -HVS_WRITE (SCALER_DISPEOLN , - (reg & ~SCALER_DISPEOLN_DSP4_MUX_MASK ) | -VC4_SET_FIELD (dsp4_mux,SCALER_DISPEOLN_DSP4_MUX )); - - reg =HVS_READ (SCALER_DISPDITHER ); -HVS_WRITE (SCALER_DISPDITHER , - (reg & ~SCALER_DISPDITHER_DSP5_MUX_MASK ) | -VC4_SET_FIELD (dsp5_mux,SCALER_DISPDITHER_DSP5_MUX )); } static void@@ -789,17 +795,20 @@ static int vc4_pv_muxing_atomic_check(struct drm_device *dev,struct vc4_crtc *vc4_crtc =to_vc4_crtc (crtc);unsigned int matching_channels; -if (old_crtc_state->enable && !new_crtc_state->enable) { +/* Nothing to do here, let's skip it */ +if (old_crtc_state->enable == new_crtc_state->enable) +continue ; + +/* Muxing will need to be modified, mark it as such */ + new_vc4_crtc_state->update_muxing = true; + +/* If we're disabling our CRTC, we put back our channel */ +if (!new_crtc_state->enable) { hvs_new_state->unassigned_channels |=BIT (old_vc4_crtc_state->assigned_channel); new_vc4_crtc_state->assigned_channel =VC4_HVS_CHANNEL_DISABLED ; +continue ; } -if (!new_crtc_state->enable) -continue ; - -if (new_vc4_crtc_state->assigned_channel !=VC4_HVS_CHANNEL_DISABLED ) -continue ; -/* * The problem we have to solve here is that we have * up to 7 encoders, connected to up to 6 CRTCs.
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Maxime Ripard
AppliedRe: [PATCH v4 2/2] drm/vc4: kms: Don't disable the muxing of an active CRTC
Quoted 13 lines · Thomas Zimmermann
Am 20.11.20 um 15:42 schrieb Maxime Ripard:
Quoted 10 lines
The current HVS muxing code will consider the CRTCs in a given state to setup their muxing in the HVS, and disable the other CRTCs muxes.
However, it's valid to only update a single CRTC with a state, and in this situation we would mux out a CRTC that was enabled but left untouched by the new state.
Fix this by setting a flag on the CRTC state when the muxing has been changed, and only change the muxing configuration when that flag is there.
Quoted 6 lines
Quoted 4 lines
Fixes 87ebcd42fb7b ("drm/vc4: crtc: Assign output to channel automatically")Reviewed-by Hoegeun Kwon <[email protected]>Tested-by Hoegeun Kwon <[email protected]>Signed-off-by Maxime Ripard <[email protected]>Reviewed-by Thomas Zimmermann <[email protected]>
Applied both, thanks!
Maxime
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel