msm: cpufreq: Release cpumask_var_t on all cases

Release cpufreq 'mask' variable when it fails to qualify for changing
cpu frequency.

CRs-fixed: 348827
Signed-off-by: Praveen Chidambaram <pchidamb@codeaurora.org>
(cherry picked from commit fdf788b79589280622f1fb7f761194234442d2ef)

Change-Id: I5d4c03c38d957ba84cac1cc140e509692b8fb1cc
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
msm: memory: Use standard cache routines

Convert custom clean, flush, and invalidate cache routines to use
standard ARM cache routines.

Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
(cherry picked from commit 29bb4d5fa7a285c8fb5d5db55225dab700b80419)

Change-Id: I2c83c27e55811a42fdfdbca08c3db772c5c83e15
Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>
msm: audio: qdsp5: Fix for logical errors in qdsp5

Add missing break statement in AUDIO_FLUSH ioctl in audio_out driver.
Add missing braces for the conditional check for buffer size in
AUDIO_SET_STREAM_CONFIG ioctl for AMR NB, EVRC and QCELP drivers.
Correct the loop terminating logic in audpcm_in_flush() function.
Add break statement in AUDPP_MSG_FLUSH_ACK ioctl in WMA and WMAPro
drivers.

CRs-Fixed: 355773
Signed-off-by: Phani Kumar Allada <pallad@codeaurora.org>
(cherry picked from commit ee940eb44f76503dc818b8a8ed21869b84990547)

Change-Id: I2ebeb27f1a024ae5df3d35f0629d321c3664c615
Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>
msm: qdsp5: Fix logging adsp messages for 32-bit address

- While enable debugfs for adsp messages to collect
D->A logs, it fails and crashes for camcorder usecase.
- Since in D->A logging, there is 32-bit address
queues for camcorder and print is done using 16-bit
pointer resulting in crash.
- Use 32-bit pointer to access 32-bit address queues
and 16-bit pointer for 16-bit address queues.

CRs-Fixed: 368093
Signed-off-by: Laxminath Kasam <lkasam@codeaurora.org>
(cherry picked from commit 6ebf89002b2995e277edbe93fe135c203a509832)

Change-Id: I5e71e61bbd5d8bfb536c67b845fa31d664dd6b6f
Signed-off-by: Sridhar Gujje <sgujje@codeaurora.org>
msm: smd: Fix race condition while processing SMSM callback

When SMSM interrupt is received, a snapshot of SMSM callback is stored
in a kfifo. The snapshot is stored as
	a) SMSM state of each subsystem
	b) Wakelock usage information.

Then a work item is scheduled in global workqueue to process the snapshot
and notify the smsm clients. The smsm snapshot is processed as
	1) Lock the snapshot
	2) Retrieve SMSM states from kfifo and process them
	3) Unlock the snapshot
	4) Retrieve Wakelock usage information from kfifo

When back-to-back smsm interrupts are received, multiple work items are
scheduled in multiple cores. The first work item performs steps 1, 2 &
3 and got pre-empted. In the meanwhile the second work item starts
with Wakelock usage information and reports wrong smsm state to the SMSM
clients.

So schedule the work items in a single thread workqueue and interchange
steps 3 & 4 while processing the SMSM snapshot.

CRs-Fixed: 353552
Change-Id: Ic08e242653cc8d1648ad7a70bf7c5f6b7c089c4e
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
(cherry picked from commit 3249a223df201088289d113b80c70b9d23dea847)
msm: smsm: Cache Flush on SMSM_RESET

Flush inner and outer cache when SMSM_RESET is received by apps proc.
On 7K targets, outer cache is not flushed during panic and ram dumps
do not provide all the updated information.

Change-Id: I97dd1ee10f9ad3656c1dda77f3e7f4542550ab13
Signed-off-by: Adinarayana Gupta Grandhi <agrandhi@codeaurora.org>
(cherry picked from commit 89abbcaed4f4216325f052f005d8d7f11610bbaa)

