From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796116099; b=a1JXlYnHT0zdkAqvc2T+8XN2RplyBDLq022KzhDRSf795RfUUa9QHWJo+uNmi64urAuD 1MPfIzmPK8Pzvjmwpo1mnMtrlxWIJqT4i3jsIHkwUrtG1h4iDW1w3Nz4KXXMv7A4bogiz eYujuU86TcsdeRL8Ut0xA4FBIDgrMEoGxt33fdilGkGx/igiLlc98dcZ7D8ws7bwPerob nIQu0V++rjf0dvHHU6lz6JGdc9lKGz72MRhQe2zUGN3tkXpCXWAfu5GGIBy/RO/dSC3um P/Dzt4ejxjteLwkHXKXFMVvOZ3k4TZXquo0LIlIupJ5045FK9E9bSE4bvbL8IO8OvXQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796116099; h=DMARC-Filter:Received:DKIM-Signature:DKIM-Signature:DKIM-Signature: DKIM-Signature:Received:Received:Message-ID:Date:MIME-Version: User-Agent:Subject:To:Cc:References:Content-Language:From:Autocrypt: In-Reply-To:Content-Type:Content-Transfer-Encoding:X-Spamd-Result: X-Rspamd-Server:X-Rspamd-Action:X-Spam-Flag:X-Spam-Score:X-Spam-Level: X-Rspamd-Queue-Id; bh=Kd1tAH8R9p7fLiA8ubuBsESzYEUzIfLe/cM8XYk5qtE=; b=TtusNLMGTngiC4FuH9ZVFSm9wsp9gNJ+BmXHq3VF9wxgst5+24EUtvYKtsi+FH7Z7ds3 vryIjr0vobfa0180rIjJkjoBVyxf6IbUaWUbMHUN4W3rTDPwlHDiqI0onZ6lizfBWeBzK yehqAz9q36eL3fvCY8bdbwQwDTbOGguen6GxVjoT7O2yUJcz7+/lJbPzzPNn3i3grf0c7 wiR3DNZqo7c9xNxzpbklQj5jdBweF9bklJmFqDS70LkkR66mneA2izDVBt0dpVE4l7dE4 Ap8RsTygb5h9/+nHd2PuwDYsc3AZo7CHJKyI2kKlRqxknH2YKRf6VwkomaRe1so0TsQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=uWombvTP; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=avZ7aUDQ; dkim=pass header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=OdfP1EgT; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=T3jA1PVw; arc=none smtp.remote-ip=195.135.223.130 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 19272606A333 for ; Tue, 1 Dec 2026 09:08:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 19272606A333 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=uWombvTP; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=avZ7aUDQ; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=OdfP1EgT; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=T3jA1PVw Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id E2D34223A2; Tue, 1 Dec 2026 09:08:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1796116095; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=Kd1tAH8R9p7fLiA8ubuBsESzYEUzIfLe/cM8XYk5qtE=; b=uWombvTPQ+TJhKKRGroqM4iigMaxpiUPp4QVNqGaD1ypi3bB7W2At3bVPz4WfypQWZ+Hqx FOQmy243SIVENjQKvuDAsCcA0IquTFs87jddTGV2pM9cNeQ2+HTpmvzSWw85KbJYQj3nP9 Kr3RlL69Gkx0R0/DpBaFfCjGbFqlhDo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1796116095; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=Kd1tAH8R9p7fLiA8ubuBsESzYEUzIfLe/cM8XYk5qtE=; b=avZ7aUDQDDAWqQa/CBycj6ZQRES5TIGYQncsJiSeID+q+lO0S/a8niGP7C5K7XHaLyjtvI MA+44PJ9PV+KeEBw== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=OdfP1EgT; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=T3jA1PVw DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1796116094; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=Kd1tAH8R9p7fLiA8ubuBsESzYEUzIfLe/cM8XYk5qtE=; b=OdfP1EgTDFRcyv8o39B1K3aQPN6FZd8Mqect40yu0EfPlLyReN0Yk/tTdIU2t6bXkL6IF+ h8XVeB5H6B4swIxREPD4EWpzu6lghL9WGJaYSv/HwL+s/xKDiSbGzAu+1lkDFmENgn3u4E 2Pz4KZaZapv6KqN+daHGPegTYb6REBo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1796116094; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=Kd1tAH8R9p7fLiA8ubuBsESzYEUzIfLe/cM8XYk5qtE=; b=T3jA1PVwdK0UlZSdVBC7k5lZzmN9NgYWiCg7z5YQLKXQT1AFpQ2G5DNK7/ro6FkFWPxTBD RPWpIoCUSKI3knAw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 35886133F6; Tue, 1 Dec 2026 09:08:14 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 35gQNX2ODmt6egAAD6G6ig (envelope-from ); Tue, 01 Dec 2026 09:08:14 +0000 Message-ID: <4653f381-cee3-4407-b393-5fc3352b3a39@suse.de> Date: Tue, 1 Dec 2026 10:08:13 +0100 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v12 3/9] drm/atomic: Allow filling a commit with pristine object states To: Maxime Ripard , Maarten Lankhorst , David Airlie , Simona Vetter , Louis Chauvet , Haneen Mohammed , Melissa Wen Cc: Daniel Stone , Harry Wentland , Jocelyn Falempe , =?UTF-8?Q?Jonas_=C3=85dahl?= , =?UTF-8?Q?Michel_D=C3=A4nzer?= , Pekka Paalanen , Sebastian Wick , Simon Ser , Victoria Brekenfeld , Xaver Hugl , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org References: <20261120-drm-reset-state-flag-v12-0-42d63d7417fc@kernel.org> <20261120-drm-reset-state-flag-v12-3-42d63d7417fc@kernel.org> Content-Language: en-US From: Thomas Zimmermann Autocrypt: addr=tzimmermann@suse.de; keydata= xsBNBFs50uABCADEHPidWt974CaxBVbrIBwqcq/WURinJ3+2WlIrKWspiP83vfZKaXhFYsdg XH47fDVbPPj+d6tQrw5lPQCyqjwrCPYnq3WlIBnGPJ4/jreTL6V+qfKRDlGLWFjZcsrPJGE0 BeB5BbqP5erN1qylK9i3gPoQjXGhpBpQYwRrEyQyjuvk+Ev0K1Jc5tVDeJAuau3TGNgah4Yc hdHm3bkPjz9EErV85RwvImQ1dptvx6s7xzwXTgGAsaYZsL8WCwDaTuqFa1d1jjlaxg6+tZsB 9GluwvIhSezPgnEmimZDkGnZRRSFiGP8yjqTjjWuf0bSj5rUnTGiyLyRZRNGcXmu6hjlABEB AAHNJ1Rob21hcyBaaW1tZXJtYW5uIDx0emltbWVybWFubkBzdXNlLmRlPsLAjgQTAQgAOAIb AwULCQgHAgYVCgkICwIEFgIDAQIeAQIXgBYhBHIX+6yM6c9jRKFo5WgNwR1TC3ojBQJftODH AAoJEGgNwR1TC3ojx1wH/0hKGWugiqDgLNXLRD/4TfHBEKmxIrmfu9Z5t7vwUKfwhFL6hqvo lXPJJKQpQ2z8+X2vZm/slsLn7J1yjrOsoJhKABDi+3QWWSGkaGwRJAdPVVyJMfJRNNNIKwVb U6B1BkX2XDKDGffF4TxlOpSQzdtNI/9gleOoUA8+jy8knnDYzjBNOZqLG2FuTdicBXblz0Mf vg41gd9kCwYXDnD91rJU8tzylXv03E75NCaTxTM+FBXPmsAVYQ4GYhhgFt8S2UWMoaaABLDe 7l5FdnLdDEcbmd8uLU2CaG4W2cLrUaI4jz2XbkcPQkqTQ3EB67hYkjiEE6Zy3ggOitiQGcqp j//OwE0EWznS4AEIAMYmP4M/V+T5RY5at/g7rUdNsLhWv1APYrh9RQefODYHrNRHUE9eosYb T6XMryR9hT8XlGOYRwKWwiQBoWSDiTMo/Xi29jUnn4BXfI2px2DTXwc22LKtLAgTRjP+qbU6 3Y0xnQN29UGDbYgyyK51DW3H0If2a3JNsheAAK+Xc9baj0LGIc8T9uiEWHBnCH+RdhgATnWW GKdDegUR5BkDfDg5O/FISymJBHx2Dyoklv5g4BzkgqTqwmaYzsl8UxZKvbaxq0zbehDda8lv hFXodNFMAgTLJlLuDYOGLK2AwbrS3Sp0AEbkpdJBb44qVlGm5bApZouHeJ/+n+7r12+lqdsA EQEAAcLAdgQYAQgAIAIbDBYhBHIX+6yM6c9jRKFo5WgNwR1TC3ojBQJftOH6AAoJEGgNwR1T C3ojVSkIALpAPkIJPQoURPb1VWjh34l0HlglmYHvZszJWTXYwavHR8+k6Baa6H7ufXNQtThR yIxJrQLW6rV5lm7TjhffEhxVCn37+cg0zZ3j7zIsSS0rx/aMwi6VhFJA5hfn3T0TtrijKP4A SAQO9xD1Zk9/61JWk8OysuIh7MXkl0fxbRKWE93XeQBhIJHQfnc+YBLprdnxR446Sh8Wn/2D Ya8cavuWf2zrB6cZurs048xe0UbSW5AOSo4V9M0jzYI4nZqTmPxYyXbm30Kvmz0rYVRaitYJ 4kyYYMhuULvrJDMjZRvaNe52tkKAvMevcGdt38H4KSVXAylqyQOW5zvPc4/sq9c= In-Reply-To: <20261120-drm-reset-state-flag-v12-3-42d63d7417fc@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spamd-Result: default: False [-12.00 / 50.00]; SUSE_INTERNAL_BYPASS(-9.00)[]; BAYES_HAM(-3.00)[100.00%]; SUSPICIOUS_RECIPS(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; XM_UA_NO_VERSION(0.01)[]; MX_GOOD(-0.01)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; ARC_NA(0.00)[]; FREEMAIL_TO(0.00)[kernel.org,linux.intel.com,gmail.com,ffwll.ch,bootlin.com]; RCPT_COUNT_TWELVE(0.00)[19]; MIME_TRACE(0.00)[0:+]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; RCVD_TLS_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.de:+]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; DNSWL_BLOCKED(0.00)[2a07:de40:b281:106:10:150:64:167:received,2a07:de40:b281:104:10:150:64:97:from]; TAGGED_RCPT(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:url,suse.de:dkim,imap1.dmz-prg2.suse.org:rdns,imap1.dmz-prg2.suse.org:helo] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spam-Flag: NO X-Spam-Score: -12.00 X-Spam-Level: X-Rspamd-Queue-Id: E2D34223A2 Hi Am 20.11.26 um 14:10 schrieb Maxime Ripard: > The upcoming DRM_MODE_ATOMIC_RESET flag will need to create an atomic > commit that brings the entire device back to a pristine state, as if > no configuration had ever been applied. > > Create drm_atomic_commit_fill_with_defaults() which iterates over all > CRTCs, planes, connectors, and color operations in the device and > inserts a fresh default state for each one into the commit. This uses > the atomic_create_state() hooks rather than atomic_duplicate_state(), > since atomic_create_state() provides exactly this pristine state on a > per-object basis. > > A lessee only gets the objects of its lease reset, the other ones > keeping their current state. Partial pipelines aren't supported > though: detaching a plane or a connector from its CRTC, and disabling > a CRTC driving them, both need the two sides in the commit, so a lease > that splits a pipeline is rejected with -ENOENT. validate_lease() is I returning -ENOENT consistent with other places in the lease code? I'm asking because the code usually means "no such file or directory". Best regards Thomas > expected to keep that from happening, since it requires a lease to > hold at least a CRTC, a connector and a plane, but it only looks at > the object types, not at what they are bound to. > > Part of the state the atomic helpers maintain is only recomputed when > something changed, which a reset re-applying the same configuration > doesn't trigger. The CRTC adjusted_mode and the connector best_encoder > are therefore carried over like a duplicated state would, and the > CRTCs ask for a zpos normalization. > > The color management changes are reported through color_mgmt_changed > for the same reason: the userspace property handlers only set it when > a property write changes the value stored in the new state, so neither > restoring a default nor leaving a property untouched would, even > though the reset clears whatever is currently programmed. > > Signed-off-by: Maxime Ripard > --- > drivers/gpu/drm/drm_atomic.c | 321 +++++++++++++++++++++++++++++++++++++++++++ > include/drm/drm_atomic.h | 2 + > 2 files changed, 323 insertions(+) > > diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c > index 7a77051096c9..43df13aaef1e 100644 > --- a/drivers/gpu/drm/drm_atomic.c > +++ b/drivers/gpu/drm/drm_atomic.c > @@ -1647,10 +1647,331 @@ bool drm_atomic_implements_create_state(struct drm_device *dev) > > return true; > } > EXPORT_SYMBOL(drm_atomic_implements_create_state); > > +/** > + * drm_atomic_commit_fill_with_defaults - populate a commit with pristine states > + * @file_priv: DRM file the reset was requested from, or NULL > + * @commit: atomic commit to fill > + * > + * Iterate over all CRTCs, planes, connectors, and color operations in > + * the device and insert a freshly created default state for each one > + * into @commit. The states are created through the atomic_create_state() > + * hooks, producing the same initial state the driver starts with rather > + * than a copy of the current hardware state. > + * > + * In the default state, all objects are disabled: CRTCs are inactive, > + * planes are disabled, and connectors are unbound. Driver-specific > + * properties such as color pipeline settings or max_bpc may carry > + * non-zero defaults appropriate for basic display output. > + * > + * If @file_priv is a lessee, only the CRTCs, planes and connectors part > + * of its lease are reset, and the other objects keep their current > + * state. @file_priv is optional: if NULL, it is considered to not hold > + * any lease, and all objects are reset. > + * > + * Partial pipelines aren't supported. Resetting a plane or a connector > + * detaches it from the CRTC it is bound to, and resetting a CRTC > + * disables the planes and connectors bound to it, neither of which the > + * atomic helpers can sort out with only one side of the pair in the > + * commit. A lease covering a plane or a connector without the CRTC it > + * is bound to, or a CRTC without all the planes and connectors bound > + * to it, would thus require reaching outside of it, so the reset is > + * rejected instead. > + * > + * Such a lease shouldn't exist in the first place: validate_lease() > + * requires a lease to hold at least a CRTC, a connector and a plane, > + * so leases are meant to describe whole pipelines. It only looks at > + * the object types though, not at what they are bound to, so the > + * reset still has to guard against it. > + * > + * This is meant to be used with the %DRM_MODE_ATOMIC_RESET flag, which > + * needs to bring the device back to a known baseline before applying > + * userspace property changes on top. > + * > + * Returns: > + * 0 on success, -ENOENT if a leased plane or connector is bound to a > + * CRTC that isn't leased or if the lease was revoked, or a negative > + * error code on failure. > + */ > +int drm_atomic_commit_fill_with_defaults(struct drm_file *file_priv, > + struct drm_atomic_commit *commit) > +{ > + struct drm_device *dev = commit->dev; > + struct drm_mode_config *config = &dev->mode_config; > + struct drm_crtc *crtc; > + struct drm_plane *plane, *crtc_plane; > + struct drm_connector *connector; > + struct drm_connector_list_iter conn_iter; > + struct drm_colorop *colorop; > + int ret; > + > + drm_WARN_ON(dev, !commit->acquire_ctx); > + > + /* > + * Private objects are ignored because none have userspace > + * properties we might want to reset. atomic_check > + * implementations will derive or infer their private obj state > + * from the state that will end up being committed anyway. > + * > + * The CRTCs are handled first because resetting a plane or a > + * connector bound to one detaches it, and the atomic helpers > + * need that CRTC in the commit to do so. > + * > + * A lease is always revoked as a whole, so a plane or a > + * connector still leased when its loop runs had its CRTC > + * leased when the CRTC loop ran. A revocation halfway through > + * can thus not leave an object detached from a CRTC that never > + * made it into the commit. > + * > + * The other way around doesn't hold though: a revocation after > + * the CRTC loop skips the planes and connectors bound to the > + * CRTCs it reset. Since the pristine CRTC states come with > + * empty plane and connector masks, neither the atomic helpers > + * nor the core checks would notice, and the commit would leave > + * those connectors bound to a disabled CRTC. The lease is thus > + * checked once more after all the loops ran. > + */ > + drm_for_each_colorop(colorop, dev) { > + struct drm_colorop_state *colorop_state; > + > + if (!drm_lease_held(file_priv, colorop->plane->base.id)) > + continue; > + > + ret = drm_modeset_lock(&colorop->plane->mutex, commit->acquire_ctx); > + if (ret) > + return ret; > + > + colorop_state = drm_atomic_helper_colorop_create_state(colorop); > + if (IS_ERR(colorop_state)) > + return PTR_ERR(colorop_state); > + > + drm_atomic_commit_set_colorop_state(commit, colorop, colorop_state); > + } > + > + drm_for_each_crtc(crtc, dev) { > + struct drm_crtc_state *crtc_state; > + > + if (!drm_lease_held(file_priv, crtc->base.id)) > + continue; > + > + ret = drm_modeset_lock(&crtc->mutex, commit->acquire_ctx); > + if (ret) > + return ret; > + > + /* > + * The reset disables the CRTC, which the planes enabled on > + * it can't stay bound to. Disabling them is only an option > + * for the ones the lease covers, so a CRTC driving a plane > + * it doesn't is rejected like the other way around. > + */ > + drm_for_each_plane_mask(crtc_plane, dev, crtc->state->plane_mask) { > + if (drm_lease_held(file_priv, crtc_plane->base.id)) > + continue; > + > + drm_dbg_atomic(dev, > + "[CRTC:%d:%s] drives [PLANE:%d:%s], which isn't leased\n", > + crtc->base.id, crtc->name, > + crtc_plane->base.id, crtc_plane->name); > + return -ENOENT; > + } > + > + crtc_state = crtc->funcs->atomic_create_state(crtc); > + if (IS_ERR(crtc_state)) > + return PTR_ERR(crtc_state); > + > + /* > + * The userspace property handlers only set > + * color_mgmt_changed when a property write changes the > + * value stored in the new state. Since the pristine states > + * we create here are already set to their default values, > + * restoring those defaults wouldn't set the flag, and > + * neither would leaving the properties untouched, even > + * though the commit clears whatever LUT or CTM is > + * currently programmed. Compare with the current state > + * so that the drivers reprogram the color management > + * hardware. > + */ > + crtc_state->color_mgmt_changed = > + crtc->state->degamma_lut != crtc_state->degamma_lut || > + crtc->state->ctm != crtc_state->ctm || > + crtc->state->gamma_lut != crtc_state->gamma_lut; > + > + /* > + * adjusted_mode is derived from the mode by the atomic > + * helpers rather than set by userspace, and mode_fixup() > + * only recomputes it when the mode or the connectors > + * changed. A duplicated state carries it over, so nothing > + * needs to be recomputed when nothing changes, but the > + * pristine states we create here would be left with a > + * zeroed adjusted_mode on a CRTC that stays enabled across > + * the commit. Carry it over too, so that the drivers and > + * the vblank timestamping constants keep seeing the > + * timings currently programmed. > + */ > + drm_mode_copy(&crtc_state->adjusted_mode, > + &crtc->state->adjusted_mode); > + > + /* > + * The planes come back with the default zpos, which the > + * atomic helpers only normalize when the planes bound to a > + * CRTC or one of their zpos changed. Re-applying the same > + * configuration on top of the reset wouldn't trigger > + * either, so ask for a normalization explicitly. > + */ > + crtc_state->zpos_changed = true; > + > + drm_atomic_commit_set_crtc_state(commit, crtc, crtc_state); > + } > + > + drm_for_each_plane(plane, dev) { > + struct drm_plane_state *plane_state; > + > + if (!drm_lease_held(file_priv, plane->base.id)) > + continue; > + > + ret = drm_modeset_lock(&plane->mutex, commit->acquire_ctx); > + if (ret) > + return ret; > + > + /* > + * The pristine state detaches the plane from the CRTC it > + * is enabled on, which the atomic helpers can only sort > + * out with that CRTC in the commit. Resetting a plane > + * enabled on a CRTC that isn't leased would thus require > + * touching an object the lease doesn't cover, so report it > + * like any other access outside of the lease. > + */ > + if (plane->state->crtc && > + !drm_lease_held(file_priv, plane->state->crtc->base.id)) { > + drm_dbg_atomic(dev, > + "[PLANE:%d:%s] is enabled on [CRTC:%d:%s], which isn't leased\n", > + plane->base.id, plane->name, > + plane->state->crtc->base.id, > + plane->state->crtc->name); > + return -ENOENT; > + } > + > + plane_state = plane->funcs->atomic_create_state(plane); > + if (IS_ERR(plane_state)) > + return PTR_ERR(plane_state); > + > + /* > + * Like the CRTC LUTs and CTM above, the pristine state > + * comes with no color pipeline, and neither restoring > + * that default nor leaving the property untouched sets > + * color_mgmt_changed, even though the commit clears the > + * pipeline currently programmed. Compare with the current > + * state so that the drivers reprogram the color > + * management hardware. > + */ > + plane_state->color_mgmt_changed = > + plane->state->color_pipeline != plane_state->color_pipeline; > + > + drm_atomic_commit_set_plane_state(commit, plane, plane_state); > + } > + > + ret = drm_modeset_lock(&config->connection_mutex, commit->acquire_ctx); > + if (ret) > + return ret; > + > + drm_connector_list_iter_begin(dev, &conn_iter); > + drm_for_each_connector_iter(connector, &conn_iter) { > + struct drm_connector_state *connector_state; > + > + if (!drm_lease_held(file_priv, connector->base.id)) { > + /* > + * Same as the planes of a leased CRTC: the reset > + * disables that CRTC, and a connector the lease > + * doesn't cover can't be unbound from it. > + */ > + if (connector->state->crtc && > + drm_lease_held(file_priv, > + connector->state->crtc->base.id)) { > + drm_dbg_atomic(dev, > + "[CONNECTOR:%d:%s] isn't leased, but [CRTC:%d:%s] it is bound to is\n", > + connector->base.id, connector->name, > + connector->state->crtc->base.id, > + connector->state->crtc->name); > + drm_connector_list_iter_end(&conn_iter); > + return -ENOENT; > + } > + > + continue; > + } > + > + /* > + * Same as the planes above: unbinding the connector from > + * an unleased CRTC would need that CRTC in the commit. > + */ > + if (connector->state->crtc && > + !drm_lease_held(file_priv, connector->state->crtc->base.id)) { > + drm_dbg_atomic(dev, > + "[CONNECTOR:%d:%s] is bound to [CRTC:%d:%s], which isn't leased\n", > + connector->base.id, connector->name, > + connector->state->crtc->base.id, > + connector->state->crtc->name); > + drm_connector_list_iter_end(&conn_iter); > + return -ENOENT; > + } > + > + /* > + * drm_atomic_implements_create_state() already checked > + * this, but connectors can be hotplugged between that > + * lockless check and the iteration here. > + */ > + if (!connector->funcs->atomic_create_state) { > + drm_connector_list_iter_end(&conn_iter); > + return -EOPNOTSUPP; > + } > + > + connector_state = connector->funcs->atomic_create_state(connector); > + if (IS_ERR(connector_state)) { > + drm_connector_list_iter_end(&conn_iter); > + ret = PTR_ERR(connector_state); > + return ret; > + } > + > + /* > + * best_encoder is a routing information maintained by the > + * atomic helpers rather than a userspace property, and it > + * is only carried over to a new state when that state is a > + * duplicate of the current one. Since > + * update_connector_routing() uses it to detect the commits > + * that keep the connector routing unchanged, carry the > + * encoder currently in use over so that a reset on which > + * userspace re-applies the exact same configuration doesn't > + * require a modeset. > + */ > + connector_state->best_encoder = connector->state->best_encoder; > + > + ret = drm_atomic_commit_set_connector_state(commit, connector, connector_state); > + if (ret) { > + connector->funcs->atomic_destroy_state(connector, connector_state); > + drm_connector_list_iter_end(&conn_iter); > + return ret; > + } > + } > + drm_connector_list_iter_end(&conn_iter); > + > + /* > + * Revoking a lease doesn't take any modeset lock, so it can > + * still happen right after this check. The loops above all saw > + * the whole lease then, and the commit is consistent. This is > + * the same window any other commit from a lessee has between > + * the lease checks and the commit. > + */ > + if (drm_lease_revoked(file_priv)) { > + drm_dbg_atomic(dev, "Lease revoked while resetting the state\n"); > + return -ENOENT; > + } > + > + return 0; > +} > +EXPORT_SYMBOL(drm_atomic_commit_fill_with_defaults); > + > /** > * drm_atomic_add_encoder_bridges - add bridges attached to an encoder > * @state: atomic state > * @encoder: DRM encoder > * > diff --git a/include/drm/drm_atomic.h b/include/drm/drm_atomic.h > index 72c3d420f40c..cac74d43a34d 100644 > --- a/include/drm/drm_atomic.h > +++ b/include/drm/drm_atomic.h > @@ -701,10 +701,12 @@ int drm_crtc_commit_wait(struct drm_crtc_commit *commit); > struct drm_atomic_commit * __must_check > drm_atomic_commit_alloc(struct drm_device *dev); > void drm_atomic_commit_clear(struct drm_atomic_commit *state); > > bool drm_atomic_implements_create_state(struct drm_device *dev); > +int drm_atomic_commit_fill_with_defaults(struct drm_file *file_priv, > + struct drm_atomic_commit *commit); > > /** > * drm_atomic_commit_get - acquire a reference to the atomic state > * @state: The atomic state > * > -- -- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com GF: Stefan Gaiser, Jochen Jaser, Abhinav Puri, (HRB 36809, AG Nürnberg)