xref: /OK3568_Linux_fs/kernel/drivers/gpu/arm/bifrost/mali_kbase_debug_mem_zones.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 // SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
2 /*
3  *
4  * (C) COPYRIGHT 2022 ARM Limited. All rights reserved.
5  *
6  * This program is free software and is provided to you under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation, and any use by you of this program is subject to the terms
9  * of such GNU license.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you can access it online at
18  * http://www.gnu.org/licenses/gpl-2.0.html.
19  *
20  */
21 
22 /*
23  * Debugfs interface to dump information about GPU_VA memory zones
24  */
25 
26 #include "mali_kbase_debug_mem_zones.h"
27 #include "mali_kbase.h"
28 
29 #include <linux/list.h>
30 #include <linux/file.h>
31 
32 #if IS_ENABLED(CONFIG_DEBUG_FS)
33 
34 /**
35  * debug_mem_zones_show - Show information about GPU_VA memory zones
36  * @sfile: The debugfs entry
37  * @data: Data associated with the entry
38  *
39  * This function is called to get the contents of the @c mem_zones debugfs file.
40  * This lists the start address and size (in pages) of each initialized memory
41  * zone within GPU_VA memory.
42  *
43  * Return:
44  * 0 if successfully prints data in debugfs entry file
45  * -1 if it encountered an error
46  */
debug_mem_zones_show(struct seq_file * sfile,void * data)47 static int debug_mem_zones_show(struct seq_file *sfile, void *data)
48 {
49 	struct kbase_context *const kctx = sfile->private;
50 	size_t i;
51 
52 	const char *zone_names[KBASE_REG_ZONE_MAX] = {
53 		"SAME_VA",
54 		"CUSTOM_VA",
55 		"EXEC_VA"
56 #if MALI_USE_CSF
57 		,
58 		"MCU_SHARED_VA",
59 		"EXEC_FIXED_VA",
60 		"FIXED_VA"
61 #endif
62 	};
63 
64 	kbase_gpu_vm_lock(kctx);
65 
66 	for (i = 0; i < KBASE_REG_ZONE_MAX; i++) {
67 		struct kbase_reg_zone *reg_zone = &kctx->reg_zone[i];
68 
69 		if (reg_zone->base_pfn) {
70 			seq_printf(sfile, "%15s %zu 0x%.16llx 0x%.16llx\n", zone_names[i], i,
71 				   reg_zone->base_pfn, reg_zone->va_size_pages);
72 		}
73 	}
74 
75 	kbase_gpu_vm_unlock(kctx);
76 	return 0;
77 }
78 
79 /*
80  *  File operations related to debugfs entry for mem_zones
81  */
debug_mem_zones_open(struct inode * in,struct file * file)82 static int debug_mem_zones_open(struct inode *in, struct file *file)
83 {
84 	return single_open(file, debug_mem_zones_show, in->i_private);
85 }
86 
87 static const struct file_operations kbase_debug_mem_zones_fops = {
88 	.owner = THIS_MODULE,
89 	.open = debug_mem_zones_open,
90 	.read = seq_read,
91 	.llseek = seq_lseek,
92 	.release = single_release,
93 };
94 
95 /*
96  *  Initialize debugfs entry for mem_zones
97  */
kbase_debug_mem_zones_init(struct kbase_context * const kctx)98 void kbase_debug_mem_zones_init(struct kbase_context *const kctx)
99 {
100 	/* Caller already ensures this, but we keep the pattern for
101 	 * maintenance safety.
102 	 */
103 	if (WARN_ON(!kctx) || WARN_ON(IS_ERR_OR_NULL(kctx->kctx_dentry)))
104 		return;
105 
106 	debugfs_create_file("mem_zones", 0400, kctx->kctx_dentry, kctx,
107 			    &kbase_debug_mem_zones_fops);
108 }
109 #else
110 /*
111  * Stub functions for when debugfs is disabled
112  */
kbase_debug_mem_zones_init(struct kbase_context * const kctx)113 void kbase_debug_mem_zones_init(struct kbase_context *const kctx)
114 {
115 }
116 #endif
117