/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2017 The FreeBSD Foundation4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8* 1. Redistributions of source code must retain the above copyright9* notice, this list of conditions and the following disclaimer.10* 2. Redistributions in binary form must reproduce the above copyright11* notice, this list of conditions and the following disclaimer in the12* documentation and/or other materials provided with the distribution.13* 3. The name of the company nor the name of the author may be used to14* endorse or promote products derived from this software without specific15* prior written permission.16*17* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND18* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE19* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE20* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE21* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL22* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS23* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)24* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT25* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY26* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF27* SUCH DAMAGE.28*/2930#ifndef _VMM_VTIMER_H_31#define _VMM_VTIMER_H_3233#define GT_PHYS_NS_IRQ 3034#define GT_VIRT_IRQ 273536struct hyp;37struct hypctx;3839struct vtimer {40uint64_t cnthctl_el2;41uint64_t cntvoff_el2;42};4344struct vtimer_timer {45struct callout callout;46struct mtx mtx;4748uint32_t irqid;4950/*51* These registers are either emulated for the physical timer, or52* the guest has full access to them for the virtual timer.5354* CNTx_CTL_EL0: Counter-timer Timer Control Register55* CNTx_CVAL_EL0: Counter-timer Timer CompareValue Register56*/57uint64_t cntx_cval_el0;58uint64_t cntx_ctl_el0;59};6061struct vtimer_cpu {62struct vtimer_timer phys_timer;63struct vtimer_timer virt_timer;6465uint32_t cntkctl_el1;66};6768int vtimer_init(void);69void vtimer_vminit(struct hyp *);70void vtimer_cpuinit(struct hypctx *);71void vtimer_cpucleanup(struct hypctx *);72void vtimer_vmcleanup(struct hyp *);73void vtimer_cleanup(void);74void vtimer_sync_hwstate(struct hypctx *hypctx);7576int vtimer_phys_ctl_read(struct vcpu *vcpu, uint64_t *rval, void *arg);77int vtimer_phys_ctl_write(struct vcpu *vcpu, uint64_t wval, void *arg);78int vtimer_phys_cnt_read(struct vcpu *vcpu, uint64_t *rval, void *arg);79int vtimer_phys_cnt_write(struct vcpu *vcpu, uint64_t wval, void *arg);80int vtimer_phys_cval_read(struct vcpu *vcpu, uint64_t *rval, void *arg);81int vtimer_phys_cval_write(struct vcpu *vcpu, uint64_t wval, void *arg);82int vtimer_phys_tval_read(struct vcpu *vcpu, uint64_t *rval, void *arg);83int vtimer_phys_tval_write(struct vcpu *vcpu, uint64_t wval, void *arg);84#endif858687