This option allows you to look up a struct device from any of the
node labels that were attached to the devicetree node used to create
the device, etc.
This is helpful because node labels are a much more human-friendly set
of unique identifiers than the node names we are currently relying on
for use with device_get_binding(). Adding this infrastructure in the
device core allows anyone to make use of it without having to
replicate node label storage and search functions in various places in
the tree. The main use case, however, is for looking up devices by
node label in the shell.
Since there is a footprint penalty associated with storing the node
label metadata, leave this option disabled by default.
Signed-off-by: Martí Bolívar <mbolivar@amperecomputing.com>
Add a symbol to enable device power state constraints this
saves resources when this feature is not needed.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
Declare power state constraints for a device in devicetree.
It allows a map between device instances and power states that disable
their power. This information is used by a new API
(pm_policy_device_power_lock_put/get) that automically set/release
pm state constraints.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
This duplicates the functionality of device_is_ready.
Calls for z_device_is_ready are being done in kernel mode, so it is
safe to call its implementation directly.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
Namespaced the generated headers with `zephyr` to prevent
potential conflict with other headers.
Introduce a temporary Kconfig `LEGACY_GENERATED_INCLUDE_PATH`
that is enabled by default. This allows the developers to
continue the use of the old include paths for the time being
until it is deprecated and eventually removed. The Kconfig will
generate a build-time warning message, similar to the
`CONFIG_TIMER_RANDOM_GENERATOR`.
Updated the includes path of in-tree sources accordingly.
Most of the changes here are scripted, check the PR for more
info.
Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Close parentheses and braces in the reverse order they are opened.
Fixes commit f91d4731af ("pm: use braces for .pm_base inside anonymous
union initializer")
I have no idea how no compiler caught this!?
I tested very carefully with two different gcc versions and one clang
version and generated binaries are strictly identical before and after
this commit. Fix the code anyway because C macros are painful enough to
debug already, so no need to add more confusion.
Signed-off-by: Marc Herbert <marc.herbert@intel.com>
Currently, all devices are initialized at boot time (following their
level and priority order). This patch introduces deferred
initialization: by setting the property `zephyr,deferred-init` on a
device on the devicetree, Zephyr will not initialized the device.
To initialize such devices, one has to call `device_init()`.
Deferred initialization is done by grouping all deferred devices on a
different ELF section. In this way, there's no need to consume more
memory to keep track of deferred devices. When `device_init()` is
called, Zephyr will scan the deferred devices section and call the
initialization function for the matching device. As this scanning is
done only during deferred device initialization, its cost should be
bearable.
Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
Based on information from doc/develop/api/overview.rst, add current
version for some groups representing APIs, following the following
table:
- Experimental: 0.1.0
- Unstable: 0.8.0
- Stable: 1.0.0
Also based on doc/develop/api/overview.rst, add 'since' tag to the
groups.
Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Fixes commit 25173f71cd ("pm: device_runtime: Extend with synchronous
runtime PM")
Fixes compilation with gcc 4.2-based toolchain used by SOF for TGL
generation products. As seen in the error message below, that gcc
version requires braces for initialization of anonymous unions:
```
zephyr/soc/xtensa/intel_adsp/common/mem_window.c:62:
error: unknown field ‘pm_base’ specified in initializer
warning: missing braces around initializer
warning: (near initialization for ‘__device_dts_ord_66.<anonymous>’)
```
This is a well-known and recurring issue, see past example(s) in #68118
As the Zephyr build is deterministic, I could easily verify that this
commit makes zero .obj difference (when using the Zephyr SDK).
Signed-off-by: Marc Herbert <marc.herbert@intel.com>
In many cases suspending or resuming of a device is limited to
just a few register writes. Current solution assumes that those
operations may be blocking, asynchronous and take a lot of time.
Due to this assumption runtime PM API cannot be effectively used
from the interrupt context. Zephyr has few driver APIs which
can be used from an interrupt context and now use of runtime PM
is limited in those cases.
Patch introduces a new type of PM device - synchronous PM. If
device is specified as capable of synchronous PM operations then
device runtime getting and putting is executed in the critical
section. In that case, runtime API can be used from an interrupt
context. Additionally, this approach reduces RAM needed for
PM device (104 -> 20 bytes of RAM on ARM Cortex-M).
Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
The init_entry struct got modified to add a union with a non const dev
pointer in afc59112a9. Some old compiler (such as GCC 4) seems to
require a pair of brackets to correctly initialize the field in the
union. Add those brackets to the initializers in device.h and init.h to
maintain compatibility.
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
Add support for mutable devices. Mutable devices are those which
can be modified after declaration, in-place, in kernel mode.
In order for a device to be mutable, the following must be true
* `CONFIG_DEVICE_MUTABLE` must be y-selected
* the Devicetree bindings for the device must include
`mutable.yaml`
* the Devicetree node must include the `zephyr,mutable` property
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
HAS_DTS has become a redundant option. All Zephyr architectures now
select this option, meaning devicetree has become a de-facto
requirement. In fact, if any board does not provide a devicetree
source, the build system uses an empty stub, meaning the devicetree
machinery always runs.
Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
Because devices share the same underlying infrastructure with SYS_INIT,
the same levels have always been available. However, not all of them are
needed, and some are not even usable. For example, `EARLY` can't be used
because when initialized `z_device_state_init` has not been called yet.
`SMP` has never been used by device drivers, and it is now in question,
likely to be moved to SMP specific hooks. Finally, `APPLICATION` does
not make much sense in the context of Kernel devices. Note that of the 3
levels just mentioned, only one was actively tested (`APPLICATION`) by
Kernel tests, meaning others were likely never considered in the context
of devices.
This patch leaves `PRE_KERNEL_1`, `PRE_KERNEL_2` and `POST_KERNEL`
available to devices. Others have been deprecated, and will generate a
compiler warning if used.
Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
Add a sub-priority field to `Z_INIT_ENTRY_SECTION`, which is used to
ensure that multiple drivers running at the same init priority still
run in an order that respects their devicetree dependencies.
This is primarily useful when multiple instances of the same device are
instantiated that can depend on each other, for example power domains
and i2c muxes.
Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
Add a sub-priority field to `Z_INIT_ENTRY_SECTION`, which is used to
ensure that multiple drivers running at the same init priority still
run in an order that respects their devicetree dependencies.
This is primarily useful when multiple instances of the same device are
instantiated that can depend on each other, for example power domains
and i2c muxes.
Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
add explicit unsigned suffix to 'Z_DEVICE_MAX_NAME_LEN' macro, matching
it to return type of sizeof (size_t), thus the comparison operator '<='
has the same essential types, complying with required [misra-c2012-10.4]
rule which states; Both operands of an operator in which the usual
arithmetic conversions are performed shall have the same essential type
category.
Found as a coding guideline violation (Rule 10.4) by static code
scanning tool.
Note: Tested on STM32L5 Nucleo-144 board (stm32l552xx).
Signed-off-by: ferar alashkar <ferar.alashkar@gmail.com>
Device dependencies are not always required, so make them optional via
CONFIG_DEVICE_DEPS. When enabled, the gen_device_deps script will run so
that dependencies are collected and part of the final image. Related
APIs will be also made available. Since device dependencies are used in
just a few places (power domains), disable the feature by default. When
not enabled, a second linking pass will not be required.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Rename the Kconfig option to be in line with recent renamings in device
handles/dependencies.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Rename the device dependencies array variable to use the "deps" name, in
line with latest renamings in device.h
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Rename struct device `handles` member to `deps`, in line with previous
renamings in the device API.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Rename multiple internal device macros to use the DEVICE_DEPS naming, so
that it is clear they belong to the device dependencies APIs.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
These macros are used internally by the device dependencies functions.
There's no need to expose them publicly, so prefix them with Z_ and add
them under INTERNAL_HIDDEN docs section.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Use the "device_deps" naming scheme to emphasize we are storing device
dependencies. The fact we are using device handles to store them is an
implementation detail.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Rename the gen_handles script and all of its references/associated files
to gen_device_deps. The new new makes things more clear, because the
script just take care of generating, for each device, an array of device
dependencies. While device handles are used internally to store this
information, it is in reality an implementation detail.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Until now iterable sections APIs have been part of the toolchain
(common) headers. They are not strictly related to a toolchain, they
just rely on linker providing support for sections. Most files relied on
indirect includes to access the API, now, it is included as needed.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Use iterable sections to handle devices list. This simplifies devices
implementation by using standard APIs.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
By using the __weak attribute with the macro `Z_DEVICE_HANDLES_DEFINE`
C++ throws the error "weak declaration must be public". This change
adds the keyword extern if the macro is included in a C++ source
file.
Signed-off-by: Victor Chavez <chavez-bermudez@fh-aachen.de>
The macro `Z_DEVICE_INIT` is not compatible with C++ due to
initialization order of the struct device. This commit fixes
the initialization for compatiblity with C++.
Signed-off-by: Victor Chavez <chavez-bermudez@fh-aachen.de>
Some devices do not need to perform any initialization, so allow the
init function to be NULL. In this case, the initialization code will
just mark the device as initialized, i.e. ready.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
__noasan attribute was accidentally removed by
a5fd0d184a. Add it back as it is causing
some address sanitizer issues when using the LLVM toolchain.
Details on why this is needed can be found in
74cc534758.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
The init infrastructure, found in `init.h`, is currently used by:
- `SYS_INIT`: to call functions before `main`
- `DEVICE_*`: to initialize devices
They are all sorted according to an initialization level + a priority.
`SYS_INIT` calls are really orthogonal to devices, however, the required
function signature requires a `const struct device *dev` as a first
argument. The only reason for that is because the same init machinery is
used by devices, so we have something like:
```c
struct init_entry {
int (*init)(const struct device *dev);
/* only set by DEVICE_*, otherwise NULL */
const struct device *dev;
}
```
As a result, we end up with such weird/ugly pattern:
```c
static int my_init(const struct device *dev)
{
/* always NULL! add ARG_UNUSED to avoid compiler warning */
ARG_UNUSED(dev);
...
}
```
This is really a result of poor internals isolation. This patch proposes
a to make init entries more flexible so that they can accept sytem
initialization calls like this:
```c
static int my_init(void)
{
...
}
```
This is achieved using a union:
```c
union init_function {
/* for SYS_INIT, used when init_entry.dev == NULL */
int (*sys)(void);
/* for DEVICE*, used when init_entry.dev != NULL */
int (*dev)(const struct device *dev);
};
struct init_entry {
/* stores init function (either for SYS_INIT or DEVICE*)
union init_function init_fn;
/* stores device pointer for DEVICE*, NULL for SYS_INIT. Allows
* to know which union entry to call.
*/
const struct device *dev;
}
```
This solution **does not increase ROM usage**, and allows to offer clean
public APIs for both SYS_INIT and DEVICE*. Note that however, init
machinery keeps a coupling with devices.
**NOTE**: This is a breaking change! All `SYS_INIT` functions will need
to be converted to the new signature. See the script offered in the
following commit.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
init: convert SYS_INIT functions to the new signature
Conversion scripted using scripts/utils/migrate_sys_init.py.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
manifest: update projects for SYS_INIT changes
Update modules with updated SYS_INIT calls:
- hal_ti
- lvgl
- sof
- TraceRecorderSource
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
tests: devicetree: devices: adjust test
Adjust test according to the recently introduced SYS_INIT
infrastructure.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
tests: kernel: threads: adjust SYS_INIT call
Adjust to the new signature: int (*init_fn)(void);
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
With the addition of #42105, `DEVICE_HANDLE_NULL` can exist in the
supported devices handle array. Stop counting supported devices if
this value is reached, as there are no more valid devices.
Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
Device state (struct device_state) was not aligned, required since all
states are gathered together in the z_devstate section. This was causing
boot failures on certain platforms depending on the layout of the struct
device_state.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
After b5f3cf8006 some platforms
(qemu_riscv32_xip) are not able to boot. Re-introduce the bit field for
init_res, using `unsigned int` (valids are signed/unsigned int, and
bool).
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Init result is stored as an 8-bit unsigned integer, so let's use
uint8_t. Docs have been clarified as well.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Formatting in the file was inconsistent, results obtained using
clang-format (80 cols), with some minor tweaks.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
- Align to 80cols
- Fix some incorrect `@p` usages
- Use `@ref foo` to let Doxygen generate references to structs instead
of using <tt>...</tt>
- Use `@ref struct.field` to reference struct fields
- Use Markdown notation for literals
- use func_name()/MACRO_NAME() to let Doxygen generate references
automatically without `@ref`
- Fix some minor typos/formatting issues
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
struct device.pm was not exposed in the docs, make it visible to Doxygen
and document it is conditional to CONFIG_PM_DEVICE=y.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
The input parameter is a device identifier, not a name. Some macros are
used for all type of devices, DT and non-DT, so adjusted documentation
to be more precise where appropriated.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Some Doxygen groups do not belong to a specific header, they are used to
group multiple other sub-groups defined in other headers. For this
purpose we have the groups.dox file, there's no need to use device.h for
that.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Instead of hardcoding alignment size for pass 2 device handles, use
Z_DECL_ALIGN. This makes sure gen_handles.py is always in sync with the
type defined in device.h. The build assert in device.h can be removed as
a result, since we do not hardcode handles size anywhere else.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
The dev_id is already unique for DT devices (dts_ord_XX), there's no
need to rely on the full node identifier.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>