msm: kgsl: disable irq when adreno device is stopped

When restoring to slumber from nap, the irq is kept enabled causing a
power drain. This change ensures that adreno device behaves similar to
z180 device.

CRs-Fixed: 331847
Signed-off-by: Ranjhith Kalisamy <ranjhith@codeaurora.org>
(cherry picked from commit ce75b0c9008e6cdc22d2bff833ef96c9bd1b2c94)

Change-Id: I5c8280d707d8d0447ed8918130666f4c65f0136e
Signed-off-by: Swetha Basineni <sbasin@codeaurora.org>
msm: kgsl: Make sure SLUMBER is the requested state

The stop_work function releases the device mutex to flush
the workqueue.  The requested state may change while the
mutex is held by a different thread.  So set the requested
state after stop_work.

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

Change-Id: I6bae6e904d7cf475adab63aa5ea5ccce3a0bdfb7
Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
Revert "msm: kgsl: flush device workqueue before stop"

This reverts commit 70dd406a399254a5420b23b94f915a2886ce6dee.

Conflicts:

	drivers/gpu/msm/adreno.c
	drivers/gpu/msm/adreno_postmortem.c
	drivers/gpu/msm/kgsl.c
	drivers/gpu/msm/kgsl_pwrctrl.h
msm: Change the permission for pwrnap, policy, modem_wait sys entries

Sysfs files are not world writable. Allowing only
root to write to sysfs files to keep non-privileged
process from change the power policy.

CRs-Fixed: 327239
Signed-off-by: Praveena Pachipulusu <pveena@codeaurora.org>
(cherry picked from commit 263467dc0b1184e562ff86e4069df76283a80d2d)

Change-Id: Ia1e213f15c2feb9aeced61b6861f9687eb1f041e
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
msm: kgsl: allocate the snapshot buffer from kmalloc

Having the snapshot buffer physically contiguous will make
it easier to recover from a ram dump in case the system
crashes after a hang. Also log the buffer address when
the snapshot is created so we know where to look for it.

Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
(cherry picked from commit 9d15ae432b2f47182dcb3f191089cf892630e406)

Change-Id: I74dbc3f40461e079506a4d4f7e56740c75454713
Signed-off-by: Gopal G Goberu <ggober@codeaurora.org>
msm: kgsl: fix size checking in adreno_find_region

This function is supposed to return the memdesc that
contains the range gpuaddr to gpuaddr + size. One of the
lookups was using sizeof(unsigned int) instead of size,
which could cause false positive results from this function
and possibly kernel panics in the snapshot or postmortem
code, which rely on it to do bounds checking for them.

Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
(cherry picked from commit 1ab51045b57edc5af3079599cfc9b843b03843f9)

Change-Id: I818c603f5b301865a87ec6bd84e6a6922c7c3234
Signed-off-by: Gopal G Goberu <ggober@codeaurora.org>
msm: kgsl: handle all indirect buffer types in postmortem

Postmortem dump was not parsing CP_INDIRECT_BUFFER_PFE commands.
Snapshot was recently fixed to handle this, and this change
extends support to postmortem dump.

Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
(cherry picked from commit 6ca1d15190f730e9c0eca510101b24c39297b736)

Change-Id: If30279161881afabb944531963daf3b5adfb1788
Signed-off-by: Gopal G Goberu <ggober@codeaurora.org>
msm: kgsl: Add a new property to IOCTL_KGSL_DEVICE_GETPROPERTY

Return the reset status of the GPU unit when
IOCTL_KGSL_DEVICE_GETPROPERTY is called with
type KGSL_PROP_GPU_RESET_STAT

(cherry picked from commit 2dfe5dd0c53c8f9abc83bc6a9671d499c8135f68)

Change-Id: I6109b2d161e1c5a82363b582e2c1f106e2753742
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
msm: kgsl: Make sure kmemleak tool does not report incorrect mem leak.

