gpu: ion: add missing parameter in secure CMA Ion heap

msm_iommu_map_extra recently gained another parameter. Add this
missing parameter to the secure CMA Ion heap which missed out on this
new parameter.

Change-Id: I25403acfeb4caf9356ecc290108dd47e84ebf418
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
gpu: ion: suppress excessive logging for expected failure cases

We expect alloc_pages to fail for high-order pages under stressed
memory conditions. It should then fall back to lower-order page
allocations but due to excessive logging the system crashes. Use
__GFP_NOWARN for high-order allocations to avoid excessive logging.

CRs-Fixed: 454877
Change-Id: Ie18c2dddd6810038abad9b06c7838ff4a0844b6d
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
gpu: ion: make cached Iommu allocations multiples of PAGE_SIZE

In future changes to Ion, we will fault in the pages one at a time
using vm_insert_page for cached allocations. There appears to be a
limitation on vm_insert_page that the pages must be of size
PAGE_SIZE. Make sure that we only allocate pages of size PAGE_SIZE for
cached allocations.

Change-Id: I2243e73c4f50b90c9345c25b9e4bc30ccfa7e198
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
gpu: ion: make cached cp allocations multiples of PAGE_SIZE

New alignment requirements in Ion require all cached allocations to be
multiples of PAGE_SIZE. Update the cp heap to follow the new
requirements.

Change-Id: I88ddf55966ccba3a00da99559b1ff4a3b6e86ce5
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
gpu: ion: check for leaks in ion_client_destroy

If an ion client is destroyed without destroying all handles created
by that client, there will be leaked buffers. Print a message if this
happens.

Change-Id: Id674f508666d506b3a9ee848adbc29435c5fe8c2
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>

Conflicts:
	include/linux/ion.h
gpu: ion: remove stale variable

Tracking the number of user mappings should be done in the Ion
heaps. Remove the variable that was used to track this in core Ion.

Change-Id: I715280515e3010bd002314aefe0ec8cdb37c143d
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
gpu: ion: Remove get_flags ioctl

There are no callers of the get flags ioctl. Remove it
before anyone tries to use it again.

Change-Id: I857ef705fc864cce49f671124b96bd9f47b66ab2
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
gpu: ion: Use %pa to print physical addresses

Using the %p format specifier for printing physical
addresses results in compilation errors when LPAE support
is enabled.

Change-Id: I93fcc75fce606fe9b4b129a46ef217f22de22418
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
gpu: ion: Switch MM heap to use CMA on DT targets

The MM heap is now dedicated for secure use cases.
Switch it over to use CMA for allocations instead of
the carveout heaps.

Change-Id: Ic110f3b34b3b1280efd3d6784a9242dcf8c627c2
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>

Conflicts:
	arch/arm/boot/dts/msm8974-ion.dtsi
	arch/arm/boot/dts/msm8974.dtsi
arm/dt: msm8974: Add aDSP heap

8974 based targets have a use case for memory to be used with
the DSP for post processing. Add a dedicated Ion heap for this
use case.

Change-Id: I481c26b6621f68511acf08b0f4ed31933ccca234
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>

Conflicts:
	arch/arm/boot/dts/msm8974.dtsi
gpu: ion: use ion_phys_addr_t where appropriate

ion_phys_addr_t should be used for physical addresses from
Ion. Change clients where appropriate.

Change-Id: Iea365b8ca008732dc21e4fe7f38d7b6ab240f906
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>

Conflicts:
	sound/soc/msm/qdsp6v2/audio_acdb.c
gpu: ion: Properly print out physical addresses

Ion physical addresses may be phys_addr_t underneath.
Use proper printing mechanisms to print the addresses
out.

Change-Id: I74e1b583f9360d7046a8f2e1fba4d3831ccb5c08
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>

Conflicts:
	drivers/video/msm/mdss/mdss_mdp_overlay.c
msm: scm: change svc id SCM_SVC_CP to a more generic SCM_SVC_MP

The svc id 0xC is defined as SVC_MEMORY_PROTECTION. Content protection
is one use case for this svc id. Change the name SCM_SVC_CP to
SCM_SVC_MP so that it applies to other usecases as well.

Change-Id: Ia91a9a34940d022aaacc0019fa65522e51807f2b
Signed-off-by: Syed Rameez Mustafa <rameezmustafa@codeaurora.org>

