Skip to content

Commit 1a3c7bb

Browse files
pcercueirafaeljw
authored andcommitted
PM: core: Add new *_PM_OPS macros, deprecate old ones
This commit introduces the following macros: SYSTEM_SLEEP_PM_OPS() LATE_SYSTEM_SLEEP_PM_OPS() NOIRQ_SYSTEM_SLEEP_PM_OPS() RUNTIME_PM_OPS() These new macros are very similar to their SET_*_PM_OPS() equivalent. They however differ in the fact that the callbacks they set will always be seen as referenced by the compiler. This means that the callback functions don't need to be wrapped with a #ifdef CONFIG_PM guard, or tagged with __maybe_unused, to prevent the compiler from complaining about unused static symbols. The compiler will then simply evaluate at compile time whether or not these symbols are dead code. The callbacks that are only useful with CONFIG_PM_SLEEP is enabled, are now also wrapped with a new pm_sleep_ptr() macro, which is inspired from pm_ptr(). This is needed for drivers that use different callbacks for sleep and runtime PM, to handle the case where CONFIG_PM is set and CONFIG_PM_SLEEP is not. This commit also deprecates the following macros: SIMPLE_DEV_PM_OPS() UNIVERSAL_DEV_PM_OPS() And introduces the following macros: DEFINE_SIMPLE_DEV_PM_OPS() DEFINE_UNIVERSAL_DEV_PM_OPS() These macros are similar to the functions they were created to replace, with the following differences: - They use the new macros introduced above, and as such always reference the provided callback functions. - They are not tagged with __maybe_unused. They are meant to be used with pm_ptr() or pm_sleep_ptr() for DEFINE_UNIVERSAL_DEV_PM_OPS() and DEFINE_SIMPLE_DEV_PM_OPS() respectively. - They declare the symbol static, since every driver seems to do that anyway; and if a non-static use-case is needed an indirection pointer could be used. The point of this change, is to progressively switch from a code model where PM callbacks are all protected behind CONFIG_PM guards, to a code model where the PM callbacks are always seen by the compiler, but discarded if not used. Signed-off-by: Paul Cercueil <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent c06ef74 commit 1a3c7bb

File tree

1 file changed

+50
-24
lines changed

1 file changed

+50
-24
lines changed

include/linux/pm.h

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -300,47 +300,59 @@ struct dev_pm_ops {
300300
int (*runtime_idle)(struct device *dev);
301301
};
302302

303+
#define SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
304+
.suspend = pm_sleep_ptr(suspend_fn), \
305+
.resume = pm_sleep_ptr(resume_fn), \
306+
.freeze = pm_sleep_ptr(suspend_fn), \
307+
.thaw = pm_sleep_ptr(resume_fn), \
308+
.poweroff = pm_sleep_ptr(suspend_fn), \
309+
.restore = pm_sleep_ptr(resume_fn),
310+
311+
#define LATE_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
312+
.suspend_late = pm_sleep_ptr(suspend_fn), \
313+
.resume_early = pm_sleep_ptr(resume_fn), \
314+
.freeze_late = pm_sleep_ptr(suspend_fn), \
315+
.thaw_early = pm_sleep_ptr(resume_fn), \
316+
.poweroff_late = pm_sleep_ptr(suspend_fn), \
317+
.restore_early = pm_sleep_ptr(resume_fn),
318+
319+
#define NOIRQ_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
320+
.suspend_noirq = pm_sleep_ptr(suspend_fn), \
321+
.resume_noirq = pm_sleep_ptr(resume_fn), \
322+
.freeze_noirq = pm_sleep_ptr(suspend_fn), \
323+
.thaw_noirq = pm_sleep_ptr(resume_fn), \
324+
.poweroff_noirq = pm_sleep_ptr(suspend_fn), \
325+
.restore_noirq = pm_sleep_ptr(resume_fn),
326+
327+
#define RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
328+
.runtime_suspend = suspend_fn, \
329+
.runtime_resume = resume_fn, \
330+
.runtime_idle = idle_fn,
331+
303332
#ifdef CONFIG_PM_SLEEP
304333
#define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
305-
.suspend = suspend_fn, \
306-
.resume = resume_fn, \
307-
.freeze = suspend_fn, \
308-
.thaw = resume_fn, \
309-
.poweroff = suspend_fn, \
310-
.restore = resume_fn,
334+
SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn)
311335
#else
312336
#define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn)
313337
#endif
314338

315339
#ifdef CONFIG_PM_SLEEP
316340
#define SET_LATE_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
317-
.suspend_late = suspend_fn, \
318-
.resume_early = resume_fn, \
319-
.freeze_late = suspend_fn, \
320-
.thaw_early = resume_fn, \
321-
.poweroff_late = suspend_fn, \
322-
.restore_early = resume_fn,
341+
LATE_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn)
323342
#else
324343
#define SET_LATE_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn)
325344
#endif
326345

327346
#ifdef CONFIG_PM_SLEEP
328347
#define SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
329-
.suspend_noirq = suspend_fn, \
330-
.resume_noirq = resume_fn, \
331-
.freeze_noirq = suspend_fn, \
332-
.thaw_noirq = resume_fn, \
333-
.poweroff_noirq = suspend_fn, \
334-
.restore_noirq = resume_fn,
348+
NOIRQ_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn)
335349
#else
336350
#define SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn)
337351
#endif
338352

339353
#ifdef CONFIG_PM
340354
#define SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
341-
.runtime_suspend = suspend_fn, \
342-
.runtime_resume = resume_fn, \
343-
.runtime_idle = idle_fn,
355+
RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn)
344356
#else
345357
#define SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn)
346358
#endif
@@ -349,9 +361,9 @@ struct dev_pm_ops {
349361
* Use this if you want to use the same suspend and resume callbacks for suspend
350362
* to RAM and hibernation.
351363
*/
352-
#define SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \
353-
const struct dev_pm_ops __maybe_unused name = { \
354-
SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
364+
#define DEFINE_SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \
365+
static const struct dev_pm_ops name = { \
366+
SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
355367
}
356368

357369
/*
@@ -367,13 +379,27 @@ const struct dev_pm_ops __maybe_unused name = { \
367379
* .resume_early(), to the same routines as .runtime_suspend() and
368380
* .runtime_resume(), respectively (and analogously for hibernation).
369381
*/
382+
#define DEFINE_UNIVERSAL_DEV_PM_OPS(name, suspend_fn, resume_fn, idle_fn) \
383+
static const struct dev_pm_ops name = { \
384+
SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
385+
RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
386+
}
387+
388+
/* Deprecated. Use DEFINE_SIMPLE_DEV_PM_OPS() instead. */
389+
#define SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \
390+
const struct dev_pm_ops __maybe_unused name = { \
391+
SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
392+
}
393+
394+
/* Deprecated. Use DEFINE_UNIVERSAL_DEV_PM_OPS() instead. */
370395
#define UNIVERSAL_DEV_PM_OPS(name, suspend_fn, resume_fn, idle_fn) \
371396
const struct dev_pm_ops __maybe_unused name = { \
372397
SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
373398
SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
374399
}
375400

376401
#define pm_ptr(_ptr) PTR_IF(IS_ENABLED(CONFIG_PM), (_ptr))
402+
#define pm_sleep_ptr(_ptr) PTR_IF(IS_ENABLED(CONFIG_PM_SLEEP), (_ptr))
377403

378404
/*
379405
* PM_EVENT_ messages

0 commit comments

Comments
 (0)