vmx_msr.h revision 276349
1207821Sjilles/*-
2207821Sjilles * Copyright (c) 2011 NetApp, Inc.
3207821Sjilles * All rights reserved.
4207821Sjilles *
5207821Sjilles * Redistribution and use in source and binary forms, with or without
6207821Sjilles * modification, are permitted provided that the following conditions
7207821Sjilles * are met:
8207821Sjilles * 1. Redistributions of source code must retain the above copyright
9207821Sjilles *    notice, this list of conditions and the following disclaimer.
10207821Sjilles * 2. Redistributions in binary form must reproduce the above copyright
11207821Sjilles *    notice, this list of conditions and the following disclaimer in the
12207821Sjilles *    documentation and/or other materials provided with the distribution.
13207821Sjilles *
14207821Sjilles * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
15207821Sjilles * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16207821Sjilles * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17207821Sjilles * ARE DISCLAIMED.  IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
18207821Sjilles * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19207821Sjilles * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20207821Sjilles * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21207821Sjilles * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22207821Sjilles * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23207821Sjilles * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24207821Sjilles * SUCH DAMAGE.
25207821Sjilles *
26207821Sjilles * $FreeBSD: stable/10/sys/amd64/vmm/intel/vmx_msr.h 276349 2014-12-28 21:27:13Z neel $
27207821Sjilles */
28207821Sjilles
29207821Sjilles#ifndef _VMX_MSR_H_
30207821Sjilles#define	_VMX_MSR_H_
31207821Sjilles
32207821Sjillesstruct vmx;
33207821Sjilles
34207821Sjillesvoid vmx_msr_init(void);
35207821Sjillesvoid vmx_msr_guest_init(struct vmx *vmx, int vcpuid);
36207821Sjillesvoid vmx_msr_guest_enter(struct vmx *vmx, int vcpuid);
37207821Sjillesvoid vmx_msr_guest_exit(struct vmx *vmx, int vcpuid);
38207821Sjillesint vmx_rdmsr(struct vmx *, int vcpuid, u_int num, uint64_t *val, bool *retu);
39207821Sjillesint vmx_wrmsr(struct vmx *, int vcpuid, u_int num, uint64_t val, bool *retu);
40207821Sjilles
41207821Sjillesuint32_t vmx_revision(void);
42207821Sjilles
43207821Sjillesint vmx_set_ctlreg(int ctl_reg, int true_ctl_reg, uint32_t ones_mask,
44207821Sjilles		   uint32_t zeros_mask, uint32_t *retval);
45207821Sjilles
46207821Sjilles/*
47207821Sjilles * According to Section 21.10.4 "Software Access to Related Structures",
48207821Sjilles * changes to data structures pointed to by the VMCS must be made only when
49207821Sjilles * there is no logical processor with a current VMCS that points to the
50207821Sjilles * data structure.
51207821Sjilles *
52207821Sjilles * This pretty much limits us to configuring the MSR bitmap before VMCS
53207821Sjilles * initialization for SMP VMs. Unless of course we do it the hard way - which
54207821Sjilles * would involve some form of synchronization between the vcpus to vmclear
55207821Sjilles * all VMCSs' that point to the bitmap.
56207821Sjilles */
57207821Sjilles#define	MSR_BITMAP_ACCESS_NONE	0x0
58207821Sjilles#define	MSR_BITMAP_ACCESS_READ	0x1
59207821Sjilles#define	MSR_BITMAP_ACCESS_WRITE	0x2
60207821Sjilles#define	MSR_BITMAP_ACCESS_RW	(MSR_BITMAP_ACCESS_READ|MSR_BITMAP_ACCESS_WRITE)
61207821Sjillesvoid	msr_bitmap_initialize(char *bitmap);
62207821Sjillesint	msr_bitmap_change_access(char *bitmap, u_int msr, int access);
63207821Sjilles
64207821Sjilles#define	guest_msr_rw(vmx, msr) \
65207821Sjilles    msr_bitmap_change_access((vmx)->msr_bitmap, (msr), MSR_BITMAP_ACCESS_RW)
66207821Sjilles
67207821Sjilles#define	guest_msr_ro(vmx, msr) \
68207821Sjilles    msr_bitmap_change_access((vmx)->msr_bitmap, (msr), MSR_BITMAP_ACCESS_READ)
69207821Sjilles
70207821Sjilles#endif
71207821Sjilles