dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Zimmermann <tzimmermann@suse.de>
To: airlied@redhat.com, daniel@ffwll.ch, sam@ravnborg.org,
	emil.l.velikov@gmail.com, kraxel@redhat.com,
	yc_chen@aspeedtech.com
Cc: Thomas Zimmermann <tzimmermann@suse.de>, dri-devel@lists.freedesktop.org
Subject: [PATCH 13/13] drm/ast: Managed device release
Date: Tue, 28 Jul 2020 09:44:25 +0200	[thread overview]
Message-ID: <20200728074425.2749-14-tzimmermann@suse.de> (raw)
In-Reply-To: <20200728074425.2749-1-tzimmermann@suse.de>

This turns the ast's device cleanup code into a managed release helper
function. Note that the code uses devres helpers. The release function
switches the device back to VGA mode and therefore runs during HW device
cleanup; not at DRM device cleanup.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/gpu/drm/ast/ast_drv.c  | 17 +++--------------
 drivers/gpu/drm/ast/ast_drv.h  |  1 -
 drivers/gpu/drm/ast/ast_main.c | 22 ++++++++++++++++------
 3 files changed, 19 insertions(+), 21 deletions(-)

diff --git a/drivers/gpu/drm/ast/ast_drv.c b/drivers/gpu/drm/ast/ast_drv.c
index c394383a7979..f0b4af1c390a 100644
--- a/drivers/gpu/drm/ast/ast_drv.c
+++ b/drivers/gpu/drm/ast/ast_drv.c
@@ -120,35 +120,24 @@ static int ast_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 		return ret;
 
 	ast = ast_device_create(&ast_driver, pdev, ent->driver_data);
-	if (IS_ERR(ast)) {
-		ret = PTR_ERR(ast);
-		goto err_drm_dev_put;
-	}
+	if (IS_ERR(ast))
+		return PTR_ERR(ast);
 	dev = &ast->base;
 
 	ret = drm_dev_register(dev, ent->driver_data);
 	if (ret)
-		goto err_ast_device_destroy;
+		return ret;
 
 	drm_fbdev_generic_setup(dev, 32);
 
 	return 0;
-
-err_ast_device_destroy:
-	ast_device_destroy(ast);
-err_drm_dev_put:
-	drm_dev_put(dev);
-	return ret;
 }
 
 static void ast_pci_remove(struct pci_dev *pdev)
 {
 	struct drm_device *dev = pci_get_drvdata(pdev);
-	struct ast_private *ast = to_ast_private(dev);
 
 	drm_dev_unregister(dev);
-	ast_device_destroy(ast);
-	drm_dev_put(dev);
 }
 
 static int ast_drm_freeze(struct drm_device *dev)
diff --git a/drivers/gpu/drm/ast/ast_drv.h b/drivers/gpu/drm/ast/ast_drv.h
index 02908d005b99..0911136e0842 100644
--- a/drivers/gpu/drm/ast/ast_drv.h
+++ b/drivers/gpu/drm/ast/ast_drv.h
@@ -162,7 +162,6 @@ static inline struct ast_private *to_ast_private(struct drm_device *dev)
 struct ast_private *ast_device_create(struct drm_driver *drv,
 				      struct pci_dev *pdev,
 				      unsigned long flags);
-void ast_device_destroy(struct ast_private *ast);
 
 #define AST_IO_AR_PORT_WRITE		(0x40)
 #define AST_IO_MISC_PORT_WRITE		(0x42)
diff --git a/drivers/gpu/drm/ast/ast_main.c b/drivers/gpu/drm/ast/ast_main.c
index 67e20727d82d..d62749a10cdd 100644
--- a/drivers/gpu/drm/ast/ast_main.c
+++ b/drivers/gpu/drm/ast/ast_main.c
@@ -380,6 +380,18 @@ static int ast_get_dram_info(struct drm_device *dev)
 	return 0;
 }
 
