Skip to content

Commit a56398d

Browse files
anchaoxiaoxiang781216
authored andcommitted
Negotiate individual buffer size dynamically
If slave support VIRTIO_RPMSG_F_BUFSZ(0x04) feature, master determine the buffer size from config space(first 8 bytes), otherwise the default size(512 bytes) will be used. Signed-off-by: Chao An <[email protected]>
1 parent e4307e1 commit a56398d

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

lib/include/openamp/remoteproc.h

+17
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,23 @@ struct fw_rsc_vdev {
303303
struct fw_rsc_vdev_vring vring[0];
304304
} METAL_PACKED_END;
305305

306+
/**
307+
* struct fw_rsc_config - configuration space declaration
308+
* @h2r_buf_size: the size of the buffer used to send data from host to remote
309+
* @r2h_buf_size: the size of the buffer used to send data from remote to host
310+
* @reserved: reserved (must be zero)
311+
*
312+
* This structure immediately follow fw_rsc_vdev to provide the config info.
313+
*/
314+
METAL_PACKED_BEGIN
315+
struct fw_rsc_config {
316+
/* The individual buffer size(if VIRTIO_RPMSG_F_BUFSZ) */
317+
uint32_t h2r_buf_size;
318+
uint32_t r2h_buf_size;
319+
uint32_t reserved[14]; /* Reserve for the future use */
320+
/* Put the customize config here */
321+
} METAL_PACKED_END;
322+
306323
/**
307324
* struct fw_rsc_vendor - remote processor vendor specific resource
308325
* @len: length of the resource

lib/include/openamp/rpmsg_virtio.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <metal/mutex.h>
1717
#include <openamp/rpmsg.h>
1818
#include <openamp/virtio.h>
19+
#include <openamp/remoteproc.h>
1920

2021
#if defined __cplusplus
2122
extern "C" {
@@ -28,6 +29,7 @@ extern "C" {
2829

2930
/* The feature bitmap for virtio rpmsg */
3031
#define VIRTIO_RPMSG_F_NS 0 /* RP supports name service notifications */
32+
#define VIRTIO_RPMSG_F_BUFSZ 2 /* RP supports buffer size negotiation */
3133

3234
/**
3335
* struct rpmsg_virtio_shm_pool - shared memory pool used for rpmsg buffers
@@ -67,7 +69,7 @@ struct rpmsg_virtio_config {
6769
*/
6870
struct rpmsg_virtio_device {
6971
struct rpmsg_device rdev;
70-
struct rpmsg_virtio_config config;
72+
struct fw_rsc_config config;
7173
struct virtio_device *vdev;
7274
struct virtqueue *rvq;
7375
struct virtqueue *svq;

lib/rpmsg/rpmsg_virtio.c

+9-1
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,8 @@ int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev,
663663
if (config == NULL) {
664664
return RPMSG_ERR_PARAM;
665665
}
666-
rvdev->config = *config;
666+
rvdev->config.h2r_buf_size = config->h2r_buf_size;
667+
rvdev->config.r2h_buf_size = config->r2h_buf_size;
667668
}
668669
#else /*!VIRTIO_SLAVE_ONLY*/
669670
/* Ignore passed config in the virtio-device-only configuration. */
@@ -680,6 +681,13 @@ int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev,
680681
vdev->features = rpmsg_virtio_get_features(rvdev);
681682
rdev->support_ns = !!(vdev->features & (1 << VIRTIO_RPMSG_F_NS));
682683

684+
if (vdev->features & (1 << VIRTIO_RPMSG_F_BUFSZ)) {
685+
rpmsg_virtio_read_config(rvdev,
686+
0,
687+
&rvdev->config,
688+
sizeof(rvdev->config));
689+
}
690+
683691
#ifndef VIRTIO_SLAVE_ONLY
684692
if (role == RPMSG_MASTER) {
685693
/*

0 commit comments

Comments
 (0)