284 Commits

Author SHA1 Message Date
Arnaud Pouliquen
a399378a5d virtio: remove deprecated virtio_describe() function
The function is deprecated since more than 2 years, remove it.

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
2025-10-20 14:27:25 +02:00
Arnaud Pouliquen
d183f24ea0 cmake: remove deprecated cache options
Remove the following CMake options and associated definitions that have
been deprecated for over two years:
- WITH_DCACHE_VRINGS
- WITH_DCACHE_BUFFERS
- WITH_DCACHE_RSC_TABLE
- VIRTIO_CACHED_RSC_TABLE
- VIRTIO_CACHED_BUFFERS
- VIRTIO_CACHED_VRINGS

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
2025-10-20 14:27:25 +02:00
Arnaud Pouliquen
f819642829 remoteproc virtio: Fix documentation
The function rproc_virtio_wait_remote_ready does not return a value.
Remove the related @return field from the documentation.

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
2025-10-17 09:22:37 +02:00
Deep Chordia
b42e8443b9 lib: remove CACHE_* macros
- removes CACHE_FLUSH macro clashing with internal QNX definition
- also removes CACHE_INVALIDATE macro for consistency

Signed-off-by: Deep Chordia <dchordia@blackberry.com>
2025-10-17 09:15:52 +02:00
Sipke Vriend
6db90ebfcd doxygen: define vring memory layout using table
review requested to use a table rather than a code snippet to define
the memory layout, so convert proposed struct to a table with
definition, size and description and explanation of padding between
available and used structures.

Signed-off-by: Sipke Vriend <sipke@direktembedded.com>
2025-10-16 11:20:37 +02:00
Bowen Wang
9c4ad74ab4 virtqueue: add more virtqueue apis for the virtio device side
In virtio device side, we always need to get the next avaiable
buffer based on current buffer index. So add these two APIs for
convinience use.

For example, virtio blk driver origanize the buffer:
+----------+
| Reqeust  | (Flags: Read | Next)
+----------+
| Buffer   | (Flags: Read/Write | Next)
+----------+
| Response | (Flags: Write)
+----------+

For the virtio blk device size, we need get the Buffer and Response buffer
based on the Request buffer index.

So add api virtqueue_get_next_avail_buffer() to get the next available
buffer based on the first buffer index.
And rename the virtqueue_get_available_buffer() to
virtqueue_get_first_avail_buffer()

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
2025-10-16 11:20:05 +02:00
Bowen Wang
b2f6099fe5 lib: virtio: add new api virtio_has_feature()
virtio_has_feature() can be easily used to check if the virtio device
support a specific feature.

And assgin feature to vdev->feature for virtio device role when get
features, so the virtio device side can use virtio_has_featrue() to
check weather the virtio device support a feature.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2025-02-05 09:09:48 +01:00
Bowen Wang
8bd6149dfc lib: virtio: add new feature bit VIRTIO_F_ANY_LAYOUT
Follow the virtio spec, this feature bit indicates that the device
accepts arbitrary descriptor layouts.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2025-02-05 09:09:48 +01:00
Arnaud Pouliquen
3122cec8aa lib: virtio: Fix VIRTIO ROLE_XXXX macro definitions
Add parentheses around the "vdev" parameter to avoid side effects.

This fixes a build error when using the macro in the following way:
  if (VIRTIO_ROLE_IS_DEVICE(&my_context->vdev))

The error encountered:
openamp/open-amp/lib/include/openamp/virtio.h:89:49: error: invalid type argument of ‘->’ (have ‘struct virtio_device’)
   89 |  (VIRTIO_ENABLED(VIRTIO_DRIVER_SUPPORT) && (vdev->role) == VIRTIO_DEV_DRIVER)

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
2025-01-13 09:14:01 +01:00
Bowen Wang
4ace3543ae virtio: Add memory operation interface for virtio device
Buffer management is different for different transport layer:

For MMIO transport layer, the buffer can directly allocated from
the geust OS heap beacase the hypervisor can access all the memory own
by guest OS.

For remoteproc transport layer, the buffer should be allocated from
the share memory region to make sure the remote core can access this
buffer too.

