msm: kgsl: Fix mem leak when page allocation fails

Page allocation may fail during OOM condition. Update
sglen and size to correct value (allocated) so that
they get freed in kgsl_sharedmem_free().

Change-Id: I1aa0ca77bb767523dfcf0f6cc3a21eac2b6b80e4
Signed-off-by: Hareesh Gundu <hareeshg@codeaurora.org>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
msm: buspm: Correct size type in buspm_xfer_req

Variable size inside buspm_xfer_req
can be negative and thus would be a
large positive number resulting in arbitary
Kernel read. This patch corrects this value.

CRs-Fixed: 563529
Change-Id: I877db6960530d6c7d1486da9cfdc15a43e57e152
Signed-off-by: Sana Venkat Raju <c_vsana@codeaurora.org>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
msm: msm_bus: Fix the type error causing bandwidth overflow

On legacy chipsets, long int was being used to store
return value after calculating interleaved bw. However,
NoCs support 64-bit integers ab/ib values. problme occurs
if client request for higher bw and if difference of ab
value exceeds the range of 32 bit integer, the Value
overflows and turns negative, which leads to wrong bw calculation.

This patch fixes this integer overflow by correcting argument
type to store bw.

CRs-Fixed: 537213
Change-Id: I8c6c79ba245a988c2c54ccaca3f3eaf5cb857ce5
Signed-off-by: Alok Chauhan <alokc@codeaurora.org>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
msm: msm_bus: send correct value to bw division function

While calculating bw for existing client request
sometimes it can go to negative if client unregisters
or send request with lesser ab/ib values. Bus driver
will divide bandwidth if interleaving enabled.

Added a macro wrapper to handle negative bw values
since the division utility function can't handle
negative values

CRs-Fixed: 521940
Change-Id: Ic3a216b8efb535593fe02ad3228d71808d2e0f98
Signed-off-by: Alok Chauhan <alokc@codeaurora.org>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
input: touchboost: don't refresh the policy limits if the current frequency is not lower than input_boost_freq.

Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
usb: gadget: Fix synchronization issue between f_audio_source

Race is happening when both audio_pcm_close() and audio_send()
executes in parallel.
When the PCM session is closed, the substream attribute of the
audio_dev structure is set to NULL in audio_pcm_close().
As there is no synchronization protection for the audio_dev subtream
attributes in audio_send(), it is causing NULL pointer dereference.
Hence fixing the issue by adding proper synchronization protection
for the audio_dev subtream attributes in audio_send().

CRs-Fixed: 613498
Change-Id: Id9ab0d4e347b8bb2f551f9033829e541bdcaf0e8
Signed-off-by: ChandanaKishori Chiluveru <cchilu@codeaurora.org>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
leds: At disable, set the trigger to default instead of wiping it

Change-Id: Ifb4a3b3034c441d29fd1d9f209ed829adfc76a72
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
mm: page_alloc: fix section_mismatch because set_pageblock_order could be called by memory_hotplug.

Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
msm: vidc: Enable venus power management

Besides clock gating, turn venus core power off
if the core stays idle for given amount of time.
Powering off venus core involves telling TZ to
suspend venus core, detach IOMMU, disable GDSC
regulator, unvote DDR/OCMEM buses.

Turn it on again when driver starts processing new
commands before enabling clocks.

Protect clock and power states and operations
with a common lock.

Change-Id: I49654069920ddaae0e2f8792b14cd1bfeb431c34
Signed-off-by: Sachin Shah <sachins@codeaurora.org>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
msm: vidc: Make HW timeout and power collapse delay configurable

Provide debugfs node for HW response timeout and a sysfs device
attribute for power collapse delay.

Change-Id: I586f10f3e90df5384c8e465fbfe8e7ebec0915eb
Signed-off-by: Sachin Shah <sachins@codeaurora.org>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
msm: vidc: Protect remaining clock operations

Clock enable/disable operations are only protected
during interframe clock gating and power collapse.
With this change, clock operations are also protected
during device initialization and removal.

Change-Id: Idcc81b7563349a45affe4abf0a148c4386be3aa0
Signed-off-by: Sachin Shah <sachins@codeaurora.org>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
msm: vidc: Add clocks and power counts

Enable power and clock ref counts in debugfs
to easily debug any ref count mismatch.

Change-Id: If06ef139f5a4517cb29a84e86193a6cc2c0f9e64
Signed-off-by: Sachin Shah <sachins@codeaurora.org>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
msm: vidc: Synchronise data shared between controls

Some of the V4L2 controls perform similar tasks and have some shared
data between them.  Unexpected sequences of controls can possibly cause
data coherency issues causing the firmware to be programmed incorrectly.
So, when a control is updated with a new value, update related controls
with a similar enum so that they both have similar values.

Also, change the frame rate values to normal FPS rather than Q16 format.

Change-Id: Iebb0ddc33374ab8eb7106b005965c2eede797aea
Signed-off-by: Deva Ramasubramanian <dramasub@codeaurora.org>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
msm: vidc: Increase timeout for power collapse

Increase power collase timeout to avoid venus power
collapse before the video video/encoding decoding is
actually started. This is needed to avoid iommu map
failures at the beginning of the playback.

Change-Id: I82457a9b847c6e8e53bd6ffb6a381a64c0d38417
Signed-off-by: Vinay Kalia <vkalia@codeaurora.org>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
msm: vidc: Handle SYS_IDLE interrupt concurrency

It is possible to receive SYS_IDLE message before
Venus core sends the interrupt for that message.
This results in clocks not being disabled at all
and device will continue to drain power.

This change checks when the interrupt is received
if the venus core is still in IDLE state. If it is
then disable the clocks.

Change-Id: If2b8d778054a702eada40ac3588e2ec3a3fbd80a
CRs-fixed: 548745
Signed-off-by: Sachin Shah <sachins@codeaurora.org>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
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>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
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>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
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>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
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>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>

Conflicts:

	drivers/media/platform/msm/vidc/venus_hfi.c

Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
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>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>