From cce22c23504fc34c2ca0c7f01b06682b5e13e1e6 Mon Sep 17 00:00:00 2001 From: Chao An Date: Mon, 10 Dec 2018 16:26:39 +0800 Subject: [PATCH] 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 --- lib/include/openamp/remoteproc.h | 17 +++++++++++++++++ lib/include/openamp/rpmsg_virtio.h | 1 + lib/rpmsg/rpmsg_virtio.c | 9 +++++++++ 3 files changed, 27 insertions(+) diff --git a/lib/include/openamp/remoteproc.h b/lib/include/openamp/remoteproc.h index d7fb8338b..ab0c3421e 100644 --- a/lib/include/openamp/remoteproc.h +++ b/lib/include/openamp/remoteproc.h @@ -334,6 +334,23 @@ struct fw_rsc_vdev { struct fw_rsc_vdev_vring vring[0]; } METAL_PACKED_END; +/** + * struct fw_rsc_config - configuration space declaration + * @h2r_buf_size: the size of the buffer used to send data from host to remote + * @r2h_buf_size: the size of the buffer used to send data from remote to host + * @reserved: reserved (must be zero) + * + * This structure immediately follow fw_rsc_vdev to provide the config info. + */ +METAL_PACKED_BEGIN +struct fw_rsc_config { + /* The individual buffer size(if VIRTIO_RPMSG_F_BUFSZ) */ + uint32_t h2r_buf_size; + uint32_t r2h_buf_size; + uint32_t reserved[14]; /* Reserve for the future use */ + /* Put the customize config here */ +} METAL_PACKED_END; + /** * @brief Resource table remote processor vendor specific entry * diff --git a/lib/include/openamp/rpmsg_virtio.h b/lib/include/openamp/rpmsg_virtio.h index 58308f70a..92253193e 100644 --- a/lib/include/openamp/rpmsg_virtio.h +++ b/lib/include/openamp/rpmsg_virtio.h @@ -29,6 +29,7 @@ extern "C" { /* The feature bitmap for virtio rpmsg */ #define VIRTIO_RPMSG_F_NS 0 /* RP supports name service notifications */ +#define VIRTIO_RPMSG_F_BUFSZ 2 /* RP supports buffer size negotiation */ #ifdef VIRTIO_CACHED_BUFFERS #warning "VIRTIO_CACHED_BUFFERS is deprecated, please use VIRTIO_USE_DCACHE" diff --git a/lib/rpmsg/rpmsg_virtio.c b/lib/rpmsg/rpmsg_virtio.c index 66623e54b..2b9aff8ac 100644 --- a/lib/rpmsg/rpmsg_virtio.c +++ b/lib/rpmsg/rpmsg_virtio.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include "rpmsg_internal.h" @@ -808,6 +809,7 @@ int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev, struct rpmsg_device *rdev; const char *vq_names[RPMSG_NUM_VRINGS]; vq_callback callback[RPMSG_NUM_VRINGS]; + struct fw_rsc_config fw_config; int status; unsigned int i, role; @@ -854,6 +856,13 @@ int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev, vdev->features = rpmsg_virtio_get_features(rvdev); rdev->support_ns = !!(vdev->features & (1 << VIRTIO_RPMSG_F_NS)); + if (vdev->features & (1 << VIRTIO_RPMSG_F_BUFSZ)) { + rpmsg_virtio_read_config(rvdev, + 0, &fw_config, sizeof(fw_config)); + rvdev->config.h2r_buf_size = fw_config.h2r_buf_size; + rvdev->config.r2h_buf_size = fw_config.r2h_buf_size; + } + #ifndef VIRTIO_DEVICE_ONLY if (role == RPMSG_HOST) { /*