Skip to content

Commit 3c4baba

Browse files
committed
drm: Call drm_atomic_helper_shutdown() at shutdown/remove time for misc drivers
Based on grepping through the source code these drivers appear to be missing a call to drm_atomic_helper_shutdown() at system shutdown time and at driver remove (or unbind) time. Among other things, this means that if a panel is in use that it won't be cleanly powered off at system shutdown time. The fact that we should call drm_atomic_helper_shutdown() in the case of OS shutdown/restart and at driver remove (or unbind) time comes straight out of the kernel doc "driver instance overview" in drm_drv.c. A few notes about these fixes: - I confirmed that these drivers were all DRIVER_MODESET type drivers, which I believe makes this relevant. - I confirmed that these drivers were all DRIVER_ATOMIC. - When adding drm_atomic_helper_shutdown() to the remove/unbind path, I added it after drm_kms_helper_poll_fini() when the driver had it. This seemed to be what other drivers did. If drm_kms_helper_poll_fini() wasn't there I added it straight after drm_dev_unregister(). - This patch deals with drivers using the component model in similar ways as the patch ("drm: Call drm_atomic_helper_shutdown() at shutdown time for misc drivers") - These fixes rely on the patch ("drm/atomic-helper: drm_atomic_helper_shutdown(NULL) should be a noop") to simplify shutdown. Suggested-by: Maxime Ripard <mripard@kernel.org> Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # tilcdc Acked-by: Maxime Ripard <mripard@kernel.org> Signed-off-by: Douglas Anderson <dianders@chromium.org> Link: https://patchwork.freedesktop.org/patch/msgid/20230901163944.RFT.5.I771eb4bd03d8772b19e7dcfaef3e2c167bce5846@changeid
1 parent 10c8204 commit 3c4baba

7 files changed

Lines changed: 56 additions & 1 deletion

File tree

drivers/gpu/drm/aspeed/aspeed_gfx_drv.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,11 +358,18 @@ static void aspeed_gfx_remove(struct platform_device *pdev)
358358
sysfs_remove_group(&pdev->dev.kobj, &aspeed_sysfs_attr_group);
359359
drm_dev_unregister(drm);
360360
aspeed_gfx_unload(drm);
361+
drm_atomic_helper_shutdown(drm);
362+
}
363+
364+
static void aspeed_gfx_shutdown(struct platform_device *pdev)
365+
{
366+
drm_atomic_helper_shutdown(platform_get_drvdata(pdev));
361367
}
362368

363369
static struct platform_driver aspeed_gfx_platform_driver = {
364370
.probe = aspeed_gfx_probe,
365371
.remove_new = aspeed_gfx_remove,
372+
.shutdown = aspeed_gfx_shutdown,
366373
.driver = {
367374
.name = "aspeed_gfx",
368375
.of_match_table = aspeed_gfx_match,

drivers/gpu/drm/mgag200/mgag200_drv.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/pci.h>
1111

1212
#include <drm/drm_aperture.h>
13+
#include <drm/drm_atomic_helper.h>
1314
#include <drm/drm_drv.h>
1415
#include <drm/drm_fbdev_generic.h>
1516
#include <drm/drm_file.h>
@@ -278,13 +279,20 @@ static void mgag200_pci_remove(struct pci_dev *pdev)
278279
struct drm_device *dev = pci_get_drvdata(pdev);
279280

280281
drm_dev_unregister(dev);
282+
drm_atomic_helper_shutdown(dev);
283+
}
284+
285+
static void mgag200_pci_shutdown(struct pci_dev *pdev)
286+
{
287+
drm_atomic_helper_shutdown(pci_get_drvdata(pdev));
281288
}
282289

283290
static struct pci_driver mgag200_pci_driver = {
284291
.name = DRIVER_NAME,
285292
.id_table = mgag200_pciidlist,
286293
.probe = mgag200_pci_probe,
287294
.remove = mgag200_pci_remove,
295+
.shutdown = mgag200_pci_shutdown,
288296
};
289297

290298
drm_module_pci_driver_if_modeset(mgag200_pci_driver, mgag200_modeset);

drivers/gpu/drm/pl111/pl111_drv.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,12 +323,18 @@ static void pl111_amba_remove(struct amba_device *amba_dev)
323323
struct pl111_drm_dev_private *priv = drm->dev_private;
324324

325325
drm_dev_unregister(drm);
326+
drm_atomic_helper_shutdown(drm);
326327
if (priv->panel)
327328
drm_panel_bridge_remove(priv->bridge);
328329
drm_dev_put(drm);
329330
of_reserved_mem_device_release(dev);
330331
}
331332

333+
static void pl111_amba_shutdown(struct amba_device *amba_dev)
334+
{
335+
drm_atomic_helper_shutdown(amba_get_drvdata(amba_dev));
336+
}
337+
332338
/*
333339
* This early variant lacks the 565 and 444 pixel formats.
334340
*/
@@ -431,6 +437,7 @@ static struct amba_driver pl111_amba_driver __maybe_unused = {
431437
},
432438
.probe = pl111_amba_probe,
433439
.remove = pl111_amba_remove,
440+
.shutdown = pl111_amba_shutdown,
434441
.id_table = pl111_id_table,
435442
};
436443

drivers/gpu/drm/stm/drv.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ static void drv_unload(struct drm_device *ddev)
114114
DRM_DEBUG("%s\n", __func__);
115115

116116
drm_kms_helper_poll_fini(ddev);
117+
drm_atomic_helper_shutdown(ddev);
117118
ltdc_unload(ddev);
118119
}
119120

@@ -225,6 +226,11 @@ static void stm_drm_platform_remove(struct platform_device *pdev)
225226
drm_dev_put(ddev);
226227
}
227228

