@@ -825,11 +825,6 @@ static int iommu_ga_log_enable(struct amd_iommu *iommu)
825825 if (!iommu -> ga_log )
826826 return - EINVAL ;
827827
828- /* Check if already running */
829- status = readl (iommu -> mmio_base + MMIO_STATUS_OFFSET );
830- if (WARN_ON (status & (MMIO_STATUS_GALOG_RUN_MASK )))
831- return 0 ;
832-
833828 entry = iommu_virt_to_phys (iommu -> ga_log ) | GA_LOG_SIZE_512 ;
834829 memcpy_toio (iommu -> mmio_base + MMIO_GA_LOG_BASE_OFFSET ,
835830 & entry , sizeof (entry ));
@@ -1915,10 +1910,6 @@ static int __init iommu_init_pci(struct amd_iommu *iommu)
19151910 if (iommu_feature (iommu , FEATURE_PPR ) && alloc_ppr_log (iommu ))
19161911 return - ENOMEM ;
19171912
1918- ret = iommu_init_ga_log (iommu );
1919- if (ret )
1920- return ret ;
1921-
19221913 if (iommu -> cap & (1UL << IOMMU_CAP_NPCACHE )) {
19231914 pr_info ("Using strict mode due to virtualization\n" );
19241915 iommu_set_dma_strict ();
@@ -1995,8 +1986,6 @@ static void print_iommu_info(void)
19951986 }
19961987 if (irq_remapping_enabled ) {
19971988 pr_info ("Interrupt remapping enabled\n" );
1998- if (AMD_IOMMU_GUEST_IR_VAPIC (amd_iommu_guest_ir ))
1999- pr_info ("Virtual APIC enabled\n" );
20001989 if (amd_iommu_xt_mode == IRQ_REMAP_X2APIC_MODE )
20011990 pr_info ("X2APIC enabled\n" );
20021991 }
@@ -2277,9 +2266,6 @@ static int iommu_init_irq(struct amd_iommu *iommu)
22772266
22782267 if (iommu -> ppr_log != NULL )
22792268 iommu_feature_enable (iommu , CONTROL_PPRINT_EN );
2280-
2281- iommu_ga_log_enable (iommu );
2282-
22832269 return 0 ;
22842270}
22852271
@@ -2485,8 +2471,6 @@ static void iommu_enable_ga(struct amd_iommu *iommu)
24852471#ifdef CONFIG_IRQ_REMAP
24862472 switch (amd_iommu_guest_ir ) {
24872473 case AMD_IOMMU_GUEST_IR_VAPIC :
2488- iommu_feature_enable (iommu , CONTROL_GAM_EN );
2489- fallthrough ;
24902474 case AMD_IOMMU_GUEST_IR_LEGACY_GA :
24912475 iommu_feature_enable (iommu , CONTROL_GA_EN );
24922476 iommu -> irte_ops = & irte_128_ops ;
@@ -2557,19 +2541,6 @@ static void early_enable_iommus(void)
25572541 iommu_flush_all_caches (iommu );
25582542 }
25592543 }
2560-
2561- #ifdef CONFIG_IRQ_REMAP
2562- /*
2563- * Note: We have already checked GASup from IVRS table.
2564- * Now, we need to make sure that GAMSup is set.
2565- */
2566- if (AMD_IOMMU_GUEST_IR_VAPIC (amd_iommu_guest_ir ) &&
2567- !check_feature_on_all_iommus (FEATURE_GAM_VAPIC ))
2568- amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY_GA ;
2569-
2570- if (AMD_IOMMU_GUEST_IR_VAPIC (amd_iommu_guest_ir ))
2571- amd_iommu_irq_ops .capability |= (1 << IRQ_POSTING_CAP );
2572- #endif
25732544}
25742545
25752546static void enable_iommus_v2 (void )
@@ -2582,10 +2553,64 @@ static void enable_iommus_v2(void)
25822553 }
25832554}
25842555
2556+ static void enable_iommus_vapic (void )
2557+ {
2558+ #ifdef CONFIG_IRQ_REMAP
2559+ u32 status , i ;
2560+ struct amd_iommu * iommu ;
2561+
2562+ for_each_iommu (iommu ) {
2563+ /*
2564+ * Disable GALog if already running. It could have been enabled
2565+ * in the previous boot before kdump.
2566+ */
2567+ status = readl (iommu -> mmio_base + MMIO_STATUS_OFFSET );
2568+ if (!(status & MMIO_STATUS_GALOG_RUN_MASK ))
2569+ continue ;
2570+
2571+ iommu_feature_disable (iommu , CONTROL_GALOG_EN );
2572+ iommu_feature_disable (iommu , CONTROL_GAINT_EN );
2573+
2574+ /*
2575+ * Need to set and poll check the GALOGRun bit to zero before
2576+ * we can set/ modify GA Log registers safely.
2577+ */
2578+ for (i = 0 ; i < LOOP_TIMEOUT ; ++ i ) {
2579+ status = readl (iommu -> mmio_base + MMIO_STATUS_OFFSET );
2580+ if (!(status & MMIO_STATUS_GALOG_RUN_MASK ))
2581+ break ;
2582+ udelay (10 );
2583+ }
2584+
2585+ if (WARN_ON (i >= LOOP_TIMEOUT ))
2586+ return ;
2587+ }
2588+
2589+ if (AMD_IOMMU_GUEST_IR_VAPIC (amd_iommu_guest_ir ) &&
2590+ !check_feature_on_all_iommus (FEATURE_GAM_VAPIC )) {
2591+ amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY_GA ;
2592+ return ;
2593+ }
2594+
2595+ /* Enabling GAM support */
2596+ for_each_iommu (iommu ) {
2597+ if (iommu_init_ga_log (iommu ) ||
2598+ iommu_ga_log_enable (iommu ))
2599+ return ;
2600+
2601+ iommu_feature_enable (iommu , CONTROL_GAM_EN );
2602+ }
2603+
2604+ amd_iommu_irq_ops .capability |= (1 << IRQ_POSTING_CAP );
2605+ pr_info ("Virtual APIC enabled\n" );
2606+ #endif
2607+ }
2608+
2609+
25852610static void enable_iommus (void )
25862611{
25872612 early_enable_iommus ();
2588-
2613+ enable_iommus_vapic ();
25892614 enable_iommus_v2 ();
25902615}
25912616
@@ -2983,6 +3008,7 @@ static int __init state_next(void)
29833008 register_syscore_ops (& amd_iommu_syscore_ops );
29843009 ret = amd_iommu_init_pci ();
29853010 init_state = ret ? IOMMU_INIT_ERROR : IOMMU_PCI_INIT ;
3011+ enable_iommus_vapic ();
29863012 enable_iommus_v2 ();
29873013 break ;
29883014 case IOMMU_PCI_INIT :
0 commit comments