Linux Audio

Check our new training course

Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 *  syscore.c - Execution of system core operations.
  4 *
  5 *  Copyright (C) 2011 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc.
 
 
  6 */
  7
  8#include <linux/syscore_ops.h>
  9#include <linux/mutex.h>
 10#include <linux/module.h>
 11#include <linux/suspend.h>
 12#include <trace/events/power.h>
 13
 14static LIST_HEAD(syscore_ops_list);
 15static DEFINE_MUTEX(syscore_ops_lock);
 16
 17/**
 18 * register_syscore_ops - Register a set of system core operations.
 19 * @ops: System core operations to register.
 20 */
 21void register_syscore_ops(struct syscore_ops *ops)
 22{
 23	mutex_lock(&syscore_ops_lock);
 24	list_add_tail(&ops->node, &syscore_ops_list);
 25	mutex_unlock(&syscore_ops_lock);
 26}
 27EXPORT_SYMBOL_GPL(register_syscore_ops);
 28
 29/**
 30 * unregister_syscore_ops - Unregister a set of system core operations.
 31 * @ops: System core operations to unregister.
 32 */
 33void unregister_syscore_ops(struct syscore_ops *ops)
 34{
 35	mutex_lock(&syscore_ops_lock);
 36	list_del(&ops->node);
 37	mutex_unlock(&syscore_ops_lock);
 38}
 39EXPORT_SYMBOL_GPL(unregister_syscore_ops);
 40
 41#ifdef CONFIG_PM_SLEEP
 42/**
 43 * syscore_suspend - Execute all the registered system core suspend callbacks.
 44 *
 45 * This function is executed with one CPU on-line and disabled interrupts.
 46 */
 47int syscore_suspend(void)
 48{
 49	struct syscore_ops *ops;
 50	int ret = 0;
 51
 52	trace_suspend_resume(TPS("syscore_suspend"), 0, true);
 53	pm_pr_dbg("Checking wakeup interrupts\n");
 54
 55	/* Return error code if there are any wakeup interrupts pending. */
 56	if (pm_wakeup_pending())
 57		return -EBUSY;
 58
 59	WARN_ONCE(!irqs_disabled(),
 60		"Interrupts enabled before system core suspend.\n");
 61
 62	list_for_each_entry_reverse(ops, &syscore_ops_list, node)
 63		if (ops->suspend) {
 64			pm_pr_dbg("Calling %pS\n", ops->suspend);
 
 65			ret = ops->suspend();
 66			if (ret)
 67				goto err_out;
 68			WARN_ONCE(!irqs_disabled(),
 69				"Interrupts enabled after %pS\n", ops->suspend);
 70		}
 71
 72	trace_suspend_resume(TPS("syscore_suspend"), 0, false);
 73	return 0;
 74
 75 err_out:
 76	pr_err("PM: System core suspend callback %pS failed.\n", ops->suspend);
 77
 78	list_for_each_entry_continue(ops, &syscore_ops_list, node)
 79		if (ops->resume)
 80			ops->resume();
 81
 82	return ret;
 83}
 84EXPORT_SYMBOL_GPL(syscore_suspend);
 85
 86/**
 87 * syscore_resume - Execute all the registered system core resume callbacks.
 88 *
 89 * This function is executed with one CPU on-line and disabled interrupts.
 90 */
 91void syscore_resume(void)
 92{
 93	struct syscore_ops *ops;
 94
 95	trace_suspend_resume(TPS("syscore_resume"), 0, true);
 96	WARN_ONCE(!irqs_disabled(),
 97		"Interrupts enabled before system core resume.\n");
 98
 99	list_for_each_entry(ops, &syscore_ops_list, node)
100		if (ops->resume) {
101			pm_pr_dbg("Calling %pS\n", ops->resume);
 
102			ops->resume();
103			WARN_ONCE(!irqs_disabled(),
104				"Interrupts enabled after %pS\n", ops->resume);
105		}
106	trace_suspend_resume(TPS("syscore_resume"), 0, false);
107}
108EXPORT_SYMBOL_GPL(syscore_resume);
109#endif /* CONFIG_PM_SLEEP */
110
111/**
112 * syscore_shutdown - Execute all the registered system core shutdown callbacks.
113 */
114void syscore_shutdown(void)
115{
116	struct syscore_ops *ops;
117
118	mutex_lock(&syscore_ops_lock);
119
120	list_for_each_entry_reverse(ops, &syscore_ops_list, node)
121		if (ops->shutdown) {
122			if (initcall_debug)
123				pr_info("PM: Calling %pS\n", ops->shutdown);
124			ops->shutdown();
125		}
126
127	mutex_unlock(&syscore_ops_lock);
128}
v4.6
 
  1/*
  2 *  syscore.c - Execution of system core operations.
  3 *
  4 *  Copyright (C) 2011 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc.
  5 *
  6 *  This file is released under the GPLv2.
  7 */
  8
  9#include <linux/syscore_ops.h>
 10#include <linux/mutex.h>
 11#include <linux/module.h>
 12#include <linux/suspend.h>
 13#include <trace/events/power.h>
 14
 15static LIST_HEAD(syscore_ops_list);
 16static DEFINE_MUTEX(syscore_ops_lock);
 17
 18/**
 19 * register_syscore_ops - Register a set of system core operations.
 20 * @ops: System core operations to register.
 21 */
 22void register_syscore_ops(struct syscore_ops *ops)
 23{
 24	mutex_lock(&syscore_ops_lock);
 25	list_add_tail(&ops->node, &syscore_ops_list);
 26	mutex_unlock(&syscore_ops_lock);
 27}
 28EXPORT_SYMBOL_GPL(register_syscore_ops);
 29
 30/**
 31 * unregister_syscore_ops - Unregister a set of system core operations.
 32 * @ops: System core operations to unregister.
 33 */
 34void unregister_syscore_ops(struct syscore_ops *ops)
 35{
 36	mutex_lock(&syscore_ops_lock);
 37	list_del(&ops->node);
 38	mutex_unlock(&syscore_ops_lock);
 39}
 40EXPORT_SYMBOL_GPL(unregister_syscore_ops);
 41
 42#ifdef CONFIG_PM_SLEEP
 43/**
 44 * syscore_suspend - Execute all the registered system core suspend callbacks.
 45 *
 46 * This function is executed with one CPU on-line and disabled interrupts.
 47 */
 48int syscore_suspend(void)
 49{
 50	struct syscore_ops *ops;
 51	int ret = 0;
 52
 53	trace_suspend_resume(TPS("syscore_suspend"), 0, true);
 54	pr_debug("Checking wakeup interrupts\n");
 55
 56	/* Return error code if there are any wakeup interrupts pending. */
 57	if (pm_wakeup_pending())
 58		return -EBUSY;
 59
 60	WARN_ONCE(!irqs_disabled(),
 61		"Interrupts enabled before system core suspend.\n");
 62
 63	list_for_each_entry_reverse(ops, &syscore_ops_list, node)
 64		if (ops->suspend) {
 65			if (initcall_debug)
 66				pr_info("PM: Calling %pF\n", ops->suspend);
 67			ret = ops->suspend();
 68			if (ret)
 69				goto err_out;
 70			WARN_ONCE(!irqs_disabled(),
 71				"Interrupts enabled after %pF\n", ops->suspend);
 72		}
 73
 74	trace_suspend_resume(TPS("syscore_suspend"), 0, false);
 75	return 0;
 76
 77 err_out:
 78	pr_err("PM: System core suspend callback %pF failed.\n", ops->suspend);
 79
 80	list_for_each_entry_continue(ops, &syscore_ops_list, node)
 81		if (ops->resume)
 82			ops->resume();
 83
 84	return ret;
 85}
 86EXPORT_SYMBOL_GPL(syscore_suspend);
 87
 88/**
 89 * syscore_resume - Execute all the registered system core resume callbacks.
 90 *
 91 * This function is executed with one CPU on-line and disabled interrupts.
 92 */
 93void syscore_resume(void)
 94{
 95	struct syscore_ops *ops;
 96
 97	trace_suspend_resume(TPS("syscore_resume"), 0, true);
 98	WARN_ONCE(!irqs_disabled(),
 99		"Interrupts enabled before system core resume.\n");
100
101	list_for_each_entry(ops, &syscore_ops_list, node)
102		if (ops->resume) {
103			if (initcall_debug)
104				pr_info("PM: Calling %pF\n", ops->resume);
105			ops->resume();
106			WARN_ONCE(!irqs_disabled(),
107				"Interrupts enabled after %pF\n", ops->resume);
108		}
109	trace_suspend_resume(TPS("syscore_resume"), 0, false);
110}
111EXPORT_SYMBOL_GPL(syscore_resume);
112#endif /* CONFIG_PM_SLEEP */
113
114/**
115 * syscore_shutdown - Execute all the registered system core shutdown callbacks.
116 */
117void syscore_shutdown(void)
118{
119	struct syscore_ops *ops;
120
121	mutex_lock(&syscore_ops_lock);
122
123	list_for_each_entry_reverse(ops, &syscore_ops_list, node)
124		if (ops->shutdown) {
125			if (initcall_debug)
126				pr_info("PM: Calling %pF\n", ops->shutdown);
127			ops->shutdown();
128		}
129
130	mutex_unlock(&syscore_ops_lock);
131}