Zephyr API Documentation 4.2.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
7#ifndef ZEPHYR_INCLUDE_PM_STATE_H_
8#define ZEPHYR_INCLUDE_PM_STATE_H_
9
10#include <zephyr/sys/util.h>
11#include <zephyr/devicetree.h>
12#include <errno.h>
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
24
111
169
188
198
200
208#define Z_DT_PHANDLE_01(node_id, prop, idx) \
209 COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(DT_PHANDLE_BY_IDX(node_id, prop, idx)), \
210 (1), (0))
211
221#define Z_PM_STATE_INFO_FROM_DT_CPU(i, node_id) \
222 COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(DT_PHANDLE_BY_IDX(node_id, cpu_power_states, i)), \
223 (PM_STATE_INFO_DT_INIT(DT_PHANDLE_BY_IDX(node_id, cpu_power_states, i)),), ())
224
234#define Z_PM_STATE_FROM_DT_CPU(i, node_id) \
235 COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(DT_PHANDLE_BY_IDX(node_id, cpu_power_states, i)), \
236 (PM_STATE_DT_INIT(DT_PHANDLE_BY_IDX(node_id, cpu_power_states, i)),), ())
237
239
246#define PM_STATE_INFO_DT_INIT(node_id) \
247 { \
248 .state = PM_STATE_DT_INIT(node_id), \
249 .substate_id = DT_PROP_OR(node_id, substate_id, 0), \
250 .min_residency_us = DT_PROP_OR(node_id, min_residency_us, 0), \
251 .exit_latency_us = DT_PROP_OR(node_id, exit_latency_us, 0), \
252 .pm_device_disabled = DT_PROP(node_id, zephyr_pm_device_disabled), \
253 }
254
261#define PM_STATE_DT_INIT(node_id) \
262 DT_ENUM_IDX(node_id, power_state_name)
263
271#define DT_NUM_CPU_POWER_STATES(node_id) \
272 COND_CODE_1(DT_NODE_HAS_PROP(node_id, cpu_power_states), \
273 (DT_FOREACH_PROP_ELEM_SEP(node_id, cpu_power_states, Z_DT_PHANDLE_01, (+))), \
274 (0))
275
320#define PM_STATE_INFO_LIST_FROM_DT_CPU(node_id) \
321 { \
322 LISTIFY(DT_PROP_LEN_OR(node_id, cpu_power_states, 0), \
323 Z_PM_STATE_INFO_FROM_DT_CPU, (), node_id) \
324 }
325
367#define PM_STATE_LIST_FROM_DT_CPU(node_id) \
368 { \
369 LISTIFY(DT_PROP_LEN_OR(node_id, cpu_power_states, 0), \
370 Z_PM_STATE_FROM_DT_CPU, (), node_id) \
371 }
372
378#define PM_STATE_CONSTRAINT_INIT(node_id) \
379 { \
380 .state = PM_STATE_DT_INIT(node_id), \
381 .substate_id = DT_PROP_OR(node_id, substate_id, 0), \
382 }
383
384#define Z_PM_STATE_CONSTRAINT_REF(node_id, phandle, idx) \
385 PM_STATE_CONSTRAINT_INIT(DT_PHANDLE_BY_IDX(node_id, phandle, idx))
386
387#define Z_PM_STATE_CONSTRAINTS_LIST_NAME(node_id, phandles) \
388 _CONCAT_4(node_id, _, phandles, _constraints)
389
399#define PM_STATE_CONSTRAINTS_LIST_DEFINE(node_id, prop) \
400 struct pm_state_constraint Z_PM_STATE_CONSTRAINTS_LIST_NAME(node_id, prop)[] = \
401 { \
402 DT_FOREACH_PROP_ELEM_SEP(node_id, prop, Z_PM_STATE_CONSTRAINT_REF, (,)) \
403 }
404
416#define PM_STATE_CONSTRAINTS_GET(node_id, prop) \
417 { \
418 .list = Z_PM_STATE_CONSTRAINTS_LIST_NAME(node_id, prop), \
419 .count = DT_PROP_LEN(node_id, prop), \
420 }
421
422#if defined(CONFIG_PM) || defined(__DOXYGEN__)
432
445
454
455
464int pm_state_from_str(const char *name, enum pm_state *out);
465
474bool pm_state_in_constraints(const struct pm_state_constraints *constraints,
475 const struct pm_state_constraint match);
476
480
481#else /* CONFIG_PM */
482
483static inline uint8_t pm_state_cpu_get_all(uint8_t cpu, const struct pm_state_info **states)
484{
485 ARG_UNUSED(cpu);
486 ARG_UNUSED(states);
487
488 return 0;
489}
490
491static inline const struct pm_state_info *pm_state_get(uint8_t cpu,
492 enum pm_state state,
494{
495 ARG_UNUSED(cpu);
496 ARG_UNUSED(state);
497 ARG_UNUSED(substate_id);
498
499 return NULL;
500}
501
502static inline bool pm_state_in_constraints(struct pm_state_constraints *constraints,
503 struct pm_state_constraint match)
504{
505 ARG_UNUSED(constraints);
506 ARG_UNUSED(match);
507
508 return false;
509}
510#endif /* CONFIG_PM */
511
512#ifdef __cplusplus
513}
514#endif
515
516#endif
Devicetree main header.
System error numbers.
pm_state
Power management state.
Definition state.h:28
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:107
@ PM_STATE_STANDBY
Standby state.
Definition state.h:71
@ PM_STATE_SUSPEND_TO_RAM
Suspend to ram state.
Definition state.h:83
@ PM_STATE_ACTIVE
Runtime active state.
Definition state.h:36
@ PM_STATE_RUNTIME_IDLE
Runtime idle state.
Definition state.h:47
@ PM_STATE_SUSPEND_TO_IDLE
Suspend to idle state.
Definition state.h:59
@ PM_STATE_COUNT
Number of power management states (internal use)
Definition state.h:109
@ PM_STATE_SUSPEND_TO_DISK
Suspend to disk state.
Definition state.h:96
#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:174
uint8_t substate_id
Power management sub-state.
Definition state.h:186
enum pm_state state
Power management state.
Definition state.h:180
Collection of multiple power state constraints.
Definition state.h:192
struct pm_state_constraint * list
Array of power state constraints.
Definition state.h:194
size_t count
Number of constraints in the list.
Definition state.h:196
Information about a power management state.
Definition state.h:115
uint8_t substate_id
Some platforms have multiple states that map to one Zephyr power state.
Definition state.h:143
uint32_t min_residency_us
Minimum residency duration in microseconds.
Definition state.h:160
uint32_t exit_latency_us
Worst case latency in microseconds required to exit the idle state.
Definition state.h:167
bool pm_device_disabled
Whether or not this state triggers device power management.
Definition state.h:152
enum pm_state state
Definition state.h:116
Misc utilities.