From patchwork Tue Aug 16 00:17:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 9282421 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3BFA8607FD for ; Tue, 16 Aug 2016 00:21:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B9AA21050 for ; Tue, 16 Aug 2016 00:21:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2083728E8E; Tue, 16 Aug 2016 00:21:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5556421050 for ; Tue, 16 Aug 2016 00:21:28 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bZS6i-0004fB-PC; Tue, 16 Aug 2016 00:19:52 +0000 Received: from mail-pf0-x230.google.com ([2607:f8b0:400e:c00::230]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bZS4k-0003RX-0d for linux-arm-kernel@lists.infradead.org; Tue, 16 Aug 2016 00:17:58 +0000 Received: by mail-pf0-x230.google.com with SMTP id p64so21403930pfb.1 for ; Mon, 15 Aug 2016 17:17:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=rETtzwZ8bLHASVxS89rZnLK5B8Kfw0FDoDe+CEQzRL8=; b=WGlyv9M4NkmxJQEcpiN+afySSoxJwxVnJP6uTSjLwhp9UjyN4RVtVXus/lmZSA+bxC TAMv85IO6YeveKU0H5SpiYV1ndZ6FUGP5VnifHCoAbtAc1X88xMOTziCNIKy32Tt7lt0 w0iHFZzIKXFBjZ1J4AUwoWSVwSwEzi0ROxpqY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=rETtzwZ8bLHASVxS89rZnLK5B8Kfw0FDoDe+CEQzRL8=; b=DzIIX1QYtVrHePY6j6nCHAdWVuEyTxJIfAbSgvwKI+rOT+BqP+xwovSiBbgpUluY49 oUcp0hijgGqpTKDp8fLy9YJ3qNkyCno86AwX/kN1MmAs8QJyrWzeRvJZUwTmKm7KW7GM g7RIPvHAjqbZynDrompwSy8KJnIOGHfNVKzkhcD5M8nZtm+E2A4HU0MWYb7TSS4/6gcf BeoM4BYegirf8bPJ0T0ZJidokNvn/5iyNULhGHQmzZKpPBProUs9ibMEHsV+NRR7v61Y Nwoez+RTSqFS6kXQpHuA1WtaczA0wYqW3NI0PCrMQdpzIQGQxYfqIGksU9FskgXxmk9O XeaQ== X-Gm-Message-State: AEkoouvUDREcgAec1k4eLuq6yFb1T+hSG5cuBcPufpMlgXBY+yNhYKubPI4CYBgTPAGW1COp X-Received: by 10.98.77.70 with SMTP id a67mr4555555pfb.151.1471306650133; Mon, 15 Aug 2016 17:17:30 -0700 (PDT) Received: from localhost.localdomain (ip68-111-223-48.sd.sd.cox.net. [68.111.223.48]) by smtp.gmail.com with ESMTPSA id p187sm34047931pfb.5.2016.08.15.17.17.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 15 Aug 2016 17:17:29 -0700 (PDT) From: Bjorn Andersson To: Ohad Ben-Cohen , Bjorn Andersson Subject: [PATCH 06/14] rpmsg: Indirect all virtio related function calls Date: Mon, 15 Aug 2016 17:17:12 -0700 Message-Id: <1471306640-29917-7-git-send-email-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1471306640-29917-1-git-send-email-bjorn.andersson@linaro.org> References: <1471306640-29917-1-git-send-email-bjorn.andersson@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160815_171750_359218_17ABC757 X-CRM114-Status: GOOD ( 16.77 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-msm@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Create indirections for functions in prepration for splitting the rpmsg core functionality from the virtio backend. Signed-off-by: Bjorn Andersson --- drivers/rpmsg/virtio_rpmsg_bus.c | 131 +++++++++++++++++++++++++++++++++++---- include/linux/rpmsg.h | 23 ++++++- 2 files changed, 139 insertions(+), 15 deletions(-) diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index a9f8cc8d968b..1dc7a1149c51 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -119,6 +119,17 @@ struct rpmsg_channel_info { /* Address 53 is reserved for advertising remote services */ #define RPMSG_NS_ADDR (53) +static int virtio_rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len); +static int virtio_rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len, + u32 dst); +static int virtio_rpmsg_send_offchannel(struct rpmsg_endpoint *ept, u32 src, + u32 dst, void *data, int len); +static int virtio_rpmsg_trysend(struct rpmsg_endpoint *ept, void *data, int len); +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); + /* sysfs show configuration fields */ #define rpmsg_show_attr(field, path, format_string) \ static ssize_t \ @@ -297,10 +308,17 @@ free_ept: struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_device *rpdev, rpmsg_rx_cb_t cb, void *priv, u32 addr) { - return __rpmsg_create_ept(rpdev->vrp, rpdev, cb, priv, addr); + return rpdev->create_ept(rpdev, cb, priv, addr); } EXPORT_SYMBOL(rpmsg_create_ept); +static struct rpmsg_endpoint *virtio_rpmsg_create_ept(struct rpmsg_device *rpdev, + rpmsg_rx_cb_t cb, + void *priv, u32 addr) +{ + return __rpmsg_create_ept(rpdev->vrp, rpdev, cb, priv, addr); +} + /** * __rpmsg_destroy_ept() - destroy an existing rpmsg endpoint * @vrp: virtproc which owns this ept @@ -336,10 +354,15 @@ __rpmsg_destroy_ept(struct virtproc_info *vrp, struct rpmsg_endpoint *ept) */ void rpmsg_destroy_ept(struct rpmsg_endpoint *ept) { - __rpmsg_destroy_ept(ept->rpdev->vrp, ept); + ept->rpdev->destroy_ept(ept); } EXPORT_SYMBOL(rpmsg_destroy_ept); +static void virtio_rpmsg_destroy_ept(struct rpmsg_endpoint *ept) +{ + __rpmsg_destroy_ept(ept->rpdev->vrp, ept); +} + /* * when an rpmsg driver is probed with a channel, we seamlessly create * it an endpoint, binding its rx callback to a unique local rpmsg @@ -352,7 +375,6 @@ static int rpmsg_dev_probe(struct device *dev) { struct rpmsg_device *rpdev = to_rpmsg_device(dev); struct rpmsg_driver *rpdrv = to_rpmsg_driver(rpdev->dev.driver); - struct virtproc_info *vrp = rpdev->vrp; struct rpmsg_endpoint *ept; int err; @@ -373,6 +395,18 @@ static int rpmsg_dev_probe(struct device *dev) goto out; } + if (rpdev->announce_create) + err = rpdev->announce_create(rpdev); +out: + return err; +} + +static int virtio_rpmsg_announce_create(struct rpmsg_device *rpdev) +{ + struct virtproc_info *vrp = rpdev->vrp; + struct device *dev = &rpdev->dev; + int err = 0; + /* need to tell remote processor's name service about this channel ? */ if (rpdev->announce && virtio_has_feature(vrp->vdev, VIRTIO_RPMSG_F_NS)) { @@ -387,15 +421,13 @@ static int rpmsg_dev_probe(struct device *dev) dev_err(dev, "failed to announce service %d\n", err); } -out: return err; } -static int rpmsg_dev_remove(struct device *dev) +static int virtio_rpmsg_announce_destroy(struct rpmsg_device *rpdev) { - struct rpmsg_device *rpdev = to_rpmsg_device(dev); - struct rpmsg_driver *rpdrv = to_rpmsg_driver(rpdev->dev.driver); struct virtproc_info *vrp = rpdev->vrp; + struct device *dev = &rpdev->dev; int err = 0; /* tell remote processor's name service we're removing this channel */ @@ -412,6 +444,18 @@ static int rpmsg_dev_remove(struct device *dev) dev_err(dev, "failed to announce service %d\n", err); } + return err; +} + +static int rpmsg_dev_remove(struct device *dev) +{ + struct rpmsg_device *rpdev = to_rpmsg_device(dev); + struct rpmsg_driver *rpdrv = to_rpmsg_driver(rpdev->dev.driver); + int err = 0; + + if (rpdev->announce_destroy) + err = rpdev->announce_destroy(rpdev); + rpdrv->remove(rpdev); rpmsg_destroy_ept(rpdev->ept); @@ -485,6 +529,19 @@ static int rpmsg_device_match(struct device *dev, void *data) return 1; } +static const struct rpmsg_device virtio_rpmsg_ops = { + .create_ept = virtio_rpmsg_create_ept, + .destroy_ept = virtio_rpmsg_destroy_ept, + .send = virtio_rpmsg_send, + .sendto = virtio_rpmsg_sendto, + .send_offchannel = virtio_rpmsg_send_offchannel, + .trysend = virtio_rpmsg_trysend, + .trysendto = virtio_rpmsg_trysendto, + .trysend_offchannel = virtio_rpmsg_trysend_offchannel, + .announce_create = virtio_rpmsg_announce_create, + .announce_destroy = virtio_rpmsg_announce_destroy, +}; + /* * create an rpmsg channel using its name and address info. * this function will be used to create both static and dynamic @@ -511,6 +568,9 @@ static struct rpmsg_device *rpmsg_create_channel(struct virtproc_info *vrp, if (!rpdev) return NULL; + /* Assign callbacks for rpmsg_channel */ + *rpdev = virtio_rpmsg_ops; + rpdev->vrp = vrp; rpdev->src = chinfo->src; rpdev->dst = chinfo->dst; @@ -793,11 +853,17 @@ out: int rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len) { struct rpmsg_device *rpdev = ept->rpdev; + + return rpdev->send(ept, data, len); +} + +static int virtio_rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len) +{ + struct rpmsg_device *rpdev = ept->rpdev; u32 src = ept->addr, dst = rpdev->dst; return rpmsg_send_offchannel_raw(rpdev, src, dst, data, len, true); } -EXPORT_SYMBOL(rpmsg_send); /** * rpmsg_sendto() - send a message across to the remote processor, specify dst @@ -820,11 +886,19 @@ EXPORT_SYMBOL(rpmsg_send); int rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst) { struct rpmsg_device *rpdev = ept->rpdev; + + return rpdev->sendto(ept, data, len, dst); +} +EXPORT_SYMBOL(rpmsg_sendto); + +static int virtio_rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len, + u32 dst) +{ + struct rpmsg_device *rpdev = ept->rpdev; u32 src = ept->addr; return rpmsg_send_offchannel_raw(rpdev, src, dst, data, len, true); } -EXPORT_SYMBOL(rpmsg_sendto); /** * rpmsg_send_offchannel() - send a message using explicit src/dst addresses @@ -851,10 +925,18 @@ int rpmsg_send_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst, { struct rpmsg_device *rpdev = ept->rpdev; - return rpmsg_send_offchannel_raw(rpdev, src, dst, data, len, true); + return rpdev->send_offchannel(ept, src, dst, data, len); } EXPORT_SYMBOL(rpmsg_send_offchannel); +static int virtio_rpmsg_send_offchannel(struct rpmsg_endpoint *ept, u32 src, + u32 dst, void *data, int len) +{ + struct rpmsg_device *rpdev = ept->rpdev; + + return rpmsg_send_offchannel_raw(rpdev, src, dst, data, len, true); +} + /** * rpmsg_send() - send a message across to the remote processor * @ept: the rpmsg endpoint @@ -875,11 +957,18 @@ EXPORT_SYMBOL(rpmsg_send_offchannel); int rpmsg_trysend(struct rpmsg_endpoint *ept, void *data, int len) { struct rpmsg_device *rpdev = ept->rpdev; + + return rpdev->trysend(ept, data, len); +} +EXPORT_SYMBOL(rpmsg_trysend); + +static int virtio_rpmsg_trysend(struct rpmsg_endpoint *ept, void *data, int len) +{ + struct rpmsg_device *rpdev = ept->rpdev; u32 src = ept->addr, dst = rpdev->dst; return rpmsg_send_offchannel_raw(rpdev, src, dst, data, len, false); } -EXPORT_SYMBOL(rpmsg_trysend); /** * rpmsg_sendto() - send a message across to the remote processor, specify dst @@ -901,11 +990,19 @@ EXPORT_SYMBOL(rpmsg_trysend); int rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst) { struct rpmsg_device *rpdev = ept->rpdev; + + return rpdev->trysendto(ept, data, len, dst); +} +EXPORT_SYMBOL(rpmsg_trysendto); + +static int virtio_rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data, + int len, u32 dst) +{ + struct rpmsg_device *rpdev = ept->rpdev; u32 src = ept->addr; return rpmsg_send_offchannel_raw(rpdev, src, dst, data, len, false); } -EXPORT_SYMBOL(rpmsg_trysendto); /** * rpmsg_send_offchannel() - send a message using explicit src/dst addresses @@ -931,10 +1028,18 @@ int rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst, { struct rpmsg_device *rpdev = ept->rpdev; - return rpmsg_send_offchannel_raw(rpdev, src, dst, data, len, false); + return rpdev->trysend_offchannel(ept, src, dst, data, len); } EXPORT_SYMBOL(rpmsg_trysend_offchannel); +static int virtio_rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src, + u32 dst, void *data, int len) +{ + struct rpmsg_device *rpdev = ept->rpdev; + + return rpmsg_send_offchannel_raw(rpdev, src, dst, data, len, false); +} + 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 3e3d5b1c154a..0b290ae18e70 100644 --- a/include/linux/rpmsg.h +++ b/include/linux/rpmsg.h @@ -96,6 +96,10 @@ enum rpmsg_ns_flags { #define RPMSG_ADDR_ANY 0xFFFFFFFF struct virtproc_info; +struct rpmsg_device; +struct rpmsg_endpoint; + +typedef void (*rpmsg_rx_cb_t)(struct rpmsg_device *, void *, int, void *, u32); /** * rpmsg_device - device that belong to the rpmsg bus @@ -115,9 +119,24 @@ struct rpmsg_device { u32 dst; struct rpmsg_endpoint *ept; bool announce; -}; -typedef void (*rpmsg_rx_cb_t)(struct rpmsg_device *, void *, int, void *, u32); + struct rpmsg_endpoint *(*create_ept)(struct rpmsg_device *rpdev, + rpmsg_rx_cb_t cb, void *priv, u32 addr); + void (*destroy_ept)(struct rpmsg_endpoint *ept); + + int (*send)(struct rpmsg_endpoint *ept, void *data, int len); + int (*sendto)(struct rpmsg_endpoint *ept, void *data, int len, u32 dst); + int (*send_offchannel)(struct rpmsg_endpoint *ept, u32 src, u32 dst, + void *data, int len); + + int (*trysend)(struct rpmsg_endpoint *ept, void *data, int len); + int (*trysendto)(struct rpmsg_endpoint *ept, void *data, int len, u32 dst); + int (*trysend_offchannel)(struct rpmsg_endpoint *ept, u32 src, u32 dst, + void *data, int len); + + int (*announce_create)(struct rpmsg_device *ept); + int (*announce_destroy)(struct rpmsg_device *ept); +}; /** * struct rpmsg_endpoint - binds a local rpmsg address to its user