Backport adsp_video_verify from .38 kernel

- The cached buffers need to be invalidated before accessing them
  and need to be flushed after modification

- Validate headers for RealMedia and VP8 formats
vidc: send flush done if flush is issued in EoS while encoding

There is a race condition in encoder, when an input buffer
is received with an EoS flag but doesn't have an output
buffer to process that and if simultaneously flush is issued.
This is fixed by sending flush done if flush is issued in EoS.

CRs-Fixed: 353081
Change-Id: I925f49779ed5cb91bfab805ba4b7102c1e3f728b
Signed-off-by: Rajeshwar Kurapaty <rkurapat@codeaurora.org>
(cherry picked from commit 602d62927c6db96f8d636f7795203b19e8c412c3)
qdsp5: audio: Set audio stopped flag before calling wakeup

During audio flush and stop command processing, wakeup on read
and write wait queue is done first and then audio stopped flag
is set to true. If a process waiting on read and write queue gets
scheduled first before stopped flag is set then this may result in
read or write command being sent to DSP after adsp disable operation,
which is unexpected.

Fix this by setting stopped flag before calling wakeup.

Change-Id: I20ef197e572d0ffc015d6004296ea7b9f5db2806
Signed-off-by: Manish Dewangan <manish@codeaurora.org>

Conflicts:

	arch/arm/mach-msm/qdsp5/audio_aac_in.c
	arch/arm/mach-msm/qdsp5/audio_evrc_in.c
	arch/arm/mach-msm/qdsp5/audio_pcm_in.c
	arch/arm/mach-msm/qdsp5/audio_qcelp_in.c
qdsp5: audio: Protect common data between ADSP ISR and flush operation

During NEEDS_DATA or BUFFER_UPDATE event processing in ISR
context, if flush command is issued by application then
there is chance of concurrent access of some of the variables
shared between ISR and Process context. This may result in race
condition causing values of these shared variables to be
inconsistent.

Fix this by protecting these variables using spin lock. Also corrected
locking sequence order in encode drivers.

Change-Id: I06b4d08053ad13d1b118ab6f29e69e95b49d133f
Signed-off-by: Manish Dewangan <manish@codeaurora.org>

Conflicts:

	arch/arm/mach-msm/qdsp5/audio_aac.c
	arch/arm/mach-msm/qdsp5/audio_aac_in.c
	arch/arm/mach-msm/qdsp5/audio_amrnb.c
	arch/arm/mach-msm/qdsp5/audio_amrwb.c
	arch/arm/mach-msm/qdsp5/audio_evrc.c
	arch/arm/mach-msm/qdsp5/audio_evrc_in.c
	arch/arm/mach-msm/qdsp5/audio_mp3.c
	arch/arm/mach-msm/qdsp5/audio_pcm.c
	arch/arm/mach-msm/qdsp5/audio_qcelp.c
	arch/arm/mach-msm/qdsp5/audio_qcelp_in.c
	arch/arm/mach-msm/qdsp5/audio_wma.c
	arch/arm/mach-msm/qdsp5/audio_wmapro.c
qdsp5: adsp: Add NULL check in adsp driver functions

ADSP driver functions are directly accessing module without checking
for NULL. This can result in crash if module supplied points to NULL.

Added NULL check to solve this.

Change-Id: I47eef0ea03086935ebfe33a2585ba214780e73f7
Signed-off-by: Manish Dewangan <manish@codeaurora.org>
msm: qdsp5: Avoid race condition of init info cmd being sent multiple times

GET_INIT_INFO command is sent to modem adsp service to get the information
such as task/queues supported by adsp. This command is sent whenever
msm_adsp_get() is called first time by any decoder/encoder drivers. This
command needs to be sent only once, to achieve this a global flag
init_info_cmd_sent is set in msm_get_adsp() after sending GET_INIT_INFO
command to adsp services. Currently flag init_info_cmd_sent is not
protected by any lock. Hence there is chance of GET_INIT_INFO command
being sent multiple times if there are concurrent calls to msm_adsp_get()
where each caller observes flag init_info_cmd_sent not to be set.

Fix this by protecting adsp info initialization sequence with mutex.

Change-Id: Ib0bd865d44e4687f9a85b56854e1fd3277a5707d
Signed-off-by: Manish Dewangan <manish@codeaurora.org>
msm: qdsp5: Initialize event length during adsp fake event generation

During adsp fake event generation, event length is not getting
initialized. This sometimes results in incorrect event data being read
during fake event processing by adsp driver clients.

Fix this by initializing event length properly before generating the
fake event.

Change-Id: Ifcab5adf542b04eef3dc03913b8e10c68f686e8c
Signed-off-by: Manish Dewangan <manish@codeaurora.org>
shmem: reduce pagefault lock contention

I'm running a shmem pagefault test case (see attached file) under a 64 CPU
system.  Profile shows shmem_inode_info->lock is heavily contented and
100% CPUs time are trying to get the lock.  In the pagefault (no swap)
case, shmem_getpage gets the lock twice, the last one is avoidable if we
prealloc a page so we could reduce one time of locking.  This is what
below patch does.

The result of the test case:
2.6.35-rc3: ~20s
2.6.35-rc3 + patch: ~12s
so this is 40% improvement.

One might argue if we could have better locking for shmem.  But even shmem
is lockless, the pagefault will soon have pagecache lock heavily contented
because shmem must add new page to pagecache.  So before we have better
locking for pagecache, improving shmem locking doesn't have too much
improvement.  I did a similar pagefault test against a ramfs file, the
test result is ~10.5s.

[akpm@linux-foundation.org: fix comment, clean up code layout, elimintate code duplication]
Signed-off-by: Shaohua Li <shaohua.li@intel.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: "Zhang, Yanmin" <yanmin.zhang@intel.com>
Cc: Tim Chen <tim.c.chen@linux.intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Revert "Leave runtime PM enabled during system shutdown"

This reverts commit e8a129b6eec91c78e16083bad4a5739351902397.
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>