Commit fbe01716 authored by Thomas Zimmermann's avatar Thomas Zimmermann

drm/ast: Replace driver load/unload functions with device create/destroy

The ast driver's load and unload functions are left-overs from when
struct drm_driver.load/unload was still in use. The PCI probe helper
allocated the DRM device and ran load to initialize it.

This patch replaces this code with device create and destroy. The
main difference is that the device's create function allocates the
DRM device and ast structures in the same place. This will be required
for switching ast to managed allocations.
Signed-off-by: default avatarThomas Zimmermann <tzimmermann@suse.de>
Acked-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
Acked-by: default avatarSam Ravnborg <sam@ravnborg.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20200730135206.30239-4-tzimmermann@suse.de
parent d50ace1e
......@@ -109,6 +109,7 @@ static void ast_kick_out_firmware_fb(struct pci_dev *pdev)
static int ast_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
{
struct ast_private *ast;
struct drm_device *dev;
int ret;
......@@ -118,27 +119,23 @@ static int ast_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
if (ret)
return ret;
dev = drm_dev_alloc(&ast_driver, &pdev->dev);
if (IS_ERR(dev))
return PTR_ERR(dev);
dev->pdev = pdev;
pci_set_drvdata(pdev, dev);
ret = ast_driver_load(dev, ent->driver_data);
if (ret)
ast = ast_device_create(&ast_driver, pdev, ent->driver_data);
if (IS_ERR(ast)) {
ret = PTR_ERR(ast);
goto err_drm_dev_put;
}
dev = ast->dev;
ret = drm_dev_register(dev, ent->driver_data);
if (ret)
goto err_ast_driver_unload;
goto err_ast_device_destroy;
drm_fbdev_generic_setup(dev, 32);
return 0;
err_ast_driver_unload:
ast_driver_unload(dev);
err_ast_device_destroy:
ast_device_destroy(ast);
err_drm_dev_put:
drm_dev_put(dev);
return ret;
......@@ -147,9 +144,10 @@ static int ast_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
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_driver_unload(dev);
ast_device_destroy(ast);
drm_dev_put(dev);
}
......
......@@ -159,8 +159,10 @@ static inline struct ast_private *to_ast_private(struct drm_device *dev)
return dev->dev_private;
}
int ast_driver_load(struct drm_device *dev, unsigned long flags);
void ast_driver_unload(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)
......
......@@ -30,6 +30,7 @@
#include <drm/drm_atomic_helper.h>
#include <drm/drm_crtc_helper.h>
#include <drm/drm_drv.h>
#include <drm/drm_gem.h>
#include <drm/drm_gem_vram_helper.h>
......@@ -378,15 +379,25 @@ static int ast_get_dram_info(struct drm_device *dev)
return 0;
}
int ast_driver_load(struct drm_device *dev, unsigned long flags)
struct ast_private *ast_device_create(struct drm_driver *drv,
struct pci_dev *pdev,
unsigned long flags)
{
struct drm_device *dev;
struct ast_private *ast;
bool need_post;
int ret = 0;
dev = drm_dev_alloc(drv, &pdev->dev);
if (IS_ERR(dev))
return ERR_CAST(dev);
dev->pdev = pdev;
pci_set_drvdata(pdev, dev);
ast = kzalloc(sizeof(struct ast_private), GFP_KERNEL);
if (!ast)
return -ENOMEM;
return ERR_PTR(-ENOMEM);
dev->dev_private = ast;
ast->dev = dev;
......@@ -435,16 +446,17 @@ int ast_driver_load(struct drm_device *dev, unsigned long flags)
if (ret)
goto out_free;
return 0;
return ast;
out_free:
kfree(ast);
dev->dev_private = NULL;
return ret;
return ERR_PTR(ret);
}
void ast_driver_unload(struct drm_device *dev)
void ast_device_destroy(struct ast_private *ast)
{
struct ast_private *ast = to_ast_private(dev);
struct drm_device *dev = ast->dev;
/* enable standard VGA decode */
ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xa1, 0x04);
......
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