mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thomas Zimmermann <tzimmermann@suse.de>
To: Maxime Ripard <mripard@kernel.org>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
	Andrzej Hajda <andrzej.hajda@intel.com>,
	Neil Armstrong <neil.armstrong@linaro.org>,
	Robert Foss <rfoss@kernel.org>,
	Laurent Pinchart <Laurent.pinchart@ideasonboard.com>,
	Jonas Karlman <jonas@kwiboo.se>,
	Jernej Skrabec <jernej.skrabec@gmail.com>,
	Jyri Sarha <jyri.sarha@iki.fi>,
	Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>,
	Devarsh Thakkar <devarsht@ti.com>,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 10/29] drm/atomic: Add atomic_state_readout infrastructure
Date: Mon, 15 Sep 2025 11:11:39 +0200	[thread overview]
Message-ID: <5920ffe5-b6b1-484b-b320-332b9eb9db82@suse.de> (raw)
In-Reply-To: <20250915-active-placid-bustard-6e1faa@penduick>

Hi

Am 15.09.25 um 10:42 schrieb Maxime Ripard:
> Hi Tohmas,
>
> On Tue, Sep 02, 2025 at 03:44:54PM +0200, Thomas Zimmermann wrote:
>>> +/**
>>> + * drm_atomic_build_readout_state - Creates an initial state from the hardware
>>> + * @dev: DRM device to build the state for
>>> + *
>>> + * This function allocates a &struct drm_atomic_state, calls the
>>> + * atomic_readout_state callbacks, and fills the global state old states
>>> + * by what the callbacks returned.
>>> + *
>>> + * Returns:
>>> + *
>>> + * A partially initialized &struct drm_atomic_state on success, an error
>>> + * pointer otherwise.
>>> + */
>>> +static struct drm_atomic_state *
>>> +drm_atomic_build_readout_state(struct drm_device *dev)
>>> +{
>>> +	struct drm_connector_list_iter conn_iter;
>>> +	struct drm_atomic_state *state;
>>> +	struct drm_mode_config *config =
>>> +		&dev->mode_config;
>>> +	struct drm_connector *connector;
>>> +	struct drm_printer p =
>>> +		drm_info_printer(dev->dev);
>>> +	struct drm_encoder *encoder;
>>> +	struct drm_plane *plane;
>>> +	struct drm_crtc *crtc;
>>> +	int ret;
>>> +
>>> +	drm_dbg_kms(dev, "Starting to build atomic state from hardware state.\n");
>>> +
>>> +	state = drm_atomic_state_alloc(dev);
>>> +	if (WARN_ON(!state))
>>> +		return ERR_PTR(-ENOMEM);
>>> +
>>> +	state->connectors = kcalloc(config->num_connector, sizeof(*state->connectors), GFP_KERNEL);
>>> +	if (WARN_ON(!state->connectors)) {
>>> +		ret = -ENOMEM;
>>> +		goto err_state_put;
>>> +	}
>>> +
>>> +	state->private_objs = kcalloc(count_private_obj(dev), sizeof(*state->private_objs), GFP_KERNEL);
>>> +	if (WARN_ON(!state->private_objs)) {
>>> +		ret = -ENOMEM;
>>> +		goto err_state_put;
>>> +	}
>>> +
>>> +	drm_for_each_crtc(crtc, dev) {
>>> +		const struct drm_crtc_funcs *crtc_funcs =
>>> +			crtc->funcs;
>>> +		struct drm_crtc_state *crtc_state;
>>> +
>>> +		drm_dbg_kms(dev, "Initializing CRTC %s state.\n", crtc->name);
>>> +
>>> +		if (crtc_funcs->atomic_readout_state) {
>>> +			crtc_state = crtc_funcs->atomic_readout_state(crtc);
>>> +		} else if (crtc_funcs->reset) {
>>> +			crtc_funcs->reset(crtc);
>>> +
>>> +			/*
>>> +			 * We don't want to set crtc->state field yet. Let's save and clear it up.
>>> +			 */
>>> +			crtc_state = crtc->state;
>>> +			crtc->state = NULL;
>> Chancing the crtc->state pointer behind the back of the reset callback seems
>> fragile. We never how if some other piece of the driver refers to it
>> (although illegally).
> I agree that it's clunky. I'm not sure who would use it at this point
> though: we're in the middle of the drm_mode_config_reset(), so the
> drivers' involvement is pretty minimal.
>
> I did wonder if changing reset to return the object instead of setting
> $OBJECT->state would be a better interface?

Probably not. The reset helper is supposed to initialize the object's 
software and hardware state. But in most drivers, we're currently mostly 
setting the minimal software state here and simply assume that hardware 
is off. Returning the state would water down semantics even further.

Having said that, I could imaging building an atomic_clean_state 
callback that replaces the reset callback. It would work alongside the 
new atomic_readout_state callback.  Current reset could be build upon 
that callback. The atomic_clean_state would intentionally only take care 
of the software state and leave hardware state undefined. This reflects 
the current realities of most DRM drivers.   From that clean state, DRM 
could do an atomic commit that also initializes the hardware.

>
>> For now, wouldn't it be better to require a read-out helper for all elements
>> of the driver's mode-setting pipeline?  The trivial implementation would
>> copy the existing reset function and keep crtc->state to NULL.
> I also considered that, but I'm not sure we can expect bridges to have
> readout hooks filled for every configuration in the wild.
>
> But maybe we can look during drm_mode_config_reset() at whether all the
> objects have their hook filled, and if not fall back on reset for
> everything.

That's what I meant, I think.

>
> It would make the implementation easier, but missing bridges
> implementations would trigger a mode change when it might actually work
> just fine since bridge state is pretty minimal.

If there's an element in the pipeline that's missing the readout helper, 
it might be safer to fallback to that modeset instead of ending up with 
inconsistent state.

Best regards
Thomas

>
> Idk.
>
>>> --- a/include/drm/drm_bridge.h
>>> +++ b/include/drm/drm_bridge.h
>>> @@ -490,10 +490,31 @@ struct drm_bridge_funcs {
>>>    	 * The @atomic_post_disable callback is optional.
>>>    	 */
>>>    	void (*atomic_post_disable)(struct drm_bridge *bridge,
>>>    				    struct drm_atomic_state *state);
>>> +	/**
>>> +	 * @atomic_readout_state:
>>> +	 *
>>> +	 * Initializes,this bridge atomic state.
>>> +	 *
>>> +	 * It's meant to be used by drivers that wants to implement fast
>> 'want'
>>
>>> +	 * / flicker-free boot and allows to initialize the atomic state
>> I think we should only call it flicker-free boot. Fast boot is misleading.
> I agree, but it's also how it's been called by the only implementation
> of it we have so far (i915), and the name of the module parameter that
> controls it.
>
> Maxime

-- 
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)



  reply	other threads:[~2025-09-15  9:11 UTC|newest]

Thread overview: 105+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-02  8:32 [PATCH 00/29] drm: Implement state readout support Maxime Ripard
2025-09-02  8:32 ` [PATCH 01/29] drm/atomic: Document atomic state lifetime Maxime Ripard
2025-09-02 13:08   ` Thomas Zimmermann
2025-09-02 18:59     ` Laurent Pinchart
2025-09-23  9:22     ` Maxime Ripard
2025-09-02  8:32 ` [PATCH 02/29] drm/atomic: Fix unused but set warning in for_each_old_plane_in_state Maxime Ripard
2025-09-02 13:10   ` Thomas Zimmermann
2025-09-02 19:25   ` Laurent Pinchart
2025-09-02  8:32 ` [PATCH 03/29] drm/atomic: Fix unused but set warning in for_each_old_private_obj_in_state Maxime Ripard
2025-09-02 13:10   ` Thomas Zimmermann
2025-09-02 19:26   ` Laurent Pinchart
2025-09-02  8:32 ` [PATCH 04/29] drm/atomic_helper: Skip over NULL private_obj pointers Maxime Ripard
2025-09-02 13:13   ` Thomas Zimmermann
2025-09-02 19:29     ` Laurent Pinchart
2025-09-23  9:23     ` Maxime Ripard
2025-09-02  8:32 ` [PATCH 05/29] drm/atomic_state_helper: Fix bridge state initialization Maxime Ripard
2025-09-02 13:18   ` Thomas Zimmermann
2025-09-15 11:27     ` Maxime Ripard
2025-09-15 13:12       ` Thomas Zimmermann
2025-09-23  9:33         ` Maxime Ripard
2025-10-01  6:45           ` Thomas Zimmermann
2025-09-15 12:54     ` Dmitry Baryshkov
2025-09-02 19:49   ` Laurent Pinchart
2025-09-02  8:32 ` [PATCH 06/29] drm/bridge: Implement atomic_print_state Maxime Ripard
2025-09-02 13:22   ` Thomas Zimmermann
2025-09-02 20:22     ` Laurent Pinchart
2025-09-15 11:28       ` Maxime Ripard
2025-09-15 12:56         ` Dmitry Baryshkov
2025-09-02  8:32 ` [PATCH 07/29] drm/atomic: Implement drm_atomic_print_old_state Maxime Ripard
2025-09-02 13:26   ` Thomas Zimmermann
2025-09-09 12:44     ` Maxime Ripard
2025-09-02 20:35   ` Laurent Pinchart
2025-09-02  8:32 ` [PATCH 08/29] drm/atomic: Only call atomic_destroy_state on a !NULL pointer Maxime Ripard
2025-09-02 13:30   ` Thomas Zimmermann
2025-09-02 20:52   ` Laurent Pinchart
2025-09-15 11:35     ` Maxime Ripard
2025-09-02  8:32 ` [PATCH 09/29] drm/modeset: Create atomic_reset hook Maxime Ripard
2025-09-02 21:04   ` Laurent Pinchart
2025-09-15 11:37     ` Maxime Ripard
2025-09-02  8:32 ` [PATCH 10/29] drm/atomic: Add atomic_state_readout infrastructure Maxime Ripard
2025-09-02 13:44   ` Thomas Zimmermann
2025-09-15  8:42     ` Maxime Ripard
2025-09-15  9:11       ` Thomas Zimmermann [this message]
2025-09-23  9:37         ` Maxime Ripard
2025-10-01  7:01           ` Thomas Zimmermann
2025-09-15 18:38       ` Dmitry Baryshkov
2025-09-23  9:38         ` Maxime Ripard
2025-09-23 10:28           ` Dmitry Baryshkov
2025-09-23 10:32             ` Laurent Pinchart
2025-09-23 10:43               ` Dmitry Baryshkov
2025-09-23 11:41                 ` Laurent Pinchart
2025-09-23 15:20                   ` Dmitry Baryshkov
2025-09-24  9:56               ` Maxime Ripard
2025-09-24  9:53             ` Maxime Ripard
2025-09-15 18:40   ` Dmitry Baryshkov
2025-09-23  9:45     ` Maxime Ripard
2025-09-23 10:30       ` Dmitry Baryshkov
2025-10-17 13:12         ` Simona Vetter
2025-10-17 13:29   ` Simona Vetter
2025-10-17 13:41   ` Simona Vetter
2025-09-02  8:32 ` [PATCH 11/29] drm/crtc: Drop no_vblank bit field Maxime Ripard
2025-09-02 13:45   ` Thomas Zimmermann
2025-09-30 10:00   ` (subset) " Maxime Ripard
2025-09-02  8:32 ` [PATCH 12/29] drm/atomic_helper: Pass nonblock to commit_tail Maxime Ripard
2025-09-02 13:46   ` Thomas Zimmermann
2025-09-02  8:32 ` [PATCH 13/29] drm/atomic_helper: Compare actual and readout states once the commit is done Maxime Ripard
2025-10-17 13:21   ` Simona Vetter
2025-10-21  9:27   ` Simona Vetter
2025-10-31 21:01   ` Simona Vetter
2025-09-02  8:32 ` [PATCH 14/29] drm/atomic_state_helper: Provide comparison macros Maxime Ripard
2025-09-02  8:32 ` [PATCH 15/29] drm/atomic_state_helper: Provide atomic_compare_state helpers Maxime Ripard
2025-09-02  8:32 ` [PATCH 16/29] drm/encoder: Create get_current_crtc hook Maxime Ripard
2025-10-17 13:19   ` Simona Vetter
2025-09-02  8:32 ` [PATCH 17/29] drm/bridge_connector: Implement hw readout for connector Maxime Ripard
2025-09-02  8:32 ` [PATCH 18/29] drm/tidss: Convert to drm logging Maxime Ripard
2025-09-02 13:49   ` Thomas Zimmermann
2025-09-30 10:00   ` (subset) " Maxime Ripard
2025-09-02  8:32 ` [PATCH 19/29] drm/tidss: Remove ftrace-like logs Maxime Ripard
2025-09-02 13:50   ` Thomas Zimmermann
2025-09-30 10:00   ` (subset) " Maxime Ripard
2025-09-02  8:32 ` [PATCH 20/29] drm/tidss: crtc: Change variable name Maxime Ripard
2025-09-02 13:51   ` Thomas Zimmermann
2025-09-30 10:00   ` (subset) " Maxime Ripard
2025-09-02  8:32 ` [PATCH 21/29] drm/tidss: crtc: Implement destroy_state Maxime Ripard
2025-09-02 13:52   ` Thomas Zimmermann
2025-09-30 10:00   ` (subset) " Maxime Ripard
2025-09-02  8:32 ` [PATCH 22/29] drm/tidss: crtc: Cleanup reset implementation Maxime Ripard
2025-09-02 13:54   ` Thomas Zimmermann
2025-09-30 10:00   ` (subset) " Maxime Ripard
2025-09-02  8:32 ` [PATCH 23/29] drm/tidss: dispc: Add format lookup by hw value Maxime Ripard
2025-10-08 12:40   ` Tomi Valkeinen
2025-09-02  8:32 ` [PATCH 24/29] drm/tidss: dispc: Improve mode checking logs Maxime Ripard
2025-09-02 14:06   ` Thomas Zimmermann
2025-09-02  8:32 ` [PATCH 25/29] drm/tidss: dispc: Move dispc_device definition to headers Maxime Ripard
2025-09-02  8:32 ` [PATCH 26/29] drm/tidss: dispc: make accessors accessible to other parts of the driver Maxime Ripard
2025-09-02  8:32 ` [PATCH 27/29] drm/tidss: Implement readout support Maxime Ripard
2025-10-08 12:44   ` Tomi Valkeinen
2025-09-02  8:32 ` [PATCH 28/29] drm/tidss: encoder: implement get_current_crtc Maxime Ripard
2025-09-02  8:32 ` [PATCH 29/29] drm/bridge: sii902x: Implement hw state readout Maxime Ripard
2025-09-02 14:13 ` [PATCH 00/29] drm: Implement state readout support Thomas Zimmermann
2025-09-23  9:15   ` Maxime Ripard
2025-10-17 13:11     ` Simona Vetter
2025-10-08 13:07 ` Tomi Valkeinen
2025-10-08 13:57   ` Maxime Ripard
2025-10-08 14:15     ` Tomi Valkeinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5920ffe5-b6b1-484b-b320-332b9eb9db82@suse.de \
    --to=tzimmermann@suse.de \
    --cc=Laurent.pinchart@ideasonboard.com \
    --cc=airlied@gmail.com \
    --cc=andrzej.hajda@intel.com \
    --cc=devarsht@ti.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jernej.skrabec@gmail.com \
    --cc=jonas@kwiboo.se \
    --cc=jyri.sarha@iki.fi \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=neil.armstrong@linaro.org \
    --cc=rfoss@kernel.org \
    --cc=simona@ffwll.ch \
    --cc=tomi.valkeinen@ideasonboard.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®