2 * Copyright 2016-17 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.
10 #define pr_fmt(fmt) "vas: " fmt
12 #include <linux/types.h>
13 #include <linux/slab.h>
14 #include <linux/debugfs.h>
15 #include <linux/seq_file.h>
18 static struct dentry *vas_debugfs;
20 static char *cop_to_str(int cop)
23 case VAS_COP_TYPE_FAULT: return "Fault";
24 case VAS_COP_TYPE_842: return "NX-842 Normal Priority";
25 case VAS_COP_TYPE_842_HIPRI: return "NX-842 High Priority";
26 case VAS_COP_TYPE_GZIP: return "NX-GZIP Normal Priority";
27 case VAS_COP_TYPE_GZIP_HIPRI: return "NX-GZIP High Priority";
28 case VAS_COP_TYPE_FTW: return "Fast Thread-wakeup";
29 default: return "Unknown";
33 static int info_dbg_show(struct seq_file *s, void *private)
35 struct vas_window *window = s->private;
37 mutex_lock(&vas_mutex);
39 /* ensure window is not unmapped */
40 if (!window->hvwc_map)
43 seq_printf(s, "Type: %s, %s\n", cop_to_str(window->cop),
44 window->tx_win ? "Send" : "Receive");
45 seq_printf(s, "Pid : %d\n", window->pid);
48 mutex_unlock(&vas_mutex);
52 static int info_dbg_open(struct inode *inode, struct file *file)
54 return single_open(file, info_dbg_show, inode->i_private);
57 static const struct file_operations info_fops = {
58 .open = info_dbg_open,
61 .release = single_release,
64 static inline void print_reg(struct seq_file *s, struct vas_window *win,
67 seq_printf(s, "0x%016llx %s\n", read_hvwc_reg(win, name, reg), name);
70 static int hvwc_dbg_show(struct seq_file *s, void *private)
72 struct vas_window *window = s->private;
74 mutex_lock(&vas_mutex);
76 /* ensure window is not unmapped */
77 if (!window->hvwc_map)
80 print_reg(s, window, VREG(LPID));
81 print_reg(s, window, VREG(PID));
82 print_reg(s, window, VREG(XLATE_MSR));
83 print_reg(s, window, VREG(XLATE_LPCR));
84 print_reg(s, window, VREG(XLATE_CTL));
85 print_reg(s, window, VREG(AMR));
86 print_reg(s, window, VREG(SEIDR));
87 print_reg(s, window, VREG(FAULT_TX_WIN));
88 print_reg(s, window, VREG(OSU_INTR_SRC_RA));
89 print_reg(s, window, VREG(HV_INTR_SRC_RA));
90 print_reg(s, window, VREG(PSWID));
91 print_reg(s, window, VREG(LFIFO_BAR));
92 print_reg(s, window, VREG(LDATA_STAMP_CTL));
93 print_reg(s, window, VREG(LDMA_CACHE_CTL));
94 print_reg(s, window, VREG(LRFIFO_PUSH));
95 print_reg(s, window, VREG(CURR_MSG_COUNT));
96 print_reg(s, window, VREG(LNOTIFY_AFTER_COUNT));
97 print_reg(s, window, VREG(LRX_WCRED));
98 print_reg(s, window, VREG(LRX_WCRED_ADDER));
99 print_reg(s, window, VREG(TX_WCRED));
100 print_reg(s, window, VREG(TX_WCRED_ADDER));
101 print_reg(s, window, VREG(LFIFO_SIZE));
102 print_reg(s, window, VREG(WINCTL));
103 print_reg(s, window, VREG(WIN_STATUS));
104 print_reg(s, window, VREG(WIN_CTX_CACHING_CTL));
105 print_reg(s, window, VREG(TX_RSVD_BUF_COUNT));
106 print_reg(s, window, VREG(LRFIFO_WIN_PTR));
107 print_reg(s, window, VREG(LNOTIFY_CTL));
108 print_reg(s, window, VREG(LNOTIFY_PID));
109 print_reg(s, window, VREG(LNOTIFY_LPID));
110 print_reg(s, window, VREG(LNOTIFY_TID));
111 print_reg(s, window, VREG(LNOTIFY_SCOPE));
112 print_reg(s, window, VREG(NX_UTIL_ADDER));
114 mutex_unlock(&vas_mutex);
118 static int hvwc_dbg_open(struct inode *inode, struct file *file)
120 return single_open(file, hvwc_dbg_show, inode->i_private);
123 static const struct file_operations hvwc_fops = {
124 .open = hvwc_dbg_open,
127 .release = single_release,
130 void vas_window_free_dbgdir(struct vas_window *window)
132 if (window->dbgdir) {
133 debugfs_remove_recursive(window->dbgdir);
134 kfree(window->dbgname);
135 window->dbgdir = NULL;
136 window->dbgname = NULL;
140 void vas_window_init_dbgdir(struct vas_window *window)
142 struct dentry *f, *d;
144 if (!window->vinst->dbgdir)
147 window->dbgname = kzalloc(16, GFP_KERNEL);
148 if (!window->dbgname)
151 snprintf(window->dbgname, 16, "w%d", window->winid);
153 d = debugfs_create_dir(window->dbgname, window->vinst->dbgdir);
159 f = debugfs_create_file("info", 0444, d, window, &info_fops);
163 f = debugfs_create_file("hvwc", 0444, d, window, &hvwc_fops);
170 debugfs_remove_recursive(window->dbgdir);
171 window->dbgdir = NULL;
174 kfree(window->dbgname);
175 window->dbgname = NULL;
178 void vas_instance_init_dbgdir(struct vas_instance *vinst)
186 vinst->dbgname = kzalloc(16, GFP_KERNEL);
190 snprintf(vinst->dbgname, 16, "v%d", vinst->vas_id);
192 d = debugfs_create_dir(vinst->dbgname, vas_debugfs);
200 kfree(vinst->dbgname);
201 vinst->dbgname = NULL;
202 vinst->dbgdir = NULL;
206 * Set up the "root" VAS debugfs dir. Return if we already set it up
207 * (or failed to) in an earlier instance of VAS.
209 void vas_init_dbgdir(void)
211 static bool first_time = true;
217 vas_debugfs = debugfs_create_dir("vas", NULL);
218 if (IS_ERR(vas_debugfs))