Merge tag 'iommu-updates-v3.13' of git://git.kernel.org/pub/scm/linux/kernel/git...
authorLinus Torvalds <torvalds@linux-foundation.org>
Fri, 15 Nov 2013 05:02:18 +0000 (14:02 +0900)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 15 Nov 2013 05:02:18 +0000 (14:02 +0900)
Pull IOMMU updates from Joerg Roedel:
 "This time the updates contain:

   - Tracepoints for certain IOMMU-API functions to make their use
     easier to debug
   - A tracepoint for IOMMU page faults to make it easier to get them in
     user space
   - Updates and fixes for the new ARM SMMU driver after the first
     hardware showed up
   - Various other fixes and cleanups in other IOMMU drivers"

* tag 'iommu-updates-v3.13' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu: (26 commits)
  iommu/shmobile: Enable the driver on all ARM platforms
  iommu/tegra-smmu: Staticize tegra_smmu_pm_ops
  iommu/tegra-gart: Staticize tegra_gart_pm_ops
  iommu/vt-d: Use list_for_each_entry_safe() for dmar_domain->devices traversal
  iommu/vt-d: Use for_each_drhd_unit() instead of list_for_each_entry()
  iommu/vt-d: Fixed interaction of VFIO_IOMMU_MAP_DMA with IOMMU address limits
  iommu/arm-smmu: Clear global and context bank fault status registers
  iommu/arm-smmu: Print context fault information
  iommu/arm-smmu: Check for num_context_irqs > 0 to avoid divide by zero exception
  iommu/arm-smmu: Refine check for proper size of mapped region
  iommu/arm-smmu: Switch to subsys_initcall for driver registration
  iommu/arm-smmu: use relaxed accessors where possible
  iommu/arm-smmu: replace devm_request_and_ioremap by devm_ioremap_resource
  iommu: Remove stack trace from broken irq remapping warning
  iommu: Change iommu driver to call io_page_fault trace event
  iommu: Add iommu_error class event to iommu trace
  iommu/tegra: gart: cleanup devm_* functions usage
  iommu/tegra: Print phys_addr_t using %pa
  iommu: No need to pass '0x' when '%pa' is used
  iommu: Change iommu driver to call unmap trace event
  ...

1  2 
drivers/iommu/arm-smmu.c
drivers/iommu/dmar.c
drivers/iommu/intel_irq_remapping.c

diff --combined drivers/iommu/arm-smmu.c
@@@ -590,6 -590,9 +590,9 @@@ static irqreturn_t arm_smmu_context_fau
                ret = IRQ_HANDLED;
                resume = RESUME_RETRY;
        } else {
+               dev_err_ratelimited(smmu->dev,
+                   "Unhandled context fault: iova=0x%08lx, fsynr=0x%x, cb=%d\n",
+                   iova, fsynr, root_cfg->cbndx);
                ret = IRQ_NONE;
                resume = RESUME_TERMINATE;
        }
