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
175
194
204
206
214#define Z_DT_PHANDLE_01(node_id, prop, idx) \
215 COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(DT_PHANDLE_BY_IDX(node_id, prop, idx)), \
216 (1), (0))
217
227#define Z_PM_STATE_INFO_FROM_DT_CPU(i, node_id) \
228 COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(DT_PHANDLE_BY_IDX(node_id, cpu_power_states, i)), \
229 (PM_STATE_INFO_DT_INIT(DT_PHANDLE_BY_IDX(node_id, cpu_power_states, i)),), ())
230
240#define Z_PM_STATE_FROM_DT_CPU(i, node_id) \
241 COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(DT_PHANDLE_BY_IDX(node_id, cpu_power_states, i)), \
242 (PM_STATE_DT_INIT(DT_PHANDLE_BY_IDX(node_id, cpu_power_states, i)),), ())
243
245
252#define PM_STATE_INFO_DT_INIT(node_id) \
253 { \
254 .state = PM_STATE_DT_INIT(node_id), \
255 .substate_id = DT_PROP_OR(node_id, substate_id, 0), \
256 .min_residency_us = DT_PROP_OR(node_id, min_residency_us, 0), \
257 .exit_latency_us = DT_PROP_OR(node_id, exit_latency_us, 0), \
258 .pm_device_disabled = DT_PROP(node_id, zephyr_pm_device_disabled), \
259 }
260
267#define PM_STATE_DT_INIT(node_id) \
268 DT_ENUM_IDX(node_id, power_state_name)
269
277#define DT_NUM_CPU_POWER_STATES(node_id) \
278 COND_CODE_1(DT_NODE_HAS_PROP(node_id, cpu_power_states), \
279 (DT_FOREACH_PROP_ELEM_SEP(node_id, cpu_power_states, Z_DT_PHANDLE_01, (+))), \
280 (0))
281
326#define PM_STATE_INFO_LIST_FROM_DT_CPU(node_id) \
327 { \
328 LISTIFY(DT_PROP_LEN_OR(node_id, cpu_power_states, 0), \
329 Z_PM_STATE_INFO_FROM_DT_CPU, (), node_id) \
330 }
331
373#define PM_STATE_LIST_FROM_DT_CPU(node_id) \
374 { \
375 LISTIFY(DT_PROP_LEN_OR(node_id, cpu_power_states, 0), \
376 Z_PM_STATE_FROM_DT_CPU, (), node_id) \
377 }
378
384#define PM_STATE_CONSTRAINT_INIT(node_id) \
385 { \
386 .state = PM_STATE_DT_INIT(node_id), \
387 .substate_id = DT_PROP_OR(node_id, substate_id, 0), \
388 }
389
390#define Z_PM_STATE_CONSTRAINT_REF(node_id, phandle, idx) \
391 PM_STATE_CONSTRAINT_INIT(DT_PHANDLE_BY_IDX(node_id, phandle, idx))
392
393#define Z_PM_STATE_CONSTRAINTS_LIST_NAME(node_id, phandles) \
394 CONCAT(node_id, _, phandles, _constraints)
395
405#define PM_STATE_CONSTRAINTS_LIST_DEFINE(node_id, prop) \
406 struct pm_state_constraint Z_PM_STATE_CONSTRAINTS_LIST_NAME(node_id, prop)[] = \
407 { \
408 DT_FOREACH_PROP_ELEM_SEP(node_id, prop, Z_PM_STATE_CONSTRAINT_REF, (,)) \
409 }
410
422#define PM_STATE_CONSTRAINTS_GET(node_id, prop) \
423 { \
424 .list = Z_PM_STATE_CONSTRAINTS_LIST_NAME(node_id, prop), \
425 .count = DT_PROP_LEN(node_id, prop), \
426 }
427
428#if defined(CONFIG_PM) || defined(__DOXYGEN__)
438
451
460
461
470int pm_state_from_str(const char *name, enum pm_state *out);
471
480bool pm_state_in_constraints(const struct pm_state_constraints *constraints,
481 const struct pm_state_constraint match);
482
486
487#else /* CONFIG_PM */
488
489static inline uint8_t pm_state_cpu_get_all(uint8_t cpu, const struct pm_state_info **states)
490{
491 ARG_UNUSED(cpu);
492 ARG_UNUSED(states);
493
494 return 0;
495}
496
497static inline const struct pm_state_info *pm_state_get(uint8_t cpu,
498 enum pm_state state,
500{
501 ARG_UNUSED(cpu);
502 ARG_UNUSED(state);
503 ARG_UNUSED(substate_id);
504
505 return NULL;
506}
507
508static inline bool pm_state_in_constraints(const struct pm_state_constraints *constraints,
509 const struct pm_state_constraint match)
510{
511 ARG_UNUSED(constraints);
512 ARG_UNUSED(match);
513
514 return false;
515}
516#endif /* CONFIG_PM */
517
518#ifdef __cplusplus
519}
520#endif
521
522#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:180
uint8_t substate_id
Power management sub-state.
Definition state.h:192
enum pm_state state
Power management state.
Definition state.h:186
Collection of multiple power state constraints.
Definition state.h:198
struct pm_state_constraint * list
Array of power state constraints.
Definition state.h:200
size_t count
Number of constraints in the list.
Definition state.h:202
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:149
uint32_t min_residency_us
Minimum residency duration in microseconds.
Definition state.h:166
uint32_t exit_latency_us
Worst case latency in microseconds required to exit the idle state.
Definition state.h:173
bool pm_device_disabled
Whether or not this state triggers device power management.
Definition state.h:158
enum pm_state state
Definition state.h:122
Misc utilities.