Commit a99a37f6 authored by Paul Cercueil's avatar Paul Cercueil Committed by Bjorn Andersson

remoteproc: Add support for runtime PM

Call pm_runtime_get_sync() before the firmware is loaded, and
pm_runtime_put() after the remote processor has been stopped.

Even though the remoteproc device has no PM callbacks, this allows the
parent device's PM callbacks to be properly called.
Signed-off-by: default avatarPaul Cercueil <paul@crapouillou.net>
Link: https://lore.kernel.org/r/20200515104340.10473-3-paul@crapouillou.netSigned-off-by: default avatarBjorn Andersson <bjorn.andersson@linaro.org>
parent 4e399b3b
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <linux/devcoredump.h> #include <linux/devcoredump.h>
#include <linux/rculist.h> #include <linux/rculist.h>
#include <linux/remoteproc.h> #include <linux/remoteproc.h>
#include <linux/pm_runtime.h>
#include <linux/iommu.h> #include <linux/iommu.h>
#include <linux/idr.h> #include <linux/idr.h>
#include <linux/elf.h> #include <linux/elf.h>
...@@ -1382,6 +1383,12 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) ...@@ -1382,6 +1383,12 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw)
if (ret) if (ret)
return ret; return ret;
ret = pm_runtime_get_sync(dev);
if (ret < 0) {
dev_err(dev, "pm_runtime_get_sync failed: %d\n", ret);
return ret;
}
dev_info(dev, "Booting fw image %s, size %zd\n", name, fw->size); dev_info(dev, "Booting fw image %s, size %zd\n", name, fw->size);
/* /*
...@@ -1391,7 +1398,7 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) ...@@ -1391,7 +1398,7 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw)
ret = rproc_enable_iommu(rproc); ret = rproc_enable_iommu(rproc);
if (ret) { if (ret) {
dev_err(dev, "can't enable iommu: %d\n", ret); dev_err(dev, "can't enable iommu: %d\n", ret);
return ret; goto put_pm_runtime;
} }
/* Prepare rproc for firmware loading if needed */ /* Prepare rproc for firmware loading if needed */
...@@ -1445,6 +1452,8 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) ...@@ -1445,6 +1452,8 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw)
rproc_unprepare_device(rproc); rproc_unprepare_device(rproc);
disable_iommu: disable_iommu:
rproc_disable_iommu(rproc); rproc_disable_iommu(rproc);
put_pm_runtime:
pm_runtime_put(dev);
return ret; return ret;
} }
...@@ -1882,6 +1891,8 @@ void rproc_shutdown(struct rproc *rproc) ...@@ -1882,6 +1891,8 @@ void rproc_shutdown(struct rproc *rproc)
rproc_disable_iommu(rproc); rproc_disable_iommu(rproc);
pm_runtime_put(dev);
/* Free the copy of the resource table */ /* Free the copy of the resource table */
kfree(rproc->cached_table); kfree(rproc->cached_table);
rproc->cached_table = NULL; rproc->cached_table = NULL;
...@@ -2172,6 +2183,9 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, ...@@ -2172,6 +2183,9 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
rproc->state = RPROC_OFFLINE; rproc->state = RPROC_OFFLINE;
pm_runtime_no_callbacks(&rproc->dev);
pm_runtime_enable(&rproc->dev);
return rproc; return rproc;
put_device: put_device:
...@@ -2191,6 +2205,7 @@ EXPORT_SYMBOL(rproc_alloc); ...@@ -2191,6 +2205,7 @@ EXPORT_SYMBOL(rproc_alloc);
*/ */
void rproc_free(struct rproc *rproc) void rproc_free(struct rproc *rproc)
{ {
pm_runtime_disable(&rproc->dev);
put_device(&rproc->dev); put_device(&rproc->dev);
} }
EXPORT_SYMBOL(rproc_free); EXPORT_SYMBOL(rproc_free);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment