msm: mpdecision: Add mpdecision driver code.

This driver is mainly responsible to convey the runqueue average and
iowait average values to the TZ periodically. The TZ returns the mask
of the cpu's that should be online and the slack timer.

The mpdecision code brings cpus up or down to match the online mask
from TZ. Also starts the slack timer as specified by TZ.

Upon expiry of the slack timer mpdecision calls TZ to get a new
mask and a new slack timer.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit a599de41a47b0b1a9f81a77227e16aff5a16a072)

Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit d2cf2db9632c3c2a33bc66ff61b2c2b758c10c86)

Change-Id: I30020fade79b61f86cbec52c90a1f5861a673a4c
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>

Conflicts:

	arch/arm/mach-msm/Makefile

Conflicts:

	arch/arm/mach-msm/include/mach/msm_dcvs_scm.h
	arch/arm/mach-msm/msm_dcvs_scm.c
	arch/arm/mach-msm/msm_mpdecision.c
msm: mpdcvs: add ftrace events.

Add ftrace events at interesting points in the dcvs and mpdecision code.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit f17f2d347acf17097ab5c6907bdc5a4c9e631a6d)

Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit 950f6a4af8454ffff69b84bd3830c7091bc53c0c)

Change-Id: Ic5cc00539b837090010627f364428c157137f052
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>

Conflicts:

	arch/arm/mach-msm/msm_mpdecision.c
msm: dcvs: run dcvs, mpdecision threads at default priority

It is not necessary to run these threads at a realtime
priority level.

Change-Id: I8c6492f22e803811db5757c51beeeb81f93f32b6
Signed-off-by: Steve Muckle <smuckle@codeaurora.org>
(cherry picked from commit 8862f41f1c632ba84f0a21e8045d70278fd67fd3)

Conflicts:

	arch/arm/mach-msm/msm_mpdecision.c
msm: mpdecision: wait at least 100ms between cpu hotremoves

To avoid spending a lot of time at once in the cpu hotremove
path, do not perform multiple hotremoves back to back.

Change-Id: I78a643f73718e4e08786193c71bbe2237aa790d2
Signed-off-by: Steve Muckle <smuckle@codeaurora.org>
(cherry picked from commit 9c0aa035f7aeac1b1039125bf27d51d11861fa03)

Conflicts:

	arch/arm/mach-msm/msm_mpdecision.c
msm: dcvs: set gpu frequency floor when multiple CPUs online

Performance is enhanced if the GPU frequency is floored at its
maximum nominal frequency when multiple CPUs are online.

Change-Id: Ib6bfd5007d660064844876b06f552f4d8c84865c
Signed-off-by: Steve Muckle <smuckle@codeaurora.org>
(cherry picked from commit 749f301c94312d2ec827c67cecb858e02383c8ab)

Conflicts:

	arch/arm/mach-msm/include/mach/msm_dcvs.h
	arch/arm/mach-msm/msm_dcvs.c
	arch/arm/mach-msm/msm_mpdecision.c
msm: dcvs: set algo params according to number of online CPUs

It is desirable for performance reasons to be able to run dcvs
with different algorithm parameters depending on the number of
CPUs that are online. The algorithm parameters are already replicated
per-CPU, but all CPUs operate in DCVS with the same parameters at
any given time.

These per-CPU parameters now correspond to the total number of CPUs
online. For example, if 2 CPUs are online, the algorithm parameters
for CPU2 are used.

Change-Id: If308a2fa949ac669823e759e0fd8e2cdbf6e4c03
Signed-off-by: Steve Muckle <smuckle@codeaurora.org>
(cherry picked from commit c48381e2336125410549d7df1425dc8009c0c495)

Conflicts:

	arch/arm/mach-msm/include/mach/msm_dcvs.h
	arch/arm/mach-msm/msm_dcvs.c
	arch/arm/mach-msm/msm_mpdecision.c
msm: mpdecision: make runqueue divisor configurable via sysfs

The runqueue divisor controls how sensitive mpdecision is to
changes in runqueue depth - if the runqueue divisor is increased,
updates to TZ are made less frequently. It is desirable to be able
to easily change this parameter from userspace.

(cherry picked from commit f5d5d54a8c64337115a44d9d9292c677042c9fc1)

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

Conflicts:

	arch/arm/mach-msm/msm_mpdecision.c
Clean
msm: dcvs: update the event enum in preparation for mpdecision.

The event numbers used to communicate with TZ have changed. Update
them here in preparation of mpdecision.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit 0db555f69e8e5b5237f2c053fffeeec3926084a1)

Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit deda7f0ef23aea568975ec73d4f54022f468adef)

