1 | // SPDX-License-Identifier: GPL-3.0-or-later |
---|---|
2 | |
3 | #include "mos/misc/power.hpp" |
4 | |
5 | #include "mos/platform/platform.hpp" |
6 | #include "mos/syslog/printk.hpp" |
7 | |
8 | #include <mos/allocator.hpp> |
9 | #include <mos/lib/structures/list.hpp> |
10 | #include <mos_stdlib.hpp> |
11 | |
12 | struct power_callback_entry_t : mos::NamedType<"PowerCallback"> |
13 | { |
14 | as_linked_list; |
15 | power_callback_t callback; |
16 | void *data; |
17 | }; |
18 | |
19 | static list_head pm_notifiers; |
20 | |
21 | void power_register_shutdown_callback(power_callback_t callback, void *data) |
22 | { |
23 | power_callback_entry_t *entry = mos::create<power_callback_entry_t>(); |
24 | linked_list_init(list_node(entry)); |
25 | entry->callback = callback; |
26 | entry->data = data; |
27 | list_node_append(head: &pm_notifiers, list_node(entry)); |
28 | } |
29 | |
30 | [[noreturn]] void power_shutdown(void) |
31 | { |
32 | pr_info("system shutdown initiated"); |
33 | list_foreach(power_callback_entry_t, e, pm_notifiers) |
34 | { |
35 | e->callback(e->data); |
36 | list_remove(e); |
37 | delete e; |
38 | } |
39 | |
40 | pr_info("Bye!"); |
41 | platform_shutdown(); |
42 | } |
43 |