Revert "msm commits from cm"
Support for display gamma control

Originally written by Paul Reioux (faux123)

Modified from his original implementation as follows:
* Remove kgamma_ctrl sysfs entry - it did absolutely nothing
* Alter the show() functions to output the checksum in the
first entry, in order to match the expected input of
the store() functions.  This should not break existing
applications
* Move store/show code to a common function
* Add limit checks from Mike Cain (motley)
* Added a kgamma_apply sysfs entry which will apply
  the current state when anything is stored to it,
  instead of waiting until the next time the LCD
  is power cycled

Change-Id: I8835e42709cefa547e02e28a7e5a381d88282700
msm: kgsl: Don't do intensive memory recovery when allocating big pages

We don't want to incur too much overhead when allocating big pages
so don't attempt to retry, perform reclaim, or run memory compaction
on high-order allocations.

Change-Id: Ic0dedbadb354c6faea34abec36aee268ac0f2c34
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
Signed-off-by: Ling Wan <lingw@codeaurora.org>
adreno: increase cmdbatch timeout to 10 seconds

Signed-off-by: Iliyan Malchev <malchev@google.com>
msm: kgsl: Use the correct length when looking for address collision

Use the right length of allocation from the aligned base address of
CPU virtual map to look for collision in the GPU vitual map. This
prevents discarding of usable address ranges due to false collision
hits.

CRs-Fixed: 492041
Change-Id: I370e6a31f98803e8ca6858a5562f47afeeaa157e
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: Prevent race conditions when freeing memory

Multiple threads can call an ioctl to free a memory region.
Only one of these threads must be allowed to free memory and
the rest can return without freeing. Add a new pending flag
which is tested and set in a critical section guarded by
spinlock to prevent multiple ioctl threads from freeing the
same memory.
Also, a thread could be freeing a memory region that is
in use by another thread. Ensure that the detachment of the
memory from the process list and freeing of the memory always
happens in the same thread. This will prevent a situation where
the memory is being used by a thread which is detached from the
process list and is yet to be freed.
Seperate the selection of gpuaddr and mapping into pagetable. The
gpuaddr assignment needs to be done with process memory lock held
in a critical section but the mapping into pagetable can be done
separately without holding memory lock.

CRs-Fixed: 495144
Change-Id: Idf85fbd4bca29c18597f4b0e737c207f002ab266
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: Only reference the rb_node after taking spinlock

Derefernce the rb node after taking spinlock since the root
node can change and is supposed to be guarded by the spinlock

CRs-Fixed: 495129
Change-Id: I63de7755cf9d5fb548c082f43403000bcef5721b
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: Only initialize process structure once

If the debug root of the process structure is initialized
then it means that the remaining fields will also be
initialized. Check this field at the beginning of the
initialization routine and skip to end of the function. This
also by-passes the reinitialization of some fields because
of errorneous NULL pointer check of rb node. The rb node is
always initialized to NULL so checking if it is NULL to
determine whether the pointer is initialized or not is wrong.

CRs-Fixed: 498014
Change-Id: I73b2124c037187bc96942714dac62c0a72c26372
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: Do not hold memory spinlock when calling find region function

The function kgsl_sharedmem_find_region holds the memory spinlock
at the beginning of the function so we do not need to hold the lock
before calling the function

Change-Id: I20ee32e0ed6aee6ed61cdd4fb7a9cc08a876fc84
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: Add a missing mutex unlock

Adding a missing mutex unlock where we return from
kgsl_late_resume_driver if we fail to wake up the device.

CRs-fixed: 500422
Change-Id: I26b56d95a9427798719fb162d1b1edaf641ae57b
Signed-off-by: Harsh Vardhan Dwivedi <hdwivedi@codeaurora.org>
msm: kgsl: generate descriptive names for kgsl-timeline

Generate names for kgsl-timelines using the following format:
<device>-<thread name>(<tid>)-<proc name>(<pid>)-<context id>

This makes it possible to identify the context of a timeline in the
sync dump, which makes it much easier to identify which context has
a GPU timeout.

Change-Id: I0ce0614a53a93fd81094d92c9bef7053e6d416d2
Git-commit: e3348f389f715cb2143a708ec6796d3f65e03821
Git-repo: https://www.codeaurora.org/gitweb/quic/la/?p=kernel/msm.git
Signed-off-by: Fred Fettinger <fred.fettinger@motorola.com>
Signed-off-by: Harsh Vardhan Dwivedi <hdwivedi@codeaurora.org>
Signed-off-by: Sridhar Gujje <sgujje@codeaurora.org>
gpu: ion: Minimize allocation fallback delay

