*WIP* GPU: revert linux upstream & gpu commits & bringup to kk *test*

* todo: readd gpu commits + linux upstream
*WIP* iommu: revert upstream & recent commits add kk bringup *test*

* todo: readd commits + linux upstream
Revert "msm: kgsl: schedule the event queue after the dispatcher work queue"

This reverts commit 4f36f4e8474b15812f4d660206519b214daf5d06.

Change-Id: I2d9a7b89aebc7fb548531dbecb791f2b2f5b4526
msm: kgsl: Re-run the events handler when inflight goes to zero

The event code is sensitive to race conditions with the GPU. We just
can't spend all day the event loops waiting for timestamp to expire.
The dispatcher loop on the other hand is far less sensitive to the
race with the GPU so we have a very good idea when the GPU is idle.

When inflight goes to zero re-run re-queue the event handler to catch
any stragglers.

Conflicts:

	drivers/gpu/msm/adreno_dispatch.c

CRs-fixed: 551825
Change-Id: Ic0dedbad9d02fca89724bf791d9c7212712a8014
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
Signed-off-by: Jeff Boody <jboody@codeaurora.org>
msm: kgsl: Do not take active_cnt for events and waittimestamp

In the mists of time it was nessesary to take an active count
for waittimestamp and events because we did not want to run
the risk of suspending while the GPU was active.  Now that we
have the dispatcher we have much better control over the GPU
so the original risk is diminished.

The problem is that holding active_cnt prevents us from going
into nap and suspend and with server-side-sync a lot of the
events we are waiting for might take a very long time before
they even get dispatched on the GPU so we are essentially
keeping the clocks on waiting for other people.

z180 must take active count on its own.

Change-Id: Ic0dedbadcb608115938b198faebe333d19c6a8f6
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Add IB submission gate for device suspend

Add IB submission gate to stop the system from making requests
while suspend is requested.  This will force users to wait for
the system to resume before making more requests.

Change-Id: I2460ef9b4237b586a31d4cea64b6dd74d30b08d9
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
msm: kgsl: always check kgsl_active_count_get() result

Getting an active count can fail if the hardware doesn't
actually wake up. Make active count get functions __mustcheck
to remind people of this and fix existing calls to
handle the error.

Change-Id: I5a0202c824ac7e436b9061da6d8f638e44e8b7f6
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
msm: kgsl: manage active count in adreno_ioctl()

Most of the adreno specific ioctls do not need the hardware
on. The few that do are perfcounter related, it may be
better at some point to optimize them further to shadow
the counters when the hardware is not on rather than
forcing the power on.

Change-Id: I9ea83106e0aaf3d3ac8d261bdec4e4c2e21c4659
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
msm: kgsl: remove KGSL_IOCTL_WAKE from context destruction

Adreno context destruction never needs the hardware on
to destroy the current context.

For z180, always take an active count while destroying.

Since this is the last ioctl to use KGSL_IOCTL_WAKE, remove
it entirely.

Change-Id: I97368c7f3c28f16538cc5f48b802b681d7af96ef
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
msm: kgsl: Set CP_DEBUG in GPU cores start routine

The CP_DEBUG register needs to be programmed with values that
depend on the GPU core. Set this register in the core specific
start routine.

Change-Id: I5fa3813fa4b98efa8c73e1fc00b61f3cc3745b2f
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
msm: kgsl: Bootstrap GPU microcode

When doing a GPU cold start after power collapse, load microcode
booter+dispatcher using AHB writes and setup a CP type3 bootstrap
packet in ringbuffer, this bootstrap packet loads the rest
of the microcode.

When doing a warm start after GPU soft reset, bootstrap microcode
jump tables.

Change-Id: I9ed07c6a428fdeed33650fa22d1b3317ea587189
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
msm: kgsl: inherit owner from kgsl/proc debug directory

Make all entries under kgsl/proc inherit its owner's uid/gid.

[ccross]
Reapplied after it was overwritten by another patch.

Bug: 10550827
Big: 10954149

Signed-off-by: Rom Lemarchand <romlem@google.com>
Signed-off-by: Colin Cross <ccross@google.com>
msm: kgsl: fix race condition setting the event->handle

A race condition existed for setting the event->handle since the
async event can signal at any time after it has been registered.
When the event signals the reference count for the synclist and
the async callback are decremented causing the event to be freed.
The kgsl_cmdbatch_add_sync_fence function needs to take another
reference to ensure that the handle can be set before the event
is freed.

Change-Id: I0d8a02246e42dce014661d6f14c685415f1704cd
Signed-off-by: Jeff Boody <jboody@codeaurora.org>
iommu: msm: Use ion_phys_addr_t for iova argument

IOMMU mapping function is using the wrong type for its
IO Virtual Address (IOVA) causing the returned address
to contain garbage in the upper 32 bits when LPAE is enabled.

CRs-fixed: 564365
Change-Id: Ied592fe855a145b0ff32d2a6228ecfcf7fd0a53e
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
gpu: ion: Use list_for_each_safe on error path

On an error, the list of pages is walked and destroyed. Since the list
is being destroyed, use list_for_each_safe to avoid list corruption.

Change-Id: Ia397a11d2d890b3458745820c79df2adaa088ade
CRs-Fixed: 565183
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
gpu: ion: Also shrink memory cached in the deferred free list

When the system is low on memory, we want to shrink any cached
system memory ion is holding.  Previously we were shrinking memory
in the page pools, but not in the deferred free list.  This patch
makes it possible to shrink both.  It also moves the shrinker
code into the heaps so they can correctly manage any caches they
might contain.

Change-Id: I177f587f999a5220eddbf7af94745aae736cac75
Signed-off-by: Rebecca Schultz Zavin <rebecca@android.com>
Git-commit: 072beca55150c0c0b652bbb24267da271e0bdf19
Git-repo: https://android.googlesource.com/kernel/common
[mitchelh@codeaurora.org: minor context fixups due to MSM changes]
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
gpu: ion: Add buffer flag to skip page pooling on free

Currently, when we free a buffer it might actually just go back into a
heap-specific page pool rather than going back to the system. This poses
a problem because sometimes (like when we're running a shrinker in low
memory conditions) we need to force the memory associated with the
buffer to truly be relinquished to the system rather than just going
back into a page pool.

There isn't an obvious use case for this flag by Ion clients. The main
use case right now is to provide a mechanism for the deferred free code
to force stale buffers to bypass page pooling.

Change-Id: I724f89cc037083fe8576784363caa18a34e8705a
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
gpu: ion: create separate heap and client debugfs directories

It can be slightly annoying to figure out which files under the ion
debugfs directory are heap debug files and which ones are client debug
files. Create separate subdirectories under ion to hold the different
types of debug files.

Change-Id: Ic773ab619ef94b9b4d0f3794def9d37645c7c212
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
gpu: ion: don't use "vmalloc" for system heap readable name

The human-readable name of the system heap is currently "vmalloc", which
is misleading since we don't use vmalloc at all for that heap, we use
alloc_pages. Make the human-readable name of the heap "system".

Change-Id: Iefb92ea8adc8d76b8eccc504010aa9bc2fa5c50c
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
gpu: ion: optimize zero'ing of pages

Instead of using __GFP_ZERO, vmap high-order pages for zero'ing all at
once (or in a few large chunks).

Test results show a ~25% speedup for allocations that are fulfilled from
lowmem, and ~100% speedup for allocations that are fulfilled from
highmem.

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