linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] gpu: host1x: Add locking in channel allocation
@ 2023-09-01 11:15 Mikko Perttunen
  2023-09-01 11:15 ` [PATCH 2/3] gpu: host1x: Stop CDMA before suspending Mikko Perttunen
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Mikko Perttunen @ 2023-09-01 11:15 UTC (permalink / raw)
  To: Thierry Reding; +Cc: Mikko Perttunen, dri-devel, linux-tegra, linux-kernel

From: Mikko Perttunen <mperttunen@nvidia.com>

Add locking around channel allocation to avoid race conditions.

Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
---
 drivers/gpu/host1x/channel.c | 7 +++++++
 drivers/gpu/host1x/channel.h | 3 +++
 2 files changed, 10 insertions(+)

diff --git a/drivers/gpu/host1x/channel.c b/drivers/gpu/host1x/channel.c
index 2d0051d6314c..79501c957532 100644
--- a/drivers/gpu/host1x/channel.c
+++ b/drivers/gpu/host1x/channel.c
@@ -27,6 +27,8 @@ int host1x_channel_list_init(struct host1x_channel_list *chlist,
 		return -ENOMEM;
 	}
 
+	mutex_init(&chlist->lock);
+
 	return 0;
 }
 
@@ -104,8 +106,11 @@ static struct host1x_channel *acquire_unused_channel(struct host1x *host)
 	unsigned int max_channels = host->info->nb_channels;
 	unsigned int index;
 
+	mutex_lock(&chlist->lock);
+
 	index = find_first_zero_bit(chlist->allocated_channels, max_channels);
 	if (index >= max_channels) {
+		mutex_unlock(&chlist->lock);
 		dev_err(host->dev, "failed to find free channel\n");
 		return NULL;
 	}
@@ -114,6 +119,8 @@ static struct host1x_channel *acquire_unused_channel(struct host1x *host)
 
 	set_bit(index, chlist->allocated_channels);
 
+	mutex_unlock(&chlist->lock);
+
 	return &chlist->channels[index];
 }
 
diff --git a/drivers/gpu/host1x/channel.h b/drivers/gpu/host1x/channel.h
index 39044ff6c3aa..b23a8071fbd0 100644
--- a/drivers/gpu/host1x/channel.h
+++ b/drivers/gpu/host1x/channel.h
@@ -10,6 +10,7 @@
 
 #include <linux/io.h>
 #include <linux/kref.h>
+#include <linux/mutex.h>
 
 #include "cdma.h"
 
@@ -18,6 +19,8 @@ struct host1x_channel;
 
 struct host1x_channel_list {
 	struct host1x_channel *channels;
+
+	struct mutex lock;
 	unsigned long *allocated_channels;
 };
 
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] gpu: host1x: Stop CDMA before suspending
  2023-09-01 11:15 [PATCH 1/3] gpu: host1x: Add locking in channel allocation Mikko Perttunen
@ 2023-09-01 11:15 ` Mikko Perttunen
  2023-09-01 11:15 ` [PATCH 3/3] gpu: host1x: Enable system suspend callbacks Mikko Perttunen
  2023-10-11 20:44 ` [PATCH 1/3] gpu: host1x: Add locking in channel allocation Thierry Reding
  2 siblings, 0 replies; 4+ messages in thread
From: Mikko Perttunen @ 2023-09-01 11:15 UTC (permalink / raw)
  To: Thierry Reding; +Cc: Mikko Perttunen, dri-devel, linux-tegra, linux-kernel

From: Mikko Perttunen <mperttunen@nvidia.com>

Before going into suspend, wait all CDMA to go idle and stop it.
This will ensure no channel is still active while we enter
suspend, and ensures the driver doesn't think that CDMA is still
active when coming back from suspend (as HW state has been reset).

Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
---
 drivers/gpu/host1x/channel.c | 19 +++++++++++++++++++
 drivers/gpu/host1x/channel.h |  1 +
 drivers/gpu/host1x/dev.c     |  1 +
 3 files changed, 21 insertions(+)

diff --git a/drivers/gpu/host1x/channel.c b/drivers/gpu/host1x/channel.c
index 79501c957532..08077afe4cde 100644
--- a/drivers/gpu/host1x/channel.c
+++ b/drivers/gpu/host1x/channel.c
@@ -81,6 +81,25 @@ void host1x_channel_stop(struct host1x_channel *channel)
 }
 EXPORT_SYMBOL(host1x_channel_stop);
 
