msm: kgsl: Print the IB causing a pagefault

If a GPU page fault occurs then store the IB information of the
of the fault and print the IB information by queueing a work item.

Change-Id: I4463305727605a65134644d22ef7f51e72740350
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
(cherry picked from commit 3e40f411dc3b67fba17e4ddcd9aff2c90bd6fbbc)
msm: kgsl: Idle the GPU after recovery in recovery routine

Before returning from recovery routine, wait for the GPU to
become completely idle to ensure that recovery passed

Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
(cherry picked from commit 1088bdb727a0360e0acf38b4420a259877deb125)

Change-Id: Ida471d10188f55f7a5f70bb2427fdac27c8d767d
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
(cherry picked from commit 776c108db6c62578a0ee618f96088649baf76bd8)

Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
msm: kgsl: Start the sleep timer after recovery has completed

Start the sleep timer if recovery from hang is successful.
This prevents GPU from entering low power states during
recovery.

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

Change-Id: I7034ad26b12175fc704656eced5ea6cf7b57413c
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
(cherry picked from commit f7593196a0fb7a1563bed6b96297c3c3d1b77e68)

Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
msm: kgsl: Always add a start identifier to a command sequence

Add command sequence start identifier for commands submitted from
kgsl as well since this will be used during recovery. We will just
try recovery and not try to differentiate between commands from
kgsl or from user space.

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

Change-Id: Ibe363682e4ea405a81fae77d5b5bfeccbad97edc
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
(cherry picked from commit b13c30dd3ad88b5a5dd128f4824876f82e695b5b)

Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
Revert "msm: kgsl: Always add a start identifier to a command sequence"

This reverts commit 2606552b754c464a118adecdf257fecb99275dca.
msm: kgsl: Introduce recovery data structure for hang
 recovery

Create a new data structure that holds all the information required
for recovering from hangs. This data structure is initialized as soon
as hang is detected because if the GPU is under DOS attack then by
the time we start recovery the recovery data may have changed.

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

Change-Id: Idcd7de7a02b4d57735c2186db9307a22bfd1a6b6
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
(cherry picked from commit a5667011435a34bedb0916abc80e3337da68f28f)

Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
msm: kgsl: Use recovery data structure to extract valid commands

Use the data set in the recovery structure when extracting
valid commands from the ringbuffer instead of reading
it from the device/memory.

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

Change-Id: I5b4f263c34c09bc724e875866806971931060d52
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
(cherry picked from commit ae6b074d30e3d1d3cad362f80ed5eb4c84f7e001)

Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
msm: kgsl: Create a separate function to extract valid commands

Create a separate function that extracts valid commands from good
contexts and invalid commands from bad contexts during recovery

Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
(cherry picked from commit 1d577fe6fc5cdf768c5f3fe59b56adcd0e86db19)

Change-Id: I03e787657d37a13cf2c915677ba05b87b5a5731c
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
(cherry picked from commit 9790eadcb74289fe3114c8cf2ba6d4d8a4920bfd)

Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
msm: kgsl: Separate function to detect last command in
 recovery

Make the code more readable by writing a separate function to
detect the end of last command that is assumed to be successfully
executed by the GPU

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

Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
(cherry picked from commit 59c917c7d6e36e5daf9820dc12a3f7c5bd508e2a)

Conflicts:

	drivers/gpu/msm/adreno_ringbuffer.h

Change-Id: Ia9065c8cf83c3404d82a2cf0865e1f0398be69da
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
msm: kgsl: Print the IB causing a pagefault

If a GPU page fault occurs then store the IB information of the
of the fault and print the IB information by queueing a work item.

Change-Id: I4463305727605a65134644d22ef7f51e72740350
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
(cherry picked from commit 3e40f411dc3b67fba17e4ddcd9aff2c90bd6fbbc)
msm: kgsl: Turn on preamble to enable replay of commands

Turn on the preamble of the IB sequence in which hang is assumed
to have happened so that the bad sequence can be replayed.

Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
(cherry picked from commit 2a85f1fb19278fa530cb31dca0198583b77fc8be)

