Commit graph

187 commits

Author SHA1 Message Date
Gerard Marull-Paretas 82d7d3c5c9 pm: rename pm_control(_fn) to (pm_)action_cb
- Rename to "action" to make its purpose more clear
- Use the _cb suffix to align with naming used for callbacks in other
  areas.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-10-14 07:55:55 -04:00
Gerard Marull-Paretas 3ca6d9503c pm: move control callback to pm_device
Move PM specific callback to the pm_device structure.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-10-14 07:55:55 -04:00
Martí Bolívar a627666e06 device: add fudge factor for handle padding
When CONFIG_USERSPACE is enabled, the ELF file from linker pass 1 is
used to create a hash table that identifies kernel objects by address.
We therefore can't allow the size of any object in the pass 2 ELF to
change in a way that would change those addresses, or we would create
a garbage hash table.

Simultaneously (and regardless of CONFIG_USERSPACE's value),
gen_handles.py must transform arrays of handles from their pass 1
values to their pass 2 values; see the file's docstring for more
details on that transformation.

The way this works is that gen_handles.py just pads out each pass 2
array so its length is the same as its pass 1 value. The padding value
is a repeated run of DEVICE_HANDLE_ENDS values. This value is the
terminator which we look for at runtime in places like
device_required_handles_get(), so there must be at least one, and we
error out in gen_handles.py if there's no room in the pass 2 array for
at least one such value. (If there is extra room, we just keep
inserting extra DEVICE_HANDLE_ENDS values to pad the array to its
original length.)

However, it is possible that a device has more direct dependencies in
the pass 2 handles array than its corresponding devicetree node had in
the pass 1 array. When this happens, users have no recourse, so that's
a potential showstopper.

To work around this possibility for now, add a new config option,
CONFIG_DEVICE_HANDLE_PADDING, whose value defaults to 0.

When nonzero, it is a count of padding handles that are inserted into
each device handles array. When gen_handles.py errors out due to lack
of room, its error message now tells the user how much to increase
CONFIG_DEVICE_HANDLE_PADDING by to work around the problem.

It looks like a real fix for this is to allocate kernel objects whose
addresses are required for hash tables in CONFIG_USERSPACE=y
configurations *before* the handle arrays. The handle arrays could
then be resized as needed in pass 2, which saves ROM by avoiding
unnecessary padding, and would avoid the need for
CONFIG_DEVICE_HANDLE_PADDING altogether.

However, this 'real fix' is not available and we are facing a deadline
to get a temporary solution in for Zephyr v2.7.0, so this is a good
enough workaround for now.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2021-09-30 21:37:59 -04:00
Martí Bolívar 2c99173d64 Revert "device: simplify structure of handles array"
This reverts commit ec331c6fe2.

Although it's a valid simplification under the assumption that we're
going to be padding the array out anyway, it would use extra ROM if we
fix the build system issues that are currently forcing gen_handles.py
to introduce extra padding in the handles arrays for linker pass 2.

On the (perhaps optimistic) assumption that we're going to fix the
build system, let's get rid of a commit that would get in the way. The
extra "complexity" in device_required_handles_get() is trivial.

This gets rid of a comment describing the linker passes, but the
structure of the comment is a bit misleading (and it contains
incorrect information for the results of pass 2: the terminator at the
end is DEVICE_HANDLE_ENDS, not DEVICE_HANDLE_NULL).

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2021-09-30 21:37:59 -04:00
Martí Bolívar 288bcb90da Revert "device: iterable supported devices"
This reverts commit 0c6588ff47.

It's not clear that the supported devices are being properly computed,
so let's revert this for v2.7.0 until we've had more time to think
it through.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2021-09-30 21:37:59 -04:00
Martí Bolívar b94a11f5d0 Revert "device: supported devices visitor API"
This reverts commit b01e41ccdd.

It's not clear that the supported devices are being properly computed,
so let's revert this for v2.7.0 until we've had more time to think
it through.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2021-09-30 21:37:59 -04:00
Gerard Marull-Paretas 4df1d15618 device: add DEVICE_DT_GET_OR_NULL utility macro
Add a new utility macro to obtain an optional reference to a device. If
the provided node_id is not enabled, the macro falls back to NULL.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-09-28 20:00:00 -04:00
Flavio Ceolin 3ad2b06f3d device: Fix device from handle function
This function was returning NULL for the last handle because of a
wrong comparison.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-09-09 19:43:48 -04:00
Gerard Marull-Paretas fe2014ae1f device: organize state and device initializers
Organize in a more logical flow the device state initializer and
the device initializer parts.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-08-27 09:06:51 -04:00
Gerard Marull-Paretas 90465fe537 device: improve device data initialization
The Z_DEVICE_STATE_DEFINE macro was conditioned by CONFIG_PM_DEVICE.
This is a problem if one day we have other conditional fields in the
device state field that need to be initialized. The approach has been
changed to have an always existing initializer for the PM field, that is
a no-op if device PM is not enabled.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-08-27 09:06:51 -04:00
Gerard Marull-Paretas a89cc157af pm: device: create struct pm_device initializer
Create a utility macro to initialize struct pm_device. The initializer
is kept in the pm/device.h header.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-08-27 09:06:51 -04:00
Gerard Marull-Paretas ae26b38870 pm: fix usage initialization
The usage field was being initialized using the ATOMIC_INIT macro,
however, it is just a uint32_t variable.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-08-27 09:06:51 -04:00
Gerard Marull-Paretas 9917de4a1b pm: fully initialize pm_device on Z_DEVICE_STATE_DEFINE
The initialization of the struct pm_device pm field found in the device
state can be statically initialized without the need of doing it at
runtime.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-08-27 09:06:51 -04:00
Daniel Leung 54c4525094 device: give device state variables a linker section
This groups the device state variables in their own linker section.
This is needed for demand paging as these variables are needed
during boot where the paging mechanism has not been initialized.
These variables need to be in the pinned section so they can
be accessed during boot.

Note that if device PM is not enabled, the device state variables
are put into BSS. So we need to pin these.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-08-26 21:16:22 -04:00
Jordan Yates b01e41ccdd device: supported devices visitor API
Adds an API to query and visit supported devices. Follows the example
set by the required devices API.

Implements #37793.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2021-08-25 19:43:54 -04:00
Jordan Yates 0c6588ff47 device: iterable supported devices
Add supported device information to the device `handles` array. This
enables API's to iterate over supported devices for power management
purposes.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2021-08-25 19:43:54 -04:00
Jordan Yates ec331c6fe2 device: simplify structure of handles array
Force the inclusion of a `DEVICE_HANDLE_SEP` at the end of the
devicetree dependency section of the array. This lets us simplify the
implementation of `device_required_handles_get`, as there is only one
symbol the section ends with.

This does not use any extra ROM as the array is padded out to the
original size with `DEVICE_HANDLE_ENDS` anyway.

Also adds a description of the array format where the array is
instantiated.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2021-08-25 19:43:54 -04:00
Jordan Yates b5c4140afb device: optimize handles array
Optimize the handles array by making the following observations:
 * The devicetree ordinal at index 0 in pass1 is discarded by
   gen_handles.py, and therefore does not appear in the pass2 array.
 * gen_handles.py does not need `DEVICE_HANDLE_ENDS` to determine the
   end of the handle array, as that information is present in the .elf.

Therefore, instead of replacing the devicetree ordinal with an
additional `DEVICE_HANDLE_ENDS` at the end (to preserve lengths), we
can simply move the ordinal to the end and have it be the original
`DEVICE_HANDLE_ENDS` symbol. This reduces the size of the array by
one handle per device (2 bytes).

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2021-08-25 19:43:54 -04:00
Jordan Yates 1660386f11 device: whitespace cleanup
Remove double spaces after full stops in doxygen comments.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2021-08-25 19:43:54 -04:00
Kumar Gala ed76b915cb pm: device: Fix if devicetree 'wakeup-source' prop isnt defined
Its possible that a dts binding doesn't inherit from base.yaml and
thus doesn't have `wakeup-source` defined.  To handle these cases
use DT_PROP_OR() which can deal with a property not existing at
all.

Fixes #37676

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-08-16 15:00:26 -04:00
Flavio Ceolin 8eceeee798 pm: device: Add wakeup source API
Introduce a new API to allow devices capable of wake up the system
register themselves was wake up sources. This permits applications to
select the most appropriate way to wake up the system when it is
suspended.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-08-11 19:39:13 -04:00
Gerard Marull-Paretas 8be0472ba8 pm: add type for device PM control callback
Add a type and documentation for the device PM control callback. This
way possible return codes and its meaning are documented.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-08-04 08:23:01 -04:00
Gerard Marull-Paretas 11eef4d8c8 pm: device: remove pointer usage for state
Since the state is no longer modified by the device PM callback, just
use the state value.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-08-04 08:23:01 -04:00
Gerard Marull-Paretas 9e7d545bb4 pm: device: remove ctrl_command callback argument
The ctrl_command is not used anymore, so remove it from the callback
signature.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-08-04 08:23:01 -04:00
Gerard Marull-Paretas 70322853a8 pm: device: move device busy APIs to pm subsystem
The following device busy APIs:

- device_busy_set()
- device_busy_clear()
- device_busy_check()
- device_any_busy_check()

were used for device PM, so they have been moved to the pm subsystem.
This means they are now prefixed with `pm_` and are defined in
`pm/device.h`.

If device PM is not enabled dummy functions are now provided that do
nothing or return `-ENOSYS`, meaning that the functionality is not
available.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-07-30 09:28:42 -04:00
Henrik Brix Andersen 51e774a3f4 device: add DEVICE_DT_GET_ONE macro
Add DEVICE_DT_GET_ONE() macro. This macro is similar to
DEVICE_DT_GET_ANY() but instead of returning NULL if no enabled,
compatible device instance is found, it throws a compilation error.

This is useful for compile-time checks in samples.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2021-07-15 11:47:11 -04:00
Gerard Marull-Paretas 26ad8376bd pm: remove callback from control function
The callback is not used anymore, so just delete it from the pm_control
callback signature.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-07-13 09:36:45 -04:00
Gerard Marull-Paretas cc2f0e9c08 pm: use enum for device PM states
Move all PM_DEVICE_STATE_* definitions to an enum. The
PM_DEVICE_STATE_SET and PM_DEVICE_STATE_GET definitions have been kept
out of the enum since they do not represent any state. However, their
name has not been changed since they will be removed soon.

All drivers and tests have been adjusted accordingly.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-07-07 14:13:12 -04:00
Kumar Gala e021ac7673 device: remove deprecated DEVICE_INIT/DEVICE_AND_API_INIT macros
The macros have been deprecated for 2 releases so remove the code
associated with them.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-06-11 08:37:08 -05:00
Gerard Marull-Paretas c708a17b8e pm: device: remove CONFIG_PM_MAX_DEVICES
When a device is defined a new pointer to a device will be created in
the "z_pm_device_slots" region, effectively creating a device array with
the same size as the number of system devices. This array is then used
by the device PM subsystem to keep track of suspended devices during
power transitions.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-05-29 07:38:06 -04:00
Gerard Marull-Paretas 2f12d53f9a device: fix unbalanced doxygen group
An extra @} was present, remove it.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-05-21 12:17:04 -04:00
Armando Visconti 4b4068c948 kernel/device: add arg checking in z_device_ready()
If this call receives an invalid device pointer as argument it
assumes that the `device` is not ready for usage.

