vidc: Migrate to ion_map_iommu() API.

Migrate video driver to use the ion_map_iommu() api,
this api provides the physical address if IOMMU is
not enabled.
If IOMMU is enabled in the system it provides the
virtual contigious address.

Change-Id: I0f6f7c50865cb3da88a0ee13425e3973037c846a
Signed-off-by: Arun Menon <menon@codeaurora.org>

Conflicts:

	drivers/video/msm/vidc/common/dec/vdec.c
vidc: Move shared memory to firmware heap

if smmu is enabled then the memory needs to be
mapped as cached for IOMMU heap, moving the
shared mmeory to firmware heap which does not
require cached mapping

Change-Id: Iac14169b1063bd2784ebf7df433614d68830e84a
Signed-off-by: Arun Menon <menon@codeaurora.org>
vidc: Move metadata shared input mem to firmware heap.

Metadata shared input is used to communicate between
the video code and video driver, hence make this buffer
as uncached and allocate it from firmware heap.

Change-Id: Iabcf6fdbdf6ebcae2fef60b9163a3dfa862624f6
Signed-off-by: Arun Menon <menon@codeaurora.org>
vidc: Migrate to new ION cache ops API

New cache ops API are provided thru ION interface
migrating the in kernel cache ops to use the
new cache ops API.

Change-Id: I18502d343c40fc0f36d979898939f0e601e2f685
Signed-off-by: Arun Menon <menon@codeaurora.org>
vidc: For CP2.0 do not program the iommu.

For CP2.0 do not call the ion_map_iommu api
use the ion_phys api to get the physical address

Change-Id: I67ebc8debf064afb78133afe75aee368b6394178
Signed-off-by: Arun Menon <menon@codeaurora.org>
msm: camera: add fields to msm_stats_buf for cache operations.

Add a couple of fields to the msm_stats_buf structure
for cache coherence support on stats buffers from
user-space.

(cherry picked from commit 073e0cab00d6cf60279de167d8063c5e5f4b5715)

Change-Id: I4358bb9f8fff444d9879e351af29e47513d114ed
Signed-off-by: Ankit Premrajka <ankitp@codeaurora.org>
(cherry picked from commit 490e18c8ccde8c4450d20781faf7529c8c9d1512)
(cherry picked from commit 1467469bb4783e9fd18f2081b2c3eb044815e22b)
gpu: ion: Add support for IOMMU in CP heap

ION clients allocating from a content protection
heap (cp heap) must be able to map the memory to
an IOMMU when IOMMU are being used.

Add callbacks to CP heap to support IOMMU mapping.

(cherry picked from commit 1c94f7be2d3fcd48978bd5276532beec184f5d74)

Change-Id: I81e726e98b8cc4b12fe8f4734c0da18a15968aee
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
(cherry picked from commit c8652e6b9a8e477513cf1f10563182a400b7cc65)
msm: Disable use of the IOMMU

Originally, if CONFIG_MSM_IOMMU was enabled, clients were
expected to use the iommu for memory mapping. Currently,
it is necessary for CONFIG_MSM_IOMMU to be enabled without
having all clients ready to use the iommu. Kill support for
APIs to use the IOMMU and attaching to all domains until
clients are ready to actually use them.

(cherry picked from commit d561f347895358028851dfa52397899048747a6d)

Change-Id: Ic7189c713722bb00cb556a3a1b01df41372a321e
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
(cherry picked from commit d813a2df8c1c3409020a8b7009dd790527b8a09f)
gpu: ion: Lower IOMMU heap priority

Video requires the IOMMU heap to be at a lower
priority so that video can try to allocate from
its MM carveout heap first and then if video needs
more memory and the MM heap is exhausted it will
automatically fall back on IOMMU heap.

Change the priority of the IOMMU heap so video
can fall back on IOMMU heap.

(cherry picked from commit 9e123f98ea133518adb5b1f4a53ccaa1c07cb568)

Change-Id: I696c292b0ad9d6b140247f32e2e22d72c5fd0000
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
(cherry picked from commit 1c94ada9be7922d8770c92cd79217ebf005fbf27)
(cherry picked from commit cb1cf4a5f754932b9c8e19eeaf90114a2b35c51b)
msm: Add new partition for IOMMU video domain

Video hardware requires its firmware address to be lower
than the the other addresses that it accesses. In addition
secure playback requires the end of the firmware address
range to be adjacent to the main memory used by the video
hardware.

Add a new partition and rename partitions to appropriate names
to enforce the order of the memory regions.

(cherry picked from commit ee365366b99d0f5f51ff27f9fe7637a792042417)

Change-Id: Ide78cddb45373b456d5efdc2b7c7fe65fd20b29d
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
(cherry picked from commit 3cbb57653580cd5dc30100cb6203c7d0e5c3141f)
gpu: ion: Add missing argument to iommu map func

There exists one definition for ion_map_iommu
function when ION is enabled and one definition when
ION is disabled. The argument list for the definition used
when ION is disabled is missing the buffer_size argument causing
compilation error for targets that call this function without
ION enabled.

