diff options
Diffstat (limited to 'drivers/gpu/nvgpu/common/linux/log.c')
-rw-r--r-- | drivers/gpu/nvgpu/common/linux/log.c | 138 |
1 files changed, 138 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..e120a3de --- /dev/null +++ b/drivers/gpu/nvgpu/common/linux/log.c | |||
@@ -0,0 +1,138 @@ | |||
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 | #include "platform_gk20a.h" | ||
24 | #include "os_linux.h" | ||
25 | |||
26 | /* | ||
27 | * Define a length for log buffers. This is the buffer that the 'fmt, ...' part | ||
28 | * of __nvgpu_do_log_print() prints into. This buffer lives on the stack so it | ||
29 | * needs to not be overly sized since we have limited kernel stack space. But at | ||
30 | * the same time we don't want it to be restrictive either. | ||
31 | */ | ||
32 | #define LOG_BUFFER_LENGTH 160 | ||
33 | |||
34 | /* | ||
35 | * Annoying quirk of Linux: this has to be a string literal since the printk() | ||
36 | * function and friends use the preprocessor to concatenate stuff to the start | ||
37 | * of this string when printing. | ||
38 | */ | ||
39 | #define LOG_FMT "nvgpu: %s %33s:%-4d [%s] %s\n" | ||
40 | |||
41 | u32 nvgpu_dbg_mask = NVGPU_DEFAULT_DBG_MASK; | ||
42 | |||
43 | static const char *log_types[] = { | ||
44 | "ERR", | ||
45 | "WRN", | ||
46 | "DBG", | ||
47 | "INFO", | ||
48 | }; | ||
49 | |||
50 | int nvgpu_log_mask_enabled(struct gk20a *g, u32 log_mask) | ||
51 | { | ||
52 | return !!(g->log_mask & log_mask); | ||
53 | } | ||
54 | |||
55 | static inline const char *nvgpu_log_name(struct gk20a *g) | ||
56 | { | ||
57 | return dev_name(dev_from_gk20a(g)); | ||
58 | } | ||
59 | |||
60 | #ifdef CONFIG_GK20A_TRACE_PRINTK | ||
61 | static void __nvgpu_trace_printk_log(u32 trace, const char *gpu_name, | ||
62 | const char *func_name, int line, | ||
63 | enum nvgpu_log_type type, const char *log) | ||
64 | { | ||
65 | const char *log_type = log_types[type]; | ||
66 | |||
67 | trace_printk(LOG_FMT, gpu_name, func_name, line, log_type, log); | ||
68 | } | ||
69 | #endif | ||
70 | |||
71 | static void __nvgpu_really_print_log(u32 trace, const char *gpu_name, | ||
72 | const char *func_name, int line, | ||
73 | enum nvgpu_log_type type, const char *log) | ||
74 | { | ||
75 | const char *name = gpu_name ? gpu_name : ""; | ||
76 | |||
77 | #ifdef CONFIG_GK20A_TRACE_PRINTK | ||
78 | if (trace) | ||
79 | return __nvgpu_trace_printk_log(trace, name, func_name, | ||
80 | line, type, log); | ||
81 | #else | ||
82 | const char *log_type = log_types[type]; | ||
83 | |||
84 | switch (type) { | ||
85 | case NVGPU_DEBUG: | ||
86 | /* | ||
87 | * We could use pr_debug() here but we control debug enablement | ||
88 | * separately from the Linux kernel. Perhaps this is a bug in | ||
89 | * nvgpu. | ||
90 | */ | ||
91 | pr_info(LOG_FMT, name, func_name, line, log_type, log); | ||
92 | break; | ||
93 | case NVGPU_INFO: | ||
94 | pr_info(LOG_FMT, name, func_name, line, log_type, log); | ||
95 | break; | ||
96 | case NVGPU_WARNING: | ||
97 | pr_warn(LOG_FMT, name, func_name, line, log_type, log); | ||
98 | break; | ||
99 | case NVGPU_ERROR: | ||
100 | pr_err(LOG_FMT, name, func_name, line, log_type, log); | ||
101 | break; | ||
102 | } | ||
103 | #endif | ||
104 | } | ||
105 | |||
106 | __attribute__((format (printf, 5, 6))) | ||
107 | void __nvgpu_log_msg(struct gk20a *g, const char *func_name, int line, | ||
108 | enum nvgpu_log_type type, const char *fmt, ...) | ||
109 | { | ||
110 | char log[LOG_BUFFER_LENGTH]; | ||
111 | va_list args; | ||
112 | |||
113 | va_start(args, fmt); | ||
114 | vsnprintf(log, LOG_BUFFER_LENGTH, fmt, args); | ||
115 | va_end(args); | ||
116 | |||
117 | __nvgpu_really_print_log(0, g ? nvgpu_log_name(g) : "", | ||
118 | func_name, line, type, log); | ||
119 | } | ||
120 | |||
121 | __attribute__((format (printf, 5, 6))) | ||
122 | void __nvgpu_log_dbg(struct gk20a *g, u32 log_mask, | ||
123 | const char *func_name, int line, | ||
124 | const char *fmt, ...) | ||
125 | { | ||
126 | char log[LOG_BUFFER_LENGTH]; | ||
127 | va_list args; | ||
128 | |||
129 | if ((log_mask & g->log_mask) == 0) | ||
130 | return; | ||
131 | |||
132 | va_start(args, fmt); | ||
133 | vsnprintf(log, LOG_BUFFER_LENGTH, fmt, args); | ||
134 | va_end(args); | ||
135 | |||
136 | __nvgpu_really_print_log(g->log_trace, nvgpu_log_name(g), | ||
137 | func_name, line, NVGPU_DEBUG, log); | ||
138 | } | ||