Commit graph

137 commits

Author SHA1 Message Date
Adam Kondraciuk
31689690c9 ipc: ipc_service: Parametrize workqueue stack size
Add `IPC_SERVICE_BACKEND_ICBMSG_EP_BOUND_WORK_Q_STACK_SIZE` config
and parametrize its value depending on the optimization level.

Signed-off-by: Adam Kondraciuk <adam.kondraciuk@nordicsemi.no>
2025-06-11 10:09:02 -07:00
Adrien Ricciardi
2f17465421 ipc: icbmsg: Add a workqueue name
This allows to easily identify the workqueue thread when using the kernel
shell commands.

Signed-off-by: Adrien Ricciardi <aricciardi@baylibre.com>
2025-06-04 16:59:04 +02:00
Radosław Koppel
26e3e82e60 ipc_service: ipc_icbmsg: Update backend API return values
Update release_rx_buffer return value to match API documentation.
Cleanup register_ept workflow - remove unused variable.

Signed-off-by: Radosław Koppel <radoslaw.koppel@nordicsemi.no>
2025-03-28 12:21:30 +01:00
Dominik Kilian
84a215aff8 ipc_service: icmsg: Add "unbound" functionality
In some cases, CPUs that may need to reset or
temporary stop communication. This commit adds "unbound"
functionality that provides a callback to IPC service user
when connection was interrupted for some reason, e.g.
expected or unexpected CPU reset, closing the
endpoint. The "unbound" callback is optional to implement
by endpoints. This commit implements it in the ICMsg
backend.

Signed-off-by: Dominik Kilian <Dominik.Kilian@nordicsemi.no>
2025-02-14 13:34:49 +01:00
Timothy Keys
614f55f8be ipc: ipc_service: Null terminate RPMsg endpoint names
This fixes the compiler warning -Wstringop-truncation in
version 13 of gcc.

Signed-off-by: Timothy Keys <timothy.keys@nordicsemi.no>
2025-01-22 10:40:27 +01:00
Daniel Mangum
2ca82ea6c4 ipc: pbuf: fix idx_occupied comment
Fix typos in the comment on the idx_occupied function.

Signed-off-by: Daniel Mangum <georgedanielmangum@gmail.com>
2025-01-16 22:38:26 +01:00
Dominik Kilian
81bb231fd0 ipc: icbmsg: Reduce block alignment to 32-bits
The ICBMsg backend divides its memory into
blocks. Each block is aligned to data cache
alignment. Is it not required, since adjacent
blocks has the same data flow direction (either
read-only or write-only). This commit changes
it to 32-bits making wasted memory significantly
reduced.

Signed-off-by: Dominik Kilian <Dominik.Kilian@nordicsemi.no>
2024-11-22 08:26:22 -05:00
Alberto Escolar Piedras
a5e3a33b39 ipc: icmsg & icbmsg: Fix alloc_tx_buffer() doxygen description
The return values were not correct, and the parameters descriptions
were not too easy to understand.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-10-24 13:15:35 +01:00
Dominik Kilian
cbaafe209c boards: nordic: ipc: added dcache alignement
The nRF54 and nRF92 chips has data cache, which means
the ICMsg and ICBMsg must be configured to follow required
cache alignment of the shared memory.
The `dcache-alignement` needs to be defined for that.

Signed-off-by: Dominik Kilian <Dominik.Kilian@nordicsemi.no>
2024-10-24 03:45:35 +01:00
Piotr Koziar
51e0130a74 ipc: icmsg: increase stack size of RX work queue thread
Increases default size of stack used by work queue RX thread
from 1024 to 1280 to avoid memory issues.

After adding the buffer with the default size of 128
that is allocated on the thread's stack (see #77552),
there is too little stack left during heavy stress.

Signed-off-by: Piotr Koziar <piotr.koziar@nordicsemi.no>
2024-10-22 20:40:57 +02:00
Dominik Kilian
131229b2c4 icbmsg: Allow deregistration of the endpoints
This is implementation of ICBMsg endpoint deregistration.
The underlying ICMsg instance and blocks are not affected by
deregistration, so it is possible to reuse the same address
during the re-registration of the same endpoint.