Change-Id: Ie3f70f2c8f273f73f5ed525f911bb2914b6bebce
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
(cherry picked from commit 53b95e6361dc7925374d375ea83cb6f51af59282)

Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
msm: kgsl: Do not restore per context timestamp states

We do not have to restore the per context timestamp states during
recovery as this data is irrelevant after recovery.

Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
(cherry picked from commit 1caba1c8066b77d3955300c95a9be2489418b094)

Change-Id: I2ebf10cb9fca40fdff9f02978bdcda18dd771871
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
(cherry picked from commit 5ef7b562609b5b1ac3159f9dfca6d9922ac66186)

Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
msm: kgsl: Write a separate function to set the reset status

Write a separate function that sets the reset status of each
context after recovery.

Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
(cherry picked from commit 29ed38ee8491fd873b304f3d2edad2a4a0395017)

Change-Id: Ic4a70823cb35637794a281142181d93b689d3b6e
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
(cherry picked from commit 51d5c7fb21d7d603a085c331bf2d29b5b6754ec3)

Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
msm: kgsl: Mark the hung context in recovery before extraction

Mark the context that has caused a hang in recovery before
calling the extraction function. This updates the context
state correctly early in recovery.

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

Change-Id: I8a3078ca76d7f447d5ca104ba98b34d46a4409aa
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
(cherry picked from commit 790998de09e2fc4a091da9444bad52d222776390)

Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
msm: kgsl: Expire timestamps after recovery

Expire the global timestamp and timestamps of contexts that have
cause at the end of recovery. This will prevent any users waiting
on timestamps of hung contexts to return without waiting.

Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
(cherry picked from commit 5f085f45b19b1fd209eef1cb02b2bb68ad40f505)

Change-Id: I916bf41bad7b2e33c5fe0a885c3ea4e132974541
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
(cherry picked from commit c1f92ca72dc3819c93a6bbee21d0af8354919465)

Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
msm: kgsl: In recovery search for command stream after global eop

In recovery search for the timestamp of the command stream after
global eop instead of searching for the command stream of the
global eop and then moving the pointer forward till the start of
the command stream following global eop. This is because if the
ringbuffer is full then the global eop timestamp may have been
overwritten, so its more reliable to search for the timestamp
that occurs after global eop.

Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
(cherry picked from commit 6f6ecb3ef3eb66ef8e07ae8473682f8b36091376)

Change-Id: I21e28acade3d6f431a00b8825845dbf4b8cb7008
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
(cherry picked from commit f96febefc320b9c6007f2c167428a7c85e8d56b0)

Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
msm: kgsl: After timeout check if timestamp has retired

When a thread times out while waiting for a timestamp, check once
whether the timestamp which it was waiting for has expired or not
before treating it as an error

Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
(cherry picked from commit 54396e5406b5fecdd1a0e347dab953967d0e9318)

Change-Id: Iaf8fef4881ca0510ac44b437d82b1382ce602097
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
(cherry picked from commit cb579bd248409c6892f4eecd0bf93383b66b375d)

Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
msm: kgsl: Increase the virtual GPU range for the IOMMU

Instead of a fixed 256MB virtual range for both the GPUMMU and IOMMU, make
the virtual range a property of the MMU engine and set the IOMMU range to
2GB.  Technically we could go all the way up to 4G, but even 2G is far out
of the realm of possiblity in the current generation, and we wanted to
reserve some of the space for future enhancements.

Change-Id: Ic0dedbad2987beb162b6a1878dd65ffae8a78522
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
(cherry picked from commit 6d76c4d0dff8edb0849ec85537d7013640d7d28a)
msm: kgsl: Detect and avoid malformed ioctl codes

Because we were using _IO_NR, one could construct a malformed ioctl
code that would avoid allocating memory yet go to a function that
expected that memory. Still use _IO_NR to index the array of ioctls,
but check that the full values match before jumping to the helper
function.

CRs-fixed: 385592
Change-Id: Ic0dedbaded469035bd0a2bb0f20fecb2a3045ca5
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
(cherry picked from commit 1e76f61bb001b93795a227f8f808104b6c10b048)
Add suport for 2nd lun num

Change-Id: I9fff01e72ec98c8d53fe03a813f42bf6f9f805bf
Signed-off-by: RonGokhale <cips173@gmail.com>