Skip to content

Commit 5c0c825

Browse files
larunbestevenprice-arm
authored andcommitted
drm/panfrost: Replace DRM driver allocation method with newer one
Drop the deprecated DRM driver allocation method in favour of devm_drm_dev_alloc(). Overall just make it the same as in Panthor. Also discard now superfluous generic and platform device pointers inside the main panfrost device structure. Some ancient checkpatch issues unearthed as a result of these changes were also fixed, like lines too long or double assignment in one line. Reviewed-by: Steven Price <steven.price@arm.com> Acked-by: Boris Brezillon <boris.brezillon@collabora.com> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com> Link: https://lore.kernel.org/r/20251019145225.3621989-2-adrian.larumbe@collabora.com Signed-off-by: Steven Price <steven.price@arm.com>
1 parent ddf70cb commit 5c0c825

11 files changed

Lines changed: 146 additions & 157 deletions

drivers/gpu/drm/panfrost/panfrost_devfreq.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static int panfrost_devfreq_get_dev_status(struct device *dev,
7474

7575
spin_unlock_irqrestore(&pfdevfreq->lock, irqflags);
7676

77-
dev_dbg(pfdev->dev, "busy %lu total %lu %lu %% freq %lu MHz\n",
77+
dev_dbg(pfdev->base.dev, "busy %lu total %lu %lu %% freq %lu MHz\n",
7878
status->busy_time, status->total_time,
7979
status->busy_time / (status->total_time / 100),
8080
status->current_frequency / 1000 / 1000);
@@ -119,7 +119,7 @@ int panfrost_devfreq_init(struct panfrost_device *pfdev)
119119
int ret;
120120
struct dev_pm_opp *opp;
121121
unsigned long cur_freq;
122-
struct device *dev = &pfdev->pdev->dev;
122+
struct device *dev = pfdev->base.dev;
123123
struct devfreq *devfreq;
124124
struct thermal_cooling_device *cooling;
125125
struct panfrost_devfreq *pfdevfreq = &pfdev->pfdevfreq;

drivers/gpu/drm/panfrost/panfrost_device.c

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020

2121
static int panfrost_reset_init(struct panfrost_device *pfdev)
2222
{
23-
pfdev->rstc = devm_reset_control_array_get_optional_exclusive(pfdev->dev);
23+
pfdev->rstc = devm_reset_control_array_get_optional_exclusive(pfdev->base.dev);
2424
if (IS_ERR(pfdev->rstc)) {
25-
dev_err(pfdev->dev, "get reset failed %ld\n", PTR_ERR(pfdev->rstc));
25+
dev_err(pfdev->base.dev, "get reset failed %ld\n", PTR_ERR(pfdev->rstc));
2626
return PTR_ERR(pfdev->rstc);
2727
}
2828

@@ -39,30 +39,30 @@ static int panfrost_clk_init(struct panfrost_device *pfdev)
3939
int err;
4040
unsigned long rate;
4141

42-
pfdev->clock = devm_clk_get(pfdev->dev, NULL);
42+
pfdev->clock = devm_clk_get(pfdev->base.dev, NULL);
4343
if (IS_ERR(pfdev->clock)) {
44-
dev_err(pfdev->dev, "get clock failed %ld\n", PTR_ERR(pfdev->clock));
44+
dev_err(pfdev->base.dev, "get clock failed %ld\n", PTR_ERR(pfdev->clock));
4545
return PTR_ERR(pfdev->clock);
4646
}
4747

4848
rate = clk_get_rate(pfdev->clock);
49-
dev_info(pfdev->dev, "clock rate = %lu\n", rate);
49+
dev_info(pfdev->base.dev, "clock rate = %lu\n", rate);
5050

5151
err = clk_prepare_enable(pfdev->clock);
5252
if (err)
5353
return err;
5454

55-
pfdev->bus_clock = devm_clk_get_optional(pfdev->dev, "bus");
55+
pfdev->bus_clock = devm_clk_get_optional(pfdev->base.dev, "bus");
5656
if (IS_ERR(pfdev->bus_clock)) {
57-
dev_err(pfdev->dev, "get bus_clock failed %ld\n",
57+
dev_err(pfdev->base.dev, "get bus_clock failed %ld\n",
5858
PTR_ERR(pfdev->bus_clock));
5959
err = PTR_ERR(pfdev->bus_clock);
6060
goto disable_clock;
6161
}
6262

6363
if (pfdev->bus_clock) {
6464
rate = clk_get_rate(pfdev->bus_clock);
65-
dev_info(pfdev->dev, "bus_clock rate = %lu\n", rate);
65+
dev_info(pfdev->base.dev, "bus_clock rate = %lu\n", rate);
6666

6767
err = clk_prepare_enable(pfdev->bus_clock);
6868
if (err)
@@ -87,7 +87,7 @@ static int panfrost_regulator_init(struct panfrost_device *pfdev)
8787
{
8888
int ret, i;
8989

90-
pfdev->regulators = devm_kcalloc(pfdev->dev, pfdev->comp->num_supplies,
90+
pfdev->regulators = devm_kcalloc(pfdev->base.dev, pfdev->comp->num_supplies,
9191
sizeof(*pfdev->regulators),
9292
GFP_KERNEL);
9393
if (!pfdev->regulators)
@@ -96,20 +96,20 @@ static int panfrost_regulator_init(struct panfrost_device *pfdev)
9696
for (i = 0; i < pfdev->comp->num_supplies; i++)
9797
pfdev->regulators[i].supply = pfdev->comp->supply_names[i];
9898

99-
ret = devm_regulator_bulk_get(pfdev->dev,
99+
ret = devm_regulator_bulk_get(pfdev->base.dev,
100100
pfdev->comp->num_supplies,
101101
pfdev->regulators);
102102
if (ret < 0) {
103103
if (ret != -EPROBE_DEFER)
104-
dev_err(pfdev->dev, "failed to get regulators: %d\n",
104+
dev_err(pfdev->base.dev, "failed to get regulators: %d\n",
105105
ret);
106106
return ret;
107107
}
108108

109109
ret = regulator_bulk_enable(pfdev->comp->num_supplies,
110110
pfdev->regulators);
111111
if (ret < 0) {
112-
dev_err(pfdev->dev, "failed to enable regulators: %d\n", ret);
112+
dev_err(pfdev->base.dev, "failed to enable regulators: %d\n", ret);
113113
return ret;
114114
}
115115

@@ -144,7 +144,7 @@ static int panfrost_pm_domain_init(struct panfrost_device *pfdev)
144144
int err;
145145
int i, num_domains;
146146

147-
num_domains = of_count_phandle_with_args(pfdev->dev->of_node,
147+
num_domains = of_count_phandle_with_args(pfdev->base.dev->of_node,
148148
"power-domains",
149149
"#power-domain-cells");
150150

@@ -156,7 +156,7 @@ static int panfrost_pm_domain_init(struct panfrost_device *pfdev)
156156
return 0;
157157

158158
if (num_domains != pfdev->comp->num_pm_domains) {
159-
dev_err(pfdev->dev,
159+
dev_err(pfdev->base.dev,
160160
"Incorrect number of power domains: %d provided, %d needed\n",
161161
num_domains, pfdev->comp->num_pm_domains);
162162
return -EINVAL;
@@ -168,20 +168,21 @@ static int panfrost_pm_domain_init(struct panfrost_device *pfdev)
168168

169169
for (i = 0; i < num_domains; i++) {
170170
pfdev->pm_domain_devs[i] =
171-
dev_pm_domain_attach_by_name(pfdev->dev,
172-
pfdev->comp->pm_domain_names[i]);
171+
dev_pm_domain_attach_by_name(pfdev->base.dev,
172+
pfdev->comp->pm_domain_names[i]);
173173
if (IS_ERR_OR_NULL(pfdev->pm_domain_devs[i])) {
174174
err = PTR_ERR(pfdev->pm_domain_devs[i]) ? : -ENODATA;
175175
pfdev->pm_domain_devs[i] = NULL;
176-
dev_err(pfdev->dev,
176+
dev_err(pfdev->base.dev,
177177
"failed to get pm-domain %s(%d): %d\n",
178178
pfdev->comp->pm_domain_names[i], i, err);
179179
goto err;
180180
}
181181

182-
pfdev->pm_domain_links[i] = device_link_add(pfdev->dev,
183-
pfdev->pm_domain_devs[i], DL_FLAG_PM_RUNTIME |
184-
DL_FLAG_STATELESS | DL_FLAG_RPM_ACTIVE);
182+
pfdev->pm_domain_links[i] =
183+
device_link_add(pfdev->base.dev,
184+
pfdev->pm_domain_devs[i], DL_FLAG_PM_RUNTIME |
185+
DL_FLAG_STATELESS | DL_FLAG_RPM_ACTIVE);
185186
if (!pfdev->pm_domain_links[i]) {
186187
dev_err(pfdev->pm_domain_devs[i],
187188
"adding device link failed!\n");
@@ -220,20 +221,20 @@ int panfrost_device_init(struct panfrost_device *pfdev)
220221

221222
err = panfrost_reset_init(pfdev);
222223
if (err) {
223-
dev_err(pfdev->dev, "reset init failed %d\n", err);
224+
dev_err(pfdev->base.dev, "reset init failed %d\n", err);
224225
goto out_pm_domain;
225226
}
226227

227228
err = panfrost_clk_init(pfdev);
228229
if (err) {
229-
dev_err(pfdev->dev, "clk init failed %d\n", err);
230+
dev_err(pfdev->base.dev, "clk init failed %d\n", err);
230231
goto out_reset;
231232
}
232233

233234
err = panfrost_devfreq_init(pfdev);
234235
if (err) {
235236
if (err != -EPROBE_DEFER)
236-
dev_err(pfdev->dev, "devfreq init failed %d\n", err);
237+
dev_err(pfdev->base.dev, "devfreq init failed %d\n", err);
237238
goto out_clk;
238239
}
239240

@@ -244,7 +245,7 @@ int panfrost_device_init(struct panfrost_device *pfdev)
244245
goto out_devfreq;
245246
}
246247

247-
pfdev->iomem = devm_platform_ioremap_resource(pfdev->pdev, 0);
248+
pfdev->iomem = devm_platform_ioremap_resource(to_platform_device(pfdev->base.dev), 0);
248249
if (IS_ERR(pfdev->iomem)) {
249250
err = PTR_ERR(pfdev->iomem);
250251
goto out_regulator;

drivers/gpu/drm/panfrost/panfrost_device.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@ struct panfrost_device_debugfs {
124124
};
125125

126126
struct panfrost_device {
127-
struct device *dev;
128-
struct drm_device *ddev;
129-
struct platform_device *pdev;
127+
struct drm_device base;
130128
int gpu_irq;
131129
int mmu_irq;
132130

@@ -222,7 +220,7 @@ static inline bool panfrost_high_prio_allowed(struct drm_file *file)
222220

223221
static inline struct panfrost_device *to_panfrost_device(struct drm_device *ddev)
224222
{
225-
return ddev->dev_private;
223+
return container_of(ddev, struct panfrost_device, base);
226224
}
227225

228226
static inline int panfrost_model_cmp(struct panfrost_device *pfdev, s32 id)

drivers/gpu/drm/panfrost/panfrost_drv.c

Lines changed: 29 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,22 @@ static int panfrost_ioctl_query_timestamp(struct panfrost_device *pfdev,
3636
{
3737
int ret;
3838

39-
ret = pm_runtime_resume_and_get(pfdev->dev);
39+
ret = pm_runtime_resume_and_get(pfdev->base.dev);
4040
if (ret)
4141
return ret;
4242

4343
panfrost_cycle_counter_get(pfdev);
4444
*arg = panfrost_timestamp_read(pfdev);
4545
panfrost_cycle_counter_put(pfdev);
4646

47-
pm_runtime_put(pfdev->dev);
47+
pm_runtime_put(pfdev->base.dev);
4848
return 0;
4949
}
5050

5151
static int panfrost_ioctl_get_param(struct drm_device *ddev, void *data, struct drm_file *file)
5252
{
5353
struct drm_panfrost_get_param *param = data;
54-
struct panfrost_device *pfdev = ddev->dev_private;
54+
struct panfrost_device *pfdev = to_panfrost_device(ddev);
5555
int ret;
5656

5757
if (param->pad != 0)
@@ -283,7 +283,7 @@ panfrost_copy_in_sync(struct drm_device *dev,
283283
static int panfrost_ioctl_submit(struct drm_device *dev, void *data,
284284
struct drm_file *file)
285285
{
286-
struct panfrost_device *pfdev = dev->dev_private;
286+
struct panfrost_device *pfdev = to_panfrost_device(dev);
287287
struct panfrost_file_priv *file_priv = file->driver_priv;
288288
struct drm_panfrost_submit *args = data;
289289
struct drm_syncobj *sync_out = NULL;
@@ -457,7 +457,7 @@ static int panfrost_ioctl_madvise(struct drm_device *dev, void *data,
457457
{
458458
struct panfrost_file_priv *priv = file_priv->driver_priv;
459459
struct drm_panfrost_madvise *args = data;
460-
struct panfrost_device *pfdev = dev->dev_private;
460+
struct panfrost_device *pfdev = to_panfrost_device(dev);
461461
struct drm_gem_object *gem_obj;
462462
struct panfrost_gem_object *bo;
463463
int ret = 0;
@@ -590,7 +590,7 @@ static int
590590
panfrost_open(struct drm_device *dev, struct drm_file *file)
591591
{
592592
int ret;
593-
struct panfrost_device *pfdev = dev->dev_private;
593+
struct panfrost_device *pfdev = to_panfrost_device(dev);
594594
struct panfrost_file_priv *panfrost_priv;
595595

596596
panfrost_priv = kzalloc(sizeof(*panfrost_priv), GFP_KERNEL);
@@ -686,8 +686,7 @@ static void panfrost_gpu_show_fdinfo(struct panfrost_device *pfdev,
686686

687687
static void panfrost_show_fdinfo(struct drm_printer *p, struct drm_file *file)
688688
{
689-
struct drm_device *dev = file->minor->dev;
690-
struct panfrost_device *pfdev = dev->dev_private;
689+
struct panfrost_device *pfdev = to_panfrost_device(file->minor->dev);
691690

692691
panfrost_gpu_show_fdinfo(pfdev, file->driver_priv, p);
693692

@@ -704,8 +703,7 @@ static const struct file_operations panfrost_drm_driver_fops = {
704703
static int panthor_gems_show(struct seq_file *m, void *data)
705704
{
706705
struct drm_info_node *node = m->private;
707-
struct drm_device *dev = node->minor->dev;
708-
struct panfrost_device *pfdev = dev->dev_private;
706+
struct panfrost_device *pfdev = to_panfrost_device(node->minor->dev);
709707

710708
panfrost_gem_debugfs_print_bos(pfdev, m);
711709

@@ -754,7 +752,8 @@ static int show_file_jm_ctxs(struct panfrost_file_priv *pfile,
754752
}
755753

756754
static struct drm_info_list panthor_debugfs_list[] = {
757-
{"gems", panthor_gems_show, 0, NULL},
755+
{"gems",
756+
panthor_gems_show, 0, NULL},
758757
};
759758

760759
static int panthor_gems_debugfs_init(struct drm_minor *minor)
@@ -861,15 +860,12 @@ static const struct drm_driver panfrost_drm_driver = {
861860
static int panfrost_probe(struct platform_device *pdev)
862861
{
863862
struct panfrost_device *pfdev;
864-
struct drm_device *ddev;
865863
int err;
866864

867-
pfdev = devm_kzalloc(&pdev->dev, sizeof(*pfdev), GFP_KERNEL);
868-
if (!pfdev)
869-
return -ENOMEM;
870-
871-
pfdev->pdev = pdev;
872-
pfdev->dev = &pdev->dev;
865+
pfdev = devm_drm_dev_alloc(&pdev->dev, &panfrost_drm_driver,
866+
struct panfrost_device, base);
867+
if (IS_ERR(pfdev))
868+
return PTR_ERR(pfdev);
873869

874870
platform_set_drvdata(pdev, pfdev);
875871

@@ -879,14 +875,6 @@ static int panfrost_probe(struct platform_device *pdev)
879875

880876
pfdev->coherent = device_get_dma_attr(&pdev->dev) == DEV_DMA_COHERENT;
881877

882-
/* Allocate and initialize the DRM device. */
883-
ddev = drm_dev_alloc(&panfrost_drm_driver, &pdev->dev);
884-
if (IS_ERR(ddev))
885-
return PTR_ERR(ddev);
886-
887-
ddev->dev_private = pfdev;
888-
pfdev->ddev = ddev;
889-
890878
mutex_init(&pfdev->shrinker_lock);
891879
INIT_LIST_HEAD(&pfdev->shrinker_list);
892880

@@ -897,51 +885,47 @@ static int panfrost_probe(struct platform_device *pdev)
897885
goto err_out0;
898886
}
899887

900-
pm_runtime_set_active(pfdev->dev);
901-
pm_runtime_mark_last_busy(pfdev->dev);
902-
pm_runtime_enable(pfdev->dev);
903-
pm_runtime_set_autosuspend_delay(pfdev->dev, 50); /* ~3 frames */
904-
pm_runtime_use_autosuspend(pfdev->dev);
888+
pm_runtime_set_active(pfdev->base.dev);
889+
pm_runtime_mark_last_busy(pfdev->base.dev);
890+
pm_runtime_enable(pfdev->base.dev);
891+
pm_runtime_set_autosuspend_delay(pfdev->base.dev, 50); /* ~3 frames */
892+
pm_runtime_use_autosuspend(pfdev->base.dev);
905893

906894
/*
907895
* Register the DRM device with the core and the connectors with
908896
* sysfs
909897
*/
910-
err = drm_dev_register(ddev, 0);
898+
err = drm_dev_register(&pfdev->base, 0);
911899
if (err < 0)
912900
goto err_out1;
913901

914-
err = panfrost_gem_shrinker_init(ddev);
902+
err = panfrost_gem_shrinker_init(&pfdev->base);
915903
if (err)
916904
goto err_out2;
917905

918906
return 0;
919907

920908
err_out2:
921-
drm_dev_unregister(ddev);
909+
drm_dev_unregister(&pfdev->base);
922910
err_out1:
923-
pm_runtime_disable(pfdev->dev);
911+
pm_runtime_disable(pfdev->base.dev);
924912
panfrost_device_fini(pfdev);
925-
pm_runtime_set_suspended(pfdev->dev);
913+
pm_runtime_set_suspended(pfdev->base.dev);
926914
err_out0:
927-
drm_dev_put(ddev);
928915
return err;
929916
}
930917

931918
static void panfrost_remove(struct platform_device *pdev)
932919
{
933920
struct panfrost_device *pfdev = platform_get_drvdata(pdev);
934-
struct drm_device *ddev = pfdev->ddev;
935921

936-
drm_dev_unregister(ddev);
937-
panfrost_gem_shrinker_cleanup(ddev);
922+
drm_dev_unregister(&pfdev->base);
923+
panfrost_gem_shrinker_cleanup(&pfdev->base);
938924

939-
pm_runtime_get_sync(pfdev->dev);
940-
pm_runtime_disable(pfdev->dev);
925+
pm_runtime_get_sync(pfdev->base.dev);
926+
pm_runtime_disable(pfdev->base.dev);
941927
panfrost_device_fini(pfdev);
942-
pm_runtime_set_suspended(pfdev->dev);
943-
944-
drm_dev_put(ddev);
928+
pm_runtime_set_suspended(pfdev->base.dev);
945929
}
946930

947931
static ssize_t profiling_show(struct device *dev,

0 commit comments

Comments
 (0)