video: msm: wfd: IOMMU migration

Migrate WFD to IOMMU APIs.  Commit contains following changes:
- Switch from allocate buffer model to use buffer model in order
  to have the flexibility to map buffers into seperate domains.
- Use the ION caching APIs to flush buffers in case they are cached.
  Earlier on, we used uncached buffers, hence we didn't have a need
  to flush.

Change-Id: I959027ee94a5d6074005f1de420c66cbe55db776
Signed-off-by: Deva Ramasubramanian <dramasub@codeaurora.org>
(cherry picked from commit 0807032a1e6c99cfc365324ec0550a553308092c)
(cherry picked from commit d7dfa4c700df06351c780a08f35167199ccef922)
video: msm: writeback: Stop providing buffers to mdp in stopping state

After writeback_stop() is called, we continue providing buffers to mdp
until the free queue is completely exhausted.  However, client can
deallocate buffers immediately after writeback_stop() is called, this
will trigger page faults from mdp accessing invalid buffers.

Change-Id: I007c10b3b9a4ddeca49b7e38ff04833a26560931
Signed-off-by: Deva Ramasubramanian <dramasub@codeaurora.org>
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>
(cherry picked from commit 0ea697d800ea0760334204ad2f828f6cba0f7995)
(cherry picked from commit 67fe55a5c714529940fe2170088050b7e249decb)
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: 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)