hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/include/kvm/arm_pmu.h
....@@ -1,18 +1,7 @@
1
+/* SPDX-License-Identifier: GPL-2.0-only */
12 /*
23 * Copyright (C) 2015 Linaro Ltd.
34 * Author: Shannon Zhao <shannon.zhao@linaro.org>
4
- *
5
- * This program is free software; you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License version 2 as
7
- * published by the Free Software Foundation.
8
- *
9
- * This program is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
13
- *
14
- * You should have received a copy of the GNU General Public License
15
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
165 */
176
187 #ifndef __ASM_ARM_KVM_PMU_H
....@@ -22,32 +11,41 @@
2211 #include <asm/perf_event.h>
2312
2413 #define ARMV8_PMU_CYCLE_IDX (ARMV8_PMU_MAX_COUNTERS - 1)
14
+#define ARMV8_PMU_MAX_COUNTER_PAIRS ((ARMV8_PMU_MAX_COUNTERS + 1) >> 1)
2515
26
-#ifdef CONFIG_KVM_ARM_PMU
16
+DECLARE_STATIC_KEY_FALSE(kvm_arm_pmu_available);
17
+
18
+static __always_inline bool kvm_arm_support_pmu_v3(void)
19
+{
20
+ return static_branch_likely(&kvm_arm_pmu_available);
21
+}
22
+
23
+#ifdef CONFIG_HW_PERF_EVENTS
2724
2825 struct kvm_pmc {
2926 u8 idx; /* index into the pmu->pmc array */
3027 struct perf_event *perf_event;
31
- u64 bitmask;
3228 };
3329
3430 struct kvm_pmu {
3531 int irq_num;
3632 struct kvm_pmc pmc[ARMV8_PMU_MAX_COUNTERS];
37
- bool ready;
33
+ DECLARE_BITMAP(chained, ARMV8_PMU_MAX_COUNTER_PAIRS);
3834 bool created;
3935 bool irq_level;
36
+ struct irq_work overflow_work;
4037 };
4138
42
-#define kvm_arm_pmu_v3_ready(v) ((v)->arch.pmu.ready)
4339 #define kvm_arm_pmu_irq_initialized(v) ((v)->arch.pmu.irq_num >= VGIC_NR_SGIS)
4440 u64 kvm_pmu_get_counter_value(struct kvm_vcpu *vcpu, u64 select_idx);
4541 void kvm_pmu_set_counter_value(struct kvm_vcpu *vcpu, u64 select_idx, u64 val);
4642 u64 kvm_pmu_valid_counter_mask(struct kvm_vcpu *vcpu);
43
+u64 kvm_pmu_get_pmceid(struct kvm_vcpu *vcpu, bool pmceid1);
44
+void kvm_pmu_vcpu_init(struct kvm_vcpu *vcpu);
4745 void kvm_pmu_vcpu_reset(struct kvm_vcpu *vcpu);
4846 void kvm_pmu_vcpu_destroy(struct kvm_vcpu *vcpu);
49
-void kvm_pmu_disable_counter(struct kvm_vcpu *vcpu, u64 val);
50
-void kvm_pmu_enable_counter(struct kvm_vcpu *vcpu, u64 val);
47
+void kvm_pmu_disable_counter_mask(struct kvm_vcpu *vcpu, u64 val);
48
+void kvm_pmu_enable_counter_mask(struct kvm_vcpu *vcpu, u64 val);
5149 void kvm_pmu_flush_hwstate(struct kvm_vcpu *vcpu);
5250 void kvm_pmu_sync_hwstate(struct kvm_vcpu *vcpu);
5351 bool kvm_pmu_should_notify_user(struct kvm_vcpu *vcpu);
....@@ -56,7 +54,6 @@
5654 void kvm_pmu_handle_pmcr(struct kvm_vcpu *vcpu, u64 val);
5755 void kvm_pmu_set_counter_event_type(struct kvm_vcpu *vcpu, u64 data,
5856 u64 select_idx);
59
-bool kvm_arm_support_pmu_v3(void);
6057 int kvm_arm_pmu_v3_set_attr(struct kvm_vcpu *vcpu,
6158 struct kvm_device_attr *attr);
6259 int kvm_arm_pmu_v3_get_attr(struct kvm_vcpu *vcpu,
....@@ -68,7 +65,6 @@
6865 struct kvm_pmu {
6966 };
7067
71
-#define kvm_arm_pmu_v3_ready(v) (false)
7268 #define kvm_arm_pmu_irq_initialized(v) (false)
7369 static inline u64 kvm_pmu_get_counter_value(struct kvm_vcpu *vcpu,
7470 u64 select_idx)
....@@ -81,10 +77,11 @@
8177 {
8278 return 0;
8379 }
80
+static inline void kvm_pmu_vcpu_init(struct kvm_vcpu *vcpu) {}
8481 static inline void kvm_pmu_vcpu_reset(struct kvm_vcpu *vcpu) {}
8582 static inline void kvm_pmu_vcpu_destroy(struct kvm_vcpu *vcpu) {}
86
-static inline void kvm_pmu_disable_counter(struct kvm_vcpu *vcpu, u64 val) {}
87
-static inline void kvm_pmu_enable_counter(struct kvm_vcpu *vcpu, u64 val) {}
83
+static inline void kvm_pmu_disable_counter_mask(struct kvm_vcpu *vcpu, u64 val) {}
84
+static inline void kvm_pmu_enable_counter_mask(struct kvm_vcpu *vcpu, u64 val) {}
8885 static inline void kvm_pmu_flush_hwstate(struct kvm_vcpu *vcpu) {}
8986 static inline void kvm_pmu_sync_hwstate(struct kvm_vcpu *vcpu) {}
9087 static inline bool kvm_pmu_should_notify_user(struct kvm_vcpu *vcpu)
....@@ -96,7 +93,6 @@
9693 static inline void kvm_pmu_handle_pmcr(struct kvm_vcpu *vcpu, u64 val) {}
9794 static inline void kvm_pmu_set_counter_event_type(struct kvm_vcpu *vcpu,
9895 u64 data, u64 select_idx) {}
99
-static inline bool kvm_arm_support_pmu_v3(void) { return false; }
10096 static inline int kvm_arm_pmu_v3_set_attr(struct kvm_vcpu *vcpu,
10197 struct kvm_device_attr *attr)
10298 {
....@@ -116,6 +112,10 @@
116112 {
117113 return 0;
118114 }
115
+static inline u64 kvm_pmu_get_pmceid(struct kvm_vcpu *vcpu, bool pmceid1)
116
+{
117
+ return 0;
118
+}
119119 #endif
120120
121121 #endif