/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2011 NetApp, Inc.4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND16* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18* ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE19* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25* SUCH DAMAGE.26*/2728#ifndef _VLAPIC_H_29#define _VLAPIC_H_3031struct vm;32struct vm_snapshot_meta;33enum x2apic_state;3435int vlapic_write(struct vlapic *vlapic, int mmio_access, uint64_t offset,36uint64_t data, bool *retu);37int vlapic_read(struct vlapic *vlapic, int mmio_access, uint64_t offset,38uint64_t *data, bool *retu);3940/*41* Returns 0 if there is no eligible vector that can be delivered to the42* guest at this time and non-zero otherwise.43*44* If an eligible vector number is found and 'vecptr' is not NULL then it will45* be stored in the location pointed to by 'vecptr'.46*47* Note that the vector does not automatically transition to the ISR as a48* result of calling this function.49*/50int vlapic_pending_intr(struct vlapic *vlapic, int *vecptr);5152/*53* Transition 'vector' from IRR to ISR. This function is called with the54* vector returned by 'vlapic_pending_intr()' when the guest is able to55* accept this interrupt (i.e. RFLAGS.IF = 1 and no conditions exist that56* block interrupt delivery).57*/58void vlapic_intr_accepted(struct vlapic *vlapic, int vector);5960/*61* Returns 1 if the vcpu needs to be notified of the interrupt and 0 otherwise.62*/63int vlapic_set_intr_ready(struct vlapic *vlapic, int vector, bool level);6465/*66* Post an interrupt to the vcpu running on 'hostcpu'. This will use a67* hardware assist if available (e.g. Posted Interrupt) or fall back to68* sending an 'ipinum' to interrupt the 'hostcpu'.69*/70void vlapic_post_intr(struct vlapic *vlapic, int hostcpu, int ipinum);7172void vlapic_fire_cmci(struct vlapic *vlapic);73int vlapic_trigger_lvt(struct vlapic *vlapic, int vector);7475void vlapic_sync_tpr(struct vlapic *vlapic);7677uint64_t vlapic_get_apicbase(struct vlapic *vlapic);78int vlapic_set_apicbase(struct vlapic *vlapic, uint64_t val);79void vlapic_set_x2apic_state(struct vcpu *vcpu, enum x2apic_state s);80bool vlapic_enabled(struct vlapic *vlapic);8182void vlapic_deliver_intr(struct vm *vm, bool level, uint32_t dest, bool phys,83int delmode, int vec);8485/* Reset the trigger-mode bits for all vectors to be edge-triggered */86void vlapic_reset_tmr(struct vlapic *vlapic);8788/*89* Set the trigger-mode bit associated with 'vector' to level-triggered if90* the (dest,phys,delmode) tuple resolves to an interrupt being delivered to91* this 'vlapic'.92*/93void vlapic_set_tmr_level(struct vlapic *vlapic, uint32_t dest, bool phys,94int delmode, int vector);9596void vlapic_set_cr8(struct vlapic *vlapic, uint64_t val);97uint64_t vlapic_get_cr8(struct vlapic *vlapic);9899/* APIC write handlers */100void vlapic_id_write_handler(struct vlapic *vlapic);101void vlapic_ldr_write_handler(struct vlapic *vlapic);102void vlapic_dfr_write_handler(struct vlapic *vlapic);103void vlapic_svr_write_handler(struct vlapic *vlapic);104void vlapic_esr_write_handler(struct vlapic *vlapic);105int vlapic_icrlo_write_handler(struct vlapic *vlapic, bool *retu);106void vlapic_icrtmr_write_handler(struct vlapic *vlapic);107void vlapic_dcr_write_handler(struct vlapic *vlapic);108void vlapic_lvt_write_handler(struct vlapic *vlapic, uint32_t offset);109void vlapic_self_ipi_handler(struct vlapic *vlapic, uint64_t val);110111#ifdef BHYVE_SNAPSHOT112int vlapic_snapshot(struct vm *vm, struct vm_snapshot_meta *meta);113#endif114115int vm_handle_ipi(struct vcpu *vcpu, struct vm_exit *vme, bool *retu);116117#endif /* _VLAPIC_H_ */118119120