msm: vidc: expose smem apis through msm vidc

The v4l2 video driver exposes two disjoint set of apis - vidc
and smem. Incorporate smem in to vidc apis.

Change-Id: I2d984cbc480be7f584b9f0ca6b4d935257417a08
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
msm: vidc: Return failure for unsupported codecs

This change will check the codec type with supported codecs
(obtained from SYS_INIT_DONE response) and return failure
if unsupported codec is being set.

Change-Id: I113b4600b8c0152227cff50d5dff8c2da6f74c86
Signed-off-by: Maheshwar Ajja <majja@codeaurora.org>
msm: vidc: Fix handling of ocmem_notifier_register() return value

The ocmem driver might return -EPROBE_DEFER (or any other error)
as a ERR_PTR.  These shouldn't be construed as a valid handle.

CRs-fixed: 565882

Change-Id: I57c9739ae766a1b512ce930005c1cb310aa74034
Signed-off-by: Vinay Kalia <vkalia@codeaurora.org>
msm: vidc: Halt axi bus before clock disable

Before turning off venus clock, host should make sure
that there are no pending AXI transactions. This is achieved
by halting AXI.

CRs-Fixed: 578007

Change-Id: Ib4a71d1097f2f62e910e00c7be5d32e006d4c62b
Signed-off-by: Vikash Garodia <vgarodia@codeaurora.org>
msm: vidc: Fix cache invalidation issue

- Cache invalidation is being skipped out on all output
  buffers except first buffer due to NULL buffer handle
  in case of all output buffers are allocated as single
  chunk.
- This change fixes the issue by properly assigning the
  buffer handle for all output buffers.

CRs-Fixed: 581806
Change-Id: I415c3cc0ef9d82ea3c97ea618babbfbfc9f36f8b
Signed-off-by: Maheshwar Ajja <majja@codeaurora.org>

Conflicts:
	drivers/media/platform/msm/vidc/msm_vidc_common.c
msm: vidc: Check input arguments correctly

This commit fixes some minor bugs in which input arguments or malloc
return values were being insufficiently validated.

Change-Id: Ib0b3d2ded29384b49ec61a5fc275d3aca1fd6e14
Signed-off-by: Deva Ramasubramanian <dramasub@codeaurora.org>
msm: vidc: Halt axi bus before clock disable

Before turning off venus clock, host should make sure
that there are no pending AXI transactions. This is achieved
by halting AXI.

CRs-Fixed: 578007

Change-Id: Ib4a71d1097f2f62e910e00c7be5d32e006d4c62b
Signed-off-by: Vikash Garodia <vgarodia@codeaurora.org>

Conflicts:
	drivers/media/platform/msm/vidc/venus_hfi.c
	drivers/media/platform/msm/vidc/vidc_hfi_io.h
msm: vidc: Mask interrupts from venus after receiving IDLE message

IDLE message from venus indicates that the venus is idle and its
clocks are turned off. These clocks should not be turned on by any
pending or spurious(interrupts without any message) interrupts to save
power.

Change-Id: I622212a7e8c51106fbf69c491d129f219eb6ce54
CRs-fixed: 583989
Signed-off-by: Vinay Kalia <vkalia@codeaurora.org>
msm: vidc: fix corruption of registered buffer list

The buffer list for output buffers is accessed from
different threads leading to race conditions. Consider
the case of firmware throwing up a fatal error, which gets
propagated to v4l2 client. The v4l2 client closes the
driver fd, which will trigger msm_vidc_release_buffers
to release all output buffers and free node from
the registered buffer list. During this time, if
firmware sends a release reference event, the buffer
node being accessed in msm_vidc_release_buffers could
be freed, triggering kernel panic.

Change-Id: I522edff06a62dbc2ab60d6cca5990babb18d5c6c
Signed-off-by: Arun Menon <avmenon@codeaurora.org>
msm: vidc: Send ABORT in FLUSH command from the Client

When session error is sent to the client, client issues FLUSH
and release buffers commands. But as instance state is INVALID,
these commands are never sent to the firmware, instead FLUSH
DONE and Release buffer done are sent back to client even
though firmware might be working on these buffers which may
result into page faults.
This change fixes the issue by sending ABORT command to the
firmware at the time when driver receives FLUSH command. Then
firmware will release all buffers, clean up session and send
ABORT_DONE back to the driver.

Change-Id: Ie4c79a312d2336c68b858f5f5e2a85331cf55f7b
CRs-fixed: 592920
Signed-off-by: Deepak Verma <dverma@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: Fix a race condition in masking interrupts

Fix a race condition when interaction with firmware happens
in following sequence:

1. Firmware writes IDLE message into the message queue.
2. Driver writes a new command into command queue.
3. Firmware reads this command and starts processing it.
4. Driver checks if command queue is empty and finds it empty.
5. Firmware writes the response (of the command sent in 2) in
   message queue. Firmware also writes another IDLE message and
   sets the idle register.
6. Driver check if the IDLE register is set and finds it set.
7. Driver masks the interrupts. Since interrupts are masked,
   driver misses the response written by firmware in 5.

This race condition is fixed by checking if message queue is
empty or not between 6 and 7.

Change-Id: I4aa17cfc5fd9e33f6b41b6c1b12625789ff02283
Signed-off-by: Vinay Kalia <vkalia@codeaurora.org>

Conflicts:

	drivers/media/platform/msm/vidc/venus_hfi.c
msm: vidc: Fix unsupported codec error from video driver

- Client is getting unsupported codec error for set format
  sometimes after opening the video driver because driver
  was not updated with supported codecs information from
  video hardware.
- The same issue can be fixed by waiting for the driver state
  changed to CORE_INIT_DONE, which ensures the supported codecs
  information will be updated in video driver, before checking
  the supported codecs information.

CRs-fixed: 590158
Change-Id: Ia9132fdc01e4fa53533a3c9d14069d49501fa7d7
Signed-off-by: Maheshwar Ajja <majja@codeaurora.org>