lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20221129191733.137897-2-paul@crapouillou.net>
Date:   Tue, 29 Nov 2022 19:17:08 +0000
From:   Paul Cercueil <paul@...pouillou.net>
To:     David Airlie <airlied@...il.com>, Daniel Vetter <daniel@...ll.ch>
Cc:     dri-devel@...ts.freedesktop.org, linux-kernel@...r.kernel.org,
        Paul Cercueil <paul@...pouillou.net>
Subject: [PATCH v2 01/26] drm: modeset-helper: Add DEFINE_DRM_MODE_CONFIG_HELPER_PM_OPS macro

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 <paul@...pouillou.net>
---
 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
-- 
2.35.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