From patchwork Tue Nov 29 19:17:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Cercueil X-Patchwork-Id: 13059031 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 24425C433FE for ; Tue, 29 Nov 2022 19:18:08 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9486310E1DD; Tue, 29 Nov 2022 19:18:06 +0000 (UTC) Received: from aposti.net (aposti.net [89.234.176.197]) by gabe.freedesktop.org (Postfix) with ESMTPS id BFD0B10E1DD for ; Tue, 29 Nov 2022 19:18:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crapouillou.net; s=mail; t=1669749469; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7gAnxaoVqEWoM5vi/BaBgxdiGzKVxjjTsGqnEeIglYs=; b=Lb3U8DMaMv86BzMM+cDyhB6ZOmgECsaSU4wa2llVOeq8427YF/e+LM6bLEc1eB2cFI1SR4 cHxQpiRDgnycev9zdcpVoeoXS8zV88XDwRPGji+L3Mg5C3mOXy4zBHGWVfl5/M/4DS7Aw9 BVcFIFgpdnmmm+0yq9xtiNKl35K8Sfs= From: Paul Cercueil To: David Airlie , Daniel Vetter Subject: [PATCH v2 01/26] drm: modeset-helper: Add DEFINE_DRM_MODE_CONFIG_HELPER_PM_OPS macro Date: Tue, 29 Nov 2022 19:17:08 +0000 Message-Id: <20221129191733.137897-2-paul@crapouillou.net> In-Reply-To: <20221129191733.137897-1-paul@crapouillou.net> References: <20221129191733.137897-1-paul@crapouillou.net> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paul Cercueil , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This macro can be used with simple drivers, which have their "struct drm_device" registered as their "struct device"'s drvdata, and only call drm_mode_config_pm_{suspend,resume}. The macro will define a "struct dev_pm_ops" with the name passed as argument. This object cannot be referenced directly; instead, the pm_sleep_ptr() macro should be used, like this: DEFINE_DRM_MODE_CONFIG_HELPER_PM_OPS(foo_pm_ops); static struct platform_driver foo_driver = { .driver.pm = pm_sleep_ptr(&foo_pm_ops), ... }; This ensures that the generated code will be dropped by the compiler in the case where CONFIG_PM has been disabled in the config. v2: instead of exporting a dev_pm_ops, introduce the DEFINE_DRM_MODE_CONFIG_HELPER_PM_OPS() macro. Signed-off-by: Paul Cercueil --- include/drm/drm_modeset_helper.h | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/include/drm/drm_modeset_helper.h b/include/drm/drm_modeset_helper.h index 995fd981cab0..2ecf0e5c2e16 100644 --- a/include/drm/drm_modeset_helper.h +++ b/include/drm/drm_modeset_helper.h @@ -41,4 +41,42 @@ int drm_crtc_init(struct drm_device *dev, struct drm_crtc *crtc, int drm_mode_config_helper_suspend(struct drm_device *dev); int drm_mode_config_helper_resume(struct drm_device *dev); +/** + * DEFINE_DRM_MODE_CONFIG_HELPER_PM_OPS - Generate simple PM callbacks + * + * This macro can be used by simple drivers that would otherwise only call + * drm_mode_config_helper_suspend / drm_mode_config_helper_resume in their PM + * callbacks. It will generate a struct dev_pm_ops of the given name, that can + * then be referenced in the device_driver structure. + * + * Note that it is only valid if the driver's drm_device has been registered as + * the struct device's drvdata. + * + * Additionally, the generated dev_pm_ops structure should not be referenced + * directly; instead, the pm_sleep_ptr() macro should be used, like this: + * + * DEFINE_DRM_MODE_CONFIG_HELPER_PM_OPS(foo_pm_ops); + * + * static struct platform_driver foo_driver = { + * .driver.pm = pm_sleep_ptr(&foo_pm_ops), + * ... + * }; + * + * This ensures that the generated code will be dropped by the compiler in the + * case where CONFIG_PM has been disabled in the config. ++ */ + +#define DEFINE_DRM_MODE_CONFIG_HELPER_PM_OPS(_name) \ + static int __##_name##_drm_mode_config_pm_suspend(struct device *dev) \ + { \ + return drm_mode_config_helper_suspend(dev_get_drvdata(dev)); \ + } \ + static int __##_name##_drm_mode_config_pm_resume(struct device *dev) \ + { \ + return drm_mode_config_helper_resume(dev_get_drvdata(dev)); \ + } \ + static DEFINE_SIMPLE_DEV_PM_OPS(_name, \ + __##_name##_drm_mode_config_pm_suspend, \ + __##_name##_drm_mode_config_pm_resume) + #endif From patchwork Tue Nov 29 19:17:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Cercueil X-Patchwork-Id: 13059032 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E1684C433FE for ; Tue, 29 Nov 2022 19:18:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A05E710E220; Tue, 29 Nov 2022 19:18:15 +0000 (UTC) Received: from aposti.net (aposti.net [89.234.176.197]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6A01B10E211 for ; Tue, 29 Nov 2022 19:18:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crapouillou.net; s=mail; t=1669749470; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dIthVPfRqMzRLHonB9Z3+9yNKc8FhZTyJnewRLDcrPs=; b=v6cI95cKHZF7JRsW6yCZyviPrYgL1hUQg6mGKb3+uSwSQT68AJ3ZblHdt2FXdYjVdF2lxU YhUSzbi1grVPHthQtkb3JWgqIRU8fEVCYtMlY3+3ITbHhcGY6uZfFk5LsBbEBlxgN4TgmX 0FTfc9J1QbkFBazrASWsvhNoZ8uol00= From: Paul Cercueil To: David Airlie , Daniel Vetter Subject: [PATCH v2 02/26] drm: bochs: Define and use generic PM ops Date: Tue, 29 Nov 2022 19:17:09 +0000 Message-Id: <20221129191733.137897-3-paul@crapouillou.net> In-Reply-To: <20221129191733.137897-1-paul@crapouillou.net> References: <20221129191733.137897-1-paul@crapouillou.net> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paul Cercueil , virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Gerd Hoffmann Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Use the new DEFINE_DRM_MODE_CONFIG_HELPER_PM_OPS() macro to create a "struct dev_pm_ops" that can be used by this driver, instead of using custom PM callbacks with the same behaviour. v2: Use the DEFINE_DRM_MODE_CONFIG_HELPER_PM_OPS() macro instead of an exported dev_pm_ops. Signed-off-by: Paul Cercueil --- Cc: Gerd Hoffmann Cc: virtualization@lists.linux-foundation.org --- drivers/gpu/drm/tiny/bochs.c | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/drivers/gpu/drm/tiny/bochs.c b/drivers/gpu/drm/tiny/bochs.c index 024346054c70..598488905607 100644 --- a/drivers/gpu/drm/tiny/bochs.c +++ b/drivers/gpu/drm/tiny/bochs.c @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -610,30 +611,6 @@ static const struct drm_driver bochs_driver = { DRM_GEM_VRAM_DRIVER, }; -/* ---------------------------------------------------------------------- */ -/* pm interface */ - -#ifdef CONFIG_PM_SLEEP -static int bochs_pm_suspend(struct device *dev) -{ - struct drm_device *drm_dev = dev_get_drvdata(dev); - - return drm_mode_config_helper_suspend(drm_dev); -} - -static int bochs_pm_resume(struct device *dev) -{ - struct drm_device *drm_dev = dev_get_drvdata(dev); - - return drm_mode_config_helper_resume(drm_dev); -} -#endif - -static const struct dev_pm_ops bochs_pm_ops = { - SET_SYSTEM_SLEEP_PM_OPS(bochs_pm_suspend, - bochs_pm_resume) -}; - /* ---------------------------------------------------------------------- */ /* pci interface */ @@ -716,12 +693,14 @@ static const struct pci_device_id bochs_pci_tbl[] = { { /* end of list */ } }; +DEFINE_DRM_MODE_CONFIG_HELPER_PM_OPS(bochs_pm_ops); + static struct pci_driver bochs_pci_driver = { .name = "bochs-drm", .id_table = bochs_pci_tbl, .probe = bochs_pci_probe, .remove = bochs_pci_remove, - .driver.pm = &bochs_pm_ops, + .driver.pm = pm_sleep_ptr(&bochs_pm_ops), }; /* ---------------------------------------------------------------------- */ From patchwork Tue Nov 29 19:17:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Cercueil X-Patchwork-Id: 13059033 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1342EC4332F for ; Tue, 29 Nov 2022 19:18:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CBE5910E211; Tue, 29 Nov 2022 19:18:26 +0000 (UTC) Received: from aposti.net (aposti.net [89.234.176.197]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9FF7A10E211 for ; Tue, 29 Nov 2022 19:18:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crapouillou.net; s=mail; t=1669749471; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bRwIBP3Bd5yyj8tKvu5xEITLhoIAEXi+VXTuD8Wv1kk=; b=LIYDR5EdYELj9tAH4IuzuOM34Lt9KwUFjWmnyL2ak9lFDTvcYqbLtlj8VsqXP1bXZfRWeD rns4LoHYtbq2AR5UPz7tQDJBGBgx93ELO4GKjErLZHroxhGXxC851HhhBoI1A5RYzrpBlP Mdv1vzV1x+ZlR21rdec8icpTZR6gL6s= From: Paul Cercueil To: David Airlie , Daniel Vetter Subject: [PATCH v2 03/26] drm: imx: Define and use generic PM ops Date: Tue, 29 Nov 2022 19:17:10 +0000 Message-Id: <20221129191733.137897-4-paul@crapouillou.net> In-Reply-To: <20221129191733.137897-1-paul@crapouillou.net> References: <20221129191733.137897-1-paul@crapouillou.net> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pengutronix Kernel Team , Sascha Hauer , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Paul Cercueil , NXP Linux Team , Shawn Guo , linux-arm-kernel@lists.infradead.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Use the new DEFINE_DRM_MODE_CONFIG_HELPER_PM_OPS() macro to create a "struct dev_pm_ops" that can be used by this driver, instead of using custom PM callbacks with the same behaviour. v2: Use the DEFINE_DRM_MODE_CONFIG_HELPER_PM_OPS() macro instead of an exported dev_pm_ops. Signed-off-by: Paul Cercueil --- Cc: Philipp Zabel Cc: Shawn Guo Cc: Sascha Hauer Cc: Pengutronix Kernel Team Cc: Fabio Estevam Cc: NXP Linux Team Cc: linux-arm-kernel@lists.infradead.org --- drivers/gpu/drm/imx/imx-drm-core.c | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/drivers/gpu/drm/imx/imx-drm-core.c b/drivers/gpu/drm/imx/imx-drm-core.c index e060fa6cbcb9..1992934034e0 100644 --- a/drivers/gpu/drm/imx/imx-drm-core.c +++ b/drivers/gpu/drm/imx/imx-drm-core.c @@ -10,6 +10,7 @@ #include #include #include +#include #include