xref: /openbmc/linux/drivers/misc/cxl/debugfs.c (revision 0898782247ae533d1f4e47a06bc5d4870931b284)
12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2f204e0b8SIan Munsie /*
3f204e0b8SIan Munsie  * Copyright 2014 IBM Corp.
4f204e0b8SIan Munsie  */
5f204e0b8SIan Munsie 
6f204e0b8SIan Munsie #include <linux/debugfs.h>
7f204e0b8SIan Munsie #include <linux/kernel.h>
8f204e0b8SIan Munsie #include <linux/slab.h>
9f204e0b8SIan Munsie 
10f204e0b8SIan Munsie #include "cxl.h"
11f204e0b8SIan Munsie 
12f204e0b8SIan Munsie static struct dentry *cxl_debugfs;
13f204e0b8SIan Munsie 
14f204e0b8SIan Munsie /* Helpers to export CXL mmaped IO registers via debugfs */
debugfs_io_u64_get(void * data,u64 * val)15f204e0b8SIan Munsie static int debugfs_io_u64_get(void *data, u64 *val)
16f204e0b8SIan Munsie {
17f204e0b8SIan Munsie 	*val = in_be64((u64 __iomem *)data);
18f204e0b8SIan Munsie 	return 0;
19f204e0b8SIan Munsie }
20f204e0b8SIan Munsie 
debugfs_io_u64_set(void * data,u64 val)21f204e0b8SIan Munsie static int debugfs_io_u64_set(void *data, u64 val)
22f204e0b8SIan Munsie {
23f204e0b8SIan Munsie 	out_be64((u64 __iomem *)data, val);
24f204e0b8SIan Munsie 	return 0;
25f204e0b8SIan Munsie }
263382a622SAndrew Donnellan DEFINE_DEBUGFS_ATTRIBUTE(fops_io_x64, debugfs_io_u64_get, debugfs_io_u64_set,
273382a622SAndrew Donnellan 			 "0x%016llx\n");
28f204e0b8SIan Munsie 
debugfs_create_io_x64(const char * name,umode_t mode,struct dentry * parent,u64 __iomem * value)29*4a14abc4SGreg Kroah-Hartman static void debugfs_create_io_x64(const char *name, umode_t mode,
30f204e0b8SIan Munsie 				  struct dentry *parent, u64 __iomem *value)
31f204e0b8SIan Munsie {
32*4a14abc4SGreg Kroah-Hartman 	debugfs_create_file_unsafe(name, mode, parent, (void __force *)value,
33*4a14abc4SGreg Kroah-Hartman 				   &fops_io_x64);
34f204e0b8SIan Munsie }
35f204e0b8SIan Munsie 
cxl_debugfs_add_adapter_regs_psl9(struct cxl * adapter,struct dentry * dir)36f24be42aSChristophe Lombard void cxl_debugfs_add_adapter_regs_psl9(struct cxl *adapter, struct dentry *dir)
37f24be42aSChristophe Lombard {
38f24be42aSChristophe Lombard 	debugfs_create_io_x64("fir1", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL9_FIR1));
398f6a9042SVaibhav Jain 	debugfs_create_io_x64("fir_mask", 0400, dir,
408f6a9042SVaibhav Jain 			      _cxl_p1_addr(adapter, CXL_PSL9_FIR_MASK));
41f24be42aSChristophe Lombard 	debugfs_create_io_x64("fir_cntl", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL9_FIR_CNTL));
42f24be42aSChristophe Lombard 	debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1_addr(adapter, CXL_PSL9_TRACECFG));
431cafc629SVaibhav Jain 	debugfs_create_io_x64("debug", 0600, dir,
441cafc629SVaibhav Jain 			      _cxl_p1_addr(adapter, CXL_PSL9_DEBUG));
451cafc629SVaibhav Jain 	debugfs_create_io_x64("xsl-debug", 0600, dir,
461cafc629SVaibhav Jain 			      _cxl_p1_addr(adapter, CXL_XSL9_DBG));
47f24be42aSChristophe Lombard }
48f24be42aSChristophe Lombard 
cxl_debugfs_add_adapter_regs_psl8(struct cxl * adapter,struct dentry * dir)4964663f37SChristophe Lombard void cxl_debugfs_add_adapter_regs_psl8(struct cxl *adapter, struct dentry *dir)
506d382616SFrederic Barrat {
516d382616SFrederic Barrat 	debugfs_create_io_x64("fir1", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_FIR1));
526d382616SFrederic Barrat 	debugfs_create_io_x64("fir2", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_FIR2));
536d382616SFrederic Barrat 	debugfs_create_io_x64("fir_cntl", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_FIR_CNTL));
546d382616SFrederic Barrat 	debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_TRACE));
556d382616SFrederic Barrat }
566d382616SFrederic Barrat 
cxl_debugfs_adapter_add(struct cxl * adapter)57*4a14abc4SGreg Kroah-Hartman void cxl_debugfs_adapter_add(struct cxl *adapter)
58f204e0b8SIan Munsie {
59f204e0b8SIan Munsie 	struct dentry *dir;
60f204e0b8SIan Munsie 	char buf[32];
61f204e0b8SIan Munsie 
62f204e0b8SIan Munsie 	if (!cxl_debugfs)
63*4a14abc4SGreg Kroah-Hartman 		return;
64f204e0b8SIan Munsie 
65f204e0b8SIan Munsie 	snprintf(buf, 32, "card%i", adapter->adapter_num);
66f204e0b8SIan Munsie 	dir = debugfs_create_dir(buf, cxl_debugfs);
67f204e0b8SIan Munsie 	adapter->debugfs = dir;
68f204e0b8SIan Munsie 
69f204e0b8SIan Munsie 	debugfs_create_io_x64("err_ivte", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_ErrIVTE));
70f204e0b8SIan Munsie 
71bdd2e715SChristophe Lombard 	if (adapter->native->sl_ops->debugfs_add_adapter_regs)
72bdd2e715SChristophe Lombard 		adapter->native->sl_ops->debugfs_add_adapter_regs(adapter, dir);
73f204e0b8SIan Munsie }
74f204e0b8SIan Munsie 
cxl_debugfs_adapter_remove(struct cxl * adapter)75f204e0b8SIan Munsie void cxl_debugfs_adapter_remove(struct cxl *adapter)
76f204e0b8SIan Munsie {
77f204e0b8SIan Munsie 	debugfs_remove_recursive(adapter->debugfs);
78f204e0b8SIan Munsie }
79f204e0b8SIan Munsie 
cxl_debugfs_add_afu_regs_psl9(struct cxl_afu * afu,struct dentry * dir)80f24be42aSChristophe Lombard void cxl_debugfs_add_afu_regs_psl9(struct cxl_afu *afu, struct dentry *dir)
81f24be42aSChristophe Lombard {
82f24be42aSChristophe Lombard 	debugfs_create_io_x64("serr", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SERR_An));
83f24be42aSChristophe Lombard }
84f24be42aSChristophe Lombard 
cxl_debugfs_add_afu_regs_psl8(struct cxl_afu * afu,struct dentry * dir)8564663f37SChristophe Lombard void cxl_debugfs_add_afu_regs_psl8(struct cxl_afu *afu, struct dentry *dir)
866d382616SFrederic Barrat {
87abd1d99bSChristophe Lombard 	debugfs_create_io_x64("sstp0", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_SSTP0_An));
88abd1d99bSChristophe Lombard 	debugfs_create_io_x64("sstp1", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_SSTP1_An));
89abd1d99bSChristophe Lombard 
906d382616SFrederic Barrat 	debugfs_create_io_x64("fir", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_FIR_SLICE_An));
916d382616SFrederic Barrat 	debugfs_create_io_x64("serr", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SERR_An));
926d382616SFrederic Barrat 	debugfs_create_io_x64("afu_debug", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_AFU_DEBUG_An));
936d382616SFrederic Barrat 	debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SLICE_TRACE));
946d382616SFrederic Barrat }
956d382616SFrederic Barrat 
cxl_debugfs_afu_add(struct cxl_afu * afu)96*4a14abc4SGreg Kroah-Hartman void cxl_debugfs_afu_add(struct cxl_afu *afu)
97f204e0b8SIan Munsie {
98f204e0b8SIan Munsie 	struct dentry *dir;
99f204e0b8SIan Munsie 	char buf[32];
100f204e0b8SIan Munsie 
101f204e0b8SIan Munsie 	if (!afu->adapter->debugfs)
102*4a14abc4SGreg Kroah-Hartman 		return;
103f204e0b8SIan Munsie 
104f204e0b8SIan Munsie 	snprintf(buf, 32, "psl%i.%i", afu->adapter->adapter_num, afu->slice);
105f204e0b8SIan Munsie 	dir = debugfs_create_dir(buf, afu->adapter->debugfs);
106f204e0b8SIan Munsie 	afu->debugfs = dir;
107f204e0b8SIan Munsie 
108f204e0b8SIan Munsie 	debugfs_create_io_x64("sr",         S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SR_An));
109f204e0b8SIan Munsie 	debugfs_create_io_x64("dsisr",      S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_DSISR_An));
110f204e0b8SIan Munsie 	debugfs_create_io_x64("dar",        S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_DAR_An));
111abd1d99bSChristophe Lombard 
112f204e0b8SIan Munsie 	debugfs_create_io_x64("err_status", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_ErrStat_An));
113f204e0b8SIan Munsie 
114bdd2e715SChristophe Lombard 	if (afu->adapter->native->sl_ops->debugfs_add_afu_regs)
115bdd2e715SChristophe Lombard 		afu->adapter->native->sl_ops->debugfs_add_afu_regs(afu, dir);
116f204e0b8SIan Munsie }
117f204e0b8SIan Munsie 
cxl_debugfs_afu_remove(struct cxl_afu * afu)118f204e0b8SIan Munsie void cxl_debugfs_afu_remove(struct cxl_afu *afu)
119f204e0b8SIan Munsie {
120f204e0b8SIan Munsie 	debugfs_remove_recursive(afu->debugfs);
121f204e0b8SIan Munsie }
122f204e0b8SIan Munsie 
cxl_debugfs_init(void)123*4a14abc4SGreg Kroah-Hartman void __init cxl_debugfs_init(void)
124f204e0b8SIan Munsie {
125ea2d1f95SFrederic Barrat 	if (!cpu_has_feature(CPU_FTR_HVMODE))
126*4a14abc4SGreg Kroah-Hartman 		return;
127ea2d1f95SFrederic Barrat 
128*4a14abc4SGreg Kroah-Hartman 	cxl_debugfs = debugfs_create_dir("cxl", NULL);
129f204e0b8SIan Munsie }
130f204e0b8SIan Munsie 
cxl_debugfs_exit(void)131f204e0b8SIan Munsie void cxl_debugfs_exit(void)
132f204e0b8SIan Munsie {
133f204e0b8SIan Munsie 	debugfs_remove_recursive(cxl_debugfs);
134f204e0b8SIan Munsie }
135