2016-11-05 22:08:07 +07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 Red Hat
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Rob Clark <robdclark@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DRM_PRINT_H_
|
|
|
|
#define DRM_PRINT_H_
|
|
|
|
|
2017-02-16 06:33:18 +07:00
|
|
|
#include <linux/compiler.h>
|
|
|
|
#include <linux/printk.h>
|
2016-11-05 22:08:07 +07:00
|
|
|
#include <linux/seq_file.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DOC: print
|
|
|
|
*
|
|
|
|
* A simple wrapper for dev_printk(), seq_printf(), etc. Allows same
|
|
|
|
* debug code to be used for both debugfs and printk logging.
|
|
|
|
*
|
|
|
|
* For example::
|
|
|
|
*
|
|
|
|
* void log_some_info(struct drm_printer *p)
|
|
|
|
* {
|
|
|
|
* drm_printf(p, "foo=%d\n", foo);
|
|
|
|
* drm_printf(p, "bar=%d\n", bar);
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* #ifdef CONFIG_DEBUG_FS
|
|
|
|
* void debugfs_show(struct seq_file *f)
|
|
|
|
* {
|
|
|
|
* struct drm_printer p = drm_seq_file_printer(f);
|
|
|
|
* log_some_info(&p);
|
|
|
|
* }
|
|
|
|
* #endif
|
|
|
|
*
|
|
|
|
* void some_other_function(...)
|
|
|
|
* {
|
|
|
|
* struct drm_printer p = drm_info_printer(drm->dev);
|
|
|
|
* log_some_info(&p);
|
|
|
|
* }
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct drm_printer - drm output "stream"
|
|
|
|
*
|
|
|
|
* Do not use struct members directly. Use drm_printer_seq_file(),
|
|
|
|
* drm_printer_info(), etc to initialize. And drm_printf() for output.
|
|
|
|
*/
|
|
|
|
struct drm_printer {
|
2016-12-28 23:42:09 +07:00
|
|
|
/* private: */
|
2016-11-05 22:08:07 +07:00
|
|
|
void (*printfn)(struct drm_printer *p, struct va_format *vaf);
|
|
|
|
void *arg;
|
2016-12-28 23:42:09 +07:00
|
|
|
const char *prefix;
|
2016-11-05 22:08:07 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
void __drm_printfn_seq_file(struct drm_printer *p, struct va_format *vaf);
|
|
|
|
void __drm_printfn_info(struct drm_printer *p, struct va_format *vaf);
|
2016-12-28 23:42:09 +07:00
|
|
|
void __drm_printfn_debug(struct drm_printer *p, struct va_format *vaf);
|
2016-11-05 22:08:07 +07:00
|
|
|
|
2017-02-16 06:33:18 +07:00
|
|
|
__printf(2, 3)
|
2016-11-05 22:08:07 +07:00
|
|
|
void drm_printf(struct drm_printer *p, const char *f, ...);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_seq_file_printer - construct a &drm_printer that outputs to &seq_file
|
2016-12-30 03:48:26 +07:00
|
|
|
* @f: the &struct seq_file to output to
|
2016-11-05 22:08:07 +07:00
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
* The &drm_printer object
|
|
|
|
*/
|
|
|
|
static inline struct drm_printer drm_seq_file_printer(struct seq_file *f)
|
|
|
|
{
|
|
|
|
struct drm_printer p = {
|
|
|
|
.printfn = __drm_printfn_seq_file,
|
|
|
|
.arg = f,
|
|
|
|
};
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_info_printer - construct a &drm_printer that outputs to dev_printk()
|
2016-12-30 03:48:26 +07:00
|
|
|
* @dev: the &struct device pointer
|
2016-11-05 22:08:07 +07:00
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
* The &drm_printer object
|
|
|
|
*/
|
|
|
|
static inline struct drm_printer drm_info_printer(struct device *dev)
|
|
|
|
{
|
|
|
|
struct drm_printer p = {
|
|
|
|
.printfn = __drm_printfn_info,
|
|
|
|
.arg = dev,
|
|
|
|
};
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2016-12-28 23:42:09 +07:00
|
|
|
/**
|
|
|
|
* drm_debug_printer - construct a &drm_printer that outputs to pr_debug()
|
|
|
|
* @prefix: debug output prefix
|
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
* The &drm_printer object
|
|
|
|
*/
|
|
|
|
static inline struct drm_printer drm_debug_printer(const char *prefix)
|
|
|
|
{
|
|
|
|
struct drm_printer p = {
|
|
|
|
.printfn = __drm_printfn_debug,
|
|
|
|
.prefix = prefix
|
|
|
|
};
|
|
|
|
return p;
|
|
|
|
}
|
2016-11-05 22:08:07 +07:00
|
|
|
#endif /* DRM_PRINT_H_ */
|