229+
static void stm_drm_platform_shutdown(struct platform_device *pdev)
230+
{
231+
drm_atomic_helper_shutdown(platform_get_drvdata(pdev));
232+
}
233+
228234
static const struct of_device_id drv_dt_ids[] = {
229235
{ .compatible = "st,stm32-ltdc"},
230236
{ /* end node */ },
@@ -234,6 +240,7 @@ MODULE_DEVICE_TABLE(of, drv_dt_ids);
234240
static struct platform_driver stm_drm_platform_driver = {
235241
.probe = stm_drm_platform_probe,
236242
.remove_new = stm_drm_platform_remove,
243+
.shutdown = stm_drm_platform_shutdown,
237244
.driver = {
238245
.name = "stm32-display",
239246
.of_match_table = drv_dt_ids,

drivers/gpu/drm/tilcdc/tilcdc_drv.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ static void tilcdc_fini(struct drm_device *dev)
175175
drm_dev_unregister(dev);
176176

177177
drm_kms_helper_poll_fini(dev);
178+
drm_atomic_helper_shutdown(dev);
178179
tilcdc_irq_uninstall(dev);
179180
drm_mode_config_cleanup(dev);
180181

@@ -389,6 +390,7 @@ static int tilcdc_init(const struct drm_driver *ddrv, struct device *dev)
389390

390391
init_failed:
391392
tilcdc_fini(ddev);
393+
platform_set_drvdata(pdev, NULL);
392394

393395
return ret;
394396
}
@@ -537,7 +539,8 @@ static void tilcdc_unbind(struct device *dev)
537539
if (!ddev->dev_private)
538540
return;
539541

540-
tilcdc_fini(dev_get_drvdata(dev));
542+
tilcdc_fini(ddev);
543+
dev_set_drvdata(dev, NULL);
541544
}
542545

543546
static const struct component_master_ops tilcdc_comp_ops = {
@@ -582,6 +585,11 @@ static int tilcdc_pdev_remove(struct platform_device *pdev)
582585
return 0;
583586
}
584587

588+
static void tilcdc_pdev_shutdown(struct platform_device *pdev)
589+
{
590+
drm_atomic_helper_shutdown(platform_get_drvdata(pdev));
591+
}
592+
585593
static const struct of_device_id tilcdc_of_match[] = {
586594
{ .compatible = "ti,am33xx-tilcdc", },
587595
{ .compatible = "ti,da850-tilcdc", },
@@ -592,6 +600,7 @@ MODULE_DEVICE_TABLE(of, tilcdc_of_match);
592600
static struct platform_driver tilcdc_platform_driver = {
593601
.probe = tilcdc_pdev_probe,
594602
.remove = tilcdc_pdev_remove,
603+
.shutdown = tilcdc_pdev_shutdown,
595604
.driver = {
596605
.name = "tilcdc",
597606
.pm = pm_sleep_ptr(&tilcdc_pm_ops),

drivers/gpu/drm/tve200/tve200_drv.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,19 @@ static void tve200_remove(struct platform_device *pdev)
242242
struct tve200_drm_dev_private *priv = drm->dev_private;
243243

244244
drm_dev_unregister(drm);
245+
drm_atomic_helper_shutdown(drm);
245246
if (priv->panel)
246247
drm_panel_bridge_remove(priv->bridge);
247248
drm_mode_config_cleanup(drm);
248249
clk_disable_unprepare(priv->pclk);
249250
drm_dev_put(drm);
250251
}
251252

253+
static void tve200_shutdown(struct platform_device *pdev)
254+
{
255+
drm_atomic_helper_shutdown(platform_get_drvdata(pdev));
256+
}
257+
252258
static const struct of_device_id tve200_of_match[] = {
253259
{
254260
.compatible = "faraday,tve200",
@@ -263,6 +269,7 @@ static struct platform_driver tve200_driver = {
263269
},
264270
.probe = tve200_probe,
265271
.remove_new = tve200_remove,
272+
.shutdown = tve200_shutdown,
266273
};
267274
drm_module_platform_driver(tve200_driver);
268275

drivers/gpu/drm/vboxvideo/vbox_drv.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/vt_kern.h>
1313

1414
#include <drm/drm_aperture.h>
15+
#include <drm/drm_atomic_helper.h>
1516
#include <drm/drm_drv.h>
1617
#include <drm/drm_fbdev_generic.h>
1718
#include <drm/drm_file.h>
@@ -97,11 +98,19 @@ static void vbox_pci_remove(struct pci_dev *pdev)
9798
struct vbox_private *vbox = pci_get_drvdata(pdev);
9899

99100
drm_dev_unregister(&vbox->ddev);
101+
drm_atomic_helper_shutdown(&vbox->ddev);
100102
vbox_irq_fini(vbox);
101103
vbox_mode_fini(vbox);
102104
vbox_hw_fini(vbox);
103105
}
104106

107+
static void vbox_pci_shutdown(struct pci_dev *pdev)
108+
{
109+
struct vbox_private *vbox = pci_get_drvdata(pdev);
110+
111+
drm_atomic_helper_shutdown(&vbox->ddev);
112+
}
113+
105114
static int vbox_pm_suspend(struct device *dev)
106115
{
107116
struct vbox_private *vbox = dev_get_drvdata(dev);
@@ -165,6 +174,7 @@ static struct pci_driver vbox_pci_driver = {
165174
.id_table = pciidlist,
166175
.probe = vbox_pci_probe,
167176
.remove = vbox_pci_remove,
177+
.shutdown = vbox_pci_shutdown,
168178
.driver.pm = pm_sleep_ptr(&vbox_pm_ops),
169179
};
170180

0 commit comments

Comments
 (0)