From nobody Thu Dec 18 00:22:09 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 879A9CA0FF6 for ; Fri, 1 Sep 2023 23:41:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351232AbjIAXld (ORCPT ); Fri, 1 Sep 2023 19:41:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351229AbjIAXlb (ORCPT ); Fri, 1 Sep 2023 19:41:31 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72D7110F8 for ; Fri, 1 Sep 2023 16:40:55 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-569deb93999so1840196a12.2 for ; Fri, 01 Sep 2023 16:40:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1693611645; x=1694216445; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=c1LlxEF4RQMcRybMyLUYgejZ0HV1kn3rreyInd+SMhw=; b=XBhWShFPR1RSx6EKUhplpox2LnfAVYalodlp16fzfOLr2D5fmIlQS9oR9lhZ5HV05f Gr1BpS7aY4ldg6myoWPdZFLlKoXgBwpQolGRlvtF5u2kXb84aNF45aH6QHLdN7NpQpFD VRP699LtNxFGieXYK7uU7JzqRAWx+lWYBhIUI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693611645; x=1694216445; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c1LlxEF4RQMcRybMyLUYgejZ0HV1kn3rreyInd+SMhw=; b=aEmf+a17RtK21dpVf2Vm3yt7Cy3UNZjl53d08AfW/RK/6/n5Nao5YAyTD89G4T4TRw BGEjZpVLRmFSjxQXTHh1VNxioBo3l+utRA32HKtzXadMdvr+MYdCNOoCexnxqw8GFXc1 EgBR9M7A8dIB36jLRWOR9Err1EpChebfFIWsbqRgFo6kguRhly65itWsolZpwNwtMnFG g9VxTn/BHVYr1g0kLGstNV6LIhyi5stJ0e31K9rR10Mgri6bV+FCyN9wkd6KmFnjYRdr g3mmHMfox6IAv4AAiloaw3haRJj3qAyusDGt8s6xRXFlH5/cvGLH8sIiuYL3Ww+rzFgi HLWA== X-Gm-Message-State: AOJu0YzvdMW3WfxIMIzXSn7712lm/5pl9BMmtjPuTbjhxjp5M/HVMnza 7NsYtcyRPvWzdKlRBRhq5TAYYQ== X-Google-Smtp-Source: AGHT+IHdqIX+XBiRHTDluS5KvZ5QkvIQj+FK8jGum6b97Eu1rT0JDLuFn7HoN6B/O2zYYxeetoxxxA== X-Received: by 2002:a17:90b:33cc:b0:269:96e:7d52 with SMTP id lk12-20020a17090b33cc00b00269096e7d52mr3827916pjb.26.1693611645262; Fri, 01 Sep 2023 16:40:45 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:8d94:1fc5:803c:41cc]) by smtp.gmail.com with ESMTPSA id 5-20020a17090a1a4500b0026b4ca7f62csm3773488pjl.39.2023.09.01.16.40.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 16:40:44 -0700 (PDT) From: Douglas Anderson To: dri-devel@lists.freedesktop.org, Maxime Ripard Cc: Douglas Anderson , airlied@gmail.com, daniel@ffwll.ch, linux-kernel@vger.kernel.org, maarten.lankhorst@linux.intel.com, tzimmermann@suse.de Subject: [RFT PATCH 1/6] drm/atomic-helper: drm_atomic_helper_shutdown(NULL) should be a noop Date: Fri, 1 Sep 2023 16:39:52 -0700 Message-ID: <20230901163944.RFT.1.I906acd535bece03b6671d97c2826c6f0444f4728@changeid> X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog In-Reply-To: <20230901234015.566018-1-dianders@chromium.org> References: <20230901234015.566018-1-dianders@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" As with other places in the Linux kernel--kfree(NULL) being the most famous example--it's convenient to treat being passed a NULL argument as a noop in cleanup functions. Let's make drm_atomic_helper_shutdown() work like this. This is convenient for DRM devices that use the "component" model. On these devices we want shutdown to be a noop if the bind() call of the component hasn't been called yet. As long as drivers are careful to make sure the drvdata is NULL whenever the driver is not bound then we can just do a simple call to drm_atomic_helper_shutdown() with the drvdata at shutdown time. Signed-off-by: Douglas Anderson Acked-by: Maxime Ripard --- drivers/gpu/drm/drm_atomic_helper.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atom= ic_helper.c index 292e38eb6218..71d399397107 100644 --- a/drivers/gpu/drm/drm_atomic_helper.c +++ b/drivers/gpu/drm/drm_atomic_helper.c @@ -3339,6 +3339,9 @@ void drm_atomic_helper_shutdown(struct drm_device *de= v) struct drm_modeset_acquire_ctx ctx; int ret; =20 + if (dev =3D=3D NULL) + return; + DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, ret); =20 ret =3D drm_atomic_helper_disable_all(dev, &ctx); --=20 2.42.0.283.g2d96d420d3-goog From nobody Thu Dec 18 00:22:09 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62354CA0FFA for ; Fri, 1 Sep 2023 23:41:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351238AbjIAXlk (ORCPT ); Fri, 1 Sep 2023 19:41:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351233AbjIAXld (ORCPT ); Fri, 1 Sep 2023 19:41:33 -0400 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EFDD1998 for ; Fri, 1 Sep 2023 16:40:57 -0700 (PDT) Received: by mail-pg1-x52e.google.com with SMTP id 41be03b00d2f7-565403bda57so1737597a12.3 for ; Fri, 01 Sep 2023 16:40:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1693611649; x=1694216449; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=avtFoQWfrX7xdMu3Sd5ac4PfesUntzwfqvS4jP+7oBI=; b=dQ5K9lwUFrTIcSOTT6hnxJRauycCe46/WcPvwV1eg4V+p2vhAkqw37Sox2TlZehG00 34FlhAyiG/Jlu3RoKrP3+6qrfJNFsoMFEd99S+w6ofRaHbYNjBPHy1ZIPWIxV3AO8caE pdPz03X6bYv1Qq38GqmAMb+2sl4uMei5VURp0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693611649; x=1694216449; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=avtFoQWfrX7xdMu3Sd5ac4PfesUntzwfqvS4jP+7oBI=; b=On1FYtlamdnRm1JWl++FdvEwx4EydmwJfh1CfutLolO0pFeO7rRYtqWJw/Ca6y96L6 tmVjjNwbPQkeSo9Ely1P+RW73d4gzphQir3GNyzzJU5WV5Olo8QwRsTurS01JTRF4Opm mppTHF/PhUunza+LjkwCAI83lv24dzYqYdQuOqfkh7+HhGVo7FqnHv/JQ5QyaGokgnwQ EgHV7TvQIcqKSTncx1z/6J756GBCv5Mqmm4Sr7gFvo1vZfqt2EuSGiZiv4UGwudRYLoa dBQ5wuYg1d3gBO1Qnlic09BSzbDjQznbxkcRByGKxhqeTlruEScsr1g/QWtugSSYTwyQ tiMQ== X-Gm-Message-State: AOJu0Yygh84qOmlnGVIONAm3FoBtv/ZCl8pNpfmA3Jf7iFzORq9Ws5ph 9gWORfNaAtOeT6UPjj1ZGyoZAw== X-Google-Smtp-Source: AGHT+IF+1sCuqR6i5s3DNMl3XitRy524OyiSPFyAlVpl5Y7dCztWfGCzWdm6Ibi7nkN2uBmxsAN69Q== X-Received: by 2002:a17:90a:898d:b0:262:ece1:5fd0 with SMTP id v13-20020a17090a898d00b00262ece15fd0mr3751666pjn.12.1693611648909; Fri, 01 Sep 2023 16:40:48 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:8d94:1fc5:803c:41cc]) by smtp.gmail.com with ESMTPSA id 5-20020a17090a1a4500b0026b4ca7f62csm3773488pjl.39.2023.09.01.16.40.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 16:40:48 -0700 (PDT) From: Douglas Anderson To: dri-devel@lists.freedesktop.org, Maxime Ripard Cc: Douglas Anderson , airlied@gmail.com, airlied@redhat.com, alain.volmat@foss.st.com, alexander.deucher@amd.com, alexandre.belloni@bootlin.com, alison.wang@nxp.com, bbrezillon@kernel.org, christian.koenig@amd.com, claudiu.beznea@microchip.com, daniel@ffwll.ch, drawat.floss@gmail.com, javierm@redhat.com, jernej.skrabec@gmail.com, jfalempe@redhat.com, jstultz@google.com, kong.kongxinwei@hisilicon.com, kraxel@redhat.com, linus.walleij@linaro.org, linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@lists.linux.dev, liviu.dudau@arm.com, nicolas.ferre@microchip.com, paul.kocialkowski@bootlin.com, sam@ravnborg.org, samuel@sholland.org, spice-devel@lists.freedesktop.org, stefan@agner.ch, suijingfeng@loongson.cn, sumit.semwal@linaro.org, tiantao6@hisilicon.com, tomi.valkeinen@ideasonboard.com, tzimmermann@suse.de, virtualization@lists.linux-foundation.org, wens@csie.org, xinliang.liu@linaro.org, yongqin.liu@linaro.org, zackr@vmware.com Subject: [RFT PATCH 2/6] drm: Call drm_atomic_helper_shutdown() at shutdown time for misc drivers Date: Fri, 1 Sep 2023 16:39:53 -0700 Message-ID: <20230901163944.RFT.2.I9115e5d094a43e687978b0699cc1fe9f2a3452ea@changeid> X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog In-Reply-To: <20230901234015.566018-1-dianders@chromium.org> References: <20230901234015.566018-1-dianders@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Based on grepping through the source code these drivers appear to be missing a call to drm_atomic_helper_shutdown() at system shutdown 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 comes straight out of the kernel doc "driver instance overview" in drm_drv.c. All of the drivers in this patch were fairly straightforward to fix since they already had a call to drm_atomic_helper_shutdown() at remove/unbind time but were just lacking one at system shutdown. The only hitch is that some of these drivers use the component model to register/unregister their DRM devices. The shutdown callback is part of the original device. The typical solution here, based on how other DRM drivers do this, is to keep track of whether the device is bound based on drvdata. In most cases the drvdata is the drm_device, so we can just make sure it is NULL when the device is not bound. In some drivers, this required minor code changes. To make things simpler, drm_atomic_helper_shutdown() has been modified to consider a NULL drm_device as a noop in the patch ("drm/atomic-helper: drm_atomic_helper_shutdown(NULL) should be a noop"). Suggested-by: Maxime Ripard Signed-off-by: Douglas Anderson Acked-by: Maxime Ripard Reviewed-by: Jernej Skrabec Reviewed-by: Sui Jingfeng Reviewed-by: Tomi Valkeinen Tested-by: Jernej Skrabec Tested-by: Sui Jingfeng Tested-by: Tomi Valkeinen --- This commit is only compile-time tested. Note that checkpatch yells that "drivers/gpu/drm/tiny/cirrus.c" is marked as 'obsolete', but it seems silly not to include the fix if it's already been written. If someone wants me to take that out, though, I can. drivers/gpu/drm/arm/display/komeda/komeda_drv.c | 9 +++++++++ drivers/gpu/drm/arm/display/komeda/komeda_kms.c | 7 +++++++ drivers/gpu/drm/arm/display/komeda/komeda_kms.h | 1 + drivers/gpu/drm/arm/hdlcd_drv.c | 6 ++++++ drivers/gpu/drm/arm/malidp_drv.c | 6 ++++++ drivers/gpu/drm/ast/ast_drv.c | 6 ++++++ drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.c | 6 ++++++ drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c | 8 ++++++++ drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c | 6 ++++++ drivers/gpu/drm/hyperv/hyperv_drm_drv.c | 6 ++++++ drivers/gpu/drm/logicvc/logicvc_drm.c | 9 +++++++++ drivers/gpu/drm/loongson/lsdc_drv.c | 6 ++++++ drivers/gpu/drm/mcde/mcde_drv.c | 9 +++++++++ drivers/gpu/drm/omapdrm/omap_drv.c | 8 ++++++++ drivers/gpu/drm/qxl/qxl_drv.c | 7 +++++++ drivers/gpu/drm/sti/sti_drv.c | 7 +++++++ drivers/gpu/drm/sun4i/sun4i_drv.c | 6 ++++++ drivers/gpu/drm/tiny/bochs.c | 6 ++++++ drivers/gpu/drm/tiny/cirrus.c | 6 ++++++ 19 files changed, 125 insertions(+) diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_drv.c b/drivers/gpu/= drm/arm/display/komeda/komeda_drv.c index cb2a2be24c5f..cc57ea4e13ae 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_drv.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_drv.c @@ -45,6 +45,14 @@ static void komeda_platform_remove(struct platform_devic= e *pdev) devm_kfree(dev, mdrv); } =20 +static void komeda_platform_shutdown(struct platform_device *pdev) +{ + struct device *dev =3D &pdev->dev; + struct komeda_drv *mdrv =3D dev_get_drvdata(dev); + + komeda_kms_shutdown(mdrv->kms); +} + static int komeda_platform_probe(struct platform_device *pdev) { struct device *dev =3D &pdev->dev; @@ -142,6 +150,7 @@ static const struct dev_pm_ops komeda_pm_ops =3D { static struct platform_driver komeda_platform_driver =3D { .probe =3D komeda_platform_probe, .remove_new =3D komeda_platform_remove, + .shutdown =3D komeda_platform_shutdown, .driver =3D { .name =3D "komeda", .of_match_table =3D komeda_of_match, diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_kms.c b/drivers/gpu/= drm/arm/display/komeda/komeda_kms.c index 9299026701f3..fe46b0ebefea 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_kms.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_kms.c @@ -340,3 +340,10 @@ void komeda_kms_detach(struct komeda_kms_dev *kms) komeda_kms_cleanup_private_objs(kms); drm->dev_private =3D NULL; } + +void komeda_kms_shutdown(struct komeda_kms_dev *kms) +{ + struct drm_device *drm =3D &kms->base; + + drm_atomic_helper_shutdown(drm); +} diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_kms.h b/drivers/gpu/= drm/arm/display/komeda/komeda_kms.h index 6ef655326357..a4048724564d 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_kms.h +++ b/drivers/gpu/drm/arm/display/komeda/komeda_kms.h @@ -190,5 +190,6 @@ void komeda_crtc_flush_and_wait_for_flip_done(struct ko= meda_crtc *kcrtc, =20 struct komeda_kms_dev *komeda_kms_attach(struct komeda_dev *mdev); void komeda_kms_detach(struct komeda_kms_dev *kms); +void komeda_kms_shutdown(struct komeda_kms_dev *kms); =20 #endif /*_KOMEDA_KMS_H_*/ diff --git a/drivers/gpu/drm/arm/hdlcd_drv.c b/drivers/gpu/drm/arm/hdlcd_dr= v.c index aa06f9838015..32be9e370049 100644 --- a/drivers/gpu/drm/arm/hdlcd_drv.c +++ b/drivers/gpu/drm/arm/hdlcd_drv.c @@ -372,6 +372,11 @@ static void hdlcd_remove(struct platform_device *pdev) component_master_del(&pdev->dev, &hdlcd_master_ops); } =20 +static void hdlcd_shutdown(struct platform_device *pdev) +{ + drm_atomic_helper_shutdown(platform_get_drvdata(pdev)); +} + static const struct of_device_id hdlcd_of_match[] =3D { { .compatible =3D "arm,hdlcd" }, {}, @@ -399,6 +404,7 @@ static SIMPLE_DEV_PM_OPS(hdlcd_pm_ops, hdlcd_pm_suspend= , hdlcd_pm_resume); static struct platform_driver hdlcd_platform_driver =3D { .probe =3D hdlcd_probe, .remove_new =3D hdlcd_remove, + .shutdown =3D hdlcd_shutdown, .driver =3D { .name =3D "hdlcd", .pm =3D &hdlcd_pm_ops, diff --git a/drivers/gpu/drm/arm/malidp_drv.c b/drivers/gpu/drm/arm/malidp_= drv.c index 62329d5dd992..6682131d2910 100644 --- a/drivers/gpu/drm/arm/malidp_drv.c +++ b/drivers/gpu/drm/arm/malidp_drv.c @@ -941,6 +941,11 @@ static void malidp_platform_remove(struct platform_dev= ice *pdev) component_master_del(&pdev->dev, &malidp_master_ops); } =20 +static void malidp_platform_shutdown(struct platform_device *pdev) +{ + drm_atomic_helper_shutdown(platform_get_drvdata(pdev)); +} + static int __maybe_unused malidp_pm_suspend(struct device *dev) { struct drm_device *drm =3D dev_get_drvdata(dev); @@ -982,6 +987,7 @@ static const struct dev_pm_ops malidp_pm_ops =3D { static struct platform_driver malidp_platform_driver =3D { .probe =3D malidp_platform_probe, .remove_new =3D malidp_platform_remove, + .shutdown =3D malidp_platform_shutdown, .driver =3D { .name =3D "mali-dp", .pm =3D &malidp_pm_ops, diff --git a/drivers/gpu/drm/ast/ast_drv.c b/drivers/gpu/drm/ast/ast_drv.c index e1224ef4ad83..cf5b754f044c 100644 --- a/drivers/gpu/drm/ast/ast_drv.c +++ b/drivers/gpu/drm/ast/ast_drv.c @@ -125,6 +125,11 @@ static void ast_pci_remove(struct pci_dev *pdev) drm_atomic_helper_shutdown(dev); } =20 +static void ast_pci_shutdown(struct pci_dev *pdev) +{ + drm_atomic_helper_shutdown(pci_get_drvdata(pdev)); +} + static int ast_drm_freeze(struct drm_device *dev) { int error; @@ -209,6 +214,7 @@ static struct pci_driver ast_pci_driver =3D { .id_table =3D ast_pciidlist, .probe =3D ast_pci_probe, .remove =3D ast_pci_remove, + .shutdown =3D ast_pci_shutdown, .driver.pm =3D &ast_pm_ops, }; =20 diff --git a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.c b/drivers/gpu/drm= /atmel-hlcdc/atmel_hlcdc_dc.c index fa0f9a93d50d..84c54e8622d1 100644 --- a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.c +++ b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.c @@ -782,6 +782,11 @@ static void atmel_hlcdc_dc_drm_remove(struct platform_= device *pdev) drm_dev_put(ddev); } =20 +static void atmel_hlcdc_dc_drm_shutdown(struct platform_device *pdev) +{ + drm_atomic_helper_shutdown(platform_get_drvdata(pdev)); +} + static int atmel_hlcdc_dc_drm_suspend(struct device *dev) { struct drm_device *drm_dev =3D dev_get_drvdata(dev); @@ -825,6 +830,7 @@ static const struct of_device_id atmel_hlcdc_dc_of_matc= h[] =3D { static struct platform_driver atmel_hlcdc_dc_platform_driver =3D { .probe =3D atmel_hlcdc_dc_drm_probe, .remove_new =3D atmel_hlcdc_dc_drm_remove, + .shutdown =3D atmel_hlcdc_dc_drm_shutdown, .driver =3D { .name =3D "atmel-hlcdc-display-controller", .pm =3D pm_sleep_ptr(&atmel_hlcdc_dc_drm_pm_ops), diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c b/drivers/gpu/drm/fs= l-dcu/fsl_dcu_drm_drv.c index a395f93449f3..ab6c0c6cd0e2 100644 --- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c +++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c @@ -356,9 +356,17 @@ static void fsl_dcu_drm_remove(struct platform_device = *pdev) clk_unregister(fsl_dev->pix_clk); } =20 +static void fsl_dcu_drm_shutdown(struct platform_device *pdev) +{ + struct fsl_dcu_drm_device *fsl_dev =3D platform_get_drvdata(pdev); + + drm_atomic_helper_shutdown(fsl_dev->drm); +} + static struct platform_driver fsl_dcu_drm_platform_driver =3D { .probe =3D fsl_dcu_drm_probe, .remove_new =3D fsl_dcu_drm_remove, + .shutdown =3D fsl_dcu_drm_shutdown, .driver =3D { .name =3D "fsl-dcu", .pm =3D &fsl_dcu_drm_pm_ops, diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c b/drivers/gpu/= drm/hisilicon/hibmc/hibmc_drm_drv.c index 8a98fa276e8a..57c21ec452b7 100644 --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c @@ -357,6 +357,11 @@ static void hibmc_pci_remove(struct pci_dev *pdev) hibmc_unload(dev); } =20 +static void hibmc_pci_shutdown(struct pci_dev *pdev) +{ + drm_atomic_helper_shutdown(pci_get_drvdata(pdev)); +} + static const struct pci_device_id hibmc_pci_table[] =3D { { PCI_VDEVICE(HUAWEI, 0x1711) }, {0,} @@ -367,6 +372,7 @@ static struct pci_driver hibmc_pci_driver =3D { .id_table =3D hibmc_pci_table, .probe =3D hibmc_pci_probe, .remove =3D hibmc_pci_remove, + .shutdown =3D hibmc_pci_shutdown, .driver.pm =3D &hibmc_pm_ops, }; =20 diff --git a/drivers/gpu/drm/hyperv/hyperv_drm_drv.c b/drivers/gpu/drm/hype= rv/hyperv_drm_drv.c index 8026118c6e03..58b0b46a21e6 100644 --- a/drivers/gpu/drm/hyperv/hyperv_drm_drv.c +++ b/drivers/gpu/drm/hyperv/hyperv_drm_drv.c @@ -178,6 +178,11 @@ static void hyperv_vmbus_remove(struct hv_device *hdev) vmbus_free_mmio(hv->mem->start, hv->fb_size); } =20 +static void hyperv_vmbus_shutdown(struct hv_device *hdev) +{ + drm_atomic_helper_shutdown(hv_get_drvdata(hdev)); +} + static int hyperv_vmbus_suspend(struct hv_device *hdev) { struct drm_device *dev =3D hv_get_drvdata(hdev); @@ -220,6 +225,7 @@ static struct hv_driver hyperv_hv_driver =3D { .id_table =3D hyperv_vmbus_tbl, .probe =3D hyperv_vmbus_probe, .remove =3D hyperv_vmbus_remove, + .shutdown =3D hyperv_vmbus_shutdown, .suspend =3D hyperv_vmbus_suspend, .resume =3D hyperv_vmbus_resume, .driver =3D { diff --git a/drivers/gpu/drm/logicvc/logicvc_drm.c b/drivers/gpu/drm/logicv= c/logicvc_drm.c index 749debd3d6a5..01a37e28c080 100644 --- a/drivers/gpu/drm/logicvc/logicvc_drm.c +++ b/drivers/gpu/drm/logicvc/logicvc_drm.c @@ -482,6 +482,14 @@ static void logicvc_drm_remove(struct platform_device = *pdev) of_reserved_mem_device_release(dev); } =20 +static void logicvc_drm_shutdown(struct platform_device *pdev) +{ + struct logicvc_drm *logicvc =3D platform_get_drvdata(pdev); + struct drm_device *drm_dev =3D &logicvc->drm_dev; + + drm_atomic_helper_shutdown(drm_dev); +} + static const struct of_device_id logicvc_drm_of_table[] =3D { { .compatible =3D "xylon,logicvc-3.02.a-display" }, { .compatible =3D "xylon,logicvc-4.01.a-display" }, @@ -492,6 +500,7 @@ MODULE_DEVICE_TABLE(of, logicvc_drm_of_table); static struct platform_driver logicvc_drm_platform_driver =3D { .probe =3D logicvc_drm_probe, .remove_new =3D logicvc_drm_remove, + .shutdown =3D logicvc_drm_shutdown, .driver =3D { .name =3D "logicvc-drm", .of_match_table =3D logicvc_drm_of_table, diff --git a/drivers/gpu/drm/loongson/lsdc_drv.c b/drivers/gpu/drm/loongson= /lsdc_drv.c index 188ec82afcfb..89ccc0c43169 100644 --- a/drivers/gpu/drm/loongson/lsdc_drv.c +++ b/drivers/gpu/drm/loongson/lsdc_drv.c @@ -327,6 +327,11 @@ static void lsdc_pci_remove(struct pci_dev *pdev) drm_atomic_helper_shutdown(ddev); } =20 +static void lsdc_pci_shutdown(struct pci_dev *pdev) +{ + drm_atomic_helper_shutdown(pci_get_drvdata(pdev)); +} + static int lsdc_drm_freeze(struct drm_device *ddev) { struct lsdc_device *ldev =3D to_lsdc(ddev); @@ -447,6 +452,7 @@ struct pci_driver lsdc_pci_driver =3D { .id_table =3D lsdc_pciid_list, .probe =3D lsdc_pci_probe, .remove =3D lsdc_pci_remove, + .shutdown =3D lsdc_pci_shutdown, .driver.pm =3D &lsdc_pm_ops, }; =20 diff --git a/drivers/gpu/drm/mcde/mcde_drv.c b/drivers/gpu/drm/mcde/mcde_dr= v.c index a2572fb311f0..10c06440c7e7 100644 --- a/drivers/gpu/drm/mcde/mcde_drv.c +++ b/drivers/gpu/drm/mcde/mcde_drv.c @@ -459,6 +459,14 @@ static void mcde_remove(struct platform_device *pdev) regulator_disable(mcde->epod); } =20 +static void mcde_shutdown(struct platform_device *pdev) +{ + struct drm_device *drm =3D platform_get_drvdata(pdev); + + if (drm->registered) + drm_atomic_helper_shutdown(drm); +} + static const struct of_device_id mcde_of_match[] =3D { { .compatible =3D "ste,mcde", @@ -473,6 +481,7 @@ static struct platform_driver mcde_driver =3D { }, .probe =3D mcde_probe, .remove_new =3D mcde_remove, + .shutdown =3D mcde_shutdown, }; =20 static struct platform_driver *const component_drivers[] =3D { diff --git a/drivers/gpu/drm/omapdrm/omap_drv.c b/drivers/gpu/drm/omapdrm/o= map_drv.c index afeeb7737552..b2835b3ea6f5 100644 --- a/drivers/gpu/drm/omapdrm/omap_drv.c +++ b/drivers/gpu/drm/omapdrm/omap_drv.c @@ -817,6 +817,13 @@ static void pdev_remove(struct platform_device *pdev) kfree(priv); } =20 +static void pdev_shutdown(struct platform_device *pdev) +{ + struct omap_drm_private *priv =3D platform_get_drvdata(pdev); + + drm_atomic_helper_shutdown(priv->ddev); +} + #ifdef CONFIG_PM_SLEEP static int omap_drm_suspend(struct device *dev) { @@ -846,6 +853,7 @@ static struct platform_driver pdev =3D { }, .probe =3D pdev_probe, .remove_new =3D pdev_remove, + .shutdown =3D pdev_shutdown, }; =20 static struct platform_driver * const drivers[] =3D { diff --git a/drivers/gpu/drm/qxl/qxl_drv.c b/drivers/gpu/drm/qxl/qxl_drv.c index b30ede1cf62d..a4144c62ca93 100644 --- a/drivers/gpu/drm/qxl/qxl_drv.c +++ b/drivers/gpu/drm/qxl/qxl_drv.c @@ -163,6 +163,12 @@ qxl_pci_remove(struct pci_dev *pdev) vga_put(pdev, VGA_RSRC_LEGACY_IO); } =20 +static void +qxl_pci_shutdown(struct pci_dev *pdev) +{ + drm_atomic_helper_shutdown(pci_get_drvdata(pdev)); +} + DEFINE_DRM_GEM_FOPS(qxl_fops); =20 static int qxl_drm_freeze(struct drm_device *dev) @@ -269,6 +275,7 @@ static struct pci_driver qxl_pci_driver =3D { .id_table =3D pciidlist, .probe =3D qxl_pci_probe, .remove =3D qxl_pci_remove, + .shutdown =3D qxl_pci_shutdown, .driver.pm =3D &qxl_pm_ops, }; =20 diff --git a/drivers/gpu/drm/sti/sti_drv.c b/drivers/gpu/drm/sti/sti_drv.c index 2390c1bb6596..4bab93c4fefd 100644 --- a/drivers/gpu/drm/sti/sti_drv.c +++ b/drivers/gpu/drm/sti/sti_drv.c @@ -174,6 +174,7 @@ static void sti_cleanup(struct drm_device *ddev) drm_atomic_helper_shutdown(ddev); drm_mode_config_cleanup(ddev); component_unbind_all(ddev->dev, ddev); + dev_set_drvdata(ddev->dev, NULL); kfree(private); ddev->dev_private =3D NULL; } @@ -253,6 +254,11 @@ static void sti_platform_remove(struct platform_device= *pdev) component_master_del(&pdev->dev, &sti_ops); } =20 +static void sti_platform_shutdown(struct platform_device *pdev) +{ + drm_atomic_helper_shutdown(platform_get_drvdata(pdev)); +} + static const struct of_device_id sti_dt_ids[] =3D { { .compatible =3D "st,sti-display-subsystem", }, { /* end node */ }, @@ -262,6 +268,7 @@ MODULE_DEVICE_TABLE(of, sti_dt_ids); static struct platform_driver sti_platform_driver =3D { .probe =3D sti_platform_probe, .remove_new =3D sti_platform_remove, + .shutdown =3D sti_platform_shutdown, .driver =3D { .name =3D DRIVER_NAME, .of_match_table =3D sti_dt_ids, diff --git a/drivers/gpu/drm/sun4i/sun4i_drv.c b/drivers/gpu/drm/sun4i/sun4= i_drv.c index 6a8dfc022d3c..35d7a7ffd208 100644 --- a/drivers/gpu/drm/sun4i/sun4i_drv.c +++ b/drivers/gpu/drm/sun4i/sun4i_drv.c @@ -413,6 +413,11 @@ static void sun4i_drv_remove(struct platform_device *p= dev) component_master_del(&pdev->dev, &sun4i_drv_master_ops); } =20 +static void sun4i_drv_shutdown(struct platform_device *pdev) +{ + drm_atomic_helper_shutdown(platform_get_drvdata(pdev)); +} + static const struct of_device_id sun4i_drv_of_table[] =3D { { .compatible =3D "allwinner,sun4i-a10-display-engine" }, { .compatible =3D "allwinner,sun5i-a10s-display-engine" }, @@ -437,6 +442,7 @@ MODULE_DEVICE_TABLE(of, sun4i_drv_of_table); static struct platform_driver sun4i_drv_platform_driver =3D { .probe =3D sun4i_drv_probe, .remove_new =3D sun4i_drv_remove, + .shutdown =3D sun4i_drv_shutdown, .driver =3D { .name =3D "sun4i-drm", .of_match_table =3D sun4i_drv_of_table, diff --git a/drivers/gpu/drm/tiny/bochs.c b/drivers/gpu/drm/tiny/bochs.c index d254679a136e..c23c9f0cf49c 100644 --- a/drivers/gpu/drm/tiny/bochs.c +++ b/drivers/gpu/drm/tiny/bochs.c @@ -690,6 +690,11 @@ static void bochs_pci_remove(struct pci_dev *pdev) drm_dev_put(dev); } =20 +static void bochs_pci_shutdown(struct pci_dev *pdev) +{ + drm_atomic_helper_shutdown(pci_get_drvdata(pdev)); +} + static const struct pci_device_id bochs_pci_tbl[] =3D { { .vendor =3D 0x1234, @@ -720,6 +725,7 @@ static struct pci_driver bochs_pci_driver =3D { .id_table =3D bochs_pci_tbl, .probe =3D bochs_pci_probe, .remove =3D bochs_pci_remove, + .shutdown =3D bochs_pci_shutdown, .driver.pm =3D &bochs_pm_ops, }; =20 diff --git a/drivers/gpu/drm/tiny/cirrus.c b/drivers/gpu/drm/tiny/cirrus.c index 594bc472862f..c5c34cd2edc1 100644 --- a/drivers/gpu/drm/tiny/cirrus.c +++ b/drivers/gpu/drm/tiny/cirrus.c @@ -727,6 +727,11 @@ static void cirrus_pci_remove(struct pci_dev *pdev) drm_atomic_helper_shutdown(dev); } =20 +static void cirrus_pci_shutdown(struct pci_dev *pdev) +{ + drm_atomic_helper_shutdown(pci_get_drvdata(pdev)); +} + static const struct pci_device_id pciidlist[] =3D { { .vendor =3D PCI_VENDOR_ID_CIRRUS, @@ -748,6 +753,7 @@ static struct pci_driver cirrus_pci_driver =3D { .id_table =3D pciidlist, .probe =3D cirrus_pci_probe, .remove =3D cirrus_pci_remove, + .shutdown =3D cirrus_pci_shutdown, }; =20 drm_module_pci_driver(cirrus_pci_driver) --=20 2.42.0.283.g2d96d420d3-goog From nobody Thu Dec 18 00:22:09 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E63D1CA0FF8 for ; Fri, 1 Sep 2023 23:41:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351257AbjIAXlo (ORCPT ); Fri, 1 Sep 2023 19:41:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351234AbjIAXld (ORCPT ); Fri, 1 Sep 2023 19:41:33 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 950201999 for ; Fri, 1 Sep 2023 16:40:57 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-565dc391be3so332391a12.0 for ; Fri, 01 Sep 2023 16:40:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1693611652; x=1694216452; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LKWxQuC7a5C4d2AKwn1t60gJwzJJHgeo8QDTwz52tgk=; b=iO3SB7IvqqpdDluCitgSVpskGa1+03QVS0GvB/y89nUV7LwkDDjnE8/kXMJXiB8Yku 0cuyiOBFCVOnXJqdxVfuyNlD/7pA0a10XPOFcdrU0MLZfIZrXJfiC4K7ej+GtYvL5B55 e+2oyG+2OsV9cDBQyV+HvGIrW5bi8k/6WW5Hc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693611652; x=1694216452; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LKWxQuC7a5C4d2AKwn1t60gJwzJJHgeo8QDTwz52tgk=; b=KD84Dr5Ss4ynV94zxs0/CGWo4HmbSJCz+VeDb69BC8GfxJu/6jmLIEVZxyfVSFXAbv cU9o9APoTsxQLi6rWKi7YhmFDlGBfnP14IYCSI9Mge+YgSEzM2EDmTXHGXbodAVaPr+Z ZoSCV9BUy+1DcU7xPR+dKijS9+3ydyKu3Tzl+AoKDy0YvqTxNGAG/4Wyji5tcmZluUac HUhTEq6lS4lQuOHdIVL0ssUf4qivRLD79aS6QPurUae7+ilcVTaJUzlC7xlJGAF/RLXf iI8aNoPWsEqJb47HYvsRk5fHGjhngsinqqNkd4e1oWGD7Lp1+kmZ+2GQvoKnpqBz49f2 52HQ== X-Gm-Message-State: AOJu0YyqylG1PNrCmmv/oLNSHADvmLnkRMgDbVpewy18HZFXkkPk0H8u 5RYBY/XYBXSskOuBwb6kPunQGY5A+gD2nxgfJdv89HVx X-Google-Smtp-Source: AGHT+IF7NMfrOZ6DTNlV36hEFwRQk2U4n0bYWcDnUFLW/Uc5W3neZ+LQyo3ZfA6voNcZiUuygY4RqA== X-Received: by 2002:a17:90a:f487:b0:268:5aaf:fbe with SMTP id bx7-20020a17090af48700b002685aaf0fbemr5397171pjb.10.1693611651768; Fri, 01 Sep 2023 16:40:51 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:8d94:1fc5:803c:41cc]) by smtp.gmail.com with ESMTPSA id 5-20020a17090a1a4500b0026b4ca7f62csm3773488pjl.39.2023.09.01.16.40.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 16:40:51 -0700 (PDT) From: Douglas Anderson To: dri-devel@lists.freedesktop.org, Maxime Ripard Cc: Douglas Anderson , airlied@gmail.com, daniel@ffwll.ch, emma@anholt.net, linux-kernel@vger.kernel.org Subject: [RFT PATCH 3/6] drm/vc4: Call drm_atomic_helper_shutdown() at shutdown time Date: Fri, 1 Sep 2023 16:39:54 -0700 Message-ID: <20230901163944.RFT.3.I10dbe099fb1059d304ba847d19fc45054f7ffe9f@changeid> X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog In-Reply-To: <20230901234015.566018-1-dianders@chromium.org> References: <20230901234015.566018-1-dianders@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Based on grepping through the source code these drivers appear to be missing a call to drm_atomic_helper_shutdown() at system shutdown 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 comes straight out of the kernel doc "driver instance overview" in drm_drv.c. Suggested-by: Maxime Ripard Signed-off-by: Douglas Anderson Acked-by: Maxime Ripard --- This commit is only compile-time tested. Though this patch could be squashed into the patch ("drm: Call drm_atomic_helper_shutdown() at shutdown time for misc drivers"), I kept it separate to call attention to this driver. While writing this patch, I noticed that the bind() function is using "devm" and thus assumes it doesn't need to do much explicit error handling. That's actually a bug. As per kernel docs [1] "the lifetime of the aggregate driver does not align with any of the underlying struct device instances. Therefore devm cannot be used and all resources acquired or allocated in this callback must be explicitly released in the unbind callback". Fixing that is outside the scope of this commit. [1] https://docs.kernel.org/driver-api/component.html drivers/gpu/drm/vc4/vc4_drv.c | 36 ++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/vc4/vc4_drv.c b/drivers/gpu/drm/vc4/vc4_drv.c index 1b3531374967..c133e96b8aca 100644 --- a/drivers/gpu/drm/vc4/vc4_drv.c +++ b/drivers/gpu/drm/vc4/vc4_drv.c @@ -324,21 +324,21 @@ static int vc4_drm_bind(struct device *dev) if (!is_vc5) { ret =3D drmm_mutex_init(drm, &vc4->bin_bo_lock); if (ret) - return ret; + goto err; =20 ret =3D vc4_bo_cache_init(drm); if (ret) - return ret; + goto err; } =20 ret =3D drmm_mode_config_init(drm); if (ret) - return ret; + goto err; =20 if (!is_vc5) { ret =3D vc4_gem_init(drm); if (ret) - return ret; + goto err; } =20 node =3D of_find_compatible_node(NULL, NULL, "raspberrypi,bcm2835-firmwar= e"); @@ -346,13 +346,15 @@ static int vc4_drm_bind(struct device *dev) firmware =3D rpi_firmware_get(node); of_node_put(node); =20 - if (!firmware) - return -EPROBE_DEFER; + if (!firmware) { + ret =3D -EPROBE_DEFER; + goto err; + } } =20 ret =3D drm_aperture_remove_framebuffers(driver); if (ret) - return ret; + goto err; =20 if (firmware) { ret =3D rpi_firmware_property(firmware, @@ -366,32 +368,33 @@ static int vc4_drm_bind(struct device *dev) =20 ret =3D component_bind_all(dev, drm); if (ret) - return ret; + goto err; =20 ret =3D devm_add_action_or_reset(dev, vc4_component_unbind_all, vc4); if (ret) - return ret; + goto err; =20 ret =3D vc4_plane_create_additional_planes(drm); if (ret) - goto unbind_all; + goto err; =20 ret =3D vc4_kms_load(drm); if (ret < 0) - goto unbind_all; + goto err; =20 drm_for_each_crtc(crtc, drm) vc4_crtc_disable_at_boot(crtc); =20 ret =3D drm_dev_register(drm, 0); if (ret < 0) - goto unbind_all; + goto err; =20 drm_fbdev_dma_setup(drm, 16); =20 return 0; =20 -unbind_all: +err: + platform_set_drvdata(pdev, NULL); return ret; } =20 @@ -401,6 +404,7 @@ static void vc4_drm_unbind(struct device *dev) =20 drm_dev_unplug(drm); drm_atomic_helper_shutdown(drm); + dev_set_drvdata(dev, NULL); } =20 static const struct component_master_ops vc4_drm_ops =3D { @@ -444,6 +448,11 @@ static void vc4_platform_drm_remove(struct platform_de= vice *pdev) component_master_del(&pdev->dev, &vc4_drm_ops); } =20 +static void vc4_platform_drm_shutdown(struct platform_device *pdev) +{ + drm_atomic_helper_shutdown(platform_get_drvdata(pdev)); +} + static const struct of_device_id vc4_of_match[] =3D { { .compatible =3D "brcm,bcm2711-vc5", }, { .compatible =3D "brcm,bcm2835-vc4", }, @@ -455,6 +464,7 @@ MODULE_DEVICE_TABLE(of, vc4_of_match); static struct platform_driver vc4_platform_driver =3D { .probe =3D vc4_platform_drm_probe, .remove_new =3D vc4_platform_drm_remove, + .shutdown =3D vc4_platform_drm_shutdown, .driver =3D { .name =3D "vc4-drm", .of_match_table =3D vc4_of_match, --=20 2.42.0.283.g2d96d420d3-goog From nobody Thu Dec 18 00:22:09 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60CC1CA0FF6 for ; Fri, 1 Sep 2023 23:41:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351259AbjIAXlq (ORCPT ); Fri, 1 Sep 2023 19:41:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351239AbjIAXlh (ORCPT ); Fri, 1 Sep 2023 19:41:37 -0400 Received: from mail-oa1-x36.google.com (mail-oa1-x36.google.com [IPv6:2001:4860:4864:20::36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F719199F for ; Fri, 1 Sep 2023 16:40:58 -0700 (PDT) Received: by mail-oa1-x36.google.com with SMTP id 586e51a60fabf-1ccc0d2e697so1653981fac.0 for ; Fri, 01 Sep 2023 16:40:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1693611654; x=1694216454; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MjN3sfEO+JM922O5awQYKULh62YjERT8p0jq8P8wGb0=; b=Wbd8V+otA+BMM3/yRsAi1bAvy1aj6qmpCPDRimTTOaqJZMu6qfq6O8XfYywEQfyn5w vgC+KVlropb7jlG91mr2b9zmmGVYhYuir6oHJqhxfnXzh95mI6LNrkhzDzU6z2n2auce sL0qG0LZnyvHVb+9+7OtomMrCr3yziYJWkCnc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693611654; x=1694216454; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MjN3sfEO+JM922O5awQYKULh62YjERT8p0jq8P8wGb0=; b=RIr7gq7/M1YdrXK1VQQzNhK4VV6p57x6H8W5XtBEkXVONTbuBSavE7DstFFXOg565o J/tl0DsSj8tZeFKXN2i8SFtzQSB9Ep1HLoArgqY6Y0RJxBCCs+ur3JD5DUwiZmbNqFXa phGkgz4EGK+owprcsuolM1zNtSVfG2jgpL5WXMo9vguSEsHWPTVad93YGzH5zc4NbDki ZVIIPXtVa/8hxXMOQ5/gZuiRbZ+4hAea+yzQPkEBEHdUf0ht9MOi1+2bA4t3osvWWANy tdm0xyNz+Sis6Qfm7PKzDt285GoWdQydhJgAZfJqDBoGvEzMjNPi2Nqtis0q9omwxAGu Vn0g== X-Gm-Message-State: AOJu0YzJOrfaaNHpNYzdZ/HyPkhEmKKmypxsKz3HA+81MaJNZQq4/wBp L2smoj+eO5bzFZM9drG+w71uSQ== X-Google-Smtp-Source: AGHT+IHtZYYm3kAb6nsZHXag2Hv09GGqSDmAQq+JJIcuHqOc1L2+l/u8XFzy1Ix3zXRbzhU1ARWddg== X-Received: by 2002:a05:6870:4290:b0:1bc:3f6:579b with SMTP id y16-20020a056870429000b001bc03f6579bmr4478955oah.22.1693611654700; Fri, 01 Sep 2023 16:40:54 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:8d94:1fc5:803c:41cc]) by smtp.gmail.com with ESMTPSA id 5-20020a17090a1a4500b0026b4ca7f62csm3773488pjl.39.2023.09.01.16.40.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 16:40:53 -0700 (PDT) From: Douglas Anderson To: dri-devel@lists.freedesktop.org, Maxime Ripard Cc: Douglas Anderson , airlied@gmail.com, daniel@ffwll.ch, javierm@redhat.com, linux-kernel@vger.kernel.org Subject: [RFT PATCH 4/6] drm/ssd130x: Call drm_atomic_helper_shutdown() at remove time Date: Fri, 1 Sep 2023 16:39:55 -0700 Message-ID: <20230901163944.RFT.4.I4752a39ad9f8fd08b32c2b78a8a3e40491bfb5eb@changeid> X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog In-Reply-To: <20230901234015.566018-1-dianders@chromium.org> References: <20230901234015.566018-1-dianders@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Based on grepping through the source code, this driver appears to be missing a call to drm_atomic_helper_shutdown() at remove time. Let's add it. The fact that we should call drm_atomic_helper_shutdown() in the case of OS driver remove comes straight out of the kernel doc "driver instance overview" in drm_drv.c. Suggested-by: Maxime Ripard Signed-off-by: Douglas Anderson Acked-by: Maxime Ripard --- This commit is only compile-time tested. NOTE: I'm not 100% sure this is the correct thing to do, but I _think_ so. Please shout if you know better. drivers/gpu/drm/solomon/ssd130x.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/gpu/drm/solomon/ssd130x.c b/drivers/gpu/drm/solomon/ss= d130x.c index 5a80b228d18c..dc06fd82fd30 100644 --- a/drivers/gpu/drm/solomon/ssd130x.c +++ b/drivers/gpu/drm/solomon/ssd130x.c @@ -1131,6 +1131,7 @@ EXPORT_SYMBOL_GPL(ssd130x_probe); void ssd130x_remove(struct ssd130x_device *ssd130x) { drm_dev_unplug(&ssd130x->drm); + drm_atomic_helper_shutdown(&ssd130x->drm); } EXPORT_SYMBOL_GPL(ssd130x_remove); =20 --=20 2.42.0.283.g2d96d420d3-goog From nobody Thu Dec 18 00:22:09 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D811CA0FF6 for ; Fri, 1 Sep 2023 23:41:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351252AbjIAXlu (ORCPT ); Fri, 1 Sep 2023 19:41:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351247AbjIAXlk (ORCPT ); Fri, 1 Sep 2023 19:41:40 -0400 Received: from mail-ot1-x334.google.com (mail-ot1-x334.google.com [IPv6:2607:f8b0:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C755F19A2 for ; Fri, 1 Sep 2023 16:41:01 -0700 (PDT) Received: by mail-ot1-x334.google.com with SMTP id 46e09a7af769-6bd0425ad4fso1938226a34.2 for ; Fri, 01 Sep 2023 16:41:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1693611658; x=1694216458; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=t1eWAYznHaK0aWczuNWbSMuURPigxfjsQS0xy+Sev48=; b=WoMw4iXX9nxGE1tVZU9F2Ge6FK8Ku+RuiBQ+7DbcD6HIifU1uWt3nCVMCjZgaH8lTK fOLwpc6IzGKWMZMGJcqsG3C2QT7v7XkIEnUg+hczAtHSXJpxzxbvcYVGScV7+g09WeDc 0R1y8FVwQsAEifEcxLjdQLmc9gfbFKP4C42X0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693611658; x=1694216458; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=t1eWAYznHaK0aWczuNWbSMuURPigxfjsQS0xy+Sev48=; b=jKCbeBclWd3MDWGPiu7jR6xeTfqaCFJoSyq0Uge1Ph3lIoWic0sbtmhToq4RR3lIsU ONEHvtZZKPdFaSjaZUBqayqGGmRjFW6hvD89JaAVuOVEE6jwriwI0jyFYBJwjMwqULrA CqyBoeyEg7SVC5RcRezXdo9Ru3C8qR9mKmPNOZZ+OelxD3iYoXfHl/k+YAp2CA58K/IE LiH7oCo7fIRY8aZeSSiwhBul0VobIEIGQVOa1w7dOYvnQZTYRr4H1GJNakGTwuVk28td VwZOugB7OiUs0OUigBq+qX3bqL2rUcJguaeCRJYjf9G8l0SQsLvyyaZjFj/xSH5Nh0vx 1yEg== X-Gm-Message-State: AOJu0Yzbrt/xs3XFTOB2vkfUgbI6NmOF3lvW/mutvhdw4Gs+I4lP1WpI atkP7+RkeawXV4f4yDpPnbGbIA== X-Google-Smtp-Source: AGHT+IHWh0EZjB4sRwdO+sv2azBowUIC3rylFr9w/wT3XrqIi1O/kU8t1TW+RVuuA1jXai1FluM7wA== X-Received: by 2002:a05:6870:e2d4:b0:1d0:f067:bf23 with SMTP id w20-20020a056870e2d400b001d0f067bf23mr4176763oad.25.1693611658361; Fri, 01 Sep 2023 16:40:58 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:8d94:1fc5:803c:41cc]) by smtp.gmail.com with ESMTPSA id 5-20020a17090a1a4500b0026b4ca7f62csm3773488pjl.39.2023.09.01.16.40.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 16:40:56 -0700 (PDT) From: Douglas Anderson To: dri-devel@lists.freedesktop.org, Maxime Ripard Cc: Douglas Anderson , airlied@gmail.com, airlied@redhat.com, alexandre.torgue@foss.st.com, andrew@aj.id.au, daniel@ffwll.ch, emma@anholt.net, hdegoede@redhat.com, jfalempe@redhat.com, joel@jms.id.au, jyri.sarha@iki.fi, linus.walleij@linaro.org, linux-arm-kernel@lists.infradead.org, linux-aspeed@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, mcoquelin.stm32@gmail.com, philippe.cornu@foss.st.com, raphael.gallais-pou@foss.st.com, tomi.valkeinen@ideasonboard.com, tzimmermann@suse.de, yannick.fertre@foss.st.com Subject: [RFT PATCH 5/6] drm: Call drm_atomic_helper_shutdown() at shutdown/remove time for misc drivers Date: Fri, 1 Sep 2023 16:39:56 -0700 Message-ID: <20230901163944.RFT.5.I771eb4bd03d8772b19e7dcfaef3e2c167bce5846@changeid> X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog In-Reply-To: <20230901234015.566018-1-dianders@chromium.org> References: <20230901234015.566018-1-dianders@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Douglas Anderson Acked-by: Maxime Ripard Reviewed-by: Tomi Valkeinen Tested-by: Tomi Valkeinen # tilcdc --- drivers/gpu/drm/aspeed/aspeed_gfx_drv.c | 7 +++++++ drivers/gpu/drm/mgag200/mgag200_drv.c | 8 ++++++++ drivers/gpu/drm/pl111/pl111_drv.c | 7 +++++++ drivers/gpu/drm/stm/drv.c | 7 +++++++ drivers/gpu/drm/tilcdc/tilcdc_drv.c | 11 ++++++++++- drivers/gpu/drm/tve200/tve200_drv.c | 7 +++++++ drivers/gpu/drm/vboxvideo/vbox_drv.c | 10 ++++++++++ 7 files changed, 56 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/aspeed/aspeed_gfx_drv.c b/drivers/gpu/drm/aspe= ed/aspeed_gfx_drv.c index d207b03f8357..78122b35a0cb 100644 --- a/drivers/gpu/drm/aspeed/aspeed_gfx_drv.c +++ b/drivers/gpu/drm/aspeed/aspeed_gfx_drv.c @@ -358,11 +358,18 @@ static void aspeed_gfx_remove(struct platform_device = *pdev) sysfs_remove_group(&pdev->dev.kobj, &aspeed_sysfs_attr_group); drm_dev_unregister(drm); aspeed_gfx_unload(drm); + drm_atomic_helper_shutdown(drm); +} + +static void aspeed_gfx_shutdown(struct platform_device *pdev) +{ + drm_atomic_helper_shutdown(platform_get_drvdata(pdev)); } =20 static struct platform_driver aspeed_gfx_platform_driver =3D { .probe =3D aspeed_gfx_probe, .remove_new =3D aspeed_gfx_remove, + .shutdown =3D aspeed_gfx_shutdown, .driver =3D { .name =3D "aspeed_gfx", .of_match_table =3D aspeed_gfx_match, diff --git a/drivers/gpu/drm/mgag200/mgag200_drv.c b/drivers/gpu/drm/mgag20= 0/mgag200_drv.c index abddf37f0ea1..2fb18b782b05 100644 --- a/drivers/gpu/drm/mgag200/mgag200_drv.c +++ b/drivers/gpu/drm/mgag200/mgag200_drv.c @@ -10,6 +10,7 @@ #include =20 #include +#include #include #include #include @@ -278,6 +279,12 @@ static void mgag200_pci_remove(struct pci_dev *pdev) struct drm_device *dev =3D pci_get_drvdata(pdev); =20 drm_dev_unregister(dev); + drm_atomic_helper_shutdown(dev); +} + +static void mgag200_pci_shutdown(struct pci_dev *pdev) +{ + drm_atomic_helper_shutdown(pci_get_drvdata(pdev)); } =20 static struct pci_driver mgag200_pci_driver =3D { @@ -285,6 +292,7 @@ static struct pci_driver mgag200_pci_driver =3D { .id_table =3D mgag200_pciidlist, .probe =3D mgag200_pci_probe, .remove =3D mgag200_pci_remove, + .shutdown =3D mgag200_pci_shutdown, }; =20 drm_module_pci_driver_if_modeset(mgag200_pci_driver, mgag200_modeset); diff --git a/drivers/gpu/drm/pl111/pl111_drv.c b/drivers/gpu/drm/pl111/pl11= 1_drv.c index ba3b5b5f0cdf..02e6b74d5016 100644 --- a/drivers/gpu/drm/pl111/pl111_drv.c +++ b/drivers/gpu/drm/pl111/pl111_drv.c @@ -323,12 +323,18 @@ static void pl111_amba_remove(struct amba_device *amb= a_dev) struct pl111_drm_dev_private *priv =3D drm->dev_private; =20 drm_dev_unregister(drm); + drm_atomic_helper_shutdown(drm); if (priv->panel) drm_panel_bridge_remove(priv->bridge); drm_dev_put(drm); of_reserved_mem_device_release(dev); } =20 +static void pl111_amba_shutdown(struct amba_device *amba_dev) +{ + drm_atomic_helper_shutdown(amba_get_drvdata(amba_dev)); +} + /* * This early variant lacks the 565 and 444 pixel formats. */ @@ -431,6 +437,7 @@ static struct amba_driver pl111_amba_driver __maybe_unu= sed =3D { }, .probe =3D pl111_amba_probe, .remove =3D pl111_amba_remove, + .shutdown =3D pl111_amba_shutdown, .id_table =3D pl111_id_table, }; =20 diff --git a/drivers/gpu/drm/stm/drv.c b/drivers/gpu/drm/stm/drv.c index c68c831136c9..e8523abef27a 100644 --- a/drivers/gpu/drm/stm/drv.c +++ b/drivers/gpu/drm/stm/drv.c @@ -114,6 +114,7 @@ static void drv_unload(struct drm_device *ddev) DRM_DEBUG("%s\n", __func__); =20 drm_kms_helper_poll_fini(ddev); + drm_atomic_helper_shutdown(ddev); ltdc_unload(ddev); } =20 @@ -225,6 +226,11 @@ static void stm_drm_platform_remove(struct platform_de= vice *pdev) drm_dev_put(ddev); } =20 +static void stm_drm_platform_shutdown(struct platform_device *pdev) +{ + drm_atomic_helper_shutdown(platform_get_drvdata(pdev)); +} + static const struct of_device_id drv_dt_ids[] =3D { { .compatible =3D "st,stm32-ltdc"}, { /* end node */ }, @@ -234,6 +240,7 @@ MODULE_DEVICE_TABLE(of, drv_dt_ids); static struct platform_driver stm_drm_platform_driver =3D { .probe =3D stm_drm_platform_probe, .remove_new =3D stm_drm_platform_remove, + .shutdown =3D stm_drm_platform_shutdown, .driver =3D { .name =3D "stm32-display", .of_match_table =3D drv_dt_ids, diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.c b/drivers/gpu/drm/tilcdc/t= ilcdc_drv.c index fe56beea3e93..8ebd7134ee21 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_drv.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_drv.c @@ -175,6 +175,7 @@ static void tilcdc_fini(struct drm_device *dev) drm_dev_unregister(dev); =20 drm_kms_helper_poll_fini(dev); + drm_atomic_helper_shutdown(dev); tilcdc_irq_uninstall(dev); drm_mode_config_cleanup(dev); =20 @@ -389,6 +390,7 @@ static int tilcdc_init(const struct drm_driver *ddrv, s= truct device *dev) =20 init_failed: tilcdc_fini(ddev); + platform_set_drvdata(pdev, NULL); =20 return ret; } @@ -537,7 +539,8 @@ static void tilcdc_unbind(struct device *dev) if (!ddev->dev_private) return; =20 - tilcdc_fini(dev_get_drvdata(dev)); + tilcdc_fini(ddev); + dev_set_drvdata(dev, NULL); } =20 static const struct component_master_ops tilcdc_comp_ops =3D { @@ -582,6 +585,11 @@ static int tilcdc_pdev_remove(struct platform_device *= pdev) return 0; } =20 +static void tilcdc_pdev_shutdown(struct platform_device *pdev) +{ + drm_atomic_helper_shutdown(platform_get_drvdata(pdev)); +} + static const struct of_device_id tilcdc_of_match[] =3D { { .compatible =3D "ti,am33xx-tilcdc", }, { .compatible =3D "ti,da850-tilcdc", }, @@ -592,6 +600,7 @@ MODULE_DEVICE_TABLE(of, tilcdc_of_match); static struct platform_driver tilcdc_platform_driver =3D { .probe =3D tilcdc_pdev_probe, .remove =3D tilcdc_pdev_remove, + .shutdown =3D tilcdc_pdev_shutdown, .driver =3D { .name =3D "tilcdc", .pm =3D pm_sleep_ptr(&tilcdc_pm_ops), diff --git a/drivers/gpu/drm/tve200/tve200_drv.c b/drivers/gpu/drm/tve200/t= ve200_drv.c index 0bb56d063536..acce210e2554 100644 --- a/drivers/gpu/drm/tve200/tve200_drv.c +++ b/drivers/gpu/drm/tve200/tve200_drv.c @@ -242,6 +242,7 @@ static void tve200_remove(struct platform_device *pdev) struct tve200_drm_dev_private *priv =3D drm->dev_private; =20 drm_dev_unregister(drm); + drm_atomic_helper_shutdown(drm); if (priv->panel) drm_panel_bridge_remove(priv->bridge); drm_mode_config_cleanup(drm); @@ -249,6 +250,11 @@ static void tve200_remove(struct platform_device *pdev) drm_dev_put(drm); } =20 +static void tve200_shutdown(struct platform_device *pdev) +{ + drm_atomic_helper_shutdown(platform_get_drvdata(pdev)); +} + static const struct of_device_id tve200_of_match[] =3D { { .compatible =3D "faraday,tve200", @@ -263,6 +269,7 @@ static struct platform_driver tve200_driver =3D { }, .probe =3D tve200_probe, .remove_new =3D tve200_remove, + .shutdown =3D tve200_shutdown, }; drm_module_platform_driver(tve200_driver); =20 diff --git a/drivers/gpu/drm/vboxvideo/vbox_drv.c b/drivers/gpu/drm/vboxvid= eo/vbox_drv.c index 4fee15c97c34..047b95812334 100644 --- a/drivers/gpu/drm/vboxvideo/vbox_drv.c +++ b/drivers/gpu/drm/vboxvideo/vbox_drv.c @@ -12,6 +12,7 @@ #include =20 #include +#include #include #include #include @@ -97,11 +98,19 @@ static void vbox_pci_remove(struct pci_dev *pdev) struct vbox_private *vbox =3D pci_get_drvdata(pdev); =20 drm_dev_unregister(&vbox->ddev); + drm_atomic_helper_shutdown(&vbox->ddev); vbox_irq_fini(vbox); vbox_mode_fini(vbox); vbox_hw_fini(vbox); } =20 +static void vbox_pci_shutdown(struct pci_dev *pdev) +{ + struct vbox_private *vbox =3D pci_get_drvdata(pdev); + + drm_atomic_helper_shutdown(&vbox->ddev); +} + static int vbox_pm_suspend(struct device *dev) { struct vbox_private *vbox =3D dev_get_drvdata(dev); @@ -165,6 +174,7 @@ static struct pci_driver vbox_pci_driver =3D { .id_table =3D pciidlist, .probe =3D vbox_pci_probe, .remove =3D vbox_pci_remove, + .shutdown =3D vbox_pci_shutdown, .driver.pm =3D pm_sleep_ptr(&vbox_pm_ops), }; =20 --=20 2.42.0.283.g2d96d420d3-goog From nobody Thu Dec 18 00:22:09 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03EF8CA0FF9 for ; Fri, 1 Sep 2023 23:41:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239479AbjIAXlt (ORCPT ); Fri, 1 Sep 2023 19:41:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351237AbjIAXlk (ORCPT ); Fri, 1 Sep 2023 19:41:40 -0400 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 191751706 for ; Fri, 1 Sep 2023 16:41:02 -0700 (PDT) Received: by mail-pg1-x530.google.com with SMTP id 41be03b00d2f7-5657add1073so326189a12.0 for ; Fri, 01 Sep 2023 16:41:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1693611660; x=1694216460; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pT1iKlrITuZofU1kQPrtkxFP604YngjW6FFJAYPzuCU=; b=MajupvmWpK2Z2Cq+gnnWnDEerUV1DTNU+6pJA0u8/gTPIWRp7+0175rn6aVCGKGUYg Csrtc9CUA7AyhRzYJzjUunF8RY0mIHVtT3/7vnPawABu18Kn/YLetlM6auBxo/6mT9f/ 4rZgnwgm8Kf7B57gUaWzSH7XT7zeaUCbaKBkQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693611660; x=1694216460; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pT1iKlrITuZofU1kQPrtkxFP604YngjW6FFJAYPzuCU=; b=SDe+zPFWed7uR5dQdXcff34gsErW9GnG8cSsGdQWU0RbMaEwCa7kGOedf3pBmEvrtY xtvdhgSSiZCcta4eewTZL9ZPsAv/H6DLlZSUjWSFdkF2QGc9N12U5HM08LauA/8AX++l iPHeviPaejNHhaFHtRiGUw9OpwgwSD6c88bLvu51oMPpOTT5Ov0jfqJJ/t7tNPPYkJGK CjlZmcJBtlDg8xhqU2AETKZXVfdtR8mCv8HCtfxFKeH9lk6iDa/+VUNL/809pLeuw6BI yQZQhKxnRVsdW9AmZ6vqjgowyJIWqLJ3H5ExAPq0qBExLIq9ssQQKGGWwDkqvLLwA1bb sxNA== X-Gm-Message-State: AOJu0YzJFYUqk0zUheyKUmRTuEuO6aUL6dspw7qreUGETN+Pv8siVj1M y+j2wk55oRUIckrpq3MrHhxSnkqgiGqYwdVFqzvyLKta X-Google-Smtp-Source: AGHT+IGqVAUGomc3SlwvihPd+jy1s+2/sdtPRZxfYwC1170/gmtaQyqQmY66o6+Nz6XRTaKspuptHQ== X-Received: by 2002:a17:90b:23c8:b0:25c:18ad:6b82 with SMTP id md8-20020a17090b23c800b0025c18ad6b82mr5046871pjb.21.1693611660378; Fri, 01 Sep 2023 16:41:00 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:8d94:1fc5:803c:41cc]) by smtp.gmail.com with ESMTPSA id 5-20020a17090a1a4500b0026b4ca7f62csm3773488pjl.39.2023.09.01.16.40.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 16:40:59 -0700 (PDT) From: Douglas Anderson To: dri-devel@lists.freedesktop.org, Maxime Ripard Cc: Douglas Anderson , airlied@gmail.com, daniel@ffwll.ch, javierm@redhat.com, jstultz@google.com, kong.kongxinwei@hisilicon.com, linux-kernel@vger.kernel.org, robh@kernel.org, steven.price@arm.com, sumit.semwal@linaro.org, tiantao6@hisilicon.com, tzimmermann@suse.de, u.kleine-koenig@pengutronix.de, xinliang.liu@linaro.org, yongqin.liu@linaro.org Subject: [RFT PATCH 6/6] drm/hisilicon/kirin: Call drm_atomic_helper_shutdown() at shutdown/unbind time Date: Fri, 1 Sep 2023 16:39:57 -0700 Message-ID: <20230901163944.RFT.6.I21e0916bbd276033f7d31979c0da171458dedd4d@changeid> X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog In-Reply-To: <20230901234015.566018-1-dianders@chromium.org> References: <20230901234015.566018-1-dianders@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Based on grepping through the source code this driver appears to be missing a call to drm_atomic_helper_shutdown() at system shutdown time and at driver 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. I have attempted to put this in the right place at unbind time. In most other DRM drivers the call is made right after the call to drm_kms_helper_poll_fini(), so I've put it there. That means that this call will also be made in the case that we hit errors in bind, since kirin_drm_kms_cleanup() is called both in the bind error path and in unbind. I believe this is harmless even though it's not needed in the bind error path. For handling shutdown, we rely on the common technique of seeing if the drvdata is NULL to know whether we need to call drm_atomic_helper_shutdown(). This makes it important to make sure that the drvdata is NULL if bind failed or if unbind was called. We don't need the actual check for NULL and we'll rely on the patch ("drm/atomic-helper: drm_atomic_helper_shutdown(NULL) should be a noop"). Suggested-by: Maxime Ripard Signed-off-by: Douglas Anderson Acked-by: Maxime Ripard --- This commit is only compile-time tested. drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c b/drivers/gpu/= drm/hisilicon/kirin/kirin_drm_drv.c index e8c77bcc6dae..75292a2f4644 100644 --- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c +++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c @@ -206,6 +206,7 @@ static int kirin_drm_kms_init(struct drm_device *dev, static int kirin_drm_kms_cleanup(struct drm_device *dev) { drm_kms_helper_poll_fini(dev); + drm_atomic_helper_shutdown(dev); kirin_drm_private_cleanup(dev); drm_mode_config_cleanup(dev); =20 @@ -244,6 +245,7 @@ static int kirin_drm_bind(struct device *dev) kirin_drm_kms_cleanup(drm_dev); err_drm_dev_put: drm_dev_put(drm_dev); + dev_set_drvdata(dev, NULL); =20 return ret; } @@ -255,6 +257,7 @@ static void kirin_drm_unbind(struct device *dev) drm_dev_unregister(drm_dev); kirin_drm_kms_cleanup(drm_dev); drm_dev_put(drm_dev); + dev_set_drvdata(dev, NULL); } =20 static const struct component_master_ops kirin_drm_ops =3D { @@ -284,6 +287,11 @@ static void kirin_drm_platform_remove(struct platform_= device *pdev) component_master_del(&pdev->dev, &kirin_drm_ops); } =20 +static void kirin_drm_platform_shutdown(struct platform_device *pdev) +{ + drm_atomic_helper_shutdown(platform_get_drvdata(pdev)); +} + static const struct of_device_id kirin_drm_dt_ids[] =3D { { .compatible =3D "hisilicon,hi6220-ade", .data =3D &ade_driver_data, @@ -295,6 +303,7 @@ MODULE_DEVICE_TABLE(of, kirin_drm_dt_ids); static struct platform_driver kirin_drm_platform_driver =3D { .probe =3D kirin_drm_platform_probe, .remove_new =3D kirin_drm_platform_remove, + .shutdown =3D kirin_drm_platform_shutdown, .driver =3D { .name =3D "kirin-drm", .of_match_table =3D kirin_drm_dt_ids, --=20 2.42.0.283.g2d96d420d3-goog