Commit graph

74 commits

Author SHA1 Message Date
Hubert Miś 0b5ac4023f ipc: icmsg multi endpoint with nocopy in receive path
Add nocopy feature to icmsg-me initiator and follower roles
in their receive path. This feature is optional, configured
with Kconfig.

Signed-off-by: Hubert Miś <hubert.mis@gmail.com>
2022-12-22 11:07:44 +01:00
Hubert Miś 6d3d2309ce ipc: icmsg multi endpoint with nocopy in send path
Add nocopy feature to icmsg-me initiator and follower roles
in their send path.

Signed-off-by: Hubert Miś <hubert.mis@gmail.com>
2022-12-22 11:07:44 +01:00
Hubert Miś 3a1c9bce6e ipc: icmsg: send nocopy feature
Add a nocopy feature for sending message through the icmsg IPC library.

Also eliminate data races if multiple threads are using the
same ipc instance and are trying to send a message simultaneously.

Signed-off-by: Hubert Miś <hubert.mis@gmail.com>
2022-12-22 11:07:44 +01:00
Hubert Miś 5b023df67f ipc: icmsg: rx nocopy feature
This patch adds an optional nocopy feature for RX message to the icmsg
IPC library. The nocopy feature can be enabled using project
configuration.

If this feature is not used by icmsg users it is recommended to disable it
to reduce memory usage and improve run-time performance.

Signed-off-by: Hubert Miś <hubert.mis@gmail.com>
2022-12-22 11:07:44 +01:00
Hubert Miś 4a79754dd5 ipc: icmsg capability to clear rx buffer headers
On system startup icmsg headers space must be cleared before
cores start handshake procedure. The simplest way to enforce
it is to clear memory by the core responsible by enabling
the remote core, before the remote core is enabled and before
the handshake is started.

This patch ensures that nRF53 APP core clears both TX and RX
memory for icmsg before it starts NET core.

Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
2022-12-22 11:07:44 +01:00
Kamil Gawor d0e21fe6a6 ipc: Enable ICMSG multiendpoint role by default
This commit enables the initiator or the follower
role for the ICMSG multi-endpoint backend
depending on dts by default.
It is needed when BT_RPMSG transport for HCI is used.

Signed-off-by: Kamil Gawor <Kamil.Gawor@nordicsemi.no>
2022-12-22 11:07:44 +01:00
Carlo Caione e1e06d05fa ipc: static_vrings: Zero config struct
Initialize the config struct to zero before passing down to OpenAMP.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2022-12-13 09:44:44 +01:00
Hubert Miś 14a03e90d5 ipc: ipc_service: kconfig cleanup
Separate ipc_service libraries Kconfig entries from ipc_service backend
entries. IPC_SERVICE_BACKEND_ICMSG_BOND_NOTIFY_REPEAT_TO_MS is renamed
to drop BACKEND part, because this entry applies to a library, not to
one backend. Icmsg related entries are grouped now in a menuconfig for
cleaner presentation in configuration editors.

Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
2022-12-05 15:26:31 +01:00
Carlo Caione cc427b4bb0 cache: Fix libraries and drivers
Fix the usage to be compliant to the new cache API.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2022-12-01 13:40:56 -05:00
Radoslaw Koppel 0620cb1fe1 ipc: ipc_service: icmsg: Increase reliability of bonding
This commit changes the way bonding between endpoints is processed.
There is no blind attempt to read the buffer without mbox notification.
On second side the notification is repeated multiple times until valid
bonding is detected.

Signed-off-by: Radoslaw Koppel <radoslaw.koppel@nordicsemi.no>
2022-11-23 11:34:04 +01:00
Hubert Miś dc9d479dea ipc: add a multi-endpoint feature to icmsg
The icmsg backend for ipc_service has a limitation of supporting only
on endpoint. This limitation is acceptable for many IPC instances.
However, some require to use multiple endpoints sharing a single
instance. To preserve the simple and the most efficient single-instance
backend, a separated backend is introduced implementing a wrapper
around icmsg core which adds multiple endpoints support.