Certain memory allocations are not properly tracked by kmemleak tool,
which makes it to incorrectly detect memory leak. Notify the tool by using
kmemleak_not_leak() to ignore the memory allocation so that incorrect leaks
report are avoided.

CRs-Fixed: 334294
Signed-off-by: Anshuman Dani <adani@codeaurora.org>
(cherry picked from commit eecd52061a50325db02d2396bfd455b306a04f34)

Change-Id: If2c955f95c650a73a04aca01977dc7ac13319878
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
msm: kgsl: Do not BUG in GPU recovery if a valid context can't be found

Don't BUG() if we can't find a valid context to recover to; just fail and
go into a zombie state. This usually happens after a first hang goes bad
and the system keeps hanging while trying to find its way. The problem with
a BUG() in this case is that the system goes down and we can't recover the
snapshot or other debug information.

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

Change-Id: I68581017f6e78a866a6d91033f980ecd06d96360
Signed-off-by: Gopal G Goberu <ggober@codeaurora.org>
msm: kgsl: set the dma_address field of scatterlists

Ion carveout and content protect heap buffers do not
have a struct page associated with them. Thus
sg_phys() will not work reliably on these buffers.
Set the dma_address field on physically contiguous
buffers.  When mapping a scatterlist to the gpummu
use sg_dma_address() first and if it returns 0
then use sg_phys().

Change-Id: Ie5f19986446be4383dfbfffa2534136b592e8e46
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
(cherry picked from commit 582fe31d2719b45fd0accf85bf2351f1a15b97b7)
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>
(cherry picked from commit d5fa912f599a71223496d2ff97ecd5040b95baaf)

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
msm: kgsl: increase valid timestamp range

The existing timestamp_cmp function returns a different
result depending on the order of the input parameters due to
having an asymetric valid window. When no rollover is
detected the window is 2^31 but when a rollover is detected
the window is 25000. This change makes the rollover window
symmetric at 2^31.

CRs-fixed: 347631
Signed-off-by: Jeff Boody <jboody@codeaurora.org>
(cherry picked from commit beb4a64b08ac49d4e01f4dd0c911c14ed6939f6d)

Conflicts:

	drivers/gpu/msm/kgsl.h

Change-Id: I22dcc773438df32f105dc8bd069051c48fde5018
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit 267762656c2fe837749eec87cd1593e21b9077b6)

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
msm:kgsl: set state as requested state when in NAP

Fix the state to requested state so that when both ISR and
timer fire at the same time, the state is set as SLEEP

CRs-Fixed: 340484
Signed-off-by: Suman Tatiraju <sumant@codeaurora.org>
(cherry picked from commit 9b6110bb38c7acf61e065ec206b62b1e1f089908)

Change-Id: Ie625aba09feddf495647be2844dc0a4014605141
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit 7704bbd086590ef68aa30530c0ea18dc7f379780)

Conflicts:

	drivers/gpu/msm/kgsl_pwrctrl.c

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
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>
(cherry picked from commit a240fca76b5562d3ca53677151213286306bbc96)

Signed-off-by: Zhoulu Luo <zluo@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>
(cherry picked from commit efa1fd88817051006d042b5ff9af871f02abc75a)

Signed-off-by: Zhoulu Luo <zluo@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>
(cherry picked from commit eef51c92910064add2877091ddbd93cdf79c0c26)

Conflicts:

	drivers/gpu/msm/kgsl_pwrctrl.c

Signed-off-by: Zhoulu Luo <zluo@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)
(cherry picked from commit 15456a25c55409ee3032c4e083d232a3d3aedf6e)

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
Revert "msm:kgsl: set state as requested state when in NAP"

This reverts commit 345ea590c7208f1d98372e5cecec5b608af4eaa9.

Change-Id: Icb8f083670b2823502f65304dae0fbbf8457d5d0
Signed-off-by: Zhoulu Luo <zluo@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: I5183e9e409f494757e44a919b87d3b078ac9ea7d
Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>