Commit ec919e6e authored by AngeloGioacchino Del Regno's avatar AngeloGioacchino Del Regno Committed by Rob Clark

drm/msm: Allocate msm_drm_private early and pass it as driver data

In preparation for registering the mdss interrupt controller earlier,
move the allocation of msm_drm_private from component bind time to
msm_drv probe; this also allows us to use the devm variant of kzalloc.

Since it is not right to allocate the drm_device at probe time (as
it should exist only when all components are bound, and taken down
when components get cleaned up), the only way to make this happen is
to pass a pointer to msm_drm_private as driver data (like done in
many other DRM drivers), instead of one to drm_device like it's
currently done in this driver.

This is also simplifying some bind/unbind functions around drm/msm,
as some of them are using drm_device just to grab a pointer to the
msm_drm_private structure, which we now retrieve in one call.
Signed-off-by: default avatarAngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Link: https://lore.kernel.org/r/20211201105210.24970-2-angelogioacchino.delregno@collabora.comSigned-off-by: default avatarRob Clark <robdclark@chromium.org>
parent 83b965d1
...@@ -427,13 +427,6 @@ struct msm_gpu *adreno_load_gpu(struct drm_device *dev) ...@@ -427,13 +427,6 @@ struct msm_gpu *adreno_load_gpu(struct drm_device *dev)
return gpu; return gpu;
} }
static void set_gpu_pdev(struct drm_device *dev,
struct platform_device *pdev)
{
struct msm_drm_private *priv = dev->dev_private;
priv->gpu_pdev = pdev;
}
static int find_chipid(struct device *dev, struct adreno_rev *rev) static int find_chipid(struct device *dev, struct adreno_rev *rev)
{ {
struct device_node *node = dev->of_node; struct device_node *node = dev->of_node;
...@@ -482,8 +475,8 @@ static int adreno_bind(struct device *dev, struct device *master, void *data) ...@@ -482,8 +475,8 @@ static int adreno_bind(struct device *dev, struct device *master, void *data)
{ {
static struct adreno_platform_config config = {}; static struct adreno_platform_config config = {};
const struct adreno_info *info; const struct adreno_info *info;
struct drm_device *drm = dev_get_drvdata(master); struct msm_drm_private *priv = dev_get_drvdata(master);
struct msm_drm_private *priv = drm->dev_private; struct drm_device *drm = priv->dev;
struct msm_gpu *gpu; struct msm_gpu *gpu;
int ret; int ret;
...@@ -492,7 +485,7 @@ static int adreno_bind(struct device *dev, struct device *master, void *data) ...@@ -492,7 +485,7 @@ static int adreno_bind(struct device *dev, struct device *master, void *data)
return ret; return ret;
dev->platform_data = &config; dev->platform_data = &config;
set_gpu_pdev(drm, to_platform_device(dev)); priv->gpu_pdev = to_platform_device(dev);
info = adreno_info(config.rev); info = adreno_info(config.rev);
...@@ -521,12 +514,13 @@ static int adreno_bind(struct device *dev, struct device *master, void *data) ...@@ -521,12 +514,13 @@ static int adreno_bind(struct device *dev, struct device *master, void *data)
static void adreno_unbind(struct device *dev, struct device *master, static void adreno_unbind(struct device *dev, struct device *master,
void *data) void *data)
{ {
struct msm_drm_private *priv = dev_get_drvdata(master);
struct msm_gpu *gpu = dev_to_gpu(dev); struct msm_gpu *gpu = dev_to_gpu(dev);
pm_runtime_force_suspend(dev); pm_runtime_force_suspend(dev);
gpu->funcs->destroy(gpu); gpu->funcs->destroy(gpu);
set_gpu_pdev(dev_get_drvdata(master), NULL); priv->gpu_pdev = NULL;
} }
static const struct component_ops a3xx_ops = { static const struct component_ops a3xx_ops = {
......
...@@ -1153,9 +1153,9 @@ struct msm_kms *dpu_kms_init(struct drm_device *dev) ...@@ -1153,9 +1153,9 @@ struct msm_kms *dpu_kms_init(struct drm_device *dev)
static int dpu_bind(struct device *dev, struct device *master, void *data) static int dpu_bind(struct device *dev, struct device *master, void *data)
{ {
struct drm_device *ddev = dev_get_drvdata(master); struct msm_drm_private *priv = dev_get_drvdata(master);
struct platform_device *pdev = to_platform_device(dev); struct platform_device *pdev = to_platform_device(dev);
struct msm_drm_private *priv = ddev->dev_private; struct drm_device *ddev = priv->dev;
struct dpu_kms *dpu_kms; struct dpu_kms *dpu_kms;
struct dss_module_power *mp; struct dss_module_power *mp;
int ret = 0; int ret = 0;
......
...@@ -921,7 +921,8 @@ static int mdp5_init(struct platform_device *pdev, struct drm_device *dev) ...@@ -921,7 +921,8 @@ static int mdp5_init(struct platform_device *pdev, struct drm_device *dev)
static int mdp5_bind(struct device *dev, struct device *master, void *data) static int mdp5_bind(struct device *dev, struct device *master, void *data)
{ {
struct drm_device *ddev = dev_get_drvdata(master); struct msm_drm_private *priv = dev_get_drvdata(master);
struct drm_device *ddev = priv->dev;
struct platform_device *pdev = to_platform_device(dev); struct platform_device *pdev = to_platform_device(dev);
DBG(""); DBG("");
......
...@@ -233,13 +233,10 @@ static int dp_display_bind(struct device *dev, struct device *master, ...@@ -233,13 +233,10 @@ static int dp_display_bind(struct device *dev, struct device *master,
{ {
int rc = 0; int rc = 0;
struct dp_display_private *dp = dev_get_dp_display_private(dev); struct dp_display_private *dp = dev_get_dp_display_private(dev);
struct msm_drm_private *priv; struct msm_drm_private *priv = dev_get_drvdata(master);
struct drm_device *drm; struct drm_device *drm = priv->dev;
drm = dev_get_drvdata(master);
dp->dp_display.drm_dev = drm; dp->dp_display.drm_dev = drm;
priv = drm->dev_private;
priv->dp[dp->id] = &dp->dp_display; priv->dp[dp->id] = &dp->dp_display;
rc = dp->parser->parse(dp->parser, dp->dp_display.connector_type); rc = dp->parser->parse(dp->parser, dp->dp_display.connector_type);
...@@ -275,8 +272,7 @@ static void dp_display_unbind(struct device *dev, struct device *master, ...@@ -275,8 +272,7 @@ static void dp_display_unbind(struct device *dev, struct device *master,
void *data) void *data)
{ {
struct dp_display_private *dp = dev_get_dp_display_private(dev); struct dp_display_private *dp = dev_get_dp_display_private(dev);
struct drm_device *drm = dev_get_drvdata(master); struct msm_drm_private *priv = dev_get_drvdata(master);
struct msm_drm_private *priv = drm->dev_private;
dp_power_client_deinit(dp->power); dp_power_client_deinit(dp->power);
dp_aux_unregister(dp->aux); dp_aux_unregister(dp->aux);
......
...@@ -110,8 +110,7 @@ static struct msm_dsi *dsi_init(struct platform_device *pdev) ...@@ -110,8 +110,7 @@ static struct msm_dsi *dsi_init(struct platform_device *pdev)
static int dsi_bind(struct device *dev, struct device *master, void *data) static int dsi_bind(struct device *dev, struct device *master, void *data)
{ {
struct drm_device *drm = dev_get_drvdata(master); struct msm_drm_private *priv = dev_get_drvdata(master);
struct msm_drm_private *priv = drm->dev_private;
struct msm_dsi *msm_dsi = dev_get_drvdata(dev); struct msm_dsi *msm_dsi = dev_get_drvdata(dev);
priv->dsi[msm_dsi->id] = msm_dsi; priv->dsi[msm_dsi->id] = msm_dsi;
...@@ -122,8 +121,7 @@ static int dsi_bind(struct device *dev, struct device *master, void *data) ...@@ -122,8 +121,7 @@ static int dsi_bind(struct device *dev, struct device *master, void *data)
static void dsi_unbind(struct device *dev, struct device *master, static void dsi_unbind(struct device *dev, struct device *master,
void *data) void *data)
{ {
struct drm_device *drm = dev_get_drvdata(master); struct msm_drm_private *priv = dev_get_drvdata(master);
struct msm_drm_private *priv = drm->dev_private;
struct msm_dsi *msm_dsi = dev_get_drvdata(dev); struct msm_dsi *msm_dsi = dev_get_drvdata(dev);
priv->dsi[msm_dsi->id] = NULL; priv->dsi[msm_dsi->id] = NULL;
......
...@@ -514,8 +514,7 @@ static int msm_hdmi_register_audio_driver(struct hdmi *hdmi, struct device *dev) ...@@ -514,8 +514,7 @@ static int msm_hdmi_register_audio_driver(struct hdmi *hdmi, struct device *dev)
static int msm_hdmi_bind(struct device *dev, struct device *master, void *data) static int msm_hdmi_bind(struct device *dev, struct device *master, void *data)
{ {
struct drm_device *drm = dev_get_drvdata(master); struct msm_drm_private *priv = dev_get_drvdata(master);
struct msm_drm_private *priv = drm->dev_private;
struct hdmi_platform_config *hdmi_cfg; struct hdmi_platform_config *hdmi_cfg;
struct hdmi *hdmi; struct hdmi *hdmi;
struct device_node *of_node = dev->of_node; struct device_node *of_node = dev->of_node;
...@@ -586,8 +585,8 @@ static int msm_hdmi_bind(struct device *dev, struct device *master, void *data) ...@@ -586,8 +585,8 @@ static int msm_hdmi_bind(struct device *dev, struct device *master, void *data)
static void msm_hdmi_unbind(struct device *dev, struct device *master, static void msm_hdmi_unbind(struct device *dev, struct device *master,
void *data) void *data)
{ {
struct drm_device *drm = dev_get_drvdata(master); struct msm_drm_private *priv = dev_get_drvdata(master);
struct msm_drm_private *priv = drm->dev_private;
if (priv->hdmi) { if (priv->hdmi) {
if (priv->hdmi->audio_pdev) if (priv->hdmi->audio_pdev)
platform_device_unregister(priv->hdmi->audio_pdev); platform_device_unregister(priv->hdmi->audio_pdev);
......
...@@ -339,8 +339,8 @@ static int vblank_ctrl_queue_work(struct msm_drm_private *priv, ...@@ -339,8 +339,8 @@ static int vblank_ctrl_queue_work(struct msm_drm_private *priv,
static int msm_drm_uninit(struct device *dev) static int msm_drm_uninit(struct device *dev)
{ {
struct platform_device *pdev = to_platform_device(dev); struct platform_device *pdev = to_platform_device(dev);
struct drm_device *ddev = platform_get_drvdata(pdev); struct msm_drm_private *priv = platform_get_drvdata(pdev);
struct msm_drm_private *priv = ddev->dev_private; struct drm_device *ddev = priv->dev;
struct msm_kms *kms = priv->kms; struct msm_kms *kms = priv->kms;
struct msm_mdss *mdss = priv->mdss; struct msm_mdss *mdss = priv->mdss;
int i; int i;
...@@ -409,7 +409,6 @@ static int msm_drm_uninit(struct device *dev) ...@@ -409,7 +409,6 @@ static int msm_drm_uninit(struct device *dev)
drm_dev_put(ddev); drm_dev_put(ddev);
destroy_workqueue(priv->wq); destroy_workqueue(priv->wq);
kfree(priv);
return 0; return 0;
} }
...@@ -512,8 +511,8 @@ static int msm_init_vram(struct drm_device *dev) ...@@ -512,8 +511,8 @@ static int msm_init_vram(struct drm_device *dev)
static int msm_drm_init(struct device *dev, const struct drm_driver *drv) static int msm_drm_init(struct device *dev, const struct drm_driver *drv)
{ {
struct platform_device *pdev = to_platform_device(dev); struct platform_device *pdev = to_platform_device(dev);
struct msm_drm_private *priv = dev_get_drvdata(dev);
struct drm_device *ddev; struct drm_device *ddev;
struct msm_drm_private *priv;
struct msm_kms *kms; struct msm_kms *kms;
struct msm_mdss *mdss; struct msm_mdss *mdss;
int ret, i; int ret, i;
...@@ -523,15 +522,6 @@ static int msm_drm_init(struct device *dev, const struct drm_driver *drv) ...@@ -523,15 +522,6 @@ static int msm_drm_init(struct device *dev, const struct drm_driver *drv)
DRM_DEV_ERROR(dev, "failed to allocate drm_device\n"); DRM_DEV_ERROR(dev, "failed to allocate drm_device\n");
return PTR_ERR(ddev); return PTR_ERR(ddev);
} }
platform_set_drvdata(pdev, ddev);
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
if (!priv) {
ret = -ENOMEM;
goto err_put_drm_dev;
}
ddev->dev_private = priv; ddev->dev_private = priv;
priv->dev = ddev; priv->dev = ddev;
...@@ -547,7 +537,7 @@ static int msm_drm_init(struct device *dev, const struct drm_driver *drv) ...@@ -547,7 +537,7 @@ static int msm_drm_init(struct device *dev, const struct drm_driver *drv)
break; break;
} }
if (ret) if (ret)
goto err_free_priv; goto err_put_drm_dev;
mdss = priv->mdss; mdss = priv->mdss;
...@@ -685,11 +675,8 @@ static int msm_drm_init(struct device *dev, const struct drm_driver *drv) ...@@ -685,11 +675,8 @@ static int msm_drm_init(struct device *dev, const struct drm_driver *drv)
err_destroy_mdss: err_destroy_mdss:
if (mdss && mdss->funcs) if (mdss && mdss->funcs)
mdss->funcs->destroy(ddev); mdss->funcs->destroy(ddev);
err_free_priv:
kfree(priv);
err_put_drm_dev: err_put_drm_dev:
drm_dev_put(ddev); drm_dev_put(ddev);
platform_set_drvdata(pdev, NULL);
return ret; return ret;
} }
...@@ -1136,8 +1123,7 @@ static const struct drm_driver msm_driver = { ...@@ -1136,8 +1123,7 @@ static const struct drm_driver msm_driver = {
static int __maybe_unused msm_runtime_suspend(struct device *dev) static int __maybe_unused msm_runtime_suspend(struct device *dev)
{ {
struct drm_device *ddev = dev_get_drvdata(dev); struct msm_drm_private *priv = dev_get_drvdata(dev);
struct msm_drm_private *priv = ddev->dev_private;
struct msm_mdss *mdss = priv->mdss; struct msm_mdss *mdss = priv->mdss;
DBG(""); DBG("");
...@@ -1150,8 +1136,7 @@ static int __maybe_unused msm_runtime_suspend(struct device *dev) ...@@ -1150,8 +1136,7 @@ static int __maybe_unused msm_runtime_suspend(struct device *dev)
static int __maybe_unused msm_runtime_resume(struct device *dev) static int __maybe_unused msm_runtime_resume(struct device *dev)
{ {
struct drm_device *ddev = dev_get_drvdata(dev); struct msm_drm_private *priv = dev_get_drvdata(dev);
struct msm_drm_private *priv = ddev->dev_private;
struct msm_mdss *mdss = priv->mdss; struct msm_mdss *mdss = priv->mdss;
DBG(""); DBG("");
...@@ -1181,8 +1166,8 @@ static int __maybe_unused msm_pm_resume(struct device *dev) ...@@ -1181,8 +1166,8 @@ static int __maybe_unused msm_pm_resume(struct device *dev)
static int __maybe_unused msm_pm_prepare(struct device *dev) static int __maybe_unused msm_pm_prepare(struct device *dev)
{ {
struct drm_device *ddev = dev_get_drvdata(dev); struct msm_drm_private *priv = dev_get_drvdata(dev);
struct msm_drm_private *priv = ddev ? ddev->dev_private : NULL; struct drm_device *ddev = priv ? priv->dev : NULL;
if (!priv || !priv->kms) if (!priv || !priv->kms)
return 0; return 0;
...@@ -1192,8 +1177,8 @@ static int __maybe_unused msm_pm_prepare(struct device *dev) ...@@ -1192,8 +1177,8 @@ static int __maybe_unused msm_pm_prepare(struct device *dev)
static void __maybe_unused msm_pm_complete(struct device *dev) static void __maybe_unused msm_pm_complete(struct device *dev)
{ {
struct drm_device *ddev = dev_get_drvdata(dev); struct msm_drm_private *priv = dev_get_drvdata(dev);
struct msm_drm_private *priv = ddev ? ddev->dev_private : NULL; struct drm_device *ddev = priv ? priv->dev : NULL;
if (!priv || !priv->kms) if (!priv || !priv->kms)
return; return;
...@@ -1392,8 +1377,15 @@ static const struct component_master_ops msm_drm_ops = { ...@@ -1392,8 +1377,15 @@ static const struct component_master_ops msm_drm_ops = {
static int msm_pdev_probe(struct platform_device *pdev) static int msm_pdev_probe(struct platform_device *pdev)
{ {
struct component_match *match = NULL; struct component_match *match = NULL;
struct msm_drm_private *priv;
int ret; int ret;
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
return -ENOMEM;
platform_set_drvdata(pdev, priv);
if (get_mdp_ver(pdev)) { if (get_mdp_ver(pdev)) {
ret = add_display_components(pdev, &match); ret = add_display_components(pdev, &match);
if (ret) if (ret)
...@@ -1432,8 +1424,8 @@ static int msm_pdev_remove(struct platform_device *pdev) ...@@ -1432,8 +1424,8 @@ static int msm_pdev_remove(struct platform_device *pdev)
static void msm_pdev_shutdown(struct platform_device *pdev) static void msm_pdev_shutdown(struct platform_device *pdev)
{ {
struct drm_device *drm = platform_get_drvdata(pdev); struct msm_drm_private *priv = platform_get_drvdata(pdev);
struct msm_drm_private *priv = drm ? drm->dev_private : NULL; struct drm_device *drm = priv ? priv->dev : NULL;
if (!priv || !priv->kms) if (!priv || !priv->kms)
return; return;
......
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