|
@@ -18,18 +18,34 @@
|
|
|
#include <linux/ioport.h>
|
|
|
#include <linux/clk.h>
|
|
|
#include <linux/platform_device.h>
|
|
|
+#include <linux/iommu.h>
|
|
|
+#include <linux/mutex.h>
|
|
|
+#include <linux/spinlock.h>
|
|
|
|
|
|
#include <asm/cacheflush.h>
|
|
|
|
|
|
#include <plat/iommu.h>
|
|
|
|
|
|
-#include "iopgtable.h"
|
|
|
+#include <plat/iopgtable.h>
|
|
|
|
|
|
#define for_each_iotlb_cr(obj, n, __i, cr) \
|
|
|
for (__i = 0; \
|
|
|
(__i < (n)) && (cr = __iotlb_read_cr((obj), __i), true); \
|
|
|
__i++)
|
|
|
|
|
|
+/**
|
|
|
+ * struct omap_iommu_domain - omap iommu domain
|
|
|
+ * @pgtable: the page table
|
|
|
+ * @iommu_dev: an omap iommu device attached to this domain. only a single
|
|
|
+ * iommu device can be attached for now.
|
|
|
+ * @lock: domain lock, should be taken when attaching/detaching
|
|
|
+ */
|
|
|
+struct omap_iommu_domain {
|
|
|
+ u32 *pgtable;
|
|
|
+ struct omap_iommu *iommu_dev;
|
|
|
+ spinlock_t lock;
|
|
|
+};
|
|
|
+
|
|
|
/* accommodate the difference between omap1 and omap2/3 */
|
|
|
static const struct iommu_functions *arch_iommu;
|
|
|
|
|
@@ -37,13 +53,13 @@ static struct platform_driver omap_iommu_driver;
|
|
|
static struct kmem_cache *iopte_cachep;
|
|
|
|
|
|
/**
|
|
|
- * install_iommu_arch - Install archtecure specific iommu functions
|
|
|
+ * omap_install_iommu_arch - Install archtecure specific iommu functions
|
|
|
* @ops: a pointer to architecture specific iommu functions
|
|
|
*
|
|
|
* There are several kind of iommu algorithm(tlb, pagetable) among
|
|
|
* omap series. This interface installs such an iommu algorighm.
|
|
|
**/
|
|
|
-int install_iommu_arch(const struct iommu_functions *ops)
|
|
|
+int omap_install_iommu_arch(const struct iommu_functions *ops)
|
|
|
{
|
|
|
if (arch_iommu)
|
|
|
return -EBUSY;
|
|
@@ -51,53 +67,53 @@ int install_iommu_arch(const struct iommu_functions *ops)
|
|
|
arch_iommu = ops;
|
|
|
return 0;
|
|
|
}
|
|
|
-EXPORT_SYMBOL_GPL(install_iommu_arch);
|
|
|
+EXPORT_SYMBOL_GPL(omap_install_iommu_arch);
|
|
|
|
|
|
/**
|
|
|
- * uninstall_iommu_arch - Uninstall archtecure specific iommu functions
|
|
|
+ * omap_uninstall_iommu_arch - Uninstall archtecure specific iommu functions
|
|
|
* @ops: a pointer to architecture specific iommu functions
|
|
|
*
|
|
|
* This interface uninstalls the iommu algorighm installed previously.
|
|
|
**/
|
|
|
-void uninstall_iommu_arch(const struct iommu_functions *ops)
|
|
|
+void omap_uninstall_iommu_arch(const struct iommu_functions *ops)
|
|
|
{
|
|
|
if (arch_iommu != ops)
|
|
|
pr_err("%s: not your arch\n", __func__);
|
|
|
|
|
|
arch_iommu = NULL;
|
|
|
}
|
|
|
-EXPORT_SYMBOL_GPL(uninstall_iommu_arch);
|
|
|
+EXPORT_SYMBOL_GPL(omap_uninstall_iommu_arch);
|
|
|
|
|
|
/**
|
|
|
- * iommu_save_ctx - Save registers for pm off-mode support
|
|
|
+ * omap_iommu_save_ctx - Save registers for pm off-mode support
|
|
|
* @obj: target iommu
|
|
|
**/
|
|
|
-void iommu_save_ctx(struct iommu *obj)
|
|
|
+void omap_iommu_save_ctx(struct omap_iommu *obj)
|
|
|
{
|
|
|
arch_iommu->save_ctx(obj);
|
|
|
}
|
|
|
-EXPORT_SYMBOL_GPL(iommu_save_ctx);
|
|
|
+EXPORT_SYMBOL_GPL(omap_iommu_save_ctx);
|
|
|
|
|
|
/**
|
|
|
- * iommu_restore_ctx - Restore registers for pm off-mode support
|
|
|
+ * omap_iommu_restore_ctx - Restore registers for pm off-mode support
|
|
|
* @obj: target iommu
|
|
|
**/
|
|
|
-void iommu_restore_ctx(struct iommu *obj)
|
|
|
+void omap_iommu_restore_ctx(struct omap_iommu *obj)
|
|
|
{
|
|
|
arch_iommu->restore_ctx(obj);
|
|
|
}
|
|
|
-EXPORT_SYMBOL_GPL(iommu_restore_ctx);
|
|
|
+EXPORT_SYMBOL_GPL(omap_iommu_restore_ctx);
|
|
|
|
|
|
/**
|
|
|
- * iommu_arch_version - Return running iommu arch version
|
|
|
+ * omap_iommu_arch_version - Return running iommu arch version
|
|
|
**/
|
|
|
-u32 iommu_arch_version(void)
|
|
|
+u32 omap_iommu_arch_version(void)
|
|
|
{
|
|
|
return arch_iommu->version;
|
|
|
}
|
|
|
-EXPORT_SYMBOL_GPL(iommu_arch_version);
|
|
|
+EXPORT_SYMBOL_GPL(omap_iommu_arch_version);
|
|
|
|
|
|
-static int iommu_enable(struct iommu *obj)
|
|
|
+static int iommu_enable(struct omap_iommu *obj)
|
|
|
{
|
|
|
int err;
|
|
|
|
|
@@ -115,7 +131,7 @@ static int iommu_enable(struct iommu *obj)
|
|
|
return err;
|
|
|
}
|
|
|
|
|
|
-static void iommu_disable(struct iommu *obj)
|
|
|
+static void iommu_disable(struct omap_iommu *obj)
|
|
|
{
|
|
|
if (!obj)
|
|
|
return;
|
|
@@ -130,13 +146,13 @@ static void iommu_disable(struct iommu *obj)
|
|
|
/*
|
|
|
* TLB operations
|
|
|
*/
|
|
|
-void iotlb_cr_to_e(struct cr_regs *cr, struct iotlb_entry *e)
|
|
|
+void omap_iotlb_cr_to_e(struct cr_regs *cr, struct iotlb_entry *e)
|
|
|
{
|
|
|
BUG_ON(!cr || !e);
|
|
|
|
|
|
arch_iommu->cr_to_e(cr, e);
|
|
|
}
|
|
|
-EXPORT_SYMBOL_GPL(iotlb_cr_to_e);
|
|
|
+EXPORT_SYMBOL_GPL(omap_iotlb_cr_to_e);
|
|
|
|
|
|
static inline int iotlb_cr_valid(struct cr_regs *cr)
|
|
|
{
|
|
@@ -146,7 +162,7 @@ static inline int iotlb_cr_valid(struct cr_regs *cr)
|
|
|
return arch_iommu->cr_valid(cr);
|
|
|
}
|
|
|
|
|
|
-static inline struct cr_regs *iotlb_alloc_cr(struct iommu *obj,
|
|
|
+static inline struct cr_regs *iotlb_alloc_cr(struct omap_iommu *obj,
|
|
|
struct iotlb_entry *e)
|
|
|
{
|
|
|
if (!e)
|
|
@@ -155,23 +171,22 @@ static inline struct cr_regs *iotlb_alloc_cr(struct iommu *obj,
|
|
|
return arch_iommu->alloc_cr(obj, e);
|
|
|
}
|
|
|
|
|
|
-u32 iotlb_cr_to_virt(struct cr_regs *cr)
|
|
|
+static u32 iotlb_cr_to_virt(struct cr_regs *cr)
|
|
|
{
|
|
|
return arch_iommu->cr_to_virt(cr);
|
|
|
}
|
|
|
-EXPORT_SYMBOL_GPL(iotlb_cr_to_virt);
|
|
|
|
|
|
static u32 get_iopte_attr(struct iotlb_entry *e)
|
|
|
{
|
|
|
return arch_iommu->get_pte_attr(e);
|
|
|
}
|
|
|
|
|
|
-static u32 iommu_report_fault(struct iommu *obj, u32 *da)
|
|
|
+static u32 iommu_report_fault(struct omap_iommu *obj, u32 *da)
|
|
|
{
|
|
|
return arch_iommu->fault_isr(obj, da);
|
|
|
}
|
|
|
|
|
|
-static void iotlb_lock_get(struct iommu *obj, struct iotlb_lock *l)
|
|
|
+static void iotlb_lock_get(struct omap_iommu *obj, struct iotlb_lock *l)
|
|
|
{
|
|
|
u32 val;
|
|
|
|
|
@@ -182,7 +197,7 @@ static void iotlb_lock_get(struct iommu *obj, struct iotlb_lock *l)
|
|
|
|
|
|
}
|
|
|
|
|
|
-static void iotlb_lock_set(struct iommu *obj, struct iotlb_lock *l)
|
|
|
+static void iotlb_lock_set(struct omap_iommu *obj, struct iotlb_lock *l)
|
|
|
{
|
|
|
u32 val;
|
|
|
|
|
@@ -192,12 +207,12 @@ static void iotlb_lock_set(struct iommu *obj, struct iotlb_lock *l)
|
|
|
iommu_write_reg(obj, val, MMU_LOCK);
|
|
|
}
|
|
|
|
|
|
-static void iotlb_read_cr(struct iommu *obj, struct cr_regs *cr)
|
|
|
+static void iotlb_read_cr(struct omap_iommu *obj, struct cr_regs *cr)
|
|
|
{
|
|
|
arch_iommu->tlb_read_cr(obj, cr);
|
|
|
}
|
|
|
|
|
|
-static void iotlb_load_cr(struct iommu *obj, struct cr_regs *cr)
|
|
|
+static void iotlb_load_cr(struct omap_iommu *obj, struct cr_regs *cr)
|
|
|
{
|
|
|
arch_iommu->tlb_load_cr(obj, cr);
|
|
|
|
|
@@ -211,7 +226,7 @@ static void iotlb_load_cr(struct iommu *obj, struct cr_regs *cr)
|
|
|
* @cr: contents of cam and ram register
|
|
|
* @buf: output buffer
|
|
|
**/
|
|
|
-static inline ssize_t iotlb_dump_cr(struct iommu *obj, struct cr_regs *cr,
|
|
|
+static inline ssize_t iotlb_dump_cr(struct omap_iommu *obj, struct cr_regs *cr,
|
|
|
char *buf)
|
|
|
{
|
|
|
BUG_ON(!cr || !buf);
|
|
@@ -220,7 +235,7 @@ static inline ssize_t iotlb_dump_cr(struct iommu *obj, struct cr_regs *cr,
|
|
|
}
|
|
|
|
|
|
/* only used in iotlb iteration for-loop */
|
|
|
-static struct cr_regs __iotlb_read_cr(struct iommu *obj, int n)
|
|
|
+static struct cr_regs __iotlb_read_cr(struct omap_iommu *obj, int n)
|
|
|
{
|
|
|
struct cr_regs cr;
|
|
|
struct iotlb_lock l;
|
|
@@ -238,7 +253,8 @@ static struct cr_regs __iotlb_read_cr(struct iommu *obj, int n)
|
|
|
* @obj: target iommu
|
|
|
* @e: an iommu tlb entry info
|
|
|
**/
|
|
|
-int load_iotlb_entry(struct iommu *obj, struct iotlb_entry *e)
|
|
|
+#ifdef PREFETCH_IOTLB
|
|
|
+static int load_iotlb_entry(struct omap_iommu *obj, struct iotlb_entry *e)
|
|
|
{
|
|
|
int err = 0;
|
|
|
struct iotlb_lock l;
|
|
@@ -294,7 +310,20 @@ out:
|
|
|
clk_disable(obj->clk);
|
|
|
return err;
|
|
|
}
|
|
|
-EXPORT_SYMBOL_GPL(load_iotlb_entry);
|
|
|
+
|
|
|
+#else /* !PREFETCH_IOTLB */
|
|
|
+
|
|
|
+static int load_iotlb_entry(struct omap_iommu *obj, struct iotlb_entry *e)
|
|
|
+{
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+#endif /* !PREFETCH_IOTLB */
|
|
|
+
|
|
|
+static int prefetch_iotlb_entry(struct omap_iommu *obj, struct iotlb_entry *e)
|
|
|
+{
|
|
|
+ return load_iotlb_entry(obj, e);
|
|
|
+}
|
|
|
|
|
|
/**
|
|
|
* flush_iotlb_page - Clear an iommu tlb entry
|
|
@@ -303,7 +332,7 @@ EXPORT_SYMBOL_GPL(load_iotlb_entry);
|
|
|
*
|
|
|
* Clear an iommu tlb entry which includes 'da' address.
|
|
|
**/
|
|
|
-void flush_iotlb_page(struct iommu *obj, u32 da)
|
|
|
+static void flush_iotlb_page(struct omap_iommu *obj, u32 da)
|
|
|
{
|
|
|
int i;
|
|
|
struct cr_regs cr;
|
|
@@ -332,33 +361,12 @@ void flush_iotlb_page(struct iommu *obj, u32 da)
|
|
|
if (i == obj->nr_tlb_entries)
|
|
|
dev_dbg(obj->dev, "%s: no page for %08x\n", __func__, da);
|
|
|
}
|
|
|
-EXPORT_SYMBOL_GPL(flush_iotlb_page);
|
|
|
-
|
|
|
-/**
|
|
|
- * flush_iotlb_range - Clear an iommu tlb entries
|
|
|
- * @obj: target iommu
|
|
|
- * @start: iommu device virtual address(start)
|
|
|
- * @end: iommu device virtual address(end)
|
|
|
- *
|
|
|
- * Clear an iommu tlb entry which includes 'da' address.
|
|
|
- **/
|
|
|
-void flush_iotlb_range(struct iommu *obj, u32 start, u32 end)
|
|
|
-{
|
|
|
- u32 da = start;
|
|
|
-
|
|
|
- while (da < end) {
|
|
|
- flush_iotlb_page(obj, da);
|
|
|
- /* FIXME: Optimize for multiple page size */
|
|
|
- da += IOPTE_SIZE;
|
|
|
- }
|
|
|
-}
|
|
|
-EXPORT_SYMBOL_GPL(flush_iotlb_range);
|
|
|
|
|
|
/**
|
|
|
* flush_iotlb_all - Clear all iommu tlb entries
|
|
|
* @obj: target iommu
|
|
|
**/
|
|
|
-void flush_iotlb_all(struct iommu *obj)
|
|
|
+static void flush_iotlb_all(struct omap_iommu *obj)
|
|
|
{
|
|
|
struct iotlb_lock l;
|
|
|
|
|
@@ -372,28 +380,10 @@ void flush_iotlb_all(struct iommu *obj)
|
|
|
|
|
|
clk_disable(obj->clk);
|
|
|
}
|
|
|
-EXPORT_SYMBOL_GPL(flush_iotlb_all);
|
|
|
-
|
|
|
-/**
|
|
|
- * iommu_set_twl - enable/disable table walking logic
|
|
|
- * @obj: target iommu
|
|
|
- * @on: enable/disable
|
|
|
- *
|
|
|
- * Function used to enable/disable TWL. If one wants to work
|
|
|
- * exclusively with locked TLB entries and receive notifications
|
|
|
- * for TLB miss then call this function to disable TWL.
|
|
|
- */
|
|
|
-void iommu_set_twl(struct iommu *obj, bool on)
|
|
|
-{
|
|
|
- clk_enable(obj->clk);
|
|
|
- arch_iommu->set_twl(obj, on);
|
|
|
- clk_disable(obj->clk);
|
|
|
-}
|
|
|
-EXPORT_SYMBOL_GPL(iommu_set_twl);
|
|
|
|
|
|
-#if defined(CONFIG_OMAP_IOMMU_DEBUG_MODULE)
|
|
|
+#if defined(CONFIG_OMAP_IOMMU_DEBUG) || defined(CONFIG_OMAP_IOMMU_DEBUG_MODULE)
|
|
|
|
|
|
-ssize_t iommu_dump_ctx(struct iommu *obj, char *buf, ssize_t bytes)
|
|
|
+ssize_t omap_iommu_dump_ctx(struct omap_iommu *obj, char *buf, ssize_t bytes)
|
|
|
{
|
|
|
if (!obj || !buf)
|
|
|
return -EINVAL;
|
|
@@ -406,9 +396,10 @@ ssize_t iommu_dump_ctx(struct iommu *obj, char *buf, ssize_t bytes)
|
|
|
|
|
|
return bytes;
|
|
|
}
|
|
|
-EXPORT_SYMBOL_GPL(iommu_dump_ctx);
|
|
|
+EXPORT_SYMBOL_GPL(omap_iommu_dump_ctx);
|
|
|
|
|
|
-static int __dump_tlb_entries(struct iommu *obj, struct cr_regs *crs, int num)
|
|
|
+static int
|
|
|
+__dump_tlb_entries(struct omap_iommu *obj, struct cr_regs *crs, int num)
|
|
|
{
|
|
|
int i;
|
|
|
struct iotlb_lock saved;
|
|
@@ -431,11 +422,11 @@ static int __dump_tlb_entries(struct iommu *obj, struct cr_regs *crs, int num)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * dump_tlb_entries - dump cr arrays to given buffer
|
|
|
+ * omap_dump_tlb_entries - dump cr arrays to given buffer
|
|
|
* @obj: target iommu
|
|
|
* @buf: output buffer
|
|
|
**/
|
|
|
-size_t dump_tlb_entries(struct iommu *obj, char *buf, ssize_t bytes)
|
|
|
+size_t omap_dump_tlb_entries(struct omap_iommu *obj, char *buf, ssize_t bytes)
|
|
|
{
|
|
|
int i, num;
|
|
|
struct cr_regs *cr;
|
|
@@ -455,14 +446,14 @@ size_t dump_tlb_entries(struct iommu *obj, char *buf, ssize_t bytes)
|
|
|
|
|
|
return p - buf;
|
|
|
}
|
|
|
-EXPORT_SYMBOL_GPL(dump_tlb_entries);
|
|
|
+EXPORT_SYMBOL_GPL(omap_dump_tlb_entries);
|
|
|
|
|
|
-int foreach_iommu_device(void *data, int (*fn)(struct device *, void *))
|
|
|
+int omap_foreach_iommu_device(void *data, int (*fn)(struct device *, void *))
|
|
|
{
|
|
|
return driver_for_each_device(&omap_iommu_driver.driver,
|
|
|
NULL, data, fn);
|
|
|
}
|
|
|
-EXPORT_SYMBOL_GPL(foreach_iommu_device);
|
|
|
+EXPORT_SYMBOL_GPL(omap_foreach_iommu_device);
|
|
|
|
|
|
#endif /* CONFIG_OMAP_IOMMU_DEBUG_MODULE */
|
|
|
|
|
@@ -495,7 +486,7 @@ static void iopte_free(u32 *iopte)
|
|
|
kmem_cache_free(iopte_cachep, iopte);
|
|
|
}
|
|
|
|
|
|
-static u32 *iopte_alloc(struct iommu *obj, u32 *iopgd, u32 da)
|
|
|
+static u32 *iopte_alloc(struct omap_iommu *obj, u32 *iopgd, u32 da)
|
|
|
{
|
|
|
u32 *iopte;
|
|
|
|
|
@@ -533,7 +524,7 @@ pte_ready:
|
|
|
return iopte;
|
|
|
}
|
|
|
|
|
|
-static int iopgd_alloc_section(struct iommu *obj, u32 da, u32 pa, u32 prot)
|
|
|
+static int iopgd_alloc_section(struct omap_iommu *obj, u32 da, u32 pa, u32 prot)
|
|
|
{
|
|
|
u32 *iopgd = iopgd_offset(obj, da);
|
|
|
|
|
@@ -548,7 +539,7 @@ static int iopgd_alloc_section(struct iommu *obj, u32 da, u32 pa, u32 prot)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-static int iopgd_alloc_super(struct iommu *obj, u32 da, u32 pa, u32 prot)
|
|
|
+static int iopgd_alloc_super(struct omap_iommu *obj, u32 da, u32 pa, u32 prot)
|
|
|
{
|
|
|
u32 *iopgd = iopgd_offset(obj, da);
|
|
|
int i;
|
|
@@ -565,7 +556,7 @@ static int iopgd_alloc_super(struct iommu *obj, u32 da, u32 pa, u32 prot)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-static int iopte_alloc_page(struct iommu *obj, u32 da, u32 pa, u32 prot)
|
|
|
+static int iopte_alloc_page(struct omap_iommu *obj, u32 da, u32 pa, u32 prot)
|
|
|
{
|
|
|
u32 *iopgd = iopgd_offset(obj, da);
|
|
|
u32 *iopte = iopte_alloc(obj, iopgd, da);
|
|
@@ -582,7 +573,7 @@ static int iopte_alloc_page(struct iommu *obj, u32 da, u32 pa, u32 prot)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-static int iopte_alloc_large(struct iommu *obj, u32 da, u32 pa, u32 prot)
|
|
|
+static int iopte_alloc_large(struct omap_iommu *obj, u32 da, u32 pa, u32 prot)
|
|
|
{
|
|
|
u32 *iopgd = iopgd_offset(obj, da);
|
|
|
u32 *iopte = iopte_alloc(obj, iopgd, da);
|
|
@@ -603,9 +594,10 @@ static int iopte_alloc_large(struct iommu *obj, u32 da, u32 pa, u32 prot)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-static int iopgtable_store_entry_core(struct iommu *obj, struct iotlb_entry *e)
|
|
|
+static int
|
|
|
+iopgtable_store_entry_core(struct omap_iommu *obj, struct iotlb_entry *e)
|
|
|
{
|
|
|
- int (*fn)(struct iommu *, u32, u32, u32);
|
|
|
+ int (*fn)(struct omap_iommu *, u32, u32, u32);
|
|
|
u32 prot;
|
|
|
int err;
|
|
|
|
|
@@ -641,23 +633,21 @@ static int iopgtable_store_entry_core(struct iommu *obj, struct iotlb_entry *e)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * iopgtable_store_entry - Make an iommu pte entry
|
|
|
+ * omap_iopgtable_store_entry - Make an iommu pte entry
|
|
|
* @obj: target iommu
|
|
|
* @e: an iommu tlb entry info
|
|
|
**/
|
|
|
-int iopgtable_store_entry(struct iommu *obj, struct iotlb_entry *e)
|
|
|
+int omap_iopgtable_store_entry(struct omap_iommu *obj, struct iotlb_entry *e)
|
|
|
{
|
|
|
int err;
|
|
|
|
|
|
flush_iotlb_page(obj, e->da);
|
|
|
err = iopgtable_store_entry_core(obj, e);
|
|
|
-#ifdef PREFETCH_IOTLB
|
|
|
if (!err)
|
|
|
- load_iotlb_entry(obj, e);
|
|
|
-#endif
|
|
|
+ prefetch_iotlb_entry(obj, e);
|
|
|
return err;
|
|
|
}
|
|
|
-EXPORT_SYMBOL_GPL(iopgtable_store_entry);
|
|
|
+EXPORT_SYMBOL_GPL(omap_iopgtable_store_entry);
|
|
|
|
|
|
/**
|
|
|
* iopgtable_lookup_entry - Lookup an iommu pte entry
|
|
@@ -666,7 +656,8 @@ EXPORT_SYMBOL_GPL(iopgtable_store_entry);
|
|
|
* @ppgd: iommu pgd entry pointer to be returned
|
|
|
* @ppte: iommu pte entry pointer to be returned
|
|
|
**/
|
|
|
-void iopgtable_lookup_entry(struct iommu *obj, u32 da, u32 **ppgd, u32 **ppte)
|
|
|
+static void
|
|
|
+iopgtable_lookup_entry(struct omap_iommu *obj, u32 da, u32 **ppgd, u32 **ppte)
|
|
|
{
|
|
|
u32 *iopgd, *iopte = NULL;
|
|
|
|
|
@@ -680,9 +671,8 @@ out:
|
|
|
*ppgd = iopgd;
|
|
|
*ppte = iopte;
|
|
|
}
|
|
|
-EXPORT_SYMBOL_GPL(iopgtable_lookup_entry);
|
|
|
|
|
|
-static size_t iopgtable_clear_entry_core(struct iommu *obj, u32 da)
|
|
|
+static size_t iopgtable_clear_entry_core(struct omap_iommu *obj, u32 da)
|
|
|
{
|
|
|
size_t bytes;
|
|
|
u32 *iopgd = iopgd_offset(obj, da);
|
|
@@ -735,7 +725,7 @@ out:
|
|
|
* @obj: target iommu
|
|
|
* @da: iommu device virtual address
|
|
|
**/
|
|
|
-size_t iopgtable_clear_entry(struct iommu *obj, u32 da)
|
|
|
+static size_t iopgtable_clear_entry(struct omap_iommu *obj, u32 da)
|
|
|
{
|
|
|
size_t bytes;
|
|
|
|
|
@@ -748,9 +738,8 @@ size_t iopgtable_clear_entry(struct iommu *obj, u32 da)
|
|
|
|
|
|
return bytes;
|
|
|
}
|
|
|
-EXPORT_SYMBOL_GPL(iopgtable_clear_entry);
|
|
|
|
|
|
-static void iopgtable_clear_entry_all(struct iommu *obj)
|
|
|
+static void iopgtable_clear_entry_all(struct omap_iommu *obj)
|
|
|
{
|
|
|
int i;
|
|
|
|
|
@@ -785,7 +774,8 @@ static irqreturn_t iommu_fault_handler(int irq, void *data)
|
|
|
{
|
|
|
u32 da, errs;
|
|
|
u32 *iopgd, *iopte;
|
|
|
- struct iommu *obj = data;
|
|
|
+ struct omap_iommu *obj = data;
|
|
|
+ struct iommu_domain *domain = obj->domain;
|
|
|
|
|
|
if (!obj->refcount)
|
|
|
return IRQ_NONE;
|
|
@@ -797,7 +787,7 @@ static irqreturn_t iommu_fault_handler(int irq, void *data)
|
|
|
return IRQ_HANDLED;
|
|
|
|
|
|
/* Fault callback or TLB/PTE Dynamic loading */
|
|
|
- if (obj->isr && !obj->isr(obj, da, errs, obj->isr_priv))
|
|
|
+ if (!report_iommu_fault(domain, obj->dev, da, 0))
|
|
|
return IRQ_HANDLED;
|
|
|
|
|
|
iommu_disable(obj);
|
|
@@ -821,7 +811,7 @@ static irqreturn_t iommu_fault_handler(int irq, void *data)
|
|
|
|
|
|
static int device_match_by_alias(struct device *dev, void *data)
|
|
|
{
|
|
|
- struct iommu *obj = to_iommu(dev);
|
|
|
+ struct omap_iommu *obj = to_iommu(dev);
|
|
|
const char *name = data;
|
|
|
|
|
|
pr_debug("%s: %s %s\n", __func__, obj->name, name);
|
|
@@ -830,57 +820,55 @@ static int device_match_by_alias(struct device *dev, void *data)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * iommu_set_da_range - Set a valid device address range
|
|
|
- * @obj: target iommu
|
|
|
- * @start Start of valid range
|
|
|
- * @end End of valid range
|
|
|
- **/
|
|
|
-int iommu_set_da_range(struct iommu *obj, u32 start, u32 end)
|
|
|
+ * omap_find_iommu_device() - find an omap iommu device by name
|
|
|
+ * @name: name of the iommu device
|
|
|
+ *
|
|
|
+ * The generic iommu API requires the caller to provide the device
|
|
|
+ * he wishes to attach to a certain iommu domain.
|
|
|
+ *
|
|
|
+ * Drivers generally should not bother with this as it should just
|
|
|
+ * be taken care of by the DMA-API using dev_archdata.
|
|
|
+ *
|
|
|
+ * This function is provided as an interim solution until the latter
|
|
|
+ * materializes, and omap3isp is fully migrated to the DMA-API.
|
|
|
+ */
|
|
|
+struct device *omap_find_iommu_device(const char *name)
|
|
|
{
|
|
|
-
|
|
|
- if (!obj)
|
|
|
- return -EFAULT;
|
|
|
-
|
|
|
- if (end < start || !PAGE_ALIGN(start | end))
|
|
|
- return -EINVAL;
|
|
|
-
|
|
|
- obj->da_start = start;
|
|
|
- obj->da_end = end;
|
|
|
-
|
|
|
- return 0;
|
|
|
+ return driver_find_device(&omap_iommu_driver.driver, NULL,
|
|
|
+ (void *)name,
|
|
|
+ device_match_by_alias);
|
|
|
}
|
|
|
-EXPORT_SYMBOL_GPL(iommu_set_da_range);
|
|
|
+EXPORT_SYMBOL_GPL(omap_find_iommu_device);
|
|
|
|
|
|
/**
|
|
|
- * iommu_get - Get iommu handler
|
|
|
- * @name: target iommu name
|
|
|
+ * omap_iommu_attach() - attach iommu device to an iommu domain
|
|
|
+ * @dev: target omap iommu device
|
|
|
+ * @iopgd: page table
|
|
|
**/
|
|
|
-struct iommu *iommu_get(const char *name)
|
|
|
+static struct omap_iommu *omap_iommu_attach(struct device *dev, u32 *iopgd)
|
|
|
{
|
|
|
int err = -ENOMEM;
|
|
|
- struct device *dev;
|
|
|
- struct iommu *obj;
|
|
|
-
|
|
|
- dev = driver_find_device(&omap_iommu_driver.driver, NULL, (void *)name,
|
|
|
- device_match_by_alias);
|
|
|
- if (!dev)
|
|
|
- return ERR_PTR(-ENODEV);
|
|
|
-
|
|
|
- obj = to_iommu(dev);
|
|
|
+ struct omap_iommu *obj = to_iommu(dev);
|
|
|
|
|
|
- mutex_lock(&obj->iommu_lock);
|
|
|
+ spin_lock(&obj->iommu_lock);
|
|
|
|
|
|
- if (obj->refcount++ == 0) {
|
|
|
- err = iommu_enable(obj);
|
|
|
- if (err)
|
|
|
- goto err_enable;
|
|
|
- flush_iotlb_all(obj);
|
|
|
+ /* an iommu device can only be attached once */
|
|
|
+ if (++obj->refcount > 1) {
|
|
|
+ dev_err(dev, "%s: already attached!\n", obj->name);
|
|
|
+ err = -EBUSY;
|
|
|
+ goto err_enable;
|
|
|
}
|
|
|
|
|
|
+ obj->iopgd = iopgd;
|
|
|
+ err = iommu_enable(obj);
|
|
|
+ if (err)
|
|
|
+ goto err_enable;
|
|
|
+ flush_iotlb_all(obj);
|
|
|
+
|
|
|
if (!try_module_get(obj->owner))
|
|
|
goto err_module;
|
|
|
|
|
|
- mutex_unlock(&obj->iommu_lock);
|
|
|
+ spin_unlock(&obj->iommu_lock);
|
|
|
|
|
|
dev_dbg(obj->dev, "%s: %s\n", __func__, obj->name);
|
|
|
return obj;
|
|
@@ -890,59 +878,32 @@ err_module:
|
|
|
iommu_disable(obj);
|
|
|
err_enable:
|
|
|
obj->refcount--;
|
|
|
- mutex_unlock(&obj->iommu_lock);
|
|
|
+ spin_unlock(&obj->iommu_lock);
|
|
|
return ERR_PTR(err);
|
|
|
}
|
|
|
-EXPORT_SYMBOL_GPL(iommu_get);
|
|
|
|
|
|
/**
|
|
|
- * iommu_put - Put back iommu handler
|
|
|
+ * omap_iommu_detach - release iommu device
|
|
|
* @obj: target iommu
|
|
|
**/
|
|
|
-void iommu_put(struct iommu *obj)
|
|
|
+static void omap_iommu_detach(struct omap_iommu *obj)
|
|
|
{
|
|
|
if (!obj || IS_ERR(obj))
|
|
|
return;
|
|
|
|
|
|
- mutex_lock(&obj->iommu_lock);
|
|
|
+ spin_lock(&obj->iommu_lock);
|
|
|
|
|
|
if (--obj->refcount == 0)
|
|
|
iommu_disable(obj);
|
|
|
|
|
|
module_put(obj->owner);
|
|
|
|
|
|
- mutex_unlock(&obj->iommu_lock);
|
|
|
-
|
|
|
- dev_dbg(obj->dev, "%s: %s\n", __func__, obj->name);
|
|
|
-}
|
|
|
-EXPORT_SYMBOL_GPL(iommu_put);
|
|
|
-
|
|
|
-int iommu_set_isr(const char *name,
|
|
|
- int (*isr)(struct iommu *obj, u32 da, u32 iommu_errs,
|
|
|
- void *priv),
|
|
|
- void *isr_priv)
|
|
|
-{
|
|
|
- struct device *dev;
|
|
|
- struct iommu *obj;
|
|
|
+ obj->iopgd = NULL;
|
|
|
|
|
|
- dev = driver_find_device(&omap_iommu_driver.driver, NULL, (void *)name,
|
|
|
- device_match_by_alias);
|
|
|
- if (!dev)
|
|
|
- return -ENODEV;
|
|
|
+ spin_unlock(&obj->iommu_lock);
|
|
|
|
|
|
- obj = to_iommu(dev);
|
|
|
- mutex_lock(&obj->iommu_lock);
|
|
|
- if (obj->refcount != 0) {
|
|
|
- mutex_unlock(&obj->iommu_lock);
|
|
|
- return -EBUSY;
|
|
|
- }
|
|
|
- obj->isr = isr;
|
|
|
- obj->isr_priv = isr_priv;
|
|
|
- mutex_unlock(&obj->iommu_lock);
|
|
|
-
|
|
|
- return 0;
|
|
|
+ dev_dbg(obj->dev, "%s: %s\n", __func__, obj->name);
|
|
|
}
|
|
|
-EXPORT_SYMBOL_GPL(iommu_set_isr);
|
|
|
|
|
|
/*
|
|
|
* OMAP Device MMU(IOMMU) detection
|
|
@@ -950,9 +911,8 @@ EXPORT_SYMBOL_GPL(iommu_set_isr);
|
|
|
static int __devinit omap_iommu_probe(struct platform_device *pdev)
|
|
|
{
|
|
|
int err = -ENODEV;
|
|
|
- void *p;
|
|
|
int irq;
|
|
|
- struct iommu *obj;
|
|
|
+ struct omap_iommu *obj;
|
|
|
struct resource *res;
|
|
|
struct iommu_platform_data *pdata = pdev->dev.platform_data;
|
|
|
|
|
@@ -974,7 +934,7 @@ static int __devinit omap_iommu_probe(struct platform_device *pdev)
|
|
|
obj->da_start = pdata->da_start;
|
|
|
obj->da_end = pdata->da_end;
|
|
|
|
|
|
- mutex_init(&obj->iommu_lock);
|
|
|
+ spin_lock_init(&obj->iommu_lock);
|
|
|
mutex_init(&obj->mmap_lock);
|
|
|
spin_lock_init(&obj->page_table_lock);
|
|
|
INIT_LIST_HEAD(&obj->mmap);
|
|
@@ -1009,22 +969,9 @@ static int __devinit omap_iommu_probe(struct platform_device *pdev)
|
|
|
goto err_irq;
|
|
|
platform_set_drvdata(pdev, obj);
|
|
|
|
|
|
- p = (void *)__get_free_pages(GFP_KERNEL, get_order(IOPGD_TABLE_SIZE));
|
|
|
- if (!p) {
|
|
|
- err = -ENOMEM;
|
|
|
- goto err_pgd;
|
|
|
- }
|
|
|
- memset(p, 0, IOPGD_TABLE_SIZE);
|
|
|
- clean_dcache_area(p, IOPGD_TABLE_SIZE);
|
|
|
- obj->iopgd = p;
|
|
|
-
|
|
|
- BUG_ON(!IS_ALIGNED((unsigned long)obj->iopgd, IOPGD_TABLE_SIZE));
|
|
|
-
|
|
|
dev_info(&pdev->dev, "%s registered\n", obj->name);
|
|
|
return 0;
|
|
|
|
|
|
-err_pgd:
|
|
|
- free_irq(irq, obj);
|
|
|
err_irq:
|
|
|
iounmap(obj->regbase);
|
|
|
err_ioremap:
|
|
@@ -1040,12 +987,11 @@ static int __devexit omap_iommu_remove(struct platform_device *pdev)
|
|
|
{
|
|
|
int irq;
|
|
|
struct resource *res;
|
|
|
- struct iommu *obj = platform_get_drvdata(pdev);
|
|
|
+ struct omap_iommu *obj = platform_get_drvdata(pdev);
|
|
|
|
|
|
platform_set_drvdata(pdev, NULL);
|
|
|
|
|
|
iopgtable_clear_entry_all(obj);
|
|
|
- free_pages((unsigned long)obj->iopgd, get_order(IOPGD_TABLE_SIZE));
|
|
|
|
|
|
irq = platform_get_irq(pdev, 0);
|
|
|
free_irq(irq, obj);
|
|
@@ -1072,6 +1018,201 @@ static void iopte_cachep_ctor(void *iopte)
|
|
|
clean_dcache_area(iopte, IOPTE_TABLE_SIZE);
|
|
|
}
|
|
|
|
|
|
+static int omap_iommu_map(struct iommu_domain *domain, unsigned long da,
|
|
|
+ phys_addr_t pa, int order, int prot)
|
|
|
+{
|
|
|
+ struct omap_iommu_domain *omap_domain = domain->priv;
|
|
|
+ struct omap_iommu *oiommu = omap_domain->iommu_dev;
|
|
|
+ struct device *dev = oiommu->dev;
|
|
|
+ size_t bytes = PAGE_SIZE << order;
|
|
|
+ struct iotlb_entry e;
|
|
|
+ int omap_pgsz;
|
|
|
+ u32 ret, flags;
|
|
|
+
|
|
|
+ /* we only support mapping a single iommu page for now */
|
|
|
+ omap_pgsz = bytes_to_iopgsz(bytes);
|
|
|
+ if (omap_pgsz < 0) {
|
|
|
+ dev_err(dev, "invalid size to map: %d\n", bytes);
|
|
|
+ return -EINVAL;
|
|
|
+ }
|
|
|
+
|
|
|
+ dev_dbg(dev, "mapping da 0x%lx to pa 0x%x size 0x%x\n", da, pa, bytes);
|
|
|
+
|
|
|
+ flags = omap_pgsz | prot;
|
|
|
+
|
|
|
+ iotlb_init_entry(&e, da, pa, flags);
|
|
|
+
|
|
|
+ ret = omap_iopgtable_store_entry(oiommu, &e);
|
|
|
+ if (ret)
|
|
|
+ dev_err(dev, "omap_iopgtable_store_entry failed: %d\n", ret);
|
|
|
+
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
+static int omap_iommu_unmap(struct iommu_domain *domain, unsigned long da,
|
|
|
+ int order)
|
|
|
+{
|
|
|
+ struct omap_iommu_domain *omap_domain = domain->priv;
|
|
|
+ struct omap_iommu *oiommu = omap_domain->iommu_dev;
|
|
|
+ struct device *dev = oiommu->dev;
|
|
|
+ size_t unmap_size;
|
|
|
+
|
|
|
+ dev_dbg(dev, "unmapping da 0x%lx order %d\n", da, order);
|
|
|
+
|
|
|
+ unmap_size = iopgtable_clear_entry(oiommu, da);
|
|
|
+
|
|
|
+ return unmap_size ? get_order(unmap_size) : -EINVAL;
|
|
|
+}
|
|
|
+
|
|
|
+static int
|
|
|
+omap_iommu_attach_dev(struct iommu_domain *domain, struct device *dev)
|
|
|
+{
|
|
|
+ struct omap_iommu_domain *omap_domain = domain->priv;
|
|
|
+ struct omap_iommu *oiommu;
|
|
|
+ int ret = 0;
|
|
|
+
|
|
|
+ spin_lock(&omap_domain->lock);
|
|
|
+
|
|
|
+ /* only a single device is supported per domain for now */
|
|
|
+ if (omap_domain->iommu_dev) {
|
|
|
+ dev_err(dev, "iommu domain is already attached\n");
|
|
|
+ ret = -EBUSY;
|
|
|
+ goto out;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* get a handle to and enable the omap iommu */
|
|
|
+ oiommu = omap_iommu_attach(dev, omap_domain->pgtable);
|
|
|
+ if (IS_ERR(oiommu)) {
|
|
|
+ ret = PTR_ERR(oiommu);
|
|
|
+ dev_err(dev, "can't get omap iommu: %d\n", ret);
|
|
|
+ goto out;
|
|
|
+ }
|
|
|
+
|
|
|
+ omap_domain->iommu_dev = oiommu;
|
|
|
+ oiommu->domain = domain;
|
|
|
+
|
|
|
+out:
|
|
|
+ spin_unlock(&omap_domain->lock);
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
+static void omap_iommu_detach_dev(struct iommu_domain *domain,
|
|
|
+ struct device *dev)
|
|
|
+{
|
|
|
+ struct omap_iommu_domain *omap_domain = domain->priv;
|
|
|
+ struct omap_iommu *oiommu = to_iommu(dev);
|
|
|
+
|
|
|
+ spin_lock(&omap_domain->lock);
|
|
|
+
|
|
|
+ /* only a single device is supported per domain for now */
|
|
|
+ if (omap_domain->iommu_dev != oiommu) {
|
|
|
+ dev_err(dev, "invalid iommu device\n");
|
|
|
+ goto out;
|
|
|
+ }
|
|
|
+
|
|
|
+ iopgtable_clear_entry_all(oiommu);
|
|
|
+
|
|
|
+ omap_iommu_detach(oiommu);
|
|
|
+
|
|
|
+ omap_domain->iommu_dev = NULL;
|
|
|
+
|
|
|
+out:
|
|
|
+ spin_unlock(&omap_domain->lock);
|
|
|
+}
|
|
|
+
|
|
|
+static int omap_iommu_domain_init(struct iommu_domain *domain)
|
|
|
+{
|
|
|
+ struct omap_iommu_domain *omap_domain;
|
|
|
+
|
|
|
+ omap_domain = kzalloc(sizeof(*omap_domain), GFP_KERNEL);
|
|
|
+ if (!omap_domain) {
|
|
|
+ pr_err("kzalloc failed\n");
|
|
|
+ goto out;
|
|
|
+ }
|
|
|
+
|
|
|
+ omap_domain->pgtable = kzalloc(IOPGD_TABLE_SIZE, GFP_KERNEL);
|
|
|
+ if (!omap_domain->pgtable) {
|
|
|
+ pr_err("kzalloc failed\n");
|
|
|
+ goto fail_nomem;
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ * should never fail, but please keep this around to ensure
|
|
|
+ * we keep the hardware happy
|
|
|
+ */
|
|
|
+ BUG_ON(!IS_ALIGNED((long)omap_domain->pgtable, IOPGD_TABLE_SIZE));
|
|
|
+
|
|
|
+ clean_dcache_area(omap_domain->pgtable, IOPGD_TABLE_SIZE);
|
|
|
+ spin_lock_init(&omap_domain->lock);
|
|
|
+
|
|
|
+ domain->priv = omap_domain;
|
|
|
+
|
|
|
+ return 0;
|
|
|
+
|
|
|
+fail_nomem:
|
|
|
+ kfree(omap_domain);
|
|
|
+out:
|
|
|
+ return -ENOMEM;
|
|
|
+}
|
|
|
+
|
|
|
+/* assume device was already detached */
|
|
|
+static void omap_iommu_domain_destroy(struct iommu_domain *domain)
|
|
|
+{
|
|
|
+ struct omap_iommu_domain *omap_domain = domain->priv;
|
|
|
+
|
|
|
+ domain->priv = NULL;
|
|
|
+
|
|
|
+ kfree(omap_domain->pgtable);
|
|
|
+ kfree(omap_domain);
|
|
|
+}
|
|
|
+
|
|
|
+static phys_addr_t omap_iommu_iova_to_phys(struct iommu_domain *domain,
|
|
|
+ unsigned long da)
|
|
|
+{
|
|
|
+ struct omap_iommu_domain *omap_domain = domain->priv;
|
|
|
+ struct omap_iommu *oiommu = omap_domain->iommu_dev;
|
|
|
+ struct device *dev = oiommu->dev;
|
|
|
+ u32 *pgd, *pte;
|
|
|
+ phys_addr_t ret = 0;
|
|
|
+
|
|
|
+ iopgtable_lookup_entry(oiommu, da, &pgd, &pte);
|
|
|
+
|
|
|
+ if (pte) {
|
|
|
+ if (iopte_is_small(*pte))
|
|
|
+ ret = omap_iommu_translate(*pte, da, IOPTE_MASK);
|
|
|
+ else if (iopte_is_large(*pte))
|
|
|
+ ret = omap_iommu_translate(*pte, da, IOLARGE_MASK);
|
|
|
+ else
|
|
|
+ dev_err(dev, "bogus pte 0x%x", *pte);
|
|
|
+ } else {
|
|
|
+ if (iopgd_is_section(*pgd))
|
|
|
+ ret = omap_iommu_translate(*pgd, da, IOSECTION_MASK);
|
|
|
+ else if (iopgd_is_super(*pgd))
|
|
|
+ ret = omap_iommu_translate(*pgd, da, IOSUPER_MASK);
|
|
|
+ else
|
|
|
+ dev_err(dev, "bogus pgd 0x%x", *pgd);
|
|
|
+ }
|
|
|
+
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
+static int omap_iommu_domain_has_cap(struct iommu_domain *domain,
|
|
|
+ unsigned long cap)
|
|
|
+{
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+static struct iommu_ops omap_iommu_ops = {
|
|
|
+ .domain_init = omap_iommu_domain_init,
|
|
|
+ .domain_destroy = omap_iommu_domain_destroy,
|
|
|
+ .attach_dev = omap_iommu_attach_dev,
|
|
|
+ .detach_dev = omap_iommu_detach_dev,
|
|
|
+ .map = omap_iommu_map,
|
|
|
+ .unmap = omap_iommu_unmap,
|
|
|
+ .iova_to_phys = omap_iommu_iova_to_phys,
|
|
|
+ .domain_has_cap = omap_iommu_domain_has_cap,
|
|
|
+};
|
|
|
+
|
|
|
static int __init omap_iommu_init(void)
|
|
|
{
|
|
|
struct kmem_cache *p;
|
|
@@ -1084,6 +1225,8 @@ static int __init omap_iommu_init(void)
|
|
|
return -ENOMEM;
|
|
|
iopte_cachep = p;
|
|
|
|
|
|
+ bus_set_iommu(&platform_bus_type, &omap_iommu_ops);
|
|
|
+
|
|
|
return platform_driver_register(&omap_iommu_driver);
|
|
|
}
|
|
|
module_init(omap_iommu_init);
|