xref: /linux/drivers/gpu/drm/xe/xe_gt_printk.h (revision 2c1ed907520c50326b8f604907a8478b27881a2e)
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_gt_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_once(_gt, _fmt, ...) \
17 	xe_gt_printk((_gt), err_once, _fmt, ##__VA_ARGS__)
18 
19 #define xe_gt_err(_gt, _fmt, ...) \
20 	xe_gt_printk((_gt), err, _fmt, ##__VA_ARGS__)
21 
22 #define xe_gt_warn(_gt, _fmt, ...) \
23 	xe_gt_printk((_gt), warn, _fmt, ##__VA_ARGS__)
24 
25 #define xe_gt_notice(_gt, _fmt, ...) \
26 	xe_gt_printk((_gt), notice, _fmt, ##__VA_ARGS__)
27 
28 #define xe_gt_info(_gt, _fmt, ...) \
29 	xe_gt_printk((_gt), info, _fmt, ##__VA_ARGS__)
30 
31 #define xe_gt_dbg(_gt, _fmt, ...) \
32 	xe_gt_printk((_gt), dbg, _fmt, ##__VA_ARGS__)
33 
34 #define xe_gt_err_ratelimited(_gt, _fmt, ...) \
35 	xe_gt_printk((_gt), err_ratelimited, _fmt, ##__VA_ARGS__)
36 
37 #define xe_gt_WARN(_gt, _condition, _fmt, ...) \
38 	drm_WARN(&gt_to_xe(_gt)->drm, _condition, "GT%u: " _fmt, (_gt)->info.id, ##__VA_ARGS__)
39 
40 #define xe_gt_WARN_ONCE(_gt, _condition, _fmt, ...) \
41 	drm_WARN_ONCE(&gt_to_xe(_gt)->drm, _condition, "GT%u: " _fmt, (_gt)->info.id, ##__VA_ARGS__)
42 
43 #define xe_gt_WARN_ON(_gt, _condition) \
44 	xe_gt_WARN((_gt), _condition, "%s(%s)", "gt_WARN_ON", __stringify(_condition))
45 
46 #define xe_gt_WARN_ON_ONCE(_gt, _condition) \
47 	xe_gt_WARN_ONCE((_gt), _condition, "%s(%s)", "gt_WARN_ON_ONCE", __stringify(_condition))
48 
__xe_gt_printfn_err(struct drm_printer * p,struct va_format * vaf)49 static inline void __xe_gt_printfn_err(struct drm_printer *p, struct va_format *vaf)
50 {
51 	struct xe_gt *gt = p->arg;
52 
53 	xe_gt_err(gt, "%pV", vaf);
54 }
55 
__xe_gt_printfn_info(struct drm_printer * p,struct va_format * vaf)56 static inline void __xe_gt_printfn_info(struct drm_printer *p, struct va_format *vaf)
57 {
58 	struct xe_gt *gt = p->arg;
59 
60 	xe_gt_info(gt, "%pV", vaf);
61 }
62 
__xe_gt_printfn_dbg(struct drm_printer * p,struct va_format * vaf)63 static inline void __xe_gt_printfn_dbg(struct drm_printer *p, struct va_format *vaf)
64 {
65 	struct xe_gt *gt = p->arg;
66 	struct drm_printer dbg;
67 
68 	/*
69 	 * The original xe_gt_dbg() callsite annotations are useless here,
70 	 * redirect to the tweaked drm_dbg_printer() instead.
71 	 */
72 	dbg = drm_dbg_printer(&gt_to_xe(gt)->drm, DRM_UT_DRIVER, NULL);
73 	dbg.origin = p->origin;
74 
75 	drm_printf(&dbg, "GT%u: %pV", gt->info.id, vaf);
76 }
77 
78 /**
79  * xe_gt_err_printer - Construct a &drm_printer that outputs to xe_gt_err()
80  * @gt: the &xe_gt pointer to use in xe_gt_err()
81  *
82  * Return: The &drm_printer object.
83  */
xe_gt_err_printer(struct xe_gt * gt)84 static inline struct drm_printer xe_gt_err_printer(struct xe_gt *gt)
85 {
86 	struct drm_printer p = {
87 		.printfn = __xe_gt_printfn_err,
88 		.arg = gt,
89 	};
90 	return p;
91 }
92 
93 /**
94  * xe_gt_info_printer - Construct a &drm_printer that outputs to xe_gt_info()
95  * @gt: the &xe_gt pointer to use in xe_gt_info()
96  *
97  * Return: The &drm_printer object.
98  */
xe_gt_info_printer(struct xe_gt * gt)99 static inline struct drm_printer xe_gt_info_printer(struct xe_gt *gt)
100 {
101 	struct drm_printer p = {
102 		.printfn = __xe_gt_printfn_info,
103 		.arg = gt,
104 	};
105 	return p;
106 }
107 
108 /**
109  * xe_gt_dbg_printer - Construct a &drm_printer that outputs like xe_gt_dbg()
110  * @gt: the &xe_gt pointer to use in xe_gt_dbg()
111  *
112  * Return: The &drm_printer object.
113  */
xe_gt_dbg_printer(struct xe_gt * gt)114 static inline struct drm_printer xe_gt_dbg_printer(struct xe_gt *gt)
115 {
116 	struct drm_printer p = {
117 		.printfn = __xe_gt_printfn_dbg,
118 		.arg = gt,
119 		.origin = (const void *)_THIS_IP_,
120 	};
121 	return p;
122 }
123 
124 #endif
125