Revert "MALI: rockchip: upgrade midgard DDK to r14p0-01rel0"
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / midgard / mali_kbase_jd_debugfs.c
1 /*
2  *
3  * (C) COPYRIGHT 2014-2015 ARM Limited. All rights reserved.
4  *
5  * This program is free software and is provided to you under the terms of the
6  * GNU General Public License version 2 as published by the Free Software
7  * Foundation, and any use by you of this program is subject to the terms
8  * of such GNU licence.
9  *
10  * A copy of the licence is included with the program, and can also be obtained
11  * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
12  * Boston, MA  02110-1301, USA.
13  *
14  */
15
16
17
18 #include <linux/seq_file.h>
19
20 #include <mali_kbase.h>
21
22 #include <mali_kbase_jd_debugfs.h>
23
24 #ifdef CONFIG_DEBUG_FS
25
26 /**
27  * kbasep_jd_debugfs_atoms_show - Show callback for the JD atoms debugfs file.
28  * @sfile: The debugfs entry
29  * @data:  Data associated with the entry
30  *
31  * This function is called to get the contents of the JD atoms debugfs file.
32  * This is a report of all atoms managed by kbase_jd_context.atoms
33  *
34  * Return: 0 if successfully prints data in debugfs entry file, failure
35  * otherwise
36  */
37 static int kbasep_jd_debugfs_atoms_show(struct seq_file *sfile, void *data)
38 {
39         struct kbase_context *kctx = sfile->private;
40         struct kbase_jd_atom *atoms;
41         unsigned long irq_flags;
42         int i;
43
44         KBASE_DEBUG_ASSERT(kctx != NULL);
45
46         /* Print version */
47         seq_printf(sfile, "v%u\n", MALI_JD_DEBUGFS_VERSION);
48
49         /* Print U/K API version */
50         seq_printf(sfile, "ukv%u.%u\n", BASE_UK_VERSION_MAJOR,
51                         BASE_UK_VERSION_MINOR);
52
53         /* Print table heading */
54         seq_puts(sfile, "atom id,core reqs,status,coreref status,predeps,start time,time on gpu\n");
55
56         atoms = kctx->jctx.atoms;
57         /* General atom states */
58         mutex_lock(&kctx->jctx.lock);
59         /* JS-related states */
60         spin_lock_irqsave(&kctx->kbdev->js_data.runpool_irq.lock, irq_flags);
61         for (i = 0; i != BASE_JD_ATOM_COUNT; ++i) {
62                 struct kbase_jd_atom *atom = &atoms[i];
63                 s64 start_timestamp = 0;
64
65                 if (atom->status == KBASE_JD_ATOM_STATE_UNUSED)
66                         continue;
67
68                 /* start_timestamp is cleared as soon as the atom leaves UNUSED state
69                  * and set before a job is submitted to the h/w, a non-zero value means
70                  * it is valid */
71                 if (ktime_to_ns(atom->start_timestamp))
72                         start_timestamp = ktime_to_ns(
73                                         ktime_sub(ktime_get(), atom->start_timestamp));
74
75                 seq_printf(sfile,
76                                 "%i,%u,%u,%u,%u %u,%lli,%llu\n",
77                                 i, atom->core_req, atom->status, atom->coreref_state,
78                                 (unsigned)(atom->dep[0].atom ?
79                                                 atom->dep[0].atom - atoms : 0),
80                                 (unsigned)(atom->dep[1].atom ?
81                                                 atom->dep[1].atom - atoms : 0),
82                                 (signed long long)start_timestamp,
83                                 (unsigned long long)(atom->time_spent_us ?
84                                         atom->time_spent_us * 1000 : start_timestamp)
85                                 );
86         }
87         spin_unlock_irqrestore(&kctx->kbdev->js_data.runpool_irq.lock, irq_flags);
88         mutex_unlock(&kctx->jctx.lock);
89
90         return 0;
91 }
92
93
94 /**
95  * kbasep_jd_debugfs_atoms_open - open operation for atom debugfs file
96  * @in: &struct inode pointer
97  * @file: &struct file pointer
98  *
99  * Return: file descriptor
100  */
101 static int kbasep_jd_debugfs_atoms_open(struct inode *in, struct file *file)
102 {
103         return single_open(file, kbasep_jd_debugfs_atoms_show, in->i_private);
104 }
105
106 static const struct file_operations kbasep_jd_debugfs_atoms_fops = {
107         .open = kbasep_jd_debugfs_atoms_open,
108         .read = seq_read,
109         .llseek = seq_lseek,
110         .release = single_release,
111 };
112
113 void kbasep_jd_debugfs_ctx_add(struct kbase_context *kctx)
114 {
115         KBASE_DEBUG_ASSERT(kctx != NULL);
116
117         /* Expose all atoms */
118         debugfs_create_file("atoms", S_IRUGO, kctx->kctx_dentry, kctx,
119                         &kbasep_jd_debugfs_atoms_fops);
120
121 }
122
123 #endif /* CONFIG_DEBUG_FS */