From a564025f60541d6175a6981e90c3936d68c8dd98 Mon Sep 17 00:00:00 2001
From: Lyude Paul <lyude@redhat.com>
Date: Sun, 30 Sep 2018 17:47:20 -0400
Subject: [PATCH] wip

---
 .../gpu/drm/nouveau/nvkm/engine/gr/gm200.c    |  3 +-
 .../gpu/drm/nouveau/nvkm/subdev/fb/gm107.c    |  3 +-
 .../gpu/drm/nouveau/nvkm/subdev/fb/gm107.h    | 32 +++++++++++++++++++
 .../gpu/drm/nouveau/nvkm/subdev/fb/gm200.c    | 21 ++++++++++++
 .../gpu/drm/nouveau/nvkm/subdev/therm/gk104.c |  1 +
 .../gpu/drm/nouveau/nvkm/subdev/therm/gm107.c |  1 +
 .../gpu/drm/nouveau/nvkm/subdev/therm/gm107.h | 32 +++++++++++++++++++
 .../gpu/drm/nouveau/nvkm/subdev/therm/gm200.c |  9 +++++-
 .../gpu/drm/nouveau/nvkm/subdev/therm/priv.h  |  2 ++
 9 files changed, 101 insertions(+), 3 deletions(-)
 create mode 100644 drivers/gpu/drm/nouveau/nvkm/subdev/fb/gm107.h
 create mode 100644 drivers/gpu/drm/nouveau/nvkm/subdev/therm/gm107.h

diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/gr/gm200.c b/drivers/gpu/drm/nouveau/nvkm/engine/gr/gm200.c
index f4831f51a5ca3..db987978c1856 100644
--- a/drivers/gpu/drm/nouveau/nvkm/engine/gr/gm200.c
+++ b/drivers/gpu/drm/nouveau/nvkm/engine/gr/gm200.c
@@ -365,7 +365,8 @@ gm200_gr = {
 		{ -1, -1, MAXWELL_B, &gf100_fermi },
 		{ -1, -1, MAXWELL_COMPUTE_B },
 		{}
-	}
+	},
+	.clkgate_pack = gm200_clkgate_pack,
 };
 
 int
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/fb/gm107.c b/drivers/gpu/drm/nouveau/nvkm/subdev/fb/gm107.c
index 361c6a1fef869..b6e3ef26c36f6 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/fb/gm107.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/fb/gm107.c
@@ -25,6 +25,7 @@
 #include "gf100.h"
 #include "gk104.h"
 #include "gk110.h"
+#include "gm107.h"
 #include "ram.h"
 
 /*
@@ -76,7 +77,7 @@ gm107_fb_clkgate_blcg_init_unk_1[] = {
 	{}
 };
 
-static const struct nvkm_therm_clkgate_pack
+const struct nvkm_therm_clkgate_pack
 gm107_fb_clkgate_pack[] = {
 	{ gm107_fb_clkgate_slcg_init_unk_0 },
 	{ gm107_fb_clkgate_slcg_init_vm_0 },
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/fb/gm107.h b/drivers/gpu/drm/nouveau/nvkm/subdev/fb/gm107.h
new file mode 100644
index 0000000000000..20b0564d3410a
--- /dev/null
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/fb/gm107.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2018 Red Hat Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: Lyude Paul
+ */
+
+#ifndef GM107_H
+#define GM107_H
+
+#include <subdev/therm.h>
+
+extern const struct nvkm_therm_clkgate_pack gm107_fb_clkgate_pack[];
+
+#endif /* !GM107_H */
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/fb/gm200.c b/drivers/gpu/drm/nouveau/nvkm/subdev/fb/gm200.c
index d3b8c3367152b..4a1dc426cf3c2 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/fb/gm200.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/fb/gm200.c
@@ -22,10 +22,30 @@
  * Authors: Ben Skeggs
  */
 #include "gf100.h"
+#include "gm107.h"
 #include "ram.h"
 
 #include <core/memory.h>
 
