From: Paul Cercueil <paul@crapouillou.net>
To: Bjorn Andersson <bjorn.andersson@linaro.org>,
Ohad Ben-Cohen <ohad@wizery.com>,
Arnaud Pouliquen <arnaud.pouliquen@st.com>
Cc: od@zcrc.me, linux-remoteproc@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
Paul Cercueil <paul@crapouillou.net>
Subject: [PATCH v7 2/5] remoteproc: Add device-managed variants of rproc_alloc/rproc_add
Date: Fri, 15 May 2020 12:43:37 +0200 [thread overview]
Message-ID: <20200515104340.10473-2-paul@crapouillou.net> (raw)
In-Reply-To: <20200515104340.10473-1-paul@crapouillou.net>
Add API functions devm_rproc_alloc() and devm_rproc_add(), which behave
like rproc_alloc() and rproc_add() respectively, but register their
respective cleanup function to be called on driver detach.
Signed-off-by: Paul Cercueil <paul@crapouillou.net>
Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
---
Notes:
v3: New patch
v4: No change
v5: - Fix return value documentation
- Fix typo in documentation
v6-v7: No change
drivers/remoteproc/remoteproc_core.c | 67 ++++++++++++++++++++++++++++
include/linux/remoteproc.h | 5 +++
2 files changed, 72 insertions(+)
diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index e12a54e67588..a7f96bc98406 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -1949,6 +1949,33 @@ int rproc_add(struct rproc *rproc)
}
EXPORT_SYMBOL(rproc_add);
+static void devm_rproc_remove(void *rproc)
+{
+ rproc_del(rproc);
+}
+
+/**
+ * devm_rproc_add() - resource managed rproc_add()
+ * @dev: the underlying device
+ * @rproc: the remote processor handle to register
+ *
+ * This function performs like rproc_add() but the registered rproc device will
+ * automatically be removed on driver detach.
+ *
+ * Returns: 0 on success, negative errno on failure
+ */
+int devm_rproc_add(struct device *dev, struct rproc *rproc)
+{
+ int err;
+
+ err = rproc_add(rproc);
+ if (err)
+ return err;
+
+ return devm_add_action_or_reset(dev, devm_rproc_remove, rproc);
+}
+EXPORT_SYMBOL(devm_rproc_add);
+
/**
* rproc_type_release() - release a remote processor instance
* @dev: the rproc's device
@@ -2171,6 +2198,46 @@ int rproc_del(struct rproc *rproc)
}
EXPORT_SYMBOL(rproc_del);
+static void devm_rproc_free(struct device *dev, void *res)
+{
+ rproc_free(*(struct rproc **)res);
+}
+
+/**
+ * devm_rproc_alloc() - resource managed rproc_alloc()
+ * @dev: the underlying device
+ * @name: name of this remote processor
+ * @ops: platform-specific handlers (mainly start/stop)
+ * @firmware: name of firmware file to load, can be NULL
+ * @len: length of private data needed by the rproc driver (in bytes)
+ *
+ * This function performs like rproc_alloc() but the acquired rproc device will
+ * automatically be released on driver detach.
+ *
+ * Returns: new rproc instance, or NULL on failure
+ */
+struct rproc *devm_rproc_alloc(struct device *dev, const char *name,
+ const struct rproc_ops *ops,
+ const char *firmware, int len)
+{
+ struct rproc **ptr, *rproc;
+
+ ptr = devres_alloc(devm_rproc_free, sizeof(*ptr), GFP_KERNEL);
+ if (!ptr)
+ return ERR_PTR(-ENOMEM);
+
+ rproc = rproc_alloc(dev, name, ops, firmware, len);
+ if (rproc) {
+ *ptr = rproc;
+ devres_add(dev, ptr);
+ } else {
+ devres_free(ptr);
+ }
+
+ return rproc;
+}
+EXPORT_SYMBOL(devm_rproc_alloc);
+
/**
* rproc_add_subdev() - add a subdevice to a remoteproc
* @rproc: rproc handle to add the subdevice to
diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
index 9c07d7958c53..8c9c0dda03c3 100644
--- a/include/linux/remoteproc.h
+++ b/include/linux/remoteproc.h
@@ -599,6 +599,11 @@ int rproc_add(struct rproc *rproc);
int rproc_del(struct rproc *rproc);
void rproc_free(struct rproc *rproc);
+struct rproc *devm_rproc_alloc(struct device *dev, const char *name,
+ const struct rproc_ops *ops,
+ const char *firmware, int len);
+int devm_rproc_add(struct device *dev, struct rproc *rproc);
+
void rproc_add_carveout(struct rproc *rproc, struct rproc_mem_entry *mem);
struct rproc_mem_entry *
--
2.26.2
next prev parent reply other threads:[~2020-05-15 10:43 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-15 10:43 [PATCH v7 1/5] dt-bindings: Document JZ47xx VPU auxiliary processor Paul Cercueil
2020-05-15 10:43 ` Paul Cercueil [this message]
2020-05-15 10:43 ` [PATCH v7 3/5] remoteproc: Add support for runtime PM Paul Cercueil
2020-05-22 16:47 ` Suman Anna
2020-05-22 17:11 ` Paul Cercueil
2020-06-08 22:03 ` Suman Anna
2020-06-08 22:46 ` Paul Cercueil
2020-06-08 23:10 ` Suman Anna
2020-06-10 9:40 ` Paul Cercueil
2020-06-11 4:39 ` Bjorn Andersson
2020-06-11 21:17 ` Suman Anna
2020-06-22 17:51 ` Arnaud POULIQUEN
2020-05-15 10:43 ` [PATCH v7 4/5] remoteproc: ingenic: Added remoteproc driver Paul Cercueil
2020-05-18 23:57 ` Bjorn Andersson
2020-06-11 21:47 ` Suman Anna
2020-06-11 22:21 ` Paul Cercueil
2020-06-12 0:21 ` Suman Anna
2020-06-12 11:47 ` Paul Cercueil
2020-06-12 14:47 ` Suman Anna
2020-06-21 19:30 ` Bjorn Andersson
2020-06-24 23:14 ` Mathieu Poirier
2020-05-15 10:43 ` [PATCH v7 5/5] MAINTAINERS: Add myself as reviewer for Ingenic rproc driver Paul Cercueil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200515104340.10473-2-paul@crapouillou.net \
--to=paul@crapouillou.net \
--cc=arnaud.pouliquen@st.com \
--cc=bjorn.andersson@linaro.org \
--cc=devicetree@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-remoteproc@vger.kernel.org \
--cc=od@zcrc.me \
--cc=ohad@wizery.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).