MALI: utgard: upgrade DDK to r7p0-00rel0
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / mali400 / mali / platform / rk30 / custom_log.h
1 /*  ----------------------------------------------------------------------------
2  *  File:   custom_log.h
3  *
4  *  Desc:   ChenZhen 偏好的 log 输出的定制实现.
5  *
6  *          --------------------------------------------------------------------
7  *          < 习语 和 缩略语 > :
8  *
9  *          --------------------------------------------------------------------
10  *  Usage:
11  *
12  *  Note:
13  *
14  *  Author: ChenZhen
15  *
16  *  ----------------------------------------------------------------------------
17  *  Version:
18  *          v1.0
19  *  ----------------------------------------------------------------------------
20  *  Log:
21         ----Fri Nov 19 15:20:28 2010            v1.0
22  *
23  *  ----------------------------------------------------------------------------
24  */
25
26
27 #ifndef __CUSTOM_LOG_H__
28 #define __CUSTOM_LOG_H__
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 /* -----------------------------------------------------------------------------
35  *  Include Files
36  * -----------------------------------------------------------------------------
37  */
38 #include <linux/kernel.h>
39 #include <linux/printk.h>
40
41
42 /* -----------------------------------------------------------------------------
43  *  Macros Definition
44  * -----------------------------------------------------------------------------
45  */
46
47 /** 若下列 macro 有被定义, 才 使能 log 输出. */
48 /* #define ENABLE_DEBUG_LOG */
49
50 /** .! : 若需要全局地关闭 D log, 可以使能下面的代码. */
51 /*
52 #undef ENABLE_DEBUG_LOG
53 #warning "custom debug log is disabled globally!"
54 */
55
56 /*----------------------------------------------------------------------------*/
57
58 #ifdef ENABLE_VERBOSE_LOG
59 /** Verbose log. */
60 #define V(fmt, args...) \
61         pr_info("V : [File] : %s; [Line] : %d; [Func] : %s(); " fmt \
62                         "\n",   \
63                 __FILE__,       \
64                 __LINE__,       \
65                 __func__,       \
66                 ## args)
67 #else
68 #define  V(...)  ((void)0)
69 #endif
70
71
72 #ifdef ENABLE_DEBUG_LOG
73 /** Debug log. */
74 #define D(fmt, args...) \
75         pr_info("D : [File] : %s; [Line] : %d; [Func] : %s(); " fmt \
76                         "\n",   \
77                 __FILE__,       \
78                 __LINE__,       \
79                 __func__,       \
80                 ## args)
81 #else
82 #define  D(...)  ((void)0)
83 #endif
84
85 #define I(fmt, args...) \
86         pr_info("I : [File] : %s; [Line] : %d; [Func] : %s(); " fmt \
87                         "\n", \
88                 __FILE__, \
89                 __LINE__, \
90                 __func__, \
91                 ## args)
92
93 #define W(fmt, args...) \
94         pr_warn("W : [File] : %s; [Line] : %d; [Func] : %s(); " \
95                         fmt "\n", \
96                 __FILE__, \
97                 __LINE__, \
98                 __func__, \
99                 ## args)
100
101 #define E(fmt, args...) \
102         pr_err("E : [File] : %s; [Line] : %d; [Func] : %s(); " fmt \
103                         "\n", \
104                 __FILE__, \
105                 __LINE__, \
106                 __func__, \
107                 ## args)
108
109 /*-------------------------------------------------------*/
110
111 /** 使用 D(), 以十进制的形式打印变量 'var' 的 value. */
112 #define D_DEC(var)  D(#var " = %d.", var)
113
114 #define E_DEC(var)  E(#var " = %d.", var)
115
116 /** 使用 D(), 以十六进制的形式打印变量 'var' 的 value. */
117 #define D_HEX(var)  D(#var " = 0x%x.", var)
118
119 #define E_HEX(var)  E(#var " = 0x%x.", var)
120
121 /**
122  * 使用 D(), 以十六进制的形式,
123  * 打印指针类型变量 'ptr' 的 value.
124  */
125 #define D_PTR(ptr)  D(#ptr " = %p.", ptr)
126
127 #define E_PTR(ptr)  E(#ptr " = %p.", ptr)
128
129 /** 使用 D(), 打印 char 字串. */
130 #define D_STR(p_str) \
131 do { \
132         if (NULL == p_str) { \
133                 D(#p_str" = NULL."); \
134         else \
135                 D(#p_str" = '%s'.", p_str); \
136 } while (0)
137
138 #define E_STR(p_str) \
139 do { \
140         if (NULL == p_str) \
141                 E(#p_str" = NULL."); \
142         else \
143                 E(#p_str" = '%s'.", p_str); \
144 } while (0)
145
146 #ifdef ENABLE_DEBUG_LOG
147 /**
148  * log 从 'p_start' 地址开始的 'len' 个字节的数据.
149  */
150 #define D_MEM(p_start, len) \
151 do { \
152         int i = 0; \
153         char *p = (char *)(p_start); \
154         D("dump memory from addr of '" #p_start "', from %p, length %d' : ", \
155                 (p_start), \
156                 (len)); \
157         pr_debug("\t\t"); \
158         for (i = 0; i < (len); i++) \
159                 pr_debug("0x%02x, ", p[i]); \
160         pr_debug("\n"); \
161 } while (0)
162 #else
163 #define  D_MEM(...)  ((void)0)
164 #endif
165
166 /*-------------------------------------------------------*/
167
168 #define EXIT_FOR_DEBUG \
169 do { \
170         E("To exit for debug."); \
171         return 1; \
172 } while (0)
173
174 /*-------------------------------------------------------*/
175
176 /**
177  * 调用函数, 并检查返回值, 根据返回值决定是否跳转到指定的错误处理代码.
178  * @param func_call
179  *      对特定函数的调用,
180  *      该函数的返回值必须是 表征 成功 or err 的 整型数.
181  *      且被 "必须" 被定义为 "返回 0 表示操作成功".
182  * @param result
183  *      用于记录函数返回的 error code 的 整型变量,
184  *      通常是 "ret" or "result" 等.
185  * @param label
186  *      若函数返回错误,
187  *      程序将要跳转到的 错误处理处的 标号,
188  *      通常就是 "EXIT".
189  */
190 #define CHECK_FUNC_CALL(func_call, result, label) \
191 do { \
192         (result) = (func_call) \
193         if (0 != (result)) { \
194                 E("Function call returned error : " #result " = %d.", result); \
195                 goto label;\
196         } \
197 } while (0)
198
199 /**
200  * 在特定条件下, 判定 error 发生, 对变量 'ret_var' 设置 'err_code',
201  * Log 输出对应的 Error Caution,
202  * 然后跳转 'label' 指定的代码处执行.
203  * @param msg
204  *      纯字串形式的提示信息.
205  * @param ret_var
206  *      标识函数执行状态或者结果的变量,
207  *      将被设置具体的 Error Code.
208  *      通常是 'ret' or 'result'.
209  * @param err_code
210  *      表征特定 error 的常数标识,
211  *      通常是 宏的形态.
212  * @param label
213  *      程序将要跳转到的错误处理代码的标号,
214  *      通常就是 'EXIT'.
215  * @param args...
216  *      对应 'msg_fmt' 实参中,
217  *      '%s', '%d', ... 等转换说明符的具体可变长实参.
218  */
219 #define SET_ERROR_AND_JUMP(msg_fmt, ret_var, err_code, label, args...) \
220 do { \
221         E("To set '" #ret_var "' to %d('" #err_code "'), because : " msg_fmt, \
222                 (err_code), \
223                 ## args); \
224         (ret_var) = (err_code); \
225         goto label; \
226 } while (0)
227
228
229 /* -----------------------------------------------------------------------------
230  *  Types and Structures Definition
231  * -----------------------------------------------------------------------------
232  */
233
234
235 /* -----------------------------------------------------------------------------
236  *  Global Functions' Prototype
237  * -----------------------------------------------------------------------------
238  */
239
240
241 /* -----------------------------------------------------------------------------
242  *  Inline Functions Implementation
243  * -----------------------------------------------------------------------------
244  */
245
246 #ifdef __cplusplus
247 }
248 #endif
249
250 #endif /* __CUSTOM_LOG_H__ */