@@ -394,6 +394,8 @@ int kvm_riscv_aia_alloc_hgei(int cpu, struct kvm_vcpu *owner,
394
394
{
395
395
int ret = - ENOENT ;
396
396
unsigned long flags ;
397
+ const struct imsic_global_config * gc ;
398
+ const struct imsic_local_config * lc ;
397
399
struct aia_hgei_control * hgctrl = per_cpu_ptr (& aia_hgei , cpu );
398
400
399
401
if (!kvm_riscv_aia_available () || !hgctrl )
@@ -409,11 +411,14 @@ int kvm_riscv_aia_alloc_hgei(int cpu, struct kvm_vcpu *owner,
409
411
410
412
raw_spin_unlock_irqrestore (& hgctrl -> lock , flags );
411
413
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
+ }
417
422
418
423
return ret ;
419
424
}
@@ -605,9 +610,11 @@ void kvm_riscv_aia_disable(void)
605
610
int kvm_riscv_aia_init (void )
606
611
{
607
612
int rc ;
613
+ const struct imsic_global_config * gc ;
608
614
609
615
if (!riscv_isa_extension_available (NULL , SxAIA ))
610
616
return - ENODEV ;
617
+ gc = imsic_get_global_config ();
611
618
612
619
/* Figure-out number of bits in HGEIE */
613
620
csr_write (CSR_HGEIE , -1UL );
@@ -619,17 +626,17 @@ int kvm_riscv_aia_init(void)
619
626
/*
620
627
* Number of usable HGEI lines should be minimum of per-HART
621
628
* IMSIC guest files and number of bits in HGEIE
622
- *
623
- * TODO: To be updated later by AIA IMSIC HW guest file support
624
629
*/
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 ;
626
635
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 */
632
637
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 ;
633
640
634
641
/* Initialize guest external interrupt line management */
635
642
rc = aia_hgei_init ();
0 commit comments