GPU Simple Governor: adapt GPU Simple Governor for Snapdrgaon 800 SOCs

initial coding for a Simple GPU governor based on my own work 2 years ago
from Sensation GB kernel commit: c1ea8f6

Signed-off-by: Paul Reioux <reioux@gmail.com>
Simple GPU governor: fix a merge derp

Signed-off-by: Paul Reioux <reioux@gmail.com>
msm: kgsl: Fix Z180 memory leak

Decerement entry refcount, which incremented
in kgsl_sharedmem_find_region.

CRs-Fixed: 635747
Change-Id: I621ba8f8e119a9ab8ba5455b28a565e3cae2f7cd
Signed-off-by: Hareesh Gundu <hareeshg@codeaurora.org>
Simple GPU Algorithm: Initial coding for devfreq based Adreno Drivers

This is an open source user configurable simple GPU Control Algorithm used to
replace the closed sourced Qualcomm TrustZone GPU controller

Signed-off-by: Paul Reioux <reioux@gmail.com>
mdnie: HIJACK MDNIE Profile v1.0a (Yank555.lu)

- added WHATHUB's new control interface keeping the current interface at the same time (stay open)

mdnie lite control: revert back to stocklike disabled by default (Yank555.lu)

mdnie lite control: update single control for black level

- black is applied as a delta to actual black RGB values (-128 to +128)

mdnie lite control: add single control for black level

- slightly adapted to keep copy_mode (Yank555.lu)
- black kept at 0 by default as Natural is kept as base calibration (Yank555.lu)

mdnie lite control: override for all samsung scenarios and profiles (WhatHub)

- slightly adapted to keep copy_mode (Yank555.lu)

mdnie lite control: adjust calibration (WhatHub)

- slightly adapted to keep copy_mode (Yank555.lu)

Simple switchable mdnie lite control interface

- make hijacking STANDARD mode sysfs switchable, disabled by default (Yank555.lu)
- add copy curve information from existing mode
- add copy full mode from existing mode

Sysfs Interface : /sys/class/mdnie/mdnie/...

Simple mdnie lite control interface (WhatHub)

- mdnie lite control: use standard mode instead of movie mode
mdnie: HIJACK MDNIE Profile v1.0b (Yank555.lu)

- change sysfs filerights to 666 by default

mdnie: HIJACK MDNIE Profile v1.0a (Yank555.lu)

- added WHATHUB's new control interface keeping the current interface at the same time (stay open)

mdnie lite control: revert back to stocklike disabled by default (Yank555.lu)

mdnie lite control: update single control for black level

- black is applied as a delta to actual black RGB values (-128 to +128)

mdnie lite control: add single control for black level

- slightly adapted to keep copy_mode (Yank555.lu)
- black kept at 0 by default as Natural is kept as base calibration (Yank555.lu)

mdnie lite control: override for all samsung scenarios and profiles (WhatHub)

- slightly adapted to keep copy_mode (Yank555.lu)

mdnie lite control: adjust calibration (WhatHub)

- slightly adapted to keep copy_mode (Yank555.lu)

Simple switchable mdnie lite control interface

- make hijacking STANDARD mode sysfs switchable, disabled by default (Yank555.lu)
- add copy curve information from existing mode
- add copy full mode from existing mode

Sysfs Interface : /sys/class/mdnie/mdnie/...

Simple mdnie lite control interface (WhatHub)

- mdnie lite control: use standard mode instead of movie mode
cpufreq: CPU max. hardlimit v1.4a (Yank555.lu)

- fix a derp in wakeupkick, scaling min and max were set to wakeup kick frequency, this was wrong, only scaling min should be raised, scaling max shouldn't be lowered

SysFs Interface :

