3 * (C) COPYRIGHT 2012-2015 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_gpu_memory_debugfs.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;
37 mutex_lock(&kctx->mem_profile_lock);
39 err = seq_write(sfile, kctx->mem_profile_data, kctx->mem_profile_size);
42 err = seq_putc(sfile, '\n');
44 mutex_unlock(&kctx->mem_profile_lock);
50 * File operations related to debugfs entry for mem_profile
52 static int kbasep_mem_profile_debugfs_open(struct inode *in, struct file *file)
54 return single_open(file, kbasep_mem_profile_seq_show, in->i_private);
57 static const struct file_operations kbasep_mem_profile_debugfs_fops = {
58 .open = kbasep_mem_profile_debugfs_open,
61 .release = single_release,
64 int kbasep_mem_profile_debugfs_insert(struct kbase_context *kctx, char *data,
69 mutex_lock(&kctx->mem_profile_lock);
71 dev_dbg(kctx->kbdev->dev, "initialised: %d",
72 kctx->mem_profile_initialized);
74 if (!kctx->mem_profile_initialized) {
75 if (!debugfs_create_file("mem_profile", S_IRUGO,
76 kctx->kctx_dentry, kctx,
77 &kbasep_mem_profile_debugfs_fops)) {
80 kctx->mem_profile_initialized = true;
84 if (kctx->mem_profile_initialized) {
85 kfree(kctx->mem_profile_data);
86 kctx->mem_profile_data = data;
87 kctx->mem_profile_size = size;
90 dev_dbg(kctx->kbdev->dev, "returning: %d, initialised: %d",
91 err, kctx->mem_profile_initialized);
93 mutex_unlock(&kctx->mem_profile_lock);
98 void kbasep_mem_profile_debugfs_remove(struct kbase_context *kctx)
100 mutex_lock(&kctx->mem_profile_lock);
102 dev_dbg(kctx->kbdev->dev, "initialised: %d",
103 kctx->mem_profile_initialized);
105 kfree(kctx->mem_profile_data);
106 kctx->mem_profile_data = NULL;
107 kctx->mem_profile_size = 0;
109 mutex_unlock(&kctx->mem_profile_lock);
112 #else /* CONFIG_DEBUG_FS */
114 int kbasep_mem_profile_debugfs_insert(struct kbase_context *kctx, char *data,
120 #endif /* CONFIG_DEBUG_FS */