From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D52934FD7A1 for ; Fri, 18 Sep 2026 14:18:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789741117; cv=none; b=twCeTbxbKGGjSPprL1J9SeRzY7GVtObmguzcwBU71PQ94u2ij+zwp4caT6bj4m6WuKKPHJYGYZqmmofWFHn6MGomFd0To9NXZNAJ4bBm3gDBOW01CfAYKj2ugehvmzwpcn9f9IEwY9ttO0tJukk5jbHRdhADF/KJheX1rhBI5d8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789741117; c=relaxed/simple; bh=Y2C0R8Cqaha9hjFthUOVKj33fKhAPVyJIizpHUxj51g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ic/pypvPTYKi27C8xQrWAT7RA0kmf27Xsj74MfDwVotIkMr77Tu9MpA4p+cMw7R3Q54YJfXH+jz8tKh3bV2fpANE033/QPfm7/S9BIwwjPgCV0bgxY7XuseJQGn334nzAMEVgbpKQjHM7qy+MB5QjCqGSrEGdK0JIu5Xpa9PBn4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jfAkDGz3; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jfAkDGz3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 36BFE1F000FF; Fri, 18 Sep 2026 14:18:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1789741115; bh=YDMIPGUl+kZWgLXxI0SgyFsNQfsPJ7fl/r1DvGq25QY=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=jfAkDGz37yAhSEY1R60wyCUW/EjIKnBVWJEL5nyaVQcggh14NgtXqy/QGkn91Mn1A T9QUBUNn0EYoEdviGNuAgsZfyMzSEyx0uNBh52+vjwVdzEmiWVWu9t0YDkOcxCYIu4 t9DvbBByjg92th615fkTw1KiJ2wLzNW4V9e+1FcNJ1Bw2LZM83pK2Yaxlt6nPXppKj N6oBKwb1tgmgkaOeQOXrxtxgpoRl6sTb3gzdau1eTdYMJB+bxrKsA6ZTD7rWc5siou 1cBURuDLOg3EqjPT7nboMbMSXdp/acb1amj8Lm4ESno+iHfrr2lGR98x4DfGJgT7sE X0y1bQJy2Be8w== From: Maxime Ripard Date: Fri, 18 Sep 2026 16:17:58 +0200 Subject: [PATCH v4 09/13] drm/atomic: Add drm_atomic_implements_create_state() helper Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260918-drm-reset-state-flag-v4-9-5ad106370f05@kernel.org> References: <20260918-drm-reset-state-flag-v4-0-5ad106370f05@kernel.org> In-Reply-To: <20260918-drm-reset-state-flag-v4-0-5ad106370f05@kernel.org> To: Maarten Lankhorst , Thomas Zimmermann , 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, Maxime Ripard X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3580; i=mripard@kernel.org; h=from:subject:message-id; bh=Y2C0R8Cqaha9hjFthUOVKj33fKhAPVyJIizpHUxj51g=; b=owGbwMvMwCmsHn9OcpHtvjLG02pJDFlrPYTdm7alft+z5d2u6u3afLO+v73Y2PDj+R4rNeYzI TejjHrbOqayMAhzMsiKKbI8kQk7vbx9cZWD/cofMHNYmUCGMHBxCsBEingY6/1CLgd33U48ttu3 hGXFzJlTOJKmOUuabTqq/bn1zT8uuYMfMjY7WxzcvMBXpbhRQP3vY8b6vDPbOHMid62581XY6c4 rsX5ZlUMTzG+8vTq9yzFHiDlviX70Pt93DybdcL3FMv+Jk9hpAA== X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D The atomic reset path will need to create pristine default states from scratch for every plane, CRTC, and connector. This requires all of them to implement the atomic_create_state hook. Introduce a drm_atomic_implements_create_state() helper that iterates over all planes, CRTCs, and connectors and returns whether they all provide the hook. Color operations are excluded since they always use drm_atomic_helper_colorop_create_state() directly. This will be used both as a precondition before filling a commit with default states, and to report the device capability to userspace. Signed-off-by: Maxime Ripard --- drivers/gpu/drm/drm_atomic.c | 49 ++++++++++++++++++++++++++++++++++++++++++++ include/drm/drm_atomic.h | 2 ++ 2 files changed, 51 insertions(+) diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c index 81591173265d..7a77051096c9 100644 --- a/drivers/gpu/drm/drm_atomic.c +++ b/drivers/gpu/drm/drm_atomic.c @@ -1598,10 +1598,59 @@ drm_atomic_get_new_bridge_state(const struct drm_atomic_commit *state, return drm_priv_to_bridge_state(obj_state); } EXPORT_SYMBOL(drm_atomic_get_new_bridge_state); +/** + * drm_atomic_implements_create_state - check if a device supports creating pristine states + * @dev: DRM device + * + * Check whether every plane, CRTC, and connector in @dev implements the + * &drm_plane_funcs.atomic_create_state, &drm_crtc_funcs.atomic_create_state, + * and &drm_connector_funcs.atomic_create_state hooks respectively. These hooks + * are required to create default states from scratch rather than duplicating + * the current state. + * + * Color operations are not checked because they always use + * drm_atomic_helper_colorop_create_state() and do not have a per-driver hook. + * + * Returns: + * True if all objects implement atomic_create_state, false otherwise. + */ +bool drm_atomic_implements_create_state(struct drm_device *dev) +{ + struct drm_connector_list_iter conn_iter; + struct drm_connector *connector; + struct drm_plane *plane; + struct drm_crtc *crtc; + + /* + * colorops don't have an atomic_create_state hook but + * drm_atomic_helper_colorop_create_state() + */ + + drm_for_each_plane(plane, dev) + if (!plane->funcs->atomic_create_state) + return false; + + drm_for_each_crtc(crtc, dev) + if (!crtc->funcs->atomic_create_state) + return false; + + drm_connector_list_iter_begin(dev, &conn_iter); + drm_for_each_connector_iter(connector, &conn_iter) { + if (!connector->funcs->atomic_create_state) { + drm_connector_list_iter_end(&conn_iter); + return false; + } + } + drm_connector_list_iter_end(&conn_iter); + + return true; +} +EXPORT_SYMBOL(drm_atomic_implements_create_state); + /** * 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 3ae35b09c0cf..94356566a514 100644 --- a/include/drm/drm_atomic.h +++ b/include/drm/drm_atomic.h @@ -700,10 +700,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_can_create_state(struct drm_device *dev); + /** * drm_atomic_commit_get - acquire a reference to the atomic state * @state: The atomic state * * Returns a new reference to the @state -- 2.55.0