Skip to contentSkip to conversation

Initial support for omap iommu driver

PATCH In review Hiroshi DOYU 6 participants 48 messages May 5, 2009 – May 19, 2009

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

cover Initial support for omap iommu driver

Some of TI OMAP series have the peripheral devices with their own Memory Management Unit(IOMMU), which is composed of its own TLB and optional H/W pagetable (TWL). These MMUs doesn't depend on MPU(ARM) MMU at all, but their algorithms are quite similar and they share the same physical address space. This patch provides with common in-kernel iommu APIs such OMAP peripheral devices(Camera ISP, IVA1, IVA2, DSP and the equivalent ones in the latest OMAP successors) to handle peripheral device IOMMUs in the same manner.

"tlb and pagetable primitives" has been updated with Russell's comments on:

      http://marc.info/?l=linux-omap&m=122087083712670&w=2

Generalizing this omap iommu code independently from each device drivers, "Camera(ISP)", "TI bridge(IVA/DSP)", "dspgateway(DSP)" and the future OMAP equivalent device would be more robust and reduce the maintenance cost since keeping this critical code at one place can avoid some risks, like wrong MMU settings, which may cause critical damages on the system.

---
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 (6):
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

 arch/arm/include/asm/io.h                |    6 +
 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                    |   11 +
 arch/arm/plat-omap/Kconfig               |    8 +
 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               |  890 ++++++++++++++++++++++++++
 13 files changed, 2775 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
#1 lore raw

PATCH 1/6 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

#2 lore raw

RE: [PATCH 1/6] omap iommu: tlb and pagetable primitives

Hi Doyu-san,

+static void iotlb_lock_set(struct iommu *obj, struct iotlb_lock *l) {
+ u32 val;
+
+ BUG_ON(l->base != 0); /* Currently no preservation is used */

-- Did you notice any issues in the IOMMU driver by enabling the preservation?

Bridge driver is locking the memory segment that is used for IPC in the TLB and by not having the preservation we might see a hit in the performance.

Thank you,
Best regards,
Hari

#3 lore raw

Re: [PATCH 1/6] omap iommu: tlb and pagetable primitives

Hi Hari,

From: "ext Kanigeri, Hari" <[email protected]>
Subject: RE: [PATCH 1/6] omap iommu: tlb and pagetable primitives
Date: Tue, 5 May 2009 22:19:55 +0200

Quoted 9 lines

Hi Doyu-san,

arch/arm/plat-omap/iommu.c new file +4 -1
+static void iotlb_lock_set(struct iommu *obj, struct iotlb_lock *l) {
+	u32 val;
+
+	BUG_ON(l->base != 0); /* Currently no preservation is used */
 
-- Did you notice any issues in the IOMMU driver by enabling the preservation? 
Quoted 3 lines

Bridge driver is locking the memory segment that is used for IPC in the TLB and by not having the preservation we might see a hit in the performance.

The current user of this driver is "camera isp" and no need for tlb preservation for it, but it's on todo list for other clients.

#4 lore raw

PATCH 2/6 omap iommu: omap2 architecture specific functions

In reply to Hiroshi DOYU

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

#5 lore raw

RE: [PATCH 2/6] omap iommu: omap2 architecture specific functions

Hi,

Quoted 22 lines
arch/arm/mach-omap2/iommu2.c new file +22 -0
+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);
+

arch/arm/mach-omap2/iommu2.c line 151

Quoted 10 lines
arch/arm/mach-omap2/iommu2.c new file +10 -0
+	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;
+}
+

-- I see you are acking the MMU fault in the ISR, but I don't think this will be enough to stop the further generation of MMU faults as the device will again try to access the same fault address.

In the mean time before the callback mechanism is implemented, we should consider disabling the MMU for the device that caused the MMU fault to stop further generation of MMU faults.

+ printk("\n");
+
+ iommu_write_reg(obj, stat, MMU_IRQSTATUS);
+ omap2_iommu_disable(obj) -----------------------> [HK]
+ return stat;
+}

Thank you,
Best regards,
Hari

#6 lore raw

Re: [PATCH 2/6] omap iommu: omap2 architecture specific functions

From: "ext Kanigeri, Hari" <[email protected]>
Subject: RE: [PATCH 2/6] omap iommu: omap2 architecture specific functions
Date: Wed, 6 May 2009 16:31:37 +0200

Quoted 30 lines

Hi,

Quoted 28 lines
arch/arm/mach-omap2/iommu2.c new file +28 -0
+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");
+
Quoted 8 lines

arch/arm/mach-omap2/iommu2.c line 151

Quoted 4 lines
arch/arm/mach-omap2/iommu2.c new file +4 -0
+	iommu_write_reg(obj, stat, MMU_IRQSTATUS);
+	return stat;
+}
+

-- I see you are acking the MMU fault in the ISR, but I don't think this will be enough to stop the further generation of MMU faults as the device will again try to access the same fault address.

My idea is that, an iommu fault should be handled by a client specific/provided callback function enough flexibly that it can handle more complecated use cases like implementing on-demand dynamic memory mapping at getting an iommu fault.

linux/arch/arm/plat-omap/iommu.c:

+static irqreturn_t iommu_fault_handler(int irq, void *data) +{

+       u32 stat, da;
+       u32 *iopgd, *iopte;
+       int err = -EIO;
+       struct iommu *obj = data;

+
+ if (!obj->refcount)
+ return IRQ_NONE;
+
+ /* Dynamic loading TLB or PTE */
+ if (obj->isr)

+               err = obj->isr(obj);
		      ^^^^^^^^^^^^^^

If the above "isr" function sets a new "tlb" or "pte" entry, then further iommu fault won't happen anymore.

arch/arm/mach-omap2/iommu2.c line 150

Quoted 11 lines

In the mean time before the callback mechanism is implemented, we should consider disabling the MMU for the device that caused the MMU fault to stop further generation of MMU faults.

arch/arm/mach-omap2/iommu2.c new file +6 -0
+	printk("\n");
+
+	iommu_write_reg(obj, stat, MMU_IRQSTATUS);
+	omap2_iommu_disable(obj) -----------------------> [HK]
+	return stat;
+}

It's not bad idea at all to disable iommu temporary as a default behavior, but maybe it should be done in the latter half of "iommu_fault_handler()".

Quoted 4 lines

Thank you,
Best regards,
Hari

#7 lore raw

RE: [PATCH 2/6] omap iommu: omap2 architecture specific functions

Hi,

Quoted 15 lines
(quoted diff) +13 -0
+static irqreturn_t iommu_fault_handler(int irq, void *data)
+{
+       u32 stat, da;
+       u32 *iopgd, *iopte;
+       int err = -EIO;
+       struct iommu *obj = data;
+
+       if (!obj->refcount)
+               return IRQ_NONE;
+
+       /* Dynamic loading TLB or PTE */
+       if (obj->isr)
+               err = obj->isr(obj);
		      ^^^^^^^^^^^^^^
Quoted 3 lines

If the above "isr" function sets a new "tlb" or "pte" entry, then further iommu fault won't happen anymore.

-- I think adding the new tlb entry or any other error recovery mechanism should be deferred to the registered callback function.

Thank you,
Best regards,
Hari

#8 lore raw

PATCH 3/6 omap iommu: omap3 iommu device registration

In reply to Hiroshi DOYU

---

 arch/arm/mach-omap2/omap3-iommu.c |  105 +++++++++++++++++++++++++++++++++++++
 1 files changed, 105 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/mach-omap2/omap3-iommu.c
arch/arm/mach-omap2/omap3-iommu.c new file +105 -0
new file mode 100644
index 0000000..367f36a
@@ -0,0 +1,105 @@
+/*
+ * 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 struct resource omap3_iommu_res[] = {
+	{ /* Camera ISP MMU */
+		.start		= OMAP3_MMU1_BASE,
+		.end		= OMAP3_MMU1_BASE + MMU_REG_SIZE - 1,
+		.flags		= IORESOURCE_MEM,
+	},
+	{
+		.start		= OMAP3_MMU1_IRQ,
+		.flags		= IORESOURCE_IRQ,
+	},
+	{ /* IVA2.2 MMU */
+		.start		= OMAP3_MMU2_BASE,
+		.end		= OMAP3_MMU2_BASE + MMU_REG_SIZE - 1,
+		.flags		= IORESOURCE_MEM,
+	},
+	{
+		.start		= OMAP3_MMU2_IRQ,
+		.flags		= IORESOURCE_IRQ,
+	},
+};
+#define NR_IOMMU_RES (ARRAY_SIZE(omap3_iommu_res) / 2)
+
+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;
+
+		pdev = platform_device_alloc("omap-iommu", i + 1);
+		if (!pdev) {
+			err = -ENOMEM;
+			goto err_out;
+		}
+		err = platform_device_add_resources(pdev,
+				    &omap3_iommu_res[2 * i], NR_IOMMU_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");
#9 lore raw

Re: [PATCH 3/6] omap iommu: omap3 iommu device registration

Quoted 44 lines · Hiroshi DOYU

---

 arch/arm/mach-omap2/omap3-iommu.c |  105 +++++++++++++++++++++++++++++++++++++

 1 files changed, 105 insertions(+), 0 deletions(-)

 create mode 100644 arch/arm/mach-omap2/omap3-iommu.c

arch/arm/mach-omap2/omap3-iommu.c new file +31 -0
new file mode 100644
index 0000000..367f36a
@@ -0,0 +1,105 @@
+/*
+ * 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 struct resource omap3_iommu_res[] = {
+       { /* Camera ISP MMU */
+               .start          = OMAP3_MMU1_BASE,
+               .end            = OMAP3_MMU1_BASE + MMU_REG_SIZE - 1,
+               .flags          = IORESOURCE_MEM,
+       },
+       {
+               .start          = OMAP3_MMU1_IRQ,
+               .flags          = IORESOURCE_IRQ,
+       },

arch/arm/mach-omap2/omap3-iommu.c line 41

Quoted 10 lines
arch/arm/mach-omap2/omap3-iommu.c new file +10 -0
+       { /* IVA2.2 MMU */
+               .start          = OMAP3_MMU2_BASE,
+               .end            = OMAP3_MMU2_BASE + MMU_REG_SIZE - 1,
+               .flags          = IORESOURCE_MEM,
+       },
+       {
+               .start          = OMAP3_MMU2_IRQ,
+               .flags          = IORESOURCE_IRQ,
+       },
+};