+/*
+ * Run this function as part of the HW device cleanup; not
+ * when the DRM device gets released.
+ */
+static void ast_device_release(void *data)
+{
+	struct ast_private *ast = data;
+
+	/* enable standard VGA decode */
+	ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xa1, 0x04);
+}
+
 struct ast_private *ast_device_create(struct drm_driver *drv,
 				      struct pci_dev *pdev,
 				      unsigned long flags)
@@ -438,11 +450,9 @@ struct ast_private *ast_device_create(struct drm_driver *drv,
 	if (ret)
 		return ERR_PTR(ret);
 
-	return ast;
-}
+	ret = devm_add_action_or_reset(dev->dev, ast_device_release, ast);
+	if (ret)
+		return ERR_PTR(ret);
 
-void ast_device_destroy(struct ast_private *ast)
-{
-	/* enable standard VGA decode */
-	ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xa1, 0x04);
+	return ast;
 }
-- 
2.27.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  parent reply	other threads:[~2020-07-28  7:45 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-28  7:44 [PATCH 00/13] drm/ast: Convert to managed initialization Thomas Zimmermann
2020-07-28  7:44 ` [PATCH 01/13] drm/ast: Move I2C code within ast_mode.c Thomas Zimmermann
2020-07-28 18:04   ` Sam Ravnborg
2020-07-30  9:18     ` Thomas Zimmermann
2020-07-28  7:44 ` [PATCH 02/13] drm/ast: Test if I2C support has been initialized Thomas Zimmermann
2020-07-28 17:38   ` Sam Ravnborg
2020-07-28  7:44 ` [PATCH 03/13] drm/ast: Embed I2C fields in struct ast_connector Thomas Zimmermann
2020-07-28  7:44 ` [PATCH 04/13] drm/ast: Managed release of I2C adapter Thomas Zimmermann
2020-07-28  9:23   ` daniel
2020-07-28  9:33     ` Thomas Zimmermann
2020-07-30  9:19     ` Thomas Zimmermann
2020-07-28 18:06   ` Sam Ravnborg
2020-07-30  9:23     ` Thomas Zimmermann
2020-07-28  7:44 ` [PATCH 05/13] drm/ast: Embed CRTC and connector in struct ast_private Thomas Zimmermann
2020-07-28  7:44 ` [PATCH 06/13] drm/ast: Separate DRM driver from PCI code Thomas Zimmermann
2020-07-28  7:44 ` [PATCH 07/13] drm/ast: Replace driver load/unload functions with device create/destroy Thomas Zimmermann
2020-07-28  7:44 ` [PATCH 08/13] drm/ast: Replace struct_drm_device.dev_private with to_ast_private() Thomas Zimmermann
2020-07-28  7:44 ` [PATCH 09/13] drm/ast: Don't use ast->dev if dev is available Thomas Zimmermann
2020-07-28  7:44 ` [PATCH 10/13] drm/ast: Embed struct drm_device in struct ast_private Thomas Zimmermann
2020-07-28  7:44 ` [PATCH 11/13] drm/ast: Managed release of ast firmware Thomas Zimmermann
2020-07-28  9:17   ` daniel
2020-07-28  9:32     ` Thomas Zimmermann
2020-07-28  9:34       ` daniel
2020-07-28  7:44 ` [PATCH 12/13] drm/ast: Manage release of firmware backup memory Thomas Zimmermann
2020-07-28  9:18   ` daniel
2020-07-28  7:44 ` Thomas Zimmermann [this message]
2020-07-28 18:10 ` [PATCH 00/13] drm/ast: Convert to managed initialization Sam Ravnborg

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=20200728074425.2749-14-tzimmermann@suse.de \
    --to=tzimmermann@suse.de \
    --cc=airlied@redhat.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=emil.l.velikov@gmail.com \
    --cc=kraxel@redhat.com \
    --cc=sam@ravnborg.org \
    --cc=yc_chen@aspeedtech.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;
as well as URLs for NNTP newsgroup(s).