Conflicts:
	drivers/iommu/msm_iommu_sec.c
	drivers/media/platform/msm/vidc/venus_hfi.c
	drivers/usb/otg/msm_otg.c
gpu: ion: Correctly print out physical addresses

Physical addresses may not always be able to be printed
with %lx. Use %pa to print out physical addresses.

Change-Id: If7e91277b04495bbb13112259428f449043fc63f
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
gpu: ion: Don't have a mapping for secure buffers

Secure buffers can't have a cpu mapping. The CPU may
speculate in to any mapping in the page tables. This
may result in security violations from speculative accesses.
Adjust the allocation to support this. Additionally,
ensure that any function which might try to use a cpu
mapping are restricted.

Change-Id: I85c7fd77c62519d6afa423d2fc125c03a5e2ca78
CRs-Fixed: 465059
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
gpu: ion: Don't have a mapping for secure buffers

Secure buffers can't have a cpu mapping. The CPU may
speculate in to any mapping in the page tables. This
may result in security violations from speculative accesses.
Adjust the allocation to support this. Additionally,
ensure that any function which might try to use a cpu
mapping are restricted.

Change-Id: I85c7fd77c62519d6afa423d2fc125c03a5e2ca78
CRs-Fixed: 465059
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
gpu: ion: enable the kmalloc heap

There are some Ion clients who would like to use the kmalloc
heap. Enable it.

Change-Id: Ie818be9e1211d52d489ad2cb63d94e2fddfc0f01
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>

Conflicts:
	include/linux/msm_ion.h
gpu: ion: minor refactor in ion_mmap

mutex_unlock is being called in the if and the else branch. Just move
it out of the if/else. This will help reduce upcoming merge conflicts
with upstream Ion changes.

Change-Id: Ib426e73f1cb9ed79f37b9c1e0a8885066ae5b4f4
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
gpu: ion: Set the dma_address of the sg list at alloc time

This patch sets the dma_address field of the sglist representing
an allocation at allocation time.  This technically breaks the dma api
which states that these addresses should be set when a particular device
takes ownership of a buffer via the dma_map apis.  In the case of our
systems the only dma address space is physical addresses.  Additionally,
we can not afford the overhead of calling dma_map_sg from this location
as it implies a cache invalidate that is not necessary if the memory
was previously mapped cached.  Instead, the expectation is that memory
being returned from the heaps is ready for dma in that if any cached
mappings of that memory exist they have been invalidated.

Change-Id: Ib3025e80cee52ac0e9d809291e0196a084ea97bd
Signed-off-by: Rebecca Schultz Zavin <rebecca@android.com>
Git-commit: 074a6a19c82eb4aee1dccf1054d44e2eb79340d8
Git-repo: https://android.googlesource.com/kernel/common
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
gpu: ion: Add cache maintenance to ion.

This patch adds cache maintenance operations to ion.  As per mailing
list discussions regarding dma_buf, cache operations are done implicitly.
At buffer allocaiton time the user can select whether he'd like mappings
(both kernel and user) to be cached.  When cached mappings are selected,
no mappings will be created for a buffer at mmap time.  Instead pages will
be faulted in one at a time so we can track which pages require flushing
before dma.  When the buffers are mapped for dma (via the dma_buf apis)
any pages which were touched will be synced for device.

Change-Id: Id5d6894e8bb52af038c91dd895143bf3b4203b0b
Signed-off-by: Rebecca Schultz Zavin <rebecca@android.com>
Git-commit: e1562c62795ac013c8feaa1a707bd7c039562de9
Git-repo: https://android.googlesource.com/kernel/common
[mitchelh@codeaurora.org: mmap ops in ion: took the Google version
(plus our unmap callback). ion_carveout_heap_map_dma: took the Google
version due to different carveout mechanism. ion_heap_map_kernel: took
the CAF version due to different ioremap
mechanism. ion_system_heap_map_kernel: took the CAF version since it's
still not clear whether mapping system memory as cached is
supported. Resolved a few other merge conflicts due to the fact that
7d72bad55a0e03392d81eee77a9a8c9df6b73a9a already brought in bits and
pieces of this patch (namely the flags/heap_mask split).]
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>