Skip to content

Commit 385a801

Browse files
committed
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 <[email protected]> Cc: John Harrison <[email protected]> Reviewed-by: John Harrison <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 5146221 commit 385a801

File tree

4 files changed

+137
-0
lines changed

4 files changed

+137
-0
lines changed

drivers/gpu/drm/xe/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ xe-y += xe_bb.o \
8888
xe_pt.o \
8989
xe_pt_walk.o \
9090
xe_pxp.o \
91+
xe_pxp_debugfs.o \
9192
xe_pxp_submit.o \
9293
xe_query.o \
9394
xe_range_fence.o \

drivers/gpu/drm/xe/xe_debugfs.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "xe_gt_printk.h"
1919
#include "xe_guc_ads.h"
2020
#include "xe_pm.h"
21+
#include "xe_pxp_debugfs.h"
2122
#include "xe_sriov.h"
2223
#include "xe_step.h"
2324

@@ -230,5 +231,7 @@ void xe_debugfs_register(struct xe_device *xe)
230231
for_each_gt(gt, xe, id)
231232
xe_gt_debugfs_register(gt);
232233

234+
xe_pxp_debugfs_register(xe->pxp);
235+
233236
fault_create_debugfs_attr("fail_gt_reset", root, &gt_reset_failure);
234237
}

drivers/gpu/drm/xe/xe_pxp_debugfs.c

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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+
}

drivers/gpu/drm/xe/xe_pxp_debugfs.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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__ */

0 commit comments

Comments
 (0)