From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 099F1606A330 for ; Fri, 20 Nov 2026 12:56:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=cOOjgrd9 Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AFE571129F7; Fri, 20 Nov 2026 12:56:38 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 715021129E5 for ; Fri, 20 Nov 2026 12:56:29 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 578BB45F9F; Fri, 20 Nov 2026 12:56:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54C9D1F00A36; Fri, 20 Nov 2026 12:56:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795179388; bh=v0wOYI9rNuZJuZ5iP1cFOFw7Rw7piVOcCe6x0I+N5OQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=cOOjgrd9pqxFpguc9LjhJGgVRl5gxSOLsiTWbqI6ocC2eeQTuGHxQYxK1OCxr0tIl DJSKpmQ7DA2vfuPWANYerfANEL4mBAKL3GhLOoiPdUwHn/kMkRKo/L4W7lSRgHW1S2 Q4nSAy5kkkU2NY7nGTEmwC5ghPbms/zoJBPAonCzhzO2hvwz6IfgB/E5F9phFzFZsW s2ID4eV0aWEUjYyYtTwnNJIaYJEufVo0nmCi2EU0jHG7H8CQxtmlXJ5HcD/anXS022 yUtW4LxMDBKrKl/S5i2zrZAxMl2feNjvH4FQ0ZUSz2X5cNzoTUiAGbPiWgeON7l0hF iDF8P3hP9CsYQ== From: Maxime Ripard Date: Fri, 20 Nov 2026 13:55:12 +0100 Subject: [PATCH v9 20/42] drm/mode-config: Introduce hw_reset hook X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261120-drm-state-readout-v9-20-a67c2b45b8ec@kernel.org> References: <20261120-drm-state-readout-v9-0-a67c2b45b8ec@kernel.org> In-Reply-To: <20261120-drm-state-readout-v9-0-a67c2b45b8ec@kernel.org> To: Maarten Lankhorst , Thomas Zimmermann , David Airlie , Simona Vetter , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Jyri Sarha , Tomi Valkeinen Cc: Devarsh Thakkar , dri-devel@lists.freedesktop.org, Maxime Ripard X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4698; i=mripard@kernel.org; h=from:subject:message-id; bh=hKsnM2BRbkgN8HD/shzLSf7w0GmQ5UsIB95kL95l/24=; b=owGbwMvMwCmsHn9OcpHtvjLG02pJDNkMztoX+zd7KJ0UMfV233Hrloj035UPCrat9SyfJt6cP fnvqk22HVNZGIQ5GWTFFFmeyISdXt6+uMrBfuUPmDmsTCBDGLg4BWAiyy8wNtxIcGKf2b7ve1LH p3Pqd6vlcsRly6tnLI+atm12SZ7bxNObzr3yzk/fyFj926P534w1IYz15d/F6kLcNVZ9lXLVFKz e5du8Q/699t5NK8oyJGsrXh1IUNrDujRn45zoaW7/N8++v+kMAA== X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "dri-devel" X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 drm_mode_config_create_initial_state() tries to read out the current hardware state to build the initial atomic state. If state readout is disabled or fails, it falls back to creating pristine software state using the objects' atomic_create_state callbacks. However, creating pristine state without resetting the hardware leaves the hardware and software states out of sync. The legacy drm_mode_config_reset() handles this by calling per-object .reset callbacks that both reset the hardware and allocate new state, but these two concerns are intertwined and cannot be reused independently. Introduce a new hw_reset hook in drm_mode_config_funcs that only performs the hardware reset, without allocating any software state. Call it in drm_mode_config_create_initial_state() after state readout fails, right before falling back to drm_mode_config_create_state(). This separates the hardware reset from state creation, allowing drivers that implement state readout to share their reset logic with the fallback path. Reviewed-by: Maarten Lankhorst Signed-off-by: Maxime Ripard --- drivers/gpu/drm/drm_mode_config.c | 8 +++++++- include/drm/drm_mode_config.h | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_mode_config.c b/drivers/gpu/drm/drm_mode_config.c index d6f92e1a54d2..0259ec48cfbc 100644 --- a/drivers/gpu/drm/drm_mode_config.c +++ b/drivers/gpu/drm/drm_mode_config.c @@ -404,11 +404,12 @@ static int drm_mode_config_create_state(struct drm_device *dev) * 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 + * read-out isn't supported or fails, it resets the hardware using + * &drm_mode_config_funcs.hw_reset() and 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. @@ -438,10 +439,15 @@ int drm_mode_config_create_initial_state(struct drm_device *dev) ret = dev->mode_config.funcs->atomic_sro_readout_state(dev); if (!ret) goto out; } + /* Reset the hardware first ... */ + if (dev->mode_config.funcs->hw_reset) + dev->mode_config.funcs->hw_reset(dev); + + /* ... then allocate a new pristine state */ ret = drm_mode_config_create_state(dev); out: DRM_MODESET_LOCK_ALL_END(dev, ctx, ret); diff --git a/include/drm/drm_mode_config.h b/include/drm/drm_mode_config.h index e1124b314524..42d37f4aba84 100644 --- a/include/drm/drm_mode_config.h +++ b/include/drm/drm_mode_config.h @@ -107,10 +107,42 @@ struct drm_mode_config_funcs { * should be checked in the .mode_valid() hook for each specific object. */ enum drm_mode_status (*mode_valid)(struct drm_device *dev, const struct drm_display_mode *mode); + /** + * @hw_reset: + * + * Optional hook for device-specific hardware reset. + * + * Unlike drm_mode_config_reset(), which both resets hardware + * and creates new software state through per-object .reset + * callbacks, this hook only resets the hardware to a known good + * state without touching the software state at all. + * + * This hook is called by + * drm_mode_config_create_initial_state() when the hardware + * state readout (atomic_sro_readout_state) is not supported + * or fails. The call sequence is: + * + * 1. Try atomic_sro_readout_state() to read the hardware state + * 2. If that fails, call hw_reset() to put the hardware in a + * known state + * 3. Create pristine software state via atomic_create_state + * callbacks + * + * 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. + * + * 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); + /** * @atomic_check: * * This is the only hook to validate an atomic modeset update. This * function must reject any modeset and state changes which the hardware -- 2.56.1