msm: kgsl: Store process id and name in context structure

Store process id and name in context structure, this
information is used to print the process name when
when we detect a error in the driver, example
GPU fault tolerance, commands from bad context
in issueibcmds.

Change-Id: I6acd63933754fdec80d8274d3e1380ff2c23770e
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
msm: kgsl: Make the snapshot dumper more tolerant of corrupted IBs

If there are a lot of sequential commands in the ringbuffer for the
same context there is a high probablity that some of the memory
for the older commands has been reused and so the contents may not
be reliable. Increase robustness by making sure we don't parse the
same IB over and over again and be more tolerant of errors and
strange sizes.

Change-Id: Ic0dedbade8504ea258ceea40593cb75e7d6211c8
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Make sure the last IB2 is in the static snapshot region

When taking a snapshot from a ramdump it is usually important that
we get the last IB2 that was executed so if we find it during
parsing put it in the static snapshot region as opposed to the
dynamic one.

Change-Id: Ic0dedbad878b961ebe29afe9145443e9bfd0bc6a
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Use the correct timestamp for the snapshot

The snapshot timestamp is currently based on wall time which makes
it very difficult to debug against a kernel log based on boot time.
It doesn't help matters that the snapshot timestamp is output in
human unfriendly hex.  Use boot time instead of wall time for the
snapshot value and print it out in decimal.

Change-Id: Ic0dedbadf9b7d799a3cb4d5917787bccd350c90a
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: snapshot: Don't keep parsing indirect buffers on failure

Stop parsing an indirect buffer if an error is encountered (such as
a missing buffer). This is a pretty good indication that the buffers
are not reliable and the further the parser goes with a unreliable
buffer the more likely it is to get confused.

Change-Id: Ic0dedbadf28ef374c9afe70613048d3c31078ec6
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Remove duplicate code for checking timestamps

Event based as well as interruptible based timestamp checks
use the same code, they differ on if the mutex is held or not.
Separate the common code out to avoid confusion.

Change-Id: Ie2ee01d7a07ff2ba7755ab8d327796345f9ca9ea
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
Signed-off-by: Rajeev Kulkarni <krajeev@codeaurora.org>
msm: kgsl: Move events to context specific lists

Move the event accounting from a master list on the device to individual
context lists. This makes the management code more simple and reduces
the amount of extra cycles taken trying to walk a single largish list.
The new added code makes the event code slightly bigger than kgsl.c can
bear. As events become more commonplace this code will be more important
and it will be easier to maintain in a dedicated file so move all the event
related code into kgsl_events.c

Change-Id: Ic0dedbadf00b96eee53aea1d26acb195f1a916ce
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Add context reference counting to KGSL events

Add reference counting to all KGSL events since they are dependent
on the context.  This avoids a race condition where the context
could be destroyed while the events are being processed during cleanup.

Change-Id: Ifcd9655a6335d22c01f2606a0fbc5346d9a0314f
CRs-fixed: 438134
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
msm: kgsl: Send the correct timestamp to an expired event

Instead of sending the currently expired timestamp to expired
events, send the timestamp that the event expected. This avoids
confusion for events that don't compare the actual timestamp
to the one they expected.  Canceled events send the current
timestamp when they were canceled.

The kgsl_sync handler wasn't prepared for the second case so
add a check to prevent strange things from happening on the
timeline when a event is canceled.

Change-Id: Ic0dedbad3681db6222720884688dcddb9b06bda2
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Don't silently ignore events that have a retired timestamp

After all the current events are processed in the main loop, the next
pending event is marked to fire an interrupt to start the cycle anew.
When the event is marked, we check the timestamp again to make sure that
we are always caught up with the GPU.  If the timestamp for the next
event happens to be retired when we get to this point, we silently leave
the function.

If there are no other subsequent events or waittimestamp requests, then
it is possible that another interrupt might never be fired for that context
and then the event gets missed.  Return a 1 in this case all the way back
up the stack and make the event code keep processing events until we are
positive that none are past.

Change-Id: I5a770e7f06612e1aecbfe2e8ccbfeebdab3fc9fc
CRs-Fixed: 441191
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>

Conflicts:
	drivers/gpu/msm/kgsl_device.h
msm: kgsl: Check the current interrupt status before power operations

Sometimes the core will go idle before the interrupt can be handled on
the GPU. If that happens then we could go to a lower power state before
cleaning up the pending interrupt and various entities that might be
waiting for it. Consider the current interrupt status when checking
for idle.

CRS-fixed: 449813
Change-Id: Ic0dedbadfd2d40e4411cf3b05e1eb4c4eecf7841
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Resolve a potential race in the interrupt handler

In the GPU interrupt handler we attempt to clear the ts_cmp_enable
for the active context so that future interrupts are skipped until
someone needs one again. If for some reason the interrupt handler
is delayed then there is a possiblity that the "current" context in
the GPU isn't the one that fired the interrupt. In that case we
could be accidently clearing a ts_cmp_enable for a context that
needs it. Instead of clearing in the interrupt handler clear it
from the GPU so we can be sure we got the right context.

As a bonus pushing this logic to the GPU side lets us get rid of
some extra register reads/writes in the interrupt handlers.

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

Conflicts:
	drivers/gpu/msm/adreno_a3xx.c
msm: kgsl: Add event tracepoints

Add tracepoints for tracking the lifespan of GPU events.

Change-Id: Ic0dedbadf99b1efcb650608c6ac664d3c4ddafd5
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Remove an uneeded log message that pre-dates tracing

Before we started using tracepoints this log message was used for
debugging the critical loop. Now that we are smarter remove the
unneeded log message.

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

Conflicts:
	drivers/gpu/msm/adreno_ringbuffer.c
msm: kgsl: Use ERR_PTR to return errors from kgsl_create_context()

Normally kgsl_create_context() returns a pointer to a new context.
In case of errors it just returns NULL pointer, and that doesn't allow
to propagate the right error code back to the user via
kgsl_ioctl_drawctxt_create()
This fix modifies kgsl_create_context to use ERR_PTR macro for passing
error codes to its caller.

Change-Id: I447c1765828912b0994bcae67a73864e62eef9b6
Signed-off-by: Vladimir Razgulin <vrazguli@codeaurora.org>
msm: kgsl: Remove extra call to sync_fence_put()

sync_fence_put is called twice and cause NULL pointer dereference.

Change-Id: Ia29e676af28d9040d1ba1ee8669f1306cc8b4035
Signed-off-by: Alex Wong <waiw@codeaurora.org>
msm: kgsl: Send the right IB size to adreno_find_ctxtmem

adreno_find_ctxtmem expects byte lengths and we were sending it
dword lengths which was about as effective as you would expect.

Change-Id: Ic0dedbad536ed377f6253c3a5e75e5d6cb838acf
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Handle a possible ringbuffer allocspace error

In the GPU specific start functions, account for the possibility
that ringbuffer allocation routine might return NULL.

Change-Id: Ic0dedbadf6199fee78b6a8c8210a1e76961873a0
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: snapshot: Don't keep parsing indirect buffers on failure

Stop parsing an indirect buffer if an error is encountered (such as
a missing buffer). This is a pretty good indication that the buffers
are not reliable and the further the parser goes with a unreliable
buffer the more likely it is to get confused.

Change-Id: Ic0dedbadf28ef374c9afe70613048d3c31078ec6
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Save the last active context in snapshot

Save the last active context that was executing when the hang happened
in snapshot.

Change-Id: I2d32de6873154ec6c200268844fee7f3947b7395
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>