blob: 2df9127f162d6afd83bf0a17d5d1d961d4e88bb3 [file] [log] [blame]
xjb04a4022021-11-25 15:01:52 +08001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (c) 2019 MediaTek Inc.
4 */
5
6#include <linux/sched/clock.h>
7#include <linux/fs.h>
8#include <linux/sched.h>
9#include <linux/module.h>
10#include <linux/device.h>
11#include <linux/miscdevice.h>
12#include <linux/kallsyms.h>
13#include <linux/syscore_ops.h>
14#include <linux/dma-mapping.h>
15#include <linux/of.h>
16#include "interface.h"
17#include "sampler.h"
18#include "util.h"
19
20#include "ondiemet.h"
21
22#include "met_drv.h"
23#include "met_tag.h"
24#include "met_kernel_symbol.h"
25#include "met_power.h"
26#include "met_api.h"
27#include "version.h"
28
29extern int enable_met_backlight_tag(void);
30extern int output_met_backlight_tag(int level);
31
32static int run = -1;
33static int sample_rate = 1000; /* Default: 1000 Hz */
34static int met_suspend_compensation_mode;
35static int met_suspend_compensation_flag;
36
37/*
38 * met_cpu_pmu_method:
39 * 0: MET pmu driver
40 * 1: perf APIs
41 */
42unsigned int met_cpu_pmu_method = 1;
43/*
44 * controls whether re-configuring pmu events after leaving cpu off state
45 */
46unsigned int met_cpu_pm_pmu_reconfig = 1;
47
48int met_hrtimer_expire; /* in ns */
49int met_timer_expire; /* in jiffies */
50unsigned int ctrl_flags;
51int met_mode;
52EXPORT_SYMBOL(met_mode);
53
54DEFINE_PER_CPU(char[MET_STRBUF_SIZE], met_strbuf_nmi);
55EXPORT_SYMBOL(met_strbuf_nmi);
56
57DEFINE_PER_CPU(char[MET_STRBUF_SIZE], met_strbuf_irq);
58EXPORT_SYMBOL(met_strbuf_irq);
59
60DEFINE_PER_CPU(char[MET_STRBUF_SIZE], met_strbuf_sirq);
61EXPORT_SYMBOL(met_strbuf_sirq);
62
63DEFINE_PER_CPU(char[MET_STRBUF_SIZE], met_strbuf);
64EXPORT_SYMBOL(met_strbuf);
65
66static void calc_timer_value(int rate)
67{
68 sample_rate = rate;
69
70 if (rate == 0) {
71 met_hrtimer_expire = 0;
72 met_timer_expire = 0;
73 return;
74 }
75
76 met_hrtimer_expire = 1000000000 / rate;
77
78 /* Case 1: hrtimer < 1 OS tick, met_timer_expire = 1 OS tick */
79 if (rate > HZ)
80 met_timer_expire = 1;
81 /* Case 2: hrtimer > 1 OS tick, met_timer_expire is hrtimer + 1 OS tick */
82 else
83 met_timer_expire = (HZ / rate) + 1;
84
85 /* pr_debug("JBK HZ=%d, met_hrtimer_expire=%d ns, met_timer_expire=%d ticks\n", */
86 /* HZ, met_hrtimer_expire, met_timer_expire); */
87}
88
89int met_parse_num(const char *str, unsigned int *value, int len)
90{
91 int ret;
92
93 if (len <= 0)
94 return -1;
95
96 if ((len > 2) &&
97 ((str[0] == '0') &&
98 ((str[1] == 'x') || (str[1] == 'X')))) {
99 ret = kstrtoint(str, 16, value);
100 } else {
101 ret = kstrtoint(str, 10, value);
102 }
103
104 if (ret != 0)
105 return -1;
106
107 return 0;
108}
109
110void met_set_suspend_notify(int flag)
111{
112 if (met_suspend_compensation_mode == 1)
113 met_suspend_compensation_flag = flag;
114 else
115 met_suspend_compensation_flag = 0;
116}
117
118LIST_HEAD(met_list);
119static struct kobject *kobj_misc;
120static struct kobject *kobj_pmu;
121static struct kobject *kobj_bus;
122
123static ssize_t ver_show(struct device *dev, struct device_attribute *attr, char *buf);
124static DEVICE_ATTR(ver, 0444, ver_show, NULL);
125
126static ssize_t plf_show(struct device *dev, struct device_attribute *attr, char *buf);
127static DEVICE_ATTR(plf, 0444, plf_show, NULL);
128
129static ssize_t chip_id_show(struct device *dev, struct device_attribute *attr, char *buf);
130static DEVICE_ATTR(chip_id, 0444, chip_id_show, NULL);
131
132static ssize_t core_topology_show(struct device *dev, struct device_attribute *attr, char *buf);
133static DEVICE_ATTR(core_topology, 0444, core_topology_show, NULL);
134
135static ssize_t devices_show(struct device *dev, struct device_attribute *attr, char *buf);
136static DEVICE_ATTR(devices, 0444, devices_show, NULL);
137
138static ssize_t ctrl_show(struct device *dev, struct device_attribute *attr, char *buf);
139static ssize_t ctrl_store(struct device *dev, struct device_attribute *attr, const char *buf,
140 size_t count);
141static DEVICE_ATTR(ctrl, 0664, ctrl_show, ctrl_store);
142
143static ssize_t spr_show(struct device *dev, struct device_attribute *attr, char *buf);
144static ssize_t spr_store(struct device *dev, struct device_attribute *attr, const char *buf,
145 size_t count);
146static DEVICE_ATTR(sample_rate, 0664, spr_show, spr_store);
147
148static ssize_t run_show(struct device *dev, struct device_attribute *attr, char *buf);
149static ssize_t run_store(struct device *dev, struct device_attribute *attr, const char *buf,
150 size_t count);
151static DEVICE_ATTR(run, 0664, run_show, run_store);
152
153static ssize_t ksym_show(struct device *dev, struct device_attribute *attr, char *buf);
154static ssize_t ksym_store(struct device *dev, struct device_attribute *attr, const char *buf,
155 size_t count);
156static DEVICE_ATTR(ksym, 0664, ksym_show, ksym_store);
157
158static ssize_t cpu_pmu_method_show(struct device *dev, struct device_attribute *attr, char *buf);
159static ssize_t cpu_pmu_method_store(struct device *dev, struct device_attribute *attr, const char *buf,
160 size_t count);
161static DEVICE_ATTR(cpu_pmu_method, 0664, cpu_pmu_method_show, cpu_pmu_method_store);
162
163static ssize_t cpu_pm_pmu_reconfig_show(struct device *dev,
164 struct device_attribute *attr,
165 char *buf);
166static ssize_t cpu_pm_pmu_reconfig_store(struct device *dev,
167 struct device_attribute *attr,
168 const char *buf,
169 size_t count);
170static DEVICE_ATTR(cpu_pm_pmu_reconfig,
171 0664,
172 cpu_pm_pmu_reconfig_show,
173 cpu_pm_pmu_reconfig_store);
174
175#ifdef PR_CPU_NOTIFY
176int met_cpu_notify;
177static ssize_t cpu_notify_show(struct device *dev, struct device_attribute *attr, char *buf);
178static ssize_t cpu_notify_store(struct device *dev, struct device_attribute *attr, const char *buf,
179 size_t count);
180static DEVICE_ATTR(cpu_notify, 0664, cpu_notify_show, cpu_notify_store);
181#endif
182
183#if IS_ENABLED(CONFIG_CPU_FREQ)
184static ssize_t dvfs_show(struct device *dev, struct device_attribute *attr, char *buf);
185static ssize_t dvfs_store(struct device *dev, struct device_attribute *attr, const char *buf,
186 size_t count);
187static DEVICE_ATTR(dvfs, 0664, dvfs_show, dvfs_store);
188#endif
189
190static ssize_t suspend_compensation_enable_show(struct device *dev, struct device_attribute *attr, char *buf);
191static ssize_t suspend_compensation_enable_store(struct device *dev, struct device_attribute *attr,
192 const char *buf, size_t count);
193static DEVICE_ATTR(suspend_compensation_enable, 0664, suspend_compensation_enable_show,
194 suspend_compensation_enable_store);
195
196static ssize_t suspend_compensation_flag_show(struct device *dev, struct device_attribute *attr, char *buf);
197static DEVICE_ATTR(suspend_compensation_flag, 0444, suspend_compensation_flag_show, NULL);
198
199static ssize_t ipi_test_store(struct device *dev, struct device_attribute *attr, const char *buf,
200 size_t count);
201static DEVICE_ATTR(ipi_test, 0220, NULL, ipi_test_store);
202
203static const struct file_operations met_file_ops = {
204 .owner = THIS_MODULE
205};
206
207struct miscdevice met_device = {
208 .minor = MISC_DYNAMIC_MINOR,
209 .name = "met",
210 .mode = 0664,
211 .fops = &met_file_ops
212};
213EXPORT_SYMBOL(met_device);
214
215static int met_run(void)
216{
217 sampler_start();
218#ifdef MET_USER_EVENT_SUPPORT
219 bltab.flag &= (~MET_CLASS_ALL);
220#endif
221
222#if IS_ENABLED(CONFIG_MTK_TINYSYS_SSPM_SUPPORT)
223#if defined(ONDIEMET_SUPPORT) || defined(TINYSYS_SSPM_SUPPORT)
224 ondiemet_start();
225#endif
226#endif
227
228 return 0;
229}
230
231static void met_stop(void)
232{
233#ifdef MET_USER_EVENT_SUPPORT
234 bltab.flag |= MET_CLASS_ALL;
235#endif
236 sampler_stop();
237
238#if IS_ENABLED(CONFIG_MTK_TINYSYS_SSPM_SUPPORT)
239#if defined(ONDIEMET_SUPPORT) || defined(TINYSYS_SSPM_SUPPORT)
240 /* the met.ko will be use by script "cat ...", release it */
241 if ((ondiemet_module[ONDIEMET_SSPM] == 0) || (sspm_buffer_size == -1))
242 ondiemet_log_manager_stop();
243 ondiemet_stop();
244 ondiemet_extract();
245#endif
246#endif
247}
248
249static ssize_t ver_show(struct device *dev, struct device_attribute *attr, char *buf)
250{
251 int i;
252
253 mutex_lock(&dev->mutex);
254 i = snprintf(buf, PAGE_SIZE, "%s\n", MET_BACKEND_VERSION);
255 mutex_unlock(&dev->mutex);
256 return i;
257}
258
259static ssize_t devices_show(struct device *dev, struct device_attribute *attr, char *buf)
260{
261 int len, total_len = 0;
262 struct metdevice *c = NULL;
263
264 mutex_lock(&dev->mutex);
265 list_for_each_entry(c, &met_list, list) {
266 len = 0;
267 if (c->type == MET_TYPE_PMU)
268 len = snprintf(buf, PAGE_SIZE - total_len, "pmu/%s:0\n", c->name);
269 else if (c->type == MET_TYPE_BUS)
270 len = snprintf(buf, PAGE_SIZE - total_len, "bus/%s:0\n", c->name);
271 else if (c->type == MET_TYPE_MISC)
272 len = snprintf(buf, PAGE_SIZE - total_len, "misc/%s:0\n", c->name);
273
274 if (c->ondiemet_mode == 0) {
275 if (c->process_argument)
276 buf[len - 2]++;
277 } else if (c->ondiemet_mode == 1) {
278 if (c->ondiemet_process_argument)
279 buf[len - 2]++;
280 } else if (c->ondiemet_mode == 2) {
281 if (c->process_argument)
282 buf[len - 2]++;
283 if (c->ondiemet_process_argument)
284 buf[len - 2]++;
285 }
286
287 buf += len;
288 total_len += len;
289 }
290
291 mutex_unlock(&dev->mutex);
292 return total_len;
293}
294
295static char met_platform[16] = "none";
296static ssize_t plf_show(struct device *dev, struct device_attribute *attr, char *buf)
297{
298 int i;
299
300 mutex_lock(&dev->mutex);
301 i = snprintf(buf, PAGE_SIZE, "%s\n", met_platform);
302 mutex_unlock(&dev->mutex);
303 return i;
304}
305
306static unsigned int met_chip_id = 0;
307static ssize_t chip_id_show(struct device *dev, struct device_attribute *attr, char *buf)
308{
309 int i;
310
311 mutex_lock(&dev->mutex);
312 i = snprintf(buf, PAGE_SIZE, "0x%08X\n", met_chip_id);
313 mutex_unlock(&dev->mutex);
314 return i;
315}
316
317static char met_topology[64] = "none";
318static ssize_t core_topology_show(struct device *dev, struct device_attribute *attr, char *buf)
319{
320 int i;
321
322 mutex_lock(&dev->mutex);
323 i = snprintf(buf, PAGE_SIZE, "%s\n", met_topology);
324 mutex_unlock(&dev->mutex);
325 return i;
326}
327
328static ssize_t ctrl_show(struct device *dev, struct device_attribute *attr, char *buf)
329{
330 return snprintf(buf, PAGE_SIZE, "%d\n", ctrl_flags);
331}
332
333static ssize_t ctrl_store(struct device *dev, struct device_attribute *attr, const char *buf,
334 size_t count)
335{
336 unsigned int value = 0;
337
338 if (met_parse_num(buf, &value, count) < 0)
339 return -EINVAL;
340
341 ctrl_flags = value;
342 return count;
343}
344
345static ssize_t cpu_pmu_method_show(struct device *dev, struct device_attribute *attr, char *buf)
346{
347 return snprintf(buf, PAGE_SIZE, "%d\n", met_cpu_pmu_method);
348}
349
350static ssize_t cpu_pmu_method_store(struct device *dev, struct device_attribute *attr, const char *buf,
351 size_t count)
352{
353 unsigned int value = 0;
354
355 if (met_parse_num(buf, &value, count) < 0)
356 return -EINVAL;
357
358 met_cpu_pmu_method = value;
359 return count;
360}
361
362static ssize_t cpu_pm_pmu_reconfig_show(struct device *dev,
363 struct device_attribute *attr,
364 char *buf)
365{
366 return snprintf(buf, PAGE_SIZE, "%d\n", met_cpu_pm_pmu_reconfig);
367}
368
369static ssize_t cpu_pm_pmu_reconfig_store(struct device *dev,
370 struct device_attribute *attr,
371 const char *buf,
372 size_t count)
373{
374 unsigned int value = 0;
375
376 if (met_parse_num(buf, &value, count) < 0)
377 return -EINVAL;
378
379 met_cpu_pm_pmu_reconfig = value;
380 return count;
381}
382
383static void _test_trace_ipi_raise(void *info)
384{
385 unsigned int *cpu = (unsigned int *)info;
386
387 if (met_export_api_symbol->met_arch_send_call_function_single_ipi)
388 met_export_api_symbol->met_arch_send_call_function_single_ipi(*cpu);
389}
390
391
392static ssize_t ipi_test_store(struct device *dev, struct device_attribute *attr, const char *buf,
393 size_t count)
394{
395 int this_cpu = smp_processor_id();
396 unsigned int cpu = 0;
397 unsigned int value = 0;
398
399 if (met_parse_num(buf, &value, count) < 0)
400 return -EINVAL;
401
402 cpu = value;
403 if (cpu == this_cpu)
404 _test_trace_ipi_raise(&cpu);
405 else {
406 if (met_export_api_symbol->met_smp_call_function_single)
407 met_export_api_symbol->met_smp_call_function_single(cpu,
408 _test_trace_ipi_raise, &cpu, 1);
409 }
410
411 return count;
412}
413
414
415#if defined(MET_BOOT_MSG)
416char met_boot_msg_tmp[256];
417char met_boot_msg[PAGE_SIZE];
418int met_boot_msg_idx;
419
420int pr_bootmsg(int str_len, char *str)
421{
422 if (met_boot_msg_idx+str_len+1 > PAGE_SIZE)
423 return -1;
424 memcpy(met_boot_msg+met_boot_msg_idx, str, str_len);
425 met_boot_msg_idx += str_len;
426 return 0;
427}
428
429static ssize_t bootmsg_show(struct device *dev, struct device_attribute *attr, char *buf)
430{
431 int i;
432
433 mutex_lock(&dev->mutex);
434 i = snprintf(buf, PAGE_SIZE, "%s\n", met_boot_msg);
435 mutex_unlock(&dev->mutex);
436 return i;
437}
438
439static DEVICE_ATTR_RO(bootmsg);
440EXPORT_SYMBOL(met_boot_msg_tmp);
441EXPORT_SYMBOL(pr_bootmsg);
442#endif
443
444static ssize_t spr_show(struct device *dev, struct device_attribute *attr, char *buf)
445{
446 int i;
447
448 mutex_lock(&dev->mutex);
449 i = snprintf(buf, PAGE_SIZE, "%d\n", sample_rate);
450 mutex_unlock(&dev->mutex);
451 return i;
452}
453
454static ssize_t spr_store(struct device *dev, struct device_attribute *attr, const char *buf,
455 size_t count)
456{
457 int value;
458 struct metdevice *c = NULL;
459
460 mutex_lock(&dev->mutex);
461
462 if ((run == 1) || (count == 0) || (buf == NULL)) {
463 mutex_unlock(&dev->mutex);
464 return -EINVAL;
465 }
466 if (kstrtoint(buf, 0, &value) != 0) {
467 mutex_unlock(&dev->mutex);
468 return -EINVAL;
469 }
470
471 if ((value < 0) || (value > 10000)) {
472 mutex_unlock(&dev->mutex);
473 return -EINVAL;
474 }
475
476 calc_timer_value(value);
477
478 list_for_each_entry(c, &met_list, list) {
479 if (c->polling_interval > 0)
480 c->polling_count_reload = ((c->polling_interval * sample_rate) - 1) / 1000;
481 else
482 c->polling_count_reload = 0;
483 }
484
485 mutex_unlock(&dev->mutex);
486
487 return count;
488}
489
490static ssize_t run_show(struct device *dev, struct device_attribute *attr, char *buf)
491{
492 int i;
493
494 mutex_lock(&dev->mutex);
495 i = snprintf(buf, PAGE_SIZE, "%d\n", run);
496 mutex_unlock(&dev->mutex);
497 return i;
498}
499
500static ssize_t run_store(struct device *dev, struct device_attribute *attr, const char *buf,
501 size_t count)
502{
503 int value;
504
505 mutex_lock(&dev->mutex);
506
507 if ((count == 0) || (buf == NULL)) {
508 mutex_unlock(&dev->mutex);
509 return -EINVAL;
510 }
511 if (kstrtoint(buf, 0, &value) != 0) {
512 mutex_unlock(&dev->mutex);
513 return -EINVAL;
514 }
515
516 switch (value) {
517 case 1:
518 if (run != 1) {
519 run = 1;
520 met_run();
521 }
522 break;
523 case 0:
524 if (run != 0) {
525 if (run == 1) {
526 met_stop();
527#ifdef MET_USER_EVENT_SUPPORT
528#ifdef CONFIG_MET_MODULE
529 met_save_dump_buffer_real("/data/trace.dump");
530#else
531 met_save_dump_buffer("/data/trace.dump");
532#endif
533#endif
534 run = 0;
535 } else
536 /* run == -1 */
537 run = 0;
538 }
539 break;
540 case -1:
541 if (run != -1) {
542 if (run == 1)
543 met_stop();
544
545 run = -1;
546 }
547 break;
548 default:
549 mutex_unlock(&dev->mutex);
550 return -EINVAL;
551 }
552
553 mutex_unlock(&dev->mutex);
554
555 return count;
556}
557
558static unsigned int met_ksym_addr;
559static char met_func_name[512];
560static ssize_t ksym_show(struct device *dev, struct device_attribute *attr, char *buf)
561{
562 int i;
563 int len = 0;
564 int idx = 0;
565
566 mutex_lock(&dev->mutex);
567 if (met_ksym_addr != 0)
568 len = sprint_symbol_no_offset(met_func_name, met_ksym_addr);
569 if (len != 0) {
570 for (idx = 0; idx < 512; idx++)
571 if (met_func_name[idx] == ' ')
572 met_func_name[idx] = '\0';
573 i = snprintf(buf, PAGE_SIZE, "%s\n", met_func_name);
574 } else
575 i = snprintf(buf, PAGE_SIZE, "ksymlookup fail(%x)\n", met_ksym_addr);
576
577 mutex_unlock(&dev->mutex);
578 return i;
579}
580
581static ssize_t ksym_store(struct device *dev, struct device_attribute *attr, const char *buf,
582 size_t count)
583{
584 mutex_lock(&dev->mutex);
585
586 if ((count == 0) || (buf == NULL)) {
587 mutex_unlock(&dev->mutex);
588 return -EINVAL;
589 }
590 if (kstrtoint(buf, 16, &met_ksym_addr) != 0) {
591 mutex_unlock(&dev->mutex);
592 return -EINVAL;
593 }
594
595 mutex_unlock(&dev->mutex);
596
597 return count;
598}
599
600#if defined(PR_CPU_NOTIFY)
601static ssize_t cpu_notify_show(struct device *dev, struct device_attribute *attr, char *buf)
602{
603 int i;
604
605 i = snprintf(buf, PAGE_SIZE, "%d\n", met_cpu_notify);
606 return i;
607}
608
609static ssize_t cpu_notify_store(struct device *dev, struct device_attribute *attr, const char *buf,
610 size_t count)
611{
612 if ((count == 0) || (buf == NULL))
613 return -EINVAL;
614
615 if (kstrtoint(buf, 0, &met_cpu_notify) != 0)
616 return -EINVAL;
617
618 return count;
619}
620#endif
621
622#if IS_ENABLED(CONFIG_CPU_FREQ)
623static ssize_t dvfs_show(struct device *dev, struct device_attribute *attr, char *buf)
624{
625 int i;
626
627 i = snprintf(buf, PAGE_SIZE, "%d\n", 0);
628 return i;
629}
630
631static ssize_t dvfs_store(struct device *dev, struct device_attribute *attr, const char *buf,
632 size_t count)
633{
634 return count;
635}
636#endif
637
638static ssize_t suspend_compensation_enable_show(struct device *dev, struct device_attribute *attr, char *buf)
639{
640 int ret;
641
642 ret = snprintf(buf, PAGE_SIZE, "%d\n", met_suspend_compensation_mode);
643
644 return ret;
645}
646
647static ssize_t suspend_compensation_enable_store(struct device *dev, struct device_attribute *attr,
648 const char *buf, size_t count)
649{
650 int value;
651
652 if ((count == 0) || (buf == NULL))
653 return -EINVAL;
654
655 if (kstrtoint(buf, 0, &value) != 0)
656 return -EINVAL;
657
658 if (value < 0)
659 return -EINVAL;
660
661 met_suspend_compensation_mode = value;
662
663 return count;
664}
665
666static ssize_t suspend_compensation_flag_show(struct device *dev, struct device_attribute *attr, char *buf)
667{
668 int ret;
669
670 ret = snprintf(buf, PAGE_SIZE, "%d\n", met_suspend_compensation_flag);
671
672 return ret;
673}
674
675static ssize_t hash_show(struct device *dev, struct device_attribute *attr, char *buf)
676{
677 return 0;
678}
679
680static ssize_t hash_store(struct device *dev, struct device_attribute *attr, const char *buf,
681 size_t count)
682{
683 return 0;
684}
685
686static DEVICE_ATTR(hash, 0664, hash_show, hash_store);
687
688static ssize_t mode_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
689{
690 struct metdevice *c = NULL;
691
692 list_for_each_entry(c, &met_list, list) {
693 if (c->kobj == kobj)
694 break;
695 }
696 if (c == NULL)
697 return -ENOENT;
698
699 return snprintf(buf, PAGE_SIZE, "%d\n", c->mode);
700}
701
702static ssize_t mode_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf,
703 size_t n)
704{
705 struct metdevice *c = NULL;
706
707 list_for_each_entry(c, &met_list, list) {
708 if (c->kobj == kobj)
709 break;
710 }
711 if (c == NULL)
712 return -ENOENT;
713
714 if (kstrtoint(buf, 0, &(c->mode)) != 0)
715 return -EINVAL;
716
717 return n;
718}
719
720static struct kobj_attribute mode_attr = __ATTR(mode, 0664, mode_show, mode_store);
721
722static ssize_t ondiemet_mode_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
723{
724 struct metdevice *c = NULL;
725
726 list_for_each_entry(c, &met_list, list) {
727 if (c->kobj == kobj)
728 break;
729 }
730 if (c == NULL)
731 return -ENOENT;
732
733 return snprintf(buf, PAGE_SIZE, "%d\n", c->ondiemet_mode);
734}
735
736static ssize_t ondiemet_mode_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf,
737 size_t n)
738{
739 struct metdevice *c = NULL;
740
741 list_for_each_entry(c, &met_list, list) {
742 if (c->kobj == kobj)
743 break;
744 }
745 if (c == NULL)
746 return -ENOENT;
747
748 if (kstrtoint(buf, 0, &(c->ondiemet_mode)) != 0)
749 return -EINVAL;
750
751 return n;
752}
753
754static struct kobj_attribute ondiemet_mode_attr = __ATTR(ondiemet_mode, 0664, ondiemet_mode_show, ondiemet_mode_store);
755
756static ssize_t polling_interval_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
757{
758 int interval = 1;
759 struct metdevice *c = NULL;
760
761 list_for_each_entry(c, &met_list, list) {
762 if (c->kobj == kobj)
763 break;
764 }
765 if (c == NULL)
766 return -ENOENT;
767
768 if (c->polling_interval)
769 interval = c->polling_interval;
770
771 return snprintf(buf, PAGE_SIZE, "%d\n", interval);
772}
773
774static ssize_t polling_interval_store(struct kobject *kobj, struct kobj_attribute *attr,
775 const char *buf, size_t n)
776{
777 struct metdevice *c = NULL;
778
779 list_for_each_entry(c, &met_list, list) {
780 if (c->kobj == kobj)
781 break;
782 }
783 if (c == NULL)
784 return -ENOENT;
785
786 if (kstrtoint(buf, 0, &(c->polling_interval)) != 0)
787 return -EINVAL;
788
789 if (c->polling_interval > 0)
790 c->polling_count_reload = ((c->polling_interval * sample_rate) - 1) / 1000;
791 else
792 c->polling_count_reload = 0;
793
794 return n;
795}
796
797static struct kobj_attribute polling_interval_attr =
798__ATTR(polling_ms, 0664, polling_interval_show, polling_interval_store);
799
800static ssize_t header_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
801{
802 struct metdevice *c = NULL;
803 ssize_t count = 0;
804
805 list_for_each_entry(c, &met_list, list) {
806 if (c->kobj == kobj)
807 break;
808 }
809 if (c == NULL)
810 return -ENOENT;
811
812 if (c->ondiemet_mode == 0) {
813 if ((c->mode) && (c->print_header))
814 return c->print_header(buf, PAGE_SIZE);
815 } else if (c->ondiemet_mode == 1) {
816 if ((c->mode) && (c->ondiemet_print_header))
817 return c->ondiemet_print_header(buf, PAGE_SIZE);
818 } else if (c->ondiemet_mode == 2) {
819 if ((c->mode) && (c->print_header))
820 count = c->print_header(buf, PAGE_SIZE);
821 if (count < PAGE_SIZE) {
822 if ((c->mode) && (c->ondiemet_print_header))
823 count += c->ondiemet_print_header(buf+count, PAGE_SIZE - count);
824 }
825 return count;
826 }
827
828 return 0;
829}
830
831static struct kobj_attribute header_attr = __ATTR(header, 0444, header_show, NULL);
832
833static ssize_t help_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
834{
835 struct metdevice *c = NULL;
836 ssize_t count = 0;
837
838 list_for_each_entry(c, &met_list, list) {
839 if (c->kobj == kobj)
840 break;
841 }
842 if (c == NULL)
843 return -ENOENT;
844
845 if (c->ondiemet_mode == 0) {
846 if (c->print_help)
847 return c->print_help(buf, PAGE_SIZE);
848 } else if (c->ondiemet_mode == 1) {
849 if (c->ondiemet_print_help)
850 return c->ondiemet_print_help(buf, PAGE_SIZE);
851 } else if (c->ondiemet_mode == 2) {
852 if (c->print_help)
853 count = c->print_help(buf, PAGE_SIZE);
854 if (count < PAGE_SIZE) {
855 if (c->ondiemet_print_help)
856 count += c->ondiemet_print_help(buf+count, PAGE_SIZE - count);
857 }
858 return count;
859 }
860
861 return 0;
862}
863
864static struct kobj_attribute help_attr = __ATTR(help, 0444, help_show, NULL);
865
866static int argu_status = -1;
867static ssize_t argu_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf,
868 size_t n)
869{
870 int ret = 0;
871 struct metdevice *c = NULL;
872
873 argu_status = -1;
874
875 list_for_each_entry(c, &met_list, list) {
876 if (c->kobj == kobj)
877 break;
878 }
879 if (c == NULL)
880 return -ENOENT;
881
882 if (c->ondiemet_mode == 0) {
883 if (c->process_argument)
884 ret = c->process_argument(buf, (int)n);
885 } else if (c->ondiemet_mode == 1) {
886 if (c->ondiemet_process_argument)
887 ret = c->ondiemet_process_argument(buf, (int)n);
888 } else if (c->ondiemet_mode == 2) {
889 if (c->process_argument)
890 ret = c->process_argument(buf, (int)n);
891 if (c->ondiemet_process_argument)
892 ret = c->ondiemet_process_argument(buf, (int)n);
893 }
894
895 if (ret != 0)
896 return -EINVAL;
897
898 argu_status = 0;
899 return n;
900}
901
902static ssize_t argu_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
903{
904 return snprintf(buf, PAGE_SIZE, "%d\n", argu_status);
905}
906
907static struct kobj_attribute argu_attr = __ATTR(argu, 0664, argu_show, argu_store);
908
909static ssize_t reset_store(struct kobject *kobj,
910 struct kobj_attribute *attr,
911 const char *buf,
912 size_t n)
913{
914 int ret = 0;
915 struct metdevice *c = NULL;
916
917 list_for_each_entry(c, &met_list, list) {
918 if (c->kobj == kobj)
919 break;
920 }
921 if (c == NULL)
922 return -ENOENT;
923
924 if (c->ondiemet_mode == 0) {
925 if (c->reset)
926 ret = c->reset();
927 else
928 c->mode = 0;
929 } else if (c->ondiemet_mode == 1) {
930 if (c->ondiemet_reset)
931 ret = c->ondiemet_reset();
932 } else if (c->ondiemet_mode == 2) {
933 if (c->reset)
934 ret = c->reset();
935 else
936 c->mode = 0;
937 if (c->ondiemet_reset)
938 ret = c->ondiemet_reset();
939 }
940
941 if (ret != 0)
942 return -EINVAL;
943
944 return n;
945}
946
947static struct kobj_attribute reset_attr = __ATTR(reset, 0220, NULL, reset_store);
948
949static ssize_t header_read_again_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
950{
951 struct metdevice *c = NULL;
952
953 list_for_each_entry(c, &met_list, list) {
954 if (c->kobj == kobj)
955 break;
956 }
957 if (c == NULL)
958 return -ENOENT;
959
960 return snprintf(buf, PAGE_SIZE, "%d\n", c->header_read_again);
961}
962
963static struct kobj_attribute header_read_again_attr = __ATTR(header_read_again, 0664, header_read_again_show, NULL);
964
965
966int met_register(struct metdevice *met)
967{
968 int ret, cpu;
969 struct metdevice *c;
970
971 list_for_each_entry(c, &met_list, list) {
972 if (!strcmp(c->name, met->name))
973 return -EEXIST;
974 }
975
976 PR_BOOTMSG("met_register %s ...\n", met->name);
977
978 INIT_LIST_HEAD(&met->list);
979
980 /* Allocate timer count for per CPU */
981 met->polling_count = alloc_percpu(int);
982 if (met->polling_count == NULL)
983 return -EINVAL;
984
985 for_each_possible_cpu(cpu)
986 *(per_cpu_ptr(met->polling_count, cpu)) = 0;
987
988 if (met->polling_interval > 0) {
989 ret = ((met->polling_interval * sample_rate) - 1) / 1000;
990 met->polling_count_reload = ret;
991 } else
992 met->polling_count_reload = 0;
993
994 met->kobj = NULL;
995
996 if (met->type == MET_TYPE_BUS)
997 met->kobj = kobject_create_and_add(met->name, kobj_bus);
998 else if (met->type == MET_TYPE_PMU)
999 met->kobj = kobject_create_and_add(met->name, kobj_pmu);
1000 else if (met->type == MET_TYPE_MISC)
1001 met->kobj = kobject_create_and_add(met->name, kobj_misc);
1002 else {
1003 ret = -EINVAL;
1004 goto err_out;
1005 }
1006
1007 if (met->kobj == NULL) {
1008 ret = -EINVAL;
1009 goto err_out;
1010 }
1011
1012 if (met->create_subfs) {
1013 ret = met->create_subfs(met->kobj);
1014 if (ret)
1015 goto err_out;
1016 }
1017
1018 ret = sysfs_create_file(met->kobj, &mode_attr.attr);
1019 if (ret)
1020 goto err_out;
1021
1022
1023 ret = sysfs_create_file(met->kobj, &ondiemet_mode_attr.attr);
1024 if (ret)
1025 goto err_out;
1026
1027 ret = sysfs_create_file(met->kobj, &polling_interval_attr.attr);
1028 if (ret)
1029 goto err_out;
1030
1031 ret = sysfs_create_file(met->kobj, &header_read_again_attr.attr);
1032 if (ret)
1033 goto err_out;
1034
1035 if (met->print_header || met->ondiemet_print_header) {
1036 ret = sysfs_create_file(met->kobj, &header_attr.attr);
1037 if (ret)
1038 goto err_out;
1039 }
1040
1041 if (met->print_help || met->ondiemet_print_help) {
1042 ret = sysfs_create_file(met->kobj, &help_attr.attr);
1043 if (ret)
1044 goto err_out;
1045 }
1046
1047 if (met->process_argument || met->ondiemet_process_argument) {
1048 ret = sysfs_create_file(met->kobj, &argu_attr.attr);
1049 if (ret)
1050 goto err_out;
1051 }
1052
1053 if (met->reset) {
1054 ret = sysfs_create_file(met->kobj, &reset_attr.attr);
1055 if (ret)
1056 goto err_out;
1057 }
1058
1059 spin_lock_init(&met->my_lock);
1060
1061 list_add(&met->list, &met_list);
1062 return 0;
1063
1064 err_out:
1065
1066 if (met->polling_count)
1067 free_percpu(met->polling_count);
1068
1069 if (met->kobj) {
1070 kobject_del(met->kobj);
1071 kobject_put(met->kobj);
1072 met->kobj = NULL;
1073 }
1074
1075 return ret;
1076}
1077EXPORT_SYMBOL(met_register);
1078
1079int met_deregister(struct metdevice *met)
1080{
1081 struct metdevice *c = NULL;
1082
1083 list_for_each_entry(c, &met_list, list) {
1084 if (c == met)
1085 break;
1086 }
1087 if (c != met)
1088 return -ENOENT;
1089
1090 if (met->print_header || met->ondiemet_print_header)
1091 sysfs_remove_file(met->kobj, &header_attr.attr);
1092
1093 if (met->print_help || met->ondiemet_print_help)
1094 sysfs_remove_file(met->kobj, &help_attr.attr);
1095
1096 if (met->process_argument || met->ondiemet_process_argument)
1097 sysfs_remove_file(met->kobj, &argu_attr.attr);
1098
1099 sysfs_remove_file(met->kobj, &reset_attr.attr);
1100 sysfs_remove_file(met->kobj, &header_read_again_attr.attr);
1101 sysfs_remove_file(met->kobj, &polling_interval_attr.attr);
1102 sysfs_remove_file(met->kobj, &mode_attr.attr);
1103 sysfs_remove_file(met->kobj, &ondiemet_mode_attr.attr);
1104
1105 if (met->delete_subfs)
1106 met->delete_subfs();
1107
1108 kobject_del(met->kobj);
1109 kobject_put(met->kobj);
1110 met->kobj = NULL;
1111
1112 if (met->polling_count)
1113 free_percpu(met->polling_count);
1114
1115 list_del(&met->list);
1116 return 0;
1117}
1118EXPORT_SYMBOL(met_deregister);
1119
1120int met_set_platform(const char *plf_name, int flag)
1121{
1122 strncpy(met_platform, plf_name, sizeof(met_platform) - 1);
1123#if 0
1124 int ret;
1125
1126 if (flag) {
1127 ret = device_create_file(met_device.this_device, &dev_attr_plf);
1128 if (ret != 0) {
1129 pr_debug("can not create device file: plf\n");
1130 return ret;
1131 }
1132 strncpy(met_platform, plf_name, sizeof(met_platform) - 1);
1133 } else
1134 device_remove_file(met_device.this_device, &dev_attr_plf);
1135
1136#endif
1137 return 0;
1138}
1139EXPORT_SYMBOL(met_set_platform);
1140
1141char *met_get_platform(void)
1142{
1143 return met_platform;
1144}
1145EXPORT_SYMBOL(met_get_platform);
1146
1147int met_set_chip_id(const unsigned int chip_id)
1148{
1149 met_chip_id = chip_id;
1150
1151 return 0;
1152}
1153EXPORT_SYMBOL(met_set_chip_id);
1154
1155const unsigned int met_get_chip_id(void)
1156{
1157 return met_chip_id;
1158}
1159EXPORT_SYMBOL(met_get_chip_id);
1160
1161unsigned int met_get_chipid_from_atag(void)
1162{
1163 struct device_node *chosen_node;
1164 struct tag_chipid *chip_id;
1165 int len;
1166
1167 chosen_node = of_find_node_by_path("/chosen");
1168 if (!chosen_node)
1169 chosen_node = of_find_node_by_path("/chosen@0");
1170
1171 if (chosen_node) {
1172 chip_id = (struct tag_chipid*) of_get_property(chosen_node, "atag,chipid", &len);
1173 if (chip_id == NULL) {
1174 PR_BOOTMSG("Warning: could not found atag,chipid in chosen\n");
1175 return -1;
1176 }
1177 } else {
1178 PR_BOOTMSG("Warning: chosen node not found in device tree\n");
1179 return -1;
1180 }
1181
1182 return chip_id->hw_code;
1183}
1184
1185int met_set_topology(const char *topology_name, int flag)
1186{
1187 strncpy(met_topology, topology_name, sizeof(met_topology) - 1);
1188#if 0
1189 int ret;
1190
1191 if (flag) {
1192 ret = device_create_file(met_device.this_device, &dev_attr_core_topology);
1193 if (ret != 0) {
1194 pr_debug("can not create device file: topology\n");
1195 return ret;
1196 }
1197 strncpy(met_topology, topology_name, sizeof(met_topology) - 1);
1198 } else {
1199 device_remove_file(met_device.this_device, &dev_attr_core_topology);
1200 }
1201#endif
1202 return 0;
1203}
1204EXPORT_SYMBOL(met_set_topology);
1205
1206#include "met_struct.h"
1207
1208void force_sample(void *unused)
1209{
1210 int cpu;
1211 unsigned long long stamp;
1212 struct metdevice *c;
1213 struct met_cpu_struct *met_cpu_ptr;
1214
1215 if ((run != 1) || (sample_rate == 0))
1216 return;
1217
1218 /* to avoid met tag is coming after __met_hrtimer_stop and before run=-1 */
1219 met_cpu_ptr = this_cpu_ptr(&met_cpu);
1220 if (met_cpu_ptr->work_enabled == 0)
1221 return;
1222
1223 cpu = smp_processor_id();
1224
1225 stamp = cpu_clock(cpu);
1226
1227 list_for_each_entry(c, &met_list, list) {
1228 if (c->ondiemet_mode == 0) {
1229 if ((c->mode != 0) && (c->tagged_polling != NULL))
1230 c->tagged_polling(stamp, 0);
1231 } else if (c->ondiemet_mode == 1) {
1232 if ((c->mode != 0) && (c->ondiemet_tagged_polling != NULL))
1233 c->ondiemet_tagged_polling(stamp, 0);
1234 } else if (c->ondiemet_mode == 2) {
1235 if ((c->mode != 0) && (c->tagged_polling != NULL))
1236 c->tagged_polling(stamp, 0);
1237 if ((c->mode != 0) && (c->ondiemet_tagged_polling != NULL))
1238 c->ondiemet_tagged_polling(stamp, 0);
1239 }
1240 }
1241}
1242
1243#define MET_SUSPEND_HAND
1244#ifdef MET_SUSPEND_HAND
1245static struct syscore_ops met_hrtimer_ops = {
1246 .suspend = met_hrtimer_suspend,
1247 .resume = met_hrtimer_resume,
1248};
1249#endif
1250
1251int fs_reg(int met_minor)
1252{
1253 int ret = -1;
1254
1255 ctrl_flags = 0;
1256 met_mode = 0;
1257
1258#ifdef MET_SUSPEND_HAND
1259 /* suspend/resume function handle register */
1260 register_syscore_ops(&met_hrtimer_ops);
1261#endif
1262
1263 calc_timer_value(sample_rate);
1264
1265 if ( met_minor != -1)
1266 met_device.minor = met_minor;
1267 ret = misc_register(&met_device);
1268 if (ret != 0) {
1269 pr_debug("misc register failed, minor = %d \n", met_device.minor);
1270 return ret;
1271 }
1272
1273 /* dma map config */
1274 /* arch_setup_dma_ops(met_device.this_device, 0, 0, NULL, false); */
1275 if (met_export_api_symbol->met_arch_setup_dma_ops)
1276 met_export_api_symbol->met_arch_setup_dma_ops(met_device.this_device);
1277
1278 ret = device_create_file(met_device.this_device, &dev_attr_ksym);
1279 if (ret != 0) {
1280 pr_debug("can not create device file: ksym\n");
1281 return ret;
1282 }
1283
1284 ret = device_create_file(met_device.this_device, &dev_attr_run);
1285 if (ret != 0) {
1286 pr_debug("can not create device file: run\n");
1287 return ret;
1288 }
1289
1290#if defined(PR_CPU_NOTIFY)
1291 ret = device_create_file(met_device.this_device, &dev_attr_cpu_notify);
1292 if (ret != 0) {
1293 pr_debug("can not create device file: cpu_notify\n");
1294 return ret;
1295 }
1296#endif
1297
1298#if IS_ENABLED(CONFIG_CPU_FREQ)
1299 ret = device_create_file(met_device.this_device, &dev_attr_dvfs);
1300 if (ret != 0) {
1301 pr_debug("can not create device file: dvfs\n");
1302 return ret;
1303 }
1304#endif
1305
1306 ret = device_create_file(met_device.this_device, &dev_attr_suspend_compensation_enable);
1307 if (ret != 0) {
1308 pr_debug("can not create device file: suspend_compensation_enable\n");
1309 return ret;
1310 }
1311
1312 ret = device_create_file(met_device.this_device, &dev_attr_suspend_compensation_flag);
1313 if (ret != 0) {
1314 pr_debug("can not create device file: suspend_compensation_enable\n");
1315 return ret;
1316 }
1317
1318 ret = device_create_file(met_device.this_device, &dev_attr_ver);
1319 if (ret != 0) {
1320 pr_debug("can not create device file: ver\n");
1321 return ret;
1322 }
1323
1324 ret = device_create_file(met_device.this_device, &dev_attr_devices);
1325 if (ret != 0) {
1326 pr_debug("can not create device file: devices\n");
1327 return ret;
1328 }
1329
1330 ret = device_create_file(met_device.this_device, &dev_attr_ctrl);
1331 if (ret != 0) {
1332 pr_debug("can not create device file: ctrl\n");
1333 return ret;
1334 }
1335
1336 ret = device_create_file(met_device.this_device, &dev_attr_cpu_pmu_method);
1337 if (ret != 0) {
1338 pr_debug("can not create device file: cpu_pmu_method\n");
1339 return ret;
1340 }
1341
1342 ret = device_create_file(met_device.this_device, &dev_attr_cpu_pm_pmu_reconfig);
1343 if (ret != 0) {
1344 pr_debug("can not create device file: cpu_pm_pmu_reconfig\n");
1345 return ret;
1346 }
1347
1348#if defined(MET_BOOT_MSG)
1349 ret = device_create_file(met_device.this_device, &dev_attr_bootmsg);
1350 if (ret != 0) {
1351 pr_debug("can not create device file: bootmsg\n");
1352 return ret;
1353 }
1354#endif
1355
1356 ret = device_create_file(met_device.this_device, &dev_attr_sample_rate);
1357 if (ret != 0) {
1358 pr_debug("can not create device file: sample_rate\n");
1359 return ret;
1360 }
1361
1362 ret = device_create_file(met_device.this_device, &dev_attr_core_topology);
1363 if (ret != 0) {
1364 pr_debug("can not create device file: topology\n");
1365 return ret;
1366 }
1367
1368 ret = device_create_file(met_device.this_device, &dev_attr_plf);
1369 if (ret != 0) {
1370 pr_debug("can not create device file: plf\n");
1371 return ret;
1372 }
1373
1374 ret = device_create_file(met_device.this_device, &dev_attr_chip_id);
1375 if (ret != 0) {
1376 pr_debug("can not create device file: chip_id\n");
1377 return ret;
1378 }
1379
1380 ret = device_create_file(met_device.this_device, &dev_attr_hash);
1381 if (ret != 0) {
1382 pr_debug("can not create device file: hash\n");
1383 return ret;
1384 }
1385
1386 ret = device_create_file(met_device.this_device, &dev_attr_ipi_test);
1387 if (ret != 0) {
1388 pr_debug("can not create device file: ipi_test\n");
1389 return ret;
1390 }
1391
1392 kobj_misc = kobject_create_and_add("misc", &met_device.this_device->kobj);
1393 if (kobj_misc == NULL) {
1394 pr_debug("can not create kobject: kobj_misc\n");
1395 return -1;
1396 }
1397
1398 kobj_pmu = kobject_create_and_add("pmu", &met_device.this_device->kobj);
1399 if (kobj_pmu == NULL) {
1400 pr_debug("can not create kobject: kobj_pmu\n");
1401 return -1;
1402 }
1403
1404 kobj_bus = kobject_create_and_add("bus", &met_device.this_device->kobj);
1405 if (kobj_bus == NULL) {
1406 pr_debug("can not create kobject: kobj_bus\n");
1407 return -1;
1408 }
1409
1410 met_register(&met_cookie);
1411 met_register(&met_cpupmu);
1412 met_register(&met_memstat);
1413 met_register(&met_switch);
1414 met_register_api_symbol->met_sched_switch = met_sched_switch;
1415#ifdef MET_EVENT_POWER_SUPPORT
1416 met_register(&met_trace_event);
1417 met_register_api_symbol->met_pm_qos_update_request = pm_qos_update_request;
1418 met_register_api_symbol->met_pm_qos_update_target = pm_qos_update_target;
1419#endif
1420
1421 met_register(&met_dummy_header);
1422#ifdef FEATURE_CPU_EB_NUM
1423#if FEATURE_CPU_EB_NUM
1424 met_register(&met_cpu_eb);
1425#endif
1426#endif
1427
1428#ifdef MET_USER_EVENT_SUPPORT
1429 tag_reg((struct file_operations * const) met_device.fops, &met_device.this_device->kobj);
1430#endif
1431
1432 met_register(&met_stat);
1433
1434#if IS_ENABLED(CONFIG_MTK_TINYSYS_SSPM_SUPPORT)
1435#if defined(ONDIEMET_SUPPORT) || defined(TINYSYS_SSPM_SUPPORT)
1436 ondiemet_log_manager_init(met_device.this_device);
1437 ondiemet_attr_init(met_device.this_device);
1438#endif
1439#endif
1440
1441 return 0;
1442}
1443
1444void fs_unreg(void)
1445{
1446 if (run == 1)
1447 met_stop();
1448
1449 run = -1;
1450
1451 met_deregister(&met_stat);
1452
1453#ifdef MET_USER_EVENT_SUPPORT
1454 tag_unreg();
1455#endif
1456
1457#ifdef FEATURE_CPU_EB_NUM
1458#if FEATURE_CPU_EB_NUM
1459 met_deregister(&met_cpu_eb);
1460#endif
1461#endif
1462
1463 met_deregister(&met_dummy_header);
1464#ifdef MET_EVENT_POWER_SUPPORT
1465 met_deregister(&met_trace_event);
1466 met_register_api_symbol->met_pm_qos_update_request = NULL;
1467 met_register_api_symbol->met_pm_qos_update_target = NULL;
1468#endif
1469 met_deregister(&met_switch);
1470 met_deregister(&met_memstat);
1471 met_deregister(&met_cpupmu);
1472 met_deregister(&met_cookie);
1473
1474 met_register_api_symbol->met_sched_switch = NULL;
1475
1476 kobject_del(kobj_misc);
1477 kobject_put(kobj_misc);
1478 kobj_misc = NULL;
1479 kobject_del(kobj_pmu);
1480 kobject_put(kobj_pmu);
1481 kobj_pmu = NULL;
1482 kobject_del(kobj_bus);
1483 kobject_put(kobj_bus);
1484 kobj_bus = NULL;
1485
1486 device_remove_file(met_device.this_device, &dev_attr_ksym);
1487
1488 device_remove_file(met_device.this_device, &dev_attr_run);
1489#ifdef PR_CPU_NOTIFY
1490 device_remove_file(met_device.this_device, &dev_attr_cpu_notify);
1491#endif
1492#if IS_ENABLED(CONFIG_CPU_FREQ)
1493 device_remove_file(met_device.this_device, &dev_attr_dvfs);
1494#endif
1495 device_remove_file(met_device.this_device, &dev_attr_suspend_compensation_enable);
1496 device_remove_file(met_device.this_device, &dev_attr_suspend_compensation_flag);
1497
1498 device_remove_file(met_device.this_device, &dev_attr_ver);
1499 device_remove_file(met_device.this_device, &dev_attr_devices);
1500 device_remove_file(met_device.this_device, &dev_attr_sample_rate);
1501
1502 device_remove_file(met_device.this_device, &dev_attr_ctrl);
1503 device_remove_file(met_device.this_device, &dev_attr_cpu_pmu_method);
1504 device_remove_file(met_device.this_device, &dev_attr_cpu_pm_pmu_reconfig);
1505
1506 device_remove_file(met_device.this_device, &dev_attr_core_topology);
1507 device_remove_file(met_device.this_device, &dev_attr_plf);
1508 device_remove_file(met_device.this_device, &dev_attr_chip_id);
1509 device_remove_file(met_device.this_device, &dev_attr_hash);
1510 device_remove_file(met_device.this_device, &dev_attr_ipi_test);
1511
1512#if IS_ENABLED(CONFIG_MTK_TINYSYS_SSPM_SUPPORT)
1513#if defined(ONDIEMET_SUPPORT) || defined(TINYSYS_SSPM_SUPPORT)
1514 ondiemet_log_manager_uninit(met_device.this_device);
1515 ondiemet_attr_uninit(met_device.this_device);
1516#endif
1517#endif
1518
1519 misc_deregister(&met_device);
1520#ifdef MET_SUSPEND_HAND
1521 /* suspend/resume function handle register */
1522 unregister_syscore_ops(&met_hrtimer_ops);
1523#endif
1524}
1525
1526unsigned int get_ctrl_flags(void)
1527{
1528 return ctrl_flags;
1529}