There are two multi-endpoint ipc_service icmsg backends: one in the
initiator role, and the other one in the follower role. In a IPC
configuration one end of communication must be in the follower role
while the other one is in the initiator. The initiator initiates
an endpoint discovery handshake to establish enpoint identifiers for
requested endpoint names. The follower responds to requests sent by
the initiator.

Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
2022-11-09 10:41:43 +01:00
Hubert Miś 6f450fdf18 ipc: separate icmsg core from ipc_service backend
icmsg library was implemented as a ipc_service backend. It is a simple
library with minimal feature set. To preserve its simplicity while
adding more features it is useful to introduce separated ipc_service
backends with added features. To reuse most of the icmsg code for the
simplest backend and other including more features, the core of icmsg
is separated from the simplest ipc_service to an icmsg module which
can be used by multiple backends.

Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
2022-11-09 10:41:43 +01:00
Emil Obalski 45f0fb1970 ipc: Add deregister API support for icmsg backend
Add support for deregister_endpoint IPC service API
in icmsg backend.

Signed-off-by: Emil Obalski <Emil.Obalski@nordicsemi.no>
2022-10-17 14:49:42 +02:00
Jackson Cooper-Driver 23c9f7b215 ipc_service: Add ipc_service_close_instance function
This function allows the application to close an ipc_service instance.
It is intended for use when the remote agent it is communicating with
has gone down and allows for cleanup.
It first checks that the endpoints have been separately deregistered
with the instance using the deregister_endpoint function before
calling into previously added functions in ipc_static_vrings.c
and ipc_rpmsg.c to close those instances.

Signed-off-by: Jackson Cooper-Driver <jackson.cooper---driver@amd.com>
2022-10-03 10:08:44 +02:00
Jackson Cooper-Driver e69d131bc5 ipc_service: Adding ipc_static_vrings_deinit function
This function deinitialises the static vrings used by the ipc_service
instance. It acheieves this by tearing down the initialised
virtqueues before closing the various aspects of libmetal which
are in use.

Signed-off-by: Jackson Cooper-Driver <jackson.cooper---driver@amd.com>
2022-10-03 10:08:44 +02:00
Jackson Cooper-Driver f16a19c33f ipc_service: Add ipc_rpmsg_deinit function
This function does the opposite of the ipc_rpmsg_init function and
allows the rpmsg instance to be torndown in the case that the application
wishes to do so. It is intended to be used by the ipc_service subsystem.

Signed-off-by: Jackson Cooper-Driver <jackson.cooper---driver@amd.com>
2022-10-03 10:08:44 +02:00
Pawel Dunaj 3676aeff78 ipc_service: icmsg: Trigger data read after magic
After magic is read during bound procedure, trigger an
initial data read. This is to ensure data is not missed
when piggybacked on magic's exchange interrupt.

Signed-off-by: Pawel Dunaj <pawel.dunaj@nordicsemi.no>
2022-09-15 16:31:48 +00:00
Gerard Marull-Paretas 79e6b0e0f6 includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.

The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.

NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-09-05 16:31:47 +02:00
Kumar Gala 482ed5b4e3 ipc: ipc_service: Update Kconfig
Utilize DT_HAS_<COMPAT>_ENABLED for devicetree based drivers

Signed-off-by: Kumar Gala <galak@kernel.org>
2022-09-01 10:26:13 +02:00
Gerard Marull-Paretas 745db7afd4 ipc: rpmsg_service: initialize devices at compile time
Initialize devices at compile time, allowing to constify device pointer.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-19 11:51:26 +02:00
Jackson Cooper-Driver 09cb88edcf ipc_service: Add ipc_service_deregister_endpoint function
In the case that an endpoint goes down, it needs to be deregistered
from the ipc_service for cleanup. This function deregisters the endpoint
from the ipc_rpmsg instance and sets the endpoint to zero.

