linux/include/linux/dev_printk.h

// SPDX-License-Identifier: GPL-2.0
/*
 * dev_printk.h - printk messages helpers for devices
 *
 * Copyright (c) 2001-2003 Patrick Mochel <[email protected]>
 * Copyright (c) 2004-2009 Greg Kroah-Hartman <[email protected]>
 * Copyright (c) 2008-2009 Novell Inc.
 *
 */

#ifndef _DEVICE_PRINTK_H_
#define _DEVICE_PRINTK_H_

#include <linux/compiler.h>
#include <linux/types.h>
#include <linux/ratelimit.h>

#ifndef dev_fmt
#define dev_fmt(fmt)
#endif

struct device;

#define PRINTK_INFO_SUBSYSTEM_LEN
#define PRINTK_INFO_DEVICE_LEN

struct dev_printk_info {};

#ifdef CONFIG_PRINTK

__printf(3, 0) __cold
int dev_vprintk_emit(int level, const struct device *dev,
		     const char *fmt, va_list args);
__printf(3, 4) __cold
int dev_printk_emit(int level, const struct device *dev, const char *fmt, ...);

__printf(3, 4) __cold
void _dev_printk(const char *level, const struct device *dev,
		 const char *fmt, ...);
__printf(2, 3) __cold
void _dev_emerg(const struct device *dev, const char *fmt, ...);
__printf(2, 3) __cold
void _dev_alert(const struct device *dev, const char *fmt, ...);
__printf(2, 3) __cold
void _dev_crit(const struct device *dev, const char *fmt, ...);
__printf(2, 3) __cold
void _dev_err(const struct device *dev, const char *fmt, ...);
__printf(2, 3) __cold
void _dev_warn(const struct device *dev, const char *fmt, ...);
__printf(2, 3) __cold
void _dev_notice(const struct device *dev, const char *fmt, ...);
__printf(2, 3) __cold
void _dev_info(const struct device *dev, const char *fmt, ...);

#else

static inline __printf(3, 0)
int dev_vprintk_emit(int level, const struct device *dev,
		     const char *fmt, va_list args)
{ return 0; }
static inline __printf(3, 4)
int dev_printk_emit(int level, const struct device *dev, const char *fmt, ...)
{ return 0; }

static inline void __dev_printk(const char *level, const struct device *dev,
				struct va_format *vaf)
{}
static inline __printf(3, 4)
void _dev_printk(const char *level, const struct device *dev,
		 const char *fmt, ...)
{}

static inline __printf(2, 3)
void _dev_emerg(const struct device *dev, const char *fmt, ...)
{}
static inline __printf(2, 3)
void _dev_crit(const struct device *dev, const char *fmt, ...)
{}
static inline __printf(2, 3)
void _dev_alert(const struct device *dev, const char *fmt, ...)
{}
static inline __printf(2, 3)
void _dev_err(const struct device *dev, const char *fmt, ...)
{}
static inline __printf(2, 3)
void _dev_warn(const struct device *dev, const char *fmt, ...)
{}
static inline __printf(2, 3)
void _dev_notice(const struct device *dev, const char *fmt, ...)
{}
static inline __printf(2, 3)
void _dev_info(const struct device *dev, const char *fmt, ...)
{}

#endif

/*
 * Need to take variadic arguments even though we don't use them, as dev_fmt()
 * may only just have been expanded and may result in multiple arguments.
 */
#define dev_printk_index_emit(level, fmt, ...)

#define dev_printk_index_wrap(_p_func, level, dev, fmt, ...)

/*
 * Some callsites directly call dev_printk rather than going through the
 * dev_<level> infrastructure, so we need to emit here as well as inside those
 * level-specific macros. Only one index entry will be produced, either way,
 * since dev_printk's `fmt` isn't known at compile time if going through the
 * dev_<level> macros.
 *
 * dev_fmt() isn't called for dev_printk when used directly, as it's used by
 * the dev_<level> macros internally which already have dev_fmt() processed.
 *
 * We also can't use dev_printk_index_wrap directly, because we have a separate
 * level to process.
 */
#define dev_printk(level, dev, fmt, ...)

/*
 * Dummy dev_printk for disabled debugging statements to use whilst maintaining
 * gcc's format checking.
 */
#define dev_no_printk(level, dev, fmt, ...)

/*
 * #defines for all the dev_<level> macros to prefix with whatever
 * possible use of #define dev_fmt(fmt) ...
 */

#define dev_emerg(dev, fmt, ...)
#define dev_crit(dev, fmt, ...)
#define dev_alert(dev, fmt, ...)
#define dev_err(dev, fmt, ...)
#define dev_warn(dev, fmt, ...)
#define dev_notice(dev, fmt, ...)
#define dev_info(dev, fmt, ...)

#if defined(CONFIG_DYNAMIC_DEBUG) || \
	(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
#define dev_dbg(dev, fmt, ...)
#elif defined(DEBUG)
#define dev_dbg
#else
#define dev_dbg
#endif

#ifdef CONFIG_PRINTK
#define dev_level_once(dev_level, dev, fmt, ...)
#else
#define dev_level_once
#endif

#define dev_emerg_once(dev, fmt, ...)
#define dev_alert_once(dev, fmt, ...)
#define dev_crit_once(dev, fmt, ...)
#define dev_err_once(dev, fmt, ...)
#define dev_warn_once(dev, fmt, ...)
#define dev_notice_once(dev, fmt, ...)
#define dev_info_once(dev, fmt, ...)
#define dev_dbg_once(dev, fmt, ...)

#define dev_level_ratelimited(dev_level, dev, fmt, ...)

#define dev_emerg_ratelimited(dev, fmt, ...)
#define dev_alert_ratelimited(dev, fmt, ...)
#define dev_crit_ratelimited(dev, fmt, ...)
#define dev_err_ratelimited(dev, fmt, ...)
#define dev_warn_ratelimited(dev, fmt, ...)
#define dev_notice_ratelimited(dev, fmt, ...)
#define dev_info_ratelimited(dev, fmt, ...)
#if defined(CONFIG_DYNAMIC_DEBUG) || \
	(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
/* descriptor check is first to prevent flooding with "callbacks suppressed" */
#define dev_dbg_ratelimited(dev, fmt, ...)
#elif defined(DEBUG)
#define dev_dbg_ratelimited
#else
#define dev_dbg_ratelimited
#endif

#ifdef VERBOSE_DEBUG
#define dev_vdbg
#else
#define dev_vdbg(dev, fmt, ...)
#endif

/*
 * dev_WARN*() acts like dev_printk(), but with the key difference of
 * using WARN/WARN_ONCE to include file/line information and a backtrace.
 */
#define dev_WARN(dev, format, arg...)

#define dev_WARN_ONCE(dev, condition, format, arg...)

__printf(3, 4) int dev_err_probe(const struct device *dev, int err, const char *fmt, ...);

/* Simple helper for dev_err_probe() when ERR_PTR() is to be returned. */
#define dev_err_ptr_probe(dev, ___err, fmt, ...)

/* Simple helper for dev_err_probe() when ERR_CAST() is to be returned. */
#define dev_err_cast_probe(dev, ___err_ptr, fmt, ...)

#endif /* _DEVICE_PRINTK_H_ */