28 Pm(L4::Ipc::String<>
const &reason) : _reason(reason)
33 auto event = cxx::make_unique<L4Re::Util::Event>();
36 if (!_inhib.is_valid())
38 Dbg::warn().printf(
"Invalid inhibitor capability.\n");
45 Dbg::warn().printf(
"Failed to initialize events.\n");
48 if (!event->irq().is_valid())
50 Dbg::warn().printf(
"Invalid event's irq capability.\n");
53 ret = _inhib->acquire(L4VBUS_INHIBITOR_SHUTDOWN, _reason);
56 Dbg::warn().printf(
"Failed to acquire shutdown inhibitor.\n");
59 ret = _inhib->acquire(L4VBUS_INHIBITOR_SUSPEND, _reason);
62 Dbg::warn().printf(
"Failed to acquire suspend inhibitor.\n");
63 if (_inhib->release(L4VBUS_INHIBITOR_SHUTDOWN))
64 Dbg::warn().printf(
"Failed to release shutdown inhibitor.\n");
67 _event = cxx::move(event);
76 if (_inhib.is_valid())
78 if (_inhib->release(L4VBUS_INHIBITOR_SHUTDOWN))
79 Dbg::warn().printf(
"Failed to release shutdown inhibitor.\n");
80 if (_inhib->release(L4VBUS_INHIBITOR_SUSPEND))
81 Dbg::warn().printf(
"Failed to release suspend inhibitor.\n");
85 template <
typename REG>
86 void register_obj(REG *registry)
92 template <
typename REG>
93 void unregister_obj(REG *registry)
95 registry->unregister_obj(
this);
100 L4Re::Util::Event_buffer::Event *e;
101 while ((e = _event->buffer().next()) != NULL)
103 if (e->payload.
type == L4RE_EV_PM)
105 switch (e->payload.
code)
107 case L4VBUS_INHIBITOR_SUSPEND:
109 if (_inhib->acquire(L4VBUS_INHIBITOR_WAKEUP, _reason))
111 Dbg::warn().printf(
"Failed to acquire wakeup inhibitor "
112 "lock, blocking suspend.\n");
116 if (_inhib->release(L4VBUS_INHIBITOR_SUSPEND))
118 "Failed to release suspend inhibitor lock.\n");
121 case L4VBUS_INHIBITOR_SHUTDOWN:
124 if (_inhib->release(L4VBUS_INHIBITOR_SHUTDOWN))
126 "Failed to release shutdown inhibitor lock.\n");
129 case L4VBUS_INHIBITOR_WAKEUP:
131 if (_inhib->acquire(L4VBUS_INHIBITOR_SUSPEND, _reason))
133 Dbg::warn().printf(
"Failed to acquire suspend inhibitor "
134 "lock, blocking wakeup.\n");
138 if (_inhib->release(L4VBUS_INHIBITOR_WAKEUP))
140 "Failed to release wakeup inhibitor lock.\n");
144 Dbg::warn().printf(
"Unexpected pm event.\n");
151 virtual void suspend() = 0;
152 virtual void shutdown() = 0;
153 virtual void wakeup() = 0;
156 L4::Ipc::String<> _reason;
157 cxx::unique_ptr<L4Re::Util::Event> _event;
165class Pm_for_dm :
public Pm
168 Pm_for_dm(DM &dm, L4::Ipc::String<>
const &reason) : Pm(reason), _dm(dm)
171 void shutdown()
override
172 { _dm.shutdown_event(Shutdown_type::System_shutdown); }
173 void suspend()
override
174 { _dm.shutdown_event(Shutdown_type::System_suspend); }
175 void wakeup()
override
176 { _dm.shutdown_event(Shutdown_type::Running); }