+/**
+ * host1x_channel_stop_all() - disable CDMA on allocated channels
+ * @host: host1x instance
+ *
+ * Stop CDMA on allocated channels
+ */
+void host1x_channel_stop_all(struct host1x *host)
+{
+	struct host1x_channel_list *chlist = &host->channel_list;
+	int bit;
+
+	mutex_lock(&chlist->lock);
+
+	for_each_set_bit(bit, chlist->allocated_channels, host->info->nb_channels)
+		host1x_channel_stop(&chlist->channels[bit]);
+
+	mutex_unlock(&chlist->lock);
+}
+
 static void release_channel(struct kref *kref)
 {
 	struct host1x_channel *channel =
diff --git a/drivers/gpu/host1x/channel.h b/drivers/gpu/host1x/channel.h
index b23a8071fbd0..d7aede204d83 100644
--- a/drivers/gpu/host1x/channel.h
+++ b/drivers/gpu/host1x/channel.h
@@ -40,5 +40,6 @@ int host1x_channel_list_init(struct host1x_channel_list *chlist,
 void host1x_channel_list_free(struct host1x_channel_list *chlist);
 struct host1x_channel *host1x_channel_get_index(struct host1x *host,
 						unsigned int index);
+void host1x_channel_stop_all(struct host1x *host);
 
 #endif
diff --git a/drivers/gpu/host1x/dev.c b/drivers/gpu/host1x/dev.c
index 7c6699aed7d2..6501bee9e8c1 100644
--- a/drivers/gpu/host1x/dev.c
+++ b/drivers/gpu/host1x/dev.c
@@ -655,6 +655,7 @@ static int __maybe_unused host1x_runtime_suspend(struct device *dev)
 	struct host1x *host = dev_get_drvdata(dev);
 	int err;
 
+	host1x_channel_stop_all(host);
 	host1x_intr_stop(host);
 	host1x_syncpt_save(host);
 
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] gpu: host1x: Enable system suspend callbacks
  2023-09-01 11:15 [PATCH 1/3] gpu: host1x: Add locking in channel allocation Mikko Perttunen
  2023-09-01 11:15 ` [PATCH 2/3] gpu: host1x: Stop CDMA before suspending Mikko Perttunen
@ 2023-09-01 11:15 ` Mikko Perttunen
  2023-10-11 20:44 ` [PATCH 1/3] gpu: host1x: Add locking in channel allocation Thierry Reding
  2 siblings, 0 replies; 4+ messages in thread
From: Mikko Perttunen @ 2023-09-01 11:15 UTC (permalink / raw)
  To: Thierry Reding; +Cc: Mikko Perttunen, dri-devel, linux-tegra, linux-kernel

From: Mikko Perttunen <mperttunen@nvidia.com>

With the previous CDMA stop fix, executing runtime PM ops around
system suspend now makes channel submissions work after system
suspend, so do that.

Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
---
 drivers/gpu/host1x/dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/host1x/dev.c b/drivers/gpu/host1x/dev.c
index 6501bee9e8c1..b8ac44e7d11a 100644
--- a/drivers/gpu/host1x/dev.c
+++ b/drivers/gpu/host1x/dev.c
@@ -720,7 +720,7 @@ static int __maybe_unused host1x_runtime_resume(struct device *dev)
 static const struct dev_pm_ops host1x_pm_ops = {
 	SET_RUNTIME_PM_OPS(host1x_runtime_suspend, host1x_runtime_resume,
 			   NULL)
-	/* TODO: add system suspend-resume once driver will be ready for that */
+	SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume)
 };
 
 static struct platform_driver tegra_host1x_driver = {
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/3] gpu: host1x: Add locking in channel allocation
  2023-09-01 11:15 [PATCH 1/3] gpu: host1x: Add locking in channel allocation Mikko Perttunen
  2023-09-01 11:15 ` [PATCH 2/3] gpu: host1x: Stop CDMA before suspending Mikko Perttunen
  2023-09-01 11:15 ` [PATCH 3/3] gpu: host1x: Enable system suspend callbacks Mikko Perttunen
@ 2023-10-11 20:44 ` Thierry Reding
  2 siblings, 0 replies; 4+ messages in thread
From: Thierry Reding @ 2023-10-11 20:44 UTC (permalink / raw)
  To: Mikko Perttunen; +Cc: Mikko Perttunen, dri-devel, linux-tegra, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 428 bytes --]

On Fri, Sep 01, 2023 at 02:15:07PM +0300, Mikko Perttunen wrote:
> From: Mikko Perttunen <mperttunen@nvidia.com>
> 
> Add locking around channel allocation to avoid race conditions.
> 
> Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
> ---
>  drivers/gpu/host1x/channel.c | 7 +++++++
>  drivers/gpu/host1x/channel.h | 3 +++
>  2 files changed, 10 insertions(+)

All three patches applied, thanks.

Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-10-11 20:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-01 11:15 [PATCH 1/3] gpu: host1x: Add locking in channel allocation Mikko Perttunen
2023-09-01 11:15 ` [PATCH 2/3] gpu: host1x: Stop CDMA before suspending Mikko Perttunen
2023-09-01 11:15 ` [PATCH 3/3] gpu: host1x: Enable system suspend callbacks Mikko Perttunen
2023-10-11 20:44 ` [PATCH 1/3] gpu: host1x: Add locking in channel allocation Thierry Reding

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).