1 /*
2  * Copyright (C) 2018-2022 Intel Corporation.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef LOGMSG_H
8 #define LOGMSG_H
9 #include <asm/cpu.h>
10 
11 /* Logging severity levels */
12 #define LOG_FATAL		1U
13 /* For msg should be write to console and sbuf meanwhile but not fatal error */
14 #define LOG_ACRN		2U
15 #define LOG_ERROR		3U
16 #define LOG_WARNING		4U
17 #define LOG_INFO		5U
18 #define LOG_DEBUG		6U
19 
20 #define LOG_ENTRY_SIZE	80U
21 /* Size of buffer used to store a message being logged,
22  * should align to LOG_ENTRY_SIZE.
23  */
24 #define LOG_MESSAGE_MAX_SIZE	(4U * LOG_ENTRY_SIZE)
25 
26 #define DBG_LEVEL_LAPICPT	5U
27 #if defined(HV_DEBUG)
28 
29 extern uint16_t console_loglevel;
30 extern uint16_t mem_loglevel;
31 extern uint16_t npk_loglevel;
32 
33 void asm_assert(int32_t line, const char *file, const char *txt);
34 
35 #define ASSERT(x, ...) \
36 	do { \
37 		if (!(x)) {\
38 			asm_assert(__LINE__, __FILE__, "fatal error");\
39 		} \
40 	} while (0)
41 
42 #else /* HV_DEBUG */
43 
44 #define ASSERT(x, ...)	do { } while (0)
45 
46 #endif /* HV_DEBUG */
47 
48 void init_logmsg();
49 
50 /*
51  * @pre the severity > 0
52  */
53 void do_logmsg(uint32_t severity, const char *fmt, ...);
54 
55 /** The well known printf() function.
56  *
57  *  Formats a string and writes it to the console output.
58  *
59  *  @param fmt A pointer to the NUL terminated format string.
60  *
61  *  @return The number of characters actually written or a negative
62  *          number if an error occurred.
63  */
64 
65 void printf(const char *fmt, ...);
66 
67 /** The well known vprintf() function.
68  *
69  *  Formats a string and writes it to the console output.
70  *
71  *  @param fmt A pointer to the NUL terminated format string.
72  *  @param args The variable long argument list as va_list.
73  *  @return The number of characters actually written or a negative
74  *          number if an error occurred.
75  */
76 
77 void vprintf(const char *fmt, va_list args);
78 
79 #ifndef pr_prefix
80 #define pr_prefix
81 #endif
82 
83 #define pr_fatal(...)						\
84 	do {							\
85 		do_logmsg(LOG_FATAL, pr_prefix __VA_ARGS__);	\
86 	} while (0)
87 
88 #define pr_acrnlog(...)						\
89 	do {							\
90 		do_logmsg(LOG_ACRN, pr_prefix __VA_ARGS__);	\
91 	} while (0)
92 
93 #define pr_err(...)						\
94 	do {							\
95 		do_logmsg(LOG_ERROR, pr_prefix __VA_ARGS__);	\
96 	} while (0)
97 
98 #define pr_warn(...)						\
99 	do {							\
100 		do_logmsg(LOG_WARNING, pr_prefix __VA_ARGS__);	\
101 	} while (0)
102 
103 #define pr_info(...)						\
104 	do {							\
105 		do_logmsg(LOG_INFO, pr_prefix __VA_ARGS__);	\
106 	} while (0)
107 
108 #define pr_dbg(...)						\
109 	do {							\
110 		do_logmsg(LOG_DEBUG, pr_prefix __VA_ARGS__);	\
111 	} while (0)
112 
113 #define dev_dbg(lvl, ...)					\
114 	do {							\
115 		if ((lvl) > 0) {                                \
116 			do_logmsg((lvl), pr_prefix __VA_ARGS__);\
117 		}                                               \
118 	} while (0)
119 
120 #define panic(...) 							\
121 	do { pr_fatal("PANIC: %s line: %d\n", __func__, __LINE__);	\
122 		pr_fatal(__VA_ARGS__); 					\
123 		while (1) { asm_pause(); }; } while (0)
124 
125 #endif /* LOGMSG_H */
126