|
@@ -16,17 +16,20 @@
|
|
|
#include <linux/slab.h>
|
|
|
#include <linux/interrupt.h>
|
|
|
#include <linux/ioport.h>
|
|
|
-#include <linux/clk.h>
|
|
|
#include <linux/platform_device.h>
|
|
|
#include <linux/iommu.h>
|
|
|
+#include <linux/omap-iommu.h>
|
|
|
#include <linux/mutex.h>
|
|
|
#include <linux/spinlock.h>
|
|
|
+#include <linux/io.h>
|
|
|
+#include <linux/pm_runtime.h>
|
|
|
|
|
|
#include <asm/cacheflush.h>
|
|
|
|
|
|
-#include <plat/iommu.h>
|
|
|
+#include <linux/platform_data/iommu-omap.h>
|
|
|
|
|
|
-#include <plat/iopgtable.h>
|
|
|
+#include "omap-iopgtable.h"
|
|
|
+#include "omap-iommu.h"
|
|
|
|
|
|
#define for_each_iotlb_cr(obj, n, __i, cr) \
|
|
|
for (__i = 0; \
|
|
@@ -51,6 +54,21 @@ struct omap_iommu_domain {
|
|
|
spinlock_t lock;
|
|
|
};
|
|
|
|
|
|
+#define MMU_LOCK_BASE_SHIFT 10
|
|
|
+#define MMU_LOCK_BASE_MASK (0x1f << MMU_LOCK_BASE_SHIFT)
|
|
|
+#define MMU_LOCK_BASE(x) \
|
|
|
+ ((x & MMU_LOCK_BASE_MASK) >> MMU_LOCK_BASE_SHIFT)
|
|
|
+
|
|
|
+#define MMU_LOCK_VICT_SHIFT 4
|
|
|
+#define MMU_LOCK_VICT_MASK (0x1f << MMU_LOCK_VICT_SHIFT)
|
|
|
+#define MMU_LOCK_VICT(x) \
|
|
|
+ ((x & MMU_LOCK_VICT_MASK) >> MMU_LOCK_VICT_SHIFT)
|
|
|
+
|
|
|
+struct iotlb_lock {
|
|
|
+ short base;
|
|
|
+ short vict;
|
|
|
+};
|
|
|
+
|
|
|
/* accommodate the difference between omap1 and omap2/3 */
|
|
|
static const struct iommu_functions *arch_iommu;
|
|
|
|
|
@@ -125,31 +143,44 @@ EXPORT_SYMBOL_GPL(omap_iommu_arch_version);
|
|
|
static int iommu_enable(struct omap_iommu *obj)
|
|
|
{
|
|
|
int err;
|
|
|
+ struct platform_device *pdev = to_platform_device(obj->dev);
|
|
|
+ struct iommu_platform_data *pdata = pdev->dev.platform_data;
|
|
|
|
|
|
- if (!obj)
|
|
|
+ if (!obj || !pdata)
|
|
|
return -EINVAL;
|
|
|
|
|
|
if (!arch_iommu)
|
|
|
return -ENODEV;
|
|
|
|
|
|
- clk_enable(obj->clk);
|
|
|
+ if (pdata->deassert_reset) {
|
|
|
+ err = pdata->deassert_reset(pdev, pdata->reset_name);
|
|
|
+ if (err) {
|
|
|
+ dev_err(obj->dev, "deassert_reset failed: %d\n", err);
|
|
|
+ return err;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ pm_runtime_get_sync(obj->dev);
|
|
|
|
|
|
err = arch_iommu->enable(obj);
|
|
|
|
|
|
- clk_disable(obj->clk);
|
|
|
return err;
|
|
|
}
|
|
|
|
|
|
static void iommu_disable(struct omap_iommu *obj)
|
|
|
{
|
|
|
- if (!obj)
|
|
|
- return;
|
|
|
+ struct platform_device *pdev = to_platform_device(obj->dev);
|
|
|
+ struct iommu_platform_data *pdata = pdev->dev.platform_data;
|
|
|
|
|
|
- clk_enable(obj->clk);
|
|
|
+ if (!obj || !pdata)
|
|
|
+ return;
|
|
|
|
|
|
arch_iommu->disable(obj);
|
|
|
|
|
|
- clk_disable(obj->clk);
|
|
|
+ pm_runtime_put_sync(obj->dev);
|
|
|
+
|
|
|
+ if (pdata->assert_reset)
|
|
|
+ pdata->assert_reset(pdev, pdata->reset_name);
|
|
|
}
|
|
|
|
|
|
/*
|
|
@@ -272,7 +303,7 @@ static int load_iotlb_entry(struct omap_iommu *obj, struct iotlb_entry *e)
|
|
|
if (!obj || !obj->nr_tlb_entries || !e)
|
|
|
return -EINVAL;
|
|
|
|
|
|
- clk_enable(obj->clk);
|
|
|
+ pm_runtime_get_sync(obj->dev);
|
|
|
|
|
|
iotlb_lock_get(obj, &l);
|
|
|
if (l.base == obj->nr_tlb_entries) {
|
|
@@ -302,7 +333,7 @@ static int load_iotlb_entry(struct omap_iommu *obj, struct iotlb_entry *e)
|
|
|
|
|
|
cr = iotlb_alloc_cr(obj, e);
|
|
|
if (IS_ERR(cr)) {
|
|
|
- clk_disable(obj->clk);
|
|
|
+ pm_runtime_put_sync(obj->dev);
|
|
|
return PTR_ERR(cr);
|
|
|
}
|
|
|
|
|
@@ -316,7 +347,7 @@ static int load_iotlb_entry(struct omap_iommu *obj, struct iotlb_entry *e)
|
|
|
l.vict = l.base;
|
|
|
iotlb_lock_set(obj, &l);
|
|
|
out:
|
|
|
- clk_disable(obj->clk);
|
|
|
+ pm_runtime_put_sync(obj->dev);
|
|
|
return err;
|
|
|
}
|
|
|
|
|
@@ -346,7 +377,7 @@ static void flush_iotlb_page(struct omap_iommu *obj, u32 da)
|
|
|
int i;
|
|
|
struct cr_regs cr;
|
|
|
|
|
|
- clk_enable(obj->clk);
|
|
|
+ pm_runtime_get_sync(obj->dev);
|
|
|
|
|
|
for_each_iotlb_cr(obj, obj->nr_tlb_entries, i, cr) {
|
|
|
u32 start;
|
|
@@ -365,7 +396,7 @@ static void flush_iotlb_page(struct omap_iommu *obj, u32 da)
|
|
|
iommu_write_reg(obj, 1, MMU_FLUSH_ENTRY);
|
|
|
}
|
|
|
}
|
|
|
- clk_disable(obj->clk);
|
|
|
+ pm_runtime_put_sync(obj->dev);
|
|
|
|
|
|
if (i == obj->nr_tlb_entries)
|
|
|
dev_dbg(obj->dev, "%s: no page for %08x\n", __func__, da);
|
|
@@ -379,7 +410,7 @@ static void flush_iotlb_all(struct omap_iommu *obj)
|
|
|
{
|
|
|
struct iotlb_lock l;
|
|
|
|
|
|
- clk_enable(obj->clk);
|
|
|
+ pm_runtime_get_sync(obj->dev);
|
|
|
|
|
|
l.base = 0;
|
|
|
l.vict = 0;
|
|
@@ -387,7 +418,7 @@ static void flush_iotlb_all(struct omap_iommu *obj)
|
|
|
|
|
|
iommu_write_reg(obj, 1, MMU_GFLUSH);
|
|
|
|
|
|
- clk_disable(obj->clk);
|
|
|
+ pm_runtime_put_sync(obj->dev);
|
|
|
}
|
|
|
|
|
|
#if defined(CONFIG_OMAP_IOMMU_DEBUG) || defined(CONFIG_OMAP_IOMMU_DEBUG_MODULE)
|
|
@@ -397,11 +428,11 @@ ssize_t omap_iommu_dump_ctx(struct omap_iommu *obj, char *buf, ssize_t bytes)
|
|
|
if (!obj || !buf)
|
|
|
return -EINVAL;
|
|
|
|
|
|
- clk_enable(obj->clk);
|
|
|
+ pm_runtime_get_sync(obj->dev);
|
|
|
|
|
|
bytes = arch_iommu->dump_ctx(obj, buf, bytes);
|
|
|
|
|
|
- clk_disable(obj->clk);
|
|
|
+ pm_runtime_put_sync(obj->dev);
|
|
|
|
|
|
return bytes;
|
|
|
}
|
|
@@ -415,7 +446,7 @@ __dump_tlb_entries(struct omap_iommu *obj, struct cr_regs *crs, int num)
|
|
|
struct cr_regs tmp;
|
|
|
struct cr_regs *p = crs;
|
|
|
|
|
|
- clk_enable(obj->clk);
|
|
|
+ pm_runtime_get_sync(obj->dev);
|
|
|
iotlb_lock_get(obj, &saved);
|
|
|
|
|
|
for_each_iotlb_cr(obj, num, i, tmp) {
|
|
@@ -425,7 +456,7 @@ __dump_tlb_entries(struct omap_iommu *obj, struct cr_regs *crs, int num)
|
|
|
}
|
|
|
|
|
|
iotlb_lock_set(obj, &saved);
|
|
|
- clk_disable(obj->clk);
|
|
|
+ pm_runtime_put_sync(obj->dev);
|
|
|
|
|
|
return p - crs;
|
|
|
}
|
|
@@ -789,9 +820,7 @@ static irqreturn_t iommu_fault_handler(int irq, void *data)
|
|
|
if (!obj->refcount)
|
|
|
return IRQ_NONE;
|
|
|
|
|
|
- clk_enable(obj->clk);
|
|
|
errs = iommu_report_fault(obj, &da);
|
|
|
- clk_disable(obj->clk);
|
|
|
if (errs == 0)
|
|
|
return IRQ_HANDLED;
|
|
|
|
|
@@ -913,17 +942,10 @@ static int __devinit omap_iommu_probe(struct platform_device *pdev)
|
|
|
struct resource *res;
|
|
|
struct iommu_platform_data *pdata = pdev->dev.platform_data;
|
|
|
|
|
|
- if (pdev->num_resources != 2)
|
|
|
- return -EINVAL;
|
|
|
-
|
|
|
obj = kzalloc(sizeof(*obj) + MMU_REG_SIZE, GFP_KERNEL);
|
|
|
if (!obj)
|
|
|
return -ENOMEM;
|
|
|
|
|
|
- obj->clk = clk_get(&pdev->dev, pdata->clk_name);
|
|
|
- if (IS_ERR(obj->clk))
|
|
|
- goto err_clk;
|
|
|
-
|
|
|
obj->nr_tlb_entries = pdata->nr_tlb_entries;
|
|
|
obj->name = pdata->name;
|
|
|
obj->dev = &pdev->dev;
|
|
@@ -966,6 +988,9 @@ static int __devinit omap_iommu_probe(struct platform_device *pdev)
|
|
|
goto err_irq;
|
|
|
platform_set_drvdata(pdev, obj);
|
|
|
|
|
|
+ pm_runtime_irq_safe(obj->dev);
|
|
|
+ pm_runtime_enable(obj->dev);
|
|
|
+
|
|
|
dev_info(&pdev->dev, "%s registered\n", obj->name);
|
|
|
return 0;
|
|
|
|
|
@@ -974,8 +999,6 @@ err_irq:
|
|
|
err_ioremap:
|
|
|
release_mem_region(res->start, resource_size(res));
|
|
|
err_mem:
|
|
|
- clk_put(obj->clk);
|
|
|
-err_clk:
|
|
|
kfree(obj);
|
|
|
return err;
|
|
|
}
|
|
@@ -996,7 +1019,8 @@ static int __devexit omap_iommu_remove(struct platform_device *pdev)
|
|
|
release_mem_region(res->start, resource_size(res));
|
|
|
iounmap(obj->regbase);
|
|
|
|
|
|
- clk_put(obj->clk);
|
|
|
+ pm_runtime_disable(obj->dev);
|
|
|
+
|
|
|
dev_info(&pdev->dev, "%s removed\n", obj->name);
|
|
|
kfree(obj);
|
|
|
return 0;
|
|
@@ -1015,6 +1039,23 @@ static void iopte_cachep_ctor(void *iopte)
|
|
|
clean_dcache_area(iopte, IOPTE_TABLE_SIZE);
|
|
|
}
|
|
|
|
|
|
+static u32 iotlb_init_entry(struct iotlb_entry *e, u32 da, u32 pa,
|
|
|
+ u32 flags)
|
|
|
+{
|
|
|
+ memset(e, 0, sizeof(*e));
|
|
|
+
|
|
|
+ e->da = da;
|
|
|
+ e->pa = pa;
|
|
|
+ e->valid = 1;
|
|
|
+ /* FIXME: add OMAP1 support */
|
|
|
+ e->pgsz = flags & MMU_CAM_PGSZ_MASK;
|
|
|
+ e->endian = flags & MMU_RAM_ENDIAN_MASK;
|
|
|
+ e->elsz = flags & MMU_RAM_ELSZ_MASK;
|
|
|
+ e->mixed = flags & MMU_RAM_MIXED_MASK;
|
|
|
+
|
|
|
+ return iopgsz_to_bytes(e->pgsz);
|
|
|
+}
|
|
|
+
|
|
|
static int omap_iommu_map(struct iommu_domain *domain, unsigned long da,
|
|
|
phys_addr_t pa, size_t bytes, int prot)
|
|
|
{
|