xref: /illumos-gate/usr/src/uts/intel/io/vmm/amd/svm_pmu.h (revision fdad6fbf87b201fdb96a704fc41fa8be1e4efbc8)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 /* This file is dual-licensed; see usr/src/contrib/bhyve/LICENSE */
12 
13 /*
14  * Copyright 2025 Oxide Computer Company
15  */
16 
17 #ifndef _SVM_PMU_H
18 #define	_SVM_PMU_H
19 
20 #include <sys/stdbool.h>
21 #include <sys/vmm_kernel.h>
22 #include <sys/hma.h>
23 
24 #include "svm_softc.h"
25 
26 #define	SVM_PMU_MAX_COUNTERS	6
27 
28 struct svm_pmu_vcpu {
29 	struct hma_svm_cpc_state spv_hma_state;
30 	uint64_t spv_evtsel_shadow[SVM_PMU_MAX_COUNTERS];
31 	hma_svm_cpc_res_t spv_last_entry;
32 };
33 
34 CTASSERT(SVM_PMU_MAX_COUNTERS == HMA_CPC_REGS_MAX);
35 
36 typedef enum svm_pmu_flavor {
37 	SPF_NONE = 0,
38 	SPF_PRE_ZEN,
39 	SPF_ZEN1,
40 	SPF_ZEN2,
41 } svm_pmu_flavor_t;
42 
43 struct svm_pmu {
44 	bool sp_enabled;
45 	svm_pmu_flavor_t sp_flavor;
46 };
47 
48 void svm_pmu_init(struct svm_softc *);
49 bool svm_pmu_owned_msr(uint32_t);
50 vm_msr_result_t svm_pmu_rdmsr(struct svm_softc *, int, uint32_t, uint64_t *);
51 vm_msr_result_t svm_pmu_wrmsr(struct svm_softc *, int, uint32_t, uint64_t);
52 bool svm_pmu_rdpmc(struct svm_softc *, int, uint32_t, uint64_t *);
53 void svm_pmu_enter(struct svm_softc *, int);
54 void svm_pmu_exit(struct svm_softc *, int);
55 
56 #endif /* _SVM_PMU_H */
57