msm: vidc: Add VP8 version set-up via Profile and Level

VP8 specification does not define level or profile concept but
specify a version. The OpenMax IL version 1.1.2 specify a single
profile and multiple levels for VP8 codec, the levels are indeed the
version numbers. The way of setting the codec version using level
field comes from the definitions at OpenMax IL. Since is a single
profile, level value is use to set-up the version but FW expects the
version value to be pass in the profile field, for that reason
incoming level is copy to FW profile.

Change-Id: I1ddc47b7a25efd1d31bed18e54c2b576427d1564
Signed-off-by: Jorge Solano Altamirano <jsolano@codeaurora.org>

Conflicts:
	include/linux/videodev2.h

Change-Id: Iab6ff5878bae312355326a9012eac0e59431aece
msm: vidc: Propagate FBD buffer offset

The offset is used to know the position of the valid data. In the past
this was not use for any codec but is essential for VPX/VP8 encoder.

Change-Id: Id0c5cef74f3ec80a0c41646a3e95d50889932f18
Signed-off-by: Jorge Solano Altamirano <jsolano@codeaurora.org>
Signed-off-by: Ajay Dudani <adudani@codeaurora.org>
msm: vidc: Remove redundant check

Removing a check that was previously done by
get_vb_from_device_addr() call. Also modify the
buffer data check print's to provide more concise
information.

Change-Id: Idf320a5ae89bf104e1ea66192fe0ea621f39185f
Signed-off-by: Jorge Solano Altamirano <jsolano@codeaurora.org>
msm: vidc: Initialize data_offset to avoid trash values

When data_offset is used by client this may get
trash values causing unexpected results.

Change-Id: Iaa7ca85f6dd81c4246580047f915cbb6327e7361
Signed-off-by: Jorge Solano Altamirano <jsolano@codeaurora.org>
msm: vidc: ensure safe deletions of session instances

Session instance should acquire lock before
cleaning up the session.

Change-Id: I0e496579794291a8115286c9550c5028c7391d55
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
msm: vidc: Fix the filled length for flushed buffers

For the buffers which are flushed internally in the driver,
the filled length should be zero. This change fixes
the same.

Change-Id: I21553c7812e2c15af14097f5562dbc8e68107506
CRs-Fixed: 513940
Signed-off-by: Praneeth Paladugu <ppaladug@codeaurora.org>
msm: vidc: add check for supported video session

Check if video session load can be handled by f/w
after session_init_done state and before moving to
load_resources state. This will ensure fallback of
unsupported video session to software codec library.

Change-Id: Ib8856a519a23c8bcab951c0e014dc5f454859efe
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
msm: vidc: Add support for dumping packets

Whenever we read and write from queues add support for logging the
packet being written or read.  As this produces heavy kmsg traffic, also
add a dynamic fallback option to use ftrace.  Output to ftrace can be
triggered by 'echo 1 > debugfs/msm_vidc/debug_output'

Change-Id: Ie221c60ab465605ede332ac7eaadfb4b26c19e01
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
Signed-off-by: Deva Ramasubramanian <dramasub@codeaurora.org>
msm: vidc: Increase maximum buffer count limit

Some clients want to allocate more buffers on decoder
input port than required (mainly for performance reasons).
Video decoder should honor the client request as long as
V4L2 framework permits.

CRs-fixed: 509088
Change-Id: Ic0da1b11ca49ebcd4498f8c8d93ba5b0e2dae8ba
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
Signed-off-by: Vinay Kalia <vkalia@codeaurora.org>
msm: vidc: Add support for ring buffer and frame assembly

Add capabilities to optimize input buffers memory usage by using a
single ring buffer and at the same time provide to firmware a
contiguous buffer to handle frame assembly internally avoiding memory
copies.

Change-Id: I37badbb86b6990c9bf47a86042290c0a1052b68c
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
Signed-off-by: Jorge Solano Altamirano <jsolano@codeaurora.org>
msm: vidc: Return min buffer count in VIDIOC_REQBUFS.

