1 // SPDX-License-Identifier: MIT 2 /* 3 * Copyright © 2022 Intel Corporation 4 */ 5 6 #include <drm/drm_debugfs.h> 7 #include <drm/drm_managed.h> 8 9 #include "xe_device.h" 10 #include "xe_gt.h" 11 #include "xe_guc.h" 12 #include "xe_guc_ct.h" 13 #include "xe_guc_debugfs.h" 14 #include "xe_guc_log.h" 15 #include "xe_macros.h" 16 17 static struct xe_gt * 18 guc_to_gt(struct xe_guc *guc) 19 { 20 return container_of(guc, struct xe_gt, uc.guc); 21 } 22 23 static struct xe_device * 24 guc_to_xe(struct xe_guc *guc) 25 { 26 return gt_to_xe(guc_to_gt(guc)); 27 } 28 29 static struct xe_guc *node_to_guc(struct drm_info_node *node) 30 { 31 return node->info_ent->data; 32 } 33 34 static int guc_info(struct seq_file *m, void *data) 35 { 36 struct xe_guc *guc = node_to_guc(m->private); 37 struct xe_device *xe = guc_to_xe(guc); 38 struct drm_printer p = drm_seq_file_printer(m); 39 40 xe_device_mem_access_get(xe); 41 xe_guc_print_info(guc, &p); 42 xe_device_mem_access_put(xe); 43 44 return 0; 45 } 46 47 static int guc_log(struct seq_file *m, void *data) 48 { 49 struct xe_guc *guc = node_to_guc(m->private); 50 struct xe_device *xe = guc_to_xe(guc); 51 struct drm_printer p = drm_seq_file_printer(m); 52 53 xe_device_mem_access_get(xe); 54 xe_guc_log_print(&guc->log, &p); 55 xe_device_mem_access_put(xe); 56 57 return 0; 58 } 59 60 #ifdef XE_GUC_CT_SELFTEST 61 static int guc_ct_selftest(struct seq_file *m, void *data) 62 { 63 struct xe_guc *guc = node_to_guc(m->private); 64 struct xe_device *xe = guc_to_xe(guc); 65 struct drm_printer p = drm_seq_file_printer(m); 66 67 xe_device_mem_access_get(xe); 68 xe_guc_ct_selftest(&guc->ct, &p); 69 xe_device_mem_access_put(xe); 70 71 return 0; 72 } 73 #endif 74 75 static const struct drm_info_list debugfs_list[] = { 76 {"guc_info", guc_info, 0}, 77 {"guc_log", guc_log, 0}, 78 #ifdef XE_GUC_CT_SELFTEST 79 {"guc_ct_selftest", guc_ct_selftest, 0}, 80 #endif 81 }; 82 83 void xe_guc_debugfs_register(struct xe_guc *guc, struct dentry *parent) 84 { 85 struct drm_minor *minor = guc_to_xe(guc)->drm.primary; 86 struct drm_info_list *local; 87 int i; 88 89 #define DEBUGFS_SIZE ARRAY_SIZE(debugfs_list) * sizeof(struct drm_info_list) 90 local = drmm_kmalloc(&guc_to_xe(guc)->drm, DEBUGFS_SIZE, GFP_KERNEL); 91 if (!local) { 92 XE_WARN_ON("Couldn't allocate memory"); 93 return; 94 } 95 96 memcpy(local, debugfs_list, DEBUGFS_SIZE); 97 #undef DEBUGFS_SIZE 98 99 for (i = 0; i < ARRAY_SIZE(debugfs_list); ++i) 100 local[i].data = guc; 101 102 drm_debugfs_create_files(local, 103 ARRAY_SIZE(debugfs_list), 104 parent, minor); 105 } 106