Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/xe: Define helper for GT specific debugfs files

Many of our debugfs files are GT specific and require a pointer to
struct xe_gt to correctly show its content. Our initial approach
to use drm_info_list.data field to pass pointer not only requires
extra steps (like copying template per each GT) but also abuses
the rule that this data field should not be device specific.

Introduce helper function that will use xe_gt pointer stored at
parent directory level and use .data only to pass actual print
function that would expects xe_gt pointer as a parameter.

Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Link: https://lore.kernel.org/r/20240214115756.1525-3-michal.wajdeczko@intel.com
Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240328162808.451-3-michal.wajdeczko@intel.com

+54
+52
drivers/gpu/drm/xe/xe_gt_debugfs.c
··· 24 24 #include "xe_uc_debugfs.h" 25 25 #include "xe_wa.h" 26 26 27 + /** 28 + * xe_gt_debugfs_simple_show - A show callback for struct drm_info_list 29 + * @m: the &seq_file 30 + * @data: data used by the drm debugfs helpers 31 + * 32 + * This callback can be used in struct drm_info_list to describe debugfs 33 + * files that are &xe_gt specific. 34 + * 35 + * It is assumed that those debugfs files will be created on directory entry 36 + * which struct dentry d_inode->i_private points to &xe_gt. 37 + * 38 + * This function assumes that &m->private will be set to the &struct 39 + * drm_info_node corresponding to the instance of the info on a given &struct 40 + * drm_minor (see struct drm_info_list.show for details). 41 + * 42 + * This function also assumes that struct drm_info_list.data will point to the 43 + * function code that will actually print a file content:: 44 + * 45 + * int (*print)(struct xe_gt *, struct drm_printer *) 46 + * 47 + * Example:: 48 + * 49 + * int foo(struct xe_gt *gt, struct drm_printer *p) 50 + * { 51 + * drm_printf(p, "GT%u\n", gt->info.id); 52 + * return 0; 53 + * } 54 + * 55 + * static const struct drm_info_list bar[] = { 56 + * { name = "foo", .show = xe_gt_debugfs_simple_show, .data = foo }, 57 + * }; 58 + * 59 + * dir = debugfs_create_dir("gt", parent); 60 + * dir->d_inode->i_private = gt; 61 + * drm_debugfs_create_files(bar, ARRAY_SIZE(bar), dir, minor); 62 + * 63 + * Return: 0 on success or a negative error code on failure. 64 + */ 65 + int xe_gt_debugfs_simple_show(struct seq_file *m, void *data) 66 + { 67 + struct drm_printer p = drm_seq_file_printer(m); 68 + struct drm_info_node *node = m->private; 69 + struct dentry *parent = node->dent->d_parent; 70 + struct xe_gt *gt = parent->d_inode->i_private; 71 + int (*print)(struct xe_gt *, struct drm_printer *) = node->info_ent->data; 72 + 73 + if (WARN_ON(!print)) 74 + return -EINVAL; 75 + 76 + return print(gt, &p); 77 + } 78 + 27 79 static struct xe_gt *node_to_gt(struct drm_info_node *node) 28 80 { 29 81 return node->info_ent->data;
+2
drivers/gpu/drm/xe/xe_gt_debugfs.h
··· 6 6 #ifndef _XE_GT_DEBUGFS_H_ 7 7 #define _XE_GT_DEBUGFS_H_ 8 8 9 + struct seq_file; 9 10 struct xe_gt; 10 11 11 12 void xe_gt_debugfs_register(struct xe_gt *gt); 13 + int xe_gt_debugfs_simple_show(struct seq_file *m, void *data); 12 14 13 15 #endif