So add memory ops in virtio device to make different transport/device can
implement their own share memory management.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-11-05 11:14:00 +01:00
Arnaud Pouliquen
71887e71df lib: remoteprocrpmsg: Fix safe_strcpy call
Fix the size of the source string passed in argument of safe_strcpy().
In rpmsg_register_endpoint we can not trust the size of the name
string provided, so we limit the max size to RPROC_MAX_NAME_LEN.

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
2024-10-25 10:16:15 +02:00
Arnaud Pouliquen
845a17b69f lib: rpmsg: Fix safe_strcpy call
Fix the size of the source string passed in argument of safe_strcpy().
In rpmsg_create_ept we can not trust the size of the name
string provided, so we limit the max size to RPMSG_NAME_SIZE.

Update the rpmsg_create_ept documentation to clarify the limit

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
2024-10-25 10:16:15 +02:00
Arnaud Pouliquen
9aa3ee53c7 lib: utils: implement internal safe_strcpy function
The strlcpy() function has only recently become available in glibc.
While this function prevents destination buffer overflow, it seems
that it cannot guarantee read access only within the source buffer.
this is for instance the case if the source string is not terminated by
a'\0' character.
Implement a safe_strcpy to ensure that no access is done out of the
source and destination buffer ranges.

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
2024-10-18 16:13:30 +02:00
Yongrong Wang
81ac4d3934 openamp/virtio.h: make final_features optional
negotiate also can be call when final_features is NULL

Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
2024-10-09 10:37:42 +02:00
Yongrong Wang
4df7975ab1 openamp/virtio.h: update vdev->features
set vdev->features in virtio_negotiate_features

Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
2024-10-09 10:37:42 +02:00
Andrew Davis
fdb8bf3424 virtio_mmio: Statically allocate metal_io_regions
Make the metal_io_region for cfg_io and shm_io into full member structs
instead of just pointers. This means they will be allocated along with
the parent virtio_mmio_device struct and not need dynamically allocated
later.

Signed-off-by: Andrew Davis <afd@ti.com>
2024-07-05 09:41:06 +02:00
Andrew Davis
6780dd2378 virtio_mmio: Remove unneeded use of libmetal device
A virtual metal_device is created, then the needed IO regions are created
and added to this device. Immediately we extract these same regions back
out and make use of them. There is no reason to do this, instead simply
use the created IO regions.

This also removes the need to have struct metal_device defined to have
more than one IO region (METAL_MAX_DEVICE_REGIONS), which is not the
default and can change per-platform. If the libmetal library was built
with the default value for METAL_MAX_DEVICE_REGIONS, then this would
have led to runtime failures.

Signed-off-by: Andrew Davis <afd@ti.com>
2024-07-05 09:41:06 +02:00
Arnaud Pouliquen
b7cadeb7ce lib: virtio: Rework macros VIRTIO_ROLE_IS_DEVICE and VIRTIO_ROLE_IS_DRIVER
The virtio.h header can be included by applications. In such cases,
VIRTIO_DRIVER_SUPPORT and VIRTIO_DEVICE_SUPPORT, which are used to
optimize the library, may not be defined in the application.

Define default VIRTIO_ROLE_IS_DEVICE and VIRTIO_ROLE_IS_DRIVER macros
that do not check for VIRTIO_DEVICE_SUPPORT or VIRTIO_DRIVER_SUPPORT if
they are not defined.

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
2024-06-28 08:42:09 +02:00
Arnaud Pouliquen
04a4185d79 lib: virtio: fix zephyr build warning
Building the samples/subsys/ipc/openamp_rsc_table/ sample generates the
following warning:

[24/182] Building C object zephyr/CMakeFiles/zephyr.dir/lib/open-amp/resource_table.c.obj
In file included from /zephyrproject/zephyr/lib/open-amp/./resource_table.h:11,
                 from /zephyrproject/zephyr/lib/open-amp/resource_table.c:30:
/zephyrproject/modules/lib/open-amp/open-amp/lib/include/openamp/virtio.h:83:2:
 warning: #warning "VIRTIO_DRIVER_SUPPORT and/or VIRTIO_DEVICE_SUPPORT should be defined" [-Wcpp]
   83 | #warning "VIRTIO_DRIVER_SUPPORT and/or VIRTIO_DEVICE_SUPPORT should be defined"
      |  ^~~~~~~

The issue occurs because the project includes the virtio API while
VIRTIO_DRIVER_SUPPORT and VIRTIO_DEVICE_SUPPORT is only defined for
the open-amp library build.