- If stream triggers multiple port reconfigure events, number of
  buffers required for output plane incremented due to actual
  buffer count returned from video driver.
- Minbuffer count should be return when buffer requirement called.

Change-Id: I943f2cfdd595b8278058b5bdcbbcf24c9f320440
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
Signed-off-by: Srinu Gorle <sgorle@codeaurora.org>
Revert "msm: vidc: Decrease the size of decoder compressed buffer"

For some codecs like VP8 the compression is not high. So the
compressed stream length could be more than 1/4th of the size
of the uncompressed stream. This change sets the size of the
compressed stream to to half of the uncompressed stream.

This reverts commit 2d72071c8759589048094adbbdc302591532ac74.

CRs-Fixed: 525713
Change-Id: I103d862c41e9dd8c4971870c5bb82a93bd0c073b
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
Signed-off-by: Praneeth Paladugu <ppaladug@codeaurora.org>
msm: vidc: Add support for V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB

V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB is the V4L2 standard version
of the vendor extension V4L2_CID_MPEG_VIDC_VIDEO_CIR_MBS. Driver needs
to support both versions as some of the clients use the standard
control.

Change-Id: Ib05f75f9c8eaa64dd08a548b71d1d2387aace9aa
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
Signed-off-by: Deva Ramasubramanian <dramasub@codeaurora.org>
msm: vidc: Add a control to disable the bit stream restrict flag

HFI_PROPERTY_PARAM_VENC_H264_VUI_BITSTREAM_RESTRC is set to true by
default in firmware, generating VUI which some decoders don't support.
This change provides an option to turn off the bitstream restrict
flag which, when used in conjunction with other VUI-related controls
being disabled, will prevent the encoder from generating VUI entirely.

Change-Id: Idb00d942bdd82b80001f9fda47a84aee231e4bdd
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
Signed-off-by: Deva Ramasubramanian <dramasub@codeaurora.org>
msm: vidc: Add control to preserve text quality

V4L2_CID_MPEG_VIDC_VIDEO_PRESERVE_TEXT_QUALITY allows the client to
tell the encoder to preserve the text quality whenever a given frame
contains text elements.  This reduces the amount of artifacts around the
text in the encoded frame.

Change-Id: If75ea580adaedc896d8a31410a194076f38b5179
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
Signed-off-by: Deva Ramasubramanian <dramasub@codeaurora.org>

Conflicts:
	drivers/media/platform/msm/vidc/vidc_hfi_api.h
vidc: move platform resource parsing out of v4l2

Keep v4l2 code cleaner by moving parsing logic to separate file.

Change-Id: I65999400ad4391caa396a2bdcc8494db1727bed9
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
Signed-off-by: Eric Ho <yinlokh@codeaurora.org>
msm: vidc: Handle SSR event in q6 hfi

APR send SSR events through callback and these
events have to handled properly in Q6 HFI. This
change translates SSR events to SYS_ERROR HFI event.

Change-Id: I82fe850d2df4ab1721755507c6d74d7b32a09b90
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
Signed-off-by: Sachin Shah <sachins@codeaurora.org>
msm: vidc: add check for bus scaling

Ensure the bus vector index calculated as
per macroblock load falls within the range
specified in the device dtsi file.

Change-Id: If972583932f26b76f10bf2e184f8050552b857cb
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
msm: vidc: Set proper verbosity in EBD function logs

Driver doesn't know if the returned values by FW will cause an error.
So lower the priority of the log being printed to avoid raising false
alarms.

Change-Id: I5bccaba13b24b48f76aa70a97e380c5096507f56
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
Signed-off-by: Jorge Solano Altamirano <jsolano@codeaurora.org>
msm: vidc: Add support for Constrained High Profile

This commit allows encoder clients to choose Constrained High
profile when encoding.

Change-Id: I0860367022bcdfab7d1a410b985f1a95fc6361cc
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
Signed-off-by: Deva Ramasubramanian <dramasub@codeaurora.org>