Signed-off-by: Dominik Kilian <Dominik.Kilian@nordicsemi.no>
2024-10-21 18:43:22 -05:00
Alberto Escolar Piedras
ca26820ac1 ipc: icmsg: Check return error of pbuf_rx_init()
When pbuf_rx_init() was added, this caller did not check for a possibly
returned error to not have more overhead than before using this
function.
Although unlikely let's check for a possible error (not configured Rx
pbuf cfg).

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-10-02 10:09:18 +02:00
Andrew Davis
df64d076d8 ipc: ipc_service: Inline libmetal_{setup,teardown}() for correct ordering
Currently metal_init() is called as part of libmetal_setup() which is
called after libmetal has already started being used (metal_io_init
called before). Same for metal_finish() but in reverse (metal_io_finish
called after). To fix this inline the content of libmetal_{setup,teardown}
into their one call-sites and move the init/finish calls to the correct
spot before/after all uses of the lib.

Signed-off-by: Andrew Davis <afd@ti.com>
2024-10-02 10:04:59 +02:00
Andrew Davis
be4a4ee324 ipc: ipc_service: Remove intermediate metal generic device
A libmetal "generic" device is created, then opened and used for its IO
regions. Since we are adding these IO regions in the first place there
is no reason for this layer of indirection.

Signed-off-by: Andrew Davis <afd@ti.com>
2024-10-02 10:04:59 +02:00
Andrew Davis
d58542fcc4 ipc: rpmsg_service: Remove virtual shared memory device
A virtual metal_device is created, next the needed IO regions are created
and added to this device. Immediately we extract these regions back out
and make use of them. There is no reason to create the metal_device and
add the IO regions to it, instead simply use the IO regions directly.

This is similar to what was already done to the openamp_rsc_table sample.

Signed-off-by: Andrew Davis <afd@ti.com>
2024-10-02 10:04:59 +02:00
Alberto Escolar Piedras
b5b91b3edb ipc: icmsg & icbmsg: Add support for POSIX arch targets
Add support in this IPC backends for POSIX arch targets in general,
and ensure the nrf5340bsim defines the buffer which will be used.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-09-26 03:34:26 -04:00
Alberto Escolar Piedras
5dc810e261 ipc: pbuf: Provide function for Rx side initialization
Provide a new function for initializing the Rx side,
so users do not need to initialize the pointers by hand
if they did not use PBUF_DEFINE().

Let's also rename pbuf_init() to pbuf_tx_init() to clearly
signify the previous function was only meant to be used
by the Tx side.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-09-26 03:34:26 -04:00
Alberto Escolar Piedras
b6f1767db5 subsys/ipc icmsg_me.c: Fix ssize_t build error for some libCs
ssize_t is not part of the C library ISO standard subset, and as such
one cannot expect a C library to expose the type by default.
Some libraries like glibc do not expose this type in general, and
trying to build using them results in build errors.

There is 3 possible options:
1. Continue using ssize_t and:
1.a define _POSIX_C_SOURCE before including any header
1.b include sys/types.h directly (A bit uglier)
3. Not use ssize_t, and instead rely on ISO standard types

Let's just go with 1.a assuming we want to keep using this type,
as that is the correct way of getting this type defined.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-09-26 03:34:26 -04:00
Magdalena Pastula
5de1c092b7 ipc: align icbmsg to no-multithreading
Modify ICBMSG so that it could be used in no-multithreading
appliactions.

Signed-off-by: Magdalena Pastula <magdalena.pastula@nordicsemi.no>
2024-09-12 10:03:05 +02:00
Bjarki Arge Andreasen
ee1e517ccf ipc: icmsg: configure PBUF RX rx_buffer using kconfig
The size of the rx_buffer used by icmsg.c mbox_callback_process()
is not MISRA compliant, being "dynamically" allocated on the stack.

This commit adds a kconfig to set the size of the read buffer and
asserts that it is large enough to read all received data.

Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
2024-08-30 11:45:38 -04:00
Pisit Sawangvonganan
8f197c955d style: subsys: comply with MISRA C:2012 Rule 15.6
Add missing braces to comply with MISRA C:2012 Rule 15.6 and
also following Zephyr's style guideline.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-08-20 10:33:51 +02:00
Jakub Zymelka
bb5b98f16c ipc: icmsg: Align to NO MULTITHREADING
Adapting icmsg to work without the MULTITHREADING functionality.
Dependencies for kernel work_queue, mutexes and other functions
related to running multithreaded applications have been 'ifdefed'.

