2 * Copyright (c) 2011 NetApp, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/types.h>
34 #include <machine/cpufunc.h>
35 #include <machine/vmm.h>
36 #include <machine/specialreg.h>
46 static int cpu_vendor_intel
, cpu_vendor_amd
;
49 emulate_wrmsr(struct vmctx
*ctx
, int vcpu
, uint32_t num
, uint64_t val
)
52 if (cpu_vendor_intel
) {
54 case 0xd04: /* Sandy Bridge uncore PMCs */
57 case MSR_BIOS_UPDT_TRIG
:
64 } else if (cpu_vendor_amd
) {
68 * Ignore writes to hardware configuration MSR.
74 return (0); /* Ignore writes */
80 /* Ignore writes to the PerfEvtSel MSRs */
87 /* Ignore writes to the PerfCtr MSRs */
90 case MSR_P_STATE_CONTROL
:
91 /* Ignore write to change the P-state */
102 emulate_rdmsr(struct vmctx
*ctx
, int vcpu
, uint32_t num
, uint64_t *val
)
106 if (cpu_vendor_intel
) {
109 case MSR_IA32_PLATFORM_ID
:
110 case MSR_PKG_ENERGY_STATUS
:
111 case MSR_PP0_ENERGY_STATUS
:
112 case MSR_PP1_ENERGY_STATUS
:
113 case MSR_DRAM_ENERGY_STATUS
:
116 case MSR_RAPL_POWER_UNIT
:
118 * Use the default value documented in section
119 * "RAPL Interfaces" in Intel SDM vol3.
127 } else if (cpu_vendor_amd
) {
134 * Bios and Kernel Developer's Guides for AMD Families
135 * 12H, 14H, 15H and 16H.
137 *val
= 0x01000010; /* Reset value */
138 *val
|= 1 << 9; /* MONITOR/MWAIT disable */
144 * The reset value is processor family dependent so
155 * PerfEvtSel MSRs are not properly virtualized so just
161 case MSR_K7_PERFCTR0
:
162 case MSR_K7_PERFCTR1
:
163 case MSR_K7_PERFCTR2
:
164 case MSR_K7_PERFCTR3
:
166 * PerfCtr MSRs are not properly virtualized so just
175 * Return the reset value defined in the AMD Bios and
176 * Kernel Developer's Guide.
181 case MSR_P_STATE_LIMIT
:
182 case MSR_P_STATE_CONTROL
:
183 case MSR_P_STATE_STATUS
:
184 case MSR_P_STATE_CONFIG(0): /* P0 configuration */
189 * OpenBSD guests test bit 0 of this MSR to detect if the
190 * workaround for erratum 721 is already applied.
191 * http://support.amd.com/TechDocs/41322_10h_Rev_Gd.pdf
215 ((u_int
*)&cpu_vendor
)[0] = regs
[1];
216 ((u_int
*)&cpu_vendor
)[1] = regs
[3];
217 ((u_int
*)&cpu_vendor
)[2] = regs
[2];
218 cpu_vendor
[12] = '\0';
221 if (strcmp(cpu_vendor
, "AuthenticAMD") == 0) {
223 } else if (strcmp(cpu_vendor
, "GenuineIntel") == 0) {
224 cpu_vendor_intel
= 1;
226 fprintf(stderr
, "Unknown cpu vendor \"%s\"\n", cpu_vendor
);