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: undo HTC ION changes
gpu: ion: Change from uncached to buffered mapping

PMEM uses buffered mappings when PMEM device is
opened with O_SYNC flag. ION should have the same
behavior as PMEM.

Change ION to provide buffered mappings instead
of uncached when the O_DSYNC flag is used when
opening the ION device.

CRs-fixed: 335827
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
(cherry picked from commit de074a7d5ba87d1bd7ed2fe445da9a0f33cb9a30)

Change-Id: I429411ffd3a9681c5e394fa47f571845e87d1b04
Signed-off-by: Swetha Basineni <sbasin@codeaurora.org>
gpu: ion: Move MFC heap to different address

Video hardware has the following requirements for
ION heaps:

1. MM heap must be at a higher address than FW heap.
2. MFC heap must at a higher address than FW
3. MM heap must be adjacent to FW heap.
   (There cannot be another heap between FW and MM heap)
4. MM and MFC heap cannot be more than 256MB away
   from the base address of the FW heap.

MM heap is configured as a reusable heap (FMEM heap) and FMEM
is carved out at a much higher address than the other heaps breaking
the above requirements. To support the above requirements the
MFC heap together with the FW heap must be carved out at the same
location as MM heap.

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

Change-Id: Ibb53c0e17f1545e2ec5258c01e01101d68c209e1
Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>

Conflicts:
	arch/arm/mach-msm/board-8960.c
ion: support creation of mm heap in a fixed place

The multimedia firmware on 8960 will always be
loaded into a fixed address, and all callers into
this firmware must be no more than 256M above the
start of this firmware.

This implies that the the mm ION heap and its associated heaps
(mm_fw and mfc) must also be created in a fixed place.

This version of the patch keeps the mm fw heap size
to 2M for compatibility with the current tip. This
will eventually be reduced to 1M.

Change-Id: I35f89b8c60165fb0adbb9d04412e0e200117beb9
Signed-off-by: Larry Bassel <lbassel@codeaurora.org>
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>

Conflicts:
	arch/arm/mach-msm/board-8960.c
gpu: ion: set dma_address for contiguous heaps in ion_map_dma()

Ion carveout and content protect heap buffers do not
have a struct page associated with them. Thus
sg_phys() will not work reliably on these buffers,
so set dma_address on their scatterlists.

CRs-Fixed: 345257
Change-Id: Ifdad5ce497de170f47b4ee2f7a93563a5cbe1a96
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
(cherry picked from commit d01042d0806af5a912bebf8c2ec44cc0158b8546)
gpu: ion: Fix fragmentation message log condition

If an ion allocation fails because of memory fragmentation a debug
message should be printed. However, the logic that decides whether
the debug message should be printed or not is incorrect causing
the debug message to not be printed when it should.

CRs-fixed: 359593
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
(cherry picked from commit 099501a01beda17a8b5be3ebc13d51791d96a269)

Change-Id: Ic91b9e97852b37461f4df503b2940714a344bdc2
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>
gpu: ion: Leave fmem in c-state until unsecured

When the last buffer is freed from a heap that uses fmem we call
into fmem to transition the memory from c-state to t-state. However,
if the heap has been secured for content protection transitioning
the memory from c-state to t-state could cause undefined behavior
in fmem.

Add checks to ensure that a secured heap will not transition to
t-state until heap is unsecured.

CRs-fixed: 359593
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
(cherry picked from commit 20f3b6d7591986db8ff46a7f7e333b3c30db04e8)

Change-Id: I0d58b82bb119f4d621a3ddf1891dc477322ad532
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>
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)
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: 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)
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: 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: 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)
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)