Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp1952681ybm; Thu, 23 May 2019 09:06:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqw5GlhevRZj9FFcZ0kEuKkfZDl2qvj7xINmANRJTHOkrMPmZATJVAK33NmFTUX89Bwq8X2c X-Received: by 2002:a62:d286:: with SMTP id c128mr105682199pfg.159.1558627586494; Thu, 23 May 2019 09:06:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558627586; cv=none; d=google.com; s=arc-20160816; b=gUK1fa7X4viPeZd+Gv1MewQB/pPYkorYC0Ulu46genIpBDa+LDybp+xn2fY+U16XdN DzCXNkWWg3RFwLO1P9E+lsdCy2quhg4Cd0r+P1sYiVp3uOjUdaSGVCvAoQUfYeXzDyQE cUZYKtC58a2OplLE1YEpkBJQDrOuao1N1Nfwep7I3dfkjhBMBG5ASa4JjJjF6OKlgg1e FpY36h1kL3o9GcmFuvMM5BAVHxLOFxwOd52TP3rOaRc7G8M9s6QgOzzIq0Erwcwn+PdP 4vr2Xig20dRWFcFDNeCGqiS8BnTQ9F2uC2gnD5brdxlhbdwS8REMdkMXLE0jHIefVKbj w2XA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=g2r1PYprYm0q7r69H59lG9W4hLpzhwRj6BRor0lcTYE=; b=fKwi8A6Is+wXqVOJo8WQPmUI59cRiuflxr+PcgWiqCWawAjMid1blsofqW8OJrpPG9 8Gzj24lZ3rwM9vRSFpVeZdShJMw0HH6vzrqectCQP0D4BefDtk6Q0ET7vnfTq6Qd1JNf 2T2u44+i/GXGv46yD16DplswusMTzQVGdLg2nHlwSTQ4Exg8S1+gd0z3XrUxlThG6A/r zrOjX2zh3NGOjpbHvqhDZhfORvk5fT4qL4xFCQLIJtTm0X0nGcDASNCl+1IGQLm87h7W Pk+yGcfhp8dyz2s7VgP5WS07gGZFGhIrAtnpwHa0a6+dWi6QCxQbhDbCga6Jos9B8pNB zJ0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@st.com header.s=STMicroelectronics header.b=CkYEyMvu; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v4si26299279pfn.197.2019.05.23.09.06.08; Thu, 23 May 2019 09:06:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@st.com header.s=STMicroelectronics header.b=CkYEyMvu; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731053AbfEWQEJ (ORCPT + 99 others); Thu, 23 May 2019 12:04:09 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:38422 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730790AbfEWQEI (ORCPT ); Thu, 23 May 2019 12:04:08 -0400 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx08-00178001.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x4NG2J4q015240; Thu, 23 May 2019 18:03:57 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=g2r1PYprYm0q7r69H59lG9W4hLpzhwRj6BRor0lcTYE=; b=CkYEyMvu6TKt4mDB1kE22EY3KrJkwx/LYpByPXpP/PA+t0P0d0nntEoIvmfuazH4oX+i 7lxgpR11hhkOxziSueLjOFiyLCrw2Llu+BokYvyz6lD5GR2YrM0/N9RljFIjfWE2wzaY suW/fNQ7GZWwp9LsVj/RgY5Y9NKJXJLcdewrTvVNJH4hSb/ocCSNZswtUjBYyfEdmefH kD/flnyMDrd8uwKRaMLKqjYxLhxWJOwx4+Gr2LNKduxigchoMZc+yjIxoSK7/O0/n703 IwEOg2/7UBNBPN9K7pIWVhxcNQqSJ3sFQUUOd6uFppj8hoAsUQmLnNtsULM6j3KrYSlR WA== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2sj8xgrbb9-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Thu, 23 May 2019 18:03:57 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 4CB4C31; Thu, 23 May 2019 16:03:56 +0000 (GMT) Received: from Webmail-eu.st.com (Safex1hubcas23.st.com [10.75.90.46]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 25BC34E98; Thu, 23 May 2019 16:03:56 +0000 (GMT) Received: from SAFEX1HUBCAS21.st.com (10.75.90.44) by SAFEX1HUBCAS23.st.com (10.75.90.46) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 23 May 2019 18:03:56 +0200 Received: from localhost (10.48.0.131) by Webmail-ga.st.com (10.75.90.48) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 23 May 2019 18:03:55 +0200 From: Arnaud Pouliquen To: Ohad Ben-Cohen , Bjorn Andersson , Greg Kroah-Hartman , Jiri Slaby , xiang xiao , CC: , Fabien DESSENNE , , Alan Cox Subject: [PATCH v4 1/2] rpmsg: core: add possibility to get message payload length Date: Thu, 23 May 2019 18:03:20 +0200 Message-ID: <1558627401-1090-2-git-send-email-arnaud.pouliquen@st.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1558627401-1090-1-git-send-email-arnaud.pouliquen@st.com> References: <1558627401-1090-1-git-send-email-arnaud.pouliquen@st.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.48.0.131] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-05-23_13:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return the rpmsg buffer payload size for sending message, so rpmsg users can split a long message in several sub rpmsg buffers. Signed-off-by: Arnaud Pouliquen Signed-off-by: Fabien Dessenne --- drivers/rpmsg/rpmsg_core.c | 20 ++++++++++++++++++++ drivers/rpmsg/rpmsg_internal.h | 2 ++ drivers/rpmsg/virtio_rpmsg_bus.c | 11 +++++++++++ include/linux/rpmsg.h | 10 ++++++++++ 4 files changed, 43 insertions(+) diff --git a/drivers/rpmsg/rpmsg_core.c b/drivers/rpmsg/rpmsg_core.c index 8122807db380..75c8c403ffe5 100644 --- a/drivers/rpmsg/rpmsg_core.c +++ b/drivers/rpmsg/rpmsg_core.c @@ -283,6 +283,26 @@ int rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst, } EXPORT_SYMBOL(rpmsg_trysend_offchannel); +/** + * rpmsg_get_buf_payload_size() + * This function returns buffer payload size available for sending messages. + * + * @ept: the rpmsg endpoint + * + * Returns buffer payload size on success and an appropriate error value on + * failure. + */ +int rpmsg_get_buf_payload_size(struct rpmsg_endpoint *ept) +{ + if (WARN_ON(!ept)) + return -EINVAL; + if (!ept->ops->get_buf_payload_size) + return -ENXIO; + + return ept->ops->get_buf_payload_size(ept); +} +EXPORT_SYMBOL(rpmsg_get_buf_payload_size); + /* * match an rpmsg channel with a channel info struct. * this is used to make sure we're not creating rpmsg devices for channels diff --git a/drivers/rpmsg/rpmsg_internal.h b/drivers/rpmsg/rpmsg_internal.h index 0d791c30b7ea..6f733a556139 100644 --- a/drivers/rpmsg/rpmsg_internal.h +++ b/drivers/rpmsg/rpmsg_internal.h @@ -46,6 +46,7 @@ struct rpmsg_device_ops { * @trysend: see @rpmsg_trysend(), required * @trysendto: see @rpmsg_trysendto(), optional * @trysend_offchannel: see @rpmsg_trysend_offchannel(), optional + * @get_buf_payload_size: see @rpmsg_get_buf_payload_size(), optional * * Indirection table for the operations that a rpmsg backend should implement. * In addition to @destroy_ept, the backend must at least implement @send and @@ -65,6 +66,7 @@ struct rpmsg_endpoint_ops { void *data, int len); __poll_t (*poll)(struct rpmsg_endpoint *ept, struct file *filp, poll_table *wait); + int (*get_buf_payload_size)(struct rpmsg_endpoint *ept); }; int rpmsg_register_device(struct rpmsg_device *rpdev); diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index 5d3685bd76a2..82753e76e377 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -175,6 +175,7 @@ static int virtio_rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst); static int virtio_rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst, void *data, int len); +static int virtio_get_buf_payload_size(struct rpmsg_endpoint *ept); static const struct rpmsg_endpoint_ops virtio_endpoint_ops = { .destroy_ept = virtio_rpmsg_destroy_ept, @@ -184,6 +185,7 @@ static const struct rpmsg_endpoint_ops virtio_endpoint_ops = { .trysend = virtio_rpmsg_trysend, .trysendto = virtio_rpmsg_trysendto, .trysend_offchannel = virtio_rpmsg_trysend_offchannel, + .get_buf_payload_size = virtio_get_buf_payload_size, }; /** @@ -699,6 +701,15 @@ static int virtio_rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src, return rpmsg_send_offchannel_raw(rpdev, src, dst, data, len, false); } +static int virtio_get_buf_payload_size(struct rpmsg_endpoint *ept) +{ + struct rpmsg_device *rpdev = ept->rpdev; + struct virtio_rpmsg_channel *vch = to_virtio_rpmsg_channel(rpdev); + int size = vch->vrp->buf_size - sizeof(struct rpmsg_hdr); + + return size < 0 ? -EMSGSIZE : size; +} + static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev, struct rpmsg_hdr *msg, unsigned int len) { diff --git a/include/linux/rpmsg.h b/include/linux/rpmsg.h index 9fe156d1c018..250df2165086 100644 --- a/include/linux/rpmsg.h +++ b/include/linux/rpmsg.h @@ -135,6 +135,8 @@ int rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst, __poll_t rpmsg_poll(struct rpmsg_endpoint *ept, struct file *filp, poll_table *wait); +int rpmsg_get_buf_payload_size(struct rpmsg_endpoint *ept); + #else static inline int register_rpmsg_device(struct rpmsg_device *dev) @@ -242,6 +244,14 @@ static inline __poll_t rpmsg_poll(struct rpmsg_endpoint *ept, return 0; } +static int rpmsg_get_buf_payload_size(struct rpmsg_endpoint *ept) +{ + /* This shouldn't be possible */ + WARN_ON(1); + + return -ENXIO; +} + #endif /* IS_ENABLED(CONFIG_RPMSG) */ /* use a macro to avoid include chaining to get THIS_MODULE */ -- 2.7.4