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