| 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 | |
| 13 | #include "i915_drv.h" |
| 14 | |
| 15 | #include "intel_pxp.h" |
| 16 | #include "intel_pxp_debugfs.h" |
| 17 | #include "intel_pxp_gsccs.h" |
| 18 | #include "intel_pxp_irq.h" |
| 19 | #include "intel_pxp_types.h" |
| 20 | |
| 21 | static int pxp_info_show(struct seq_file *m, void *data) |
| 22 | { |
| 23 | struct intel_pxp *pxp = m->private; |
| 24 | struct drm_printer p = drm_seq_file_printer(f: m); |
| 25 | |
| 26 | if (!intel_pxp_is_enabled(pxp)) { |
| 27 | drm_printf(p: &p, f: "pxp disabled\n" ); |
| 28 | return 0; |
| 29 | } |
| 30 | |
| 31 | drm_printf(p: &p, f: "active: %s\n" , str_yes_no(v: intel_pxp_is_active(pxp))); |
| 32 | drm_printf(p: &p, f: "instance counter: %u\n" , pxp->key_instance); |
| 33 | |
| 34 | return 0; |
| 35 | } |
| 36 | |
| 37 | DEFINE_SHOW_ATTRIBUTE(pxp_info); |
| 38 | |
| 39 | static int pxp_terminate_get(void *data, u64 *val) |
| 40 | { |
| 41 | /* nothing to read */ |
| 42 | return -EPERM; |
| 43 | } |
| 44 | |
| 45 | static int pxp_terminate_set(void *data, u64 val) |
| 46 | { |
| 47 | struct intel_pxp *pxp = data; |
| 48 | struct intel_gt *gt = pxp->ctrl_gt; |
| 49 | int timeout_ms; |
| 50 | |
| 51 | if (!intel_pxp_is_active(pxp)) |
| 52 | return -ENODEV; |
| 53 | |
| 54 | /* simulate a termination interrupt */ |
| 55 | spin_lock_irq(lock: gt->irq_lock); |
| 56 | intel_pxp_irq_handler(pxp, GEN12_DISPLAY_PXP_STATE_TERMINATED_INTERRUPT); |
| 57 | spin_unlock_irq(lock: gt->irq_lock); |
| 58 | |
| 59 | timeout_ms = intel_pxp_get_backend_timeout_ms(pxp); |
| 60 | |
| 61 | if (!wait_for_completion_timeout(x: &pxp->termination, |
| 62 | timeout: msecs_to_jiffies(m: timeout_ms))) |
| 63 | return -ETIMEDOUT; |
| 64 | |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | DEFINE_SIMPLE_ATTRIBUTE(pxp_terminate_fops, pxp_terminate_get, pxp_terminate_set, "%llx\n" ); |
| 69 | |
| 70 | void intel_pxp_debugfs_register(struct intel_pxp *pxp) |
| 71 | { |
| 72 | struct dentry *debugfs_root; |
| 73 | struct dentry *pxproot; |
| 74 | |
| 75 | if (!intel_pxp_is_supported(pxp)) |
| 76 | return; |
| 77 | |
| 78 | debugfs_root = pxp->ctrl_gt->i915->drm.debugfs_root; |
| 79 | if (!debugfs_root) |
| 80 | return; |
| 81 | |
| 82 | pxproot = debugfs_create_dir(name: "pxp" , parent: debugfs_root); |
| 83 | if (IS_ERR(ptr: pxproot)) |
| 84 | return; |
| 85 | |
| 86 | debugfs_create_file("info" , 0444, pxproot, |
| 87 | pxp, &pxp_info_fops); |
| 88 | |
| 89 | debugfs_create_file("terminate_state" , 0644, pxproot, |
| 90 | pxp, &pxp_terminate_fops); |
| 91 | } |
| 92 | |