Skip to contentSkip to conversation

omap iommu: tlb and pagetable primitives

PATCH In review Hiroshi DOYU 4 participants 17 messages May 20, 2009 – May 25, 2009

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/7 omap iommu: tlb and pagetable primitives

This patch provides:

- iotlb_*() : iommu tlb operations
- iopgtable_*() : iommu pagetable(twl) operations
- iommu_*() : the other generic operations

and the entry points to register and acquire iommu object.

---

 arch/arm/plat-omap/include/mach/iommu.h |  168 +++++
 arch/arm/plat-omap/iommu.c              |  996 +++++++++++++++++++++++++++++++
 arch/arm/plat-omap/iopgtable.h          |   72 ++
 3 files changed, 1236 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/plat-omap/include/mach/iommu.h
 create mode 100644 arch/arm/plat-omap/iommu.c
 create mode 100644 arch/arm/plat-omap/iopgtable.h
arch/arm/plat-omap/include/mach/iommu.h new file +168 -0
new file mode 100644
index 0000000..769b00b
@@ -0,0 +1,168 @@
+/*
+ * omap iommu: main structures
+ *
+ * Copyright (C) 2008-2009 Nokia Corporation
+ *
+ * Written by Hiroshi DOYU <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __MACH_IOMMU_H
+#define __MACH_IOMMU_H
+
+struct iotlb_entry {
+	u32 da;
+	u32 pa;
+	u32 pgsz, prsvd, valid;
+	union {
+		u16 ap;
+		struct {
+			u32 endian, elsz, mixed;
+		};
+	};
+};
+
+struct iommu {
+	const char	*name;
+	struct module	*owner;
+	struct clk	*clk;
+	void __iomem	*regbase;
+	struct device	*dev;
+
+	unsigned int	refcount;
+	struct mutex	iommu_lock;	/* global for this whole object */
+
+	/*
+	 * We don't change iopgd for a situation like pgd for a task,
+	 * but share it globally for each iommu.
+	 */
+	u32		*iopgd;
+	spinlock_t	page_table_lock; /* protect iopgd */
+
+	int		nr_tlb_entries;
+
+	struct list_head	mmap;
+	struct mutex		mmap_lock; /* protect mmap */
+
+	int (*isr)(struct iommu *obj);
+
+	void *ctx; /* iommu context: registres saved area */
+};
+
+struct cr_regs {
+	union {
+		struct {
+			u16 cam_l;
+			u16 cam_h;
+		};
+		u32 cam;
+	};
+	union {
+		struct {
+			u16 ram_l;
+			u16 ram_h;
+		};
+		u32 ram;
+	};
+};
+
+struct iotlb_lock {
+	short base;
+	short vict;
+};
+
+/* architecture specific functions */
+struct iommu_functions {
+	unsigned long	version;
+
+	int (*enable)(struct iommu *obj);
+	void (*disable)(struct iommu *obj);
+	u32 (*fault_isr)(struct iommu *obj, u32 *ra);
+
+	void (*tlb_read_cr)(struct iommu *obj, struct cr_regs *cr);
+	void (*tlb_load_cr)(struct iommu *obj, struct cr_regs *cr);
+
+	struct cr_regs *(*alloc_cr)(struct iommu *obj, struct iotlb_entry *e);
+	int (*cr_valid)(struct cr_regs *cr);
+	u32 (*cr_to_virt)(struct cr_regs *cr);
+	void (*cr_to_e)(struct cr_regs *cr, struct iotlb_entry *e);
+	ssize_t (*dump_cr)(struct iommu *obj, struct cr_regs *cr, char *buf);
+
+	u32 (*get_pte_attr)(struct iotlb_entry *e);
+
+	void (*save_ctx)(struct iommu *obj);
+	void (*restore_ctx)(struct iommu *obj);
+	ssize_t (*dump_ctx)(struct iommu *obj, char *buf);
+};
+
+struct iommu_platform_data {
+	const char *name;
+	const char *clk_name;
+	const int nr_tlb_entries;
+};
+
+#if defined(CONFIG_ARCH_OMAP1)
+#error "iommu for this processor not implemented yet"
+#else
+#include <mach/iommu2.h>
+#endif
+
+/*
+ * utilities for super page(16MB, 1MB, 64KB and 4KB)
+ */
+
+#define iopgsz_max(bytes)			\
+	(((bytes) >= SZ_16M) ? SZ_16M :		\
+	 ((bytes) >= SZ_1M)  ? SZ_1M  :		\
+	 ((bytes) >= SZ_64K) ? SZ_64K :		\
+	 ((bytes) >= SZ_4K)  ? SZ_4K  :	0)
+
+#define bytes_to_iopgsz(bytes)				\
+	(((bytes) == SZ_16M) ? MMU_CAM_PGSZ_16M :	\
+	 ((bytes) == SZ_1M)  ? MMU_CAM_PGSZ_1M  :	\
+	 ((bytes) == SZ_64K) ? MMU_CAM_PGSZ_64K :	\
+	 ((bytes) == SZ_4K)  ? MMU_CAM_PGSZ_4K  : -1)
+
+#define iopgsz_to_bytes(iopgsz)				\
+	(((iopgsz) == MMU_CAM_PGSZ_16M)	? SZ_16M :	\
+	 ((iopgsz) == MMU_CAM_PGSZ_1M)	? SZ_1M  :	\
+	 ((iopgsz) == MMU_CAM_PGSZ_64K)	? SZ_64K :	\
+	 ((iopgsz) == MMU_CAM_PGSZ_4K)	? SZ_4K  : 0)
+
+#define iopgsz_ok(bytes) (bytes_to_iopgsz(bytes) >= 0)
+
+/*
+ * global functions
+ */
+extern u32 iommu_arch_version(void);
+
+extern void iotlb_cr_to_e(struct cr_regs *cr, struct iotlb_entry *e);
+extern u32 iotlb_cr_to_virt(struct cr_regs *cr);
+
+extern int load_iotlb_entry(struct iommu *obj, struct iotlb_entry *e);
+extern void flush_iotlb_page(struct iommu *obj, u32 da);
+extern void flush_iotlb_range(struct iommu *obj, u32 start, u32 end);
+extern void flush_iotlb_all(struct iommu *obj);
+
+extern int iopgtable_store_entry(struct iommu *obj, struct iotlb_entry *e);
+extern size_t iopgtable_clear_entry(struct iommu *obj, u32 iova);
+
+extern struct iommu *iommu_get(const char *name);
+extern void iommu_put(struct iommu *obj);
+
+extern void iommu_save_ctx(struct iommu *obj);
+extern void iommu_restore_ctx(struct iommu *obj);
+
+extern int install_iommu_arch(const struct iommu_functions *ops);
+extern void uninstall_iommu_arch(const struct iommu_functions *ops);
+
+extern int foreach_iommu_device(void *data,
+				int (*fn)(struct device *, void *));
+
+extern ssize_t iommu_dump_ctx(struct iommu *obj, char *buf);
+extern size_t dump_tlb_entries(struct iommu *obj, char *buf);
+
+#endif /* __MACH_IOMMU_H */
arch/arm/plat-omap/iommu.c new file +996 -0

