msm: vidc: defer probe if iommu_group_find fails

v4l2 video driver probe needs to defer till
iommu domains probe has been called. Without this
change, v4l2 video driver probe will fail if
iommu domains probe is not invoked prior to it.

Change-Id: Idbc1a4c90e558952f41f51ec96fdd3e7974490cd
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
msm: vidc: enable deferred probe support for Q6

Add support to defer probe for Q6 driver. Also fixes
a bug in venus hfi, whereby probe for venus hfi fails
if the core_id is not zero.

Change-Id: I67269107132bf352186fad1e177e4099cf9f4534
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
msm: vidc: change interface for opening driver instance

This change will ensure that vidc clients specify the
core id as venus or q6 to open a driver session.
Without this change, sometimes due to driver probe deferral,
core_id_0 would be taken by q6 and vidc clients intending to open a
venus decode session ended up opening a q6 decode session.

Change-Id: I4f9c862b8057999e4db7ca75be493138737a58a8
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
msm: vidc: Disable clock gating for 8x26

There are stability issue observed on 8x26 with
inter-frame clock gating enabled so disable
interframe clock gating on 8x26.

Change-Id: I0e2b89a0ce36ed4d5f15903ffe68b7c7275719c9
Signed-off-by: Vinay Kalia <vkalia@codeaurora.org>
msm: vidc: fix memory leak issue in dynamic buffer mode

While flushing output buffers held in v4l2 video
driver, i.e, with ref count equal to 2, the driver
was freeing the binfo structure. This would leak
the mapped output buffer memory. By avoiding
freeing of the binfo structure, the driver waits
for the release reference event from the firmware
to free and unmap the output buffer. Also move
initialization of dequeued flag for buffers to be
held in driver, till the time we queue this buffer
to firmware. By not doing so, the video driver can
enter a race condition, whereby, a output buffer could
be unmapped and freed before v4l2 client has called
dequeue on the buffer.

Change-Id: Ic95f13b9f4426574012539a76c0b87bedb8e805a
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
msm: vidc: add sleep of 100us before clock disable

ARM9 execute following sequence when venus is idle
1. Disable ARM9 watchdog
2. Set bit 30 of A_VENUS_CPU_CS_SCIACMDARG0 register
   to indicate venus is idle
3. Write HFI_MSG_SYS_IDLE to message queue
4. Raise interrupt to host
5. ARM9 execute wait for interrupt instruction to go
   into low power state. This will internally drain the
   ARM9 write buffer which can generate bus transaction.
6. ARM9 in idle

Host clock gate venus based on following sequence
1. Host receive HFI_MSG_SYS_IDLE from the msg queue
2. Host check both cmd / msg queue are empty by
   comparing the queue read/write pointers.
3. Host check bit 30 of A_VENUS_CPU_CS_SCIACMDARG0
   register to confirm it indicate idle
4. Host clock gate whole venus

As the host clock gate venus in step 4, ARM9 is still
in step 5&6. The sleep will ensure that step 5 and 6
are completed before host clock gates venus.

CRs-Fixed: 589417
CRs-Fixed: 595251
Change-Id: Idf1f788718adea2dacceca97afa4ba4fe4562ddd
Signed-off-by: Vikash Garodia <vgarodia@codeaurora.org>
msm: vidc: NULL terminate devicetree match table

Without NULL termination, of_dev_lookup() can run
off the end of the array and looking at invalid data.

Change-Id: Ib7d8b3afdc76d3f196d620d47eb77d4e0bc74d53
CRs-fixed: 582111
Signed-off-by: Sachin Shah <sachins@codeaurora.org>
msm: vidc: update max P frames num for encode

Remove the restriction on the max number of
P frame interval.

Change-Id: I637372d7b0d409602df251bad4a135b25514dc95
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
msm: vidc: Change tz version for dynamic buffer feature support

Use scm api to check if tz version is atleast 1.1.0. The tz changes
for assigning hint on map rather than the lock call are present
from that version onwards, which is needed for dynamic buffer
feature support.

