|
17 | 17 | #include "xe_macros.h" |
18 | 18 | #include "xe_pm.h" |
19 | 19 |
|
20 | | -static struct xe_guc *node_to_guc(struct drm_info_node *node) |
21 | | -{ |
22 | | - return node->info_ent->data; |
23 | | -} |
24 | | - |
25 | | -static int guc_info(struct seq_file *m, void *data) |
| 20 | +/* |
| 21 | + * guc_debugfs_show - A show callback for struct drm_info_list |
| 22 | + * @m: the &seq_file |
| 23 | + * @data: data used by the drm debugfs helpers |
| 24 | + * |
| 25 | + * This callback can be used in struct drm_info_list to describe debugfs |
| 26 | + * files that are &xe_guc specific in similar way how we handle &xe_gt |
| 27 | + * specific files using &xe_gt_debugfs_simple_show. |
| 28 | + * |
| 29 | + * It is assumed that those debugfs files will be created on directory entry |
| 30 | + * which grandparent struct dentry d_inode->i_private points to &xe_gt. |
| 31 | + * |
| 32 | + * /sys/kernel/debug/dri/0/ |
| 33 | + * ├── gt0 # dent->d_parent->d_parent (d_inode->i_private == gt) |
| 34 | + * │ ├── uc # dent->d_parent |
| 35 | + * │ │ ├── guc_info # dent |
| 36 | + * │ │ ├── guc_... |
| 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_guc *, struct drm_printer *) |
| 46 | + * |
| 47 | + * Example:: |
| 48 | + * |
| 49 | + * int foo(struct xe_guc *guc, struct drm_printer *p) |
| 50 | + * { |
| 51 | + * drm_printf(p, "enabled %d\n", guc->submission_state.enabled); |
| 52 | + * return 0; |
| 53 | + * } |
| 54 | + * |
| 55 | + * static const struct drm_info_list bar[] = { |
| 56 | + * { name = "foo", .show = guc_debugfs_show, .data = foo }, |
| 57 | + * }; |
| 58 | + * |
| 59 | + * parent = debugfs_create_dir("uc", gtdir); |
| 60 | + * drm_debugfs_create_files(bar, ARRAY_SIZE(bar), parent, minor); |
| 61 | + * |
| 62 | + * Return: 0 on success or a negative error code on failure. |
| 63 | + */ |
| 64 | +static int guc_debugfs_show(struct seq_file *m, void *data) |
26 | 65 | { |
27 | | - struct xe_guc *guc = node_to_guc(m->private); |
28 | | - struct xe_device *xe = guc_to_xe(guc); |
29 | 66 | struct drm_printer p = drm_seq_file_printer(m); |
| 67 | + struct drm_info_node *node = m->private; |
| 68 | + struct dentry *parent = node->dent->d_parent; |
| 69 | + struct dentry *grandparent = parent->d_parent; |
| 70 | + struct xe_gt *gt = grandparent->d_inode->i_private; |
| 71 | + struct xe_device *xe = gt_to_xe(gt); |
| 72 | + int (*print)(struct xe_guc *, struct drm_printer *) = node->info_ent->data; |
| 73 | + int ret; |
30 | 74 |
|
31 | 75 | xe_pm_runtime_get(xe); |
32 | | - xe_guc_print_info(guc, &p); |
| 76 | + ret = print(>->uc.guc, &p); |
33 | 77 | xe_pm_runtime_put(xe); |
34 | 78 |
|
35 | | - return 0; |
| 79 | + return ret; |
36 | 80 | } |
37 | 81 |
|
38 | | -static int guc_log(struct seq_file *m, void *data) |
| 82 | +static int guc_log(struct xe_guc *guc, struct drm_printer *p) |
39 | 83 | { |
40 | | - struct xe_guc *guc = node_to_guc(m->private); |
41 | | - struct xe_device *xe = guc_to_xe(guc); |
42 | | - struct drm_printer p = drm_seq_file_printer(m); |
43 | | - |
44 | | - xe_pm_runtime_get(xe); |
45 | | - xe_guc_log_print(&guc->log, &p); |
46 | | - xe_pm_runtime_put(xe); |
47 | | - |
| 84 | + xe_guc_log_print(&guc->log, p); |
48 | 85 | return 0; |
49 | 86 | } |
50 | 87 |
|
51 | | -static int guc_log_dmesg(struct seq_file *m, void *data) |
| 88 | +static int guc_log_dmesg(struct xe_guc *guc, struct drm_printer *p) |
52 | 89 | { |
53 | | - struct xe_guc *guc = node_to_guc(m->private); |
54 | | - struct xe_device *xe = guc_to_xe(guc); |
55 | | - |
56 | | - xe_pm_runtime_get(xe); |
57 | 90 | xe_guc_log_print_dmesg(&guc->log); |
58 | | - xe_pm_runtime_put(xe); |
59 | | - |
60 | 91 | return 0; |
61 | 92 | } |
62 | 93 |
|
63 | | -static int guc_ctb(struct seq_file *m, void *data) |
| 94 | +static int guc_ctb(struct xe_guc *guc, struct drm_printer *p) |
64 | 95 | { |
65 | | - struct xe_guc *guc = node_to_guc(m->private); |
66 | | - struct xe_device *xe = guc_to_xe(guc); |
67 | | - struct drm_printer p = drm_seq_file_printer(m); |
68 | | - |
69 | | - xe_pm_runtime_get(xe); |
70 | | - xe_guc_ct_print(&guc->ct, &p, true); |
71 | | - xe_pm_runtime_put(xe); |
72 | | - |
| 96 | + xe_guc_ct_print(&guc->ct, p, true); |
73 | 97 | return 0; |
74 | 98 | } |
75 | 99 |
|
76 | | -static int guc_pc(struct seq_file *m, void *data) |
| 100 | +static int guc_pc(struct xe_guc *guc, struct drm_printer *p) |
77 | 101 | { |
78 | | - struct xe_guc *guc = node_to_guc(m->private); |
79 | | - struct xe_device *xe = guc_to_xe(guc); |
80 | | - struct drm_printer p = drm_seq_file_printer(m); |
81 | | - |
82 | | - xe_pm_runtime_get(xe); |
83 | | - xe_guc_pc_print(&guc->pc, &p); |
84 | | - xe_pm_runtime_put(xe); |
85 | | - |
| 102 | + xe_guc_pc_print(&guc->pc, p); |
86 | 103 | return 0; |
87 | 104 | } |
88 | 105 |
|
89 | 106 | static const struct drm_info_list debugfs_list[] = { |
90 | | - {"guc_info", guc_info, 0}, |
91 | | - {"guc_log", guc_log, 0}, |
92 | | - {"guc_log_dmesg", guc_log_dmesg, 0}, |
93 | | - {"guc_ctb", guc_ctb, 0}, |
94 | | - {"guc_pc", guc_pc, 0}, |
| 107 | + { "guc_info", .show = guc_debugfs_show, .data = xe_guc_print_info }, |
| 108 | + { "guc_log", .show = guc_debugfs_show, .data = guc_log }, |
| 109 | + { "guc_log_dmesg", .show = guc_debugfs_show, .data = guc_log_dmesg }, |
| 110 | + { "guc_ctb", .show = guc_debugfs_show, .data = guc_ctb }, |
| 111 | + { "guc_pc", .show = guc_debugfs_show, .data = guc_pc }, |
95 | 112 | }; |
96 | 113 |
|
97 | 114 | void xe_guc_debugfs_register(struct xe_guc *guc, struct dentry *parent) |
98 | 115 | { |
99 | 116 | struct drm_minor *minor = guc_to_xe(guc)->drm.primary; |
100 | | - struct drm_info_list *local; |
101 | | - int i; |
102 | | - |
103 | | -#define DEBUGFS_SIZE (ARRAY_SIZE(debugfs_list) * sizeof(struct drm_info_list)) |
104 | | - local = drmm_kmalloc(&guc_to_xe(guc)->drm, DEBUGFS_SIZE, GFP_KERNEL); |
105 | | - if (!local) |
106 | | - return; |
107 | | - |
108 | | - memcpy(local, debugfs_list, DEBUGFS_SIZE); |
109 | | -#undef DEBUGFS_SIZE |
110 | | - |
111 | | - for (i = 0; i < ARRAY_SIZE(debugfs_list); ++i) |
112 | | - local[i].data = guc; |
113 | 117 |
|
114 | | - drm_debugfs_create_files(local, |
| 118 | + drm_debugfs_create_files(debugfs_list, |
115 | 119 | ARRAY_SIZE(debugfs_list), |
116 | 120 | parent, minor); |
117 | 121 | } |
0 commit comments