msm: kgsl: Convert all physical address to type phys_addr_t

Future chipsets may not define phys_addr_t to 32 bits hence convert
all physical address variables to this type.

Change-Id: I4ac5bd1aabda455456ff867c973a264f68992404
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Only reference the rb_node after taking spinlock

Derefernce the rb node after taking spinlock since the root
node can change and is supposed to be guarded by the spinlock

CRs-Fixed: 495129
Change-Id: I63de7755cf9d5fb548c082f43403000bcef5721b
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Set alignment to 0 when low on mapped memory

If CPU map returns error due to low memory then we need to set
the alignment to 0 and instead of setting it to PAGE_OFFSET. This
is because we then simply search of a free memory gap at page
boundary and disrerard alignment requirement since memory is
low.

Change-Id: I828f5d0120d6d530e0e8857bcd96c9d5f266da10
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Do not hold memory spinlock when calling find region function

The function kgsl_sharedmem_find_region holds the memory spinlock
at the beginning of the function so we do not need to hold the lock
before calling the function

Change-Id: I20ee32e0ed6aee6ed61cdd4fb7a9cc08a876fc84
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Enable special case performance counters

Special case performance counters do not have select registers.
Enabling performance counters first checks that the counters we want
are valid and have select registers, then it would enable the counters.
The special case performance registers were not being enabled in this
case since they fail the initial test.  Move these special cases to
before the select register error checking and perform their own sanity
checks before enabling the performance counters

Change-Id: I716103fb6bfb97ba3e198503531af139fb1725f8
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Option to disable GPU fault tolerance

When GPU Fault tolerance is set to KGSL_FT_OFF do not run
fault tolerance. When we turn off fault tolerance
a) If GPU continues executing commands then
   GPU stall detection is false
b) If GPU does not execute further commands then
   GPU stall detection is correct

When GPU stall detection is suspected to be false,
we can use this option to confirm stall detection.

Change-Id: Iac4d235377df015db223df9ec5597fb43d4c8878
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Fix a missing semicolon in the KGSL IOMMU handler

in check_if_freed() a call to kgsl_get_memory_usage() was terminated with
a comma instead of a semicolon.  Through a quirk in a macro this somehow
managed to compile and function properly but that doesn't make it okay.

CRs-fixed: 497280
Change-Id: Ic0dedbadfdf901bbc68b7f8cefb231d08dd01a95
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Reduce unnecessary calls to _wake

If the device is already ACTIVE do not call _wake.

Change-Id: I2ae3956eb1bbc0a8bc0f1c147547aeed601622aa
Signed-off-by: Lucille Sylvester <lsylvest@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Only turn on the idle timer when active_cnt is 0

Only turn on the idle timer when the GPU expected to be quiet.
If the idle timer is enabled while the GPU is busy, there is
a chance it might unnecessarily fire during heavy GPU activity
such as a compute job.

Additionally, rather than trying to NAP directly from
kgsl_active_count_put(), just trigger the idle check work.

All of this makes the idle check happen more consistently.

Change-Id: Ic0dedbad57846f1e7bf7820ec3152cd20598b448
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Make active_cnt an atomic variable

In kgsl_active_cnt_light() the mutex was needed just to check and
increment the active_cnt value.  Move active_cnt to an atomic to
begin the task of freeing ourselves from the grip of the device
mutex if we can avoid it.

Change-Id: Ic0dedbad78e086e3aa3559fab8ecebc43539f769
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: don't store rptr in struct adreno_ringbuffer

Since the rptr is written by the GPU, there's no point
in keeping a copy in the ringbuffer struct where it will
likely be out of date. If you need to look at the ringbuffer,
read it into a local variable with adreno_get_rptr().

Change-Id: Ibf1ba0b9c71a93f65a5c85a58328b2202a27af3f
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Add support for 8226v2

8226v2 has a new spin of the 305B GPU with a different chip ID.
Add an entry to the GPU list for the new chip ID.  Unfortunately
we can't use the normal ANY_ID trick here because we have so many
different types of chips that use the same core, major and minor
values and differ only in the patchlevel.

Change-Id: Ic0dedbad9bb856a25b71cb825a2960fd0e1d4198
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Define register offset array

Different adreno cores have different offsets for same register.
These registers are referenced in code areas which are common to
all adreno cores. Hence, they should be referenced with a variable
instead of using a constant to make things more generic. This makes
the code more suitable for accomodating future cores.

Change-Id: Ie3d387d7cf767d46eea90e0fecdbba88dad97860
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Use a standard function for register access

There were dual functions for reading and writing registers for
adreno devices. Stop the use of one of these dual functions as
it makes the code more uniform.

Change-Id: I703d27d1674a85a6c2d7a9fe6dc49f13005a3410
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Fix context reference counting

Get rid of kgsl_find_context. Use instead kgsl_context_get that does
correct RCU read locking around the itr_find and increases the
reference count on the context before returning it.  This eliminates
the chance that a context will be destroyed while somebody is still
using it.  Of course increased use of kgsl_context_get is accompanied
by kgsl_context_put in all the right places.

Change-Id: Ic0dedbad73d497fd9b451aefad8e5b28d33b829d
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Use a read/lock for the context idr

Everybody loves a rcu but in this case we are dangerously mixing rcus and
atomic operations.  Add a read/write lock to explicitly protect the idr.
Also fix a few spots where the idr was used without protection.

Change-Id: Ic0dedbad517a9f89134cbcf7af29c8bf0f034708
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: convert cffdump stub functions to inlines

Since cffdump is not often enabled in Kconfig, it is helpful
to at least catch compiler errors and warnings when it is off.

Change-Id: Ic0dedbad41b0faac6e0a2514e694f8e369c61f7f
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: use the same logic in adreno_idle and adreno_isidle

These two functions need to agree on the meaning of "idle",
so that calling adreno_isidle() right after an adreno_idle()
will always return true.

Change-Id: I7cddf73773186c3ec8b56c111affacac3b07fcc7
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: use kgsl_mmu_device_setstate() whenever the gpu is idle

We really don't want new GPU commands or events to be generated
just to manage the iommu while we are idle.

Change-Id: I2e8740bee8c25c93bddc51a90a3370d151aaf558
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: embed kgsl_context struct in adreno_context struct

Having a separate allocated struct for the device specific context
makes ownership unclear, which could lead to reference counting
problems or invalid pointers. Also, duplicate members were
starting to appear in adreno_context because there wasn't a safe
way to reach the kgsl_context from some parts of the adreno code.
This can now be done via container_of().

This change alters the lifecycle of the context->id, which is
now freed when the context reference count hits zero rather
than in kgsl_context_detach().

It also changes the context creation and destruction sequence.
The device specific code must allocate a structure containing
a struct kgsl_context and passes a pointer it to kgsl_init_context()
before doing any device specific initialization. There is also a
separate drawctxt_detach() callback for doing device specific
cleanup. This is separate from freeing memory, which is done
by the drawctxt_destroy() callback.

Change-Id: I7d238476a3bfec98fd8dbc28971cf3187a81dac2
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>