msm: vidc: send release buffers cmd during instance clean up

During instance cleanup, if internal or output buffer
list is not empty, respective buffers are unmapped.
Modify the cleanup instance to send release buffers to
video core if internal or output buffer list is not
empty and then unmap the respective buffers.

CRs-Fixed: 619239
Change-Id: I56bd4248173992dedfb36098dfa9ddf35fc12a4e
Signed-off-by: Rajeshwar Kurapaty <rkurapat@codeaurora.org>
msm: vidc: change error msg for max sessions condition

When the max sessions condition is reached, the firmware
sends session init to the driver. Change the error message
from 'core is in a bad state' to reflect the actual
behavior.

CRs-fixed: 625684
Change-Id: Iddf7d3fc72c1c2696200789954c1e69fd0419dca
Signed-off-by: Pushkaraj Patil <ppatil@codeaurora.org>
msm: vidc: remove non fatal error messages

V4L2 core fails reqbufs ioctl if file IO is in
progress. This message is non fatal, so avoid
logging it as a error message in the video driver.

Change-Id: Ie5ea22925f9c698c82cfaeb6e77b66cf77e5e866
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
msm: vidc: return EBUSY when hw is overloaded

Component reports hw error to client immediately in
the same thread after stream on failure and blocks
subsequence errors to client. Therefore, the async
v4l2 event "V4L2_EVENT_MSM_VIDC_HW_OVERLOAD" will
be ignored in component.
When loading resource fails because of hw
overload, instead of sending V4l2 event, we are
going to return EBUSY and this return value will
be checked in userspace.

Change-Id: I26b3315afbe4c7cc4be9e740595d1db5153467dc
Signed-off-by: Jia Meng <jmeng@codeaurora.org>
msm: vidc: add kzalloc success check for new HAL session

Memory allocation must be verified before proceeding.

CRs-Fixed: 606527
Change-Id: Ic340bf9926f84507294c576997948ddbe61dd62f
Signed-off-by: Jorge Solano Altamirano <jsolano@codeaurora.org>
msm: vidc: add input parameter checks to exported functions

Check for invalid null parameter passed to functions

CRs-Fixed: 606467
Change-Id: I860ca3d69d8705c7b3d6f27f9504b567be5aeea3
Signed-off-by: Jorge Solano Altamirano <jsolano@codeaurora.org>
msm: vidc: add kzalloc success check for new q6 HAL session

Memory allocation must be verified before proceeding.

CRs-Fixed: 606522
Change-Id: I809acc21dcd5e680827feb5d0fa8f45814bf4773
Signed-off-by: Jorge Solano Altamirano <jsolano@codeaurora.org>
msm: vidc: add input check for hfi q6 function.

The input parameters may be null. This change adds input checks at
function q6_hfi_iface_eventq_read

CRs-Fixed: 606516
Change-Id: I801a9d3249e9b97fa218fc29bc3a2a0e7a0d4d3f
Signed-off-by: Prasad Nallani <pnalla@codeaurora.org>
msm: vidc: Add null pointer checks

msm_vidc_inst pointer instance is used in without any null
pointer check, dereferencing t could device crash.
Fix the issue by adding null pointer checks.

Change-Id: Ia17b380063326aa587aac941aac0131871147e8a
CRs-Fixed: 606486,606469
Signed-off-by: Jayasena Sangaraboina <jsanga@codeaurora.org>
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.

CRs-Fixed: 571083
Change-Id: I88f7e771b21046d9817feb17b06b3739f128c434
Signed-off-by: Vikash Garodia <vgarodia@codeaurora.org>
msm: vidc: unprepare clocks during power collapse

If any clock is still prepared (only disabled), apps will
not vote for XO shutdown. Unprepared clocks will remove the
vote and facilitate XO shutdown.
During power collapse, video drivers now disable and
unprepare venus clocks.
There was minimal power savings during internal tests,
but customer reported to have impact of 13mA without
the change.
The change add different clock states. Clock state
transitions with clock api is shown below
====================  clk_prepare_enable()    ==================
|DISABLED_UNPREPARED| ----------------------  |ENABLED_PREPARED|
====================  clk_disable_unprepare() ==================
   ||                                                   ||
   || clk_unprepare() ================    clk_disable() ||
    -----------------|DISABLED_PREPARED| ---------------
      clk_prepare()   ================    clk_enable()

Change-Id: Id23302e359abcdf91c993835c6353fb251c96fe6
CRs-Fixed: 604629
Signed-off-by: Vikash Garodia <vgarodia@codeaurora.org>
msm: vidc: ensure venus clocks are enabled while release buffer

While interframe clock gating, venus clock are gated ON and
OFF based on firmware response. It may happen that venus
clocks are disabled while iommu driver unmaps output buffers.
This may lead to unclocked memory access.
Venus clocks should be enabled while releasing output buffers.

Change-Id: Ib7a04c2d3600ae91a229730e2caffbff9c8353ca
CRs-Fixed: 645657
Signed-off-by: Vikash Garodia <vgarodia@codeaurora.org>
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.

Change-Id: Ifadb2ecf6e7021ed60ee3b0992e4d1950f8ca53d
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
msm: vidc: update format during downscaling

When downscaling is enabled, update the port format
parameters based on port type.
Avoid updating the instance property during reconfig event
with sufficient resource. IL Client expects downscaled
parameters rather than reconfig parameters.

CRs-Fixed: 629474
Change-Id: I629a0b78a56806018976f7f82e8c526fef456ec9
Signed-off-by: Pushkaraj Patil <ppatil@codeaurora.org>
msm: vidc: queue output-1 buffers to FW

While seeking, FW returns all the buffers to host.
In multi-stream usecase like downscaling, the o/p
buffers need to be re-queued back to FW.

Change-Id: I5ea8534c06b3e48dadd4d73ab4432a13687a99c1
CRs-Fixed: 631827
Signed-off-by: Vikash Garodia <vgarodia@codeaurora.org>
msm: vidc: Check maximum width capability of Q6

Maximum width capability check is required to take
care of indefinite behavior when a clip having width
more than Q6 capability is played. Also, make the
capability check generic for Q6 and Venus.

CRs-fixed: 626642
Change-Id: Ic10be0ad4434019fea45e7a090b21ba5cf54d9a6
Signed-off-by: Ravi Kiran Vonteddu <rvontedd@codeaurora.org>
msm: vidc: Remove artificial cap of VP8 at 1080p

VP8 encoding or decoding wasn't officially supported at > 1080p
resolutions until now.

Change-Id: Ibc2934c7562643217999a592967f3278c72de563
Signed-off-by: Deva Ramasubramanian <dramasub@codeaurora.org>
CRs-Fixed: 566047
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: Praneeth Paladugu <ppaladug@codeaurora.org>
msm: vidc: Query deblocker parameters from cluster

Various fields of h264_db_control were left uninitialised before being
sent to the firmware.  As a result, due to poor luck, the resulting
encoded bitstreams were invalid as the alpha and beta were not in the
acceptable range of [-6, 6].  This commit fills the uninitialised values
with values obtained by querying the cluster.

Change-Id: Ic217d007239bc059302bdcdf2aebad1c9ca88244
Signed-off-by: Deva Ramasubramanian <dramasub@codeaurora.org>
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
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>