Commit e0f5a738 authored by Thomas Zimmermann's avatar Thomas Zimmermann

drm/ast: Embed struct drm_device in struct ast_private

Turns struct ast_private into a subclass of struct drm_device by
embedding the latter. This allows for using DRM's managed device
allocation.

The use of struct drm_device.dev_private is deprecated. The patch
converts the last remaining users to to_ast_private().
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-7-tzimmermann@suse.de
parent 21d79b69
...@@ -57,7 +57,7 @@ static void ast_cursor_release(struct drm_device *dev, void *ptr) ...@@ -57,7 +57,7 @@ static void ast_cursor_release(struct drm_device *dev, void *ptr)
*/ */
int ast_cursor_init(struct ast_private *ast) int ast_cursor_init(struct ast_private *ast)
{ {
struct drm_device *dev = ast->dev; struct drm_device *dev = &ast->base;
size_t size, i; size_t size, i;
struct drm_gem_vram_object *gbo; struct drm_gem_vram_object *gbo;
void __iomem *vaddr; void __iomem *vaddr;
...@@ -168,7 +168,7 @@ static void update_cursor_image(u8 __iomem *dst, const u8 *src, int width, int h ...@@ -168,7 +168,7 @@ static void update_cursor_image(u8 __iomem *dst, const u8 *src, int width, int h
int ast_cursor_blit(struct ast_private *ast, struct drm_framebuffer *fb) int ast_cursor_blit(struct ast_private *ast, struct drm_framebuffer *fb)
{ {
struct drm_device *dev = ast->dev; struct drm_device *dev = &ast->base;
struct drm_gem_vram_object *gbo; struct drm_gem_vram_object *gbo;
int ret; int ret;
void *src; void *src;
...@@ -217,7 +217,7 @@ static void ast_cursor_set_base(struct ast_private *ast, u64 address) ...@@ -217,7 +217,7 @@ static void ast_cursor_set_base(struct ast_private *ast, u64 address)
void ast_cursor_page_flip(struct ast_private *ast) void ast_cursor_page_flip(struct ast_private *ast)
{ {
struct drm_device *dev = ast->dev; struct drm_device *dev = &ast->base;
struct drm_gem_vram_object *gbo; struct drm_gem_vram_object *gbo;
s64 off; s64 off;
......
...@@ -124,7 +124,7 @@ static int ast_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -124,7 +124,7 @@ static int ast_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
ret = PTR_ERR(ast); ret = PTR_ERR(ast);
goto err_drm_dev_put; goto err_drm_dev_put;
} }
dev = ast->dev; dev = &ast->base;
ret = drm_dev_register(dev, ent->driver_data); ret = drm_dev_register(dev, ent->driver_data);
if (ret) if (ret)
......
...@@ -116,7 +116,7 @@ to_ast_connector(struct drm_connector *connector) ...@@ -116,7 +116,7 @@ to_ast_connector(struct drm_connector *connector)
} }
struct ast_private { struct ast_private {
struct drm_device *dev; struct drm_device base;
void __iomem *regs; void __iomem *regs;
void __iomem *ioregs; void __iomem *ioregs;
...@@ -156,7 +156,7 @@ struct ast_private { ...@@ -156,7 +156,7 @@ struct ast_private {
static inline struct ast_private *to_ast_private(struct drm_device *dev) static inline struct ast_private *to_ast_private(struct drm_device *dev)
{ {
return dev->dev_private; return container_of(dev, struct ast_private, base);
} }
struct ast_private *ast_device_create(struct drm_driver *drv, struct ast_private *ast_device_create(struct drm_driver *drv,
......
...@@ -388,25 +388,17 @@ struct ast_private *ast_device_create(struct drm_driver *drv, ...@@ -388,25 +388,17 @@ struct ast_private *ast_device_create(struct drm_driver *drv,
bool need_post; bool need_post;
int ret = 0; int ret = 0;
dev = drm_dev_alloc(drv, &pdev->dev); ast = devm_drm_dev_alloc(&pdev->dev, drv, struct ast_private, base);
if (IS_ERR(dev)) if (IS_ERR(ast))
return ERR_CAST(dev); return ast;
dev = &ast->base;
dev->pdev = pdev; dev->pdev = pdev;
pci_set_drvdata(pdev, dev); pci_set_drvdata(pdev, dev);
ast = kzalloc(sizeof(struct ast_private), GFP_KERNEL);
if (!ast)
return ERR_PTR(-ENOMEM);
dev->dev_private = ast;
ast->dev = dev;
ast->regs = pci_iomap(dev->pdev, 1, 0); ast->regs = pci_iomap(dev->pdev, 1, 0);
if (!ast->regs) { if (!ast->regs)
ret = -EIO; return ERR_PTR(-EIO);
goto out_free;
}
/* /*
* If we don't have IO space at all, use MMIO now and * If we don't have IO space at all, use MMIO now and
...@@ -421,17 +413,16 @@ struct ast_private *ast_device_create(struct drm_driver *drv, ...@@ -421,17 +413,16 @@ struct ast_private *ast_device_create(struct drm_driver *drv,
/* "map" IO regs if the above hasn't done so already */ /* "map" IO regs if the above hasn't done so already */
if (!ast->ioregs) { if (!ast->ioregs) {
ast->ioregs = pci_iomap(dev->pdev, 2, 0); ast->ioregs = pci_iomap(dev->pdev, 2, 0);
if (!ast->ioregs) { if (!ast->ioregs)
ret = -EIO; return ERR_PTR(-EIO);
goto out_free;
}
} }
ast_detect_chip(dev, &need_post); ast_detect_chip(dev, &need_post);
ret = ast_get_dram_info(dev); ret = ast_get_dram_info(dev);
if (ret) if (ret)
goto out_free; return ERR_PTR(ret);
drm_info(dev, "dram MCLK=%u Mhz type=%d bus_width=%d\n", drm_info(dev, "dram MCLK=%u Mhz type=%d bus_width=%d\n",
ast->mclk, ast->dram_type, ast->dram_bus_width); ast->mclk, ast->dram_type, ast->dram_bus_width);
...@@ -440,29 +431,22 @@ struct ast_private *ast_device_create(struct drm_driver *drv, ...@@ -440,29 +431,22 @@ struct ast_private *ast_device_create(struct drm_driver *drv,
ret = ast_mm_init(ast); ret = ast_mm_init(ast);
if (ret) if (ret)
goto out_free; return ERR_PTR(ret);
ret = ast_mode_config_init(ast); ret = ast_mode_config_init(ast);
if (ret) if (ret)
goto out_free; return ERR_PTR(ret);
return ast; return ast;
out_free:
kfree(ast);
dev->dev_private = NULL;
return ERR_PTR(ret);
} }
void ast_device_destroy(struct ast_private *ast) void ast_device_destroy(struct ast_private *ast)
{ {
struct drm_device *dev = ast->dev; struct drm_device *dev = &ast->base;
/* enable standard VGA decode */ /* enable standard VGA decode */
ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xa1, 0x04); ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xa1, 0x04);
ast_release_firmware(dev); ast_release_firmware(dev);
kfree(ast->dp501_fw_addr); kfree(ast->dp501_fw_addr);
kfree(ast);
} }
...@@ -85,9 +85,9 @@ static void ast_mm_release(struct drm_device *dev, void *ptr) ...@@ -85,9 +85,9 @@ static void ast_mm_release(struct drm_device *dev, void *ptr)
int ast_mm_init(struct ast_private *ast) int ast_mm_init(struct ast_private *ast)
{ {
struct drm_device *dev = &ast->base;
u32 vram_size; u32 vram_size;
int ret; int ret;
struct drm_device *dev = ast->dev;
vram_size = ast_get_vram_size(ast); vram_size = ast_get_vram_size(ast);
......
...@@ -1063,7 +1063,7 @@ static const struct drm_mode_config_funcs ast_mode_config_funcs = { ...@@ -1063,7 +1063,7 @@ static const struct drm_mode_config_funcs ast_mode_config_funcs = {
int ast_mode_config_init(struct ast_private *ast) int ast_mode_config_init(struct ast_private *ast)
{ {
struct drm_device *dev = ast->dev; struct drm_device *dev = &ast->base;
int ret; int ret;
ret = ast_cursor_init(ast); ret = ast_cursor_init(ast);
......
...@@ -365,8 +365,8 @@ static void ast_init_dram_reg(struct drm_device *dev) ...@@ -365,8 +365,8 @@ static void ast_init_dram_reg(struct drm_device *dev)
void ast_post_gpu(struct drm_device *dev) void ast_post_gpu(struct drm_device *dev)
{ {
u32 reg;
struct ast_private *ast = to_ast_private(dev); struct ast_private *ast = to_ast_private(dev);
u32 reg;
pci_read_config_dword(dev->pdev, 0x04, &reg); pci_read_config_dword(dev->pdev, 0x04, &reg);
reg |= 0x3; reg |= 0x3;
......
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