iommu/omap: Correct init value of iotlb_entry valid field

The iotlb_entry field values are used directly in omap2_alloc_cr,
a function used in preparing the MMU_CAM and MMU_RAM registers.
The iotlb_entry.valid value is being set incorrectly to 1 at the
moment, and this would result in overriding the PAGESIZE bit field
of the MMU_CAM register if prefetching of the entries were to be
supported.

The bug has not caused any MMU faults due to incorrect size
programming so far as the prefetching is disabled by default. Fix
this by using the correct init value for the iotlb_entry.valid
field.

Signed-off-by: Suman Anna <s-anna@ti.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
[s-anna@ti.com: cherry-pick commit 'd760e3e' from v3.16]
Signed-off-by: Suman Anna <s-anna@ti.com>
iommu/omap: Remove omap_iommu_domain_has_cap() function

The current OMAP IOMMU ops for .domain_has_cap is a stub,
and the iommu core already returns a value of 0 if the
domain doesn't have a .domain_has_cap ops plugged in. So,
clean up this stub function.

Signed-off-by: Suman Anna <s-anna@ti.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
[s-anna@ti.com: cherry-pick commit '2ac6133' from v3.16]
Signed-off-by: Suman Anna <s-anna@ti.com>
iommu/omap: Move to_iommu definition from omap-iopgtable.h

The to_iommu definition is used only locally to the omap-iommu.c
source file, and it has nothing to do with the page attributes
defined in omap-iopgtable.h. So, move the definition out of
omap-iopgtable.h header file.

Signed-off-by: Suman Anna <s-anna@ti.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
[s-anna@ti.com: cherry-pick commit '5acc97d' from v3.16]
Signed-off-by: Suman Anna <s-anna@ti.com>
iommu/omap: Fix 'no page for' debug message in flush_iotlb_page()

The flush_iotlb_page() function prints a debug message when no
corresponding page was found in the TLB. That condition is incorrectly
checked and always resolves to true, given that the for_each_iotlb_cr()
loop is never interrupted and always reaches obj->nr_tlb_entries.

Given that we can't have two TLB entries for the same VA, break from the
loop when a match is found.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Suman Anna <s-anna@ti.com>
[s-anna@ti.com: cherry-pick commit 'f7129a0' from v3.16]
Signed-off-by: Suman Anna <s-anna@ti.com>
iommu/omap: Remove comment about supporting single page mappings only

The IOMMU core breaks out mappings into pages already, there's no
need to support mapping multiple pages in one go.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Sakari Ailus <sakari.ailus@iki.fi>
[s-anna@ti.com: cherry-pick commit '67b779d' from v3.16]
Signed-off-by: Suman Anna <s-anna@ti.com>
iommu/omap: Fix map protection value handling

The prot flags passed to the IOMMU map handler are defined in
include/linux/iommu.h as IOMMU_(READ|WRITE|CACHE|EXEC). However, the
driver expects to receive MMU_RAM_* OMAP-specific flags. This causes
IOMMU flags being interpreted as page sizes, leading to failures.

Hardcode the OMAP mapping parameters to little-endian, 8-bits and
non-mixed page attributes. Furthermore, as the OMAP IOMMU doesn't
support read-only or write-only mappings, ignore the prot value.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Sakari Ailus <sakari.ailus@iki.fi>
Acked-by: Suman Anna <s-anna@ti.com>
[s-anna@ti.com: cherry-pick commit '286f600' from v3.16]
Signed-off-by: Suman Anna <s-anna@ti.com>
of: document bindings for reserved-memory nodes

Reserved memory nodes allow for the reservation of static (fixed
address) regions, or dynamically allocated regions for a specific
purpose.

