iommu: undo HTC IOMMU changes
msm_fb: display: Add IOMMU support to MDP and rotator driver

Add IOMMU support to MDP and rotator driver for operating with
virtual addresses instead of physical addresses

Change-Id: Ia5afcf33220e0e75e92948649c2bd4d7ef32917d
Signed-off-by: Ravishangar Kalyanam <rkalya@codeaurora.org>

Conflicts:
	drivers/char/msm_rotator.c
	drivers/video/msm/msm_fb.c
	include/linux/msm_mdp.h
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.

Change-Id: I6ffb43f43eaa0e3e6b5a43f01b31d83d3effd970
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
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.

Change-Id: I5d35dbab38a4be66eb464fee42e0e844404d5cf7
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
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.

Change-Id: I58e8325e29bde3efbafe8a545b16255551bb9d66
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
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: I8b2871538c05986811fb565f9ebf1344e848cc10
Signed-off-by: Deepak Kotur <dkotur@codeaurora.org>

Conflicts:
	drivers/video/msm/vidc/1080p/resource_tracker/vcd_res_tracker.c
	drivers/video/msm/vidc/common/dec/vdec.c
	drivers/video/msm/vidc/common/init/vidc_init.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: Ic3152e63686b51ba8768dbf38a9d9f7fdec1a963
Signed-off-by: Deepak Kotur <dkotur@codeaurora.org>

Conflicts:
	drivers/video/msm/vidc/1080p/ddl/vcd_ddl.c
	drivers/video/msm/vidc/1080p/ddl/vcd_ddl_helper.c
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: Ib1f4005bae1778f68d228bd3c798457c7c15d83d
Signed-off-by: Deepak Kotur <dkotur@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: Idf152429316cec2eec8417d72160b7bd53488fc4
Signed-off-by: Deepak Kotur <dkotur@codeaurora.org>

Conflicts:
	drivers/video/msm/vidc/common/dec/vdec.c
	drivers/video/msm/vidc/common/init/vidc_init.c
	include/media/msm/vcd_api.h
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: I8e39fb3bfb7f68df167b9432fbc008980e28742e
Signed-off-by: Deepak Kotur <dkotur@codeaurora.org>

Conflicts:
	drivers/video/msm/vidc/common/init/vidc_init.c
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.

Change-Id: I5dd70096edcab4866a436ae4447f9a6e00e2f0ec
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
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.

Change-Id: Id1fc19e2c3af18ced028132d1a1bdb6a3935380f
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
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.

Change-Id: I2b676dbe32372b3c17e4aaf39f51878b105a699c
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
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.

Change-Id: Ie184e4a6dbec2bc3dff75ab3b25985fd64e2baac
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
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.

Change-Id: Idaeae269d9ba623e25a0cb087a89b4cbb63915af
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
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.

Change-Id: Ic63a24bf651d613933633cd81143701f66df566c
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
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.

Change-Id: I1241f952359f6bb1d5bb0deb11cc0f44d94a3404
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
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.

Change-Id: I49a84dca613b7c209dde03b67b2fc1b2c9d844dd
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
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.

Change-Id: If5723f0d7ec1145e9c9d8b88a42b57ab0f2c2da7
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
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>