412412#define MSI_IOVA_BASE 0x8000000
413413#define MSI_IOVA_LENGTH 0x100000
414414
415+ #define ARM_SMMU_PAGE0_REGS_ONLY (smmu ) \
416+ ((smmu)->options & ARM_SMMU_OPT_PAGE0_REGS_ONLY)
417+
415418static bool disable_bypass ;
416419module_param_named (disable_bypass , disable_bypass , bool , S_IRUGO );
417420MODULE_PARM_DESC (disable_bypass ,
@@ -597,6 +600,7 @@ struct arm_smmu_device {
597600 u32 features ;
598601
599602#define ARM_SMMU_OPT_SKIP_PREFETCH (1 << 0)
603+ #define ARM_SMMU_OPT_PAGE0_REGS_ONLY (1 << 1)
600604 u32 options ;
601605
602606 struct arm_smmu_cmdq cmdq ;
@@ -663,9 +667,19 @@ struct arm_smmu_option_prop {
663667
664668static struct arm_smmu_option_prop arm_smmu_options [] = {
665669 { ARM_SMMU_OPT_SKIP_PREFETCH , "hisilicon,broken-prefetch-cmd" },
670+ { ARM_SMMU_OPT_PAGE0_REGS_ONLY , "cavium,cn9900-broken-page1-regspace" },
666671 { 0 , NULL },
667672};
668673
674+ static inline void __iomem * arm_smmu_page1_fixup (unsigned long offset ,
675+ struct arm_smmu_device * smmu )
676+ {
677+ if (offset > SZ_64K && ARM_SMMU_PAGE0_REGS_ONLY (smmu ))
678+ offset -= SZ_64K ;
679+
680+ return smmu -> base + offset ;
681+ }
682+
669683static struct arm_smmu_domain * to_smmu_domain (struct iommu_domain * dom )
670684{
671685 return container_of (dom , struct arm_smmu_domain , domain );
@@ -1961,8 +1975,8 @@ static int arm_smmu_init_one_queue(struct arm_smmu_device *smmu,
19611975 return - ENOMEM ;
19621976 }
19631977
1964- q -> prod_reg = smmu -> base + prod_off ;
1965- q -> cons_reg = smmu -> base + cons_off ;
1978+ q -> prod_reg = arm_smmu_page1_fixup ( prod_off , smmu ) ;
1979+ q -> cons_reg = arm_smmu_page1_fixup ( cons_off , smmu ) ;
19661980 q -> ent_dwords = dwords ;
19671981
19681982 q -> q_base = Q_BASE_RWA ;
@@ -2363,8 +2377,10 @@ static int arm_smmu_device_reset(struct arm_smmu_device *smmu, bool bypass)
23632377
23642378 /* Event queue */
23652379 writeq_relaxed (smmu -> evtq .q .q_base , smmu -> base + ARM_SMMU_EVTQ_BASE );
2366- writel_relaxed (smmu -> evtq .q .prod , smmu -> base + ARM_SMMU_EVTQ_PROD );
2367- writel_relaxed (smmu -> evtq .q .cons , smmu -> base + ARM_SMMU_EVTQ_CONS );
2380+ writel_relaxed (smmu -> evtq .q .prod ,
2381+ arm_smmu_page1_fixup (ARM_SMMU_EVTQ_PROD , smmu ));
2382+ writel_relaxed (smmu -> evtq .q .cons ,
2383+ arm_smmu_page1_fixup (ARM_SMMU_EVTQ_CONS , smmu ));
23682384
23692385 enables |= CR0_EVTQEN ;
23702386 ret = arm_smmu_write_reg_sync (smmu , enables , ARM_SMMU_CR0 ,
@@ -2379,9 +2395,9 @@ static int arm_smmu_device_reset(struct arm_smmu_device *smmu, bool bypass)
23792395 writeq_relaxed (smmu -> priq .q .q_base ,
23802396 smmu -> base + ARM_SMMU_PRIQ_BASE );
23812397 writel_relaxed (smmu -> priq .q .prod ,
2382- smmu -> base + ARM_SMMU_PRIQ_PROD );
2398+ arm_smmu_page1_fixup ( ARM_SMMU_PRIQ_PROD , smmu ) );
23832399 writel_relaxed (smmu -> priq .q .cons ,
2384- smmu -> base + ARM_SMMU_PRIQ_CONS );
2400+ arm_smmu_page1_fixup ( ARM_SMMU_PRIQ_CONS , smmu ) );
23852401
23862402 enables |= CR0_PRIQEN ;
23872403 ret = arm_smmu_write_reg_sync (smmu , enables , ARM_SMMU_CR0 ,
@@ -2605,6 +2621,14 @@ static int arm_smmu_device_hw_probe(struct arm_smmu_device *smmu)
26052621}
26062622
26072623#ifdef CONFIG_ACPI
2624+ static void acpi_smmu_get_options (u32 model , struct arm_smmu_device * smmu )
2625+ {
2626+ if (model == ACPI_IORT_SMMU_CAVIUM_CN99XX )
2627+ smmu -> options |= ARM_SMMU_OPT_PAGE0_REGS_ONLY ;
2628+
2629+ dev_notice (smmu -> dev , "option mask 0x%x\n" , smmu -> options );
2630+ }
2631+
26082632static int arm_smmu_device_acpi_probe (struct platform_device * pdev ,
26092633 struct arm_smmu_device * smmu )
26102634{
@@ -2617,6 +2641,8 @@ static int arm_smmu_device_acpi_probe(struct platform_device *pdev,
26172641 /* Retrieve SMMUv3 specific data */
26182642 iort_smmu = (struct acpi_iort_smmu_v3 * )node -> node_data ;
26192643
2644+ acpi_smmu_get_options (iort_smmu -> model , smmu );
2645+
26202646 if (iort_smmu -> flags & ACPI_IORT_SMMU_V3_COHACC_OVERRIDE )
26212647 smmu -> features |= ARM_SMMU_FEAT_COHERENCY ;
26222648
@@ -2652,6 +2678,14 @@ static int arm_smmu_device_dt_probe(struct platform_device *pdev,
26522678 return ret ;
26532679}
26542680
2681+ static unsigned long arm_smmu_resource_size (struct arm_smmu_device * smmu )
2682+ {
2683+ if (ARM_SMMU_PAGE0_REGS_ONLY (smmu ))
2684+ return SZ_64K ;
2685+ else
2686+ return SZ_128K ;
2687+ }
2688+
26552689static int arm_smmu_device_probe (struct platform_device * pdev )
26562690{
26572691 int irq , ret ;
@@ -2668,9 +2702,17 @@ static int arm_smmu_device_probe(struct platform_device *pdev)
26682702 }
26692703 smmu -> dev = dev ;
26702704
2705+ if (dev -> of_node ) {
2706+ ret = arm_smmu_device_dt_probe (pdev , smmu );
2707+ } else {
2708+ ret = arm_smmu_device_acpi_probe (pdev , smmu );
2709+ if (ret == - ENODEV )
2710+ return ret ;
2711+ }
2712+
26712713 /* Base address */
26722714 res = platform_get_resource (pdev , IORESOURCE_MEM , 0 );
2673- if (resource_size (res ) + 1 < SZ_128K ) {
2715+ if (resource_size (res ) + 1 < arm_smmu_resource_size ( smmu ) ) {
26742716 dev_err (dev , "MMIO region too small (%pr)\n" , res );
26752717 return - EINVAL ;
26762718 }
@@ -2697,14 +2739,6 @@ static int arm_smmu_device_probe(struct platform_device *pdev)
26972739 if (irq > 0 )
26982740 smmu -> gerr_irq = irq ;
26992741
2700- if (dev -> of_node ) {
2701- ret = arm_smmu_device_dt_probe (pdev , smmu );
2702- } else {
2703- ret = arm_smmu_device_acpi_probe (pdev , smmu );
2704- if (ret == - ENODEV )
2705- return ret ;
2706- }
2707-
27082742 /* Set bypass mode according to firmware probing result */
27092743 bypass = !!ret ;
27102744
0 commit comments