[joshc: Based on binding document proposed (in non-patch form) here:
 http://lkml.kernel.org/g/20131030134702.19B57C402A0@trevor.secretlab.ca
 adapted to support #memory-region-cells]
Signed-off-by: Josh Cartwright <joshc@codeaurora.org>
[mszyprow: removed #memory-region-cells property]
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
[grant.likely: removed residual #memory-region-cells example]
Signed-off-by: Grant Likely <grant.likely@linaro.org>
[s-anna@ti.com: cherry-pick commit 'f08ad1d' from v3.15]
Signed-off-by: Suman Anna <s-anna@ti.com>
drivers: of: add initialization code for static reserved memory

This patch adds support for static (defined by 'reg' property) reserved
memory regions declared in device tree.

Memory blocks can be reliably reserved only during early boot. This must
happen before the whole memory management subsystem is initialized,
because we need to ensure that the given contiguous blocks are not yet
allocated by kernel. Also it must happen before kernel mappings for the
whole low memory are created, to ensure that there will be no mappings
(for reserved blocks). Typically, all this happens before device tree
structures are unflattened, so we need to get reserved memory layout
directly from fdt.

Based on previous code provided by Josh Cartwright <joshc@codeaurora.org>

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Grant Likely <grant.likely@linaro.org>
[s-anna@ti.com: cherry-pick commit 'e8d9d1f' from v3.15]
Signed-off-by: Suman Anna <s-anna@ti.com>
drivers: of: add initialization code for dynamic reserved memory

This patch adds support for dynamically allocated reserved memory regions
declared in device tree. Such regions are defined by 'size', 'alignment'
and 'alloc-ranges' properties.

Based on previous code provided by Josh Cartwright <joshc@codeaurora.org>

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Grant Likely <grant.likely@linaro.org>
[s-anna@ti.com: cherry-pick commit '3f0c820' from v3.15]
Signed-off-by: Suman Anna <s-anna@ti.com>
drivers: of: add support for custom reserved memory drivers

Add support for custom reserved memory drivers. Call their init() function
for each reserved region and prepare for using operations provided by them
with by the reserved_mem->ops array.

Based on previous code provided by Josh Cartwright <joshc@codeaurora.org>

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Grant Likely <grant.likely@linaro.org>
[s-anna@ti.com: cherry-pick commit 'f618c47' from v3.15]
Signed-off-by: Suman Anna <s-anna@ti.com>
arm: add support for reserved memory defined by device tree

Enable reserved memory initialization from device tree.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Grant Likely <grant.likely@linaro.org>
[s-anna@ti.com: cherry-pick commit 'bcedb5f' from v3.15]
Signed-off-by: Suman Anna <s-anna@ti.com>
arm64: add support for reserved memory defined by device tree

Enable reserved memory initialization from device tree.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Grant Likely <grant.likely@linaro.org>
[s-anna@ti.com: cherry-pick commit '9bf14b7' from v3.15]
Signed-off-by: Suman Anna <s-anna@ti.com>
powerpc: add support for reserved memory defined by device tree

Enable reserved memory initialization from device tree.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Grant Likely <grant.likely@linaro.org>
[s-anna@ti.com: cherry-pick commit '708b7ee' from v3.15]
Signed-off-by: Suman Anna <s-anna@ti.com>
of: only scan for reserved mem when fdt present

When the reserved memory patches hit -next, several legacy (non-DT) boot
failures were detected and bisected down to that commit. There needs to
be some sanity checking whether a DT is even present before parsing the
reserved ranges.

Reported-by: Kevin Hilman <khilman@linaro.org>
Signed-off-by: Josh Cartwright <joshc@codeaurora.org>
Tested-by: Kevin Hilman <khilman@linaro.org>
Signed-off-by: Grant Likely <grant.likely@linaro.org>
[s-anna@ti.com: cherry-pick commit '2040b52' from v3.15]
Signed-off-by: Suman Anna <s-anna@ti.com>
of: Fix the section mismatch warnings.

In tag next-20140407, building with CONFIG_DEBUG_SECTION_MISMATCH
enabled, the following WARNING is occured:

WARNING: drivers/built-in.o(.text.unlikely+0x2220): Section mismatch
in reference from the function __reserved_mem_check_root() to the
function .init.text:of_get_flat_dt_prop()
The function __reserved_mem_check_root() references
the function __init of_get_flat_dt_prop().
This is often because __reserved_mem_check_root lacks a __init
annotation or the annotation of of_get_flat_dt_prop is wrong.

WARNING: vmlinux.o(.text.unlikely+0xb9d0): Section mismatch in reference
from the function __reserved_mem_check_root() to the (unknown reference)
.init.data:(unknown)
The function __reserved_mem_check_root() references
the (unknown reference) __initdata (unknown).
This is often because __reserved_mem_check_root lacks a __initdata
annotation or the annotation of (unknown) is wrong.

This is cause by :
'drivers: of: add initialization code for dynamic reserved memory'.

Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com>
Signed-off-by: Rob Herring <robh@kernel.org>
[s-anna@ti.com: cherry-pick commit '5b62411' from v3.15]
Signed-off-by: Suman Anna <s-anna@ti.com>
iommu/omap: Use PAGE_ALIGNED instead of IS_ALIGNED(PAGE_SIZE)

use mm.h definition

Cc: Joerg Roedel <joro@8bytes.org>
Cc: iommu@lists.linux-foundation.org
Signed-off-by: Fabian Frederick <fabf@skynet.be>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
[s-anna@ti.com: cherry-pick commit '0f19889' from v3.17]
Signed-off-by: Suman Anna <s-anna@ti.com>
iommu/omap: check for valid archdata in attach_dev

A device is tied to an iommu through its archdata field, any device
requiring to be attached to an iommu_domain must have valid archdata
containing the necessary iommu information. This archdata information
to be added is SoC-specific. Add a check in the omap_iommu_attach_dev
to make sure that the device has non-NULL archdata before accessing
different SoC-specific fields of the archdata. This prevents a NULL
pointer dereference on any misconfigured devices.

Signed-off-by: Suman Anna <s-anna@ti.com>
iommu/omap: fix iommu archdata name for DT-based devices

A device is tied to an iommu through its archdata field. The archdata
is allocated on the fly for DT-based devices automatically through the
.add_device iommu ops. The current logic assigns the name of the IOMMU
user device, instead of the name of the IOMMU device as required by
the attach logic. Fix this issue so that DT-based devices can attach
successfully to an IOMMU domain.

Signed-off-by: Suman Anna <s-anna@ti.com>
iommu/omap: add cache flushing operation for L2 cache

Signed-off-by: Ramesh Gupta <grgupta@ti.com>
Signed-off-by: Hari Kanigeri <h-kanigeri2@ti.com>
iommu/omap: dmm fixes

This fixes the following:
  1. pgd and pte entries weren't getting flushed out leading to MMU faults.
  2. Cache invalidate was setting wrong size parameter to
     memory_regain_ownership leading cache invalidate function to fail.

Signed-off-by: Hari Kanigeri <h-kanigeri2@ti.com>