1 // SPDX-License-Identifier: MIT 2 /* 3 * Copyright © 2019 Intel Corporation 4 */ 5 6 #include <linux/debugfs.h> 7 8 #include "i915_drv.h" 9 #include "intel_gt_debugfs.h" 10 #include "intel_gt_engines_debugfs.h" 11 #include "intel_gt_pm_debugfs.h" 12 #include "intel_sseu_debugfs.h" 13 #include "pxp/intel_pxp_debugfs.h" 14 #include "uc/intel_uc_debugfs.h" 15 16 int intel_gt_debugfs_reset_show(struct intel_gt *gt, u64 *val) 17 { 18 int ret = intel_gt_terminally_wedged(gt); 19 20 switch (ret) { 21 case -EIO: 22 *val = 1; 23 return 0; 24 case 0: 25 *val = 0; 26 return 0; 27 default: 28 return ret; 29 } 30 } 31 32 int intel_gt_debugfs_reset_store(struct intel_gt *gt, u64 val) 33 { 34 /* Flush any previous reset before applying for a new one */ 35 wait_event(gt->reset.queue, 36 !test_bit(I915_RESET_BACKOFF, >->reset.flags)); 37 38 intel_gt_handle_error(gt, val, I915_ERROR_CAPTURE, 39 "Manually reset engine mask to %llx", val); 40 return 0; 41 } 42 43 /* 44 * keep the interface clean where the first parameter 45 * is a 'struct intel_gt *' instead of 'void *' 46 */ 47 static int __intel_gt_debugfs_reset_show(void *data, u64 *val) 48 { 49 return intel_gt_debugfs_reset_show(data, val); 50 } 51 52 static int __intel_gt_debugfs_reset_store(void *data, u64 val) 53 { 54 return intel_gt_debugfs_reset_store(data, val); 55 } 56 57 DEFINE_SIMPLE_ATTRIBUTE(reset_fops, __intel_gt_debugfs_reset_show, 58 __intel_gt_debugfs_reset_store, "%llu\n"); 59 60 static void gt_debugfs_register(struct intel_gt *gt, struct dentry *root) 61 { 62 static const struct intel_gt_debugfs_file files[] = { 63 { "reset", &reset_fops, NULL }, 64 }; 65 66 intel_gt_debugfs_register_files(root, files, ARRAY_SIZE(files), gt); 67 } 68 69 void intel_gt_debugfs_register(struct intel_gt *gt) 70 { 71 struct dentry *root; 72 73 if (!gt->i915->drm.primary->debugfs_root) 74 return; 75 76 root = debugfs_create_dir("gt", gt->i915->drm.primary->debugfs_root); 77 if (IS_ERR(root)) 78 return; 79 80 gt_debugfs_register(gt, root); 81 82 intel_gt_engines_debugfs_register(gt, root); 83 intel_gt_pm_debugfs_register(gt, root); 84 intel_sseu_debugfs_register(gt, root); 85 86 intel_uc_debugfs_register(>->uc, root); 87 intel_pxp_debugfs_register(>->pxp, root); 88 } 89 90 void intel_gt_debugfs_register_files(struct dentry *root, 91 const struct intel_gt_debugfs_file *files, 92 unsigned long count, void *data) 93 { 94 while (count--) { 95 umode_t mode = files->fops->write ? 0644 : 0444; 96 97 if (!files->eval || files->eval(data)) 98 debugfs_create_file(files->name, 99 mode, root, data, 100 files->fops); 101 102 files++; 103 } 104 } 105