Add buffer_size argument to ion_map_iommu function
for targets that does not have ION enabled.

(cherry picked from commit 9a27d4c55b862eecc1c5eacb7fc0185957b851a0)

Change-Id: I135f748ef61ece79c2c61c1e1e2478bb7174c61c
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
(cherry picked from commit 70371b7cf9d0b280178c26dfbd95e649d2fbfdb9)
gpu: ion: Do not allow cached IOMMU mappings.

Cached IOMMU mapping is not supported.

Add check for clients trying to map buffers
into IOMMU as cached and return error.

(cherry picked from commit 79e9ffa55afdf664990b2765de297f3d95e59612)

Change-Id: I92bde98a816afb2c3b231e91902b4443774c2b85
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
(cherry picked from commit 82836cc1818a9a428e5acfbb4f9b62f5892f75fe)
gpu: ion: Add API to do cache operations

Clients need to be able to do cache operations
on ION buffers in the kernel. Add API to
flush, invalidate, or invalidate and flush the
cache of an ION buffer.

(cherry picked from commit 41f8579a79c1a6513577465cd376fb5b1bf4cab2)

Change-Id: I9a00fec1bd891f730b448d06f10be07bd79b3011
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
(cherry picked from commit 74c2772e4e6b4ed695cd5b69c024c86a2bdcdd88)
gpu: ion: Allow smaller mappings

Clients using ION must be able to mmap a smaller
set of pages than what was allocated from the
IOMMU heap.

Add check that we don't try to map a page passed
the end of the vma.

(cherry picked from commit dbec7db15ddbf7d9b529077ffa61b9b2c30b33a0)

Change-Id: Iaf63a1099510ec4cdbcd294762b451037fe7784a
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
(cherry picked from commit 9c2eabefcb4e745b0c8f3bd90ee5fed742fc0e93)
(cherry picked from commit d2d1934c322f18e59e83eb501e8ad22f8e6ba648)
gpu: ion: Add cache operations to IOMMU heap

The IOMMU heap must support cache operations so that clients
can do cached allocations from the heap.

Add function to perform cache operations on memory
allocated from IOMMU heap.

(cherry picked from commit ef0107124e052b86ce883ee6b0c1488d26de0775)

Change-Id: I59a6c6949432cc783b4bd3d7bd212da35bfe73ff
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
(cherry picked from commit 398f5c2d05c5eb8a004bc9a3489e586b345b3d4e)
gpu: ion: Add map_dma support in IOMMU heap

IOMMU is missing support for ion_map_dma.
ION clients need support for this api.

Add functions to implement ion_map_dma and
ion_unmap_dma in the IOMMU heap.

(cherry picked from commit ab804b883a58c44df40e92940ac4dae3a91e7beb)

Change-Id: I2f2664b07d7a8c42ff8c915fa23ce159a84899ed
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
(cherry picked from commit c78083f5a1e505325e3e355b36def763a5cd05c4)
gpu: ion: Delay unmapping from IOMMU.

Due to limitations in the multimedia architecure
clients might not know when a buffer can be unmapped
from the IOMMU. In addition, the multimedia architecture
causes unnecessary mappings/unmappings for the same buffers
which reduces framerates.

Add logic to delay unmapping from the IOMMU
until buffer memory is freed and unmap any outstanding
mappings to avoid virtual memory address space leak.

(cherry picked from commit b36765960a60150af1c0faea0e0535123d40f90e)

Change-Id: Ic19d79328c48ea5a22bc7ac7f0bd6c54fb9de543
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
(cherry picked from commit d480e12d368915922b4f3d0b2dcd7d1852f2556a)
msm: Define 4 domains for IOMMU

Define one domain each for video, camera,
display, and rotator. Having separate domains
makes programming the IOMMU by the different subsystems
more efficient.

(cherry picked from commit ab77b1b6341e20760ada76e1735614d64594bb0b)

Change-Id: I98aafb6f6ef578599f2745fccf21e0c94077a865
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
(cherry picked from commit 15e8a68f711f0091f0e9655135298a3c9fbfeac5)
gpu: ion: Map a range into the IOMMU

Instead of mapping 1 4K page at a time into the IOMMU create a
scatterlist and map everything at once. This will be more efficient.

(cherry picked from commit 16cdb41acb58dc352994e9b27a9344b1337b0c46)

Change-Id: I8488cc8e6d013d1e62c6ea5fcfc2425384daefe9
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
(cherry picked from commit 8ddf658dc1a93a91eacf8d47779710ff860337aa)
iommu: Fix flags passed to iommu map functions.

iommu map functions requires clients to specify whether
the mappings should be read only or read-write (write only
is not supported). Ensure clients specify the appropriate
flags when calling map functions.

Change-Id: If42b4b0367b4311aa36d3063979ef04af3a43fc6
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
(cherry picked from commit bcf5ae04a9bf744a7a3d119c93d439a682404877)