Fix the warning by testing deprecated usage of VIRTIO_DRIVER_ONLY and
VIRTIO_DEVICE_ONLY but not under
#if !defined(VIRTIO_DRIVER_SUPPORT) && !defined(VIRTIO_DEVICE_SUPPORT)
condition.

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
2024-06-28 08:42:09 +02:00
Arnaud Pouliquen
0538be5c94 lib: fix build error using legacy VIRTIO_DEVICE/DRIVER_ONLY
As part of the deprecation process for VIRTIO_DEVICE_ONLY and
VIRTIO_DRIVER_ONLY, we should still support builds without errors when
possible.
For legacy support, define VIRTIO_DRIVER_SUPPORT and VIRTIO_DEVICE_SUPPORT
default values based on VIRTIO_DEVICE_ONLY and VIRTIO_DRIVER_ONLY.

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
2024-05-22 16:58:10 +02:00
Andrew Davis
31fb9138bc rpmsg_virtio: Fix return value comment for rpmsg_virtio_get_role()
The `role` member of `struct virtio_device` stores either the value
VIRTIO_DEV_DRIVER or VIRTIO_DEV_DEVICE. This means the function
rpmsg_virtio_get_role() will also return one of these values.
The values RPMSG_HOST and RPMSG_REMOTE are defined to be the same,
but there is no need for this redefinition. Update the return
values in the comment docs.

While here, remove the same from rpmsg_virtio_set_wait_cb() which
does not return anything, this looks to be a copy/paste error.

Signed-off-by: Andrew Davis <afd@ti.com>
2024-05-20 09:40:16 +02:00
Arnaud Pouliquen
7257deaab3 lib: fix doxygen warning: "Found unknown command"
The doxygen build report issue for function descriptions that provide
reference to some function parameters using @:

...
lib/include/openamp/rpmsg.h:160: warning: Found unknown command '\data'
lib/include/openamp/rpmsg.h:160: warning: Found unknown command '\len'
...

Fix the warning by replacing with back-ticks that will be interpreted as
code by Markdown(Markdown support is enabled in the Doxygen configuration).

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
2024-05-16 09:05:29 +02:00
Arnaud Pouliquen
304c34606e lib: fix doxygen miscellaneous warnings
Remove warning reported by Doxygen on doc generation:
- rewrite enum documentation,
- replace @ by \ref for references,
- fix param names

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
2024-05-16 09:05:29 +02:00
Arnaud Pouliquen
e0dc7bd1f2 lib: rpmsg_rpc: fix compilation warning and bad API
Fix following warning by updating bad rpc_id parameter type in
the rpmsg_rpc_client_send() API.
Align the rpc_id type to the one used in rpmsg_rpc_server_send().

/github/workspace/lib/service/rpmsg/rpc/rpmsg_rpc_client.c:60:9:
error: ‘memcpy’ reading 8 bytes from a region of size 4
[-Werror=stringop-overread]
1286
   60 |  memcpy(tmpbuf, &rpc_id, MAX_FUNC_ID_LEN);
1287
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1288
/github/workspace/lib/service/rpmsg/rpc/rpmsg_rpc_client.c:51:40:
note: source object ‘rpc_id’ of size 4
1289
   51 |  unsigned int rpc_id, void *request_param,
1290
      |  ~~~~~~~~~~~~~^~~~~~

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
2024-05-07 08:47:26 +02:00
Arnaud Pouliquen
07109214ee lib: remove deprecated MASTER/SLAVE configuration
The use of the master and slave terminologies in configs and API are now
deprecated since 2 years, we can remove the associated code.

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
2024-05-06 19:35:22 +02:00
Andrew Davis
f939a86143 lib: Add and use VIRTIO_ROLE_IS_{DRIVER,DEVICE}() macros
There is a common pattern of checking the virtio role while also checking
that this role is supported in this build, which can help optimize away
unusable code. Add a couple macros for this. This has two main benefits,
first being shorter and easier to read if statements, and also makes it
easier to not forget to always do both checks.

Use these everywhere except rpmsg_virtio.c which needs one more refactor
before we can switch it over.

Signed-off-by: Andrew Davis <afd@ti.com>
2024-04-23 09:29:18 +02:00
Andrew Davis
7a8c292754 lib: Add and use VIRTIO_ENABLED() macro
Checks if this symbol is defined and set to equal 1. Used to make it
more clear that a preprocessor level check is intended.

