@@ -908,11 +908,6 @@ static int iommu_ga_log_enable(struct amd_iommu *iommu)
908908 if (!iommu -> ga_log )
909909 return - EINVAL ;
910910
911- /* Check if already running */
912- status = readl (iommu -> mmio_base + MMIO_STATUS_OFFSET );
913- if (WARN_ON (status & (MMIO_STATUS_GALOG_RUN_MASK )))
914- return 0 ;
915-
916911 entry = iommu_virt_to_phys (iommu -> ga_log ) | GA_LOG_SIZE_512 ;
917912 memcpy_toio (iommu -> mmio_base + MMIO_GA_LOG_BASE_OFFSET ,
918913 & entry , sizeof (entry ));
@@ -2068,10 +2063,6 @@ static int __init iommu_init_pci(struct amd_iommu *iommu)
20682063 if (iommu_feature (iommu , FEATURE_PPR ) && alloc_ppr_log (iommu ))
20692064 return - ENOMEM ;
20702065
2071- ret = iommu_init_ga_log (iommu );
2072- if (ret )
2073- return ret ;
2074-
20752066 if (iommu -> cap & (1UL << IOMMU_CAP_NPCACHE )) {
20762067 pr_info ("Using strict mode due to virtualization\n" );
20772068 iommu_set_dma_strict ();
@@ -2155,8 +2146,6 @@ static void print_iommu_info(void)
21552146 }
21562147 if (irq_remapping_enabled ) {
21572148 pr_info ("Interrupt remapping enabled\n" );
2158- if (AMD_IOMMU_GUEST_IR_VAPIC (amd_iommu_guest_ir ))
2159- pr_info ("Virtual APIC enabled\n" );
21602149 if (amd_iommu_xt_mode == IRQ_REMAP_X2APIC_MODE )
21612150 pr_info ("X2APIC enabled\n" );
21622151 }
@@ -2446,9 +2435,6 @@ static int iommu_init_irq(struct amd_iommu *iommu)
24462435
24472436 if (iommu -> ppr_log != NULL )
24482437 iommu_feature_enable (iommu , CONTROL_PPRINT_EN );
2449-
2450- iommu_ga_log_enable (iommu );
2451-
24522438 return 0 ;
24532439}
24542440
@@ -2678,8 +2664,6 @@ static void iommu_enable_ga(struct amd_iommu *iommu)
26782664#ifdef CONFIG_IRQ_REMAP
26792665 switch (amd_iommu_guest_ir ) {
26802666 case AMD_IOMMU_GUEST_IR_VAPIC :
2681- iommu_feature_enable (iommu , CONTROL_GAM_EN );
2682- fallthrough ;
26832667 case AMD_IOMMU_GUEST_IR_LEGACY_GA :
26842668 iommu_feature_enable (iommu , CONTROL_GA_EN );
26852669 iommu -> irte_ops = & irte_128_ops ;
@@ -2759,19 +2743,6 @@ static void early_enable_iommus(void)
27592743 iommu_flush_all_caches (iommu );
27602744 }
27612745 }
2762-
2763- #ifdef CONFIG_IRQ_REMAP
2764- /*
2765- * Note: We have already checked GASup from IVRS table.
2766- * Now, we need to make sure that GAMSup is set.
2767- */
2768- if (AMD_IOMMU_GUEST_IR_VAPIC (amd_iommu_guest_ir ) &&
2769- !check_feature_on_all_iommus (FEATURE_GAM_VAPIC ))
2770- amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY_GA ;
2771-
2772- if (AMD_IOMMU_GUEST_IR_VAPIC (amd_iommu_guest_ir ))
2773- amd_iommu_irq_ops .capability |= (1 << IRQ_POSTING_CAP );
2774- #endif
27752746}
27762747
27772748static void enable_iommus_v2 (void )
@@ -2784,10 +2755,63 @@ static void enable_iommus_v2(void)
27842755 }
27852756}
27862757
2758+ static void enable_iommus_vapic (void )
2759+ {
2760+ #ifdef CONFIG_IRQ_REMAP
2761+ u32 status , i ;
2762+ struct amd_iommu * iommu ;
2763+
2764+ for_each_iommu (iommu ) {
2765+ /*
2766+ * Disable GALog if already running. It could have been enabled
2767+ * in the previous boot before kdump.
2768+ */
2769+ status = readl (iommu -> mmio_base + MMIO_STATUS_OFFSET );
2770+ if (!(status & MMIO_STATUS_GALOG_RUN_MASK ))
2771+ continue ;
2772+
2773+ iommu_feature_disable (iommu , CONTROL_GALOG_EN );
2774+ iommu_feature_disable (iommu , CONTROL_GAINT_EN );
2775+
2776+ /*
2777+ * Need to set and poll check the GALOGRun bit to zero before
2778+ * we can set/ modify GA Log registers safely.
2779+ */
2780+ for (i = 0 ; i < LOOP_TIMEOUT ; ++ i ) {
2781+ status = readl (iommu -> mmio_base + MMIO_STATUS_OFFSET );
2782+ if (!(status & MMIO_STATUS_GALOG_RUN_MASK ))
2783+ break ;
2784+ udelay (10 );
2785+ }
2786+
2787+ if (WARN_ON (i >= LOOP_TIMEOUT ))
2788+ return ;
2789+ }
2790+
2791+ if (AMD_IOMMU_GUEST_IR_VAPIC (amd_iommu_guest_ir ) &&
2792+ !check_feature_on_all_iommus (FEATURE_GAM_VAPIC )) {
2793+ amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY_GA ;
2794+ return ;
2795+ }
2796+
2797+ /* Enabling GAM support */
2798+ for_each_iommu (iommu ) {
2799+ if (iommu_init_ga_log (iommu ) ||
2800+ iommu_ga_log_enable (iommu ))
2801+ return ;
2802+
2803+ iommu_feature_enable (iommu , CONTROL_GAM_EN );
2804+ }
2805+
2806+ amd_iommu_irq_ops .capability |= (1 << IRQ_POSTING_CAP );
2807+ pr_info ("Virtual APIC enabled\n" );
2808+ #endif
2809+ }
2810+
27872811static void enable_iommus (void )
27882812{
27892813 early_enable_iommus ();
2790-
2814+ enable_iommus_vapic ();
27912815 enable_iommus_v2 ();
27922816}
27932817
@@ -3126,6 +3150,7 @@ static int __init state_next(void)
31263150 register_syscore_ops (& amd_iommu_syscore_ops );
31273151 ret = amd_iommu_init_pci ();
31283152 init_state = ret ? IOMMU_INIT_ERROR : IOMMU_PCI_INIT ;
3153+ enable_iommus_vapic ();
31293154 enable_iommus_v2 ();
31303155 break ;
31313156 case IOMMU_PCI_INIT :
0 commit comments