rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2018 MediaTek Inc. |
| 3 | * |
| 4 | * This program is free software: you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | |
| 14 | #ifndef _CPU_PMU_H_ |
| 15 | #define _CPU_PMU_H_ |
| 16 | |
| 17 | #include <linux/device.h> |
| 18 | |
| 19 | #define MODE_DISABLED 0 |
| 20 | #define MODE_INTERRUPT 1 |
| 21 | #define MODE_POLLING 2 |
| 22 | |
| 23 | #define MXSIZE_PMU_DESC 32 |
| 24 | #define MXNR_CPU NR_CPUS |
| 25 | |
| 26 | #define MXNR_PMU_EVENTS 8 /* max number of pmu counter for armv8 is 6+1 */ |
| 27 | struct met_pmu { |
| 28 | unsigned char mode; |
| 29 | unsigned short event; |
| 30 | unsigned long freq; |
| 31 | struct kobject *kobj_cpu_pmu; |
| 32 | }; |
| 33 | |
| 34 | struct cpu_pmu_hw { |
| 35 | const char *name; |
| 36 | const char *cpu_name; |
| 37 | int nr_cnt; |
| 38 | int (*get_event_desc)(int idx, int event, char *event_desc); |
| 39 | int (*check_event)(struct met_pmu *pmu, int idx, int event); |
| 40 | void (*start)(struct met_pmu *pmu, int count); |
| 41 | void (*stop)(int count); |
| 42 | unsigned int (*polling)(struct met_pmu *pmu, int count, unsigned int *pmu_value); |
| 43 | struct met_pmu *pmu[MXNR_CPU]; |
| 44 | int event_count[MXNR_CPU]; |
| 45 | /* |
| 46 | * used for compensation of pmu counter loss |
| 47 | * between end of polling and start of cpu pm |
| 48 | */ |
| 49 | unsigned int cpu_pm_unpolled_loss[MXNR_CPU][MXNR_PMU_EVENTS]; |
| 50 | }; |
| 51 | |
| 52 | struct pmu_desc { |
| 53 | unsigned int event; |
| 54 | char name[MXSIZE_PMU_DESC]; |
| 55 | }; |
| 56 | |
| 57 | struct cpu_pmu_hw *cpu_pmu_hw_init(void); |
| 58 | |
| 59 | extern struct cpu_pmu_hw *cpu_pmu; |
| 60 | extern noinline void mp_cpu(unsigned char cnt, unsigned int *value); |
| 61 | |
| 62 | extern int met_perf_cpupmu_status; |
| 63 | extern void met_perf_cpupmu_polling(unsigned long long stamp, int cpu); |
| 64 | |
| 65 | #endif /* _CPU_PMU_H_ */ |