996 lines not on this page · raw message

arch/arm/plat-omap/iopgtable.h new file +72 -0

72 lines not on this page · raw message

#1 lore raw

PATCH 2/7 omap iommu: omap2 architecture specific functions

The structure 'arch_mmu' accommodates the difference between omap1 and omap2/3.

This patch provides omap2/3 specific functions

---

 arch/arm/mach-omap2/iommu2.c             |  323 ++++++++++++++++++++++++++++++
 arch/arm/plat-omap/include/mach/iommu2.h |   96 +++++++++
 2 files changed, 419 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/mach-omap2/iommu2.c
 create mode 100644 arch/arm/plat-omap/include/mach/iommu2.h
arch/arm/mach-omap2/iommu2.c new file +323 -0
new file mode 100644
index 0000000..015f22a
@@ -0,0 +1,323 @@
+/*
+ * omap iommu: omap2/3 architecture specific functions
+ *
+ * Copyright (C) 2008-2009 Nokia Corporation
+ *
+ * Written by Hiroshi DOYU <[email protected]>,
+ *		Paul Mundt and Toshihiro Kobayashi
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/err.h>
+#include <linux/device.h>
+#include <linux/jiffies.h>
+#include <linux/module.h>
+#include <linux/stringify.h>
+
+#include <mach/iommu.h>
+
+/*
+ * omap2 architecture specific register bit definitions
+ */
+#define IOMMU_ARCH_VERSION	0x00000011
+
+/* SYSCONF */
+#define MMU_SYS_IDLE_SHIFT	3
+#define MMU_SYS_IDLE_FORCE	(0 << MMU_SYS_IDLE_SHIFT)
+#define MMU_SYS_IDLE_NONE	(1 << MMU_SYS_IDLE_SHIFT)
+#define MMU_SYS_IDLE_SMART	(2 << MMU_SYS_IDLE_SHIFT)
+#define MMU_SYS_IDLE_MASK	(3 << MMU_SYS_IDLE_SHIFT)
+
+#define MMU_SYS_SOFTRESET	(1 << 1)
+#define MMU_SYS_AUTOIDLE	1
+
+/* SYSSTATUS */
+#define MMU_SYS_RESETDONE	1
+
+/* IRQSTATUS & IRQENABLE */
+#define MMU_IRQ_MULTIHITFAULT	(1 << 4)
+#define MMU_IRQ_TABLEWALKFAULT	(1 << 3)
+#define MMU_IRQ_EMUMISS		(1 << 2)
+#define MMU_IRQ_TRANSLATIONFAULT	(1 << 1)
+#define MMU_IRQ_TLBMISS		(1 << 0)
+#define MMU_IRQ_MASK	\
+	(MMU_IRQ_MULTIHITFAULT | MMU_IRQ_TABLEWALKFAULT | MMU_IRQ_EMUMISS | \
+	 MMU_IRQ_TRANSLATIONFAULT)
+
+/* MMU_CNTL */
+#define MMU_CNTL_SHIFT		1
+#define MMU_CNTL_MASK		(7 << MMU_CNTL_SHIFT)
+#define MMU_CNTL_EML_TLB	(1 << 3)
+#define MMU_CNTL_TWL_EN		(1 << 2)
+#define MMU_CNTL_MMU_EN		(1 << 1)
+
+#define get_cam_va_mask(pgsz)				\
+	(((pgsz) == MMU_CAM_PGSZ_16M) ? 0xff000000 :	\
+	 ((pgsz) == MMU_CAM_PGSZ_1M)  ? 0xfff00000 :	\
+	 ((pgsz) == MMU_CAM_PGSZ_64K) ? 0xffff0000 :	\
+	 ((pgsz) == MMU_CAM_PGSZ_4K)  ? 0xfffff000 : 0)
+
+static int omap2_iommu_enable(struct iommu *obj)
+{
+	u32 l, pa;
+	unsigned long timeout;
+
+	if (!obj->iopgd || !IS_ALIGNED((u32)obj->iopgd,  SZ_16K))
+		return -EINVAL;
+
+	pa = virt_to_phys(obj->iopgd);
+	if (!IS_ALIGNED(pa, SZ_16K))
+		return -EINVAL;
+
+	iommu_write_reg(obj, MMU_SYS_SOFTRESET, MMU_SYSCONFIG);
+
+	timeout = jiffies + msecs_to_jiffies(20);
+	do {
+		l = iommu_read_reg(obj, MMU_SYSSTATUS);
+		if (l & MMU_SYS_RESETDONE)
+			break;
+	} while (time_after(jiffies, timeout));
+
+	if (!(l & MMU_SYS_RESETDONE)) {
+		dev_err(obj->dev, "can't take mmu out of reset\n");
+		return -ENODEV;
+	}
+
+	l = iommu_read_reg(obj, MMU_REVISION);
+	dev_info(obj->dev, "%s: version %d.%d\n", obj->name,
+		 (l >> 4) & 0xf, l & 0xf);
+
+	l = iommu_read_reg(obj, MMU_SYSCONFIG);
+	l &= ~MMU_SYS_IDLE_MASK;
+	l |= (MMU_SYS_IDLE_SMART | MMU_SYS_AUTOIDLE);
+	iommu_write_reg(obj, l, MMU_SYSCONFIG);
+
+	iommu_write_reg(obj, MMU_IRQ_MASK, MMU_IRQENABLE);
+	iommu_write_reg(obj, pa, MMU_TTB);
+
+	l = iommu_read_reg(obj, MMU_CNTL);
+	l &= ~MMU_CNTL_MASK;
+	l |= (MMU_CNTL_MMU_EN | MMU_CNTL_TWL_EN);
+	iommu_write_reg(obj, l, MMU_CNTL);
+
+	return 0;
+}
+
+static void omap2_iommu_disable(struct iommu *obj)
+{
+	u32 l = iommu_read_reg(obj, MMU_CNTL);
+
+	l &= ~MMU_CNTL_MASK;
+	iommu_write_reg(obj, l, MMU_CNTL);
+	iommu_write_reg(obj, MMU_SYS_IDLE_FORCE, MMU_SYSCONFIG);
+
+	dev_dbg(obj->dev, "%s is shutting down\n", obj->name);
+}
+
+static u32 omap2_iommu_fault_isr(struct iommu *obj, u32 *ra)
+{
+	int i;
+	u32 stat, da;
+	const char *err_msg[] =	{
+		"tlb miss",
+		"translation fault",
+		"emulation miss",
+		"table walk fault",
+		"multi hit fault",
+	};
+
+	stat = iommu_read_reg(obj, MMU_IRQSTATUS);
+	stat &= MMU_IRQ_MASK;
+	if (!stat)
+		return 0;
+
+	da = iommu_read_reg(obj, MMU_FAULT_AD);
+	*ra = da;
+
+	dev_err(obj->dev, "%s:\tda:%08x ", __func__, da);
+
+	for (i = 0; i < ARRAY_SIZE(err_msg); i++) {
+		if (stat & (1 << i))
+			printk("%s ", err_msg[i]);
+	}
+	printk("\n");
+
+	iommu_write_reg(obj, stat, MMU_IRQSTATUS);
+	return stat;
+}
+
+static void omap2_tlb_read_cr(struct iommu *obj, struct cr_regs *cr)
+{
+	cr->cam = iommu_read_reg(obj, MMU_READ_CAM);
+	cr->ram = iommu_read_reg(obj, MMU_READ_RAM);
+}
+
+static void omap2_tlb_load_cr(struct iommu *obj, struct cr_regs *cr)
+{
+	iommu_write_reg(obj, cr->cam | MMU_CAM_V, MMU_CAM);
+	iommu_write_reg(obj, cr->ram, MMU_RAM);
+}
+
+static u32 omap2_cr_to_virt(struct cr_regs *cr)
+{
+	u32 page_size = cr->cam & MMU_CAM_PGSZ_MASK;
+	u32 mask = get_cam_va_mask(cr->cam & page_size);
+
+	return cr->cam & mask;
+}
+
+static struct cr_regs *omap2_alloc_cr(struct iommu *obj, struct iotlb_entry *e)
+{
+	struct cr_regs *cr;
+
+	if (e->da & ~(get_cam_va_mask(e->pgsz))) {
+		dev_err(obj->dev, "%s:\twrong alignment: %08x\n", __func__,
+			e->da);
+		return ERR_PTR(-EINVAL);
+	}
+
+	cr = kmalloc(sizeof(*cr), GFP_KERNEL);
+	if (!cr)
+		return ERR_PTR(-ENOMEM);
+
+	cr->cam = (e->da & MMU_CAM_VATAG_MASK) | e->prsvd | e->pgsz;
+	cr->ram = e->pa | e->endian | e->elsz | e->mixed;
+
+	return cr;
+}
+
+static inline int omap2_cr_valid(struct cr_regs *cr)
+{
+	return cr->cam & MMU_CAM_V;
+}
+
+static u32 omap2_get_pte_attr(struct iotlb_entry *e)
+{
+	u32 attr;
+
+	attr = e->mixed << 5;
+	attr |= e->endian;
+	attr |= e->elsz >> 3;
+	attr <<= ((e->pgsz & MMU_CAM_PGSZ_4K) ? 0 : 6);
+
+	return attr;
+}
+
+static ssize_t omap2_dump_cr(struct iommu *obj, struct cr_regs *cr, char *buf)
+{
+	char *p = buf;
+
+	/* FIXME: Need more detail analysis of cam/ram */
+	p += sprintf(p, "%08x %08x\n", cr->cam, cr->ram);
+
+	return p - buf;
+}
+
+#define pr_reg(name)							\
+	p += sprintf(p, "%20s: %08x\n",					\
+		     __stringify(name), iommu_read_reg(obj, MMU_##name));
+
+static ssize_t omap2_iommu_dump_ctx(struct iommu *obj, char *buf)
+{
+	char *p = buf;
+
+	pr_reg(REVISION);
+	pr_reg(SYSCONFIG);
+	pr_reg(SYSSTATUS);
+	pr_reg(IRQSTATUS);
+	pr_reg(IRQENABLE);
+	pr_reg(WALKING_ST);
+	pr_reg(CNTL);
+	pr_reg(FAULT_AD);
+	pr_reg(TTB);
+	pr_reg(LOCK);
+	pr_reg(LD_TLB);
+	pr_reg(CAM);
+	pr_reg(RAM);
+	pr_reg(GFLUSH);
+	pr_reg(FLUSH_ENTRY);
+	pr_reg(READ_CAM);
+	pr_reg(READ_RAM);
+	pr_reg(EMU_FAULT_AD);
+
+	return p - buf;
+}
+
+static void omap2_iommu_save_ctx(struct iommu *obj)
+{
+	int i;
+	u32 *p = obj->ctx;
+
+	for (i = 0; i < (MMU_REG_SIZE / sizeof(u32)); i++) {
+		p[i] = iommu_read_reg(obj, i * sizeof(u32));
+		dev_dbg(obj->dev, "%s\t[%02d] %08x\n", __func__, i, p[i]);
+	}
+
+	BUG_ON(p[0] != IOMMU_ARCH_VERSION);
+}
+
+static void omap2_iommu_restore_ctx(struct iommu *obj)
+{
+	int i;
+	u32 *p = obj->ctx;
+
+	for (i = 0; i < (MMU_REG_SIZE / sizeof(u32)); i++) {
+		iommu_write_reg(obj, p[i], i * sizeof(u32));
+		dev_dbg(obj->dev, "%s\t[%02d] %08x\n", __func__, i, p[i]);
+	}
+
+	BUG_ON(p[0] != IOMMU_ARCH_VERSION);
+}
+
+static void omap2_cr_to_e(struct cr_regs *cr, struct iotlb_entry *e)
+{
+	e->da		= cr->cam & MMU_CAM_VATAG_MASK;
+	e->pa		= cr->ram & MMU_RAM_PADDR_MASK;
+	e->valid	= cr->cam & MMU_CAM_V;
+	e->pgsz		= cr->cam & MMU_CAM_PGSZ_MASK;
+	e->endian	= cr->ram & MMU_RAM_ENDIAN_MASK;
+	e->elsz		= cr->ram & MMU_RAM_ELSZ_MASK;
+	e->mixed	= cr->ram & MMU_RAM_MIXED;
+}
+
+static const struct iommu_functions omap2_iommu_ops = {
+	.version	= IOMMU_ARCH_VERSION,
+
+	.enable		= omap2_iommu_enable,
+	.disable	= omap2_iommu_disable,
+	.fault_isr	= omap2_iommu_fault_isr,
+
+	.tlb_read_cr	= omap2_tlb_read_cr,
+	.tlb_load_cr	= omap2_tlb_load_cr,
+
+	.cr_to_e	= omap2_cr_to_e,
+	.cr_to_virt	= omap2_cr_to_virt,
+	.alloc_cr	= omap2_alloc_cr,
+	.cr_valid	= omap2_cr_valid,
+	.dump_cr	= omap2_dump_cr,
+
+	.get_pte_attr	= omap2_get_pte_attr,
+
+	.save_ctx	= omap2_iommu_save_ctx,
+	.restore_ctx	= omap2_iommu_restore_ctx,
+	.dump_ctx	= omap2_iommu_dump_ctx,
+};
+
+static int __init omap2_iommu_init(void)
+{
+	return install_iommu_arch(&omap2_iommu_ops);
+}
+module_init(omap2_iommu_init);
+
+static void __exit omap2_iommu_exit(void)
+{
+	uninstall_iommu_arch(&omap2_iommu_ops);
+}
+module_exit(omap2_iommu_exit);
+
+MODULE_AUTHOR("Hiroshi DOYU, Paul Mundt and Toshihiro Kobayashi");
+MODULE_DESCRIPTION("omap iommu: omap2/3 architecture specific functions");
+MODULE_LICENSE("GPL v2");
arch/arm/plat-omap/include/mach/iommu2.h new file +96 -0

96 lines not on this page · raw message

#2 lore raw

PATCH 3/7 omap iommu: omap3 iommu device registration

In reply to Hiroshi DOYU

---

 arch/arm/mach-omap2/omap3-iommu.c |  103 +++++++++++++++++++++++++++++++++++++
 1 files changed, 103 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/mach-omap2/omap3-iommu.c
arch/arm/mach-omap2/omap3-iommu.c new file +103 -0
new file mode 100644
index 0000000..91ee38a
@@ -0,0 +1,103 @@
+/*
+ * omap iommu: omap3 device registration
+ *
+ * Copyright (C) 2008-2009 Nokia Corporation
+ *
+ * Written by Hiroshi DOYU <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/platform_device.h>
+
+#include <mach/iommu.h>
+
+#define OMAP3_MMU1_BASE	0x480bd400
+#define OMAP3_MMU2_BASE	0x5d000000
+#define OMAP3_MMU1_IRQ	24
+#define OMAP3_MMU2_IRQ	28
+
+
+static unsigned long iommu_base[] __initdata = {
+	OMAP3_MMU1_BASE,
+	OMAP3_MMU2_BASE,
+};
+
+static int iommu_irq[] __initdata = {
+	OMAP3_MMU1_IRQ,
+	OMAP3_MMU2_IRQ,
+};
+
+static const struct iommu_platform_data omap3_iommu_pdata[] __initconst = {
+	{
+		.name = "isp",
+		.nr_tlb_entries = 8,
+		.clk_name = "cam_ick",
+	},
+	{
+		.name = "iva2",
+		.nr_tlb_entries = 32,
+		.clk_name = "iva2_ck",
+	},
+};
+#define NR_IOMMU_DEVICES ARRAY_SIZE(omap3_iommu_pdata)
+
+static struct platform_device *omap3_iommu_pdev[NR_IOMMU_DEVICES];
+
+static int __init omap3_iommu_init(void)
+{
+	int i, err;
+
+	for (i = 0; i < NR_IOMMU_DEVICES; i++) {
+		struct platform_device *pdev;
+		struct resource res[2];
+
+		pdev = platform_device_alloc("omap-iommu", i);
+		if (!pdev) {
+			err = -ENOMEM;
+			goto err_out;
+		}
+
+		memset(res, 0,  sizeof(res));
+		res[0].start = iommu_base[i];
+		res[0].end = iommu_base[i] + MMU_REG_SIZE - 1;
+		res[0].flags = IORESOURCE_MEM;
+		res[1].start = res[1].end = iommu_irq[i];
+		res[1].flags = IORESOURCE_IRQ;
+
+		err = platform_device_add_resources(pdev, res,
+						    ARRAY_SIZE(res));
+		if (err)
+			goto err_out;
+		err = platform_device_add_data(pdev, &omap3_iommu_pdata[i],
+					       sizeof(omap3_iommu_pdata[0]));
+		if (err)
+			goto err_out;
+		err = platform_device_add(pdev);
+		if (err)
+			goto err_out;
+		omap3_iommu_pdev[i] = pdev;
+	}
+	return 0;
+
+err_out:
+	while (i--)
+		platform_device_put(omap3_iommu_pdev[i]);
+	return err;
+}
+module_init(omap3_iommu_init);
+
+static void __exit omap3_iommu_exit(void)
+{
+	int i;
+
+	for (i = 0; i < NR_IOMMU_DEVICES; i++)
+		platform_device_unregister(omap3_iommu_pdev[i]);
+}
+module_exit(omap3_iommu_exit);
+
+MODULE_AUTHOR("Hiroshi DOYU");
+MODULE_DESCRIPTION("omap iommu: omap3 device registration");
+MODULE_LICENSE("GPL v2");
#3 lore raw

PATCH 4/7 omap iommu: simple virtual address space management

In reply to Hiroshi DOYU

This patch provides a device drivers, which has a omap iommu, with address mapping APIs between device virtual address(iommu), physical address and MPU virtual address.

There are 4 possible patterns for iommu virtual address(iova/da) mapping.

    |iova/			  mapping		iommu_		page
    | da	pa	va	(d)-(p)-(v)		function	type
  ---------------------------------------------------------------------------
  1 | c		c	c	 1 - 1 - 1	  _kmap() / _kunmap()	s
  2 | c		c,a	c	 1 - 1 - 1	_kmalloc()/ _kfree()	s
  3 | c		d	c	 1 - n - 1	  _vmap() / _vunmap()	s
  4 | c		d,a	c	 1 - n - 1	_vmalloc()/ _vfree()	n*

'iova': device iommu virtual address
'da': alias of 'iova'
'pa': physical address
'va': mpu virtual address

'c': contiguous memory area
'd': dicontiguous memory area
'a': anonymous memory allocation
'()': optional feature

'n': a normal page(4KB) size is used.
's': multiple iommu superpage(16MB, 1MB, 64KB, 4KB) size is used.

'*': not yet, but feasible.

---

 arch/arm/include/asm/mach/map.h         |    8 
 arch/arm/mm/ioremap.c                   |    6 
 arch/arm/mm/mmu.c                       |    1 
 arch/arm/plat-omap/include/mach/iovmm.h |   94 +++
 arch/arm/plat-omap/iovmm.c              |  896 +++++++++++++++++++++++++++++++
 5 files changed, 1005 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/plat-omap/include/mach/iovmm.h
 create mode 100644 arch/arm/plat-omap/iovmm.c
arch/arm/include/asm/mach/map.h +8 -0
index 58cf91f..742c2aa 100644
@@ -30,6 +30,14 @@ struct map_desc {
 
 #ifdef CONFIG_MMU
 extern void iotable_init(struct map_desc *, int);
+
+struct mem_type;
+extern const struct mem_type *get_mem_type(unsigned int type);
+/*
+ * external interface to remap single page with appropriate type
+ */
+extern int ioremap_page(unsigned long virt, unsigned long phys,
+			const struct mem_type *mtype);
 #else
 #define iotable_init(map,num)	do { } while (0)
 #endif
arch/arm/mm/ioremap.c +6 -0
index 9f88dd3..0ab75c6 100644
@@ -110,6 +110,12 @@ static int remap_area_pages(unsigned long start, unsigned long pfn,
 	return err;
 }
 
+int ioremap_page(unsigned long virt, unsigned long phys,
+		 const struct mem_type *mtype)
+{
+	return remap_area_pages(virt, __phys_to_pfn(phys), PAGE_SIZE, mtype);
+}
+EXPORT_SYMBOL(ioremap_page);
 
 void __check_kvm_seq(struct mm_struct *mm)
 {
arch/arm/mm/mmu.c +1 -0
index e6344ec..70974d7 100644
@@ -255,6 +255,7 @@ const struct mem_type *get_mem_type(unsigned int type)
 {
 	return type < ARRAY_SIZE(mem_types) ? &mem_types[type] : NULL;
 }
+EXPORT_SYMBOL(get_mem_type);
 
 /*
  * Adjust the PMD section entries according to the CPU in use.
arch/arm/plat-omap/include/mach/iovmm.h new file +94 -0

94 lines not on this page · raw message

arch/arm/plat-omap/iovmm.c new file +896 -0

896 lines not on this page · raw message

#4 lore raw

PATCH 5/7 omap iommu: entries for Kconfig and Makefile

In reply to Hiroshi DOYU

---

 arch/arm/plat-omap/Kconfig  |    6 ++++++
 arch/arm/plat-omap/Makefile |    1 +
 2 files changed, 7 insertions(+), 0 deletions(-)
arch/arm/plat-omap/Kconfig +6 -0
index 9dd68fa..30e47a3 100644
@@ -115,6 +115,12 @@ config OMAP_MBOX_FWK
 	  Say Y here if you want to use OMAP Mailbox framework support for
 	  DSP, IVA1.0 and IVA2 in OMAP1/2/3.
 
+config OMAP_IOMMU
+	tristate "IOMMU support"
+	help
+	  Say Y here if you want to use OMAP IOMMU support for IVA2 and
+	  Camera in OMAP3.
+
 choice
         prompt "System timer"
 	default OMAP_MPU_TIMER
arch/arm/plat-omap/Makefile +1 -0
index 04a100c..a832795 100644
@@ -13,6 +13,7 @@ obj-  :=
 obj-$(CONFIG_ARCH_OMAP16XX) += ocpi.o
 
 obj-$(CONFIG_OMAP_MCBSP) += mcbsp.o
+obj-$(CONFIG_OMAP_IOMMU) += iommu.o iovmm.o
 
 obj-$(CONFIG_CPU_FREQ) += cpu-omap.o
 obj-$(CONFIG_OMAP_DM_TIMER) += dmtimer.o
#5 lore raw

Re: [PATCH 5/7] omap iommu: entries for Kconfig and Makefile

Quoted 15 lines · Hiroshi DOYU

---

 arch/arm/plat-omap/Kconfig  |    6 ++++++
 arch/arm/plat-omap/Makefile |    1 +

 2 files changed, 7 insertions(+), 0 deletions(-)
arch/arm/plat-omap/Kconfig +0 -0
index 9dd68fa..30e47a3 100644
@@ -115,6 +115,12 @@ config OMAP_MBOX_FWK

         Say Y here if you want to use OMAP Mailbox framework support for DSP, IVA1.0 and IVA2 in OMAP1/2/3.

Quoted 2 lines

+config OMAP_IOMMU
+       tristate "IOMMU support"

Should be:
+ tristate

As Russell suggested there's not point in letting users manually enable or disable it. It only makes sense when you use camera or dsp.

Quoted 25 lines

+       help
+         Say Y here if you want to use OMAP IOMMU support for IVA2 and
+         Camera in OMAP3.
+
 choice
        prompt "System timer"
       default OMAP_MPU_TIMER

arch/arm/plat-omap/Makefile +0 -0
index 04a100c..a832795 100644
@@ -13,6 +13,7 @@ obj-  :=

 obj-$(CONFIG_ARCH_OMAP16XX) += ocpi.o

 obj-$(CONFIG_OMAP_MCBSP) += mcbsp.o
+obj-$(CONFIG_OMAP_IOMMU) += iommu.o iovmm.o

 obj-$(CONFIG_CPU_FREQ) += cpu-omap.o
 obj-$(CONFIG_OMAP_DM_TIMER) += dmtimer.o

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Signature · 5 lines
Felipe Contreras
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#6 lore raw

PATCH 6/7 omap2 iommu: entries for Kconfig and Makefile

In reply to Hiroshi DOYU

---

 arch/arm/mach-omap2/Makefile |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
arch/arm/mach-omap2/Makefile +5 -0
index c49d9bf..88629a7 100644
@@ -28,6 +28,11 @@ endif
 obj-$(CONFIG_ARCH_OMAP2)		+= clock24xx.o
 obj-$(CONFIG_ARCH_OMAP3)		+= clock34xx.o
 
+iommu-y					+= iommu2.o
+iommu-$(CONFIG_ARCH_OMAP3)		+= omap3-iommu.o
+
+obj-$(CONFIG_OMAP_IOMMU)		+= $(iommu-y)
+
 # Specific board support
 obj-$(CONFIG_MACH_OMAP_GENERIC)		+= board-generic.o
 obj-$(CONFIG_MACH_OMAP_H4)		+= board-h4.o
#7 lore raw

PATCH 7/7 omap iommu: add MPU_BRIDGE_IOMMU for tidspbridge migration

In reply to Hiroshi DOYU

Currently "tidspbridge" driver uses its own mmu implementation and will migrate to use this "omap iommu" eventually. This config is provided to make this migration happen smoothly.

---

 arch/arm/mach-omap2/omap3-iommu.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
arch/arm/mach-omap2/omap3-iommu.c +2 -0
index 91ee38a..194189c 100644
@@ -36,11 +36,13 @@ static const struct iommu_platform_data omap3_iommu_pdata[] __initconst = {
 		.nr_tlb_entries = 8,
 		.clk_name = "cam_ick",
 	},
+#if defined(CONFIG_MPU_BRIDGE_IOMMU)
 	{
 		.name = "iva2",
 		.nr_tlb_entries = 32,
 		.clk_name = "iva2_ck",
 	},
+#endif
 };
 #define NR_IOMMU_DEVICES ARRAY_SIZE(omap3_iommu_pdata)
 
#8 lore raw
In reply to Hiroshi DOYU

Hi,

If there's no problem with those patches, please pull them from the following.

The following changes since commit 091438dd5668396328a3419abcbc6591159eb8d1:
Linus Torvalds (1):

        Linux 2.6.30-rc4

are available in the git repository at:

http://git.gitorious.org/lk/mainline.git iommu

Hiroshi DOYU (7):
omap iommu: tlb and pagetable primitives
omap iommu: omap2 architecture specific functions omap iommu: omap3 iommu device registration
omap iommu: simple virtual address space management omap iommu: entries for Kconfig and Makefile omap2 iommu: entries for Kconfig and Makefile omap iommu: add MPU_BRIDGE_IOMMU for tidspbridge migration

 arch/arm/include/asm/mach/map.h          |    8 +
 arch/arm/mach-omap2/Makefile             |    5 +
 arch/arm/mach-omap2/iommu2.c             |  323 ++++++++++
 arch/arm/mach-omap2/omap3-iommu.c        |  105 ++++
 arch/arm/mm/ioremap.c                    |    6 +
 arch/arm/mm/mmu.c                        |    1 +
 arch/arm/plat-omap/Kconfig               |    6 +
 arch/arm/plat-omap/Makefile              |    1 +
 arch/arm/plat-omap/include/mach/iommu.h  |  168 +++++
 arch/arm/plat-omap/include/mach/iommu2.h |   96 +++
 arch/arm/plat-omap/include/mach/iovmm.h  |   94 +++
 arch/arm/plat-omap/iommu.c               |  996 ++++++++++++++++++++++++++++++
 arch/arm/plat-omap/iopgtable.h           |   72 +++
 arch/arm/plat-omap/iovmm.c               |  896 +++++++++++++++++++++++++++
 14 files changed, 2777 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/mach-omap2/iommu2.c
 create mode 100644 arch/arm/mach-omap2/omap3-iommu.c
 create mode 100644 arch/arm/plat-omap/include/mach/iommu.h
 create mode 100644 arch/arm/plat-omap/include/mach/iommu2.h
 create mode 100644 arch/arm/plat-omap/include/mach/iovmm.h
 create mode 100644 arch/arm/plat-omap/iommu.c
 create mode 100644 arch/arm/plat-omap/iopgtable.h
 create mode 100644 arch/arm/plat-omap/iovmm.c
#9 lore raw

From: Hiroshi DOYU <[email protected]>
Subject: Re: [PATCH 1/7] omap iommu: tlb and pagetable primitives
Date: Wed, 20 May 2009 12:48:14 +0300 (EEST)

Quoted 11 lines

Hi,

If there's no problem with those patches, please pull them from the following.

The following changes since commit 091438dd5668396328a3419abcbc6591159eb8d1:
Linus Torvalds (1):

        Linux 2.6.30-rc4

are available in the git repository at:

http://git.gitorious.org/lk/mainline.git iommu

Russell, are you okay with this going into the patch system?

Kconfig patch is updated with your proposal.

maintainer
#10 lore raw
Quoted 12 lines · Hiroshi DOYU

From: Hiroshi DOYU <[email protected]>
Subject: Re: [PATCH 1/7] omap iommu: tlb and pagetable primitives
Date: Wed, 20 May 2009 12:48:14 +0300 (EEST)

Quoted 8 lines

Hi,

If there's no problem with those patches, please pull them from the following.

The following changes since commit 091438dd5668396328a3419abcbc6591159eb8d1:
Linus Torvalds (1):

        Linux 2.6.30-rc4
Quoted 5 lines
Quoted 3 lines

are available in the git repository at:

http://git.gitorious.org/lk/mainline.git iommu

Russell, are you okay with this going into the patch system?

I can also queue these to omap for-next once Russell is OK with them. Up to Russell as this series contains ARM generic changes too.

Quoted 1 line

Kconfig patch is updated with your proposal.

#11 lore raw
In reply to Hiroshi DOYU
Quoted 12 lines · Hiroshi DOYU

From: Hiroshi DOYU <[email protected]>
Subject: Re: [PATCH 1/7] omap iommu: tlb and pagetable primitives
Date: Wed, 20 May 2009 12:48:14 +0300 (EEST)

Quoted 8 lines

Hi,

If there's no problem with those patches, please pull them from the following.

The following changes since commit 091438dd5668396328a3419abcbc6591159eb8d1:
Linus Torvalds (1):

        Linux 2.6.30-rc4
Quoted 7 lines
Quoted 3 lines

are available in the git repository at:

http://git.gitorious.org/lk/mainline.git iommu

Russell, are you okay with this going into the patch system?

Kconfig patch is updated with your proposal.

Thanks, can I pull from a git url of the above?

#12 lore raw

From: ext Russell King - ARM Linux <[email protected]>
Subject: Re: [PATCH 1/7] omap iommu: tlb and pagetable primitives
Date: Mon, 25 May 2009 00:19:59 +0200

Quoted 15 lines · Hiroshi DOYU
Quoted 14 lines

From: Hiroshi DOYU <[email protected]>
Subject: Re: [PATCH 1/7] omap iommu: tlb and pagetable primitives
Date: Wed, 20 May 2009 12:48:14 +0300 (EEST)

Quoted 10 lines

Hi,

If there's no problem with those patches, please pull them from the following.

The following changes since commit 091438dd5668396328a3419abcbc6591159eb8d1:
Linus Torvalds (1):

        Linux 2.6.30-rc4

are available in the git repository at:

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

http://git.gitorious.org/lk/mainline.git iommu

Russell, are you okay with this going into the patch system?

Kconfig patch is updated with your proposal.

Thanks, can I pull from a git url of the above?

Yes, you can. Also it's mirrored on:

git://git.kernel.org/pub/scm/linux/kernel/git/tmlind/linux-omap-2.6.git iommu

#13 lore raw
Quoted 23 lines · Hiroshi DOYU

From: ext Russell King - ARM Linux <[email protected]>
Subject: Re: [PATCH 1/7] omap iommu: tlb and pagetable primitives
Date: Mon, 25 May 2009 00:19:59 +0200

Quoted 19 lines · Hiroshi DOYU
Quoted 18 lines

From: Hiroshi DOYU <[email protected]>
Subject: Re: [PATCH 1/7] omap iommu: tlb and pagetable primitives
Date: Wed, 20 May 2009 12:48:14 +0300 (EEST)

Quoted 11 lines

Hi,

If there's no problem with those patches, please pull them from the following.

The following changes since commit 091438dd5668396328a3419abcbc6591159eb8d1:
Linus Torvalds (1):

        Linux 2.6.30-rc4

are available in the git repository at:

http://git.gitorious.org/lk/mainline.git iommu

Russell, are you okay with this going into the patch system?

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Kconfig patch is updated with your proposal.

Thanks, can I pull from a git url of the above?

Yes, you can. Also it's mirrored on:

git://git.kernel.org/pub/scm/linux/kernel/git/tmlind/linux-omap-2.6.git iommu

Pulled. Doesn't gitorious.org have its own git URLs?

#14 lore raw

From: ext Russell King - ARM Linux <[email protected]>
Subject: Re: [PATCH 1/7] omap iommu: tlb and pagetable primitives
Date: Mon, 25 May 2009 11:21:12 +0200

Quoted 26 lines · Hiroshi DOYU
Quoted 25 lines

From: ext Russell King - ARM Linux <[email protected]>
Subject: Re: [PATCH 1/7] omap iommu: tlb and pagetable primitives
Date: Mon, 25 May 2009 00:19:59 +0200

Quoted 21 lines · Hiroshi DOYU
Quoted 19 lines

From: Hiroshi DOYU <[email protected]>
Subject: Re: [PATCH 1/7] omap iommu: tlb and pagetable primitives
Date: Wed, 20 May 2009 12:48:14 +0300 (EEST)

Quoted 11 lines

Hi,

If there's no problem with those patches, please pull them from the following.

The following changes since commit 091438dd5668396328a3419abcbc6591159eb8d1:
Linus Torvalds (1):

        Linux 2.6.30-rc4

are available in the git repository at:

http://git.gitorious.org/lk/mainline.git iommu

Russell, are you okay with this going into the patch system?

Kconfig patch is updated with your proposal.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Thanks, can I pull from a git url of the above?

Yes, you can. Also it's mirrored on:

git://git.kernel.org/pub/scm/linux/kernel/git/tmlind/linux-omap-2.6.git iommu

Pulled. Doesn't gitorious.org have its own git URLs?

Right, the gitorious has the git version url,

git://gitorious.org/lk/mainline.git iommu

I'll use the git one next time. Thanks.

#15 lore raw
Quoted 34 lines · Hiroshi DOYU

From: ext Russell King - ARM Linux <[email protected]>
Subject: Re: [PATCH 1/7] omap iommu: tlb and pagetable primitives
Date: Mon, 25 May 2009 11:21:12 +0200

Quoted 30 lines · Hiroshi DOYU
Quoted 29 lines

From: ext Russell King - ARM Linux <[email protected]>
Subject: Re: [PATCH 1/7] omap iommu: tlb and pagetable primitives
Date: Mon, 25 May 2009 00:19:59 +0200

Quoted 15 lines · Hiroshi DOYU
Quoted 14 lines

From: Hiroshi DOYU <[email protected]>
Subject: Re: [PATCH 1/7] omap iommu: tlb and pagetable primitives
Date: Wed, 20 May 2009 12:48:14 +0300 (EEST)

Quoted 10 lines

Hi,

If there's no problem with those patches, please pull them from the following.

The following changes since commit 091438dd5668396328a3419abcbc6591159eb8d1:
  Linus Torvalds (1):
        Linux 2.6.30-rc4

are available in the git repository at:

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

  http://git.gitorious.org/lk/mainline.git iommu

Russell, are you okay with this going into the patch system?

Kconfig patch is updated with your proposal.

Thanks, can I pull from a git url of the above?

Yes, you can. Also it's mirrored on:

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

git://git.kernel.org/pub/scm/linux/kernel/git/tmlind/linux-omap-2.6.git iommu

Pulled.  Doesn't gitorious.org have its own git URLs?

Right, the gitorious has the git version url,

      git://gitorious.org/lk/mainline.git iommu

How about having a project (in gitorious) for all our repos? I cloned the 'linux-omap/mainline' repo to my personal repo, maybe you can do the same? Or maybe we should create a new 'linux' project.

http://gitorious.org/linux-omap

Signature · 5 lines
Felipe Contreras
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#16 lore raw

From: ext Felipe Contreras <[email protected]>
Subject: Re: [PATCH 1/7] omap iommu: tlb and pagetable primitives
Date: Mon, 25 May 2009 11:36:03 +0200

Quoted 39 lines · Hiroshi DOYU
Quoted 38 lines

From: ext Russell King - ARM Linux <[email protected]>
Subject: Re: [PATCH 1/7] omap iommu: tlb and pagetable primitives
Date: Mon, 25 May 2009 11:21:12 +0200

Quoted 33 lines · Hiroshi DOYU
Quoted 23 lines

From: ext Russell King - ARM Linux <[email protected]>
Subject: Re: [PATCH 1/7] omap iommu: tlb and pagetable primitives
Date: Mon, 25 May 2009 00:19:59 +0200

Quoted 19 lines · Hiroshi DOYU
Quoted 18 lines

From: Hiroshi DOYU <[email protected]>
Subject: Re: [PATCH 1/7] omap iommu: tlb and pagetable primitives
Date: Wed, 20 May 2009 12:48:14 +0300 (EEST)

Quoted 11 lines

Hi,

If there's no problem with those patches, please pull them from the following.

The following changes since commit 091438dd5668396328a3419abcbc6591159eb8d1:
  Linus Torvalds (1):
        Linux 2.6.30-rc4

are available in the git repository at:

  http://git.gitorious.org/lk/mainline.git iommu

Russell, are you okay with this going into the patch system?

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Kconfig patch is updated with your proposal.

Thanks, can I pull from a git url of the above?

Yes, you can. Also it's mirrored on:

git://git.kernel.org/pub/scm/linux/kernel/git/tmlind/linux-omap-2.6.git iommu

Pulled.  Doesn't gitorious.org have its own git URLs?

Quoted 7 lines
Quoted 3 lines

Right, the gitorious has the git version url,

      git://gitorious.org/lk/mainline.git iommu

How about having a project (in gitorious) for all our repos? I cloned the 'linux-omap/mainline' repo to my personal repo, maybe you can do the same? Or maybe we should create a new 'linux' project.

Not bad idea generally, but just for kernel patches, I'd rather work more closely/directly with the mainline than keeping changes some git repositories locally for some time.

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html