add CMA heap

New heap type ION_HEAP_TYPE_DMA where allocation is done with dma_alloc_coherent API.
device coherent_dma_mask must be set to DMA_BIT_MASK(32).
ion_platform_heap private field is used to retrieve the device linked to CMA,
if NULL the default CMA area is used.
ion_cma_get_sgtable is a copy of dma_common_get_sgtable function which should
be in kernel 3.5

Change-Id: I9ae54a3a021cb3513c2b0e8c58b69f3ae118561b
Signed-off-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
[lauraa: Fix context in ion_priv.h/ion.h and omit Makefile change for now]
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>

Conflicts:
	include/linux/ion.h
gpu: ion: Add msm specific extensions to CMA heap

A number of changes have been made to the Ion framework for the
msm target. Add the necessary changes on top of the CMA heap to
allow the CMA heap to be fully utilized.

Change-Id: Ie006dcd4c41481e4d914c67bafbf42d1afdb1a76
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
Revert "gpu: ion: Add msm specific extensions to CMA heap"

This reverts commit a9b0f2019886e665cb52dbed4cd3e1bbcac3400d.
Revert "add CMA heap"

This reverts commit 184559e5fef1ce0e587c7c21cd7e700a47cd52ca.
ion: Add reserve function to ion

Rather than requiring each platform call memblock_remove or reserve
from the board file, add this to ion

Change-Id: Ie418a692c13e9e0cfe93ecc83d253d3ce860fc83
Signed-off-by: Rebecca Schultz Zavin <rebecca@android.com>
msm: kgsl: Check before resetting timestamps of 2D core to 0 on startup

The timestamp of 2D core should not be set to 0 on startup if the
device has previously been started and is waking up from a suspend call.
This can cause processes to wait indefinitely for the 2D core if
they received a timestamp before the device went into suspend

Change-Id: Ida5dbdcb89ea7e0cf86110ecc2bd7d568123c364
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: fix statistics for ion memory regions

The sysfs code was reading the wrong entry in the stats
array, so it printed the wrong value.

Change-Id: I26ce8bbca152a98e3dac53a9c154e52b020d5532
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
msm: kgsl: return correct error code for unknown ioctls

Unknown ioctl code errors are supposed to be ENOIOCTLCMD,
not EINVAL.

Change-Id: Id38529e4ec70d63091a9273a780585aea6ae9d9a
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
msm: kgsl: add userspace memory alloc and free tracepoints

Add events for tracking memory operations by userspace
clients: kgsl_mem_alloc, kgsl_mem_map, kgsl_mem_free,
kgsl_mem_timestamp_queue (adding an entry to the free
on timestamp list) and kgsl_mem_timestamp_free (when
the memory is actually freed).

Change-Id: Id62eec30ea20a0f00f7a7a791c7e5b8dfad487af
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
msm: kgsl: Remove DRM specific gpu cache flush

DRM specific gpu cache flushing was causing kernel
crashes (NULL dereferences) and is no longer necessary.

Change-Id: I47d82baa9454a29e7f21b9ac5365921379bfb09d
Signed-off-by: Michael Street <mstreet@codeaurora.org>
msm: kgsl: Remove some uneeded debug output

Remove a block of code that dumped the ringbuffer contents after they
were extracted.  The dump is no longer needed and the longer we
stick around dumping things to the console with the mutexes locked,
the better the chance that the watchdog will come bite us.

Change-Id: Ic0dedbadd22993f0f1646841f481cdc6713d38e8
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Detach memory objects from a process ahead of destroy time

Previously, memory objects assumed that they remained attached to a
process until they are destroyed. In the past this was mostly true,
but worked by luck because a process could technically map the memory
and then close the file descriptor which would eventually explode. Now we
do the process related cleanup (MMU unmap, fixup statistics) when the
object is released from the process so the process can go away without
affecting the other holders of the mem object refcount.

Change-Id: Ic0dedbadde0db62b5f3eb02716d6bb8f65f2562d
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>

Conflicts:
	drivers/gpu/msm/kgsl.c
Revert "msm: kgsl: Check before resetting timestamps of 2D core to 0 on startup"

This reverts commit fd4ee4967ab70e2ff02fe53ce822370aa80860a8.
Revert "msm: kgsl: Remove DRM specific gpu cache flush"

This reverts commit fb0296c87ce592097da405c2df44e059c641767b.
Revert "msm: kgsl: Detach memory objects from a process ahead of destroy time"

This reverts commit 06ceb83629fbf296c7c5051350cde83902146448.
Revert "Revert "msm: kgsl: Check before resetting timestamps of 2D core to 0 on startup""

This reverts commit 643ade0171898fec84e9f003e33b65f6e37a15dd.
Revert "Revert "msm: kgsl: Remove DRM specific gpu cache flush""

This reverts commit ff86203bae5cba277d085958f9c74afe495e353e.
msm: kgsl: Find a mem_entry by way of a GPU address and a pagetable base

Given a pagetable base and a GPU address, find the struct kgsl_mem_entry
that matches the object.  Move this functionality out from inside another
function and promote it to top level so it can be used by upcoming
functionality.

Change-Id: Ic0dedbad965530a28c43bac36dda0535dcd1c95b
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Freeze GPU memory objects to be dumped with the snapshot

In addition to the usual objects in a snapshot (registers, ringbuffer,
IBs, etc), there are a handful of indirect GPU buffer objects that are
created and used during draw operations. These include shaders, buffer
objects, and various state buffers.  Taken together, these buffer
objects can be large, much larger then the snapshot region we have set
aside. Fortunately, these buffers are independent and don't need to be
freed or overwritten when the context is reset.

Long story short we can take these buffers, put them in a list at snapshot
time and mark them so they don't get freed.  Then, when the snapshot is
grabbed dump them into the output stream inline and only then free them.
This allows us to snapshot a larger section of the GPU state without having
to worry about having enough memory set aside.  The only downside is that
some GPU memory will stick around, but we hope that hangs are few and far
between and that some entity will grab the dump soon after the hang so the
memory can be released.

Change-Id: Ic0dedbad0629fa483b077e727d512877bbbf81d6
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>

Conflicts:
	drivers/gpu/msm/kgsl_snapshot.h
msm: kgsl: Add indirect shader buffers to the snapshot

There are two ways to load shader instructions and constants -
direct (in the IB) and indirect (with a pointer to another
GPU buffer). Start dumping indirect shader buffers into the snapshot
so that complete shader information can be recreated at parse time.

Change-Id: Ic0dedbada6b0e6ba26d2bd57617976d16809129e
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>

Conflicts:
	drivers/gpu/msm/adreno_pm4types.h