From patchwork Thu May 5 13:29:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 67206 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp752048qge; Thu, 5 May 2016 06:32:28 -0700 (PDT) X-Received: by 10.98.100.71 with SMTP id y68mr20619665pfb.84.1462455148139; Thu, 05 May 2016 06:32:28 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id xo3si11432674pac.215.2016.05.05.06.32.27; Thu, 05 May 2016 06:32:28 -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=@linaro.org; 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; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757034AbcEENbr (ORCPT + 29 others); Thu, 5 May 2016 09:31:47 -0400 Received: from mail-wm0-f44.google.com ([74.125.82.44]:35247 "EHLO mail-wm0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756602AbcEENbo (ORCPT ); Thu, 5 May 2016 09:31:44 -0400 Received: by mail-wm0-f44.google.com with SMTP id e201so20713442wme.0 for ; Thu, 05 May 2016 06:31:43 -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=7Wk67C2UUH2h/XGv5I0j1bNJjd2sCCyb8kE0u9TiTJ4=; b=AIWLo91hgtzpKnenLcLSs40YfcOhRw3DF3rCvNGYXYhf1IYRu4OPl5j3+oULdm3fVh +qwrm0XSyi2BiUA2mt8x50B6h559tBwu12KSW8lwsgj29eEgx0L0U5RpglkMa4Rjfqmd Z3/Ft4bqwNgGtMQTuYfbUjWTcEEE9s6Cquzkg= 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=7Wk67C2UUH2h/XGv5I0j1bNJjd2sCCyb8kE0u9TiTJ4=; b=AONM2ABaOsCIbcoOcFrh9LYpYqkcg1UU2ohXBYciD2BfQp4Mq2XLCNYl6blrGVUVad o5n2nrjlyRdIMY7eOkF8CBeBm0Gfaaw3b8gl0+S7QfE2oakDVolLqNX/m3z7jGRdiWD2 7rebv/tUJAvWcUrNxvVuqfiCuFytzfzzVNpSHz5tUtl+PMDPyD8lnp5ATo5Xrr0li4KV 2vtLFL6dm/rif2oI8rmCSOWh0+g0cEBEwksEx2SByH8X5SeYzQ6mR/lHzCmVXYKRL63I voRRnmjLcL3ukPvFP8JlL1nJA14mqRSl/o/8N0JhLop9RTWRJuxarcuOlKfpWthI7u/Y EWow== X-Gm-Message-State: AOPr4FWIKBDeoprsKWCdZ06ngPl/eGSLuhvASdDN97kxO15kUDdXVeksxxz99ecnUVPXFfWW X-Received: by 10.28.63.15 with SMTP id m15mr3636104wma.55.1462455102885; Thu, 05 May 2016 06:31:42 -0700 (PDT) Received: from localhost.localdomain (host81-129-173-198.range81-129.btcentralplus.com. [81.129.173.198]) by smtp.gmail.com with ESMTPSA id lf9sm9776868wjc.44.2016.05.05.06.31.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 May 2016 06:31:42 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: kernel@stlinux.com, maxime.coquelin@st.com, ohad@wizery.com, bjorn.andersson@linaro.org, linux-remoteproc@vger.kernel.org, Lee Jones , Ludovic Barre Subject: [PATCH 2/5] remoteproc: core: Add rproc OF look-up functions Date: Thu, 5 May 2016 14:29:40 +0100 Message-Id: <1462454983-13168-3-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 2.8.0 In-Reply-To: <1462454983-13168-1-git-send-email-lee.jones@linaro.org> References: <1462454983-13168-1-git-send-email-lee.jones@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org - of_rproc_byindex(): look-up and obtain a reference to a rproc using the DT phandle "rprocs" and a index. - of_rproc_byname(): lookup and obtain a reference to a rproc using the DT phandle "rprocs" and "rproc-names". Signed-off-by: Ludovic Barre Signed-off-by: Lee Jones --- drivers/remoteproc/remoteproc_core.c | 96 +++++++++++++++++++++++++++++++++++- include/linux/remoteproc.h | 3 ++ 2 files changed, 98 insertions(+), 1 deletion(-) -- 2.8.0 diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 7db2818..85e5fd8 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -41,12 +41,19 @@ #include #include #include +#include +#include +#include #include "remoteproc_internal.h" static DEFINE_MUTEX(rproc_list_mutex); static LIST_HEAD(rproc_list); +static void klist_rproc_get(struct klist_node *n); +static void klist_rproc_put(struct klist_node *n); +static DEFINE_KLIST(rprocs, klist_rproc_get, klist_rproc_put); + typedef int (*rproc_handle_resources_t)(struct rproc *rproc, struct resource_table *table, int len); typedef int (*rproc_handle_resource_t)(struct rproc *rproc, @@ -1196,6 +1203,87 @@ out: } EXPORT_SYMBOL(rproc_shutdown); +/* will be called when an rproc is added to the rprocs klist */ +static void klist_rproc_get(struct klist_node *n) +{ + struct rproc *rproc = container_of(n, struct rproc, klist); + + get_device(&rproc->dev); +} + +/* will be called when an rproc is removed from the rprocs klist */ +static void klist_rproc_put(struct klist_node *n) +{ + struct rproc *rproc = container_of(n, struct rproc, klist); + + put_device(&rproc->dev); +} + +static struct rproc *next_rproc(struct klist_iter *i) +{ + struct klist_node *n; + + n = klist_next(i); + if (!n) + return NULL; + + return container_of(n, struct rproc, klist); +} + +/** + * of_rproc_by_index() - lookup and obtain a reference to an rproc + * @np: node to search for rproc + * @index: index into the phandle list + * + * Returns the rproc driver on success and an appropriate error code otherwise. + */ +struct rproc *of_rproc_byindex(struct device_node *np, int index) +{ + struct rproc *rproc; + struct device_node *rproc_node; + struct platform_device *pdev; + struct klist_iter i; + + if (index < 0) + return ERR_PTR(-EINVAL); + + rproc_node = of_parse_phandle(np, "rprocs", index); + if (!rproc_node) + return ERR_PTR(-ENODEV); + + pdev = of_find_device_by_node(rproc_node); + if (!pdev) + return ERR_PTR(-ENODEV); + + klist_iter_init(&rprocs, &i); + while ((rproc = next_rproc(&i)) != NULL) + if (rproc->dev.parent == &pdev->dev) + break; + klist_iter_exit(&i); + + return rproc; +} +EXPORT_SYMBOL(of_rproc_byindex); + +/** + * of_rproc_byname() - lookup and obtain a reference to an rproc + * @np: node to search for rproc + * @name: name of the remoteproc from device's point of view + * + * Returns the rproc driver on success and an appropriate error code otherwise. + */ +struct rproc *of_rproc_byname(struct device_node *np, const char *name) +{ + int index; + + if (unlikely(!name)) + return ERR_PTR(-EINVAL); + + index = of_property_match_string(np, "rproc-names", name); + return of_rproc_byindex(np, index); +} +EXPORT_SYMBOL(of_rproc_byname); + /** * rproc_get_by_phandle() - find a remote processor by phandle * @phandle: phandle to the rproc @@ -1282,7 +1370,13 @@ int rproc_add(struct rproc *rproc) /* create debugfs entries */ rproc_create_debug_dir(rproc); - return rproc_add_virtio_devices(rproc); + ret = rproc_add_virtio_devices(rproc); + if (ret < 0) + klist_remove(&rproc->klist); + else + klist_add_tail(&rproc->klist, &rprocs); + + return ret; } EXPORT_SYMBOL(rproc_add); diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index 9c4e138..4c96e78 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -410,6 +410,7 @@ enum rproc_crash_type { */ struct rproc { struct list_head node; + struct klist_node klist; struct iommu_domain *domain; const char *name; const char *firmware; @@ -494,6 +495,8 @@ int rproc_del(struct rproc *rproc); int rproc_boot(struct rproc *rproc); void rproc_shutdown(struct rproc *rproc); void rproc_report_crash(struct rproc *rproc, enum rproc_crash_type type); +struct rproc *of_rproc_byindex(struct device_node *np, int index); +struct rproc *of_rproc_byname(struct device_node *np, const char *name); static inline struct rproc_vdev *vdev_to_rvdev(struct virtio_device *vdev) {