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_mode_config.h | 5 +++++ include/drm/drm_modeset_helper.h | 1 + 3 files changed, 37 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 @@ -260,5 +260,36 @@ int drm_mode_config_helper_resume(struct drm_device *dev) drm_kms_helper_poll_enable(dev); return ret; } 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_mode_config.h b/include/drm/drm_mode_config.h index 42d37f4aba84..9f8674870248 100644 --- a/include/drm/drm_mode_config.h +++ b/include/drm/drm_mode_config.h @@ -133,10 +133,15 @@ struct drm_mode_config_funcs { * Drivers that implement state readout and need a hardware * reset on the fallback path should implement this hook. * Drivers that don't implement state readout at all can keep * using drm_mode_config_reset() instead. * + * drm_mode_config_helper_hw_reset() resets all the objects + * that require it, and can be used as the implementation of + * this hook, or called from it once the device specific reset + * is done. + * * This hook is optional. If not provided, the fallback path * will create software state without resetting the hardware * first. */ void (*hw_reset)(struct drm_device *dev); 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 @@ -40,7 +40,8 @@ void drm_helper_mode_fill_fb_struct(struct drm_device *dev, int drm_crtc_init(struct drm_device *dev, struct drm_crtc *crtc, const struct drm_crtc_funcs *funcs); 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.56.1