@@@ -778,7 -781,7 +781,7 @@@ static void arm_smmu_init_context_bank(
  #ifdef __BIG_ENDIAN
        reg |= SCTLR_E;
  #endif
-       writel(reg, cb_base + ARM_SMMU_CB_SCTLR);
+       writel_relaxed(reg, cb_base + ARM_SMMU_CB_SCTLR);
  }
  
  static int arm_smmu_init_domain_context(struct iommu_domain *domain,
@@@ -1212,10 -1215,7 +1215,10 @@@ static int arm_smmu_alloc_init_pte(stru
  
                arm_smmu_flush_pgtable(smmu, page_address(table),
                                       ARM_SMMU_PTE_HWTABLE_SIZE);
 -              pgtable_page_ctor(table);
 +              if (!pgtable_page_ctor(table)) {
 +                      __free_page(table);
 +                      return -ENOMEM;
 +              }
                pmd_populate(NULL, pmd, table);
                arm_smmu_flush_pgtable(smmu, pmd, sizeof(*pmd));
        }
@@@ -1562,9 -1562,13 +1565,13 @@@ static struct iommu_ops arm_smmu_ops = 
  static void arm_smmu_device_reset(struct arm_smmu_device *smmu)
  {
        void __iomem *gr0_base = ARM_SMMU_GR0(smmu);
-       void __iomem *sctlr_base = ARM_SMMU_CB_BASE(smmu) + ARM_SMMU_CB_SCTLR;
+       void __iomem *cb_base;
        int i = 0;
-       u32 scr0 = readl_relaxed(gr0_base + ARM_SMMU_GR0_sCR0);
+       u32 reg;
+       /* Clear Global FSR */
+       reg = readl_relaxed(gr0_base + ARM_SMMU_GR0_sGFSR);
+       writel(reg, gr0_base + ARM_SMMU_GR0_sGFSR);
  
        /* Mark all SMRn as invalid and all S2CRn as bypass */
        for (i = 0; i < smmu->num_mapping_groups; ++i) {
                writel_relaxed(S2CR_TYPE_BYPASS, gr0_base + ARM_SMMU_GR0_S2CR(i));
        }
  
-       /* Make sure all context banks are disabled */
-       for (i = 0; i < smmu->num_context_banks; ++i)
-               writel_relaxed(0, sctlr_base + ARM_SMMU_CB(smmu, i));
+       /* Make sure all context banks are disabled and clear CB_FSR  */
+       for (i = 0; i < smmu->num_context_banks; ++i) {
+               cb_base = ARM_SMMU_CB_BASE(smmu) + ARM_SMMU_CB(smmu, i);
+               writel_relaxed(0, cb_base + ARM_SMMU_CB_SCTLR);
+               writel_relaxed(FSR_FAULT, cb_base + ARM_SMMU_CB_FSR);
+       }
  
        /* Invalidate the TLB, just in case */
        writel_relaxed(0, gr0_base + ARM_SMMU_GR0_STLBIALL);
        writel_relaxed(0, gr0_base + ARM_SMMU_GR0_TLBIALLH);
        writel_relaxed(0, gr0_base + ARM_SMMU_GR0_TLBIALLNSNH);
  
+       reg = readl_relaxed(gr0_base + ARM_SMMU_GR0_sCR0);
        /* Enable fault reporting */
-       scr0 |= (sCR0_GFRE | sCR0_GFIE | sCR0_GCFGFRE | sCR0_GCFGFIE);
+       reg |= (sCR0_GFRE | sCR0_GFIE | sCR0_GCFGFRE | sCR0_GCFGFIE);
  
        /* Disable TLB broadcasting. */
-       scr0 |= (sCR0_VMIDPNE | sCR0_PTM);
+       reg |= (sCR0_VMIDPNE | sCR0_PTM);
  
        /* Enable client access, but bypass when no mapping is found */
-       scr0 &= ~(sCR0_CLIENTPD | sCR0_USFCFG);
+       reg &= ~(sCR0_CLIENTPD | sCR0_USFCFG);
  
        /* Disable forced broadcasting */
-       scr0 &= ~sCR0_FB;
+       reg &= ~sCR0_FB;
  
        /* Don't upgrade barriers */
-       scr0 &= ~(sCR0_BSU_MASK << sCR0_BSU_SHIFT);
+       reg &= ~(sCR0_BSU_MASK << sCR0_BSU_SHIFT);
  
        /* Push the button */
        arm_smmu_tlb_sync(smmu);
-       writel(scr0, gr0_base + ARM_SMMU_GR0_sCR0);
+       writel_relaxed(reg, gr0_base + ARM_SMMU_GR0_sCR0);
  }
  
  static int arm_smmu_id_size_to_bits(int size)
@@@ -1703,13 -1712,12 +1715,12 @@@ static int arm_smmu_device_cfg_probe(st
        id = readl_relaxed(gr0_base + ARM_SMMU_GR0_ID1);
        smmu->pagesize = (id & ID1_PAGESIZE) ? SZ_64K : SZ_4K;
  
-       /* Check that we ioremapped enough */
+       /* Check for size mismatch of SMMU address space from mapped region */
        size = 1 << (((id >> ID1_NUMPAGENDXB_SHIFT) & ID1_NUMPAGENDXB_MASK) + 1);
        size *= (smmu->pagesize << 1);
-       if (smmu->size < size)
-               dev_warn(smmu->dev,
-                        "device is 0x%lx bytes but only mapped 0x%lx!\n",
-                        size, smmu->size);
+       if (smmu->size != size)
+               dev_warn(smmu->dev, "SMMU address space size (0x%lx) differs "
+                       "from mapped region size (0x%lx)!\n", size, smmu->size);
  
        smmu->num_s2_context_banks = (id >> ID1_NUMS2CB_SHIFT) &
                                      ID1_NUMS2CB_MASK;
@@@ -1784,15 -1792,10 +1795,10 @@@ static int arm_smmu_device_dt_probe(str
        smmu->dev = dev;
  
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-       if (!res) {
-               dev_err(dev, "missing base address/size\n");
-               return -ENODEV;
-       }
+       smmu->base = devm_ioremap_resource(dev, res);
+       if (IS_ERR(smmu->base))
+               return PTR_ERR(smmu->base);
        smmu->size = resource_size(res);
-       smmu->base = devm_request_and_ioremap(dev, res);
-       if (!smmu->base)
-               return -EADDRNOTAVAIL;
  
        if (of_property_read_u32(dev->of_node, "#global-interrupts",
                                 &smmu->num_global_irqs)) {
                        smmu->num_context_irqs++;
        }
  
-       if (num_irqs < smmu->num_global_irqs) {
-               dev_warn(dev, "found %d interrupts but expected at least %d\n",
-                        num_irqs, smmu->num_global_irqs);
-               smmu->num_global_irqs = num_irqs;
+       if (!smmu->num_context_irqs) {
+               dev_err(dev, "found %d interrupts but expected at least %d\n",
+                       num_irqs, smmu->num_global_irqs + 1);
+               return -ENODEV;
        }
-       smmu->num_context_irqs = num_irqs - smmu->num_global_irqs;
  
        smmu->irqs = devm_kzalloc(dev, sizeof(*smmu->irqs) * num_irqs,
                                  GFP_KERNEL);
@@@ -1936,7 -1938,7 +1941,7 @@@ static int arm_smmu_device_remove(struc
                free_irq(smmu->irqs[i], smmu);
  
        /* Turn the thing off */
-       writel(sCR0_CLIENTPD, ARM_SMMU_GR0(smmu) + ARM_SMMU_GR0_sCR0);
+       writel_relaxed(sCR0_CLIENTPD, ARM_SMMU_GR0(smmu) + ARM_SMMU_GR0_sCR0);
        return 0;
  }
  
@@@ -1984,7 -1986,7 +1989,7 @@@ static void __exit arm_smmu_exit(void
        return platform_driver_unregister(&arm_smmu_driver);
  }
  
module_init(arm_smmu_init);
subsys_initcall(arm_smmu_init);
  module_exit(arm_smmu_exit);
  
  MODULE_DESCRIPTION("IOMMU API for ARM architected SMMU implementations");
diff --combined drivers/iommu/dmar.c
@@@ -88,7 -88,7 +88,7 @@@ static int __init dmar_parse_one_dev_sc
                        pr_warn("Device scope bus [%d] not found\n", scope->bus);
                        break;
                }
 -              pdev = pci_get_slot(bus, PCI_DEVFN(path->dev, path->fn));
 +              pdev = pci_get_slot(bus, PCI_DEVFN(path->device, path->function));
                if (!pdev) {
                        /* warning will be printed below */
                        break;
@@@ -99,7 -99,7 +99,7 @@@
        }
        if (!pdev) {
                pr_warn("Device scope device [%04x:%02x:%02x.%02x] not found\n",
 -                      segment, scope->bus, path->dev, path->fn);
 +                      segment, scope->bus, path->device, path->function);
                *dev = NULL;
                return 0;
        }
@@@ -403,7 -403,7 +403,7 @@@ dmar_find_matched_drhd_unit(struct pci_
  
        dev = pci_physfn(dev);
  
-       list_for_each_entry(dmaru, &dmar_drhd_units, list) {
+       for_each_drhd_unit(dmaru) {
                drhd = container_of(dmaru->hdr,
                                    struct acpi_dmar_hardware_unit,
                                    header);
@@@ -525,12 -525,13 +525,13 @@@ static int __init intel_irq_remapping_s
        if (disable_irq_remap)
                return 0;
        if (irq_remap_broken) {
-               WARN_TAINT(1, TAINT_FIRMWARE_WORKAROUND,
-                          "This system BIOS has enabled interrupt remapping\n"
-                          "on a chipset that contains an erratum making that\n"
-                          "feature unstable.  To maintain system stability\n"
-                          "interrupt remapping is being disabled.  Please\n"
-                          "contact your BIOS vendor for an update\n");
+               printk(KERN_WARNING
+                       "This system BIOS has enabled interrupt remapping\n"
+                       "on a chipset that contains an erratum making that\n"
+                       "feature unstable.  To maintain system stability\n"
+                       "interrupt remapping is being disabled.  Please\n"
+                       "contact your BIOS vendor for an update\n");
+               add_taint(TAINT_FIRMWARE_WORKAROUND, LOCKDEP_STILL_OK);
                disable_irq_remap = 1;
                return 0;
        }
@@@ -686,12 -687,12 +687,12 @@@ static void ir_parse_one_hpet_scope(str
                 * Access PCI directly due to the PCI
                 * subsystem isn't initialized yet.
                 */
 -              bus = read_pci_config_byte(bus, path->dev, path->fn,
 +              bus = read_pci_config_byte(bus, path->device, path->function,
                                           PCI_SECONDARY_BUS);
                path++;
        }
        ir_hpet[ir_hpet_num].bus   = bus;
 -      ir_hpet[ir_hpet_num].devfn = PCI_DEVFN(path->dev, path->fn);
 +      ir_hpet[ir_hpet_num].devfn = PCI_DEVFN(path->device, path->function);
        ir_hpet[ir_hpet_num].iommu = iommu;
        ir_hpet[ir_hpet_num].id    = scope->enumeration_id;
        ir_hpet_num++;
@@@ -714,13 -715,13 +715,13 @@@ static void ir_parse_one_ioapic_scope(s
                 * Access PCI directly due to the PCI
                 * subsystem isn't initialized yet.
                 */
 -              bus = read_pci_config_byte(bus, path->dev, path->fn,
 +              bus = read_pci_config_byte(bus, path->device, path->function,
                                           PCI_SECONDARY_BUS);
                path++;
        }
  
        ir_ioapic[ir_ioapic_num].bus   = bus;
 -      ir_ioapic[ir_ioapic_num].devfn = PCI_DEVFN(path->dev, path->fn);
 +      ir_ioapic[ir_ioapic_num].devfn = PCI_DEVFN(path->device, path->function);
        ir_ioapic[ir_ioapic_num].iommu = iommu;
        ir_ioapic[ir_ioapic_num].id    = scope->enumeration_id;
        ir_ioapic_num++;