This routine is currently called by two device specific APIs:

    - device_usable_check(const struct device *dev)
    - device_is_ready(const struct device *dev)

The device-specific APIs documentation claims that these two
routines must be called with a device pointer captured from
DEVICE_DT_GET(). So passing NULL is a violation of the rule.

Nevertheless, is quite common in drivers to assign NULL to
a device pointer if the corresponding DT property has not been
found (e.g. a not used gpio interrupt declaration for a given
device instance) and seems legit to interpret this condition
same as the device is not ready for usage.

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2021-05-18 11:29:46 -05:00
Flavio Ceolin 7eba310220 power: device: void *context -> uint32_t *state
The context parameter used across device power management is
actually the power state. Just use it and avoid a lot of
unnecessary casts.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-05-07 16:55:31 -04:00
Gerard Marull-Paretas 1e50e08bca pm: move device_set/get_power_state to pm/device.h
These are device PM APIs, so move them to the device PM API header.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-05-05 18:35:49 -04:00
Gerard Marull-Paretas dbf46b3815 pm: rename device_pm_cb to pm_device_cb
Prefix all device PM functions/data structures with pm.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-05-05 18:35:49 -04:00
Gerard Marull-Paretas 7bfd3a11f3 device: rename device_pm_control to pm_control
Remove device_ prefix since it is redundant.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-05-05 18:35:49 -04:00
Gerard Marull-Paretas d31a9be27c pm: device: rename device_pm struct to pm_device
Prefix all PM related functions/structures with pm.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-05-05 18:35:49 -04:00
Gerard Marull-Paretas 2c7b763e47 pm: replace DEVICE_PM_* states with PM_DEVICE_*
Prefix device PM states with PM.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-05-05 18:35:49 -04:00
Gerard Marull-Paretas 25bb163dc2 pm: reorganize headers
- Move PM related APIs to `include/pm` so that it follows API `pm_`
  prefix namespace. In order to make transition easier
  `include/power/power.h` is kept pointing to `include/pm/pm.h`.
