summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/common/linux/log.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/nvgpu/common/linux/log.c')
-rw-r--r--drivers/gpu/nvgpu/common/linux/log.c130
1 files changed, 130 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/common/linux/log.c b/drivers/gpu/nvgpu/common/linux/log.c
new file mode 100644
index 00000000..9dd965ec
--- /dev/null
+++ b/drivers/gpu/nvgpu/common/linux/log.c
@@ -0,0 +1,130 @@
1/*
2 * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include <linux/kernel.h>
18#include <linux/device.h>
19
20#include <nvgpu/log.h>
21
22#include "gk20a/gk20a.h"
23
24/*
25 * Define a length for log buffers. This is the buffer that the 'fmt, ...' part
26 * of __nvgpu_do_log_print() prints into. This buffer lives on the stack so it
27 * needs to not be overly sized since we have limited kernel stack space. But at
28 * the same time we don't want it to be restrictive either.
29 */
30#define LOG_BUFFER_LENGTH 160
31
32/*
33 * Annoying quirk of Linux: this has to be a string literal since the printk()
34 * function and friends use the preprocessor to concatenate stuff to the start
35 * of this string when printing.
36 */
37#define LOG_FMT "nvgpu: %s %33s:%-4d [%s] %s"
38
39u32 nvgpu_dbg_mask = NVGPU_DEFAULT_DBG_MASK;
40
41static const char *log_types[] = {
42 "ERR",
43 "WRN",
44 "DBG"
45};
46
47int nvgpu_log_mask_enabled(struct gk20a *g, u32 log_mask)
48{
49 return !!(g->log_mask & log_mask);
50}
51
52static inline const char *nvgpu_log_name(struct gk20a *g)
53{
54 return dev_name(g->dev);
55}
56
57#ifdef CONFIG_GK20A_TRACE_PRINTK
58static void __nvgpu_trace_printk_log(u32 trace, const char *gpu_name,
59 const char *func_name, int line,
60 enum nvgpu_log_type type, const char *log)
61{
62 trace_printk(LOG_FMT, gpu_name, func_name, line, type, log);
63}
64#endif
65
66static void __nvgpu_really_print_log(u32 trace, const char *gpu_name,
67 const char *func_name, int line,
68 enum nvgpu_log_type type, const char *log)
69{
70 const char *name = gpu_name ? gpu_name : "";
71
72#ifdef CONFIG_GK20A_TRACE_PRINTK
73 if (trace)
74 return __nvgpu_trace_printk_log(trace, name, func_name,
75 line, type, log);
76#else
77 const char *log_type = log_types[type];
78
79 switch (type) {
80 case DEBUG:
81 /*
82 * We could use pr_debug() here but we control debug enablement
83 * separately from the Linux kernel. Perhaps this is a bug in
84 * nvgpu.
85 */
86 pr_info(LOG_FMT, name, func_name, line, log_type, log);
87 break;
88 case WARNING:
89 pr_warn(LOG_FMT, name, func_name, line, log_type, log);
90 break;
91 case ERROR:
92 pr_err(LOG_FMT, name, func_name, line, log_type, log);
93 break;
94 }
95#endif
96}
97
98__attribute__((format (printf, 5, 6)))
99void __nvgpu_log_msg(struct gk20a *g, const char *func_name, int line,
100 enum nvgpu_log_type type, const char *fmt, ...)
101{
102 char log[LOG_BUFFER_LENGTH];
103 va_list args;
104
105 va_start(args, fmt);
106 vsnprintf(log, LOG_BUFFER_LENGTH, fmt, args);
107 va_end(args);
108
109 __nvgpu_really_print_log(0, g ? nvgpu_log_name(g) : "",
110 func_name, line, type, log);
111}
112
113__attribute__((format (printf, 5, 6)))
114void __nvgpu_log_dbg(struct gk20a *g, u32 log_mask,
115 const char *func_name, int line,
116 const char *fmt, ...)
117{
118 char log[LOG_BUFFER_LENGTH];
119 va_list args;
120
121 if ((log_mask & g->log_mask) == 0)
122 return;
123
124 va_start(args, fmt);
125 vsnprintf(log, LOG_BUFFER_LENGTH, fmt, args);
126 va_end(args);
127
128 __nvgpu_really_print_log(g->log_trace, nvgpu_log_name(g),
129 func_name, line, DEBUG, log);
130}