Skip to content

Commit

Permalink
drm/ast: Replace driver load/unload functions with device create/destroy
Browse files Browse the repository at this point in the history
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: Thomas Zimmermann <tzimmermann@suse.de>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Acked-by: Sam Ravnborg <sam@ravnborg.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20200730135206.30239-4-tzimmermann@suse.de
  • Loading branch information
Thomas Zimmermann committed Aug 3, 2020
1 parent d50ace1 commit fbe0171
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
24 changes: 11 additions & 13 deletions drivers/gpu/drm/ast/ast_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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);
}

Expand Down
6 changes: 4 additions & 2 deletions drivers/gpu/drm/ast/ast_drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 18 additions & 6 deletions drivers/gpu/drm/ast/ast_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit fbe0171

Please sign in to comment.