xref: /OK3568_Linux_fs/kernel/drivers/misc/cxl/debugfs.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-or-later
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright 2014 IBM Corp.
4*4882a593Smuzhiyun  */
5*4882a593Smuzhiyun 
6*4882a593Smuzhiyun #include <linux/debugfs.h>
7*4882a593Smuzhiyun #include <linux/kernel.h>
8*4882a593Smuzhiyun #include <linux/slab.h>
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun #include "cxl.h"
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun static struct dentry *cxl_debugfs;
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun /* Helpers to export CXL mmaped IO registers via debugfs */
debugfs_io_u64_get(void * data,u64 * val)15*4882a593Smuzhiyun static int debugfs_io_u64_get(void *data, u64 *val)
16*4882a593Smuzhiyun {
17*4882a593Smuzhiyun 	*val = in_be64((u64 __iomem *)data);
18*4882a593Smuzhiyun 	return 0;
19*4882a593Smuzhiyun }
20*4882a593Smuzhiyun 
debugfs_io_u64_set(void * data,u64 val)21*4882a593Smuzhiyun static int debugfs_io_u64_set(void *data, u64 val)
22*4882a593Smuzhiyun {
23*4882a593Smuzhiyun 	out_be64((u64 __iomem *)data, val);
24*4882a593Smuzhiyun 	return 0;
25*4882a593Smuzhiyun }
26*4882a593Smuzhiyun DEFINE_DEBUGFS_ATTRIBUTE(fops_io_x64, debugfs_io_u64_get, debugfs_io_u64_set,
27*4882a593Smuzhiyun 			 "0x%016llx\n");
28*4882a593Smuzhiyun 
debugfs_create_io_x64(const char * name,umode_t mode,struct dentry * parent,u64 __iomem * value)29*4882a593Smuzhiyun static void debugfs_create_io_x64(const char *name, umode_t mode,
30*4882a593Smuzhiyun 				  struct dentry *parent, u64 __iomem *value)
31*4882a593Smuzhiyun {
32*4882a593Smuzhiyun 	debugfs_create_file_unsafe(name, mode, parent, (void __force *)value,
33*4882a593Smuzhiyun 				   &fops_io_x64);
34*4882a593Smuzhiyun }
35*4882a593Smuzhiyun 
cxl_debugfs_add_adapter_regs_psl9(struct cxl * adapter,struct dentry * dir)36*4882a593Smuzhiyun void cxl_debugfs_add_adapter_regs_psl9(struct cxl *adapter, struct dentry *dir)
37*4882a593Smuzhiyun {
38*4882a593Smuzhiyun 	debugfs_create_io_x64("fir1", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL9_FIR1));
39*4882a593Smuzhiyun 	debugfs_create_io_x64("fir_mask", 0400, dir,
40*4882a593Smuzhiyun 			      _cxl_p1_addr(adapter, CXL_PSL9_FIR_MASK));
41*4882a593Smuzhiyun 	debugfs_create_io_x64("fir_cntl", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL9_FIR_CNTL));
42*4882a593Smuzhiyun 	debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1_addr(adapter, CXL_PSL9_TRACECFG));
43*4882a593Smuzhiyun 	debugfs_create_io_x64("debug", 0600, dir,
44*4882a593Smuzhiyun 			      _cxl_p1_addr(adapter, CXL_PSL9_DEBUG));
45*4882a593Smuzhiyun 	debugfs_create_io_x64("xsl-debug", 0600, dir,
46*4882a593Smuzhiyun 			      _cxl_p1_addr(adapter, CXL_XSL9_DBG));
47*4882a593Smuzhiyun }
48*4882a593Smuzhiyun 
cxl_debugfs_add_adapter_regs_psl8(struct cxl * adapter,struct dentry * dir)49*4882a593Smuzhiyun void cxl_debugfs_add_adapter_regs_psl8(struct cxl *adapter, struct dentry *dir)
50*4882a593Smuzhiyun {
51*4882a593Smuzhiyun 	debugfs_create_io_x64("fir1", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_FIR1));
52*4882a593Smuzhiyun 	debugfs_create_io_x64("fir2", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_FIR2));
53*4882a593Smuzhiyun 	debugfs_create_io_x64("fir_cntl", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_FIR_CNTL));
54*4882a593Smuzhiyun 	debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_TRACE));
55*4882a593Smuzhiyun }
56*4882a593Smuzhiyun 
cxl_debugfs_adapter_add(struct cxl * adapter)57*4882a593Smuzhiyun void cxl_debugfs_adapter_add(struct cxl *adapter)
58*4882a593Smuzhiyun {
59*4882a593Smuzhiyun 	struct dentry *dir;
60*4882a593Smuzhiyun 	char buf[32];
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun 	if (!cxl_debugfs)
63*4882a593Smuzhiyun 		return;
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun 	snprintf(buf, 32, "card%i", adapter->adapter_num);
66*4882a593Smuzhiyun 	dir = debugfs_create_dir(buf, cxl_debugfs);
67*4882a593Smuzhiyun 	adapter->debugfs = dir;
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun 	debugfs_create_io_x64("err_ivte", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_ErrIVTE));
70*4882a593Smuzhiyun 
71*4882a593Smuzhiyun 	if (adapter->native->sl_ops->debugfs_add_adapter_regs)
72*4882a593Smuzhiyun 		adapter->native->sl_ops->debugfs_add_adapter_regs(adapter, dir);
73*4882a593Smuzhiyun }
74*4882a593Smuzhiyun 
cxl_debugfs_adapter_remove(struct cxl * adapter)75*4882a593Smuzhiyun void cxl_debugfs_adapter_remove(struct cxl *adapter)
76*4882a593Smuzhiyun {
77*4882a593Smuzhiyun 	debugfs_remove_recursive(adapter->debugfs);
78*4882a593Smuzhiyun }
79*4882a593Smuzhiyun 
cxl_debugfs_add_afu_regs_psl9(struct cxl_afu * afu,struct dentry * dir)80*4882a593Smuzhiyun void cxl_debugfs_add_afu_regs_psl9(struct cxl_afu *afu, struct dentry *dir)
81*4882a593Smuzhiyun {
82*4882a593Smuzhiyun 	debugfs_create_io_x64("serr", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SERR_An));
83*4882a593Smuzhiyun }
84*4882a593Smuzhiyun 
cxl_debugfs_add_afu_regs_psl8(struct cxl_afu * afu,struct dentry * dir)85*4882a593Smuzhiyun void cxl_debugfs_add_afu_regs_psl8(struct cxl_afu *afu, struct dentry *dir)
86*4882a593Smuzhiyun {
87*4882a593Smuzhiyun 	debugfs_create_io_x64("sstp0", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_SSTP0_An));
88*4882a593Smuzhiyun 	debugfs_create_io_x64("sstp1", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_SSTP1_An));
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun 	debugfs_create_io_x64("fir", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_FIR_SLICE_An));
91*4882a593Smuzhiyun 	debugfs_create_io_x64("serr", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SERR_An));
92*4882a593Smuzhiyun 	debugfs_create_io_x64("afu_debug", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_AFU_DEBUG_An));
93*4882a593Smuzhiyun 	debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SLICE_TRACE));
94*4882a593Smuzhiyun }
95*4882a593Smuzhiyun 
cxl_debugfs_afu_add(struct cxl_afu * afu)96*4882a593Smuzhiyun void cxl_debugfs_afu_add(struct cxl_afu *afu)
97*4882a593Smuzhiyun {
98*4882a593Smuzhiyun 	struct dentry *dir;
99*4882a593Smuzhiyun 	char buf[32];
100*4882a593Smuzhiyun 
101*4882a593Smuzhiyun 	if (!afu->adapter->debugfs)
102*4882a593Smuzhiyun 		return;
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun 	snprintf(buf, 32, "psl%i.%i", afu->adapter->adapter_num, afu->slice);
105*4882a593Smuzhiyun 	dir = debugfs_create_dir(buf, afu->adapter->debugfs);
106*4882a593Smuzhiyun 	afu->debugfs = dir;
107*4882a593Smuzhiyun 
108*4882a593Smuzhiyun 	debugfs_create_io_x64("sr",         S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SR_An));
109*4882a593Smuzhiyun 	debugfs_create_io_x64("dsisr",      S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_DSISR_An));
110*4882a593Smuzhiyun 	debugfs_create_io_x64("dar",        S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_DAR_An));
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun 	debugfs_create_io_x64("err_status", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_ErrStat_An));
113*4882a593Smuzhiyun 
114*4882a593Smuzhiyun 	if (afu->adapter->native->sl_ops->debugfs_add_afu_regs)
115*4882a593Smuzhiyun 		afu->adapter->native->sl_ops->debugfs_add_afu_regs(afu, dir);
116*4882a593Smuzhiyun }
117*4882a593Smuzhiyun 
cxl_debugfs_afu_remove(struct cxl_afu * afu)118*4882a593Smuzhiyun void cxl_debugfs_afu_remove(struct cxl_afu *afu)
119*4882a593Smuzhiyun {
120*4882a593Smuzhiyun 	debugfs_remove_recursive(afu->debugfs);
121*4882a593Smuzhiyun }
122*4882a593Smuzhiyun 
cxl_debugfs_init(void)123*4882a593Smuzhiyun void __init cxl_debugfs_init(void)
124*4882a593Smuzhiyun {
125*4882a593Smuzhiyun 	if (!cpu_has_feature(CPU_FTR_HVMODE))
126*4882a593Smuzhiyun 		return;
127*4882a593Smuzhiyun 
128*4882a593Smuzhiyun 	cxl_debugfs = debugfs_create_dir("cxl", NULL);
129*4882a593Smuzhiyun }
130*4882a593Smuzhiyun 
cxl_debugfs_exit(void)131*4882a593Smuzhiyun void cxl_debugfs_exit(void)
132*4882a593Smuzhiyun {
133*4882a593Smuzhiyun 	debugfs_remove_recursive(cxl_debugfs);
134*4882a593Smuzhiyun }
135