Signed-off-by: Jakub Zymelka <jakub.zymelka@nordicsemi.no>
2024-08-01 13:31:53 +02:00
Pieter De Gendt
ad63ca284e kconfig: replace known integer constants with variables
Make the intent of the value clear and avoid invalid ranges with typos.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-07-27 20:49:15 +03:00
Jordan Yates
91f8c1aea9 everywhere: replace #if IS_ENABLED() as per docs
Replace `#if IS_ENABLED()` with `#if defined()` as recommended by the
documentation of `IS_ENABLED`.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-06-28 07:20:32 -04:00
Piotr Koziar
e66b382639 ipc: fix return code of icbmsg backend send operation.
This commit fixes the issue where a serialization
error was reported after properly sending a data with 'icbmsg' backend.

The icbmsg send function's return code is set to
the sent data's len as in other backends.
The related docs were fixed and updated.

Signed-off-by: Piotr Koziar <piotr.koziar@nordicsemi.no>
2024-06-10 15:00:01 +03:00
Flavio Ceolin
cbbb64a3aa ipc: icmsg_me: Fix possible integer overflow
Fix possible integer overflow and underflow.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2024-05-09 12:40:24 -04:00
Kamil Piszczek
1e6e6a228f ipc: ipc_service: icbmsg backend: workaround endpoint binding deadlock
This change works around the issue with the semaphore timeout during
the Bluetooth HCI driver initialization when the bt_enable function
is called in the context of the System Workqueue thread. This issue
only affects platform that use the IPC service and its ICBMsg backend
(e.g. the nRF54H20 DK target).

The bt_enable function, when called in the System Workqueue context,
results in a deadlock, as the waiting semaphore of the Bluetooth HCI
driver times out:

bt_hci_driver: Endpoint binding failed with -11

During the Bluetooth HCI driver open operation in the context of the
bt_enable function, the driver code waits using the semaphore for the
endpoint binding process of the IPC service module to finalize. The
issue occurs when the  waiting occurs in the System Workqueue context.
The ICBMsg backend from the IPC service schedules a system work during
the endpoint registration, in which it finalizes the binding operation
- also in the System Workqueue context. As the Bluetooth HCI driver
with its wait operation keeps the System Workqueue context busy, the
endpoint binding cannot be completed by the ICBMsg backend before the
HCI driver semaphore timeout.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2024-05-08 19:11:09 +01:00
Bogdan Marinescu
da708e232a ipc_rpmsg_static_vrings: use names for WQ threads
This patch adds names to the threads created by `mbox_init` via
`k_work_queue_start`. The name of the thread is the same as the name in
the device instance.

The main reason for this has to do with how `mcumgr` reports [thread
information](https://docs.zephyrproject.org/latest/services/device_mgmt/smp_groups/smp_group_0.html#task-statistics-command).
Specifically, data about threads is sent in a CBOR encoded map where the
map keys are the thread names (at least in the default configuration). If
there's more than one IPC channel defined (one example of this being
`samples/subsys/logging/multidomain`), both threads would be created
with an empty name and `mcumgr` will only return the data associated
with the thread created by the last call to `mbox_init`.

Signed-off-by: Bogdan Marinescu <bogdan.marinescu@gmail.com>
2024-05-02 20:47:38 +03:00
Herman Berget
9729651bb5 ipc_service: backends: icbmsg: Silence maybe-uninitialized warning
If compiling with optimizations (-O2/-Ofast) gcc emits a
maybe-uninitialized warning for `size`.

As far as I can tell, `size` will always be initialized in the cases
where it is used and only left uninitialized in error cases.

Reproduced on main with the multi_endpoint sample on
nrf5340dk/nrf5340/cpuapp.

Signed-off-by: Herman Berget <herman.berget@nordicsemi.no>
2024-04-22 06:48:54 -07:00
Kamil Gawor
6c130bcbab ipc_service: backends: icbmsg: Fix strnlen warnings
This fixes warnings when building with icbmsg
backend for IPC service by defining
_POSIX_C_SOURCE 200809L in source file.

