1 /* SPDX-License-Identifier: MIT */
2 /*
3 * Copyright © 2025 Intel Corporation
4 */
5
6 #ifndef _XE_PRINTK_H_
7 #define _XE_PRINTK_H_
8
9 #include <drm/drm_print.h>
10
11 #include "xe_device_types.h"
12
13 #define __XE_PRINTK_FMT(_xe, _fmt, _args...) _fmt, ##_args
14
15 #define xe_printk(_xe, _level, _fmt, ...) \
16 drm_##_level(&(_xe)->drm, __XE_PRINTK_FMT((_xe), _fmt, ## __VA_ARGS__))
17
18 #define xe_err(_xe, _fmt, ...) \
19 xe_printk((_xe), err, _fmt, ##__VA_ARGS__)
20
21 #define xe_err_once(_xe, _fmt, ...) \
22 xe_printk((_xe), err_once, _fmt, ##__VA_ARGS__)
23
24 #define xe_err_ratelimited(_xe, _fmt, ...) \
25 xe_printk((_xe), err_ratelimited, _fmt, ##__VA_ARGS__)
26
27 #define xe_warn(_xe, _fmt, ...) \
28 xe_printk((_xe), warn, _fmt, ##__VA_ARGS__)
29
30 #define xe_notice(_xe, _fmt, ...) \
31 xe_printk((_xe), notice, _fmt, ##__VA_ARGS__)
32
33 #define xe_info(_xe, _fmt, ...) \
34 xe_printk((_xe), info, _fmt, ##__VA_ARGS__)
35
36 #define xe_dbg(_xe, _fmt, ...) \
37 xe_printk((_xe), dbg, _fmt, ##__VA_ARGS__)
38
39 #define xe_WARN_type(_xe, _type, _condition, _fmt, ...) \
40 drm_WARN##_type(&(_xe)->drm, _condition, _fmt, ## __VA_ARGS__)
41
42 #define xe_WARN(_xe, _condition, _fmt, ...) \
43 xe_WARN_type((_xe),, _condition, __XE_PRINTK_FMT((_xe), _fmt, ## __VA_ARGS__))
44
45 #define xe_WARN_ONCE(_xe, _condition, _fmt, ...) \
46 xe_WARN_type((_xe), _ONCE, _condition, __XE_PRINTK_FMT((_xe), _fmt, ## __VA_ARGS__))
47
48 #define xe_WARN_ON(_xe, _condition) \
49 xe_WARN((_xe), _condition, "%s(%s)", "WARN_ON", __stringify(_condition))
50
51 #define xe_WARN_ON_ONCE(_xe, _condition) \
52 xe_WARN_ONCE((_xe), _condition, "%s(%s)", "WARN_ON_ONCE", __stringify(_condition))
53
__xe_printfn_err(struct drm_printer * p,struct va_format * vaf)54 static inline void __xe_printfn_err(struct drm_printer *p, struct va_format *vaf)
55 {
56 struct xe_device *xe = p->arg;
57
58 xe_err(xe, "%pV", vaf);
59 }
60
__xe_printfn_info(struct drm_printer * p,struct va_format * vaf)61 static inline void __xe_printfn_info(struct drm_printer *p, struct va_format *vaf)
62 {
63 struct xe_device *xe = p->arg;
64
65 xe_info(xe, "%pV", vaf);
66 }
67
__xe_printfn_dbg(struct drm_printer * p,struct va_format * vaf)68 static inline void __xe_printfn_dbg(struct drm_printer *p, struct va_format *vaf)
69 {
70 struct xe_device *xe = p->arg;
71 struct drm_printer ddp;
72
73 /*
74 * The original xe_dbg() callsite annotations are useless here,
75 * redirect to the tweaked drm_dbg_printer() instead.
76 */
77 ddp = drm_dbg_printer(&xe->drm, DRM_UT_DRIVER, NULL);
78 ddp.origin = p->origin;
79
80 drm_printf(&ddp, __XE_PRINTK_FMT(xe, "%pV", vaf));
81 }
82
83 /**
84 * xe_err_printer - Construct a &drm_printer that outputs to xe_err()
85 * @xe: the &xe_device pointer to use in xe_err()
86 *
87 * Return: The &drm_printer object.
88 */
xe_err_printer(struct xe_device * xe)89 static inline struct drm_printer xe_err_printer(struct xe_device *xe)
90 {
91 struct drm_printer p = {
92 .printfn = __xe_printfn_err,
93 .arg = xe,
94 };
95 return p;
96 }
97
98 /**
99 * xe_info_printer - Construct a &drm_printer that outputs to xe_info()
100 * @xe: the &xe_device pointer to use in xe_info()
101 *
102 * Return: The &drm_printer object.
103 */
xe_info_printer(struct xe_device * xe)104 static inline struct drm_printer xe_info_printer(struct xe_device *xe)
105 {
106 struct drm_printer p = {
107 .printfn = __xe_printfn_info,
108 .arg = xe,
109 };
110 return p;
111 }
112
113 /**
114 * xe_dbg_printer - Construct a &drm_printer that outputs like xe_dbg()
115 * @xe: the &xe_device pointer to use in xe_dbg()
116 *
117 * Return: The &drm_printer object.
118 */
xe_dbg_printer(struct xe_device * xe)119 static inline struct drm_printer xe_dbg_printer(struct xe_device *xe)
120 {
121 struct drm_printer p = {
122 .printfn = __xe_printfn_dbg,
123 .arg = xe,
124 .origin = (const void *)_THIS_IP_,
125 };
126 return p;
127 }
128
129 #endif
130