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 12 /* 13 * Copyright 2025 Oxide Computer Company 14 */ 15 16 #ifndef _SVM_PMU_H 17 #define _SVM_PMU_H 18 19 #include <sys/stdbool.h> 20 #include <sys/vmm_kernel.h> 21 #include <sys/hma.h> 22 23 #include "svm_softc.h" 24 25 #define SVM_PMU_MAX_COUNTERS 6 26 27 struct svm_pmu_vcpu { 28 struct hma_svm_cpc_state spv_hma_state; 29 uint64_t spv_evtsel_shadow[SVM_PMU_MAX_COUNTERS]; 30 hma_svm_cpc_res_t spv_last_entry; 31 }; 32 33 CTASSERT(SVM_PMU_MAX_COUNTERS == HMA_CPC_REGS_MAX); 34 35 typedef enum svm_pmu_flavor { 36 SPF_NONE = 0, 37 SPF_PRE_ZEN, 38 SPF_ZEN1, 39 SPF_ZEN2, 40 } svm_pmu_flavor_t; 41 42 struct svm_pmu { 43 bool sp_enabled; 44 svm_pmu_flavor_t sp_flavor; 45 }; 46 47 void svm_pmu_init(struct svm_softc *); 48 bool svm_pmu_owned_msr(uint32_t); 49 vm_msr_result_t svm_pmu_rdmsr(struct svm_softc *, int, uint32_t, uint64_t *); 50 vm_msr_result_t svm_pmu_wrmsr(struct svm_softc *, int, uint32_t, uint64_t); 51 bool svm_pmu_rdpmc(struct svm_softc *, int, uint32_t, uint64_t *); 52 void svm_pmu_enter(struct svm_softc *, int); 53 void svm_pmu_exit(struct svm_softc *, int); 54 55 #endif /* _SVM_PMU_H */ 56