1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#pragma once
4
5#include "mos/syslog/debug.h"
6#include "mos/syslog/syslog.h"
7
8#include <mos/mos_global.h>
9#include <mos/types.h>
10#include <stdarg.h>
11
12#ifndef pr_fmt
13#define pr_fmt(fmt) fmt // default format string
14#endif
15
16#define emit_syslog(level, feat, fmt, ...) do_syslog(level, current_thread, __FILE_NAME__, __func__, __LINE__, &mos_debug_info.feat, fmt, ##__VA_ARGS__)
17#define emit_syslog_nofeat(level, fmt, ...) do_syslog(level, current_thread, __FILE_NAME__, __func__, __LINE__, NULL, fmt, ##__VA_ARGS__)
18
19#define lprintk_debug_wrapper(feat, level, fmt, ...) \
20 do \
21 { \
22 if (mos_debug_enabled(feat)) \
23 emit_syslog(level, feat, fmt, ##__VA_ARGS__); \
24 } while (0)
25
26// clang-format off
27#define pr_dinfo2(feat, fmt, ...) lprintk_debug_wrapper(feat, MOS_LOG_INFO2, pr_fmt(fmt), ##__VA_ARGS__)
28#define pr_dinfo(feat, fmt, ...) lprintk_debug_wrapper(feat, MOS_LOG_INFO, pr_fmt(fmt), ##__VA_ARGS__)
29#define pr_demph(feat, fmt, ...) lprintk_debug_wrapper(feat, MOS_LOG_EMPH, pr_fmt(fmt), ##__VA_ARGS__)
30#define pr_dwarn(feat, fmt, ...) lprintk_debug_wrapper(feat, MOS_LOG_WARN, pr_fmt(fmt), ##__VA_ARGS__)
31#define pr_demerg(feat, fmt, ...) lprintk_debug_wrapper(feat, MOS_LOG_EMERG, pr_fmt(fmt), ##__VA_ARGS__)
32#define pr_dfatal(feat, fmt, ...) lprintk_debug_wrapper(feat, MOS_LOG_FATAL, pr_fmt(fmt), ##__VA_ARGS__)
33#define pr_dcont(feat, fmt, ...) do { if (mos_debug_enabled(feat)) pr_cont(fmt, ##__VA_ARGS__); } while (0)
34
35#define pr_info(fmt, ...) emit_syslog_nofeat(MOS_LOG_INFO, pr_fmt(fmt), ##__VA_ARGS__)
36#define pr_info2(fmt, ...) emit_syslog_nofeat(MOS_LOG_INFO2, pr_fmt(fmt), ##__VA_ARGS__)
37#define pr_emph(fmt, ...) emit_syslog_nofeat(MOS_LOG_EMPH, pr_fmt(fmt), ##__VA_ARGS__)
38#define pr_warn(fmt, ...) emit_syslog_nofeat(MOS_LOG_WARN, pr_fmt(fmt), ##__VA_ARGS__)
39#define pr_emerg(fmt, ...) emit_syslog_nofeat(MOS_LOG_EMERG, pr_fmt(fmt), ##__VA_ARGS__)
40#define pr_fatal(fmt, ...) emit_syslog_nofeat(MOS_LOG_FATAL, pr_fmt(fmt), ##__VA_ARGS__)
41#define pr_cont(fmt, ...) emit_syslog_nofeat(MOS_LOG_UNSET, "" fmt, ##__VA_ARGS__)
42// clang-format off
43
44__BEGIN_DECLS
45
46void lvprintk(loglevel_t loglevel, const char *fmt, va_list args);
47__printf(1, 2) void printk(const char *format, ...);
48__printf(2, 3) void lprintk(loglevel_t loglevel, const char *format, ...);
49
50bool printk_unquiet(void);
51void printk_set_quiet(bool quiet);
52
53__END_DECLS
54