- Move most of device PM related content from `include/device.h` to
  `include/pm/device.h` and `include/pm/runtime.h`.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-05-05 18:35:49 -04:00
Gerard Marull-Paretas cc6c9086de pm: deprecate device_pm_control_nop
All in-tree usage has been replaced with `NULL`, so flag it as
deprecated.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-04-28 20:40:00 -04:00
Gerard Marull-Paretas bfce935caf power: remove device_pm_control_nop function
Devices that do not require PM should just use NULL.
`device_pm_control_nop` is still kept as an alias to NULL untill all
in-tree usage is replaced with NULL.

Code relying on device_pm_control function now returns -ENOTSUP
(equivalent to calling device_pm_control_nop).

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-04-27 16:28:49 -04:00
Evgeniy Paltsev 2b76f0fee2 init: tweak Zephyr .init* section name conflicting with toolchain
In case of ARC MWDT toolchain and C++ support enabled the Zephyr .init*
section conflicts with .init* sections derived from toolchain libs.

Let's add 'z_' prefix to Zephyr .init* section (and therefore .device
section as they share the same macros) to make Zephyr section name
unique.

Signed-off-by: Evgeniy Paltsev <PaltsevEvgeniy@gmail.com>
2021-04-26 14:15:43 -04:00
Anas Nashif 25c87db860 kernel/arch: cleanup function definitions
make identifiers used in the declaration and definition identical. This
is based on MISRA rule 8.3.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-04-01 05:34:17 -04:00
Martí Bolívar 005dbf1d79 device.h: DEVICE_DT_GET_ANY refactor
Rewrite this in terms of DT_COMPAT_GET_ANY_STATUS_OKAY().

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2021-03-29 16:33:51 +02:00
Eugeniy Paltsev e828702b6a linker-defs: Fix sorting order of objects by priority
Commit 0a7b65e tweaked the CREATE_OBJ_LEVEL macro in such a way
that it would break the expected sorting order.

