2009-01-26 21:13:40 +08:00
|
|
|
/*
|
|
|
|
* omap iommu: tlb and pagetable primitives
|
|
|
|
*
|
2010-02-16 02:03:32 +08:00
|
|
|
* Copyright (C) 2008-2010 Nokia Corporation
|
2009-01-26 21:13:40 +08:00
|
|
|
*
|
|
|
|
* 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 cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2009-01-26 21:13:40 +08:00
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/platform_device.h>
|
2011-06-02 06:46:12 +08:00
|
|
|
#include <linux/iommu.h>
|
2012-11-03 03:24:03 +08:00
|
|
|
#include <linux/omap-iommu.h>
|
2011-06-02 06:46:12 +08:00
|
|
|
#include <linux/mutex.h>
|
|
|
|
#include <linux/spinlock.h>
|
2012-11-03 03:24:06 +08:00
|
|
|
#include <linux/io.h>
|
2012-11-20 09:05:51 +08:00
|
|
|
#include <linux/pm_runtime.h>
|
2014-03-01 04:42:36 +08:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_iommu.h>
|
|
|
|
#include <linux/of_irq.h>
|
2014-09-05 06:27:30 +08:00
|
|
|
#include <linux/of_platform.h>
|
2015-10-03 07:02:44 +08:00
|
|
|
#include <linux/regmap.h>
|
|
|
|
#include <linux/mfd/syscon.h>
|
2009-01-26 21:13:40 +08:00
|
|
|
|
|
|
|
#include <asm/cacheflush.h>
|
|
|
|
|
2012-11-03 03:24:14 +08:00
|
|
|
#include <linux/platform_data/iommu-omap.h>
|
2009-01-26 21:13:40 +08:00
|
|
|
|
2012-11-03 03:24:00 +08:00
|
|
|
#include "omap-iopgtable.h"
|
2012-11-03 03:24:06 +08:00
|
|
|
#include "omap-iommu.h"
|
2009-01-26 21:13:40 +08:00
|
|
|
|
2014-03-18 09:31:34 +08:00
|
|
|
#define to_iommu(dev) \
|
|
|
|
((struct omap_iommu *)platform_get_drvdata(to_platform_device(dev)))
|
|
|
|
|
2011-11-10 17:32:27 +08:00
|
|
|
/* bitmap of the page sizes currently supported */
|
|
|
|
#define OMAP_IOMMU_PGSIZES (SZ_4K | SZ_64K | SZ_1M | SZ_16M)
|
|
|
|
|
2011-06-02 06:46:12 +08:00
|
|
|
/**
|
|
|
|
* struct omap_iommu_domain - omap iommu domain
|
|
|
|
* @pgtable: the page table
|
|
|
|
* @iommu_dev: an omap iommu device attached to this domain. only a single
|
|
|
|
* iommu device can be attached for now.
|
2012-04-19 02:09:41 +08:00
|
|
|
* @dev: Device using this domain.
|
2011-06-02 06:46:12 +08:00
|
|
|
* @lock: domain lock, should be taken when attaching/detaching
|
|
|
|
*/
|
|
|
|
struct omap_iommu_domain {
|
|
|
|
u32 *pgtable;
|
2011-08-18 03:57:56 +08:00
|
|
|
struct omap_iommu *iommu_dev;
|
2012-04-19 02:09:41 +08:00
|
|
|
struct device *dev;
|
2011-06-02 06:46:12 +08:00
|
|
|
spinlock_t lock;
|
2015-03-26 20:43:09 +08:00
|
|
|
struct iommu_domain domain;
|
2011-06-02 06:46:12 +08:00
|
|
|
};
|
|
|
|
|
2012-11-03 03:24:09 +08:00
|
|
|
#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)
|
|
|
|
|
2009-01-26 21:13:40 +08:00
|
|
|
static struct platform_driver omap_iommu_driver;
|
|
|
|
static struct kmem_cache *iopte_cachep;
|
|
|
|
|
2015-03-26 20:43:09 +08:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
|
2009-01-26 21:13:40 +08:00
|
|
|
/**
|
2011-08-18 03:57:56 +08:00
|
|
|
* omap_iommu_save_ctx - Save registers for pm off-mode support
|
2011-10-11 06:18:33 +08:00
|
|
|
* @dev: client device
|
2009-01-26 21:13:40 +08:00
|
|
|
**/
|
2011-10-11 06:18:33 +08:00
|
|
|
void omap_iommu_save_ctx(struct device *dev)
|
2009-01-26 21:13:40 +08:00
|
|
|
{
|
2011-10-11 06:18:33 +08:00
|
|
|
struct omap_iommu *obj = dev_to_omap_iommu(dev);
|
iommu/omap: Consolidate OMAP IOMMU modules
The OMAP IOMMU driver was originally designed as modules, and split
into a core module and a thin arch-specific module through the OMAP
arch-specific struct iommu_functions, to scale for both OMAP1 and
OMAP2+ IOMMU variants. The driver can only be built for OMAP2+
platforms currently, and also can only be built-in after the
adaptation to generic IOMMU API. The OMAP1 variant was never added
and will most probably be never added (the code for the only potential
user, its parent, DSP processor has already been cleaned up). So,
consolidate the OMAP2 specific omap-iommu2 module into the core OMAP
IOMMU driver - this eliminates the arch-specific ops structure and
simplifies the driver into a single module that only implements the
generic IOMMU API's iommu_ops.
The following are the main changes:
- omap-iommu2 module is completely eliminated, with the common
definitions moved to the internal omap-iommu.h, and the ops
implementations moved into omap-iommu.c
- OMAP arch-specific struct iommu_functions is also eliminated,
with the ops implementations directly absorbed into the calling
functions
- iotlb_alloc_cr() is no longer inlined and defined only when
PREFETCH_IOTLB is defined
- iotlb_dump_cr() is similarly defined only when CONFIG_OMAP_IOMMU_DEBUG
is defined
- Elimination of the OMAP IOMMU exported functions to register the
arch ops, omap_install_iommu_arch() & omap_uninstall_iommu_arch()
- Any stale comments about OMAP1 are also cleaned up
Signed-off-by: Suman Anna <s-anna@ti.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
2014-10-23 06:22:27 +08:00
|
|
|
u32 *p = obj->ctx;
|
|
|
|
int i;
|
2011-10-11 06:18:33 +08:00
|
|
|
|
iommu/omap: Consolidate OMAP IOMMU modules
The OMAP IOMMU driver was originally designed as modules, and split
into a core module and a thin arch-specific module through the OMAP
arch-specific struct iommu_functions, to scale for both OMAP1 and
OMAP2+ IOMMU variants. The driver can only be built for OMAP2+
platforms currently, and also can only be built-in after the
adaptation to generic IOMMU API. The OMAP1 variant was never added
and will most probably be never added (the code for the only potential
user, its parent, DSP processor has already been cleaned up). So,
consolidate the OMAP2 specific omap-iommu2 module into the core OMAP
IOMMU driver - this eliminates the arch-specific ops structure and
simplifies the driver into a single module that only implements the
generic IOMMU API's iommu_ops.
The following are the main changes:
- omap-iommu2 module is completely eliminated, with the common
definitions moved to the internal omap-iommu.h, and the ops
implementations moved into omap-iommu.c
- OMAP arch-specific struct iommu_functions is also eliminated,
with the ops implementations directly absorbed into the calling
functions
- iotlb_alloc_cr() is no longer inlined and defined only when
PREFETCH_IOTLB is defined
- iotlb_dump_cr() is similarly defined only when CONFIG_OMAP_IOMMU_DEBUG
is defined
- Elimination of the OMAP IOMMU exported functions to register the
arch ops, omap_install_iommu_arch() & omap_uninstall_iommu_arch()
- Any stale comments about OMAP1 are also cleaned up
Signed-off-by: Suman Anna <s-anna@ti.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
2014-10-23 06:22:27 +08:00
|
|
|
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]);
|
|
|
|
}
|
2009-01-26 21:13:40 +08:00
|
|
|
}
|
2011-08-18 03:57:56 +08:00
|
|
|
EXPORT_SYMBOL_GPL(omap_iommu_save_ctx);
|
2009-01-26 21:13:40 +08:00
|
|
|
|
|
|
|
/**
|
2011-08-18 03:57:56 +08:00
|
|
|
* omap_iommu_restore_ctx - Restore registers for pm off-mode support
|
2011-10-11 06:18:33 +08:00
|
|
|
* @dev: client device
|
2009-01-26 21:13:40 +08:00
|
|
|
**/
|
2011-10-11 06:18:33 +08:00
|
|
|
void omap_iommu_restore_ctx(struct device *dev)
|
2009-01-26 21:13:40 +08:00
|
|
|
{
|
2011-10-11 06:18:33 +08:00
|
|
|
struct omap_iommu *obj = dev_to_omap_iommu(dev);
|
iommu/omap: Consolidate OMAP IOMMU modules
The OMAP IOMMU driver was originally designed as modules, and split
into a core module and a thin arch-specific module through the OMAP
arch-specific struct iommu_functions, to scale for both OMAP1 and
OMAP2+ IOMMU variants. The driver can only be built for OMAP2+
platforms currently, and also can only be built-in after the
adaptation to generic IOMMU API. The OMAP1 variant was never added
and will most probably be never added (the code for the only potential
user, its parent, DSP processor has already been cleaned up). So,
consolidate the OMAP2 specific omap-iommu2 module into the core OMAP
IOMMU driver - this eliminates the arch-specific ops structure and
simplifies the driver into a single module that only implements the
generic IOMMU API's iommu_ops.
The following are the main changes:
- omap-iommu2 module is completely eliminated, with the common
definitions moved to the internal omap-iommu.h, and the ops
implementations moved into omap-iommu.c
- OMAP arch-specific struct iommu_functions is also eliminated,
with the ops implementations directly absorbed into the calling
functions
- iotlb_alloc_cr() is no longer inlined and defined only when
PREFETCH_IOTLB is defined
- iotlb_dump_cr() is similarly defined only when CONFIG_OMAP_IOMMU_DEBUG
is defined
- Elimination of the OMAP IOMMU exported functions to register the
arch ops, omap_install_iommu_arch() & omap_uninstall_iommu_arch()
- Any stale comments about OMAP1 are also cleaned up
Signed-off-by: Suman Anna <s-anna@ti.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
2014-10-23 06:22:27 +08:00
|
|
|
u32 *p = obj->ctx;
|
|
|
|
int i;
|
2011-10-11 06:18:33 +08:00
|
|
|
|
iommu/omap: Consolidate OMAP IOMMU modules
The OMAP IOMMU driver was originally designed as modules, and split
into a core module and a thin arch-specific module through the OMAP
arch-specific struct iommu_functions, to scale for both OMAP1 and
OMAP2+ IOMMU variants. The driver can only be built for OMAP2+
platforms currently, and also can only be built-in after the
adaptation to generic IOMMU API. The OMAP1 variant was never added
and will most probably be never added (the code for the only potential
user, its parent, DSP processor has already been cleaned up). So,
consolidate the OMAP2 specific omap-iommu2 module into the core OMAP
IOMMU driver - this eliminates the arch-specific ops structure and
simplifies the driver into a single module that only implements the
generic IOMMU API's iommu_ops.
The following are the main changes:
- omap-iommu2 module is completely eliminated, with the common
definitions moved to the internal omap-iommu.h, and the ops
implementations moved into omap-iommu.c
- OMAP arch-specific struct iommu_functions is also eliminated,
with the ops implementations directly absorbed into the calling
functions
- iotlb_alloc_cr() is no longer inlined and defined only when
PREFETCH_IOTLB is defined
- iotlb_dump_cr() is similarly defined only when CONFIG_OMAP_IOMMU_DEBUG
is defined
- Elimination of the OMAP IOMMU exported functions to register the
arch ops, omap_install_iommu_arch() & omap_uninstall_iommu_arch()
- Any stale comments about OMAP1 are also cleaned up
Signed-off-by: Suman Anna <s-anna@ti.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
2014-10-23 06:22:27 +08:00
|
|
|
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]);
|
|
|
|
}
|
2009-01-26 21:13:40 +08:00
|
|
|
}
|
2011-08-18 03:57:56 +08:00
|
|
|
EXPORT_SYMBOL_GPL(omap_iommu_restore_ctx);
|
2009-01-26 21:13:40 +08:00
|
|
|
|
2015-10-03 07:02:44 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
iommu/omap: Consolidate OMAP IOMMU modules
The OMAP IOMMU driver was originally designed as modules, and split
into a core module and a thin arch-specific module through the OMAP
arch-specific struct iommu_functions, to scale for both OMAP1 and
OMAP2+ IOMMU variants. The driver can only be built for OMAP2+
platforms currently, and also can only be built-in after the
adaptation to generic IOMMU API. The OMAP1 variant was never added
and will most probably be never added (the code for the only potential
user, its parent, DSP processor has already been cleaned up). So,
consolidate the OMAP2 specific omap-iommu2 module into the core OMAP
IOMMU driver - this eliminates the arch-specific ops structure and
simplifies the driver into a single module that only implements the
generic IOMMU API's iommu_ops.
The following are the main changes:
- omap-iommu2 module is completely eliminated, with the common
definitions moved to the internal omap-iommu.h, and the ops
implementations moved into omap-iommu.c
- OMAP arch-specific struct iommu_functions is also eliminated,
with the ops implementations directly absorbed into the calling
functions
- iotlb_alloc_cr() is no longer inlined and defined only when
PREFETCH_IOTLB is defined
- iotlb_dump_cr() is similarly defined only when CONFIG_OMAP_IOMMU_DEBUG
is defined
- Elimination of the OMAP IOMMU exported functions to register the
arch ops, omap_install_iommu_arch() & omap_uninstall_iommu_arch()
- Any stale comments about OMAP1 are also cleaned up
Signed-off-by: Suman Anna <s-anna@ti.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
2014-10-23 06:22:27 +08: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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2015-10-03 07:02:44 +08:00
|
|
|
dra7_cfg_dspsys_mmu(obj, true);
|
|
|
|
|
iommu/omap: Consolidate OMAP IOMMU modules
The OMAP IOMMU driver was originally designed as modules, and split
into a core module and a thin arch-specific module through the OMAP
arch-specific struct iommu_functions, to scale for both OMAP1 and
OMAP2+ IOMMU variants. The driver can only be built for OMAP2+
platforms currently, and also can only be built-in after the
adaptation to generic IOMMU API. The OMAP1 variant was never added
and will most probably be never added (the code for the only potential
user, its parent, DSP processor has already been cleaned up). So,
consolidate the OMAP2 specific omap-iommu2 module into the core OMAP
IOMMU driver - this eliminates the arch-specific ops structure and
simplifies the driver into a single module that only implements the
generic IOMMU API's iommu_ops.
The following are the main changes:
- omap-iommu2 module is completely eliminated, with the common
definitions moved to the internal omap-iommu.h, and the ops
implementations moved into omap-iommu.c
- OMAP arch-specific struct iommu_functions is also eliminated,
with the ops implementations directly absorbed into the calling
functions
- iotlb_alloc_cr() is no longer inlined and defined only when
PREFETCH_IOTLB is defined
- iotlb_dump_cr() is similarly defined only when CONFIG_OMAP_IOMMU_DEBUG
is defined
- Elimination of the OMAP IOMMU exported functions to register the
arch ops, omap_install_iommu_arch() & omap_uninstall_iommu_arch()
- Any stale comments about OMAP1 are also cleaned up
Signed-off-by: Suman Anna <s-anna@ti.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
2014-10-23 06:22:27 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2015-10-03 07:02:44 +08:00
|
|
|
dra7_cfg_dspsys_mmu(obj, false);
|
iommu/omap: Consolidate OMAP IOMMU modules
The OMAP IOMMU driver was originally designed as modules, and split
into a core module and a thin arch-specific module through the OMAP
arch-specific struct iommu_functions, to scale for both OMAP1 and
OMAP2+ IOMMU variants. The driver can only be built for OMAP2+
platforms currently, and also can only be built-in after the
adaptation to generic IOMMU API. The OMAP1 variant was never added
and will most probably be never added (the code for the only potential
user, its parent, DSP processor has already been cleaned up). So,
consolidate the OMAP2 specific omap-iommu2 module into the core OMAP
IOMMU driver - this eliminates the arch-specific ops structure and
simplifies the driver into a single module that only implements the
generic IOMMU API's iommu_ops.
The following are the main changes:
- omap-iommu2 module is completely eliminated, with the common
definitions moved to the internal omap-iommu.h, and the ops
implementations moved into omap-iommu.c
- OMAP arch-specific struct iommu_functions is also eliminated,
with the ops implementations directly absorbed into the calling
functions
- iotlb_alloc_cr() is no longer inlined and defined only when
PREFETCH_IOTLB is defined
- iotlb_dump_cr() is similarly defined only when CONFIG_OMAP_IOMMU_DEBUG
is defined
- Elimination of the OMAP IOMMU exported functions to register the
arch ops, omap_install_iommu_arch() & omap_uninstall_iommu_arch()
- Any stale comments about OMAP1 are also cleaned up
Signed-off-by: Suman Anna <s-anna@ti.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
2014-10-23 06:22:27 +08:00
|
|
|
|
|
|
|
dev_dbg(obj->dev, "%s is shutting down\n", obj->name);
|
|
|
|
}
|
|
|
|
|
2011-08-18 03:57:56 +08:00
|
|
|
static int iommu_enable(struct omap_iommu *obj)
|
2009-01-26 21:13:40 +08:00
|
|
|
{
|
|
|
|
int err;
|
2012-11-20 09:05:50 +08:00
|
|
|
struct platform_device *pdev = to_platform_device(obj->dev);
|
2014-10-30 14:29:47 +08:00
|
|
|
struct iommu_platform_data *pdata = dev_get_platdata(&pdev->dev);
|
2009-01-26 21:13:40 +08:00
|
|
|
|
2014-03-01 04:42:34 +08:00
|
|
|
if (pdata && pdata->deassert_reset) {
|
2012-11-20 09:05:50 +08:00
|
|
|
err = pdata->deassert_reset(pdev, pdata->reset_name);
|
|
|
|
if (err) {
|
|
|
|
dev_err(obj->dev, "deassert_reset failed: %d\n", err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-20 09:05:51 +08:00
|
|
|
pm_runtime_get_sync(obj->dev);
|
2009-01-26 21:13:40 +08:00
|
|
|
|
iommu/omap: Consolidate OMAP IOMMU modules
The OMAP IOMMU driver was originally designed as modules, and split
into a core module and a thin arch-specific module through the OMAP
arch-specific struct iommu_functions, to scale for both OMAP1 and
OMAP2+ IOMMU variants. The driver can only be built for OMAP2+
platforms currently, and also can only be built-in after the
adaptation to generic IOMMU API. The OMAP1 variant was never added
and will most probably be never added (the code for the only potential
user, its parent, DSP processor has already been cleaned up). So,
consolidate the OMAP2 specific omap-iommu2 module into the core OMAP
IOMMU driver - this eliminates the arch-specific ops structure and
simplifies the driver into a single module that only implements the
generic IOMMU API's iommu_ops.
The following are the main changes:
- omap-iommu2 module is completely eliminated, with the common
definitions moved to the internal omap-iommu.h, and the ops
implementations moved into omap-iommu.c
- OMAP arch-specific struct iommu_functions is also eliminated,
with the ops implementations directly absorbed into the calling
functions
- iotlb_alloc_cr() is no longer inlined and defined only when
PREFETCH_IOTLB is defined
- iotlb_dump_cr() is similarly defined only when CONFIG_OMAP_IOMMU_DEBUG
is defined
- Elimination of the OMAP IOMMU exported functions to register the
arch ops, omap_install_iommu_arch() & omap_uninstall_iommu_arch()
- Any stale comments about OMAP1 are also cleaned up
Signed-off-by: Suman Anna <s-anna@ti.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
2014-10-23 06:22:27 +08:00
|
|
|
err = omap2_iommu_enable(obj);
|
2009-01-26 21:13:40 +08:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-08-18 03:57:56 +08:00
|
|
|
static void iommu_disable(struct omap_iommu *obj)
|
2009-01-26 21:13:40 +08:00
|
|
|
{
|
2012-11-20 09:05:50 +08:00
|
|
|
struct platform_device *pdev = to_platform_device(obj->dev);
|
2014-10-30 14:29:47 +08:00
|
|
|
struct iommu_platform_data *pdata = dev_get_platdata(&pdev->dev);
|
2012-11-20 09:05:50 +08:00
|
|
|
|
iommu/omap: Consolidate OMAP IOMMU modules
The OMAP IOMMU driver was originally designed as modules, and split
into a core module and a thin arch-specific module through the OMAP
arch-specific struct iommu_functions, to scale for both OMAP1 and
OMAP2+ IOMMU variants. The driver can only be built for OMAP2+
platforms currently, and also can only be built-in after the
adaptation to generic IOMMU API. The OMAP1 variant was never added
and will most probably be never added (the code for the only potential
user, its parent, DSP processor has already been cleaned up). So,
consolidate the OMAP2 specific omap-iommu2 module into the core OMAP
IOMMU driver - this eliminates the arch-specific ops structure and
simplifies the driver into a single module that only implements the
generic IOMMU API's iommu_ops.
The following are the main changes:
- omap-iommu2 module is completely eliminated, with the common
definitions moved to the internal omap-iommu.h, and the ops
implementations moved into omap-iommu.c
- OMAP arch-specific struct iommu_functions is also eliminated,
with the ops implementations directly absorbed into the calling
functions
- iotlb_alloc_cr() is no longer inlined and defined only when
PREFETCH_IOTLB is defined
- iotlb_dump_cr() is similarly defined only when CONFIG_OMAP_IOMMU_DEBUG
is defined
- Elimination of the OMAP IOMMU exported functions to register the
arch ops, omap_install_iommu_arch() & omap_uninstall_iommu_arch()
- Any stale comments about OMAP1 are also cleaned up
Signed-off-by: Suman Anna <s-anna@ti.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
2014-10-23 06:22:27 +08:00
|
|
|
omap2_iommu_disable(obj);
|
2009-01-26 21:13:40 +08:00
|
|
|
|
2012-11-20 09:05:51 +08:00
|
|
|
pm_runtime_put_sync(obj->dev);
|
2012-11-20 09:05:50 +08:00
|
|
|
|
2014-03-01 04:42:34 +08:00
|
|
|
if (pdata && pdata->assert_reset)
|
2012-11-20 09:05:50 +08:00
|
|
|
pdata->assert_reset(pdev, pdata->reset_name);
|
2009-01-26 21:13:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TLB operations
|
|
|
|
*/
|
2011-08-16 19:58:14 +08:00
|
|
|
static u32 iotlb_cr_to_virt(struct cr_regs *cr)
|
2009-01-26 21:13:40 +08:00
|
|
|
{
|
iommu/omap: Consolidate OMAP IOMMU modules
The OMAP IOMMU driver was originally designed as modules, and split
into a core module and a thin arch-specific module through the OMAP
arch-specific struct iommu_functions, to scale for both OMAP1 and
OMAP2+ IOMMU variants. The driver can only be built for OMAP2+
platforms currently, and also can only be built-in after the
adaptation to generic IOMMU API. The OMAP1 variant was never added
and will most probably be never added (the code for the only potential
user, its parent, DSP processor has already been cleaned up). So,
consolidate the OMAP2 specific omap-iommu2 module into the core OMAP
IOMMU driver - this eliminates the arch-specific ops structure and
simplifies the driver into a single module that only implements the
generic IOMMU API's iommu_ops.
The following are the main changes:
- omap-iommu2 module is completely eliminated, with the common
definitions moved to the internal omap-iommu.h, and the ops
implementations moved into omap-iommu.c
- OMAP arch-specific struct iommu_functions is also eliminated,
with the ops implementations directly absorbed into the calling
functions
- iotlb_alloc_cr() is no longer inlined and defined only when
PREFETCH_IOTLB is defined
- iotlb_dump_cr() is similarly defined only when CONFIG_OMAP_IOMMU_DEBUG
is defined
- Elimination of the OMAP IOMMU exported functions to register the
arch ops, omap_install_iommu_arch() & omap_uninstall_iommu_arch()
- Any stale comments about OMAP1 are also cleaned up
Signed-off-by: Suman Anna <s-anna@ti.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
2014-10-23 06:22:27 +08:00
|
|
|
u32 page_size = cr->cam & MMU_CAM_PGSZ_MASK;
|
|
|
|
u32 mask = get_cam_va_mask(cr->cam & page_size);
|
|
|
|
|
|
|
|
return cr->cam & mask;
|
2009-01-26 21:13:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static u32 get_iopte_attr(struct iotlb_entry *e)
|
|
|
|
{
|
iommu/omap: Consolidate OMAP IOMMU modules
The OMAP IOMMU driver was originally designed as modules, and split
into a core module and a thin arch-specific module through the OMAP
arch-specific struct iommu_functions, to scale for both OMAP1 and
OMAP2+ IOMMU variants. The driver can only be built for OMAP2+
platforms currently, and also can only be built-in after the
adaptation to generic IOMMU API. The OMAP1 variant was never added
and will most probably be never added (the code for the only potential
user, its parent, DSP processor has already been cleaned up). So,
consolidate the OMAP2 specific omap-iommu2 module into the core OMAP
IOMMU driver - this eliminates the arch-specific ops structure and
simplifies the driver into a single module that only implements the
generic IOMMU API's iommu_ops.
The following are the main changes:
- omap-iommu2 module is completely eliminated, with the common
definitions moved to the internal omap-iommu.h, and the ops
implementations moved into omap-iommu.c
- OMAP arch-specific struct iommu_functions is also eliminated,
with the ops implementations directly absorbed into the calling
functions
- iotlb_alloc_cr() is no longer inlined and defined only when
PREFETCH_IOTLB is defined
- iotlb_dump_cr() is similarly defined only when CONFIG_OMAP_IOMMU_DEBUG
is defined
- Elimination of the OMAP IOMMU exported functions to register the
arch ops, omap_install_iommu_arch() & omap_uninstall_iommu_arch()
- Any stale comments about OMAP1 are also cleaned up
Signed-off-by: Suman Anna <s-anna@ti.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
2014-10-23 06:22:27 +08:00
|
|
|
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;
|
2009-01-26 21:13:40 +08:00
|
|
|
}
|
|
|
|
|
2011-08-18 03:57:56 +08:00
|
|
|
static u32 iommu_report_fault(struct omap_iommu *obj, u32 *da)
|
2009-01-26 21:13:40 +08:00
|
|
|
{
|
iommu/omap: Consolidate OMAP IOMMU modules
The OMAP IOMMU driver was originally designed as modules, and split
into a core module and a thin arch-specific module through the OMAP
arch-specific struct iommu_functions, to scale for both OMAP1 and
OMAP2+ IOMMU variants. The driver can only be built for OMAP2+
platforms currently, and also can only be built-in after the
adaptation to generic IOMMU API. The OMAP1 variant was never added
and will most probably be never added (the code for the only potential
user, its parent, DSP processor has already been cleaned up). So,
consolidate the OMAP2 specific omap-iommu2 module into the core OMAP
IOMMU driver - this eliminates the arch-specific ops structure and
simplifies the driver into a single module that only implements the
generic IOMMU API's iommu_ops.
The following are the main changes:
- omap-iommu2 module is completely eliminated, with the common
definitions moved to the internal omap-iommu.h, and the ops
implementations moved into omap-iommu.c
- OMAP arch-specific struct iommu_functions is also eliminated,
with the ops implementations directly absorbed into the calling
functions
- iotlb_alloc_cr() is no longer inlined and defined only when
PREFETCH_IOTLB is defined
- iotlb_dump_cr() is similarly defined only when CONFIG_OMAP_IOMMU_DEBUG
is defined
- Elimination of the OMAP IOMMU exported functions to register the
arch ops, omap_install_iommu_arch() & omap_uninstall_iommu_arch()
- Any stale comments about OMAP1 are also cleaned up
Signed-off-by: Suman Anna <s-anna@ti.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
2014-10-23 06:22:27 +08:00
|
|
|
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;
|
2009-01-26 21:13:40 +08:00
|
|
|
}
|
|
|
|
|
2015-07-21 06:33:25 +08:00
|
|
|
void iotlb_lock_get(struct omap_iommu *obj, struct iotlb_lock *l)
|
2009-01-26 21:13:40 +08:00
|
|
|
{
|
|
|
|
u32 val;
|
|
|
|
|
|
|
|
val = iommu_read_reg(obj, MMU_LOCK);
|
|
|
|
|
|
|
|
l->base = MMU_LOCK_BASE(val);
|
|
|
|
l->vict = MMU_LOCK_VICT(val);
|
|
|
|
}
|
|
|
|
|
2015-07-21 06:33:25 +08:00
|
|
|
void iotlb_lock_set(struct omap_iommu *obj, struct iotlb_lock *l)
|
2009-01-26 21:13:40 +08:00
|
|
|
{
|
|
|
|
u32 val;
|
|
|
|
|
|
|
|
val = (l->base << MMU_LOCK_BASE_SHIFT);
|
|
|
|
val |= (l->vict << MMU_LOCK_VICT_SHIFT);
|
|
|
|
|
|
|
|
iommu_write_reg(obj, val, MMU_LOCK);
|
|
|
|
}
|
|
|
|
|
2011-08-18 03:57:56 +08:00
|
|
|
static void iotlb_read_cr(struct omap_iommu *obj, struct cr_regs *cr)
|
2009-01-26 21:13:40 +08:00
|
|
|
{
|
iommu/omap: Consolidate OMAP IOMMU modules
The OMAP IOMMU driver was originally designed as modules, and split
into a core module and a thin arch-specific module through the OMAP
arch-specific struct iommu_functions, to scale for both OMAP1 and
OMAP2+ IOMMU variants. The driver can only be built for OMAP2+
platforms currently, and also can only be built-in after the
adaptation to generic IOMMU API. The OMAP1 variant was never added
and will most probably be never added (the code for the only potential
user, its parent, DSP processor has already been cleaned up). So,
consolidate the OMAP2 specific omap-iommu2 module into the core OMAP
IOMMU driver - this eliminates the arch-specific ops structure and
simplifies the driver into a single module that only implements the
generic IOMMU API's iommu_ops.
The following are the main changes:
- omap-iommu2 module is completely eliminated, with the common
definitions moved to the internal omap-iommu.h, and the ops
implementations moved into omap-iommu.c
- OMAP arch-specific struct iommu_functions is also eliminated,
with the ops implementations directly absorbed into the calling
functions
- iotlb_alloc_cr() is no longer inlined and defined only when
PREFETCH_IOTLB is defined
- iotlb_dump_cr() is similarly defined only when CONFIG_OMAP_IOMMU_DEBUG
is defined
- Elimination of the OMAP IOMMU exported functions to register the
arch ops, omap_install_iommu_arch() & omap_uninstall_iommu_arch()
- Any stale comments about OMAP1 are also cleaned up
Signed-off-by: Suman Anna <s-anna@ti.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
2014-10-23 06:22:27 +08:00
|
|
|
cr->cam = iommu_read_reg(obj, MMU_READ_CAM);
|
|
|
|
cr->ram = iommu_read_reg(obj, MMU_READ_RAM);
|
2009-01-26 21:13:40 +08:00
|
|
|
}
|
|
|
|
|
2011-08-18 03:57:56 +08:00
|
|
|
static void iotlb_load_cr(struct omap_iommu *obj, struct cr_regs *cr)
|
2009-01-26 21:13:40 +08:00
|
|
|
{
|
iommu/omap: Consolidate OMAP IOMMU modules
The OMAP IOMMU driver was originally designed as modules, and split
into a core module and a thin arch-specific module through the OMAP
arch-specific struct iommu_functions, to scale for both OMAP1 and
OMAP2+ IOMMU variants. The driver can only be built for OMAP2+
platforms currently, and also can only be built-in after the
adaptation to generic IOMMU API. The OMAP1 variant was never added
and will most probably be never added (the code for the only potential
user, its parent, DSP processor has already been cleaned up). So,
consolidate the OMAP2 specific omap-iommu2 module into the core OMAP
IOMMU driver - this eliminates the arch-specific ops structure and
simplifies the driver into a single module that only implements the
generic IOMMU API's iommu_ops.
The following are the main changes:
- omap-iommu2 module is completely eliminated, with the common
definitions moved to the internal omap-iommu.h, and the ops
implementations moved into omap-iommu.c
- OMAP arch-specific struct iommu_functions is also eliminated,
with the ops implementations directly absorbed into the calling
functions
- iotlb_alloc_cr() is no longer inlined and defined only when
PREFETCH_IOTLB is defined
- iotlb_dump_cr() is similarly defined only when CONFIG_OMAP_IOMMU_DEBUG
is defined
- Elimination of the OMAP IOMMU exported functions to register the
arch ops, omap_install_iommu_arch() & omap_uninstall_iommu_arch()
- Any stale comments about OMAP1 are also cleaned up
Signed-off-by: Suman Anna <s-anna@ti.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
2014-10-23 06:22:27 +08:00
|
|
|
iommu_write_reg(obj, cr->cam | MMU_CAM_V, MMU_CAM);
|
|
|
|
iommu_write_reg(obj, cr->ram, MMU_RAM);
|
2009-01-26 21:13:40 +08:00
|
|
|
|
|
|
|
iommu_write_reg(obj, 1, MMU_FLUSH_ENTRY);
|
|
|
|
iommu_write_reg(obj, 1, MMU_LD_TLB);
|
|
|
|
}
|
|
|
|
|
2010-04-27 13:37:12 +08:00
|
|
|
/* only used in iotlb iteration for-loop */
|
2015-07-21 06:33:25 +08:00
|
|
|
struct cr_regs __iotlb_read_cr(struct omap_iommu *obj, int n)
|
2010-04-27 13:37:12 +08:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
iommu/omap: Consolidate OMAP IOMMU modules
The OMAP IOMMU driver was originally designed as modules, and split
into a core module and a thin arch-specific module through the OMAP
arch-specific struct iommu_functions, to scale for both OMAP1 and
OMAP2+ IOMMU variants. The driver can only be built for OMAP2+
platforms currently, and also can only be built-in after the
adaptation to generic IOMMU API. The OMAP1 variant was never added
and will most probably be never added (the code for the only potential
user, its parent, DSP processor has already been cleaned up). So,
consolidate the OMAP2 specific omap-iommu2 module into the core OMAP
IOMMU driver - this eliminates the arch-specific ops structure and
simplifies the driver into a single module that only implements the
generic IOMMU API's iommu_ops.
The following are the main changes:
- omap-iommu2 module is completely eliminated, with the common
definitions moved to the internal omap-iommu.h, and the ops
implementations moved into omap-iommu.c
- OMAP arch-specific struct iommu_functions is also eliminated,
with the ops implementations directly absorbed into the calling
functions
- iotlb_alloc_cr() is no longer inlined and defined only when
PREFETCH_IOTLB is defined
- iotlb_dump_cr() is similarly defined only when CONFIG_OMAP_IOMMU_DEBUG
is defined
- Elimination of the OMAP IOMMU exported functions to register the
arch ops, omap_install_iommu_arch() & omap_uninstall_iommu_arch()
- Any stale comments about OMAP1 are also cleaned up
Signed-off-by: Suman Anna <s-anna@ti.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
2014-10-23 06:22:27 +08: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;
|
|
|
|
}
|
|
|
|
|
2009-01-26 21:13:40 +08:00
|
|
|
/**
|
|
|
|
* load_iotlb_entry - Set an iommu tlb entry
|
|
|
|
* @obj: target iommu
|
|
|
|
* @e: an iommu tlb entry info
|
|
|
|
**/
|
2011-08-18 03:57:56 +08:00
|
|
|
static int load_iotlb_entry(struct omap_iommu *obj, struct iotlb_entry *e)
|
2009-01-26 21:13:40 +08:00
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
struct iotlb_lock l;
|
|
|
|
struct cr_regs *cr;
|
|
|
|
|
|
|
|
if (!obj || !obj->nr_tlb_entries || !e)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2012-11-20 09:05:51 +08:00
|
|
|
pm_runtime_get_sync(obj->dev);
|
2009-01-26 21:13:40 +08:00
|
|
|
|
2010-04-23 07:26:11 +08:00
|
|
|
iotlb_lock_get(obj, &l);
|
|
|
|
if (l.base == obj->nr_tlb_entries) {
|
|
|
|
dev_warn(obj->dev, "%s: preserve entries full\n", __func__);
|
2009-01-26 21:13:40 +08:00
|
|
|
err = -EBUSY;
|
|
|
|
goto out;
|
|
|
|
}
|
2010-04-23 07:26:11 +08:00
|
|
|
if (!e->prsvd) {
|
2010-04-27 13:37:12 +08:00
|
|
|
int i;
|
|
|
|
struct cr_regs tmp;
|
2010-04-23 07:26:11 +08:00
|
|
|
|
2010-04-27 13:37:12 +08:00
|
|
|
for_each_iotlb_cr(obj, obj->nr_tlb_entries, i, tmp)
|
2010-04-23 07:26:11 +08:00
|
|
|
if (!iotlb_cr_valid(&tmp))
|
|
|
|
break;
|
2010-04-27 13:37:12 +08:00
|
|
|
|
2010-04-23 07:26:11 +08:00
|
|
|
if (i == obj->nr_tlb_entries) {
|
|
|
|
dev_dbg(obj->dev, "%s: full: no entry\n", __func__);
|
|
|
|
err = -EBUSY;
|
|
|
|
goto out;
|
|
|
|
}
|
2010-04-27 13:37:12 +08:00
|
|
|
|
|
|
|
iotlb_lock_get(obj, &l);
|
2010-04-23 07:26:11 +08:00
|
|
|
} else {
|
|
|
|
l.vict = l.base;
|
|
|
|
iotlb_lock_set(obj, &l);
|
|
|
|
}
|
2009-01-26 21:13:40 +08:00
|
|
|
|
|
|
|
cr = iotlb_alloc_cr(obj, e);
|
|
|
|
if (IS_ERR(cr)) {
|
2012-11-20 09:05:51 +08:00
|
|
|
pm_runtime_put_sync(obj->dev);
|
2009-01-26 21:13:40 +08:00
|
|
|
return PTR_ERR(cr);
|
|
|
|
}
|
|
|
|
|
|
|
|
iotlb_load_cr(obj, cr);
|
|
|
|
kfree(cr);
|
|
|
|
|
2010-04-23 07:26:11 +08:00
|
|
|
if (e->prsvd)
|
|
|
|
l.base++;
|
2009-01-26 21:13:40 +08:00
|
|
|
/* increment victim for next tlb load */
|
|
|
|
if (++l.vict == obj->nr_tlb_entries)
|
2010-04-23 07:26:11 +08:00
|
|
|
l.vict = l.base;
|
2009-01-26 21:13:40 +08:00
|
|
|
iotlb_lock_set(obj, &l);
|
|
|
|
out:
|
2012-11-20 09:05:51 +08:00
|
|
|
pm_runtime_put_sync(obj->dev);
|
2009-01-26 21:13:40 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-08-16 20:19:10 +08:00
|
|
|
#else /* !PREFETCH_IOTLB */
|
|
|
|
|
2011-08-18 03:57:56 +08:00
|
|
|
static int load_iotlb_entry(struct omap_iommu *obj, struct iotlb_entry *e)
|
2011-08-16 20:19:10 +08:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* !PREFETCH_IOTLB */
|
|
|
|
|
2011-08-18 03:57:56 +08:00
|
|
|
static int prefetch_iotlb_entry(struct omap_iommu *obj, struct iotlb_entry *e)
|
2011-08-16 20:19:10 +08:00
|
|
|
{
|
|
|
|
return load_iotlb_entry(obj, e);
|
|
|
|
}
|
2009-01-26 21:13:40 +08: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.
|
|
|
|
**/
|
2011-08-18 03:57:56 +08:00
|
|
|
static void flush_iotlb_page(struct omap_iommu *obj, u32 da)
|
2009-01-26 21:13:40 +08:00
|
|
|
{
|
|
|
|
int i;
|
2010-04-27 13:37:12 +08:00
|
|
|
struct cr_regs cr;
|
2009-01-26 21:13:40 +08:00
|
|
|
|
2012-11-20 09:05:51 +08:00
|
|
|
pm_runtime_get_sync(obj->dev);
|
2009-01-26 21:13:40 +08:00
|
|
|
|
2010-04-27 13:37:12 +08:00
|
|
|
for_each_iotlb_cr(obj, obj->nr_tlb_entries, i, cr) {
|
2009-01-26 21:13:40 +08:00
|
|
|
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);
|
2010-08-20 21:50:18 +08:00
|
|
|
iotlb_load_cr(obj, &cr);
|
2009-01-26 21:13:40 +08:00
|
|
|
iommu_write_reg(obj, 1, MMU_FLUSH_ENTRY);
|
2014-03-08 06:47:03 +08:00
|
|
|
break;
|
2009-01-26 21:13:40 +08:00
|
|
|
}
|
|
|
|
}
|
2012-11-20 09:05:51 +08:00
|
|
|
pm_runtime_put_sync(obj->dev);
|
2009-01-26 21:13:40 +08:00
|
|
|
|
|
|
|
if (i == obj->nr_tlb_entries)
|
|
|
|
dev_dbg(obj->dev, "%s: no page for %08x\n", __func__, da);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* flush_iotlb_all - Clear all iommu tlb entries
|
|
|
|
* @obj: target iommu
|
|
|
|
**/
|
2011-08-18 03:57:56 +08:00
|
|
|
static void flush_iotlb_all(struct omap_iommu *obj)
|
2009-01-26 21:13:40 +08:00
|
|
|
{
|
|
|
|
struct iotlb_lock l;
|
|
|
|
|
2012-11-20 09:05:51 +08:00
|
|
|
pm_runtime_get_sync(obj->dev);
|
2009-01-26 21:13:40 +08:00
|
|
|
|
|
|
|
l.base = 0;
|
|
|
|
l.vict = 0;
|
|
|
|
iotlb_lock_set(obj, &l);
|
|
|
|
|
|
|
|
iommu_write_reg(obj, 1, MMU_GFLUSH);
|
|
|
|
|
2012-11-20 09:05:51 +08:00
|
|
|
pm_runtime_put_sync(obj->dev);
|
2009-01-26 21:13:40 +08:00
|
|
|
}
|
2010-05-24 10:01:51 +08:00
|
|
|
|
2009-01-26 21:13:40 +08: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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void iopte_free(u32 *iopte)
|
|
|
|
{
|
|
|
|
/* Note: freed iopte's must be clean ready for re-use */
|
2014-03-05 18:20:19 +08:00
|
|
|
if (iopte)
|
|
|
|
kmem_cache_free(iopte_cachep, iopte);
|
2009-01-26 21:13:40 +08:00
|
|
|
}
|
|
|
|
|
2011-08-18 03:57:56 +08:00
|
|
|
static u32 *iopte_alloc(struct omap_iommu *obj, u32 *iopgd, u32 da)
|
2009-01-26 21:13:40 +08:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-08-18 03:57:56 +08:00
|
|
|
static int iopgd_alloc_section(struct omap_iommu *obj, u32 da, u32 pa, u32 prot)
|
2009-01-26 21:13:40 +08:00
|
|
|
{
|
|
|
|
u32 *iopgd = iopgd_offset(obj, da);
|
|
|
|
|
2010-05-06 23:24:04 +08:00
|
|
|
if ((da | pa) & ~IOSECTION_MASK) {
|
|
|
|
dev_err(obj->dev, "%s: %08x:%08x should aligned on %08lx\n",
|
|
|
|
__func__, da, pa, IOSECTION_SIZE);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2009-01-26 21:13:40 +08:00
|
|
|
*iopgd = (pa & IOSECTION_MASK) | prot | IOPGD_SECTION;
|
|
|
|
flush_iopgd_range(iopgd, iopgd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-18 03:57:56 +08:00
|
|
|
static int iopgd_alloc_super(struct omap_iommu *obj, u32 da, u32 pa, u32 prot)
|
2009-01-26 21:13:40 +08:00
|
|
|
{
|
|
|
|
u32 *iopgd = iopgd_offset(obj, da);
|
|
|
|
int i;
|
|
|
|
|
2010-05-06 23:24:04 +08:00
|
|
|
if ((da | pa) & ~IOSUPER_MASK) {
|
|
|
|
dev_err(obj->dev, "%s: %08x:%08x should aligned on %08lx\n",
|
|
|
|
__func__, da, pa, IOSUPER_SIZE);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2009-01-26 21:13:40 +08:00
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
*(iopgd + i) = (pa & IOSUPER_MASK) | prot | IOPGD_SUPER;
|
|
|
|
flush_iopgd_range(iopgd, iopgd + 15);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-18 03:57:56 +08:00
|
|
|
static int iopte_alloc_page(struct omap_iommu *obj, u32 da, u32 pa, u32 prot)
|
2009-01-26 21:13:40 +08:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-08-18 03:57:56 +08:00
|
|
|
static int iopte_alloc_large(struct omap_iommu *obj, u32 da, u32 pa, u32 prot)
|
2009-01-26 21:13:40 +08:00
|
|
|
{
|
|
|
|
u32 *iopgd = iopgd_offset(obj, da);
|
|
|
|
u32 *iopte = iopte_alloc(obj, iopgd, da);
|
|
|
|
int i;
|
|
|
|
|
2010-05-06 23:24:04 +08:00
|
|
|
if ((da | pa) & ~IOLARGE_MASK) {
|
|
|
|
dev_err(obj->dev, "%s: %08x:%08x should aligned on %08lx\n",
|
|
|
|
__func__, da, pa, IOLARGE_SIZE);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2009-01-26 21:13:40 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-08-18 03:57:56 +08:00
|
|
|
static int
|
|
|
|
iopgtable_store_entry_core(struct omap_iommu *obj, struct iotlb_entry *e)
|
2009-01-26 21:13:40 +08:00
|
|
|
{
|
2011-08-18 03:57:56 +08:00
|
|
|
int (*fn)(struct omap_iommu *, u32, u32, u32);
|
2009-01-26 21:13:40 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-04-05 06:46:19 +08:00
|
|
|
if (WARN_ON(!fn))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2009-01-26 21:13:40 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-08-18 03:57:56 +08:00
|
|
|
* omap_iopgtable_store_entry - Make an iommu pte entry
|
2009-01-26 21:13:40 +08:00
|
|
|
* @obj: target iommu
|
|
|
|
* @e: an iommu tlb entry info
|
|
|
|
**/
|
2014-10-23 06:22:32 +08:00
|
|
|
static int
|
|
|
|
omap_iopgtable_store_entry(struct omap_iommu *obj, struct iotlb_entry *e)
|
2009-01-26 21:13:40 +08:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
flush_iotlb_page(obj, e->da);
|
|
|
|
err = iopgtable_store_entry_core(obj, e);
|
|
|
|
if (!err)
|
2011-08-16 20:19:10 +08:00
|
|
|
prefetch_iotlb_entry(obj, e);
|
2009-01-26 21:13:40 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
**/
|
2011-08-16 19:58:14 +08:00
|
|
|
static void
|
|
|
|
iopgtable_lookup_entry(struct omap_iommu *obj, u32 da, u32 **ppgd, u32 **ppte)
|
2009-01-26 21:13:40 +08:00
|
|
|
{
|
|
|
|
u32 *iopgd, *iopte = NULL;
|
|
|
|
|
|
|
|
iopgd = iopgd_offset(obj, da);
|
|
|
|
if (!*iopgd)
|
|
|
|
goto out;
|
|
|
|
|
2010-05-13 14:45:35 +08:00
|
|
|
if (iopgd_is_table(*iopgd))
|
2009-01-26 21:13:40 +08:00
|
|
|
iopte = iopte_offset(iopgd, da);
|
|
|
|
out:
|
|
|
|
*ppgd = iopgd;
|
|
|
|
*ppte = iopte;
|
|
|
|
}
|
|
|
|
|
2011-08-18 03:57:56 +08:00
|
|
|
static size_t iopgtable_clear_entry_core(struct omap_iommu *obj, u32 da)
|
2009-01-26 21:13:40 +08:00
|
|
|
{
|
|
|
|
size_t bytes;
|
|
|
|
u32 *iopgd = iopgd_offset(obj, da);
|
|
|
|
int nent = 1;
|
|
|
|
|
|
|
|
if (!*iopgd)
|
|
|
|
return 0;
|
|
|
|
|
2010-05-13 14:45:35 +08:00
|
|
|
if (iopgd_is_table(*iopgd)) {
|
2009-01-26 21:13:40 +08:00
|
|
|
int i;
|
|
|
|
u32 *iopte = iopte_offset(iopgd, da);
|
|
|
|
|
|
|
|
bytes = IOPTE_SIZE;
|
|
|
|
if (*iopte & IOPTE_LARGE) {
|
|
|
|
nent *= 16;
|
|
|
|
/* rewind to the 1st entry */
|
2010-02-16 02:03:32 +08:00
|
|
|
iopte = iopte_offset(iopgd, (da & IOLARGE_MASK));
|
2009-01-26 21:13:40 +08:00
|
|
|
}
|
|
|
|
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;
|
2009-10-23 05:46:32 +08:00
|
|
|
if ((*iopgd & IOPGD_SUPER) == IOPGD_SUPER) {
|
2009-01-26 21:13:40 +08:00
|
|
|
nent *= 16;
|
|
|
|
/* rewind to the 1st entry */
|
2010-02-16 02:03:32 +08:00
|
|
|
iopgd = iopgd_offset(obj, (da & IOSUPER_MASK));
|
2009-01-26 21:13:40 +08:00
|
|
|
}
|
|
|
|
bytes *= nent;
|
|
|
|
}
|
|
|
|
memset(iopgd, 0, nent * sizeof(*iopgd));
|
|
|
|
flush_iopgd_range(iopgd, iopgd + (nent - 1) * sizeof(*iopgd));
|
|
|
|
out:
|
|
|
|
return bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* iopgtable_clear_entry - Remove an iommu pte entry
|
|
|
|
* @obj: target iommu
|
|
|
|
* @da: iommu device virtual address
|
|
|
|
**/
|
2011-08-18 03:57:56 +08:00
|
|
|
static size_t iopgtable_clear_entry(struct omap_iommu *obj, u32 da)
|
2009-01-26 21:13:40 +08:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-08-18 03:57:56 +08:00
|
|
|
static void iopgtable_clear_entry_all(struct omap_iommu *obj)
|
2009-01-26 21:13:40 +08:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2010-05-13 14:45:35 +08:00
|
|
|
if (iopgd_is_table(*iopgd))
|
2009-01-26 21:13:40 +08:00
|
|
|
iopte_free(iopte_offset(iopgd, 0));
|
|
|
|
|
|
|
|
*iopgd = 0;
|
|
|
|
flush_iopgd_range(iopgd, iopgd);
|
|
|
|
}
|
|
|
|
|
|
|
|
flush_iotlb_all(obj);
|
|
|
|
|
|
|
|
spin_unlock(&obj->page_table_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Device IOMMU generic operations
|
|
|
|
*/
|
|
|
|
static irqreturn_t iommu_fault_handler(int irq, void *data)
|
|
|
|
{
|
2011-02-17 03:35:51 +08:00
|
|
|
u32 da, errs;
|
2009-01-26 21:13:40 +08:00
|
|
|
u32 *iopgd, *iopte;
|
2011-08-18 03:57:56 +08:00
|
|
|
struct omap_iommu *obj = data;
|
2011-09-14 03:26:29 +08:00
|
|
|
struct iommu_domain *domain = obj->domain;
|
2015-03-26 20:43:09 +08:00
|
|
|
struct omap_iommu_domain *omap_domain = to_omap_domain(domain);
|
2009-01-26 21:13:40 +08:00
|
|
|
|
2014-10-23 06:22:19 +08:00
|
|
|
if (!omap_domain->iommu_dev)
|
2009-01-26 21:13:40 +08:00
|
|
|
return IRQ_NONE;
|
|
|
|
|
2011-02-17 03:35:51 +08:00
|
|
|
errs = iommu_report_fault(obj, &da);
|
2011-05-10 22:56:46 +08:00
|
|
|
if (errs == 0)
|
|
|
|
return IRQ_HANDLED;
|
2011-02-17 03:35:51 +08:00
|
|
|
|
|
|
|
/* Fault callback or TLB/PTE Dynamic loading */
|
2011-09-14 03:26:29 +08:00
|
|
|
if (!report_iommu_fault(domain, obj->dev, da, 0))
|
2009-01-26 21:13:40 +08:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
|
2010-05-24 10:01:52 +08:00
|
|
|
iommu_disable(obj);
|
|
|
|
|
2009-01-26 21:13:40 +08:00
|
|
|
iopgd = iopgd_offset(obj, da);
|
|
|
|
|
2010-05-13 14:45:35 +08:00
|
|
|
if (!iopgd_is_table(*iopgd)) {
|
2013-05-31 07:10:59 +08:00
|
|
|
dev_err(obj->dev, "%s: errs:0x%08x da:0x%08x pgd:0x%p *pgd:px%08x\n",
|
2015-07-21 06:33:32 +08:00
|
|
|
obj->name, errs, da, iopgd, *iopgd);
|
2009-01-26 21:13:40 +08:00
|
|
|
return IRQ_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
iopte = iopte_offset(iopgd, da);
|
|
|
|
|
2013-05-31 07:10:59 +08:00
|
|
|
dev_err(obj->dev, "%s: errs:0x%08x da:0x%08x pgd:0x%p *pgd:0x%08x pte:0x%p *pte:0x%08x\n",
|
2015-07-21 06:33:32 +08:00
|
|
|
obj->name, errs, da, iopgd, *iopgd, iopte, *iopte);
|
2009-01-26 21:13:40 +08:00
|
|
|
|
|
|
|
return IRQ_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int device_match_by_alias(struct device *dev, void *data)
|
|
|
|
{
|
2011-08-18 03:57:56 +08:00
|
|
|
struct omap_iommu *obj = to_iommu(dev);
|
2009-01-26 21:13:40 +08:00
|
|
|
const char *name = data;
|
|
|
|
|
|
|
|
pr_debug("%s: %s %s\n", __func__, obj->name, name);
|
|
|
|
|
|
|
|
return strcmp(obj->name, name) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-06-02 06:46:12 +08:00
|
|
|
* omap_iommu_attach() - attach iommu device to an iommu domain
|
2011-10-11 06:18:33 +08:00
|
|
|
* @name: name of target omap iommu device
|
2011-06-02 06:46:12 +08:00
|
|
|
* @iopgd: page table
|
2009-01-26 21:13:40 +08:00
|
|
|
**/
|
2011-10-11 06:18:33 +08:00
|
|
|
static struct omap_iommu *omap_iommu_attach(const char *name, u32 *iopgd)
|
2009-01-26 21:13:40 +08:00
|
|
|
{
|
2014-03-01 04:42:33 +08:00
|
|
|
int err;
|
2011-10-11 06:18:33 +08:00
|
|
|
struct device *dev;
|
|
|
|
struct omap_iommu *obj;
|
|
|
|
|
2015-07-21 06:33:32 +08:00
|
|
|
dev = driver_find_device(&omap_iommu_driver.driver, NULL, (void *)name,
|
|
|
|
device_match_by_alias);
|
2011-10-11 06:18:33 +08:00
|
|
|
if (!dev)
|
2014-03-01 04:42:33 +08:00
|
|
|
return ERR_PTR(-ENODEV);
|
2011-10-11 06:18:33 +08:00
|
|
|
|
|
|
|
obj = to_iommu(dev);
|
2009-01-26 21:13:40 +08:00
|
|
|
|
2011-06-02 06:46:12 +08:00
|
|
|
spin_lock(&obj->iommu_lock);
|
2009-01-26 21:13:40 +08:00
|
|
|
|
2011-06-02 06:46:12 +08:00
|
|
|
obj->iopgd = iopgd;
|
|
|
|
err = iommu_enable(obj);
|
|
|
|
if (err)
|
|
|
|
goto err_enable;
|
|
|
|
flush_iotlb_all(obj);
|
|
|
|
|
|
|
|
spin_unlock(&obj->iommu_lock);
|
2009-01-26 21:13:40 +08:00
|
|
|
|
|
|
|
dev_dbg(obj->dev, "%s: %s\n", __func__, obj->name);
|
|
|
|
return obj;
|
|
|
|
|
|
|
|
err_enable:
|
2011-06-02 06:46:12 +08:00
|
|
|
spin_unlock(&obj->iommu_lock);
|
2009-01-26 21:13:40 +08:00
|
|
|
return ERR_PTR(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-06-02 06:46:12 +08:00
|
|
|
* omap_iommu_detach - release iommu device
|
2009-01-26 21:13:40 +08:00
|
|
|
* @obj: target iommu
|
|
|
|
**/
|
2011-08-18 03:57:56 +08:00
|
|
|
static void omap_iommu_detach(struct omap_iommu *obj)
|
2009-01-26 21:13:40 +08:00
|
|
|
{
|
2010-01-09 02:29:05 +08:00
|
|
|
if (!obj || IS_ERR(obj))
|
2009-01-26 21:13:40 +08:00
|
|
|
return;
|
|
|
|
|
2011-06-02 06:46:12 +08:00
|
|
|
spin_lock(&obj->iommu_lock);
|
2009-01-26 21:13:40 +08:00
|
|
|
|
2014-10-23 06:22:19 +08:00
|
|
|
iommu_disable(obj);
|
2011-06-02 06:46:12 +08:00
|
|
|
obj->iopgd = NULL;
|
2011-02-17 03:35:51 +08:00
|
|
|
|
2011-06-02 06:46:12 +08:00
|
|
|
spin_unlock(&obj->iommu_lock);
|
2011-02-17 03:35:51 +08:00
|
|
|
|
2009-01-26 21:13:40 +08:00
|
|
|
dev_dbg(obj->dev, "%s: %s\n", __func__, obj->name);
|
2011-02-17 03:35:51 +08:00
|
|
|
}
|
|
|
|
|
2015-10-03 07:02:44 +08: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;
|
|
|
|
}
|
|
|
|
|
2009-01-26 21:13:40 +08:00
|
|
|
/*
|
|
|
|
* OMAP Device MMU(IOMMU) detection
|
|
|
|
*/
|
2012-12-22 07:05:21 +08:00
|
|
|
static int omap_iommu_probe(struct platform_device *pdev)
|
2009-01-26 21:13:40 +08:00
|
|
|
{
|
|
|
|
int err = -ENODEV;
|
|
|
|
int irq;
|
2011-08-18 03:57:56 +08:00
|
|
|
struct omap_iommu *obj;
|
2009-01-26 21:13:40 +08:00
|
|
|
struct resource *res;
|
2014-10-30 14:29:47 +08:00
|
|
|
struct iommu_platform_data *pdata = dev_get_platdata(&pdev->dev);
|
2014-03-01 04:42:36 +08:00
|
|
|
struct device_node *of = pdev->dev.of_node;
|
2009-01-26 21:13:40 +08:00
|
|
|
|
2014-03-01 04:42:32 +08:00
|
|
|
obj = devm_kzalloc(&pdev->dev, sizeof(*obj) + MMU_REG_SIZE, GFP_KERNEL);
|
2009-01-26 21:13:40 +08:00
|
|
|
if (!obj)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2014-03-01 04:42:36 +08:00
|
|
|
if (of) {
|
|
|
|
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;
|
2014-03-01 04:42:37 +08:00
|
|
|
if (of_find_property(of, "ti,iommu-bus-err-back", NULL))
|
|
|
|
obj->has_bus_err_back = MMU_GP_REG_BUS_ERR_BACK_EN;
|
2014-03-01 04:42:36 +08:00
|
|
|
} else {
|
|
|
|
obj->nr_tlb_entries = pdata->nr_tlb_entries;
|
|
|
|
obj->name = pdata->name;
|
|
|
|
}
|
|
|
|
|
2009-01-26 21:13:40 +08:00
|
|
|
obj->dev = &pdev->dev;
|
|
|
|
obj->ctx = (void *)obj + sizeof(*obj);
|
|
|
|
|
2011-06-02 06:46:12 +08:00
|
|
|
spin_lock_init(&obj->iommu_lock);
|
2009-01-26 21:13:40 +08:00
|
|
|
spin_lock_init(&obj->page_table_lock);
|
|
|
|
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
2014-03-01 04:42:32 +08:00
|
|
|
obj->regbase = devm_ioremap_resource(obj->dev, res);
|
|
|
|
if (IS_ERR(obj->regbase))
|
|
|
|
return PTR_ERR(obj->regbase);
|
2011-03-14 20:28:32 +08:00
|
|
|
|
2015-10-03 07:02:44 +08:00
|
|
|
err = omap_iommu_dra7_get_dsp_system_cfg(pdev, obj);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2009-01-26 21:13:40 +08:00
|
|
|
irq = platform_get_irq(pdev, 0);
|
2014-03-01 04:42:32 +08:00
|
|
|
if (irq < 0)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
err = devm_request_irq(obj->dev, irq, iommu_fault_handler, IRQF_SHARED,
|
|
|
|
dev_name(obj->dev), obj);
|
2009-01-26 21:13:40 +08:00
|
|
|
if (err < 0)
|
2014-03-01 04:42:32 +08:00
|
|
|
return err;
|
2009-01-26 21:13:40 +08:00
|
|
|
platform_set_drvdata(pdev, obj);
|
|
|
|
|
2012-11-20 09:05:51 +08:00
|
|
|
pm_runtime_irq_safe(obj->dev);
|
|
|
|
pm_runtime_enable(obj->dev);
|
|
|
|
|
2014-10-23 06:22:30 +08:00
|
|
|
omap_iommu_debugfs_add(obj);
|
|
|
|
|
2009-01-26 21:13:40 +08:00
|
|
|
dev_info(&pdev->dev, "%s registered\n", obj->name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-22 07:05:21 +08:00
|
|
|
static int omap_iommu_remove(struct platform_device *pdev)
|
2009-01-26 21:13:40 +08:00
|
|
|
{
|
2011-08-18 03:57:56 +08:00
|
|
|
struct omap_iommu *obj = platform_get_drvdata(pdev);
|
2009-01-26 21:13:40 +08:00
|
|
|
|
2014-10-23 06:22:30 +08:00
|
|
|
omap_iommu_debugfs_remove(obj);
|
2009-01-26 21:13:40 +08:00
|
|
|
|
2012-11-20 09:05:51 +08:00
|
|
|
pm_runtime_disable(obj->dev);
|
|
|
|
|
2009-01-26 21:13:40 +08:00
|
|
|
dev_info(&pdev->dev, "%s removed\n", obj->name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-09-11 21:37:36 +08:00
|
|
|
static const struct of_device_id omap_iommu_of_match[] = {
|
2014-03-01 04:42:36 +08:00
|
|
|
{ .compatible = "ti,omap2-iommu" },
|
|
|
|
{ .compatible = "ti,omap4-iommu" },
|
|
|
|
{ .compatible = "ti,dra7-iommu" },
|
2015-10-03 07:02:44 +08:00
|
|
|
{ .compatible = "ti,dra7-dsp-iommu" },
|
2014-03-01 04:42:36 +08:00
|
|
|
{},
|
|
|
|
};
|
|
|
|
|
2009-01-26 21:13:40 +08:00
|
|
|
static struct platform_driver omap_iommu_driver = {
|
|
|
|
.probe = omap_iommu_probe,
|
2012-12-22 07:05:21 +08:00
|
|
|
.remove = omap_iommu_remove,
|
2009-01-26 21:13:40 +08:00
|
|
|
.driver = {
|
|
|
|
.name = "omap-iommu",
|
2014-03-01 04:42:36 +08:00
|
|
|
.of_match_table = of_match_ptr(omap_iommu_of_match),
|
2009-01-26 21:13:40 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void iopte_cachep_ctor(void *iopte)
|
|
|
|
{
|
|
|
|
clean_dcache_area(iopte, IOPTE_TABLE_SIZE);
|
|
|
|
}
|
|
|
|
|
2014-03-08 07:44:38 +08:00
|
|
|
static u32 iotlb_init_entry(struct iotlb_entry *e, u32 da, u32 pa, int pgsz)
|
2012-11-03 03:24:06 +08:00
|
|
|
{
|
|
|
|
memset(e, 0, sizeof(*e));
|
|
|
|
|
|
|
|
e->da = da;
|
|
|
|
e->pa = pa;
|
2014-03-18 09:31:32 +08:00
|
|
|
e->valid = MMU_CAM_V;
|
2014-03-08 07:44:38 +08:00
|
|
|
e->pgsz = pgsz;
|
|
|
|
e->endian = MMU_RAM_ENDIAN_LITTLE;
|
|
|
|
e->elsz = MMU_RAM_ELSZ_8;
|
|
|
|
e->mixed = 0;
|
2012-11-03 03:24:06 +08:00
|
|
|
|
|
|
|
return iopgsz_to_bytes(e->pgsz);
|
|
|
|
}
|
|
|
|
|
2011-06-02 06:46:12 +08:00
|
|
|
static int omap_iommu_map(struct iommu_domain *domain, unsigned long da,
|
2015-07-21 06:33:32 +08:00
|
|
|
phys_addr_t pa, size_t bytes, int prot)
|
2011-06-02 06:46:12 +08:00
|
|
|
{
|
2015-03-26 20:43:09 +08:00
|
|
|
struct omap_iommu_domain *omap_domain = to_omap_domain(domain);
|
2011-08-18 03:57:56 +08:00
|
|
|
struct omap_iommu *oiommu = omap_domain->iommu_dev;
|
2011-06-02 06:46:12 +08:00
|
|
|
struct device *dev = oiommu->dev;
|
|
|
|
struct iotlb_entry e;
|
|
|
|
int omap_pgsz;
|
2014-03-08 07:44:38 +08:00
|
|
|
u32 ret;
|
2011-06-02 06:46:12 +08:00
|
|
|
|
|
|
|
omap_pgsz = bytes_to_iopgsz(bytes);
|
|
|
|
if (omap_pgsz < 0) {
|
|
|
|
dev_err(dev, "invalid size to map: %d\n", bytes);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2015-01-22 21:42:06 +08:00
|
|
|
dev_dbg(dev, "mapping da 0x%lx to pa %pa size 0x%x\n", da, &pa, bytes);
|
2011-06-02 06:46:12 +08:00
|
|
|
|
2014-03-08 07:44:38 +08:00
|
|
|
iotlb_init_entry(&e, da, pa, omap_pgsz);
|
2011-06-02 06:46:12 +08:00
|
|
|
|
2011-08-18 03:57:56 +08:00
|
|
|
ret = omap_iopgtable_store_entry(oiommu, &e);
|
2011-09-03 01:32:31 +08:00
|
|
|
if (ret)
|
2011-08-18 03:57:56 +08:00
|
|
|
dev_err(dev, "omap_iopgtable_store_entry failed: %d\n", ret);
|
2011-06-02 06:46:12 +08:00
|
|
|
|
2011-09-03 01:32:31 +08:00
|
|
|
return ret;
|
2011-06-02 06:46:12 +08:00
|
|
|
}
|
|
|
|
|
2011-11-10 17:32:25 +08:00
|
|
|
static size_t omap_iommu_unmap(struct iommu_domain *domain, unsigned long da,
|
2015-07-21 06:33:32 +08:00
|
|
|
size_t size)
|
2011-06-02 06:46:12 +08:00
|
|
|
{
|
2015-03-26 20:43:09 +08:00
|
|
|
struct omap_iommu_domain *omap_domain = to_omap_domain(domain);
|
2011-08-18 03:57:56 +08:00
|
|
|
struct omap_iommu *oiommu = omap_domain->iommu_dev;
|
2011-06-02 06:46:12 +08:00
|
|
|
struct device *dev = oiommu->dev;
|
|
|
|
|
2011-11-10 17:32:25 +08:00
|
|
|
dev_dbg(dev, "unmapping da 0x%lx size %u\n", da, size);
|
2011-06-02 06:46:12 +08:00
|
|
|
|
2011-11-10 17:32:25 +08:00
|
|
|
return iopgtable_clear_entry(oiommu, da);
|
2011-06-02 06:46:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
omap_iommu_attach_dev(struct iommu_domain *domain, struct device *dev)
|
|
|
|
{
|
2015-03-26 20:43:09 +08:00
|
|
|
struct omap_iommu_domain *omap_domain = to_omap_domain(domain);
|
2011-08-18 03:57:56 +08:00
|
|
|
struct omap_iommu *oiommu;
|
2011-10-11 06:18:33 +08:00
|
|
|
struct omap_iommu_arch_data *arch_data = dev->archdata.iommu;
|
2011-06-02 06:46:12 +08:00
|
|
|
int ret = 0;
|
|
|
|
|
2014-09-05 06:27:29 +08:00
|
|
|
if (!arch_data || !arch_data->name) {
|
|
|
|
dev_err(dev, "device doesn't have an associated iommu\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2011-06-02 06:46:12 +08:00
|
|
|
spin_lock(&omap_domain->lock);
|
|
|
|
|
|
|
|
/* only a single device is supported per domain for now */
|
|
|
|
if (omap_domain->iommu_dev) {
|
|
|
|
dev_err(dev, "iommu domain is already attached\n");
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get a handle to and enable the omap iommu */
|
2011-10-11 06:18:33 +08:00
|
|
|
oiommu = omap_iommu_attach(arch_data->name, omap_domain->pgtable);
|
2011-06-02 06:46:12 +08:00
|
|
|
if (IS_ERR(oiommu)) {
|
|
|
|
ret = PTR_ERR(oiommu);
|
|
|
|
dev_err(dev, "can't get omap iommu: %d\n", ret);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2011-10-11 06:18:33 +08:00
|
|
|
omap_domain->iommu_dev = arch_data->iommu_dev = oiommu;
|
2012-04-19 02:09:41 +08:00
|
|
|
omap_domain->dev = dev;
|
2011-09-14 03:26:29 +08:00
|
|
|
oiommu->domain = domain;
|
2011-06-02 06:46:12 +08:00
|
|
|
|
|
|
|
out:
|
|
|
|
spin_unlock(&omap_domain->lock);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-04-19 02:09:41 +08:00
|
|
|
static void _omap_iommu_detach_dev(struct omap_iommu_domain *omap_domain,
|
2015-07-21 06:33:32 +08:00
|
|
|
struct device *dev)
|
2011-06-02 06:46:12 +08:00
|
|
|
{
|
2011-10-11 06:18:33 +08:00
|
|
|
struct omap_iommu *oiommu = dev_to_omap_iommu(dev);
|
2012-04-19 02:09:41 +08:00
|
|
|
struct omap_iommu_arch_data *arch_data = dev->archdata.iommu;
|
2011-06-02 06:46:12 +08:00
|
|
|
|
|
|
|
/* only a single device is supported per domain for now */
|
|
|
|
if (omap_domain->iommu_dev != oiommu) {
|
|
|
|
dev_err(dev, "invalid iommu device\n");
|
2012-04-19 02:09:41 +08:00
|
|
|
return;
|
2011-06-02 06:46:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
iopgtable_clear_entry_all(oiommu);
|
|
|
|
|
|
|
|
omap_iommu_detach(oiommu);
|
|
|
|
|
2011-10-11 06:18:33 +08:00
|
|
|
omap_domain->iommu_dev = arch_data->iommu_dev = NULL;
|
2012-04-19 02:09:41 +08:00
|
|
|
omap_domain->dev = NULL;
|
2014-10-23 06:22:33 +08:00
|
|
|
oiommu->domain = NULL;
|
2012-04-19 02:09:41 +08:00
|
|
|
}
|
2011-06-02 06:46:12 +08:00
|
|
|
|
2012-04-19 02:09:41 +08:00
|
|
|
static void omap_iommu_detach_dev(struct iommu_domain *domain,
|
2015-07-21 06:33:32 +08:00
|
|
|
struct device *dev)
|
2012-04-19 02:09:41 +08:00
|
|
|
{
|
2015-03-26 20:43:09 +08:00
|
|
|
struct omap_iommu_domain *omap_domain = to_omap_domain(domain);
|
2012-04-19 02:09:41 +08:00
|
|
|
|
|
|
|
spin_lock(&omap_domain->lock);
|
|
|
|
_omap_iommu_detach_dev(omap_domain, dev);
|
2011-06-02 06:46:12 +08:00
|
|
|
spin_unlock(&omap_domain->lock);
|
|
|
|
}
|
|
|
|
|
2015-03-26 20:43:09 +08:00
|
|
|
static struct iommu_domain *omap_iommu_domain_alloc(unsigned type)
|
2011-06-02 06:46:12 +08:00
|
|
|
{
|
|
|
|
struct omap_iommu_domain *omap_domain;
|
|
|
|
|
2015-03-26 20:43:09 +08:00
|
|
|
if (type != IOMMU_DOMAIN_UNMANAGED)
|
|
|
|
return NULL;
|
|
|
|
|
2011-06-02 06:46:12 +08:00
|
|
|
omap_domain = kzalloc(sizeof(*omap_domain), GFP_KERNEL);
|
2015-07-21 06:33:29 +08:00
|
|
|
if (!omap_domain)
|
2011-06-02 06:46:12 +08:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
omap_domain->pgtable = kzalloc(IOPGD_TABLE_SIZE, GFP_KERNEL);
|
2015-07-21 06:33:29 +08:00
|
|
|
if (!omap_domain->pgtable)
|
2011-06-02 06:46:12 +08:00
|
|
|
goto fail_nomem;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* should never fail, but please keep this around to ensure
|
|
|
|
* we keep the hardware happy
|
|
|
|
*/
|
2016-04-05 06:46:20 +08:00
|
|
|
if (WARN_ON(!IS_ALIGNED((long)omap_domain->pgtable, IOPGD_TABLE_SIZE)))
|
|
|
|
goto fail_align;
|
2011-06-02 06:46:12 +08:00
|
|
|
|
|
|
|
clean_dcache_area(omap_domain->pgtable, IOPGD_TABLE_SIZE);
|
|
|
|
spin_lock_init(&omap_domain->lock);
|
|
|
|
|
2015-03-26 20:43:09 +08:00
|
|
|
omap_domain->domain.geometry.aperture_start = 0;
|
|
|
|
omap_domain->domain.geometry.aperture_end = (1ULL << 32) - 1;
|
|
|
|
omap_domain->domain.geometry.force_aperture = true;
|
2011-06-02 06:46:12 +08:00
|
|
|
|
2015-03-26 20:43:09 +08:00
|
|
|
return &omap_domain->domain;
|
2011-06-02 06:46:12 +08:00
|
|
|
|
2016-04-05 06:46:20 +08:00
|
|
|
fail_align:
|
|
|
|
kfree(omap_domain->pgtable);
|
2011-06-02 06:46:12 +08:00
|
|
|
fail_nomem:
|
|
|
|
kfree(omap_domain);
|
|
|
|
out:
|
2015-03-26 20:43:09 +08:00
|
|
|
return NULL;
|
2011-06-02 06:46:12 +08:00
|
|
|
}
|
|
|
|
|
2015-03-26 20:43:09 +08:00
|
|
|
static void omap_iommu_domain_free(struct iommu_domain *domain)
|
2011-06-02 06:46:12 +08:00
|
|
|
{
|
2015-03-26 20:43:09 +08:00
|
|
|
struct omap_iommu_domain *omap_domain = to_omap_domain(domain);
|
2011-06-02 06:46:12 +08:00
|
|
|
|
2012-04-19 02:09:41 +08:00
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
|
2011-06-02 06:46:12 +08:00
|
|
|
kfree(omap_domain->pgtable);
|
|
|
|
kfree(omap_domain);
|
|
|
|
}
|
|
|
|
|
|
|
|
static phys_addr_t omap_iommu_iova_to_phys(struct iommu_domain *domain,
|
2015-07-21 06:33:32 +08:00
|
|
|
dma_addr_t da)
|
2011-06-02 06:46:12 +08:00
|
|
|
{
|
2015-03-26 20:43:09 +08:00
|
|
|
struct omap_iommu_domain *omap_domain = to_omap_domain(domain);
|
2011-08-18 03:57:56 +08:00
|
|
|
struct omap_iommu *oiommu = omap_domain->iommu_dev;
|
2011-06-02 06:46:12 +08:00
|
|
|
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
|
2013-05-31 07:10:38 +08:00
|
|
|
dev_err(dev, "bogus pte 0x%x, da 0x%llx", *pte,
|
2015-07-21 06:33:32 +08:00
|
|
|
(unsigned long long)da);
|
2011-06-02 06:46:12 +08:00
|
|
|
} 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
|
2013-05-31 07:10:38 +08:00
|
|
|
dev_err(dev, "bogus pgd 0x%x, da 0x%llx", *pgd,
|
2015-07-21 06:33:32 +08:00
|
|
|
(unsigned long long)da);
|
2011-06-02 06:46:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-03-01 04:42:38 +08:00
|
|
|
static int omap_iommu_add_device(struct device *dev)
|
|
|
|
{
|
|
|
|
struct omap_iommu_arch_data *arch_data;
|
|
|
|
struct device_node *np;
|
2014-09-05 06:27:30 +08:00
|
|
|
struct platform_device *pdev;
|
2014-03-01 04:42:38 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
|
2014-09-05 06:27:30 +08:00
|
|
|
pdev = of_find_device_by_node(np);
|
|
|
|
if (WARN_ON(!pdev)) {
|
|
|
|
of_node_put(np);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2014-03-01 04:42:38 +08:00
|
|
|
arch_data = kzalloc(sizeof(*arch_data), GFP_KERNEL);
|
|
|
|
if (!arch_data) {
|
|
|
|
of_node_put(np);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2014-09-05 06:27:30 +08:00
|
|
|
arch_data->name = kstrdup(dev_name(&pdev->dev), GFP_KERNEL);
|
2014-03-01 04:42:38 +08:00
|
|
|
dev->archdata.iommu = arch_data;
|
|
|
|
|
|
|
|
of_node_put(np);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
kfree(arch_data->name);
|
|
|
|
kfree(arch_data);
|
|
|
|
}
|
|
|
|
|
2014-06-27 15:03:12 +08:00
|
|
|
static const struct iommu_ops omap_iommu_ops = {
|
2015-03-26 20:43:09 +08:00
|
|
|
.domain_alloc = omap_iommu_domain_alloc,
|
|
|
|
.domain_free = omap_iommu_domain_free,
|
2011-06-02 06:46:12 +08:00
|
|
|
.attach_dev = omap_iommu_attach_dev,
|
|
|
|
.detach_dev = omap_iommu_detach_dev,
|
|
|
|
.map = omap_iommu_map,
|
|
|
|
.unmap = omap_iommu_unmap,
|
2014-10-26 00:55:16 +08:00
|
|
|
.map_sg = default_iommu_map_sg,
|
2011-06-02 06:46:12 +08:00
|
|
|
.iova_to_phys = omap_iommu_iova_to_phys,
|
2014-03-01 04:42:38 +08:00
|
|
|
.add_device = omap_iommu_add_device,
|
|
|
|
.remove_device = omap_iommu_remove_device,
|
2011-11-10 17:32:27 +08:00
|
|
|
.pgsize_bitmap = OMAP_IOMMU_PGSIZES,
|
2011-06-02 06:46:12 +08:00
|
|
|
};
|
|
|
|
|
2009-01-26 21:13:40 +08:00
|
|
|
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 */
|
2015-02-06 18:44:06 +08:00
|
|
|
struct device_node *np;
|
|
|
|
|
|
|
|
np = of_find_matching_node(NULL, omap_iommu_of_match);
|
|
|
|
if (!np)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
of_node_put(np);
|
2009-01-26 21:13:40 +08:00
|
|
|
|
|
|
|
p = kmem_cache_create("iopte_cache", IOPTE_TABLE_SIZE, align, flags,
|
|
|
|
iopte_cachep_ctor);
|
|
|
|
if (!p)
|
|
|
|
return -ENOMEM;
|
|
|
|
iopte_cachep = p;
|
|
|
|
|
2011-09-06 23:56:07 +08:00
|
|
|
bus_set_iommu(&platform_bus_type, &omap_iommu_ops);
|
2011-06-02 06:46:12 +08:00
|
|
|
|
2014-10-23 06:22:30 +08:00
|
|
|
omap_iommu_debugfs_init();
|
|
|
|
|
2009-01-26 21:13:40 +08:00
|
|
|
return platform_driver_register(&omap_iommu_driver);
|
|
|
|
}
|
2012-02-26 18:14:14 +08:00
|
|
|
subsys_initcall(omap_iommu_init);
|
2015-07-21 06:33:24 +08:00
|
|
|
/* must be ready before omap3isp is probed */
|