blob: 9b75c72c9ca934c222e2028c4e6dbe72a764304f [file] [log] [blame]
Srinu Gorlecf8c6752018-01-19 18:36:13 +05301/* Copyright (c) 2012-2015, 2017-2018, The Linux Foundation.
2 * All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 */
14
15#ifndef __MSM_VIDC_DEBUG__
16#define __MSM_VIDC_DEBUG__
17#include <linux/debugfs.h>
18#include <linux/delay.h>
19#include "msm_vidc_internal.h"
20#include "trace/events/msm_vidc.h"
21
22#ifndef VIDC_DBG_LABEL
23#define VIDC_DBG_LABEL "msm_vidc"
24#endif
25
26#define VIDC_DBG_TAG VIDC_DBG_LABEL ": %4s: "
27#define VIDC_DBG_WARN_ENABLE (msm_vidc_debug & VIDC_INFO)
28
29/* To enable messages OR these values and
30 * echo the result to debugfs file.
31 *
32 * To enable all messages set debug_level = 0x101F
33 */
34
35enum vidc_msg_prio {
36 VIDC_ERR = 0x0001,
37 VIDC_WARN = 0x0002,
38 VIDC_INFO = 0x0004,
39 VIDC_DBG = 0x0008,
40 VIDC_PROF = 0x0010,
41 VIDC_PKT = 0x0020,
42 VIDC_FW = 0x1000,
43};
44
45enum vidc_msg_out {
46 VIDC_OUT_PRINTK = 0,
47 VIDC_OUT_FTRACE,
48};
49
50enum msm_vidc_debugfs_event {
51 MSM_VIDC_DEBUGFS_EVENT_ETB,
52 MSM_VIDC_DEBUGFS_EVENT_EBD,
53 MSM_VIDC_DEBUGFS_EVENT_FTB,
54 MSM_VIDC_DEBUGFS_EVENT_FBD,
55};
56
57extern int msm_vidc_debug;
58extern int msm_vidc_debug_out;
59extern int msm_vidc_fw_debug;
60extern int msm_vidc_fw_debug_mode;
61extern int msm_vidc_fw_low_power_mode;
62extern int msm_vidc_hw_rsp_timeout;
63extern bool msm_vidc_fw_coverage;
64extern int msm_vidc_vpe_csc_601_to_709;
65extern bool msm_vidc_dec_dcvs_mode;
66extern bool msm_vidc_enc_dcvs_mode;
67extern bool msm_vidc_sys_idle_indicator;
68extern int msm_vidc_firmware_unload_delay;
69extern bool msm_vidc_thermal_mitigation_disabled;
70extern bool msm_vidc_bitrate_clock_scaling;
71extern bool msm_vidc_debug_timeout;
72
73static inline char *VIDC_MSG_PRIO2STRING(int __level)
74{
75 char *__str;
76
77 switch (__level) {
78 case VIDC_ERR:
79 __str = "err";
80 break;
81 case VIDC_WARN:
82 __str = "warn";
83 break;
84 case VIDC_INFO:
85 __str = "info";
86 break;
87 case VIDC_DBG:
88 __str = "dbg";
89 break;
90 case VIDC_PROF:
91 __str = "prof";
92 break;
93 case VIDC_PKT:
94 __str = "pkt";
95 break;
96 case VIDC_FW:
97 __str = "fw";
98 break;
99 default:
100 __str = "????";
101 break;
102 }
103 return __str;
104}
105
106#define dprintk(__level, __fmt, arg...) \
107 do { \
108 if (msm_vidc_debug & __level) { \
109 if (msm_vidc_debug_out == VIDC_OUT_PRINTK) { \
110 pr_info(VIDC_DBG_TAG __fmt, \
111 VIDC_MSG_PRIO2STRING(__level), \
112 ## arg); \
113 } else if (msm_vidc_debug_out == VIDC_OUT_FTRACE) { \
114 trace_printk(KERN_DEBUG VIDC_DBG_TAG __fmt, \
115 VIDC_MSG_PRIO2STRING(__level), \
116 ## arg); \
117 } \
118 } \
119 } while (0)
120
121
122
123struct dentry *msm_vidc_debugfs_init_drv(void);
124struct dentry *msm_vidc_debugfs_init_core(struct msm_vidc_core *core,
125 struct dentry *parent);
126struct dentry *msm_vidc_debugfs_init_inst(struct msm_vidc_inst *inst,
127 struct dentry *parent);
128void msm_vidc_debugfs_deinit_inst(struct msm_vidc_inst *inst);
129void msm_vidc_debugfs_update(struct msm_vidc_inst *inst,
130 enum msm_vidc_debugfs_event e);
131
132static inline void tic(struct msm_vidc_inst *i, enum profiling_points p,
133 char *b)
134{
135 struct timeval __ddl_tv;
136
137 if (!i->debug.pdata[p].name[0])
138 memcpy(i->debug.pdata[p].name, b, 64);
139 if ((msm_vidc_debug & VIDC_PROF) &&
140 i->debug.pdata[p].sampling) {
141 do_gettimeofday(&__ddl_tv);
142 i->debug.pdata[p].start =
143 (__ddl_tv.tv_sec * 1000) + (__ddl_tv.tv_usec / 1000);
144 i->debug.pdata[p].sampling = false;
145 }
146}
147
148static inline void toc(struct msm_vidc_inst *i, enum profiling_points p)
149{
150 struct timeval __ddl_tv;
151
152 if ((msm_vidc_debug & VIDC_PROF) &&
153 !i->debug.pdata[p].sampling) {
154 do_gettimeofday(&__ddl_tv);
155 i->debug.pdata[p].stop = (__ddl_tv.tv_sec * 1000)
156 + (__ddl_tv.tv_usec / 1000);
157 i->debug.pdata[p].cumulative += i->debug.pdata[p].stop -
158 i->debug.pdata[p].start;
159 i->debug.pdata[p].sampling = true;
160 }
161}
162
163static inline void show_stats(struct msm_vidc_inst *i)
164{
165 int x;
166
167 for (x = 0; x < MAX_PROFILING_POINTS; x++) {
168 if (i->debug.pdata[x].name[0] &&
169 (msm_vidc_debug & VIDC_PROF)) {
170 if (i->debug.samples) {
171 dprintk(VIDC_PROF, "%s averaged %d ms/sample\n",
172 i->debug.pdata[x].name,
173 i->debug.pdata[x].cumulative /
174 i->debug.samples);
175 }
176
177 dprintk(VIDC_PROF, "%s Samples: %d\n",
178 i->debug.pdata[x].name,
179 i->debug.samples);
180 }
181 }
182}
183
184#endif