]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - drivers/iommu/tegra-gart.c
treewide: Use array_size() in vmalloc()
[linux.git] / drivers / iommu / tegra-gart.c
index b62f790ad1bab5e607d6c8dd95d8172a7b03d075..a004f6da35f21f0d751eeefce10c65de3a3c08a0 100644 (file)
@@ -72,6 +72,8 @@ struct gart_domain {
 
 static struct gart_device *gart_handle; /* unique for a system */
 
+static bool gart_debug;
+
 #define GART_PTE(_pfn)                                         \
        (GART_ENTRY_PHYS_ADDR_VALID | ((_pfn) << PAGE_SHIFT))
 
@@ -271,6 +273,7 @@ static int gart_iommu_map(struct iommu_domain *domain, unsigned long iova,
        struct gart_device *gart = gart_domain->gart;
        unsigned long flags;
        unsigned long pfn;
+       unsigned long pte;
 
        if (!gart_iova_range_valid(gart, iova, bytes))
                return -EINVAL;
@@ -282,6 +285,14 @@ static int gart_iommu_map(struct iommu_domain *domain, unsigned long iova,
                spin_unlock_irqrestore(&gart->pte_lock, flags);
                return -EINVAL;
        }
+       if (gart_debug) {
+               pte = gart_read_pte(gart, iova);
+               if (pte & GART_ENTRY_PHYS_ADDR_VALID) {
+                       spin_unlock_irqrestore(&gart->pte_lock, flags);
+                       dev_err(gart->dev, "Page entry is in-use\n");
+                       return -EBUSY;
+               }
+       }
        gart_set_pte(gart, iova, GART_PTE(pfn));
        FLUSH_GART_REGS(gart);
        spin_unlock_irqrestore(&gart->pte_lock, flags);
@@ -302,7 +313,7 @@ static size_t gart_iommu_unmap(struct iommu_domain *domain, unsigned long iova,
        gart_set_pte(gart, iova, 0);
        FLUSH_GART_REGS(gart);
        spin_unlock_irqrestore(&gart->pte_lock, flags);
-       return 0;
+       return bytes;
 }
 
 static phys_addr_t gart_iommu_iova_to_phys(struct iommu_domain *domain,
@@ -454,7 +465,7 @@ static int tegra_gart_probe(struct platform_device *pdev)
        gart->iovmm_base = (dma_addr_t)res_remap->start;
        gart->page_count = (resource_size(res_remap) >> GART_PAGE_SHIFT);
 
-       gart->savedata = vmalloc(sizeof(u32) * gart->page_count);
+       gart->savedata = vmalloc(array_size(sizeof(u32), gart->page_count));
        if (!gart->savedata) {
                dev_err(dev, "failed to allocate context save area\n");
                return -ENOMEM;
@@ -515,7 +526,9 @@ static void __exit tegra_gart_exit(void)
 
 subsys_initcall(tegra_gart_init);
 module_exit(tegra_gart_exit);
+module_param(gart_debug, bool, 0644);
 
+MODULE_PARM_DESC(gart_debug, "Enable GART debugging");
 MODULE_DESCRIPTION("IOMMU API for GART in Tegra20");
 MODULE_AUTHOR("Hiroshi DOYU <hdoyu@nvidia.com>");
 MODULE_ALIAS("platform:tegra-gart");