msm: kgsl: Introduce a KGSL_USER_MEM_TYPE_MAX enum

Introduce an enum for the max memory type supported by kgsl. This is
used by kgsl_test to pass the correct parameters to kgsl.

CRs-fixed: 331563
Signed-off-by: Lynus Vaz <lvaz@codeaurora.org>
(cherry picked from commit 31b5290e0f0a32fe56a4cc80983b9e223e22399d)

Change-Id: I5aa50e92707b1423150205a1dbf1b4af6d63c082
Signed-off-by: Swetha Basineni <sbasin@codeaurora.org>
Signed-off-by: Ronny Schmatzler <schmatzler@googlemail.com>
msm: kgsl: remove unneeded idle calls from context create

These idles were necessary when the context switch code
preserved PM_OVERRIDE registers. That was removed some time
ago so now the idles are not needed.

(cherry picked from commit 2794ab6dfe3ae8d88de8bad1022b8b5f2a194041)

Change-Id: I8f168ac6745ad5fa6de0ae41d1e38b9b01e22514
CRs-Fixed: 331325
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Ronny Schmatzler <schmatzler@googlemail.com>
msm: Add support for uncached buffer logging

Add an API to print data to a small uncached buffer.
When a system reset occurs valuable data may still
be remaining in the cache (e.g. last printks) and this
data will probably be lost, giving an incomplete picture
of what the system was last doing. By logging useful
information to this uncached region (e.g. readl/writel,
last printk) a better picture of what the system was
last doing emerges.

Change-Id: I1f2c548059cb6bba8003f11fd1c54e7f789dfbae
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
Signed-off-by: Ronny Schmatzler <schmatzler@googlemail.com>
msm: iomap: Add static IO mappings for MSM Copper

Map QGIC and TLMM IO addresses

Change-Id: I6b58065d7d573e92f69ae797eb76a9367d2217d0
Signed-off-by: Sathish Ambley <sambley@codeaurora.org>
Signed-off-by: Ronny Schmatzler <schmatzler@googlemail.com>
msm: Deprecate use of MSM_DEBUG_UART1,2,3 for low level debug

This patch is based off "msm: Consolidate and move DEBUG_LL
to generic ARM Kconfig" where use of MSM_DEBUG_UART1,2,3 is
deprecated and instead have one Kconfig per target/board.

The choice menu for selecting the DEBUG UART still remains
in mach-msm folder and has not been moved under DEBUG_LL
unlike the original patch.

Remove machine_is_*() checks from uncompress.h for various
targets and instead use CONFIG_SERIAL_MSM_HSL to identify
the UART core.

Change-Id: I1de37dfe093213185fb7c759cd731c950a7d0acc
Signed-off-by: Sathish Ambley <sambley@codeaurora.org>
Signed-off-by: Ronny Schmatzler <schmatzler@googlemail.com>
msm: kgsl: disable irq when adreno device is stopped

When restoring to slumber from nap, the irq is kept enabled causing a
power drain. This change ensures that adreno device behaves similar to
z180 device.

CRs-Fixed: 331847
Signed-off-by: Ranjhith Kalisamy <ranjhith@codeaurora.org>
(cherry picked from commit ce75b0c9008e6cdc22d2bff833ef96c9bd1b2c94)

Change-Id: I5c8280d707d8d0447ed8918130666f4c65f0136e
Signed-off-by: Swetha Basineni <sbasin@codeaurora.org>
Signed-off-by: Ronny Schmatzler <schmatzler@googlemail.com>
msm: kgsl: Be explicit about what states may access hw

If the core is in SUSPEND or INIT hw access should not be allowed.

Signed-off-by: Lucille Sylvester <lsylvest@codeaurora.org>
(cherry picked from commit 8b803e975369e89b3d0061f5a1e9048942d0543a)

Change-Id: I9302f24821ce1d79b3e612dc0b0d306802898e15
Signed-off-by: Swetha Basineni <sbasin@codeaurora.org>
Signed-off-by: Ronny Schmatzler <schmatzler@googlemail.com>
msm: kgsl: Clarify the circumstances to enable SLUMBER state

Use the restore_slumber variable at as low a level as possible
to remove confusion from the state machine.  Also do not let
restore_slumber impact the function of NAP state.

Signed-off-by: Lucille Sylvester <lsylvest@codeaurora.org>
(cherry picked from commit a985adf60ef350c3924587e7b4d11fb05be453ad)

Conflicts:

	drivers/gpu/msm/kgsl_pwrctrl.c

Change-Id: If88de825949c77306b4c46f02bf2679cc06b9ac8
Signed-off-by: Swetha Basineni <sbasin@codeaurora.org>
Signed-off-by: Ronny Schmatzler <schmatzler@googlemail.com>
msm: kgsl: add new adreno225 registers to context switching

Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Ronny Schmatzler <schmatzler@googlemail.com>
msm: kgsl: fix adreno225 register ranges

There is a gap between GRAS_UCP5W and GRAS_UCP_ENABLED.
Trying to save and restore these registers with shadow writes off
results in rbbm read errors.

Change-Id: I4c99d9e23cae81315418f33aa656117303f990f2
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Ronny Schmatzler <schmatzler@googlemail.com>
msm: kgsl: Add GPU snapshot support

