hv:Rename ptdev to ptirq for some APIs

-- Rename the fowllowing APIs:
  ptdev_intx_pin_remap --> ptirq_intx_pin_remap
  ptdev_msix_remap  --> ptirq_msix_remap
  ptdev_add_intx_remapping --> ptirq_add_intx_remapping
  ptdev_remove_intx_remapping --> ptirq_remove_intx_remapping
  ptdev_add_msix_remapping --> ptirq_add_msix_remapping
  ptdev_remove_msix_remapping --> ptirq_remove_msix_remapping
  ptdev_intx_ack  --> ptirq_intx_ack
  ptdev_lookup_entry_by_sid --> ptirq_lookup_entry_by_sid
  ptdev_lookup_entry_by_vpin --> ptirq_lookup_entry_by_vpin
  ptdev_build_physical_msi --> ptirq_build_physical_msi
  ptdev_build_physical_rte --> ptirq_build_physical_rte
  alloc_entry   --> ptirq_alloc_entry
  release_entry --> ptirq_release_one_entry
  ptdev_activate_entry --> ptirq_activate_entry
  ptdev_deactivate_entry --> ptirq_deactivate_entry
  ptdev_intr_handle_irq --> ptirq_handle_intx
  ptdev_softirq --> ptirq_softirq
  ptdev_enqueue_softirq --> ptirq_enqueue_softirq
  ptdev_dequeue_softirq --> ptirq_dequeue_softirq
  get_vm_ptdev_intr_data --> ptirq_get_intr_data
  alloc_ptdev_entry_id --> ptirq_alloc_entry_id
  ptdev_intr_delay_callback --> ptirq_intr_delay_callback
  ptdev_dequeue_softirq --> ptirq_dequeue_softirq
  ptdev_interrupt_handler --> ptirq_interrupt_handler

-- Merge 'ptdev_release_all_entries' and 'release_all_entries'
   to 'ptirq_release_all_entries'

v2-->v3:
   Rename ptirq_release_one_entry to ptirq_release_entry
v1-->v2:
   still use ptdev_init instead of ptirq_init

Tracked-On: #861
Signed-off-by: Mingqiang Chi <mingqiang.chi@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Mingqiang Chi 2018-11-29 16:42:45 +08:00 committed by Xie, Nanlin
parent 5b43aa8a65
commit 5dcfc1336b
10 changed files with 111 additions and 121 deletions

View File

@ -136,7 +136,7 @@ Interrupt Remapping
When the physical interrupt of a passthrough device happens, hypervisor has When the physical interrupt of a passthrough device happens, hypervisor has
to distribute it to the relevant VM according to interrupt remapping to distribute it to the relevant VM according to interrupt remapping
relationships. The structure ``ptdev_remapping_info`` is used to define relationships. The structure ``ptirq_remapping_info`` is used to define
the subordination relation between physical interrupt and VM, the the subordination relation between physical interrupt and VM, the
virtual destination, etc. See the following figure for details: virtual destination, etc. See the following figure for details:
@ -186,7 +186,7 @@ the following steps:
- VM exit happens and the trapped vCPU is the target where the interrupt - VM exit happens and the trapped vCPU is the target where the interrupt
will be injected. will be injected.
- Hypervisor will handle the interrupt and translate the vector - Hypervisor will handle the interrupt and translate the vector
according to ptdev_remapping_info. according to ptirq_remapping_info.
- Hypervisor delivers the interrupt to UOS. - Hypervisor delivers the interrupt to UOS.
When the SOS needs to use the physical device, the passthrough is also When the SOS needs to use the physical device, the passthrough is also
@ -198,7 +198,7 @@ active because the SOS is the first VM. The detail steps are:
- When physical interrupt is trapped, an exception will happen after VMCS - When physical interrupt is trapped, an exception will happen after VMCS
has been set. has been set.
- Hypervisor will handle the vm exit issue according to - Hypervisor will handle the vm exit issue according to
ptdev_remapping_info and translates the vector. ptirq_remapping_info and translates the vector.
- The interrupt will be injected the same as a virtual interrupt. - The interrupt will be injected the same as a virtual interrupt.
ACPI Virtualization ACPI Virtualization
@ -234,28 +234,28 @@ Data structures and interfaces
The following APIs are provided to initialize interrupt remapping for The following APIs are provided to initialize interrupt remapping for
SOS: SOS:
.. doxygenfunction:: ptdev_intx_pin_remap .. doxygenfunction:: ptirq_intx_pin_remap
:project: Project ACRN :project: Project ACRN
.. doxygenfunction:: ptdev_msix_remap .. doxygenfunction:: ptirq_msix_remap
:project: Project ACRN :project: Project ACRN
The following APIs are provided to manipulate the interrupt remapping The following APIs are provided to manipulate the interrupt remapping
for UOS. for UOS.
.. doxygenfunction:: ptdev_add_intx_remapping .. doxygenfunction:: ptirq_add_intx_remapping
:project: Project ACRN :project: Project ACRN
.. doxygenfunction:: ptdev_remove_intx_remapping .. doxygenfunction:: ptirq_remove_intx_remapping
:project: Project ACRN :project: Project ACRN
.. doxygenfunction:: ptdev_add_msix_remapping .. doxygenfunction:: ptirq_add_msix_remapping
:project: Project ACRN :project: Project ACRN
.. doxygenfunction:: ptdev_remove_msix_remapping .. doxygenfunction:: ptirq_remove_msix_remapping
:project: Project ACRN :project: Project ACRN
The following APIs are provided to acknowledge a virtual interrupt. The following APIs are provided to acknowledge a virtual interrupt.
.. doxygenfunction:: ptdev_intx_ack .. doxygenfunction:: ptirq_intx_ack
:project: Project ACRN :project: Project ACRN

View File

