hwrng: core - Don't use a stack buffer in add_early_randomness()
[linux/fpc-iii.git] / drivers / misc / cxl / debugfs.c
blobec7b8a0174393204667915175d6a01dba48d35ee
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 void cxl_stop_trace(struct cxl *adapter)
20 int slice;
22 /* Stop the trace */
23 cxl_p1_write(adapter, CXL_PSL_TRACE, 0x8000000000000017LL);
25 /* Stop the slice traces */
26 spin_lock(&adapter->afu_list_lock);
27 for (slice = 0; slice < adapter->slices; slice++) {
28 if (adapter->afu[slice])
29 cxl_p1n_write(adapter->afu[slice], CXL_PSL_SLICE_TRACE, 0x8000000000000000LL);
31 spin_unlock(&adapter->afu_list_lock);
34 /* Helpers to export CXL mmaped IO registers via debugfs */
35 static int debugfs_io_u64_get(void *data, u64 *val)
37 *val = in_be64((u64 __iomem *)data);
38 return 0;
41 static int debugfs_io_u64_set(void *data, u64 val)
43 out_be64((u64 __iomem *)data, val);
44 return 0;
46 DEFINE_SIMPLE_ATTRIBUTE(fops_io_x64, debugfs_io_u64_get, debugfs_io_u64_set, "0x%016llx\n");
48 static struct dentry *debugfs_create_io_x64(const char *name, umode_t mode,
49 struct dentry *parent, u64 __iomem *value)
51 return debugfs_create_file(name, mode, parent, (void __force *)value, &fops_io_x64);
54 void cxl_debugfs_add_adapter_psl_regs(struct cxl *adapter, struct dentry *dir)
56 debugfs_create_io_x64("fir1", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_FIR1));
57 debugfs_create_io_x64("fir2", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_FIR2));
58 debugfs_create_io_x64("fir_cntl", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_FIR_CNTL));
59 debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_TRACE));
62 void cxl_debugfs_add_adapter_xsl_regs(struct cxl *adapter, struct dentry *dir)
64 debugfs_create_io_x64("fec", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_XSL_FEC));
67 int cxl_debugfs_adapter_add(struct cxl *adapter)
69 struct dentry *dir;
70 char buf[32];
72 if (!cxl_debugfs)
73 return -ENODEV;
75 snprintf(buf, 32, "card%i", adapter->adapter_num);
76 dir = debugfs_create_dir(buf, cxl_debugfs);
77 if (IS_ERR(dir))
78 return PTR_ERR(dir);
79 adapter->debugfs = dir;
81 debugfs_create_io_x64("err_ivte", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_ErrIVTE));
83 if (adapter->native->sl_ops->debugfs_add_adapter_sl_regs)
84 adapter->native->sl_ops->debugfs_add_adapter_sl_regs(adapter, dir);
85 return 0;
88 void cxl_debugfs_adapter_remove(struct cxl *adapter)
90 debugfs_remove_recursive(adapter->debugfs);
93 void cxl_debugfs_add_afu_psl_regs(struct cxl_afu *afu, struct dentry *dir)
95 debugfs_create_io_x64("fir", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_FIR_SLICE_An));
96 debugfs_create_io_x64("serr", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SERR_An));
97 debugfs_create_io_x64("afu_debug", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_AFU_DEBUG_An));
98 debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SLICE_TRACE));
101 int cxl_debugfs_afu_add(struct cxl_afu *afu)
103 struct dentry *dir;
104 char buf[32];
106 if (!afu->adapter->debugfs)
107 return -ENODEV;
109 snprintf(buf, 32, "psl%i.%i", afu->adapter->adapter_num, afu->slice);
110 dir = debugfs_create_dir(buf, afu->adapter->debugfs);
111 if (IS_ERR(dir))
112 return PTR_ERR(dir);
113 afu->debugfs = dir;
115 debugfs_create_io_x64("sr", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SR_An));
116 debugfs_create_io_x64("dsisr", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_DSISR_An));
117 debugfs_create_io_x64("dar", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_DAR_An));
118 debugfs_create_io_x64("sstp0", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_SSTP0_An));
119 debugfs_create_io_x64("sstp1", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_SSTP1_An));
120 debugfs_create_io_x64("err_status", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_ErrStat_An));
122 if (afu->adapter->native->sl_ops->debugfs_add_afu_sl_regs)
123 afu->adapter->native->sl_ops->debugfs_add_afu_sl_regs(afu, dir);
125 return 0;
128 void cxl_debugfs_afu_remove(struct cxl_afu *afu)
130 debugfs_remove_recursive(afu->debugfs);
133 int __init cxl_debugfs_init(void)
135 struct dentry *ent;
137 if (!cpu_has_feature(CPU_FTR_HVMODE))
138 return 0;
140 ent = debugfs_create_dir("cxl", NULL);
141 if (IS_ERR(ent))
142 return PTR_ERR(ent);
143 cxl_debugfs = ent;
145 return 0;
148 void cxl_debugfs_exit(void)
150 debugfs_remove_recursive(cxl_debugfs);