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