Signed-off-by: Jackson Cooper-Driver <jackson.cooper---driver@amd.com>
2022-08-18 12:32:21 +02:00
Kumar Gala 8d0b1650a9 ipc: rpmsg_service: Convert to devicetree APIs
* Convert device_get_binding to DEVICE_DT_GET
* Convert Kconfig RPMSG_SERVICE_SHM_BASE_ADDRESS and
  RPMSG_SERVICE_SHM_SIZE to DT_REG_ADDR/DT_REG_SIZE

Signed-off-by: Kumar Gala <galak@kernel.org>
2022-08-16 15:50:03 +02:00
Jackson Cooper-Driver f06c06de07 ipc_service: Add endpoint registered check
Currently, it is possible to call various ipc_service functions
which take in an endpoint pointer (such as send, get_tx_buffer)
with an endpoint which has not been registered with the instance.
This leads to dereferencing a NULL pointer when the function tries
to access the api field of ept->instance.
This patch adds in multiple checks to ensure that the endpoint is
registered before continuing, one in the frontend, when ensures
that the ept->instance pointer is not NULL and one in the backend
which checks the value of the token pointer. If either of these fail,
we return -ENOENT.

Signed-off-by: Jackson Cooper-Driver <jackson.cooper---driver@amd.com>
2022-07-14 10:29:42 +02:00
Aleksandar Radovanovic 69690e3505 ipc_service: static_vrings: Fix TX virtqueue alignment
This patch fixes an issues where the TX virtqueue is misaligned by
2 bytes due to the way the virtqueue start address is calculated.
It is currently set to immediatelly follow the RX virtqueue:

    vr->tx_addr = vr->rx_addr + vring_size(num_desc, VRING_ALIGNMENT);

but the RX virtqueue does not end on an aligned boundary (last field,
avail_event is uint16_t). The resulting misaligned virtqueue causes
alignment faults on architectures that do not support unaligned
accesses (and is suboptimal otherwise)

The fix is to realign tx_addr to requested VRING_ALIGNMENT.

Signed-off-by: Aleksandar Radovanovic <aleksandar.radovanovic@amd.com>
2022-07-06 11:03:04 +02:00
Krzysztof Chruscinski 041f0e5379 all: logging: Remove log_strdup function
Logging v1 has been removed and log_strdup wrapper function is no
longer needed. Removing the function and its use in the tree.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-06-23 13:42:23 +02:00
Krzysztof Chruscinski 0829610bbc lib: os: spsc_pbuf: Add option to use cache
Add flags option to init call and a flag to use cache.
Add Kconfig choice to pick how to approach cache. Cache can be
enforced in all spsc_pbuf instances, disable in all, or runtime selected
based on configuration flag. Option is added to allow memory footprint
savings.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-06-07 19:04:35 +02:00
Krzysztof Chruscinski 2f189e39a5 lib: os: Rename icmsg_buf to spsc_pbuf
Move icmsg_buf to lib/os and rename to spsc_pbuf (Single Producer
Single Consumer Packet Buffer). It is a generic module and initially
was created as internal module for ipc service.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-06-07 19:04:35 +02:00
Carlo Caione 4ef13f7ecd ipc_service: static_vrings: Set WQ priority back to PRIO_PREEMPT
This reverts commit 7f51907fda.

The problem with setting the priority at the highest priority possible
is that when the IPC is under high traffic, the WQ could starve the
scheduler.

Move back to a more sane preemptive priority as default value.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2022-06-07 11:53:22 +02:00
Carlo Caione 2bf678af1b ipc: static_vrings: Fix timeout management
The ipc_service_get_tx_buffer() has a timeout parameter that can be used
to wait a certain amount of time for a TX buffer to be available.

Unfortunately, for the static vrings backend, an asymmetry
between remote and host exists that makes the usage of this parameter
confusing when the user requests a buffer when no buffers are available
at that time.

When the remote endpoints requests a TX buffer specifying a certain
size and there are no TX buffers available, the function ignores the
parameter and ipc_service_get_tx_buffer() immediately returns -ENOMEM.

