Skip to content

Commit 34e1ed1

Browse files
pcercueirafaeljw
authored andcommitted
PM: Improve EXPORT_*_DEV_PM_OPS macros
Update the _EXPORT_DEV_PM_OPS() internal macro. It was not used anywhere outside pm.h and pm_runtime.h, so it is safe to update it. Before, this macro would take a few parameters to be used as sleep and runtime callbacks. This made it unsuitable to use with different callbacks, for instance the "noirq" ones. It is now semantically different: instead of creating a conditionally exported dev_pm_ops structure, it only contains part of the definition. This macro should however never be used directly (hence the trailing underscore). Instead, the following four macros are provided: - EXPORT_DEV_PM_OPS(name) - EXPORT_GPL_DEV_PM_OPS(name) - EXPORT_NS_DEV_PM_OPS(name, ns) - EXPORT_NS_GPL_DEV_PM_OPS(name, ns) For instance, it is now possible to conditionally export noirq suspend/resume PM functions like this: EXPORT_GPL_DEV_PM_OPS(foo_pm_ops) = { NOIRQ_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) }; The existing helper macros EXPORT_*_SIMPLE_DEV_PM_OPS() and EXPORT_*_RUNTIME_DEV_PM_OPS() have been updated to use these new macros. Signed-off-by: Paul Cercueil <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent c79e6fa commit 34e1ed1

File tree

2 files changed

+35
-22
lines changed

2 files changed

+35
-22
lines changed

include/linux/pm.h

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -375,19 +375,20 @@ const struct dev_pm_ops name = { \
375375
}
376376

377377
#ifdef CONFIG_PM
378-
#define _EXPORT_DEV_PM_OPS(name, suspend_fn, resume_fn, runtime_suspend_fn, \
379-
runtime_resume_fn, idle_fn, sec, ns) \
380-
_DEFINE_DEV_PM_OPS(name, suspend_fn, resume_fn, runtime_suspend_fn, \
381-
runtime_resume_fn, idle_fn); \
382-
__EXPORT_SYMBOL(name, sec, ns)
378+
#define _EXPORT_DEV_PM_OPS(name, sec, ns) \
379+
const struct dev_pm_ops name; \
380+
__EXPORT_SYMBOL(name, sec, ns); \
381+
const struct dev_pm_ops name
383382
#else
384-
#define _EXPORT_DEV_PM_OPS(name, suspend_fn, resume_fn, runtime_suspend_fn, \
385-
runtime_resume_fn, idle_fn, sec, ns) \
386-
static __maybe_unused _DEFINE_DEV_PM_OPS(__static_##name, suspend_fn, \
387-
resume_fn, runtime_suspend_fn, \
388-
runtime_resume_fn, idle_fn)
383+
#define _EXPORT_DEV_PM_OPS(name, sec, ns) \
384+
static __maybe_unused const struct dev_pm_ops __static_##name
389385
#endif
390386

387+
#define EXPORT_DEV_PM_OPS(name) _EXPORT_DEV_PM_OPS(name, "", "")
388+
#define EXPORT_GPL_DEV_PM_OPS(name) _EXPORT_DEV_PM_OPS(name, "_gpl", "")
389+
#define EXPORT_NS_DEV_PM_OPS(name, ns) _EXPORT_DEV_PM_OPS(name, "", #ns)
390+
#define EXPORT_NS_GPL_DEV_PM_OPS(name, ns) _EXPORT_DEV_PM_OPS(name, "_gpl", #ns)
391+
391392
/*
392393
* Use this if you want to use the same suspend and resume callbacks for suspend
393394
* to RAM and hibernation.
@@ -399,13 +400,21 @@ static __maybe_unused _DEFINE_DEV_PM_OPS(__static_##name, suspend_fn, \
399400
_DEFINE_DEV_PM_OPS(name, suspend_fn, resume_fn, NULL, NULL, NULL)
400401

401402
#define EXPORT_SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \
402-
_EXPORT_DEV_PM_OPS(name, suspend_fn, resume_fn, NULL, NULL, NULL, "", "")
403+
EXPORT_DEV_PM_OPS(name) = { \
404+
SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
405+
}
403406
#define EXPORT_GPL_SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \
404-
_EXPORT_DEV_PM_OPS(name, suspend_fn, resume_fn, NULL, NULL, NULL, "_gpl", "")
407+
EXPORT_GPL_DEV_PM_OPS(name) = { \
408+
SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
409+
}
405410
#define EXPORT_NS_SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn, ns) \
406-
_EXPORT_DEV_PM_OPS(name, suspend_fn, resume_fn, NULL, NULL, NULL, "", #ns)
411+
EXPORT_NS_DEV_PM_OPS(name, ns) = { \
412+
SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
413+
}
407414
#define EXPORT_NS_GPL_SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn, ns) \
408-
_EXPORT_DEV_PM_OPS(name, suspend_fn, resume_fn, NULL, NULL, NULL, "_gpl", #ns)
415+
EXPORT_NS_GPL_DEV_PM_OPS(name, ns) = { \
416+
SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
417+
}
409418

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

include/linux/pm_runtime.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,21 @@
4040
resume_fn, idle_fn)
4141

4242
#define EXPORT_RUNTIME_DEV_PM_OPS(name, suspend_fn, resume_fn, idle_fn) \
43-
_EXPORT_DEV_PM_OPS(name, pm_runtime_force_suspend, pm_runtime_force_resume, \
44-
suspend_fn, resume_fn, idle_fn, "", "")
43+
EXPORT_DEV_PM_OPS(name) = { \
44+
RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
45+
}
4546
#define EXPORT_GPL_RUNTIME_DEV_PM_OPS(name, suspend_fn, resume_fn, idle_fn) \
46-
_EXPORT_DEV_PM_OPS(name, pm_runtime_force_suspend, pm_runtime_force_resume, \
47-
suspend_fn, resume_fn, idle_fn, "_gpl", "")
47+
EXPORT_GPL_DEV_PM_OPS(name) = { \
48+
RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
49+
}
4850
#define EXPORT_NS_RUNTIME_DEV_PM_OPS(name, suspend_fn, resume_fn, idle_fn, ns) \
49-
_EXPORT_DEV_PM_OPS(name, pm_runtime_force_suspend, pm_runtime_force_resume, \
50-
suspend_fn, resume_fn, idle_fn, "", #ns)
51+
EXPORT_NS_DEV_PM_OPS(name, ns) = { \
52+
RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
53+
}
5154
#define EXPORT_NS_GPL_RUNTIME_DEV_PM_OPS(name, suspend_fn, resume_fn, idle_fn, ns) \
52-
_EXPORT_DEV_PM_OPS(name, pm_runtime_force_suspend, pm_runtime_force_resume, \
53-
suspend_fn, resume_fn, idle_fn, "_gpl", #ns)
55+
EXPORT_NS_GPL_DEV_PM_OPS(name, ns) = { \
56+
RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
57+
}
5458

5559
#ifdef CONFIG_PM
5660
extern struct workqueue_struct *pm_wq;

0 commit comments

Comments
 (0)