Skip to content

Commit 7f36844

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 79b795e commit 7f36844

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
@@ -334,6 +334,23 @@ struct fw_rsc_vdev {
334334
struct fw_rsc_vdev_vring vring[0];
335335
} METAL_PACKED_END;
336336

337+
/**
338+
* struct fw_rsc_config - configuration space declaration
339+
* @h2r_buf_size: the size of the buffer used to send data from host to remote
340+
* @r2h_buf_size: the size of the buffer used to send data from remote to host
341+
* @reserved: reserved (must be zero)
342+
*
343+
* This structure immediately follow fw_rsc_vdev to provide the config info.
344+
*/
345+
METAL_PACKED_BEGIN
346+
struct fw_rsc_config {
347+
/* The individual buffer size(if VIRTIO_RPMSG_F_BUFSZ) */
348+
uint32_t h2r_buf_size;
349+
uint32_t r2h_buf_size;
350+
uint32_t reserved[14]; /* Reserve for the future use */
351+
/* Put the customize config here */
352+
} METAL_PACKED_END;
353+
337354
/**
338355
* @brief Resource table remote processor vendor specific entry
339356
*

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"
@@ -808,6 +809,7 @@ int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev,
808809
struct rpmsg_device *rdev;
809810
const char *vq_names[RPMSG_NUM_VRINGS];
810811
vq_callback callback[RPMSG_NUM_VRINGS];
812+
struct fw_rsc_config fw_config;
811813
int status;
812814
unsigned int i, role;
813815

@@ -854,6 +856,13 @@ int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev,
854856
vdev->features = rpmsg_virtio_get_features(rvdev);
855857
rdev->support_ns = !!(vdev->features & (1 << VIRTIO_RPMSG_F_NS));
856858

859+
if (vdev->features & (1 << VIRTIO_RPMSG_F_BUFSZ)) {
860+
rpmsg_virtio_read_config(rvdev,
861+
0, &fw_config, sizeof(fw_config));
862+
rvdev->config.h2r_buf_size = fw_config.h2r_buf_size;
863+
rvdev->config.r2h_buf_size = fw_config.r2h_buf_size;
864+
}
865+
857866
#ifndef VIRTIO_DEVICE_ONLY
858867
if (role == RPMSG_HOST) {
859868
/*

0 commit comments

Comments
 (0)