1/* SPDX-License-Identifier: MIT */
2/*
3 * Copyright �� 2023 Intel Corporation
4 */
5
6#ifndef _XE_GT_PRINTK_H_
7#define _XE_GT_PRINTK_H_
8
9#include <drm/drm_print.h>
10
11#include "xe_device_types.h"
12
13#define xe_gt_printk(_gt, _level, _fmt, ...) \
14	drm_##_level(&gt_to_xe(_gt)->drm, "GT%u: " _fmt, (_gt)->info.id, ##__VA_ARGS__)
15
16#define xe_gt_err(_gt, _fmt, ...) \
17	xe_gt_printk((_gt), err, _fmt, ##__VA_ARGS__)
18
19#define xe_gt_warn(_gt, _fmt, ...) \
20	xe_gt_printk((_gt), warn, _fmt, ##__VA_ARGS__)
21
22#define xe_gt_notice(_gt, _fmt, ...) \
23	xe_gt_printk((_gt), notice, _fmt, ##__VA_ARGS__)
24
25#define xe_gt_info(_gt, _fmt, ...) \
26	xe_gt_printk((_gt), info, _fmt, ##__VA_ARGS__)
27
28#define xe_gt_dbg(_gt, _fmt, ...) \
29	xe_gt_printk((_gt), dbg, _fmt, ##__VA_ARGS__)
30
31#define xe_gt_err_ratelimited(_gt, _fmt, ...) \
32	xe_gt_printk((_gt), err_ratelimited, _fmt, ##__VA_ARGS__)
33
34#define xe_gt_WARN(_gt, _condition, _fmt, ...) \
35	drm_WARN(&gt_to_xe(_gt)->drm, _condition, "GT%u: " _fmt, (_gt)->info.id, ##__VA_ARGS__)
36
37#define xe_gt_WARN_ONCE(_gt, _condition, _fmt, ...) \
38	drm_WARN_ONCE(&gt_to_xe(_gt)->drm, _condition, "GT%u: " _fmt, (_gt)->info.id, ##__VA_ARGS__)
39
40#define xe_gt_WARN_ON(_gt, _condition) \
41	xe_gt_WARN((_gt), _condition, "%s(%s)", "gt_WARN_ON", __stringify(_condition))
42
43#define xe_gt_WARN_ON_ONCE(_gt, _condition) \
44	xe_gt_WARN_ONCE((_gt), _condition, "%s(%s)", "gt_WARN_ON_ONCE", __stringify(_condition))
45
46static inline void __xe_gt_printfn_err(struct drm_printer *p, struct va_format *vaf)
47{
48	struct xe_gt *gt = p->arg;
49
50	xe_gt_err(gt, "%pV", vaf);
51}
52
53static inline void __xe_gt_printfn_info(struct drm_printer *p, struct va_format *vaf)
54{
55	struct xe_gt *gt = p->arg;
56
57	xe_gt_info(gt, "%pV", vaf);
58}
59
60/**
61 * xe_gt_err_printer - Construct a &drm_printer that outputs to xe_gt_err()
62 * @gt: the &xe_gt pointer to use in xe_gt_err()
63 *
64 * Return: The &drm_printer object.
65 */
66static inline struct drm_printer xe_gt_err_printer(struct xe_gt *gt)
67{
68	struct drm_printer p = {
69		.printfn = __xe_gt_printfn_err,
70		.arg = gt,
71	};
72	return p;
73}
74
75/**
76 * xe_gt_info_printer - Construct a &drm_printer that outputs to xe_gt_info()
77 * @gt: the &xe_gt pointer to use in xe_gt_info()
78 *
79 * Return: The &drm_printer object.
80 */
81static inline struct drm_printer xe_gt_info_printer(struct xe_gt *gt)
82{
83	struct drm_printer p = {
84		.printfn = __xe_gt_printfn_info,
85		.arg = gt,
86	};
87	return p;
88}
89
90#endif
91