1 // SPDX-License-Identifier: MIT 2 /* 3 * Copyright © 2021 Intel Corporation 4 */ 5 6 #include <linux/debugfs.h> 7 #include <linux/string_helpers.h> 8 9 #include <drm/drm_print.h> 10 11 #include "gt/intel_gt_debugfs.h" 12 #include "i915_drv.h" 13 #include "intel_pxp.h" 14 #include "intel_pxp_debugfs.h" 15 #include "intel_pxp_irq.h" 16 17 static int pxp_info_show(struct seq_file *m, void *data) 18 { 19 struct intel_pxp *pxp = m->private; 20 struct drm_printer p = drm_seq_file_printer(m); 21 bool enabled = intel_pxp_is_enabled(pxp); 22 23 if (!enabled) { 24 drm_printf(&p, "pxp disabled\n"); 25 return 0; 26 } 27 28 drm_printf(&p, "active: %s\n", str_yes_no(intel_pxp_is_active(pxp))); 29 drm_printf(&p, "instance counter: %u\n", pxp->key_instance); 30 31 return 0; 32 } 33 DEFINE_INTEL_GT_DEBUGFS_ATTRIBUTE(pxp_info); 34 35 static int pxp_terminate_get(void *data, u64 *val) 36 { 37 /* nothing to read */ 38 return -EPERM; 39 } 40 41 static int pxp_terminate_set(void *data, u64 val) 42 { 43 struct intel_pxp *pxp = data; 44 struct intel_gt *gt = pxp_to_gt(pxp); 45 46 if (!intel_pxp_is_active(pxp)) 47 return -ENODEV; 48 49 /* simulate a termination interrupt */ 50 spin_lock_irq(gt->irq_lock); 51 intel_pxp_irq_handler(pxp, GEN12_DISPLAY_PXP_STATE_TERMINATED_INTERRUPT); 52 spin_unlock_irq(gt->irq_lock); 53 54 if (!wait_for_completion_timeout(&pxp->termination, 55 msecs_to_jiffies(100))) 56 return -ETIMEDOUT; 57 58 return 0; 59 } 60 61 DEFINE_SIMPLE_ATTRIBUTE(pxp_terminate_fops, pxp_terminate_get, pxp_terminate_set, "%llx\n"); 62 void intel_pxp_debugfs_register(struct intel_pxp *pxp, struct dentry *gt_root) 63 { 64 static const struct intel_gt_debugfs_file files[] = { 65 { "info", &pxp_info_fops, NULL }, 66 { "terminate_state", &pxp_terminate_fops, NULL }, 67 }; 68 struct dentry *root; 69 70 if (!gt_root) 71 return; 72 73 if (!HAS_PXP((pxp_to_gt(pxp)->i915))) 74 return; 75 76 root = debugfs_create_dir("pxp", gt_root); 77 if (IS_ERR(root)) 78 return; 79 80 intel_gt_debugfs_register_files(root, files, ARRAY_SIZE(files), pxp); 81 } 82