1 // SPDX-License-Identifier: MIT 2 /* 3 * Copyright © 2025 Intel Corporation 4 */ 5 6 #include <linux/debugfs.h> 7 #include <drm/drm_debugfs.h> 8 9 #include "xe_pm.h" 10 #include "xe_sa.h" 11 #include "xe_tile_debugfs.h" 12 13 static struct xe_tile *node_to_tile(struct drm_info_node *node) 14 { 15 return node->dent->d_parent->d_inode->i_private; 16 } 17 18 /** 19 * tile_debugfs_simple_show - A show callback for struct drm_info_list 20 * @m: the &seq_file 21 * @data: data used by the drm debugfs helpers 22 * 23 * This callback can be used in struct drm_info_list to describe debugfs 24 * files that are &xe_tile specific. 25 * 26 * It is assumed that those debugfs files will be created on directory entry 27 * which struct dentry d_inode->i_private points to &xe_tile. 28 * 29 * /sys/kernel/debug/dri/0/ 30 * ├── tile0/ # tile = dentry->d_inode->i_private 31 * │ │ ├── id # tile = dentry->d_parent->d_inode->i_private 32 * 33 * This function assumes that &m->private will be set to the &struct 34 * drm_info_node corresponding to the instance of the info on a given &struct 35 * drm_minor (see struct drm_info_list.show for details). 36 * 37 * This function also assumes that struct drm_info_list.data will point to the 38 * function code that will actually print a file content:: 39 * 40 * int (*print)(struct xe_tile *, struct drm_printer *) 41 * 42 * Example:: 43 * 44 * int tile_id(struct xe_tile *tile, struct drm_printer *p) 45 * { 46 * drm_printf(p, "%u\n", tile->id); 47 * return 0; 48 * } 49 * 50 * static const struct drm_info_list info[] = { 51 * { name = "id", .show = tile_debugfs_simple_show, .data = tile_id }, 52 * }; 53 * 54 * dir = debugfs_create_dir("tile0", parent); 55 * dir->d_inode->i_private = tile; 56 * drm_debugfs_create_files(info, ARRAY_SIZE(info), dir, minor); 57 * 58 * Return: 0 on success or a negative error code on failure. 59 */ 60 static int tile_debugfs_simple_show(struct seq_file *m, void *data) 61 { 62 struct drm_printer p = drm_seq_file_printer(m); 63 struct drm_info_node *node = m->private; 64 struct xe_tile *tile = node_to_tile(node); 65 int (*print)(struct xe_tile *, struct drm_printer *) = node->info_ent->data; 66 67 return print(tile, &p); 68 } 69 70 /** 71 * tile_debugfs_show_with_rpm - A show callback for struct drm_info_list 72 * @m: the &seq_file 73 * @data: data used by the drm debugfs helpers 74 * 75 * Similar to tile_debugfs_simple_show() but implicitly takes a RPM ref. 76 * 77 * Return: 0 on success or a negative error code on failure. 78 */ 79 static int tile_debugfs_show_with_rpm(struct seq_file *m, void *data) 80 { 81 struct drm_info_node *node = m->private; 82 struct xe_tile *tile = node_to_tile(node); 83 struct xe_device *xe = tile_to_xe(tile); 84 int ret; 85 86 xe_pm_runtime_get(xe); 87 ret = tile_debugfs_simple_show(m, data); 88 xe_pm_runtime_put(xe); 89 90 return ret; 91 } 92 93 static int sa_info(struct xe_tile *tile, struct drm_printer *p) 94 { 95 drm_suballoc_dump_debug_info(&tile->mem.kernel_bb_pool->base, p, 96 xe_sa_manager_gpu_addr(tile->mem.kernel_bb_pool)); 97 98 return 0; 99 } 100 101 /* only for debugfs files which can be safely used on the VF */ 102 static const struct drm_info_list vf_safe_debugfs_list[] = { 103 { "sa_info", .show = tile_debugfs_show_with_rpm, .data = sa_info }, 104 }; 105 106 /** 107 * xe_tile_debugfs_register - Register tile's debugfs attributes 108 * @tile: the &xe_tile to register 109 * 110 * Create debugfs sub-directory with a name that includes a tile ID and 111 * then creates set of debugfs files (attributes) specific to this tile. 112 */ 113 void xe_tile_debugfs_register(struct xe_tile *tile) 114 { 115 struct xe_device *xe = tile_to_xe(tile); 116 struct drm_minor *minor = xe->drm.primary; 117 struct dentry *root = minor->debugfs_root; 118 char name[8]; 119 120 snprintf(name, sizeof(name), "tile%u", tile->id); 121 tile->debugfs = debugfs_create_dir(name, root); 122 if (IS_ERR(tile->debugfs)) 123 return; 124 125 /* 126 * Store the xe_tile pointer as private data of the tile/ directory 127 * node so other tile specific attributes under that directory may 128 * refer to it by looking at its parent node private data. 129 */ 130 tile->debugfs->d_inode->i_private = tile; 131 132 drm_debugfs_create_files(vf_safe_debugfs_list, 133 ARRAY_SIZE(vf_safe_debugfs_list), 134 tile->debugfs, minor); 135 } 136