Commit a71ff21e authored by Thomas Zimmermann's avatar Thomas Zimmermann

drm/mgag200: Switch to managed MM

The memory-management code now cleans up automatically as part of
device destruction.
Signed-off-by: default avatarThomas Zimmermann <tzimmermann@suse.de>
Acked-by: default avatarSam Ravnborg <sam@ravnborg.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20200605135803.19811-8-tzimmermann@suse.de
parent e9f896b7
......@@ -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__ */
......@@ -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;
}
......@@ -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);
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;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment