ade0cef328d735a44ef30a44c8ebd8a466d97c4c
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / t6xx / kbase / src / linux / mali_kbase_gpu_memory_debugfs.c
1 /*
2  *
3  * (C) COPYRIGHT 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 <kbase/src/linux/mali_kbase_gpu_memory_debugfs.h>
19
20 /** Show callback for the @c gpu_memory debugfs file.
21  *
22  * This function is called to get the contents of the @c gpu_memory debugfs
23  * file. This is a report of current gpu memory usage.
24  *
25  * @param sfile The debugfs entry
26  * @param data Data associated with the entry
27  *
28  * @return 0 if successfully prints data in debugfs entry file
29  *         -1 if it encountered an error
30  */
31
32 static int kbasep_gpu_memory_seq_show(struct seq_file *sfile, void *data)
33 {
34         ssize_t ret = 0;
35         struct list_head *entry;
36         const struct list_head *kbdev_list;
37         ret = seq_printf(sfile, "Name              cap(pages) usage(pages)\n" \
38                                 "========================================\n");
39         kbdev_list = kbase_dev_list_get();
40         list_for_each(entry, kbdev_list) {
41                 struct kbase_device *kbdev = NULL;
42                 kbasep_kctx_list_element *element;
43
44                 kbdev = list_entry(entry, struct kbase_device, osdev.entry);
45                 /* output the total memory usage and cap for this device */
46                 ret = seq_printf(sfile, "%-16s  %10u   %10u\n", \
47                                 kbdev->osdev.devname, \
48                                 kbdev->memdev.usage.max_pages, \
49                                 atomic_read(&(kbdev->memdev.usage.cur_pages)));
50                 mutex_lock(&kbdev->kctx_list_lock);
51                 list_for_each_entry(element, &kbdev->kctx_list, link) {
52                         /* output the memory usage and cap for each kctx
53                         * opened on this device */
54                         ret = seq_printf(sfile, "  %s-0x%p %10u   %10u\n", \
55                                 "kctx",
56                                 element->kctx, \
57                                 element->kctx->usage.max_pages, \
58                                 atomic_read(&(element->kctx->usage.cur_pages)));
59                 }
60                 mutex_unlock(&kbdev->kctx_list_lock);
61         }
62         kbase_dev_list_put(kbdev_list);
63         return ret;
64 }
65
66 /*
67  *  File operations related to debugfs entry for gpu_memory
68  */
69 STATIC int kbasep_gpu_memory_debugfs_open(struct inode *in, struct file *file)
70 {
71         return single_open(file, kbasep_gpu_memory_seq_show , NULL);
72 }
73
74 static const struct file_operations kbasep_gpu_memory_debugfs_fops = {
75         .open = kbasep_gpu_memory_debugfs_open,
76         .read = seq_read,
77         .llseek = seq_lseek,
78         .release = seq_release_private,
79 };
80
81 /*
82  *  Initialize debugfs entry for gpu_memory
83  */
84 mali_error kbasep_gpu_memory_debugfs_init(kbase_device *kbdev)
85 {
86         kbdev->gpu_memory_dentry = debugfs_create_file("gpu_memory", \
87                                         S_IRUGO, \
88                                         kbdev->mali_debugfs_directory, \
89                                         NULL, \
90                                         &kbasep_gpu_memory_debugfs_fops);
91         if (IS_ERR(kbdev->gpu_memory_dentry))
92                 return MALI_ERROR_FUNCTION_FAILED;
93
94         return MALI_ERROR_NONE;
95 }
96
97 /*
98  *  Terminate debugfs entry for gpu_memory
99  */
100 void kbasep_gpu_memory_debugfs_term(kbase_device *kbdev)
101 {
102         debugfs_remove(kbdev->gpu_memory_dentry);
103 }
104