From patchwork Tue Jul 19 15:49:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 9237767 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 81DA1602F0 for ; Tue, 19 Jul 2016 15:52:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7126D2624C for ; Tue, 19 Jul 2016 15:52:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6562F26C2F; Tue, 19 Jul 2016 15:52:01 +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 CFA1B2624C for ; Tue, 19 Jul 2016 15:52: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 1bPXHy-0001dm-1I; Tue, 19 Jul 2016 15:50:30 +0000 Received: from mail-wm0-x235.google.com ([2a00:1450:400c:c09::235]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bPXHs-0000ms-Vw for linux-arm-kernel@lists.infradead.org; Tue, 19 Jul 2016 15:50:26 +0000 Received: by mail-wm0-x235.google.com with SMTP id q128so24013249wma.1 for ; Tue, 19 Jul 2016 08:50:03 -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; bh=UE48wIuq0Cc5c1LBAs/ku5dQPt7/Xw/yJgnz+cKhr8M=; b=OuRxKC+bMM/fMjkeLZzA1ZoSBY/dxopkOPnKM0ZPKzECBuzLGHSB+K0z2FA/qMYXuC ugqMeX7SJTaBpDoOE5MPQAKfR00h033tOOqSB1yzbdEFhFlYhOpyX4jzTg/Bi9hXmR4p RnzlhAhyZhW/vMnB9bf+5dMcbwQtiskDsMIgk= 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; bh=UE48wIuq0Cc5c1LBAs/ku5dQPt7/Xw/yJgnz+cKhr8M=; b=Z9F/bjJOCx9RSJ++ny3S/O+NH8+DBMyCs7noOO1H2wg9AOVnLWmTlWcxC2/AIL90/O POEA2IP8/sK2SH9FpF/7uKDIjUBKA+omxFPwceO5anXm5aOnWqMdvZRsPdKzg/mafgFA 0GzgHxVgi+DHZK5Wv9R62vbXbXvvmymXCD/olOe13nDek4ROEwXiJsLesJTGxjyZ/D/c BD6OmsC2HYEM/rchcI+AklksFJkBJf35TgALQ0VILquG2RO1abRJfWGlANi8ROQ4y3RH 3Cwz8i89tymIzAK8UekoJBliLkBzqHJJnWIeKsk8a/3KrbSsCrhNNGKh+5RYbGRCuOKo H19A== X-Gm-Message-State: ALyK8tLE+3COGbdl7HOPWyhCOzp/6r6yM/DwChmjaQfC/WOBU0YQNx5Lpg9XjqFaA1Vyn1lI X-Received: by 10.28.107.144 with SMTP id a16mr5430932wmi.75.1468943402464; Tue, 19 Jul 2016 08:50:02 -0700 (PDT) Received: from localhost.localdomain (host81-129-170-195.range81-129.btcentralplus.com. [81.129.170.195]) by smtp.gmail.com with ESMTPSA id g184sm23904164wme.15.2016.07.19.08.50.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Jul 2016 08:50:01 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] remoteproc: core: Add rproc OF look-up functions Date: Tue, 19 Jul 2016 16:49:04 +0100 Message-Id: <20160719154905.23344-1-lee.jones@linaro.org> X-Mailer: git-send-email 2.9.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160719_085025_567579_ABB85D4E X-CRM114-Status: GOOD ( 18.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: ohad@wizery.com, kernel@stlinux.com, linux-remoteproc@vger.kernel.org, patrice.chotard@st.com, bjorn.andersson@linaro.org, ssantosh@kernel.org, Lee Jones , ludovic.barre@st.com 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 - of_rproc_by_index(): look-up and obtain a reference to a rproc using the DT phandle "rprocs" and a index. - of_rproc_by_name(): 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 | 78 +++++++++++++++++++++++++++++++++++- include/linux/remoteproc.h | 25 +++++++++++- 2 files changed, 101 insertions(+), 2 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index db3958b..6a0d158 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -41,6 +41,8 @@ #include #include #include +#include +#include #include "remoteproc_internal.h" @@ -1191,6 +1193,81 @@ out: } EXPORT_SYMBOL(rproc_shutdown); +#ifdef CONFIG_OF +/** + * of_get_rproc_by_index() - lookup and obtain a reference to an rproc + * @np: node to search for rproc phandle + * @index: index into the phandle list + * + * This function increments the remote processor's refcount, so always + * use rproc_put() to decrement it back once rproc isn't needed anymore. + * + * Returns a pointer to the rproc struct on success or an appropriate error + * code otherwise. + */ +struct rproc *of_get_rproc_by_index(struct device_node *np, int index) +{ + struct rproc *rproc = NULL, *r; + struct device_node *rproc_np; + + if (index < 0) { + pr_err("Invalid index: %d\n", index); + return ERR_PTR(-EINVAL); + } + + rproc_np = of_parse_phandle(np, "rprocs", index); + if (!rproc_np) { + /* Unfortunately we have to support this, at least for now */ + rproc_np = of_parse_phandle(np, "ti,rprocs", index); + if (!rproc_np) { + pr_err("Failed to obtain phandle\n"); + return ERR_PTR(-ENODEV); + } + } + + mutex_lock(&rproc_list_mutex); + list_for_each_entry(r, &rproc_list, node) { + if (r->dev.parent && r->dev.parent->of_node == rproc_np) { + get_device(&r->dev); + rproc = r; + break; + } + } + mutex_unlock(&rproc_list_mutex); + + of_node_put(rproc_np); + + if (!rproc) + pr_err("Could not find rproc, deferring\n"); + + return rproc ?: ERR_PTR(-EPROBE_DEFER); +} +EXPORT_SYMBOL(of_get_rproc_by_index); + +/** + * of_get_rproc_by_name() - 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 + * + * This function increments the remote processor's refcount, so always + * use rproc_put() to decrement it back once rproc isn't needed anymore. + * + * Returns a pointer to the rproc struct on success or an appropriate error + * code otherwise. + */ +struct rproc *of_get_rproc_by_name(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_get_rproc_by_index(np, index); +} +EXPORT_SYMBOL(of_get_rproc_by_name); + /** * rproc_get_by_phandle() - find a remote processor by phandle * @phandle: phandle to the rproc @@ -1203,7 +1280,6 @@ EXPORT_SYMBOL(rproc_shutdown); * * Returns the rproc handle on success, and NULL on failure. */ -#ifdef CONFIG_OF struct rproc *rproc_get_by_phandle(phandle phandle) { struct rproc *rproc = NULL, *r; diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index 1c457a8..f130938 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -487,7 +487,6 @@ struct rproc_vdev { u32 rsc_offset; }; -struct rproc *rproc_get_by_phandle(phandle phandle); struct rproc *rproc_alloc(struct device *dev, const char *name, const struct rproc_ops *ops, const char *firmware, int len); @@ -511,4 +510,28 @@ static inline struct rproc *vdev_to_rproc(struct virtio_device *vdev) return rvdev->rproc; } +#ifdef CONFIG_OF +extern struct rproc *of_get_rproc_by_index(struct device_node *np, + int index); +extern struct rproc *of_get_rproc_by_name(struct device_node *np, + const char *name); +extern struct rproc *rproc_get_by_phandle(phandle phandle); +#else +static inline +struct rproc *of_get_rproc_by_index(struct device_node *np, int index) +{ + return NULL; +} +static inline +struct rproc *of_get_rproc_by_name(struct device_node *np, const char *name) +{ + return NULL; +} +static inline +struct rproc *rproc_get_by_phandle(phandle phandle) +{ + return NULL; +} +#endif /* CONFIG_OF */ + #endif /* REMOTEPROC_H */