Linux Remote Processor Subsystem development
 help / color / mirror / Atom feed
From: Divin Raj <divin.raj@arm.com>
To: Bjorn Andersson <andersson@kernel.org>,
	Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: linux-kernel@vger.kernel.org, linux-remoteproc@vger.kernel.org,
	Peter Hoyes <Peter.Hoyes@arm.com>
Subject: [PATCH 1/1] rpmsg: virtio: Make buffer size and number configurable
Date: Thu, 28 Sep 2023 16:38:25 +0100	[thread overview]
Message-ID: <20230928153825.151948-2-divin.raj@arm.com> (raw)
In-Reply-To: <20230928153825.151948-1-divin.raj@arm.com>

From: Peter Hoyes <Peter.Hoyes@arm.com>

Replace the MAX_RPMSG_BUF_SIZE and MAX_RPMSG_NUM_BUFS #define in
virtio_rpmsg_bus.c with the Kconfig parameters CONFIG_RPMSG_VIRTIO_BUF_SIZE
and CONFIG_RPMSG_VIRTIO_MAX_NUM_BUFS, allowing user-provided customization.

Making both the number of buffers and size configurable facilitates aligning
memory requirements between vdev-buffer and vdev-vrings for client drivers
that require larger buffer sizes, for example.

Signed-off-by: Peter Hoyes <Peter.Hoyes@arm.com>
Signed-off-by: Divin Raj <divin.raj@arm.com>
---
 drivers/rpmsg/Kconfig            | 23 +++++++++++++++++++++++
 drivers/rpmsg/virtio_rpmsg_bus.c | 27 +++------------------------
 2 files changed, 26 insertions(+), 24 deletions(-)

diff --git a/drivers/rpmsg/Kconfig b/drivers/rpmsg/Kconfig
index d3795860f5c0..677f4a1ac8bb 100644
--- a/drivers/rpmsg/Kconfig
+++ b/drivers/rpmsg/Kconfig
@@ -81,4 +81,27 @@ config RPMSG_VIRTIO
 	select RPMSG_NS
 	select VIRTIO
 
+config RPMSG_VIRTIO_MAX_BUF_SIZE
+	int "Virtio RPMSG max buffer size (in bytes)"
+	default 512
+	depends on RPMSG_VIRTIO
+	help
+	  This option allows you to configure the maximum buffer size (in bytes)
+	  for Virtio RPMSG communications. The number of buffers will be computed
+	  based on the number of buffers (CONFIG_RPMSG_VIRTIO_MAX_NUM_BUFS)
+	  supported by the vring. By default, it supports up to a maximum of 512
+	  buffers (256 in each direction). Each buffer consists of 16 bytes for the
+	  message header and the remaining bytes for the payload.The default values
+	  will utilize a maximum total space of 256KB for the buffers.
+
+config RPMSG_VIRTIO_MAX_NUM_BUFS
+	int "Virtio RPMSG max buffer count (even number for TX and Rx)"
+	default 512
+	depends on RPMSG_VIRTIO
+	help
+	  This option allows you to configure the maximum number of buffers used
+	  for Virtio RPMSG communication. By default, it supports up to a maximum
+	  of 512 buffers (256 in each direction). Please note that this value
+	  should be an even number, as it accounts for both transmit (TX) and
+	  receive (Rx) buffers.
 endmenu
diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c
index 905ac7910c98..87a9a4fa30e0 100644
--- a/drivers/rpmsg/virtio_rpmsg_bus.c
+++ b/drivers/rpmsg/virtio_rpmsg_bus.c
@@ -109,27 +109,6 @@ struct virtio_rpmsg_channel {
 #define to_virtio_rpmsg_channel(_rpdev) \
 	container_of(_rpdev, struct virtio_rpmsg_channel, rpdev)
 
-/*
- * We're allocating buffers of 512 bytes each for communications. The
- * number of buffers will be computed from the number of buffers supported
- * by the vring, upto a maximum of 512 buffers (256 in each direction).
- *
- * Each buffer will have 16 bytes for the msg header and 496 bytes for
- * the payload.
- *
- * This will utilize a maximum total space of 256KB for the buffers.
- *
- * We might also want to add support for user-provided buffers in time.
- * This will allow bigger buffer size flexibility, and can also be used
- * to achieve zero-copy messaging.
- *
- * Note that these numbers are purely a decision of this driver - we
- * can change this without changing anything in the firmware of the remote
- * processor.
- */
-#define MAX_RPMSG_NUM_BUFS	(512)
-#define MAX_RPMSG_BUF_SIZE	(512)
-
 /*
  * Local addresses are dynamically allocated on-demand.
  * We do not dynamically assign addresses from the low 1024 range,
@@ -902,12 +881,12 @@ static int rpmsg_probe(struct virtio_device *vdev)
 		virtqueue_get_vring_size(vrp->svq));
 
 	/* we need less buffers if vrings are small */
-	if (virtqueue_get_vring_size(vrp->rvq) < MAX_RPMSG_NUM_BUFS / 2)
+	if (virtqueue_get_vring_size(vrp->rvq) < CONFIG_RPMSG_VIRTIO_MAX_NUM_BUFS / 2)
 		vrp->num_bufs = virtqueue_get_vring_size(vrp->rvq) * 2;
 	else
-		vrp->num_bufs = MAX_RPMSG_NUM_BUFS;
+		vrp->num_bufs = CONFIG_RPMSG_VIRTIO_MAX_NUM_BUFS;
 
-	vrp->buf_size = MAX_RPMSG_BUF_SIZE;
+	vrp->buf_size = CONFIG_RPMSG_VIRTIO_MAX_BUF_SIZE;
 
 	total_buf_space = vrp->num_bufs * vrp->buf_size;
 
-- 
2.25.1


  reply	other threads:[~2023-09-28 15:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-28 15:38 [PATCH 0/1] rpmsg: virtio: Make buffer size and number configurable Divin Raj
2023-09-28 15:38 ` Divin Raj [this message]
2023-09-28 15:51   ` [PATCH 1/1] " Randy Dunlap
2023-09-28 16:10   ` Tanmay Shah
     [not found]     ` <45db1e0a-4f60-4fcc-bf30-06630a712ccc@arm.com>
2023-10-03 18:01       ` Tanmay Shah

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230928153825.151948-2-divin.raj@arm.com \
    --to=divin.raj@arm.com \
    --cc=Peter.Hoyes@arm.com \
    --cc=andersson@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-remoteproc@vger.kernel.org \
    --cc=mathieu.poirier@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox