dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Maxime Ripard <mripard@kernel.org>
To: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	 Thomas Zimmermann <tzimmermann@suse.de>,
	David Airlie <airlied@gmail.com>,
	 Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org,
	Maxime Ripard <mripard@kernel.org>,
	 Paul Cercueil <paul@crapouillou.net>,
	linux-mips@vger.kernel.org
Subject: [PATCH 09/16] drm/ingenic: Switch private_obj initialization to reset
Date: Wed, 08 Oct 2025 14:04:07 +0200	[thread overview]
Message-ID: <20251008-drm-private-obj-reset-v1-9-805ab43ae65a@kernel.org> (raw)
In-Reply-To: <20251008-drm-private-obj-reset-v1-0-805ab43ae65a@kernel.org>

The ingenic driver relies on two drm_private_objs, that are initialized
by allocating and initializing a state, and then passing it to
drm_private_obj_init.

Since we're gradually moving away from that pattern to the more
established one relying on a reset implementation, let's migrate this
instance to the new pattern.

Signed-off-by: Maxime Ripard <mripard@kernel.org>

---

Cc: Paul Cercueil <paul@crapouillou.net>
Cc: linux-mips@vger.kernel.org
---
 drivers/gpu/drm/ingenic/ingenic-drm-drv.c | 30 +++++++++++++++++++-----------
 drivers/gpu/drm/ingenic/ingenic-ipu.c     | 30 ++++++++++++++++++------------
 2 files changed, 37 insertions(+), 23 deletions(-)

diff --git a/drivers/gpu/drm/ingenic/ingenic-drm-drv.c b/drivers/gpu/drm/ingenic/ingenic-drm-drv.c
index 9db1ceaed5188a4ef0897280dc72108eb3815b5f..18f20d96f6e4a7d9e5209ee770c7b4fc81adbad7 100644
--- a/drivers/gpu/drm/ingenic/ingenic-drm-drv.c
+++ b/drivers/gpu/drm/ingenic/ingenic-drm-drv.c
@@ -947,10 +947,26 @@ static void ingenic_drm_destroy_state(struct drm_private_obj *obj,
 	struct ingenic_drm_private_state *priv_state = to_ingenic_drm_priv_state(state);
 
 	kfree(priv_state);
 }
 