Change-Id: I8a463c206f610d5d599d392e2502de307bfb95c0
Signed-off-by: Shalaj Jain <shalajj@codeaurora.org>
Revert "msm: vidc: Disable clock gating for 8x26"

This reverts commit 4a73878e8eef36c661b99afa19122632ccffa084.
Inter frame clock gating was earlier disabled to resolve PDT
issues.Venus clock was getting disabled, when the ARM9 was
still doing bus access.
The final fix is merged as 0435d4a997f43ec1612a796ed871dbc71ae98368.
With the fix, clock gating can be enabled again to save power
during Interframe clock gating as well as during power
collapse.Hence the revert to enable Interframe clock
gating.

Change-Id: I5c9815cd6281535654f55aa72f15715fc7f747a5
Signed-off-by: Vikash Garodia <vgarodia@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.

Change-Id: Idd8101e84823b10736ab75ced2ea3235d944ef55
CRs-fixed: 509088
Signed-off-by: Vinay Kalia <vkalia@codeaurora.org>

Conflicts:
	drivers/media/platform/msm/vidc/msm_vdec.c
msm: vidc: do not send release buffer to f/w in dynamic buffer mode

In dynamic buffer mode, the output buffers are not registered
with the firmware. So the v4l2 video driver does not need
to send release buffer command for output buffers to firmware.

Change-Id: I3b8f37fafe9fa07a45a68ded1de77e90f2764f6c
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
msm: vidc: add support to set VP8 QP range

QP range differs from codec to codec. This change adds support
for VP8 QP min and max range.

Change-Id: Ia44cf885a8b6f71b7eef51076968021ae68d7a7e
CRs-Fixed: 578892
Signed-off-by: Jorge Solano Altamirano <jsolano@codeaurora.org>
msm: vidc: Suppress spammy log

Suppress a needlessly spammy log that shows up when secure content is
being played.  Also make some other logs print out something useful.

Change-Id: I971e8f45393730218bc7a6947bdd938aa6b0732c
Signed-off-by: Deva Ramasubramanian <dramasub@codeaurora.org>
msm: vidc: fix issues raised by static analyzer

This change fixes the warnings raised by the
static code analyzer.

Change-Id: Ibbefb9bb945128ece8923dbb23679716a0654f7b
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
msm: vidc: Check if buffers are mapped before validating buffer_info

When buffers are not mapped by the driver (i.e. buffer being used by
kernel client), inst->registered_buffers is usually empty.  As a result,
in *_dqbuf(), binfo is always NULL.  This commit bypasses the NULL check
if buffers aren't being mapped by the driver.

CRs-Fixed: 610866
Change-Id: I111150564549a74f077ba8a7115129f497d734fc
Signed-off-by: Deva Ramasubramanian <dramasub@codeaurora.org>
msm: vidc: eliminate race condition in dynamic buffer mode

Function get_same_fd_buffer returned a pointer to
registered buffer, which shared the same fd as the
current buffer being mapped. While this buffer was
being accessed in map_and_register_buf(), it was
not guarded by the inst lock. So if the buffer was
erroneously freed, while it's still being accessed
in map_and_register_buf(), we may see a kernel
panic due to garbage values. To avoid this race
condition, introduce more checks in get_same_fd_buffer()
and return only the required handle information back to
map_and_register_buf.

Change-Id: I798c33dc344977c5db3bd74e5f863ca5cda14cb9
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
msm: vidc: Add min resolution check for video session

Add a check for minimum supported video resolution, based
on firmware capabilities and reject unsupported video sessions.

Change-Id: Ib5a4eb6e6ab66408cf13829e20d3933138f357c1
Signed-off-by: Arun Menon <avmenon@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: detect mbaff information from firmware

Firmware will set the FBD flags if mbaff interface
is detected for decoded video bitstream. Previously
the mbaff information was parsed in the v4l2 video
client, but now firmware parses and sends the information.

Change-Id: Ic557cdb7bf49aab3eb29a3f3aa3e363bf7223a36
Signed-off-by: Arun Menon <avmenon@codeaurora.org>