The same case on the host endpoint works correctly only when the
specified timeout is <= 15 seconds. All timeouts > 15 seconds simply
returns -EIO after 15 seconds.

This patch is reworking the timeout management trying to behave
correctly in all the cases.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2022-06-05 14:49:26 +02:00
Carlo Caione 01305942f6 ipc: static_vrings: Support DT-defined buffer size
Recently OpenAMP introduced the possibility to set the sizes for TX and
RX buffers per created instance. Expose this also to Zephyr users by
using a DT property "zephyr,buffer-size".

For the sake of simplicity use the same DT property to set the buffer
size for both TX and RX buffers.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2022-06-05 14:46:18 +02:00
Carlo Caione 11f0bb9d1a ipc: static_vrings: Add -ENOMEM case
Sometimes it is important to know when the backend fails to send out
data because no memory / buffers are available. Return -ENOMEM in that
case.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2022-05-16 16:56:33 +02:00
Gerard Marull-Paretas 5113c1418d subsystems: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all subsystems code to
the new prefix <zephyr/...>. Note that the conversion has been scripted,
refer to zephyrproject-rtos#45388 for more details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-09 12:07:35 +02:00
Carlo Caione 55dc21ffb9 openamp: Bump to v2022.04.0
Bump OpenAMP to v2022.04.0 and fix Zephyr terminology linked to OpenAMP.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2022-05-02 08:44:17 -05:00
Carlo Caione 7f51907fda ipc_service: static_vrings: Set WQ default type to PRIO_COOP
In 92d8329d5b a new DT property was introduced to set the WQ priority
of the instance. The fallback value when the property was not present
was arbitrarily set to <0 PRIO_PREEMPT>.

The problem is that this value is actually changing the behaviour for
the code that is not explicitly setting the DT property, breaking in
some cases the existing code.

Move the default value to <0 PRIO_COOP> to give the old code a
consistent behaviour before and after the 92d8329d5b commit.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2022-04-28 10:27:10 +02:00
Carlo Caione 9bd8bbe35b ipc_service: static_vrings: Add NOCOPY capability
Add the newly introduced NOCOPY capability to the static vrings backend.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2022-04-01 09:05:06 -05:00
Carlo Caione 7cb91be0c0 ipc_service: Extend API with nocopy functions
Add several new functions to the IPC service API:
  - ipc_service_get_tx_buffer()
  - ipc_service_drop_tx_buffer()
  - ipc_service_send_nocopy()
  - ipc_service_release_rx_buffer()
  - ipc_service_hold_rx_buffer()

This set of function is used to support backends with nocopy capability.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2022-04-01 09:05:06 -05:00
Emil Obalski d877e1dded ipc_service: Automatically include source files for backends
The purpose of this change is to allow to enable more than one
backend at once by removing choice from ipc-service backend Kconfig
and depending backend Kconfig option on existing of correct compatible.

Overwriting IPC_SERVICE_BACKEND option in some places is removes
as no longer needed.

Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
2022-03-29 12:30:50 -07:00
Kamil Piszczek 33408fa7af ipc: backends: rpmsg: initialize shared memory to zero
Added a code for initializing shared memory to zero. This operation
normalizes the memory state so that the IPC service is no longer
prone to reading status bits from the previous reset session.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2022-03-28 12:46:32 +02:00
Carlo Caione 92d8329d5b ipc_service: static_vrings: Move to one WQ per instance
Instead of having one single WQ per backend, move to one WQ per
instance instead and add a new "zephyr,priority" property in the DT to
set the WQ priority of the instance. Fix the sample as well.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2022-03-28 12:46:15 +02:00
Emil Obalski 63b4f3e6ce ipc_service: icmsg: Pass priv user data to callbacks
This change fixes inconsistency with ipc-service API.

Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
2022-03-25 11:33:42 +01:00
Dominik Ermel e20f72f7cb kconfig: Remove unneeded ${ZEPHYR_BASE} from template import
The commit removes, from various Kconfigs, ${ZEPHYR_BASE} in
sourcing of logging template.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-03-24 18:07:28 -04:00
Emil Obalski 40b28ab51e ipc_service: Add new backend based on custom messaging buffer
This commit adds ipc backend, that relies on simple
inter core messaging buffer also added by this commit.