Change-Id: I8a0bd62d06135714ce954c4cf6083523f5c1ca84
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>

Conflicts:

	arch/arm/mach-msm/include/mach/msm_dcvs.h
	arch/arm/mach-msm/msm_dcvs.c
msm: dcvs: rearrange platform data.

This change
-removes the use of group id and instead introduces core type
-rearranges platform data, adds energy curve coefficients and power
 parameters
-allow for the energy params to be -ve numbers

The change also mandates updates to the msm8974-gpu.dtsi and the
associated binding documentation.

Also take this opportunity to remove devices for unsupported platform
- 8930 and 8960

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit 4445166ad16be0c45b077bfb10487de355ed2e05)

Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit 24d2351f6a5e7069e5d554dbc999280a69288c5d)

Change-Id: I5c65c0e65cc7652eee72c525f0db10e128061cf9
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>

Conflicts:

	Documentation/devicetree/bindings/arm/msm/dcvs-core-info.txt
	arch/arm/boot/dts/msm8974-gpu.dtsi
	arch/arm/mach-msm/board-8064-gpu.c
	arch/arm/mach-msm/board-8930.c
	arch/arm/mach-msm/board-8960.c
	arch/arm/mach-msm/devices-8064.c
	arch/arm/mach-msm/devices-8930.c
	arch/arm/mach-msm/devices-8960.c
	arch/arm/mach-msm/devices.h
	arch/arm/mach-msm/include/mach/msm_dcvs.h
	arch/arm/mach-msm/include/mach/msm_dcvs_scm.h
	arch/arm/mach-msm/msm_dcvs.c
	drivers/cpufreq/cpufreq_gov_msm.c
	drivers/gpu/msm/adreno.c
	drivers/gpu/msm/kgsl_pwrscale_msm.c
msm: dcvs: Add thermal interfaces.

The algorithm needs thermal inputs for all the cores. Create members in
the internal core_info strucutre and platform data/device tree to pass
in the sensors they use.

Update the dcvs code to notify the temperature to TZ.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit fc7dca4c325725492af997fa282e07b9d03154d1)

Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit eb478c5b7b55ea8a57e0336e4cf9979be935b289)

Change-Id: I505903eb8b9779f2065aebfab5b3f2aefc874200
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>

Conflicts:

	Documentation/devicetree/bindings/arm/msm/dcvs-core-info.txt
	arch/arm/boot/dts/msm8974-gpu.dtsi
	arch/arm/mach-msm/include/mach/msm_dcvs.h
	arch/arm/mach-msm/msm_dcvs.c
	drivers/cpufreq/cpufreq_gov_msm.c
	drivers/gpu/msm/adreno.c
cpufreq: msm: remove gov_mutex from stop.

The stop could end up calling set_frequency callback. The set_frequency
callback takes the same gov_mutex lock and we end up in a deadlock.

Fix this by removing the locks around stop.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit 5106c477a747279dbf045eed5a6ab4f68ac3501c)

Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit e0fa1831db0c57a8be8d5471ee3382b0f8a9165e)

Change-Id: I306f9cd2c05ce1e9c4c36d22d16b775a42881f0d
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>

Conflicts:

	drivers/cpufreq/cpufreq_gov_msm.c
cpufreq: msm: fix race in cpufreq.

__cpufreq_driver_target expects to be called with the rw semaphore
held. We are not doing this when the frequency is asked to be changed
by dcvs.

Use cpufreq_driver_target variant of that function which gets the
rw semaphore before setting the frequency.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit 54fc08ea6d33c6c561167f369cba060fe33755c9)

Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit a63446bcd75909db632ffc8ff3c4e6a96c8593c5)

Change-Id: I33cdac0aaac7fb44acf6f9eb451a80ff94175c46
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>

Conflicts:

	drivers/cpufreq/cpufreq_gov_msm.c
msm: dcvs: prevent thread creations upon cpu hotplug insertions.

Numerous threads were seen created and left idle as cpu's were
hotplugged in and out. Avoid creating new threads unnecessarily.

Instead create just one thread when a core is registered and use
it later.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit e039aac0c0be7c0d914055224103e8f41821320d)

Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit dbbe1e71a6f1be2dee99104281ad47e6884891bc)

Change-Id: Ib1255f9df5b41fbb49d25fdd6d661ebfa7f7642b
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>

Conflicts:

	arch/arm/mach-msm/msm_dcvs.c
msm: dcvs: get rid of the pending freq array.

Only one pending frequency should be set, there is no need to
maintain an array of intermediate requests.

