From patchwork Tue Aug 16 14:38:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 74020 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp2040455qga; Tue, 16 Aug 2016 07:38:09 -0700 (PDT) X-Received: by 10.98.88.131 with SMTP id m125mr13166924pfb.63.1471358288862; Tue, 16 Aug 2016 07:38:08 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c6si32426434pfd.259.2016.08.16.07.38.08; Tue, 16 Aug 2016 07:38:08 -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 S1753806AbcHPOiB (ORCPT + 27 others); Tue, 16 Aug 2016 10:38:01 -0400 Received: from mail-wm0-f47.google.com ([74.125.82.47]:35321 "EHLO mail-wm0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753762AbcHPOh7 (ORCPT ); Tue, 16 Aug 2016 10:37:59 -0400 Received: by mail-wm0-f47.google.com with SMTP id f65so146280119wmi.0 for ; Tue, 16 Aug 2016 07:37:58 -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=E6+SIqNgSRwng/qaLCowDqJ76dNQTjJgDCooEjqtZXs=; b=dKP0HKS1lMV9xITjNcjxaGrsIOjA0UYrXZwV9Yf8gnqT3V7v73Gb8rD3qoe9Z7LF+1 vGDmKKfxDitkq0xa0JBOQDnDcLmJUibqQqvmSImDEC5PQfj/MIn4GqpouC4fAIZC+4// VGmY2Fl1oIGr/R5/InN/FFGTKgKputYZtjdX4= 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=E6+SIqNgSRwng/qaLCowDqJ76dNQTjJgDCooEjqtZXs=; b=PL+WeB69m1/vngbD3qxCUupU+zpHrmJQR/ulcqtbKzRdV+53uV+F3MhcTcu3DgsLxn qSUk5ivNrxwo8kgZRF+GK1Okndc+3yU5/s5RSByVNDETOQLhvKBLkuP5UVMa+aqc+s1r odlnYKdlRC59gfFVBz0NVRuVpvATNKoBZS0H2hW0JaEWG2QJAgELMs5RdiXfVcKo+IKh MthHn2RtkJuT0eiTIMcVhFiq+7Jq4dhZ/Gksov0y+l8LeXSzpFpZQnNepu5Bld3D5wH8 5x5xfSyjwgI6j6594ZHXlypFr20/GyX/eiqWZopcDIDC5rEczWxEhCRzh7dOvOn0BxjX 34Jw== X-Gm-Message-State: AEkooutXU7y4jyfcRO4zEl9szQ1XPBluynRLm9yl9s4FvmVErvDffzi7fpWCcwLQlamg7Sdr X-Received: by 10.194.175.106 with SMTP id bz10mr38738557wjc.42.1471358277614; Tue, 16 Aug 2016 07:37:57 -0700 (PDT) Received: from localhost.localdomain (host81-129-169-93.range81-129.btcentralplus.com. [81.129.169.93]) by smtp.gmail.com with ESMTPSA id e5sm3768484wma.13.2016.08.16.07.37.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Aug 2016 07:37:56 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: kernel@stlinux.com, patrice.chotard@st.com, ohad@wizery.com, bjorn.andersson@linaro.org, ssantosh@kernel.org, linux-remoteproc@vger.kernel.org, ludovic.barre@st.com, s-anna@ti.com, loic.pallardy@st.com, Lee Jones Subject: [PATCH v2 1/2] remoteproc: core: Add rproc OF look-up functions Date: Tue, 16 Aug 2016 15:38:23 +0100 Message-Id: <20160816143824.4120-1-lee.jones@linaro.org> X-Mailer: git-send-email 2.9.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org - 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 --- v1 => v2: - s/ti,rprocs/ti,rproc drivers/remoteproc/remoteproc_core.c | 78 +++++++++++++++++++++++++++++++++++- include/linux/remoteproc.h | 25 +++++++++++- 2 files changed, 101 insertions(+), 2 deletions(-) -- 2.9.0 diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index fe0539e..fe362fb 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,rproc", 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 */