Signed-off-by: Gopal G Goberu <ggober@codeaurora.org>

Conflicts:

	arch/arm/mach-msm/smd.c
msm: smd_pkt: fix wake lock locking race condition

When smd_pkt receives data for a client in userspace, smd_pkt locks a wake
lock to give the userspace client time to lock their own wake lock if
necessary.  Clients using poll() will trigger the unlocking of the wake
lock in smd_pkt, otherwise smd_pkt modifies the wake lock to expire in two
seconds.

Fix a race condition where smd_pkt locks the wake lock, the client reads
their data and triggers the unlocking, and then smd_pkt relocks the wake
lock when it modifies the timeout to two seconds.  This causes suspend to
be unnecessarily delayed.  The fix is to bypass setting the timeout if the
client has already read their data and triggered the unlocking of the wake
lock.

CRs-Fixed: 367001
Signed-off-by: Jeffrey Hugo <jhugo@codeaurora.org>
(cherry picked from commit 93476a35471a8ffa926ab4474bf028795db95cca)

Conflicts:

	arch/arm/mach-msm/smd_pkt.c

Change-Id: I561abdf34aacaaecd617b80c1ea476d4b9c373f1
Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>
msm: smd_pkt: Fix wakelock concurrency issue

In failure conditions, some clients violate the SMD PKT restriction of
single-threaded access resulting in overlapping open requests which
corrupt the wakelock list.

Move the wakelock initialization into the channel mutex to prevent
concurrent access from corrupting the wakelock.

CRs-Fixed: 374644
Signed-off-by: Eric Holmberg <eholmber@codeaurora.org>

(cherry picked from commit b399a4fbce9c9b20ef258e3245e916cd9ce788e2)

Conflicts:

	arch/arm/mach-msm/smd_pkt.c

Change-Id: I43df498cbf3480b8e345900be49c16afc4669f4a
Signed-off-by: Subrahmanyam Uppala <csuppal@codeaurora.org>
Signed-off-by: Eric Holmberg <eholmber@codeaurora.org>
msm: gic: Remove manual GIC programming for PPI trigger type

There is no need to manually program GIC for edge trigger PPIs
through board or device file hooks after the introduction of
enable_percpu_irq(.., type) interface. 2nd parameter of this
API needs to be used for programming the right trigger
type for the PPI.

Change-Id: Ie200928eb70fcbab6646ddd63acfd89a1a87f5fe
Signed-off-by: Trilok Soni <tsoni@codeaurora.org>
Signed-off-by: Taniya Das <tdas@codeaurora.org>
cpufreq: Add cpu utilization statistics to aid decisions made by userspace.

Understanding system load as seen by cpufreq can help userspace
algorithms make better decisions to improve system responsiveness.
One such example would be the MP decision algorithm which mines
various system info to make decisions on hotplugging in/out
the additional cores.

CRs-fixed: 344675
Signed-off-by: Anitha Anand <anithas@codeaurora.org>
(cherry picked from commit cbeef6aafc4964c4a6cfafd26b23eaccd40804b4)

Change-Id: I7b4450ed7b3bf8196870717e1907fd93c5cfbe98
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>
cpufreq: Fix sysfs deadlock with concurrent hotplug/frequency switch

Running one program that continuously hotplugs and replugs a cpu
concurrently with another program that continuously writes to the
scaling_set_speed node eventually deadlocks with:

