blob: 2566b6ed991db8a8b3a74a39a18529ffda68c124 [file] [log] [blame]
developerfbdb5112023-08-21 15:12:14 +08001// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright (c) 2023 MediaTek Inc. All Rights Reserved.
4 *
5 * Author: Alvin Kuo <alvin.kuog@mediatek.com>
6 */
7
8#include <linux/debugfs.h>
9#include <linux/uaccess.h>
10
developer0fb30d52023-12-04 09:51:36 +080011#include "tops/debugfs.h"
12#include "tops/internal.h"
13#include "tops/tops.h"
14#include "tops/trm-debugfs.h"
15#include "tops/trm.h"
developerfbdb5112023-08-21 15:12:14 +080016
17struct dentry *trm_debugfs_root;
18
19static int cpu_utilization_debug_read(struct seq_file *s, void *private)
20{
21 u32 cpu_utilization;
22 enum core_id core;
23 int ret;
24
25 seq_puts(s, "CPU Utilization:\n");
26 for (core = CORE_OFFLOAD_0; core <= CORE_MGMT; core++) {
27 ret = mtk_trm_cpu_utilization(core, &cpu_utilization);
28 if (ret) {
29 if (core <= CORE_OFFLOAD_3)
30 TOPS_ERR("fetch Core%d cpu utilization failed(%d)\n", core, ret);
31 else
32 TOPS_ERR("fetch CoreM cpu utilization failed(%d)\n", ret);
33
34 return ret;
35 }
36
37 if (core <= CORE_OFFLOAD_3)
38 seq_printf(s, "Core%d\t\t%u%%\n", core, cpu_utilization);
39 else
40 seq_printf(s, "CoreM\t\t%u%%\n", cpu_utilization);
41 }
42
43 return 0;
44}
45
46static int cpu_utilization_debug_open(struct inode *inode, struct file *file)
47{
48 return single_open(file, cpu_utilization_debug_read, file->private_data);
49}
50
51static ssize_t cpu_utilization_debug_write(struct file *file,
52 const char __user *buffer,
53 size_t count, loff_t *data)
54{
55 return count;
56}
57
58static const struct file_operations cpu_utilization_debug_ops = {
59 .open = cpu_utilization_debug_open,
60 .read = seq_read,
61 .llseek = seq_lseek,
62 .write = cpu_utilization_debug_write,
63 .release = single_release,
64};
65
66int mtk_trm_debugfs_init(void)
67{
68 if (!tops_debugfs_root)
69 return -ENOENT;
70
71 if (!trm_debugfs_root) {
72 trm_debugfs_root = debugfs_create_dir("trm", tops_debugfs_root);
73 if (IS_ERR(trm_debugfs_root)) {
74 TOPS_ERR("create trm debugfs root directory failed\n");
75 return PTR_ERR(trm_debugfs_root);
76 }
77 }
78
79 debugfs_create_file("cpu-utilization", 0644, trm_debugfs_root, NULL,
80 &cpu_utilization_debug_ops);
81
82 return 0;
83}
84
85void mtk_trm_debugfs_deinit(void)
86{
87 debugfs_remove_recursive(trm_debugfs_root);
88}