This will break TI's bridgedriver, right?

Can camera ISP and IVA request the registration of their respective IOMMU's from their codebase?

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
#10 lore raw

Re: [PATCH 3/6] omap iommu: omap3 iommu device registration

From: ext Felipe Contreras <[email protected]>
Subject: Re: [PATCH 3/6] omap iommu: omap3 iommu device registration
Date: Tue, 5 May 2009 21:32:34 +0200

Quoted 49 lines · Hiroshi DOYU
Quoted 48 lines

---

 arch/arm/mach-omap2/omap3-iommu.c |  105 +++++++++++++++++++++++++++++++++++++

 1 files changed, 105 insertions(+), 0 deletions(-)

 create mode 100644 arch/arm/mach-omap2/omap3-iommu.c

arch/arm/mach-omap2/omap3-iommu.c new file +35 -0
new file mode 100644
index 0000000..367f36a
@@ -0,0 +1,105 @@
+/*
+ * 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 struct resource omap3_iommu_res[] = {
+       { /* Camera ISP MMU */
+               .start          = OMAP3_MMU1_BASE,
+               .end            = OMAP3_MMU1_BASE + MMU_REG_SIZE - 1,
+               .flags          = IORESOURCE_MEM,
+       },
+       {
+               .start          = OMAP3_MMU1_IRQ,
+               .flags          = IORESOURCE_IRQ,
+       },
+       { /* IVA2.2 MMU */
+               .start          = OMAP3_MMU2_BASE,
+               .end            = OMAP3_MMU2_BASE + MMU_REG_SIZE - 1,
+               .flags          = IORESOURCE_MEM,
Quoted 8 lines

arch/arm/mach-omap2/omap3-iommu.c line 41

Quoted 6 lines
arch/arm/mach-omap2/omap3-iommu.c new file +6 -0
+       },
+       {
+               .start          = OMAP3_MMU2_IRQ,
+               .flags          = IORESOURCE_IRQ,
+       },
+};

This will break TI's bridgedriver, right?

Working around is easy, but let's go forward, correcting TI's bridgedriver;-)

http://marc.info/?l=linux-omap&m=124148814309478&w=2

Quoted 6 lines

Can camera ISP and IVA request the registration of their respective IOMMU's from their codebase?

Signature · 1 line
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

#11 lore raw

Re: [PATCH 3/6] omap iommu: omap3 iommu device registration

Quoted 62 lines · Hiroshi DOYU

From: ext Felipe Contreras <[email protected]>
Subject: Re: [PATCH 3/6] omap iommu: omap3 iommu device registration
Date: Tue, 5 May 2009 21:32:34 +0200

Quoted 49 lines · Hiroshi DOYU
Quoted 48 lines

---

 arch/arm/mach-omap2/omap3-iommu.c |  105 +++++++++++++++++++++++++++++++++++++

 1 files changed, 105 insertions(+), 0 deletions(-)

 create mode 100644 arch/arm/mach-omap2/omap3-iommu.c

arch/arm/mach-omap2/omap3-iommu.c new file +35 -0
new file mode 100644
index 0000000..367f36a
@@ -0,0 +1,105 @@
+/*
+ * 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 struct resource omap3_iommu_res[] = {
+       { /* Camera ISP MMU */
+               .start          = OMAP3_MMU1_BASE,
+               .end            = OMAP3_MMU1_BASE + MMU_REG_SIZE - 1,
+               .flags          = IORESOURCE_MEM,
+       },
+       {
+               .start          = OMAP3_MMU1_IRQ,
+               .flags          = IORESOURCE_IRQ,
+       },
+       { /* IVA2.2 MMU */
+               .start          = OMAP3_MMU2_BASE,
+               .end            = OMAP3_MMU2_BASE + MMU_REG_SIZE - 1,
+               .flags          = IORESOURCE_MEM,
Quoted 8 lines

arch/arm/mach-omap2/omap3-iommu.c line 41

Quoted 6 lines
arch/arm/mach-omap2/omap3-iommu.c new file +6 -0
+       },
+       {
+               .start          = OMAP3_MMU2_IRQ,
+               .flags          = IORESOURCE_IRQ,
+       },
+};

This will break TI's bridgedriver, right?

Quoted 3 lines

Working around is easy, but let's go forward, correcting TI's bridgedriver;-)

http://marc.info/?l=linux-omap&m=124148814309478&w=2

*sigh*

I can't recall how many times I've asked for this, I'm sending a patch series (RFC) that allows exactly what I want.

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
#12 lore raw

cover omap3-iommu: cleanups and remote registration

This patch series cleanups up a bit the opap3-iommu device registration and then allows registration from other parts of the code.

Currently the iva2 code (tidspbridge) is not using iommu, therefore it can't be used as-is with the current omap iommu. By allowing devies to be registered externaly (either isp, or iva2) this problem goes away.

Felipe Contreras (3):
omap3-iommu: reorganize
omap3-iommu: split init function into omap_iommu_add
omap3-iommu: remote registration

 arch/arm/mach-omap2/omap3-iommu.c       |  130 ++++++++++++++-----------------
 arch/arm/plat-omap/include/mach/iommu.h |    2 +
 2 files changed, 62 insertions(+), 70 deletions(-)
#13 lore raw

PATCH 1/3 omap3-iommu: reorganize

No functional changes.

---
 arch/arm/mach-omap2/omap3-iommu.c |   72 ++++++++++++++++++------------------
 1 files changed, 36 insertions(+), 36 deletions(-)
arch/arm/mach-omap2/omap3-iommu.c +36 -36
index 367f36a..f4232ec 100644
@@ -14,43 +14,31 @@
 
 #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 struct resource omap3_iommu_res[] = {
-	{ /* Camera ISP MMU */
-		.start		= OMAP3_MMU1_BASE,
-		.end		= OMAP3_MMU1_BASE + MMU_REG_SIZE - 1,
-		.flags		= IORESOURCE_MEM,
-	},
-	{
-		.start		= OMAP3_MMU1_IRQ,
-		.flags		= IORESOURCE_IRQ,
-	},
-	{ /* IVA2.2 MMU */
-		.start		= OMAP3_MMU2_BASE,
-		.end		= OMAP3_MMU2_BASE + MMU_REG_SIZE - 1,
-		.flags		= IORESOURCE_MEM,
-	},
-	{
-		.start		= OMAP3_MMU2_IRQ,
-		.flags		= IORESOURCE_IRQ,
-	},
+struct iommu_device {
+	resource_size_t base;
+	resource_size_t irq;
+	struct iommu_platform_data pdata;
+	struct resource res[2];
 };
-#define NR_IOMMU_RES (ARRAY_SIZE(omap3_iommu_res) / 2)
 
-static const struct iommu_platform_data omap3_iommu_pdata[] __initconst = {
+static struct iommu_device devices[] = {
 	{
-		.name = "isp",
-		.nr_tlb_entries = 8,
-		.clk_name = "cam_ick",
+		.base = 0x480bd400,
+		.irq = 24,
+		.pdata = {
+			.name = "isp",
+			.nr_tlb_entries = 8,
+			.clk_name = "cam_ick",
+		},
 	},
 	{
-		.name = "iva2",
-		.nr_tlb_entries = 32,
-		.clk_name = "iva2_ck",
+		.base = 0x5d000000,
+		.irq = 28,
+		.pdata = {
+			.name = "iva2",
+			.nr_tlb_entries = 32,
+			.clk_name = "iva2_ck",
+		},
 	},
 };
 #define NR_IOMMU_DEVICES ARRAY_SIZE(omap3_iommu_pdata)
@@ -63,23 +51,35 @@ static int __init omap3_iommu_init(void)
 
 	for (i = 0; i < NR_IOMMU_DEVICES; i++) {
 		struct platform_device *pdev;
+		const struct iommu_device *d = &devices[i];
+		struct resource res[] = {
+			{ .flags = IORESOURCE_MEM },
+			{ .flags = IORESOURCE_IRQ },
+		};
 
 		pdev = platform_device_alloc("omap-iommu", i + 1);
 		if (!pdev) {
 			err = -ENOMEM;
 			goto err_out;
 		}
-		err = platform_device_add_resources(pdev,
-				    &omap3_iommu_res[2 * i], NR_IOMMU_RES);
+
+		res[0].start = d->base;
+		res[0].end = d->base + MMU_REG_SIZE - 1;
+
+		res[1].start = d->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]));
+
+		err = platform_device_add_data(pdev, &d->pdata, sizeof(d->pdata));
 		if (err)
 			goto err_out;
+
 		err = platform_device_add(pdev);
 		if (err)
 			goto err_out;
+
 		omap3_iommu_pdev[i] = pdev;
 	}
 	return 0;
Signature · 1 line
1.6.3.GIT
#14 lore raw

PATCH 2/3 omap3-iommu: split init function into omap_iommu_add

In preparation for external registration.

---
 arch/arm/mach-omap2/omap3-iommu.c |   76 ++++++++++++++++++++++++-------------
 1 files changed, 49 insertions(+), 27 deletions(-)
