OpenAMP Library  353
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 __deprecated
146 static inline void rpmsg_virtio_set_status(struct rpmsg_virtio_device *rvdev,
147  uint8_t status)
148 {
149  rvdev->vdev->func->set_status(rvdev->vdev, status);
150 }
151 
161 __deprecated
162 static inline uint8_t rpmsg_virtio_get_status(struct rpmsg_virtio_device *rvdev)
163 {
164  return rvdev->vdev->func->get_status(rvdev->vdev);
165 }
166 
176 __deprecated
177 static inline uint32_t
179 {
180  return rvdev->vdev->func->get_features(rvdev->vdev);
181 }
182 
193 __deprecated
194 static inline void
196  uint32_t offset, void *dst, int length)
197 {
198  rvdev->vdev->func->read_config(rvdev->vdev, offset, dst, length);
199 }
200 
213 __deprecated
214 static inline void
216  uint32_t offset, void *src, int length)
217 {
218  rvdev->vdev->func->write_config(rvdev->vdev, offset, src, length);
219 }
220 
234 __deprecated
235 static inline int
237  int flags, unsigned int nvqs,
238  const char *names[],
239  vq_callback *callbacks)
240 {
241  return virtio_create_virtqueues(rvdev->vdev, flags, nvqs, names,
242  callbacks, NULL);
243 }
244 
252 __deprecated
253 static inline void
255 {
257 }
258 
267 
276 
287 static inline int rpmsg_virtio_get_buffer_size(struct rpmsg_device *rdev)
288 {
289  return rpmsg_virtio_get_tx_buffer_size(rdev);
290 }
291 
315 int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev,
316  struct virtio_device *vdev,
317  rpmsg_ns_bind_cb ns_bind_cb,
318  struct metal_io_region *shm_io,
319  struct rpmsg_virtio_shm_pool *shpool);
320 
354  struct virtio_device *vdev,
355  rpmsg_ns_bind_cb ns_bind_cb,
356  struct metal_io_region *shm_io,
357  struct rpmsg_virtio_shm_pool *shpool,
358  const struct rpmsg_virtio_config *config);
359 
365 void rpmsg_deinit_vdev(struct rpmsg_virtio_device *rvdev);
366 
380  void *shbuf, size_t size);
381 
389 static inline struct rpmsg_device *
391 {
392  if (!rvdev)
393  return NULL;
394 
395  return &rvdev->rdev;
396 }
397 
411 metal_weak void *
413  size_t size);
414 
415 #if defined __cplusplus
416 }
417 #endif
418 
419 #endif /* _RPMSG_VIRTIO_H_ */
void(* rpmsg_ns_bind_cb)(struct rpmsg_device *rdev, const char *name, uint32_t dest)
Definition: rpmsg.h:56
static __deprecated void rpmsg_virtio_write_config(struct rpmsg_virtio_device *rvdev, uint32_t offset, void *src, int length)
Write configuration data to the rpmsg virtio device.
Definition: rpmsg_virtio.h:215
static __deprecated uint8_t rpmsg_virtio_get_status(struct rpmsg_virtio_device *rvdev)
Retrieve rpmsg virtio device status.
Definition: rpmsg_virtio.h:162
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 __deprecated int rpmsg_virtio_create_virtqueues(struct rpmsg_virtio_device *rvdev, int flags, unsigned int nvqs, const char *names[], vq_callback *callbacks)
Create the rpmsg virtio device virtqueue.
Definition: rpmsg_virtio.h:236
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:390
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 __deprecated void rpmsg_virtio_delete_virtqueues(struct rpmsg_virtio_device *rvdev)
Delete the virtqueues created in rpmsg_virtio_create_virtqueues()
Definition: rpmsg_virtio.h:254
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
static __deprecated void rpmsg_virtio_read_config(struct rpmsg_virtio_device *rvdev, uint32_t offset, void *dst, int length)
Retrieve configuration data from the rpmsg virtio device.
Definition: rpmsg_virtio.h:195
int rpmsg_virtio_get_rx_buffer_size(struct rpmsg_device *rdev)
Get rpmsg virtio Rx buffer size.
Definition: rpmsg_virtio.c:742
static __deprecated void rpmsg_virtio_set_status(struct rpmsg_virtio_device *rvdev, uint8_t status)
Set rpmsg virtio device status.
Definition: rpmsg_virtio.h:146
static __deprecated uint32_t rpmsg_virtio_get_features(struct rpmsg_virtio_device *rvdev)
Get the rpmsg virtio device features.
Definition: rpmsg_virtio.h:178
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:287
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:188
unsigned int role
If it is virtio backend or front end.
Definition: virtio.h:199
const struct virtio_dispatch * func
Virtio dispatch table.
Definition: virtio.h:205
void(* read_config)(struct virtio_device *dev, uint32_t offset, void *dst, int length)
Read a variable amount from the device specific (ie, network) configuration region.
Definition: virtio.h:265
uint8_t(* get_status)(struct virtio_device *dev)
Get the status of the virtio device.
Definition: virtio.h:243
uint32_t(* get_features)(struct virtio_device *dev)
Get the feature exposed by the virtio device.
Definition: virtio.h:249
void(* set_status)(struct virtio_device *dev, uint8_t status)
Set the status of the virtio device.
Definition: virtio.h:246
void(* write_config)(struct virtio_device *dev, uint32_t offset, void *src, int length)
Write a variable amount from the device specific (ie, network) configuration region.
Definition: virtio.h:272
Local virtio queue to manage a virtio ring for sending or receiving.
Definition: virtqueue.h:78
static void virtio_delete_virtqueues(struct virtio_device *vdev)
Delete the virtio device virtqueue.
Definition: virtio.h:312
int virtio_create_virtqueues(struct virtio_device *vdev, unsigned int flags, unsigned int nvqs, const char *names[], vq_callback callbacks[], void *callback_args[])
Create the virtio device virtqueue.
Definition: virtio.c:53
void(* vq_callback)(struct virtqueue *)
Definition: virtqueue.h:154