Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/xe/pxp: Add PXP debugfs support

This patch introduces 2 PXP debugfs entries:

- info: prints the current PXP status and key instance
- terminate: simulate a termination interrupt

The first one is useful for debug, while the second one can be used for
testing the termination flow.

v2: move the info prints inside the lock (John)

Signed-off-by: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com>
Cc: John Harrison <John.C.Harrison@Intel.com>
Reviewed-by: John Harrison <John.C.Harrison@Intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20250129174140.948829-13-daniele.ceraolospurio@intel.com

+137
+1
drivers/gpu/drm/xe/Makefile
··· 88 88 xe_pt.o \ 89 89 xe_pt_walk.o \ 90 90 xe_pxp.o \ 91 + xe_pxp_debugfs.o \ 91 92 xe_pxp_submit.o \ 92 93 xe_query.o \ 93 94 xe_range_fence.o \
+3
drivers/gpu/drm/xe/xe_debugfs.c
··· 18 18 #include "xe_gt_printk.h" 19 19 #include "xe_guc_ads.h" 20 20 #include "xe_pm.h" 21 + #include "xe_pxp_debugfs.h" 21 22 #include "xe_sriov.h" 22 23 #include "xe_step.h" 23 24 ··· 230 229 231 230 for_each_gt(gt, xe, id) 232 231 xe_gt_debugfs_register(gt); 232 + 233 + xe_pxp_debugfs_register(xe->pxp); 233 234 234 235 fault_create_debugfs_attr("fail_gt_reset", root, &gt_reset_failure); 235 236 }
+120
drivers/gpu/drm/xe/xe_pxp_debugfs.c
··· 1 + // SPDX-License-Identifier: MIT 2 + /* 3 + * Copyright © 2024 Intel Corporation 4 + */ 5 + 6 + #include "xe_pxp_debugfs.h" 7 + 8 + #include <linux/debugfs.h> 9 + 10 + #include <drm/drm_debugfs.h> 11 + #include <drm/drm_managed.h> 12 + #include <drm/drm_print.h> 13 + 14 + #include "xe_device.h" 15 + #include "xe_pxp.h" 16 + #include "xe_pxp_types.h" 17 + #include "regs/xe_irq_regs.h" 18 + 19 + static struct xe_pxp *node_to_pxp(struct drm_info_node *node) 20 + { 21 + return node->info_ent->data; 22 + } 23 + 24 + static const char *pxp_status_to_str(struct xe_pxp *pxp) 25 + { 26 + lockdep_assert_held(&pxp->mutex); 27 + 28 + switch (pxp->status) { 29 + case XE_PXP_ERROR: 30 + return "error"; 31 + case XE_PXP_NEEDS_TERMINATION: 32 + return "needs termination"; 33 + case XE_PXP_TERMINATION_IN_PROGRESS: 34 + return "termination in progress"; 35 + case XE_PXP_READY_TO_START: 36 + return "ready to start"; 37 + case XE_PXP_ACTIVE: 38 + return "active"; 39 + case XE_PXP_SUSPENDED: 40 + return "suspended"; 41 + default: 42 + return "unknown"; 43 + } 44 + }; 45 + 46 + static int pxp_info(struct seq_file *m, void *data) 47 + { 48 + struct xe_pxp *pxp = node_to_pxp(m->private); 49 + struct drm_printer p = drm_seq_file_printer(m); 50 + const char *status; 51 + 52 + if (!xe_pxp_is_enabled(pxp)) 53 + return -ENODEV; 54 + 55 + mutex_lock(&pxp->mutex); 56 + status = pxp_status_to_str(pxp); 57 + 58 + drm_printf(&p, "status: %s\n", status); 59 + drm_printf(&p, "instance counter: %u\n", pxp->key_instance); 60 + mutex_unlock(&pxp->mutex); 61 + 62 + return 0; 63 + } 64 + 65 + static int pxp_terminate(struct seq_file *m, void *data) 66 + { 67 + struct xe_pxp *pxp = node_to_pxp(m->private); 68 + struct drm_printer p = drm_seq_file_printer(m); 69 + 70 + if (!xe_pxp_is_enabled(pxp)) 71 + return -ENODEV; 72 + 73 + /* simulate a termination interrupt */ 74 + spin_lock_irq(&pxp->xe->irq.lock); 75 + xe_pxp_irq_handler(pxp->xe, KCR_PXP_STATE_TERMINATED_INTERRUPT); 76 + spin_unlock_irq(&pxp->xe->irq.lock); 77 + 78 + drm_printf(&p, "PXP termination queued\n"); 79 + 80 + return 0; 81 + } 82 + 83 + static const struct drm_info_list debugfs_list[] = { 84 + {"info", pxp_info, 0}, 85 + {"terminate", pxp_terminate, 0}, 86 + }; 87 + 88 + void xe_pxp_debugfs_register(struct xe_pxp *pxp) 89 + { 90 + struct drm_minor *minor; 91 + struct drm_info_list *local; 92 + struct dentry *root; 93 + int i; 94 + 95 + if (!xe_pxp_is_enabled(pxp)) 96 + return; 97 + 98 + minor = pxp->xe->drm.primary; 99 + if (!minor->debugfs_root) 100 + return; 101 + 102 + #define DEBUGFS_SIZE (ARRAY_SIZE(debugfs_list) * sizeof(struct drm_info_list)) 103 + local = drmm_kmalloc(&pxp->xe->drm, DEBUGFS_SIZE, GFP_KERNEL); 104 + if (!local) 105 + return; 106 + 107 + memcpy(local, debugfs_list, DEBUGFS_SIZE); 108 + #undef DEBUGFS_SIZE 109 + 110 + for (i = 0; i < ARRAY_SIZE(debugfs_list); ++i) 111 + local[i].data = pxp; 112 + 113 + root = debugfs_create_dir("pxp", minor->debugfs_root); 114 + if (IS_ERR(root)) 115 + return; 116 + 117 + drm_debugfs_create_files(local, 118 + ARRAY_SIZE(debugfs_list), 119 + root, minor); 120 + }
+13
drivers/gpu/drm/xe/xe_pxp_debugfs.h
··· 1 + /* SPDX-License-Identifier: MIT */ 2 + /* 3 + * Copyright © 2024 Intel Corporation 4 + */ 5 + 6 + #ifndef __XE_PXP_DEBUGFS_H__ 7 + #define __XE_PXP_DEBUGFS_H__ 8 + 9 + struct xe_pxp; 10 + 11 + void xe_pxp_debugfs_register(struct xe_pxp *pxp); 12 + 13 + #endif /* __XE_PXP_DEBUGFS_H__ */