Signed-off-by: Kamil Gawor <Kamil.Gawor@nordicsemi.no>
2024-04-17 16:52:52 +01:00
Joakim Andersson
8858a024c0 ipc: Add thread name to mbox work queues
Add thread name to mbox work queues when thread names are enabled.

Signed-off-by: Joakim Andersson <joakim.andersson@heimdallpower.com>
2024-03-19 15:01:16 +01:00
Gerard Marull-Paretas
80cc7d1ee5 drivers: mbox: update MBOX consumers to the new API
Update all usages of the MBOX API to the latest API changes (to be
squashed for bisectability).

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
2024-03-07 14:32:57 +00:00
Gerard Marull-Paretas
ad136ba38d ipc: ipc_service: backends: use MBOX_DT_INST_CHANNEL_GET
Instead of MBOX_DT_CHANNEL_GET(DT_DRV_INST(i), ...).

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
2024-03-07 14:32:57 +00:00
Celina Sophie Kalus
19c8fa2441 ipc: rpmsg_service: Support IPM without data transfer
RPMsg currently sends four dummy bytes over the IPM when sending a
notification/interrupt to another CPU. However, most IPM drivers
support sending messages with no data transfer, and for some IPM
drivers, like the STM32 HSEM IPM driver, data transfer is not
possible at all, thus breaking compatibility. To fix this, send an
empty message with size 0 instead of a dummy message if the STM32
HSEM IPM driver is active.

Signed-off-by: Celina Sophie Kalus <hello@celinakalus.de>
2024-02-26 11:39:29 +00:00
Jonathan Rico
f24a01e6d1 ipc: Drain pending work items before deregistering endpoint
The work item will attempt to dereference pointers that have been nulled
by the backend.

To avoid that, wait until all items currently on the queue have been
processed.

The symptom is a busfault on ARM, and is "fixed" by adding a
`k_msleep(1)` right before `ipc_service_deregister_endpoint()`. This
will in effect do the same thing as this patch, and allow the scheduler
to run the work item on the ipc workqueue.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2024-02-06 14:22:36 +01:00
Arnaud Pouliquen
bf2bdcf6f7 ipc_service: open-amp: Fix libmetal shared memory registration
When using multiple instances of IPC static vring, each instance
should register its shared memory with a unique name.
Instead of a predefined default name, the name of the ipc instance
is reused for the metal device name.

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
2023-12-14 16:18:55 +02:00
Dominik Kilian
28df44946f ipc: add dynamically allocated buffers to icmsg
The icmsg and icmsg_me backends has limitations in context of
concurrent access to single instance. Some limitations are:
* sending by more thread at the same time may cause -EBUSY
* allocating TX buffer will cause errors in other threads that want
  to allocate before first thread sent the message,
* during no-copy receive, when RX buffer is on hold receiving is
  totally blocked.
This backend resolves those limitations by adding dynamically allocated
buffers on shared memory next to ICmsg circular buffer. The data is
passed using those buffers, so concurrency is not a problem. The ICmsg
is used only to pass short 2-byte messages containing references to
those buffers. The backend also supports multiple endpoint.
The ipc/icmsg_me sample was modified to support this backend.

Signed-off-by: Dominik Kilian <Dominik.Kilian@nordicsemi.no>
2023-11-13 11:11:43 +01:00
Emil Obalski
d769a92520 ipc: icmsg: Allow to support future versions
Allow magic number to be longer than the sizeof(magic).
This will allow to support future versions of the icmsg
with backwards compatibility.

Signed-off-by: Emil Obalski <Emil.Obalski@nordicsemi.no>
2023-11-09 10:19:02 +00:00
Emil Obalski
eb4fc3f083 ipc: backends: Port IcMsg based backends to use pbuf
Replace spsc_pbuf with pbuf implementation dedicated to
be used by IcMsg based backends.
The pbuf is written on top of simple read/write semantics
with minimal footprint and code complexity

Signed-off-by: Emil Obalski <Emil.Obalski@nordicsemi.no>
2023-11-09 10:18:37 +00:00
Emil Obalski
380f83bab1 ipc: Add pbuf implementation
This adds implementation of secure packed buffer.
Secure packed buffer is added with intention to be used
in icmsg backed backends.

