Revert "gpu: nvgpu: gk20a: wrap debug session as optional"

This reverts commit 717090a488769d03ebd43c9b7a7b2567fd25d91a.

Signed-off-by: Mark Salyzyn <salyzyn@google.com>
Bug: 33379507
Bug: 33260045
Bug: 32370135
Bug: 33461166
Change-Id: I868116def8a7aa8631345c7d39d75a4930a9e497
(cherry picked from commit f6a0a63f83a81355bf75185775f7691efedb5ca4)
diff --git a/drivers/gpu/nvgpu/Kconfig b/drivers/gpu/nvgpu/Kconfig
index e0a0250..238d87e 100644
--- a/drivers/gpu/nvgpu/Kconfig
+++ b/drivers/gpu/nvgpu/Kconfig
@@ -46,18 +46,10 @@
 
 endchoice
 
-config TEGRA_GK20A_DEBUG_SESSION
-	bool "Enable debug session"
-	depends on GK20A
-	default n
-	help
-	  Enables using debug session on GK20A.
-
 config GK20A_CYCLE_STATS
 	bool "Support GK20A GPU CYCLE STATS"
 	depends on GK20A
-	depends on TEGRA_GK20A_DEBUG_SESSION
-	default n
+	default y
 	help
 	  Say Y here to enable the cycle stats debugging features.
 
diff --git a/drivers/gpu/nvgpu/gk20a/Makefile b/drivers/gpu/nvgpu/gk20a/Makefile
index 20f4c72..cba3168 100644
--- a/drivers/gpu/nvgpu/gk20a/Makefile
+++ b/drivers/gpu/nvgpu/gk20a/Makefile
@@ -12,6 +12,8 @@
 	channel_gk20a.o \
 	channel_sync_gk20a.o \
 	debug_gk20a.o \
+	dbg_gpu_gk20a.o \
+	regops_gk20a.o \
 	gr_gk20a.o \
 	kind_gk20a.o \
 	mm_gk20a.o \
@@ -31,8 +33,5 @@
 	gk20a_allocator.o \
 	platform_gk20a_generic.o
 nvgpu-$(CONFIG_TEGRA_GK20A) += platform_gk20a_tegra.o
-nvgpu-$(CONFIG_TEGRA_GK20A_DEBUG_SESSION) += \
-	dbg_gpu_gk20a.o \
-	regops_gk20a.o \
 
 obj-$(CONFIG_GK20A) := nvgpu.o
diff --git a/drivers/gpu/nvgpu/gk20a/channel_gk20a.c b/drivers/gpu/nvgpu/gk20a/channel_gk20a.c
index 27e661c..d3fba20 100644
--- a/drivers/gpu/nvgpu/gk20a/channel_gk20a.c
+++ b/drivers/gpu/nvgpu/gk20a/channel_gk20a.c
@@ -30,11 +30,9 @@
 #include <linux/dma-buf.h>
 
 #include "debug_gk20a.h"
-#include "gk20a.h"
 
-#if defined(CONFIG_TEGRA_GK20A_DEBUG_SESSION)
+#include "gk20a.h"
 #include "dbg_gpu_gk20a.h"
-#endif
 
 #include "hw_ram_gk20a.h"
 #include "hw_fifo_gk20a.h"
@@ -623,9 +621,7 @@
 	struct gr_gk20a *gr = &g->gr;
 	struct vm_gk20a *ch_vm = ch->vm;
 	unsigned long timeout = gk20a_get_gr_idle_timeout(g);
-#if defined(CONFIG_TEGRA_GK20A_DEBUG_SESSION)
 	struct dbg_session_gk20a *dbg_s;
-#endif
 
 	gk20a_dbg_fn("");
 
@@ -698,12 +694,10 @@
 	/* unlink all debug sessions */
 	mutex_lock(&ch->dbg_s_lock);
 
