From patchwork Tue Aug 16 00:17:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 9282425 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 EB88E607FD for ; Tue, 16 Aug 2016 00:23:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DAAC021050 for ; Tue, 16 Aug 2016 00:23:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CF2EB28E8E; Tue, 16 Aug 2016 00:23:00 +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 2581821050 for ; Tue, 16 Aug 2016 00:23:00 +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 1bZS87-00073Z-JF; Tue, 16 Aug 2016 00:21:19 +0000 Received: from mail-pf0-x229.google.com ([2607:f8b0:400e:c00::229]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bZS4o-0003SE-Ks for linux-arm-kernel@lists.infradead.org; Tue, 16 Aug 2016 00:18:03 +0000 Received: by mail-pf0-x229.google.com with SMTP id h186so21304653pfg.3 for ; Mon, 15 Aug 2016 17:17:34 -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=NDuw6BTfxP/V5MRK/owr+Wc5hjctyo7vc7BUgq3Z5t4=; b=QhSWSHLagFvW9FcnwbvCC0MkjrUJsiIUegnWhdFv3RGnD4uroEN9Z59juPYS+Lq0Ch W+gunga/dvTdfNXw713hpzrmj4oYs31LwxpybFhPOucdi5WXSbfjh8/c7ryYl6GM2Y1r 8J9E7FZjPy9D7uKZykrycV3zwmGl9UYEZMRyo= 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=NDuw6BTfxP/V5MRK/owr+Wc5hjctyo7vc7BUgq3Z5t4=; b=e/H64hV0jrgI+10AVzDrtKxzptjppa7UbMwBD8jsf1YJ48cZgKv7tQODqywl8P5+SV /pxgdNKcs9Ay6ESPTDk1taRSAha6TsM/nWQIX70U2gXOfRwStHf+/wkCUOu+e8KcAjLB 0v/nxqLgCkfEVEMGqe6rKt5ZbJvH1hX8VFFtV4uzFwCX4vFbEjwG0MUW86fqwkxmCmRT IVSkeuhKFLLekxO4lkbEAEwhtMgB2/SG9MHIZ8V3AdAeTjnr65xjxUPydW6qtQGVGiF5 bJrtoeo1PLM6qnPv2H+I4HqLl5hWtYcY2jk6nhI/N+Mwb13dbCBCuoiCI3vvDtLkRvFX tblA== X-Gm-Message-State: AEkoouvU0mXWRl7LtOpPVid3V+WrcSoykiXemPs/0lJPHF/xx/sWvB1ouKazMsmsSMR6BYcF X-Received: by 10.98.26.133 with SMTP id a127mr58404688pfa.46.1471306653709; Mon, 15 Aug 2016 17:17:33 -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.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 15 Aug 2016 17:17:33 -0700 (PDT) From: Bjorn Andersson To: Ohad Ben-Cohen , Bjorn Andersson Subject: [PATCH 09/14] rpmsg: Internalize rpmsg core ops Date: Mon, 15 Aug 2016 17:17:15 -0700 Message-Id: <1471306640-29917-10-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_171755_072460_6BAC034E X-CRM114-Status: GOOD ( 14.65 ) 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 Introduce a container struct rpmsg_channel around the rpmsg_device to keep rpmsg internal data hidden from the public API. Signed-off-by: Bjorn Andersson --- drivers/rpmsg/rpmsg_core.c | 42 +++++++++++++++++++++++----------------- drivers/rpmsg/rpmsg_internal.h | 30 ++++++++++++++++++++++++++++ drivers/rpmsg/virtio_rpmsg_bus.c | 10 ++++++---- include/linux/rpmsg.h | 17 ---------------- 4 files changed, 60 insertions(+), 39 deletions(-) diff --git a/drivers/rpmsg/rpmsg_core.c b/drivers/rpmsg/rpmsg_core.c index 73bbc5ea5778..6f7cc79f7229 100644 --- a/drivers/rpmsg/rpmsg_core.c +++ b/drivers/rpmsg/rpmsg_core.c @@ -80,7 +80,9 @@ struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_device *rpdev, rpmsg_rx_cb_t cb, void *priv, u32 addr) { - return rpdev->create_ept(rpdev, cb, priv, addr); + struct rpmsg_channel *rpch = to_rpmsg_channel(&rpdev->dev); + + return rpch->create_ept(rpdev, cb, priv, addr); } EXPORT_SYMBOL(rpmsg_create_ept); @@ -93,7 +95,9 @@ EXPORT_SYMBOL(rpmsg_create_ept); */ void rpmsg_destroy_ept(struct rpmsg_endpoint *ept) { - ept->rpdev->destroy_ept(ept); + struct rpmsg_channel *rpch = to_rpmsg_channel(&ept->rpdev->dev); + + rpch->destroy_ept(ept); } EXPORT_SYMBOL(rpmsg_destroy_ept); @@ -117,9 +121,9 @@ EXPORT_SYMBOL(rpmsg_destroy_ept); */ int rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len) { - struct rpmsg_device *rpdev = ept->rpdev; + struct rpmsg_channel *rpch = to_rpmsg_channel(&ept->rpdev->dev); - return rpdev->send(ept, data, len); + return rpch->send(ept, data, len); } /** @@ -142,9 +146,9 @@ int rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len) */ int rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst) { - struct rpmsg_device *rpdev = ept->rpdev; + struct rpmsg_channel *rpch = to_rpmsg_channel(&ept->rpdev->dev); - return rpdev->sendto(ept, data, len, dst); + return rpch->sendto(ept, data, len, dst); } EXPORT_SYMBOL(rpmsg_sendto); @@ -171,9 +175,9 @@ EXPORT_SYMBOL(rpmsg_sendto); int rpmsg_send_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst, void *data, int len) { - struct rpmsg_device *rpdev = ept->rpdev; + struct rpmsg_channel *rpch = to_rpmsg_channel(&ept->rpdev->dev); - return rpdev->send_offchannel(ept, src, dst, data, len); + return rpch->send_offchannel(ept, src, dst, data, len); } EXPORT_SYMBOL(rpmsg_send_offchannel); @@ -196,9 +200,9 @@ EXPORT_SYMBOL(rpmsg_send_offchannel); */ int rpmsg_trysend(struct rpmsg_endpoint *ept, void *data, int len) { - struct rpmsg_device *rpdev = ept->rpdev; + struct rpmsg_channel *rpch = to_rpmsg_channel(&ept->rpdev->dev); - return rpdev->trysend(ept, data, len); + return rpch->trysend(ept, data, len); } EXPORT_SYMBOL(rpmsg_trysend); @@ -221,9 +225,9 @@ EXPORT_SYMBOL(rpmsg_trysend); */ int rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst) { - struct rpmsg_device *rpdev = ept->rpdev; + struct rpmsg_channel *rpch = to_rpmsg_channel(&ept->rpdev->dev); - return rpdev->trysendto(ept, data, len, dst); + return rpch->trysendto(ept, data, len, dst); } EXPORT_SYMBOL(rpmsg_trysendto); @@ -249,9 +253,9 @@ EXPORT_SYMBOL(rpmsg_trysendto); int rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst, void *data, int len) { - struct rpmsg_device *rpdev = ept->rpdev; + struct rpmsg_channel *rpch = to_rpmsg_channel(&ept->rpdev->dev); - return rpdev->trysend_offchannel(ept, src, dst, data, len); + return rpch->trysend_offchannel(ept, src, dst, data, len); } EXPORT_SYMBOL(rpmsg_trysend_offchannel); @@ -330,6 +334,7 @@ static int rpmsg_uevent(struct device *dev, struct kobj_uevent_env *env) */ static int rpmsg_dev_probe(struct device *dev) { + struct rpmsg_channel *rpch = to_rpmsg_channel(dev); struct rpmsg_device *rpdev = to_rpmsg_device(dev); struct rpmsg_driver *rpdrv = to_rpmsg_driver(rpdev->dev.driver); struct rpmsg_endpoint *ept; @@ -352,20 +357,21 @@ static int rpmsg_dev_probe(struct device *dev) goto out; } - if (rpdev->announce_create) - err = rpdev->announce_create(rpdev); + if (rpch->announce_create) + err = rpch->announce_create(rpdev); out: return err; } static int rpmsg_dev_remove(struct device *dev) { + struct rpmsg_channel *rpch = to_rpmsg_channel(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); + if (rpch->announce_destroy) + err = rpch->announce_destroy(rpdev); rpdrv->remove(rpdev); diff --git a/drivers/rpmsg/rpmsg_internal.h b/drivers/rpmsg/rpmsg_internal.h index fa91075c7956..54083bf54d14 100644 --- a/drivers/rpmsg/rpmsg_internal.h +++ b/drivers/rpmsg/rpmsg_internal.h @@ -35,6 +35,36 @@ struct rpmsg_channel_info { u32 dst; }; +struct rpmsg_channel { + struct rpmsg_device rpdev; + + 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 *rpdev); + int (*announce_destroy)(struct rpmsg_device *rpdev); +}; + +static inline struct rpmsg_channel *to_rpmsg_channel(struct device *d) +{ + struct rpmsg_device *rpdev = to_rpmsg_device(d); + + return container_of(rpdev, struct rpmsg_channel, rpdev); +} + int rpmsg_register_device(struct rpmsg_device *rpdev); int rpmsg_unregister_device(struct device *parent, struct rpmsg_channel_info *chinfo); diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index 779c54304774..d08facbcd30a 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -271,7 +271,7 @@ static int virtio_rpmsg_announce_destroy(struct rpmsg_device *rpdev) return err; } -static const struct rpmsg_device virtio_rpmsg_ops = { +static const struct rpmsg_channel virtio_rpmsg_ops = { .create_ept = virtio_rpmsg_create_ept, .destroy_ept = virtio_rpmsg_destroy_ept, .send = virtio_rpmsg_send, @@ -292,6 +292,7 @@ static const struct rpmsg_device virtio_rpmsg_ops = { static struct rpmsg_device *rpmsg_create_channel(struct virtproc_info *vrp, struct rpmsg_channel_info *chinfo) { + struct rpmsg_channel *rpch; struct rpmsg_device *rpdev; struct device *tmp, *dev = &vrp->vdev->dev; int ret; @@ -306,13 +307,14 @@ static struct rpmsg_device *rpmsg_create_channel(struct virtproc_info *vrp, return NULL; } - rpdev = kzalloc(sizeof(*rpdev), GFP_KERNEL); - if (!rpdev) + rpch = kzalloc(sizeof(*rpch), GFP_KERNEL); + if (!rpch) return NULL; /* Assign callbacks for rpmsg_channel */ - *rpdev = virtio_rpmsg_ops; + *rpch = virtio_rpmsg_ops; + rpdev = &rpch->rpdev; rpdev->vrp = vrp; rpdev->src = chinfo->src; rpdev->dst = chinfo->dst; diff --git a/include/linux/rpmsg.h b/include/linux/rpmsg.h index 0b290ae18e70..3d0ff950c0d6 100644 --- a/include/linux/rpmsg.h +++ b/include/linux/rpmsg.h @@ -119,23 +119,6 @@ struct rpmsg_device { u32 dst; struct rpmsg_endpoint *ept; bool announce; - - 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); }; /**