Linux 4.16.11
[linux/fpc-iii.git] / drivers / misc / cxl / debugfs.c
blob1643850d2302d042349a1953fa81acdaf5eb7c1a
1 /*
2 * Copyright 2014 IBM Corp.
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 */
10 #include <linux/debugfs.h>
11 #include <linux/kernel.h>
12 #include <linux/slab.h>
14 #include "cxl.h"
16 static struct dentry *cxl_debugfs;
18 /* Helpers to export CXL mmaped IO registers via debugfs */
19 static int debugfs_io_u64_get(void *data, u64 *val)
21 *val = in_be64((u64 __iomem *)data);
22 return 0;
25 static int debugfs_io_u64_set(void *data, u64 val)
27 out_be64((u64 __iomem *)data, val);
28 return 0;
30 DEFINE_DEBUGFS_ATTRIBUTE(fops_io_x64, debugfs_io_u64_get, debugfs_io_u64_set,
31 "0x%016llx\n");
33 static struct dentry *debugfs_create_io_x64(const char *name, umode_t mode,
34 struct dentry *parent, u64 __iomem *value)
36 return debugfs_create_file_unsafe(name, mode, parent,
37 (void __force *)value, &fops_io_x64);
40 void cxl_debugfs_add_adapter_regs_psl9(struct cxl *adapter, struct dentry *dir)
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));
53 void cxl_debugfs_add_adapter_regs_psl8(struct cxl *adapter, struct dentry *dir)
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));
61 void cxl_debugfs_add_adapter_regs_xsl(struct cxl *adapter, struct dentry *dir)
63 debugfs_create_io_x64("fec", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_XSL_FEC));
66 int cxl_debugfs_adapter_add(struct cxl *adapter)
68 struct dentry *dir;
69 char buf[32];
71 if (!cxl_debugfs)
72 return -ENODEV;
74 snprintf(buf, 32, "card%i", adapter->adapter_num);
75 dir = debugfs_create_dir(buf, cxl_debugfs);
76 if (IS_ERR(dir))
77 return PTR_ERR(dir);
78 adapter->debugfs = dir;
80 debugfs_create_io_x64("err_ivte", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_ErrIVTE));
82 if (adapter->native->sl_ops->debugfs_add_adapter_regs)
83 adapter->native->sl_ops->debugfs_add_adapter_regs(adapter, dir);
84 return 0;
87 void cxl_debugfs_adapter_remove(struct cxl *adapter)
89 debugfs_remove_recursive(adapter->debugfs);
92 void cxl_debugfs_add_afu_regs_psl9(struct cxl_afu *afu, struct dentry *dir)
94 debugfs_create_io_x64("serr", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SERR_An));
97 void cxl_debugfs_add_afu_regs_psl8(struct cxl_afu *afu, struct dentry *dir)
99 debugfs_create_io_x64("sstp0", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_SSTP0_An));
100 debugfs_create_io_x64("sstp1", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_SSTP1_An));
102 debugfs_create_io_x64("fir", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_FIR_SLICE_An));
103 debugfs_create_io_x64("serr", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SERR_An));
104 debugfs_create_io_x64("afu_debug", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_AFU_DEBUG_An));
105 debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SLICE_TRACE));
108 int cxl_debugfs_afu_add(struct cxl_afu *afu)
110 struct dentry *dir;
111 char buf[32];
113 if (!afu->adapter->debugfs)
114 return -ENODEV;
116 snprintf(buf, 32, "psl%i.%i", afu->adapter->adapter_num, afu->slice);
117 dir = debugfs_create_dir(buf, afu->adapter->debugfs);
118 if (IS_ERR(dir))
119 return PTR_ERR(dir);
120 afu->debugfs = dir;
122 debugfs_create_io_x64("sr", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SR_An));
123 debugfs_create_io_x64("dsisr", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_DSISR_An));
124 debugfs_create_io_x64("dar", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_DAR_An));
126 debugfs_create_io_x64("err_status", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_ErrStat_An));
128 if (afu->adapter->native->sl_ops->debugfs_add_afu_regs)
129 afu->adapter->native->sl_ops->debugfs_add_afu_regs(afu, dir);
131 return 0;
134 void cxl_debugfs_afu_remove(struct cxl_afu *afu)
136 debugfs_remove_recursive(afu->debugfs);
139 int __init cxl_debugfs_init(void)
141 struct dentry *ent;
143 if (!cpu_has_feature(CPU_FTR_HVMODE))
144 return 0;
146 ent = debugfs_create_dir("cxl", NULL);
147 if (IS_ERR(ent))
148 return PTR_ERR(ent);
149 cxl_debugfs = ent;
151 return 0;
154 void cxl_debugfs_exit(void)
156 debugfs_remove_recursive(cxl_debugfs);