Signed-off-by: Emil Obalski <Emil.Obalski@nordicsemi.no>
2023-11-09 10:18:37 +00:00
Emil Obalski
f93243b68f ipc: Remove nocopy feature from icmsg_me backend
Remove nocopy feature from icmsg_me backend.
The backend is not meant to be used to send big
data chunks thus no-copy feature is removed.
If one wants to use no-copy it is recommended
to use icmsg_me only for control messages while
allocator will shall be written seperately.

Signed-off-by: Emil Obalski <Emil.Obalski@nordicsemi.no>
2023-11-09 10:18:37 +00:00
Alberto Escolar Piedras
eab871a1ff ipc: backend: rpmsg: Add support for POSIX arch
To enable runninng and testing this backend on the POSIX
architecture, we need to allow defining the shared memory
buffer as a compiler provided symbol, instead of a hard
address provided by the DTS.
For this case we refer to a symbol a POSIX arch implementation
(typically the board) needs to provide.
It is the responsability of that implementation to ensure
that symbol exists and points to a memory buffer of the
DT defined size.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-10-23 10:37:33 +02:00
Rafał Kuźnia
5b12b6ab55 ipc: icmsg: Dedicated workqueue for ICMSG backend
The ICMSG backend now has a dedicated workqueue to process incoming IPC
messages. The system workqueue is no longer utilized for that purpose.

Testing shows that in certain scenarios substituting a RPMsg backend
with ICMsg results in deadlocks.
The deadlocks were a symptom of running a synchronous RPC protocol from
the context of the system workqueue and transpired as follows:

1. The RPC protocol sends a request over the ICMsg backend on the system
   workqueue thread.
2. The RPC protocol puts the thread to sleep until response is received.
   This puts the system workqueue thread to sleep.
3. The response to the request arrives over ICMsg backend.
4. The backend signals a work item to the system workqueue.
5. The system workqueue is unable to process the response due to being
   previously pended on the RPC request.

The deadlock was initially observed with the nrf-802154 driver in
conjuntion with the IPv6 stack.

To prevent this condition from occurring, the approach was selected to
give ICMsg a dedicated workqueue thread.

Added a Kconfig option that enables the dedicated workqueue by default.
The config can be disabled, if the user wants to preserve RAM capacity
and is certain that the deadlock condition is not encountered.

Signed-off-by: Rafał Kuźnia <rafal.kuznia@nordicsemi.no>
2023-09-12 10:17:27 +02:00
Gerard Marull-Paretas
95cac89b4e ipc: rpmsg_service: s/device.h/init.h
Because module uses init.h APIs (SYS_INIT), not device.h.

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
2023-09-05 12:01:01 +02:00
Gerard Marull-Paretas
68552f0c4c ipc: rpmsg_service: add missing init.h
File was using SYS_INIT without including init.h.

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
2023-08-31 14:43:08 +02:00
Riadh Ghaddab
5eaace1c01 ipc_service: static_vrings: fix num_desc return value
currently when no enough memory is found a (1 << (-1)) value is returned
instead of 0.
Fix this by returning 0 and simplify log2 computation

Signed-off-by: Riadh Ghaddab <rghaddab@baylibre.com>
2023-08-30 14:44:51 +02:00
Gerard Marull-Paretas
b97bfa91f3 ipc: ipc_service: backends: rpmsg_static_vrings: add missing init.h
SYS_INIT was used without including init.h.

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
2023-08-30 10:41:20 +02:00
Carlo Caione
4b713dc2e8 ipc_service: static_vrings: Fix misnamed define
VRING_ALIGNMENT was renamed to MEM_ALIGNMENT but it was forgotten in one
place. Fix it.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2023-08-29 16:28:27 +02:00
Carlo Caione
6ae34c9176 ipc_service: static_vrings: Fix buffer sizing
We are returning an off-by-one number of buffers in some circumstances,
fix the calculation.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2023-08-29 10:26:59 +02:00
Daniel Leung
8cdcf1a8cb ipc: rename shadow variables
Rename shadow variables found by -Wshadow.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-08-22 11:39:58 +02:00