All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: Thomas Zimmermann <tzimmermann@suse.de>
Cc: dri-devel@lists.freedesktop.org, kraxel@redhat.com,
	airlied@redhat.com, sam@ravnborg.org, emil.velikov@collabora.com
Subject: Re: [PATCH 07/14] drm/mgag200: Switch to managed MM
Date: Fri, 5 Jun 2020 18:22:29 +0200	[thread overview]
Message-ID: <20200605162229.GV20149@phenom.ffwll.local> (raw)
In-Reply-To: <20200605135803.19811-8-tzimmermann@suse.de>

On Fri, Jun 05, 2020 at 03:57:56PM +0200, Thomas Zimmermann wrote:
> The memory-management code now cleans up automatically as part of
> device destruction.
> 
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> ---
>  drivers/gpu/drm/mgag200/mgag200_drv.h  |  1 -
>  drivers/gpu/drm/mgag200/mgag200_main.c |  5 +----
>  drivers/gpu/drm/mgag200/mgag200_mm.c   | 28 ++++++++++++++------------
>  3 files changed, 16 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/gpu/drm/mgag200/mgag200_drv.h b/drivers/gpu/drm/mgag200/mgag200_drv.h
> index cd786ffe319b8..7b6e6827a9a21 100644
> --- a/drivers/gpu/drm/mgag200/mgag200_drv.h
> +++ b/drivers/gpu/drm/mgag200/mgag200_drv.h
> @@ -198,6 +198,5 @@ void mgag200_i2c_destroy(struct mga_i2c_chan *i2c);
>  
>  				/* mgag200_mm.c */
>  int mgag200_mm_init(struct mga_device *mdev);
> -void mgag200_mm_fini(struct mga_device *mdev);
>  
>  #endif				/* __MGAG200_DRV_H__ */
> diff --git a/drivers/gpu/drm/mgag200/mgag200_main.c b/drivers/gpu/drm/mgag200/mgag200_main.c
> index e9ad783c2b44d..49bcdfcb40a4e 100644
> --- a/drivers/gpu/drm/mgag200/mgag200_main.c
> +++ b/drivers/gpu/drm/mgag200/mgag200_main.c
> @@ -57,13 +57,11 @@ int mgag200_driver_load(struct drm_device *dev, unsigned long flags)
>  	ret = mgag200_modeset_init(mdev);
>  	if (ret) {
>  		drm_err(dev, "Fatal error during modeset init: %d\n", ret);
> -		goto err_mgag200_mm_fini;
> +		goto err_mm;
>  	}
>  
>  	return 0;
>  
> -err_mgag200_mm_fini:
> -	mgag200_mm_fini(mdev);
>  err_mm:
>  	dev->dev_private = NULL;
>  	return ret;
> @@ -75,6 +73,5 @@ void mgag200_driver_unload(struct drm_device *dev)
>  
>  	if (mdev == NULL)
>  		return;
> -	mgag200_mm_fini(mdev);
>  	dev->dev_private = NULL;
>  }
> diff --git a/drivers/gpu/drm/mgag200/mgag200_mm.c b/drivers/gpu/drm/mgag200/mgag200_mm.c
> index f56b0456994f4..1b1e5ec5d1ceb 100644
> --- a/drivers/gpu/drm/mgag200/mgag200_mm.c
> +++ b/drivers/gpu/drm/mgag200/mgag200_mm.c
> @@ -28,6 +28,8 @@
>  
>  #include <linux/pci.h>
>  
> +#include <drm/drm_managed.h>
> +
>  #include "mgag200_drv.h"
>  
>  static size_t mgag200_probe_vram(struct mga_device *mdev, void __iomem *mem,
> @@ -73,6 +75,18 @@ static size_t mgag200_probe_vram(struct mga_device *mdev, void __iomem *mem,
>  	return offset - 65536;
>  }
>  
> +static void mgag200_mm_release(struct drm_device *dev, void *ptr)
> +{
> +	struct mga_device *mdev = to_mga_device(dev);
> +
> +	mdev->vram_fb_available = 0;
> +	iounmap(mdev->vram);
> +	arch_io_free_memtype_wc(pci_resource_start(dev->pdev, 0),
> +				pci_resource_len(dev->pdev, 0));
> +	arch_phys_wc_del(mdev->fb_mtrr);
> +	mdev->fb_mtrr = 0;
> +}
> +
>  int mgag200_mm_init(struct mga_device *mdev)
>  {
>  	struct drm_device *dev = mdev->dev;
> @@ -104,22 +118,10 @@ int mgag200_mm_init(struct mga_device *mdev)
>  
>  	mdev->vram_fb_available = mdev->mc.vram_size;
>  
> -	return 0;
> +	return drmm_add_action_or_reset(dev, mgag200_mm_release, NULL);
>  
>  err_arch_phys_wc_del:
>  	arch_phys_wc_del(mdev->fb_mtrr);
>  	arch_io_free_memtype_wc(start, len);

Btw I think devm versions of these two would benefit a bunch of drivers in
their cleanup code. devm_ not drmm_ since it's hw resource cleanup. In
case you ever run out of ideas :-)

Cheeres, Daniel

>  	return ret;
>  }
> -
> -void mgag200_mm_fini(struct mga_device *mdev)
> -{
> -	struct drm_device *dev = mdev->dev;
> -
> -	mdev->vram_fb_available = 0;
> -	iounmap(mdev->vram);
> -	arch_io_free_memtype_wc(pci_resource_start(dev->pdev, 0),
> -				pci_resource_len(dev->pdev, 0));
> -	arch_phys_wc_del(mdev->fb_mtrr);
> -	mdev->fb_mtrr = 0;
> -}
> -- 
> 2.26.2
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2020-06-05 16:22 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-05 13:57 [PATCH 00/14] drm/mgag200: Use managed interfaces for auto-cleanup Thomas Zimmermann
2020-06-05 13:57 ` [PATCH 01/14] drm/mgag200: Remove declaration of mgag200_mmap() from header file Thomas Zimmermann
2020-06-05 13:57   ` Thomas Zimmermann
2020-06-05 13:57 ` [PATCH 02/14] drm/mgag200: Remove mgag200_cursor.c Thomas Zimmermann
2020-06-05 13:57 ` [PATCH 03/14] drm/mgag200: Use pcim_enable_device() Thomas Zimmermann
2020-06-05 13:57 ` [PATCH 04/14] drm/mgag200: Rename mgag200_ttm.c to mgag200_mm.c Thomas Zimmermann
2020-06-05 13:57 ` [PATCH 05/14] drm/mgag200: Lookup VRAM PCI BAR start and length only once Thomas Zimmermann
2020-06-05 13:57 ` [PATCH 06/14] drm/mgag200: Merge VRAM setup into MM initialization Thomas Zimmermann
2020-06-05 14:39   ` Sam Ravnborg
2020-06-08 13:05     ` Thomas Zimmermann
2020-06-05 13:57 ` [PATCH 07/14] drm/mgag200: Switch to managed MM Thomas Zimmermann
2020-06-05 16:22   ` Daniel Vetter [this message]
2020-06-08 12:57     ` Thomas Zimmermann
2020-06-05 13:57 ` [PATCH 08/14] drm/mgag200: Separate DRM and PCI functionality from each other Thomas Zimmermann
2020-06-05 13:57 ` [PATCH 09/14] drm/mgag200: Prefix global names in mgag200_drv.c with mgag200_ Thomas Zimmermann
2020-06-05 14:42   ` Sam Ravnborg
2020-06-08 13:06     ` Thomas Zimmermann
2020-06-05 13:57 ` [PATCH 10/14] drm/mgag200: Move device init and cleanup to mgag200_drv.c Thomas Zimmermann
2020-06-05 14:45   ` Sam Ravnborg
2020-06-05 17:23     ` Thomas Zimmermann
2020-06-05 13:58 ` [PATCH 11/14] drm/mgag200: Separate device initialization into allocation Thomas Zimmermann
2020-06-05 13:58 ` [PATCH 12/14] drm/mgag200: Allocate device structures in mgag200_driver_load() Thomas Zimmermann
2020-06-05 13:58 ` [PATCH 13/14] drm/mgag200: Embed instance of struct drm_device in struct mga_device Thomas Zimmermann
2020-06-05 13:58 ` [PATCH 14/14] drm/mgag200: Use managed device initialization Thomas Zimmermann
2020-06-05 14:50 ` [PATCH 00/14] drm/mgag200: Use managed interfaces for auto-cleanup 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=20200605162229.GV20149@phenom.ffwll.local \
    --to=daniel@ffwll.ch \
    --cc=airlied@redhat.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=emil.velikov@collabora.com \
    --cc=kraxel@redhat.com \
    --cc=sam@ravnborg.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.