Zephyr Project API 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
state.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Intel corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
12
13#ifndef ZEPHYR_INCLUDE_PM_STATE_H_
14#define ZEPHYR_INCLUDE_PM_STATE_H_
15
16#include <zephyr/sys/util.h>
17#include <zephyr/devicetree.h>
18#include <errno.h>
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
30
117
176
195
205
207
215#define Z_DT_PHANDLE_01(node_id, prop, idx) \
216 COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(DT_PHANDLE_BY_IDX(node_id, prop, idx)), \
217 (1), (0))
218
228#define Z_PM_STATE_INFO_FROM_DT_CPU(i, node_id) \
229 COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(DT_PHANDLE_BY_IDX(node_id, cpu_power_states, i)), \
230 (PM_STATE_INFO_DT_INIT(DT_PHANDLE_BY_IDX(node_id, cpu_power_states, i)),), ())
231
241#define Z_PM_STATE_FROM_DT_CPU(i, node_id) \
242 COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(DT_PHANDLE_BY_IDX(node_id, cpu_power_states, i)), \
243 (PM_STATE_DT_INIT(DT_PHANDLE_BY_IDX(node_id, cpu_power_states, i)),), ())
244
246
253#define PM_STATE_INFO_DT_INIT(node_id) \
254 { \
255 .state = PM_STATE_DT_INIT(node_id), \
256 .substate_id = DT_PROP_OR(node_id, substate_id, 0), \
257 .min_residency_us = DT_PROP_OR(node_id, min_residency_us, 0), \
258 .exit_latency_us = DT_PROP_OR(node_id, exit_latency_us, 0), \
259 .pm_device_disabled = DT_PROP(node_id, zephyr_pm_device_disabled), \
260 }
261
268#define PM_STATE_DT_INIT(node_id) \
269 DT_ENUM_IDX(node_id, power_state_name)
270
278#define DT_NUM_CPU_POWER_STATES(node_id) \
279 COND_CODE_1(DT_NODE_HAS_PROP(node_id, cpu_power_states), \
280 (DT_FOREACH_PROP_ELEM_SEP(node_id, cpu_power_states, Z_DT_PHANDLE_01, (+))), \
281 (0))
282
327#define PM_STATE_INFO_LIST_FROM_DT_CPU(node_id) \
328 { \
329 LISTIFY(DT_PROP_LEN_OR(node_id, cpu_power_states, 0), \
330 Z_PM_STATE_INFO_FROM_DT_CPU, (), node_id) \
331 }
332
374#define PM_STATE_LIST_FROM_DT_CPU(node_id) \
375 { \
376 LISTIFY(DT_PROP_LEN_OR(node_id, cpu_power_states, 0), \
377 Z_PM_STATE_FROM_DT_CPU, (), node_id) \
378 }
379
385#define PM_STATE_CONSTRAINT_INIT(node_id) \
386 { \
387 .state = PM_STATE_DT_INIT(node_id), \
388 .substate_id = DT_PROP_OR(node_id, substate_id, 0), \
389 }
390
391#define Z_PM_STATE_CONSTRAINT_REF(node_id, phandle, idx) \
392 PM_STATE_CONSTRAINT_INIT(DT_PHANDLE_BY_IDX(node_id, phandle, idx))
393
394#define Z_PM_STATE_CONSTRAINTS_LIST_NAME(node_id, phandles) \
395 CONCAT(node_id, _, phandles, _constraints)
396
406#define PM_STATE_CONSTRAINTS_LIST_DEFINE(node_id, prop) \
407 struct pm_state_constraint Z_PM_STATE_CONSTRAINTS_LIST_NAME(node_id, prop)[] = \
408 { \
409 DT_FOREACH_PROP_ELEM_SEP(node_id, prop, Z_PM_STATE_CONSTRAINT_REF, (,)) \
410 }
411
423#define PM_STATE_CONSTRAINTS_GET(node_id, prop) \
424 { \
425 .list = Z_PM_STATE_CONSTRAINTS_LIST_NAME(node_id, prop), \
426 .count = DT_PROP_LEN(node_id, prop), \
427 }
428
429#if defined(CONFIG_PM) || defined(__DOXYGEN__)
439
452
461
462
471int pm_state_from_str(const char *name, enum pm_state *out);
472
481bool pm_state_in_constraints(const struct pm_state_constraints *constraints,
482 const struct pm_state_constraint match);
483
487
488#else /* CONFIG_PM */
489
490static inline uint8_t pm_state_cpu_get_all(uint8_t cpu, const struct pm_state_info **states)
491{
492 ARG_UNUSED(cpu);
493 ARG_UNUSED(states);
494
495 return 0;
496}
497
498static inline const struct pm_state_info *pm_state_get(uint8_t cpu,
499 enum pm_state state,
501{
502 ARG_UNUSED(cpu);
503 ARG_UNUSED(state);
504 ARG_UNUSED(substate_id);
505
506 return NULL;
507}
508
509static inline bool pm_state_in_constraints(const struct pm_state_constraints *constraints,
510 const struct pm_state_constraint match)
511{
512 ARG_UNUSED(constraints);
513 ARG_UNUSED(match);
514
515 return false;
516}
517#endif /* CONFIG_PM */
518
519#ifdef __cplusplus
520}
521#endif
522
523#endif
Devicetree main header.
System error numbers.
pm_state
Power management state.
Definition state.h:34
bool pm_state_in_constraints(const struct pm_state_constraints *constraints, const struct pm_state_constraint match)
Check if a power management constraint matches any in a set of constraints.
uint8_t pm_state_cpu_get_all(uint8_t cpu, const struct pm_state_info **states)
Obtain information about all supported states by a CPU.
const struct pm_state_info * pm_state_get(uint8_t cpu, enum pm_state state, uint8_t substate_id)
Get power state structure.
int pm_state_from_str(const char *name, enum pm_state *out)
Parse a string and convert it to a pm_state enum value.
const char * pm_state_to_str(enum pm_state state)
Convert a pm_state enum value to its string representation.
@ PM_STATE_SOFT_OFF
Soft off state.
Definition state.h:113
@ PM_STATE_STANDBY
Standby state.
Definition state.h:77
@ PM_STATE_SUSPEND_TO_RAM
Suspend to ram state.
Definition state.h:89
@ PM_STATE_ACTIVE
Runtime active state.
Definition state.h:42
@ PM_STATE_RUNTIME_IDLE
Runtime idle state.
Definition state.h:53
@ PM_STATE_SUSPEND_TO_IDLE
Suspend to idle state.
Definition state.h:65
@ PM_STATE_COUNT
Number of power management states (internal use).
Definition state.h:115
@ PM_STATE_SUSPEND_TO_DISK
Suspend to disk state.
Definition state.h:102
#define NULL
Definition iar_missing_defs.h:20
state
Definition parser_state.h:29
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
Information needed to be able to reference a power state as a constraint on some device or system fun...
Definition state.h:181
uint8_t substate_id
Power management sub-state.
Definition state.h:193
enum pm_state state
Power management state.
Definition state.h:187
Collection of multiple power state constraints.
Definition state.h:199
struct pm_state_constraint * list
Array of power state constraints.
Definition state.h:201
size_t count
Number of constraints in the list.
Definition state.h:203
Information about a power management state.
Definition state.h:121
uint8_t substate_id
Some platforms have multiple states that map to one Zephyr power state.
Definition state.h:150
uint32_t min_residency_us
Minimum residency duration in microseconds.
Definition state.h:167
uint32_t exit_latency_us
Worst case latency in microseconds required to exit the idle state.
Definition state.h:174
bool pm_device_disabled
Whether or not this state triggers device power management.
Definition state.h:159
enum pm_state state
Power management state.
Definition state.h:123
Misc utilities.