All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roger Quadros <rogerq@ti.com>
To: tony@atomide.com, ohad@wizery.com, bjorn.andersson@linaro.org
Cc: s-anna@ti.com, david@lechnology.com, nsekhar@ti.com,
	t-kristo@ti.com, nsaulnier@ti.com, jreeder@ti.com,
	m-karicheri2@ti.com, woods.technical@gmail.com,
	linux-omap@vger.kernel.org, linux-remoteproc@vger.kernel.org,
	linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
	rogerq@ti.com
Subject: [PATCH v2 07/14] remoteproc: Add a rproc_set_firmware() API
Date: Mon, 4 Feb 2019 16:22:40 +0200	[thread overview]
Message-ID: <1549290167-876-8-git-send-email-rogerq@ti.com> (raw)
In-Reply-To: <1549290167-876-1-git-send-email-rogerq@ti.com>

From: Suman Anna <s-anna@ti.com>

A new API, rproc_set_firmware() is added to allow the remoteproc platform
drivers and remoteproc client drivers to be able to configure a custom
firmware name that is different from the default name used during
remoteproc registration. This function is being introduced to provide
a kernel-level equivalent of the current sysfs interface to remoteproc
client drivers. This allows some remoteproc drivers to choose different
firmwares at runtime when the remote processor is not running based on
the functional feature it is providing using that remote processor.
The TI PRU Ethernet driver will be an example of such usage as it
requires to use different firmwares for different supported protocols.

Also, update the firmware_store() function used by the sysfs interface
to reuse this function to avoid code duplication.

Signed-off-by: Suman Anna <s-anna@ti.com>
Signed-off-by: Roger Quadros <rogerq@ti.com>
---
 drivers/remoteproc/remoteproc_core.c  | 61 +++++++++++++++++++++++++++++++++++
 drivers/remoteproc/remoteproc_sysfs.c | 33 ++-----------------
 include/linux/remoteproc.h            |  1 +
 3 files changed, 64 insertions(+), 31 deletions(-)

diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index 06ef4fa..2d9646f 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -2149,6 +2149,67 @@ void rproc_report_crash(struct rproc *rproc, enum rproc_crash_type type)
 }
 EXPORT_SYMBOL(rproc_report_crash);
 
