Skip to content

Commit 3385339

Browse files
committed
RISC-V: KVM: Use IMSIC guest files when available
Let us discover and use IMSIC guest files from the IMSIC global config provided by the IMSIC irqchip driver. Signed-off-by: Anup Patel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
1 parent e5b088c commit 3385339

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

arch/riscv/kvm/aia.c

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ int kvm_riscv_aia_alloc_hgei(int cpu, struct kvm_vcpu *owner,
394394
{
395395
int ret = -ENOENT;
396396
unsigned long flags;
397+
const struct imsic_global_config *gc;
398+
const struct imsic_local_config *lc;
397399
struct aia_hgei_control *hgctrl = per_cpu_ptr(&aia_hgei, cpu);
398400

399401
if (!kvm_riscv_aia_available() || !hgctrl)
@@ -409,11 +411,14 @@ int kvm_riscv_aia_alloc_hgei(int cpu, struct kvm_vcpu *owner,
409411

410412
raw_spin_unlock_irqrestore(&hgctrl->lock, flags);
411413

412-
/* TODO: To be updated later by AIA IMSIC HW guest file support */
413-
if (hgei_va)
414-
*hgei_va = NULL;
415-
if (hgei_pa)
416-
*hgei_pa = 0;
414+
gc = imsic_get_global_config();
415+
lc = (gc) ? per_cpu_ptr(gc->local, cpu) : NULL;
416+
if (lc && ret > 0) {
417+
if (hgei_va)
418+
*hgei_va = lc->msi_va + (ret * IMSIC_MMIO_PAGE_SZ);
419+
if (hgei_pa)
420+
*hgei_pa = lc->msi_pa + (ret * IMSIC_MMIO_PAGE_SZ);
421+
}
417422

418423
return ret;
419424
}
@@ -605,9 +610,11 @@ void kvm_riscv_aia_disable(void)
605610
int kvm_riscv_aia_init(void)
606611
{
607612
int rc;
613+
const struct imsic_global_config *gc;
608614

609615
if (!riscv_isa_extension_available(NULL, SxAIA))
610616
return -ENODEV;
617+
gc = imsic_get_global_config();
611618

612619
/* Figure-out number of bits in HGEIE */
613620
csr_write(CSR_HGEIE, -1UL);
@@ -619,17 +626,17 @@ int kvm_riscv_aia_init(void)
619626
/*
620627
* Number of usable HGEI lines should be minimum of per-HART
621628
* IMSIC guest files and number of bits in HGEIE
622-
*
623-
* TODO: To be updated later by AIA IMSIC HW guest file support
624629
*/
625-
kvm_riscv_aia_nr_hgei = 0;
630+
if (gc)
631+
kvm_riscv_aia_nr_hgei = min((ulong)kvm_riscv_aia_nr_hgei,
632+
BIT(gc->guest_index_bits) - 1);
633+
else
634+
kvm_riscv_aia_nr_hgei = 0;
626635

627-
/*
628-
* Find number of guest MSI IDs
629-
*
630-
* TODO: To be updated later by AIA IMSIC HW guest file support
631-
*/
636+
/* Find number of guest MSI IDs */
632637
kvm_riscv_aia_max_ids = IMSIC_MAX_ID;
638+
if (gc && kvm_riscv_aia_nr_hgei)
639+
kvm_riscv_aia_max_ids = gc->nr_guest_ids + 1;
633640

634641
/* Initialize guest external interrupt line management */
635642
rc = aia_hgei_init();

0 commit comments

Comments
 (0)