drm_mode_config_create_state() creates the initial state for all KMS objects at driver registration time.
Call the drm_mode_config_funcs.atomic_sro_readout_state hook from it so that the initial state is populated from the hardware rather than being left as a pristine default. Signed-off-by: Maxime Ripard <[email protected]> --- drivers/gpu/drm/drm_mode_config.c | 47 ++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/drivers/gpu/drm/drm_mode_config.c b/drivers/gpu/drm/drm_mode_config.c index f432f485a914..7c351c6f34a4 100644 --- a/drivers/gpu/drm/drm_mode_config.c +++ b/drivers/gpu/drm/drm_mode_config.c @@ -22,10 +22,11 @@ #include <linux/export.h> #include <linux/uaccess.h> #include <drm/drm_atomic.h> +#include <drm/drm_atomic_sro.h> #include <drm/drm_drv.h> #include <drm/drm_encoder.h> #include <drm/drm_file.h> #include <drm/drm_framebuffer.h> #include <drm/drm_managed.h> @@ -315,25 +316,11 @@ void drm_mode_config_reset(struct drm_device *dev) } drm_connector_list_iter_end(&conn_iter); } EXPORT_SYMBOL(drm_mode_config_reset); -/** - * drm_mode_config_create_initial_state - Allocates the initial state - * @dev: drm device - * - * This functions creates the initial state for all the objects. Drivers - * can use this in e.g. probe to initialize their software state. - * - * It has two main differences with drm_mode_config_reset(): the reset() - * hooks aren't called and thus the hardware will be left untouched, but - * also the &drm_private_obj structures will be initialized as opposed - * to drm_mode_config_reset() that skips them. - * - * Returns: 0 on success, negative error value on failure. - */ -int drm_mode_config_create_initial_state(struct drm_device *dev) +static int drm_mode_config_create_state(struct drm_device *dev) { struct drm_crtc *crtc; struct drm_colorop *colorop; struct drm_plane *plane; struct drm_connector *connector; @@ -401,10 +388,40 @@ int drm_mode_config_create_initial_state(struct drm_device *dev) } drm_connector_list_iter_end(&conn_iter); return 0; } + +/** + * drm_mode_config_create_initial_state - Allocates the initial state + * @dev: drm device + * + * This functions creates the initial state for all the objects. Drivers + * can use this in e.g. probe to initialize their state. + * + * It creates the initial state in several steps. It first tries to + * read-out the initial state from the hardware for all objects if state + * read-out is enabled and the driver supports it. Then, if state + * read-out isn't supported or fails, it creates a new, pristine state + * using the objects atomic_create_state callback. + * + * For historical reasons, drm_mode_config_reset() is similar, but + * doesn't support state read-out, and will always reset the hardware. + * It will also ignore all &drm_private_obj. + * + * Returns: 0 on success, negative error value on failure. + */ +int drm_mode_config_create_initial_state(struct drm_device *dev) +{ + int ret; + + ret = dev->mode_config.funcs->atomic_sro_readout_state(dev); + if (!ret) + return 0; + + return drm_mode_config_create_state(dev); +} EXPORT_SYMBOL(drm_mode_config_create_initial_state); /* * Global properties */ -- 2.54.0