When we allocate from iommu heap we first try to allocate 1M pages. If
that fails we try 64K pages, which falls back to 4K pages. However,
we don't want to incur too much overhead when allocating with fallbacks
so we don't want the higher order page allocation to retry, perform
reclaim, or run memory compaction.

Configure the GFP flags to ensure that when we allocate pages greater
than order 0 we don't try to do any retries, reclaim, access emergency
pools, or run memory compaction. This will ensure lower memory allocation
latency for applications.

CRs-Fixed: 470389
Change-Id: Ibb3483dddbedbc733a1f7968821e7bc47bedffcd
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
gpu: ion: Add null-pointer check after allocation

Check for failed allocation and return appropritate
return code if memory allocation fails.

Change-Id: Iefb83b5e30c3cc581ccecaf6e59eae621be98083
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
Signed-off-by: Ajay Dudani <adudani@codeaurora.org>
msm: kgsl: Map sync lock variables to every pagetable

Map sync lock variables to every pagetable since we don't
use TTBR1 anymore.

Change-Id: If2d43c4c57d0cdcf6076229dfad32c0375e74df4
Signed-off-by: Rajesh Kemisetti <rajeshk@codeaurora.org>
kgsl: Add memory barrier to kgsl_iommu_lock_rb_in_tlb iommu operation

Signed-off-by: Ajay Dudani <adudani@codeaurora.org>
msm: kgsl: show timestamp in sync dump

Improve the debug information printed for kgsl points and timelines.

kgsl_sync_pt_value_str:
  - show timestamp passed to kgsl_add_fence_event()
kgsl_sync_timeline_value_str:
  - show most recent timestamp passed to kgsl_sync_timeline_signal()
  - show last retired timestamp according to kgsl_sync_get_timestamp()

Change-Id: I93fe408b06de054b11e05784cd7175ed3fcb76ad
Git-commit: 595e213985f63d6aa484c966a4f4a710b31ca209
Git-repo: https://www.codeaurora.org/gitweb/quic/la/?p=kernel/msm.git
Signed-off-by: Fred Fettinger <fred.fettinger@motorola.com>
Signed-off-by: Harsh Vardhan Dwivedi <hdwivedi@codeaurora.org>
Signed-off-by: Sridhar Gujje <sgujje@codeaurora.org>
msm: kgsl: Add a check to free the kgsl_timeline object.

Add a check to free the kgsl_timeline object only after
destroy flag is set. This is to avoid further references to timeline
from kgsl if it is already freed and also to catch any unbalanced
kref count.

Change-Id: I8017b9a928a26b703eb92b17ab6a361e4b479e5a
Signed-off-by: Rajesh Kemisetti <rajeshk@codeaurora.org>
watchdog: Fix warning caused by use of smp_processor_id()

watchdog driver creates per-cpu kernel threads that are bound to
separate cpus. Use of smp_processor_id() by such threads in
__touch_watchdog() is perfectly fine, as they are generally pinned to
the cpu on which they are running.

During cpu offline event, however, affinity for the watchdog thread
bound to dying cpu is broken before it is killed. There is a small
time window between affinity broken and thread dying in which thread
can run on a cpu with its affinity not set to that cpu exclusively.
This will trigger a warning from use of smp_processor_id(), which is
harmless in this case as it will provide the required heartbeat on cpu
where it is running and moreover that thread will be shortly killed.

Mute the harmless warning by use of raw_smp_processor_id() in
__touch_watchdog(). This seems less intrusive fix than killing threads
in CPU_DOWN_PREPARE event handler.

Change-Id: I7fa22ff529aeea0ec3d5610cfec87aea92cf95a0
CRs-Fixed: 517188
Signed-off-by: Srivatsa Vaddagiri <vatsa@codeaurora.org>
msm: vidc: Correct log tagging for kernel messages

This change amends the log tagging in kernel.

CRs-fixed: 478607
Change-Id: I2c7056d8fc9ec82ffbc6824790c064033481a9af
Signed-off-by: Shobhit Pandey <cshopan@codeaurora.org>
msm: camera: Fix camera crash in msm_open_config

Add proper check before accessing mctl handle to
avoid camera crash.

Change-Id: I1413f086ab7d94fe223a814bb16867d1dcc0a4bf
CRs-Fixed: 481757
Signed-off-by: Suresh Vankadara <svankada@codeaurora.org>