For example if you had 2, 19, 20, 30 as the level, we'd end up sort
these to be 19, 2, 20, 30.

Fix this by adding aditional "_" symbol after the init level counter.
That allows to keep correct sort order (for both GNU and MWDT
toolchains) and distinguish init level counter from section suffix
(for MWDT toolchain).

Fixes zephyrproject-rtos#33464

Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
2021-03-25 12:20:39 -05:00
Kumar Gala a56bdc4c6c device: remove deprecated device_list_get
device_list_get has been deprecated for 2 releases so remove the code
associated with it.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-03-22 10:15:26 -05:00
Hubert Miś 7d8f78a08b drv: display: Initial FT800 display driver
This patch includes initial support for FT800 display driver.
It includes basic features. It can be easily extended with more
FT800 display list and co-processor features.

Signed-off-by: Hubert Miś <hubert.mis@gmail.com>
2021-03-19 19:05:53 +01:00
Andrzej Głąbek 890eff6c0c device: Remove unnecessary z_impl_device_is_ready()
This is a follow up to commit 2aab687270.

Since device_is_ready() is no longer a system call, there is no need
to keep z_impl_device_is_ready().

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2021-03-15 10:44:53 -05:00
Peter Bigot b29abe3710 device: add API to visit required devices
The static device dependencies from devicetree are not the only ones
that might be present at runtime.  Add API that allows visiting
required devices without assuming that handles for or pointers to them
can be accessed as a static contiguous sequence.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-03-11 08:53:18 -05:00
Kumar Gala 5b6de52a71 device.h: Add macro API to get a devicename from a devicetree node
We default to use the "label" properties of a devicetree node as the
name if it exists.  If the "label" does not exist we than use the
node-name@unit-address for the node as the name.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-02-28 17:12:04 -05:00