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 /* mam_profile file name max length 22 based on format <int>_<int>\0 */
23 #define KBASEP_DEBUGFS_FNAME_SIZE_MAX (10+1+10+1)
25 void kbasep_mem_profile_debugfs_insert(struct kbase_context *kctx, char *data,
28 spin_lock(&kctx->mem_profile_lock);
29 kfree(kctx->mem_profile_data);
30 kctx->mem_profile_data = data;
31 kctx->mem_profile_size = size;
32 spin_unlock(&kctx->mem_profile_lock);
35 /** Show callback for the @c mem_profile debugfs file.
37 * This function is called to get the contents of the @c mem_profile debugfs
38 * file. This is a report of current memory usage and distribution in userspace.
40 * @param sfile The debugfs entry
41 * @param data Data associated with the entry
43 * @return 0 if successfully prints data in debugfs entry file
44 * -1 if it encountered an error
46 static int kbasep_mem_profile_seq_show(struct seq_file *sfile, void *data)
48 struct kbase_context *kctx = sfile->private;
50 KBASE_DEBUG_ASSERT(kctx != NULL);
52 spin_lock(&kctx->mem_profile_lock);
53 seq_write(sfile, kctx->mem_profile_data, kctx->mem_profile_size);
54 seq_putc(sfile, '\n');
55 spin_unlock(&kctx->mem_profile_lock);
61 * File operations related to debugfs entry for mem_profile
63 static int kbasep_mem_profile_debugfs_open(struct inode *in, struct file *file)
65 return single_open(file, kbasep_mem_profile_seq_show, in->i_private);
68 static const struct file_operations kbasep_mem_profile_debugfs_fops = {
69 .open = kbasep_mem_profile_debugfs_open,
72 .release = single_release,
75 void kbasep_mem_profile_debugfs_add(struct kbase_context *kctx)
77 KBASE_DEBUG_ASSERT(kctx != NULL);
79 spin_lock_init(&kctx->mem_profile_lock);
81 debugfs_create_file("mem_profile", S_IRUGO, kctx->kctx_dentry, kctx,
82 &kbasep_mem_profile_debugfs_fops);
85 void kbasep_mem_profile_debugfs_remove(struct kbase_context *kctx)
87 KBASE_DEBUG_ASSERT(kctx != NULL);
89 spin_lock(&kctx->mem_profile_lock);
90 kfree(kctx->mem_profile_data);
91 kctx->mem_profile_data = NULL;
92 spin_unlock(&kctx->mem_profile_lock);
95 #else /* CONFIG_DEBUG_FS */
98 * @brief Stub function for when debugfs is disabled
100 void kbasep_mem_profile_debugfs_insert(struct kbase_context *kctx, char *data,
105 #endif /* CONFIG_DEBUG_FS */