arch/arm/mach-omap2/omap3-iommu.c +49 -27
index f4232ec..149c624 100644
@@ -45,43 +45,65 @@ static struct iommu_device devices[] = {
 
 static struct platform_device *omap3_iommu_pdev[NR_IOMMU_DEVICES];
 
-static int __init omap3_iommu_init(void)
+static struct platform_device *omap_iommu_add(const char *name)
 {
-	int i, err;
-
-	for (i = 0; i < NR_IOMMU_DEVICES; i++) {
-		struct platform_device *pdev;
-		const struct iommu_device *d = &devices[i];
-		struct resource res[] = {
-			{ .flags = IORESOURCE_MEM },
-			{ .flags = IORESOURCE_IRQ },
-		};
-
-		pdev = platform_device_alloc("omap-iommu", i + 1);
-		if (!pdev) {
-			err = -ENOMEM;
-			goto err_out;
+	struct platform_device *pdev;
+	const struct iommu_device *d = NULL;
+	struct resource res[] = {
+		{ .flags = IORESOURCE_MEM },
+		{ .flags = IORESOURCE_IRQ },
+	};
+	int err, i;
+
+	for (i = 0; i < ARRAY_SIZE(devices); i++)
+		if (strcmp(devices[i].pdata.name, name) == 0) {
+			d = &devices[i];
+			break;
 		}
 
-		res[0].start = d->base;
-		res[0].end = d->base + MMU_REG_SIZE - 1;
+	if (!d)
+		return NULL;
 
-		res[1].start = d->irq;
+	pdev = platform_device_alloc("omap-iommu", i + 1);
+	if (!pdev)
+		return NULL;
 
-		err = platform_device_add_resources(pdev, res, ARRAY_SIZE(res));
-		if (err)
-			goto err_out;
+	res[0].start = d->base;
+	res[0].end = d->base + MMU_REG_SIZE - 1;
 
-		err = platform_device_add_data(pdev, &d->pdata, sizeof(d->pdata));
-		if (err)
-			goto err_out;
+	res[1].start = d->irq;
 
-		err = platform_device_add(pdev);
-		if (err)
-			goto err_out;
+	err = platform_device_add_resources(pdev, res, ARRAY_SIZE(res));
+	if (err)
+		goto err_out;
+
+	err = platform_device_add_data(pdev, &d->pdata, sizeof(d->pdata));
+	if (err)
+		goto err_out;
+
+	err = platform_device_add(pdev);
+	if (err)
+		goto err_out;
+
+	return pdev;
 
+err_out:
+	platform_device_put(pdev);
+	return NULL;
+}
+
+static int __init omap3_iommu_init(void)
+{
+	struct platform_device *pdev;
+	int i, err;
+
+	for (i = 0; i < ARRAY_SIZE(devices); i++) {
+		pdev = omap_iommu_add(devices[i].pdata.name);
+		if (!pdev)
+			goto err_out;
 		omap3_iommu_pdev[i] = pdev;
 	}
+
 	return 0;
 
 err_out:
Signature · 1 line
1.6.3.GIT
#15 lore raw

PATCH 3/3 omap3-iommu: remote registration

---
 arch/arm/mach-omap2/omap3-iommu.c       |   36 +-----------------------------
 arch/arm/plat-omap/include/mach/iommu.h |    2 +
 2 files changed, 4 insertions(+), 34 deletions(-)
arch/arm/mach-omap2/omap3-iommu.c +2 -34
index 149c624..8380cd5 100644
@@ -41,11 +41,8 @@ static struct iommu_device devices[] = {
 		},
 	},
 };
-#define NR_IOMMU_DEVICES ARRAY_SIZE(omap3_iommu_pdata)
 
-static struct platform_device *omap3_iommu_pdev[NR_IOMMU_DEVICES];
-
-static struct platform_device *omap_iommu_add(const char *name)
+struct platform_device *omap_iommu_add(const char *name)
 {
 	struct platform_device *pdev;
 	const struct iommu_device *d = NULL;
@@ -91,36 +88,7 @@ err_out:
 	platform_device_put(pdev);
 	return NULL;
 }
-
-static int __init omap3_iommu_init(void)
-{
-	struct platform_device *pdev;
-	int i, err;
-
-	for (i = 0; i < ARRAY_SIZE(devices); i++) {
-		pdev = omap_iommu_add(devices[i].pdata.name);
-		if (!pdev)
-			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);
+EXPORT_SYMBOL_GPL(omap_iommu_add);
 
 MODULE_AUTHOR("Hiroshi DOYU");
 MODULE_DESCRIPTION("omap iommu: omap3 device registration");
arch/arm/plat-omap/include/mach/iommu.h +2 -0
index 769b00b..e22a4a4 100644
@@ -165,4 +165,6 @@ extern int foreach_iommu_device(void *data,
 extern ssize_t iommu_dump_ctx(struct iommu *obj, char *buf);
 extern size_t dump_tlb_entries(struct iommu *obj, char *buf);
 
+struct platform_device *omap_iommu_add(const char *name);
+
 #endif /* __MACH_IOMMU_H */
Signature · 1 line
1.6.3.GIT
#16 lore raw

Re: [RFC/PATCH 1/3] omap3-iommu: reorganize

In reply to Felipe Contreras
Quoted 9 lines · ext Felipe Contreras
arch/arm/mach-omap2/omap3-iommu.c +0 -9
-static struct resource omap3_iommu_res[] = {
-	{ /* Camera ISP MMU */
-		.start		= OMAP3_MMU1_BASE,
-		.end		= OMAP3_MMU1_BASE + MMU_REG_SIZE - 1,
-		.flags		= IORESOURCE_MEM,
-	},
-	{
-		.start		= OMAP3_MMU1_IRQ,
-		.flags		= IORESOURCE_IRQ,

arch/arm/mach-omap2/omap3-iommu.c line 40

Quoted 10 lines
arch/arm/mach-omap2/omap3-iommu.c +0 -10
-	},
-	{ /* IVA2.2 MMU */
-		.start		= OMAP3_MMU2_BASE,
-		.end		= OMAP3_MMU2_BASE + MMU_REG_SIZE - 1,
-		.flags		= IORESOURCE_MEM,
-	},
-	{
-		.start		= OMAP3_MMU2_IRQ,
-		.flags		= IORESOURCE_IRQ,
-	},

i find this one much more readable :-s

arch/arm/mach-omap2/omap3-iommu.c line 20

Quoted 4 lines
arch/arm/mach-omap2/omap3-iommu.c +4 -0
+struct iommu_device {
+	resource_size_t base;
+	resource_size_t irq;
+	struct iommu_platform_data pdata;

generally, platform_data is a void *. Don't know if it matters here.

Quoted 6 lines
arch/arm/mach-omap2/omap3-iommu.c +2 -2
+	struct resource res[2];
 };
-#define NR_IOMMU_RES (ARRAY_SIZE(omap3_iommu_res) / 2)
 
-static const struct iommu_platform_data omap3_iommu_pdata[] __initconst = {
+static struct iommu_device devices[] = {

arch/arm/mach-omap2/omap3-iommu.c line 31

Quoted 10 lines
arch/arm/mach-omap2/omap3-iommu.c +6 -3
 	{
-		.name = "isp",
-		.nr_tlb_entries = 8,
-		.clk_name = "cam_ick",
+		.base = 0x480bd400,
+		.irq = 24,
+		.pdata = {
+			.name = "isp",
+			.nr_tlb_entries = 8,
+			.clk_name = "cam_ick",

still passing clk names ? what about clkdev ?

Signature · 1 line
balbi
#17 lore raw

Re: [RFC/PATCH 1/3] omap3-iommu: reorganize

Quoted 21 lines · Felipe Balbi
Quoted 11 lines · ext Felipe Contreras

-static struct resource omap3_iommu_res[] = {
-     { /* Camera ISP MMU */
-             .start          = OMAP3_MMU1_BASE,
-             .end            = OMAP3_MMU1_BASE + MMU_REG_SIZE - 1,
-             .flags          = IORESOURCE_MEM,
-     },
-     {
-             .start          = OMAP3_MMU1_IRQ,
-             .flags          = IORESOURCE_IRQ,
-     },
-     { /* IVA2.2 MMU */

Quoted 8 lines

-             .start          = OMAP3_MMU2_BASE,
-             .end            = OMAP3_MMU2_BASE + MMU_REG_SIZE - 1,
-             .flags          = IORESOURCE_MEM,
-     },
-     {
-             .start          = OMAP3_MMU2_IRQ,
-             .flags          = IORESOURCE_IRQ,
-     },

Quoted 1 line

i find this one much more readable :-s

You find an array of 'struct resource' more readable than this?

+ .base = 0x480bd400,
+ .irq = 24,

+ .base = 0x5d000000,
+ .irq = 28,

+ res[0].start = d->base;
+ res[0].end = d->base + MMU_REG_SIZE - 1;
+
+ res[1].start = d->irq;

How would you calculate the number of resources per iommu device?

How about these?

- err = platform_device_add_resources(pdev,
- &omap3_iommu_res[2 * i], NR_IOMMU_RES);

+               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]));
+               err = platform_device_add_data(pdev, &d->pdata,
sizeof(d->pdata));
               if (err)
                       goto err_out;

Do you find the original version easier to read?

Quoted 6 lines
Quoted 4 lines

+struct iommu_device {
+     resource_size_t base;
+     resource_size_t irq;
+     struct iommu_platform_data pdata;

generally, platform_data is a void *. Don't know if it matters here.

Yes but we need to set the actual contents for platform_device_add_data.

Quoted 4 lines
Quoted 4 lines

+     struct resource res[2];
 };
-#define NR_IOMMU_RES (ARRAY_SIZE(omap3_iommu_res) / 2)

Quoted 14 lines
Quoted 4 lines
arch/arm/mach-omap2/omap3-iommu.c +1 -1
-static const struct iommu_platform_data omap3_iommu_pdata[] __initconst = {
+static struct iommu_device devices[] = {

      {
-             .name = "isp",

Quoted 8 lines

-             .nr_tlb_entries = 8,
-             .clk_name = "cam_ick",
+             .base = 0x480bd400,
+             .irq = 24,
+             .pdata = {
+                     .name = "isp",
+                     .nr_tlb_entries = 8,
+                     .clk_name = "cam_ick",

still passing clk names ? what about clkdev ?

That's for iommu to fix. I'm simply interested on decoupling iommu and a hypothetical tidspbridge that doesn't exists yet.

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
#18 lore raw

Re: [RFC/PATCH 1/3] omap3-iommu: reorganize

In reply to Felipe Balbi

From: "Balbi Felipe (Nokia-D/Helsinki)" <[email protected]>
Subject: Re: [RFC/PATCH 1/3] omap3-iommu: reorganize
Date: Thu, 7 May 2009 23:14:47 +0200

Quoted 34 lines · ext Felipe Contreras
Quoted 9 lines
arch/arm/mach-omap2/omap3-iommu.c +0 -9
-static struct resource omap3_iommu_res[] = {
-	{ /* Camera ISP MMU */
-		.start		= OMAP3_MMU1_BASE,
-		.end		= OMAP3_MMU1_BASE + MMU_REG_SIZE - 1,
-		.flags		= IORESOURCE_MEM,
-	},
-	{
-		.start		= OMAP3_MMU1_IRQ,
-		.flags		= IORESOURCE_IRQ,

arch/arm/mach-omap2/omap3-iommu.c line 40

Quoted 10 lines
arch/arm/mach-omap2/omap3-iommu.c +0 -10
-	},
-	{ /* IVA2.2 MMU */
-		.start		= OMAP3_MMU2_BASE,
-		.end		= OMAP3_MMU2_BASE + MMU_REG_SIZE - 1,
-		.flags		= IORESOURCE_MEM,
-	},
-	{
-		.start		= OMAP3_MMU2_IRQ,
-		.flags		= IORESOURCE_IRQ,
-	},

i find this one much more readable :-s

arch/arm/mach-omap2/omap3-iommu.c line 20

Quoted 4 lines
arch/arm/mach-omap2/omap3-iommu.c +4 -0
+struct iommu_device {
+	resource_size_t base;
+	resource_size_t irq;
+	struct iommu_platform_data pdata;

generally, platform_data is a void *. Don't know if it matters here.

Quoted 4 lines
arch/arm/mach-omap2/omap3-iommu.c +1 -1
+	struct resource res[2];
 };
-#define NR_IOMMU_RES (ARRAY_SIZE(omap3_iommu_res) / 2)
Quoted 14 lines

arch/arm/mach-omap2/omap3-iommu.c line 31

Quoted 12 lines
arch/arm/mach-omap2/omap3-iommu.c +7 -4
-static const struct iommu_platform_data omap3_iommu_pdata[] __initconst = {
+static struct iommu_device devices[] = {
 	{
-		.name = "isp",
-		.nr_tlb_entries = 8,
-		.clk_name = "cam_ick",
+		.base = 0x480bd400,
+		.irq = 24,
+		.pdata = {
+			.name = "isp",
+			.nr_tlb_entries = 8,
+			.clk_name = "cam_ick",

still passing clk names ? what about clkdev ?

Useful comment, I'll update mine;) thanks

#19 lore raw

RE: [RFC/PATCH 0/3] omap3-iommu: cleanups and remote registration

In reply to Felipe Contreras
Quoted 3 lines

Currently the iva2 code (tidspbridge) is not using iommu, therefore it can't be
used as-is with the current omap iommu.

Bridge can use IOMMU module that Hiroshi has sent by calling below 2 lines of code.

struct iommu *iva_iommu_ptr;
iva_iommu_ptr = iommu_get("iva2");

Thank you,
Best regards,
Hari

Quoted 32 lines

-----Original Message-----
From: [email protected] [mailto:linux-omap- [email protected]] On Behalf Of Felipe Contreras
Sent: Thursday, May 07, 2009 3:11 PM
To: [email protected]
Cc: Hiroshi DOYU; Felipe Contreras; Tony Lindgren; Felipe Contreras
Subject: [RFC/PATCH 0/3] omap3-iommu: cleanups and remote registration

This patch series cleanups up a bit the opap3-iommu device registration and
then allows registration from other parts of the code.

Currently the iva2 code (tidspbridge) is not using iommu, therefore it can't be
used as-is with the current omap iommu. By allowing devies to be registered
externaly (either isp, or iva2) this problem goes away.

Felipe Contreras (3):
omap3-iommu: reorganize
omap3-iommu: split init function into omap_iommu_add
omap3-iommu: remote registration

 arch/arm/mach-omap2/omap3-iommu.c       |  130 ++++++++++++++------------
-----
 arch/arm/plat-omap/include/mach/iommu.h |    2 +
 2 files changed, 62 insertions(+), 70 deletions(-)

--
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

#20 lore raw

Re: [RFC/PATCH 0/3] omap3-iommu: cleanups and remote registration

Quoted 10 lines · Hari
Quoted 3 lines

Currently the iva2 code (tidspbridge) is not using iommu, therefore it can't be
used as-is with the current omap iommu.

Bridge can use IOMMU module that Hiroshi has sent by calling below 2 lines of code.

struct iommu *iva_iommu_ptr;
iva_iommu_ptr = iommu_get("iva2");

From where? Care to send an actual patch?

Signature · 1 line
Felipe Contreras
#21 lore raw

RE: [RFC/PATCH 0/3] omap3-iommu: cleanups and remote registration

Quoted 14 lines

-----Original Message-----
From: Felipe Contreras [mailto:[email protected]]
Sent: Thursday, May 07, 2009 3:40 PM
To: Kanigeri, Hari
Cc: [email protected]; Hiroshi DOYU; Felipe Contreras; Tony Lindgren
Subject: Re: [RFC/PATCH 0/3] omap3-iommu: cleanups and remote registration

Quoted 4 lines · Hari
Quoted 3 lines

Currently the iva2 code (tidspbridge) is not using iommu, therefore it can't be
used as-is with the current omap iommu.

Quoted 8 lines
Quoted 1 line

Bridge can use IOMMU module that Hiroshi has sent by calling below 2

lines of code.

Quoted 3 lines

struct iommu *iva_iommu_ptr;
iva_iommu_ptr = iommu_get("iva2");

From where? Care to send an actual patch?

I think it is in the initial set of patches that Hiroshi has sent some time ago.

He provided the link to it in this first email [patch 0/6].
http://marc.info/?l=linux-omap&m=122087083712670&w=2

Thank you,
Best regards,
Hari

#22 lore raw

Re: [RFC/PATCH 0/3] omap3-iommu: cleanups and remote registration

In reply to Felipe Contreras

Hi Felipe,

From: ext Felipe Contreras <[email protected]>
Subject: [RFC/PATCH 0/3] omap3-iommu: cleanups and remote registration
Date: Thu, 7 May 2009 22:11:06 +0200

Quoted 2 lines

This patch series cleanups up a bit the opap3-iommu device registration and then allows registration from other parts of the code.

I think that this part of code is just a simple conventional platform_device registration and there may be no need to add more complexicity by introducing a new special structure/function just for a workaround of a client module("tidspbridge"). Also having these device registrations here and there doesn't look so nice, looking at other ones around kernel.

Quoted 3 lines

Currently the iva2 code (tidspbridge) is not using iommu, therefore it can't be used as-is with the current omap iommu. By allowing devies to be registered externaly (either isp, or iva2) this problem goes away.

Fixing tidspbridge itself is the way to go, and it seems that Hari has already verified this iommu with tidspbridge and he's pointed out some of missing features(*1). I hope that tidspbridge will start to use iommu soon.

*1: http://marc.info/?l=linux-omap&m=124148814309478&w=2

#23 lore raw

Re: [RFC/PATCH 0/3] omap3-iommu: cleanups and remote registration

Quoted 9 lines · Hiroshi DOYU

Hi Felipe,

From: ext Felipe Contreras <[email protected]>
Subject: [RFC/PATCH 0/3] omap3-iommu: cleanups and remote registration
Date: Thu, 7 May 2009 22:11:06 +0200

Quoted 2 lines

This patch series cleanups up a bit the opap3-iommu device registration and then allows registration from other parts of the code.

Quoted 6 lines

I think that this part of code is just a simple conventional platform_device registration and there may be no need to add more complexicity by introducing a new special structure/function just for a workaround of a client module("tidspbridge"). Also having these device registrations here and there doesn't look so nice, looking at other ones around kernel.

First of all, it's not a workaround. Fake dependencies are bad. iommu should not depend on isp or iva2 (or how they are implemented), it's the other way around.

Let's say you disable isp, do you want iommu to add the isp iommu device (same for iva2)? What happens if you don't want either isp or iva2 in the kernel, what is the point of having iommu?

Second, it's not introducing any new structure, the structure is internal, you can remove it if you want and implement the same with a select or any way you want, I just thought an internal structure was easier to follow.

And third, this kind of device registration is used all over the place, look at:
omap_mmc_add
pxa2xx_set_spi_info
at32_add_device_psif
at32_add_device_twi
at32_add_device_mci
at32_add_device_pwm
at32_add_device_usba
at32_add_device_ide
at32_add_device_cf
at32_add_device_nand
at32_add_device_ac97c
at32_add_device_abdac
txx9_ethaddr_init
txx9_physmap_flash_init
txx9_iocled_init
mv64x60_mpsc_device_setup
mv64x60_eth_device_setup
mv64x60_i2c_device_setup
mv64x60_wdt_device_setup
ipmi_bmc_register
aem_init_aem1_inst
aem_init_aem2_inst
w1_ds2760_add_slave
of_snd_soc_register_device

Quoted 8 lines
Quoted 3 lines

Currently the iva2 code (tidspbridge) is not using iommu, therefore it can't be used as-is with the current omap iommu. By allowing devies to be registered externaly (either isp, or iva2) this problem goes away.

Fixing tidspbridge itself is the way to go, and it seems that Hari has already verified this iommu with tidspbridge and he's pointed out some of missing features(*1). I hope that tidspbridge will start to use iommu soon.

Yes, definitely, but that's not an excuse not to make iommu more extensible. With my patch the iommu can be merged as is and would not *require* any change in tidspbridge. When the tidspbridge is ready, it would be a matter of adding one line.

Also, it's better to have independent branches. It would be ugly to modify iommu code from the tidspbridge branch depending on whether or not the migration to iommu have happened.

And finally, suppose you load the bridgedriver on-demand, with my patch the iva2 iommu device will be created *only* when the bridgedriver is loaded, and when the bridgedriver itself is unloaded it can remove the iva2 iommu device. So essentially we'll have only the iommu devices that we really need.

Now I ask the question the other way around, what do we loose if we apply these patches?

Signature · 1 line
Felipe Contreras
#24 lore raw

Re: [PATCH 3/6] omap iommu: omap3 iommu device registration

In reply to Hiroshi DOYU
Quoted 45 lines · Hiroshi DOYU

---

 arch/arm/mach-omap2/omap3-iommu.c |  105 +++++++++++++++++++++++++++++++++++++

 1 files changed, 105 insertions(+), 0 deletions(-)

 create mode 100644 arch/arm/mach-omap2/omap3-iommu.c

arch/arm/mach-omap2/omap3-iommu.c new file +32 -0
new file mode 100644
index 0000000..367f36a
@@ -0,0 +1,105 @@
+/*
+ * 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 struct resource omap3_iommu_res[] = {
+       { /* Camera ISP MMU */
+               .start          = OMAP3_MMU1_BASE,
+               .end            = OMAP3_MMU1_BASE + MMU_REG_SIZE - 1,
+               .flags          = IORESOURCE_MEM,
+       },
+       {
+               .start          = OMAP3_MMU1_IRQ,
+               .flags          = IORESOURCE_IRQ,
+       },
+       { /* IVA2.2 MMU */

arch/arm/mach-omap2/omap3-iommu.c line 42

Quoted 10 lines
arch/arm/mach-omap2/omap3-iommu.c new file +10 -0
+               .start          = OMAP3_MMU2_BASE,
+               .end            = OMAP3_MMU2_BASE + MMU_REG_SIZE - 1,
+               .flags          = IORESOURCE_MEM,
+       },
+       {
+               .start          = OMAP3_MMU2_IRQ,
+               .flags          = IORESOURCE_IRQ,
+       },
+};
+#define NR_IOMMU_RES (ARRAY_SIZE(omap3_iommu_res) / 2)

<snip/>

arch/arm/mach-omap2/omap3-iommu.c line 73

Quoted 2 lines
arch/arm/mach-omap2/omap3-iommu.c new file +2 -0
+               err = platform_device_add_resources(pdev,
+                                   &omap3_iommu_res[2 * i], NR_IOMMU_RES);

This is wrong. In this particular case NR_IOMMU_RES is 2, but not because there's 2 resources: MEM and IRQ, but because there's 2 iommu
devices: isp and iva2.

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
#25 lore raw

Re: [PATCH 3/6] omap iommu: omap3 iommu device registration

Hi Felipe,

From: ext Felipe Contreras <[email protected]>
Subject: Re: [PATCH 3/6] omap iommu: omap3 iommu device registration
Date: Thu, 7 May 2009 22:05:00 +0200

Quoted 59 lines · Hiroshi DOYU
Quoted 45 lines

---

 arch/arm/mach-omap2/omap3-iommu.c |  105 +++++++++++++++++++++++++++++++++++++

 1 files changed, 105 insertions(+), 0 deletions(-)

 create mode 100644 arch/arm/mach-omap2/omap3-iommu.c

arch/arm/mach-omap2/omap3-iommu.c new file +32 -0
new file mode 100644
index 0000000..367f36a
@@ -0,0 +1,105 @@
+/*
+ * 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 struct resource omap3_iommu_res[] = {
+       { /* Camera ISP MMU */
+               .start          = OMAP3_MMU1_BASE,
+               .end            = OMAP3_MMU1_BASE + MMU_REG_SIZE - 1,
+               .flags          = IORESOURCE_MEM,
+       },
+       {
+               .start          = OMAP3_MMU1_IRQ,
+               .flags          = IORESOURCE_IRQ,
+       },
+       { /* IVA2.2 MMU */

arch/arm/mach-omap2/omap3-iommu.c line 42

Quoted 10 lines
arch/arm/mach-omap2/omap3-iommu.c new file +10 -0
+               .start          = OMAP3_MMU2_BASE,
+               .end            = OMAP3_MMU2_BASE + MMU_REG_SIZE - 1,
+               .flags          = IORESOURCE_MEM,
+       },
+       {
+               .start          = OMAP3_MMU2_IRQ,
+               .flags          = IORESOURCE_IRQ,
+       },
+};
+#define NR_IOMMU_RES (ARRAY_SIZE(omap3_iommu_res) / 2)

<snip/>

Quoted 6 lines

arch/arm/mach-omap2/omap3-iommu.c line 73

Quoted 2 lines
arch/arm/mach-omap2/omap3-iommu.c new file +2 -0
+               err = platform_device_add_resources(pdev,
+                                   &omap3_iommu_res[2 * i], NR_IOMMU_RES);

This is wrong. In this particular case NR_IOMMU_RES is 2, but not because there's 2 resources: MEM and IRQ, but because there's 2 iommu
devices: isp and iva2.

Does the following make sense?

+#define NR_IOMMU_RES 2

....

+               err = platform_device_add_resources(pdev,
+                                   omap3_iommu_res + i * NR_IOMMU_RES, NR_IOMMU_RES); --
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

#26 lore raw

Re: [PATCH 3/6] omap iommu: omap3 iommu device registration

Quoted 72 lines · Hiroshi DOYU

Hi Felipe,

From: ext Felipe Contreras <[email protected]>
Subject: Re: [PATCH 3/6] omap iommu: omap3 iommu device registration
Date: Thu, 7 May 2009 22:05:00 +0200

Quoted 59 lines · Hiroshi DOYU
Quoted 45 lines

---

 arch/arm/mach-omap2/omap3-iommu.c |  105 +++++++++++++++++++++++++++++++++++++

 1 files changed, 105 insertions(+), 0 deletions(-)

 create mode 100644 arch/arm/mach-omap2/omap3-iommu.c

arch/arm/mach-omap2/omap3-iommu.c new file +32 -0
new file mode 100644
index 0000000..367f36a
@@ -0,0 +1,105 @@
+/*
+ * 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 struct resource omap3_iommu_res[] = {
+       { /* Camera ISP MMU */
+               .start          = OMAP3_MMU1_BASE,
+               .end            = OMAP3_MMU1_BASE + MMU_REG_SIZE - 1,
+               .flags          = IORESOURCE_MEM,
+       },
+       {
+               .start          = OMAP3_MMU1_IRQ,
+               .flags          = IORESOURCE_IRQ,
+       },
+       { /* IVA2.2 MMU */

arch/arm/mach-omap2/omap3-iommu.c line 42

Quoted 10 lines
arch/arm/mach-omap2/omap3-iommu.c new file +10 -0
+               .start          = OMAP3_MMU2_BASE,
+               .end            = OMAP3_MMU2_BASE + MMU_REG_SIZE - 1,
+               .flags          = IORESOURCE_MEM,
+       },
+       {
+               .start          = OMAP3_MMU2_IRQ,
+               .flags          = IORESOURCE_IRQ,
+       },
+};
+#define NR_IOMMU_RES (ARRAY_SIZE(omap3_iommu_res) / 2)

<snip/>

Quoted 6 lines

arch/arm/mach-omap2/omap3-iommu.c line 73

Quoted 2 lines
arch/arm/mach-omap2/omap3-iommu.c new file +2 -0
+               err = platform_device_add_resources(pdev,
+                                   &omap3_iommu_res[2 * i], NR_IOMMU_RES);

This is wrong. In this particular case NR_IOMMU_RES is 2, but not because there's 2 resources: MEM and IRQ, but because there's 2 iommu
devices: isp and iva2.

Quoted 8 lines

Does the following make sense?

+#define NR_IOMMU_RES 2

....

+               err = platform_device_add_resources(pdev,
+                                   omap3_iommu_res +  i * NR_IOMMU_RES, NR_IOMMU_RES);

Yeap, also:

Quoted 1 line

+ err = platform_device_add_resources(pdev, omap3_iommu_res + i * 2, 2);

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
#27 lore raw

RE: [PATCH 3/6] omap iommu: omap3 iommu device registration

Hi,

Just one comment below:

Quoted 6 lines
Quoted 6 lines

Does the following make sense?

+#define NR_IOMMU_RES 2

....

Quoted 8 lines
Quoted 2 lines

+               err = platform_device_add_resources(pdev,
+                                   omap3_iommu_res +  i * NR_IOMMU_RES,

NR_IOMMU_RES);

Yeap, also:

Quoted 1 line

+ err = platform_device_add_resources(pdev,

omap3_iommu_res + i * 2, 2);

IMHO, I don't think it's a good idea to add magical numbers to any code in the kernel. Why is it better to NOT use a define?

Regards,
Sergio
--
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

#28 lore raw

Re: [PATCH 3/6] omap iommu: omap3 iommu device registration

Quoted 12 lines · Sergio Alberto

Hi,

Just one comment below:

Quoted 8 lines
Quoted 8 lines

Does the following make sense?

+#define NR_IOMMU_RES 2

....

+               err = platform_device_add_resources(pdev,
+                                   omap3_iommu_res +  i * NR_IOMMU_RES,

Quoted 8 lines
Quoted 6 lines

NR_IOMMU_RES);

Yeap, also:

Quoted 1 line

+               err = platform_device_add_resources(pdev,

omap3_iommu_res +  i * 2, 2);

IMHO, I don't think it's a good idea to add magical numbers to any code in the kernel. Why is it better to NOT use a define?

I agree, but even a define is not good enough. For example you can update the array without updating the define.

A better solution is to do what I did on my follow up patch series:

+ struct resource res[] = {
+ { .flags = IORESOURCE_MEM },
+ { .flags = IORESOURCE_IRQ },
+ };

+ err = platform_device_add_resources(pdev, res, ARRAY_SIZE(res));

No need for a define, and as soon as the array is updated so will the second argument sent to platform_device_add_resources.

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
#29 lore raw

Re: [PATCH 3/6] omap iommu: omap3 iommu device registration

In reply to Hiroshi DOYU
Quoted 11 lines · Hiroshi DOYU
arch/arm/mach-omap2/omap3-iommu.c new file +11 -0
+static struct resource omap3_iommu_res[] = {
+	{ /* Camera ISP MMU */
+		.start		= OMAP3_MMU1_BASE,
+		.end		= OMAP3_MMU1_BASE + MMU_REG_SIZE - 1,
+		.flags		= IORESOURCE_MEM,
+	},
+	{
+		.start		= OMAP3_MMU1_IRQ,
+		.flags		= IORESOURCE_IRQ,
+	},
+	{ /* IVA2.2 MMU */

arch/arm/mach-omap2/omap3-iommu.c line 42

Quoted 10 lines
arch/arm/mach-omap2/omap3-iommu.c new file +10 -0
+		.start		= OMAP3_MMU2_BASE,
+		.end		= OMAP3_MMU2_BASE + MMU_REG_SIZE - 1,
+		.flags		= IORESOURCE_MEM,
+	},
+	{
+		.start		= OMAP3_MMU2_IRQ,
+		.flags		= IORESOURCE_IRQ,
+	},
+};
+#define NR_IOMMU_RES (ARRAY_SIZE(omap3_iommu_res) / 2)

This looks all very convoluted. Why not do something like:

static unsigned long iommu_base[] = {
	OMAP3_MMU1_BASE,
	OMAP3_MMU2_BASE,
};
static int iommu_irq[] = {
	OMAP3_MMU1_IRQ,
	OMAP3_MMU2_IRQ,
};

arch/arm/mach-omap2/omap3-iommu.c line 67

Quoted 10 lines
arch/arm/mach-omap2/omap3-iommu.c new file +10 -0
+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;
+
+		pdev = platform_device_alloc("omap-iommu", i + 1);

Why number them 1 and up when zero is perfectly fine?

arch/arm/mach-omap2/omap3-iommu.c line 73

Quoted 6 lines
arch/arm/mach-omap2/omap3-iommu.c new file +6 -0
+		if (!pdev) {
+			err = -ENOMEM;
+			goto err_out;
+		}
+		err = platform_device_add_resources(pdev,
+				    &omap3_iommu_res[2 * i], NR_IOMMU_RES);
		struct resource res[2];

		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));

There's no need to keep 'res' around since it's copied by add_resources.

Quoted 38 lines
arch/arm/mach-omap2/omap3-iommu.c new file +32 -1
+		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");
 
 
-------------------------------------------------------------------
List admin: http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm-kernel
FAQ:        http://www.arm.linux.org.uk/mailinglists/faq.php
Etiquette:  http://www.arm.linux.org.uk/mailinglists/etiquette.php
#30 lore raw

Re: [PATCH 3/6] omap iommu: omap3 iommu device registration

Quoted 30 lines · Russell King - ARM Linux
Quoted 11 lines · Hiroshi DOYU
arch/arm/mach-omap2/omap3-iommu.c new file +11 -0
+static struct resource omap3_iommu_res[] = {
+     { /* Camera ISP MMU */
+             .start          = OMAP3_MMU1_BASE,
+             .end            = OMAP3_MMU1_BASE + MMU_REG_SIZE - 1,
+             .flags          = IORESOURCE_MEM,
+     },
+     {
+             .start          = OMAP3_MMU1_IRQ,
+             .flags          = IORESOURCE_IRQ,
+     },
+     { /* IVA2.2 MMU */

arch/arm/mach-omap2/omap3-iommu.c line 42

Quoted 10 lines
arch/arm/mach-omap2/omap3-iommu.c new file +10 -0
+             .start          = OMAP3_MMU2_BASE,
+             .end            = OMAP3_MMU2_BASE + MMU_REG_SIZE - 1,
+             .flags          = IORESOURCE_MEM,
+     },
+     {
+             .start          = OMAP3_MMU2_IRQ,
+             .flags          = IORESOURCE_IRQ,
+     },
+};
+#define NR_IOMMU_RES (ARRAY_SIZE(omap3_iommu_res) / 2)

This looks all very convoluted.  Why not do something like:

static unsigned long iommu_base[] = {
       OMAP3_MMU1_BASE,
       OMAP3_MMU2_BASE,
};

Quoted 4 lines

static int iommu_irq[] = {
       OMAP3_MMU1_IRQ,
       OMAP3_MMU2_IRQ,
};

All your comments are pretty similar to my reorganize patch:
http://marc.info/?l=linux-omap&m=124172711303076&w=2

Signature · 1 line
Felipe Contreras
#31 lore raw

Re: [PATCH 3/6] omap iommu: omap3 iommu device registration

Quoted 32 lines · Felipe Contreras
Quoted 30 lines · Russell King - ARM Linux
Quoted 11 lines · Hiroshi DOYU
arch/arm/mach-omap2/omap3-iommu.c new file +11 -0
+static struct resource omap3_iommu_res[] = {
+     { /* Camera ISP MMU */
+             .start          = OMAP3_MMU1_BASE,
+             .end            = OMAP3_MMU1_BASE + MMU_REG_SIZE - 1,
+             .flags          = IORESOURCE_MEM,
+     },
+     {
+             .start          = OMAP3_MMU1_IRQ,
+             .flags          = IORESOURCE_IRQ,
+     },
+     { /* IVA2.2 MMU */

arch/arm/mach-omap2/omap3-iommu.c line 42

Quoted 10 lines
arch/arm/mach-omap2/omap3-iommu.c new file +10 -0
+             .start          = OMAP3_MMU2_BASE,
+             .end            = OMAP3_MMU2_BASE + MMU_REG_SIZE - 1,
+             .flags          = IORESOURCE_MEM,
+     },
+     {
+             .start          = OMAP3_MMU2_IRQ,
+             .flags          = IORESOURCE_IRQ,
+     },
+};
+#define NR_IOMMU_RES (ARRAY_SIZE(omap3_iommu_res) / 2)

This looks all very convoluted.  Why not do something like:

static unsigned long iommu_base[] = {
       OMAP3_MMU1_BASE,
       OMAP3_MMU2_BASE,
};

Quoted 7 lines
Quoted 4 lines

static int iommu_irq[] = {
       OMAP3_MMU1_IRQ,
       OMAP3_MMU2_IRQ,
};

All your comments are pretty similar to my reorganize patch:
http://marc.info/?l=linux-omap&m=124172711303076&w=2

... which hasn't been posted to linux-arm-kernel, and so I won't see it. --
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

#32 lore raw

Re: [PATCH 3/6] omap iommu: omap3 iommu device registration

Quoted 38 lines · Russell King - ARM Linux
Quoted 37 lines · Felipe Contreras
Quoted 34 lines · Russell King - ARM Linux
Quoted 11 lines · Hiroshi DOYU
arch/arm/mach-omap2/omap3-iommu.c new file +11 -0
+static struct resource omap3_iommu_res[] = {
+     { /* Camera ISP MMU */
+             .start          = OMAP3_MMU1_BASE,
+             .end            = OMAP3_MMU1_BASE + MMU_REG_SIZE - 1,
+             .flags          = IORESOURCE_MEM,
+     },
+     {
+             .start          = OMAP3_MMU1_IRQ,
+             .flags          = IORESOURCE_IRQ,
+     },
+     { /* IVA2.2 MMU */

arch/arm/mach-omap2/omap3-iommu.c line 42

Quoted 10 lines
arch/arm/mach-omap2/omap3-iommu.c new file +10 -0
+             .start          = OMAP3_MMU2_BASE,
+             .end            = OMAP3_MMU2_BASE + MMU_REG_SIZE - 1,
+             .flags          = IORESOURCE_MEM,
+     },
+     {
+             .start          = OMAP3_MMU2_IRQ,
+             .flags          = IORESOURCE_IRQ,
+     },
+};
+#define NR_IOMMU_RES (ARRAY_SIZE(omap3_iommu_res) / 2)

This looks all very convoluted.  Why not do something like:

static unsigned long iommu_base[] = {
       OMAP3_MMU1_BASE,
       OMAP3_MMU2_BASE,
};

static int iommu_irq[] = {
       OMAP3_MMU1_IRQ,
       OMAP3_MMU2_IRQ,
};

Quoted 4 lines
Quoted 2 lines

All your comments are pretty similar to my reorganize patch:
http://marc.info/?l=linux-omap&m=124172711303076&w=2

... which hasn't been posted to linux-arm-kernel, and so I won't see it.

You are not subscribed to linux-omap? I wasn't subscribed to linux-arm-kernel at that point, I'll resend to there.

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
#33 lore raw

Re: [PATCH 3/6] omap iommu: omap3 iommu device registration

In reply to Russell King - ARM Linux
Quoted 11 lines · Russell King - ARM Linux

This looks all very convoluted. Why not do something like:

static unsigned long iommu_base[] = {
	OMAP3_MMU1_BASE,
	OMAP3_MMU2_BASE,
};
static int iommu_irq[] = {
	OMAP3_MMU1_IRQ,
	OMAP3_MMU2_IRQ,
};

BTW, both of these can be __initdata.

#34 lore raw

Re: [PATCH 3/6] omap iommu: omap3 iommu device registration

From: ext Russell King - ARM Linux <[email protected]>
Subject: Re: [PATCH 3/6] omap iommu: omap3 iommu device registration
Date: Sat, 16 May 2009 11:55:14 +0200

Quoted 8 lines · Russell King - ARM Linux
Quoted 7 lines

This looks all very convoluted. Why not do something like:

static unsigned long iommu_base[] = {
	OMAP3_MMU1_BASE,
	OMAP3_MMU2_BASE,
};
Quoted 6 lines
Quoted 4 lines
static int iommu_irq[] = {
	OMAP3_MMU1_IRQ,
	OMAP3_MMU2_IRQ,
};

BTW, both of these can be __initdata.

OK, I'll send the update ones. Thank you for reviewing them.

#35 lore raw

Re: [PATCH 3/6] omap iommu: omap3 iommu device registration

In reply to Russell King - ARM Linux

From: ext Russell King - ARM Linux <[email protected]>
Subject: Re: [PATCH 3/6] omap iommu: omap3 iommu device registration
Date: Sat, 16 May 2009 11:55:14 +0200

Quoted 8 lines · Russell King - ARM Linux
Quoted 7 lines

This looks all very convoluted. Why not do something like:

static unsigned long iommu_base[] = {
	OMAP3_MMU1_BASE,
	OMAP3_MMU2_BASE,
};
Quoted 6 lines
Quoted 4 lines
static int iommu_irq[] = {
	OMAP3_MMU1_IRQ,
	OMAP3_MMU2_IRQ,
};

BTW, both of these can be __initdata.

Attached the updated one.

Quoted 1 line

From 2bfdb4130433708dc04e1c30aa5099d48de408e0 Mon Sep 17 00:00:00 2001

From: Hiroshi DOYU <[email protected]>
Date: Wed, 28 Jan 2009 21:32:04 +0200
Subject: [PATCH 3/6] omap iommu: omap3 iommu device registration

---
 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");
Signature · 1 line
1.6.0.4
#36 lore raw

Re: [PATCH 3/6] omap iommu: omap3 iommu device registration

In reply to Russell King - ARM Linux

From: ext Russell King - ARM Linux <[email protected]>
Subject: Re: [PATCH 3/6] omap iommu: omap3 iommu device registration
Date: Sat, 16 May 2009 11:55:14 +0200

Quoted 8 lines · Russell King - ARM Linux
Quoted 7 lines

This looks all very convoluted. Why not do something like:

static unsigned long iommu_base[] = {
	OMAP3_MMU1_BASE,
	OMAP3_MMU2_BASE,
};
Quoted 6 lines
Quoted 4 lines
static int iommu_irq[] = {
	OMAP3_MMU1_IRQ,
	OMAP3_MMU2_IRQ,
};

BTW, both of these can be __initdata.

Attached the updated one.

Quoted 1 line

From 2bfdb4130433708dc04e1c30aa5099d48de408e0 Mon Sep 17 00:00:00 2001

From: Hiroshi DOYU <[email protected]>
Date: Wed, 28 Jan 2009 21:32:04 +0200
Subject: [PATCH 3/6] omap iommu: omap3 iommu device registration

---
 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");
Signature · 1 line
1.6.0.4
#37 lore raw

PATCH 1/1 omap3-iommu: reorganize

No functional changes.

---

How about this?

 arch/arm/mach-omap2/omap3-iommu.c |   53 ++++++++++++++++++-------------------
 1 files changed, 26 insertions(+), 27 deletions(-)
arch/arm/mach-omap2/omap3-iommu.c +26 -27
index 91ee38a..50bd445 100644
@@ -14,32 +14,30 @@
 
 #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,
+struct iommu_device {
+	resource_size_t base;
+	int irq;
+	struct iommu_platform_data pdata;
 };
 
-static const struct iommu_platform_data omap3_iommu_pdata[] __initconst = {
+static struct iommu_device devices[] __initdata = {
 	{
-		.name = "isp",
-		.nr_tlb_entries = 8,
-		.clk_name = "cam_ick",
+		.base = 0x480bd400,
+		.irq = 24,
+		.pdata = {
+			.name = "isp",
+			.nr_tlb_entries = 8,
+			.clk_name = "cam_ick",
+		},
 	},
 	{
-		.name = "iva2",
-		.nr_tlb_entries = 32,
-		.clk_name = "iva2_ck",
+		.base = 0x5d000000,
+		.irq = 28,
+		.pdata = {
+			.name = "iva2",
+			.nr_tlb_entries = 32,
+			.clk_name = "iva2_ck",
+		},
 	},
 };
 #define NR_IOMMU_DEVICES ARRAY_SIZE(omap3_iommu_pdata)
@@ -52,6 +50,7 @@ static int __init omap3_iommu_init(void)
 
 	for (i = 0; i < NR_IOMMU_DEVICES; i++) {
 		struct platform_device *pdev;
+		const struct iommu_device *d = &devices[i];
 		struct resource res[2];
 
 		pdev = platform_device_alloc("omap-iommu", i);
@@ -60,19 +59,19 @@ static int __init omap3_iommu_init(void)
 			goto err_out;
 		}
 
-		memset(res, 0,  sizeof(res));
-		res[0].start = iommu_base[i];
-		res[0].end = iommu_base[i] + MMU_REG_SIZE - 1;
+		memset(res, 0, sizeof(res));
+		res[0].start = d->base;
+		res[0].end = d->base + MMU_REG_SIZE - 1;
 		res[0].flags = IORESOURCE_MEM;
-		res[1].start = res[1].end = iommu_irq[i];
+		res[1].start = res[1].end = d->irq;
 		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]));
+		err = platform_device_add_data(pdev, &d->pdata,
+					       sizeof(d->pdata));
 		if (err)
 			goto err_out;
 		err = platform_device_add(pdev);
Signature · 1 line
1.6.3.1
#38 lore raw

Re: [PATCH] omap3-iommu: reorganize

From: ext Felipe Contreras <[email protected]>
Subject: [PATCH] omap3-iommu: reorganize
Date: Mon, 18 May 2009 18:43:00 +0200

Quoted 6 lines

No functional changes.

---

How about this?

What's the advantage of introducing a new structure here?

Quoted 97 lines
 arch/arm/mach-omap2/omap3-iommu.c |   53 ++++++++++++++++++-------------------
 1 files changed, 26 insertions(+), 27 deletions(-)
arch/arm/mach-omap2/omap3-iommu.c +26 -27
index 91ee38a..50bd445 100644
@@ -14,32 +14,30 @@
 
 #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,
+struct iommu_device {
+	resource_size_t base;
+	int irq;
+	struct iommu_platform_data pdata;
 };
 
-static const struct iommu_platform_data omap3_iommu_pdata[] __initconst = {
+static struct iommu_device devices[] __initdata = {
 	{
-		.name = "isp",
-		.nr_tlb_entries = 8,
-		.clk_name = "cam_ick",
+		.base = 0x480bd400,
+		.irq = 24,
+		.pdata = {
+			.name = "isp",
+			.nr_tlb_entries = 8,
+			.clk_name = "cam_ick",
+		},
 	},
 	{
-		.name = "iva2",
-		.nr_tlb_entries = 32,
-		.clk_name = "iva2_ck",
+		.base = 0x5d000000,
+		.irq = 28,
+		.pdata = {
+			.name = "iva2",
+			.nr_tlb_entries = 32,
+			.clk_name = "iva2_ck",
+		},
 	},
 };
 #define NR_IOMMU_DEVICES ARRAY_SIZE(omap3_iommu_pdata)
@@ -52,6 +50,7 @@ static int __init omap3_iommu_init(void)
 
 	for (i = 0; i < NR_IOMMU_DEVICES; i++) {
 		struct platform_device *pdev;
+		const struct iommu_device *d = &devices[i];
 		struct resource res[2];
 
 		pdev = platform_device_alloc("omap-iommu", i);
@@ -60,19 +59,19 @@ static int __init omap3_iommu_init(void)
 			goto err_out;
 		}
 
-		memset(res, 0,  sizeof(res));
-		res[0].start = iommu_base[i];
-		res[0].end = iommu_base[i] + MMU_REG_SIZE - 1;
+		memset(res, 0, sizeof(res));
+		res[0].start = d->base;
+		res[0].end = d->base + MMU_REG_SIZE - 1;
 		res[0].flags = IORESOURCE_MEM;
-		res[1].start = res[1].end = iommu_irq[i];
+		res[1].start = res[1].end = d->irq;
 		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]));
+		err = platform_device_add_data(pdev, &d->pdata,
+					       sizeof(d->pdata));
 		if (err)
 			goto err_out;
 		err = platform_device_add(pdev);
Signature · 1 line
1.6.3.1
#39 lore raw

Re: [PATCH] omap3-iommu: reorganize

Quoted 4 lines · Hiroshi DOYU

From: ext Felipe Contreras <[email protected]>
Subject: [PATCH] omap3-iommu: reorganize
Date: Mon, 18 May 2009 18:43:00 +0200

Quoted 8 lines
Quoted 6 lines

No functional changes.

---

How about this?

What's the advantage of introducing a new structure here?

That instead of having 3 arrays with potentially different sizes:

iommu_base
iommu_irq
omap3_iommu_pdata

You have one:

devices

Also, think about the hypothetical situation where you need 2 more iommu devices (maybe OMAP4?). What would you need to do? You'll need to add OMAP3_MMU3_BASE and OMAP3_MMU4_BASE add them to iommu_base, then add OMAP3_MMU3_IRQ and OMAP3_MMU4_IRQ and put them to iommu_irq, finally add the device data to omap3_iommu_pdata.

In the process a simple mistake would be easy to overlook:

static unsigned long iommu_base[] __initdata = {
       OMAP3_MMU1_BASE,
       OMAP3_MMU2_BASE,

+ OMAP3_MMU3_BASE,
+ OMAP3_MMU2_BASE,
};

With the 'devices' array you just need to add two more elements and that's it. It leaves less room for mistakes.

However 'struct iommu_device' is a local structure, it could very well be called __foobar__, nobody outside omap3-iommu.c will see it anyway.

Signature · 1 line
Felipe Contreras
#40 lore raw

Re: [PATCH 3/6] omap iommu: omap3 iommu device registration

In reply to Russell King - ARM Linux

Hi Russell,

From: ext Russell King - ARM Linux <[email protected]>
Subject: Re: [PATCH 3/6] omap iommu: omap3 iommu device registration
Date: Sat, 16 May 2009 11:20:36 +0200

Quoted 35 lines · Hiroshi DOYU
Quoted 11 lines
arch/arm/mach-omap2/omap3-iommu.c new file +11 -0
+static struct resource omap3_iommu_res[] = {
+	{ /* Camera ISP MMU */
+		.start		= OMAP3_MMU1_BASE,
+		.end		= OMAP3_MMU1_BASE + MMU_REG_SIZE - 1,
+		.flags		= IORESOURCE_MEM,
+	},
+	{
+		.start		= OMAP3_MMU1_IRQ,
+		.flags		= IORESOURCE_IRQ,
+	},
+	{ /* IVA2.2 MMU */

arch/arm/mach-omap2/omap3-iommu.c line 42

Quoted 10 lines
arch/arm/mach-omap2/omap3-iommu.c new file +10 -0
+		.start		= OMAP3_MMU2_BASE,
+		.end		= OMAP3_MMU2_BASE + MMU_REG_SIZE - 1,
+		.flags		= IORESOURCE_MEM,
+	},
+	{
+		.start		= OMAP3_MMU2_IRQ,
+		.flags		= IORESOURCE_IRQ,
+	},
+};
+#define NR_IOMMU_RES (ARRAY_SIZE(omap3_iommu_res) / 2)

This looks all very convoluted. Why not do something like:

static unsigned long iommu_base[] = {
	OMAP3_MMU1_BASE,
	OMAP3_MMU2_BASE,
};
static int iommu_irq[] = {
	OMAP3_MMU1_IRQ,
	OMAP3_MMU2_IRQ,
};
Quoted 12 lines

arch/arm/mach-omap2/omap3-iommu.c line 67

Quoted 10 lines
arch/arm/mach-omap2/omap3-iommu.c new file +10 -0
+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;
+
+		pdev = platform_device_alloc("omap-iommu", i + 1);

Why number them 1 and up when zero is perfectly fine?

I just wanted to use the same expression in TRM. Actually no need to start from 1.

Quoted 18 lines

arch/arm/mach-omap2/omap3-iommu.c line 73

Quoted 7 lines
arch/arm/mach-omap2/omap3-iommu.c new file +6 -0
+		if (!pdev) {
+			err = -ENOMEM;
+			goto err_out;
+		}
+		err = platform_device_add_resources(pdev,
+				    &omap3_iommu_res[2 * i], NR_IOMMU_RES);
		struct resource res[2];

		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));
Quoted 2 lines

There's no need to keep 'res' around since it's copied by add_resources.

OK.

Quoted 39 lines
Quoted 39 lines
arch/arm/mach-omap2/omap3-iommu.c new file +32 -1
+		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");
 
 
-------------------------------------------------------------------
List admin: http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm-kernel
FAQ:        http://www.arm.linux.org.uk/mailinglists/faq.php
Etiquette:  http://www.arm.linux.org.uk/mailinglists/etiquette.php
#41 lore raw

PATCH 4/6 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/io.h               |    6 
 arch/arm/mm/ioremap.c                   |   11 
 arch/arm/plat-omap/include/mach/iovmm.h |   94 +++
 arch/arm/plat-omap/iovmm.c              |  890 +++++++++++++++++++++++++++++++
 4 files changed, 1001 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/io.h +6 -0
index d2a59cf..cbdadfe 100644
@@ -75,6 +75,12 @@ extern void __iomem * __arm_ioremap(unsigned long, size_t, unsigned int);
 extern void __iounmap(volatile void __iomem *addr);
 
 /*
+ * external interface to remap single page with appropriate type
+ */
+extern int ioremap_page(unsigned long virt, unsigned long phys,
+			unsigned int mtype);
+
+/*
  * Bad read/write accesses...
  */
 extern void __readwrite_bug(const char *fn);
arch/arm/mm/ioremap.c +11 -0
index 9f88dd3..8441351 100644
@@ -110,6 +110,17 @@ static int remap_area_pages(unsigned long start, unsigned long pfn,
 	return err;
 }
 
+int ioremap_page(unsigned long virt, unsigned long phys, unsigned int mtype)
+{
+	const struct mem_type *type;
+
+	type = get_mem_type(mtype);
+	if (!type)
+		return -EINVAL;
+
+	return remap_area_pages(virt, __phys_to_pfn(phys), PAGE_SIZE, type);
+}
+EXPORT_SYMBOL(ioremap_page);
 
 void __check_kvm_seq(struct mm_struct *mm)
 {
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 +890 -0

890 lines not on this page · raw message

#42 lore raw

Re: [PATCH 4/6] omap iommu: simple virtual address space management

arch/arm/mm/ioremap.c static int remap_area_pages(unsigned long start, unsigned long pfn, · line 119

Quoted 7 lines · Hiroshi DOYU
arch/arm/mm/ioremap.c +7 -0
+int ioremap_page(unsigned long virt, unsigned long phys, unsigned int mtype)
+{
+	const struct mem_type *type;
+
+	type = get_mem_type(mtype);
+	if (!type)
+		return -EINVAL;

I think it would make more sense to move this lookup into the caller for this - you're going to be making quite a lot of calls into ioremap_page() so you really don't want to be doing the same lookup every time.

Quoted 7 lines
arch/arm/plat-omap/iovmm.c new file +7 -0
+/* map 'sglist' to a contiguous mpu virtual area and return 'va' */
+static void *vmap_sg(const struct sg_table *sgt)
+{
+	u32 va;
+	size_t total;
+	unsigned int i;
+	struct scatterlist *sg;

arch/arm/plat-omap/iovmm.c line 177

Quoted 10 lines
arch/arm/plat-omap/iovmm.c new file +10 -0
+	struct vm_struct *new;
+
+	total = sgtable_len(sgt);
+	if (!total)
+		return ERR_PTR(-EINVAL);
+
+	new = __get_vm_area(total, VM_IOREMAP, VMALLOC_START, VMALLOC_END);
+	if (!new)
+		return ERR_PTR(-ENOMEM);
+	va = (u32)new->addr;

In other words, move it here.

Quoted 26 lines
arch/arm/plat-omap/iovmm.c new file +26 -0
+
+	for_each_sg(sgt->sgl, sg, sgt->nents, i) {
+		size_t bytes;
+		u32 pa;
+		int err;
+
+		pa = sg_phys(sg);
+		bytes = sg_dma_len(sg);
+
+		BUG_ON(bytes != PAGE_SIZE);
+
+		err = ioremap_page(va,  pa, MT_DEVICE);
+		if (err)
+			goto err_out;
+
+		va += bytes;
+	}
+
+	flush_cache_vmap(new->addr, total);
+	return new->addr;
+
+err_out:
+	WARN_ON(1); /* FIXME: cleanup some mpu mappings */
+	vunmap(new->addr);
+	return ERR_PTR(-EAGAIN);
+}
#43 lore raw

Re: [PATCH 4/6] omap iommu: simple virtual address space management

Hi Russell,

From: ext Russell King - ARM Linux <[email protected]>
Subject: Re: [PATCH 4/6] omap iommu: simple virtual address space management
Date: Sat, 16 May 2009 11:22:48 +0200

Quoted 25 lines · Hiroshi DOYU

Review

Quoted 7 lines
(quoted diff) +7 -0
+int ioremap_page(unsigned long virt, unsigned long phys, unsigned int mtype)
+{
+	const struct mem_type *type;
+
+	type = get_mem_type(mtype);
+	if (!type)
+		return -EINVAL;

I think it would make more sense to move this lookup into the caller for this - you're going to be making quite a lot of calls into ioremap_page() so you really don't want to be doing the same lookup every time.

Quoted 11 lines
(quoted diff) +11 -0
+/* map 'sglist' to a contiguous mpu virtual area and return 'va' */
+static void *vmap_sg(const struct sg_table *sgt)
+{
+	u32 va;
+	size_t total;
+	unsigned int i;
+	struct scatterlist *sg;
+	struct vm_struct *new;
+
+	total = sgtable_len(sgt);
+	if (!total)
Quoted 8 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+		return ERR_PTR(-EINVAL);
+
+	new = __get_vm_area(total, VM_IOREMAP, VMALLOC_START, VMALLOC_END);
+	if (!new)
+		return ERR_PTR(-ENOMEM);
+	va = (u32)new->addr;

In other words, move it here.

Right. In this change for better performance, I have to expose "struct mem_type" and "get_mem_type()" a bit more as below. Is this change acceptable, or do you have a better idea?

arch/arm/include/asm/io.h +10 -1
index 85a49e2..ad1cbc4 100644
@@ -77,8 +77,17 @@ extern void __iounmap(volatile void __iomem *addr);
 /*
  * external interface to remap single page with appropriate type
  */
+struct mem_type {
+	unsigned int prot_pte;
+	unsigned int prot_l1;
+	unsigned int prot_sect;
+	unsigned int domain;
+};
+
+const struct mem_type *get_mem_type(unsigned int type);
+
 extern int ioremap_page(unsigned long virt, unsigned long phys,
-			unsigned int mtype);
+			const struct mem_type *mtype);
 
 /*
  * Bad read/write accesses...
arch/arm/mm/ioremap.c +3 -8
index 8441351..0ab75c6 100644
@@ -110,15 +110,10 @@ static int remap_area_pages(unsigned long start, unsigned long pfn,
 	return err;
 }
 
-int ioremap_page(unsigned long virt, unsigned long phys, unsigned int mtype)
+int ioremap_page(unsigned long virt, unsigned long phys,
+		 const struct mem_type *mtype)
 {
-	const struct mem_type *type;
-
-	type = get_mem_type(mtype);
-	if (!type)
-		return -EINVAL;
-
-	return remap_area_pages(virt, __phys_to_pfn(phys), PAGE_SIZE, type);
+	return remap_area_pages(virt, __phys_to_pfn(phys), PAGE_SIZE, mtype);
 }
 EXPORT_SYMBOL(ioremap_page);
 
arch/arm/mm/mm.h +0 -9
index 5d9f539..57f10aa 100644
@@ -16,15 +16,6 @@ static inline pmd_t *pmd_off_k(unsigned long virt)
 	return pmd_off(pgd_offset_k(virt), virt);
 }
 
-struct mem_type {
-	unsigned int prot_pte;
-	unsigned int prot_l1;
-	unsigned int prot_sect;
-	unsigned int domain;
-};
-
-const struct mem_type *get_mem_type(unsigned int type);
-
 #endif
 
 struct map_desc;
arch/arm/plat-omap/iovmm.c +6 -1
index a539051..020f5af 100644
@@ -167,6 +167,11 @@ static void *vmap_sg(const struct sg_table *sgt)
 	unsigned int i;
 	struct scatterlist *sg;
 	struct vm_struct *new;
+	const struct mem_type *mtype;
+
+	mtype = get_mem_type(MT_DEVICE);
+	if (!type)
+		return -EINVAL;
 
 	total = sgtable_len(sgt);
 	if (!total)
@@ -187,7 +192,7 @@ static void *vmap_sg(const struct sg_table *sgt)
 
 		BUG_ON(bytes != PAGE_SIZE);
 
-		err = ioremap_page(va,  pa, MT_DEVICE);
+		err = ioremap_page(va,  pa, mtype);
 		if (err)
 			goto err_out;
 
#44 lore raw

Re: [PATCH 4/6] omap iommu: simple virtual address space management

Quoted 3 lines · Hiroshi DOYU

Right. In this change for better performance, I have to expose "struct mem_type" and "get_mem_type()" a bit more as below. Is this change acceptable, or do you have a better idea?

You don't need to expose struct mem_type at all. You only need to tell the compiler that it exists and is valid by:

struct mem_type;

Then you can use it in function prototypes without complaint. I'd also prefer to hide ioremap_page() and get_mem_type() outside of the normal Linux headers - maybe in asm/mach/map.h.

#45 lore raw

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

In reply to Hiroshi DOYU

---

 arch/arm/plat-omap/Kconfig  |    8 ++++++++
 arch/arm/plat-omap/Makefile |    1 +
 2 files changed, 9 insertions(+), 0 deletions(-)
arch/arm/plat-omap/Kconfig +8 -0
index 9dd68fa..505e6ab 100644
@@ -115,6 +115,14 @@ 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"
+	depends on ARCH_OMAP
+	default n
+	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
#46 lore raw

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

arch/arm/plat-omap/Kconfig config OMAP_MBOX_FWK · line 121

Quoted 4 lines · Hiroshi DOYU
arch/arm/plat-omap/Kconfig +4 -0
+config OMAP_IOMMU
+	tristate "IOMMU support"
+	depends on ARCH_OMAP
+	default n

default n is the default whatever. There's no need for the depends line either - the whole file is protected by an "if ARCH_OMAP".."endif" encapsulation.

#47 lore raw

PATCH 6/6 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