* /sys/kernel/cpufreq/hardlimit (rw)
*
* set or show the real hard CPU frequency limit when screen is on
*
* /sys/kernel/cpufreq/hardlimit_screen_off (rw)
*
* set or show the real hard CPU frequency limit when screen is off
*
* /sys/kernel/cpufreq/wakeup_kick_freq (rw)
*
* set or show the wakeup kick frequency (scaling_min for delay time)
*
* /sys/kernel/cpufreq/wakeup_kick_delay (rw)
*
* set or show the wakeup kick duration (in ms)
*
* /sys/kernel/cpufreq/available_frequencies (ro)
*
* display list of available CPU frequencies for convenience
*
* /sys/kernel/cpufreq/current_limit_max (ro)
*
* display current applied hardlimit for CPU max
*
* /sys/kernel/cpufreq/current_limit_min (ro)
*
* display current applied hardlimit for CPU min
*
* /sys/kernel/cpufreq/version (ro)
*
* display CPU freq hard limit version information

cpufreq: CPU max. hardlimit v1.4 (Yank555.lu)

- keep scaling min/max from overlapping (through sysfs)

* /sys/kernel/cpufreq/hardlimit (rw)
*
* set or show the real hard CPU frequency limit when screen is on
*
* /sys/kernel/cpufreq/hardlimit_screen_off (rw)
*
* set or show the real hard CPU frequency limit when screen is off
*
* /sys/kernel/cpufreq/wakeup_kick_freq (rw)
*
* set or show the wakeup kick frequency (scaling_min for delay time)
*
* /sys/kernel/cpufreq/wakeup_kick_delay (rw)
*
* set or show the wakeup kick duration (in ms)
*
* /sys/kernel/cpufreq/available_frequencies (ro)
*
* display list of available CPU frequencies for convenience
*
* /sys/kernel/cpufreq/current_limit_max (ro)
*
* display current applied hardlimit for CPU max
*
* /sys/kernel/cpufreq/current_limit_min (ro)
*
* display current applied hardlimit for CPU min
*
* /sys/kernel/cpufreq/version (ro)
*
* display CPU freq hard limit version information

cpufreq: CPU max. hardlimit v1.3 (Yank555.lu)

- add a wakeup kick frequency/delay setting scaling min to given frequency for given delay on powersuspend resume

SysFS interface :

* /sys/kernel/cpufreq/hardlimit (rw)
*
* set or show the real hard CPU frequency limit when screen is on
*
* /sys/kernel/cpufreq/hardlimit_screen_off (rw)
*
* set or show the real hard CPU frequency limit when screen is off
*
* /sys/kernel/cpufreq/wakeup_kick_freq (rw)
*
* set or show the wakeup kick frequency (scaling_min for delay time)
*
* /sys/kernel/cpufreq/wakeup_kick_delay (rw)
*
* set or show the wakeup kick duration (in ms)
*
* /sys/kernel/cpufreq/available_frequencies (ro)
*
* display list of available CPU frequencies for convenience
*
* /sys/kernel/cpufreq/current_limit_max (ro)
*
* display current applied hardlimit for CPU max
*
* /sys/kernel/cpufreq/current_limit_min (ro)
*
* display current applied hardlimit for CPU min
*
* /sys/kernel/cpufreq/version (ro)
*
* display CPU freq hard limit version information

cpufreq: CPU max. hardlimit v1.2 (Yank555.lu)

- add a screen off CPU max hardlimit enforced independantly of the used governor

SysFS interface :

* /sys/kernel/cpufreq/hardlimit (rw)
*
* set or show the real hard CPU frequency limit when screen is on
*
* /sys/kernel/cpufreq/hardlimit_screen_off (rw)
*
* set or show the real hard CPU frequency limit when screen is off
*
* /sys/kernel/cpufreq/available_frequencies (ro)
*
* display list of available CPU frequencies for convenience
*
* /sys/kernel/cpufreq/screen_state (ro)
*
* display current screen state as seen by CPU hardlimit
*
* /sys/kernel/cpufreq/current_limit (ro)
*
* display current applied hardlimit
*
* /sys/kernel/cpufreq/version (ro)
*
* display CPU freq hard limit version information

cpufreq: CPU max. hardlimit v1.1 (Yank555.lu)

 - add a hook in cpufreq_verify_within_limits() in cpufreq.h

SysFS interface :

