From patchwork Fri Jan 2 19:45:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Gerlach X-Patchwork-Id: 5560501 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C43EC9F2ED for ; Fri, 2 Jan 2015 19:48:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C343420256 for ; Fri, 2 Jan 2015 19:48:57 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C4FFE2024D for ; Fri, 2 Jan 2015 19:48:56 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Y78Ap-0008N5-KD; Fri, 02 Jan 2015 19:46:15 +0000 Received: from comal.ext.ti.com ([198.47.26.152]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Y78Al-0008Ls-Tz for linux-arm-kernel@lists.infradead.org; Fri, 02 Jan 2015 19:46:12 +0000 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id t02JjiOY000373; Fri, 2 Jan 2015 13:45:44 -0600 Received: from DLEE71.ent.ti.com (dlee71.ent.ti.com [157.170.170.114]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id t02JjhMS002997; Fri, 2 Jan 2015 13:45:43 -0600 Received: from dlep33.itg.ti.com (157.170.170.75) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.3.174.1; Fri, 2 Jan 2015 13:45:43 -0600 Received: from legion.dal.design.ti.com (legion.dal.design.ti.com [128.247.22.53]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id t02JjhFY018896; Fri, 2 Jan 2015 13:45:43 -0600 Received: from localhost (dave-ubuntu.am.dhcp.ti.com [128.247.71.184]) by legion.dal.design.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id t02Jjht19562; Fri, 2 Jan 2015 13:45:43 -0600 (CST) From: Dave Gerlach To: , , Subject: [PATCH] remoteproc: Introduce rproc_get_by_phandle API Date: Fri, 2 Jan 2015 13:45:21 -0600 Message-ID: <1420227921-40853-1-git-send-email-d-gerlach@ti.com> X-Mailer: git-send-email 2.1.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150102_114612_062180_28286E21 X-CRM114-Status: GOOD ( 16.28 ) X-Spam-Score: -5.0 (-----) Cc: Ohad Ben-Cohen , Tony Lindgren , Arnd Bergmann , Dave Gerlach X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Allow users of remoteproc the ability to get a handle to an rproc by passing a phandle supplied in the user's device tree node. This is useful in situations that require manual booting of the rproc. This patch uses the code removed by commit 40e575b1d0b3 ("remoteproc: remove the get_by_name/put API") for the ref counting a rproc klist code but has rproc_get_by_name replaced with an rproc_get_by_phandle API. Signed-off-by: Dave Gerlach --- Documentation/remoteproc.txt | 6 +++ drivers/remoteproc/remoteproc_core.c | 85 ++++++++++++++++++++++++++++++++++++ include/linux/remoteproc.h | 1 + 3 files changed, 92 insertions(+) diff --git a/Documentation/remoteproc.txt b/Documentation/remoteproc.txt index e6469fd..81b5240 100644 --- a/Documentation/remoteproc.txt +++ b/Documentation/remoteproc.txt @@ -51,6 +51,12 @@ cost. rproc_shutdown() returns, and users can still use it with a subsequent rproc_boot(), if needed. + struct rproc *rproc_get_by_phandle(const char *name) + - Find an rproc handle using a device tree phandle. Returns the rproc + handle on success, and NULL on failure. This function increments + the remote processor's refcount, so always use rproc_put() to + decrement it back once rproc isn't needed anymore. + 3. Typical usage #include diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index e2bd869..6b78ba4 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -36,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -44,6 +46,17 @@ #include "remoteproc_internal.h" +static void klist_rproc_get(struct klist_node *n); +static void klist_rproc_put(struct klist_node *n); + +/* + * klist of the available remote processors. + * + * We need this in order to support rproc lookups (needed by the + * rproc_get_by_phandle()). + */ +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, @@ -1234,6 +1247,72 @@ 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, node); + + 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, node); + + 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, node); +} + +/** + * rproc_get_by_phandle() - find a remote processor by phandle and boot it + * @phandle: phandle to the rproc + * + * Finds an rproc handle using the remote processor's phandle, and then + * boot it. If it's already powered on, then just immediately return + * (successfully). + * + * Returns the rproc handle on success, and NULL on failure. + * + * This function increments the remote processor's refcount, so always + * use rproc_put() to decrement it back once rproc isn't needed anymore. + * + * Note: currently this function (and its counterpart rproc_put()) are not + * being used. We need to scrutinize the use cases + * that still need them, and see if we can migrate them to use the non + * name-based boot/shutdown interface. + */ +struct rproc *rproc_get_by_phandle(uint32_t phandle) +{ + struct rproc *rproc; + struct klist_iter i; + struct device_node *np; + + np = of_find_node_by_phandle(phandle); + + /* find the remote processor, and upref its refcount */ + klist_iter_init(&rprocs, &i); + while ((rproc = next_rproc(&i)) != NULL) + if (rproc->dev.parent && rproc->dev.parent->of_node == np) { + get_device(&rproc->dev); + break; + } + klist_iter_exit(&i); + + return rproc; +} +EXPORT_SYMBOL(rproc_get_by_phandle); + /** * rproc_add() - register a remote processor * @rproc: the remote processor handle to register @@ -1263,6 +1342,9 @@ int rproc_add(struct rproc *rproc) if (ret < 0) return ret; + /* expose to rproc_get_by_phandle users */ + klist_add_tail(&rproc->node, &rprocs); + dev_info(dev, "%s is available\n", rproc->name); dev_info(dev, "Note: remoteproc is still under development and considered experimental.\n"); @@ -1452,6 +1534,9 @@ int rproc_del(struct rproc *rproc) /* Free the copy of the resource table */ kfree(rproc->cached_table); + /* the rproc is downref'ed as soon as it's removed from the klist */ + klist_del(&rproc->node); + device_del(&rproc->dev); return 0; diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index 2a25ee8..9bf7b52 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -522,6 +522,7 @@ struct rproc_vdev { u32 rsc_offset; }; +struct rproc *rproc_get_by_phandle(uint32_t phandle); struct rproc *rproc_alloc(struct device *dev, const char *name, const struct rproc_ops *ops, const char *firmware, int len);