@@ -806,16 +806,27 @@ static int iommu_ga_log_enable(struct amd_iommu *iommu)
806806{
807807#ifdef CONFIG_IRQ_REMAP
808808 u32 status , i ;
809+ u64 entry ;
809810
810811 if (!iommu -> ga_log )
811812 return - EINVAL ;
812813
813- status = readl (iommu -> mmio_base + MMIO_STATUS_OFFSET );
814-
815814 /* Check if already running */
816- if (status & (MMIO_STATUS_GALOG_RUN_MASK ))
815+ status = readl (iommu -> mmio_base + MMIO_STATUS_OFFSET );
816+ if (WARN_ON (status & (MMIO_STATUS_GALOG_RUN_MASK )))
817817 return 0 ;
818818
819+ entry = iommu_virt_to_phys (iommu -> ga_log ) | GA_LOG_SIZE_512 ;
820+ memcpy_toio (iommu -> mmio_base + MMIO_GA_LOG_BASE_OFFSET ,
821+ & entry , sizeof (entry ));
822+ entry = (iommu_virt_to_phys (iommu -> ga_log_tail ) &
823+ (BIT_ULL (52 )- 1 )) & ~7ULL ;
824+ memcpy_toio (iommu -> mmio_base + MMIO_GA_LOG_TAIL_OFFSET ,
825+ & entry , sizeof (entry ));
826+ writel (0x00 , iommu -> mmio_base + MMIO_GA_HEAD_OFFSET );
827+ writel (0x00 , iommu -> mmio_base + MMIO_GA_TAIL_OFFSET );
828+
829+
819830 iommu_feature_enable (iommu , CONTROL_GAINT_EN );
820831 iommu_feature_enable (iommu , CONTROL_GALOG_EN );
821832
@@ -825,7 +836,7 @@ static int iommu_ga_log_enable(struct amd_iommu *iommu)
825836 break ;
826837 }
827838
828- if (i >= LOOP_TIMEOUT )
839+ if (WARN_ON ( i >= LOOP_TIMEOUT ) )
829840 return - EINVAL ;
830841#endif /* CONFIG_IRQ_REMAP */
831842 return 0 ;
@@ -834,8 +845,6 @@ static int iommu_ga_log_enable(struct amd_iommu *iommu)
834845static int iommu_init_ga_log (struct amd_iommu * iommu )
835846{
836847#ifdef CONFIG_IRQ_REMAP
837- u64 entry ;
838-
839848 if (!AMD_IOMMU_GUEST_IR_VAPIC (amd_iommu_guest_ir ))
840849 return 0 ;
841850
@@ -849,16 +858,6 @@ static int iommu_init_ga_log(struct amd_iommu *iommu)
849858 if (!iommu -> ga_log_tail )
850859 goto err_out ;
851860
852- entry = iommu_virt_to_phys (iommu -> ga_log ) | GA_LOG_SIZE_512 ;
853- memcpy_toio (iommu -> mmio_base + MMIO_GA_LOG_BASE_OFFSET ,
854- & entry , sizeof (entry ));
855- entry = (iommu_virt_to_phys (iommu -> ga_log_tail ) &
856- (BIT_ULL (52 )- 1 )) & ~7ULL ;
857- memcpy_toio (iommu -> mmio_base + MMIO_GA_LOG_TAIL_OFFSET ,
858- & entry , sizeof (entry ));
859- writel (0x00 , iommu -> mmio_base + MMIO_GA_HEAD_OFFSET );
860- writel (0x00 , iommu -> mmio_base + MMIO_GA_TAIL_OFFSET );
861-
862861 return 0 ;
863862err_out :
864863 free_ga_log (iommu );
0 commit comments