diff options
Diffstat (limited to 'runlist_procfs.c')
-rw-r--r-- | runlist_procfs.c | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/runlist_procfs.c b/runlist_procfs.c new file mode 100644 index 0000000..2107bd4 --- /dev/null +++ b/runlist_procfs.c | |||
@@ -0,0 +1,102 @@ | |||
1 | #include <linux/seq_file.h> // For seq_* functions and types | ||
2 | |||
3 | #include "nvdebug.h" | ||
4 | |||
5 | #define RUNLIST_PROCFS_NAME "runlist" | ||
6 | |||
7 | static void *runlist_file_seq_start(struct seq_file *s, loff_t *pos) { | ||
8 | static struct runlist_iter rl_iter; | ||
9 | |||
10 | // *pos == 0 for first call after read of file | ||
11 | if (*pos == 0) { | ||
12 | int err = get_runlist_iter(&rl_iter); | ||
13 | if (err) | ||
14 | return NULL; | ||
15 | return &rl_iter; | ||
16 | } | ||
17 | // When called with *pos != 0, we already traversed the runlist | ||
18 | return NULL; | ||
19 | } | ||
20 | |||
21 | static void* runlist_file_seq_next(struct seq_file *s, void *raw_rl_iter, | ||
22 | loff_t *pos) { | ||
23 | struct runlist_iter* rl_iter = raw_rl_iter; | ||
24 | // Advance by one TSG + channels under last TSG | ||
25 | *pos += 1 + rl_iter->curr_tsg->tsg_length; | ||
26 | // Verify we haven't reached the end of the runlist | ||
27 | // rl_info.len is the num of tsg entries + total num of channel entries | ||
28 | if (*pos < rl_iter->rl_info.len) { | ||
29 | rl_iter->curr_tsg = next_tsg(rl_iter->curr_tsg); | ||
30 | return rl_iter; | ||
31 | } | ||
32 | return NULL; | ||
33 | } | ||
34 | |||
35 | static void runlist_file_seq_stop(struct seq_file *s, void *raw_rl_iter) { | ||
36 | // No cleanup needed | ||
37 | } | ||
38 | |||
39 | static int runlist_file_seq_show(struct seq_file *s, void *raw_rl_iter) { | ||
40 | struct entry_tsg* tsg = ((struct runlist_iter*)raw_rl_iter)->curr_tsg; | ||
41 | struct runlist_chan* chan; | ||
42 | if (tsg->entry_type != ENTRY_TYPE_TSG) { | ||
43 | printk(KERN_WARNING "[nvdebug] Attempted to print non-TSG in nvdebug_print_tsg()!\n"); | ||
44 | return -EIO; | ||
45 | } | ||
46 | seq_printf(s, "+---- TSG Entry %-2d----+\n", tsg->tsgid); | ||
47 | seq_printf(s, "| Scale: %-13d|\n", tsg->timeslice_scale); | ||
48 | seq_printf(s, "| Timeout: %-11d|\n", tsg->timeslice_timeout); | ||
49 | seq_printf(s, "+---------------------+\n"); | ||
50 | for_chan_in_tsg(chan, tsg) { | ||
51 | char* loc_txt; | ||
52 | u64 instance_ptr; | ||
53 | if (chan->entry_type != ENTRY_TYPE_CHAN) { | ||
54 | printk(KERN_WARNING "[nvdebug] Attempted to print non-channel in nvdebug_print_channel()!\n"); | ||
55 | return -EIO; | ||
56 | } | ||
57 | switch (chan->inst_target) { | ||
58 | case TARGET_VID_MEM: | ||
59 | loc_txt = "VID_MEM"; | ||
60 | break; | ||
61 | case TARGET_SYS_MEM_COHERENT: | ||
62 | loc_txt = "SYS_MEM_COHERENT"; | ||
63 | break; | ||
64 | case TARGET_SYS_MEM_NONCOHERENT: | ||
65 | loc_txt = "SYS_MEM_NONCOHERENT"; | ||
66 | break; | ||
67 | default: | ||
68 | printk(KERN_WARNING "[nvdebug] Invalid aperture in runlist channel!\n"); | ||
69 | return -EIO; | ||
70 | } | ||
71 | // Reconstruct pointer to channel instance block | ||
72 | instance_ptr = chan->inst_ptr_hi; | ||
73 | instance_ptr <<= 32; | ||
74 | instance_ptr |= chan->inst_ptr_lo << 12; | ||
75 | |||
76 | seq_printf(s, " +- Channel Entry %-4d-+\n", chan->chid); | ||
77 | seq_printf(s, " | Runqueue Selector: %d|\n", chan->runqueue_selector); | ||
78 | seq_printf(s, " | Instance PTR: |\n"); | ||
79 | seq_printf(s, " | %#018llx |\n", instance_ptr); | ||
80 | seq_printf(s, " | %-20s|\n", loc_txt); | ||
81 | seq_printf(s, " +---------------------+\n"); | ||
82 | } | ||
83 | return 0; | ||
84 | } | ||
85 | |||
86 | static const struct seq_operations runlist_file_seq_ops = { | ||
87 | .start = runlist_file_seq_start, | ||
88 | .next = runlist_file_seq_next, | ||
89 | .stop = runlist_file_seq_stop, | ||
90 | .show = runlist_file_seq_show, | ||
91 | }; | ||
92 | |||
93 | static int runlist_file_open(struct inode *inode, struct file *f) { | ||
94 | return seq_open(f, &runlist_file_seq_ops); | ||
95 | } | ||
96 | |||
97 | const struct file_operations runlist_file_ops = { | ||
98 | .open = runlist_file_open, | ||
99 | .read = seq_read, | ||
100 | .llseek = seq_lseek, | ||
101 | .release = seq_release, | ||
102 | }; | ||