drm_mode_config_create_initial_state() calls &drm_mode_config_funcs.hw_reset when the hardware state readout fails, to put the hardware in a known-good state before creating pristine software state.
Provide drm_mode_config_helper_hw_reset() as a default implementation of &drm_mode_config_funcs.hw_reset that resets all the objects requiring it. Reviewed-by: Maarten Lankhorst <[email protected]> Signed-off-by: Maxime Ripard <[email protected]> --- drivers/gpu/drm/drm_modeset_helper.c | 31 +++++++++++++++++++++++++++++++ include/drm/drm_modeset_helper.h | 1 + 2 files changed, 32 insertions(+) diff --git a/drivers/gpu/drm/drm_modeset_helper.c b/drivers/gpu/drm/drm_modeset_helper.c index cca623eb23e5..1a49ab8a0e41 100644 --- a/drivers/gpu/drm/drm_modeset_helper.c +++ b/drivers/gpu/drm/drm_modeset_helper.c @@ -263,2 +263,33 @@ int drm_mode_config_helper_resume(struct drm_device *dev) } EXPORT_SYMBOL(drm_mode_config_helper_resume); + +/** + * drm_mode_config_helper_hw_reset - default &drm_mode_config_funcs.hw_reset implementation + * @dev: DRM device + * + * Resets all KMS objects that provide a hardware reset hook to a + * known-good state, without touching the software state. + * + * Drivers can assign this function as their + * &drm_mode_config_funcs.hw_reset implementation. + */ +void drm_mode_config_helper_hw_reset(struct drm_device *dev) +{ + struct drm_crtc *crtc; + + drm_for_each_crtc(crtc, dev) { + const struct drm_crtc_helper_funcs *helper_funcs = + crtc->helper_private; + + if (helper_funcs && helper_funcs->hw_reset) + helper_funcs->hw_reset(crtc); + } + + /* + * TODO: Reset encoders once the semantics of + * encoder->funcs->reset have been clarified. Some drivers + * (e.g. i915) reset both hardware and software state, while + * others (e.g. loongson) only reset hardware registers. + */ +} +EXPORT_SYMBOL(drm_mode_config_helper_hw_reset); diff --git a/include/drm/drm_modeset_helper.h b/include/drm/drm_modeset_helper.h index 7e3d4c5a7f66..bd4193fbd907 100644 --- a/include/drm/drm_modeset_helper.h +++ b/include/drm/drm_modeset_helper.h @@ -43,4 +43,5 @@ int drm_crtc_init(struct drm_device *dev, struct drm_crtc *crtc, int drm_mode_config_helper_suspend(struct drm_device *dev); int drm_mode_config_helper_resume(struct drm_device *dev); +void drm_mode_config_helper_hw_reset(struct drm_device *dev); #endif -- 2.55.0