Signed-off-by: Andrew Davis <afd@ti.com>
2024-04-23 09:29:18 +02:00
Andrew Davis
ca56246b19 lib: Use VIRTIO_{DRIVER,DEVICE}_SUPPORT to improve readability
Currently compiler defines are defined when support for driver or device
is the only support being built. This is a negative define, it surrounds
the code to not be built and we use ifndef. This is confusing. It also
leaves ifndefs all throughout the code-base. Instead, define a macro that
is set to 1 if support is enabled. Use this inline in if statements where
possible. Any sane compiler will optimize away the code in the branch
when support is not enabled just the same as when using the preprocessor
so we keep the same binary size.

Signed-off-by: Andrew Davis <afd@ti.com>
2024-04-23 09:29:18 +02:00
Arnaud Pouliquen
793851621d rpmsg_virtio: fix initialized notify_wait_cb
The rvdev->notify_wait_cb is not initialized to NULL if
not set by the user.
Initialize it to NULL and provide an API for the application to set it.

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
2024-04-19 11:20:54 +02:00
Andrew Davis
4db4a08135 virtqueue: Fix comment on shm_io and fix type
This should hold a pointer to a metal_io_region, make that the type.

Also fix the comment above this variable. This region holds the address
of the message buffers, not the vring descriptor table nor available/used
ring data. It is only used for virt-to-phys/phys-to-vert translation on
the buffers pointed to by these descriptors.

Signed-off-by: Andrew Davis <afd@ti.com>
2024-04-17 16:02:55 +02:00
Andrew Davis
1680aada79 remoteproc: Un-inline remoteproc_init_mem() and remoteproc_add_mem()
Having these functions as inline header functions forces the contents of
struct remoteproc_mem to remain externally exposed. It also does not save
space in most cases as every call-site gets the full contents of the
function instead of just a call instruction. Make these normal functions
like all others in remoteproc.h.

Signed-off-by: Andrew Davis <afd@ti.com>
2024-04-09 11:53:17 +02:00
Andrew Davis
f81114b21d rpmsg: Add API for retrieving message buffer sizes
Add an RPMsg API to get the buffer sizes supported by the backing
transport layer. Add hooks so that transport layers can register
functions to provide this data.

Signed-off-by: Andrew Davis <afd@ti.com>
2024-04-09 09:20:43 +02:00
Andrew Davis
d233fdc110 rpmsg_virtio: Deprecate functions that duplicate virtio functions
Do not expose new functions that reach into structs not belonging to
rpmsg_virtio, that breaks layering. Functions to access these members of
struct virtio are already provided by virtio, use those instead. Deprecate
the unneeded and layer breaking rpmsg_virtio functions for the same.

Signed-off-by: Andrew Davis <afd@ti.com>
2024-04-02 18:05:03 +02:00
Andrew Davis
962b6ef071 rpmsg_virtio: Deprecate rpmsg_virtio_{create,delete}_virtqueues helpers
These are only used internally by rpmsg_virtio. They also already exist
as part of the virtio API. Do not create an extra wrapper API out of
these functions. Deprecate these functions.

Signed-off-by: Andrew Davis <afd@ti.com>
2024-04-02 18:05:03 +02:00
Andrew Davis
a0b2b7c10f rsc_table_parser: Move header to make internal functions internal only
The files in include/openamp are deployed on install and can be used
by applications using the OpenAMP API. The functions in rsc_table_parser
are all internal use only. Move this header out of that location.

Signed-off-by: Andrew Davis <afd@ti.com>
2024-04-02 15:54:23 +02:00
Andrew Davis
d6b3604022 rsc_table_parser: Do not expose internal-only functions
These functions are only used within rsc_table_parser. These should be
only available there and made static. This prevents them from becoming
part of the API.

Signed-off-by: Andrew Davis <afd@ti.com>
2024-04-02 15:54:23 +02:00
Yongrong Wang
15b4a8b621 openamp: add notify_wait_cb to avoid looping in tx buffer get
Give users a chance to handle the no tx buffer situation when get tx
buffer, with this patch, user can set the notify_wait_cb in driver
and this callback function will be called to handle the wait when no
tx buffer in tx virtqueue.

Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
2024-03-18 10:42:29 +01:00
Yongrong Wang
198e2e69a9 Revert "openamp: add new ops wait_notified() to avoid looping in tx buffer get"
This reverts commit 95802c1d03.

Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
2024-03-18 10:42:29 +01:00
Bowen Wang
0c7e4202d0 remoteproc_virtio: optimize the remoteproc virtio transport layer
1. Implement the rproc_virtio_create_virtqueues() and
   rproc_virtio_delete_virtqueues().
