msm: kgsl: Add max and min power level controls in sysfs

Add min_pwrlevel, max_pwrlevel and thermal_pwrlevel to give a
privileged user more control over which power levels are considered
during DCVS power management.  max_pwrlevel is the maximum power
level that the system can go to at any time, min_pwrlevel represents
the lowest power level.  DCVS will chose any level between these
two extremes.  thermal_pwrlevel allows a daemon to set an absolute
top for frequency to prevent thermal issues. The effective maximum
power level is considered to be the lower of thermal or max.

Also added is num_pwrlevels that shows the number of active power
levels. This corresponds to the gpu frequencies in
available_gpu_frequencies.

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

Conflicts:

	drivers/gpu/msm/kgsl_pwrctrl.c
	drivers/gpu/msm/kgsl_pwrctrl.h
msm: kgsl: Always set the active powerlevel when changing clock rates

kgsl_pwrctrl_pwrlevel_change might be called when clocks are on or off.
If clocks are off we don't step the clock rate and the active_pwrlevel
won't be set to the new and correct level.  Set active_pwrlevel to its
new level before doing anything else.

Change-Id: Ic0dedbad84ce1cc1b3b8df97df32e39686b85671
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Use signed integers for power level comparsions

The code that clamped the power levels to the requested minimum and
maximum values was mixing comparison signed and unsigned integers with
predictiably faulty results.  Move all values to signed integers to
handle negative power level numbers correctly

CRs-fixed: 427670
Change-Id: Ic0dedbada6153dc0b109923b376c3aa9a6abbeee
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Make the GPU device aware of the next pending event

The adreno core needs to know what the next event pending for
any given context is so it can mark the interupt to be fired.
If this isn't done then some timestamps that don't have a
matching waittimestamp call won't fire an interrupt. This is
dangerous on the last interrupt/event before a context goes
away.

Change-Id: Ic0dedbad71f6de07b43b0656128c76509326d645
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Remove extra interrupts when setting MMU state

The interrupts added to the ringbuffer on PTFLUSH and TLBUPDATE
were causing a major increase in the number of interrupts from the GPU.
This was leading to increase in power and loss of performance. Add a check
to turn off IOMMU clocks when going to SLEEP.

Change-Id: I41617dd3b7b3f7d9622523f2a1407b912dbd989e
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: Idle GPU core before programming SMMU from CPU

Always idle the GPU core before programming SMMU from CPU for
SMMU-v1. GPU core was already being idled before programming
the pagetable register, make sure that it's also idle before
programming the tlb invalidate registers. This is required to
prevent a deadlock from happening at the bus level.

Change-Id: Ie901b92028b289fc546ab6186eedd01411d0727e
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
Signed-off-by: Rajeev Kulkarni <krajeev@codeaurora.org>
msm: kgsl: Synchronize access to IOMMU cfg port

Add a software based spinlock between CPU and GPU.
This spinlock is used to grant mutually exclusive access to
SMMU configuration between CPU and GPU. This mutual exclusion
is required to prevent deadlock in the system.

CRs-Fixed: 409198
Change-Id: Ic375beaaf4c5505b41d3fabc4adf15965d71b13a
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
Signed-off-by: Rajeev Kulkarnie <krajeev@codeaurora.org>
msm: dcvs: add ss_no_corr_below_freq parameter

The busy/idle behavior of different cores can be correlated by
DCVS when determining what frequency to run cores at. However,
this is not desirable below a certain frequency. Add a parameter
to establish what this frequency is. The parameter is configurable
in userspace via sysfs.

The ss_iobusy_conv parameter is currently unused, so it is
being replaced with ss_no_corr_below_freq.

(cherry picked from commit e8c6d615259af5fde8a6613f53c41c212407bda9)

Change-Id: Ibf814f3f93b92a532d7b3af80721a5bc7db1bd31
Signed-off-by: Steve Muckle <smuckle@codeaurora.org>

Conflicts:

	Documentation/devicetree/bindings/gpu/adreno.txt
msm: kgsl: Define unique values for context flags

Use BIT to define all context related flags. This ensures
that these flags are unique and is easier to maintain. Also,
fix spelling of CTXT_FLAGS_BEING_DESTOYED to
CTXT_FLAGS_BEING_DESTROYED

Change-Id: I866c67b9c5d59d6117e31714756af3106018f9cb
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: Check for valid pointer before dereferencing

Check to make sure that there is a valid context pointer before
dereferencing it when adding commands to the ringbuffer.

Change-Id: Icf9824de8f62a28cdeeef4378246d9fb334d39fa
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>