MALI: rockchip: upgrade midgard DDK to r14p0-01rel0
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / midgard / mali_kbase_as_fault_debugfs.c
1 /*
2  *
3  * (C) COPYRIGHT 2016 ARM Limited. All rights reserved.
4  *
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
8  * of such GNU licence.
9  *
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.
13  *
14  */
15
16
17
18 #include <linux/debugfs.h>
19
20 #include <mali_kbase.h>
21 #include <mali_kbase_as_fault_debugfs.h>
22
23 #ifdef CONFIG_DEBUG_FS
24 #ifdef CONFIG_MALI_DEBUG
25
26 static int kbase_as_fault_read(struct seq_file *sfile, void *data)
27 {
28         uintptr_t as_no = (uintptr_t) sfile->private;
29
30         struct list_head *entry;
31         const struct list_head *kbdev_list;
32         struct kbase_device *kbdev = NULL;
33
34         kbdev_list = kbase_dev_list_get();
35
36         list_for_each(entry, kbdev_list) {
37                 kbdev = list_entry(entry, struct kbase_device, entry);
38
39                 if(kbdev->debugfs_as_read_bitmap & (1ULL << as_no)) {
40
41                         /* don't show this one again until another fault occors */
42                         kbdev->debugfs_as_read_bitmap &= ~(1ULL << as_no);
43
44                         /* output the last page fault addr */
45                         seq_printf(sfile, "%llu\n", (u64) kbdev->as[as_no].fault_addr);
46                 }
47
48         }
49
50         kbase_dev_list_put(kbdev_list);
51
52         return 0;
53 }
54
55 static int kbase_as_fault_debugfs_open(struct inode *in, struct file *file)
56 {
57         return single_open(file, kbase_as_fault_read , in->i_private);
58 }
59
60 static const struct file_operations as_fault_fops = {
61         .open = kbase_as_fault_debugfs_open,
62         .read = seq_read,
63         .llseek = seq_lseek,
64         .release = single_release,
65 };
66
67 #endif /* CONFIG_MALI_DEBUG */
68 #endif /* CONFIG_DEBUG_FS */
69
70 /*
71  *  Initialize debugfs entry for each address space
72  */
73 void kbase_as_fault_debugfs_init(struct kbase_device *kbdev)
74 {
75 #ifdef CONFIG_DEBUG_FS
76 #ifdef CONFIG_MALI_DEBUG
77         uint i;
78         char as_name[64];
79         struct dentry *debugfs_directory;
80
81         kbdev->debugfs_as_read_bitmap = 0ULL;
82
83         KBASE_DEBUG_ASSERT(kbdev->nr_hw_address_spaces);
84         KBASE_DEBUG_ASSERT(sizeof(kbdev->as[0].fault_addr) == sizeof(u64));
85
86         debugfs_directory = debugfs_create_dir("address_spaces",
87                 kbdev->mali_debugfs_directory);
88
89         if(debugfs_directory) {
90                 for(i = 0; i < kbdev->nr_hw_address_spaces; i++) {
91                         snprintf(as_name, ARRAY_SIZE(as_name), "as%u", i);
92                         debugfs_create_file(as_name, S_IRUGO,
93                                 debugfs_directory, (void*) ((uintptr_t) i), &as_fault_fops);
94                 }
95         }
96         else
97                 dev_warn(kbdev->dev, "unable to create address_spaces debugfs directory");
98
99 #endif /* CONFIG_MALI_DEBUG */
100 #endif /* CONFIG_DEBUG_FS */
101         return;
102 }