2 * (c) 2014 Alexander Warg <warg@os.inf.tu-dresden.de>
4 * This file is part of TUD:OS and distributed under the terms of the
5 * GNU General Public License 2.
6 * Please see the COPYING-GPL-2 file for details.
9 #include "hw_root_bus.h"
10 #include "platform_control.h"
14 #include <l4/cxx/static_container>
15 #include <l4/sys/platform_control>
16 #include <l4/cxx/ipc_timeout_queue>
20 struct Suspend_timeout : L4::Ipc_svr::Timeout
22 Platform_control *ctl;
23 explicit Suspend_timeout(Platform_control *ctl) : ctl(ctl) {}
27 d_printf(DBG_ERR, "error: timeout during suspend, abort suspend\n");
28 ctl->print_lock_holders(L4VBUS_INHIBITOR_SUSPEND);
29 ctl->inhibitor_signal(L4VBUS_INHIBITOR_WAKEUP);
34 struct Shutdown_timeout : L4::Ipc_svr::Timeout
36 Platform_control *ctl;
37 explicit Shutdown_timeout(Platform_control *ctl) : ctl(ctl) {}
42 "error: timeout during shutdown / reboot, force operation\n");
43 ctl->print_lock_holders(L4VBUS_INHIBITOR_SHUTDOWN);
44 // this will do a reboot if the operation in progress is reboot
45 ctl->all_inhibitors_free(L4VBUS_INHIBITOR_SHUTDOWN);
52 cxx::Static_container<Suspend_timeout> suspend;
53 cxx::Static_container<Shutdown_timeout> shutdown;
59 Platform_control::start_operation(unsigned op)
61 using L4::Ipc_svr::Timeout_queue;
63 if (in_progress_ops())
67 Timeout_queue::Timeout *timeout;
70 case Suspend_in_progress:
71 inhibitor = L4VBUS_INHIBITOR_SUSPEND;
72 op_timeout.suspend.construct(this);
73 timeout = op_timeout.suspend;
76 case Shutdown_in_progress: /* fall through */
77 case Reboot_in_progress:
78 inhibitor = L4VBUS_INHIBITOR_SHUTDOWN;
79 op_timeout.shutdown.construct(this);
80 timeout = op_timeout.shutdown;
88 if (inhibitors_free(inhibitor))
90 all_inhibitors_free(inhibitor);
93 inhibitor_signal(inhibitor);
94 server_iface()->add_timeout(timeout, l4_kip_clock(l4re_kip()) + 10000000);
99 Platform_control::all_inhibitors_free(l4_umword_t id)
101 if (!_hw_root->supports_pm())
104 unsigned in_progress = in_progress_ops();
114 case L4VBUS_INHIBITOR_SUSPEND:
115 if (in_progress & Suspend_in_progress)
117 server_iface()->remove_timeout(op_timeout.suspend);
119 _state &= ~Suspend_in_progress;
120 inhibitor_signal(L4VBUS_INHIBITOR_WAKEUP);
124 case L4VBUS_INHIBITOR_SHUTDOWN:
125 // reboot overrides shutdown (HMM: this is policy)
126 server_iface()->remove_timeout(op_timeout.shutdown);
127 if (in_progress & Reboot_in_progress)
130 d_printf(DBG_ERR, "fatal: platform reboot returned\n");
134 if (in_progress & Shutdown_in_progress)
136 _hw_root->shutdown();
137 d_printf(DBG_ERR, "fatal: platform shutdown returned\n");