msm: kgsl: Fix policy sysfs implementation

When switching to another governor, the pwrscale kobject will be deleted
and sysfs_create_group fails due to the uninitialized kobj. This patch
deletes the kobject before attaching the file group.

[   36.270044] [<c0134304>] (__kmalloc_track_caller+0x80/0x194) from [<c010a6d0>] (kstrdup+0x2c/0x54)
[   36.270166] [<c010a6d0>] (kstrdup+0x2c/0x54) from [<c019cc98>] (create_dir+0x24/0x204)
[   36.270257] [<c019cc98>] (create_dir+0x24/0x204) from [<c019d154>] (sysfs_create_subdir+0x24/0x2c)
[   36.270318] [<c019d154>] (sysfs_create_subdir+0x24/0x2c) from [<c019e878>] (sysfs_create_group+0x40/0x1d8)
[   36.270441] [<c019e878>] (sysfs_create_group+0x40/0x1d8) from [<c0389e40>] (kgsl_pwrscale_policy_add_files+0x44/0x68)
[   36.270563] [<c0389e40>] (kgsl_pwrscale_policy_add_files+0x44/0x68) from [<c038e714>] (conservative_init+0xc/0x18)
[   36.270654] [<c038e714>] (conservative_init+0xc/0x18) from [<c0389c6c>] (pwrscale_policy_store+0xcc/0x154)
[   36.270776] [<c0389c6c>] (pwrscale_policy_store+0xcc/0x154) from [<c0389a90>] (pwrscale_sysfs_store+0x20/0x2c)
[   36.270868] [<c0389a90>] (pwrscale_sysfs_store+0x20/0x2c) from [<c019b2a4>] (sysfs_write_file+0x168/0x198)
[   36.270990] [<c019b2a4>] (sysfs_write_file+0x168/0x198) from [<c01382c4>] (vfs_write+0x9c/0x170)
[   36.271112] [<c01382c4>] (vfs_write+0x9c/0x170) from [<c0138440>] (sys_write+0x38/0x70)
[   36.271173] [<c0138440>] (sys_write+0x38/0x70) from [<c000f000>] (ret_fast_syscall+0x0/0x30)
[   36.271265] Code: e7925001 e3550000 0a000033 e5942014 (e795a002)
[   36.271661] ---[ end trace ef0d8b9c8acc7bbb ]---
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
msm: kgsl: Set requested power state to NONE after resume

When GPU resumes from suspend requested state is not cleared to NONE.
Due to this idle reporting is not done and GPU stays at MAX freq. As
a fix if the current power state is already ACTIVE and request is
made for active power state then clear the requested state immediately.

CRs-fixed: 424682
Change-Id: I7f0d7fa819308f166cbbbf30b2c20aee73644cfb
Signed-off-by: Vinay Roy <vroy@codeaurora.org>
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: Process all idle checks

Rather than ignore some categories of idle events,
bin the events with small timelines and process all
events with the GPU DCVS algorithm.

CRs-Fixed: 427559
Signed-off-by: Lucille Sylvester <lsylvest@codeaurora.org>
Change-Id: I1a5e8d8af6020a08cf95a9daa934e825bc5f2854
msm: kgsl: pwrscale functions should be run while GPU is ACTIVE

Base the decision to call power scaling functions on the current
state, not the requested state.  The GPU may not transition to the
requested state; call through based on current GPU state instead.

Change-Id: I1524bc92c908dc50a60b5815f2221ae3feef59be
CRs-Fixed: 441847
Signed-off-by: Lucille Sylvester <lsylvest@codeaurora.org>
kgsl: Implement conservative scaling policy

This behaves similarly to the conservative cpufreq governor,
which is similar to how most Mali GPU scaling algorithms behave.

The "trustzone" policy that is default relies on an undocumented
black box to make scaling decisions.

How to enable:
echo conservative > /sys/devices/platform/kgsl-3d0.0/kgsl/kgsl-3d0/pwrscale/policy

Conservative attr group:	18
/sys/devices/platform/kgsl-3d0.0/kgsl/kgsl-3d0/pwrscale/policy_config/conservative

Polling interval (10-1000):
/sys/devices/platform/kgsl-3d0.0/kgsl/kgsl-3d0/pwrscale/policy_config/conservative/polling_interval

Enable stats printing (causes microlags on low polling intervals):
echo 1 > /sys/devices/platform/kgsl-3d0.0/kgsl/kgsl-3d0/pwrscale/policy_config/conservative/print_stats

NOTE:
- perms are set to 666 for testing purposes
Change-Id: I9d854a73981515fc9850104302804928b04c4687
Signed-off-by: Andrew Dodd <atd7@cornell.edu>
msm: kgsl: conservative: Lindent, cleanup, adjust thresholds
msm: kgsl: Define PWRSCALE_POLICY_ATTR with a static scope