Skip to content

Commit 4ac8ac2

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 <anchao@pinecone.net>
1 parent c468328 commit 4ac8ac2

3 files changed

Lines changed: 27 additions & 0 deletions

File tree

lib/include/openamp/remoteproc.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,23 @@ struct fw_rsc_vdev {
343343
struct fw_rsc_vdev_vring vring[0];
344344
} METAL_PACKED_END;
345345

346+
/**
347+
* struct fw_rsc_config - configuration space declaration
348+
* @h2r_buf_size: the size of the buffer used to send data from host to remote
349+
* @r2h_buf_size: the size of the buffer used to send data from remote to host
350+
* @reserved: reserved (must be zero)
351+
*
352+
* This structure immediately follow fw_rsc_vdev to provide the config info.
353+
*/
354+
METAL_PACKED_BEGIN
355+
struct fw_rsc_config {
356+
/* The individual buffer size(if VIRTIO_RPMSG_F_BUFSZ) */
357+
uint32_t h2r_buf_size;
358+
uint32_t r2h_buf_size;
359+
uint32_t reserved[14]; /* Reserve for the future use */
360+
/* Put the customize config here */
361+
} METAL_PACKED_END;
362+
346363
/**
347364
* @brief Resource table remote processor vendor specific entry
348365
*

lib/include/openamp/rpmsg_virtio.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ extern "C" {
2929

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

3334
#ifdef VIRTIO_CACHED_BUFFERS
3435
#warning "VIRTIO_CACHED_BUFFERS is deprecated, please use VIRTIO_USE_DCACHE"

lib/rpmsg/rpmsg_virtio.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <metal/sleep.h>
1313
#include <metal/utilities.h>
1414
#include <openamp/rpmsg_virtio.h>
15+
#include <openamp/remoteproc.h>
1516
#include <openamp/virtqueue.h>
1617

1718
#include "rpmsg_internal.h"
@@ -783,6 +784,7 @@ int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev,
783784
struct rpmsg_device *rdev;
784785
const char *vq_names[RPMSG_NUM_VRINGS];
785786
vq_callback callback[RPMSG_NUM_VRINGS];
787+
struct fw_rsc_config fw_config;
786788
uint32_t features;
787789
int status;
788790
unsigned int i;
@@ -829,6 +831,13 @@ int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev,
829831
return status;
830832
rdev->support_ns = !!(features & (1 << VIRTIO_RPMSG_F_NS));
831833

834+
if (features & (1 << VIRTIO_RPMSG_F_BUFSZ)) {
835+
virtio_read_config(vdev,
836+
0, &fw_config, sizeof(fw_config));
837+
rvdev->config.h2r_buf_size = fw_config.h2r_buf_size;
838+
rvdev->config.r2h_buf_size = fw_config.r2h_buf_size;
839+
}
840+
832841
if (VIRTIO_ROLE_IS_DRIVER(rvdev->vdev)) {
833842
/*
834843
* Since device is RPMSG Remote so we need to manage the

0 commit comments

Comments
 (0)