Commit 832eddf5 authored by Thomas Zimmermann's avatar Thomas Zimmermann

drm/mgag200: Embed instance of struct drm_device in struct mga_device

Following current best practice, the instance of struct drm_device is now
embedded in struct mga_device. The respective field has been renamed from
'dev' to 'base' to reflect the relationship. Conversion from DRM device is
done via upcast. Using dev_private is no longer possible.

The patch also open-codes drm_dev_alloc() and DRM device initialization
is now performed by a call to drm_device_init().
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-14-tzimmermann@suse.de
parent 3c8923c3
...@@ -45,7 +45,7 @@ static struct drm_driver mgag200_driver = { ...@@ -45,7 +45,7 @@ static struct drm_driver mgag200_driver = {
static int mgag200_device_init(struct mga_device *mdev, unsigned long flags) static int mgag200_device_init(struct mga_device *mdev, unsigned long flags)
{ {
struct drm_device *dev = mdev->dev; struct drm_device *dev = &mdev->base;
int ret, option; int ret, option;
mdev->flags = mgag200_flags_from_driver_data(flags); mdev->flags = mgag200_flags_from_driver_data(flags);
...@@ -89,25 +89,24 @@ static int mgag200_device_init(struct mga_device *mdev, unsigned long flags) ...@@ -89,25 +89,24 @@ static int mgag200_device_init(struct mga_device *mdev, unsigned long flags)
} }
static struct mga_device * static struct mga_device *
mgag200_driver_load(struct pci_dev *pdev, unsigned long flags) mgag200_device_create(struct pci_dev *pdev, unsigned long flags)
{ {
struct drm_device *dev; struct drm_device *dev;
struct mga_device *mdev; struct mga_device *mdev;
int ret; int ret;
dev = drm_dev_alloc(&mgag200_driver, &pdev->dev); mdev = devm_kzalloc(&pdev->dev, sizeof(*mdev), GFP_KERNEL);
if (IS_ERR(dev)) if (!mdev)
return ERR_CAST(dev); return ERR_PTR(-ENOMEM);
dev = &mdev->base;
ret = drm_dev_init(dev, &mgag200_driver, &pdev->dev);
if (ret)
return ERR_PTR(ret);
dev->pdev = pdev; dev->pdev = pdev;
pci_set_drvdata(pdev, dev); pci_set_drvdata(pdev, dev);
mdev = devm_kzalloc(dev->dev, sizeof(struct mga_device), GFP_KERNEL);
if (mdev == NULL)
return ERR_PTR(-ENOMEM);
dev->dev_private = (void *)mdev;
mdev->dev = dev;
ret = mgag200_device_init(mdev, flags); ret = mgag200_device_init(mdev, flags);
if (ret) if (ret)
goto err_drm_dev_put; goto err_drm_dev_put;
...@@ -116,19 +115,9 @@ mgag200_driver_load(struct pci_dev *pdev, unsigned long flags) ...@@ -116,19 +115,9 @@ mgag200_driver_load(struct pci_dev *pdev, unsigned long flags)
err_drm_dev_put: err_drm_dev_put:
drm_dev_put(dev); drm_dev_put(dev);
dev->dev_private = NULL;
return ERR_PTR(ret); return ERR_PTR(ret);
} }
static void mgag200_driver_unload(struct drm_device *dev)
{
struct mga_device *mdev = to_mga_device(dev);
if (mdev == NULL)
return;
dev->dev_private = NULL;
}
/* /*
* PCI driver * PCI driver
*/ */
...@@ -161,21 +150,22 @@ mgag200_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -161,21 +150,22 @@ mgag200_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
if (ret) if (ret)
return ret; return ret;
mdev = mgag200_driver_load(pdev, ent->driver_data); mdev = mgag200_device_create(pdev, ent->driver_data);
if (IS_ERR(mdev)) if (IS_ERR(mdev)) {
return PTR_ERR(mdev); ret = PTR_ERR(mdev);
dev = mdev->dev; goto err_drm_dev_put;
}
dev = &mdev->base;
ret = drm_dev_register(dev, ent->driver_data); ret = drm_dev_register(dev, ent->driver_data);
if (ret) if (ret)
goto err_mgag200_driver_unload; goto err_drm_dev_put;
drm_fbdev_generic_setup(dev, 0); drm_fbdev_generic_setup(dev, 0);
return 0; return 0;
err_mgag200_driver_unload: err_drm_dev_put:
mgag200_driver_unload(dev);
drm_dev_put(dev); drm_dev_put(dev);
return ret; return ret;
} }
...@@ -185,7 +175,6 @@ static void mgag200_pci_remove(struct pci_dev *pdev) ...@@ -185,7 +175,6 @@ static void mgag200_pci_remove(struct pci_dev *pdev)
struct drm_device *dev = pci_get_drvdata(pdev); struct drm_device *dev = pci_get_drvdata(pdev);
drm_dev_unregister(dev); drm_dev_unregister(dev);
mgag200_driver_unload(dev);
drm_dev_put(dev); drm_dev_put(dev);
} }
......
...@@ -142,7 +142,7 @@ enum mga_type { ...@@ -142,7 +142,7 @@ enum mga_type {
#define IS_G200_SE(mdev) (mdev->type == G200_SE_A || mdev->type == G200_SE_B) #define IS_G200_SE(mdev) (mdev->type == G200_SE_A || mdev->type == G200_SE_B)
struct mga_device { struct mga_device {
struct drm_device *dev; struct drm_device base;
unsigned long flags; unsigned long flags;
resource_size_t rmmio_base; resource_size_t rmmio_base;
...@@ -170,7 +170,7 @@ struct mga_device { ...@@ -170,7 +170,7 @@ struct mga_device {
static inline struct mga_device *to_mga_device(struct drm_device *dev) static inline struct mga_device *to_mga_device(struct drm_device *dev)
{ {
return dev->dev_private; return container_of(dev, struct mga_device, base);
} }
static inline enum mga_type static inline enum mga_type
......
...@@ -89,7 +89,7 @@ static void mgag200_mm_release(struct drm_device *dev, void *ptr) ...@@ -89,7 +89,7 @@ static void mgag200_mm_release(struct drm_device *dev, void *ptr)
int mgag200_mm_init(struct mga_device *mdev) int mgag200_mm_init(struct mga_device *mdev)
{ {
struct drm_device *dev = mdev->dev; struct drm_device *dev = &mdev->base;
resource_size_t start, len; resource_size_t start, len;
int ret; int ret;
......
...@@ -854,7 +854,7 @@ static void mga_g200wb_commit(struct drm_crtc *crtc) ...@@ -854,7 +854,7 @@ static void mga_g200wb_commit(struct drm_crtc *crtc)
static void mgag200_set_startadd(struct mga_device *mdev, static void mgag200_set_startadd(struct mga_device *mdev,
unsigned long offset) unsigned long offset)
{ {
struct drm_device *dev = mdev->dev; struct drm_device *dev = &mdev->base;
u32 startadd; u32 startadd;
u8 crtcc, crtcd, crtcext0; u8 crtcc, crtcd, crtcext0;
...@@ -882,7 +882,7 @@ static void mgag200_set_startadd(struct mga_device *mdev, ...@@ -882,7 +882,7 @@ static void mgag200_set_startadd(struct mga_device *mdev,
static void mgag200_set_pci_regs(struct mga_device *mdev) static void mgag200_set_pci_regs(struct mga_device *mdev)
{ {
uint32_t option = 0, option2 = 0; uint32_t option = 0, option2 = 0;
struct drm_device *dev = mdev->dev; struct drm_device *dev = &mdev->base;
switch (mdev->type) { switch (mdev->type) {
case G200_SE_A: case G200_SE_A:
...@@ -1153,7 +1153,7 @@ static void mgag200_set_offset(struct mga_device *mdev, ...@@ -1153,7 +1153,7 @@ static void mgag200_set_offset(struct mga_device *mdev,
static void mgag200_set_format_regs(struct mga_device *mdev, static void mgag200_set_format_regs(struct mga_device *mdev,
const struct drm_framebuffer *fb) const struct drm_framebuffer *fb)
{ {
struct drm_device *dev = mdev->dev; struct drm_device *dev = &mdev->base;
const struct drm_format_info *format = fb->format; const struct drm_format_info *format = fb->format;
unsigned int bpp, bppshift, scale; unsigned int bpp, bppshift, scale;
u8 crtcext3, xmulctrl; u8 crtcext3, xmulctrl;
...@@ -1537,7 +1537,7 @@ static const struct drm_connector_funcs mga_vga_connector_funcs = { ...@@ -1537,7 +1537,7 @@ static const struct drm_connector_funcs mga_vga_connector_funcs = {
static int mgag200_vga_connector_init(struct mga_device *mdev) static int mgag200_vga_connector_init(struct mga_device *mdev)
{ {
struct drm_device *dev = mdev->dev; struct drm_device *dev = &mdev->base;
struct mga_connector *mconnector = &mdev->connector; struct mga_connector *mconnector = &mdev->connector;
struct drm_connector *connector = &mconnector->base; struct drm_connector *connector = &mconnector->base;
struct mga_i2c_chan *i2c; struct mga_i2c_chan *i2c;
...@@ -1579,7 +1579,7 @@ static void ...@@ -1579,7 +1579,7 @@ static void
mgag200_handle_damage(struct mga_device *mdev, struct drm_framebuffer *fb, mgag200_handle_damage(struct mga_device *mdev, struct drm_framebuffer *fb,
struct drm_rect *clip) struct drm_rect *clip)
{ {
struct drm_device *dev = mdev->dev; struct drm_device *dev = &mdev->base;
void *vmap; void *vmap;
vmap = drm_gem_shmem_vmap(fb->obj[0]); vmap = drm_gem_shmem_vmap(fb->obj[0]);
...@@ -1718,7 +1718,7 @@ static unsigned int mgag200_preferred_depth(struct mga_device *mdev) ...@@ -1718,7 +1718,7 @@ static unsigned int mgag200_preferred_depth(struct mga_device *mdev)
int mgag200_modeset_init(struct mga_device *mdev) int mgag200_modeset_init(struct mga_device *mdev)
{ {
struct drm_device *dev = mdev->dev; struct drm_device *dev = &mdev->base;
struct drm_connector *connector = &mdev->connector.base; struct drm_connector *connector = &mdev->connector.base;
struct drm_simple_display_pipe *pipe = &mdev->display_pipe; struct drm_simple_display_pipe *pipe = &mdev->display_pipe;
size_t format_count = ARRAY_SIZE(mgag200_simple_display_pipe_formats); size_t format_count = ARRAY_SIZE(mgag200_simple_display_pipe_formats);
......
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