1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2017 The FreeBSD Foundation 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. The name of the company nor the name of the author may be used to 15 * endorse or promote products derived from this software without specific 16 * prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30 31 #ifndef _VMM_VTIMER_H_ 32 #define _VMM_VTIMER_H_ 33 34 #define GT_PHYS_NS_IRQ 30 35 #define GT_VIRT_IRQ 27 36 37 struct hyp; 38 struct hypctx; 39 40 struct vtimer { 41 uint64_t cnthctl_el2; 42 uint64_t cntvoff_el2; 43 }; 44 45 struct vtimer_timer { 46 struct callout callout; 47 struct mtx mtx; 48 49 uint32_t irqid; 50 51 /* 52 * These registers are either emulated for the physical timer, or 53 * the guest has full access to them for the virtual timer. 54 55 * CNTx_CTL_EL0: Counter-timer Timer Control Register 56 * CNTx_CVAL_EL0: Counter-timer Timer CompareValue Register 57 */ 58 uint64_t cntx_cval_el0; 59 uint64_t cntx_ctl_el0; 60 }; 61 62 struct vtimer_cpu { 63 struct vtimer_timer phys_timer; 64 struct vtimer_timer virt_timer; 65 66 uint32_t cntkctl_el1; 67 }; 68 69 int vtimer_init(uint64_t cnthctl_el2); 70 void vtimer_vminit(struct hyp *); 71 void vtimer_cpuinit(struct hypctx *); 72 void vtimer_cpucleanup(struct hypctx *); 73 void vtimer_vmcleanup(struct hyp *); 74 void vtimer_cleanup(void); 75 void vtimer_sync_hwstate(struct hypctx *hypctx); 76 77 int vtimer_phys_ctl_read(struct vcpu *vcpu, uint64_t *rval, void *arg); 78 int vtimer_phys_ctl_write(struct vcpu *vcpu, uint64_t wval, void *arg); 79 int vtimer_phys_cnt_read(struct vcpu *vcpu, uint64_t *rval, void *arg); 80 int vtimer_phys_cnt_write(struct vcpu *vcpu, uint64_t wval, void *arg); 81 int vtimer_phys_cval_read(struct vcpu *vcpu, uint64_t *rval, void *arg); 82 int vtimer_phys_cval_write(struct vcpu *vcpu, uint64_t wval, void *arg); 83 int vtimer_phys_tval_read(struct vcpu *vcpu, uint64_t *rval, void *arg); 84 int vtimer_phys_tval_write(struct vcpu *vcpu, uint64_t wval, void *arg); 85 #endif 86