msm: vidc: Free OCMEM during power collapse

To disable OCMEM clock during power collapse, video driver
has to free up the allocated OCMEM. This memory will be
re-allocated before bringing venus core out of reset.

Signed-off-by: Vikash Garodia <vgarodia@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
msm: vidc: recover from firmware fatal error

If firmware goes in to bad state, the video driver
should try to restart the firmware, so that subsequent
new video sessions can play fine without error.
Previous to this change, the video driver would
unload the firmware only after all open instances
have been closed by the client. If the client fails
to close any of the open instances, then firmware
would not be unloaded and continue to remain in bad
state. This would fail all new video sessions and could
be overcome only after the device was reset.

Signed-off-by: Arun Menon <avmenon@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
msm: vidc: Fix various decoder downscalar issues

Queue output buffers without extradata to Venus.
Venus is returning UPSCALE_NOT_SUPPORTED error when
output2 size is bigger than output size. This change
suppresses this error as it is not fatal.

Change-Id: I8a3f708092b131400b88828f6c1a684f08b3f18a
Signed-off-by: Manikanta Sivapala <msivap@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
msm: vidc: Fix race condition during concurrent sessions

The core->instances list structure is guarded by
mutex core->lock, whenever a new video instance is added
or deleted from the list. However this list was accessed
from certain functions without acquiring the lock, which
resulted in race condition, causing the device to crash.
Also clean up the core locking mechanism.

Change-Id: I6f431bc381d54948611783e19fac853c83a87203
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
msm: vidc: Delay firmware unload during session close

Video driver loads and unloads firmware at the start
and end of each session. Firmware download takes up
to 100 msec. When there are many b2b video sessions
e.g. thumbnail generation, this is an unnecessary
overhead. To overcome this problem, video driver will
unload the firmware 10 secs after the session is closed.
If a new session starts during this period, it will not
be required to download the firmware again.

Change-Id: Ia515c3ed89c75ea9e43852958d1cbb2d77fe4c51
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
Signed-off-by: Maheshwar Ajja <majja@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
msm: vidc: Unload firmware immediately after sys error

Currently the video driver delays unloading of firmware
by 10 sec. This was primarily done to avoid re-loading
the firmware if we had another video instance starting
immediately. However, if firmware goes in to bad state
and firmware unload is delayed, then any subsequent session
started within 10 sec will fail, as firmware is still in
bad state. We can avoid this by unloading firmware without
delay when video firmware goes in to bad state.

Change-Id: I747d6ce2fa61916cd8a24c180068879b371101a8
Signed-off-by: Maheshwar Ajja <majja@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
msm: vidc: Increase firmware unload delay

Using the same delay for power collapse and
firmware unload can trigger race conditions in
the power collapse and firmware unload sequences.
Increase the firmware unload delay from 10 seconds
to 15 seconds to avoid this.

Change-Id: I0fbde99e8c7fca93f7b227d351a73c580e244614
Signed-off-by: Maheshwar Ajja <majja@codeaurora.org>
Signed-off-by: Sivasri Kumar Vanka <sivasri@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
msm: vidc: Disable clock gating feature

Clock gating between inter frames when video hardware
is in IDLE state is not giving any power savings and
at the same time this feature is resulting in few
stability issues. So disabling clock gating feature.

Change-Id: I3d1d4521ec3ee2fbd25d80b33bd5c531a25d9034
Signed-off-by: Maheshwar Ajja <majja@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
msm: ocmem: Check for NULL pointer from get_zone

The get_zone function might return NULL if it is
unable to find the zone for the associated client
id. Add check to prevent NULL pointer dereferencing.

Signed-off-by: Neeti Desai <neetid@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
msm: ocmem: Add NULL pointer check for req structure

BUG_ON if req structure returned from handle_to_req
returns a NULL pointer.

Signed-off-by: Neeti Desai <neetid@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
Signed-off-by: Dan Trifan <jimsth@gmail.com>