gpu: nvgpu: gk20a: wrap debug session as optional

Allows cleanly turning off debug session feature which is
not used out side engineering stage.

NvBug 1832095
NvBug 1832259
Bug: 31799885
Bug: 32370135

Change-Id: If1e76b8137131c52bc4a06d55265fe4689b1cf7b
Signed-off-by: Xia Yang <xiay@nvidia.com>
diff --git a/drivers/gpu/nvgpu/Kconfig b/drivers/gpu/nvgpu/Kconfig
index 238d87e..e0a0250 100644
--- a/drivers/gpu/nvgpu/Kconfig
+++ b/drivers/gpu/nvgpu/Kconfig
@@ -46,10 +46,18 @@
 
 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
-	default y
+	depends on TEGRA_GK20A_DEBUG_SESSION
+	default n
 	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 cba3168..20f4c72 100644
--- a/drivers/gpu/nvgpu/gk20a/Makefile
+++ b/drivers/gpu/nvgpu/gk20a/Makefile
@@ -12,8 +12,6 @@
 	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 \
@@ -33,5 +31,8 @@
 	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 334858a..73e943b 100644
--- a/drivers/gpu/nvgpu/gk20a/channel_gk20a.c
+++ b/drivers/gpu/nvgpu/gk20a/channel_gk20a.c
@@ -30,9 +30,11 @@
 #include <linux/dma-buf.h>
 
 #include "debug_gk20a.h"
-
 #include "gk20a.h"
+
+#if defined(CONFIG_TEGRA_GK20A_DEBUG_SESSION)
 #include "dbg_gpu_gk20a.h"
+#endif
 
 #include "hw_ram_gk20a.h"
 #include "hw_fifo_gk20a.h"
@@ -621,7 +623,9 @@
 	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("");
 
@@ -694,10 +698,12 @@
 	/* 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 547bb06..414e2ff 100644
--- a/drivers/gpu/nvgpu/gk20a/channel_gk20a.h
+++ b/drivers/gpu/nvgpu/gk20a/channel_gk20a.h
@@ -28,7 +28,6 @@
 #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 4982760..9ba477d 100644
--- a/drivers/gpu/nvgpu/gk20a/dbg_gpu_gk20a.h
+++ b/drivers/gpu/nvgpu/gk20a/dbg_gpu_gk20a.h
@@ -19,6 +19,8 @@
 #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 6dc10d1..149b1fb 100644
--- a/drivers/gpu/nvgpu/gk20a/gk20a.c
+++ b/drivers/gpu/nvgpu/gk20a/gk20a.c
@@ -58,9 +58,12 @@
 #include "hw_top_gk20a.h"
 #include "hw_ltc_gk20a.h"
 #include "gk20a_scale.h"
-#include "dbg_gpu_gk20a.h"
 #include "hal.h"
 
+#if defined(CONFIG_TEGRA_GK20A_DEBUG_SESSION)
+#include "dbg_gpu_gk20a.h"
+#endif
+
 #ifdef CONFIG_ARM64
 #define __cpuc_flush_dcache_area __flush_dcache_area
 #endif
@@ -106,6 +109,7 @@
 #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,
@@ -116,6 +120,7 @@
 	.compat_ioctl = gk20a_dbg_gpu_dev_ioctl,
 #endif
 };
+#endif
 
 static const struct file_operations gk20a_as_ops = {
 	.owner = THIS_MODULE,
@@ -133,6 +138,7 @@
  * 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,
@@ -145,6 +151,7 @@
 	.compat_ioctl = gk20a_dbg_gpu_dev_ioctl,
 #endif
 };
+#endif
 
 static inline void sim_writel(struct gk20a *g, u32 r, u32 v)
 {
@@ -1103,6 +1110,7 @@
 	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);
@@ -1114,6 +1122,7 @@
 				  &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 40dd8b2..d96943a 100644
--- a/drivers/gpu/nvgpu/gk20a/gr_gk20a.c
+++ b/drivers/gpu/nvgpu/gk20a/gr_gk20a.c
@@ -49,8 +49,12 @@
 #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)
 
@@ -5278,12 +5282,6 @@
 			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)
 {
@@ -5299,7 +5297,9 @@
 			  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, "");
 
@@ -5329,10 +5329,12 @@
 		}
 	}
 
+#if defined(CONFIG_TEGRA_GK20A_DEBUG_SESSION)
 	/* finally, signal any client waiting on an event */
-	fault_ch = channel_from_hw_chid(g, isr_data->chid);
+	fault_ch = g->fifo.channel + 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 23b4865..7ef8d62 100644
--- a/drivers/gpu/nvgpu/gk20a/regops_gk20a.h
+++ b/drivers/gpu/nvgpu/gk20a/regops_gk20a.h
@@ -19,14 +19,17 @@
 #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) ||