This backend is configurable with DT overlay. Each
ipc instance could be defined with ipc-icmsg commpatible.

Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
2022-03-22 12:36:39 +01:00
Artur Hadasz 001894a1c0 ipc: use highest coop priority for workqueue in new IPC backend
The priority of workqueue responsible for rpmsg processing was too
low. Any cooperative task could cause rpmsg processing to be
slightly delayed.

Signed-off-by: Artur Hadasz <artur.hadasz@nordicsemi.no>
2022-03-22 12:29:17 +01:00
Carlo Caione 3fc5150f36 ipc_service: static_vrings: Use atomic helpers
Use the correct atomic helpers when accessing atomic_t variables and fix
a possible race condition.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2022-03-21 10:14:32 +01:00
Carlo Caione 4ea6fd4f20 ipc_service: Start the wq only once
No need to start the wq every time the mbox is initialized, it must be
done once for all the instances (it is shared by all the instances).

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2022-03-07 10:52:51 +01:00
Carlo Caione 93b0ea9782 ipc: Remove multi-instance backend
Remove the legacy multi-instance backend and the sample.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2022-01-17 15:50:58 -05:00
Andrzej Kuroś 288f9c0b11 ipc: use highest coop priority for IPM workqueue
The priority of workqueue responsible for rpmsg processing was too
low. Any cooperative task could cause rpmsg processing to be
slightly delayed.

Signed-off-by: Andrzej Kuroś <andrzej.kuros@nordicsemi.no>
2021-11-24 18:59:02 +01:00
Carlo Caione 983d4606ff ipc_service: Add new RPMsg with static VRINGs backend
Introduce a new RPMsg with static VRINGs backend. This new backend makes
easy to generate and use IPC instances backed by OpenAMP using the DT.

Each instance is defined in the DT as (for example):

  ipc: ipc {
          compatible = "zephyr,ipc-openamp-static-vrings";
          shm = <&sram_ipc0>;
          mboxes = <&mbox 0>, <&mbox 1>;
          mbox-names = "tx", "rx";
          role = "primary";
          status = "okay";
  };

It is then possible to register an send data through endpoints using the
IPC service APIs.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2021-11-22 23:03:23 -05:00
Carlo Caione d7a40ba5d7 ipc_service: Extend RPMsg structs and misc fixes
Extend the RPMsg structs to accommodate for the introduction of new
backends and contextually fix the ipc_rpmsg_static_vrings_mi backend
(the only user).

Rework also some comments and ipc_service glue code.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2021-11-22 23:03:23 -05:00
Carlo Caione 83d0c96915 ipc_service: Add open_instance function
As know, an instance is the representation of a physical communication
channel between two domains / CPUs.

This communication channel must be usually known and initialized (that
is "opened") by both parties in the communication before a proper
communication can be instaurated using endpoints.

Depending on the backend and on the library / protocol used by the
backend, this "opening" can go through some handshaking or
synchronization procedure run by the parties that sometimes can be
blocking or time-consuming.

For example in the simplest case of a backend using OpenAMP, the remote
side of the communication is waiting for the local part to be up and
running by loop-waiting on some flag set in the shared memory by the
local party.

This is a blocking process so a particular attention must be paid to
where this is going to be placed in the backend code.

Currently it is only possible to have this synchronization procedure in
two points: (1) the init function of the instance, (2) during
ipc_service_register_endpoint().

It should be highly discouraged to put any blocking routine in the init
code, so (1) must be excluded. It is also frowned upon using the
endpoint registration function (2) because the synchronization is
something concerning the instance, not the single endpoints.

This patch is adding a new optional ipc_service_open_instance() function
that can be used to host the handshaking or synchronization code between
the two parties of the instance.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2021-11-22 23:03:23 -05:00