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 <kbase/src/linux/mali_kbase_gpu_memory_debugfs.h>
20 /** Show callback for the @c gpu_memory debugfs file.
22 * This function is called to get the contents of the @c gpu_memory debugfs
23 * file. This is a report of current gpu memory usage.
25 * @param sfile The debugfs entry
26 * @param data Data associated with the entry
28 * @return 0 if successfully prints data in debugfs entry file
29 * -1 if it encountered an error
32 static int kbasep_gpu_memory_seq_show(struct seq_file *sfile, void *data)
35 struct list_head *entry;
36 const struct list_head *kbdev_list;
37 ret = seq_printf(sfile, "Name cap(pages) usage(pages)\n" \
38 "========================================\n");
39 kbdev_list = kbase_dev_list_get();
40 list_for_each(entry, kbdev_list) {
41 struct kbase_device *kbdev = NULL;
42 kbasep_kctx_list_element *element;
44 kbdev = list_entry(entry, struct kbase_device, osdev.entry);
45 /* output the total memory usage and cap for this device */
46 ret = seq_printf(sfile, "%-16s %10u %10u\n", \
47 kbdev->osdev.devname, \
48 kbdev->memdev.usage.max_pages, \
49 atomic_read(&(kbdev->memdev.usage.cur_pages)));
50 mutex_lock(&kbdev->kctx_list_lock);
51 list_for_each_entry(element, &kbdev->kctx_list, link) {
52 /* output the memory usage and cap for each kctx
53 * opened on this device */
54 ret = seq_printf(sfile, " %s-0x%p %10u %10u\n", \
57 element->kctx->usage.max_pages, \
58 atomic_read(&(element->kctx->usage.cur_pages)));
60 mutex_unlock(&kbdev->kctx_list_lock);
62 kbase_dev_list_put(kbdev_list);
67 * File operations related to debugfs entry for gpu_memory
69 STATIC int kbasep_gpu_memory_debugfs_open(struct inode *in, struct file *file)
71 return single_open(file, kbasep_gpu_memory_seq_show , NULL);
74 static const struct file_operations kbasep_gpu_memory_debugfs_fops = {
75 .open = kbasep_gpu_memory_debugfs_open,
78 .release = seq_release_private,
82 * Initialize debugfs entry for gpu_memory
84 mali_error kbasep_gpu_memory_debugfs_init(kbase_device *kbdev)
86 kbdev->gpu_memory_dentry = debugfs_create_file("gpu_memory", \
88 kbdev->mali_debugfs_directory, \
90 &kbasep_gpu_memory_debugfs_fops);
91 if (IS_ERR(kbdev->gpu_memory_dentry))
92 return MALI_ERROR_FUNCTION_FAILED;
94 return MALI_ERROR_NONE;
98 * Terminate debugfs entry for gpu_memory
100 void kbasep_gpu_memory_debugfs_term(kbase_device *kbdev)
102 debugfs_remove(kbdev->gpu_memory_dentry);