xref: /illumos-gate/usr/src/uts/intel/io/vmm/io/vlapic.h (revision 32640292)
1bf21cd93STycho Nightingale /*-
2*32640292SAndy Fiddaman  * SPDX-License-Identifier: BSD-2-Clause
34c87aefeSPatrick Mooney  *
4bf21cd93STycho Nightingale  * Copyright (c) 2011 NetApp, Inc.
5bf21cd93STycho Nightingale  * All rights reserved.
6bf21cd93STycho Nightingale  *
7bf21cd93STycho Nightingale  * Redistribution and use in source and binary forms, with or without
8bf21cd93STycho Nightingale  * modification, are permitted provided that the following conditions
9bf21cd93STycho Nightingale  * are met:
10bf21cd93STycho Nightingale  * 1. Redistributions of source code must retain the above copyright
11bf21cd93STycho Nightingale  *    notice, this list of conditions and the following disclaimer.
12bf21cd93STycho Nightingale  * 2. Redistributions in binary form must reproduce the above copyright
13bf21cd93STycho Nightingale  *    notice, this list of conditions and the following disclaimer in the
14bf21cd93STycho Nightingale  *    documentation and/or other materials provided with the distribution.
15bf21cd93STycho Nightingale  *
16bf21cd93STycho Nightingale  * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
17bf21cd93STycho Nightingale  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18bf21cd93STycho Nightingale  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19bf21cd93STycho Nightingale  * ARE DISCLAIMED.  IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
20bf21cd93STycho Nightingale  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21bf21cd93STycho Nightingale  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22bf21cd93STycho Nightingale  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23bf21cd93STycho Nightingale  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24bf21cd93STycho Nightingale  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25bf21cd93STycho Nightingale  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26bf21cd93STycho Nightingale  * SUCH DAMAGE.
274c87aefeSPatrick Mooney  */
284c87aefeSPatrick Mooney 
294c87aefeSPatrick Mooney /*
304c87aefeSPatrick Mooney  * Copyright 2018 Joyent, Inc.
312cac0506SPatrick Mooney  * Copyright 2022 Oxide Computer Company
32bf21cd93STycho Nightingale  */
33bf21cd93STycho Nightingale 
34bf21cd93STycho Nightingale #ifndef _VLAPIC_H_
35bf21cd93STycho Nightingale #define	_VLAPIC_H_
36bf21cd93STycho Nightingale 
372606939dSPatrick Mooney void vlapic_reset(struct vlapic *vlapic);
382606939dSPatrick Mooney 
39d2f938fdSPatrick Mooney int vlapic_mmio_write(struct vlapic *, uint64_t, uint64_t, uint_t);
40d2f938fdSPatrick Mooney int vlapic_mmio_read(struct vlapic *, uint64_t, uint64_t *, uint_t);
41d2f938fdSPatrick Mooney 
42d2f938fdSPatrick Mooney bool vlapic_owned_msr(uint32_t);
43d2f938fdSPatrick Mooney vm_msr_result_t vlapic_rdmsr(struct vlapic *, uint32_t, uint64_t *);
44d2f938fdSPatrick Mooney vm_msr_result_t vlapic_wrmsr(struct vlapic *, uint32_t, uint64_t);
45bf21cd93STycho Nightingale 
46bf21cd93STycho Nightingale /*
47bf21cd93STycho Nightingale  * Returns 0 if there is no eligible vector that can be delivered to the
48bf21cd93STycho Nightingale  * guest at this time and non-zero otherwise.
49bf21cd93STycho Nightingale  *
50bf21cd93STycho Nightingale  * If an eligible vector number is found and 'vecptr' is not NULL then it will
51bf21cd93STycho Nightingale  * be stored in the location pointed to by 'vecptr'.
52bf21cd93STycho Nightingale  *
53bf21cd93STycho Nightingale  * Note that the vector does not automatically transition to the ISR as a
54bf21cd93STycho Nightingale  * result of calling this function.
55bf21cd93STycho Nightingale  */
56bf21cd93STycho Nightingale int vlapic_pending_intr(struct vlapic *vlapic, int *vecptr);
57bf21cd93STycho Nightingale 
58bf21cd93STycho Nightingale /*
59bf21cd93STycho Nightingale  * Transition 'vector' from IRR to ISR. This function is called with the
60bf21cd93STycho Nightingale  * vector returned by 'vlapic_pending_intr()' when the guest is able to
61bf21cd93STycho Nightingale  * accept this interrupt (i.e. RFLAGS.IF = 1 and no conditions exist that
62bf21cd93STycho Nightingale  * block interrupt delivery).
63bf21cd93STycho Nightingale  */
64bf21cd93STycho Nightingale void vlapic_intr_accepted(struct vlapic *vlapic, int vector);
65bf21cd93STycho Nightingale 
66c74a40a5SPatrick Mooney vcpu_notify_t vlapic_set_intr_ready(struct vlapic *vlapic, int vector,
67c74a40a5SPatrick Mooney     bool level);
68bf21cd93STycho Nightingale 
69bf21cd93STycho Nightingale /*
70bf21cd93STycho Nightingale  * Post an interrupt to the vcpu running on 'hostcpu'. This will use a
71bf21cd93STycho Nightingale  * hardware assist if available (e.g. Posted Interrupt) or fall back to
720153d828SPatrick Mooney  * sending an IPI to interrupt the 'hostcpu'.
73bf21cd93STycho Nightingale  */
740153d828SPatrick Mooney void vlapic_post_intr(struct vlapic *vlapic, int hostcpu);
75bf21cd93STycho Nightingale 
76bf21cd93STycho Nightingale void vlapic_fire_cmci(struct vlapic *vlapic);
77bf21cd93STycho Nightingale int vlapic_trigger_lvt(struct vlapic *vlapic, int vector);
78bf21cd93STycho Nightingale 
79154972afSPatrick Mooney void vlapic_sync_tpr(struct vlapic *vlapic);
80154972afSPatrick Mooney 
81bf21cd93STycho Nightingale void vlapic_set_x2apic_state(struct vm *vm, int vcpuid, enum x2apic_state s);
82bf21cd93STycho Nightingale 
83bf21cd93STycho Nightingale void vlapic_deliver_intr(struct vm *vm, bool level, uint32_t dest, bool phys,
84bf21cd93STycho Nightingale     int delmode, int vec);
85bf21cd93STycho Nightingale 
864c87aefeSPatrick Mooney void vlapic_calcdest(struct vm *vm, cpuset_t *dmask, uint32_t dest, bool phys,
874c87aefeSPatrick Mooney     bool lowprio, bool x2apic_dest);
88bf21cd93STycho Nightingale 
89bf21cd93STycho Nightingale void vlapic_set_cr8(struct vlapic *vlapic, uint64_t val);
90d515dd77SPatrick Mooney uint64_t vlapic_get_cr8(const struct vlapic *vlapic);
91bf21cd93STycho Nightingale 
92bf21cd93STycho Nightingale /* APIC write handlers */
93bf21cd93STycho Nightingale void vlapic_id_write_handler(struct vlapic *vlapic);
94bf21cd93STycho Nightingale void vlapic_ldr_write_handler(struct vlapic *vlapic);
95bf21cd93STycho Nightingale void vlapic_dfr_write_handler(struct vlapic *vlapic);
96bf21cd93STycho Nightingale void vlapic_svr_write_handler(struct vlapic *vlapic);
97bf21cd93STycho Nightingale void vlapic_esr_write_handler(struct vlapic *vlapic);
98d2f938fdSPatrick Mooney void vlapic_icrlo_write_handler(struct vlapic *vlapic);
99bf21cd93STycho Nightingale void vlapic_icrtmr_write_handler(struct vlapic *vlapic);
100bf21cd93STycho Nightingale void vlapic_dcr_write_handler(struct vlapic *vlapic);
101bf21cd93STycho Nightingale void vlapic_lvt_write_handler(struct vlapic *vlapic, uint32_t offset);
102d2f938fdSPatrick Mooney void vlapic_self_ipi_handler(struct vlapic *vlapic, uint32_t val);
1034c87aefeSPatrick Mooney 
1044c87aefeSPatrick Mooney void vlapic_localize_resources(struct vlapic *vlapic);
1052cac0506SPatrick Mooney void vlapic_pause(struct vlapic *);
1062cac0506SPatrick Mooney void vlapic_resume(struct vlapic *);
1074c87aefeSPatrick Mooney 
108bf21cd93STycho Nightingale #endif	/* _VLAPIC_H_ */
109