Add support for snapshotting the state of the GPU in a binary format. The
snapshot can be pulled from sysfs and parsed off-target.  The advantage is
that far more information can be encapsulated in a snapshot then can be
printed on the console during a hang.  Snapshots are automatically created
during a hang, or can be manually triggered by writing 'trigger'
in /sys/class/kgsl/kgsl-<n>/snapshot where n is either the 2D or 3D device.
Snapshot data can be pulled from 'dump' in the same directory.

(cherry picked from commit 156cfbc7c372c3cd0690a70f83b44c55e5a913fb)

Change-Id: I08e44d136be41ce6a32594e7f3fd364684d36e0f
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
Signed-off-by: Ronny Schmatzler <schmatzler@googlemail.com>
msm: kgsl: Add a constant for adreno_ringbuffer_issuecmds flags

Use a #define constant instead of a bare constant for the flags
parameter of adreno_ringbuffer_issuecmds.

Change-Id: Ic0dedbadecabe396a51201859a444e68ba64c53d
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
(cherry picked from commit e0ea762600b5002c7e6d964c0ab82e4f75ad63a7)
Signed-off-by: Ronny Schmatzler <schmatzler@googlemail.com>
msm: kgsl: Add CP_DRAW_INDX commands after a context save

Issue an empty draw call to avoid possible hangs due to
repeated idles without intervening draw calls.
On adreno 225 the PC block has a cache that is only
flushed on draw calls and repeated idles can make it
overflow if there are not intervening draw calls.
The gmem save path contains draw calls so this workaround
isn't needed there.

CRs-Fixed: 316084
CRs-Fixed: 317712
Change-Id: I280468b61fd3a6b6ffb30a1cdf118399f115f0dd
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Ronny Schmatzler <schmatzler@googlemail.com>
msm: kgsl: fix parameter checking in adreno_ringbuffer_issueibcmds

Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Ronny Schmatzler <schmatzler@googlemail.com>
msm: kgsl: Add support for the preamble context flag

Userspace will set a flag in the context if preambles are in use. If
they are, we can safely skip save and restore commands for the
context. GMEM save/restore is still required.  To improve performance,
preamble commands are skipped when the context hasn't changed since
the last issueibcmds.

Change-Id: I21bb8996d62651122dbebcf7a79543679109e1f9
Signed-off-by: Vijay Krishnamoorthy <adivarah@codeaurora.org>
(cherry picked from commit bef66933eeae5f0d5e9563eea441cadc6d2de8ba)
Signed-off-by: Ronny Schmatzler <schmatzler@googlemail.com>
msm: kgsl: Make sure SLUMBER is the requested state

The stop_work function releases the device mutex to flush
the workqueue.  The requested state may change while the
mutex is held by a different thread.  So set the requested
state after stop_work.

Signed-off-by: Lucille Sylvester <lsylvest@codeaurora.org>
(cherry picked from commit 344e46286bba0fb6c0c7ae7bd2b09d5cd452adfa)

Change-Id: I6bae6e904d7cf475adab63aa5ea5ccce3a0bdfb7
Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
Signed-off-by: Ronny Schmatzler <schmatzler@googlemail.com>
msm: kgsl: queue timestamp expired work more often

There are a some workloads where interrupts do not
always get generated, and as a result the timestamp
work was not triggered often enough.

Queue timestamp expired work from adreno_waittimestamp(),
when the timestamp expires while we are not waiting.
It is possible in this case that no interrupt fired
because no processes were waiting.

Queue timestamp expired work when freememontimestamp
is called, which reduces the amount of memory
built up by applications that use this api often.

(cherry picked from commit 63904835725a479a70d078aa68ba4b42af1bb175)

Change-Id: I98868d029c436608e66c98a217cf65f0178d5fea
CRs-Fixed: 336057
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Ronny Schmatzler <schmatzler@googlemail.com>
msm: kgsl: Idle the core before changing the gpu clock.

Idle the core before changing the gpu clock as instability
is caused on some platforms on changing the clock freq when
core is busy.

CRs-fixed: 328249
Signed-off-by: Kedar Joshi <kjoshi@codeaurora.org>
(cherry picked from commit c11d098f53dd1fb07ea03475510c29c39b9671ab)

Change-Id: I11fc58128560b131f60a84fc94b8bc48134a9eaa
Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>
Signed-off-by: Ronny Schmatzler <schmatzler@googlemail.com>
msm: kgsl: remove readl/writel use for dma memory

For dma_alloc_coherent() you don't need writel/readl because
it's just a plain old void *. Linux tries very hard to make a
distinction between io memory (void __iomem *) and memory
(void *) so that drivers are portable to architectures that
don't have a way to access registers via pointer dereferences.
You can see http://lwn.net/Articles/102232/ and the Linus rant
http://lwn.net/Articles/102240/ here for more details behind
the motivation.

Change-Id: I3da075c30304e4adf321cfb3edb1baa4a93fc2ce
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Ronny Schmatzler <schmatzler@googlemail.com>
msm: kgsl: cancel events from kgsl_release

Events need to be cancelled when an fd is released,
to avoid possible memory leaks or use after free.

When the event is cancelled, its callback is called.
Currently this is sufficient since events are used for
resource management and we have no option but to
release the lock or memory. If future uses need to
distinguish between the callback firing and
a cancel, they can look at the timestamp passed to
the callback, which will be before the timestamp they
expected. Otherwise a separate cancel callback can
be added.

CRs-Fixed: 327647
Change-Id: I49f8f58aea6366344d1c82613f73881a169834b3
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Ronny Schmatzler <schmatzler@googlemail.com>