Skip to content

Commit 0ae101f

Browse files
pcercueirafaeljw
authored andcommitted
PM: core: Add EXPORT[_GPL]_SIMPLE_DEV_PM_OPS macros
These macros are defined conditionally, according to CONFIG_PM: - if CONFIG_PM is enabled, these macros resolve to DEFINE_SIMPLE_DEV_PM_OPS(), and the dev_pm_ops symbol will be exported. - if CONFIG_PM is disabled, these macros will result in a dummy static dev_pm_ops to be created with the __maybe_unused flag. The dev_pm_ops will then be discarded by the compiler, along with the provided callback functions if they are not used anywhere else. In the second case, the symbol is not exported, which should be perfectly fine - users of the symbol should all use the pm_ptr() or pm_sleep_ptr() macro, so the dev_pm_ops marked as "extern" in the client's code will never be accessed. Signed-off-by: Paul Cercueil <[email protected]> Acked-by: Jonathan Cameron <[email protected]> Reviewed-by: Ulf Hansson <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 52cc1d7 commit 0ae101f

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

include/linux/pm.h

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#ifndef _LINUX_PM_H
99
#define _LINUX_PM_H
1010

11+
#include <linux/export.h>
1112
#include <linux/list.h>
1213
#include <linux/workqueue.h>
1314
#include <linux/spinlock.h>
@@ -357,14 +358,42 @@ struct dev_pm_ops {
357358
#define SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn)
358359
#endif
359360

361+
#define _DEFINE_DEV_PM_OPS(name, \
362+
suspend_fn, resume_fn, \
363+
runtime_suspend_fn, runtime_resume_fn, idle_fn) \
364+
const struct dev_pm_ops name = { \
365+
SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
366+
RUNTIME_PM_OPS(runtime_suspend_fn, runtime_resume_fn, idle_fn) \
367+
}
368+
369+
#ifdef CONFIG_PM
370+
#define _EXPORT_DEV_PM_OPS(name, suspend_fn, resume_fn, runtime_suspend_fn, \
371+
runtime_resume_fn, idle_fn, sec) \
372+
_DEFINE_DEV_PM_OPS(name, suspend_fn, resume_fn, runtime_suspend_fn, \
373+
runtime_resume_fn, idle_fn); \
374+
_EXPORT_SYMBOL(name, sec)
375+
#else
376+
#define _EXPORT_DEV_PM_OPS(name, suspend_fn, resume_fn, runtime_suspend_fn, \
377+
runtime_resume_fn, idle_fn, sec) \
378+
static __maybe_unused _DEFINE_DEV_PM_OPS(__static_##name, suspend_fn, \
379+
resume_fn, runtime_suspend_fn, \
380+
runtime_resume_fn, idle_fn)
381+
#endif
382+
360383
/*
361384
* Use this if you want to use the same suspend and resume callbacks for suspend
362385
* to RAM and hibernation.
386+
*
387+
* If the underlying dev_pm_ops struct symbol has to be exported, use
388+
* EXPORT_SIMPLE_DEV_PM_OPS() or EXPORT_GPL_SIMPLE_DEV_PM_OPS() instead.
363389
*/
364390
#define DEFINE_SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \
365-
const struct dev_pm_ops name = { \
366-
SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
367-
}
391+
_DEFINE_DEV_PM_OPS(name, suspend_fn, resume_fn, NULL, NULL, NULL)
392+
393+
#define EXPORT_SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \
394+
_EXPORT_DEV_PM_OPS(name, suspend_fn, resume_fn, NULL, NULL, NULL, "")
395+
#define EXPORT_GPL_SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \
396+
_EXPORT_DEV_PM_OPS(name, suspend_fn, resume_fn, NULL, NULL, NULL, "_gpl")
368397

369398
/* Deprecated. Use DEFINE_SIMPLE_DEV_PM_OPS() instead. */
370399
#define SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \

0 commit comments

Comments
 (0)