3 * (C) COPYRIGHT 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 mali_error kbasep_mem_profile_debugfs_add(struct kbase_context *kctx)
77 char name[KBASEP_DEBUGFS_FNAME_SIZE_MAX];
79 KBASE_DEBUG_ASSERT(kctx != NULL);
81 spin_lock_init(&kctx->mem_profile_lock);
83 scnprintf(name, KBASEP_DEBUGFS_FNAME_SIZE_MAX, "%d_%d", kctx->pid,
86 kctx->mem_dentry = debugfs_create_file(name, S_IRUGO,
87 kctx->kbdev->memory_profile_directory,
88 kctx, &kbasep_mem_profile_debugfs_fops);
89 if (IS_ERR(kctx->mem_dentry))
92 return MALI_ERROR_NONE;
95 return MALI_ERROR_FUNCTION_FAILED;
98 void kbasep_mem_profile_debugfs_remove(struct kbase_context *kctx)
100 KBASE_DEBUG_ASSERT(kctx != NULL);
102 spin_lock(&kctx->mem_profile_lock);
103 kfree(kctx->mem_profile_data);
104 kctx->mem_profile_data = NULL;
105 spin_unlock(&kctx->mem_profile_lock);
107 if (IS_ERR(kctx->mem_dentry))
109 debugfs_remove(kctx->mem_dentry);
112 #else /* CONFIG_DEBUG_FS */
115 * @brief Stub function for when debugfs is disabled
117 mali_error kbasep_mem_profile_debugfs_add(struct kbase_context *ctx)
119 return MALI_ERROR_NONE;
123 * @brief Stub function for when debugfs is disabled
125 void kbasep_mem_profile_debugfs_remove(struct kbase_context *ctx)
130 * @brief Stub function for when debugfs is disabled
132 void kbasep_mem_profile_debugfs_insert(struct kbase_context *kctx, char *data,
137 #endif /* CONFIG_DEBUG_FS */