* /sys/kernel/cpufreq/hardlimit (rw)
*
* set or show the real hard CPU frequency limit
*
* /sys/kernel/cpufreq/version (ro)
*
* display CPU freq hard limit version information

cpufreq: update cpu-boost driver to make it behave with cpufreq hardlimit (Yank555.lu)

cpufreq: introduce a hardlimit that will be respected no matter what userspace is trying to force (Yank555.lu)

SysFS interface :

 * /sys/kernel/cpufreq/hardlimit (rw)
 *
 *   set or show the real hard CPU frequency limit
 *
 * /sys/kernel/cpufreq/version (ro)
 *
 *   display CPU freq hard limit version information
cpufreq: CPU max. hardlimit v1.5 (Yank555.lu)

- add user configurable touchboost frequencies

SysFs Interface :

 * /sys/kernel/cpufreq/hardlimit (rw)
 *
 *   set or show the real hard CPU frequency limit when screen is on
 *
 * /sys/kernel/cpufreq/hardlimit_screen_off (rw)
 *
 *   set or show the real hard CPU frequency limit when screen is off
 *
 * /sys/kernel/cpufreq/wakeup_kick_freq (rw)
 *
 *   set or show the wakeup kick frequency (scaling_min for delay time)
 *
 * /sys/kernel/cpufreq/wakeup_kick_delay (rw)
 *
 *   set or show the wakeup kick duration (in ms)
 *
 * /sys/kernel/cpufreq/touchboost_lo_freq (rw)
 *
 *   set or show touchboost low frequency
 *
 * /sys/kernel/cpufreq/touchboost_hi_freq (rw)
 *
 *   set or show touchboost high frequency
 *
 * /sys/kernel/cpufreq/available_frequencies (ro)
 *
 *   display list of available CPU frequencies for convenience
 *
 * /sys/kernel/cpufreq/current_limit_max (ro)
 *
 *   display current applied hardlimit for CPU max
 *
 * /sys/kernel/cpufreq/current_limit_min (ro)
 *
 *   display current applied hardlimit for CPU min
 *
 * /sys/kernel/cpufreq/version (ro)
 *
 *   display CPU freq hard limit version information
cpufreq: CPU max. hardlimit v1.6 (Yank555.lu)

- big code review
- added loads of debugging prints to dmesg (not compiled by default)
- fixed scaling_min/max getting stuck

SysFs Interface :

* /sys/kernel/cpufreq/hardlimit (rw)
*
* set or show the real hard CPU frequency limit when screen is on
*
* /sys/kernel/cpufreq/hardlimit_screen_off (rw)
*
* set or show the real hard CPU frequency limit when screen is off
*
* /sys/kernel/cpufreq/wakeup_kick_freq (rw)
*
* set or show the wakeup kick frequency (scaling_min for delay time)
*
* /sys/kernel/cpufreq/wakeup_kick_delay (rw)
*
* set or show the wakeup kick duration (in ms)
*
* /sys/kernel/cpufreq/touchboost_lo_freq (rw)
*
* set or show touchboost low frequency
*
* /sys/kernel/cpufreq/touchboost_hi_freq (rw)
*
* set or show touchboost high frequency
*
* /sys/kernel/cpufreq/available_frequencies (ro)
*
* display list of available CPU frequencies for convenience
*
* /sys/kernel/cpufreq/current_limit_max (ro)
*
* display current applied hardlimit for CPU max
*
* /sys/kernel/cpufreq/current_limit_min (ro)
*
* display current applied hardlimit for CPU min
*
* /sys/kernel/cpufreq/version (ro)
*
* display CPU freq hard limit version information
cpufreq: CPU max. hardlimit v1.7 (Yank555.lu)

- make touchboost respect hardlimit
- make taking CPUs online respect hardlimit

SysFs Interface :

