/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2013 Anish Gupta ([email protected])4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice unmodified, this list of conditions, and the following11* disclaimer.12* 2. Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in the14* documentation and/or other materials provided with the distribution.15*16* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR17* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES18* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.19* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,20* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT21* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,22* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY23* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF25* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.26*/2728#ifndef _SVM_SOFTC_H_29#define _SVM_SOFTC_H_3031#include "x86.h"3233#define SVM_IO_BITMAP_SIZE (3 * PAGE_SIZE)34#define SVM_MSR_BITMAP_SIZE (2 * PAGE_SIZE)3536struct svm_softc;3738struct dbg {39uint32_t rflags_tf; /* saved RFLAGS.TF value when single-stepping a vcpu */40bool popf_sstep; /* indicates that we've stepped over popf */41bool pushf_sstep; /* indicates that we've stepped over pushf */42};4344struct asid {45uint64_t gen; /* range is [1, ~0UL] */46uint32_t num; /* range is [1, nasid - 1] */47};4849struct svm_vcpu {50struct svm_softc *sc;51struct vcpu *vcpu;52struct vmcb *vmcb; /* hardware saved vcpu context */53struct svm_regctx swctx; /* software saved vcpu context */54uint64_t vmcb_pa; /* VMCB physical address */55uint64_t nextrip; /* next instruction to be executed by guest */56int lastcpu; /* host cpu that the vcpu last ran on */57uint32_t dirty; /* state cache bits that must be cleared */58long eptgen; /* pmap->pm_eptgen when the vcpu last ran */59struct asid asid;60struct vm_mtrr mtrr;61int vcpuid;62struct dbg dbg;63int caps; /* optional vm capabilities */64};6566/*67* SVM softc, one per virtual machine.68*/69struct svm_softc {70vm_paddr_t nptp; /* nested page table */71uint8_t *iopm_bitmap; /* shared by all vcpus */72uint8_t *msr_bitmap; /* shared by all vcpus */73struct vm *vm;74};7576#define SVM_CTR0(vcpu, format) \77VCPU_CTR0((vcpu)->sc->vm, (vcpu)->vcpuid, format)7879#define SVM_CTR1(vcpu, format, p1) \80VCPU_CTR1((vcpu)->sc->vm, (vcpu)->vcpuid, format, p1)8182#define SVM_CTR2(vcpu, format, p1, p2) \83VCPU_CTR2((vcpu)->sc->vm, (vcpu)->vcpuid, format, p1, p2)8485#define SVM_CTR3(vcpu, format, p1, p2, p3) \86VCPU_CTR3((vcpu)->sc->vm, (vcpu)->vcpuid, format, p1, p2, p3)8788#define SVM_CTR4(vcpu, format, p1, p2, p3, p4) \89VCPU_CTR4((vcpu)->sc->vm, (vcpu)->vcpuid, format, p1, p2, p3, p4)9091static __inline struct vmcb *92svm_get_vmcb(struct svm_vcpu *vcpu)93{9495return (vcpu->vmcb);96}9798static __inline struct vmcb_state *99svm_get_vmcb_state(struct svm_vcpu *vcpu)100{101102return (&vcpu->vmcb->state);103}104105static __inline struct vmcb_ctrl *106svm_get_vmcb_ctrl(struct svm_vcpu *vcpu)107{108109return (&vcpu->vmcb->ctrl);110}111112static __inline struct svm_regctx *113svm_get_guest_regctx(struct svm_vcpu *vcpu)114{115116return (&vcpu->swctx);117}118119static __inline void120svm_set_dirty(struct svm_vcpu *vcpu, uint32_t dirtybits)121{122123vcpu->dirty |= dirtybits;124}125126#endif /* _SVM_SOFTC_H_ */127128129