=============================================
[ INFO: possible recursive locking detected ]
3.4.0 #37 Tainted: G        W
---------------------------------------------
filemonkey/122 is trying to acquire lock:
 (s_active#13){++++.+}, at: [<c01a3d28>] sysfs_remove_dir+0x9c/0xb4

but task is already holding lock:
 (s_active#13){++++.+}, at: [<c01a22f0>] sysfs_write_file+0xe8/0x140

other info that might help us debug this:
 Possible unsafe locking scenario:

       CPU0
       ----
  lock(s_active#13);
  lock(s_active#13);

 *** DEADLOCK ***

 May be due to missing lock nesting notation

2 locks held by filemonkey/122:
 #0:  (&buffer->mutex){+.+.+.}, at: [<c01a2230>] sysfs_write_file+0x28/0x140
 #1:  (s_active#13){++++.+}, at: [<c01a22f0>] sysfs_write_file+0xe8/0x140

stack backtrace:
[<c0014fcc>] (unwind_backtrace+0x0/0x120) from [<c00ca600>] (validate_chain+0x6f8/0x1054)
[<c00ca600>] (validate_chain+0x6f8/0x1054) from [<c00cb778>] (__lock_acquire+0x81c/0x8d8)
[<c00cb778>] (__lock_acquire+0x81c/0x8d8) from [<c00cb9c0>] (lock_acquire+0x18c/0x1e8)
[<c00cb9c0>] (lock_acquire+0x18c/0x1e8) from [<c01a3ba8>] (sysfs_addrm_finish+0xd0/0x180)
[<c01a3ba8>] (sysfs_addrm_finish+0xd0/0x180) from [<c01a3d28>] (sysfs_remove_dir+0x9c/0xb4)
[<c01a3d28>] (sysfs_remove_dir+0x9c/0xb4) from [<c02d0e5c>] (kobject_del+0x10/0x38)
[<c02d0e5c>] (kobject_del+0x10/0x38) from [<c02d0f74>] (kobject_release+0xf0/0x194)
[<c02d0f74>] (kobject_release+0xf0/0x194) from [<c0565a98>] (cpufreq_cpu_put+0xc/0x24)
[<c0565a98>] (cpufreq_cpu_put+0xc/0x24) from [<c05683f0>] (store+0x6c/0x74)
[<c05683f0>] (store+0x6c/0x74) from [<c01a2314>] (sysfs_write_file+0x10c/0x140)
[<c01a2314>] (sysfs_write_file+0x10c/0x140) from [<c014af44>] (vfs_write+0xb0/0x128)
[<c014af44>] (vfs_write+0xb0/0x128) from [<c014b06c>] (sys_write+0x3c/0x68)
[<c014b06c>] (sys_write+0x3c/0x68) from [<c000e0e0>] (ret_fast_syscall+0x0/0x3c)

This is because store() in cpufreq.c indirectly grabs a kobject
with kobject_get() and is the last one to call kobject_put()
indirectly via cpufreq_cpu_put().

Fix this deadlock by introducing two new functions,
cpufreq_cpu_get_sysfs() and cpufreq_cpu_put_sysfs() which do the
same thing as cpufreq_cpu_{get,put}() but don't grab the kobject.

CRs-fixed: 366560
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
(cherry picked from commit f82ef51be26b44b83d86afa56b3cd9c743023470)

Change-Id: Ia692e64dc3ce40f0ff3e209025a346f7d9b569da
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>
This is a combination of 13 commits.

msm: kgsl: flush outer cache for alloc_page() pages

The outer cache needs to be flushed for these pages
after they are allocated so that the GPU and CPU
have a consistent view of them.

CRs-Fixed: 346921
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
(cherry picked from commit 7018a21bf2b52f1296557d1f6ec9ed64e9169de7)

Change-Id: Id5c11ab8d856fc270330fd3258baa51b8efca192
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>

msm: kgsl: Resolve conflicts in state changes

Only check requested state once, and fully transition to that
specific state.  This will resolve any conflicts arising from
changes to the requested_state as the state transition occurs.

Signed-off-by: Lucille Sylvester <lsylvest@codeaurora.org>
(cherry picked from commit e4a7c1a365ea32aebfe3995e13fc63ca8c2916c5)

Change-Id: I9d351d9d7e479389e473fc6e54d9d06d7ef200b9
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>

msm: kgsl: Allocate physical pages instead of using vmalloc

Replace vmalloc allocation with physical page allocation. For most
allocations we do not need a kernel virual address. vmalloc uses up
the kernel virtual address space. By replacing vmalloc with physical
page alloction and mapping that allocation to kernel space only
when it is required prevents the kgsl driver from using unnecessary
vmalloc virtual space.

CRs-Fixed: 346921

Signed-off-by: Harsh Vardhan Dwivedi <hdwivedi@codeaurora.org>
(cherry picked from commit 8cb835b656ae2c3faa79af4f374563d344b46d4a)

Conflicts:

	drivers/gpu/msm/kgsl_sharedmem.c

Change-Id: I88e1eb282cc4822970811728d00b1096188f64e9
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>

Revert "msm: kgsl: Remove wakelock and pm_qos requirements"

This reverts commit ef44e7338f1c021909133f481348a641d84652ee.

Conflicts:

	drivers/gpu/msm/kgsl_pwrctrl.c

CRs-Fixed: 333977
(cherry picked from commit 10297895f5cf1271309514ded1b34a2a412c0a92)

Change-Id: I74a31ea7f8ddfca6015872721ed2b7582841c74f
Signed-off-by: Lucille Sylvester <lsylvest@codeaurora.org>
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>

msm: kgsl: make pm_qos vote to default when in slumber

Change the pm_qos vote to default when the diplay goes
off. This allows the cpu to do idle power collapse after
display goes off.

CRs-fixed: 333977
Signed-off-by: Suman Tatiraju <sumant@codeaurora.org>
(cherry picked from commit 3005cddf5800135618354f35dd0822e18d1e9b44)

Conflicts:

	drivers/gpu/msm/kgsl_pwrctrl.c

Change-Id: Ie40454287669845e57afc235f17daa8b87176eeb
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>

msm: kgsl: Create ion client in the probe function

Move the call for creating the ion client from kgsl_setup_ion to
kgsl_device_platform_probe. Keeping the create ion client call linked to
kgsl_ioctl_map_user_mem made the user process which first used this
ioctl be forever visible as an ion client in debugfs, even when the
process itself had terminated. Creating ion client in probe ensures that
kgsl appears as the ion client in debugfs and avoids confusion.

CRs-fixed: 349112
Signed-off-by: Harsh Vardhan Dwivedi <hdwivedi@codeaurora.org>
(cherry picked from commit f48af7f2fc1f2c863c48b6d4c65f83ef65228eb7)

Change-Id: I193cd495939210274c7e5d7a6910c319355f3205
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>

msm: kgsl: call sysfs_notify when a hang snapshot is made

/sys/class/kgsl/kgsl-3d0/snapshot/timestamp will have sysfs_notify()
called when a hang happens, so that a userspace process can
poll(2) on this file to detect a hang.

CRs-Fixed: 354385
Change-Id: I0a3c8fcbe3fb09256bcd12f6e63c107536734485
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
(cherry picked from commit 90812c8eac42b5ce7bb48e35897537021e01e6de)

msm: kgsl: Write the retired timestamp on resume

Write the retired timestamp into the expected location. This fixes
userspace crashes after resume when the retired timestamp is read
as 0 instead of the expected last timestamp.

CRs-Fixed: 350556
Signed-off-by: Lynus Vaz <lvaz@codeaurora.org>
(cherry picked from commit 68dba7b544a9f2351d61dff7f7c47aaff96d0413)

Change-Id: Ib57e7d59b5481357ab6f23b460ea435462192065
Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>

msm: kgsl: release the wakelock when going to suspend

This change is needed only if slumber is disabled
CRs-Fixed: 355216
Signed-off-by: Suman Tatiraju <sumant@codeaurora.org>
(cherry picked from commit 48e727689b8fabbb44f20e86f1ad6a04b8111e0a)

Change-Id: Iedcfce9b422c4441442d2a8b667e7ed2ad189348
Signed-off-by: Gopal G Goberu <ggober@codeaurora.org>

msm: kgsl: disable early suspend and late resume for 2d cores.

The powerrail off during slumber is causing a GPU hang

CRs-Fixed: 355216
Signed-off-by: Suman Tatiraju <sumant@codeaurora.org>
(cherry picked from commit 2bd5c33b0c7a47fffc089ced6d14efc0369a5bdc)

Change-Id: I6582aa2fb428f87f5b16975b747e147c673731bb
Signed-off-by: Gopal G Goberu <ggober@codeaurora.org>

msm: kgsl: Do not dereference pointer before checking against NULL

The pagetable pointer was checked against NULL after being used.
Check against NULL first and then dereference it.

Change-Id: I714de9e3b153f212cb92502a21c7d720dd4e1e37
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>

msm: kgsl: convert timestamp_cmp logic to use unsigned logic

The meaning of timestamps becomes difficult to understand when
converting between unsigned and signed values. Values that
were seperated by 0x80000000 also returned inconsistent
results.

CRs-Fixed: 355752

Conflicts:

	drivers/gpu/msm/kgsl.h

Change-Id: I5d5d1ad64ef120da8769d72ac69dde37f8f5c6ae
Signed-off-by: Jeff Boody <jboody@codeaurora.org>

msm: kgsl: fix cleanup code in kgsl_ioctl_map_user_mem()

ion handles need to be handled differently than pmem or
ashmem handles.

CRs-Fixed: 359268
Change-Id: I20637644f247859245fbba80e5bc6b50fd896403
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
(cherry picked from commit 53d4dd028583c3d0a97233d3dff4336ae086ca91)
This is a combination of 29 commits.
msm: kgsl: Make sure that gpu clock goes to turbo after wake

Change-Id: I11348ac36a81ca2bdaf708d2340f2589b88a7d45
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>

msm: kgsl: Store process mem entries in a rbtree

The list of memory objects attached to a process gets searched quite
a lot during normal operation of the driver.  For processes with a
lot of memory allocations, the linear search through the list is O(N)
and uses a lot more CPU during critical loops than it should. Change
the mem entry list to a rbtree for faster search speeds.

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

Conflicts:
	drivers/gpu/msm/kgsl.c
(cherry picked from commit c9559e461e3df1b828218421430a38c9d7a38ca4)

Change-Id: Ie1639fe75718038c8149e519952f7085dede4c0a
Signed-off-by: Jeremy Gebben <jgebben@quicinc.com>

msm: kgsl: rework ib checking

Separate ib parse checking from cffdump as it is useful
in other situations. This is controlled by a new debugfs
file, ib_check. All ib checking is off (0) by default,
because parsing and mem_entry lookup can have a performance
impact on some benchmarks. Level 1 checking verifies the
IB1's. Level 2 checking also verifies the IB2.

Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>

Conflicts:
	drivers/gpu/msm/adreno.h
	drivers/gpu/msm/adreno_pm4types.h
	drivers/gpu/msm/adreno_ringbuffer.c
(cherry-picked from commit d0ab6adeeae7dd039069fd93e6649777aff23668)

Change-Id: If7c93596d0228792002868a56cdf61dc9d34dd5c
Signed-off-by: Jeremy Gebben <jgebben@quicinc.com>

msm: kgsl: Use kzalloc to allocate scatterlists of 1 page or less

The majority of the scatterlist allocations used in KGSL are under 1
page (1 page of struct scatterlist is approximately 1024 entries
equalling 4MB of allocated buffer).  In these cases using vmalloc
for the sglist is undesirable and slow.  Add functions to check the
size of the allocation and favor kzalloc for 1 page allocations and
vmalloc for larger lists.

Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
(cherry-picked from commit a652a07b0d719c4925ca45c018432888dd2388a4)

Conflicts:
	drivers/gpu/msm/kgsl_sharedmem.h

Change-Id: I6b676b4d72f20b43a4cbf3a51099aaa2e8aa8b66
Signed-off-by: Jeremy Gebben <jgebben@quicinc.com>

msm: kgsl: fix 2d IB processing

The 2d hardware handles ringbuffer and IB commands as
a series of gotos. At the end of each IB, there must
be a goto command back to the ringbuffer, which must
be "monkey patched" into the IB by the driver.
Fix this code to use a proper kernel mapping.

Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>

(cherry-picked from commit d27b09f388bab25f7e15ed9c5ca5eb1203c85492)

Change-Id: Ib61d612e9f6f38be147e620eaf6086396ec86228
Signed-off-by: Jeremy Gebben <jgebben@quicinc.com>

Revert "msm: kgsl: Store process mem entries in a rbtree"

This reverts commit 33bceb148eaadf18ea91378dd9b9ac5861b36a09.

Change-Id: Iaa97f45751165a75e83a74da0ef997a11e3ed9db
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>

Revert "msm: kgsl: rework ib checking"

This reverts commit f6924037a5d56f2934ef7d2b2cafb5ab3e49c94e.

Change-Id: Ie14ae137de5e81f7522dfc1e304f190865ae47e2
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>

Revert "msm: kgsl: Use kzalloc to allocate scatterlists of 1 page or less"

This reverts commit 157ce2805727972f48881b37ba1ffe192b1801c6.

Change-Id: Ia7f8ed3c0cc6e379f7752bb3306a94d1705f6e40
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>

Revert "msm: kgsl: fix 2d IB processing"

This reverts commit 7c284e2286cc70d5be0403c09074b381844d3057.

Change-Id: I73855e8bcf077d82d53c9c12c3b5f65e37447645
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>

msm: kgsl: Store process mem entries in a rbtree

The list of memory objects attached to a process gets searched quite
a lot during normal operation of the driver.  For processes with a
lot of memory allocations, the linear search through the list is O(N)
and uses a lot more CPU during critical loops than it should. Change
the mem entry list to a rbtree for faster search speeds.

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

(cherry picked from commit c9559e461e3df1b828218421430a38c9d7a38ca4)

(cherry picked from commit 33bceb148eaadf18ea91378dd9b9ac5861b36a09)

Change-Id: Ic769e0d2bb52cb4d14955942ce6bd8744d8a5995
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>

msm: kgsl: rework ib checking

Separate ib parse checking from cffdump as it is useful
in other situations. This is controlled by a new debugfs
file, ib_check. All ib checking is off (0) by default,
because parsing and mem_entry lookup can have a performance
impact on some benchmarks. Level 1 checking verifies the
IB1's. Level 2 checking also verifies the IB2.

Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>

CRs-Fixed: 351811
(cherry-picked from commit d0ab6adeeae7dd039069fd93e6649777aff23668)

(cherry picked from commit f6924037a5d56f2934ef7d2b2cafb5ab3e49c94e)

Change-Id: Iebf462c29021cf0b7a830a8ff2d4cebcc3a39d43
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>

msm: kgsl: Use kzalloc to allocate scatterlists of 1 page or less

The majority of the scatterlist allocations used in KGSL are under 1
page (1 page of struct scatterlist is approximately 1024 entries
equalling 4MB of allocated buffer).  In these cases using vmalloc
for the sglist is undesirable and slow.  Add functions to check the
size of the allocation and favor kzalloc for 1 page allocations and
vmalloc for larger lists.

CRs-Fixed: 351811
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
(cherry-picked from commit a652a07b0d719c4925ca45c018432888dd2388a4)

(cherry picked from commit 157ce2805727972f48881b37ba1ffe192b1801c6)

Change-Id: I54ff7011cfcbe8128e93063d2b43bc0688902a8f
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>

msm: kgsl: fix 2d IB processing

The 2d hardware handles ringbuffer and IB commands as
a series of gotos. At the end of each IB, there must
be a goto command back to the ringbuffer, which must
be "monkey patched" into the IB by the driver.
Fix this code to use a proper kernel mapping.

CRs-Fixed: 351811
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
(cherry-picked from commit d27b09f388bab25f7e15ed9c5ca5eb1203c85492)

(cherry picked from commit 7c284e2286cc70d5be0403c09074b381844d3057)

Change-Id: I3c04dcff27ecf326b40aad0dc74f46fc0f4b8c95
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>

msm: kgsl: Change name of vmalloc allocator

Change the vmalloc allocation name to something more appropriate since
we do not allocate memory using vmalloc for userspace driver. We
directly allocate physical pages and map that to user address space. The
name is changed to page_alloc instead of vmalloc. Add sysfs files to
track memory usage via both vmalloc and page_alloc.

Signed-off-by: Harsh Vardhan Dwivedi <hdwivedi@codeaurora.org>
(cherry picked from commit f99c263b56dbf6c7c57cf6edd7b3cbbdbc326bbc)

Conflicts:

	drivers/gpu/msm/kgsl_drm.c

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

msm: kgsl: Only return tlb flush flag if bit is set for given device

We should only return the tlb flush flag if the bit corresponding
to the given device is set in the tlb flags. Earlier we were returning
the flush flag always if the tlb flags had the flush bit set for any
device.

Change-Id: Ia598694b295e650ce97dde83ccd89c99e5811d06
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>

msm: kgsl: Report error if regulator enable fails

In function kgsl_pwrctrl_pwrrail check if call to enable the
regulator fails or not and report an error message on failure.

CRs-Fixed: 340649
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
(cherry picked from commit e86ba5ca2814cbbcb803c154bda0c14851d33d37)

Change-Id: Id77422bd73c6a0f5f8106834419cfa13e8e807bd
Signed-off-by: Gopal G Goberu <ggober@codeaurora.org>

msm: kgsl: Check whether the ops pointer is valid.

Check that the ops pointer is valid before using it, otherwise we
may fault.

CRs-fixed: 360810
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
(cherry picked from commit be9799810e79340362978979ce1ff2d9f185904e)

Conflicts:

	drivers/gpu/msm/kgsl.h

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

msm: kgsl: Pass correct datatype to kgsl_mmu_ptpool_destroy()

This fixes a crash due to NULL pointer access when allocation of DMA
Coherent memory fails.

Change-Id: I7ea7405713682aaa7cd660ef341a968342dc0880
Signed-off-by: Ranjhith Kalisamy <ranjhith@codeaurora.org>

msm: kgsl: Follow reverse sequence of init procedure during exit

Fixes kernel warnings about sysfs entries being unavailable when they
are removed during exit.

Change-Id: I6caaaff935b31d3f39a3610cdd2b048baf2f1a97
Signed-off-by: Ranjhith Kalisamy <ranjhith@codeaurora.org>

msm: kgsl: Modify kgsl_core_exit to release resources carefully.

kgsl_core_exit() should not call kgsl_sharedmem_uninit_sysfs() and
device_unregister() if those resources have not been allocated.
We check this by seeing if kgsl_driver.virtdev has been
populated or not.

CRs-fixed: 359477
Change-Id: Ic040667b29bd4e006e6f29a50809d94a2bb4b469
Signed-off-by: Harsh Vardhan Dwivedi <hdwivedi@codeaurora.org>

msm: kgsl: use correct 2d ringbuffer offset in resume

The 2d timestamp is used as an index into the ringbuffer.
Now that z180_dev->current_timestamp is preserved across
resume, make sure that ADDR_VGV3_NEXTADDR is set to the
gpu address that corresponds to the current timestamp.

CRs-Fixed: 347025
Change-Id: Ib7dc4579943ab24e04279ede1555539ec21adabd
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>

msm: kgsl: Add draw workaround commands after every 50 context switches

We need to add a draw workaround command sequence after every 50 context
switches if the gmem has not been saved in those 50 switches. This
workaround is required to prevent the GPU from deadlocking. Since gmem
save commands have draw calls in them we only need to execute this
workaround if the gmem has not been saved. The number 50 was chosen
empirically.

CRs-fixed: 362302
Change-Id: I1a659c85736c47fe6f45030b20ce7a12851b0815
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>

Conflicts:

	drivers/gpu/msm/adreno.h
	drivers/gpu/msm/adreno_a3xx.c

Signed-off-by: Anshuman Dani <adani@codeaurora.org>

msm: kgsl: Issue packet to set shader bases on A20x/220 GPU

When GMEM save is not performed, the events to reuse shader space
can get dropped. This make the CP block to wait indefinitely
causing a hang. To unblock this, issue a packet to set shader bases.
This applies only to A20x/220 GPU.

CRs-fixed: 365465
Signed-off-by: Ranjhith Kalisamy <ranjhith@codeaurora.org>
(cherry picked from commit d71cfd6ee15626dfd66e2b94ed524fbd2488fe91)

Change-Id: I9a4bb72de7922e22f5c9a2d7972062e5ec15a187
Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>

msm: kgsl: Add TLB flush for each submit in case of 8x25/7x2xa

Add TLB flush for each submit to prevent target freeze
in case of 8x25/7x27a/7x25a targets.

CRs-fixed: 379991
Signed-off-by: Rajesh Kemisetti <rajeshk@codeaurora.org>
(cherry picked from commit 22a06d18c6eb100419616ddf7a2c4ac403420a9e)

Change-Id: I7c34660128c791c9329b41246af39879625d64d3
Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>

msm: kgsl: Do bounds checking on user supplied GPU addresses

Add bounds checking to kgsl_sharedmem_find_region to ensure that GPU
addresses supplied by the user via KGSL_IOCTL_SHAREMEM_FREE and
KGSL_IOCTL_CFF_SYNCMEM are within a valid range for the MMU scheme of
choice.

CRs-Fixed: 380296
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
(cherry picked from commit e22e21d93260cee3aff0dff7247635d9624c8aa5)

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

msm: kgsl: Increase REG_RBBM_CNTL value to 0xFFFF for A200

Increase number of clocks that RBBM will wait before de-asserting
the Register Clock Active signal. This fixes kernel panics during
stability tests on multiple devices

Change-Id: I50ad69f28b50444e88239c2332bd5756db1ae089
CRs-fixed: 372793
Signed-off-by: Rammohan Basavaraju <rammoh@codeaurora.org>

msm: kgsl: Update pagetable on context destruction for A20x

Ensure that pagetable is updated during context destruction. This
resolves stability issues during Camera launch/exit scenarios. Applies
only to A20x GPUs. This change is already done for Z180 device.

Change-Id: I955c7220aa8234009f5bca0a273093e47147279d
Signed-off-by: Rammohan Basavaraju <rammoh@codeaurora.org>

msm: kgsl: Set sysfs max clock for devices with no power scale policy

When the sysfs entry for max clock is updated, set it immediately for the
devices that has no power scale policy. This prevents the device from
running with undesired clock.

(cherry picked from commit 6ca8011b4feb30c29e8e6fb5b3571fd2314879e0)

Change-Id: I3a4d689d90036edc243fa97562a79394ace94c2a
CRs-fixed: 408963
Signed-off-by: Ranjhith Kalisamy <ranjhith@codeaurora.org>

msm: kgsl: Turn off the CP_DEBUG dynamic clock

The CP dynamic clock seems to be glitchy when the CP clocks are turned
back on after a power event. Turn off said dynamic clock control at
init time. The impact of leaving the dynamic clock control off is
negligible since the CP clock is only on when the CP is actually in
use.

CRs-fixed: 402119
CRs-fixed: 409253
CRs-fixed: 413224
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
(cherry picked from commit ed201aa291dfe13629d8c6cfa1d6e6f229b0c3c2)

Conflicts:

	drivers/gpu/msm/adreno_ringbuffer.c

Change-Id: I97d82ab71def370c16d4a5504087467aba82e4bb
Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>