xref: /freebsd/sys/arm64/vmm/io/vtimer.h (revision 35164034e390f56f83efe5bf073d36812b19df23)
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_timer {
41 	struct callout	callout;
42 	struct mtx	mtx;
43 
44 	uint32_t	irqid;
45 
46 	/*
47 	 * These registers are either emulated for the physical timer, or
48 	 * the guest has full access to them for the virtual timer.
49 
50 	 * CNTx_CTL_EL0:  Counter-timer Timer Control Register
51 	 * CNTx_CVAL_EL0: Counter-timer Timer CompareValue Register
52 	 */
53 	uint64_t	cntx_cval_el0;
54 	uint64_t	cntx_ctl_el0;
55 };
56 
57 struct vtimer_cpu {
58 	struct vtimer_timer phys_timer;
59 	struct vtimer_timer virt_timer;
60 
61 	uint32_t	cntkctl_el1;
62 };
63 
64 int 	vtimer_init(void);
65 void 	vtimer_cpuinit(struct hypctx *);
66 void 	vtimer_cpucleanup(struct hypctx *);
67 void	vtimer_vmcleanup(struct hyp *);
68 void	vtimer_cleanup(void);
69 void	vtimer_sync_hwstate(struct hypctx *hypctx);
70 
71 int 	vtimer_phys_ctl_read(struct vcpu *vcpu, uint64_t *rval, void *arg);
72 int 	vtimer_phys_ctl_write(struct vcpu *vcpu, uint64_t wval, void *arg);
73 int 	vtimer_phys_cnt_read(struct vcpu *vcpu, uint64_t *rval, void *arg);
74 int 	vtimer_phys_cnt_write(struct vcpu *vcpu, uint64_t wval, void *arg);
75 int 	vtimer_phys_cval_read(struct vcpu *vcpu, uint64_t *rval, void *arg);
76 int 	vtimer_phys_cval_write(struct vcpu *vcpu, uint64_t wval, void *arg);
77 int 	vtimer_phys_tval_read(struct vcpu *vcpu, uint64_t *rval, void *arg);
78 int 	vtimer_phys_tval_write(struct vcpu *vcpu, uint64_t wval, void *arg);
79 #endif
80