[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210513110040.2268-15-maciej.kwapulinski@linux.intel.com>
Date: Thu, 13 May 2021 13:00:40 +0200
From: Maciej Kwapulinski <maciej.kwapulinski@...ux.intel.com>
To: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Arnd Bergmann <arnd@...db.de>,
Jonathan Corbet <corbet@....net>,
Derek Kiernan <derek.kiernan@...inx.com>,
Dragan Cvetic <dragan.cvetic@...inx.com>,
Andy Shevchenko <andy.shevchenko@...il.com>
Cc: linux-kernel@...r.kernel.org, linux-doc@...r.kernel.org,
Maciej Kwapulinski <maciej.kwapulinski@...ux.intel.com>,
Savo Novakovic <savox.novakovic@...el.com>,
Jianxun Zhang <jianxun.zhang@...ux.intel.com>,
Tomasz Jankowski <tomasz1.jankowski@...el.com>
Subject: [PATCH v3 14/14] intel_gna: add power management
Implement power management in intel_gna driver
Signed-off-by: Maciej Kwapulinski <maciej.kwapulinski@...ux.intel.com>
Tested-by: Savo Novakovic <savox.novakovic@...el.com>
Co-developed-by: Jianxun Zhang <jianxun.zhang@...ux.intel.com>
Signed-off-by: Jianxun Zhang <jianxun.zhang@...ux.intel.com>
Co-developed-by: Tomasz Jankowski <tomasz1.jankowski@...el.com>
Signed-off-by: Tomasz Jankowski <tomasz1.jankowski@...el.com>
---
drivers/misc/intel/gna/device.c | 55 +++++++++++++++++++++++++++++++-
drivers/misc/intel/gna/device.h | 3 ++
drivers/misc/intel/gna/hw.h | 1 +
drivers/misc/intel/gna/pci.c | 3 ++
drivers/misc/intel/gna/request.c | 15 +++++++++
5 files changed, 76 insertions(+), 1 deletion(-)
diff --git a/drivers/misc/intel/gna/device.c b/drivers/misc/intel/gna/device.c
index c882055de8cf..d7b0697bdd7c 100644
--- a/drivers/misc/intel/gna/device.c
+++ b/drivers/misc/intel/gna/device.c
@@ -22,6 +22,30 @@ module_param(recovery_timeout, int, 0644);
MODULE_PARM_DESC(recovery_timeout, "Recovery timeout in seconds");
#endif
+static int __maybe_unused gna_runtime_suspend(struct device *dev)
+{
+ struct gna_private *gna_priv = dev_get_drvdata(dev);
+ u32 val = gna_reg_read(gna_priv, GNA_MMIO_D0I3C);
+
+ dev_dbg(dev, "%s D0I3, reg %.8x\n", __func__, val);
+
+ return 0;
+}
+
+static int __maybe_unused gna_runtime_resume(struct device *dev)
+{
+ struct gna_private *gna_priv = dev_get_drvdata(dev);
+ u32 val = gna_reg_read(gna_priv, GNA_MMIO_D0I3C);
+
+ dev_dbg(dev, "%s D0I3, reg %.8x\n", __func__, val);
+
+ return 0;
+}
+
+const struct dev_pm_ops __maybe_unused gna_pm = {
+ SET_RUNTIME_PM_OPS(gna_runtime_suspend, gna_runtime_resume, NULL)
+};
+
static int gna_open(struct inode *inode, struct file *f)
{
struct gna_file_private *file_priv;
@@ -123,6 +147,22 @@ static int gna_devm_register_misc_dev(struct device *parent, struct miscdevice *
return ret;
}
+static void gna_pm_init(struct device *dev)
+{
+ pm_runtime_set_autosuspend_delay(dev, 200);
+ pm_runtime_use_autosuspend(dev);
+ pm_runtime_mark_last_busy(dev);
+ pm_runtime_allow(dev);
+ pm_runtime_put_noidle(dev);
+}
+
+static void gna_pm_remove(void *data)
+{
+ struct device *dev = data;
+
+ pm_runtime_get_noresume(dev);
+}
+
static irqreturn_t gna_interrupt(int irq, void *priv)
{
struct gna_private *gna_priv;
@@ -245,7 +285,20 @@ int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomem
gna_priv->misc.fops = &gna_file_ops;
gna_priv->misc.mode = 0666;
- return gna_devm_register_misc_dev(parent, &gna_priv->misc);
+ ret = gna_devm_register_misc_dev(parent, &gna_priv->misc);
+ if (ret)
+ return ret;
+
+ dev_set_drvdata(parent, gna_priv);
+
+ gna_pm_init(parent);
+ ret = devm_add_action(parent, gna_pm_remove, parent);
+ if (ret) {
+ dev_err(parent, "could not add devm action for pm\n");
+ return ret;
+ }
+
+ return 0;
}
static u32 gna_device_type_by_hwid(u32 hwid)
diff --git a/drivers/misc/intel/gna/device.h b/drivers/misc/intel/gna/device.h
index ea3caf679c77..a0e28d05ebfa 100644
--- a/drivers/misc/intel/gna/device.h
+++ b/drivers/misc/intel/gna/device.h
@@ -10,6 +10,7 @@
#include <linux/list.h>
#include <linux/miscdevice.h>
#include <linux/mutex.h>
+#include <linux/pm_runtime.h>
#include <linux/types.h>
#include "hw.h"
@@ -75,6 +76,8 @@ struct gna_private {
int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomem *iobase, int irq);
int gna_getparam(struct gna_private *gna_priv, union gna_parameter *param);
+extern const struct dev_pm_ops __maybe_unused gna_pm;
+
static inline u32 gna_reg_read(struct gna_private *gna_priv, u32 reg)
{
return readl(gna_priv->iobase + reg);
diff --git a/drivers/misc/intel/gna/hw.h b/drivers/misc/intel/gna/hw.h
index 2a6890fb748e..c0a8120b84d9 100644
--- a/drivers/misc/intel/gna/hw.h
+++ b/drivers/misc/intel/gna/hw.h
@@ -49,6 +49,7 @@ struct gna_private;
#define GNA_MMIO_CTRL 0x84
#define GNA_MMIO_PTC 0x8C
#define GNA_MMIO_PSC 0x90
+#define GNA_MMIO_D0I3C 0xA8
#define GNA_MMIO_DESBASE 0xB0
#define GNA_MMIO_IBUFFS 0xB4
diff --git a/drivers/misc/intel/gna/pci.c b/drivers/misc/intel/gna/pci.c
index a31f0142a4f2..4aad4cf702b7 100644
--- a/drivers/misc/intel/gna/pci.c
+++ b/drivers/misc/intel/gna/pci.c
@@ -139,6 +139,9 @@ static struct pci_driver gna_pci_driver = {
.name = GNA_DV_NAME,
.id_table = gna_pci_ids,
.probe = gna_pci_probe,
+ .driver = {
+ .pm = &gna_pm,
+ },
};
module_pci_driver(gna_pci_driver);
diff --git a/drivers/misc/intel/gna/request.c b/drivers/misc/intel/gna/request.c
index eabbab8924be..e923f0d2651d 100644
--- a/drivers/misc/intel/gna/request.c
+++ b/drivers/misc/intel/gna/request.c
@@ -6,6 +6,7 @@
#include <linux/idr.h>
#include <linux/mm.h>
#include <linux/mutex.h>
+#include <linux/pm_runtime.h>
#include <linux/uaccess.h>
#include <linux/slab.h>
@@ -65,6 +66,14 @@ static void gna_request_process(struct work_struct *work)
score_request->drv_perf.pre_processing = ktime_get_ns();
+ ret = pm_runtime_get_sync(gna_parent(gna_priv));
+ if (ret < 0 && ret != -EACCES) {
+ dev_warn(gna_dev(gna_priv), "pm_runtime_get_sync() failed: %d\n", ret);
+ score_request->status = -ENODEV;
+ pm_runtime_put_noidle(gna_parent(gna_priv));
+ goto end;
+ }
+
/* Set busy flag before kicking off HW. The isr will clear it and wake up us. There is
* no difference if isr is missed in a timeout situation of the last request. We just
* always set it busy and let the wait_event_timeout check the reset.
@@ -75,6 +84,8 @@ static void gna_request_process(struct work_struct *work)
ret = gna_score(score_request);
if (ret) {
+ if (pm_runtime_put(gna_parent(gna_priv)) < 0)
+ dev_warn(gna_dev(gna_priv), "pm_runtime_put() failed: %d\n", ret);
score_request->status = ret;
goto end;
}
@@ -94,6 +105,10 @@ static void gna_request_process(struct work_struct *work)
gna_request_update_status(score_request);
gna_abort_hw(gna_priv);
+ ret = pm_runtime_put(gna_parent(gna_priv));
+ if (ret < 0)
+ dev_warn(gna_dev(gna_priv), "pm_runtime_put() failed: %d\n", ret);
+
buffer = score_request->buffer_list;
for (i = 0; i < score_request->buffer_count; i++, buffer++) {
mutex_lock(&gna_priv->memidr_lock);
--
2.28.0
Powered by blists - more mailing lists