1 // SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
2 /*
3 *
4 * (C) COPYRIGHT 2020-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 #include "mali_kbase_dvfs_debugfs.h"
23 #include <mali_kbase.h>
24 #include <linux/seq_file.h>
25
26 #if IS_ENABLED(CONFIG_DEBUG_FS)
27
28 /**
29 * kbasep_dvfs_utilization_debugfs_show() - Print the DVFS utilization info
30 *
31 * @file: The seq_file for printing to
32 * @data: The debugfs dentry private data, a pointer to kbase_context
33 *
34 * Return: Negative error code or 0 on success.
35 */
kbasep_dvfs_utilization_debugfs_show(struct seq_file * file,void * data)36 static int kbasep_dvfs_utilization_debugfs_show(struct seq_file *file, void *data)
37 {
38 struct kbase_device *kbdev = file->private;
39
40 #if MALI_USE_CSF
41 seq_printf(file, "busy_time: %u idle_time: %u protm_time: %u\n",
42 kbdev->pm.backend.metrics.values.time_busy,
43 kbdev->pm.backend.metrics.values.time_idle,
44 kbdev->pm.backend.metrics.values.time_in_protm);
45 #else
46 seq_printf(file, "busy_time: %u idle_time: %u\n",
47 kbdev->pm.backend.metrics.values.time_busy,
48 kbdev->pm.backend.metrics.values.time_idle);
49 #endif
50
51 return 0;
52 }
53
kbasep_dvfs_utilization_debugfs_open(struct inode * in,struct file * file)54 static int kbasep_dvfs_utilization_debugfs_open(struct inode *in,
55 struct file *file)
56 {
57 return single_open(file, kbasep_dvfs_utilization_debugfs_show,
58 in->i_private);
59 }
60
61 static const struct file_operations kbasep_dvfs_utilization_debugfs_fops = {
62 .open = kbasep_dvfs_utilization_debugfs_open,
63 .read = seq_read,
64 .llseek = seq_lseek,
65 .release = single_release,
66 };
67
kbase_dvfs_status_debugfs_init(struct kbase_device * kbdev)68 void kbase_dvfs_status_debugfs_init(struct kbase_device *kbdev)
69 {
70 struct dentry *file;
71 const mode_t mode = 0444;
72
73 if (WARN_ON(!kbdev || IS_ERR_OR_NULL(kbdev->mali_debugfs_directory)))
74 return;
75
76 file = debugfs_create_file("dvfs_utilization", mode,
77 kbdev->mali_debugfs_directory, kbdev,
78 &kbasep_dvfs_utilization_debugfs_fops);
79
80 if (IS_ERR_OR_NULL(file)) {
81 dev_warn(kbdev->dev,
82 "Unable to create dvfs debugfs entry");
83 }
84 }
85
86 #else
87 /*
88 * Stub functions for when debugfs is disabled
89 */
kbase_dvfs_status_debugfs_init(struct kbase_device * kbdev)90 void kbase_dvfs_status_debugfs_init(struct kbase_device *kbdev)
91 {
92 }
93
94 #endif /* CONFIG_DEBUG_FS */
95