-#if defined(CONFIG_TEGRA_GK20A_DEBUG_SESSION)
 	list_for_each_entry(dbg_s, &ch->dbg_s_list, dbg_s_list_node) {
 		dbg_s->ch = NULL;
 		list_del_init(&dbg_s->dbg_s_list_node);
 	}
-#endif
 
 	mutex_unlock(&ch->dbg_s_lock);
 
diff --git a/drivers/gpu/nvgpu/gk20a/channel_gk20a.h b/drivers/gpu/nvgpu/gk20a/channel_gk20a.h
index 20a5ccf..c426d31 100644
--- a/drivers/gpu/nvgpu/gk20a/channel_gk20a.h
+++ b/drivers/gpu/nvgpu/gk20a/channel_gk20a.h
@@ -28,6 +28,7 @@
 #include <linux/nvhost_ioctl.h>
 struct gk20a;
 struct gr_gk20a;
+struct dbg_session_gk20a;
 
 #include "channel_sync_gk20a.h"
 
diff --git a/drivers/gpu/nvgpu/gk20a/dbg_gpu_gk20a.h b/drivers/gpu/nvgpu/gk20a/dbg_gpu_gk20a.h
index 9ba477d..4982760 100644
--- a/drivers/gpu/nvgpu/gk20a/dbg_gpu_gk20a.h
+++ b/drivers/gpu/nvgpu/gk20a/dbg_gpu_gk20a.h
@@ -19,8 +19,6 @@
 #define __DBG_GPU_GK20A_H_
 #include <linux/poll.h>
 
-struct dbg_session_gk20a;
-
 /* module debug driver interface */
 int gk20a_dbg_gpu_dev_release(struct inode *inode, struct file *filp);
 int gk20a_dbg_gpu_dev_open(struct inode *inode, struct file *filp);
diff --git a/drivers/gpu/nvgpu/gk20a/gk20a.c b/drivers/gpu/nvgpu/gk20a/gk20a.c
index 149b1fb..6dc10d1 100644
--- a/drivers/gpu/nvgpu/gk20a/gk20a.c
+++ b/drivers/gpu/nvgpu/gk20a/gk20a.c
@@ -58,11 +58,8 @@
 #include "hw_top_gk20a.h"
 #include "hw_ltc_gk20a.h"
 #include "gk20a_scale.h"
-#include "hal.h"
-
-#if defined(CONFIG_TEGRA_GK20A_DEBUG_SESSION)
 #include "dbg_gpu_gk20a.h"
-#endif
+#include "hal.h"
 
 #ifdef CONFIG_ARM64
 #define __cpuc_flush_dcache_area __flush_dcache_area
@@ -109,7 +106,6 @@
 #endif
 };
 
-#if defined(CONFIG_TEGRA_GK20A_DEBUG_SESSION)
 static const struct file_operations gk20a_dbg_ops = {
 	.owner = THIS_MODULE,
 	.release        = gk20a_dbg_gpu_dev_release,
@@ -120,7 +116,6 @@
 	.compat_ioctl = gk20a_dbg_gpu_dev_ioctl,
 #endif
 };
