diff --git a/hypervisor/arch/x86/assign.c b/hypervisor/arch/x86/assign.c index 4a61d747c..c7095c86d 100644 --- a/hypervisor/arch/x86/assign.c +++ b/hypervisor/arch/x86/assign.c @@ -789,114 +789,3 @@ void ptdev_remove_msix_remapping(const struct acrn_vm *vm, uint16_t virt_bdf, spinlock_release(&ptdev_lock); } } - -#ifdef HV_DEBUG -#define PTDEV_INVALID_PIN 0xffU -static void get_entry_info(const struct ptdev_remapping_info *entry, char *type, - uint32_t *irq, uint32_t *vector, uint64_t *dest, bool *lvl_tm, - uint8_t *pin, uint8_t *vpin, uint32_t *bdf, uint32_t *vbdf) -{ - if (is_entry_active(entry)) { - if (entry->intr_type == PTDEV_INTR_MSI) { - (void)strcpy_s(type, 16U, "MSI"); - *dest = (entry->msi.pmsi_addr & 0xFF000U) >> CPU_PAGE_SHIFT; - if ((entry->msi.pmsi_data & APIC_TRIGMOD_LEVEL) != 0U) { - *lvl_tm = true; - } else { - *lvl_tm = false; - } - *pin = PTDEV_INVALID_PIN; - *vpin = PTDEV_INVALID_PIN; - *bdf = entry->phys_sid.msi_id.bdf; - *vbdf = entry->virt_sid.msi_id.bdf; - } else { - uint32_t phys_irq = entry->allocated_pirq; - union ioapic_rte rte; - - if (entry->virt_sid.intx_id.src == PTDEV_VPIN_IOAPIC) { - (void)strcpy_s(type, 16U, "IOAPIC"); - } else { - (void)strcpy_s(type, 16U, "PIC"); - } - ioapic_get_rte(phys_irq, &rte); - *dest = rte.full >> IOAPIC_RTE_DEST_SHIFT; - if ((rte.full & IOAPIC_RTE_TRGRLVL) != 0UL) { - *lvl_tm = true; - } else { - *lvl_tm = false; - } - *pin = entry->phys_sid.intx_id.pin; - *vpin = entry->virt_sid.intx_id.pin; - *bdf = 0U; - *vbdf = 0U; - } - *irq = entry->allocated_pirq; - *vector = irq_to_vector(entry->allocated_pirq); - } else { - (void)strcpy_s(type, 16U, "NONE"); - *irq = IRQ_INVALID; - *vector = 0U; - *dest = 0UL; - *lvl_tm = 0; - *pin = -1; - *vpin = -1; - *bdf = 0U; - *vbdf = 0U; - } -} - -void get_ptdev_info(char *str_arg, size_t str_max) -{ - char *str = str_arg; - struct ptdev_remapping_info *entry; - uint16_t idx; - size_t len, size = str_max; - uint32_t irq, vector; - char type[16]; - uint64_t dest; - bool lvl_tm; - uint8_t pin, vpin; - uint32_t bdf, vbdf; - - len = snprintf(str, size, "\r\nVM\tTYPE\tIRQ\tVEC\tDEST\tTM\tPIN\tVPIN\tBDF\tVBDF"); - if (len >= size) { - goto overflow; - } - size -= len; - str += len; - - for (idx = 0U; idx < CONFIG_MAX_PT_IRQ_ENTRIES; idx++) { - entry = &ptdev_irq_entries[idx]; - if (is_entry_active(entry)) { - get_entry_info(entry, type, &irq, &vector, - &dest, &lvl_tm, &pin, &vpin, - &bdf, &vbdf); - len = snprintf(str, size, "\r\n%d\t%s\t%d\t0x%X\t0x%X", - entry->vm->vm_id, type, irq, vector, dest); - if (len >= size) { - goto overflow; - } - size -= len; - str += len; - - len = snprintf(str, size, "\t%s\t%hhu\t%hhu\t%x:%x.%x\t%x:%x.%x", - is_entry_active(entry) ? (lvl_tm ? "level" : "edge") : "none", - pin, vpin, (bdf & 0xff00U) >> 8U, - (bdf & 0xf8U) >> 3U, bdf & 0x7U, - (vbdf & 0xff00U) >> 8U, - (vbdf & 0xf8U) >> 3U, vbdf & 0x7U); - if (len >= size) { - goto overflow; - } - size -= len; - str += len; - } - } - - snprintf(str, size, "\r\n"); - return; - -overflow: - printf("buffer size could not be enough! please check!\n"); -} -#endif /* HV_DEBUG */ diff --git a/hypervisor/debug/shell.c b/hypervisor/debug/shell.c index cb454ebd1..4595bd375 100644 --- a/hypervisor/debug/shell.c +++ b/hypervisor/debug/shell.c @@ -908,6 +908,115 @@ static int shell_show_cpu_int(__unused int argc, __unused char **argv) return 0; } +#define PTDEV_INVALID_PIN 0xffU +static void get_entry_info(const struct ptdev_remapping_info *entry, char *type, + uint32_t *irq, uint32_t *vector, uint64_t *dest, bool *lvl_tm, + uint8_t *pin, uint8_t *vpin, uint32_t *bdf, uint32_t *vbdf) +{ + if (is_entry_active(entry)) { + if (entry->intr_type == PTDEV_INTR_MSI) { + (void)strcpy_s(type, 16U, "MSI"); + *dest = (entry->msi.pmsi_addr & 0xFF000U) >> CPU_PAGE_SHIFT; + if ((entry->msi.pmsi_data & APIC_TRIGMOD_LEVEL) != 0U) { + *lvl_tm = true; + } else { + *lvl_tm = false; + } + *pin = PTDEV_INVALID_PIN; + *vpin = PTDEV_INVALID_PIN; + *bdf = entry->phys_sid.msi_id.bdf; + *vbdf = entry->virt_sid.msi_id.bdf; + } else { + uint32_t phys_irq = entry->allocated_pirq; + union ioapic_rte rte; + + if (entry->virt_sid.intx_id.src == PTDEV_VPIN_IOAPIC) { + (void)strcpy_s(type, 16U, "IOAPIC"); + } else { + (void)strcpy_s(type, 16U, "PIC"); + } + ioapic_get_rte(phys_irq, &rte); + *dest = rte.full >> IOAPIC_RTE_DEST_SHIFT; + if ((rte.full & IOAPIC_RTE_TRGRLVL) != 0UL) { + *lvl_tm = true; + } else { + *lvl_tm = false; + } + *pin = entry->phys_sid.intx_id.pin; + *vpin = entry->virt_sid.intx_id.pin; + *bdf = 0U; + *vbdf = 0U; + } + *irq = entry->allocated_pirq; + *vector = irq_to_vector(entry->allocated_pirq); + } else { + (void)strcpy_s(type, 16U, "NONE"); + *irq = IRQ_INVALID; + *vector = 0U; + *dest = 0UL; + *lvl_tm = 0; + *pin = -1; + *vpin = -1; + *bdf = 0U; + *vbdf = 0U; + } +} + +static void get_ptdev_info(char *str_arg, size_t str_max) +{ + char *str = str_arg; + struct ptdev_remapping_info *entry; + uint16_t idx; + size_t len, size = str_max; + uint32_t irq, vector; + char type[16]; + uint64_t dest; + bool lvl_tm; + uint8_t pin, vpin; + uint32_t bdf, vbdf; + + len = snprintf(str, size, "\r\nVM\tTYPE\tIRQ\tVEC\tDEST\tTM\tPIN\tVPIN\tBDF\tVBDF"); + if (len >= size) { + goto overflow; + } + size -= len; + str += len; + + for (idx = 0U; idx < CONFIG_MAX_PT_IRQ_ENTRIES; idx++) { + entry = &ptdev_irq_entries[idx]; + if (is_entry_active(entry)) { + get_entry_info(entry, type, &irq, &vector, + &dest, &lvl_tm, &pin, &vpin, + &bdf, &vbdf); + len = snprintf(str, size, "\r\n%d\t%s\t%d\t0x%X\t0x%X", + entry->vm->vm_id, type, irq, vector, dest); + if (len >= size) { + goto overflow; + } + size -= len; + str += len; + + len = snprintf(str, size, "\t%s\t%hhu\t%hhu\t%x:%x.%x\t%x:%x.%x", + is_entry_active(entry) ? (lvl_tm ? "level" : "edge") : "none", + pin, vpin, (bdf & 0xff00U) >> 8U, + (bdf & 0xf8U) >> 3U, bdf & 0x7U, + (vbdf & 0xff00U) >> 8U, + (vbdf & 0xf8U) >> 3U, vbdf & 0x7U); + if (len >= size) { + goto overflow; + } + size -= len; + str += len; + } + } + + snprintf(str, size, "\r\n"); + return; + +overflow: + printf("buffer size could not be enough! please check!\n"); +} + static int shell_show_ptdev_info(__unused int argc, __unused char **argv) { get_ptdev_info(shell_log_buf, SHELL_LOG_BUF_SIZE); diff --git a/hypervisor/include/common/ptdev.h b/hypervisor/include/common/ptdev.h index 2ee471d4c..e3f02b8fc 100644 --- a/hypervisor/include/common/ptdev.h +++ b/hypervisor/include/common/ptdev.h @@ -77,17 +77,11 @@ void ptdev_init(void); void ptdev_release_all_entries(const struct acrn_vm *vm); struct ptdev_remapping_info *ptdev_dequeue_softirq(struct acrn_vm *vm); -struct ptdev_remapping_info *alloc_entry(struct acrn_vm *vm, - uint32_t intr_type); +struct ptdev_remapping_info *alloc_entry(struct acrn_vm *vm, uint32_t intr_type); void release_entry(struct ptdev_remapping_info *entry); int32_t ptdev_activate_entry(struct ptdev_remapping_info *entry, uint32_t phys_irq); void ptdev_deactivate_entry(struct ptdev_remapping_info *entry); -#ifdef HV_DEBUG -void get_ptdev_info(char *str_arg, size_t str_max); -#endif /* HV_DEBUG */ - -uint32_t get_vm_ptdev_intr_data(const struct acrn_vm *target_vm, uint64_t *buffer, - uint32_t buffer_cnt); +uint32_t get_vm_ptdev_intr_data(const struct acrn_vm *target_vm, uint64_t *buffer, uint32_t buffer_cnt); #endif /* PTDEV_H */