msm: vidc: Provide qmenu for V4L2_CID_MPEG_VIDC_VIDEO_INTRA_REFRESH_MODE

The v4l2 control framework requires a qmenu containing a string
description of each menu item.

Change-Id: Id41fd794a6f7ad8711caf9d072975ad6cabad6f9
Signed-off-by: Deva Ramasubramanian <dramasub@codeaurora.org>
msm: vidc: initialize venus hfi locks during hfi creation

Venus hfi locks were initialized during core init,
which is invoked when the first video instance is
created. If a debugfs command is executed before
starting the first video instance, then video driver
crashes trying to lock an uninitialized mutex.

Change-Id: I472e9de91dada94a2728dd02c747e7fde63e3e4f
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
msm: vidc: Add entry to scale buses for True 4k @ 24 fps

We weren't asking for enough bandwidth for 4k (3840x2160) @ 30 fps
sessions because we were missing an entry for True 4k @ 24 fps (which
requires less bandwith).  Now sessions of the former type are mapped to
the right ab-ib values.

Also get rid of some unused macros in msm_vidc_common.c

Change-Id: I40d3f8d079ffba586d96e8042b40bb0648ba7ae2
Signed-off-by: Deva Ramasubramanian <dramasub@codeaurora.org>
ARM: dts: msm: Add new property to specify OCMEM size

OCMEM is required by video hardware to deliver optimal
performance mostly at higher resolutions/fps. For targets
which have low specifications, OCMEM is not needed or not
needed as much as for higher targets. This change adds the
property to dtsi file to specify the size of OCMEM.

Change-Id: I65ae271bc73d302975957727a95461c7388727f6
Signed-off-by: Ashray Kulkarni <ashrayk@codeaurora.org>
Signed-off-by: Vinay Kalia <vkalia@codeaurora.org>
Signed-off-by: Praneeth Paladugu <ppaladug@codeaurora.org>

Conflicts:
	arch/arm/boot/dts/msm8974.dtsi
msm: vidc: Free smem client after moving core to UNINIT

If userspace crashes prematurely, there will be a good chance that the
driver hasn't unmapped or freed certain buffers.  These buffers will be
freed in the state transition to UNINIT.  At that point the smem client
needs to be valid for the free/unmaps to be valid.

CRs-Fixed: 611946
Change-Id: I089dcbd1e79f1c2a8671e5719d3a5dbc9926b252
Signed-off-by: Deva Ramasubramanian <dramasub@codeaurora.org>
msm: vidc: Re-program the vbif settings post-power collapse

As part of power collapse we turn off the venus GDSC. When we turn it
back on, we need to re-program the VBIF registers to overwrite the
reset values.

CRs-Fixed: 585609
Change-Id: Ic2ac40274773f9592f510ccb573b9d4920a8647f
Signed-off-by: Deva Ramasubramanian <dramasub@codeaurora.org>
msm: vidc: Update vb2q buffer sizes

Currenttly is updating vb2q buffer size on CAPTURE port.
only.This change will update the buffer size on OUTPORT port
along with CAPTURE port.

Change-Id: Ieb0a898ae5b012f3bf1a1073d2ddf5ce72647252
CRs-Fixed: 621134
Signed-off-by: Prasad Nallani <pnalla@codeaurora.org>
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>

Conflicts:
	drivers/media/platform/msm/vidc/venus_hfi.c
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>