From patchwork Thu Sep 1 22:27:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 75241 Delivered-To: patch@linaro.org Received: by 10.140.29.8 with SMTP id a8csp536232qga; Thu, 1 Sep 2016 15:28:45 -0700 (PDT) X-Received: by 10.66.222.202 with SMTP id qo10mr30821105pac.76.1472768923918; Thu, 01 Sep 2016 15:28:43 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id yu2si7588818pac.273.2016.09.01.15.28.42; Thu, 01 Sep 2016 15:28:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752301AbcIAW2Y (ORCPT + 8 others); Thu, 1 Sep 2016 18:28:24 -0400 Received: from mail-pa0-f49.google.com ([209.85.220.49]:32890 "EHLO mail-pa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752043AbcIAW2U (ORCPT ); Thu, 1 Sep 2016 18:28:20 -0400 Received: by mail-pa0-f49.google.com with SMTP id cy9so33876649pac.0 for ; Thu, 01 Sep 2016 15:28:20 -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=XFZ9I0BQtdSn/MnNXQrXFXBAcZOa5O5Ijp5JSlzHKh8=; b=eWbXyppOZGEXVOwegKe1zmV2LW+fq0DUNdUqpMzkQZN/uBL7SclAeoGDvUCtIpOPmz AIc/vrG1jkTVYQx00Z88VHm2r7t3PMVmyZLoqiLgKfNozGtLurfCbJIGYSMyURd9OdNN tLV2k9brB1JIwGTUCAJy5UWY5AaXvp32V1RPw= 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=XFZ9I0BQtdSn/MnNXQrXFXBAcZOa5O5Ijp5JSlzHKh8=; b=SkfUqfOOBziACqC/dSufFecX+gN17DyS0+DI856E9gUVu8GdfHn818pyP1QXGCjPet Fwh6K0IVNLGChEw9ROAfT7actS5kELehRZDZw1xlQTrpm08UggtJVGzAqLlGWlkG34Rd Sl3yrLNbdSqt0SZ7kJVokm00xfmUsUuEiT0MyaA07HEk2fHG/DX69t28KEfA5VvZ2JJJ NmVZl5e+jf+tykutfyrieDV44TSMsSaHjhQE72SF5RmcT++Krjr9RwUZlWSvwT4W/D80 JjvBQMszUCDlAfVURU/dpw7oav+KT7ACws64jyxg+CwK0H6QrCPc08sXvYrZdzS3v0PA 11Ig== X-Gm-Message-State: AE9vXwNT2Hx3gSlbBsPU+9Y/+AI8ByUmfYiI2rY1bZx+Lp4RAvsYXTHRmuuYOzEv6Z9f5B5f X-Received: by 10.66.170.44 with SMTP id aj12mr30910737pac.131.1472768899460; Thu, 01 Sep 2016 15:28:19 -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 iw10sm8887131pac.14.2016.09.01.15.28.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Sep 2016 15:28:18 -0700 (PDT) From: Bjorn Andersson To: Ohad Ben-Cohen , Bjorn Andersson Cc: linux-remoteproc@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 06/17] rpmsg: Introduce indirection table for rpmsg_device operations Date: Thu, 1 Sep 2016 15:27:58 -0700 Message-Id: <1472768889-3906-7-git-send-email-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1472768889-3906-1-git-send-email-bjorn.andersson@linaro.org> References: <1472768889-3906-1-git-send-email-bjorn.andersson@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org To allow for multiple backend implementations add an indireection table for rpmsg_device related operations and move the virtio implementation behind this table. Signed-off-by: Bjorn Andersson --- Per Loic's comment I did consider adding parameter validation to the exposed functions in this patch, but as the previous implementation did not gracefully handle bad input parameters I decided to defer this until after this series has been merged. Changes since v1: - Split table in device vs endpoint - Moved ops pointer to the public structs to reduce code clutter - Kerneldoc for rpmsg_device_ops drivers/rpmsg/virtio_rpmsg_bus.c | 48 +++++++++++++++++++++++++++++++++++----- include/linux/rpmsg.h | 23 +++++++++++++++++++ 2 files changed, 65 insertions(+), 6 deletions(-) -- 2.5.0 -- To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index 1ac9fd871760..088203ed1df8 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -286,10 +286,18 @@ struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_device *rpdev, rpmsg_rx_cb_t cb, void *priv, struct rpmsg_channel_info chinfo) { - return __rpmsg_create_ept(rpdev->vrp, rpdev, cb, priv, chinfo.src); + return rpdev->ops->create_ept(rpdev, cb, priv, chinfo); } EXPORT_SYMBOL(rpmsg_create_ept); +static struct rpmsg_endpoint *virtio_rpmsg_create_ept(struct rpmsg_device *rpdev, + rpmsg_rx_cb_t cb, + void *priv, + struct rpmsg_channel_info chinfo) +{ + return __rpmsg_create_ept(rpdev->vrp, rpdev, cb, priv, chinfo.src); +} + /** * __rpmsg_destroy_ept() - destroy an existing rpmsg endpoint * @vrp: virtproc which owns this ept @@ -341,7 +349,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_channel_info chinfo = {}; struct rpmsg_endpoint *ept; int err; @@ -367,6 +374,18 @@ static int rpmsg_dev_probe(struct device *dev) goto out; } + if (rpdev->ops->announce_create) + err = rpdev->ops->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)) { @@ -381,15 +400,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 */ @@ -406,6 +423,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->ops->announce_destroy) + err = rpdev->ops->announce_destroy(rpdev); + rpdrv->remove(rpdev); rpmsg_destroy_ept(rpdev->ept); @@ -479,6 +508,12 @@ static int rpmsg_device_match(struct device *dev, void *data) return 1; } +static const struct rpmsg_device_ops virtio_rpmsg_ops = { + .create_ept = virtio_rpmsg_create_ept, + .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 @@ -508,6 +543,7 @@ static struct rpmsg_device *rpmsg_create_channel(struct virtproc_info *vrp, rpdev->vrp = vrp; rpdev->src = chinfo->src; rpdev->dst = chinfo->dst; + rpdev->ops = &virtio_rpmsg_ops; /* * rpmsg server channels has predefined local address (for now), diff --git a/include/linux/rpmsg.h b/include/linux/rpmsg.h index 35a0f39fd09b..9fdcfc7c7837 100644 --- a/include/linux/rpmsg.h +++ b/include/linux/rpmsg.h @@ -96,6 +96,8 @@ enum rpmsg_ns_flags { #define RPMSG_ADDR_ANY 0xFFFFFFFF struct virtproc_info; +struct rpmsg_endpoint; +struct rpmsg_device_ops; /** * struct rpmsg_channel_info - channel info representation @@ -127,11 +129,32 @@ struct rpmsg_device { u32 dst; struct rpmsg_endpoint *ept; bool announce; + + const struct rpmsg_device_ops *ops; }; typedef void (*rpmsg_rx_cb_t)(struct rpmsg_device *, void *, int, void *, u32); /** + * struct rpmsg_device_ops - indirection table for the rpmsg_device operations + * @create_ept: create backend-specific endpoint, requried + * @announce_create: announce presence of new channel, optional + * @announce_destroy: announce destruction of channel, optional + * + * Indirection table for the operations that a rpmsg backend should implement. + * @announce_create and @announce_destroy are optional as the backend might + * advertise new channels implicitly by creating the endpoints. + */ +struct rpmsg_device_ops { + struct rpmsg_endpoint *(*create_ept)(struct rpmsg_device *rpdev, + rpmsg_rx_cb_t cb, void *priv, + struct rpmsg_channel_info chinfo); + + 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 * @rpdev: rpmsg channel device * @refcount: when this drops to zero, the ept is deallocated