xref: /freebsd/sys/amd64/vmm/vmm_lapic.h (revision 330baf58c6cf2ad1cecf8ac7c9a1d0f3be36d37f)
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);
35becd9849SNeel Natu int	lapic_rdmsr(struct vm *vm, int cpu, u_int msr, uint64_t *rval,
36becd9849SNeel Natu 	    bool *retu);
37becd9849SNeel Natu int	lapic_wrmsr(struct vm *vm, int cpu, u_int msr, uint64_t wval,
38becd9849SNeel Natu 	    bool *retu);
392d3a73edSNeel Natu 
40ba9b7bf7SNeel Natu int	lapic_mmio_read(void *vm, int cpu, uint64_t gpa,
41ba9b7bf7SNeel Natu 			uint64_t *rval, int size, void *arg);
42ba9b7bf7SNeel Natu int	lapic_mmio_write(void *vm, int cpu, uint64_t gpa,
43ba9b7bf7SNeel Natu 			 uint64_t wval, int size, void *arg);
44a2da7af6SNeel Natu 
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  */
69b5b28fc9SNeel Natu int	lapic_set_intr(struct vm *vm, int cpu, int vector, bool trig);
70b5b28fc9SNeel Natu 
71b5b28fc9SNeel Natu #define	LAPIC_TRIG_LEVEL	true
72b5b28fc9SNeel Natu #define	LAPIC_TRIG_EDGE		false
73b5b28fc9SNeel Natu static __inline int
74b5b28fc9SNeel Natu lapic_intr_level(struct vm *vm, int cpu, int vector)
75b5b28fc9SNeel Natu {
76b5b28fc9SNeel Natu 
77b5b28fc9SNeel Natu 	return (lapic_set_intr(vm, cpu, vector, LAPIC_TRIG_LEVEL));
78b5b28fc9SNeel Natu }
79b5b28fc9SNeel Natu 
80b5b28fc9SNeel Natu static __inline int
81b5b28fc9SNeel Natu lapic_intr_edge(struct vm *vm, int cpu, int vector)
82b5b28fc9SNeel Natu {
83b5b28fc9SNeel Natu 
84b5b28fc9SNeel Natu 	return (lapic_set_intr(vm, cpu, vector, LAPIC_TRIG_EDGE));
85b5b28fc9SNeel Natu }
86366f6083SPeter Grehan 
87*330baf58SJohn Baldwin /*
88*330baf58SJohn Baldwin  * Triggers the LAPIC local interrupt (LVT) 'vector' on 'cpu'.  'cpu' can
89*330baf58SJohn Baldwin  * be set to -1 to trigger the interrupt on all CPUs.
90*330baf58SJohn Baldwin  */
91*330baf58SJohn Baldwin int	lapic_set_local_intr(struct vm *vm, int cpu, int vector);
92*330baf58SJohn Baldwin 
934f8be175SNeel Natu int	lapic_intr_msi(struct vm *vm, uint64_t addr, uint64_t msg);
94*330baf58SJohn Baldwin 
95366f6083SPeter Grehan #endif
96