forked from zephyrproject-rtos/zephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolicy.h
329 lines (287 loc) · 8.19 KB
/
policy.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
/*
* Copyright (c) 2018 Intel Corporation.
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_INCLUDE_PM_POLICY_H_
#define ZEPHYR_INCLUDE_PM_POLICY_H_
#include <stdbool.h>
#include <stdint.h>
#include <zephyr/device.h>
#include <zephyr/pm/state.h>
#include <zephyr/sys/slist.h>
#include <zephyr/toolchain.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief System Power Management Policy API
* @defgroup subsys_pm_sys_policy Policy
* @ingroup subsys_pm_sys
* @{
*/
/**
* @brief Callback to notify when maximum latency changes.
*
* @param latency New maximum latency. Positive value represents latency in
* microseconds. SYS_FOREVER_US value lifts the latency constraint. Other values
* are forbidden.
*/
typedef void (*pm_policy_latency_changed_cb_t)(int32_t latency);
/**
* @brief Latency change subscription.
*
* @note All fields in this structure are meant for private usage.
*/
struct pm_policy_latency_subscription {
/** @cond INTERNAL_HIDDEN */
sys_snode_t node;
pm_policy_latency_changed_cb_t cb;
/** @endcond */
};
/**
* @brief Latency request.
*
* @note All fields in this structure are meant for private usage.
*/
struct pm_policy_latency_request {
/** @cond INTERNAL_HIDDEN */
sys_snode_t node;
uint32_t value_us;
/** @endcond */
};
/**
* @brief Event.
*
* @note All fields in this structure are meant for private usage.
*/
struct pm_policy_event {
/** @cond INTERNAL_HIDDEN */
sys_snode_t node;
uint32_t value_cyc;
/** @endcond */
};
/** @cond INTERNAL_HIDDEN */
/**
* @brief Function to get the next PM state
*
* This function is called by the power subsystem when the system is
* idle and returns the most appropriate state based on the number of
* ticks to the next event.
*
* @param cpu CPU index.
* @param ticks The number of ticks to the next scheduled event.
*
* @return The power state the system should use for the given cpu. The function
* will return NULL if system should remain into PM_STATE_ACTIVE.
*/
const struct pm_state_info *pm_policy_next_state(uint8_t cpu, int32_t ticks);
/** @endcond */
/** Special value for 'all substates'. */
#define PM_ALL_SUBSTATES (UINT8_MAX)
#if defined(CONFIG_PM) || defined(__DOXYGEN__)
/**
* @brief Increase a power state lock counter.
*
* A power state will not be allowed on the first call of
* pm_policy_state_lock_get(). Subsequent calls will just increase a reference
* count, thus meaning this API can be safely used concurrently. A state will
* be allowed again after pm_policy_state_lock_put() is called as many times as
* pm_policy_state_lock_get().
*
* Note that the PM_STATE_ACTIVE state is always allowed, so calling this API
* with PM_STATE_ACTIVE will have no effect.
*
* @param state Power state.
* @param substate_id Power substate ID. Use PM_ALL_SUBSTATES to affect all the
* substates in the given power state.
*
* @see pm_policy_state_lock_put()
*/
void pm_policy_state_lock_get(enum pm_state state, uint8_t substate_id);
/**
* @brief Decrease a power state lock counter.
*
* @param state Power state.
* @param substate_id Power substate ID. Use PM_ALL_SUBSTATES to affect all the
* substates in the given power state.
*
* @see pm_policy_state_lock_get()
*/
void pm_policy_state_lock_put(enum pm_state state, uint8_t substate_id);
/**
* @brief Check if a power state lock is active (not allowed).
*
* @param state Power state.
* @param substate_id Power substate ID. Use PM_ALL_SUBSTATES to affect all the
* substates in the given power state.
*
* @retval true if power state lock is active.
* @retval false if power state lock is not active.
*/
bool pm_policy_state_lock_is_active(enum pm_state state, uint8_t substate_id);
/**
* @brief Add a new latency requirement.
*
* The system will not enter any power state that would make the system to
* exceed the given latency value.
*
* @param req Latency request.
* @param value_us Maximum allowed latency in microseconds.
*/
void pm_policy_latency_request_add(struct pm_policy_latency_request *req,
uint32_t value_us);
/**
* @brief Update a latency requirement.
*
* @param req Latency request.
* @param value_us New maximum allowed latency in microseconds.
*/
void pm_policy_latency_request_update(struct pm_policy_latency_request *req,
uint32_t value_us);
/**
* @brief Remove a latency requirement.
*
* @param req Latency request.
*/
void pm_policy_latency_request_remove(struct pm_policy_latency_request *req);
/**
* @brief Subscribe to maximum latency changes.
*
* @param req Subscription request.
* @param cb Callback function (NULL to disable).
*/
void pm_policy_latency_changed_subscribe(struct pm_policy_latency_subscription *req,
pm_policy_latency_changed_cb_t cb);
/**
* @brief Unsubscribe to maximum latency changes.
*
* @param req Subscription request.
*/
void pm_policy_latency_changed_unsubscribe(struct pm_policy_latency_subscription *req);
/**
* @brief Register an event.
*
* Events in the power-management policy context are defined as any source that
* will wake up the system at a known time in the future. By registering such
* event, the policy manager will be able to decide whether certain power states
* are worth entering or not.
*
* @note It is mandatory to unregister events once they have happened by using
* pm_policy_event_unregister(). Not doing so is an API contract violation,
* because the system would continue to consider them as valid events in the
* *far* future, that is, after the cycle counter rollover.
*
* @param evt Event.
* @param time_us When the event will occur, in microseconds from now.
*
* @see pm_policy_event_unregister
*/
void pm_policy_event_register(struct pm_policy_event *evt, uint32_t time_us);
/**
* @brief Update an event.
*
* @param evt Event.
* @param time_us When the event will occur, in microseconds from now.
*
* @see pm_policy_event_register
*/
void pm_policy_event_update(struct pm_policy_event *evt, uint32_t time_us);
/**
* @brief Unregister an event.
*
* @param evt Event.
*
* @see pm_policy_event_register
*/
void pm_policy_event_unregister(struct pm_policy_event *evt);
/**
* @brief Increase power state locks.
*
* Set power state locks in all power states that disable power in the given
* device.
*
* @param dev Device reference.
*
* @see pm_policy_device_power_lock_put()
* @see pm_policy_state_lock_get()
*/
void pm_policy_device_power_lock_get(const struct device *dev);
/**
* @brief Decrease power state locks.
*
* Remove power state locks in all power states that disable power in the given
* device.
*
* @param dev Device reference.
*
* @see pm_policy_device_power_lock_get()
* @see pm_policy_state_lock_put()
*/
void pm_policy_device_power_lock_put(const struct device *dev);
#else
static inline void pm_policy_state_lock_get(enum pm_state state, uint8_t substate_id)
{
ARG_UNUSED(state);
ARG_UNUSED(substate_id);
}
static inline void pm_policy_state_lock_put(enum pm_state state, uint8_t substate_id)
{
ARG_UNUSED(state);
ARG_UNUSED(substate_id);
}
static inline bool pm_policy_state_lock_is_active(enum pm_state state, uint8_t substate_id)
{
ARG_UNUSED(state);
ARG_UNUSED(substate_id);
return false;
}
static inline void pm_policy_latency_request_add(
struct pm_policy_latency_request *req, uint32_t value_us)
{
ARG_UNUSED(req);
ARG_UNUSED(value_us);
}
static inline void pm_policy_latency_request_update(
struct pm_policy_latency_request *req, uint32_t value_us)
{
ARG_UNUSED(req);
ARG_UNUSED(value_us);
}
static inline void pm_policy_latency_request_remove(
struct pm_policy_latency_request *req)
{
ARG_UNUSED(req);
}
static inline void pm_policy_event_register(struct pm_policy_event *evt,
uint32_t time_us)
{
ARG_UNUSED(evt);
ARG_UNUSED(time_us);
}
static inline void pm_policy_event_update(struct pm_policy_event *evt,
uint32_t time_us)
{
ARG_UNUSED(evt);
ARG_UNUSED(time_us);
}
static inline void pm_policy_event_unregister(struct pm_policy_event *evt)
{
ARG_UNUSED(evt);
}
static inline void pm_policy_device_power_lock_get(const struct device *dev)
{
ARG_UNUSED(dev);
}
static inline void pm_policy_device_power_lock_put(const struct device *dev)
{
ARG_UNUSED(dev);
}
#endif /* CONFIG_PM */
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* ZEPHYR_INCLUDE_PM_POLICY_H_ */