Release 4.12 drivers/iommu/omap-iommu.c
  
  
  
/*
 * omap iommu: tlb and pagetable primitives
 *
 * Copyright (C) 2008-2010 Nokia Corporation
 *
 * Written by Hiroshi DOYU <Hiroshi.DOYU@nokia.com>,
 *              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/slab.h>
#include <linux/interrupt.h>
#include <linux/ioport.h>
#include <linux/platform_device.h>
#include <linux/iommu.h>
#include <linux/omap-iommu.h>
#include <linux/mutex.h>
#include <linux/spinlock.h>
#include <linux/io.h>
#include <linux/pm_runtime.h>
#include <linux/of.h>
#include <linux/of_iommu.h>
#include <linux/of_irq.h>
#include <linux/of_platform.h>
#include <linux/regmap.h>
#include <linux/mfd/syscon.h>
#include <asm/cacheflush.h>
#include <linux/platform_data/iommu-omap.h>
#include "omap-iopgtable.h"
#include "omap-iommu.h"
static const struct iommu_ops omap_iommu_ops;
#define to_iommu(dev)							\
	((struct omap_iommu *)platform_get_drvdata(to_platform_device(dev)))
/* bitmap of the page sizes currently supported */
#define OMAP_IOMMU_PGSIZES	(SZ_4K | SZ_64K | SZ_1M | SZ_16M)
#define MMU_LOCK_BASE_SHIFT	10
#define MMU_LOCK_BASE_MASK	(0x1f << MMU_LOCK_BASE_SHIFT)
#define MMU_LOCK_BASE(x)	\
	((x & MMU_LOCK_BASE_MASK) >> MMU_LOCK_BASE_SHIFT)
#define MMU_LOCK_VICT_SHIFT	4
#define MMU_LOCK_VICT_MASK	(0x1f << MMU_LOCK_VICT_SHIFT)
#define MMU_LOCK_VICT(x)	\
	((x & MMU_LOCK_VICT_MASK) >> MMU_LOCK_VICT_SHIFT)
static struct platform_driver omap_iommu_driver;
static struct kmem_cache *iopte_cachep;
/**
 * to_omap_domain - Get struct omap_iommu_domain from generic iommu_domain
 * @dom:        generic iommu domain handle
 **/
static struct omap_iommu_domain *to_omap_domain(struct iommu_domain *dom)
{
	return container_of(dom, struct omap_iommu_domain, domain);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Joerg Roedel | 24 | 100.00% | 1 | 100.00% | 
| Total | 24 | 100.00% | 1 | 100.00% | 
/**
 * omap_iommu_save_ctx - Save registers for pm off-mode support
 * @dev:        client device
 **/
void omap_iommu_save_ctx(struct device *dev)
{
	struct omap_iommu *obj = dev_to_omap_iommu(dev);
	u32 *p = obj->ctx;
	int i;
	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]);
	}
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Suman Anna | 81 | 92.05% | 1 | 50.00% | 
| Hiroshi Doyu | 7 | 7.95% | 1 | 50.00% | 
| Total | 88 | 100.00% | 2 | 100.00% | 
EXPORT_SYMBOL_GPL(omap_iommu_save_ctx);
/**
 * omap_iommu_restore_ctx - Restore registers for pm off-mode support
 * @dev:        client device
 **/