@ -16,7 +16,7 @@
* vm must not be NULL when lookup by virtual sid. * vm must not be NULL when lookup by virtual sid.
*/ */
static inline struct ptirq_remapping_info * static inline struct ptirq_remapping_info *
ptdev_lookup_entry_by_sid(uint32_t intr_type, ptirq_lookup_entry_by_sid(uint32_t intr_type,
const union source_id *sid,const struct acrn_vm *vm) const union source_id *sid,const struct acrn_vm *vm)
{ {
uint16_t idx; uint16_t idx;
@ -40,7 +40,7 @@ ptdev_lookup_entry_by_sid(uint32_t intr_type,
} }
static inline struct ptirq_remapping_info * static inline struct ptirq_remapping_info *
ptdev_lookup_entry_by_vpin(struct acrn_vm *vm, uint8_t virt_pin, bool pic_pin) ptirq_lookup_entry_by_vpin(struct acrn_vm *vm, uint8_t virt_pin, bool pic_pin)
{ {
struct ptirq_remapping_info *entry; struct ptirq_remapping_info *entry;
@ -79,7 +79,7 @@ static uint64_t calculate_logical_dest_mask(uint64_t pdmask)
return dest_mask; return dest_mask;
} }
static void ptdev_build_physical_msi(struct acrn_vm *vm, struct ptirq_msi_info *info, static void ptirq_build_physical_msi(struct acrn_vm *vm, struct ptirq_msi_info *info,
uint32_t vector) uint32_t vector)
{ {
uint64_t vdmask, pdmask, dest_mask; uint64_t vdmask, pdmask, dest_mask;
@ -116,7 +116,7 @@ static void ptdev_build_physical_msi(struct acrn_vm *vm, struct ptirq_msi_info *
} }
static union ioapic_rte static union ioapic_rte
ptdev_build_physical_rte(struct acrn_vm *vm, struct ptirq_remapping_info *entry) ptirq_build_physical_rte(struct acrn_vm *vm, struct ptirq_remapping_info *entry)
{ {
union ioapic_rte rte; union ioapic_rte rte;
uint32_t phys_irq = entry->allocated_pirq; uint32_t phys_irq = entry->allocated_pirq;
@ -206,14 +206,14 @@ static struct ptirq_remapping_info *add_msix_remapping(struct acrn_vm *vm,
DEFINE_MSI_SID(phys_sid, phys_bdf, entry_nr); DEFINE_MSI_SID(phys_sid, phys_bdf, entry_nr);
DEFINE_MSI_SID(virt_sid, virt_bdf, entry_nr); DEFINE_MSI_SID(virt_sid, virt_bdf, entry_nr);
entry = ptdev_lookup_entry_by_sid(PTDEV_INTR_MSI, &phys_sid, NULL); entry = ptirq_lookup_entry_by_sid(PTDEV_INTR_MSI, &phys_sid, NULL);
if (entry == NULL) { if (entry == NULL) {
if (ptdev_lookup_entry_by_sid(PTDEV_INTR_MSI, &virt_sid, vm) != NULL) { if (ptirq_lookup_entry_by_sid(PTDEV_INTR_MSI, &virt_sid, vm) != NULL) {
pr_err("MSIX re-add vbdf%x", virt_bdf); pr_err("MSIX re-add vbdf%x", virt_bdf);
return NULL; return NULL;
} }
entry = alloc_entry(vm, PTDEV_INTR_MSI); entry = ptirq_alloc_entry(vm, PTDEV_INTR_MSI);
if (entry == NULL) { if (entry == NULL) {
return NULL; return NULL;
} }
@ -221,8 +221,8 @@ static struct ptirq_remapping_info *add_msix_remapping(struct acrn_vm *vm,
entry->virt_sid.value = virt_sid.value; entry->virt_sid.value = virt_sid.value;
/* update msi source and active entry */ /* update msi source and active entry */
if (ptdev_activate_entry(entry, IRQ_INVALID) < 0) { if (ptirq_activate_entry(entry, IRQ_INVALID) < 0) {
release_entry(entry); ptirq_release_entry(entry);
entry = NULL; entry = NULL;
} }
} else if (entry->vm != vm) { } else if (entry->vm != vm) {
@ -255,14 +255,14 @@ remove_msix_remapping(const struct acrn_vm *vm, uint16_t virt_bdf, uint32_t entr
struct ptirq_remapping_info *entry; struct ptirq_remapping_info *entry;
DEFINE_MSI_SID(virt_sid, virt_bdf, entry_nr); DEFINE_MSI_SID(virt_sid, virt_bdf, entry_nr);
entry = ptdev_lookup_entry_by_sid(PTDEV_INTR_MSI, &virt_sid, vm); entry = ptirq_lookup_entry_by_sid(PTDEV_INTR_MSI, &virt_sid, vm);
if (entry == NULL) { if (entry == NULL) {
return; return;
} }
if (is_entry_active(entry)) { if (is_entry_active(entry)) {
/*TODO: disable MSIX device when HV can in future */ /*TODO: disable MSIX device when HV can in future */
ptdev_deactivate_entry(entry); ptirq_deactivate_entry(entry);
} }
dev_dbg(ACRN_DBG_IRQ, dev_dbg(ACRN_DBG_IRQ,
@ -270,7 +270,7 @@ remove_msix_remapping(const struct acrn_vm *vm, uint16_t virt_bdf, uint32_t entr
entry->vm->vm_id, virt_bdf, entry->vm->vm_id, virt_bdf,
entry->phys_sid.msi_id.bdf, entry_nr); entry->phys_sid.msi_id.bdf, entry_nr);
release_entry(entry); ptirq_release_entry(entry);
} }
@ -290,7 +290,7 @@ static struct ptirq_remapping_info *add_intx_remapping(struct acrn_vm *vm, uint8
if ((!pic_pin && virt_pin >= vioapic_pincount(vm)) if ((!pic_pin && virt_pin >= vioapic_pincount(vm))
|| (pic_pin && virt_pin >= vpic_pincount())) { || (pic_pin && virt_pin >= vpic_pincount())) {
pr_err("ptdev_add_intx_remapping fails!\n"); pr_err("ptirq_add_intx_remapping fails!\n");
return NULL; return NULL;
} }
@ -299,13 +299,13 @@ static struct ptirq_remapping_info *add_intx_remapping(struct acrn_vm *vm, uint8
return NULL; return NULL;
} }
entry = ptdev_lookup_entry_by_sid(PTDEV_INTR_INTX, &phys_sid, NULL); entry = ptirq_lookup_entry_by_sid(PTDEV_INTR_INTX, &phys_sid, NULL);
if (entry == NULL) { if (entry == NULL) {
if (ptdev_lookup_entry_by_vpin(vm, virt_pin, pic_pin) != NULL) { if (ptirq_lookup_entry_by_vpin(vm, virt_pin, pic_pin) != NULL) {
pr_err("INTX re-add vpin %d", virt_pin); pr_err("INTX re-add vpin %d", virt_pin);
return NULL; return NULL;
} }
entry = alloc_entry(vm, PTDEV_INTR_INTX); entry = ptirq_alloc_entry(vm, PTDEV_INTR_INTX);
if (entry == NULL) { if (entry == NULL) {
return NULL; return NULL;
} }
@ -313,8 +313,8 @@ static struct ptirq_remapping_info *add_intx_remapping(struct acrn_vm *vm, uint8
entry->virt_sid.value = virt_sid.value; entry->virt_sid.value = virt_sid.value;
/* activate entry */ /* activate entry */
if (ptdev_activate_entry(entry, phys_irq) < 0) { if (ptirq_activate_entry(entry, phys_irq) < 0) {
release_entry(entry); ptirq_release_entry(entry);
entry = NULL; entry = NULL;
} }
} else if (entry->vm != vm) { } else if (entry->vm != vm) {
@ -354,7 +354,7 @@ static void remove_intx_remapping(struct acrn_vm *vm, uint8_t virt_pin, bool pic
return; return;
} }
entry = ptdev_lookup_entry_by_vpin(vm, virt_pin, pic_pin); entry = ptirq_lookup_entry_by_vpin(vm, virt_pin, pic_pin);
if (entry == NULL) { if (entry == NULL) {
return; return;
} }
@ -363,7 +363,7 @@ static void remove_intx_remapping(struct acrn_vm *vm, uint8_t virt_pin, bool pic
/* disable interrupt */ /* disable interrupt */
gsi_mask_irq(phys_irq); gsi_mask_irq(phys_irq);
ptdev_deactivate_entry(entry); ptirq_deactivate_entry(entry);
dev_dbg(ACRN_DBG_IRQ, dev_dbg(ACRN_DBG_IRQ,
"deactive %s intx entry:ppin=%d, pirq=%d ", "deactive %s intx entry:ppin=%d, pirq=%d ",
pic_pin ? "vPIC" : "vIOAPIC", pic_pin ? "vPIC" : "vIOAPIC",
@ -378,10 +378,10 @@ static void remove_intx_remapping(struct acrn_vm *vm, uint8_t virt_pin, bool pic
vm->arch_vm.vioapic.vpin_to_pt_entry[virt_pin] = NULL; vm->arch_vm.vioapic.vpin_to_pt_entry[virt_pin] = NULL;
} }
release_entry(entry); ptirq_release_entry(entry);
} }
static void ptdev_intr_handle_irq(struct acrn_vm *vm, static void ptirq_handle_intx(struct acrn_vm *vm,
const struct ptirq_remapping_info *entry) const struct ptirq_remapping_info *entry)
{ {
const union source_id *virt_sid = &entry->virt_sid; const union source_id *virt_sid = &entry->virt_sid;
@ -446,13 +446,13 @@ static void ptdev_intr_handle_irq(struct acrn_vm *vm,
} }
} }
void ptdev_softirq(uint16_t pcpu_id) void ptirq_softirq(uint16_t pcpu_id)
{ {
struct acrn_vcpu *vcpu = (struct acrn_vcpu *)per_cpu(vcpu, pcpu_id); struct acrn_vcpu *vcpu = (struct acrn_vcpu *)per_cpu(vcpu, pcpu_id);
struct acrn_vm *vm = vcpu->vm; struct acrn_vm *vm = vcpu->vm;
while (1) { while (1) {
struct ptirq_remapping_info *entry = ptdev_dequeue_softirq(vm); struct ptirq_remapping_info *entry = ptirq_dequeue_softirq(vm);
struct ptirq_msi_info *msi; struct ptirq_msi_info *msi;
if (entry == NULL) { if (entry == NULL) {
@ -469,7 +469,7 @@ void ptdev_softirq(uint16_t pcpu_id)
/* handle real request */ /* handle real request */
if (entry->intr_type == PTDEV_INTR_INTX) { if (entry->intr_type == PTDEV_INTR_INTX) {
ptdev_intr_handle_irq(vm, entry); ptirq_handle_intx(vm, entry);
} else { } else {
/* TODO: msi destmode check required */ /* TODO: msi destmode check required */
(void)vlapic_intr_msi(vm, (void)vlapic_intr_msi(vm,
@ -488,14 +488,14 @@ void ptdev_softirq(uint16_t pcpu_id)
} }
} }
void ptdev_intx_ack(struct acrn_vm *vm, uint8_t virt_pin, void ptirq_intx_ack(struct acrn_vm *vm, uint8_t virt_pin,
enum ptirq_vpin_source vpin_src) enum ptirq_vpin_source vpin_src)
{ {
uint32_t phys_irq; uint32_t phys_irq;
struct ptirq_remapping_info *entry; struct ptirq_remapping_info *entry;
bool pic_pin = (vpin_src == PTDEV_VPIN_PIC); bool pic_pin = (vpin_src == PTDEV_VPIN_PIC);
entry = ptdev_lookup_entry_by_vpin(vm, virt_pin, pic_pin); entry = ptirq_lookup_entry_by_vpin(vm, virt_pin, pic_pin);
if (entry == NULL) { if (entry == NULL) {
return; return;
} }
@ -535,7 +535,7 @@ void ptdev_intx_ack(struct acrn_vm *vm, uint8_t virt_pin,
* entry_nr = 0 means first vector * entry_nr = 0 means first vector
* user must provide bdf and entry_nr * user must provide bdf and entry_nr
*/ */
int ptdev_msix_remap(struct acrn_vm *vm, uint16_t virt_bdf, int ptirq_msix_remap(struct acrn_vm *vm, uint16_t virt_bdf,
uint16_t entry_nr, struct ptirq_msi_info *info) uint16_t entry_nr, struct ptirq_msi_info *info)
{ {
struct ptirq_remapping_info *entry; struct ptirq_remapping_info *entry;
@ -543,13 +543,13 @@ int ptdev_msix_remap(struct acrn_vm *vm, uint16_t virt_bdf,
/* /*
* Device Model should pre-hold the mapping entries by calling * Device Model should pre-hold the mapping entries by calling
* ptdev_add_msix_remapping for UOS. * ptirq_add_msix_remapping for UOS.
* *
* For SOS(vm0), it adds the mapping entries at runtime, if the * For SOS(vm0), it adds the mapping entries at runtime, if the
* entry already be held by others, return error. * entry already be held by others, return error.
*/ */
spinlock_obtain(&ptdev_lock); spinlock_obtain(&ptdev_lock);
entry = ptdev_lookup_entry_by_sid(PTDEV_INTR_MSI, &virt_sid, vm); entry = ptirq_lookup_entry_by_sid(PTDEV_INTR_MSI, &virt_sid, vm);
if (entry == NULL) { if (entry == NULL) {
/* VM0 we add mapping dynamically */ /* VM0 we add mapping dynamically */
if (is_vm0(vm)) { if (is_vm0(vm)) {
@ -561,7 +561,7 @@ int ptdev_msix_remap(struct acrn_vm *vm, uint16_t virt_bdf,
return -ENODEV; return -ENODEV;
} }
} else { } else {
/* ptdev_msix_remap is called by SOS on demand, if /* ptirq_msix_remap is called by SOS on demand, if
* failed to find pre-hold mapping, return error to * failed to find pre-hold mapping, return error to
* the caller. * the caller.
*/ */
@ -580,7 +580,7 @@ int ptdev_msix_remap(struct acrn_vm *vm, uint16_t virt_bdf,
} }
/* build physical config MSI, update to info->pmsi_xxx */ /* build physical config MSI, update to info->pmsi_xxx */
ptdev_build_physical_msi(vm, info, irq_to_vector(entry->allocated_pirq)); ptirq_build_physical_msi(vm, info, irq_to_vector(entry->allocated_pirq));
entry->msi = *info; entry->msi = *info;
dev_dbg(ACRN_DBG_IRQ, "PCI %x:%x.%x MSI VR[%d] 0x%x->0x%x assigned to vm%d", dev_dbg(ACRN_DBG_IRQ, "PCI %x:%x.%x MSI VR[%d] 0x%x->0x%x assigned to vm%d",
@ -602,7 +602,7 @@ static void activate_physical_ioapic(struct acrn_vm *vm,
gsi_mask_irq(phys_irq); gsi_mask_irq(phys_irq);
/* build physical IOAPIC RTE */ /* build physical IOAPIC RTE */
rte = ptdev_build_physical_rte(vm, entry); rte = ptirq_build_physical_rte(vm, entry);
intr_mask = (uint32_t)(rte.full & IOAPIC_RTE_INTMASK); intr_mask = (uint32_t)(rte.full & IOAPIC_RTE_INTMASK);
/* update irq trigger mode according to info in guest */ /* update irq trigger mode according to info in guest */
@ -623,7 +623,7 @@ static void activate_physical_ioapic(struct acrn_vm *vm,
/* Main entry for PCI/Legacy device assignment with INTx, calling from vIOAPIC /* Main entry for PCI/Legacy device assignment with INTx, calling from vIOAPIC
* or vPIC * or vPIC
*/ */
int ptdev_intx_pin_remap(struct acrn_vm *vm, uint8_t virt_pin, int ptirq_intx_pin_remap(struct acrn_vm *vm, uint8_t virt_pin,
enum ptirq_vpin_source vpin_src) enum ptirq_vpin_source vpin_src)
{ {
struct ptirq_remapping_info *entry; struct ptirq_remapping_info *entry;
@ -636,7 +636,7 @@ int ptdev_intx_pin_remap(struct acrn_vm *vm, uint8_t virt_pin,
* while phys pin is always means for physical IOAPIC. * while phys pin is always means for physical IOAPIC.
* *
* Device Model should pre-hold the mapping entries by calling * Device Model should pre-hold the mapping entries by calling
* ptdev_add_intx_remapping for UOS. * ptirq_add_intx_remapping for UOS.
* *
* For SOS(vm0), it adds the mapping entries at runtime, if the * For SOS(vm0), it adds the mapping entries at runtime, if the
* entry already be held by others, return error. * entry already be held by others, return error.
@ -651,7 +651,7 @@ int ptdev_intx_pin_remap(struct acrn_vm *vm, uint8_t virt_pin,
/* query if we have virt to phys mapping */ /* query if we have virt to phys mapping */
spinlock_obtain(&ptdev_lock); spinlock_obtain(&ptdev_lock);
entry = ptdev_lookup_entry_by_vpin(vm, virt_pin, pic_pin); entry = ptirq_lookup_entry_by_vpin(vm, virt_pin, pic_pin);
if (entry == NULL) { if (entry == NULL) {
if (is_vm0(vm)) { if (is_vm0(vm)) {
@ -665,7 +665,7 @@ int ptdev_intx_pin_remap(struct acrn_vm *vm, uint8_t virt_pin,
if (virt_pin < NR_LEGACY_PIN) { if (virt_pin < NR_LEGACY_PIN) {
uint8_t vpin = pic_ioapic_pin_map[virt_pin]; uint8_t vpin = pic_ioapic_pin_map[virt_pin];
entry = ptdev_lookup_entry_by_vpin(vm, vpin, !pic_pin); entry = ptirq_lookup_entry_by_vpin(vm, vpin, !pic_pin);
if (entry != NULL) { if (entry != NULL) {
need_switch_vpin_src = true; need_switch_vpin_src = true;
} }
@ -689,7 +689,7 @@ int ptdev_intx_pin_remap(struct acrn_vm *vm, uint8_t virt_pin,
} }
} }
} else { } else {
/* ptdev_intx_pin_remap is triggered by vPIC/vIOAPIC /* ptirq_intx_pin_remap is triggered by vPIC/vIOAPIC
* everytime a pin get unmask, here filter out pins * everytime a pin get unmask, here filter out pins
* not get mapped. * not get mapped.
*/ */
@ -729,7 +729,7 @@ END:
* - currently, one phys_pin can only be held by one pin source (vPIC or * - currently, one phys_pin can only be held by one pin source (vPIC or
* vIOAPIC) * vIOAPIC)
*/ */
int ptdev_add_intx_remapping(struct acrn_vm *vm, uint8_t virt_pin, uint8_t phys_pin, int ptirq_add_intx_remapping(struct acrn_vm *vm, uint8_t virt_pin, uint8_t phys_pin,
bool pic_pin) bool pic_pin)
{ {
struct ptirq_remapping_info *entry; struct ptirq_remapping_info *entry;
@ -744,7 +744,7 @@ int ptdev_add_intx_remapping(struct acrn_vm *vm, uint8_t virt_pin, uint8_t phys_
/* /*
* @pre vm != NULL * @pre vm != NULL
*/ */
void ptdev_remove_intx_remapping(struct acrn_vm *vm, uint8_t virt_pin, bool pic_pin) void ptirq_remove_intx_remapping(struct acrn_vm *vm, uint8_t virt_pin, bool pic_pin)
{ {
spinlock_obtain(&ptdev_lock); spinlock_obtain(&ptdev_lock);
remove_intx_remapping(vm, virt_pin, pic_pin); remove_intx_remapping(vm, virt_pin, pic_pin);
@ -756,7 +756,7 @@ void ptdev_remove_intx_remapping(struct acrn_vm *vm, uint8_t virt_pin, bool pic_
* - the entry is identified by phys_bdf:msi_idx: * - the entry is identified by phys_bdf:msi_idx:
* one entry vs. one phys_bdf:msi_idx * one entry vs. one phys_bdf:msi_idx
*/ */
int ptdev_add_msix_remapping(struct acrn_vm *vm, uint16_t virt_bdf, int ptirq_add_msix_remapping(struct acrn_vm *vm, uint16_t virt_bdf,
uint16_t phys_bdf, uint32_t vector_count) uint16_t phys_bdf, uint32_t vector_count)
{ {
struct ptirq_remapping_info *entry; struct ptirq_remapping_info *entry;
@ -777,7 +777,7 @@ int ptdev_add_msix_remapping(struct acrn_vm *vm, uint16_t virt_bdf,
/* /*
* @pre vm != NULL * @pre vm != NULL
*/ */
void ptdev_remove_msix_remapping(const struct acrn_vm *vm, uint16_t virt_bdf, void ptirq_remove_msix_remapping(const struct acrn_vm *vm, uint16_t virt_bdf,
uint32_t vector_count) uint32_t vector_count)
{ {
uint32_t i; uint32_t i;

View File

@ -870,10 +870,10 @@ int32_t hcall_set_ptdev_intr_info(struct acrn_vm *vm, uint16_t vmid, uint64_t pa
#endif #endif
if (irq.type == IRQ_INTX) { if (irq.type == IRQ_INTX) {
ret = ptdev_add_intx_remapping(target_vm, irq.is.intx.virt_pin, ret = ptirq_add_intx_remapping(target_vm, irq.is.intx.virt_pin,
irq.is.intx.phys_pin, irq.is.intx.pic_pin); irq.is.intx.phys_pin, irq.is.intx.pic_pin);
} else if ((irq.type == IRQ_MSI) || (irq.type == IRQ_MSIX)) { } else if ((irq.type == IRQ_MSI) || (irq.type == IRQ_MSIX)) {
ret = ptdev_add_msix_remapping(target_vm, ret = ptirq_add_msix_remapping(target_vm,
irq.virt_bdf, irq.phys_bdf, irq.virt_bdf, irq.phys_bdf,
irq.is.msix.vector_cnt); irq.is.msix.vector_cnt);
} else { } else {
@ -914,7 +914,7 @@ hcall_reset_ptdev_intr_info(struct acrn_vm *vm, uint16_t vmid, uint64_t param)
} }
if (irq.type == IRQ_INTX) { if (irq.type == IRQ_INTX) {
ptdev_remove_intx_remapping(target_vm, ptirq_remove_intx_remapping(target_vm,
irq.is.intx.virt_pin, irq.is.intx.virt_pin,
irq.is.intx.pic_pin); irq.is.intx.pic_pin);
} else if ((irq.type == IRQ_MSI) || (irq.type == IRQ_MSIX)) { } else if ((irq.type == IRQ_MSI) || (irq.type == IRQ_MSIX)) {
@ -927,7 +927,7 @@ hcall_reset_ptdev_intr_info(struct acrn_vm *vm, uint16_t vmid, uint64_t param)
vpci_reset_ptdev_intr_info(target_vm, irq.virt_bdf, irq.phys_bdf); vpci_reset_ptdev_intr_info(target_vm, irq.virt_bdf, irq.phys_bdf);
#endif #endif
ptdev_remove_msix_remapping(target_vm, ptirq_remove_msix_remapping(target_vm,
irq.virt_bdf, irq.virt_bdf,
irq.is.msix.vector_cnt); irq.is.msix.vector_cnt);
} else { } else {
@ -1076,7 +1076,7 @@ int32_t hcall_vm_intr_monitor(struct acrn_vm *vm, uint16_t vmid, uint64_t param)
switch (intr_hdr->cmd) { switch (intr_hdr->cmd) {
case INTR_CMD_GET_DATA: case INTR_CMD_GET_DATA:
intr_hdr->buf_cnt = get_vm_ptdev_intr_data(target_vm, intr_hdr->buf_cnt = ptirq_get_intr_data(target_vm,
intr_hdr->buffer, intr_hdr->buf_cnt); intr_hdr->buffer, intr_hdr->buf_cnt);
break; break;

View File

@ -18,7 +18,7 @@ bool is_entry_active(const struct ptirq_remapping_info *entry)
return atomic_load32(&entry->active) == ACTIVE_FLAG; return atomic_load32(&entry->active) == ACTIVE_FLAG;
} }
static inline uint16_t alloc_ptdev_entry_id(void) static inline uint16_t ptirq_alloc_entry_id(void)
{ {
uint16_t id = (uint16_t)ffz64_ex(ptirq_entry_bitmaps, CONFIG_MAX_PT_IRQ_ENTRIES); uint16_t id = (uint16_t)ffz64_ex(ptirq_entry_bitmaps, CONFIG_MAX_PT_IRQ_ENTRIES);
@ -32,7 +32,7 @@ static inline uint16_t alloc_ptdev_entry_id(void)
return INVALID_PTDEV_ENTRY_ID; return INVALID_PTDEV_ENTRY_ID;
} }
static void ptdev_enqueue_softirq(struct ptirq_remapping_info *entry) static void ptirq_enqueue_softirq(struct ptirq_remapping_info *entry)
{ {
uint64_t rflags; uint64_t rflags;
@ -48,16 +48,15 @@ static void ptdev_enqueue_softirq(struct ptirq_remapping_info *entry)
fire_softirq(SOFTIRQ_PTDEV); fire_softirq(SOFTIRQ_PTDEV);
} }
static void ptdev_intr_delay_callback(void *data) static void ptirq_intr_delay_callback(void *data)
{ {
struct ptirq_remapping_info *entry = struct ptirq_remapping_info *entry =
(struct ptirq_remapping_info *) data; (struct ptirq_remapping_info *) data;
ptdev_enqueue_softirq(entry); ptirq_enqueue_softirq(entry);
} }
struct ptirq_remapping_info* struct ptirq_remapping_info *ptirq_dequeue_softirq(struct acrn_vm *vm)
ptdev_dequeue_softirq(struct acrn_vm *vm)
{ {
uint64_t rflags; uint64_t rflags;
struct ptirq_remapping_info *entry = NULL; struct ptirq_remapping_info *entry = NULL;
@ -85,27 +84,26 @@ ptdev_dequeue_softirq(struct acrn_vm *vm)
return entry; return entry;
} }
struct ptirq_remapping_info * struct ptirq_remapping_info *ptirq_alloc_entry(struct acrn_vm *vm, uint32_t intr_type)
alloc_entry(struct acrn_vm *vm, uint32_t intr_type)
{ {
struct ptirq_remapping_info *entry; struct ptirq_remapping_info *entry;
uint16_t ptdev_id = alloc_ptdev_entry_id(); uint16_t ptirq_id = ptirq_alloc_entry_id();
if (ptdev_id >= CONFIG_MAX_PT_IRQ_ENTRIES) { if (ptirq_id >= CONFIG_MAX_PT_IRQ_ENTRIES) {
pr_err("Alloc ptdev irq entry failed"); pr_err("Alloc ptdev irq entry failed");
return NULL; return NULL;
} }
entry = &ptirq_entries[ptdev_id]; entry = &ptirq_entries[ptirq_id];
(void)memset((void *)entry, 0U, sizeof(struct ptirq_remapping_info)); (void)memset((void *)entry, 0U, sizeof(struct ptirq_remapping_info));
entry->ptdev_entry_id = ptdev_id; entry->ptdev_entry_id = ptirq_id;
entry->intr_type = intr_type; entry->intr_type = intr_type;
entry->vm = vm; entry->vm = vm;
entry->intr_count = 0UL; entry->intr_count = 0UL;
INIT_LIST_HEAD(&entry->softirq_node); INIT_LIST_HEAD(&entry->softirq_node);
initialize_timer(&entry->intr_delay_timer, ptdev_intr_delay_callback, initialize_timer(&entry->intr_delay_timer, ptirq_intr_delay_callback,
entry, 0UL, 0, 0UL); entry, 0UL, 0, 0UL);
atomic_clear32(&entry->active, ACTIVE_FLAG); atomic_clear32(&entry->active, ACTIVE_FLAG);
@ -113,14 +111,13 @@ alloc_entry(struct acrn_vm *vm, uint32_t intr_type)
return entry; return entry;
} }
void void ptirq_release_entry(struct ptirq_remapping_info *entry)
release_entry(struct ptirq_remapping_info *entry)
{ {
uint64_t rflags; uint64_t rflags;
/* /*
* remove entry from softirq list * remove entry from softirq list
* is required before calling release_entry. * is required before calling ptirq_release_entry.
*/ */
spinlock_irqsave_obtain(&entry->vm->softirq_dev_lock, &rflags); spinlock_irqsave_obtain(&entry->vm->softirq_dev_lock, &rflags);
list_del_init(&entry->softirq_node); list_del_init(&entry->softirq_node);
@ -129,22 +126,8 @@ release_entry(struct ptirq_remapping_info *entry)
bitmap_clear_nolock((entry->ptdev_entry_id) & 0x3FU, &ptirq_entry_bitmaps[(entry->ptdev_entry_id) >> 6U]); bitmap_clear_nolock((entry->ptdev_entry_id) & 0x3FU, &ptirq_entry_bitmaps[(entry->ptdev_entry_id) >> 6U]);
} }
static void
release_all_entries(const struct acrn_vm *vm)
{
struct ptirq_remapping_info *entry;
uint16_t idx;
for (idx = 0U; idx < CONFIG_MAX_PT_IRQ_ENTRIES; idx++) {
entry = &ptirq_entries[idx];
if (entry->vm == vm) {
release_entry(entry);
}
}
}
/* interrupt context */ /* interrupt context */
static void ptdev_interrupt_handler(__unused uint32_t irq, void *data) static void ptirq_interrupt_handler(__unused uint32_t irq, void *data)
{ {
struct ptirq_remapping_info *entry = struct ptirq_remapping_info *entry =
(struct ptirq_remapping_info *) data; (struct ptirq_remapping_info *) data;
@ -165,16 +148,16 @@ static void ptdev_interrupt_handler(__unused uint32_t irq, void *data)
} }
} }
ptdev_enqueue_softirq(entry); ptirq_enqueue_softirq(entry);
} }
/* active intr with irq registering */ /* active intr with irq registering */
int32_t ptdev_activate_entry(struct ptirq_remapping_info *entry, uint32_t phys_irq) int32_t ptirq_activate_entry(struct ptirq_remapping_info *entry, uint32_t phys_irq)
{ {
int32_t retval; int32_t retval;
/* register and allocate host vector/irq */ /* register and allocate host vector/irq */
retval = request_irq(phys_irq, ptdev_interrupt_handler, (void *)entry, IRQF_PT); retval = request_irq(phys_irq, ptirq_interrupt_handler, (void *)entry, IRQF_PT);
if (retval < 0) { if (retval < 0) {
pr_err("request irq failed, please check!, phys-irq=%d", phys_irq); pr_err("request irq failed, please check!, phys-irq=%d", phys_irq);
@ -186,8 +169,7 @@ int32_t ptdev_activate_entry(struct ptirq_remapping_info *entry, uint32_t phys_i
return retval; return retval;
} }
void void ptirq_deactivate_entry(struct ptirq_remapping_info *entry)
ptdev_deactivate_entry(struct ptirq_remapping_info *entry)
{ {
uint64_t rflags; uint64_t rflags;
@ -210,19 +192,27 @@ void ptdev_init(void)
} }
spinlock_init(&ptdev_lock); spinlock_init(&ptdev_lock);
register_softirq(SOFTIRQ_PTDEV, ptdev_softirq); register_softirq(SOFTIRQ_PTDEV, ptirq_softirq);
} }
void ptdev_release_all_entries(const struct acrn_vm *vm) void ptdev_release_all_entries(const struct acrn_vm *vm)
{ {
struct ptirq_remapping_info *entry;
uint16_t idx;
/* VM already down */ /* VM already down */
spinlock_obtain(&ptdev_lock); for (idx = 0U; idx < CONFIG_MAX_PT_IRQ_ENTRIES; idx++) {
release_all_entries(vm); entry = &ptirq_entries[idx];
spinlock_release(&ptdev_lock); if (entry->vm == vm) {
spinlock_obtain(&ptdev_lock);
ptirq_release_entry(entry);
spinlock_release(&ptdev_lock);
}
}
} }
uint32_t get_vm_ptdev_intr_data(const struct acrn_vm *target_vm, uint64_t *buffer, uint32_t ptirq_get_intr_data(const struct acrn_vm *target_vm, uint64_t *buffer, uint32_t buffer_cnt)
uint32_t buffer_cnt)
{ {
uint32_t index = 0U; uint32_t index = 0U;
uint16_t i; uint16_t i;

View File

@ -400,7 +400,7 @@ vioapic_indirect_write(struct acrn_vioapic *vioapic, uint32_t addr,
((last.full & IOAPIC_RTE_INTMASK) == 0UL)) { ((last.full & IOAPIC_RTE_INTMASK) == 0UL)) {
/* VM enable intr */ /* VM enable intr */
/* NOTE: only support max 256 pin */ /* NOTE: only support max 256 pin */
(void)ptdev_intx_pin_remap(vioapic->vm, (void)ptirq_intx_pin_remap(vioapic->vm,
(uint8_t)pin, PTDEV_VPIN_IOAPIC); (uint8_t)pin, PTDEV_VPIN_IOAPIC);
} }
} }
@ -468,7 +468,7 @@ vioapic_process_eoi(struct acrn_vm *vm, uint32_t vector)
continue; continue;
} }
ptdev_intx_ack(vm, (uint8_t)pin, PTDEV_VPIN_IOAPIC); ptirq_intx_ack(vm, (uint8_t)pin, PTDEV_VPIN_IOAPIC);
} }
/* /*

View File

@ -78,7 +78,7 @@ static int32_t vmsi_remap(struct pci_vdev *vdev, bool enable)
info.vmsi_data = 0U; info.vmsi_data = 0U;
} }
ret = ptdev_msix_remap(vm, vdev->vbdf.value, 0U, &info); ret = ptirq_msix_remap(vm, vdev->vbdf.value, 0U, &info);
if (ret == 0) { if (ret == 0) {
/* Update MSI Capability structure to physical device */ /* Update MSI Capability structure to physical device */
pci_pdev_write_cfg(pbdf, capoff + PCIR_MSI_ADDR, 0x4U, (uint32_t)info.pmsi_addr); pci_pdev_write_cfg(pbdf, capoff + PCIR_MSI_ADDR, 0x4U, (uint32_t)info.pmsi_addr);
@ -220,7 +220,7 @@ void populate_msi_struct(struct pci_vdev *vdev)
static int32_t vmsi_deinit(struct pci_vdev *vdev) static int32_t vmsi_deinit(struct pci_vdev *vdev)
{ {
if (vdev->msi.capoff != 0U) { if (vdev->msi.capoff != 0U) {
ptdev_remove_msix_remapping(vdev->vpci->vm, vdev->vbdf.value, 1U); ptirq_remove_msix_remapping(vdev->vpci->vm, vdev->vbdf.value, 1U);
} }
return 0; return 0;

View File

@ -59,7 +59,7 @@ static int vmsix_remap_entry(struct pci_vdev *vdev, uint32_t index, bool enable)
info.vmsi_addr = vdev->msix.tables[index].addr; info.vmsi_addr = vdev->msix.tables[index].addr;
info.vmsi_data = (enable) ? vdev->msix.tables[index].data : 0U; info.vmsi_data = (enable) ? vdev->msix.tables[index].data : 0U;
ret = ptdev_msix_remap(vdev->vpci->vm, vdev->vbdf.value, (uint16_t)index, &info); ret = ptirq_msix_remap(vdev->vpci->vm, vdev->vbdf.value, (uint16_t)index, &info);
if (ret == 0) { if (ret == 0) {
/* Write the table entry to the physical structure */ /* Write the table entry to the physical structure */
hva = vdev->msix.mmio_hva + vdev->msix.table_offset; hva = vdev->msix.mmio_hva + vdev->msix.table_offset;
@ -412,7 +412,7 @@ static int vmsix_deinit(struct pci_vdev *vdev)
vdev->msix.intercepted_size = 0U; vdev->msix.intercepted_size = 0U;
if (vdev->msix.table_count != 0U) { if (vdev->msix.table_count != 0U) {
ptdev_remove_msix_remapping(vdev->vpci->vm, vdev->vbdf.value, vdev->msix.table_count); ptirq_remove_msix_remapping(vdev->vpci->vm, vdev->vbdf.value, vdev->msix.table_count);
} }
return 0; return 0;

View File

@ -328,7 +328,7 @@ static int vpic_ocw1(const struct acrn_vpic *vpic, struct i8259_reg_state *i8259
virt_pin = (master_pic(vpic, i8259)) ? virt_pin = (master_pic(vpic, i8259)) ?
pin : (pin + 8U); pin : (pin + 8U);
(void)ptdev_intx_pin_remap(vpic->vm, (void)ptirq_intx_pin_remap(vpic->vm,
virt_pin, PTDEV_VPIN_PIC); virt_pin, PTDEV_VPIN_PIC);
} }
pin = (pin + 1U) & 0x7U; pin = (pin + 1U) & 0x7U;
@ -365,7 +365,7 @@ static int vpic_ocw2(struct acrn_vpic *vpic, struct i8259_reg_state *i8259, uint
/* if level ack PTDEV */ /* if level ack PTDEV */
if ((i8259->elc & (1U << (isr_bit & 0x7U))) != 0U) { if ((i8259->elc & (1U << (isr_bit & 0x7U))) != 0U) {
ptdev_intx_ack(vpic->vm, ptirq_intx_ack(vpic->vm,
(master_pic(vpic, i8259) ? isr_bit : isr_bit + 8U), (master_pic(vpic, i8259) ? isr_bit : isr_bit + 8U),
PTDEV_VPIN_PIC); PTDEV_VPIN_PIC);
} }

View File

@ -36,7 +36,7 @@
* @pre vm != NULL * @pre vm != NULL
* *
*/ */
void ptdev_intx_ack(struct acrn_vm *vm, uint8_t virt_pin, enum ptirq_vpin_source vpin_src); void ptirq_intx_ack(struct acrn_vm *vm, uint8_t virt_pin, enum ptirq_vpin_source vpin_src);
/** /**
* @brief MSI/MSI-x remapping for passthrough device. * @brief MSI/MSI-x remapping for passthrough device.
@ -59,7 +59,7 @@ void ptdev_intx_ack(struct acrn_vm *vm, uint8_t virt_pin, enum ptirq_vpin_source
* @pre info != NULL * @pre info != NULL
* *
*/ */
int ptdev_msix_remap(struct acrn_vm *vm, uint16_t virt_bdf, uint16_t entry_nr, struct ptirq_msi_info *info); int ptirq_msix_remap(struct acrn_vm *vm, uint16_t virt_bdf, uint16_t entry_nr, struct ptirq_msi_info *info);
/** /**
@ -81,7 +81,7 @@ int ptdev_msix_remap(struct acrn_vm *vm, uint16_t virt_bdf, uint16_t entry_nr, s
* @pre vm != NULL * @pre vm != NULL
* *
*/ */
int ptdev_intx_pin_remap(struct acrn_vm *vm, uint8_t virt_pin, enum ptirq_vpin_source vpin_src); int ptirq_intx_pin_remap(struct acrn_vm *vm, uint8_t virt_pin, enum ptirq_vpin_source vpin_src);
/** /**
* @brief Add an interrupt remapping entry for INTx as pre-hold mapping. * @brief Add an interrupt remapping entry for INTx as pre-hold mapping.
@ -103,7 +103,7 @@ int ptdev_intx_pin_remap(struct acrn_vm *vm, uint8_t virt_pin, enum ptirq_vpin_s
* @pre vm != NULL * @pre vm != NULL
* *
*/ */
int ptdev_add_intx_remapping(struct acrn_vm *vm, uint8_t virt_pin, uint8_t phys_pin, bool pic_pin); int ptirq_add_intx_remapping(struct acrn_vm *vm, uint8_t virt_pin, uint8_t phys_pin, bool pic_pin);
/** /**
* @brief Remove an interrupt remapping entry for INTx. * @brief Remove an interrupt remapping entry for INTx.
@ -119,7 +119,7 @@ int ptdev_add_intx_remapping(struct acrn_vm *vm, uint8_t virt_pin, uint8_t phys_
* @pre vm != NULL * @pre vm != NULL
* *
*/ */
void ptdev_remove_intx_remapping(struct acrn_vm *vm, uint8_t virt_pin, bool pic_pin); void ptirq_remove_intx_remapping(struct acrn_vm *vm, uint8_t virt_pin, bool pic_pin);
/** /**
* @brief Add interrupt remapping entry/entries for MSI/MSI-x as pre-hold mapping. * @brief Add interrupt remapping entry/entries for MSI/MSI-x as pre-hold mapping.
@ -140,7 +140,7 @@ void ptdev_remove_intx_remapping(struct acrn_vm *vm, uint8_t virt_pin, bool pic_
* @pre vm != NULL * @pre vm != NULL
* *
*/ */
int ptdev_add_msix_remapping(struct acrn_vm *vm, uint16_t virt_bdf, uint16_t phys_bdf, uint32_t vector_count); int ptirq_add_msix_remapping(struct acrn_vm *vm, uint16_t virt_bdf, uint16_t phys_bdf, uint32_t vector_count);
/** /**
* @brief Remove interrupt remapping entry/entries for MSI/MSI-x. * @brief Remove interrupt remapping entry/entries for MSI/MSI-x.
@ -156,7 +156,7 @@ int ptdev_add_msix_remapping(struct acrn_vm *vm, uint16_t virt_bdf, uint16_t phy
* @pre vm != NULL * @pre vm != NULL
* *
*/ */
void ptdev_remove_msix_remapping(const struct acrn_vm *vm, uint16_t virt_bdf, uint32_t vector_count); void ptirq_remove_msix_remapping(const struct acrn_vm *vm, uint16_t virt_bdf, uint32_t vector_count);
/** /**
* @} * @}

View File

@ -72,16 +72,16 @@ extern struct ptirq_remapping_info ptirq_entries[];
extern spinlock_t ptdev_lock; extern spinlock_t ptdev_lock;
bool is_entry_active(const struct ptirq_remapping_info *entry); bool is_entry_active(const struct ptirq_remapping_info *entry);
void ptdev_softirq(uint16_t pcpu_id); void ptirq_softirq(uint16_t pcpu_id);
void ptdev_init(void); void ptdev_init(void);
void ptdev_release_all_entries(const struct acrn_vm *vm); void ptdev_release_all_entries(const struct acrn_vm *vm);
struct ptirq_remapping_info *ptdev_dequeue_softirq(struct acrn_vm *vm); struct ptirq_remapping_info *ptirq_dequeue_softirq(struct acrn_vm *vm);
struct ptirq_remapping_info *alloc_entry(struct acrn_vm *vm, uint32_t intr_type); struct ptirq_remapping_info *ptirq_alloc_entry(struct acrn_vm *vm, uint32_t intr_type);
void release_entry(struct ptirq_remapping_info *entry); void ptirq_release_entry(struct ptirq_remapping_info *entry);
int32_t ptdev_activate_entry(struct ptirq_remapping_info *entry, uint32_t phys_irq); int32_t ptirq_activate_entry(struct ptirq_remapping_info *entry, uint32_t phys_irq);
void ptdev_deactivate_entry(struct ptirq_remapping_info *entry); void ptirq_deactivate_entry(struct ptirq_remapping_info *entry);
uint32_t get_vm_ptdev_intr_data(const struct acrn_vm *target_vm, uint64_t *buffer, uint32_t buffer_cnt); uint32_t ptirq_get_intr_data(const struct acrn_vm *target_vm, uint64_t *buffer, uint32_t buffer_cnt);
#endif /* PTDEV_H */ #endif /* PTDEV_H */