Commit 2b669875 authored by Archit Taneja's avatar Archit Taneja Committed by Rob Clark

drm/msm: Drop load/unload drm_driver ops

The load/unload drm_driver ops are deprecated. They should be removed as
they result in creation of devices visible to userspace even before
the drm_device is registered.

Drop these ops and use drm_dev_alloc/register and drm_dev_unregister/unref
to explicitly create and destroy the drm device in the msm platform
driver's bind and unbind ops. With this in use, the drm connectors are
only registered once the drm_device is registered.

It also fixes the issue of stray debugfs files after the msm module is
removed. With this, all the debugfs files are removed, and allows
successive module insertions/removals.
Signed-off-by: default avatarArchit Taneja <architt@codeaurora.org>
parent 8208ed93
...@@ -175,13 +175,11 @@ static int vblank_ctrl_queue_work(struct msm_drm_private *priv, ...@@ -175,13 +175,11 @@ static int vblank_ctrl_queue_work(struct msm_drm_private *priv,
return 0; return 0;
} }
/* static int msm_drm_uninit(struct device *dev)
* DRM operations:
*/
static int msm_unload(struct drm_device *dev)
{ {
struct msm_drm_private *priv = dev->dev_private; struct platform_device *pdev = to_platform_device(dev);
struct drm_device *ddev = platform_get_drvdata(pdev);
struct msm_drm_private *priv = ddev->dev_private;
struct msm_kms *kms = priv->kms; struct msm_kms *kms = priv->kms;
struct msm_gpu *gpu = priv->gpu; struct msm_gpu *gpu = priv->gpu;
struct msm_vblank_ctrl *vbl_ctrl = &priv->vblank_ctrl; struct msm_vblank_ctrl *vbl_ctrl = &priv->vblank_ctrl;
...@@ -197,20 +195,21 @@ static int msm_unload(struct drm_device *dev) ...@@ -197,20 +195,21 @@ static int msm_unload(struct drm_device *dev)
kfree(vbl_ev); kfree(vbl_ev);
} }
drm_kms_helper_poll_fini(dev); drm_kms_helper_poll_fini(ddev);
drm_connector_unregister_all(ddev);
drm_connector_unregister_all(dev); drm_dev_unregister(ddev);
#ifdef CONFIG_DRM_FBDEV_EMULATION #ifdef CONFIG_DRM_FBDEV_EMULATION
if (fbdev && priv->fbdev) if (fbdev && priv->fbdev)
msm_fbdev_free(dev); msm_fbdev_free(ddev);
#endif #endif
drm_mode_config_cleanup(dev); drm_mode_config_cleanup(ddev);
drm_vblank_cleanup(dev);
pm_runtime_get_sync(dev->dev); pm_runtime_get_sync(dev);
drm_irq_uninstall(dev); drm_irq_uninstall(ddev);
pm_runtime_put_sync(dev->dev); pm_runtime_put_sync(dev);
flush_workqueue(priv->wq); flush_workqueue(priv->wq);
destroy_workqueue(priv->wq); destroy_workqueue(priv->wq);
...@@ -219,14 +218,14 @@ static int msm_unload(struct drm_device *dev) ...@@ -219,14 +218,14 @@ static int msm_unload(struct drm_device *dev)
destroy_workqueue(priv->atomic_wq); destroy_workqueue(priv->atomic_wq);
if (kms) { if (kms) {
pm_runtime_disable(dev->dev); pm_runtime_disable(dev);
kms->funcs->destroy(kms); kms->funcs->destroy(kms);
} }
if (gpu) { if (gpu) {
mutex_lock(&dev->struct_mutex); mutex_lock(&ddev->struct_mutex);
gpu->funcs->pm_suspend(gpu); gpu->funcs->pm_suspend(gpu);
mutex_unlock(&dev->struct_mutex); mutex_unlock(&ddev->struct_mutex);
gpu->funcs->destroy(gpu); gpu->funcs->destroy(gpu);
} }
...@@ -234,13 +233,14 @@ static int msm_unload(struct drm_device *dev) ...@@ -234,13 +233,14 @@ static int msm_unload(struct drm_device *dev)
DEFINE_DMA_ATTRS(attrs); DEFINE_DMA_ATTRS(attrs);
dma_set_attr(DMA_ATTR_NO_KERNEL_MAPPING, &attrs); dma_set_attr(DMA_ATTR_NO_KERNEL_MAPPING, &attrs);
drm_mm_takedown(&priv->vram.mm); drm_mm_takedown(&priv->vram.mm);
dma_free_attrs(dev->dev, priv->vram.size, NULL, dma_free_attrs(dev, priv->vram.size, NULL,
priv->vram.paddr, &attrs); priv->vram.paddr, &attrs);
} }
component_unbind_all(dev->dev, dev); component_unbind_all(dev, ddev);
dev->dev_private = NULL; ddev->dev_private = NULL;
drm_dev_unref(ddev);
kfree(priv); kfree(priv);
...@@ -328,20 +328,30 @@ static int msm_init_vram(struct drm_device *dev) ...@@ -328,20 +328,30 @@ static int msm_init_vram(struct drm_device *dev)
return ret; return ret;
} }
static int msm_load(struct drm_device *dev, unsigned long flags) static int msm_drm_init(struct device *dev, struct drm_driver *drv)
{ {
struct platform_device *pdev = dev->platformdev; struct platform_device *pdev = to_platform_device(dev);
struct drm_device *ddev;
struct msm_drm_private *priv; struct msm_drm_private *priv;
struct msm_kms *kms; struct msm_kms *kms;
int ret; int ret;
ddev = drm_dev_alloc(drv, dev);
if (!ddev) {
dev_err(dev, "failed to allocate drm_device\n");
return -ENOMEM;
}
platform_set_drvdata(pdev, ddev);
ddev->platformdev = pdev;
priv = kzalloc(sizeof(*priv), GFP_KERNEL); priv = kzalloc(sizeof(*priv), GFP_KERNEL);
if (!priv) { if (!priv) {
dev_err(dev->dev, "failed to allocate private data\n"); drm_dev_unref(ddev);
return -ENOMEM; return -ENOMEM;
} }
dev->dev_private = priv; ddev->dev_private = priv;
priv->wq = alloc_ordered_workqueue("msm", 0); priv->wq = alloc_ordered_workqueue("msm", 0);
priv->atomic_wq = alloc_ordered_workqueue("msm:atomic", 0); priv->atomic_wq = alloc_ordered_workqueue("msm:atomic", 0);
...@@ -352,25 +362,26 @@ static int msm_load(struct drm_device *dev, unsigned long flags) ...@@ -352,25 +362,26 @@ static int msm_load(struct drm_device *dev, unsigned long flags)
INIT_WORK(&priv->vblank_ctrl.work, vblank_ctrl_worker); INIT_WORK(&priv->vblank_ctrl.work, vblank_ctrl_worker);
spin_lock_init(&priv->vblank_ctrl.lock); spin_lock_init(&priv->vblank_ctrl.lock);
drm_mode_config_init(dev); drm_mode_config_init(ddev);
platform_set_drvdata(pdev, dev);
/* Bind all our sub-components: */ /* Bind all our sub-components: */
ret = component_bind_all(dev->dev, dev); ret = component_bind_all(dev, ddev);
if (ret) if (ret) {
kfree(priv);
drm_dev_unref(ddev);
return ret; return ret;
}
ret = msm_init_vram(dev); ret = msm_init_vram(ddev);
if (ret) if (ret)
goto fail; goto fail;
switch (get_mdp_ver(pdev)) { switch (get_mdp_ver(pdev)) {
case 4: case 4:
kms = mdp4_kms_init(dev); kms = mdp4_kms_init(ddev);
break; break;
case 5: case 5:
kms = mdp5_kms_init(dev); kms = mdp5_kms_init(ddev);
break; break;
default: default:
kms = ERR_PTR(-ENODEV); kms = ERR_PTR(-ENODEV);
...@@ -384,7 +395,7 @@ static int msm_load(struct drm_device *dev, unsigned long flags) ...@@ -384,7 +395,7 @@ static int msm_load(struct drm_device *dev, unsigned long flags)
* and (for example) use dmabuf/prime to share buffers with * and (for example) use dmabuf/prime to share buffers with
* imx drm driver on iMX5 * imx drm driver on iMX5
*/ */
dev_err(dev->dev, "failed to load kms\n"); dev_err(dev, "failed to load kms\n");
ret = PTR_ERR(kms); ret = PTR_ERR(kms);
goto fail; goto fail;
} }
...@@ -392,56 +403,64 @@ static int msm_load(struct drm_device *dev, unsigned long flags) ...@@ -392,56 +403,64 @@ static int msm_load(struct drm_device *dev, unsigned long flags)
priv->kms = kms; priv->kms = kms;
if (kms) { if (kms) {
pm_runtime_enable(dev->dev); pm_runtime_enable(dev);
ret = kms->funcs->hw_init(kms); ret = kms->funcs->hw_init(kms);
if (ret) { if (ret) {
dev_err(dev->dev, "kms hw init failed: %d\n", ret); dev_err(dev, "kms hw init failed: %d\n", ret);
goto fail; goto fail;
} }
} }
dev->mode_config.funcs = &mode_config_funcs; ddev->mode_config.funcs = &mode_config_funcs;
ret = drm_vblank_init(dev, priv->num_crtcs); ret = drm_vblank_init(ddev, priv->num_crtcs);
if (ret < 0) { if (ret < 0) {
dev_err(dev->dev, "failed to initialize vblank\n"); dev_err(dev, "failed to initialize vblank\n");
goto fail; goto fail;
} }
pm_runtime_get_sync(dev->dev); pm_runtime_get_sync(dev);
ret = drm_irq_install(dev, platform_get_irq(dev->platformdev, 0)); ret = drm_irq_install(ddev, platform_get_irq(pdev, 0));
pm_runtime_put_sync(dev->dev); pm_runtime_put_sync(dev);
if (ret < 0) { if (ret < 0) {
dev_err(dev->dev, "failed to install IRQ handler\n"); dev_err(dev, "failed to install IRQ handler\n");
goto fail; goto fail;
} }
ret = drm_connector_register_all(dev); ret = drm_dev_register(ddev, 0);
if (ret)
goto fail;
ret = drm_connector_register_all(ddev);
if (ret) { if (ret) {
dev_err(dev->dev, "failed to register connectors\n"); dev_err(dev, "failed to register connectors\n");
goto fail; goto fail;
} }
drm_mode_config_reset(dev); drm_mode_config_reset(ddev);
#ifdef CONFIG_DRM_FBDEV_EMULATION #ifdef CONFIG_DRM_FBDEV_EMULATION
if (fbdev) if (fbdev)
priv->fbdev = msm_fbdev_init(dev); priv->fbdev = msm_fbdev_init(ddev);
#endif #endif
ret = msm_debugfs_late_init(dev); ret = msm_debugfs_late_init(ddev);
if (ret) if (ret)
goto fail; goto fail;
drm_kms_helper_poll_init(dev); drm_kms_helper_poll_init(ddev);
return 0; return 0;
fail: fail:
msm_unload(dev); msm_drm_uninit(dev);
return ret; return ret;
} }
/*
* DRM operations:
*/
static void load_gpu(struct drm_device *dev) static void load_gpu(struct drm_device *dev)
{ {
static DEFINE_MUTEX(init_lock); static DEFINE_MUTEX(init_lock);
...@@ -708,8 +727,6 @@ static struct drm_driver msm_driver = { ...@@ -708,8 +727,6 @@ static struct drm_driver msm_driver = {
DRIVER_RENDER | DRIVER_RENDER |
DRIVER_ATOMIC | DRIVER_ATOMIC |
DRIVER_MODESET, DRIVER_MODESET,
.load = msm_load,
.unload = msm_unload,
.open = msm_open, .open = msm_open,
.preclose = msm_preclose, .preclose = msm_preclose,
.lastclose = msm_lastclose, .lastclose = msm_lastclose,
...@@ -809,12 +826,12 @@ static int add_components(struct device *dev, struct component_match **matchptr, ...@@ -809,12 +826,12 @@ static int add_components(struct device *dev, struct component_match **matchptr,
static int msm_drm_bind(struct device *dev) static int msm_drm_bind(struct device *dev)
{ {
return drm_platform_init(&msm_driver, to_platform_device(dev)); return msm_drm_init(dev, &msm_driver);
} }
static void msm_drm_unbind(struct device *dev) static void msm_drm_unbind(struct device *dev)
{ {
drm_put_dev(platform_get_drvdata(to_platform_device(dev))); msm_drm_uninit(dev);
} }
static const struct component_master_ops msm_drm_ops = { static const struct component_master_ops msm_drm_ops = {
......
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