gpu: ion: Return error value when iommu map fails

When __ion_map_iommu returns a non-zero value (i.e.
error occured), properly propagate this error back
up to the client.

Change-Id: I6cd5ce8a723ad1cbbd6c42b712f5a19fa2ba719f
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
ion: remove ion_share_set_flags

Due to changes in the semantics of the `flags' field of `struct
ion_buffer', it is no longer necessary to set the flags when setting
up an ion share.

Change-Id: I2f34868cc6d2045f78dbd5f0a67d3e40778af0de
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
gpu: ion: Fix a contiguous system heap crash

map_kernel and unmap_kernel in kmalloc_ops should support
a contiguous heap. The existing functions
ion_system_heap_map_kernel and ion_system_heap_unmap_kernel
are geared towards discontiguous memory (supported via
vmalloc_ops) and crash while handling contiguous heaps. This
patch adds two new functions specific to contiguous system
heaps to initialize kmalloc_ops.

Change-Id: I48d30ca01c5a0b71af4e1e640c79a920a298aedb
Acked-by: Jennifer L. Zenner <jzenner@qti.qualcomm.com>
Signed-off-by: Rohit Vaswani <rvaswani@codeaurora.org>
gpu: ion: Free heaps after checking for overlap

The platform data needs to be freed after checking for overlaps,
otherwise a use after free bug occurs.

Change-Id: I3b75e9573d3f6608312e63c56f52daaebfc51b4c
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
ion: tracing: add ftrace events for ion allocations

Add ftrace events for ion allocations to make it easier to profile
their performance.

Change-Id: I9f32e076cd50d7d3a145353dfcef74f0f6cdf8a0
Signed-off-by: Liam Mark <lmark@codeaurora.org>
ion: cma: Add debug heap ops for CMA heap

For tracking CMA allocation by address and fragmentation
(if any), add debug heap ops which gives buffer allocation
info.

Change-Id: Ia8bed38034b85b2d4dcf84811a348bbbe50dc16b
Signed-off-by: Chintan Pandya <cpandya@codeaurora.org>
gpu: ion: add pointer null checks in map and unmap

Clients may pass incorrect arguments to ION causing crashes.
Add checks to validate input for ION APIs.

Change-Id: Idafa4535b3ef71184ca11fb2c0c4ab073a52ac2f
Signed-off-by: Huaibin Yang <huaibiny@codeaurora.org>
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>

Conflicts:
	drivers/gpu/ion/ion.c
msm: iommu: re-use existing buffers for `extra' mappings

There is a bug on some hardware that requires us to overmap Iommu
mappings by 2x. Currently, we set aside a dummy buffer onto which we
map all of these dummy mappings. In general, for large mappings it's
nice to use the more efficient iommu_map_range instead of calling
iommu_map repeatedly. However, with our current approach in
msm_iommu_map_extra we can't use iommu_map_range for page_sizes larger
than the dummy buffer. To avoid wasting memory by increasing the size
of the dummy buffer, we can simply remap on top of the the buffer
being mapped in the first place. Since the second mapping should never
be used (besides by the buggy hardware) this should not be a problem.

Re-use existing buffers for all `extra' mappings. Essentially, map the
same physical address range twice. To be extra safe, make the second
mapping read-only.

Change-Id: I35462ad50de8da1f2befa3e3f0895925535cdc98
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
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: 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>
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>
msm: Add support for ION Flushing without virtual address

Video has very large buffers to be flushed. Due to lack of
vmalloc space, ion_map_kernel cannot be called on each of
the video buffers. With this change the ion handle can be
flushed without the need of the kernel mapping.

Change-Id: If026f21e44a2cce6c2b8c232fc80a69d0dabcd14
Signed-off-by: Neeti Desai <neetid@codeaurora.org>

Conflicts:

	drivers/gpu/ion/ion_cp_heap.c
	drivers/gpu/ion/msm/msm_ion.c

Signed-off-by: Maheshwar Ajja <majja@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: 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>
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: Align va address to biggest buffer size

Align the virtual address to the max buffer size to
allow IOMMU mappings at the biggest buffer size.

Change-Id: I74ba665c1782e2f0631274766c5caeeb192224e0
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
gpu: ion: add generic function for creating chunked sg tables

Add a helper function to create sg tables composed of items of some
given chunk size.

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

Conflicts:
	drivers/gpu/ion/ion.c
	drivers/gpu/ion/ion_cp_heap.c
	drivers/gpu/ion/ion_priv.h
ion: Zero out pages with __GFP_ZERO flag

Userspace expects the pages to be zeroed out, so zero them.

Signed-off-by: Laura Abbot <lauraa@codeaurora.org>
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
gpu: ion: Set dma length in sg_list

Ensure that the length of the scatterlist entry is set
correctly.

Change-Id: Ide2c4169f0a873d44fc14470a1e06f0e2c26f101
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
crypto: Use scatterwalk APIs in crypto

sg_next() may find wrong scatter-gather buffer in crypto subsystem,
and this causes a kernel crash. scatterwalk_sg_next() should be used
instead in crypto related drivers.

Change-Id: Ibb454bc8a8b2c0318e55cd12ba3e4ca2f3647e36
Acked-by: Ho Lee <holee@qti.qualcomm.com>
Signed-off-by: Rohit Vaswani <rvaswani@codeaurora.org>