+/* XXX FIXME: Clockgate pack for fb appears to be identical between maxwell 1
+ * and 2, but there's an idle filter in the middle. Make sure that not having
+ * this included is OK */
+/*static const struct nvkm_therm_clkgate_pack*/
+/*gm200_fb_clkgate_pack[] = {*/
+	/*{ gm107_fb_clkgate_slcg_init_unk_0 },*/
+	/*{ gm107_fb_clkgate_slcg_init_vm_0 },*/
+	/*{ gm107_fb_clkgate_slcg_init_bcast_0 },*/
+	/*{ gm107_fb_clkgate_slcg_init_pxbar_0 },*/
+	/* FIXME: /IN THEORY/ this should not matter if we have a proper
+	 * understanding of the clockgating enable sequence, but this is the
+	 * point where the blob appears to program an idle filter. We need to
+	 * find a GPU with a different idle filter programmed in the vbios and
+	 * see if programming this late causes any issues. Karol kerbst maybe?
+	 */
+	/*{ gk110_fb_clkgate_blcg_init_unk_0 },*/
+	/*{ gk104_fb_clkgate_blcg_init_vm_0 },*/
+/*};*/
+
 int
 gm200_fb_init_page(struct nvkm_fb *fb)
 {
@@ -64,6 +84,7 @@ gm200_fb = {
 	.intr = gf100_fb_intr,
 	.ram_new = gm200_ram_new,
 	.default_bigpage = 0 /* per-instance. */,
+	.clkgate_pack = gm107_fb_clkgate_pack,
 };
 
 int
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gk104.c b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gk104.c
index efc8a23b55f86..5ae5f16657ce3 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gk104.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gk104.c
@@ -25,6 +25,7 @@
 
 #include "priv.h"
 #include "gk104.h"
+#include "gm107.h"
 
 void
 gk104_clkgate_enable(struct nvkm_therm *base)
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gm107.c b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gm107.c
index 2ad3b2bf57385..11e76eafcbc78 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gm107.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gm107.c
@@ -23,6 +23,7 @@
  */
 #include "priv.h"
 #include "gk104.h"
+#include "gm107.h"
 
 void
 gm107_clkgate_enable(struct nvkm_therm *base)
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gm107.h b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gm107.h
new file mode 100644
index 0000000000000..fa012733ea9a9
--- /dev/null
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gm107.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2018 Red Hat
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: Lyude Paul
+ */
+
+#ifndef GM107_H
+#define GM107_H
+
+#include "gf100.h"
+
+extern const struct gf100_idle_filter gm107_idle_filter;
+
+#endif /* !GM107_H */
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gm200.c b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gm200.c
index 73dc78093d5d5..d07d9469e34ae 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gm200.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gm200.c
@@ -22,6 +22,8 @@
  * Authors: Karol Herbst
  */
 #include "priv.h"
+#include "gk104.h"
+#include "gm107.h"
 
 static const struct nvkm_therm_func
 gm200_therm = {
@@ -29,11 +31,16 @@ gm200_therm = {
 	.fini = g84_therm_fini,
 	.temp_get = g84_temp_get,
 	.program_alarms = nvkm_therm_program_alarms_polling,
+	.clkgate_init = gf100_clkgate_init,
+	.clkgate_enable = gm107_clkgate_enable,
+	.clkgate_fini = gk104_clkgate_fini,
 };
 
 int
 gm200_therm_new(struct nvkm_device *device, int index,
 		struct nvkm_therm **ptherm)
 {
-	return nvkm_therm_new_(&gm200_therm, device, index, ptherm);
+	return gk104_therm_new_(&gm200_therm, device, index,
+				gk104_clkgate_engine_info, &gm107_idle_filter,
+				ptherm);
 }
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/priv.h b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/priv.h
index 21659daf18649..24aaa12781fc3 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/priv.h
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/priv.h
@@ -131,6 +131,8 @@ void gk104_therm_init(struct nvkm_therm *);
 void gk104_clkgate_enable(struct nvkm_therm *);
 void gk104_clkgate_fini(struct nvkm_therm *, bool);
 
+void gm107_clkgate_enable(struct nvkm_therm *);
+
 int nvkm_fanpwm_create(struct nvkm_therm *, struct dcb_gpio_func *);
 int nvkm_fantog_create(struct nvkm_therm *, struct dcb_gpio_func *);
 int nvkm_fannil_create(struct nvkm_therm *);
-- 
GitLab