xref: /OK3568_Linux_fs/external/security/librkcrypto/include/rkcrypto_trace.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Copyright (c) 2022 Rockchip Electronics Co. Ltd.
3  */
4 #ifndef _RKCRYPTO_TRACE_H_
5 #define _RKCRYPTO_TRACE_H_
6 
7 #include <stdio.h>
8 #include "rkcrypto_common.h"
9 
10 enum RKCRYPTO_TRACE_LEVEL {
11 	TRACE_TOP     = 0,
12 	TRACE_ERROR   = 1,
13 	TRACE_INFO    = 2,
14 	TRACE_DEBUG   = 3,
15 	TRACE_VERBOSE = 4,
16 	TRACE_BUTT,
17 };
18 
19 void trace_printf(int level, const char *function, int line, const char *fmt, ...);
20 void hex_dump(int level, const char *function, int line, const char *buffer_name,
21 	      const void *buffer, int len);
22 #define V_TRACE(...) \
23 	trace_printf(TRACE_VERBOSE, __func__, __LINE__, __VA_ARGS__)
24 
25 #define D_TRACE(...) \
26 	trace_printf(TRACE_DEBUG, __func__, __LINE__, __VA_ARGS__)
27 
28 #define I_TRACE(...) \
29 	trace_printf(TRACE_INFO, __func__, __LINE__, __VA_ARGS__)
30 
31 #define E_TRACE(...) \
32 	trace_printf(TRACE_ERROR, __func__, __LINE__, __VA_ARGS__)
33 
34 #define VHEX_DUMP(buffer_name, buffer, len) \
35 	hex_dump(TRACE_VERBOSE, __func__, __LINE__, buffer_name, buffer, len)
36 
37 #define RK_CRYPTO_CHECK_PARAM(_val)\
38 	do {\
39 		if (_val) {\
40 			E_TRACE("RK_CRYPTO_CHECK_PARAM ERR! 0x%08x", RK_CRYPTO_ERR_PARAMETER);\
41 			return RK_CRYPTO_ERR_PARAMETER;\
42 		}\
43 	} while (0)
44 
45 RK_RES rkcrypto_set_trace_level(enum RKCRYPTO_TRACE_LEVEL level);
46 
47 #endif /* _RKCRYPTO_TRACE_H_ */
48