* /sys/kernel/cpufreq/hardlimit (rw)
*
* set or show the real hard CPU frequency limit when screen is on
*
* /sys/kernel/cpufreq/hardlimit_screen_off (rw)
*
* set or show the real hard CPU frequency limit when screen is off
*
* /sys/kernel/cpufreq/wakeup_kick_freq (rw)
*
* set or show the wakeup kick frequency (scaling_min for delay time)
*
* /sys/kernel/cpufreq/wakeup_kick_delay (rw)
*
* set or show the wakeup kick duration (in ms)
*
* /sys/kernel/cpufreq/touchboost_lo_freq (rw)
*
* set or show touchboost low frequency
*
* /sys/kernel/cpufreq/touchboost_hi_freq (rw)
*
* set or show touchboost high frequency
*
* /sys/kernel/cpufreq/available_frequencies (ro)
*
* display list of available CPU frequencies for convenience
*
* /sys/kernel/cpufreq/current_limit_max (ro)
*
* display current applied hardlimit for CPU max
*
* /sys/kernel/cpufreq/current_limit_min (ro)
*
* display current applied hardlimit for CPU min
*
* /sys/kernel/cpufreq/version (ro)
*
* display CPU freq hard limit version information
cpufreq: CPU max. hardlimit v2.0 (Yank555.lu)

This has grown from a simply OC max control thingy to a full cpufreq control driver, hence the need to review the whole sysfs interface

- added CPU min screen on / off control
- added userspace DVFS lock (prevent scaling min/max changes through sysfs)
- completely new sysfs interface
- lagacy sysfs interface can be kept for compatibily (but without CPU min support, though)