+static void ingenic_drm_reset(struct drm_private_obj *obj)
+{
+	struct ingenic_drm_private_state *priv_state;
+
+	if (obj->state) {
+		ingenic_drm_destroy_state(obj, obj->state);
+		obj->state = NULL;
+	}
+
+	priv_state = kzalloc(sizeof(*priv_state), GFP_KERNEL);
+	if (!priv_state)
+		return;
+
+	__drm_atomic_helper_private_obj_reset(obj, &priv_state->base);
+}
+
 DEFINE_DRM_GEM_DMA_FOPS(ingenic_drm_fops);
 
 static const struct drm_driver ingenic_drm_driver_data = {
 	.driver_features	= DRIVER_MODESET | DRIVER_GEM | DRIVER_ATOMIC,
 	.name			= "ingenic-drm",
@@ -1029,10 +1045,11 @@ static struct drm_mode_config_helper_funcs ingenic_drm_mode_config_helpers = {
 };
 
 static const struct drm_private_state_funcs ingenic_drm_private_state_funcs = {
 	.atomic_duplicate_state = ingenic_drm_duplicate_state,
 	.atomic_destroy_state = ingenic_drm_destroy_state,
+	.reset = ingenic_drm_reset,
 };
 
 static void ingenic_drm_unbind_all(void *d)
 {
 	struct ingenic_drm *priv = d;
@@ -1080,11 +1097,10 @@ static void ingenic_drm_atomic_private_obj_fini(struct drm_device *drm, void *pr
 }
 
 static int ingenic_drm_bind(struct device *dev, bool has_components)
 {
 	struct platform_device *pdev = to_platform_device(dev);
-	struct ingenic_drm_private_state *private_state;
 	const struct jz_soc_info *soc_info;
 	struct ingenic_drm *priv;
 	struct clk *parent_clk;
 	struct drm_plane *primary;
 	struct drm_bridge *bridge;
@@ -1380,23 +1396,17 @@ static int ingenic_drm_bind(struct device *dev, bool has_components)
 	if (ret) {
 		dev_err(dev, "Unable to register clock notifier\n");
 		goto err_devclk_disable;
 	}
 
-	private_state = kzalloc(sizeof(*private_state), GFP_KERNEL);
-	if (!private_state) {
-		ret = -ENOMEM;
-		goto err_clk_notifier_unregister;
-	}
-
-	drm_atomic_private_obj_init(drm, &priv->private_obj, &private_state->base,
+	drm_atomic_private_obj_init(drm, &priv->private_obj, NULL,
 				    &ingenic_drm_private_state_funcs);
 
 	ret = drmm_add_action_or_reset(drm, ingenic_drm_atomic_private_obj_fini,
 				       &priv->private_obj);
 	if (ret)
-		goto err_private_state_free;
+		goto err_clk_notifier_unregister;
 
 	ret = drm_dev_register(drm, 0);
 	if (ret) {
 		dev_err(dev, "Failed to register DRM driver\n");
 		goto err_clk_notifier_unregister;
@@ -1404,12 +1414,10 @@ static int ingenic_drm_bind(struct device *dev, bool has_components)
 
 	drm_client_setup(drm, NULL);
 
 	return 0;
 
-err_private_state_free:
-	kfree(private_state);
 err_clk_notifier_unregister:
 	clk_notifier_unregister(parent_clk, &priv->clock_nb);
 err_devclk_disable:
 	if (priv->lcd_clk)
 		clk_disable_unprepare(priv->lcd_clk);
diff --git a/drivers/gpu/drm/ingenic/ingenic-ipu.c b/drivers/gpu/drm/ingenic/ingenic-ipu.c
index 26ebf424d63ec21ccee80221745c3e8bcc6b3d7f..ddaf80052f03b8e366c89a6562b430a400b6dacd 100644
--- a/drivers/gpu/drm/ingenic/ingenic-ipu.c
+++ b/drivers/gpu/drm/ingenic/ingenic-ipu.c
@@ -748,13 +748,30 @@ static void ingenic_ipu_destroy_state(struct drm_private_obj *obj,
 	struct ingenic_ipu_private_state *priv_state = to_ingenic_ipu_priv_state(state);
 
 	kfree(priv_state);
 }
 
+static void ingenic_ipu_reset(struct drm_private_obj *obj)
+{
+	struct ingenic_ipu_private_state *priv_state;
+
+	if (obj->state) {
+		ingenic_ipu_destroy_state(obj, obj->state);
+		obj->state = NULL;
+	}
+
+	priv_state = kzalloc(sizeof(*priv_state), GFP_KERNEL);
+	if (!priv_state)
+		return;
+
+	__drm_atomic_helper_private_obj_reset(obj, &priv_state->base);
+}
+
 static const struct drm_private_state_funcs ingenic_ipu_private_state_funcs = {
 	.atomic_duplicate_state = ingenic_ipu_duplicate_state,
 	.atomic_destroy_state = ingenic_ipu_destroy_state,
+	.reset = ingenic_ipu_reset,
 };
 
 static irqreturn_t ingenic_ipu_irq_handler(int irq, void *arg)
 {
 	struct ingenic_ipu *ipu = arg;
@@ -791,11 +808,10 @@ static const struct regmap_config ingenic_ipu_regmap_config = {
 };
 
 static int ingenic_ipu_bind(struct device *dev, struct device *master, void *d)
 {
 	struct platform_device *pdev = to_platform_device(dev);
-	struct ingenic_ipu_private_state *private_state;
 	const struct soc_info *soc_info;
 	struct drm_device *drm = d;
 	struct drm_plane *plane;
 	struct ingenic_ipu *ipu;
 	void __iomem *base;
@@ -885,24 +901,14 @@ static int ingenic_ipu_bind(struct device *dev, struct device *master, void *d)
 	if (err) {
 		dev_err(dev, "Unable to prepare clock\n");
 		return err;
 	}
 
-	private_state = kzalloc(sizeof(*private_state), GFP_KERNEL);
-	if (!private_state) {
-		err = -ENOMEM;
-		goto err_clk_unprepare;
-	}
-
-	drm_atomic_private_obj_init(drm, &ipu->private_obj, &private_state->base,
+	drm_atomic_private_obj_init(drm, &ipu->private_obj, NULL,
 				    &ingenic_ipu_private_state_funcs);
 
 	return 0;
-
-err_clk_unprepare:
-	clk_unprepare(ipu->clk);
-	return err;
 }
 
 static void ingenic_ipu_unbind(struct device *dev,
 			       struct device *master, void *d)
 {

-- 
2.51.0


  parent reply	other threads:[~2025-10-08 12:04 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-08 12:03 [PATCH 00/16] drm/atomic: Switch drm_private_obj to reset Maxime Ripard
2025-10-08 12:03 ` [PATCH 01/16] drm/atomic: Add dev pointer to drm_private_obj Maxime Ripard
2025-10-08 13:21   ` Tomi Valkeinen
2025-10-08 15:48   ` Dmitry Baryshkov
2025-10-08 12:04 ` [PATCH 02/16] drm/atomic: Add reset " Maxime Ripard
2025-10-08 13:24   ` Tomi Valkeinen
2025-10-08 12:04 ` [PATCH 03/16] drm/atomic-helper: Add private_obj reset helper Maxime Ripard
2025-10-08 13:27   ` Tomi Valkeinen
2025-10-08 18:35   ` Dmitry Baryshkov
2025-10-08 12:04 ` [PATCH 04/16] drm/bridge: Switch private_obj initialization to reset Maxime Ripard
2025-10-08 18:40   ` Dmitry Baryshkov
2025-10-10  9:47   ` kernel test robot
2025-10-08 12:04 ` [PATCH 05/16] drm/dp_mst: " Maxime Ripard
2025-10-08 14:06   ` Ville Syrjälä
2025-10-08 14:53     ` Maxime Ripard
2025-10-08 16:12       ` Ville Syrjälä
2025-10-09 14:42         ` Maxime Ripard
2025-10-09 16:03           ` Ville Syrjälä
2025-10-08 16:24     ` Imre Deak
2025-10-14 22:35       ` Dmitry Baryshkov
2025-10-16  6:36         ` Imre Deak
2025-10-08 12:04 ` [PATCH 06/16] drm/dp_tunnel: " Maxime Ripard
2025-10-08 12:04 ` [PATCH 07/16] drm/amdgpu: " Maxime Ripard
2025-10-08 12:04 ` [PATCH 08/16] drm/arm: komeda: " Maxime Ripard
2025-10-08 12:04 ` Maxime Ripard [this message]
2025-10-08 12:04 ` [PATCH 10/16] drm/msm: mdp5: " Maxime Ripard
2025-10-08 18:48   ` Dmitry Baryshkov
2025-10-08 12:04 ` [PATCH 11/16] drm/msm: dpu1: " Maxime Ripard
2025-10-08 18:47   ` Dmitry Baryshkov
2025-10-08 12:04 ` [PATCH 12/16] drm/omapdrm: " Maxime Ripard
2025-10-08 13:29   ` Tomi Valkeinen
2025-10-08 12:04 ` [PATCH 13/16] drm/tegra: " Maxime Ripard
2025-10-08 12:04 ` [PATCH 14/16] drm/vc4: " Maxime Ripard
2025-10-08 12:04 ` [PATCH 15/16] drm/atomic: Remove state argument to drm_atomic_private_obj_init Maxime Ripard
2025-10-08 13:30   ` Tomi Valkeinen
2025-10-08 18:50   ` Dmitry Baryshkov
2025-10-08 12:04 ` [PATCH 16/16] drm/mode_config: Call private obj reset with the other objects Maxime Ripard
2025-10-08 18:52   ` Dmitry Baryshkov

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=20251008-drm-private-obj-reset-v1-9-805ab43ae65a@kernel.org \
    --to=mripard@kernel.org \
    --cc=airlied@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=paul@crapouillou.net \
    --cc=simona@ffwll.ch \
    --cc=tzimmermann@suse.de \
    /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;
as well as URLs for NNTP newsgroup(s).