xref: /freebsd/sys/amd64/vmm/vmm_lapic.h (revision ba9b7bf73aa2c67604b2cd52e37ca5130f45fd2c)
1366f6083SPeter Grehan /*-
2366f6083SPeter Grehan  * Copyright (c) 2011 NetApp, Inc.
3366f6083SPeter Grehan  * All rights reserved.
4366f6083SPeter Grehan  *
5366f6083SPeter Grehan  * Redistribution and use in source and binary forms, with or without
6366f6083SPeter Grehan  * modification, are permitted provided that the following conditions
7366f6083SPeter Grehan  * are met:
8366f6083SPeter Grehan  * 1. Redistributions of source code must retain the above copyright
9366f6083SPeter Grehan  *    notice, this list of conditions and the following disclaimer.
10366f6083SPeter Grehan  * 2. Redistributions in binary form must reproduce the above copyright
11366f6083SPeter Grehan  *    notice, this list of conditions and the following disclaimer in the
12366f6083SPeter Grehan  *    documentation and/or other materials provided with the distribution.
13366f6083SPeter Grehan  *
14366f6083SPeter Grehan  * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
15366f6083SPeter Grehan  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16366f6083SPeter Grehan  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17366f6083SPeter Grehan  * ARE DISCLAIMED.  IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
18366f6083SPeter Grehan  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19366f6083SPeter Grehan  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20366f6083SPeter Grehan  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21366f6083SPeter Grehan  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22366f6083SPeter Grehan  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23366f6083SPeter Grehan  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24366f6083SPeter Grehan  * SUCH DAMAGE.
25366f6083SPeter Grehan  *
26366f6083SPeter Grehan  * $FreeBSD$
27366f6083SPeter Grehan  */
28366f6083SPeter Grehan 
29366f6083SPeter Grehan #ifndef _VMM_LAPIC_H_
30366f6083SPeter Grehan #define	_VMM_LAPIC_H_
31366f6083SPeter Grehan 
32366f6083SPeter Grehan struct vm;
33366f6083SPeter Grehan 
342d3a73edSNeel Natu boolean_t lapic_msr(u_int num);
352d3a73edSNeel Natu int	lapic_rdmsr(struct vm *vm, int cpu, u_int msr, uint64_t *rval);
362d3a73edSNeel Natu int	lapic_wrmsr(struct vm *vm, int cpu, u_int msr, uint64_t wval);
372d3a73edSNeel Natu 
38*ba9b7bf7SNeel Natu int	lapic_mmio_read(void *vm, int cpu, uint64_t gpa,
39*ba9b7bf7SNeel Natu 			uint64_t *rval, int size, void *arg);
40*ba9b7bf7SNeel Natu int	lapic_mmio_write(void *vm, int cpu, uint64_t gpa,
41*ba9b7bf7SNeel Natu 			 uint64_t wval, int size, void *arg);
42a2da7af6SNeel Natu 
432e25737aSNeel Natu int	lapic_timer_tick(struct vm *vm, int cpu);
44366f6083SPeter Grehan 
45366f6083SPeter Grehan /*
46366f6083SPeter Grehan  * Returns a vector between 32 and 255 if an interrupt is pending in the
47366f6083SPeter Grehan  * IRR that can be delivered based on the current state of ISR and TPR.
48366f6083SPeter Grehan  *
49366f6083SPeter Grehan  * Note that the vector does not automatically transition to the ISR as a
50366f6083SPeter Grehan  * result of calling this function.
51366f6083SPeter Grehan  *
52366f6083SPeter Grehan  * Returns -1 if there is no eligible vector that can be delivered to the
53366f6083SPeter Grehan  * guest at this time.
54366f6083SPeter Grehan  */
55366f6083SPeter Grehan int	lapic_pending_intr(struct vm *vm, int cpu);
56366f6083SPeter Grehan 
57366f6083SPeter Grehan /*
58366f6083SPeter Grehan  * Transition 'vector' from IRR to ISR. This function is called with the
59366f6083SPeter Grehan  * vector returned by 'lapic_pending_intr()' when the guest is able to
60366f6083SPeter Grehan  * accept this interrupt (i.e. RFLAGS.IF = 1 and no conditions exist that
61366f6083SPeter Grehan  * block interrupt delivery).
62366f6083SPeter Grehan  */
63366f6083SPeter Grehan void	lapic_intr_accepted(struct vm *vm, int cpu, int vector);
64366f6083SPeter Grehan 
65366f6083SPeter Grehan /*
66366f6083SPeter Grehan  * Signals to the LAPIC that an interrupt at 'vector' needs to be generated
67366f6083SPeter Grehan  * to the 'cpu', the state is recorded in IRR.
68366f6083SPeter Grehan  */
69366f6083SPeter Grehan int	lapic_set_intr(struct vm *vm, int cpu, int vector);
70366f6083SPeter Grehan 
71366f6083SPeter Grehan #endif
72