-#endif
 
 static const struct file_operations gk20a_as_ops = {
 	.owner = THIS_MODULE,
@@ -138,7 +133,6 @@
  * code does get too tangled trying to handle each in the same path we can
  * separate them cleanly.
  */
-#if defined(CONFIG_TEGRA_GK20A_DEBUG_SESSION)
 static const struct file_operations gk20a_prof_ops = {
 	.owner = THIS_MODULE,
 	.release        = gk20a_dbg_gpu_dev_release,
@@ -151,7 +145,6 @@
 	.compat_ioctl = gk20a_dbg_gpu_dev_ioctl,
 #endif
 };
-#endif
 
 static inline void sim_writel(struct gk20a *g, u32 r, u32 v)
 {
@@ -1110,7 +1103,6 @@
 	if (err)
 		goto fail;
 
-#if defined(CONFIG_TEGRA_GK20A_DEBUG_SESSION)
 	err = gk20a_create_device(dev, devno++, "-dbg",
 				  &g->dbg.cdev, &g->dbg.node,
 				  &gk20a_dbg_ops);
@@ -1122,7 +1114,6 @@
 				  &gk20a_prof_ops);
 	if (err)
 		goto fail;
-#endif
 
 	return 0;
 fail:
diff --git a/drivers/gpu/nvgpu/gk20a/gr_gk20a.c b/drivers/gpu/nvgpu/gk20a/gr_gk20a.c
index 2bb0ee7..309ea9c 100644
--- a/drivers/gpu/nvgpu/gk20a/gr_gk20a.c
+++ b/drivers/gpu/nvgpu/gk20a/gr_gk20a.c
@@ -49,12 +49,8 @@
 #include "hw_therm_gk20a.h"
 #include "hw_pbdma_gk20a.h"
 #include "gr_pri_gk20a.h"
-
 #include "regops_gk20a.h"
-
-#if defined(CONFIG_TEGRA_GK20A_DEBUG_SESSION)
 #include "dbg_gpu_gk20a.h"
-#endif
 
 #define BLK_SIZE (256)
 
@@ -5256,6 +5252,12 @@
 			gr_gpc0_tpc0_sm_hww_warp_esr_error_none_f());
 }
 
+static struct channel_gk20a *
+channel_from_hw_chid(struct gk20a *g, u32 hw_chid)
+{
+	return g->fifo.channel+hw_chid;
+}
+
 static int gk20a_gr_handle_sm_exception(struct gk20a *g,
 		struct gr_isr_data *isr_data)
 {
@@ -5271,9 +5273,7 @@
 			  gr_gpc0_tpc0_sm_hww_global_esr_single_step_complete_pending_f();
 	u32 global_esr, warp_esr;
 	bool sm_debugger_attached = gk20a_gr_sm_debugger_attached(g);
-#if defined(CONFIG_TEGRA_GK20A_DEBUG_SESSION)
 	struct channel_gk20a *fault_ch;
-#endif
 
 	gk20a_dbg(gpu_dbg_fn | gpu_dbg_gpu_dbg, "");
 
@@ -5303,12 +5303,10 @@
 		}
 	}
 
-#if defined(CONFIG_TEGRA_GK20A_DEBUG_SESSION)
 	/* finally, signal any client waiting on an event */
-	fault_ch = g->fifo.channel + isr_data->chid;
+	fault_ch = channel_from_hw_chid(g, isr_data->chid);
 	if (fault_ch)
 		gk20a_dbg_gpu_post_events(fault_ch);
-#endif
 
 	return ret;
 }
diff --git a/drivers/gpu/nvgpu/gk20a/regops_gk20a.h b/drivers/gpu/nvgpu/gk20a/regops_gk20a.h
index 7ef8d62..23b4865 100644
--- a/drivers/gpu/nvgpu/gk20a/regops_gk20a.h
+++ b/drivers/gpu/nvgpu/gk20a/regops_gk20a.h
@@ -19,17 +19,14 @@
 #ifndef __REGOPS_GK20A_H_
 #define __REGOPS_GK20A_H_
 
-#if defined(CONFIG_TEGRA_GK20A_DEBUG_SESSION)
-struct dbg_session_gk20a;
-
 int exec_regops_gk20a(struct dbg_session_gk20a *dbg_s,
 		      struct nvhost_dbg_gpu_reg_op *ops,
 		      u64 num_ops);
-#endif
 
 /* turn seriously unwieldy names -> something shorter */
 #define REGOP(x) NVHOST_DBG_GPU_REG_OP_##x
 
+
 static inline bool reg_op_is_gr_ctx(u8 type)
 {
 	return  type == REGOP(TYPE_GR_CTX) ||