3 * (C) COPYRIGHT 2012-2016 ARM Limited. All rights reserved.
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
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.
18 #include <mali_kbase.h>
20 #ifdef CONFIG_DEBUG_FS
22 /** Show callback for the @c mem_profile debugfs file.
24 * This function is called to get the contents of the @c mem_profile debugfs
25 * file. This is a report of current memory usage and distribution in userspace.
27 * @param sfile The debugfs entry
28 * @param data Data associated with the entry
30 * @return 0 if it successfully prints data in debugfs entry file, non-zero otherwise
32 static int kbasep_mem_profile_seq_show(struct seq_file *sfile, void *data)
34 struct kbase_context *kctx = sfile->private;
36 mutex_lock(&kctx->mem_profile_lock);
38 seq_write(sfile, kctx->mem_profile_data, kctx->mem_profile_size);
40 seq_putc(sfile, '\n');
42 mutex_unlock(&kctx->mem_profile_lock);
48 * File operations related to debugfs entry for mem_profile
50 static int kbasep_mem_profile_debugfs_open(struct inode *in, struct file *file)
52 return single_open(file, kbasep_mem_profile_seq_show, in->i_private);
55 static const struct file_operations kbasep_mem_profile_debugfs_fops = {
56 .open = kbasep_mem_profile_debugfs_open,
59 .release = single_release,
62 int kbasep_mem_profile_debugfs_insert(struct kbase_context *kctx, char *data,
67 mutex_lock(&kctx->mem_profile_lock);
69 dev_dbg(kctx->kbdev->dev, "initialised: %d",
70 kctx->mem_profile_initialized);
72 if (!kctx->mem_profile_initialized) {
73 if (!debugfs_create_file("mem_profile", S_IRUGO,
74 kctx->kctx_dentry, kctx,
75 &kbasep_mem_profile_debugfs_fops)) {
78 kctx->mem_profile_initialized = true;
82 if (kctx->mem_profile_initialized) {
83 kfree(kctx->mem_profile_data);
84 kctx->mem_profile_data = data;
85 kctx->mem_profile_size = size;
88 dev_dbg(kctx->kbdev->dev, "returning: %d, initialised: %d",
89 err, kctx->mem_profile_initialized);
91 mutex_unlock(&kctx->mem_profile_lock);
96 void kbasep_mem_profile_debugfs_remove(struct kbase_context *kctx)
98 mutex_lock(&kctx->mem_profile_lock);
100 dev_dbg(kctx->kbdev->dev, "initialised: %d",
101 kctx->mem_profile_initialized);
103 kfree(kctx->mem_profile_data);
104 kctx->mem_profile_data = NULL;
105 kctx->mem_profile_size = 0;
107 mutex_unlock(&kctx->mem_profile_lock);
110 #else /* CONFIG_DEBUG_FS */
112 int kbasep_mem_profile_debugfs_insert(struct kbase_context *kctx, char *data,
118 #endif /* CONFIG_DEBUG_FS */