New SysFs Interface :

 * /sys/kernel/cpufreq_hardlimit/scaling_max_freq_screen_on (rw)
 *
 *   set or show the real hard CPU max frequency limit when screen is on
 *
 * /sys/kernel/cpufreq_hardlimit/scaling_max_freq_screen_off (rw)
 *
 *   set or show the real hard CPU max frequency limit when screen is off
 *
 * /sys/kernel/cpufreq_hardlimit/scaling_min_freq_screen_on (rw)
 *
 *   set or show the real hard CPU min frequency limit when screen is on
 *
 * /sys/kernel/cpufreq_hardlimit/scaling_min_freq_screen_off (rw)
 *
 *   set or show the real hard CPU min frequency limit when screen is off
 *
 * /sys/kernel/cpufreq_hardlimit/wakeup_kick_freq (rw)
 *
 *   set or show the wakeup kick frequency (scaling_min for delay time)
 *
 * /sys/kernel/cpufreq_hardlimit/wakeup_kick_delay (rw)
 *
 *   set or show the wakeup kick duration (in ms)
 *
 * /sys/kernel/cpufreq_hardlimit/touchboost_lo_freq (rw)
 *
 *   set or show touchboost low frequency
 *
 * /sys/kernel/cpufreq_hardlimit/touchboost_hi_freq (rw)
 *
 *   set or show touchboost high frequency
 *
 * /sys/kernel/cpufreq_hardlimit/userspace_dvfs_lock (rw)
 *
 *   0 = allow changes to scaling min/max
 *   1 = ignore (don't apply, but don't return an error)
 *   2 = refuse (don't apply, return EINVAL)
 *
 * /sys/kernel/cpufreq_hardlimit/available_frequencies (ro)
 *
 *   display list of available CPU frequencies for convenience
 *
 * /sys/kernel/cpufreq_hardlimit/current_limit_max (ro)
 *
 *   display current applied hardlimit for CPU max
 *
 * /sys/kernel/cpufreq_hardlimit/current_limit_min (ro)
 *
 *   display current applied hardlimit for CPU min
 *
 * /sys/kernel/cpufreq_hardlimit/version (ro)
 *
 *   display CPU freq hard limit version information

Legacy SysFs Interface :

 * /sys/kernel/cpufreq/hardlimit (rw)
 *
 *   set or show the real hard CPU frequency limit when screen is on
 *
 * /sys/kernel/cpufreq/hardlimit_screen_off (rw)
 *
 *   set or show the real hard CPU frequency limit when screen is off
 *
 * /sys/kernel/cpufreq/wakeup_kick_freq (rw)
 *
 *   set or show the wakeup kick frequency (scaling_min for delay time)
 *
 * /sys/kernel/cpufreq/wakeup_kick_delay (rw)
 *
 *   set or show the wakeup kick duration (in ms)
 *
 * /sys/kernel/cpufreq/touchboost_lo_freq (rw)
 *
 *   set or show touchboost low frequency
 *
 * /sys/kernel/cpufreq/touchboost_hi_freq (rw)
 *
 *   set or show touchboost high frequency
 *
 * /sys/kernel/cpufreq/available_frequencies (ro)
 *
 *   display list of available CPU frequencies for convenience
 *
 * /sys/kernel/cpufreq/current_limit_max (ro)
 *
 *   display current applied hardlimit for CPU max
 *
 * /sys/kernel/cpufreq/current_limit_min (ro)
 *
 *   display current applied hardlimit for CPU min
 *
 * /sys/kernel/cpufreq/version (ro)
 *
 *   display CPU freq hard limit version information
cpufreq: CPU max. hardlimit v2.0a (Yank555.lu)

- fixed wakeup_kick_freq must be between screen on min and max (instead of screen on max and screen off max)

Thanx to zancum for reporting this !

New SysFs Interface :

* /sys/kernel/cpufreq_hardlimit/scaling_max_freq_screen_on (rw)
*
* set or show the real hard CPU max frequency limit when screen is on
*
* /sys/kernel/cpufreq_hardlimit/scaling_max_freq_screen_off (rw)
*
* set or show the real hard CPU max frequency limit when screen is off
*
* /sys/kernel/cpufreq_hardlimit/scaling_min_freq_screen_on (rw)
*
* set or show the real hard CPU min frequency limit when screen is on
*
* /sys/kernel/cpufreq_hardlimit/scaling_min_freq_screen_off (rw)
*
* set or show the real hard CPU min frequency limit when screen is off
*
* /sys/kernel/cpufreq_hardlimit/wakeup_kick_freq (rw)
*
* set or show the wakeup kick frequency (scaling_min for delay time)
*
* /sys/kernel/cpufreq_hardlimit/wakeup_kick_delay (rw)
*
* set or show the wakeup kick duration (in ms)
*
* /sys/kernel/cpufreq_hardlimit/touchboost_lo_freq (rw)
*
* set or show touchboost low frequency
*
* /sys/kernel/cpufreq_hardlimit/touchboost_hi_freq (rw)
*
* set or show touchboost high frequency
*
* /sys/kernel/cpufreq_hardlimit/userspace_dvfs_lock (rw)
*
* 0 = allow changes to scaling min/max
* 1 = ignore (don't apply, but don't return an error)
* 2 = refuse (don't apply, return EINVAL)
*
* /sys/kernel/cpufreq_hardlimit/available_frequencies (ro)
*
* display list of available CPU frequencies for convenience
*
* /sys/kernel/cpufreq_hardlimit/current_limit_max (ro)
*
* display current applied hardlimit for CPU max
*
* /sys/kernel/cpufreq_hardlimit/current_limit_min (ro)
*
* display current applied hardlimit for CPU min
*
* /sys/kernel/cpufreq_hardlimit/version (ro)
*
* display CPU freq hard limit version information
fs/dyn_sync_cntrl: dynamic sync control v1.5 (faux123)

The dynamic sync control interface uses new power_suspend interface

While screen is on, file sync is disabled
when screen is off, a file sync is called to flush all outstanding writes
and restore file sync operation as normal.

updated for 8974 kernels

Signed-off-by: Paul Reioux <reioux@gmail.com>;

fs/dyn_sync_cntrl: keep dynamic sync control off by default (Yank555.lu)
LED eXtended ConTRoLs v1.1 (Yank555.lu)

  - Fixes Samsung LED pattern not repecting the user changes

 * SysFs interface :
 *
 * /sys/class/sec/led/led_intensity : 0 - 255 (100 = stock)
 *
 *     Set the relative intensity of the LED respecting the userspace's request
 *
 * /sys/class/sec/led/led_speed_on  : 1 - 5 (1 = stock)
 *
 *     Devider for delayon  (1 - 5 times shorter than requested by userspace)
 *
 * /sys/class/sec/led/led_speed_off  : 1 - 5 (1 = stock)
 *
 *     Devider for delayoff (1 - 5 times shorter than requested by userspace)
 *
 * /sys/class/sec/led/led_xctrl_version :
 *
 *     Display the current version of the eXtended ConTRoLs
 *
 * /sys/class/sec/led/led_xctrl_info :
 *
 *     Display the current settings in human readable format

LED eXtended ConTRoLs v1.0 (Yank555.lu)

 - Allow for customized brightness and delayon / delayoff control by user

 * SysFs interface :
 * -----------------
 *
 * /sys/class/sec/led/led_intensity : 0 - 255 (100 = stock)
 *
 *     Set the relative intensity of the LED respecting the userspace's request
 *
 * /sys/class/sec/led/led_speed_on  : 1 - 5 (1 = stock)
 *
 *     Devider for delayon  (1 - 5 times shorter than requested by userspace)
 *
 * /sys/class/sec/led/led_speed_off  : 1 - 5 (1 = stock)
 *
 *     Devider for delayoff (1 - 5 times shorter than requested by userspace)
 *
 * /sys/class/sec/led/led_xctrl_version :
 *
 *     Display the current version of the eXtended ConTRoLs
 *
 * /sys/class/sec/led/led_xctrl_info :
 *
 *     Display the current settings in human readable format
leds: Add Yank555.lu kernel LED boot signature (for fun)
char-random: increase default entropy settings to (512,2048)
binfmt_elf.c: use get_random_int() to fix entropy depleting (Jeff Liu )

See http://lkml.indiana.edu/hypermail/linux/kernel/1211.1/03767.html for details.
cpufreq: Resolve CPUFREQ_NOTIFY issue

When the cpufreq_stat receives the frequency policy notification,
it checks if the frequency table and stats table are present for the cpu.
If both are present, it returns with -EBUSY error to the notification.
Due to this, none of the other registered modules receive this
notification.

If the stat table and sysfs nodes are already created, return 0 instead
of returning EBUSY error.

Change-Id: I1fd4a46e6a65edfc6253c4271288f10912ae2ad7
Signed-off-by: Archana Sathyakumar <asathyak@codeaurora.org>
Cpufreq: create/remove percpu sysfs nodes once

On cpu hotplug on/off, percpu "cpufreq" sysfs node and it's
sub nodes are freshly created and removed. This increases
cpu up/down latency.

Create percpu "cpufreq" sysfs node and it's sub nodes in driver
registration and remove it in unregistration. This decreases
cpu up/down latency significantly.

Change-Id: I5c2b02e74de0ae4fe08dedc959bd7402cd9b7aa5
Signed-off-by: Puneet Saxena <puneets@nvidia.com>
Reviewed-on: http://git-master/r/146812
(cherry picked from commit 298382285677fa791098d117ccc0a0a3d9ab0f9a)
Reviewed-on: http://git-master/r/219379
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Sachin Nikam <snikam@nvidia.com>

modified for use on Mako by faux123

Signed-off-by: Paul Reioux <reioux@gmail.com>
nohz: stat: Fix CPU idle time accounting

Since cpustat[CPUTIME_IDLE] is never connected to ts->idle_sleeptime,
never read from cpustat[CPUTIME_IDLE] when reporting stats in
/proc/stat.

Note this was rejected by Michal Hocko when it was initially proposed
by Martin Schwidefsky in LKML, so if you want to upstream it, better
find an alternative (either completely disable cpustat[CPUTIME_IDLE]
for CONFIG_NO_HZ or somehow connect them to keep them in sync.)

bug 1190321

Change-Id: Idc92488910b826aff850a010016d8326c7ab9e6c
Signed-off-by: Bo Yan <byan@nvidia.com>
Reviewed-on: http://git-master/r/214638
Reviewed-by: Automatic_Commit_Validation_User
GVS: Gerrit_Virtual_Submit
Reviewed-by: Liang Cheng (SW) <licheng@nvidia.com>
Tested-by: Liang Cheng (SW) <licheng@nvidia.com>