OpenAMP Library  v2026.04.0
rpmsg_virtio.h
Go to the documentation of this file.
1 /*
2  * rpmsg based on virtio
3  *
4  * Copyright (C) 2018 Linaro, Inc.
5  *
6  * All rights reserved.
7  * Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
8  *
9  * SPDX-License-Identifier: BSD-3-Clause
10  */
11 
12 #ifndef _RPMSG_VIRTIO_H_
13 #define _RPMSG_VIRTIO_H_
14 
15 #include <metal/io.h>
16 #include <metal/mutex.h>
17 #include <metal/cache.h>
18 #include <openamp/rpmsg.h>
19 #include <openamp/virtio.h>
20 
21 #if defined __cplusplus
22 extern "C" {
23 #endif
24 
25 /* Configurable parameters */
26 #ifndef RPMSG_BUFFER_SIZE
27 #define RPMSG_BUFFER_SIZE (512)
28 #endif
29 
30 /* The feature bitmap for virtio rpmsg */
31 #define VIRTIO_RPMSG_F_NS 0 /* RP supports name service notifications */
32 
33 #if defined(VIRTIO_USE_DCACHE)
34 #define BUFFER_FLUSH(x, s) metal_cache_flush(x, s)
35 #define BUFFER_INVALIDATE(x, s) metal_cache_invalidate(x, s)
36 #else
37 #define BUFFER_FLUSH(x, s) do { } while (0)
38 #define BUFFER_INVALIDATE(x, s) do { } while (0)
39 #endif /* VIRTIO_USE_DCACHE */
40 
41 /* Callback handler for rpmsg virtio service */
42 typedef int (*rpmsg_virtio_notify_wait_cb)(struct rpmsg_device *rdev, uint32_t id);
43 
47  void *base;
48 
50  size_t avail;
51 
53  size_t size;
54 };
55 
64  uint32_t h2r_buf_size;
65 
67  uint32_t r2h_buf_size;
68 
71 };
72 
76  struct rpmsg_device rdev;
77 
80 
83 
85  struct virtqueue *rvq;
86 
88  struct virtqueue *svq;
89 
91  struct metal_io_region *shbuf_io;
92 
95 
100  struct metal_list reclaimer;
101 
107 };
108 
109 #define RPMSG_REMOTE VIRTIO_DEV_DEVICE
110 #define RPMSG_HOST VIRTIO_DEV_DRIVER
111 
118 static inline void rpmsg_virtio_set_wait_cb(struct rpmsg_virtio_device *rvdev,
119  rpmsg_virtio_notify_wait_cb notify_wait_cb)
120 {
121  rvdev->notify_wait_cb = notify_wait_cb;
122 }
123 
131 static inline unsigned int
133 {
134  return rvdev->vdev->role;
135 }
136 
145 
154 
165 static inline int rpmsg_virtio_get_buffer_size(struct rpmsg_device *rdev)
166 {
167  return rpmsg_virtio_get_tx_buffer_size(rdev);
168 }
169 
193 int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev,
194  struct virtio_device *vdev,
195  rpmsg_ns_bind_cb ns_bind_cb,
196  struct metal_io_region *shm_io,
197  struct rpmsg_virtio_shm_pool *shpool);
198 
232  struct virtio_device *vdev,
233  rpmsg_ns_bind_cb ns_bind_cb,
234  struct metal_io_region *shm_io,
235  struct rpmsg_virtio_shm_pool *shpool,
236  const struct rpmsg_virtio_config *config);
237 
243 void rpmsg_deinit_vdev(struct rpmsg_virtio_device *rvdev);
244 
258  void *shbuf, size_t size);
259 
267 static inline struct rpmsg_device *
269 {
270  if (!rvdev)
271  return NULL;
272 
273  return &rvdev->rdev;
274 }
275 
289 metal_weak void *
291  size_t size);
292 
293 #if defined __cplusplus
294 }
295 #endif
296 
297 #endif /* _RPMSG_VIRTIO_H_ */
void(* rpmsg_ns_bind_cb)(struct rpmsg_device *rdev, const char *name, uint32_t dest)
Definition: rpmsg.h:56
int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev, struct virtio_device *vdev, rpmsg_ns_bind_cb ns_bind_cb, struct metal_io_region *shm_io, struct rpmsg_virtio_shm_pool *shpool, const struct rpmsg_virtio_config *config)
Initialize rpmsg virtio device with config.
Definition: rpmsg_virtio.c:788
metal_weak void * rpmsg_virtio_shm_pool_get_buffer(struct rpmsg_virtio_shm_pool *shpool, size_t size)
Get buffer in the shared memory pool.
static struct rpmsg_device * rpmsg_virtio_get_rpmsg_device(struct rpmsg_virtio_device *rvdev)
Get RPMsg device from RPMsg virtio device.
Definition: rpmsg_virtio.h:268
static void rpmsg_virtio_set_wait_cb(struct rpmsg_virtio_device *rvdev, rpmsg_virtio_notify_wait_cb notify_wait_cb)
Set the virtio callback to manage the wait for TX buffer availability.
Definition: rpmsg_virtio.h:118
static unsigned int rpmsg_virtio_get_role(struct rpmsg_virtio_device *rvdev)
Get rpmsg virtio device role.
Definition: rpmsg_virtio.h:132
int rpmsg_virtio_get_tx_buffer_size(struct rpmsg_device *rdev)
Get rpmsg virtio buffer size.
Definition: rpmsg_virtio.c:706
int rpmsg_virtio_get_rx_buffer_size(struct rpmsg_device *rdev)
Get rpmsg virtio Rx buffer size.
Definition: rpmsg_virtio.c:742
void rpmsg_virtio_init_shm_pool(struct rpmsg_virtio_shm_pool *shpool, void *shbuf, size_t size)
Initialize default shared buffers pool.
Definition: rpmsg_virtio.c:89
void rpmsg_deinit_vdev(struct rpmsg_virtio_device *rvdev)
Deinitialize rpmsg virtio device.
Definition: rpmsg_virtio.c:960
static int rpmsg_virtio_get_buffer_size(struct rpmsg_device *rdev)
Get rpmsg virtio Tx buffer size.
Definition: rpmsg_virtio.h:165
int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev, struct virtio_device *vdev, rpmsg_ns_bind_cb ns_bind_cb, struct metal_io_region *shm_io, struct rpmsg_virtio_shm_pool *shpool)
Initialize rpmsg virtio device.
Definition: rpmsg_virtio.c:778
int(* rpmsg_virtio_notify_wait_cb)(struct rpmsg_device *rdev, uint32_t id)
Definition: rpmsg_virtio.h:42
Representation of a RPMsg device.
Definition: rpmsg.h:133
Configuration of RPMsg device based on virtio.
Definition: rpmsg_virtio.h:62
bool split_shpool
The flag for splitting shared memory pool to TX and RX.
Definition: rpmsg_virtio.h:70
uint32_t h2r_buf_size
The size of the buffer used to send data from host to remote.
Definition: rpmsg_virtio.h:64
uint32_t r2h_buf_size
The size of the buffer used to send data from remote to host.
Definition: rpmsg_virtio.h:67
Representation of a RPMsg device based on virtio.
Definition: rpmsg_virtio.h:74
struct virtio_device * vdev
Pointer to the virtio device.
Definition: rpmsg_virtio.h:82
rpmsg_virtio_notify_wait_cb notify_wait_cb
Callback handler for rpmsg virtio service, called when service can't get tx buffer.
Definition: rpmsg_virtio.h:106
struct metal_io_region * shbuf_io
Pointer to the shared buffer I/O region.
Definition: rpmsg_virtio.h:91
struct rpmsg_virtio_shm_pool * shpool
Pointer to the shared buffers pool.
Definition: rpmsg_virtio.h:94
struct virtqueue * rvq
Pointer to receive virtqueue.
Definition: rpmsg_virtio.h:85
struct virtqueue * svq
Pointer to send virtqueue.
Definition: rpmsg_virtio.h:88
struct rpmsg_device rdev
RPMsg device.
Definition: rpmsg_virtio.h:76
struct rpmsg_virtio_config config
Structure containing virtio configuration.
Definition: rpmsg_virtio.h:79
struct metal_list reclaimer
RPMsg buffer reclaimer that contains buffers released by the rpmsg_virtio_release_tx_buffer function.
Definition: rpmsg_virtio.h:100
Shared memory pool used for RPMsg buffers.
Definition: rpmsg_virtio.h:45
size_t size
Total pool size.
Definition: rpmsg_virtio.h:53
size_t avail
Available memory size.
Definition: rpmsg_virtio.h:50
void * base
Base address of the memory pool.
Definition: rpmsg_virtio.h:47
Structure definition for virtio devices for use by the applications/drivers.
Definition: virtio.h:176
unsigned int role
If it is virtio backend or front end.
Definition: virtio.h:187
Local virtio queue to manage a virtio ring for sending or receiving.
Definition: virtqueue.h:78