acrn-hypervisor/hypervisor/include/arch/x86/guest/assign.h
Sainath Grandhi 06b59e0bc1 hv: Use ptirq_lookup_entry_by_sid to lookup virtual source id in IOAPIC irq entries
Reverts 538ba08c: hv:Add vpin to ptdev entry mapping for vpic/vioapic

ACRN uses an array of size  per VM to store ptirq entries against the vIOAPIC pin
and an array of size per VM to store ptirq entries against the vPIC pin.
This is done to speed up "ptirq entry" lookup at runtime for Level triggered
interrupts in API ptirq_intx_ack used on EOI.

This patch switches the lookup API for INTx interrupts to the API,
ptirq_lookup_entry_by_sid

This could add delay to processing EOI for Level triggered interrupts.
Trade-off here is space saved for array/s of size CONFIG_MAX_IOAPIC_LINES with 8 bytes
per data. On a server platform, ACRN needs to emulate multiple vIOAPICs for
SOS VM, same as the number of physical IO-APICs. Thereby ACRN would need around
10 such arrays per VM.

Removes the need of "pic_pin" except for the APIs facing the hypercalls
hcall_set_ptdev_intr_info, hcall_reset_ptdev_intr_info

Tracked-On: #4151
Signed-off-by: Sainath Grandhi <sainath.grandhi@intel.com>
Acked-by: Eddie Dong <eddie.dong@Intel.com>
2020-03-25 09:36:18 +08:00

148 lines
4.1 KiB
C

/*
* Copyright (C) 2018 Intel Corporation. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef ASSIGN_H
#define ASSIGN_H
#include <types.h>
#include <ptdev.h>
/**
* @file assign.h
*
* @brief public APIs for Passthrough Interrupt Remapping
*/
/**
* @brief VT-d
*
* @defgroup acrn_passthrough ACRN Passthrough
* @{
*/
/**
* @brief Acknowledge a virtual interrupt for passthrough device.
*
* Acknowledge a virtual legacy interrupt for a passthrough device.
*
* @param[in] vm pointer to acrn_vm
* @param[in] virt_pin virtual pin number associated with the passthrough device
* @param[in] vpin_ctlr INTX_CTLR_IOAPIC or INTX_CTLR_PIC
*
* @return None
*
* @pre vm != NULL
*
*/
void ptirq_intx_ack(struct acrn_vm *vm, uint32_t virt_pin, enum intx_ctlr vpin_ctlr);
/**
* @brief MSI/MSI-x remapping for passthrough device.
*
* Main entry for PCI device assignment with MSI and MSI-X.
* MSI can up to 8 vectors and MSI-X can up to 1024 Vectors.
*
* @param[in] vm pointer to acrn_vm
* @param[in] virt_bdf virtual bdf associated with the passthrough device
* @param[in] phys_bdf virtual bdf associated with the passthrough device
* @param[in] entry_nr indicate coming vectors, entry_nr = 0 means first vector
* @param[in] info structure used for MSI/MSI-x remapping
*
* @return
* - 0: on success
* - \p -ENODEV:
* - for SOS, the entry already be held by others
* - for UOS, no pre-hold mapping found.
*
* @pre vm != NULL
* @pre info != NULL
*
*/
int32_t ptirq_prepare_msix_remap(struct acrn_vm *vm, uint16_t virt_bdf, uint16_t phys_bdf,
uint16_t entry_nr, struct ptirq_msi_info *info);
/**
* @brief INTx remapping for passthrough device.
*
* Set up the remapping of the given virtual pin for the given vm.
* This is the main entry for PCI/Legacy device assignment with INTx, calling from vIOAPIC or vPIC.
*
* @param[in] vm pointer to acrn_vm
* @param[in] virt_pin virtual pin number associated with the passthrough device
* @param[in] vpin_ctlr INTX_CTLR_IOAPIC or INTX_CTLR_PIC
*
* @return
* - 0: on success
* - \p -ENODEV:
* - for SOS, the entry already be held by others
* - for UOS, no pre-hold mapping found.
*
* @pre vm != NULL
*
*/
int32_t ptirq_intx_pin_remap(struct acrn_vm *vm, uint32_t virt_pin, enum intx_ctlr vpin_ctlr);
/**
* @brief Add an interrupt remapping entry for INTx as pre-hold mapping.
*
* Except sos_vm, Device Model should call this function to pre-hold ptdev intx
* The entry is identified by phys_pin, one entry vs. one phys_pin.
* Currently, one phys_pin can only be held by one pin source (vPIC or vIOAPIC).
*
* @param[in] vm pointer to acrn_vm
* @param[in] virt_pin virtual pin number associated with the passthrough device
* @param[in] phys_pin physical pin number associated with the passthrough device
* @param[in] pic_pin true for pic, false for ioapic
*
* @return
* - 0: on success
* - \p -EINVAL: invalid virt_pin value
* - \p -ENODEV: failed to add the remapping entry
*
* @pre vm != NULL
*
*/
int32_t ptirq_add_intx_remapping(struct acrn_vm *vm, uint32_t virt_pin, uint32_t phys_pin, bool pic_pin);
/**
* @brief Remove an interrupt remapping entry for INTx.
*
* Deactivate & remove mapping entry of the given virt_pin for given vm.
*
* @param[in] vm pointer to acrn_vm
* @param[in] virt_pin virtual pin number associated with the passthrough device
* @param[in] pic_pin true for pic, false for ioapic
*
* @return None
*
* @pre vm != NULL
*
*/
void ptirq_remove_intx_remapping(const struct acrn_vm *vm, uint32_t virt_pin, bool pic_pin);
/**
* @brief Remove interrupt remapping entry/entries for MSI/MSI-x.
*
* Remove the mapping of given number of vectors of the given virtual BDF for the given vm.
*
* @param[in] vm pointer to acrn_vm
* @param[in] virt_bdf virtual bdf associated with the passthrough device
* @param[in] vector_count number of vectors
*
* @return None
*
* @pre vm != NULL
*
*/
void ptirq_remove_msix_remapping(const struct acrn_vm *vm, uint16_t virt_bdf, uint32_t vector_count);
/**
* @}
*/
#endif /* ASSIGN_H */