void omap_iommu_restore_ctx(struct device *dev)
{
	struct omap_iommu *obj = dev_to_omap_iommu(dev);
	u32 *p = obj->ctx;
	int i;
	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]);
	}
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Suman Anna | 86 | 97.73% | 1 | 50.00% | 
| Hiroshi Doyu | 2 | 2.27% | 1 | 50.00% | 
| Total | 88 | 100.00% | 2 | 100.00% | 
EXPORT_SYMBOL_GPL(omap_iommu_restore_ctx);
static void dra7_cfg_dspsys_mmu(struct omap_iommu *obj, bool enable)
{
	u32 val, mask;
	if (!obj->syscfg)
		return;
	mask = (1 << (obj->id * DSP_SYS_MMU_CONFIG_EN_SHIFT));
	val = enable ? mask : 0;
	regmap_update_bits(obj->syscfg, DSP_SYS_MMU_CONFIG, mask, val);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Suman Anna | 62 | 100.00% | 1 | 100.00% | 
| Total | 62 | 100.00% | 1 | 100.00% | 
static void __iommu_set_twl(struct omap_iommu *obj, bool on)
{
	u32 l = iommu_read_reg(obj, MMU_CNTL);
	if (on)
		iommu_write_reg(obj, MMU_IRQ_TWL_MASK, MMU_IRQENABLE);
	else
		iommu_write_reg(obj, MMU_IRQ_TLB_MISS_MASK, MMU_IRQENABLE);
	l &= ~MMU_CNTL_MASK;
	if (on)
		l |= (MMU_CNTL_MMU_EN | MMU_CNTL_TWL_EN);
	else
		l |= (MMU_CNTL_MMU_EN);
	iommu_write_reg(obj, l, MMU_CNTL);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Suman Anna | 80 | 100.00% | 1 | 100.00% | 
| Total | 80 | 100.00% | 1 | 100.00% | 
static int omap2_iommu_enable(struct omap_iommu *obj)
{
	u32 l, pa;
	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;
	l = iommu_read_reg(obj, MMU_REVISION);
	dev_info(obj->dev, "%s: version %d.%d\n", obj->name,
		 (l >> 4) & 0xf, l & 0xf);
	iommu_write_reg(obj, pa, MMU_TTB);
	dra7_cfg_dspsys_mmu(obj, true);
	if (obj->has_bus_err_back)
		iommu_write_reg(obj, MMU_GP_REG_BUS_ERR_BACK_EN, MMU_GP_REG);
	__iommu_set_twl(obj, true);
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Suman Anna | 115 | 83.33% | 2 | 50.00% | 
| Hiroshi Doyu | 19 | 13.77% | 1 | 25.00% | 
| Ohad Ben-Cohen | 4 | 2.90% | 1 | 25.00% | 
| Total | 138 | 100.00% | 4 | 100.00% | 
static void omap2_iommu_disable(struct omap_iommu *obj)
{
	u32 l = iommu_read_reg(obj, MMU_CNTL);
	l &= ~MMU_CNTL_MASK;
	iommu_write_reg(obj, l, MMU_CNTL);
	dra7_cfg_dspsys_mmu(obj, false);
	dev_dbg(obj->dev, "%s is shutting down\n", obj->name);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Suman Anna | 38 | 69.09% | 2 | 50.00% | 
| Hiroshi Doyu | 10 | 18.18% | 1 | 25.00% | 
| Ohad Ben-Cohen | 7 | 12.73% | 1 | 25.00% | 
| Total | 55 | 100.00% | 4 | 100.00% | 
static int iommu_enable(struct omap_iommu *obj)
{
	int err;
	struct platform_device *pdev = to_platform_device(obj->dev);
	struct iommu_platform_data *pdata = dev_get_platdata(&pdev->dev);
	if (pdata && pdata->deassert_reset) {
		err = pdata->deassert_reset(pdev, pdata->reset_name);
		if (err) {
			dev_err(obj->dev, "deassert_reset failed: %d\n", err);
			return err;
		}
	}
	pm_runtime_get_sync(obj->dev);
	err = omap2_iommu_enable(obj);
	return err;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Omar Ramirez Luna | 62 | 62.63% | 2 | 28.57% | 
| Hiroshi Doyu | 29 | 29.29% | 1 | 14.29% | 
| Kiran Padwal | 4 | 4.04% | 1 | 14.29% | 
| Florian Vaussard | 2 | 2.02% | 1 | 14.29% | 
| Suman Anna | 1 | 1.01% | 1 | 14.29% | 
| Ohad Ben-Cohen | 1 | 1.01% | 1 | 14.29% | 
| Total | 99 | 100.00% | 7 | 100.00% | 
static void iommu_disable(struct omap_iommu *obj)
{
	struct platform_device *pdev = to_platform_device(obj->dev);
	struct iommu_platform_data *pdata = dev_get_platdata(&pdev->dev);
	omap2_iommu_disable(obj);
	pm_runtime_put_sync(obj->dev);
	if (pdata && pdata->assert_reset)
		pdata->assert_reset(pdev, pdata->reset_name);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Omar Ramirez Luna | 40 | 59.70% | 2 | 28.57% | 
| Hiroshi Doyu | 19 | 28.36% | 1 | 14.29% | 
| Kiran Padwal | 4 | 5.97% | 1 | 14.29% | 
| Florian Vaussard | 2 | 2.99% | 1 | 14.29% | 
| Ohad Ben-Cohen | 1 | 1.49% | 1 | 14.29% | 
| Suman Anna | 1 | 1.49% | 1 | 14.29% | 
| Total | 67 | 100.00% | 7 | 100.00% | 
/*
 *      TLB operations
 */
static u32 iotlb_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;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Suman Anna | 23 | 58.97% | 1 | 33.33% | 
| Hiroshi Doyu | 15 | 38.46% | 1 | 33.33% | 
| Ohad Ben-Cohen | 1 | 2.56% | 1 | 33.33% | 
| Total | 39 | 100.00% | 3 | 100.00% | 
static u32 get_iopte_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) ||
			(e->pgsz == MMU_CAM_PGSZ_64K)) ? 0 : 6);
	return attr;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Suman Anna | 51 | 78.46% | 1 | 50.00% | 
| Hiroshi Doyu | 14 | 21.54% | 1 | 50.00% | 
| Total | 65 | 100.00% | 2 | 100.00% | 
static u32 iommu_report_fault(struct omap_iommu *obj, u32 *da)
{
	u32 status, fault_addr;
	status = iommu_read_reg(obj, MMU_IRQSTATUS);
	status &= MMU_IRQ_MASK;
	if (!status) {
		*da = 0;
		return 0;
	}
	fault_addr = iommu_read_reg(obj, MMU_FAULT_AD);
	*da = fault_addr;
	iommu_write_reg(obj, status, MMU_IRQSTATUS);
	return status;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Suman Anna | 52 | 70.27% | 1 | 33.33% | 
| Hiroshi Doyu | 21 | 28.38% | 1 | 33.33% | 
| Ohad Ben-Cohen | 1 | 1.35% | 1 | 33.33% | 
| Total | 74 | 100.00% | 3 | 100.00% | 
void iotlb_lock_get(struct omap_iommu *obj, struct iotlb_lock *l)
{
	u32 val;
	val = iommu_read_reg(obj, MMU_LOCK);
	l->base = MMU_LOCK_BASE(val);
	l->vict = MMU_LOCK_VICT(val);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Hiroshi Doyu | 44 | 97.78% | 1 | 50.00% | 
| Ohad Ben-Cohen | 1 | 2.22% | 1 | 50.00% | 
| Total | 45 | 100.00% | 2 | 100.00% | 
void iotlb_lock_set(struct omap_iommu *obj, struct iotlb_lock *l)
{
	u32 val;
	val = (l->base << MMU_LOCK_BASE_SHIFT);
	val |= (l->vict << MMU_LOCK_VICT_SHIFT);
	iommu_write_reg(obj, val, MMU_LOCK);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Hiroshi Doyu | 46 | 97.87% | 1 | 50.00% | 
| Ohad Ben-Cohen | 1 | 2.13% | 1 | 50.00% | 
| Total | 47 | 100.00% | 2 | 100.00% | 
static void iotlb_read_cr(struct omap_iommu *obj, struct cr_regs *cr)
{
	cr->cam = iommu_read_reg(obj, MMU_READ_CAM);
	cr->ram = iommu_read_reg(obj, MMU_READ_RAM);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Hiroshi Doyu | 22 | 57.89% | 1 | 33.33% | 
| Suman Anna | 15 | 39.47% | 1 | 33.33% | 
| Ohad Ben-Cohen | 1 | 2.63% | 1 | 33.33% | 
| Total | 38 | 100.00% | 3 | 100.00% | 
static void iotlb_load_cr(struct omap_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);
	iommu_write_reg(obj, 1, MMU_FLUSH_ENTRY);
	iommu_write_reg(obj, 1, MMU_LD_TLB);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Hiroshi Doyu | 40 | 68.97% | 1 | 33.33% | 
| Suman Anna | 17 | 29.31% | 1 | 33.33% | 
| Ohad Ben-Cohen | 1 | 1.72% | 1 | 33.33% | 
| Total | 58 | 100.00% | 3 | 100.00% | 
/* only used in iotlb iteration for-loop */
struct cr_regs __iotlb_read_cr(struct omap_iommu *obj, int n)
{
	struct cr_regs cr;
	struct iotlb_lock l;
	iotlb_lock_get(obj, &l);
	l.vict = n;
	iotlb_lock_set(obj, &l);
	iotlb_read_cr(obj, &cr);
	return cr;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Suman Anna | 36 | 65.45% | 1 | 33.33% | 
| Hiroshi Doyu | 18 | 32.73% | 1 | 33.33% | 
| Ohad Ben-Cohen | 1 | 1.82% | 1 | 33.33% | 
| Total | 55 | 100.00% | 3 | 100.00% | 
#ifdef PREFETCH_IOTLB
static struct cr_regs *iotlb_alloc_cr(struct omap_iommu *obj,
				      struct iotlb_entry *e)
{
	struct cr_regs *cr;
	if (!e)
		return NULL;
	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 | e->valid;
	cr->ram = e->pa | e->endian | e->elsz | e->mixed;
	return cr;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Suman Anna | 114 | 79.72% | 1 | 33.33% | 
| Hiroshi Doyu | 28 | 19.58% | 1 | 33.33% | 
| Ohad Ben-Cohen | 1 | 0.70% | 1 | 33.33% | 
| Total | 143 | 100.00% | 3 | 100.00% | 
/**
 * load_iotlb_entry - Set an iommu tlb entry
 * @obj:        target iommu
 * @e:          an iommu tlb entry info
 **/
static int load_iotlb_entry(struct omap_iommu *obj, struct iotlb_entry *e)
{
	int err = 0;
	struct iotlb_lock l;
	struct cr_regs *cr;
	if (!obj || !obj->nr_tlb_entries || !e)
		return -EINVAL;
	pm_runtime_get_sync(obj->dev);
	iotlb_lock_get(obj, &l);
	if (l.base == obj->nr_tlb_entries) {
		dev_warn(obj->dev, "%s: preserve entries full\n", __func__);
		err = -EBUSY;
		goto out;
	}
	if (!e->prsvd) {
		int i;
		struct cr_regs tmp;
		for_each_iotlb_cr(obj, obj->nr_tlb_entries, i, tmp)
			if (!iotlb_cr_valid(&tmp))
				break;
		if (i == obj->nr_tlb_entries) {
			dev_dbg(obj->dev, "%s: full: no entry\n", __func__);
			err = -EBUSY;
			goto out;
		}
		iotlb_lock_get(obj, &l);
	} else {
		l.vict = l.base;
		iotlb_lock_set(obj, &l);
	}
	cr = iotlb_alloc_cr(obj, e);
	if (IS_ERR(cr)) {
		pm_runtime_put_sync(obj->dev);
		return PTR_ERR(cr);
	}
	iotlb_load_cr(obj, cr);
	kfree(cr);
	if (e->prsvd)
		l.base++;
	/* increment victim for next tlb load */
	if (++l.vict == obj->nr_tlb_entries)
		l.vict = l.base;
	iotlb_lock_set(obj, &l);
out:
	pm_runtime_put_sync(obj->dev);
	return err;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Hiroshi Doyu | 190 | 68.10% | 2 | 33.33% | 
| Hari Kanigeri | 81 | 29.03% | 1 | 16.67% | 
| Omar Ramirez Luna | 6 | 2.15% | 1 | 16.67% | 
| Ohad Ben-Cohen | 2 | 0.72% | 2 | 33.33% | 
| Total | 279 | 100.00% | 6 | 100.00% | 
#else /* !PREFETCH_IOTLB */
static int load_iotlb_entry(struct omap_iommu *obj, struct iotlb_entry *e)
{
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Ohad Ben-Cohen | 19 | 100.00% | 2 | 100.00% | 
| Total | 19 | 100.00% | 2 | 100.00% | 
#endif /* !PREFETCH_IOTLB */
static int prefetch_iotlb_entry(struct omap_iommu *obj, struct iotlb_entry *e)
{
	return load_iotlb_entry(obj, e);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Ohad Ben-Cohen | 22 | 91.67% | 2 | 66.67% | 
| Hiroshi Doyu | 2 | 8.33% | 1 | 33.33% | 
| Total | 24 | 100.00% | 3 | 100.00% | 
/**
 * flush_iotlb_page - Clear an iommu tlb entry
 * @obj:        target iommu
 * @da:         iommu device virtual address
 *
 * Clear an iommu tlb entry which includes 'da' address.
 **/
static void flush_iotlb_page(struct omap_iommu *obj, u32 da)
{
	int i;
	struct cr_regs cr;
	pm_runtime_get_sync(obj->dev);
	for_each_iotlb_cr(obj, obj->nr_tlb_entries, i, cr) {
		u32 start;
		size_t bytes;
		if (!iotlb_cr_valid(&cr))
			continue;
		start = iotlb_cr_to_virt(&cr);
		bytes = iopgsz_to_bytes(cr.cam & 3);
		if ((start <= da) && (da < start + bytes)) {
			dev_dbg(obj->dev, "%s: %08x<=%08x(%x)\n",
				__func__, start, da, bytes);
			iotlb_load_cr(obj, &cr);
			iommu_write_reg(obj, 1, MMU_FLUSH_ENTRY);
			break;
		}
	}
	pm_runtime_put_sync(obj->dev);
	if (i == obj->nr_tlb_entries)
		dev_dbg(obj->dev, "%s: no page for %08x\n", __func__, da);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Hiroshi Doyu | 141 | 90.38% | 2 | 28.57% | 
| Hari Kanigeri | 8 | 5.13% | 1 | 14.29% | 
| Omar Ramirez Luna | 4 | 2.56% | 1 | 14.29% | 
| Ohad Ben-Cohen | 2 | 1.28% | 2 | 28.57% | 
| Laurent Pinchart | 1 | 0.64% | 1 | 14.29% | 
| Total | 156 | 100.00% | 7 | 100.00% | 
/**
 * flush_iotlb_all - Clear all iommu tlb entries
 * @obj:        target iommu
 **/
static void flush_iotlb_all(struct omap_iommu *obj)
{
	struct iotlb_lock l;
	pm_runtime_get_sync(obj->dev);
	l.base = 0;
	l.vict = 0;
	iotlb_lock_set(obj, &l);
	iommu_write_reg(obj, 1, MMU_GFLUSH);
	pm_runtime_put_sync(obj->dev);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Hiroshi Doyu | 52 | 89.66% | 1 | 25.00% | 
| Omar Ramirez Luna | 4 | 6.90% | 1 | 25.00% | 
| Ohad Ben-Cohen | 2 | 3.45% | 2 | 50.00% | 
| Total | 58 | 100.00% | 4 | 100.00% | 
/*
 *      H/W pagetable operations
 */
static void flush_iopgd_range(u32 *first, u32 *last)
{
	/* FIXME: L2 cache should be taken care of if it exists */
	do {
		asm("mcr        p15, 0, %0, c7, c10, 1 @ flush_pgd"
                    : : "r" (first));
		first += L1_CACHE_BYTES / sizeof(*first);
	} while (first <= last);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Hiroshi Doyu | 36 | 100.00% | 1 | 100.00% | 
| Total | 36 | 100.00% | 1 | 100.00% | 
static void flush_iopte_range(u32 *first, u32 *last)
{
	/* FIXME: L2 cache should be taken care of if it exists */
	do {
		asm("mcr        p15, 0, %0, c7, c10, 1 @ flush_pte"
                    : : "r" (first));
		first += L1_CACHE_BYTES / sizeof(*first);
	} while (first <= last);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Hiroshi Doyu | 36 | 100.00% | 1 | 100.00% | 
| Total | 36 | 100.00% | 1 | 100.00% | 
static void iopte_free(u32 *iopte)
{
	/* Note: freed iopte's must be clean ready for re-use */
	if (iopte)
		kmem_cache_free(iopte_cachep, iopte);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Hiroshi Doyu | 18 | 81.82% | 1 | 50.00% | 
| Zhouyi Zhou | 4 | 18.18% | 1 | 50.00% | 
| Total | 22 | 100.00% | 2 | 100.00% | 
static u32 *iopte_alloc(struct omap_iommu *obj, u32 *iopgd, u32 da)
{
	u32 *iopte;
	/* a table has already existed */
	if (*iopgd)
		goto pte_ready;
	/*
         * do the allocation outside the page table lock
         */
	spin_unlock(&obj->page_table_lock);
	iopte = kmem_cache_zalloc(iopte_cachep, GFP_KERNEL);
	spin_lock(&obj->page_table_lock);
	if (!*iopgd) {
		if (!iopte)
			return ERR_PTR(-ENOMEM);
		*iopgd = virt_to_phys(iopte) | IOPGD_TABLE;
		flush_iopgd_range(iopgd, iopgd);
		dev_vdbg(obj->dev, "%s: a new pte:%p\n", __func__, iopte);
	} else {
		/* We raced, free the reduniovant table */
		iopte_free(iopte);
	}
pte_ready:
	iopte = iopte_offset(iopgd, da);
	dev_vdbg(obj->dev,
		 "%s: da:%08x pgd:%p *pgd:%08x pte:%p *pte:%08x\n",
		 __func__, da, iopgd, *iopgd, iopte, *iopte);
	return iopte;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Hiroshi Doyu | 153 | 99.35% | 1 | 50.00% | 
| Ohad Ben-Cohen | 1 | 0.65% | 1 | 50.00% | 
| Total | 154 | 100.00% | 2 | 100.00% | 
static int iopgd_alloc_section(struct omap_iommu *obj, u32 da, u32 pa, u32 prot)
{
	u32 *iopgd = iopgd_offset(obj, da);
	if ((da | pa) & ~IOSECTION_MASK) {
		dev_err(obj->dev, "%s: %08x:%08x should aligned on %08lx\n",
			__func__, da, pa, IOSECTION_SIZE);
		return -EINVAL;
	}
	*iopgd = (pa & IOSECTION_MASK) | prot | IOPGD_SECTION;
	flush_iopgd_range(iopgd, iopgd);
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Hiroshi Doyu | 87 | 98.86% | 2 | 66.67% | 
| Ohad Ben-Cohen | 1 | 1.14% | 1 | 33.33% | 
| Total | 88 | 100.00% | 3 | 100.00% | 
static int iopgd_alloc_super(struct omap_iommu *obj, u32 da, u32 pa, u32 prot)
{
	u32 *iopgd = iopgd_offset(obj, da);
	int i;
	if ((da | pa) & ~IOSUPER_MASK) {
		dev_err(obj->dev, "%s: %08x:%08x should aligned on %08lx\n",
			__func__, da, pa, IOSUPER_SIZE);
		return -EINVAL;
	}
	for (i = 0; i < 16; i++)
		*(iopgd + i) = (pa & IOSUPER_MASK) | prot | IOPGD_SUPER;
	flush_iopgd_range(iopgd, iopgd + 15);
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Hiroshi Doyu | 109 | 99.09% | 2 | 66.67% | 
| Ohad Ben-Cohen | 1 | 0.91% | 1 | 33.33% | 
| Total | 110 | 100.00% | 3 | 100.00% | 
static int iopte_alloc_page(struct omap_iommu *obj, u32 da, u32 pa, u32 prot)
{
	u32 *iopgd = iopgd_offset(obj, da);
	u32 *iopte = iopte_alloc(obj, iopgd, da);
	if (IS_ERR(iopte))
		return PTR_ERR(iopte);
	*iopte = (pa & IOPAGE_MASK) | prot | IOPTE_SMALL;
	flush_iopte_range(iopte, iopte);
	dev_vdbg(obj->dev, "%s: da:%08x pa:%08x pte:%p *pte:%08x\n",
		 __func__, da, pa, iopte, *iopte);
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Hiroshi Doyu | 99 | 99.00% | 1 | 50.00% | 
| Ohad Ben-Cohen | 1 | 1.00% | 1 | 50.00% | 
| Total | 100 | 100.00% | 2 | 100.00% | 
static int iopte_alloc_large(struct omap_iommu *obj, u32 da, u32 pa, u32 prot)
{
	u32 *iopgd = iopgd_offset(obj, da);
	u32 *iopte = iopte_alloc(obj, iopgd, da);
	int i;
	if ((da | pa) & ~IOLARGE_MASK) {
		dev_err(obj->dev, "%s: %08x:%08x should aligned on %08lx\n",
			__func__, da, pa, IOLARGE_SIZE);
		return -EINVAL;
	}
	if (IS_ERR(iopte))
		return PTR_ERR(iopte);
	for (i = 0; i < 16; i++)
		*(iopte + i) = (pa & IOLARGE_MASK) | prot | IOPTE_LARGE;
	flush_iopte_range(iopte, iopte + 15);
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Hiroshi Doyu | 135 | 99.26% | 2 | 66.67% | 
| Ohad Ben-Cohen | 1 | 0.74% | 1 | 33.33% | 
| Total | 136 | 100.00% | 3 | 100.00% | 
static int
iopgtable_store_entry_core(struct omap_iommu *obj, struct iotlb_entry *e)
{
	int (*fn)(struct omap_iommu *, u32, u32, u32);
	u32 prot;
	int err;
	if (!obj || !e)
		return -EINVAL;
	switch (e->pgsz) {
	case MMU_CAM_PGSZ_16M:
		fn = iopgd_alloc_super;
		break;
	case MMU_CAM_PGSZ_1M:
		fn = iopgd_alloc_section;
		break;
	case MMU_CAM_PGSZ_64K:
		fn = iopte_alloc_large;
		break;
	case MMU_CAM_PGSZ_4K:
		fn = iopte_alloc_page;
		break;
	default:
		fn = NULL;
		break;
	}
	if (WARN_ON(!fn))
		return -EINVAL;
	prot = get_iopte_attr(e);
	spin_lock(&obj->page_table_lock);
	err = fn(obj, e->da, e->pa, prot);
	spin_unlock(&obj->page_table_lock);
	return err;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Hiroshi Doyu | 138 | 90.79% | 1 | 33.33% | 
| Suman Anna | 12 | 7.89% | 1 | 33.33% | 
| Ohad Ben-Cohen | 2 | 1.32% | 1 | 33.33% | 
| Total | 152 | 100.00% | 3 | 100.00% | 
/**
 * omap_iopgtable_store_entry - Make an iommu pte entry
 * @obj:        target iommu
 * @e:          an iommu tlb entry info
 **/
static int
omap_iopgtable_store_entry(struct omap_iommu *obj, struct iotlb_entry *e)
{
	int err;
	flush_iotlb_page(obj, e->da);
	err = iopgtable_store_entry_core(obj, e);
	if (!err)
		prefetch_iotlb_entry(obj, e);
	return err;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Hiroshi Doyu | 48 | 92.31% | 1 | 25.00% | 
| Ohad Ben-Cohen | 3 | 5.77% | 2 | 50.00% | 
| Suman Anna | 1 | 1.92% | 1 | 25.00% | 
| Total | 52 | 100.00% | 4 | 100.00% | 
/**
 * iopgtable_lookup_entry - Lookup an iommu pte entry
 * @obj:        target iommu
 * @da:         iommu device virtual address
 * @ppgd:       iommu pgd entry pointer to be returned
 * @ppte:       iommu pte entry pointer to be returned
 **/
static void
iopgtable_lookup_entry(struct omap_iommu *obj, u32 da, u32 **ppgd, u32 **ppte)
{
	u32 *iopgd, *iopte = NULL;
	iopgd = iopgd_offset(obj, da);
	if (!*iopgd)
		goto out;
	if (iopgd_is_table(*iopgd))
		iopte = iopte_offset(iopgd, da);
out:
	*ppgd = iopgd;
	*ppte = iopte;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Hiroshi Doyu | 78 | 97.50% | 2 | 66.67% | 
| Ohad Ben-Cohen | 2 | 2.50% | 1 | 33.33% | 
| Total | 80 | 100.00% | 3 | 100.00% | 
static size_t iopgtable_clear_entry_core(struct omap_iommu *obj, u32 da)
{
	size_t bytes;
	u32 *iopgd = iopgd_offset(obj, da);
	int nent = 1;
	if (!*iopgd)
		return 0;
	if (iopgd_is_table(*iopgd)) {
		int i;
		u32 *iopte = iopte_offset(iopgd, da);
		bytes = IOPTE_SIZE;
		if (*iopte & IOPTE_LARGE) {
			nent *= 16;
			/* rewind to the 1st entry */
			iopte = iopte_offset(iopgd, (da & IOLARGE_MASK));
		}
		bytes *= nent;
		memset(iopte, 0, nent * sizeof(*iopte));
		flush_iopte_range(iopte, iopte + (nent - 1) * sizeof(*iopte));
		/*
                 * do table walk to check if this table is necessary or not
                 */
		iopte = iopte_offset(iopgd, 0);
		for (i = 0; i < PTRS_PER_IOPTE; i++)
			if (iopte[i])
				goto out;
		iopte_free(iopte);
		nent = 1; /* for the next L1 entry */
	} else {
		bytes = IOPGD_SIZE;
		if ((*iopgd & IOPGD_SUPER) == IOPGD_SUPER) {
			nent *= 16;
			/* rewind to the 1st entry */
			iopgd = iopgd_offset(obj, (da & IOSUPER_MASK));
		}
		bytes *= nent;
	}
	memset(iopgd, 0, nent * sizeof(*iopgd));
	flush_iopgd_range(iopgd, iopgd + (nent - 1) * sizeof(*iopgd));
out:
	return bytes;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Hiroshi Doyu | 258 | 99.61% | 5 | 83.33% | 
| Ohad Ben-Cohen | 1 | 0.39% | 1 | 16.67% | 
| Total | 259 | 100.00% | 6 | 100.00% | 
/**
 * iopgtable_clear_entry - Remove an iommu pte entry
 * @obj:        target iommu
 * @da:         iommu device virtual address
 **/
static size_t iopgtable_clear_entry(struct omap_iommu *obj, u32 da)
{
	size_t bytes;
	spin_lock(&obj->page_table_lock);
	bytes = iopgtable_clear_entry_core(obj, da);
	flush_iotlb_page(obj, da);
	spin_unlock(&obj->page_table_lock);
	return bytes;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Hiroshi Doyu | 50 | 96.15% | 1 | 33.33% | 
| Ohad Ben-Cohen | 2 | 3.85% | 2 | 66.67% | 
| Total | 52 | 100.00% | 3 | 100.00% | 
static void iopgtable_clear_entry_all(struct omap_iommu *obj)
{
	int i;
	spin_lock(&obj->page_table_lock);
	for (i = 0; i < PTRS_PER_IOPGD; i++) {
		u32 da;
		u32 *iopgd;
		da = i << IOPGD_SHIFT;
		iopgd = iopgd_offset(obj, da);
		if (!*iopgd)
			continue;
		if (iopgd_is_table(*iopgd))
			iopte_free(iopte_offset(iopgd, 0));
		*iopgd = 0;
		flush_iopgd_range(iopgd, iopgd);
	}
	flush_iotlb_all(obj);
	spin_unlock(&obj->page_table_lock);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Hiroshi Doyu | 108 | 99.08% | 2 | 66.67% | 
| Ohad Ben-Cohen | 1 | 0.92% | 1 | 33.33% | 
| Total | 109 | 100.00% | 3 | 100.00% | 
/*
 *      Device IOMMU generic operations
 */
static irqreturn_t iommu_fault_handler(int irq, void *data)
{
	u32 da, errs;
	u32 *iopgd, *iopte;
	struct omap_iommu *obj = data;
	struct iommu_domain *domain = obj->domain;
	struct omap_iommu_domain *omap_domain = to_omap_domain(domain);
	if (!omap_domain->iommu_dev)
		return IRQ_NONE;
	errs = iommu_report_fault(obj, &da);
	if (errs == 0)
		return IRQ_HANDLED;
	/* Fault callback or TLB/PTE Dynamic loading */
	if (!report_iommu_fault(domain, obj->dev, da, 0))
		return IRQ_HANDLED;
	iommu_disable(obj);
	iopgd = iopgd_offset(obj, da);
	if (!iopgd_is_table(*iopgd)) {
		dev_err(obj->dev, "%s: errs:0x%08x da:0x%08x pgd:0x%p *pgd:px%08x\n",
			obj->name, errs, da, iopgd, *iopgd);
		return IRQ_NONE;
	}
	iopte = iopte_offset(iopgd, da);
	dev_err(obj->dev, "%s: errs:0x%08x da:0x%08x pgd:0x%p *pgd:0x%08x pte:0x%p *pte:0x%08x\n",
		obj->name, errs, da, iopgd, *iopgd, iopte, *iopte);
	return IRQ_NONE;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Hiroshi Doyu | 130 | 68.78% | 3 | 27.27% | 
| David Cohen | 21 | 11.11% | 2 | 18.18% | 
| Ohad Ben-Cohen | 15 | 7.94% | 2 | 18.18% | 
| Suman Anna | 11 | 5.82% | 2 | 18.18% | 
| Laurent Pinchart | 9 | 4.76% | 1 | 9.09% | 
| Joerg Roedel | 3 | 1.59% | 1 | 9.09% | 
| Total | 189 | 100.00% | 11 | 100.00% | 
/**
 * omap_iommu_attach() - attach iommu device to an iommu domain
 * @obj:        target omap iommu device
 * @iopgd:      page table
 **/
static int omap_iommu_attach(struct omap_iommu *obj, u32 *iopgd)
{
	int err;
	spin_lock(&obj->iommu_lock);
	obj->iopgd = iopgd;
	err = iommu_enable(obj);
	if (err)
		goto err_enable;
	flush_iotlb_all(obj);
	spin_unlock(&obj->iommu_lock);
	dev_dbg(obj->dev, "%s: %s\n", __func__, obj->name);
	return 0;
err_enable:
	spin_unlock(&obj->iommu_lock);
	return err;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Hiroshi Doyu | 65 | 72.22% | 1 | 20.00% | 
| Ohad Ben-Cohen | 18 | 20.00% | 2 | 40.00% | 
| Joerg Roedel | 5 | 5.56% | 1 | 20.00% | 
| Fernando Guzman Lugo | 2 | 2.22% | 1 | 20.00% | 
| Total | 90 | 100.00% | 5 | 100.00% | 
/**
 * omap_iommu_detach - release iommu device
 * @obj:        target iommu
 **/
static void omap_iommu_detach(struct omap_iommu *obj)
{
	if (!obj || IS_ERR(obj))
		return;
	spin_lock(&obj->iommu_lock);
	iommu_disable(obj);
	obj->iopgd = NULL;
	spin_unlock(&obj->iommu_lock);
	dev_dbg(obj->dev, "%s: %s\n", __func__, obj->name);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Hiroshi Doyu | 52 | 81.25% | 1 | 25.00% | 
| Ohad Ben-Cohen | 11 | 17.19% | 2 | 50.00% | 
| Roel Kluin | 1 | 1.56% | 1 | 25.00% | 
| Total | 64 | 100.00% | 4 | 100.00% | 
static int omap_iommu_dra7_get_dsp_system_cfg(struct platform_device *pdev,
					      struct omap_iommu *obj)
{
	struct device_node *np = pdev->dev.of_node;
	int ret;
	if (!of_device_is_compatible(np, "ti,dra7-dsp-iommu"))
		return 0;
	if (!of_property_read_bool(np, "ti,syscon-mmuconfig")) {
		dev_err(&pdev->dev, "ti,syscon-mmuconfig property is missing\n");
		return -EINVAL;
	}
	obj->syscfg =
		syscon_regmap_lookup_by_phandle(np, "ti,syscon-mmuconfig");
	if (IS_ERR(obj->syscfg)) {
		/* can fail with -EPROBE_DEFER */
		ret = PTR_ERR(obj->syscfg);
		return ret;
	}
	if (of_property_read_u32_index(np, "ti,syscon-mmuconfig", 1,
				       &obj->id)) {
		dev_err(&pdev->dev, "couldn't get the IOMMU instance id within subsystem\n");
		return -EINVAL;
	}
	if (obj->id != 0 && obj->id != 1) {
		dev_err(&pdev->dev, "invalid IOMMU instance id\n");
		return -EINVAL;
	}
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Suman Anna | 169 | 100.00% | 1 | 100.00% | 
| Total | 169 | 100.00% | 1 | 100.00% | 
/*
 *      OMAP Device MMU(IOMMU) detection
 */
static int omap_iommu_probe(struct platform_device *pdev)
{
	int err = -ENODEV;
	int irq;
	struct omap_iommu *obj;
	struct resource *res;
	struct device_node *of = pdev->dev.of_node;
	if (!of) {
		pr_err("%s: only DT-based devices are supported\n", __func__);
		return -ENODEV;
	}
	obj = devm_kzalloc(&pdev->dev, sizeof(*obj) + MMU_REG_SIZE, GFP_KERNEL);
	if (!obj)
		return -ENOMEM;
	obj->name = dev_name(&pdev->dev);
	obj->nr_tlb_entries = 32;
	err = of_property_read_u32(of, "ti,#tlb-entries", &obj->nr_tlb_entries);
	if (err && err != -EINVAL)
		return err;
	if (obj->nr_tlb_entries != 32 && obj->nr_tlb_entries != 8)
		return -EINVAL;
	if (of_find_property(of, "ti,iommu-bus-err-back", NULL))
		obj->has_bus_err_back = MMU_GP_REG_BUS_ERR_BACK_EN;
	obj->dev = &pdev->dev;
	obj->ctx = (void *)obj + sizeof(*obj);
	spin_lock_init(&obj->iommu_lock);
	spin_lock_init(&obj->page_table_lock);
	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	obj->regbase = devm_ioremap_resource(obj->dev, res);
	if (IS_ERR(obj->regbase))
		return PTR_ERR(obj->regbase);
	err = omap_iommu_dra7_get_dsp_system_cfg(pdev, obj);
	if (err)
		return err;
	irq = platform_get_irq(pdev, 0);
	if (irq < 0)
		return -ENODEV;
	err = devm_request_irq(obj->dev, irq, iommu_fault_handler, IRQF_SHARED,
			       dev_name(obj->dev), obj);
	if (err < 0)
		return err;
	platform_set_drvdata(pdev, obj);
	obj->group = iommu_group_alloc();
	if (IS_ERR(obj->group))
		return PTR_ERR(obj->group);
	err = iommu_device_sysfs_add(&obj->iommu, obj->dev, NULL, obj->name);
	if (err)
		goto out_group;
	iommu_device_set_ops(&obj->iommu, &omap_iommu_ops);
	err = iommu_device_register(&obj->iommu);
	if (err)
		goto out_sysfs;
	pm_runtime_irq_safe(obj->dev);
	pm_runtime_enable(obj->dev);
	omap_iommu_debugfs_add(obj);
	dev_info(&pdev->dev, "%s registered\n", obj->name);
	return 0;
out_sysfs:
	iommu_device_sysfs_remove(&obj->iommu);
out_group:
	iommu_group_put(obj->group);
	return err;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Hiroshi Doyu | 164 | 35.57% | 1 | 7.14% | 
| Joerg Roedel | 101 | 21.91% | 2 | 14.29% | 
| Suman Anna | 87 | 18.87% | 5 | 35.71% | 
| Florian Vaussard | 74 | 16.05% | 1 | 7.14% | 
| Omar Ramirez Luna | 14 | 3.04% | 1 | 7.14% | 
| David Cohen | 13 | 2.82% | 1 | 7.14% | 
| Aaro Koskinen | 6 | 1.30% | 1 | 7.14% | 
| Ohad Ben-Cohen | 2 | 0.43% | 2 | 14.29% | 
| Total | 461 | 100.00% | 14 | 100.00% | 
static int omap_iommu_remove(struct platform_device *pdev)
{
	struct omap_iommu *obj = platform_get_drvdata(pdev);
	iommu_group_put(obj->group);
	obj->group = NULL;
	iommu_device_sysfs_remove(&obj->iommu);
	iommu_device_unregister(&obj->iommu);
	omap_iommu_debugfs_remove(obj);
	pm_runtime_disable(obj->dev);
	dev_info(&pdev->dev, "%s removed\n", obj->name);
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Hiroshi Doyu | 42 | 53.16% | 1 | 16.67% | 
| Joerg Roedel | 29 | 36.71% | 2 | 33.33% | 
| Suman Anna | 5 | 6.33% | 1 | 16.67% | 
| Omar Ramirez Luna | 2 | 2.53% | 1 | 16.67% | 
| Ohad Ben-Cohen | 1 | 1.27% | 1 | 16.67% | 
| Total | 79 | 100.00% | 6 | 100.00% | 
static const struct of_device_id omap_iommu_of_match[] = {
	{ .compatible = "ti,omap2-iommu" },
	{ .compatible = "ti,omap4-iommu" },
	{ .compatible = "ti,dra7-iommu"	},
	{ .compatible = "ti,dra7-dsp-iommu" },
	{},
};
static struct platform_driver omap_iommu_driver = {
	.probe	= omap_iommu_probe,
	.remove	= omap_iommu_remove,
	.driver	= {
		.name	= "omap-iommu",
		.of_match_table = of_match_ptr(omap_iommu_of_match),
        },
};
static void iopte_cachep_ctor(void *iopte)
{
	clean_dcache_area(iopte, IOPTE_TABLE_SIZE);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Hiroshi Doyu | 17 | 100.00% | 1 | 100.00% | 
| Total | 17 | 100.00% | 1 | 100.00% | 
static u32 iotlb_init_entry(struct iotlb_entry *e, u32 da, u32 pa, int pgsz)
{
	memset(e, 0, sizeof(*e));
	e->da		= da;
	e->pa		= pa;
	e->valid	= MMU_CAM_V;
	e->pgsz		= pgsz;
	e->endian	= MMU_RAM_ENDIAN_LITTLE;
	e->elsz		= MMU_RAM_ELSZ_8;
	e->mixed	= 0;
	return iopgsz_to_bytes(e->pgsz);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Tony Lindgren | 76 | 91.57% | 1 | 33.33% | 
| Laurent Pinchart | 6 | 7.23% | 1 | 33.33% | 
| Suman Anna | 1 | 1.20% | 1 | 33.33% | 
| Total | 83 | 100.00% | 3 | 100.00% | 
static int omap_iommu_map(struct iommu_domain *domain, unsigned long da,
			  phys_addr_t pa, size_t bytes, int prot)
{
	struct omap_iommu_domain *omap_domain = to_omap_domain(domain);
	struct omap_iommu *oiommu = omap_domain->iommu_dev;
	struct device *dev = oiommu->dev;
	struct iotlb_entry e;
	int omap_pgsz;
	u32 ret;
	omap_pgsz = bytes_to_iopgsz(bytes);
	if (omap_pgsz < 0) {
		dev_err(dev, "invalid size to map: %d\n", bytes);
		return -EINVAL;
	}
	dev_dbg(dev, "mapping da 0x%lx to pa %pa size 0x%x\n", da, &pa, bytes);
	iotlb_init_entry(&e, da, pa, omap_pgsz);
	ret = omap_iopgtable_store_entry(oiommu, &e);
	if (ret)
		dev_err(dev, "omap_iopgtable_store_entry failed: %d\n", ret);
	return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Ohad Ben-Cohen | 114 | 80.28% | 3 | 42.86% | 
| Hiroshi Doyu | 22 | 15.49% | 1 | 14.29% | 
| Joerg Roedel | 5 | 3.52% | 2 | 28.57% | 
| Laurent Pinchart | 1 | 0.70% | 1 | 14.29% | 
| Total | 142 | 100.00% | 7 | 100.00% | 
static size_t omap_iommu_unmap(struct iommu_domain *domain, unsigned long da,
			       size_t size)
{
	struct omap_iommu_domain *omap_domain = to_omap_domain(domain);
	struct omap_iommu *oiommu = omap_domain->iommu_dev;
	struct device *dev = oiommu->dev;
	dev_dbg(dev, "unmapping da 0x%lx size %u\n", da, size);
	return iopgtable_clear_entry(oiommu, da);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Ohad Ben-Cohen | 61 | 93.85% | 3 | 60.00% | 
| Joerg Roedel | 3 | 4.62% | 1 | 20.00% | 
| Hiroshi Doyu | 1 | 1.54% | 1 | 20.00% | 
| Total | 65 | 100.00% | 5 | 100.00% | 
static int
omap_iommu_attach_dev(struct iommu_domain *domain, struct device *dev)
{
	struct omap_iommu_domain *omap_domain = to_omap_domain(domain);
	struct omap_iommu_arch_data *arch_data = dev->archdata.iommu;
	struct omap_iommu *oiommu;
	int ret = 0;
	if (!arch_data || !arch_data->iommu_dev) {
		dev_err(dev, "device doesn't have an associated iommu\n");
		return -EINVAL;
	}
	spin_lock(&omap_domain->lock);
	/* only a single device is supported per domain for now */
	if (omap_domain->iommu_dev) {
		dev_err(dev, "iommu domain is already attached\n");
		ret = -EBUSY;
		goto out;
	}
	oiommu = arch_data->iommu_dev;
	/* get a handle to and enable the omap iommu */
	ret = omap_iommu_attach(oiommu, omap_domain->pgtable);
	if (ret) {
		dev_err(dev, "can't get omap iommu: %d\n", ret);
		goto out;
	}
	omap_domain->iommu_dev = oiommu;
	omap_domain->dev = dev;
	oiommu->domain = domain;
out:
	spin_unlock(&omap_domain->lock);
	return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Ohad Ben-Cohen | 123 | 72.78% | 3 | 42.86% | 
| Suman Anna | 22 | 13.02% | 1 | 14.29% | 
| Joerg Roedel | 18 | 10.65% | 2 | 28.57% | 
| Omar Ramirez Luna | 6 | 3.55% | 1 | 14.29% | 
| Total | 169 | 100.00% | 7 | 100.00% | 
static void _omap_iommu_detach_dev(struct omap_iommu_domain *omap_domain,
				   struct device *dev)
{
	struct omap_iommu *oiommu = dev_to_omap_iommu(dev);
	/* only a single device is supported per domain for now */
	if (omap_domain->iommu_dev != oiommu) {
		dev_err(dev, "invalid iommu device\n");
		return;
	}
	iopgtable_clear_entry_all(oiommu);
	omap_iommu_detach(oiommu);
	omap_domain->iommu_dev = NULL;
	omap_domain->dev = NULL;
	oiommu->domain = NULL;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Ohad Ben-Cohen | 50 | 68.49% | 1 | 33.33% | 
| Omar Ramirez Luna | 17 | 23.29% | 1 | 33.33% | 
| Suman Anna | 6 | 8.22% | 1 | 33.33% | 
| Total | 73 | 100.00% | 3 | 100.00% | 
static void omap_iommu_detach_dev(struct iommu_domain *domain,
				  struct device *dev)
{
	struct omap_iommu_domain *omap_domain = to_omap_domain(domain);
	spin_lock(&omap_domain->lock);
	_omap_iommu_detach_dev(omap_domain, dev);
	spin_unlock(&omap_domain->lock);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Omar Ramirez Luna | 37 | 75.51% | 1 | 33.33% | 
| Ohad Ben-Cohen | 9 | 18.37% | 1 | 33.33% | 
| Joerg Roedel | 3 | 6.12% | 1 | 33.33% | 
| Total | 49 | 100.00% | 3 | 100.00% | 
static struct iommu_domain *omap_iommu_domain_alloc(unsigned type)
{
	struct omap_iommu_domain *omap_domain;
	if (type != IOMMU_DOMAIN_UNMANAGED)
		return NULL;
	omap_domain = kzalloc(sizeof(*omap_domain), GFP_KERNEL);
	if (!omap_domain)
		goto out;
	omap_domain->pgtable = kzalloc(IOPGD_TABLE_SIZE, GFP_KERNEL);
	if (!omap_domain->pgtable)
		goto fail_nomem;
	/*
         * should never fail, but please keep this around to ensure
         * we keep the hardware happy
         */
	if (WARN_ON(!IS_ALIGNED((long)omap_domain->pgtable, IOPGD_TABLE_SIZE)))
		goto fail_align;
	clean_dcache_area(omap_domain->pgtable, IOPGD_TABLE_SIZE);
	spin_lock_init(&omap_domain->lock);
	omap_domain->domain.geometry.aperture_start = 0;
	omap_domain->domain.geometry.aperture_end   = (1ULL << 32) - 1;
	omap_domain->domain.geometry.force_aperture = true;
	return &omap_domain->domain;
fail_align:
	kfree(omap_domain->pgtable);
fail_nomem:
	kfree(omap_domain);
out:
	return NULL;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Ohad Ben-Cohen | 100 | 59.17% | 1 | 25.00% | 
| Joerg Roedel | 53 | 31.36% | 2 | 50.00% | 
| Suman Anna | 16 | 9.47% | 1 | 25.00% | 
| Total | 169 | 100.00% | 4 | 100.00% | 
static void omap_iommu_domain_free(struct iommu_domain *domain)
{
	struct omap_iommu_domain *omap_domain = to_omap_domain(domain);
	/*
         * An iommu device is still attached
         * (currently, only one device can be attached) ?
         */
	if (omap_domain->iommu_dev)
		_omap_iommu_detach_dev(omap_domain, omap_domain->dev);
	kfree(omap_domain->pgtable);
	kfree(omap_domain);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Ohad Ben-Cohen | 29 | 59.18% | 1 | 33.33% | 
| Omar Ramirez Luna | 16 | 32.65% | 1 | 33.33% | 
| Joerg Roedel | 4 | 8.16% | 1 | 33.33% | 
| Total | 49 | 100.00% | 3 | 100.00% | 
static phys_addr_t omap_iommu_iova_to_phys(struct iommu_domain *domain,
					   dma_addr_t da)
{
	struct omap_iommu_domain *omap_domain = to_omap_domain(domain);
	struct omap_iommu *oiommu = omap_domain->iommu_dev;
	struct device *dev = oiommu->dev;
	u32 *pgd, *pte;
	phys_addr_t ret = 0;
	iopgtable_lookup_entry(oiommu, da, &pgd, &pte);
	if (pte) {
		if (iopte_is_small(*pte))
			ret = omap_iommu_translate(*pte, da, IOPTE_MASK);
		else if (iopte_is_large(*pte))
			ret = omap_iommu_translate(*pte, da, IOLARGE_MASK);
		else
			dev_err(dev, "bogus pte 0x%x, da 0x%llx", *pte,
				(unsigned long long)da);
	} else {
		if (iopgd_is_section(*pgd))
			ret = omap_iommu_translate(*pgd, da, IOSECTION_MASK);
		else if (iopgd_is_super(*pgd))
			ret = omap_iommu_translate(*pgd, da, IOSUPER_MASK);
		else
			dev_err(dev, "bogus pgd 0x%x, da 0x%llx", *pgd,
				(unsigned long long)da);
	}
	return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Ohad Ben-Cohen | 181 | 91.88% | 3 | 50.00% | 
| Suman Anna | 12 | 6.09% | 1 | 16.67% | 
| Joerg Roedel | 3 | 1.52% | 1 | 16.67% | 
| Varun Sethi | 1 | 0.51% | 1 | 16.67% | 
| Total | 197 | 100.00% | 6 | 100.00% | 
static int omap_iommu_add_device(struct device *dev)
{
	struct omap_iommu_arch_data *arch_data;
	struct omap_iommu *oiommu;
	struct iommu_group *group;
	struct device_node *np;
	struct platform_device *pdev;
	int ret;
	/*
         * Allocate the archdata iommu structure for DT-based devices.
         *
         * TODO: Simplify this when removing non-DT support completely from the
         * IOMMU users.
         */
	if (!dev->of_node)
		return 0;
	np = of_parse_phandle(dev->of_node, "iommus", 0);
	if (!np)
		return 0;
	pdev = of_find_device_by_node(np);
	if (WARN_ON(!pdev)) {
		of_node_put(np);
		return -EINVAL;
	}
	oiommu = platform_get_drvdata(pdev);
	if (!oiommu) {
		of_node_put(np);
		return -EINVAL;
	}
	arch_data = kzalloc(sizeof(*arch_data), GFP_KERNEL);
	if (!arch_data) {
		of_node_put(np);
		return -ENOMEM;
	}
	ret = iommu_device_link(&oiommu->iommu, dev);
	if (ret) {
		kfree(arch_data);
		of_node_put(np);
		return ret;
	}
	arch_data->iommu_dev = oiommu;
	dev->archdata.iommu = arch_data;
	/*
         * IOMMU group initialization calls into omap_iommu_device_group, which
         * needs a valid dev->archdata.iommu pointer
         */
	group = iommu_group_get_for_dev(dev);
	if (IS_ERR(group)) {
		iommu_device_unlink(&oiommu->iommu, dev);
		dev->archdata.iommu = NULL;
		kfree(arch_data);
		return PTR_ERR(group);
	}
	iommu_group_put(group);
	of_node_put(np);
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Joerg Roedel | 120 | 47.43% | 3 | 60.00% | 
| Laurent Pinchart | 102 | 40.32% | 1 | 20.00% | 
| Suman Anna | 31 | 12.25% | 1 | 20.00% | 
| Total | 253 | 100.00% | 5 | 100.00% | 
static void omap_iommu_remove_device(struct device *dev)
{
	struct omap_iommu_arch_data *arch_data = dev->archdata.iommu;
	if (!dev->of_node || !arch_data)
		return;
	iommu_device_unlink(&arch_data->iommu_dev->iommu, dev);
	iommu_group_remove_device(dev);
	dev->archdata.iommu = NULL;
	kfree(arch_data);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Laurent Pinchart | 40 | 63.49% | 1 | 25.00% | 
| Joerg Roedel | 23 | 36.51% | 3 | 75.00% | 
| Total | 63 | 100.00% | 4 | 100.00% | 
static struct iommu_group *omap_iommu_device_group(struct device *dev)
{
	struct omap_iommu_arch_data *arch_data = dev->archdata.iommu;
	struct iommu_group *group = NULL;
	if (arch_data->iommu_dev)
		group = arch_data->iommu_dev->group;
	return group;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Joerg Roedel | 48 | 100.00% | 1 | 100.00% | 
| Total | 48 | 100.00% | 1 | 100.00% | 
static const struct iommu_ops omap_iommu_ops = {
	.domain_alloc	= omap_iommu_domain_alloc,
	.domain_free	= omap_iommu_domain_free,
	.attach_dev	= omap_iommu_attach_dev,
	.detach_dev	= omap_iommu_detach_dev,
	.map		= omap_iommu_map,
	.unmap		= omap_iommu_unmap,
	.map_sg		= default_iommu_map_sg,
	.iova_to_phys	= omap_iommu_iova_to_phys,
	.add_device	= omap_iommu_add_device,
	.remove_device	= omap_iommu_remove_device,
	.device_group	= omap_iommu_device_group,
	.pgsize_bitmap	= OMAP_IOMMU_PGSIZES,
};
static int __init omap_iommu_init(void)
{
	struct kmem_cache *p;
	const unsigned long flags = SLAB_HWCACHE_ALIGN;
	size_t align = 1 << 10; /* L2 pagetable alignement */
	struct device_node *np;
	int ret;
	np = of_find_matching_node(NULL, omap_iommu_of_match);
	if (!np)
		return 0;
	of_node_put(np);
	p = kmem_cache_create("iopte_cache", IOPTE_TABLE_SIZE, align, flags,
			      iopte_cachep_ctor);
	if (!p)
		return -ENOMEM;
	iopte_cachep = p;
	omap_iommu_debugfs_init();
	ret = platform_driver_register(&omap_iommu_driver);
	if (ret) {
		pr_err("%s: failed to register driver\n", __func__);
		goto fail_driver;
	}
	ret = bus_set_iommu(&platform_bus_type, &omap_iommu_ops);
	if (ret)
		goto fail_bus;
	return 0;
fail_bus:
	platform_driver_unregister(&omap_iommu_driver);
fail_driver:
	kmem_cache_destroy(iopte_cachep);
	return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Suman Anna | 54 | 35.29% | 1 | 20.00% | 
| Hiroshi Doyu | 51 | 33.33% | 1 | 20.00% | 
| Thierry Reding | 27 | 17.65% | 1 | 20.00% | 
| Ohad Ben-Cohen | 17 | 11.11% | 1 | 20.00% | 
| Joerg Roedel | 4 | 2.61% | 1 | 20.00% | 
| Total | 153 | 100.00% | 5 | 100.00% | 
subsys_initcall(omap_iommu_init);
/* must be ready before omap3isp is probed */
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Hiroshi Doyu | 2689 | 44.24% | 8 | 10.96% | 
| Suman Anna | 1238 | 20.37% | 19 | 26.03% | 
| Ohad Ben-Cohen | 881 | 14.49% | 10 | 13.70% | 
| Joerg Roedel | 463 | 7.62% | 7 | 9.59% | 
| Omar Ramirez Luna | 211 | 3.47% | 3 | 4.11% | 
| Laurent Pinchart | 169 | 2.78% | 4 | 5.48% | 
| Florian Vaussard | 126 | 2.07% | 2 | 2.74% | 
| Hari Kanigeri | 89 | 1.46% | 2 | 2.74% | 
| Tony Lindgren | 86 | 1.41% | 3 | 4.11% | 
| David Cohen | 34 | 0.56% | 2 | 2.74% | 
| Ido Yariv | 33 | 0.54% | 2 | 2.74% | 
| Thierry Reding | 28 | 0.46% | 2 | 2.74% | 
| Kiran Padwal | 9 | 0.15% | 2 | 2.74% | 
| Aaro Koskinen | 6 | 0.10% | 1 | 1.37% | 
| Olav Haugan | 5 | 0.08% | 1 | 1.37% | 
| Zhouyi Zhou | 4 | 0.07% | 1 | 1.37% | 
| Tejun Heo | 3 | 0.05% | 1 | 1.37% | 
| Fernando Guzman Lugo | 2 | 0.03% | 1 | 1.37% | 
| Varun Sethi | 1 | 0.02% | 1 | 1.37% | 
| Roel Kluin | 1 | 0.02% | 1 | 1.37% | 
| Total | 6078 | 100.00% | 73 | 100.00% | 
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.