2. Because 1, also modified the rpmsg init.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-02-23 09:51:00 +01:00
Guiding Li
95802c1d03 openamp: add new ops wait_notified() to avoid looping in tx buffer get
Give users a chance to handle the no tx buffer situation when get tx
buffer, with this patch, user can call rproc_virtio_set_wait_notified()
to set the wait_notified() callback and this callback function will be
called to handle the wait when no tx buffer in tx virtqueue.

Signed-off-by: Guiding Li <liguiding1@xiaomi.com>
Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2023-12-05 13:24:32 +01:00
Bowen Wang
b33183fea5 rpmsg: add release cb and refcnt in endpoint to fix ept used-after-free
if rpmsg service free the ept when has got the ept from the ept
list in rpmsg_virtio_rx_callback, there is a used after free about
the ept, so add refcnt to end point and call the rpmsg service
release callback when ept callback fininshed.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2023-11-29 18:11:39 +01:00
Guiding Li
d51364594d openamp: add new API rpmsg_virtio_get_rx_buffer_size()
This API can be used by the endpoint callback to limit the rx
buffer usage range.

Signed-off-by: Guiding Li <liguiding1@xiaomi.com>
Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2023-11-06 16:00:37 +01:00
Guiding Li
bbefedd495 rpmsg: set ept address to incease num when alloc from the bitmap
CPU0                                CPU1
create_ept1:addr1                   create_ept1
OK                       <======    msg1
OK                       <======    msg2
OK                       <======    msg3
                           msg4
                         <======    msg4 on the virtioqueue
close_ept1                          close_ept1

create_ept2:addr1                   create_ept1
(same addr with ept1)
                           msg4
ept2 recv ept1 msg ERROR <======

The msg4 which belong to ep1, error received by ept2.

For this issue, I give a resolve method:
Let the rpmsg_get_address() always return a new increased num.

Signed-off-by: Guiding Li <liguiding1@xiaomi.com>
2023-10-31 18:52:41 +01:00
Arnaud Pouliquen
de33a8d675 virtio: Fix delete_virtqueues function
The function should return void. the reason is that
vdev->func->delete_virtqueues() is optional and return void.

To be generic we should call virtio_delete_virtqueues in all cases.
Then depending on the dispatcher we do nothing or call delete_virtqueues()

Fixes: 7f90610 ("virtio: add create_virtqueues and delete_virtqueues in virtio_dispatch")

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
2023-10-19 16:00:21 -07:00
Arnaud Pouliquen
cd8823876f virtio: make unused function virtio_describe() deprecated
The virtio_describe() function does not seem usable.
Therefore, it should be marked as deprecated to initiate
the removal process.

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
2023-10-16 16:53:32 +02:00
Arnaud Pouliquen
0360890c32 virtio: Add virtio_dev_name function description
Add function description in Doxygen format for documentation.

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
2023-10-13 10:29:36 +02:00
Arnaud Pouliquen
adc68ec055 virtio: Complete virtio and virtqueue structures Doxygen description
Add descriptions for following structures:
- virtio_device_id
- virtio_feature_desc
- virtio_dispatch
- virtqueue_buf
- virtqueue
- vring_alloc_info

Move some comments related to the vring structure in its description.

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
2023-10-13 10:29:36 +02:00
Dan Milea
bdf5f910c0 Refactor VRING macros for AMP VIRTIO
Renamed AMP VIRTIO macros to avoid conflicts.

Signed-off-by: Dan Milea <dan.milea@windriver.com>
2023-10-10 16:22:53 +02:00
Tammy Leino
937ba1d700 Doxygen updates for data structures
Improved doxygen formatting and consistency for data structures.
Signed-off-by: Tammy Leino <tammy.leino@siemens.com>
2023-10-06 16:44:53 +02:00
Iuliana Prodan
f2162a69ac options: add option for all cache operations
Add WITH_DCACHE operation used for all cache operations:
vrings, buffers and resource table.
The other options will be deprecated - add warning
message for this.

Add info for WITH_DCACHE option in README.

Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
2023-09-18 09:12:36 +02:00