+/**
+ * rproc_set_firmware() - assign a new firmware
+ * @rproc: rproc handle to which the new firmware is being assigned
+ * @fw_name: new firmware name to be assigned
+ *
+ * This function allows remoteproc drivers or clients to configure a custom
+ * firmware name that is different from the default name used during remoteproc
+ * registration. The function does not trigger a remote processor boot,
+ * only sets the firmware name used for a subsequent boot. This function
+ * should also be called only when the remote processor is offline.
+ *
+ * This allows either the userspace to configure a different name through
+ * sysfs or a kernel-level remoteproc or a remoteproc client driver to set
+ * a specific firmware when it is controlling the boot and shutdown of the
+ * remote processor.
+ *
+ * Returns 0 on success or a negative value upon failure
+ */
+int rproc_set_firmware(struct rproc *rproc, const char *fw_name)
+{
+	struct device *dev = rproc->dev.parent;
+	int ret, len;
+	char *p;
+
+	if (!rproc || !fw_name)
+		return -EINVAL;
+
+	ret = mutex_lock_interruptible(&rproc->lock);
+	if (ret) {
+		dev_err(dev, "can't lock rproc %s: %d\n", rproc->name, ret);
+		return -EINVAL;
+	}
+
+	if (rproc->state != RPROC_OFFLINE) {
+		dev_err(dev, "can't change firmware while running\n");
+		ret = -EBUSY;
+		goto out;
+	}
+
+	len = strcspn(fw_name, "\n");
+	if (!len) {
+		dev_err(dev, "empty firmware name string\n");
+		ret = -EINVAL;
+		goto out;
+	}
+
+	p = kstrndup(fw_name, len, GFP_KERNEL);
+	if (!p) {
+		ret = -ENOMEM;
+		goto out;
+	}
+
+	kfree(rproc->firmware);
+	rproc->firmware = p;
+
+out:
+	mutex_unlock(&rproc->lock);
+	return ret;
+}
+EXPORT_SYMBOL(rproc_set_firmware);
+
 static int __init remoteproc_init(void)
 {
 	rproc_init_sysfs();
diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c
index 3a4c3d7..6cf04a7 100644
--- a/drivers/remoteproc/remoteproc_sysfs.c
+++ b/drivers/remoteproc/remoteproc_sysfs.c
@@ -32,38 +32,9 @@ static ssize_t firmware_store(struct device *dev,
 			      const char *buf, size_t count)
 {
 	struct rproc *rproc = to_rproc(dev);
-	char *p;
-	int err, len = count;
+	int err;
 
-	err = mutex_lock_interruptible(&rproc->lock);
-	if (err) {
-		dev_err(dev, "can't lock rproc %s: %d\n", rproc->name, err);
-		return -EINVAL;
-	}
-
-	if (rproc->state != RPROC_OFFLINE) {
-		dev_err(dev, "can't change firmware while running\n");
-		err = -EBUSY;
-		goto out;
-	}
-
-	len = strcspn(buf, "\n");
-	if (!len) {
-		dev_err(dev, "can't provide a NULL firmware\n");
-		err = -EINVAL;
-		goto out;
-	}
-
-	p = kstrndup(buf, len, GFP_KERNEL);
-	if (!p) {
-		err = -ENOMEM;
-		goto out;
-	}
-
-	kfree(rproc->firmware);
-	rproc->firmware = p;
-out:
-	mutex_unlock(&rproc->lock);
+	err = rproc_set_firmware(rproc, buf);
 
 	return err ? err : count;
 }
diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
index e908b58..b5aa5fb 100644
--- a/include/linux/remoteproc.h
+++ b/include/linux/remoteproc.h
@@ -590,6 +590,7 @@ rproc_of_resm_mem_entry_init(struct device *dev, u32 of_resm_idx, int len,
 
 int rproc_boot(struct rproc *rproc);
 void rproc_shutdown(struct rproc *rproc);
+int rproc_set_firmware(struct rproc *rproc, const char *fw_name);
 void rproc_report_crash(struct rproc *rproc, enum rproc_crash_type type);
 int rproc_coredump_add_segment(struct rproc *rproc, dma_addr_t da, size_t size);
 int rproc_coredump_add_custom_segment(struct rproc *rproc,
-- 
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

WARNING: multiple messages have this Message-ID (diff)
From: Roger Quadros <rogerq@ti.com>
To: <tony@atomide.com>, <ohad@wizery.com>, <bjorn.andersson@linaro.org>
Cc: <s-anna@ti.com>, <david@lechnology.com>, <nsekhar@ti.com>,
	<t-kristo@ti.com>, <nsaulnier@ti.com>, <jreeder@ti.com>,
	<m-karicheri2@ti.com>, <woods.technical@gmail.com>,
	<linux-omap@vger.kernel.org>, <linux-remoteproc@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <devicetree@vger.kernel.org>,
	<rogerq@ti.com>
Subject: [PATCH v2 07/14] remoteproc: Add a rproc_set_firmware() API
Date: Mon, 4 Feb 2019 16:22:40 +0200	[thread overview]
Message-ID: <1549290167-876-8-git-send-email-rogerq@ti.com> (raw)
In-Reply-To: <1549290167-876-1-git-send-email-rogerq@ti.com>

From: Suman Anna <s-anna@ti.com>

A new API, rproc_set_firmware() is added to allow the remoteproc platform
drivers and remoteproc client drivers to be able to configure a custom
firmware name that is different from the default name used during
remoteproc registration. This function is being introduced to provide
a kernel-level equivalent of the current sysfs interface to remoteproc
client drivers. This allows some remoteproc drivers to choose different
firmwares at runtime when the remote processor is not running based on
the functional feature it is providing using that remote processor.
The TI PRU Ethernet driver will be an example of such usage as it
requires to use different firmwares for different supported protocols.

Also, update the firmware_store() function used by the sysfs interface
to reuse this function to avoid code duplication.

Signed-off-by: Suman Anna <s-anna@ti.com>
Signed-off-by: Roger Quadros <rogerq@ti.com>
---
 drivers/remoteproc/remoteproc_core.c  | 61 +++++++++++++++++++++++++++++++++++
 drivers/remoteproc/remoteproc_sysfs.c | 33 ++-----------------
 include/linux/remoteproc.h            |  1 +
 3 files changed, 64 insertions(+), 31 deletions(-)

diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index 06ef4fa..2d9646f 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -2149,6 +2149,67 @@ void rproc_report_crash(struct rproc *rproc, enum rproc_crash_type type)
 }
 EXPORT_SYMBOL(rproc_report_crash);
 
+/**
+ * rproc_set_firmware() - assign a new firmware
+ * @rproc: rproc handle to which the new firmware is being assigned
+ * @fw_name: new firmware name to be assigned
+ *
+ * This function allows remoteproc drivers or clients to configure a custom
+ * firmware name that is different from the default name used during remoteproc
+ * registration. The function does not trigger a remote processor boot,
+ * only sets the firmware name used for a subsequent boot. This function
+ * should also be called only when the remote processor is offline.
+ *
+ * This allows either the userspace to configure a different name through
+ * sysfs or a kernel-level remoteproc or a remoteproc client driver to set
+ * a specific firmware when it is controlling the boot and shutdown of the
+ * remote processor.
+ *
+ * Returns 0 on success or a negative value upon failure
+ */
+int rproc_set_firmware(struct rproc *rproc, const char *fw_name)
+{
+	struct device *dev = rproc->dev.parent;
+	int ret, len;
+	char *p;
+
+	if (!rproc || !fw_name)
+		return -EINVAL;
+
+	ret = mutex_lock_interruptible(&rproc->lock);
+	if (ret) {
+		dev_err(dev, "can't lock rproc %s: %d\n", rproc->name, ret);
+		return -EINVAL;
+	}
+
+	if (rproc->state != RPROC_OFFLINE) {
+		dev_err(dev, "can't change firmware while running\n");
+		ret = -EBUSY;
+		goto out;
+	}
+
+	len = strcspn(fw_name, "\n");
+	if (!len) {
+		dev_err(dev, "empty firmware name string\n");
+		ret = -EINVAL;
+		goto out;
+	}
+
+	p = kstrndup(fw_name, len, GFP_KERNEL);
+	if (!p) {
+		ret = -ENOMEM;
+		goto out;
+	}
+
+	kfree(rproc->firmware);
+	rproc->firmware = p;
+
+out:
+	mutex_unlock(&rproc->lock);
+	return ret;
+}
+EXPORT_SYMBOL(rproc_set_firmware);
+
 static int __init remoteproc_init(void)
 {
 	rproc_init_sysfs();
diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c
index 3a4c3d7..6cf04a7 100644
--- a/drivers/remoteproc/remoteproc_sysfs.c
+++ b/drivers/remoteproc/remoteproc_sysfs.c
@@ -32,38 +32,9 @@ static ssize_t firmware_store(struct device *dev,
 			      const char *buf, size_t count)
 {
 	struct rproc *rproc = to_rproc(dev);
-	char *p;
-	int err, len = count;
+	int err;
 
-	err = mutex_lock_interruptible(&rproc->lock);
-	if (err) {
-		dev_err(dev, "can't lock rproc %s: %d\n", rproc->name, err);
-		return -EINVAL;
-	}
-
-	if (rproc->state != RPROC_OFFLINE) {
-		dev_err(dev, "can't change firmware while running\n");
-		err = -EBUSY;
-		goto out;
-	}
-
-	len = strcspn(buf, "\n");
-	if (!len) {
-		dev_err(dev, "can't provide a NULL firmware\n");
-		err = -EINVAL;
-		goto out;
-	}
-
-	p = kstrndup(buf, len, GFP_KERNEL);
-	if (!p) {
-		err = -ENOMEM;
-		goto out;
-	}
-
-	kfree(rproc->firmware);
-	rproc->firmware = p;
-out:
-	mutex_unlock(&rproc->lock);
+	err = rproc_set_firmware(rproc, buf);
 
 	return err ? err : count;
 }
diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
index e908b58..b5aa5fb 100644
--- a/include/linux/remoteproc.h
+++ b/include/linux/remoteproc.h
@@ -590,6 +590,7 @@ rproc_of_resm_mem_entry_init(struct device *dev, u32 of_resm_idx, int len,
 
 int rproc_boot(struct rproc *rproc);
 void rproc_shutdown(struct rproc *rproc);
+int rproc_set_firmware(struct rproc *rproc, const char *fw_name);
 void rproc_report_crash(struct rproc *rproc, enum rproc_crash_type type);
 int rproc_coredump_add_segment(struct rproc *rproc, dma_addr_t da, size_t size);
 int rproc_coredump_add_custom_segment(struct rproc *rproc,
-- 
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki


  parent reply	other threads:[~2019-02-04 14:22 UTC|newest]

Thread overview: 122+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-04 14:22 [PATCH v2 00/14] Add support for TI PRU ICSS Roger Quadros
2019-02-04 14:22 ` Roger Quadros
2019-02-04 14:22 ` [PATCH v2 01/14] dt-bindings: remoteproc: Add TI PRUSS bindings Roger Quadros
2019-02-04 14:22   ` Roger Quadros
2019-02-04 16:33   ` Tony Lindgren
2019-02-05  9:39     ` Roger Quadros
2019-02-05  9:39       ` Roger Quadros
2019-02-05 15:08       ` Murali Karicheri
2019-02-05 15:08         ` Murali Karicheri
2019-02-05 15:41         ` Roger Quadros
2019-02-05 15:41           ` Roger Quadros
2019-02-05 16:15           ` Murali Karicheri
2019-02-05 16:15             ` Murali Karicheri
2019-02-05 16:19             ` Tony Lindgren
2019-02-06 15:04               ` Roger Quadros
2019-02-06 15:04                 ` Roger Quadros
2019-02-14  2:47                 ` Suman Anna
2019-02-14  2:47                   ` Suman Anna
2019-02-05 16:41       ` Tony Lindgren
2019-02-14  3:01         ` Suman Anna
2019-02-14  3:01           ` Suman Anna
2019-02-08 13:51   ` Linus Walleij
2019-02-08 13:51     ` Linus Walleij
2019-02-14  3:12     ` Suman Anna
2019-02-14  3:12       ` Suman Anna
2019-02-14  3:12       ` Suman Anna
2019-02-14  8:37       ` Linus Walleij
2019-02-14  8:37         ` Linus Walleij
2019-02-14 10:55         ` Roger Quadros
2019-02-14 10:55           ` Roger Quadros
2019-02-14 10:55           ` Roger Quadros
2019-02-14 12:52           ` Marc Zyngier
2019-02-14 15:44             ` Roger Quadros
2019-02-14 15:44               ` Roger Quadros
2019-02-14 15:44               ` Roger Quadros
2019-02-14 15:48               ` Roger Quadros
2019-02-14 15:48                 ` Roger Quadros
2019-02-14 15:48                 ` Roger Quadros
2019-02-15  0:59                 ` Suman Anna
2019-02-15  0:59                   ` Suman Anna
2019-02-15  0:59                   ` Suman Anna
2019-02-20  9:51                   ` Linus Walleij
2019-02-14 15:51               ` Marc Zyngier
2019-02-14 15:51                 ` Marc Zyngier
2019-02-14 16:50                 ` Roger Quadros
2019-02-14 16:50                   ` Roger Quadros
2019-02-14 16:50                   ` Roger Quadros
2019-02-14  9:47       ` Marc Zyngier
2019-02-14  2:52   ` Suman Anna
2019-02-14  2:52     ` Suman Anna
2019-02-14 11:08     ` Roger Quadros
2019-02-14 11:08       ` Roger Quadros
2019-02-14 15:56       ` Tony Lindgren
2019-02-15  1:22         ` Suman Anna
2019-02-15  1:22           ` Suman Anna
2019-02-15  1:08       ` Suman Anna
2019-02-15  1:08         ` Suman Anna
2019-02-15 13:43       ` Matthijs van Duin
2019-02-04 14:22 ` [PATCH v2 02/14] soc: ti: pruss: Add a platform driver for PRUSS in TI SoCs Roger Quadros
2019-02-04 14:22   ` Roger Quadros
2019-02-04 14:52   ` Andrew F. Davis
2019-02-04 14:52     ` Andrew F. Davis
2019-02-04 15:32     ` Roger Quadros
2019-02-04 15:32       ` Roger Quadros
2019-02-04 16:35     ` Tony Lindgren
2019-02-04 14:22 ` [PATCH v2 03/14] dt-binding: irqchip: Add pruss-intc-irq driver for PRUSS interrupts Roger Quadros
2019-02-04 14:22   ` Roger Quadros
2019-02-04 16:36   ` Tony Lindgren
2019-02-14  2:40   ` Suman Anna
2019-02-14  2:40     ` Suman Anna
2019-02-18 19:32   ` Rob Herring
2019-02-04 14:22 ` [PATCH v2 04/14] irqchip: pruss: Add a PRUSS irqchip " Roger Quadros
2019-02-04 14:22   ` Roger Quadros
2019-02-04 15:11   ` Andrew F. Davis
2019-02-04 15:11     ` Andrew F. Davis
2019-02-04 15:33     ` Roger Quadros
2019-02-04 15:33       ` Roger Quadros
2019-02-05  8:51       ` Roger Quadros
2019-02-05  8:51         ` Roger Quadros
2019-02-14  2:15         ` Suman Anna
2019-02-14  2:15           ` Suman Anna
2019-02-04 18:15   ` Tony Lindgren
2019-02-05 10:35     ` Roger Quadros
2019-02-05 10:35       ` Roger Quadros
2019-02-05 11:04       ` Marc Zyngier
2019-02-05 11:04         ` Marc Zyngier
2019-02-14  2:16         ` Suman Anna
2019-02-14  2:16           ` Suman Anna
2019-02-14  2:16           ` Suman Anna
2019-02-04 14:22 ` [PATCH v2 05/14] remoteproc: add map parameter to da_to_va Roger Quadros
2019-02-04 14:22   ` Roger Quadros
2019-02-04 14:22 ` [PATCH v2 06/14] remoteproc: add page lookup for TI PRU to ELF loader Roger Quadros
2019-02-04 14:22   ` Roger Quadros
2019-02-04 15:19   ` Andrew F. Davis
2019-02-04 15:19     ` Andrew F. Davis
2019-02-14  2:22     ` Suman Anna
2019-02-14  2:22       ` Suman Anna
2019-02-04 14:22 ` Roger Quadros [this message]
2019-02-04 14:22   ` [PATCH v2 07/14] remoteproc: Add a rproc_set_firmware() API Roger Quadros
2019-02-04 14:22 ` [PATCH v2 08/14] remoteproc: Add support to handle device specific resource types Roger Quadros
2019-02-04 14:22   ` Roger Quadros
2019-02-04 14:22 ` [PATCH v2 09/14] dt-binding: remoteproc: Add binding doc for PRU Cores in the PRU-ICSS Roger Quadros
2019-02-04 14:22   ` Roger Quadros
2019-02-18 19:36   ` Rob Herring
2019-02-18 19:36     ` Rob Herring
2019-02-18 19:36     ` Rob Herring
2019-02-04 14:22 ` [PATCH v2 10/14] remoteproc/pru: Add PRU remoteproc driver Roger Quadros
2019-02-04 14:22   ` Roger Quadros
2019-02-14  2:35   ` Suman Anna
2019-02-14  2:35     ` Suman Anna
2019-02-14  3:44     ` Suman Anna
2019-02-14  3:44       ` Suman Anna
2019-02-04 14:22 ` [PATCH v2 11/14] remoteproc/pru: Add pru_rproc_set_ctable() and pru_rproc_set_gpimode() Roger Quadros
2019-02-04 14:22   ` Roger Quadros
2019-02-04 14:22 ` [PATCH v2 12/14] remoteproc/pru: Add support for virtio rpmsg stack Roger Quadros
2019-02-04 14:22   ` Roger Quadros
2019-02-04 14:22 ` [PATCH v2 13/14] rpmsg: virtio_rpmsg_bus: move back rpmsg_hdr into a public header Roger Quadros
2019-02-04 14:22   ` Roger Quadros
2019-02-04 14:22 ` [PATCH v2 14/14] rpmsg: pru: add a PRU RPMsg driver Roger Quadros
2019-02-04 14:22   ` Roger Quadros
2019-02-04 15:26   ` Andrew F. Davis
2019-02-04 15:26     ` Andrew F. Davis

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=1549290167-876-8-git-send-email-rogerq@ti.com \
    --to=rogerq@ti.com \
    --cc=bjorn.andersson@linaro.org \
    --cc=david@lechnology.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jreeder@ti.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux-remoteproc@vger.kernel.org \
    --cc=m-karicheri2@ti.com \
    --cc=nsaulnier@ti.com \
    --cc=nsekhar@ti.com \
    --cc=ohad@wizery.com \
    --cc=s-anna@ti.com \
    --cc=t-kristo@ti.com \
    --cc=tony@atomide.com \
    --cc=woods.technical@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.