mali_760_driver : rk_ext on arm_release_ver, from r5p0-02dev0.
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / midgard / 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 <mali_kbase_gpu_memory_debugfs.h>
19
20 #ifdef CONFIG_DEBUG_FS
21 /** Show callback for the @c gpu_memory debugfs file.
22  *
23  * This function is called to get the contents of the @c gpu_memory debugfs
24  * file. This is a report of current gpu memory usage.
25  *
26  * @param sfile The debugfs entry
27  * @param data Data associated with the entry
28  *
29  * @return 0 if successfully prints data in debugfs entry file
30  *         -1 if it encountered an error
31  */
32
33 static int kbasep_gpu_memory_seq_show(struct seq_file *sfile, void *data)
34 {
35         ssize_t ret = 0;
36         struct list_head *entry;
37         const struct list_head *kbdev_list;
38         kbdev_list = kbase_dev_list_get();
39         list_for_each(entry, kbdev_list) {
40                 struct kbase_device *kbdev = NULL;
41                 struct kbasep_kctx_list_element *element;
42
43                 kbdev = list_entry(entry, struct kbase_device, entry);
44                 /* output the total memory usage and cap for this device */
45                 ret = seq_printf(sfile, "%-16s  %10u\n", \
46                                 kbdev->devname, \
47                                 atomic_read(&(kbdev->memdev.used_pages)));
48                 mutex_lock(&kbdev->kctx_list_lock);
49                 list_for_each_entry(element, &kbdev->kctx_list, link) {
50                         /* output the memory usage and cap for each kctx
51                         * opened on this device */
52                         ret = seq_printf(sfile, "  %s-0x%p %10u %10u %10u %10u\n", \
53                                 "kctx", \
54                                 element->kctx, \
55                                 element->kctx->pid, \
56                                 atomic_read(&(element->kctx->osalloc.free_list_size)), \
57                                 atomic_read(&(element->kctx->used_pages)), \
58                                 atomic_read(&(element->kctx->nonmapped_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(struct 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(struct kbase_device *kbdev)
101 {
102         debugfs_remove(kbdev->gpu_memory_dentry);
103 }
104 #else
105 /*
106  * Stub functions for when debugfs is disabled
107  */
108 mali_error kbasep_gpu_memory_debugfs_init(struct kbase_device *kbdev)
109 {
110         return MALI_ERROR_NONE;
111 }
112 void kbasep_gpu_memory_debugfs_term(struct kbase_device *kbdev)
113 {
114 }
115 #endif