Cleanup the code and remove new_freq[] array and the index to
it. Introduce pending_freq a single entity that carries the
latest frequency request. Use the core's cpu_lock to protect
it.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit bea1b7628356bd953a88596c556373a6ec355f94)

Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit 32f01b8af255b565d5bcf1496a1aaea77250e205)

Change-Id: Ie939700f7f62e453638e73f489e729105e363d29
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>

Conflicts:

	arch/arm/mach-msm/msm_dcvs.c
msm: dcvs: use wait_q.

It is cleaner to use wait_q mechanism instead of waking up the thread
and managing the scheduling flag ourselves.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit 33bf417160e9340f2dd5f9f275e7e6021987bfe1)

Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit de943e4aff2a26e0d21b208d85b5876c31bfda85)

Change-Id: I4316ee58633f7353197654074263466cdaa25778
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>

Conflicts:

	arch/arm/mach-msm/msm_dcvs.c
msm: dcvs: update dcvs if the governor limits change.

We had seen issues where dcvs goes out of sync with the actual
freq the cpu is running at. The root cause was if the userspace
changes the limits on the governor, the governor ends up changing
the frequency without notifying dcvs.

Provide an api for the governor to call dcvs when a frequency change
happens.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit 68c970e38fcb700d851301dbacc56da9387294c6)

Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit a7d720e513cfae2d3f9c03c25f2ce2f10c2e9de7)

Change-Id: I3f321df0270e997531d1a4cf3ee2251f86aef0bc
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>

Conflicts:

	arch/arm/mach-msm/include/mach/msm_dcvs.h
	arch/arm/mach-msm/msm_dcvs.c
	drivers/cpufreq/cpufreq_gov_msm.c
msm: dcvs: provide frequency set/get callbacks at registration.

There is no need to register a separate structure for setting and
getting frequency.

Simply pass function pointers to set and get callbacks when a
core is registered.

While at it rename the msm_dcvs_freq_sink_register/unregister to
msm_dcvs_freq_sink_start/stop to better reflect that those
apis are meant to do.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit 69134111c2a24002d1995a05c99f84403ac6a7e8)

Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit 52cb57c3c6bc1c0d08c1ae9eb5dd0ff1e1125a96)

Change-Id: Iee7aee1cbb2f33ed2852f1816ab62416b96fa7e6
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>

Conflicts:

	arch/arm/mach-msm/include/mach/msm_dcvs.h
	arch/arm/mach-msm/msm_dcvs.c
	drivers/cpufreq/cpufreq_gov_msm.c
	drivers/gpu/msm/kgsl_pwrscale_msm.c
msm: dcvs: remove idle notification registration.

Register the idle enable callback along with the core. The code
becomes cleaner and easy to update.

Importantly, the msm_dcvs_idle driver becomes useless. Remove it
and instead let the msm governor handle idle enabling and disabling.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit c1ed66c9035b4fbf240e46837d86a9a6442531f1)

Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit b4f5c2274fa2180b53563f2db0922eef212c0fcd)

Change-Id: Ice039e608d45bdeb9b8b718e5fbbf82a698d584d
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>

Conflicts:

	arch/arm/mach-msm/Makefile

Conflicts:

	arch/arm/mach-msm/board-8064.c
	arch/arm/mach-msm/board-8930.c
	arch/arm/mach-msm/board-8960.c
	arch/arm/mach-msm/devices-8064.c
	arch/arm/mach-msm/devices-8930.c
	arch/arm/mach-msm/devices-8960.c
	arch/arm/mach-msm/devices.h
	arch/arm/mach-msm/include/mach/msm_dcvs.h
	arch/arm/mach-msm/msm_dcvs.c
	drivers/cpufreq/cpufreq_gov_msm.c
	drivers/gpu/msm/kgsl_pwrscale_msm.c
msm: 8064: add board file structures for mpdecision and msm governor.

Add device structures in the board file for mpdecision and the msm
governor. This essentially probes mpdecision driver and the msm
governor driver. When enabled mpdecision communicates the run queue
average with TZ and obtains back a mask of which cpus should be
online. The msm governor communicates the frequencies of the cpus
with TZ and obtains newer frequency for that cpu.

Both combined they govern which cpus stay online and how fast they
run.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit fb4a2f8e62af9cfa0852b16b2370f0d3df324e59)

Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit 2015b46a54dbcae9439cec27dddee1916d3071f3)

Conflicts:

	arch/arm/mach-msm/board-8064.c

Change-Id: Ic720e88e110b320ef3ce1ae35901411202066951
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>

Conflicts:
	arch/arm/mach-msm/board-8064.c
	arch/arm/mach-msm/devices-8064.c

Conflicts:

	arch/arm/mach-msm/board-8064.c